ReceiptController.php 558 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050
  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. private function _itineraryDateMin(){
  58. Doo::loadModel ( "itinerary" );
  59. $itinerary = new itinerary ();
  60. $itineraryDetail=$itinerary->getOne(array (
  61. 'where'=>'sid ='.$this->staff [0] ['sid'],
  62. 'desc'=>'itineraryDate',
  63. 'asArray' => true
  64. ));
  65. return date("Y-m-d",strtotime("+1 day",strtotime($itineraryDetail['itineraryDate'])));
  66. }
  67. public function beforeRun($resource, $action) {
  68. Doo::loadClass ( 'XDeode' );
  69. $XDeode = new XDeode ( 5 );
  70. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  71. // 单独判断公司汇总的访问权限
  72. if ($action == 'companyCategoryCollect') {
  73. Doo::loadModel ( "receiptAuthorityManage" );
  74. $invoiceCompanyManage = new receiptAuthorityManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request-statistics' );
  78. }
  79. Doo::loadModel ( 'staff' );
  80. $staff = new staff ();
  81. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  82. $accessModular = 'RECEIPTS';
  83. if (empty ( $detail ['cldAccessArray'] ))
  84. die ( 'illegal request' );
  85. else {
  86. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  87. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  88. $flag = true;
  89. } else {
  90. $flag = false;
  91. }
  92. } else {
  93. die ( 'illegal request' );
  94. }
  95. }
  96. if (! $flag)
  97. die ( 'illegal request' );
  98. }
  99. function __construct() {
  100. if (isset ( $_COOKIE ["staff"] )) {
  101. if (! empty ( $_COOKIE ["staff"] )) {
  102. Doo::loadModel ( 'staff' );
  103. Doo::loadModel ( 'verify' );
  104. $verify = new verify ();
  105. $staff = new staff ();
  106. Doo::loadModel ( "execute" );
  107. $execute = new execute ();
  108. $verifyList = $verify->find ( array (
  109. 'select' => 'staff',
  110. 'asArray' => true
  111. ) );
  112. $list = array ();
  113. // 判断角色的审批权限
  114. foreach ( $verifyList as $key => $value ) {
  115. $ver = json_decode ( $value ['staff'] );
  116. foreach ( $ver as $k => $v ) {
  117. if ($v [1] == 'ROLE') {
  118. $roleList = json_decode ( $v [3] );
  119. foreach ( $roleList as $t => $g ) {
  120. $gList = explode ( "_", $g );
  121. array_push ( $list, $gList [0] );
  122. // print_r($list);
  123. }
  124. } else
  125. array_push ( $list, $v [0] );
  126. }
  127. }
  128. // 判断执行人的审批权限
  129. $executeList = $execute->find ( array (
  130. 'where'=>'mold !="日常收支"',
  131. 'select' => 'staff',
  132. 'asArray' => true
  133. ) );
  134. $list2 = array ();
  135. foreach ( $executeList as $key => $value ) {
  136. $ver = json_decode ( $value ['staff'] );
  137. foreach ( $ver as $k => $v ) {
  138. array_push ( $list2, $v [0] );
  139. }
  140. }
  141. $eidList = file_get_contents ( "protected/config/execute/execute.ini" );
  142. $eidList = array_filter ( explode ( ",", $eidList ) );
  143. $this->executeId = array_merge ( $list2, $eidList );
  144. //print_r($this->executeId);
  145. $this->verifyId = $list;
  146. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  147. // 检测用户信息完成
  148. $this->data ['isStaffCompleteMsg'] = false;
  149. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  150. if (! empty ( $detail ))
  151. $this->data ['isStaffCompleteMsg'] = true;
  152. return "/";
  153. }
  154. }
  155. Doo::loadCore ( 'uri/DooUriRouter' );
  156. $router = new DooUriRouter ();
  157. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  158. if ($routeRs ['1'] != "login") {
  159. header ( 'Content-Type:text/html;charset=utf-8' );
  160. @header ( "Location: /login" );
  161. }
  162. }
  163. /**
  164. * 费用首页
  165. */
  166. function saeaBorad() {
  167. $travel= $this->get_args ( 'travel' ) ? $this->get_args ( 'travel' ) : "";
  168. Doo::loadModel ( 'receipt' );
  169. $receipt = new receipt ();
  170. Doo::loadModel ( 'verify' );
  171. $verify = new verify ();
  172. Doo::loadModel ( 'L_category' );
  173. $lCategory = new L_category ();
  174. Doo::loadModel ( "role" );
  175. $role = new role ();
  176. Doo::loadModel ( "receiptLog" );
  177. $receiptLog = new receiptLog ();
  178. Doo::loadModel ( 'accountItem' );
  179. $accountItem = new accountItem ();
  180. Doo::loadClass ( 'XDeode' );
  181. $XDeode = new XDeode ( 7 );
  182. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  183. $receiptDetail = $receipt->find ( array (
  184. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  185. 'desc' => 'rid',
  186. 'asArray' => true
  187. ) );
  188. foreach ( $receiptDetail as $key => $value ) {
  189. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  190. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  191. $veList = $verify->getOne ( array (
  192. 'where' => 'vid=' . $value ['verify'],
  193. 'asArray' => true
  194. ) );
  195. $v = json_decode ( $veList ['staff'] );
  196. array_push ( $v [0], $veList ['description'] );
  197. foreach ( $v as $n => $m ) {
  198. if ($m ['1'] == 'ROLE') {
  199. $roleInfo = $role->getOne ( array (
  200. 'where' => 'rid=' . $m [0],
  201. 'asArray' => true
  202. ) );
  203. $v [$n] [1] = $roleInfo ['name'];
  204. }
  205. }
  206. $receiptDetail [$key] ['staff'] = $v;
  207. $category = $lCategory->getOne ( array (
  208. 'where' => 'cid=' . $value ['cid'],
  209. 'asArray' => true
  210. ) );
  211. $receiptDetail [$key] ['category'] = $category ['title'];
  212. }
  213. // print_r($receiptLogList);
  214. Doo::loadModel ( 'RAssist' );
  215. $RAssist = new RAssist ();
  216. $receiptExtendList=$RAssist->getRAssistBySid($this->staff[0]['sid']);
  217. //费用项目
  218. $acItem = $accountItem->find ( array ('asArray' => true) );
  219. if ($travel=='success'){
  220. $data ['travel'] =true;
  221. }else{
  222. $data ['travel'] =false;
  223. }
  224. $data ['acItem'] = $acItem;
  225. $data ['receiptExtendList'] = $receiptExtendList;
  226. $data ['receiptLogList'] = $receiptLogList;
  227. $data ['receiptDetail'] = $receiptDetail;
  228. $data ['memu'] = "receipt";
  229. $data ['staff'] = $this->staff;
  230. $data ['receiptMemu'] = 'saeaBorad';
  231. $data ['verifyId'] = $this->verifyId;
  232. $data ['executeId'] = $this->executeId;
  233. $this->render ( "/receipt/receiptFee", $data );
  234. }
  235. /**
  236. * 费用报销单-导流入哪个细分类
  237. */
  238. function receiptFeeDiversion(){
  239. $feeType= $this->get_args ( 'feeType' ) ? $this->get_args ( 'feeType' ) : "";
  240. if($feeType==2){
  241. return '/receipt/feeTravel';
  242. }elseif($feeType==3){
  243. return '/receipt/feeInternalTrain';
  244. }else{
  245. return '/receipt/feeAgency';
  246. }
  247. }
  248. private function _feeData(){
  249. Doo::loadModel ( 'L_category' );
  250. $lCategory = new L_category ();
  251. Doo::loadModel ( 'verify' );
  252. $verify = new verify ();
  253. Doo::loadModel ( 'accountItem' );
  254. $accountItem = new accountItem ();
  255. Doo::loadModel ( "role" );
  256. $role = new role ();
  257. $acItem = $accountItem->find ( array (
  258. 'asArray' => true
  259. ) );
  260. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  261. $data ['category'] = $lCategory->find ( array (
  262. 'asArray' => true
  263. ) );
  264. $data ['itineraryDate'] = $this->_itineraryDateMin();
  265. $data ['veList'] = $veList;
  266. $data ['acItem'] = $acItem;
  267. $data ['memu'] = "receipt";
  268. $data ['staff'] = $this->staff;
  269. $data ['receiptMemu'] = 'saeaBorad';
  270. $data ['verifyId'] = $this->verifyId;
  271. $data ['executeId'] = $this->executeId;
  272. return $data;
  273. }
  274. /**
  275. * 办事处相关费用
  276. */
  277. function feeAgency(){
  278. $data=$this->_feeData();
  279. $this->render ( "/receipt/feeAgency", $data );
  280. }
  281. /**
  282. * 办事处
  283. */
  284. function feeTravel(){
  285. $data=$this->_feeData();
  286. $this->render ( "/receipt/feeTravel", $data );
  287. }
  288. function feeInternalTrain(){
  289. $data=$this->_feeData();
  290. $this->render ( "/receipt/feeInternalTrain", $data );
  291. }
  292. /**
  293. * 添加费用报销单页面
  294. */
  295. function saeaCreate() {
  296. Doo::loadModel ( 'accountItem' );
  297. Doo::loadModel ( 'verify' );
  298. Doo::loadModel ( 'receipt' );
  299. Doo::loadModel ( 'L_category' );
  300. $lCategory = new L_category ();
  301. $receipt = new receipt ();
  302. $verify = new verify ();
  303. $accountItem = new accountItem ();
  304. Doo::loadModel ( "role" );
  305. $role = new role ();
  306. $acItem = $accountItem->find ( array (
  307. 'asArray' => true
  308. ) );
  309. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  310. $data ['category'] = $lCategory->find ( array (
  311. 'asArray' => true
  312. ) );
  313. $data ['veList'] = $veList;
  314. $data ['acItem'] = $acItem;
  315. $data ['memu'] = "receipt";
  316. $data ['staff'] = $this->staff;
  317. $data ['receiptMemu'] = 'saeaBorad';
  318. $data ['verifyId'] = $this->verifyId;
  319. $data ['executeId'] = $this->executeId;
  320. $this->render ( "/admin/saea_create", $data );
  321. }
  322. private function _storageItinerary($itinerary,$rid,$version=2){
  323. $itineraryJson=json_decode($itinerary,true);
  324. Doo::loadModel ( 'itinerary' );
  325. $itinerary = new itinerary ();
  326. $itinerary->delete(array('where' => 'rid=' . $rid ));
  327. if($version==2){
  328. foreach ($itineraryJson as $k=>$v){
  329. foreach ($v as $kk=>$vv){
  330. foreach ($vv as $key=>$value){
  331. if($key==0){
  332. $feeTraveItem=json_encode($value['feeTraveItem']);
  333. $itinerary = new itinerary ();
  334. $itinerary->rid=$rid;
  335. $itinerary->sid=$this->staff [0] ['sid'];
  336. $itinerary->itineraryDate=$value['departuredate'];
  337. $itinerary->itineraryCity=$value['departurecity'];
  338. $itinerary->feeTraveItem='';
  339. $itinerary->itineraryIndex=0;
  340. $itinerary->insert ();
  341. $itinerary = new itinerary ();
  342. $itinerary->rid=$rid;
  343. $itinerary->sid=$this->staff [0] ['sid'];
  344. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  345. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  346. $itinerary->feeTraveItem=$feeTraveItem;
  347. $itinerary->itineraryIndex=1;
  348. $itinerary->insert ();
  349. }else{
  350. $feeTraveItem=json_encode($value['feeTraveItem']);
  351. $itinerary = new itinerary ();
  352. $itinerary->rid=$rid;
  353. $itinerary->sid=$this->staff [0] ['sid'];
  354. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  355. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  356. $itinerary->feeTraveItem=$feeTraveItem;
  357. $itinerary->itineraryIndex=$key+1;
  358. $itinerary->insert ();
  359. }
  360. }
  361. }
  362. }
  363. }elseif($version==1){
  364. foreach ($itineraryJson as $key=>$value){
  365. if($key==0){
  366. $feeTraveItem=json_encode($value['feeTraveItem']);
  367. $itinerary = new itinerary ();
  368. $itinerary->rid=$rid;
  369. $itinerary->sid=$this->staff [0] ['sid'];
  370. $itinerary->itineraryDate=$value['departuredate'];
  371. $itinerary->itineraryCity=$value['departurecity'];
  372. $itinerary->feeTraveItem='';
  373. $itinerary->itineraryIndex=0;
  374. $itinerary->insert ();
  375. $itinerary = new itinerary ();
  376. $itinerary->rid=$rid;
  377. $itinerary->sid=$this->staff [0] ['sid'];
  378. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  379. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  380. $itinerary->feeTraveItem=$feeTraveItem;
  381. $itinerary->itineraryIndex=1;
  382. $itinerary->insert ();
  383. }else{
  384. $feeTraveItem=json_encode($value['feeTraveItem']);
  385. $itinerary = new itinerary ();
  386. $itinerary->rid=$rid;
  387. $itinerary->sid=$this->staff [0] ['sid'];
  388. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  389. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  390. $itinerary->feeTraveItem=$feeTraveItem;
  391. $itinerary->itineraryIndex=$key+1;
  392. $itinerary->insert ();
  393. }
  394. }
  395. }else{
  396. die ( '行程单版本不正确' );
  397. }
  398. }
  399. private function _verificationItinerary($itinerary){
  400. Doo::loadModel ( 'itinerary' );
  401. $itineraryObj = new itinerary ();
  402. if(empty($itinerary)){
  403. return false;
  404. }
  405. $itineraryJson=json_decode($itinerary,true);
  406. $itineraryDate=array();$sql=array();
  407. foreach ($itineraryJson as $k=>$v){
  408. foreach ($v as $kk=>$vv){
  409. foreach ($vv as $key=>$value){
  410. if($key==0){
  411. array_push($itineraryDate, $value['departuredate']);
  412. array_push($itineraryDate, substr($value['arrivalsdate'],1));
  413. array_push($sql,'?');array_push($sql,'?');
  414. }else{
  415. array_push($itineraryDate, substr($value['arrivalsdate'],1));
  416. array_push($sql,'?');
  417. }
  418. }
  419. }
  420. }
  421. array_push($itineraryDate, $this->staff [0] ['sid']);
  422. $sql=implode(',',$sql);
  423. // $itineraryDate=array();$sql=array();
  424. // foreach ($itineraryJson as $key=>$value){
  425. // if($key==0){
  426. // array_push($itineraryDate, $value['departuredate']);
  427. // array_push($itineraryDate, substr($value['arrivalsdate'],1));
  428. // array_push($sql,'?');array_push($sql,'?');
  429. // }else{
  430. // array_push($itineraryDate, substr($value['arrivalsdate'],1));
  431. // array_push($sql,'?');
  432. // }
  433. // }
  434. // array_push($itineraryDate, $this->staff [0] ['sid']);
  435. // $sql=implode(',',$sql);
  436. $qualification=array(
  437. 'where' => 'itineraryDate in ('.$sql.') and sid=? ',
  438. 'param' => $itineraryDate,
  439. 'asArray' => TRUE);
  440. $itDateList=$itineraryObj->find($qualification);
  441. if(empty($itDateList)){
  442. return false;
  443. }else{
  444. return true;
  445. }
  446. }
  447. private function _buildFeeData($receiptClass=1,$itinerary=''){
  448. $agency = $this->get_args ( 'agency' );
  449. $travel = $this->get_args ( 'travel' );
  450. $train = $this->get_args ( 'train' );
  451. $other = $this->get_args ( 'other' );
  452. $inttrain = $this->get_args ( 'inttrain' );
  453. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  454. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  455. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  456. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  457. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  458. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  459. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  460. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  461. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  462. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  463. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  464. header ( 'Content-Type:text/html;charset=utf-8' );
  465. die ( '请填写联行号' );
  466. }
  467. if($receiptClass==2){
  468. //TODO 日期检测
  469. if($this->_verificationItinerary($itinerary)){
  470. header ( 'Content-Type:text/html;charset=utf-8' );
  471. die ( '已申请过类此日期的行程' );
  472. }
  473. }
  474. $itinerary=str_replace('\n','<br/>',$itinerary);
  475. Doo::loadModel ( 'receipt' );
  476. Doo::loadModel ( 'receiptDetail' );
  477. Doo::loadModel ( 'accountItem' );
  478. $accountItem = new accountItem ();
  479. $receipt = new receipt ();
  480. Doo::loadModel ( 'enclosur' );
  481. Doo::loadModel ( 'execute' );
  482. $execute = new execute ();
  483. $executeDetail = $execute->getOne ( array (
  484. 'where' => 'mold="报销单执行人"',
  485. 'asArray' => true
  486. ) );
  487. $aItem = $accountItem->find ( array (
  488. 'asArray' => true
  489. ) );
  490. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  491. $ag = $tr = $ta = $ot= $it = 0;
  492. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  493. foreach ( $aItem as $key => $value ) {
  494. if ($value ['category'] == $this->AGENCY) {
  495. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  496. array_push ( $accountJson [$this->AGENCY], array (
  497. 'aid' => $value ['aid'],
  498. 'name' => $value ['name'],
  499. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  500. ) );
  501. $sum += $agency [$ag];
  502. $agencySum += $agency [$ag];
  503. }
  504. $ag ++;
  505. }
  506. if ($value ['category'] == $this->TRAVEL) {
  507. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  508. array_push ( $accountJson [$this->TRAVEL], array (
  509. 'aid' => $value ['aid'],
  510. 'name' => $value ['name'],
  511. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  512. ) );
  513. $sum += $travel [$tr];
  514. $travelSum += $travel [$tr];
  515. }
  516. $tr ++;
  517. }
  518. if ($value ['category'] == $this->TRAIN) {
  519. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  520. array_push ( $accountJson [$this->TRAIN], array (
  521. 'aid' => $value ['aid'],
  522. 'name' => $value ['name'],
  523. 'price' => number_format ( $train [$ta], 2, '.', '' )
  524. ) );
  525. $sum += $train [$ta];
  526. $trainSum += $train [$ta];
  527. }
  528. $ta ++;
  529. }
  530. if ($value ['category'] == $this->INTTRAIN) {
  531. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  532. array_push ( $accountJson [$this->INTTRAIN], array (
  533. 'aid' => $value ['aid'],
  534. 'name' => $value ['name'],
  535. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  536. ) );
  537. $sum += $inttrain [$it];
  538. $inttrainSum += $inttrain [$it];
  539. }
  540. $it ++;
  541. }
  542. if ($value ['category'] == $this->OTHER) {
  543. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  544. array_push ( $accountJson [$this->OTHER], array (
  545. 'aid' => $value ['aid'],
  546. 'name' => $value ['name'],
  547. 'price' => number_format ( $other [$ot], 2, '.', '' )
  548. ) );
  549. $sum += $other [$ot];
  550. $otherSum += $other [$ot];
  551. }
  552. $ot ++;
  553. }
  554. }
  555. $accountJson ['cSum'] = array (
  556. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  557. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  558. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  559. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  560. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  561. );
  562. // 报销单
  563. $receipt->accountItem = json_encode ( $accountJson );
  564. $receipt->staff = $this->staff [0] ['sid'];
  565. $receipt->sum = number_format ( $sum, 2, '.', '' );
  566. $receipt->date = date ( "Y-m-d" );
  567. $receipt->cid = $cid;
  568. $receipt->status = 5;
  569. // 修改审批流程加入角色
  570. $receipt->verify = $verify;
  571. $receipt->executeCopy = $executeDetail ['staff'];
  572. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  573. $order = array (
  574. "\r\n",
  575. "\n",
  576. "\r"
  577. );
  578. $replace = '<br/>';
  579. $explanation = str_replace ( $order, $replace, $explanation );
  580. $receipt->explanation = $explanation;
  581. $receipt->receiptClass = $receiptClass;
  582. $receipt->itinerary2=$itinerary;
  583. $receipt->remittanceName = $remittanceName;
  584. $receipt->bankName = $bankName;
  585. $receipt->bankNumber = $bankNumber;
  586. $receipt->remittanceBankType = $remittanceBankType;
  587. if ($remittanceBankType == 1) {
  588. $receipt->coupletNumber = $coupletNumber;
  589. }
  590. $rid = $receipt->insert ();
  591. //记录行程单
  592. $this->_storageItinerary($itinerary,$rid);
  593. // 附件
  594. if (! empty ( $enclosurName )) {
  595. $enclosurArray = explode ( '-', $enclosurName );
  596. foreach ( $enclosurArray as $value ) {
  597. $enclosur = new enclosur ();
  598. $enclosur->name = $value;
  599. $enclosur->rid = $rid;
  600. $enclosur->insert ();
  601. }
  602. }
  603. // 报销详情
  604. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  605. $receiptDetail = new receiptDetail ();
  606. $receiptDetail->staff = $this->staff [0] ['sid'];
  607. $receiptDetail->item = $value ['name'];
  608. $receiptDetail->itemCategory = $this->AGENCY;
  609. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  610. $receiptDetail->date = date ( "Y-m-d" );
  611. $receiptDetail->cid = $cid;
  612. $receiptDetail->rid = $rid;
  613. $receiptDetail->status = 4;
  614. $receiptDetail->insert ();
  615. }
  616. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  617. $receiptDetail = new receiptDetail ();
  618. $receiptDetail->staff = $this->staff [0] ['sid'];
  619. $receiptDetail->item = $value ['name'];
  620. $receiptDetail->itemCategory = $this->TRAVEL;
  621. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  622. $receiptDetail->date = date ( "Y-m-d" );
  623. $receiptDetail->cid = $cid;
  624. $receiptDetail->rid = $rid;
  625. $receiptDetail->status = 4;
  626. $receiptDetail->insert ();
  627. }
  628. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  629. $receiptDetail = new receiptDetail ();
  630. $receiptDetail->staff = $this->staff [0] ['sid'];
  631. $receiptDetail->item = $value ['name'];
  632. $receiptDetail->itemCategory = $this->TRAIN;
  633. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  634. $receiptDetail->date = date ( "Y-m-d" );
  635. $receiptDetail->cid = $cid;
  636. $receiptDetail->rid = $rid;
  637. $receiptDetail->status = 4;
  638. $receiptDetail->insert ();
  639. }
  640. // 内训
  641. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  642. $receiptDetail = new receiptDetail ();
  643. $receiptDetail->staff = $this->staff [0] ['sid'];
  644. $receiptDetail->item = $value ['name'];
  645. $receiptDetail->itemCategory = $this->INTTRAIN;
  646. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  647. $receiptDetail->date = date ( "Y-m-d" );
  648. $receiptDetail->cid = $cid;
  649. $receiptDetail->rid = $rid;
  650. $receiptDetail->status = 4;
  651. $receiptDetail->insert ();
  652. }
  653. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  654. $receiptDetail = new receiptDetail ();
  655. $receiptDetail->staff = $this->staff [0] ['sid'];
  656. $receiptDetail->item = $value ['name'];
  657. $receiptDetail->itemCategory = $this->OTHER;
  658. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  659. $receiptDetail->date = date ( "Y-m-d" );
  660. $receiptDetail->cid = $cid;
  661. $receiptDetail->rid = $rid;
  662. $receiptDetail->status = 4;
  663. $receiptDetail->insert ();
  664. }
  665. return true;
  666. } else
  667. return false;
  668. }
  669. function addReceipt() {
  670. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  671. if ($this->_buildFeeData(1)) {
  672. return "/saeaBorad";
  673. } else{
  674. die ( 'illegal request' );
  675. }
  676. }
  677. function addFeeTravel(){
  678. $itinerary = $_POST['itinerary'] ? $_POST['itinerary'] : "";
  679. $itineraryList=json_decode($itinerary,true);
  680. // foreach ($itineraryList as $key=>$value){
  681. // if(empty($value['departuredate'])||empty($value['departurecity'])){
  682. // header ( 'Content-Type:text/html;charset=utf-8' );
  683. // die ( '请设置出发地和出发日期' );
  684. // }
  685. // }
  686. if ($this->_buildFeeData(2,$itinerary)) {
  687. return "/saeaBorad?travel=success";
  688. } else{
  689. die ( 'illegal request' );
  690. }
  691. }
  692. function addFeeInternalTrain(){
  693. if ($this->_buildFeeData(3)) {
  694. return "/saeaBorad";
  695. } else{
  696. die ( 'illegal request' );
  697. }
  698. }
  699. function referReceipt() {
  700. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  701. Doo::loadModel ( 'receipt' );
  702. Doo::loadModel ( 'verify' );
  703. $verify = new verify ();
  704. $receipt = new receipt ();
  705. Doo::loadModel ( 'L_category' );
  706. $lCategory = new L_category ();
  707. Doo::loadModel ( "role" );
  708. $role = new role ();
  709. $receiptDetail = $receipt->find ( array (
  710. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  711. 'asArray' => true
  712. ) );
  713. if (empty ( $receiptDetail ))
  714. return "/addReceipt";
  715. foreach ( $receiptDetail as $key => $value ) {
  716. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  717. $veList = $verify->getOne ( array (
  718. 'where' => 'vid=' . $value ['verify'],
  719. 'asArray' => true
  720. ) );
  721. $v = json_decode ( $veList ['staff'] );
  722. array_push ( $v [0], $veList ['description'] );
  723. foreach ( $v as $n => $m ) {
  724. if ($m ['1'] == 'ROLE') {
  725. $roleInfo = $role->getOne ( array (
  726. 'where' => 'rid=' . $m [0],
  727. 'asArray' => true
  728. ) );
  729. $v [$n] [1] = $roleInfo ['name'];
  730. }
  731. }
  732. $receiptDetail [$key] ['staff'] = $v;
  733. $category = $lCategory->getOne ( array (
  734. 'where' => 'cid=' . $value ['cid'],
  735. 'asArray' => true
  736. ) );
  737. $receiptDetail [$key] ['category'] = $category ['title'];
  738. }
  739. // print_r($receiptDetail);
  740. $data ['receiptDetail'] = $receiptDetail;
  741. $data ['memu'] = "receipt";
  742. $data ['staff'] = $this->staff;
  743. $data ['receiptMemu'] = 'saeaCreate';
  744. $data ['verifyId'] = $this->verifyId;
  745. $data ['executeId'] = $this->executeId;
  746. $this->render ( "/admin/saea_confirm", $data );
  747. }
  748. function editReceipt() {
  749. // edit status 4
  750. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  751. Doo::loadClass ( 'XDeode' );
  752. $XDeode = new XDeode ( 7 );
  753. $rid = $XDeode->decode ( $ridKey );
  754. if (empty ( $rid )) {
  755. die ( 'illegal request-id' );
  756. }
  757. // echo $rid.'sd';
  758. Doo::loadModel ( 'accountItem' );
  759. Doo::loadModel ( 'verify' );
  760. Doo::loadModel ( 'receipt' );
  761. $receipt = new receipt ();
  762. $verify = new verify ();
  763. $accountItem = new accountItem ();
  764. Doo::loadModel ( 'L_category' );
  765. $lCategory = new L_category ();
  766. Doo::loadModel ( "role" );
  767. $role = new role ();
  768. Doo::loadModel ( 'enclosur' );
  769. $enclosur = new enclosur ();
  770. $receiptDetail = $receipt->getOne ( array (
  771. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  772. 'asArray' => true
  773. ) );
  774. if (empty ( $receiptDetail )) {
  775. die ( 'illegal request-emptyData' );
  776. }
  777. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  778. $acItem = $accountItem->find ( array (
  779. 'asArray' => true
  780. ) );
  781. $veList = $verify->getVerifyBySubordinate ( 'RECEIPT' );
  782. // 配置编辑信息
  783. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  784. foreach ( $acItem as $key => $value ) {
  785. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  786. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  787. $acItem [$key] ['price'] = $v ['price'];
  788. }
  789. }
  790. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  791. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  792. $acItem [$key] ['price'] = $v ['price'];
  793. }
  794. }
  795. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  796. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  797. $acItem [$key] ['price'] = $v ['price'];
  798. }
  799. }
  800. // 内训
  801. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  802. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  803. $acItem [$key] ['price'] = $v ['price'];
  804. }
  805. }
  806. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  807. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  808. $acItem [$key] ['price'] = $v ['price'];
  809. }
  810. }
  811. }
  812. //$receiptDetail['itinerary']=str_replace('\n','<br/>',$receiptDetail['itinerary']);
  813. //nl2br($receiptDetail['explanation']);
  814. $receiptDetail['explanation']= str_replace('<br/>',"\n",$receiptDetail['explanation']);
  815. $data ['category'] = $lCategory->find ( array (
  816. 'asArray' => true
  817. ) );
  818. $data ['cSum'] = $accountItemList ['cSum'];
  819. $data ['sum'] = $receiptDetail ['sum'];
  820. $data ['enclosurList'] = $enclosurList;
  821. $data ['receiptDetail'] = $receiptDetail;
  822. $data ['veList'] = $veList;
  823. $data ['acItem'] = $acItem;
  824. $data ['memu'] = "receipt";
  825. $data ['staff'] = $this->staff;
  826. $data ['receiptMemu'] = 'saeaBorad';
  827. $data ['verify'] = $receiptDetail ['verify'];
  828. $data ['verifyId'] = $this->verifyId;
  829. $data ['executeId'] = $this->executeId;
  830. $data ['rid'] = $ridKey;
  831. if($receiptDetail['receiptClass']==1){
  832. $this->render ( "/receipt/feeAgencyEdi", $data );
  833. }elseif($receiptDetail['receiptClass']==2){
  834. if(!empty($receiptDetail['itinerary2'])){
  835. //TODO 报销说明
  836. $this->render ( "/receipt/feeTravelEdi2", $data );
  837. }else{
  838. $this->render ( "/receipt/feeTravelEdi", $data );
  839. }
  840. }elseif($receiptDetail['receiptClass']==3){
  841. $this->render ( "/receipt/feeInternalTrainEdi", $data );
  842. }else{
  843. $this->render ( "/admin/saea_edit", $data );
  844. //die ( 'illegal request-renderHtml' );
  845. }
  846. }
  847. function updateReceipt() {
  848. $agency = $this->get_args ( 'agency' );
  849. $travel = $this->get_args ( 'travel' );
  850. $train = $this->get_args ( 'train' );
  851. $other = $this->get_args ( 'other' );
  852. $inttrain = $this->get_args ( 'inttrain' );
  853. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  854. $itinerary = $_POST['itinerary'];
  855. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  856. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  857. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  858. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  859. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  860. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  861. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  862. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  863. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  864. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  865. Doo::loadClass ( 'XDeode' );
  866. $XDeode = new XDeode ( 7 );
  867. $rid = $XDeode->decode ( $ridKey );
  868. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  869. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  870. header ( 'Content-Type:text/html;charset=utf-8' );
  871. die ( '请填写联行号' );
  872. }
  873. Doo::loadModel ( 'receipt' );
  874. Doo::loadModel ( 'receiptDetail' );
  875. Doo::loadModel ( 'accountItem' );
  876. $accountItem = new accountItem ();
  877. $receipt = new receipt ();
  878. Doo::loadModel ( 'enclosur' );
  879. Doo::loadModel ( 'execute' );
  880. $execute = new execute ();
  881. $receiptDetail = $receipt->getOne ( array (
  882. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  883. 'asArray' => true
  884. ) );
  885. if (empty ( $receiptDetail )) {
  886. return "/saeaBorad";
  887. }
  888. //TODO 存储行程单-兼容旧版本的行程单
  889. $itinerary=str_replace('\n','<br/>',$itinerary);
  890. if(!empty($receiptDetail['itinerary2'])){
  891. $this->_storageItinerary($itinerary,$rid);
  892. }else{
  893. $this->_storageItinerary($itinerary,$rid,1);
  894. }
  895. if ($receiptDetail ['Rtype'] == 1) {
  896. $executeDetail = $execute->getOne ( array (
  897. 'where' => 'mold="借款费用执行人"',
  898. 'asArray' => true
  899. ) );
  900. } else {
  901. $executeDetail = $execute->getOne ( array (
  902. 'where' => 'mold="报销单执行人"',
  903. 'asArray' => true
  904. ) );
  905. }
  906. $aItem = $accountItem->find ( array (
  907. 'asArray' => true
  908. ) );
  909. $accountJson [$this->AGENCY] = $accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  910. $ag = $tr = $ta = $ot = $it = 0;
  911. $sum = $agencySum = $travelSum = $trainSum = $inttrainSum = $otherSum = 0;
  912. foreach ( $aItem as $key => $value ) {
  913. if ($value ['category'] == $this->AGENCY) {
  914. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  915. array_push ( $accountJson [$this->AGENCY], array (
  916. 'aid' => $value ['aid'],
  917. 'name' => $value ['name'],
  918. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  919. ) );
  920. $sum += $agency [$ag];
  921. $agencySum += $agency [$ag];
  922. }
  923. $ag ++;
  924. }
  925. if ($value ['category'] == $this->TRAVEL) {
  926. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  927. array_push ( $accountJson [$this->TRAVEL], array (
  928. 'aid' => $value ['aid'],
  929. 'name' => $value ['name'],
  930. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  931. ) );
  932. $sum += $travel [$tr];
  933. $travelSum += $travel [$tr];
  934. }
  935. $tr ++;
  936. }
  937. if ($value ['category'] == $this->TRAIN) {
  938. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  939. array_push ( $accountJson [$this->TRAIN], array (
  940. 'aid' => $value ['aid'],
  941. 'name' => $value ['name'],
  942. 'price' => number_format ( $train [$ta], 2, '.', '' )
  943. ) );
  944. $sum += $train [$ta];
  945. $trainSum += $train [$ta];
  946. }
  947. $ta ++;
  948. }
  949. if ($value ['category'] == $this->INTTRAIN) {
  950. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  951. array_push ( $accountJson [$this->INTTRAIN], array (
  952. 'aid' => $value ['aid'],
  953. 'name' => $value ['name'],
  954. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  955. ) );
  956. $sum += $inttrain [$it];
  957. $inttrainSum += $inttrain [$it];
  958. }
  959. $it ++;
  960. }
  961. if ($value ['category'] == $this->OTHER) {
  962. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  963. array_push ( $accountJson [$this->OTHER], array (
  964. 'aid' => $value ['aid'],
  965. 'name' => $value ['name'],
  966. 'price' => number_format ( $other [$ot], 2, '.', '' )
  967. ) );
  968. $sum += $other [$ot];
  969. $otherSum += $other [$ot];
  970. }
  971. $ot ++;
  972. }
  973. }
  974. $accountJson ['cSum'] = array (
  975. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  976. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  977. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  978. 'inttrainSum' => number_format ( $inttrainSum, 2, '.', '' ),
  979. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  980. );
  981. // 报销单
  982. $rid = $receipt->rid = $receiptDetail ['rid'];
  983. $receipt->accountItem = json_encode ( $accountJson );
  984. $receipt->staff = $this->staff [0] ['sid'];
  985. $receipt->sum = number_format ( $sum, 2, '.', '' );
  986. $receipt->date = date ( "Y-m-d" );
  987. $receipt->cid = $cid;
  988. if (($receiptDetail ['status'] != 4)) {
  989. if ($receiptDetail ['Rtype'] == 1) {
  990. $receipt->status = 7;
  991. } else {
  992. $receipt->status = 5;
  993. }
  994. }
  995. if ($receiptDetail != 4 && ! empty ( $verify ))
  996. $receipt->verify = $verify;
  997. $receipt->executeCopy = $executeDetail ['staff'];
  998. $order = array (
  999. "\r\n",
  1000. "\n",
  1001. "\r"
  1002. );
  1003. $replace = '<br/>';
  1004. $explanation = str_replace ( $order, $replace, $explanation );
  1005. $receipt->explanation = $explanation;
  1006. if($receiptClass=='trave'){
  1007. if(!empty($receiptDetail['itinerary2'])){//行程单版本
  1008. $receipt->itinerary2=$itinerary;
  1009. }else{
  1010. $receipt->itinerary=$itinerary;
  1011. }
  1012. }
  1013. $receipt->remittanceName = $remittanceName;
  1014. $receipt->bankName = $bankName;
  1015. $receipt->bankNumber = $bankNumber;
  1016. $receipt->remittanceBankType = $remittanceBankType;
  1017. if ($remittanceBankType == 1)
  1018. $receipt->coupletNumber = $coupletNumber;
  1019. $receipt->update ();
  1020. $receiptDetail = new receiptDetail ();
  1021. $receiptDetail->delete ( array (
  1022. 'where' => 'rid=' . $rid
  1023. ) );
  1024. // 报销详情
  1025. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1026. $receiptDetail = new receiptDetail ();
  1027. $receiptDetail->staff = $this->staff [0] ['sid'];
  1028. $receiptDetail->item = $value ['name'];
  1029. $receiptDetail->itemCategory = $this->AGENCY;
  1030. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1031. $receiptDetail->date = date ( "Y-m-d" );
  1032. $receiptDetail->cid = $cid;
  1033. $receiptDetail->rid = $rid;
  1034. $receiptDetail->status = 4;
  1035. $receiptDetail->insert ();
  1036. }
  1037. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1038. $receiptDetail = new receiptDetail ();
  1039. $receiptDetail->staff = $this->staff [0] ['sid'];
  1040. $receiptDetail->item = $value ['name'];
  1041. $receiptDetail->itemCategory = $this->TRAVEL;
  1042. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1043. $receiptDetail->date = date ( "Y-m-d" );
  1044. $receiptDetail->cid = $cid;
  1045. $receiptDetail->rid = $rid;
  1046. $receiptDetail->status = 4;
  1047. $receiptDetail->insert ();
  1048. }
  1049. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1050. $receiptDetail = new receiptDetail ();
  1051. $receiptDetail->staff = $this->staff [0] ['sid'];
  1052. $receiptDetail->item = $value ['name'];
  1053. $receiptDetail->itemCategory = $this->TRAIN;
  1054. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1055. $receiptDetail->date = date ( "Y-m-d" );
  1056. $receiptDetail->cid = $cid;
  1057. $receiptDetail->rid = $rid;
  1058. $receiptDetail->status = 4;
  1059. $receiptDetail->insert ();
  1060. }
  1061. // 内训
  1062. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1063. $receiptDetail = new receiptDetail ();
  1064. $receiptDetail->staff = $this->staff [0] ['sid'];
  1065. $receiptDetail->item = $value ['name'];
  1066. $receiptDetail->itemCategory = $this->INTTRAIN;
  1067. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1068. $receiptDetail->date = date ( "Y-m-d" );
  1069. $receiptDetail->cid = $cid;
  1070. $receiptDetail->rid = $rid;
  1071. $receiptDetail->status = 4;
  1072. $receiptDetail->insert ();
  1073. }
  1074. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1075. $receiptDetail = new receiptDetail ();
  1076. $receiptDetail->staff = $this->staff [0] ['sid'];
  1077. $receiptDetail->item = $value ['name'];
  1078. $receiptDetail->itemCategory = $this->OTHER;
  1079. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1080. $receiptDetail->date = date ( "Y-m-d" );
  1081. $receiptDetail->cid = $cid;
  1082. $receiptDetail->rid = $rid;
  1083. $receiptDetail->status = 4;
  1084. $receiptDetail->insert ();
  1085. }
  1086. // 附件
  1087. if (! empty ( $enclosurName )) {
  1088. $enclosurArray = explode ( '-', $enclosurName );
  1089. foreach ( $enclosurArray as $value ) {
  1090. $enclosur = new enclosur ();
  1091. $enclosur->name = $value;
  1092. $enclosur->rid = $rid;
  1093. $enclosur->insert ();
  1094. }
  1095. }
  1096. // return "/referReceipt/".$rid;
  1097. }
  1098. return "/saeaBorad";
  1099. }
  1100. function remitAdd() {
  1101. Doo::loadModel ( 'accountItem' );
  1102. Doo::loadModel ( 'verify' );
  1103. Doo::loadModel ( 'receipt' );
  1104. Doo::loadModel ( 'L_category' );
  1105. $lCategory = new L_category ();
  1106. $receipt = new receipt ();
  1107. $verify = new verify ();
  1108. $accountItem = new accountItem ();
  1109. Doo::loadModel ( "role" );
  1110. $role = new role ();
  1111. $acItem = $accountItem->find ( array (
  1112. 'asArray' => true
  1113. ) );
  1114. $veList = $verify->getVerifyBySubordinate('REMIT');
  1115. $data ['category'] = $lCategory->find ( array (
  1116. 'asArray' => true
  1117. ) );
  1118. $data ['veList'] = $veList;
  1119. $data ['acItem'] = $acItem;
  1120. $data ['memu'] = "receipt";
  1121. $data ['staff'] = $this->staff;
  1122. $data ['receiptMemu'] = 'saeaBorad';
  1123. $data ['verifyId'] = $this->verifyId;
  1124. $data ['executeId'] = $this->executeId;
  1125. $this->render ( "/admin/remitAdd", $data );
  1126. }
  1127. function remitAddDo() {
  1128. $agency = $this->get_args ( 'agency' );
  1129. $travel = $this->get_args ( 'travel' );
  1130. $train = $this->get_args ( 'train' );
  1131. $other = $this->get_args ( 'other' );
  1132. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1133. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1134. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1135. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1136. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1137. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1138. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1139. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1140. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1141. // print_r($agency);die;
  1142. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1143. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1144. header ( 'Content-Type:text/html;charset=utf-8' );
  1145. die ( '请填写联行号' );
  1146. }
  1147. Doo::loadModel ( 'receipt' );
  1148. Doo::loadModel ( 'receiptDetail' );
  1149. Doo::loadModel ( 'accountItem' );
  1150. $accountItem = new accountItem ();
  1151. $receipt = new receipt ();
  1152. Doo::loadModel ( 'enclosur' );
  1153. Doo::loadModel ( 'execute' );
  1154. $execute = new execute ();
  1155. $executeDetail = $execute->getOne ( array (
  1156. 'where' => 'mold="对公汇款执行人"',
  1157. 'asArray' => true
  1158. ) );
  1159. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  1160. $aItem = $accountItem->find ( array (
  1161. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  1162. 'asArray' => true
  1163. ) );
  1164. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1165. $ag = $tr = $ta = $ot = 0;
  1166. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1167. print_r($aItem);
  1168. foreach ( $aItem as $key => $value ) {
  1169. if ($value ['category'] == $this->AGENCY) {
  1170. if (isset ( $agency [$ag] )) {
  1171. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1172. array_push ( $accountJson [$this->AGENCY], array (
  1173. 'aid' => $value ['aid'],
  1174. 'name' => $value ['name'],
  1175. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1176. ) );
  1177. $sum += $agency [$ag];
  1178. $agencySum += $agency [$ag];
  1179. }
  1180. }
  1181. $ag ++;
  1182. }
  1183. }
  1184. $accountJson ['cSum'] = array (
  1185. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1186. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1187. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1188. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1189. );
  1190. //die;
  1191. // 报销单
  1192. $receipt->accountItem = json_encode ( $accountJson );
  1193. $receipt->staff = $this->staff [0] ['sid'];
  1194. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1195. $receipt->date = date ( "Y-m-d" );
  1196. $receipt->cid = $cid;
  1197. $receipt->status = 5;
  1198. $receipt->Rtype = 2;
  1199. // 修改审批流程加入角色
  1200. $receipt->verify = $verify;
  1201. $receipt->executeCopy = $executeDetail ['staff'];
  1202. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1203. $order = array (
  1204. "\r\n",
  1205. "\n",
  1206. "\r"
  1207. );
  1208. $replace = '<br/>';
  1209. $explanation = str_replace ( $order, $replace, $explanation );
  1210. $receipt->explanation = $explanation;
  1211. $receipt->remittanceName = $remittanceName;
  1212. $receipt->bankName = $bankName;
  1213. $receipt->bankNumber = $bankNumber;
  1214. $receipt->remittanceBankType = $remittanceBankType;
  1215. if ($remittanceBankType == 1)
  1216. $receipt->coupletNumber = $coupletNumber;
  1217. $rid = $receipt->insert ();
  1218. // 附件
  1219. if (! empty ( $enclosurName )) {
  1220. $enclosurArray = explode ( '-', $enclosurName );
  1221. foreach ( $enclosurArray as $value ) {
  1222. $enclosur = new enclosur ();
  1223. $enclosur->name = $value;
  1224. $enclosur->rid = $rid;
  1225. $enclosur->insert ();
  1226. }
  1227. // print_r($enclosurArray);die;
  1228. }
  1229. // 报销详情
  1230. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1231. $receiptDetail = new receiptDetail ();
  1232. $receiptDetail->staff = $this->staff [0] ['sid'];
  1233. $receiptDetail->item = $value ['name'];
  1234. $receiptDetail->itemCategory = $this->AGENCY;
  1235. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1236. $receiptDetail->date = date ( "Y-m-d" );
  1237. $receiptDetail->cid = $cid;
  1238. $receiptDetail->rid = $rid;
  1239. $receiptDetail->status = 4;
  1240. $receiptDetail->insert ();
  1241. }
  1242. return "/saeaBorad";
  1243. } else
  1244. die ( 'illegal request' );
  1245. }
  1246. function remitEdit() {
  1247. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1248. Doo::loadClass ( 'XDeode' );
  1249. $XDeode = new XDeode ( 7 );
  1250. $rid = $XDeode->decode ( $ridKey );
  1251. if (! is_numeric ( $rid ))
  1252. die ( 'illegal request' );
  1253. Doo::loadModel ( 'accountItem' );
  1254. Doo::loadModel ( 'verify' );
  1255. Doo::loadModel ( 'receipt' );
  1256. $receipt = new receipt ();
  1257. $verify = new verify ();
  1258. $accountItem = new accountItem ();
  1259. Doo::loadModel ( 'L_category' );
  1260. $lCategory = new L_category ();
  1261. Doo::loadModel ( "role" );
  1262. $role = new role ();
  1263. Doo::loadModel ( 'enclosur' );
  1264. $enclosur = new enclosur ();
  1265. $receiptDetail = $receipt->getOne ( array (
  1266. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  1267. 'asArray' => true
  1268. ) );
  1269. if (empty ( $receiptDetail ))
  1270. return "/saeaCreate";
  1271. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  1272. $acItem = $accountItem->find ( array (
  1273. 'asArray' => true
  1274. ) );
  1275. $veList = $verify->getVerifyBySubordinate('REMIT');
  1276. // 配置编辑信息
  1277. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1278. foreach ( $acItem as $key => $value ) {
  1279. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1280. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1281. $acItem [$key] ['price'] = $v ['price'];
  1282. }
  1283. }
  1284. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1285. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1286. $acItem [$key] ['price'] = $v ['price'];
  1287. }
  1288. }
  1289. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1290. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1291. $acItem [$key] ['price'] = $v ['price'];
  1292. }
  1293. }
  1294. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1295. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1296. $acItem [$key] ['price'] = $v ['price'];
  1297. }
  1298. }
  1299. }
  1300. $data ['category'] = $lCategory->find ( array (
  1301. 'asArray' => true
  1302. ) );
  1303. $data ['enclosurList'] = $enclosurList;
  1304. $data ['cSum'] = $accountItemList ['cSum'];
  1305. $data ['sum'] = $receiptDetail ['sum'];
  1306. $data ['receiptDetail'] = $receiptDetail;
  1307. $data ['veList'] = $veList;
  1308. $data ['acItem'] = $acItem;
  1309. $data ['memu'] = "receipt";
  1310. $data ['staff'] = $this->staff;
  1311. $data ['receiptMemu'] = 'saeaBorad';
  1312. $data ['verify'] = $receiptDetail ['verify'];
  1313. $data ['verifyId'] = $this->verifyId;
  1314. $data ['executeId'] = $this->executeId;
  1315. $data ['rid'] = $rid;
  1316. $data ['ridKey'] = $ridKey;
  1317. $this->render ( "/admin/remitEdit", $data );
  1318. }
  1319. function remitEdiDo() {
  1320. $agency = $this->get_args ( 'agency' );
  1321. $travel = $this->get_args ( 'travel' );
  1322. $train = $this->get_args ( 'train' );
  1323. $other = $this->get_args ( 'other' );
  1324. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1325. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1326. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1327. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1328. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1329. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1330. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1331. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1332. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1333. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1334. Doo::loadClass ( 'XDeode' );
  1335. $XDeode = new XDeode ( 7 );
  1336. $rid = $XDeode->decode ( $ridKey );
  1337. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1338. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1339. header ( 'Content-Type:text/html;charset=utf-8' );
  1340. die ( '请填写联行号' );
  1341. }
  1342. Doo::loadModel ( 'receipt' );
  1343. Doo::loadModel ( 'receiptDetail' );
  1344. Doo::loadModel ( 'accountItem' );
  1345. $accountItem = new accountItem ();
  1346. $receipt = new receipt ();
  1347. Doo::loadModel ( 'enclosur' );
  1348. $enclosur = new enclosur ();
  1349. Doo::loadModel ( 'execute' );
  1350. $execute = new execute ();
  1351. $executeDetail = $execute->getOne ( array (
  1352. 'where' => 'mold="对公汇款执行人"',
  1353. 'asArray' => true
  1354. ) );
  1355. $receiptDetail = $receipt->getOne ( array (
  1356. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  1357. 'asArray' => true
  1358. ) );
  1359. if (empty ( $receiptDetail ))
  1360. return "/saeaBorad";
  1361. $aItem = $accountItem->find ( array (
  1362. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  1363. 'asArray' => true
  1364. ) );
  1365. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1366. $ag = $tr = $ta = $ot = 0;
  1367. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1368. foreach ( $aItem as $key => $value ) {
  1369. if ($value ['category'] == $this->AGENCY) {
  1370. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1371. array_push ( $accountJson [$this->AGENCY], array (
  1372. 'aid' => $value ['aid'],
  1373. 'name' => $value ['name'],
  1374. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1375. ) );
  1376. $sum += $agency [$ag];
  1377. $agencySum += $agency [$ag];
  1378. }
  1379. $ag ++;
  1380. }
  1381. }
  1382. $accountJson ['cSum'] = array (
  1383. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1384. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1385. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1386. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1387. );
  1388. // 报销单
  1389. $rid = $receipt->rid = $receiptDetail ['rid'];
  1390. $receipt->accountItem = json_encode ( $accountJson );
  1391. $receipt->staff = $this->staff [0] ['sid'];
  1392. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1393. $receipt->date = date ( "Y-m-d" );
  1394. $receipt->cid = $cid;
  1395. if ($receiptDetail ['Rtype'] == 1)
  1396. $receipt->status = 7;
  1397. else
  1398. $receipt->status = 5;
  1399. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  1400. $receipt->verify = $verify;
  1401. $receipt->executeCopy = $executeDetail ['staff'];
  1402. $order = array (
  1403. "\r\n",
  1404. "\n",
  1405. "\r"
  1406. );
  1407. $replace = '<br/>';
  1408. $explanation = str_replace ( $order, $replace, $explanation );
  1409. $receipt->explanation = $explanation;
  1410. $receipt->remittanceName = $remittanceName;
  1411. $receipt->bankName = $bankName;
  1412. $receipt->bankNumber = $bankNumber;
  1413. $receipt->remittanceBankType = $remittanceBankType;
  1414. if ($remittanceBankType == 1)
  1415. $receipt->coupletNumber = $coupletNumber;
  1416. $receipt->update ();
  1417. $receiptDetail = new receiptDetail ();
  1418. $receiptDetail->delete ( array (
  1419. 'where' => 'rid=' . $rid
  1420. ) );
  1421. // 报销详情
  1422. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1423. $receiptDetail = new receiptDetail ();
  1424. $receiptDetail->staff = $this->staff [0] ['sid'];
  1425. $receiptDetail->item = $value ['name'];
  1426. $receiptDetail->itemCategory = $this->AGENCY;
  1427. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1428. $receiptDetail->date = date ( "Y-m-d" );
  1429. $receiptDetail->cid = $cid;
  1430. $receiptDetail->rid = $rid;
  1431. $receiptDetail->status = 4;
  1432. $receiptDetail->insert ();
  1433. }
  1434. // 附件
  1435. if (! empty ( $enclosurName )) {
  1436. $enclosurArray = explode ( '-', $enclosurName );
  1437. foreach ( $enclosurArray as $value ) {
  1438. $enclosur = new enclosur ();
  1439. $enclosur->name = $value;
  1440. $enclosur->rid = $rid;
  1441. $enclosur->insert ();
  1442. }
  1443. }
  1444. }
  1445. return "/saeaBorad";
  1446. }
  1447. function remitApproval() {
  1448. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1449. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  1450. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  1451. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  1452. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1453. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  1454. if (empty ( $status ))
  1455. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  1456. $vidList = array ();
  1457. $button = 0;
  1458. Doo::loadModel ( 'verify' );
  1459. Doo::loadModel ( 'receipt' );
  1460. Doo::loadModel ( 'staff' );
  1461. $staff = new staff ();
  1462. $receipt = new receipt ();
  1463. $verify = new verify ();
  1464. Doo::loadModel ( 'L_category' );
  1465. $Lcategory = new L_category ();
  1466. Doo::loadModel ( 'enclosur' );
  1467. $enclosur = new enclosur ();
  1468. // user verify ID
  1469. $verifyDetail = $verify->find ( array (
  1470. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  1471. 'asArray' => true
  1472. ) );
  1473. foreach ( $verifyDetail as $key => $value ) {
  1474. array_push ( $vidList, $value ['vid'] );
  1475. }
  1476. $vid = implode ( ",", $vidList );
  1477. if (empty ( $verifyDetail ))
  1478. $vid = 0;
  1479. $categoryList = $Lcategory->find ( array (
  1480. 'asArray' => true
  1481. ) );
  1482. $staffList = $staff->find ( array (
  1483. 'where' => 'cid=' . $cid,
  1484. 'asArray' => true
  1485. ) );
  1486. $ap = "";
  1487. if ($status == 4) {
  1488. $ap = 4;
  1489. $status = 2;
  1490. }
  1491. // get Receipt By verifyID status 2
  1492. $receiptList = $receipt->find ( array (
  1493. 'where' => 'rid =' . $rid . ' and status=2',
  1494. 'desc' => 'rid',
  1495. 'asArray' => true
  1496. ) );
  1497. if (empty ( $receiptList )) {
  1498. die ( 'illegal request' );
  1499. }
  1500. $Locate = 0;
  1501. $roleId = 0;
  1502. if ($ap == 4)
  1503. $status = 4;
  1504. foreach ( $receiptList as $key => $value ) {
  1505. $receiptList [$key] ['Locate'] = $Locate;
  1506. $Locate ++;
  1507. $receiptList [$key] ['reviseDetail'] = array ();
  1508. if (! empty ( $value ['reviseDetail'] ))
  1509. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1510. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1511. $categoryDetil = $Lcategory->getOne ( array (
  1512. 'where' => 'cid=' . $value ['cid'],
  1513. 'asArray' => true
  1514. ) );
  1515. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1516. // 检测编辑状态
  1517. $verifyList = $verify->getOne ( array (
  1518. 'where' => 'vid=' . $value ['verify'],
  1519. 'asArray' => true
  1520. ) );
  1521. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1522. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1523. Doo::loadModel ( 'role' );
  1524. $role = new role ();
  1525. // print_r($verifyList);
  1526. $flag = true;
  1527. $roleKey = 0;
  1528. $endStaffArray = array ();
  1529. $roleArrayCopy = array ();
  1530. foreach ( $verifyList as $k => $v ) {
  1531. // init verifyStaff
  1532. if ($v [1] == 'ROLE') {
  1533. if (! empty ( $verifyStaff )) {
  1534. $endStaffArray = end ( $verifyStaff );
  1535. if ($v [0] == $endStaffArray ['nextStaff']) {
  1536. $roleId = $v [0];
  1537. }
  1538. }
  1539. $roleVerify = json_decode ( $v [3], true );
  1540. $roleKey = $k;
  1541. $roleArray = array ();
  1542. $rolename = $role->getOne ( array (
  1543. 'where' => 'rid=' . $v [0],
  1544. 'asArray' => true
  1545. ) );
  1546. foreach ( $roleVerify as $o => $p ) {
  1547. $staffID = explode ( '_', $p );
  1548. $staffInfo = $staff->getOne ( array (
  1549. 'where' => 'sid=' . $staffID [0],
  1550. 'asArray' => true
  1551. ) );
  1552. // print_r($staffID);
  1553. $exp = array (
  1554. 0 => $staffInfo ['sid'],
  1555. 1 => $staffID [1],
  1556. 2 => $staffInfo ['avatar'],
  1557. 'date' => '',
  1558. 'date' => '',
  1559. 'opinion' => '',
  1560. 'status' => '',
  1561. 'rolename' => $rolename ['name']
  1562. );
  1563. array_push ( $roleArray, $exp );
  1564. }
  1565. $roleArrayCopy [$v [0]] = $roleArray;
  1566. // $verifyList[$k]['roleArray']=$roleArray;
  1567. }
  1568. // print_r($roleArray);
  1569. $verifyList [$k] ['date'] = "";
  1570. $verifyList [$k] ['opinion'] = "";
  1571. $verifyList [$k] ['status'] = "";
  1572. if (empty ( $verifyStaff )) {
  1573. $verifyList [$k] ['date'] = "";
  1574. $verifyList [$k] ['opinion'] = "";
  1575. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1576. $verifyList [$k] ['status'] = 4;
  1577. $button = 4;
  1578. $flag = false;
  1579. }
  1580. } else {
  1581. foreach ( $verifyStaff as $m => $u ) {
  1582. if ($v [0] == $m) {
  1583. $verifyList [$k] ['date'] = $u ['date'];
  1584. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1585. $verifyList [$k] ['status'] = $u ['status'];
  1586. $flag = false;
  1587. break;
  1588. }
  1589. }
  1590. $endStaffArray = end ( $verifyStaff );
  1591. if (isset ( $endStaffArray ['ROLE'] )) {
  1592. } else {
  1593. $endKey = key ( $verifyStaff );
  1594. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  1595. $button = 4;
  1596. $verifyList [$k] ['status'] = 4;
  1597. }
  1598. }
  1599. }
  1600. }
  1601. $rolename ['name'] = '';
  1602. if (! empty ( $roleId )) {
  1603. Doo::loadModel ( 'role' );
  1604. $role = new role ();
  1605. $rolename = $role->getOne ( array (
  1606. 'where' => 'rid=' . $roleId,
  1607. 'asArray' => true
  1608. ) );
  1609. }
  1610. if (! empty ( $verifyStaff ))
  1611. $endStaffArray = end ( $verifyStaff );
  1612. $KOP = false;
  1613. foreach ( $roleArrayCopy as $P => $A ) {
  1614. foreach ( $A as $MKI => $AVL ) {
  1615. if (! empty ( $verifyStaff )) {
  1616. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1617. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1618. $button = 4;
  1619. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1620. }
  1621. foreach ( $verifyStaff as $m => $u ) {
  1622. $AVLFK = $AVL [0] . '_R';
  1623. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1624. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1625. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1626. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1627. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1628. break;
  1629. }
  1630. }
  1631. } else {
  1632. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1633. $button = 4;
  1634. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1635. }
  1636. }
  1637. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1638. $KOP = true;
  1639. }
  1640. }
  1641. foreach ( $roleArrayCopy as $k => $v ) {
  1642. foreach ( $verifyList as $m => $n ) {
  1643. if ($n [0] == $k) {
  1644. array_splice ( $verifyList, $m, 1, $v );
  1645. }
  1646. }
  1647. }
  1648. $receiptList [$key] ['verifyList'] = $verifyList;
  1649. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1650. 'where' => 'sid=' . $value ['staff'],
  1651. 'asArray' => true
  1652. ) );
  1653. $receiptList [$key] ['button'] = $button;
  1654. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1655. }
  1656. $mothHtml = "";
  1657. for($i = 1; $i <= 12; $i ++) {
  1658. if ($month == $i)
  1659. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  1660. else
  1661. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  1662. }
  1663. // 获取审批日志
  1664. Doo::loadModel ( 'receiptLog' );
  1665. $receiptLog = new receiptLog ();
  1666. $rlList = array ();
  1667. $rlInfo = $receiptLog->getOne ( array (
  1668. 'where' => 'rid=' . $rid . ' and status=4',
  1669. 'asArray' => true
  1670. ) );
  1671. $tijdate = $receiptLog->getOne ( array (
  1672. 'where' => 'rid=' . $rid . ' and status=2',
  1673. 'asc' => 'rlid',
  1674. 'asArray' => true
  1675. ) );
  1676. if (! empty ( $rlInfo )) {
  1677. $rlList = $receiptLog->find ( array (
  1678. 'where' => 'rid=' . $rid,
  1679. 'asc' => 'rlid',
  1680. 'asArray' => true
  1681. ) );
  1682. }
  1683. $receiptList [0] ['rlList'] = $rlList;
  1684. $enclosurList = $enclosur->find ( array (
  1685. 'where' => 'rid=' . $rid,
  1686. 'asArray' => true
  1687. ) );
  1688. $enclosurHtml = '';
  1689. foreach ( $enclosurList as $value ) {
  1690. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  1691. }
  1692. // print_r($receiptList);
  1693. $data ['enclosurHtml'] = $enclosurHtml;
  1694. $data ['rolename'] = $rolename ['name'];
  1695. $data ['datetij'] = $tijdate ['date'];
  1696. $data ['mothHtml'] = $mothHtml;
  1697. $data ['rid'] = $rid;
  1698. $data ['receiptList'] = $receiptList;
  1699. $data ['receiptApprovalCount'] = count ( $receiptList );
  1700. $data ['status'] = $status;
  1701. $data ['year'] = $year;
  1702. $data ['categoryList'] = $categoryList;
  1703. $data ['staffList'] = $staffList;
  1704. $data ['cid'] = $cid;
  1705. $data ['sid'] = $sid;
  1706. $data ['ap'] = $ap;
  1707. $data ['memu'] = "receipt";
  1708. $data ['staff'] = $this->staff;
  1709. $data ['receiptMemu'] = 'approvalExpenses';
  1710. $data ['verifyId'] = $this->verifyId;
  1711. $data ['executeId'] = $this->executeId;
  1712. $this->render ( "/admin/remitApproval", $data );
  1713. }
  1714. function saeaLoanAdd() {
  1715. Doo::loadModel ( 'verify' );
  1716. $verify = new verify ();
  1717. Doo::loadModel ( "role" );
  1718. $role = new role ();
  1719. Doo::loadModel ( 'L_category' );
  1720. $lCategory = new L_category ();
  1721. $veList = $verify->getVerifyBySubordinate('LOAN');
  1722. $data ['category'] = $lCategory->find ( array (
  1723. 'asArray' => true
  1724. ) );
  1725. $data ['veList'] = $veList;
  1726. $data ['memu'] = "receipt";
  1727. $data ['staff'] = $this->staff;
  1728. $data ['receiptMemu'] = 'saeaBorad';
  1729. $data ['verifyId'] = $this->verifyId;
  1730. $data ['executeId'] = $this->executeId;
  1731. $this->render ( "/admin/saeaLoanAdd", $data );
  1732. }
  1733. function saeaLoanAddDo() {
  1734. $agency = $this->get_args ( 'agency' );
  1735. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1736. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1737. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1738. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1739. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1740. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1741. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1742. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1743. // die;
  1744. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1745. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1746. header ( 'Content-Type:text/html;charset=utf-8' );
  1747. die ( '请填写联行号' );
  1748. }
  1749. Doo::loadModel ( 'receipt' );
  1750. Doo::loadModel ( 'receiptDetail' );
  1751. Doo::loadModel ( 'accountItem' );
  1752. $accountItem = new accountItem ();
  1753. $receipt = new receipt ();
  1754. Doo::loadModel ( 'loanReceipt' );
  1755. $loanReceipt = new loanReceipt ();
  1756. Doo::loadModel ( 'execute' );
  1757. $execute = new execute ();
  1758. Doo::loadModel ( 'enclosur' );
  1759. $executeDetail = $execute->getOne ( array (
  1760. 'where' => 'mold="借款执行人"',
  1761. 'asArray' => true
  1762. ) );
  1763. $aItem = $accountItem->find ( array (
  1764. 'asArray' => true
  1765. ) );
  1766. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1767. $ag = $tr = $ta = $ot = 0;
  1768. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1769. array_push ( $accountJson ['借款费用'], array (
  1770. 'aid' => 0,
  1771. 'name' => '申请金额',
  1772. 'price' => number_format ( $agency, 2, '.', '' )
  1773. ) );
  1774. $sum += $agency;
  1775. $agencySum += $agency;
  1776. $accountJson ['cSum'] = array (
  1777. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1778. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1779. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1780. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1781. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1782. );
  1783. // 借款数据备份
  1784. $loanReceipt->loanItem = json_encode ( $accountJson );
  1785. $loanReceipt->staff = $this->staff [0] ['sid'];
  1786. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1787. $loanReceipt->date = date ( "Y-m-d" );
  1788. $loanReceipt->cid = $cid;
  1789. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1790. $loanReceipt->status = 5;
  1791. $loanReceipt->Rtype = 1;
  1792. $loanReceipt->verify = $verify;
  1793. $receipt->receiptOrder = $receipt->receiptOrder;
  1794. // 添加HTML换行符
  1795. // var_dump($explanation);
  1796. $order = array (
  1797. "\r\n",
  1798. "\n",
  1799. "\r"
  1800. );
  1801. $replace = '<br/>';
  1802. $explanation = str_replace ( $order, $replace, $explanation );
  1803. // $explanation=str_replace('\r',"<br/>",$explanation);
  1804. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  1805. $loanReceipt->explanation = $explanation;
  1806. $loanRid = $loanReceipt->insert ();
  1807. // 报销单
  1808. $receipt->loanItem = json_encode ( $accountJson );
  1809. $receipt->staff = $this->staff [0] ['sid'];
  1810. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1811. $receipt->date = date ( "Y-m-d" );
  1812. $receipt->cid = $cid;
  1813. // 特殊状态
  1814. $receipt->status = 5;
  1815. $receipt->Rtype = 1;
  1816. $receipt->loanRid = $loanRid;
  1817. // 修改审批流程加入角色
  1818. $receipt->verify = $verify;
  1819. $receipt->executeCopy = $executeDetail ['staff'];
  1820. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  1821. $receipt->explanation = $explanation;
  1822. $receipt->remittanceName = $remittanceName;
  1823. $receipt->bankName = $bankName;
  1824. $receipt->bankNumber = $bankNumber;
  1825. $receipt->remittanceBankType = $remittanceBankType;
  1826. if ($remittanceBankType == 1)
  1827. $receipt->coupletNumber = $coupletNumber;
  1828. $rid = $receipt->insert ();
  1829. return "/saeaBorad";
  1830. } else
  1831. die ( 'illegal request' );
  1832. }
  1833. function saeaLoanEdi() {
  1834. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1835. Doo::loadClass ( 'XDeode' );
  1836. $XDeode = new XDeode ( 7 );
  1837. $rid = $XDeode->decode ( $ridKey );
  1838. if (! is_numeric ( $rid ))
  1839. die ( 'illegal request' );
  1840. Doo::loadModel ( 'verify' );
  1841. $verify = new verify ();
  1842. Doo::loadModel ( "role" );
  1843. $role = new role ();
  1844. Doo::loadModel ( 'L_category' );
  1845. $lCategory = new L_category ();
  1846. Doo::loadModel ( 'receipt' );
  1847. $receipt = new receipt ();
  1848. $receiptInfo = $receipt->getOne ( array (
  1849. 'where' => 'rid=' . $rid,
  1850. 'asArray' => true
  1851. ) );
  1852. $veList = $verify->find ( array (
  1853. 'where'=>'subordinate like "%LOAN%"',
  1854. 'asArray' => true
  1855. ) );
  1856. foreach ( $veList as $key => $value ) {
  1857. $v = json_decode ( $value ['staff'] );
  1858. $list = array ();
  1859. foreach ( $v as $n => $m ) {
  1860. if ($m ['1'] == 'ROLE') {
  1861. $roleInfo = $role->getOne ( array (
  1862. 'where' => 'rid=' . $m [0],
  1863. 'asArray' => true
  1864. ) );
  1865. $v [$n] [1] = $roleInfo ['name'];
  1866. array_push ( $list, $roleInfo ['name'] );
  1867. } else {
  1868. array_push ( $list, $v [$n] [1] );
  1869. }
  1870. }
  1871. $veList [$key] ['staff'] = implode ( '>', $list );
  1872. }
  1873. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  1874. // print_r($receiptInfo);
  1875. $data ['receiptInfo'] = $receiptInfo;
  1876. $data ['category'] = $lCategory->find ( array (
  1877. 'asArray' => true
  1878. ) );
  1879. $data ['veList'] = $veList;
  1880. $data ['ridKey'] = $ridKey;
  1881. $data ['memu'] = "receipt";
  1882. $data ['staff'] = $this->staff;
  1883. $data ['receiptMemu'] = 'saeaBorad';
  1884. $data ['verifyId'] = $this->verifyId;
  1885. $data ['executeId'] = $this->executeId;
  1886. $this->render ( "/admin/saeaLoanEdi", $data );
  1887. }
  1888. function saeaLoanEdiDo() {
  1889. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1890. $agency = $this->get_args ( 'agency' );
  1891. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1892. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1893. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1894. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1895. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1896. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1897. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1898. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1899. // die;
  1900. Doo::loadClass ( 'XDeode' );
  1901. $XDeode = new XDeode ( 7 );
  1902. $rid = $XDeode->decode ( $ridKey );
  1903. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1904. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1905. header ( 'Content-Type:text/html;charset=utf-8' );
  1906. die ( '请填写联行号' );
  1907. }
  1908. Doo::loadModel ( 'receipt' );
  1909. Doo::loadModel ( 'receiptDetail' );
  1910. Doo::loadModel ( 'accountItem' );
  1911. $accountItem = new accountItem ();
  1912. $receipt = new receipt ();
  1913. Doo::loadModel ( 'loanReceipt' );
  1914. $loanReceipt = new loanReceipt ();
  1915. Doo::loadModel ( 'enclosur' );
  1916. Doo::loadModel ( 'execute' );
  1917. $execute = new execute ();
  1918. $executeDetail = $execute->getOne ( array (
  1919. 'where' => 'mold="借款执行人"',
  1920. 'asArray' => true
  1921. ) );
  1922. $receiptDetail = $receipt->getOne ( array (
  1923. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1924. 'asArray' => true
  1925. ) );
  1926. if (empty ( $receiptDetail ))
  1927. die ( '参数错误' );
  1928. $aItem = $accountItem->find ( array (
  1929. 'asArray' => true
  1930. ) );
  1931. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1932. $ag = $tr = $ta = $ot = 0;
  1933. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1934. array_push ( $accountJson ['借款费用'], array (
  1935. 'aid' => 0,
  1936. 'name' => '申请金额',
  1937. 'price' => number_format ( $agency, 2, '.', '' )
  1938. ) );
  1939. $sum += $agency;
  1940. $agencySum += $agency;
  1941. $accountJson ['cSum'] = array (
  1942. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1943. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1944. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1945. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1946. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1947. );
  1948. // 报销单
  1949. $receipt->loanItem = json_encode ( $accountJson );
  1950. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1951. $receipt->cid = $cid;
  1952. // 特殊状态
  1953. // 修改审批流程加入角色
  1954. if ($receiptDetail ['status'] != 4)
  1955. $receipt->verify = $verify;
  1956. $order = array (
  1957. "\r\n",
  1958. "\n",
  1959. "\r"
  1960. );
  1961. $replace = '<br/>';
  1962. $explanation = str_replace ( $order, $replace, $explanation );
  1963. $receipt->explanation = $explanation;
  1964. $receipt->remittanceName = $remittanceName;
  1965. $receipt->bankName = $bankName;
  1966. $receipt->bankNumber = $bankNumber;
  1967. $receipt->remittanceBankType = $remittanceBankType;
  1968. if ($remittanceBankType == 1)
  1969. $receipt->coupletNumber = $coupletNumber;
  1970. $receipt->update ( array (
  1971. 'where' => 'rid=' . $rid
  1972. ) );
  1973. // 借款数据更新
  1974. $loanReceipt->loanItem = json_encode ( $accountJson );
  1975. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1976. $loanReceipt->cid = $cid;
  1977. if ($receiptDetail ['status'] != 4)
  1978. $loanReceipt->verify = $verify;
  1979. $loanReceipt->explanation = $explanation;
  1980. $receipt->executeCopy = $executeDetail ['staff'];
  1981. $loanReceipt->update ( array (
  1982. 'where' => 'rid=' . $receiptDetail ['loanRid']
  1983. ) );
  1984. }
  1985. return "/saeaBorad";
  1986. }
  1987. function saeaLoanReceiptAdd() {
  1988. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1989. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  1990. Doo::loadModel ( 'receipt' );
  1991. $receipt = new receipt ();
  1992. Doo::loadModel ( 'loanReceipt' );
  1993. $loanReceipt = new loanReceipt ();
  1994. Doo::loadModel ( 'L_category' );
  1995. $Lcategory = new L_category ();
  1996. Doo::loadModel ( 'verify' );
  1997. Doo::loadModel ( 'statistics' );
  1998. $statistics = new statistics ();
  1999. $verify = new verify ();
  2000. Doo::loadModel ( 'staff' );
  2001. $staff = new staff ();
  2002. $receiptDetail = $receipt->getOne ( array (
  2003. 'where' => 'rid=' . $rid,
  2004. 'desc' => 'rid',
  2005. 'asArray' => true
  2006. ) );
  2007. $receiptList = $loanReceipt->find ( array (
  2008. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  2009. 'desc' => 'rid',
  2010. 'asArray' => true
  2011. ) );
  2012. $Locate = 0;
  2013. $roleId = 0;
  2014. $button = 0;
  2015. foreach ( $receiptList as $key => $value ) {
  2016. $receiptList [$key] ['Locate'] = $Locate;
  2017. $Locate ++;
  2018. $receiptList [$key] ['reviseDetail'] = array ();
  2019. if (! empty ( $value ['reviseDetail'] ))
  2020. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2021. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2022. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2023. $categoryDetil = $Lcategory->getOne ( array (
  2024. 'where' => 'cid=' . $value ['cid'],
  2025. 'asArray' => true
  2026. ) );
  2027. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2028. // 检测编辑状态
  2029. $verifyList = $verify->getOne ( array (
  2030. 'where' => 'vid=' . $value ['verify'],
  2031. 'asArray' => true
  2032. ) );
  2033. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2034. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2035. Doo::loadModel ( 'role' );
  2036. $role = new role ();
  2037. $flag = true;
  2038. $roleKey = 0;
  2039. $endStaffArray = array ();
  2040. $roleArrayCopy = array ();
  2041. foreach ( $verifyList as $k => $v ) {
  2042. // init verifyStaff
  2043. if ($v [1] == 'ROLE') {
  2044. if (! empty ( $verifyStaff )) {
  2045. $endStaffArray = end ( $verifyStaff );
  2046. // if ($v[0]==$endStaffArray['nextStaff']){
  2047. // $roleId=$v[0];
  2048. // }
  2049. }
  2050. $roleVerify = json_decode ( $v [3], true );
  2051. $roleKey = $k;
  2052. $roleArray = array ();
  2053. $rolename = $role->getOne ( array (
  2054. 'where' => 'rid=' . $v [0],
  2055. 'asArray' => true
  2056. ) );
  2057. foreach ( $roleVerify as $o => $p ) {
  2058. $staffID = explode ( '_', $p );
  2059. $staffInfo = $staff->getOne ( array (
  2060. 'where' => 'sid=' . $staffID [0],
  2061. 'asArray' => true
  2062. ) );
  2063. // print_r($staffID);
  2064. $exp = array (
  2065. 0 => $staffInfo ['sid'],
  2066. 1 => $staffID [1],
  2067. 2 => $staffInfo ['avatar'],
  2068. 'date' => '',
  2069. 'date' => '',
  2070. 'opinion' => '',
  2071. 'status' => '',
  2072. 'rolename' => $rolename ['name']
  2073. );
  2074. array_push ( $roleArray, $exp );
  2075. }
  2076. $roleArrayCopy [$v [0]] = $roleArray;
  2077. // $verifyList[$k]['roleArray']=$roleArray;
  2078. }
  2079. $verifyList [$k] ['date'] = "";
  2080. $verifyList [$k] ['opinion'] = "";
  2081. $verifyList [$k] ['status'] = "";
  2082. if (empty ( $verifyStaff )) {
  2083. $verifyList [$k] ['date'] = "";
  2084. $verifyList [$k] ['opinion'] = "";
  2085. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2086. $verifyList [$k] ['status'] = 4;
  2087. $flag = false;
  2088. }
  2089. } else {
  2090. foreach ( $verifyStaff as $m => $u ) {
  2091. if ($v [0] == $m) {
  2092. $verifyList [$k] ['date'] = $u ['date'];
  2093. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2094. $verifyList [$k] ['status'] = $u ['status'];
  2095. $flag = false;
  2096. break;
  2097. }
  2098. }
  2099. $endStaffArray = end ( $verifyStaff );
  2100. if (isset ( $endStaffArray ['ROLE'] )) {
  2101. } else {
  2102. // $endKey=key($verifyStaff);
  2103. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2104. // $button=4;
  2105. // $verifyList[$k]['status']=4;
  2106. // }
  2107. }
  2108. }
  2109. }
  2110. $rolename ['name'] = '';
  2111. if (! empty ( $roleId )) {
  2112. Doo::loadModel ( 'role' );
  2113. $role = new role ();
  2114. $rolename = $role->getOne ( array (
  2115. 'where' => 'rid=' . $roleId,
  2116. 'asArray' => true
  2117. ) );
  2118. }
  2119. if (! empty ( $verifyStaff ))
  2120. $endStaffArray = end ( $verifyStaff );
  2121. $KOP = false;
  2122. foreach ( $roleArrayCopy as $P => $A ) {
  2123. foreach ( $A as $MKI => $AVL ) {
  2124. if (! empty ( $verifyStaff )) {
  2125. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2126. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2127. $button = 4;
  2128. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2129. }
  2130. foreach ( $verifyStaff as $m => $u ) {
  2131. $AVLFK = $AVL [0] . '_R';
  2132. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2133. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2134. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2135. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2136. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2137. break;
  2138. }
  2139. }
  2140. } else {
  2141. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2142. $button = 4;
  2143. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2144. }
  2145. }
  2146. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2147. $KOP = true;
  2148. }
  2149. }
  2150. foreach ( $roleArrayCopy as $k => $v ) {
  2151. foreach ( $verifyList as $m => $n ) {
  2152. if ($n [0] == $k) {
  2153. array_splice ( $verifyList, $m, 1, $v );
  2154. }
  2155. }
  2156. }
  2157. $receiptList [$key] ['verifyList'] = $verifyList;
  2158. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2159. 'where' => 'sid=' . $value ['staff'],
  2160. 'asArray' => true
  2161. ) );
  2162. $receiptList [$key] ['button'] = $button;
  2163. //
  2164. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  2165. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2166. }
  2167. $data ['receiptList'] = $receiptList;
  2168. $data ['receiptDetail'] = $receiptDetail;
  2169. Doo::loadModel ( 'L_category' );
  2170. $lCategory = new L_category ();
  2171. Doo::loadModel ( 'accountItem' );
  2172. $accountItem = new accountItem ();
  2173. $acItem = $accountItem->find ( array (
  2174. 'asArray' => true
  2175. ) );
  2176. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  2177. $data ['rid'] = $rid;
  2178. $data ['category'] = $lCategory->find ( array (
  2179. 'asArray' => true
  2180. ) );
  2181. $data ['veList'] = $veList;
  2182. $data ['acItem'] = $acItem;
  2183. $data['itineraryDate']=$this->_itineraryDateMin();
  2184. $data ['memu'] = "receipt";
  2185. $data ['staff'] = $this->staff;
  2186. $data ['receiptMemu'] = 'saeaBorad';
  2187. $data ['verifyId'] = $this->verifyId;
  2188. $data ['executeId'] = $this->executeId;
  2189. $data['receiptClass']=$receiptClass;
  2190. if($receiptClass=='trave'){
  2191. $this->render ( "/receipt/feeLoanReceiptTrave", $data );
  2192. }else{
  2193. $this->render ( "/receipt/feeLoanReceipt", $data );
  2194. }
  2195. }
  2196. function saeaLoanReceiptAddDo() {
  2197. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  2198. $agency = $this->get_args ( 'agency' );
  2199. $travel = $this->get_args ( 'travel' );
  2200. $train = $this->get_args ( 'train' );
  2201. $other = $this->get_args ( 'other' );
  2202. $inttrain = $this->get_args ( 'inttrain' );
  2203. $itinerary = $_POST['itinerary'];//$this->get_args ( 'itinerary' ) ? $this->get_args ( 'itinerary' ) : "";
  2204. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  2205. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2206. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  2207. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  2208. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  2209. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2210. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2211. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2212. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2213. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2214. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  2215. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2216. header ( 'Content-Type:text/html;charset=utf-8' );
  2217. die ( '请填写联行号' );
  2218. }
  2219. if($receiptClass=='agency'){
  2220. $receiptClass=1;
  2221. }elseif($receiptClass=='trave'){
  2222. $receiptClass=2;
  2223. if($this->_verificationItinerary($itinerary)){
  2224. header ( 'Content-Type:text/html;charset=utf-8' );
  2225. die ( '已申请过类此日期的行程' );
  2226. }
  2227. }elseif($receiptClass=='internalTrain'){
  2228. $receiptClass=3;
  2229. }else{
  2230. header ( 'Content-Type:text/html;charset=utf-8' );
  2231. die ( '借款报销单分类不正确' );
  2232. }
  2233. Doo::loadModel ( 'receipt' );
  2234. Doo::loadModel ( 'receiptDetail' );
  2235. Doo::loadModel ( 'accountItem' );
  2236. $accountItem = new accountItem ();
  2237. $receipt = new receipt ();
  2238. Doo::loadModel ( 'enclosur' );
  2239. Doo::loadModel ( 'execute' );
  2240. $execute = new execute ();
  2241. $executeDetail = $execute->getOne ( array (
  2242. 'where' => 'mold="借款费用执行人"',
  2243. 'asArray' => true
  2244. ) );
  2245. $receiptDet = $receipt->getOne ( array (
  2246. 'where' => 'rid=' . $rid,
  2247. 'asArray' => true
  2248. ) );
  2249. // if(!empty($receiptDetail))
  2250. // return "/referReceipt/".$receiptDetail['rid'];
  2251. $aItem = $accountItem->find ( array (
  2252. 'asArray' => true
  2253. ) );
  2254. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2255. $ag = $tr = $ta = $ot =$it = 0;
  2256. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  2257. foreach ( $aItem as $key => $value ) {
  2258. if ($value ['category'] == $this->AGENCY) {
  2259. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  2260. array_push ( $accountJson [$this->AGENCY], array (
  2261. 'aid' => $value ['aid'],
  2262. 'name' => $value ['name'],
  2263. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  2264. ) );
  2265. $sum += $agency [$ag];
  2266. $agencySum += $agency [$ag];
  2267. }
  2268. $ag ++;
  2269. }
  2270. if ($value ['category'] == $this->TRAVEL) {
  2271. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  2272. array_push ( $accountJson [$this->TRAVEL], array (
  2273. 'aid' => $value ['aid'],
  2274. 'name' => $value ['name'],
  2275. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  2276. ) );
  2277. $sum += $travel [$tr];
  2278. $travelSum += $travel [$tr];
  2279. }
  2280. $tr ++;
  2281. }
  2282. if ($value ['category'] == $this->INTTRAIN) {
  2283. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  2284. array_push ( $accountJson [$this->INTTRAIN], array (
  2285. 'aid' => $value ['aid'],
  2286. 'name' => $value ['name'],
  2287. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  2288. ) );
  2289. $sum += $inttrain [$it];
  2290. $inttrainSum += $inttrain [$it];
  2291. }
  2292. $it ++;
  2293. }
  2294. if ($value ['category'] == $this->TRAIN) {
  2295. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  2296. array_push ( $accountJson [$this->TRAIN], array (
  2297. 'aid' => $value ['aid'],
  2298. 'name' => $value ['name'],
  2299. 'price' => number_format ( $train [$ta], 2, '.', '' )
  2300. ) );
  2301. $sum += $train [$ta];
  2302. $trainSum += $train [$ta];
  2303. }
  2304. $ta ++;
  2305. }
  2306. if ($value ['category'] == $this->OTHER) {
  2307. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  2308. array_push ( $accountJson [$this->OTHER], array (
  2309. 'aid' => $value ['aid'],
  2310. 'name' => $value ['name'],
  2311. 'price' => number_format ( $other [$ot], 2, '.', '' )
  2312. ) );
  2313. $sum += $other [$ot];
  2314. $otherSum += $other [$ot];
  2315. }
  2316. $ot ++;
  2317. }
  2318. }
  2319. $accountJson ['cSum'] = array (
  2320. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2321. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2322. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2323. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  2324. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2325. );
  2326. // 报销单
  2327. $receipt->accountItem = json_encode ( $accountJson );
  2328. $receipt->staff = $this->staff [0] ['sid'];
  2329. $receipt->loanSum = $receiptDet ['sum'];
  2330. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2331. $receipt->date = date ( "Y-m-d" );
  2332. $receipt->pastDate = '0000-00-00';
  2333. $receipt->cid = $cid;
  2334. $receipt->status = 7;
  2335. $receipt->receiptClass=$receiptClass;
  2336. if($receiptClass==2){
  2337. $receipt->itinerary=$itinerary;
  2338. $this->_storageItinerary($itinerary, $rid);
  2339. }
  2340. // 修改审批流程加入角色
  2341. $receipt->verify = $verify;
  2342. $receipt->verifyStaff = '';
  2343. $receipt->executeStaff = '';
  2344. $receipt->executeCopy = $executeDetail ['staff'];
  2345. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  2346. $receipt->explanation = $explanation;
  2347. $receipt->remittanceName = $remittanceName;
  2348. $receipt->bankName = $bankName;
  2349. $receipt->bankNumber = $bankNumber;
  2350. $receipt->remittanceBankType = $remittanceBankType;
  2351. if ($remittanceBankType == 1)
  2352. $receipt->coupletNumber = $coupletNumber;
  2353. $receipt->update ( array (
  2354. 'where' => 'rid=' . $rid
  2355. ) );
  2356. // 附件
  2357. if (! empty ( $enclosurName )) {
  2358. $enclosurArray = explode ( '-', $enclosurName );
  2359. foreach ( $enclosurArray as $value ) {
  2360. $enclosur = new enclosur ();
  2361. $enclosur->name = $value;
  2362. $enclosur->rid = $rid;
  2363. $enclosur->insert ();
  2364. }
  2365. // print_r($enclosurArray);die;
  2366. }
  2367. // 报销详情
  2368. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  2369. $receiptDetail = new receiptDetail ();
  2370. $receiptDetail->staff = $this->staff [0] ['sid'];
  2371. $receiptDetail->item = $value ['name'];
  2372. $receiptDetail->itemCategory = $this->AGENCY;
  2373. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2374. $receiptDetail->date = date ( "Y-m-d" );
  2375. $receiptDetail->cid = $cid;
  2376. $receiptDetail->rid = $rid;
  2377. $receiptDetail->status = 4;
  2378. $receiptDetail->insert ();
  2379. }
  2380. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  2381. $receiptDetail = new receiptDetail ();
  2382. $receiptDetail->staff = $this->staff [0] ['sid'];
  2383. $receiptDetail->item = $value ['name'];
  2384. $receiptDetail->itemCategory = $this->TRAVEL;
  2385. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2386. $receiptDetail->date = date ( "Y-m-d" );
  2387. $receiptDetail->cid = $cid;
  2388. $receiptDetail->rid = $rid;
  2389. $receiptDetail->status = 4;
  2390. $receiptDetail->insert ();
  2391. }
  2392. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  2393. $receiptDetail = new receiptDetail ();
  2394. $receiptDetail->staff = $this->staff [0] ['sid'];
  2395. $receiptDetail->item = $value ['name'];
  2396. $receiptDetail->itemCategory = $this->TRAIN;
  2397. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2398. $receiptDetail->date = date ( "Y-m-d" );
  2399. $receiptDetail->cid = $cid;
  2400. $receiptDetail->rid = $rid;
  2401. $receiptDetail->status = 4;
  2402. $receiptDetail->insert ();
  2403. }
  2404. //内训
  2405. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  2406. $receiptDetail = new receiptDetail ();
  2407. $receiptDetail->staff = $this->staff [0] ['sid'];
  2408. $receiptDetail->item = $value ['name'];
  2409. $receiptDetail->itemCategory = $this->INTTRAIN;
  2410. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2411. $receiptDetail->date = date ( "Y-m-d" );
  2412. $receiptDetail->cid = $cid;
  2413. $receiptDetail->rid = $rid;
  2414. $receiptDetail->status = 4;
  2415. $receiptDetail->insert ();
  2416. }
  2417. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  2418. $receiptDetail = new receiptDetail ();
  2419. $receiptDetail->staff = $this->staff [0] ['sid'];
  2420. $receiptDetail->item = $value ['name'];
  2421. $receiptDetail->itemCategory = $this->OTHER;
  2422. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2423. $receiptDetail->date = date ( "Y-m-d" );
  2424. $receiptDetail->cid = $cid;
  2425. $receiptDetail->rid = $rid;
  2426. $receiptDetail->status = 4;
  2427. $receiptDetail->insert ();
  2428. }
  2429. return "/saeaBorad";
  2430. }
  2431. return "/saeaLoanReceiptAdd/" . $rid;
  2432. }
  2433. function saeaLoanReceiptEdi() {
  2434. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2435. Doo::loadClass ( 'XDeode' );
  2436. $XDeode = new XDeode ( 7 );
  2437. $rid = $XDeode->decode ( $ridKey );
  2438. if (! is_numeric ( $rid ))
  2439. die ( 'illegal request' );
  2440. Doo::loadModel ( 'accountItem' );
  2441. Doo::loadModel ( 'verify' );
  2442. Doo::loadModel ( 'receipt' );
  2443. $receipt = new receipt ();
  2444. $verify = new verify ();
  2445. $accountItem = new accountItem ();
  2446. Doo::loadModel ( 'L_category' );
  2447. $Lcategory = new L_category ();
  2448. Doo::loadModel ( "role" );
  2449. $role = new role ();
  2450. Doo::loadModel ( 'loanReceipt' );
  2451. $loanReceipt = new loanReceipt ();
  2452. Doo::loadModel ( 'staff' );
  2453. $staff = new staff ();
  2454. $receiptDetail = $receipt->getOne ( array (
  2455. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  2456. 'asArray' => true
  2457. ) );
  2458. if (empty ( $receiptDetail ))
  2459. return "/saeaBorad";
  2460. $receiptList = $loanReceipt->find ( array (
  2461. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  2462. 'desc' => 'rid',
  2463. 'asArray' => true
  2464. ) );
  2465. $Locate = 0;
  2466. $roleId = 0;
  2467. $button = 0;
  2468. foreach ( $receiptList as $key => $value ) {
  2469. $receiptList [$key] ['Locate'] = $Locate;
  2470. $Locate ++;
  2471. $receiptList [$key] ['reviseDetail'] = array ();
  2472. if (! empty ( $value ['reviseDetail'] ))
  2473. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2474. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2475. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2476. $categoryDetil = $Lcategory->getOne ( array (
  2477. 'where' => 'cid=' . $value ['cid'],
  2478. 'asArray' => true
  2479. ) );
  2480. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2481. // 检测编辑状态
  2482. $verifyList = $verify->getOne ( array (
  2483. 'where' => 'vid=' . $value ['verify'],
  2484. 'asArray' => true
  2485. ) );
  2486. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2487. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2488. Doo::loadModel ( 'role' );
  2489. $role = new role ();
  2490. $flag = true;
  2491. $roleKey = 0;
  2492. $endStaffArray = array ();
  2493. $roleArrayCopy = array ();
  2494. foreach ( $verifyList as $k => $v ) {
  2495. // init verifyStaff
  2496. if ($v [1] == 'ROLE') {
  2497. if (! empty ( $verifyStaff )) {
  2498. $endStaffArray = end ( $verifyStaff );
  2499. // if ($v[0]==$endStaffArray['nextStaff']){
  2500. // $roleId=$v[0];
  2501. // }
  2502. }
  2503. $roleVerify = json_decode ( $v [3], true );
  2504. $roleKey = $k;
  2505. $roleArray = array ();
  2506. $rolename = $role->getOne ( array (
  2507. 'where' => 'rid=' . $v [0],
  2508. 'asArray' => true
  2509. ) );
  2510. foreach ( $roleVerify as $o => $p ) {
  2511. $staffID = explode ( '_', $p );
  2512. $staffInfo = $staff->getOne ( array (
  2513. 'where' => 'sid=' . $staffID [0],
  2514. 'asArray' => true
  2515. ) );
  2516. // print_r($staffID);
  2517. $exp = array (
  2518. 0 => $staffInfo ['sid'],
  2519. 1 => $staffID [1],
  2520. 2 => $staffInfo ['avatar'],
  2521. 'date' => '',
  2522. 'date' => '',
  2523. 'opinion' => '',
  2524. 'status' => '',
  2525. 'rolename' => $rolename ['name']
  2526. );
  2527. array_push ( $roleArray, $exp );
  2528. }
  2529. $roleArrayCopy [$v [0]] = $roleArray;
  2530. // $verifyList[$k]['roleArray']=$roleArray;
  2531. }
  2532. $verifyList [$k] ['date'] = "";
  2533. $verifyList [$k] ['opinion'] = "";
  2534. $verifyList [$k] ['status'] = "";
  2535. if (empty ( $verifyStaff )) {
  2536. $verifyList [$k] ['date'] = "";
  2537. $verifyList [$k] ['opinion'] = "";
  2538. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2539. $verifyList [$k] ['status'] = 4;
  2540. $flag = false;
  2541. }
  2542. } else {
  2543. foreach ( $verifyStaff as $m => $u ) {
  2544. if ($v [0] == $m) {
  2545. $verifyList [$k] ['date'] = $u ['date'];
  2546. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2547. $verifyList [$k] ['status'] = $u ['status'];
  2548. $flag = false;
  2549. break;
  2550. }
  2551. }
  2552. $endStaffArray = end ( $verifyStaff );
  2553. if (isset ( $endStaffArray ['ROLE'] )) {
  2554. } else {
  2555. // $endKey=key($verifyStaff);
  2556. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2557. // $button=4;
  2558. // $verifyList[$k]['status']=4;
  2559. // }
  2560. }
  2561. }
  2562. }
  2563. $rolename ['name'] = '';
  2564. if (! empty ( $roleId )) {
  2565. Doo::loadModel ( 'role' );
  2566. $role = new role ();
  2567. $rolename = $role->getOne ( array (
  2568. 'where' => 'rid=' . $roleId,
  2569. 'asArray' => true
  2570. ) );
  2571. }
  2572. if (! empty ( $verifyStaff ))
  2573. $endStaffArray = end ( $verifyStaff );
  2574. $KOP = false;
  2575. foreach ( $roleArrayCopy as $P => $A ) {
  2576. foreach ( $A as $MKI => $AVL ) {
  2577. if (! empty ( $verifyStaff )) {
  2578. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2579. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2580. $button = 4;
  2581. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2582. }
  2583. foreach ( $verifyStaff as $m => $u ) {
  2584. $AVLFK = $AVL [0] . '_R';
  2585. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2586. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2587. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2588. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2589. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2590. break;
  2591. }
  2592. }
  2593. } else {
  2594. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2595. $button = 4;
  2596. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2597. }
  2598. }
  2599. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2600. $KOP = true;
  2601. }
  2602. }
  2603. foreach ( $roleArrayCopy as $k => $v ) {
  2604. foreach ( $verifyList as $m => $n ) {
  2605. if ($n [0] == $k) {
  2606. array_splice ( $verifyList, $m, 1, $v );
  2607. }
  2608. }
  2609. }
  2610. $receiptList [$key] ['verifyList'] = $verifyList;
  2611. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2612. 'where' => 'sid=' . $value ['staff'],
  2613. 'asArray' => true
  2614. ) );
  2615. $receiptList [$key] ['button'] = $button;
  2616. //
  2617. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  2618. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2619. }
  2620. $data ['receiptList'] = $receiptList;
  2621. $acItem = $accountItem->find ( array (
  2622. 'asArray' => true
  2623. ) );
  2624. $veList = $verify->find ( array (
  2625. 'asArray' => true
  2626. ) );
  2627. foreach ( $veList as $key => $value ) {
  2628. $v = json_decode ( $value ['staff'] );
  2629. $list = array ();
  2630. foreach ( $v as $n => $m ) {
  2631. if ($m ['1'] == 'ROLE') {
  2632. $roleInfo = $role->getOne ( array (
  2633. 'where' => 'rid=' . $m [0],
  2634. 'asArray' => true
  2635. ) );
  2636. $v [$n] [1] = $roleInfo ['name'];
  2637. array_push ( $list, $roleInfo ['name'] );
  2638. } else {
  2639. array_push ( $list, $v [$n] [1] );
  2640. }
  2641. }
  2642. $veList [$key] ['staff'] = implode ( '>', $list );
  2643. }
  2644. // 配置编辑信息
  2645. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  2646. foreach ( $acItem as $key => $value ) {
  2647. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  2648. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  2649. $acItem [$key] ['price'] = $v ['price'];
  2650. }
  2651. }
  2652. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  2653. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2654. $acItem [$key] ['price'] = $v ['price'];
  2655. }
  2656. }
  2657. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  2658. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  2659. $acItem [$key] ['price'] = $v ['price'];
  2660. }
  2661. }
  2662. //内训
  2663. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  2664. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2665. $acItem [$key] ['price'] = $v ['price'];
  2666. }
  2667. }
  2668. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  2669. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  2670. $acItem [$key] ['price'] = $v ['price'];
  2671. }
  2672. }
  2673. }
  2674. $data ['category'] = $Lcategory->find ( array (
  2675. 'asArray' => true
  2676. ) );
  2677. $data ['ridKey'] = $ridKey;
  2678. $data ['cSum'] = $accountItemList ['cSum'];
  2679. $data ['sum'] = $receiptDetail ['sum'];
  2680. $data ['receiptDetail'] = $receiptDetail;
  2681. $data ['veList'] = $veList;
  2682. $data ['acItem'] = $acItem;
  2683. $data ['memu'] = "receipt";
  2684. $data ['staff'] = $this->staff;
  2685. $data ['receiptMemu'] = 'saeaBorad';
  2686. $data ['verify'] = $receiptDetail ['verify'];
  2687. $data ['verifyId'] = $this->verifyId;
  2688. $data ['executeId'] = $this->executeId;
  2689. $data ['rid'] = $rid;
  2690. if($receiptDetail['receiptClass']==1){
  2691. $this->render ( "/receipt/feeLoanReceiptAgencyEdi", $data );
  2692. }elseif($receiptDetail['receiptClass']==2){
  2693. $this->render ( "/receipt/feeLoanReceiptTraveEdi", $data );
  2694. }elseif($receiptDetail['receiptClass']==3){
  2695. $this->render ( "/receipt/feeLoanReceiptITEdi", $data );
  2696. }else{
  2697. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  2698. }
  2699. }
  2700. /**
  2701. * 培训班结算
  2702. */
  2703. function receiptTrainAdd() {
  2704. Doo::loadModel ( 'accountItem' );
  2705. $accountItem = new accountItem ();
  2706. $acItem = $accountItem->find ( array (
  2707. 'asArray' => true
  2708. ) );
  2709. // 审批组
  2710. Doo::loadModel ( 'verify' );
  2711. $verify = new verify ();
  2712. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2713. // 办事处
  2714. Doo::loadModel ( 'L_category' );
  2715. $lCategory = new L_category ();
  2716. $data ['category'] = $lCategory->getCategory ();
  2717. $data ['veList'] = $veList;
  2718. $data ['memu'] = "receipt";
  2719. $data ['staff'] = $this->staff;
  2720. $data ['acItem'] = $acItem;
  2721. $data ['receiptMemu'] = 'saeaBorad';
  2722. $data ['verifyId'] = $this->verifyId;
  2723. $data ['executeId'] = $this->executeId;
  2724. $this->render ( "/receipt/receiptTrainAdd", $data );
  2725. }
  2726. /**
  2727. * 添加培训班结算
  2728. */
  2729. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  2730. // 培训班信息
  2731. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2732. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2733. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2734. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2735. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  2736. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2737. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2738. // 发票信息
  2739. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2740. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2741. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2742. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2743. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2744. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2745. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2746. //&&! empty ( $participants )
  2747. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  2748. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2749. header ( 'Content-Type:text/html;charset=utf-8' );
  2750. die ( '请填写联行号' );
  2751. }
  2752. Doo::loadModel ( 'execute' );
  2753. $execute = new execute ();
  2754. $executeDetail = $execute->getOne ( array (
  2755. 'where' => 'mold="培训班结算"',
  2756. 'asArray' => true
  2757. ) );
  2758. if (empty ( $executeDetail )) {
  2759. header ( 'Content-Type:text/html;charset=utf-8' );
  2760. die ( '未设置执行人' );
  2761. }
  2762. Doo::loadClass ( 'XDeode' );
  2763. $XDeode = new XDeode ( 5 );
  2764. $cid = $XDeode->decode ( $cid );
  2765. Doo::loadModel ( 'receipt' );
  2766. $receipt = new receipt ();
  2767. Doo::loadModel ( 'receiptTraining' );
  2768. $receiptTraining = new receiptTraining ();
  2769. // 创建费用培训班
  2770. $item = array (
  2771. 'cid' => $this->staff [0] ['cid'],
  2772. 'categoryName' => $this->staff [0] ['category'],
  2773. 'trainName' => $trainName,
  2774. 'trainStartDate' => $trainStartDate,
  2775. 'trainEndDate' => $trainEndDate,
  2776. 'participants' => $participants,
  2777. 'freeParticipants'=>$freeParticipants,
  2778. 'trainAddress' => $trainAddress,
  2779. 'trainRemarks' => $trainRemarks,
  2780. 'creator' => $this->staff [0] ['sid'],
  2781. 'creatorDate' => date ( "Y-m-d H:i:s" )
  2782. );
  2783. $irid = $receiptTraining->addReceiptTraining ( $item );
  2784. // 报销单
  2785. $receipt->status = 5;
  2786. $receipt->trainId = $irid;
  2787. $receipt->Rtype = 3;
  2788. $receipt->staff = $this->staff [0] ['sid'];
  2789. $receipt->cid = $cid;
  2790. $receipt->verify = $verify;
  2791. $receipt->date = date ( "Y-m-d" );
  2792. $receipt->executeCopy = $executeDetail ['staff'];
  2793. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2794. $receipt->remittanceName = $remittanceName;
  2795. $receipt->bankName = $bankName;
  2796. $receipt->bankNumber = $bankNumber;
  2797. $receipt->remittanceBankType = $remittanceBankType;
  2798. if ($remittanceBankType == 1)
  2799. $receipt->coupletNumber = $coupletNumber;
  2800. $rid = $receipt->insert ();
  2801. $XDeode = new XDeode ( 7 );
  2802. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  2803. } else
  2804. die ( 'illegal request' );
  2805. }
  2806. /**
  2807. * 培训班编辑
  2808. */
  2809. function receiptTrainEdi() {
  2810. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2811. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  2812. Doo::loadClass ( 'XDeode' );
  2813. $XDeode = new XDeode ( 7 );
  2814. $rid = $XDeode->decode ( $ridKey );
  2815. if (! is_numeric ( $rid ))
  2816. die ( 'illegal request' );
  2817. Doo::loadModel ( 'receipt' );
  2818. $receipt = new receipt ();
  2819. Doo::loadModel ( 'receiptTraining' );
  2820. $receiptTraining = new receiptTraining ();
  2821. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2822. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  2823. die ('illegal request--status');
  2824. }
  2825. //如有已入账已收款的发票,自动取消办事处已收款
  2826. // Doo::loadModel ( 'RIExtend' );
  2827. // $RIExtend = new RIExtend ();
  2828. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  2829. // if (!empty($RIExtendList)){
  2830. // foreach ($RIExtendList as $key=>$value){
  2831. // $RIExtend = new RIExtend ();
  2832. // $RIExtend->delete(array (
  2833. // 'where' => 'iid=' . $value['iid'],
  2834. // 'limit' => 1
  2835. // ));
  2836. // }
  2837. // }
  2838. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2839. // 汇总表合计
  2840. // 收入合计--加入开票合计
  2841. Doo::loadModel ( 'invoiceTraining' );
  2842. $invoiceTraining = new invoiceTraining ();
  2843. $invoiceTrainingDetail = array (
  2844. 'invoiceArriveAmount' => 0,
  2845. 'RIAmount' => 0,
  2846. 'invoiceTotalAmount' => 0,
  2847. 'invoiceCompanyAmount'=>0
  2848. );
  2849. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2850. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2851. }
  2852. // print_r($invoiceTrainingDetail);
  2853. $invoiceArriveAmount = $RIAmount = 0;
  2854. if (! empty ( $invoiceTrainingDetail )) {
  2855. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  2856. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  2857. }
  2858. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2859. //print_r($invoiceTrainingDetail);
  2860. // 支出项目
  2861. Doo::loadModel ( 'accountItem' );
  2862. $accountItem = new accountItem ();
  2863. // 项目金额合计
  2864. Doo::loadModel ( 'RItem' );
  2865. $RItem = new RItem ();
  2866. // 讲师获得
  2867. Doo::loadModel ( 'RILecturer' );
  2868. $RILecturer = new RILecturer ();
  2869. $RItemList = $RItem->getRItemByRid ( $rid );
  2870. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2871. // 支出项金额详情
  2872. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  2873. // print_r($aiData);
  2874. // 利润
  2875. $profit=$invoiceArriveAmount - $aiData ['total'];
  2876. $companyProfit=$profit * 0.6;
  2877. $categoryProfit=$profit * 0.4;
  2878. $data ['profit'] = sprintf("%.2f",$profit);
  2879. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  2880. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  2881. //发票利润
  2882. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  2883. //发票公司利润
  2884. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  2885. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  2886. //办事处利润
  2887. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  2888. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  2889. // print_r($aiData['dataList']);
  2890. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  2891. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  2892. // 备用金
  2893. $sum = 0;
  2894. $data ['receiptLoanDetail'] = array (
  2895. 'sum' => '0.00'
  2896. );
  2897. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2898. //$data ['receiptLoanDetail'] = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2899. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2900. $sum=0;
  2901. foreach ($receiptLoanList as $key=>$value){
  2902. $sum+=$value['sum'];
  2903. }
  2904. $data ['receiptLoanDetail'] = array (
  2905. 'sum' => $sum
  2906. );
  2907. //$sum = $data ['receiptLoanDetail'] ['sum'];
  2908. }
  2909. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  2910. $data ['payment'] = sprintf("%.2f",$payment);
  2911. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  2912. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  2913. $data ['aiList'] = $aiData ['dataList'];
  2914. // 占比计算
  2915. if ($invoiceArriveAmount != 0) {
  2916. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  2917. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2918. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2919. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  2920. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  2921. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  2922. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  2923. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  2924. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  2925. } else {
  2926. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  2927. }
  2928. //发票金额占比计算
  2929. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  2930. //支出
  2931. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2932. //利润
  2933. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2934. //公司利润
  2935. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2936. //办事处利润
  2937. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2938. //公司收款
  2939. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2940. //备用金
  2941. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2942. //办事处收款
  2943. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2944. //办事处实际支出
  2945. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2946. //付总部款
  2947. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2948. }else{
  2949. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2950. }
  2951. //讲师人数
  2952. Doo::loadModel ( 'RILecturer' );
  2953. $RILecturer = new RILecturer ();
  2954. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2955. $data['lectureCount']=count($RILecturerList);
  2956. // 审批组
  2957. Doo::loadModel ( 'verify' );
  2958. $verify = new verify ();
  2959. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2960. // 办事处
  2961. Doo::loadModel ( 'L_category' );
  2962. $lCategory = new L_category ();
  2963. $data ['category'] = $lCategory->getCategory ();
  2964. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2965. $data ['receiptDetail'] = $receiptDetail;
  2966. $data ['veList'] = $veList;
  2967. $data ['trainEdiType'] = $trainEdiType;
  2968. $data ['ridKey'] = $ridKey;
  2969. $data ['memu'] = "receipt";
  2970. $data ['staff'] = $this->staff;
  2971. $data ['receiptMemu'] = 'saeaBorad';
  2972. $data ['verifyId'] = $this->verifyId;
  2973. $data ['executeId'] = $this->executeId;
  2974. $this->render ( "/receipt/receiptTrainEdi", $data );
  2975. }
  2976. /**
  2977. * 培训班借款编辑
  2978. */
  2979. function receiptTrainLoanEdi() {
  2980. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2981. Doo::loadClass ( 'XDeode' );
  2982. $XDeode = new XDeode ( 7 );
  2983. $rid = $XDeode->decode ( $ridKey );
  2984. if (! is_numeric ( $rid ))
  2985. die ( 'illegal request' );
  2986. Doo::loadModel ( 'receipt' );
  2987. $receipt = new receipt ();
  2988. Doo::loadModel ( 'receiptTraining' );
  2989. $receiptTraining = new receiptTraining ();
  2990. Doo::loadModel ( 'verify' );
  2991. $verify = new verify ();
  2992. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2993. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  2994. die ();
  2995. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2996. // 借款详情HTML
  2997. // 获得借款信息
  2998. $receiptLoanHtml = '';
  2999. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  3000. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  3001. foreach ($receiptLoanList as $key=>$value){
  3002. // 获得某费用单审批信息
  3003. $verifylist = $verify->getVerifyByRid ( $value ['rid'] );
  3004. Doo::loadClass ( 'receipt.func' );
  3005. $extendHtml = '<p><a class="button"
  3006. href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $value ['ridKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  3007. $receiptLoanHtml .= _getReceiptLoanHtml ( $value, $verifylist, $extendHtml );
  3008. }
  3009. }
  3010. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  3011. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3012. $data ['receiptDetail'] = $receiptDetail;
  3013. $data ['trainEdiType'] = "LOAN";
  3014. $data ['ridKey'] = $ridKey;
  3015. $data ['memu'] = "receipt";
  3016. $data ['staff'] = $this->staff;
  3017. $data ['receiptMemu'] = 'saeaBorad';
  3018. $data ['verifyId'] = $this->verifyId;
  3019. $data ['executeId'] = $this->executeId;
  3020. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  3021. }
  3022. /**
  3023. * 更新培训班结算基本信息
  3024. */
  3025. function receiptTrainInfoEdiDo() {
  3026. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  3027. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  3028. // 培训班信息
  3029. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  3030. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  3031. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  3032. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  3033. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  3034. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  3035. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  3036. // 发票信息
  3037. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  3038. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3039. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  3040. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3041. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  3042. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  3043. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  3044. //&& ! empty ( $participants )
  3045. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  3046. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  3047. header ( 'Content-Type:text/html;charset=utf-8' );
  3048. die ( '请填写联行号' );
  3049. }
  3050. Doo::loadClass ( 'XDeode' );
  3051. $XDeode = new XDeode ( 5 );
  3052. $cid = $XDeode->decode ( $cid );
  3053. $rtid = $XDeode->decode ( $rtid );
  3054. $rid = $XDeode->decode ( $rid );
  3055. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  3056. die ( 'illegal request-IdError' );
  3057. }
  3058. Doo::loadModel ( 'receipt' );
  3059. $receipt = new receipt ();
  3060. Doo::loadModel ( 'receiptTraining' );
  3061. $receiptTraining = new receiptTraining ();
  3062. // 更新费用培训班
  3063. $item = array (
  3064. 'rtid' => $rtid,
  3065. 'trainName' => $trainName,
  3066. 'trainStartDate' => $trainStartDate,
  3067. 'trainEndDate' => $trainEndDate,
  3068. 'participants' => $participants,
  3069. 'freeParticipants'=>$freeParticipants,
  3070. 'trainAddress' => $trainAddress,
  3071. 'trainRemarks' => $trainRemarks
  3072. );
  3073. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  3074. // 报销单
  3075. $receipt->rid = $rid;
  3076. $receipt->cid = $cid;
  3077. $receipt->verify = $verify;
  3078. $receipt->remittanceName = $remittanceName;
  3079. $receipt->bankName = $bankName;
  3080. $receipt->bankNumber = $bankNumber;
  3081. $receipt->remittanceBankType = $remittanceBankType;
  3082. if ($remittanceBankType == 1)
  3083. $receipt->coupletNumber = $coupletNumber;
  3084. $receipt->update ();
  3085. $XDeode = new XDeode ( 7 );
  3086. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  3087. } else
  3088. die ( 'illegal request' );
  3089. }
  3090. /**
  3091. * 编辑培训班结算---更新借款
  3092. */
  3093. function receiptTrainLoanEdiDo() {
  3094. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3095. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  3096. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  3097. Doo::loadModel ( 'receipt' );
  3098. $receipt = new receipt ();
  3099. Doo::loadClass ( 'XDeode' );
  3100. $XDeode = new XDeode ( 5 );
  3101. $rid = $XDeode->decode ( $ridKey );
  3102. $ridLoan = $XDeode->decode ( $ridLoanKey );
  3103. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  3104. die ( 'illegal request-ridError' );
  3105. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3106. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  3107. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3108. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3109. die ( 'illegal request-receiptError' );
  3110. }
  3111. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  3112. die ( 'illegal request-receipLoantError' );
  3113. }
  3114. // 培训班结算挂钩借款
  3115. $receipt = new receipt ();
  3116. $trainLoanRid=$ridLoan;
  3117. if (!empty($receiptDetail['trainLoanRid'])){
  3118. $trainLoanRid=$receiptDetail['trainLoanRid'].','.$ridLoan;
  3119. }
  3120. $item = array (
  3121. 'rid' => $rid,
  3122. 'trainLoanRid' => $trainLoanRid
  3123. );
  3124. $receipt->setReceiptByCondition ( $item );
  3125. // 更新借款状态变成已挂钩
  3126. $receipt = new receipt ();
  3127. $item = array (
  3128. 'rid' => $ridLoan,
  3129. 'status' => 10,
  3130. 'statusTrain' => 1
  3131. );
  3132. $receipt->setReceiptByCondition ( $item );
  3133. $XDeode = new XDeode ( 7 );
  3134. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  3135. } else
  3136. die ( 'illegal request' );
  3137. }
  3138. /**
  3139. * 编辑培训班结算--移除借款
  3140. */
  3141. function receiptTrainLoanRemoveDo() {
  3142. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  3143. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  3144. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  3145. Doo::loadModel ( 'receipt' );
  3146. $receipt = new receipt ();
  3147. Doo::loadClass ( 'XDeode' );
  3148. $XDeode = new XDeode ( 5 );
  3149. $rid = $XDeode->decode ( $ridKey );
  3150. $ridLoan = $XDeode->decode ( $ridLoanKey );
  3151. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  3152. die ( 'illegal request-ridError' );
  3153. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3154. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  3155. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  3156. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3157. die ( 'illegal request-receiptError' );
  3158. }
  3159. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  3160. die ( 'illegal request-receipLoantError' );
  3161. }
  3162. // 培训班结算挂钩借款
  3163. $receipt = new receipt ();
  3164. $trainLoanRidArray=explode(",", $receiptDetail['trainLoanRid']);
  3165. foreach ($trainLoanRidArray as $key=>$value){
  3166. if($value==$ridLoan){
  3167. unset($trainLoanRidArray[$key]);
  3168. }
  3169. }
  3170. $trainLoanRidString=implode(",", $trainLoanRidArray);
  3171. $item = array (
  3172. 'rid' => $rid,
  3173. 'trainLoanRid' => $trainLoanRidString
  3174. );
  3175. $receipt->setReceiptByCondition ( $item );
  3176. // 更新借款状态变成已挂钩
  3177. $receipt = new receipt ();
  3178. $item = array (
  3179. 'rid' => $ridLoan,
  3180. 'status' => 8,
  3181. 'statusTrain' => 0
  3182. );
  3183. $receipt->setReceiptByCondition ( $item );
  3184. $XDeode = new XDeode ( 7 );
  3185. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  3186. } else
  3187. die ( 'illegal request' );
  3188. }
  3189. /**
  3190. * 编辑培训班结算 ---开票
  3191. */
  3192. function receiptTrainInvoiceEdi() {
  3193. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3194. Doo::loadClass ( 'XDeode' );
  3195. $XDeode = new XDeode ( 7 );
  3196. $rid = $XDeode->decode ( $ridKey );
  3197. if (! is_numeric ( $rid ))
  3198. die ( 'illegal request' );
  3199. Doo::loadModel ( 'receipt' );
  3200. $receipt = new receipt ();
  3201. Doo::loadModel ( 'receiptTraining' );
  3202. $receiptTraining = new receiptTraining ();
  3203. Doo::loadModel ( 'invoice' );
  3204. $invoice = new invoice ();
  3205. Doo::loadModel ( 'invoiceTraining' );
  3206. $invoiceTraining = new invoiceTraining ();
  3207. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3208. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  3209. die ();
  3210. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3211. $invoiceList = $invoiceTrainingDetail = array ();
  3212. if ($receiptDetail ['invoiceTrainId'] != 0) {
  3213. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  3214. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  3215. }
  3216. //print_r($invoiceList);
  3217. $data ['invoiceList'] = $invoiceList;
  3218. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  3219. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3220. $data ['receiptDetail'] = $receiptDetail;
  3221. $data ['trainEdiType'] = "INVOICE";
  3222. $data ['ridKey'] = $ridKey;
  3223. $data ['memu'] = "receipt";
  3224. $data ['staff'] = $this->staff;
  3225. $data ['receiptMemu'] = 'saeaBorad';
  3226. $data ['verifyId'] = $this->verifyId;
  3227. $data ['executeId'] = $this->executeId;
  3228. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  3229. }
  3230. /**
  3231. * 编辑培训班结算---更新开票
  3232. */
  3233. function receiptTrainInvoiceEdiDo() {
  3234. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3235. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  3236. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  3237. Doo::loadModel ( 'receipt' );
  3238. $receipt = new receipt ();
  3239. Doo::loadModel ( 'invoiceTraining' );
  3240. $invoiceTraining = new invoiceTraining ();
  3241. Doo::loadClass ( 'XDeode' );
  3242. $XDeode = new XDeode ( 5 );
  3243. $rid = $XDeode->decode ( $ridKey );
  3244. $itid = $XDeode->decode ( $itidKey );
  3245. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  3246. die ( 'illegal request-idError' );
  3247. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3248. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  3249. // 不合法的数据
  3250. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3251. die ( 'illegal request-receiptError' );
  3252. }
  3253. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  3254. die ( 'illegal request-receipLoantError' );
  3255. }
  3256. // 培训班结算挂钩借款
  3257. $receipt = new receipt ();
  3258. $item = array (
  3259. 'rid' => $rid,
  3260. 'invoiceTrainId' => $itid
  3261. );
  3262. $receipt->setReceiptByCondition ( $item );
  3263. $invoiceTraining = new invoiceTraining ();
  3264. $item = array (
  3265. 'bindReceipt' => 1,
  3266. 'itid' => $itid
  3267. );
  3268. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3269. $XDeode = new XDeode ( 7 );
  3270. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  3271. } else
  3272. die ( 'illegal request' );
  3273. }
  3274. /**
  3275. * 更新培训班结算 收款和取消收款
  3276. */
  3277. function receiptTrainReceivables() {
  3278. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  3279. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3280. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3281. Doo::loadClass ( 'XDeode' );
  3282. $XDeode = new XDeode ( 5 );
  3283. $rid = $XDeode->decode ( $ridKey );
  3284. $iid = $XDeode->decode ( $iidKey );
  3285. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  3286. die ( 'illegal request-iid' );
  3287. Doo::loadModel ( 'RIExtend' );
  3288. $RIExtend = new RIExtend ();
  3289. if ($doType == 'CONFIRM') {
  3290. $RIExtend->rid = $rid;
  3291. $RIExtend->iid = $iid;
  3292. $RIExtend->RIstatus = 1;
  3293. $RIExtend->insert ();
  3294. echo json_encode ( array (
  3295. 'status' => 1,
  3296. ) );
  3297. die ( );
  3298. } elseif ($doType == 'CANCEL') {
  3299. $RIExtend->delete ( array (
  3300. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  3301. 'limit' => 1
  3302. ) );
  3303. echo json_encode ( array (
  3304. 'status' => 1,
  3305. ) );
  3306. die ( );
  3307. } else {
  3308. echo json_encode ( array (
  3309. 'status' => 2,
  3310. ) );
  3311. die ( );
  3312. }
  3313. }
  3314. /**
  3315. * 移除挂钩的培训班发票
  3316. */
  3317. function receiptTrainReceivablesDelDo() {
  3318. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3319. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  3320. Doo::loadModel ( 'receipt' );
  3321. $receipt = new receipt ();
  3322. Doo::loadModel ( 'RIExtend' );
  3323. $RIExtend = new RIExtend ();
  3324. Doo::loadClass ( 'XDeode' );
  3325. $XDeode = new XDeode ( 5 );
  3326. $rid = $XDeode->decode ( $ridKey );
  3327. $itid = $XDeode->decode ( $itidKey );
  3328. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  3329. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3330. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3331. die ( 'illegal request-status' );
  3332. }
  3333. $receipt = new receipt ();
  3334. $receipt->rid = $rid;
  3335. $receipt->invoiceTrainId = 0;
  3336. $receipt->update ();
  3337. Doo::loadModel ( 'invoiceTraining' );
  3338. $invoiceTraining = new invoiceTraining ();
  3339. $item = array (
  3340. 'bindReceipt' => 0,
  3341. 'itid' => $itid
  3342. );
  3343. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3344. $RIExtend->delete ( array (
  3345. 'where' => 'rid=' . $rid
  3346. ) );
  3347. $XDeode = new XDeode ( 7 );
  3348. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  3349. } else
  3350. die ( 'illegal request-iid' );
  3351. }
  3352. /**
  3353. * 编辑培训班结算
  3354. */
  3355. function receiptTrainItemEdi() {
  3356. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3357. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3358. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  3359. Doo::loadClass ( 'XDeode' );
  3360. $XDeode = new XDeode ( 7 );
  3361. $rid = $XDeode->decode ( $ridKey );
  3362. if (! is_numeric ( $rid ))
  3363. die ( 'illegal request' );
  3364. Doo::loadModel ( 'receipt' );
  3365. $receipt = new receipt ();
  3366. Doo::loadModel ( 'receiptTraining' );
  3367. $receiptTraining = new receiptTraining ();
  3368. Doo::loadModel ( 'RItem' );
  3369. $RItem = new RItem ();
  3370. Doo::loadModel ( 'accountItem' );
  3371. $accountItem = new accountItem ();
  3372. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3373. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3374. die ();
  3375. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3376. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  3377. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  3378. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  3379. // if($value['name']=='税款'){
  3380. // unset($aiList[$key]);break;
  3381. // }
  3382. // }
  3383. //print_r($RItemList);
  3384. $data ['name'] = $name;
  3385. $data ['RItemList'] = $RItemList;
  3386. $data ['aiList'] = $aiList;
  3387. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3388. $data ['receiptDetail'] = $receiptDetail;
  3389. $data ['trainEdiType'] = "ITEM";
  3390. $data ['ridKey'] = $ridKey;
  3391. $data ['memu'] = "receipt";
  3392. $data ['staff'] = $this->staff;
  3393. $data ['receiptMemu'] = 'saeaBorad';
  3394. $data ['verifyId'] = $this->verifyId;
  3395. $data ['executeId'] = $this->executeId;
  3396. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  3397. }
  3398. /**
  3399. * 添加支出项 需要修改 费用金额合计
  3400. */
  3401. function receiptTrainItemAddDo() {
  3402. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3403. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  3404. // 支出项信息
  3405. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3406. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  3407. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3408. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  3409. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  3410. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  3411. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  3412. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  3413. Doo::loadClass ( 'XDeode' );
  3414. $XDeode = new XDeode ( 5 );
  3415. Doo::loadModel ( 'RItem' );
  3416. $RItem = new RItem ();
  3417. $rid = $XDeode->decode ( $ridKey );
  3418. $rtid= $XDeode->decode ( $rtidKey );
  3419. if (! is_numeric ( $rid )){
  3420. die ( 'illegal request' );
  3421. }
  3422. Doo::loadModel ( 'receiptDetail' );
  3423. $receiptDetail = new receiptDetail ();
  3424. Doo::loadModel ( 'receipt' );
  3425. $receipt = new receipt ();
  3426. Doo::loadModel ( 'receiptTraining' );
  3427. $receiptTraining = new receiptTraining ();
  3428. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  3429. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  3430. $order = array (
  3431. "\r\n",
  3432. "\n",
  3433. "\r"
  3434. );
  3435. $replace = '<br/>';
  3436. $describe = str_replace ( $order, $replace, $describe );
  3437. $itemData = array (
  3438. 'rid' => $rid,
  3439. 'item' => $item,
  3440. 'price' => $price,
  3441. 'date' => $date,
  3442. 'inputer' => $inputer,
  3443. 'describe' => $describe,
  3444. 'creater' => $this->staff['0']['username'],
  3445. 'createrId' => $this->staff['0']['sid'],
  3446. 'creatDate' => date ( "Y-m-d H:i:s" ),
  3447. 'identifying'=>$identifyingTotal
  3448. );
  3449. if($payType=='company'){
  3450. $itemData += array (
  3451. 'payType' => 1
  3452. );
  3453. }
  3454. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  3455. //更新支出项标识总数
  3456. $itemData = array (
  3457. 'rtid'=>$rtid,
  3458. 'identifyingTotal'=>$identifyingTotal
  3459. );
  3460. $receiptTraining->setReceiptTrainByCondition($itemData);
  3461. $XDeode = new XDeode ( 7 );
  3462. if($payType=='company'){
  3463. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  3464. }else{
  3465. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  3466. }
  3467. } else
  3468. die ( 'illegal request-dataError' );
  3469. }
  3470. /**
  3471. * 培训班结算-讲师
  3472. */
  3473. function receiptTrainLecturerEdi() {
  3474. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3475. Doo::loadClass ( 'XDeode' );
  3476. $XDeode = new XDeode ( 7 );
  3477. $rid = $XDeode->decode ( $ridKey );
  3478. if (! is_numeric ( $rid ))
  3479. die ( 'illegal request' );
  3480. Doo::loadModel ( 'receipt' );
  3481. $receipt = new receipt ();
  3482. Doo::loadModel ( 'receiptTraining' );
  3483. $receiptTraining = new receiptTraining ();
  3484. Doo::loadModel ( 'RILecturer' );
  3485. $RILecturer = new RILecturer ();
  3486. Doo::loadModel ( 'lecturer' );
  3487. $lecturer = new lecturer ();
  3488. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3489. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3490. die ();
  3491. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3492. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3493. $lecturerList = $lecturer->getLecturerAll ();
  3494. $INSIDEhtml = $OUTSIDEhtml = '';
  3495. foreach ( $lecturerList as $key => $value ) {
  3496. if ($value ['ltype'] == 'INSIDE') {
  3497. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  3498. } elseif ($value ['ltype'] == 'OUTSIDE') {
  3499. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  3500. }
  3501. }
  3502. $data ['INSIDEhtml'] = $INSIDEhtml;
  3503. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  3504. // print_r($RItemList);
  3505. $data ['RILecturerList'] = $RILecturerList;
  3506. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3507. $data ['receiptDetail'] = $receiptDetail;
  3508. $data ['trainEdiType'] = "LECTURER";
  3509. $data ['ridKey'] = $ridKey;
  3510. $data ['memu'] = "receipt";
  3511. $data ['staff'] = $this->staff;
  3512. $data ['receiptMemu'] = 'saeaBorad';
  3513. $data ['verifyId'] = $this->verifyId;
  3514. $data ['executeId'] = $this->executeId;
  3515. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  3516. }
  3517. /**
  3518. * 添加讲师
  3519. */
  3520. function receiptTrainLecturerAddDo() {
  3521. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3522. // 支出项信息
  3523. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  3524. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  3525. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  3526. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  3527. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  3528. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  3529. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  3530. Doo::loadClass ( 'XDeode' );
  3531. $XDeode = new XDeode ( 5 );
  3532. Doo::loadModel ( 'RILecturer' );
  3533. $RILecturer = new RILecturer ();
  3534. $rid = $XDeode->decode ( $ridKey );
  3535. if (! is_numeric ( $rid ))
  3536. die ( 'illegal request' );
  3537. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  3538. die ( 'illegal request-taxationError' );
  3539. $RILecturer->rid = $rid;
  3540. $RILecturer->ltype = $ltype;
  3541. if ($ltype == 'OUTSIDE') {
  3542. if ($taxation == 'TAXATION') {
  3543. $RILecturer->taxation = 1;
  3544. } elseif ($taxation == 'NOTAXATION') {
  3545. $RILecturer->taxation = 0;
  3546. }
  3547. }
  3548. $RILecturer->lecturerName = $lecturerName;
  3549. $RILecturer->schoolDay = $schoolDay;
  3550. $RILecturer->price = $price;
  3551. $RILecturer->fees=$fees;
  3552. $RILecturer->insert ();
  3553. // 添加公司汇总
  3554. // 报销详情
  3555. Doo::loadModel ( 'receiptDetail' );
  3556. $receiptDetail = new receiptDetail ();
  3557. Doo::loadModel ( 'receipt' );
  3558. $receipt = new receipt ();
  3559. // 金额总计
  3560. $price = $price * $schoolDay;
  3561. $rInfo = $receipt->getReceiptByRid ( $rid );
  3562. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3563. if (empty ( $rdInfo )) {
  3564. $receiptDetail = new receiptDetail ();
  3565. $receiptDetail->staff = $rInfo ['staff'];
  3566. $receiptDetail->item = '讲课费';
  3567. $receiptDetail->itemCategory = '培训班费用';
  3568. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  3569. $receiptDetail->date = date ( "Y-m-d" );
  3570. $receiptDetail->cid = $rInfo ['cid'];
  3571. $receiptDetail->rid = $rid;
  3572. $receiptDetail->status = 4;
  3573. $receiptDetail->insert ();
  3574. } else {
  3575. $receiptDetail = new receiptDetail ();
  3576. $rdInfo ['price'] += $fees;
  3577. $receiptDetail->price = $rdInfo ['price'];
  3578. $receiptDetail->update ( array (
  3579. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3580. ) );
  3581. }
  3582. $receipt = new receipt ();
  3583. $receipt->sum=$rInfo['sum']+$fees;
  3584. $receipt->update ( array (
  3585. 'where' => 'rid=' . $rid
  3586. ) );
  3587. $XDeode = new XDeode ( 7 );
  3588. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3589. } else
  3590. die ( 'illegal request' );
  3591. }
  3592. /**
  3593. * 移除讲师
  3594. */
  3595. function receiptTrainLecturerDelDo() {
  3596. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3597. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  3598. Doo::loadModel ( 'receipt' );
  3599. $receipt = new receipt ();
  3600. Doo::loadModel ( 'RILecturer' );
  3601. $RILecturer = new RILecturer ();
  3602. Doo::loadClass ( 'XDeode' );
  3603. $XDeode = new XDeode ( 5 );
  3604. $rid = $XDeode->decode ( $ridKey );
  3605. $rlid = $XDeode->decode ( $rlidKey );
  3606. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  3607. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3608. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3609. die ( 'illegal request-status' );
  3610. }
  3611. $detail=$RILecturer->getRILecturerByRlid($rlid);
  3612. if (empty($detail)){
  3613. die ( 'illegal request-data' );
  3614. }
  3615. $RILecturer->delete ( array (
  3616. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  3617. ) );
  3618. //更新费用合计金额
  3619. $rInfo = $receipt->getReceiptByRid ( $rid );
  3620. $receipt = new receipt ();
  3621. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  3622. $receipt->update ( array (
  3623. 'where' => 'rid=' . $rid
  3624. ) );
  3625. Doo::loadModel ( 'receiptDetail' );
  3626. $receiptDetail = new receiptDetail ();
  3627. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3628. $receiptDetail = new receiptDetail ();
  3629. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  3630. $receiptDetail->price = $rdInfo ['price'];
  3631. $receiptDetail->update ( array (
  3632. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3633. ) );
  3634. $XDeode = new XDeode ( 7 );
  3635. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3636. } else
  3637. die ( 'illegal request-iid' );
  3638. }
  3639. /**
  3640. * 培训班提交审批
  3641. */
  3642. function receiptTrainDo() {
  3643. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3644. Doo::loadClass ( 'XDeode' );
  3645. $XDeode = new XDeode ( 7 );
  3646. $rid = $XDeode->decode ( $ridKey );
  3647. Doo::loadModel ( 'receipt' );
  3648. $receipt = new receipt ();
  3649. Doo::loadModel ( 'receiptDetail' );
  3650. $receiptDetail = new receiptDetail ();
  3651. Doo::loadModel ( 'statistics' );
  3652. $statistics = new statistics ();
  3653. Doo::loadModel ( "verify" );
  3654. $verify = new verify ();
  3655. // 审批状态的判定
  3656. $receiptDetailList = $receipt->getOne ( array (
  3657. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  3658. 'asArray' => true
  3659. ) );
  3660. if (empty ( $receiptDetailList ))
  3661. return "/saeaBorad";
  3662. $verifyDetail = $verify->getOne ( array (
  3663. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3664. 'asArray' => true
  3665. ) );
  3666. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3667. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3668. $nowStaff = "";
  3669. $nowStaffList = array ();
  3670. if ($verifyDetail [0] [1] == 'ROLE') {
  3671. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3672. foreach ( $vStaffString as $key => $value ) {
  3673. $staffK = explode ( "_", $value );
  3674. array_push ( $nowStaffList, $staffK [0] );
  3675. }
  3676. $nowStaff = implode ( ',', $nowStaffList );
  3677. } else {
  3678. $nowStaff = $verifyDetail [0] [0];
  3679. }
  3680. $receipt->nowStaff = $nowStaff;
  3681. }
  3682. // echo $nowStaff;
  3683. // print_r($verifyDetail);die;
  3684. $receipt->rid = $receiptDetailList ['rid'];
  3685. $receipt->date = date ( "Y-m-d" );
  3686. $receipt->status = 2;
  3687. $receipt->update ();
  3688. $receiptDetail->status = 2;
  3689. $receiptDetail->update ( array (
  3690. 'where' => 'rid=' . $receiptDetailList ['rid']
  3691. ) );
  3692. Doo::loadModel ( "receiptLog" );
  3693. $receiptLog = new receiptLog ();
  3694. Doo::loadModel ( "verify" );
  3695. $verify = new verify ();
  3696. $vr = $verify->getOne ( array (
  3697. 'where' => 'vid=' . $receiptDetailList ['verify'],
  3698. 'asArray' => true
  3699. ) );
  3700. $jd = json_decode ( $vr ['staff'] );
  3701. $roleId = 0;
  3702. foreach ( $jd as $key => $value ) {
  3703. if ($value [1] == 'ROLE') {
  3704. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3705. if ($pos !== false) {
  3706. $roleId = $value [0];
  3707. }
  3708. }
  3709. }
  3710. // 审批日志
  3711. // echo $roleId;die;
  3712. if (! empty ( $roleId )) {
  3713. Doo::loadModel ( "role" );
  3714. $role = new role ();
  3715. $roleInfo = $role->getOne ( array (
  3716. 'where' => 'rid=' . $roleId,
  3717. 'asArray' => true
  3718. ) );
  3719. // $receiptLog->rolename = $roleInfo ['name'];
  3720. }
  3721. $receiptLog->username = $this->staff [0] ['username'];
  3722. $receiptLog->uid = $this->staff [0] ['sid'];
  3723. $receiptLog->date = date ( "Y-m-d" );
  3724. $receiptLog->opinion = '提交审批';
  3725. $receiptLog->img = $this->staff [0] ['avatar'];
  3726. $receiptLog->status = 2;
  3727. $receiptLog->rid = $rid;
  3728. $receiptLog->insert ();
  3729. // 写入列表项
  3730. Doo::loadModel ( 'accountItem' );
  3731. $accountItem = new accountItem ();
  3732. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  3733. // 项目金额合计
  3734. Doo::loadModel ( 'RItem' );
  3735. $RItem = new RItem ();
  3736. // 讲师获得
  3737. Doo::loadModel ( 'RILecturer' );
  3738. $RILecturer = new RILecturer ();
  3739. $RItemList = $RItem->getRItemByRid ( $rid );
  3740. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3741. // 支出项金额详情
  3742. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  3743. // print_r($aItem);
  3744. // print_r($aiData);
  3745. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  3746. $ag = $tr = $ta = $ot = 0;
  3747. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  3748. foreach ( $aItem as $key => $value ) {
  3749. if ($value ['category'] == $this->TRAIN) {
  3750. foreach ( $aiData ['dataList'] as $k => $v ) {
  3751. if ($value ['name'] == $v ['name']) {
  3752. array_push ( $accountJson [$this->TRAIN], array (
  3753. 'aid' => $value ['aid'],
  3754. 'name' => $value ['name'],
  3755. 'price' => number_format ( $v ['price'], 2, '.', '' )
  3756. ) );
  3757. $sum += $v ['price'];
  3758. $trainSum += $v ['price'];
  3759. unset ( $aiData ['dataList'] [$k] );
  3760. break;
  3761. }
  3762. }
  3763. }
  3764. }
  3765. $accountJson ['cSum'] = array (
  3766. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  3767. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  3768. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  3769. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  3770. );
  3771. // 报销单
  3772. $receipt = new receipt ();
  3773. $receipt->accountItem = json_encode ( $accountJson );
  3774. $receipt->sum = number_format ( $sum, 2, '.', '' );
  3775. $receipt->update ( array (
  3776. 'where' => 'rid=' . $rid
  3777. ) );
  3778. // print_r($accountJson);
  3779. // statistics item 统计写入
  3780. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  3781. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  3782. $accountItem = $accountJson;
  3783. $stat = $statistics->getOne ( array (
  3784. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3785. 'asArray' => true
  3786. ) );
  3787. if (empty ( $stat )) {
  3788. $statistics->date = date ( "Y-m-d" );
  3789. $statistics->cid = $this->staff [0] ['cid'];
  3790. $statistics->staff = $this->staff [0] ['sid'];
  3791. $statistics->agPrice = 0;
  3792. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3793. $statistics->insert ();
  3794. } else {
  3795. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3796. $statistics->update ( array (
  3797. 'where' => 'sid=' . $stat ['sid']
  3798. ) );
  3799. }
  3800. return "/saeaBorad";
  3801. }
  3802. function confirmation() {
  3803. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3804. Doo::loadModel ( 'receipt' );
  3805. Doo::loadModel ( 'receiptDetail' );
  3806. $receipt = new receipt ();
  3807. $receiptDetail = new receiptDetail ();
  3808. Doo::loadModel ( 'statistics' );
  3809. Doo::loadModel ( 'itemStatistics' );
  3810. $statistics = new statistics ();
  3811. $itemStatistics = new itemStatistics ();
  3812. Doo::loadModel ( "verify" );
  3813. $verify = new verify ();
  3814. $receiptDetailList = $receipt->getOne ( array (
  3815. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  3816. 'asArray' => true
  3817. ) );
  3818. if (empty ( $receiptDetailList ))
  3819. return "/saeaBorad";
  3820. $verifyDetail = $verify->getOne ( array (
  3821. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3822. 'asArray' => true
  3823. ) );
  3824. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3825. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3826. $nowStaff = "";
  3827. $nowStaffList = array ();
  3828. if ($verifyDetail [0] [1] == 'ROLE') {
  3829. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3830. foreach ( $vStaffString as $key => $value ) {
  3831. $staffK = explode ( "_", $value );
  3832. array_push ( $nowStaffList, $staffK [0] );
  3833. }
  3834. $nowStaff = implode ( ',', $nowStaffList );
  3835. } else {
  3836. $nowStaff = $verifyDetail [0] [0];
  3837. }
  3838. $receipt->nowStaff = $nowStaff;
  3839. }
  3840. // echo $nowStaff;
  3841. // print_r($verifyDetail);die;
  3842. $receipt->rid = $receiptDetailList ['rid'];
  3843. $receipt->status = 2;
  3844. $receipt->update ();
  3845. // 操作日志
  3846. Doo::loadModel ( "receiptLog" );
  3847. $receiptLog = new receiptLog ();
  3848. $verify = new verify ();
  3849. $receiptInfo = $receipt->getOne ( array (
  3850. 'where' => 'rid=' . $rid,
  3851. 'asArray' => true
  3852. ) );
  3853. $vr = $verify->getOne ( array (
  3854. 'where' => 'vid=' . $receiptInfo ['verify'],
  3855. 'asArray' => true
  3856. ) );
  3857. $jd = json_decode ( $vr ['staff'] );
  3858. $roleId = 0;
  3859. foreach ( $jd as $key => $value ) {
  3860. if ($value [1] == 'ROLE') {
  3861. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3862. if ($pos !== false) {
  3863. $roleId = $value [0];
  3864. }
  3865. }
  3866. }
  3867. // 审批日志
  3868. // echo $roleId;die;
  3869. if (! empty ( $roleId )) {
  3870. Doo::loadModel ( "role" );
  3871. $role = new role ();
  3872. $roleInfo = $role->getOne ( array (
  3873. 'where' => 'rid=' . $roleId,
  3874. 'asArray' => true
  3875. ) );
  3876. // $receiptLog->rolename = $roleInfo ['name'];
  3877. }
  3878. $receiptLog->username = $this->staff [0] ['username'];
  3879. $receiptLog->uid = $this->staff [0] ['sid'];
  3880. $receiptLog->date = date ( "Y-m-d" );
  3881. $receiptLog->opinion = '提交审批';
  3882. $receiptLog->img = $this->staff [0] ['avatar'];
  3883. $receiptLog->status = 2;
  3884. $receiptLog->rid = $rid;
  3885. $receiptLog->insert ();
  3886. return "/expenses";
  3887. }
  3888. function expenses() {
  3889. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  3890. if (empty ( $item ))
  3891. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3892. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3893. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  3894. Doo::loadClass ( 'XDeode' );
  3895. $XDeode = new XDeode ( 7 );
  3896. Doo::loadModel ( 'receipt' );
  3897. $receipt = new receipt ();
  3898. Doo::loadModel ( 'L_category' );
  3899. $Lcategory = new L_category ();
  3900. Doo::loadModel ( 'verify' );
  3901. Doo::loadModel ( 'statistics' );
  3902. $statistics = new statistics ();
  3903. $verify = new verify ();
  3904. Doo::loadModel ( 'staff' );
  3905. $staff = new staff ();
  3906. $condition = "";
  3907. if ($item == "expenses")
  3908. $condition = " and Rtype=1 ";
  3909. elseif ($item == "receipts")
  3910. $condition = " and Rtype=0 ";
  3911. elseif ($item == "remits")
  3912. $condition = " and Rtype=2 ";
  3913. elseif ($item == "train")
  3914. $condition = " and Rtype=3 ";
  3915. $dateCondition = " and Year(date) =" . $year;
  3916. if (! empty ( $moth )) {
  3917. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  3918. $stList = $statistics->getOne ( array (
  3919. 'select' => 'rePrice ,agPrice',
  3920. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3921. 'asArray' => true
  3922. ) );
  3923. } else
  3924. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  3925. if (empty ( $stList ))
  3926. $stList = array (
  3927. 'rePrice' => 0,
  3928. 'agPrice' => 0
  3929. );
  3930. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  3931. if (! isset ( $noPassSum ['sum'] ))
  3932. $noPassSum ['sum'] = 0;
  3933. $data ['stList'] = array (
  3934. 'rePrice' => $stList ['rePrice'],
  3935. 'agPrice' => $stList ['agPrice'],
  3936. 'skPrice' => ($noPassSum ['sum'])
  3937. );
  3938. $receiptList = $receipt->find ( array (
  3939. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  3940. 'desc' => 'rid',
  3941. 'asArray' => true
  3942. ) );
  3943. $Locate = 0;
  3944. $roleId = 0;
  3945. $button = 0;
  3946. foreach ( $receiptList as $key => $value ) {
  3947. $receiptList[$key]['balance']='';
  3948. if($value['Rtype']==1){
  3949. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  3950. $receiptList[$key]['balanceABS']=abs($receiptList[$key]['balance']);
  3951. }elseif($value['Rtype']==3){
  3952. $payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
  3953. $receiptList[$key]['payment']=$payment;
  3954. $receiptList[$key]['paymentABS']=abs($payment);
  3955. }
  3956. $receiptList [$key] ['Locate'] = $Locate;
  3957. $Locate ++;
  3958. $receiptList [$key] ['reviseDetail'] = array ();
  3959. if (! empty ( $value ['reviseDetail'] ))
  3960. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3961. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3962. $categoryDetil = $Lcategory->getOne ( array (
  3963. 'where' => 'cid=' . $value ['cid'],
  3964. 'asArray' => true
  3965. ) );
  3966. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3967. // 检测编辑状态
  3968. $verifyList = $verify->getOne ( array (
  3969. 'where' => 'vid=' . $value ['verify'],
  3970. 'asArray' => true
  3971. ) );
  3972. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  3973. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  3974. Doo::loadModel ( 'role' );
  3975. $role = new role ();
  3976. $flag = true;
  3977. $roleKey = 0;
  3978. $endStaffArray = array ();
  3979. $roleArrayCopy = array ();
  3980. foreach ( $verifyList as $k => $v ) {
  3981. // init verifyStaff
  3982. if ($v [1] == 'ROLE') {
  3983. if (! empty ( $verifyStaff )) {
  3984. $endStaffArray = end ( $verifyStaff );
  3985. // if ($v[0]==$endStaffArray['nextStaff']){
  3986. // $roleId=$v[0];
  3987. // }
  3988. }
  3989. $roleVerify = json_decode ( $v [3], true );
  3990. $roleKey = $k;
  3991. $roleArray = array ();
  3992. $rolename = $role->getOne ( array (
  3993. 'where' => 'rid=' . $v [0],
  3994. 'asArray' => true
  3995. ) );
  3996. foreach ( $roleVerify as $o => $p ) {
  3997. $staffID = explode ( '_', $p );
  3998. $staffInfo = $staff->getOne ( array (
  3999. 'where' => 'sid=' . $staffID [0],
  4000. 'asArray' => true
  4001. ) );
  4002. // print_r($staffID);
  4003. $exp = array (
  4004. 0 => $staffInfo ['sid'],
  4005. 1 => $staffID [1],
  4006. 2 => $staffInfo ['avatar'],
  4007. 'date' => '',
  4008. 'date' => '',
  4009. 'opinion' => '',
  4010. 'status' => '',
  4011. 'rolename' => $rolename ['name']
  4012. );
  4013. array_push ( $roleArray, $exp );
  4014. }
  4015. $roleArrayCopy [$v [0]] = $roleArray;
  4016. // $verifyList[$k]['roleArray']=$roleArray;
  4017. }
  4018. $verifyList [$k] ['date'] = "";
  4019. $verifyList [$k] ['opinion'] = "";
  4020. $verifyList [$k] ['status'] = "";
  4021. if (empty ( $verifyStaff )) {
  4022. $verifyList [$k] ['date'] = "";
  4023. $verifyList [$k] ['opinion'] = "";
  4024. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4025. $verifyList [$k] ['status'] = 4;
  4026. $flag = false;
  4027. }
  4028. } else {
  4029. foreach ( $verifyStaff as $m => $u ) {
  4030. if ($v [0] == $m) {
  4031. $verifyList [$k] ['date'] = $u ['date'];
  4032. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4033. $verifyList [$k] ['status'] = $u ['status'];
  4034. $flag = false;
  4035. break;
  4036. }
  4037. }
  4038. $endStaffArray = end ( $verifyStaff );
  4039. if (isset ( $endStaffArray ['ROLE'] )) {
  4040. } else {
  4041. // $endKey=key($verifyStaff);
  4042. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4043. // $button=4;
  4044. // $verifyList[$k]['status']=4;
  4045. // }
  4046. }
  4047. }
  4048. }
  4049. $rolename ['name'] = '';
  4050. if (! empty ( $roleId )) {
  4051. Doo::loadModel ( 'role' );
  4052. $role = new role ();
  4053. $rolename = $role->getOne ( array (
  4054. 'where' => 'rid=' . $roleId,
  4055. 'asArray' => true
  4056. ) );
  4057. }
  4058. if (! empty ( $verifyStaff ))
  4059. $endStaffArray = end ( $verifyStaff );
  4060. $KOP = false;
  4061. foreach ( $roleArrayCopy as $P => $A ) {
  4062. foreach ( $A as $MKI => $AVL ) {
  4063. if (! empty ( $verifyStaff )) {
  4064. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4065. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4066. $button = 4;
  4067. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4068. }
  4069. foreach ( $verifyStaff as $m => $u ) {
  4070. $AVLFK = $AVL [0] . '_R';
  4071. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4072. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4073. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4074. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4075. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4076. break;
  4077. }
  4078. }
  4079. } else {
  4080. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4081. $button = 4;
  4082. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4083. }
  4084. }
  4085. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4086. $KOP = true;
  4087. }
  4088. }
  4089. foreach ( $roleArrayCopy as $k => $v ) {
  4090. foreach ( $verifyList as $m => $n ) {
  4091. if ($n [0] == $k) {
  4092. array_splice ( $verifyList, $m, 1, $v );
  4093. }
  4094. }
  4095. }
  4096. $receiptList [$key] ['verifyList'] = $verifyList;
  4097. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4098. 'where' => 'sid=' . $value ['staff'],
  4099. 'asArray' => true
  4100. ) );
  4101. $receiptList [$key] ['button'] = $button;
  4102. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  4103. }
  4104. // print_r($receiptList);die;
  4105. $mothHtml = "";
  4106. for($i = 1; $i <= 12; $i ++) {
  4107. if ($moth == $i)
  4108. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4109. else
  4110. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4111. }
  4112. $dateHtml = "";
  4113. $now = date ( "Y" );
  4114. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  4115. if ($YEARD <= $now) {
  4116. $dateHtml .= '<option ';
  4117. if ($year == $YEARD) {
  4118. $dateHtml .= 'selected ';
  4119. }
  4120. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  4121. }
  4122. }
  4123. $data ['dateHtml'] = $dateHtml;
  4124. $data ['mothHtml'] = $mothHtml;
  4125. $data ['receiptList'] = $receiptList;
  4126. $data ['memu'] = "receipt";
  4127. $data ['staff'] = $this->staff;
  4128. $data ['receiptMemu'] = 'expenses';
  4129. $data ['verifyId'] = $this->verifyId;
  4130. $data ['executeId'] = $this->executeId;
  4131. $data ['item'] = $item;
  4132. $data ['year'] = $year;
  4133. $this->render ( "/admin/expenses", $data );
  4134. }
  4135. function expensesCollect() {
  4136. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4137. Doo::loadModel ( 'receipt' );
  4138. $receipt = new receipt ();
  4139. Doo::loadModel ( 'L_category' );
  4140. $Lcategory = new L_category ();
  4141. Doo::loadModel ( 'verify' );
  4142. Doo::loadModel ( 'statistics' );
  4143. $statistics = new statistics ();
  4144. $verify = new verify ();
  4145. Doo::loadModel ( 'staff' );
  4146. $staff = new staff ();
  4147. Doo::loadModel ( 'loanReceipt' );
  4148. $loanReceipt = new loanReceipt ();
  4149. $receiptList = $receipt->find ( array (//去掉
  4150. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  4151. 'desc' => 'rid',
  4152. 'asArray' => true
  4153. ) );
  4154. $loanList = $loanReceipt->find ( array (
  4155. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4156. 'desc' => 'rid',
  4157. 'asArray' => true
  4158. ) );
  4159. /*
  4160. * $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;
  4161. */
  4162. $data ['explanation'] = '';
  4163. if (! empty ( $loanList ))
  4164. $data ['explanation'] = $loanList [0] ['explanation'];
  4165. $Locate = 0;
  4166. $roleId = 0;
  4167. $button = 0;
  4168. foreach ( $receiptList as $key => $value ) {
  4169. $receiptList [$key] ['Locate'] = $Locate;
  4170. $Locate ++;
  4171. $receiptList [$key] ['reviseDetail'] = array ();
  4172. if (! empty ( $value ['reviseDetail'] ))
  4173. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4174. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4175. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4176. $categoryDetil = $Lcategory->getOne ( array (
  4177. 'where' => 'cid=' . $value ['cid'],
  4178. 'asArray' => true
  4179. ) );
  4180. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4181. // 检测编辑状态
  4182. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  4183. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  4184. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  4185. else
  4186. $verifyList ['staff'] = $value ['verifyBreakup'];
  4187. } else
  4188. $verifyList = $verify->getOne ( array (
  4189. 'where' => 'vid=' . $value ['verify'],
  4190. 'asArray' => true
  4191. ) );
  4192. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4193. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4194. Doo::loadModel ( 'role' );
  4195. $role = new role ();
  4196. $flag = true;
  4197. $roleKey = 0;
  4198. $endStaffArray = array ();
  4199. $roleArrayCopy = array ();
  4200. foreach ( $verifyList as $k => $v ) {
  4201. // init verifyStaff
  4202. if ($v [1] == 'ROLE') {
  4203. if (! empty ( $verifyStaff )) {
  4204. $endStaffArray = end ( $verifyStaff );
  4205. // if ($v[0]==$endStaffArray['nextStaff']){
  4206. // $roleId=$v[0];
  4207. // }
  4208. }
  4209. $roleVerify = json_decode ( $v [3], true );
  4210. $roleKey = $k;
  4211. $roleArray = array ();
  4212. $rolename = $role->getOne ( array (
  4213. 'where' => 'rid=' . $v [0],
  4214. 'asArray' => true
  4215. ) );
  4216. foreach ( $roleVerify as $o => $p ) {
  4217. $staffID = explode ( '_', $p );
  4218. $staffInfo = $staff->getOne ( array (
  4219. 'where' => 'sid=' . $staffID [0],
  4220. 'asArray' => true
  4221. ) );
  4222. // print_r($staffID);
  4223. $exp = array (
  4224. 0 => $staffInfo ['sid'],
  4225. 1 => $staffID [1],
  4226. 2 => $staffInfo ['avatar'],
  4227. 'date' => '',
  4228. 'date' => '',
  4229. 'opinion' => '',
  4230. 'status' => '',
  4231. 'rolename' => $rolename ['name']
  4232. );
  4233. array_push ( $roleArray, $exp );
  4234. }
  4235. $roleArrayCopy [$v [0]] = $roleArray;
  4236. // $verifyList[$k]['roleArray']=$roleArray;
  4237. }
  4238. $verifyList [$k] ['date'] = "";
  4239. $verifyList [$k] ['opinion'] = "";
  4240. $verifyList [$k] ['status'] = "";
  4241. if (empty ( $verifyStaff )) {
  4242. $verifyList [$k] ['date'] = "";
  4243. $verifyList [$k] ['opinion'] = "";
  4244. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4245. $verifyList [$k] ['status'] = 4;
  4246. $flag = false;
  4247. }
  4248. } else {
  4249. foreach ( $verifyStaff as $m => $u ) {
  4250. if ($v [0] == $m) {
  4251. $verifyList [$k] ['date'] = $u ['date'];
  4252. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4253. $verifyList [$k] ['status'] = $u ['status'];
  4254. $flag = false;
  4255. break;
  4256. }
  4257. }
  4258. $endStaffArray = end ( $verifyStaff );
  4259. if (isset ( $endStaffArray ['ROLE'] )) {
  4260. } else {
  4261. // $endKey=key($verifyStaff);
  4262. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4263. // $button=4;
  4264. // $verifyList[$k]['status']=4;
  4265. // }
  4266. }
  4267. }
  4268. }
  4269. $rolename ['name'] = '';
  4270. if (! empty ( $roleId )) {
  4271. Doo::loadModel ( 'role' );
  4272. $role = new role ();
  4273. $rolename = $role->getOne ( array (
  4274. 'where' => 'rid=' . $roleId,
  4275. 'asArray' => true
  4276. ) );
  4277. }
  4278. if (! empty ( $verifyStaff ))
  4279. $endStaffArray = end ( $verifyStaff );
  4280. $KOP = false;
  4281. foreach ( $roleArrayCopy as $P => $A ) {
  4282. foreach ( $A as $MKI => $AVL ) {
  4283. if (! empty ( $verifyStaff )) {
  4284. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4285. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4286. $button = 4;
  4287. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4288. }
  4289. foreach ( $verifyStaff as $m => $u ) {
  4290. $AVLFK = $AVL [0] . '_R';
  4291. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4292. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4293. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4294. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4295. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4296. break;
  4297. }
  4298. }
  4299. } else {
  4300. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4301. $button = 4;
  4302. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4303. }
  4304. }
  4305. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4306. $KOP = true;
  4307. }
  4308. }
  4309. foreach ( $roleArrayCopy as $k => $v ) {
  4310. foreach ( $verifyList as $m => $n ) {
  4311. if ($n [0] == $k) {
  4312. array_splice ( $verifyList, $m, 1, $v );
  4313. }
  4314. }
  4315. }
  4316. // 费用执行人相关数据
  4317. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4318. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4319. foreach ( $executeCopy as $k => $v ) {
  4320. $executeCopy [$k] ['date'] = '';
  4321. $executeCopy [$k] ['opinion'] = '';
  4322. $executeCopy [$k] ['status'] = '';
  4323. if (! empty ( $executeStaff ))
  4324. foreach ( $executeStaff as $m => $u ) {
  4325. if ($v [0] == $m) {
  4326. $executeCopy [$k] ['date'] = $u ['date'];
  4327. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4328. $executeCopy [$k] ['status'] = $u ['status'];
  4329. break;
  4330. }
  4331. }
  4332. }
  4333. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4334. $receiptList [$key] ['verifyList'] = $verifyList;
  4335. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4336. 'where' => 'sid=' . $value ['staff'],
  4337. 'asArray' => true
  4338. ) );
  4339. $receiptList [$key] ['button'] = $button;
  4340. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4341. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4342. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4343. $receiptList [$key] ['relust'] = $relust;
  4344. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4345. }
  4346. Doo::loadModel ( 'enclosur' );
  4347. $enclosur = new enclosur ();
  4348. $enclosurList = $enclosur->find ( array (
  4349. 'where' => 'rid=' . $rid,
  4350. 'asArray' => true
  4351. ) );
  4352. $enclosurHtml = '';
  4353. foreach ( $enclosurList as $value ) {
  4354. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4355. }
  4356. $receiptList[0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  4357. $data ['enclosurHtml'] = $enclosurHtml;
  4358. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  4359. $data ['receiptList'] = $receiptList;
  4360. $data ['memu'] = "receipt";
  4361. $data ['staff'] = $this->staff;
  4362. $data ['receiptMemu'] = 'expenses';
  4363. $data ['verifyId'] = $this->verifyId;
  4364. $data ['executeId'] = $this->executeId;
  4365. if($receiptList[0]['receiptClass']==2){
  4366. if(!empty($receiptList[0]['itinerary2'])){
  4367. $this->render ( "/receipt/feeTraveDetail2", $data );
  4368. }else{
  4369. $this->render ( "/receipt/feeTraveDetail", $data );
  4370. }
  4371. }else{
  4372. $this->render ( "/admin/expensesCollect", $data );
  4373. }
  4374. }
  4375. function approvalExpenses() {
  4376. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  4377. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4378. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4379. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4380. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4381. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  4382. // echo $rdate;
  4383. if (empty ( $status ))
  4384. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4385. $page_size = 8;
  4386. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4387. $vidList = array ();
  4388. $button = 0;
  4389. Doo::loadModel ( 'verify' );
  4390. $verify = new verify ();
  4391. Doo::loadModel ( 'receipt' );
  4392. $receipt = new receipt ();
  4393. Doo::loadModel ( 'staff' );
  4394. $staff = new staff ();
  4395. Doo::loadModel ( 'L_category' );
  4396. $Lcategory = new L_category ();
  4397. // user verify ID
  4398. $verifyDetail = $verify->find ( array (
  4399. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4400. 'asArray' => true
  4401. ) );
  4402. foreach ( $verifyDetail as $key => $value ) {
  4403. array_push ( $vidList, $value ['vid'] );
  4404. }
  4405. $vid = implode ( ",", $vidList );
  4406. if (empty ( $verifyDetail ))
  4407. $vid = 0;
  4408. // if ($status==0)
  4409. // $dateCondition="";
  4410. // else
  4411. $dateCondition = " ";
  4412. // if (! empty ( $month ))
  4413. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  4414. if ($status == 'done' || $status == 'termination') {
  4415. if (! empty ( $year )) {
  4416. $dateCondition = " and Year(pastDate) =" . $year;
  4417. if (! empty ( $month ))
  4418. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4419. }
  4420. } elseif ($status == 'finish') {
  4421. if (! empty ( $year )) {
  4422. $dateCondition = " and Year(pastDate) =" . $year;
  4423. if (! empty ( $month ))
  4424. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4425. }
  4426. }
  4427. // date ( 'Y-m' )
  4428. // if (! empty ( $rdate ) && $status == 'done')
  4429. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  4430. // elseif (! empty ( $rdate ))
  4431. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  4432. $categoryList = $Lcategory->find ( array (
  4433. 'asArray' => true
  4434. ) );
  4435. $staffList = $staff->find ( array (
  4436. 'where' => 'cid=' . $cid,
  4437. 'asArray' => true
  4438. ) );
  4439. $cateCondition = "";
  4440. $staffCondition = "";
  4441. $approvalCondition = "";
  4442. if (! empty ( $cid )) {
  4443. $cateCondition = ' and cid=' . $cid;
  4444. }
  4445. if (! empty ( $sid )) {
  4446. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  4447. $cateCondition = "";
  4448. }
  4449. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  4450. if ($status == 'pendApproval') {
  4451. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4452. }
  4453. if ($status == 'ongoing') {
  4454. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  4455. }
  4456. if ($status == 'done') {
  4457. $approvalCondition = ' and (status=8 or status=9 ) ';
  4458. }
  4459. if ($status == 'termination') {
  4460. $approvalCondition = " and status=3";
  4461. }
  4462. if ($status == 'finish') {
  4463. $approvalCondition = " and (status=1 or status=8 or status=9 or status=10)";
  4464. }
  4465. $pageinfo ['page'] = array (
  4466. 'previous' => ''
  4467. );
  4468. if(!empty($receiptOrder)){
  4469. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4470. $receiptList = $receipt->find ( array ( // $dateCondition
  4471. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  4472. 'desc' => 'rid',
  4473. 'asArray' => true
  4474. ) );
  4475. }else{
  4476. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  4477. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4478. $receiptList = $receipt->find ( array ( // $dateCondition.
  4479. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4480. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  4481. 'desc' => 'rid',
  4482. 'asArray' => true
  4483. ) );
  4484. } else {
  4485. $receiptList = $receipt->find ( array ( // $dateCondition
  4486. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4487. 'desc' => 'rid',
  4488. 'asArray' => true
  4489. ) );
  4490. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4491. }
  4492. }
  4493. $rLRes = $receipt->find ( array (
  4494. '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 . ')',
  4495. 'desc' => 'rid',
  4496. 'asArray' => true
  4497. ) );
  4498. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4499. // print_r($receiptList);
  4500. Doo::loadClass ( 'XDeode' );
  4501. $XDeode = new XDeode ( 7 );
  4502. $Locate = 0;
  4503. //
  4504. $reportList = $reportCateList = array ();
  4505. foreach ( $receiptList as $key => $value ) {
  4506. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  4507. $receiptList [$key] ['Locate'] = $Locate;
  4508. $Locate ++;
  4509. $receiptList [$key] ['reviseDetail'] = array ();
  4510. if (! empty ( $value ['reviseDetail'] ))
  4511. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4512. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4513. $categoryDetil = $Lcategory->getOne ( array (
  4514. 'where' => 'cid=' . $value ['cid'],
  4515. 'asArray' => true
  4516. ) );
  4517. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4518. $verifyList = $verify->getOne ( array (
  4519. 'where' => 'vid=' . $value ['verify'],
  4520. 'asArray' => true
  4521. ) );
  4522. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4523. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4524. foreach ( $verifyList as $k => $v ) {
  4525. // init verifyStaff
  4526. $verifyList [$k] ['date'] = "";
  4527. $verifyList [$k] ['opinion'] = "";
  4528. $verifyList [$k] ['status'] = "";
  4529. if (empty ( $verifyStaff )) {
  4530. $verifyList [$k] ['date'] = "";
  4531. $verifyList [$k] ['opinion'] = "";
  4532. if ($v [0] == $this->staff [0] ['sid']) {
  4533. $verifyList [$k] ['status'] = 4;
  4534. $button = 4;
  4535. }
  4536. } else {
  4537. $flag = true;
  4538. foreach ( $verifyStaff as $m => $u ) {
  4539. if ($v [0] == $m) {
  4540. $verifyList [$k] ['date'] = $u ['date'];
  4541. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4542. $verifyList [$k] ['status'] = $u ['status'];
  4543. $flag = false;
  4544. break;
  4545. }
  4546. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4547. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4548. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4549. }
  4550. if ($flag) { // 检测可编辑
  4551. if ($v [0] == $this->staff [0] ['sid']) {
  4552. $verifyList [$k] ['status'] = 4;
  4553. $button = 4;
  4554. }
  4555. }
  4556. }
  4557. }
  4558. $receiptList [$key] ['verifyList'] = $verifyList;
  4559. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4560. 'where' => 'sid=' . $value ['staff'],
  4561. 'asArray' => true
  4562. ) );
  4563. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4564. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4565. $receiptList [$key] ['button'] = $button;
  4566. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  4567. //获得培训班结算RID 借款费用--已经锁定
  4568. if($value['status']==10){
  4569. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  4570. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  4571. }
  4572. }
  4573. $reportList = array_unique ( $reportList );
  4574. $reportHtml = '';
  4575. foreach ( $reportList as $key => $value ) {
  4576. $v = explode ( "-", $value );
  4577. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  4578. }
  4579. // print_r($reportList)
  4580. $data ['reportHtml'] = $reportHtml;
  4581. $reportCateList = array_unique ( $reportCateList );
  4582. $reportCateHtml = '';
  4583. foreach ( $reportCateList as $key => $value ) {
  4584. $v = explode ( "-", $value );
  4585. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  4586. }
  4587. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  4588. $data ['reportCateHtml'] = $reportCateHtml;
  4589. // print_r($receiptList);die;
  4590. // $data['verifyDetail']=$verifyDetail;
  4591. $mothHtml = "";
  4592. for($i = 1; $i <= 12; $i ++) {
  4593. if ($month == $i)
  4594. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  4595. else
  4596. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  4597. }
  4598. $data ['mothHtml'] = $mothHtml;
  4599. $dateHtml = "";
  4600. $now = date ( "Y" );
  4601. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  4602. if ($YEARD <= $now) {
  4603. $dateHtml .= '<option ';
  4604. if ($year == $YEARD) {
  4605. $dateHtml .= 'selected ';
  4606. }
  4607. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  4608. }
  4609. }
  4610. $data ['dateHtml'] = $dateHtml;
  4611. $data ['page'] = $pageinfo;
  4612. $data ['receiptList'] = $receiptList;
  4613. $data ['receiptApprovalCount'] = count ( $rLRes );
  4614. $data ['status'] = $status;
  4615. $data ['year'] = $year;
  4616. $data ['month'] = $month;
  4617. $data ['categoryList'] = $categoryList;
  4618. $data ['staffList'] = $staffList;
  4619. $data ['cid'] = $cid;
  4620. $data ['sid'] = $sid;
  4621. // print_r($receiptList);
  4622. $data['receiptOrder']=$receiptOrder;
  4623. $data ['memu'] = "receipt";
  4624. $data ['staff'] = $this->staff;
  4625. $data ['receiptMemu'] = 'approvalExpenses';
  4626. $data ['verifyId'] = $this->verifyId;
  4627. $data ['executeId'] = $this->executeId;
  4628. $this->render ( "/admin/approvalExpenses", $data );
  4629. }
  4630. private function _expensesDoc(){
  4631. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  4632. Doo::loadClass ( 'XDeode' );
  4633. $XDeode = new XDeode ( 5 );
  4634. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  4635. $rid = $XDeode->decode ( $rid );
  4636. if (! is_numeric ( $rid ))
  4637. die ( 'illegal request' );
  4638. Doo::loadModel ( 'receipt' );
  4639. $receipt = new receipt ();
  4640. Doo::loadModel ( 'L_category' );
  4641. $Lcategory = new L_category ();
  4642. Doo::loadModel ( 'verify' );
  4643. Doo::loadModel ( 'statistics' );
  4644. $statistics = new statistics ();
  4645. $verify = new verify ();
  4646. Doo::loadModel ( 'staff' );
  4647. $staff = new staff ();
  4648. Doo::loadModel ( 'loanReceipt' );
  4649. $loanReceipt = new loanReceipt ();
  4650. $receiptList = $receipt->find ( array (
  4651. 'where' => ' rid=' . $rid,
  4652. 'desc' => 'rid',
  4653. 'asArray' => true
  4654. ) );
  4655. $loanList = array ();
  4656. if (! empty ( $receiptList ))
  4657. $loanList = $loanReceipt->find ( array (
  4658. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4659. 'desc' => 'rid',
  4660. 'asArray' => true
  4661. ) );
  4662. $Locate = 0;
  4663. $roleId = 0;
  4664. $button = 0;
  4665. foreach ( $loanList as $key => $value ) {
  4666. $loanList [$key] ['Locate'] = $Locate;
  4667. $Locate ++;
  4668. $loanList [$key] ['reviseDetail'] = array ();
  4669. if (! empty ( $value ['reviseDetail'] ))
  4670. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4671. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4672. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4673. $categoryDetil = $Lcategory->getOne ( array (
  4674. 'where' => 'cid=' . $value ['cid'],
  4675. 'asArray' => true
  4676. ) );
  4677. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4678. // 检测编辑状态
  4679. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  4680. $verifyList ['staff'] = $value ['verifyBreakup'];
  4681. else
  4682. $verifyList = $verify->getOne ( array (
  4683. 'where' => 'vid=' . $value ['verify'],
  4684. 'asArray' => true
  4685. ) );
  4686. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4687. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4688. Doo::loadModel ( 'role' );
  4689. $role = new role ();
  4690. $flag = true;
  4691. $roleKey = 0;
  4692. $endStaffArray = array ();
  4693. $roleArrayCopy = array ();
  4694. foreach ( $verifyList as $k => $v ) {
  4695. // init verifyStaff
  4696. if ($v [1] == 'ROLE') {
  4697. if (! empty ( $verifyStaff )) {
  4698. $endStaffArray = end ( $verifyStaff );
  4699. // if ($v[0]==$endStaffArray['nextStaff']){
  4700. // $roleId=$v[0];
  4701. // }
  4702. }
  4703. $roleVerify = json_decode ( $v [3], true );
  4704. $roleKey = $k;
  4705. $roleArray = array ();
  4706. $rolename = $role->getOne ( array (
  4707. 'where' => 'rid=' . $v [0],
  4708. 'asArray' => true
  4709. ) );
  4710. foreach ( $roleVerify as $o => $p ) {
  4711. $staffID = explode ( '_', $p );
  4712. $staffInfo = $staff->getOne ( array (
  4713. 'where' => 'sid=' . $staffID [0],
  4714. 'asArray' => true
  4715. ) );
  4716. // print_r($staffID);
  4717. $exp = array (
  4718. 0 => $staffInfo ['sid'],
  4719. 1 => $staffID [1],
  4720. 2 => $staffInfo ['avatar'],
  4721. 'date' => '',
  4722. 'date' => '',
  4723. 'opinion' => '',
  4724. 'status' => '',
  4725. 'rolename' => $rolename ['name']
  4726. );
  4727. array_push ( $roleArray, $exp );
  4728. }
  4729. $roleArrayCopy [$v [0]] = $roleArray;
  4730. // $verifyList[$k]['roleArray']=$roleArray;
  4731. }
  4732. $verifyList [$k] ['date'] = "";
  4733. $verifyList [$k] ['opinion'] = "";
  4734. $verifyList [$k] ['status'] = "";
  4735. if (empty ( $verifyStaff )) {
  4736. $verifyList [$k] ['date'] = "";
  4737. $verifyList [$k] ['opinion'] = "";
  4738. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4739. $verifyList [$k] ['status'] = 4;
  4740. $flag = false;
  4741. }
  4742. } else {
  4743. foreach ( $verifyStaff as $m => $u ) {
  4744. if ($v [0] == $m) {
  4745. $verifyList [$k] ['date'] = $u ['date'];
  4746. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4747. $verifyList [$k] ['status'] = $u ['status'];
  4748. $flag = false;
  4749. break;
  4750. }
  4751. }
  4752. $endStaffArray = end ( $verifyStaff );
  4753. if (isset ( $endStaffArray ['ROLE'] )) {
  4754. } else {
  4755. // $endKey=key($verifyStaff);
  4756. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4757. // $button=4;
  4758. // $verifyList[$k]['status']=4;
  4759. // }
  4760. }
  4761. }
  4762. }
  4763. $rolename ['name'] = '';
  4764. if (! empty ( $roleId )) {
  4765. Doo::loadModel ( 'role' );
  4766. $role = new role ();
  4767. $rolename = $role->getOne ( array (
  4768. 'where' => 'rid=' . $roleId,
  4769. 'asArray' => true
  4770. ) );
  4771. }
  4772. if (! empty ( $verifyStaff ))
  4773. $endStaffArray = end ( $verifyStaff );
  4774. $KOP = false;
  4775. foreach ( $roleArrayCopy as $P => $A ) {
  4776. foreach ( $A as $MKI => $AVL ) {
  4777. if (! empty ( $verifyStaff )) {
  4778. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4779. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4780. $button = 4;
  4781. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4782. }
  4783. foreach ( $verifyStaff as $m => $u ) {
  4784. $AVLFK = $AVL [0] . '_R';
  4785. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4786. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4787. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4788. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4789. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4790. break;
  4791. }
  4792. }
  4793. } else {
  4794. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4795. $button = 4;
  4796. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4797. }
  4798. }
  4799. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4800. $KOP = true;
  4801. }
  4802. }
  4803. foreach ( $roleArrayCopy as $k => $v ) {
  4804. foreach ( $verifyList as $m => $n ) {
  4805. if ($n [0] == $k) {
  4806. array_splice ( $verifyList, $m, 1, $v );
  4807. }
  4808. }
  4809. }
  4810. $loanList [$key] ['verifyList'] = $verifyList;
  4811. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4812. 'where' => 'sid=' . $value ['staff'],
  4813. 'asArray' => true
  4814. ) );
  4815. $loanList [$key] ['button'] = $button;
  4816. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  4817. }
  4818. $data ['loanList'] = $loanList;
  4819. //print_r($loanList);
  4820. $Locate = 0;
  4821. $roleId = 0;
  4822. $button = 0;
  4823. foreach ( $receiptList as $key => $value ) {
  4824. $receiptList [$key] ['Locate'] = $Locate;
  4825. $Locate ++;
  4826. $receiptList [$key] ['reviseDetail'] = array ();
  4827. if (! empty ( $value ['reviseDetail'] ))
  4828. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4829. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4830. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4831. $categoryDetil = $Lcategory->getOne ( array (
  4832. 'where' => 'cid=' . $value ['cid'],
  4833. 'asArray' => true
  4834. ) );
  4835. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4836. // 检测编辑状态
  4837. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  4838. $verifyList ['staff'] = $value ['verifyBreakup'];
  4839. } else
  4840. $verifyList = $verify->getOne ( array (
  4841. 'where' => 'vid=' . $value ['verify'],
  4842. 'asArray' => true
  4843. ) );
  4844. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4845. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4846. Doo::loadModel ( 'role' );
  4847. $role = new role ();
  4848. if ($verifyList == NULL)
  4849. $verifyList = array ();
  4850. $flag = true;
  4851. $roleKey = 0;
  4852. $endStaffArray = array ();
  4853. $roleArrayCopy = array ();
  4854. foreach ( $verifyList as $k => $v ) {
  4855. // init verifyStaff
  4856. if ($v [1] == 'ROLE') {
  4857. if (! empty ( $verifyStaff )) {
  4858. $endStaffArray = end ( $verifyStaff );
  4859. // if ($v[0]==$endStaffArray['nextStaff']){
  4860. // $roleId=$v[0];
  4861. // }
  4862. }
  4863. $roleVerify = json_decode ( $v [3], true );
  4864. $roleKey = $k;
  4865. $roleArray = array ();
  4866. $rolename = $role->getOne ( array (
  4867. 'where' => 'rid=' . $v [0],
  4868. 'asArray' => true
  4869. ) );
  4870. foreach ( $roleVerify as $o => $p ) {
  4871. $staffID = explode ( '_', $p );
  4872. $staffInfo = $staff->getOne ( array (
  4873. 'where' => 'sid=' . $staffID [0],
  4874. 'asArray' => true
  4875. ) );
  4876. // print_r($staffID);
  4877. $exp = array (
  4878. 0 => $staffInfo ['sid'],
  4879. 1 => $staffID [1],
  4880. 2 => $staffInfo ['avatar'],
  4881. 'date' => '',
  4882. 'date' => '',
  4883. 'opinion' => '',
  4884. 'status' => '',
  4885. 'rolename' => $rolename ['name']
  4886. );
  4887. array_push ( $roleArray, $exp );
  4888. }
  4889. $roleArrayCopy [$v [0]] = $roleArray;
  4890. // $verifyList[$k]['roleArray']=$roleArray;
  4891. }
  4892. $verifyList [$k] ['date'] = "";
  4893. $verifyList [$k] ['opinion'] = "";
  4894. $verifyList [$k] ['status'] = "";
  4895. if (empty ( $verifyStaff )) {
  4896. $verifyList [$k] ['date'] = "";
  4897. $verifyList [$k] ['opinion'] = "";
  4898. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4899. $verifyList [$k] ['status'] = 4;
  4900. $flag = false;
  4901. }
  4902. } else {
  4903. foreach ( $verifyStaff as $m => $u ) {
  4904. if ($v [0] == $m) {
  4905. $verifyList [$k] ['date'] = $u ['date'];
  4906. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4907. $verifyList [$k] ['status'] = $u ['status'];
  4908. $flag = false;
  4909. break;
  4910. }
  4911. }
  4912. $endStaffArray = end ( $verifyStaff );
  4913. if (isset ( $endStaffArray ['ROLE'] )) {
  4914. } else {
  4915. // $endKey=key($verifyStaff);
  4916. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4917. // $button=4;
  4918. // $verifyList[$k]['status']=4;
  4919. // }
  4920. }
  4921. }
  4922. }
  4923. $FC = @$rolename ['name'];
  4924. $rolename ['name'] = '';
  4925. if (! empty ( $roleId )) {
  4926. Doo::loadModel ( 'role' );
  4927. $role = new role ();
  4928. $rolename = $role->getOne ( array (
  4929. 'where' => 'rid=' . $roleId,
  4930. 'asArray' => true
  4931. ) );
  4932. }
  4933. if (! empty ( $verifyStaff ))
  4934. $endStaffArray = end ( $verifyStaff );
  4935. $KOP = false;
  4936. foreach ( $roleArrayCopy as $P => $A ) {
  4937. foreach ( $A as $MKI => $AVL ) {
  4938. if (! empty ( $verifyStaff )) {
  4939. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4940. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4941. $button = 4;
  4942. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4943. }
  4944. foreach ( $verifyStaff as $m => $u ) {
  4945. $AVLFK = $AVL [0] . '_R';
  4946. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4947. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4948. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4949. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4950. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4951. break;
  4952. }
  4953. }
  4954. } else {
  4955. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4956. $button = 4;
  4957. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4958. }
  4959. }
  4960. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4961. $KOP = true;
  4962. }
  4963. }
  4964. foreach ( $roleArrayCopy as $k => $v ) {
  4965. foreach ( $verifyList as $m => $n ) {
  4966. if ($n [0] == $k) {
  4967. array_splice ( $verifyList, $m, 1, $v );
  4968. }
  4969. }
  4970. }
  4971. // 费用执行人相关数据
  4972. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4973. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4974. foreach ( $executeCopy as $k => $v ) {
  4975. $executeCopy [$k] ['date'] = '';
  4976. $executeCopy [$k] ['opinion'] = '';
  4977. $executeCopy [$k] ['status'] = '';
  4978. if (! empty ( $executeStaff ))
  4979. foreach ( $executeStaff as $m => $u ) {
  4980. if ($v [0] == $m) {
  4981. $executeCopy [$k] ['date'] = $u ['date'];
  4982. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4983. $executeCopy [$k] ['status'] = $u ['status'];
  4984. break;
  4985. }
  4986. }
  4987. }
  4988. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4989. // print_r($verifyList);
  4990. $receiptList [$key] ['verifyList'] = $verifyList;
  4991. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4992. 'where' => 'sid=' . $value ['staff'],
  4993. 'asArray' => true
  4994. ) );
  4995. $receiptList [$key] ['button'] = $button;
  4996. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4997. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4998. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4999. $receiptList [$key] ['relust'] = $relust;
  5000. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5001. }
  5002. // print_r($receiptList);
  5003. // 获取审批日志
  5004. Doo::loadModel ( 'receiptLog' );
  5005. $receiptLog = new receiptLog ();
  5006. $rlList = array ();
  5007. $rlInfo = $receiptLog->getOne ( array (
  5008. 'where' => 'rid=' . $rid . ' and status=4',
  5009. 'asArray' => true
  5010. ) );
  5011. // $tijdate = $receiptLog->getOne ( array (
  5012. // 'where' => 'rid=' . $rid . ' and status=2',
  5013. // 'asc' => 'rlid',
  5014. // 'asArray' => true
  5015. // ) );
  5016. if (! empty ( $rlInfo )) {
  5017. $rlList = $receiptLog->find ( array (
  5018. 'where' => 'rid=' . $rid,
  5019. 'asc' => 'rlid',
  5020. 'asArray' => true
  5021. ) );
  5022. }
  5023. $RN=array();
  5024. if (!empty( $rolename ['staff'])){
  5025. $RN = @json_decode ( $rolename ['staff'] );
  5026. }
  5027. //
  5028. foreach ( $rlList as $key => $value ) {
  5029. $rlList [$key] ['rolename'] = '';
  5030. foreach ( $RN as $k => $v ) {
  5031. $id = explode ( "_", $v );
  5032. if ($id [0] == $value ['uid']) {
  5033. $rlList [$key] ['rolename'] = $FC;
  5034. break;
  5035. }
  5036. }
  5037. }
  5038. Doo::loadModel ( 'enclosur' );
  5039. $enclosur = new enclosur ();
  5040. $enclosurList = $enclosur->find ( array (
  5041. 'where' => 'rid=' . $rid,
  5042. 'asArray' => true
  5043. ) );
  5044. $enclosurHtml = '';
  5045. foreach ( $enclosurList as $value ) {
  5046. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5047. }
  5048. $data ['enclosurHtml'] = $enclosurHtml;
  5049. $receiptList [0] ['rlList'] = $rlList;
  5050. $data ['receiptList'] = $receiptList;
  5051. $data ['receiptList'][0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  5052. // print_r($receiptList);
  5053. $data ['memu'] = "receipt";
  5054. $data ['staff'] = $this->staff;
  5055. $data ['receiptMemu'] = 'approvalExpenses';
  5056. $data ['verifyId'] = $this->verifyId;
  5057. $data ['executeId'] = $this->executeId;
  5058. return $data;
  5059. }
  5060. function expensesDoc() {
  5061. $data=$this->_expensesDoc();
  5062. if(!empty($data['receiptList'][0]['itinerary2'])){
  5063. $this->render ( "/receipt/feeTraveView", $data );
  5064. }else{
  5065. $this->render ( "/admin/expensesDoc", $data );
  5066. }
  5067. }
  5068. function expensesDocPrint(){
  5069. $data=$this->_expensesDoc();
  5070. $this->render ( "/receipt/expensesDocPrint", $data );
  5071. }
  5072. function expensesEdi() {
  5073. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5074. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5075. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5076. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5077. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5078. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5079. if (empty ( $status ))
  5080. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5081. $vidList = array ();
  5082. $button = 0;
  5083. Doo::loadModel ( 'verify' );
  5084. Doo::loadModel ( 'receipt' );
  5085. Doo::loadModel ( 'staff' );
  5086. $staff = new staff ();
  5087. $receipt = new receipt ();
  5088. $verify = new verify ();
  5089. Doo::loadModel ( 'L_category' );
  5090. $Lcategory = new L_category ();
  5091. Doo::loadModel ( 'enclosur' );
  5092. $enclosur = new enclosur ();
  5093. // user verify ID
  5094. $verifyDetail = $verify->find ( array (
  5095. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5096. 'asArray' => true
  5097. ) );
  5098. foreach ( $verifyDetail as $key => $value ) {
  5099. array_push ( $vidList, $value ['vid'] );
  5100. }
  5101. $vid = implode ( ",", $vidList );
  5102. if (empty ( $verifyDetail ))
  5103. $vid = 0;
  5104. $categoryList = $Lcategory->find ( array (
  5105. 'asArray' => true
  5106. ) );
  5107. $staffList = $staff->find ( array (
  5108. 'where' => 'cid=' . $cid,
  5109. 'asArray' => true
  5110. ) );
  5111. $ap = "";
  5112. if ($status == 4) {
  5113. $ap = 4;
  5114. $status = 2;
  5115. }
  5116. // get Receipt By verifyID status 2
  5117. $receiptList = $receipt->find ( array (
  5118. 'where' => 'rid =' . $rid . ' and status=2',
  5119. 'desc' => 'rid',
  5120. 'asArray' => true
  5121. ) );
  5122. if (empty ( $receiptList )) {
  5123. die ( 'illegal request' );
  5124. }
  5125. $Locate = 0;
  5126. $roleId = 0;
  5127. if ($ap == 4)
  5128. $status = 4;
  5129. foreach ( $receiptList as $key => $value ) {
  5130. $receiptList [$key] ['Locate'] = $Locate;
  5131. $Locate ++;
  5132. $receiptList [$key] ['reviseDetail'] = array ();
  5133. if (! empty ( $value ['reviseDetail'] ))
  5134. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5135. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5136. $categoryDetil = $Lcategory->getOne ( array (
  5137. 'where' => 'cid=' . $value ['cid'],
  5138. 'asArray' => true
  5139. ) );
  5140. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5141. // 检测编辑状态
  5142. $verifyList = $verify->getOne ( array (
  5143. 'where' => 'vid=' . $value ['verify'],
  5144. 'asArray' => true
  5145. ) );
  5146. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5147. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5148. Doo::loadModel ( 'role' );
  5149. $role = new role ();
  5150. // print_r($verifyList);
  5151. $flag = true;
  5152. $roleKey = 0;
  5153. $endStaffArray = array ();
  5154. $roleArrayCopy = array ();
  5155. foreach ( $verifyList as $k => $v ) {
  5156. // init verifyStaff
  5157. if ($v [1] == 'ROLE') {
  5158. if (! empty ( $verifyStaff )) {
  5159. $endStaffArray = end ( $verifyStaff );
  5160. if ($v [0] == $endStaffArray ['nextStaff']) {
  5161. $roleId = $v [0];
  5162. }
  5163. }
  5164. $roleVerify = json_decode ( $v [3], true );
  5165. $roleKey = $k;
  5166. $roleArray = array ();
  5167. $rolename = $role->getOne ( array (
  5168. 'where' => 'rid=' . $v [0],
  5169. 'asArray' => true
  5170. ) );
  5171. foreach ( $roleVerify as $o => $p ) {
  5172. $staffID = explode ( '_', $p );
  5173. $staffInfo = $staff->getOne ( array (
  5174. 'where' => 'sid=' . $staffID [0],
  5175. 'asArray' => true
  5176. ) );
  5177. // print_r($staffID);
  5178. $exp = array (
  5179. 0 => $staffInfo ['sid'],
  5180. 1 => $staffID [1],
  5181. 2 => $staffInfo ['avatar'],
  5182. 'date' => '',
  5183. 'date' => '',
  5184. 'opinion' => '',
  5185. 'status' => '',
  5186. 'rolename' => $rolename ['name']
  5187. );
  5188. array_push ( $roleArray, $exp );
  5189. }
  5190. $roleArrayCopy [$v [0]] = $roleArray;
  5191. // $verifyList[$k]['roleArray']=$roleArray;
  5192. }
  5193. // print_r($roleArray);
  5194. $verifyList [$k] ['date'] = "";
  5195. $verifyList [$k] ['opinion'] = "";
  5196. $verifyList [$k] ['status'] = "";
  5197. if (empty ( $verifyStaff )) {
  5198. $verifyList [$k] ['date'] = "";
  5199. $verifyList [$k] ['opinion'] = "";
  5200. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5201. $verifyList [$k] ['status'] = 4;
  5202. $button = 4;
  5203. $flag = false;
  5204. }
  5205. } else {
  5206. foreach ( $verifyStaff as $m => $u ) {
  5207. if ($v [0] == $m) {
  5208. $verifyList [$k] ['date'] = $u ['date'];
  5209. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5210. $verifyList [$k] ['status'] = $u ['status'];
  5211. $flag = false;
  5212. break;
  5213. }
  5214. }
  5215. $endStaffArray = end ( $verifyStaff );
  5216. if (isset ( $endStaffArray ['ROLE'] )) {
  5217. } else {
  5218. $endKey = key ( $verifyStaff );
  5219. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5220. $button = 4;
  5221. $verifyList [$k] ['status'] = 4;
  5222. }
  5223. }
  5224. }
  5225. }
  5226. $rolename ['name'] = '';
  5227. if (! empty ( $roleId )) {
  5228. Doo::loadModel ( 'role' );
  5229. $role = new role ();
  5230. $rolename = $role->getOne ( array (
  5231. 'where' => 'rid=' . $roleId,
  5232. 'asArray' => true
  5233. ) );
  5234. }
  5235. if (! empty ( $verifyStaff ))
  5236. $endStaffArray = end ( $verifyStaff );
  5237. $KOP = false;
  5238. foreach ( $roleArrayCopy as $P => $A ) {
  5239. foreach ( $A as $MKI => $AVL ) {
  5240. if (! empty ( $verifyStaff )) {
  5241. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5242. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5243. $button = 4;
  5244. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5245. }
  5246. foreach ( $verifyStaff as $m => $u ) {
  5247. $AVLFK = $AVL [0] . '_R';
  5248. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5249. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5250. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5251. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5252. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5253. break;
  5254. }
  5255. }
  5256. } else {
  5257. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5258. $button = 4;
  5259. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5260. }
  5261. }
  5262. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5263. $KOP = true;
  5264. }
  5265. }
  5266. // print_r($roleArrayCopy);
  5267. // echo $roleKey;
  5268. foreach ( $roleArrayCopy as $k => $v ) {
  5269. foreach ( $verifyList as $m => $n ) {
  5270. if ($n [0] == $k) {
  5271. array_splice ( $verifyList, $m, 1, $v );
  5272. }
  5273. }
  5274. }
  5275. $receiptList [$key] ['verifyList'] = $verifyList;
  5276. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5277. 'where' => 'sid=' . $value ['staff'],
  5278. 'asArray' => true
  5279. ) );
  5280. $receiptList [$key] ['button'] = $button;
  5281. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  5282. }
  5283. // $data['verifyDetail']=$verifyDetail;
  5284. $mothHtml = "";
  5285. for($i = 1; $i <= 12; $i ++) {
  5286. if ($month == $i)
  5287. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5288. else
  5289. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5290. }
  5291. // 获取审批日志
  5292. Doo::loadModel ( 'receiptLog' );
  5293. $receiptLog = new receiptLog ();
  5294. $rlList = array ();
  5295. $rlInfo = $receiptLog->getOne ( array (
  5296. 'where' => 'rid=' . $rid . ' and status=4',
  5297. 'asArray' => true
  5298. ) );
  5299. $tijdate = $receiptLog->getOne ( array (
  5300. 'where' => 'rid=' . $rid . ' and status=2',
  5301. 'asc' => 'rlid',
  5302. 'asArray' => true
  5303. ) );
  5304. if (! empty ( $rlInfo )) {
  5305. $rlList = $receiptLog->find ( array (
  5306. 'where' => 'rid=' . $rid,
  5307. 'asc' => 'rlid',
  5308. 'asArray' => true
  5309. ) );
  5310. }
  5311. $receiptList [0] ['rlList'] = $rlList;
  5312. $enclosurList = $enclosur->find ( array (
  5313. 'where' => 'rid=' . $rid,
  5314. 'asArray' => true
  5315. ) );
  5316. $enclosurHtml = '';
  5317. foreach ( $enclosurList as $value ) {
  5318. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5319. }
  5320. // print_r($receiptList);
  5321. $data ['rid'] = $rid;
  5322. $data ['enclosurHtml'] = $enclosurHtml;
  5323. $data ['rolename'] = $rolename ['name'];
  5324. $data ['datetij'] = $tijdate ['date'];
  5325. $data ['mothHtml'] = $mothHtml;
  5326. $data ['receiptList'] = $receiptList;
  5327. $data ['receiptApprovalCount'] = count ( $receiptList );
  5328. $data ['status'] = $status;
  5329. $data ['year'] = $year;
  5330. $data ['categoryList'] = $categoryList;
  5331. $data ['staffList'] = $staffList;
  5332. $data ['cid'] = $cid;
  5333. $data ['sid'] = $sid;
  5334. $data ['ap'] = $ap;
  5335. $data ['memu'] = "receipt";
  5336. $data ['staff'] = $this->staff;
  5337. $data ['receiptMemu'] = 'approvalExpenses';
  5338. $data ['verifyId'] = $this->verifyId;
  5339. $data ['executeId'] = $this->executeId;
  5340. $this->render ( "/admin/expensesEdi", $data );
  5341. }
  5342. function expensesDefray() {
  5343. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5344. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  5345. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5346. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  5347. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  5348. if (! empty ( $rid )) {
  5349. Doo::loadModel ( "verify" );
  5350. $verify = new verify ();
  5351. Doo::loadModel ( "receiptDetail" );
  5352. $receiptDetailObj = new receiptDetail ();
  5353. Doo::loadModel ( "itemStatistics" );
  5354. Doo::loadModel ( "statistics" );
  5355. $statistics = new statistics ();
  5356. $itemStatistics = new itemStatistics ();
  5357. Doo::loadModel ( "receipt" );
  5358. $receipt = new receipt ();
  5359. Doo::loadModel ( "loanReceipt" );
  5360. $loanReceipt = new loanReceipt ();
  5361. $receiptDetail = $receipt->getOne ( array (
  5362. 'where' => 'rid=' . $rid . ' and status=2 ',
  5363. 'asArray' => true
  5364. ) );
  5365. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  5366. $nsflag = true;
  5367. foreach ( $nslist as $value ) {
  5368. if ($value == $this->staff ['0'] ['sid']) {
  5369. $nsflag = false;
  5370. break;
  5371. }
  5372. }
  5373. // print_r($nslist);die;
  5374. if (empty ( $receiptDetail ) || $nsflag)
  5375. return "/approvalExpenses/pendApproval";
  5376. $verifyDetail = $verify->getOne ( array (
  5377. 'where' => ' vid =' . $receiptDetail ['verify'],
  5378. 'asArray' => true
  5379. ) );
  5380. $verifyString = $verifyDetail ['staff'];
  5381. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  5382. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  5383. if (empty ( $opinion )) {
  5384. if ($status == 3)
  5385. $opinion = "终止";
  5386. else
  5387. $opinion = "同意支付";
  5388. }
  5389. $nowStaff = 0;
  5390. $nowStaffList = array ();
  5391. if (empty ( $verifyStaff )) {
  5392. // 还需加入是否已经进入角色审批
  5393. if ($verifyDetail [0] [1] == 'ROLE') {
  5394. // print_r($verifyDetail);echo "ddd";
  5395. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  5396. foreach ( $vStaffString as $key => $value ) {
  5397. $staffK = explode ( "_", $value );
  5398. if ($staffK [0] != $this->staff [0] ['sid'])
  5399. array_push ( $nowStaffList, $staffK [0] );
  5400. }
  5401. // print_r($verifyDetail);
  5402. // die;
  5403. if (! empty ( $nowStaffList )) {
  5404. $nowStaff = implode ( ',', $nowStaffList );
  5405. $verifyStaff = array (
  5406. $this->staff [0] ['sid'] . "_R" => array (
  5407. 'date' => date ( 'Y-m-d' ),
  5408. 'opinion' => $opinion,
  5409. 'status' => $status,
  5410. 'nextStaff' => $verifyDetail [0] [0],
  5411. 'ROLE' => 1
  5412. )
  5413. );
  5414. } else {
  5415. $nowStaff = $verifyDetail [1] [0];
  5416. $verifyStaff = array (
  5417. $this->staff [0] ['sid'] . "_R" => array (
  5418. 'date' => date ( 'Y-m-d' ),
  5419. 'opinion' => $opinion,
  5420. 'status' => $status,
  5421. 'nextStaff' => $verifyDetail [1] [0]
  5422. )
  5423. );
  5424. }
  5425. } else {
  5426. if ($verifyDetail [1] [1] == 'ROLE') {
  5427. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  5428. // echo "dd";
  5429. foreach ( $vStaffString as $key => $value ) {
  5430. $staffK = explode ( "_", $value );
  5431. array_push ( $nowStaffList, $staffK [0] );
  5432. }
  5433. $nowStaff = implode ( ',', $nowStaffList );
  5434. $verifyStaff = array (
  5435. $this->staff [0] ['sid'] => array (
  5436. 'date' => date ( 'Y-m-d' ),
  5437. 'opinion' => $opinion,
  5438. 'status' => $status,
  5439. 'nextStaff' => $verifyDetail [1] [0],
  5440. 'ROLE' => 1
  5441. )
  5442. );
  5443. } else {
  5444. $nowStaff = $verifyDetail [1] [0];
  5445. $verifyStaff = array (
  5446. $this->staff [0] ['sid'] => array (
  5447. 'date' => date ( 'Y-m-d' ),
  5448. 'opinion' => $opinion,
  5449. 'status' => $status,
  5450. 'nextStaff' => $verifyDetail [1] [0]
  5451. )
  5452. );
  5453. }
  5454. }
  5455. if ($status == 3)
  5456. $verifyStaff = array (
  5457. 'final' => $status,
  5458. $this->staff [0] ['sid'] => array (
  5459. 'date' => date ( 'Y-m-d' ),
  5460. 'opinion' => $opinion,
  5461. 'status' => $status
  5462. )
  5463. );
  5464. $vStaffString = json_encode ( $verifyStaff );
  5465. $receipt->nowStaff = $nowStaff;
  5466. $receipt->verifyStaff = $vStaffString;
  5467. $loanReceipt->nowStaff = $nowStaff;
  5468. $loanReceipt->verifyStaff = $vStaffString;
  5469. } else {
  5470. $VS = end ( $verifyStaff );
  5471. // 非角色审批
  5472. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  5473. $nextStaff = 0;
  5474. $roleSTF = false;
  5475. foreach ( $verifyDetail as $key => $value ) {
  5476. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  5477. if (isset ( $verifyDetail [$key + 1] )) {
  5478. $nextStaff = $verifyDetail [$key + 1] [0];
  5479. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  5480. $roleSTF = true;
  5481. }
  5482. break;
  5483. }
  5484. }
  5485. if (! $roleSTF) {
  5486. $nowStaff = $nextStaff;
  5487. $verifyStaff [$this->staff [0] ['sid']] = array (
  5488. 'date' => date ( 'Y-m-d' ),
  5489. 'opinion' => $opinion,
  5490. 'status' => $status,
  5491. 'nextStaff' => $nextStaff
  5492. );
  5493. } else {
  5494. // 获取角色下的所有用户ID
  5495. $nowStaffList = array ();
  5496. foreach ( $verifyDetail as $vfk ) {
  5497. if ($vfk [1] == 'ROLE') {
  5498. $vStaffString = json_decode ( $vfk [3] );
  5499. foreach ( $vStaffString as $key => $value ) {
  5500. $staffK = explode ( "_", $value );
  5501. array_push ( $nowStaffList, $staffK [0] );
  5502. }
  5503. }
  5504. }
  5505. $nowStaff = implode ( ',', $nowStaffList );
  5506. $verifyStaff [$this->staff [0] ['sid']] = array (
  5507. 'date' => date ( 'Y-m-d' ),
  5508. 'opinion' => $opinion,
  5509. 'status' => $status,
  5510. 'nextStaff' => $nextStaff,
  5511. 'ROLE' => 0
  5512. );
  5513. }
  5514. if ($status == 3) {
  5515. $verifyStaff ['final'] = $status;
  5516. $verifyStaff [$this->staff [0] ['sid']] = array (
  5517. 'date' => date ( 'Y-m-d' ),
  5518. 'opinion' => $opinion,
  5519. 'status' => $status
  5520. );
  5521. }
  5522. $vStaffString = json_encode ( $verifyStaff );
  5523. $receipt->nowStaff = $nowStaff;
  5524. $receipt->verifyStaff = $vStaffString;
  5525. $loanReceipt->nowStaff = $nowStaff;
  5526. $loanReceipt->verifyStaff = $vStaffString;
  5527. }
  5528. // 角色审批
  5529. if (isset ( $VS ['ROLE'] )) {
  5530. // 找出角色人 当前审批角色组
  5531. $verifyJSStaff = array ();
  5532. $nowStaffList2 = array ();
  5533. foreach ( $verifyDetail as $key => $value ) {
  5534. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  5535. $verifyJSStaff = json_decode ( $value [3] );
  5536. foreach ( $verifyJSStaff as $m ) {
  5537. $staffK = explode ( "_", $m );
  5538. array_push ( $nowStaffList2, $staffK [0] );
  5539. }
  5540. // print_r($nowStaffList2);
  5541. }
  5542. }
  5543. $RoleVerifyStaff = array ();
  5544. foreach ( $verifyStaff as $key => $value ) {
  5545. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  5546. foreach ( $nowStaffList2 as $m ) {
  5547. if ($key == $m . "_R")
  5548. $RoleVerifyStaff [$key] = $value;
  5549. }
  5550. }
  5551. }
  5552. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  5553. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  5554. // 下一个审批人ID
  5555. $nextStaff = 0;
  5556. $falg = false;
  5557. foreach ( $verifyDetail as $key => $value ) {
  5558. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  5559. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  5560. $falg = true;
  5561. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  5562. $nowStaffList = array ();
  5563. foreach ( $vStaffString as $v ) {
  5564. $staffK = explode ( "_", $v );
  5565. array_push ( $nowStaffList, $staffK [0] );
  5566. }
  5567. $nowStaff = implode ( ',', $nowStaffList );
  5568. $nextStaff = $verifyDetail [$key + 1] [0];
  5569. } elseif (isset ( $verifyDetail [$key + 1] )) {
  5570. $nextStaff = $verifyDetail [$key + 1] [0];
  5571. $nowStaff = $nextStaff;
  5572. } else
  5573. $nowStaff = '';
  5574. break;
  5575. }
  5576. }
  5577. if ($falg)
  5578. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5579. 'date' => date ( 'Y-m-d' ),
  5580. 'opinion' => $opinion,
  5581. 'status' => $status,
  5582. 'nextStaff' => $nextStaff,
  5583. 'ROLE' => 1
  5584. );
  5585. else
  5586. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5587. 'date' => date ( 'Y-m-d' ),
  5588. 'opinion' => $opinion,
  5589. 'status' => $status,
  5590. 'nextStaff' => $nextStaff
  5591. );
  5592. // print_r($verifyStaff);
  5593. // echo $nowStaff;die;
  5594. } else { // 进入下一个角色或者审批人
  5595. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  5596. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5597. 'date' => date ( 'Y-m-d' ),
  5598. 'opinion' => $opinion,
  5599. 'status' => $status,
  5600. 'nextStaff' => $VS ['nextStaff'],
  5601. 'ROLE' => 1
  5602. );
  5603. }
  5604. if ($status == 3) {
  5605. $verifyStaff ['final'] = $status;
  5606. $verifyStaff [$this->staff [0] ['sid']] = array (
  5607. 'date' => date ( 'Y-m-d' ),
  5608. 'opinion' => $opinion,
  5609. 'status' => $status
  5610. );
  5611. }
  5612. $vStaffString = json_encode ( $verifyStaff );
  5613. $receipt->verifyStaff = $vStaffString;
  5614. $receipt->nowStaff = $nowStaff;
  5615. $loanReceipt->nowStaff = $nowStaff;
  5616. $loanReceipt->verifyStaff = $vStaffString;
  5617. }
  5618. // print_r($verifyStaff);die;
  5619. }
  5620. $roleKey = 0;
  5621. $roleId = 0;
  5622. $verifyDetailCopy = array ();
  5623. foreach ( $verifyDetail as $k => $v ) {
  5624. if ($v [1] == 'ROLE') {
  5625. $roleId = $v [0];
  5626. $roleVerify = json_decode ( $v [3], true );
  5627. $roleKey = $k;
  5628. $roleArray = array ();
  5629. foreach ( $roleVerify as $o => $p ) {
  5630. $staffID = explode ( '_', $p );
  5631. $exp = array (
  5632. 0 => $staffID [0],
  5633. 1 => $staffID [1]
  5634. );
  5635. array_push ( $roleArray, $exp );
  5636. }
  5637. $verifyDetailCopy [$v [0]] = $roleArray;
  5638. }
  5639. }
  5640. // print_r($verifyDetail);
  5641. foreach ( $verifyDetailCopy as $k => $v ) {
  5642. foreach ( $verifyDetail as $m => $n ) {
  5643. if ($n [0] == $k) {
  5644. array_splice ( $verifyDetail, $m, 1, $v );
  5645. }
  5646. }
  5647. }
  5648. // 审批日志
  5649. if (! isset ( $verifyStaff ['final'] )) {
  5650. Doo::loadModel ( "receiptLog" );
  5651. $receiptLog = new receiptLog ();
  5652. if (! empty ( $roleId )) {
  5653. Doo::loadModel ( "role" );
  5654. $role = new role ();
  5655. $roleInfo = $role->getOne ( array (
  5656. 'where' => 'rid=' . $roleId,
  5657. 'asArray' => true
  5658. ) );
  5659. $receiptLog->rolename = $roleInfo ['name'];
  5660. }
  5661. $receiptLog->username = $this->staff [0] ['username'];
  5662. $receiptLog->uid = $this->staff [0] ['sid'];
  5663. $receiptLog->date = date ( "Y-m-d" );
  5664. $receiptLog->opinion = $opinion;
  5665. $receiptLog->img = $this->staff [0] ['avatar'];
  5666. $receiptLog->status = 1;
  5667. $receiptLog->rid = $rid;
  5668. $receiptLog->insert ();
  5669. }
  5670. if (isset ( $verifyStaff ['final'] )) { // rDetail
  5671. $receipt->status = 3;
  5672. $receipt->verifyBreakup = $verifyString;
  5673. $receiptDetailObj->status = 3;
  5674. $receiptDetailObj->update ( array (
  5675. 'where' => 'rid=' . $rid
  5676. ) );
  5677. // 微信企业号通知
  5678. $this->setWXMsg ( $rid, 3 );
  5679. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  5680. $receipt->status = 6;
  5681. $receipt->pastDate = date ( "Y-m-d" );
  5682. $receipt->isBK = 1;
  5683. $loanReceipt->verifyBreakup = $verifyString;
  5684. $loanReceipt->status = 1;
  5685. $loanReceipt->pastDate = date ( "Y-m-d" );
  5686. //生成流水后 不更新汇款金额
  5687. Doo::loadModel ( 'wasteBook' );
  5688. $wasteBook = new wasteBook ();
  5689. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  5690. if (empty($wbDetail)){
  5691. $loanReceipt->amount = $receiptDetail ['amount'];
  5692. }
  5693. $loanReceipt->update ( array (
  5694. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  5695. ) );
  5696. // 微信企业号通知
  5697. $this->setWXMsg ( $rid, 1 );
  5698. }
  5699. $receipt->amount = $receiptDetail['sum'];
  5700. $receipt->update ( array (
  5701. 'where' => ' rid = ' . $rid
  5702. ) );
  5703. // 进入下一条审批费用新加需求
  5704. $vidList = array ();
  5705. $verifyDetail = $verify->find ( array (
  5706. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  5707. 'asArray' => true
  5708. ) );
  5709. foreach ( $verifyDetail as $key => $value ) {
  5710. array_push ( $vidList, $value ['vid'] );
  5711. }
  5712. $vid = implode ( ",", $vidList );
  5713. if (empty ( $verifyDetail ))
  5714. $vid = 0;
  5715. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  5716. $receipt = new receipt ();
  5717. $rd = $receipt->getOne ( array (
  5718. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  5719. 'asc' => 'rid',
  5720. 'asArray' => true
  5721. ) );
  5722. if (empty ( $rd )) {
  5723. return '/approvalExpenses/pendApproval';
  5724. }
  5725. if ($rd ['Rtype'] == 1) {
  5726. if ($rd ['isBK'] == 1) {
  5727. return '/receiptburEdi/' . $rd ['rid'];
  5728. } else {
  5729. return '/expensesEdi/' . $rd ['rid'];
  5730. }
  5731. } elseif ($rd ['Rtype'] == 2) {
  5732. return '/remitApproval/' . $rd ['rid'];
  5733. } else {
  5734. return '/receiptburEdi/' . $rd ['rid'];
  5735. }
  5736. // return "/approvalExpenses/pendApproval";
  5737. }
  5738. }
  5739. function ajaxExamineExe() {
  5740. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5741. Doo::loadModel ( 'receipt' );
  5742. $receipt = new receipt ();
  5743. Doo::loadClass ( 'XDeode' );
  5744. $XDeode = new XDeode ( 5 );
  5745. if (! empty ( $rid )) {
  5746. $rLRes = $receipt->find ( array (
  5747. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  5748. 'asArray' => true
  5749. ) );
  5750. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  5751. echo json_encode ( array (
  5752. 'status' => 1,
  5753. 'receipt' => $rLRes [0]
  5754. ) );
  5755. die ();
  5756. }
  5757. echo json_encode ( array (
  5758. 'status' => 0,
  5759. 'receipt' => array ()
  5760. ) );
  5761. die ();
  5762. }
  5763. function implement() {
  5764. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5765. $Rtype = isset ( $this->params ['Rtype'] ) ? $this->params ['Rtype'] : '';
  5766. Doo::loadClass ( 'XDeode' );
  5767. $XDeode = new XDeode ( 5 );
  5768. Doo::loadModel ( 'receipt' );
  5769. $receipt = new receipt ();
  5770. Doo::loadModel ( 'L_category' );
  5771. $Lcategory = new L_category ();
  5772. Doo::loadModel ( 'verify' );
  5773. $verify = new verify ();
  5774. Doo::loadModel ( 'staff' );
  5775. $staff = new staff ();
  5776. Doo::loadModel ( "execute" );
  5777. $execute = new execute ();
  5778. $rid = $XDeode->decode ( $rid );
  5779. $receiptList = $receipt->find ( array (
  5780. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  5781. 'desc' => 'rid',
  5782. 'asArray' => true
  5783. ) );
  5784. Doo::loadModel ( 'loanReceipt' );
  5785. $loanReceipt = new loanReceipt ();
  5786. // print_r($receiptList);
  5787. $loanList = array ();
  5788. if (! isset ( $receiptList ))
  5789. $loanList = $loanReceipt->find ( array (
  5790. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5791. 'desc' => 'rid',
  5792. 'asArray' => true
  5793. ) );
  5794. $Locate = 0;
  5795. $roleId = 0;
  5796. $button = 0;
  5797. foreach ( $loanList as $key => $value ) {
  5798. $loanList [$key] ['Locate'] = $Locate;
  5799. $Locate ++;
  5800. $loanList [$key] ['reviseDetail'] = array ();
  5801. if (! empty ( $value ['reviseDetail'] ))
  5802. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5803. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5804. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5805. $categoryDetil = $Lcategory->getOne ( array (
  5806. 'where' => 'cid=' . $value ['cid'],
  5807. 'asArray' => true
  5808. ) );
  5809. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5810. // 检测编辑状态
  5811. $verifyList = $verify->getOne ( array (
  5812. 'where' => 'vid=' . $value ['verify'],
  5813. 'asArray' => true
  5814. ) );
  5815. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5816. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5817. Doo::loadModel ( 'role' );
  5818. $role = new role ();
  5819. $flag = true;
  5820. $roleKey = 0;
  5821. $endStaffArray = array ();
  5822. $roleArrayCopy = array ();
  5823. foreach ( $verifyList as $k => $v ) {
  5824. // init verifyStaff
  5825. if ($v [1] == 'ROLE') {
  5826. if (! empty ( $verifyStaff )) {
  5827. $endStaffArray = end ( $verifyStaff );
  5828. // if ($v[0]==$endStaffArray['nextStaff']){
  5829. // $roleId=$v[0];
  5830. // }
  5831. }
  5832. $roleVerify = json_decode ( $v [3], true );
  5833. $roleKey = $k;
  5834. $roleArray = array ();
  5835. $rolename = $role->getOne ( array (
  5836. 'where' => 'rid=' . $v [0],
  5837. 'asArray' => true
  5838. ) );
  5839. foreach ( $roleVerify as $o => $p ) {
  5840. $staffID = explode ( '_', $p );
  5841. $staffInfo = $staff->getOne ( array (
  5842. 'where' => 'sid=' . $staffID [0],
  5843. 'asArray' => true
  5844. ) );
  5845. // print_r($staffID);
  5846. $exp = array (
  5847. 0 => $staffInfo ['sid'],
  5848. 1 => $staffID [1],
  5849. 2 => $staffInfo ['avatar'],
  5850. 'date' => '',
  5851. 'date' => '',
  5852. 'opinion' => '',
  5853. 'status' => '',
  5854. 'rolename' => $rolename ['name']
  5855. );
  5856. array_push ( $roleArray, $exp );
  5857. }
  5858. $roleArrayCopy [$v [0]] = $roleArray;
  5859. // $verifyList[$k]['roleArray']=$roleArray;
  5860. }
  5861. $verifyList [$k] ['date'] = "";
  5862. $verifyList [$k] ['opinion'] = "";
  5863. $verifyList [$k] ['status'] = "";
  5864. if (empty ( $verifyStaff )) {
  5865. $verifyList [$k] ['date'] = "";
  5866. $verifyList [$k] ['opinion'] = "";
  5867. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5868. $verifyList [$k] ['status'] = 4;
  5869. $flag = false;
  5870. }
  5871. } else {
  5872. foreach ( $verifyStaff as $m => $u ) {
  5873. if ($v [0] == $m) {
  5874. $verifyList [$k] ['date'] = $u ['date'];
  5875. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5876. $verifyList [$k] ['status'] = $u ['status'];
  5877. $flag = false;
  5878. break;
  5879. }
  5880. }
  5881. $endStaffArray = end ( $verifyStaff );
  5882. if (isset ( $endStaffArray ['ROLE'] )) {
  5883. } else {
  5884. // $endKey=key($verifyStaff);
  5885. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5886. // $button=4;
  5887. // $verifyList[$k]['status']=4;
  5888. // }
  5889. }
  5890. }
  5891. }
  5892. $rolename ['name'] = '';
  5893. if (! empty ( $roleId )) {
  5894. Doo::loadModel ( 'role' );
  5895. $role = new role ();
  5896. $rolename = $role->getOne ( array (
  5897. 'where' => 'rid=' . $roleId,
  5898. 'asArray' => true
  5899. ) );
  5900. }
  5901. if (! empty ( $verifyStaff ))
  5902. $endStaffArray = end ( $verifyStaff );
  5903. $KOP = false;
  5904. foreach ( $roleArrayCopy as $P => $A ) {
  5905. foreach ( $A as $MKI => $AVL ) {
  5906. if (! empty ( $verifyStaff )) {
  5907. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5908. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5909. $button = 4;
  5910. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5911. }
  5912. foreach ( $verifyStaff as $m => $u ) {
  5913. $AVLFK = $AVL [0] . '_R';
  5914. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5915. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5916. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5917. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5918. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5919. break;
  5920. }
  5921. }
  5922. } else {
  5923. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5924. $button = 4;
  5925. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5926. }
  5927. }
  5928. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5929. $KOP = true;
  5930. }
  5931. }
  5932. foreach ( $roleArrayCopy as $k => $v ) {
  5933. foreach ( $verifyList as $m => $n ) {
  5934. if ($n [0] == $k) {
  5935. array_splice ( $verifyList, $m, 1, $v );
  5936. }
  5937. }
  5938. }
  5939. $loanList [$key] ['verifyList'] = $verifyList;
  5940. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  5941. 'where' => 'sid=' . $value ['staff'],
  5942. 'asArray' => true
  5943. ) );
  5944. }
  5945. $data ['loanList'] = $loanList;
  5946. $Locate = 0;
  5947. $roleId = 0;
  5948. $button = 0;
  5949. Doo::loadClass ( 'XDeode' );
  5950. $XDeode = new XDeode ( 5 );
  5951. foreach ( $receiptList as $key => $value ) {
  5952. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  5953. $button2 = 0;
  5954. $receiptList [$key] ['Locate'] = $Locate;
  5955. $Locate ++;
  5956. $receiptList [$key] ['reviseDetail'] = array ();
  5957. if (! empty ( $value ['reviseDetail'] ))
  5958. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5959. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5960. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5961. $categoryDetil = $Lcategory->getOne ( array (
  5962. 'where' => 'cid=' . $value ['cid'],
  5963. 'asArray' => true
  5964. ) );
  5965. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5966. $executeList = json_decode ( $value ['executeCopy'], true );
  5967. $executeStaff = array ();
  5968. if (! empty ( $value ['executeStaff'] ))
  5969. $executeStaff = json_decode ( $value ['executeStaff'], true );
  5970. if (isset ( $executeList )) {
  5971. foreach ( $executeList as $op => $lo ) {
  5972. $executeList [$op] ['date'] = "";
  5973. $executeList [$op] ['opinion'] = "";
  5974. $executeList [$op] ['status'] = "";
  5975. foreach ( $executeStaff as $m => $u ) {
  5976. if ($lo [0] == $m) {
  5977. $executeList [$op] ['date'] = $u ['date'];
  5978. $executeList [$op] ['opinion'] = $u ['opinion'];
  5979. $executeList [$op] ['status'] = $u ['status'];
  5980. break;
  5981. }
  5982. }
  5983. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  5984. $button2 = 1;
  5985. $executeList [$op] ['status'] = 4;
  5986. }
  5987. }
  5988. }
  5989. // 检测编辑状态
  5990. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  5991. $verifyList ['staff'] = $value ['verifyBreakup'];
  5992. } else
  5993. $verifyList = $verify->getOne ( array (
  5994. 'where' => 'vid=' . $value ['verify'],
  5995. 'asArray' => true
  5996. ) );
  5997. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5998. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5999. Doo::loadModel ( 'role' );
  6000. $role = new role ();
  6001. if ($verifyList == NULL)
  6002. $verifyList = array ();
  6003. $flag = true;
  6004. $roleKey = 0;
  6005. $endStaffArray = array ();
  6006. $roleArrayCopy = array ();
  6007. foreach ( $verifyList as $k => $v ) {
  6008. // init verifyStaff
  6009. if ($v [1] == 'ROLE') {
  6010. if (! empty ( $verifyStaff )) {
  6011. $endStaffArray = end ( $verifyStaff );
  6012. // if ($v[0]==$endStaffArray['nextStaff']){
  6013. // $roleId=$v[0];
  6014. // }
  6015. }
  6016. $roleVerify = json_decode ( $v [3], true );
  6017. $roleKey = $k;
  6018. $roleArray = array ();
  6019. $rolename = $role->getOne ( array (
  6020. 'where' => 'rid=' . $v [0],
  6021. 'asArray' => true
  6022. ) );
  6023. foreach ( $roleVerify as $o => $p ) {
  6024. $staffID = explode ( '_', $p );
  6025. $staffInfo = $staff->getOne ( array (
  6026. 'where' => 'sid=' . $staffID [0],
  6027. 'asArray' => true
  6028. ) );
  6029. // print_r($staffID);
  6030. $exp = array (
  6031. 0 => $staffInfo ['sid'],
  6032. 1 => $staffID [1],
  6033. 2 => $staffInfo ['avatar'],
  6034. 'date' => '',
  6035. 'date' => '',
  6036. 'opinion' => '',
  6037. 'status' => '',
  6038. 'rolename' => $rolename ['name']
  6039. );
  6040. array_push ( $roleArray, $exp );
  6041. }
  6042. $roleArrayCopy [$v [0]] = $roleArray;
  6043. // $verifyList[$k]['roleArray']=$roleArray;
  6044. }
  6045. $verifyList [$k] ['date'] = "";
  6046. $verifyList [$k] ['opinion'] = "";
  6047. $verifyList [$k] ['status'] = "";
  6048. if (empty ( $verifyStaff )) {
  6049. $verifyList [$k] ['date'] = "";
  6050. $verifyList [$k] ['opinion'] = "";
  6051. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6052. $verifyList [$k] ['status'] = 4;
  6053. $flag = false;
  6054. }
  6055. } else {
  6056. foreach ( $verifyStaff as $m => $u ) {
  6057. if ($v [0] == $m) {
  6058. $verifyList [$k] ['date'] = $u ['date'];
  6059. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6060. $verifyList [$k] ['status'] = $u ['status'];
  6061. $flag = false;
  6062. break;
  6063. }
  6064. }
  6065. $endStaffArray = end ( $verifyStaff );
  6066. if (isset ( $endStaffArray ['ROLE'] )) {
  6067. } else {
  6068. // $endKey=key($verifyStaff);
  6069. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6070. // $button=4;
  6071. // $verifyList[$k]['status']=4;
  6072. // }
  6073. }
  6074. }
  6075. }
  6076. $rolename ['name'] = '';
  6077. if (! empty ( $roleId )) {
  6078. Doo::loadModel ( 'role' );
  6079. $role = new role ();
  6080. $rolename = $role->getOne ( array (
  6081. 'where' => 'rid=' . $roleId,
  6082. 'asArray' => true
  6083. ) );
  6084. }
  6085. if (! empty ( $verifyStaff ))
  6086. $endStaffArray = end ( $verifyStaff );
  6087. $KOP = false;
  6088. foreach ( $roleArrayCopy as $P => $A ) {
  6089. foreach ( $A as $MKI => $AVL ) {
  6090. if (! empty ( $verifyStaff )) {
  6091. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6092. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6093. $button = 4;
  6094. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6095. }
  6096. foreach ( $verifyStaff as $m => $u ) {
  6097. $AVLFK = $AVL [0] . '_R';
  6098. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6099. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6100. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6101. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6102. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6103. break;
  6104. }
  6105. }
  6106. } else {
  6107. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6108. $button = 4;
  6109. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6110. }
  6111. }
  6112. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6113. $KOP = true;
  6114. }
  6115. }
  6116. foreach ( $roleArrayCopy as $k => $v ) {
  6117. foreach ( $verifyList as $m => $n ) {
  6118. if ($n [0] == $k) {
  6119. array_splice ( $verifyList, $m, 1, $v );
  6120. }
  6121. }
  6122. }
  6123. $receiptList [$key] ['verifyList'] = $verifyList;
  6124. $receiptList [$key] ['executeList'] = $executeList;
  6125. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6126. 'where' => 'sid=' . $value ['staff'],
  6127. 'asArray' => true
  6128. ) );
  6129. $receiptList [$key] ['button2'] = $button2;
  6130. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  6131. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  6132. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  6133. $receiptList [$key] ['relust'] = $relust;
  6134. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  6135. $receiptList [$key] ['amountABS'] = abs ( $value ['amount'] );
  6136. }
  6137. //执行人是否是最后一位
  6138. $executeCopy = json_decode ( $receiptList [0] ['executeCopy'], true );
  6139. $executeStaff = json_decode ( $receiptList [0] ['executeStaff'], true );
  6140. $executePrimary=count($executeCopy)-1;
  6141. $lastOne=true;
  6142. if($executePrimary!=count($executeStaff)){
  6143. $lastOne=false;
  6144. }
  6145. $data['lastOne']=$lastOne;
  6146. // 是否写入过流水
  6147. $accountType = 0;
  6148. if ($receiptList [0] ['Rtype'] == 0) {
  6149. $accountType = 3;
  6150. } elseif ($receiptList [0] ['Rtype'] == 1) {
  6151. if (!empty($receiptList [0]['accountItem']) )
  6152. $accountType = 2;
  6153. else
  6154. $accountType = 1;
  6155. } elseif ($receiptList [0] ['Rtype'] == 2) {
  6156. $accountType = 4;
  6157. } elseif ($receiptList [0] ['Rtype'] == 3) {
  6158. $accountType = 12;
  6159. }
  6160. Doo::loadModel ( 'wasteBook' );
  6161. $wasteBook = new wasteBook ();
  6162. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  6163. $data ['wbDetail'] = $wbDetail;
  6164. $wbDetailLoan=array();
  6165. if ($accountType==2){
  6166. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  6167. }
  6168. $data ['wbDetailLoan'] = $wbDetailLoan;
  6169. $data['inputDate']=date ( "Y-m-d H:i:s" );
  6170. //print_r($wbDetail);
  6171. $data ['receiptList'] = $receiptList;
  6172. $data ['memu'] = "receipt";
  6173. $data ['staff'] = $this->staff;
  6174. $data ['receiptMemu'] = 'implement';
  6175. $data ['verifyId'] = $this->verifyId;
  6176. $data ['executeId'] = $this->executeId;
  6177. if ($Rtype=="loan"){
  6178. $this->render ( "/receipt/receiptImplementLoan", $data );
  6179. }elseif($Rtype=="receipt"){
  6180. if($receiptList[0]['receiptClass']==2){
  6181. //TODO 费用执行行程单2.0
  6182. if(!empty($receiptList[0]['itinerary2'])){
  6183. $this->render ( "/receipt/receiptImplementTrave2", $data );
  6184. }else{
  6185. $this->render ( "/receipt/receiptImplementTrave", $data );
  6186. }
  6187. }else{
  6188. $this->render ( "/receipt/receiptImplement", $data );
  6189. }
  6190. }elseif($Rtype=="public"){
  6191. $this->render ( "/receipt/receiptImplementPublic", $data );
  6192. }else{
  6193. //$this->render ( "/admin/implement", $data );
  6194. }
  6195. }
  6196. function implementDo() {
  6197. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  6198. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  6199. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  6200. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  6201. // $ab = '';
  6202. // if ($accountBank == 'CGBDeposit')
  6203. // $ab = '纵横广发';
  6204. // elseif ($accountBank == 'ICBCDeposit')
  6205. // $ab = '纵横工行';
  6206. // elseif ($accountBank == 'HUADeposit')
  6207. // $ab = '华润银行';
  6208. // elseif ($accountBank == 'PersonalDeposit')
  6209. // $ab = '个人广发';
  6210. // if (empty ( $ab ))
  6211. // die ( 'illegal request--22' );
  6212. if (! empty ( $rid )) {
  6213. Doo::loadModel ( 'receipt' );
  6214. $receipt = new receipt ();
  6215. Doo::loadClass ( 'XDeode' );
  6216. $XDeode = new XDeode ( 5 );
  6217. $rid=$XDeode->decode($rid);
  6218. if (!is_numeric($rid)){
  6219. die;
  6220. }
  6221. // $rinfo = $receipt->getOne ( array (
  6222. // 'where' => 'rid=' . $rid,
  6223. // 'asArray' => true
  6224. // ) );
  6225. $rinfo = $receipt->getReceiptByRid ( $rid );
  6226. // $accountType = '';
  6227. // if ($rinfo ['Rtype'] == 1) {
  6228. // if ($rinfo ['loanRid'] != 0)//判断有问题
  6229. // $accountType = 2;
  6230. // else
  6231. // $accountType = 1;
  6232. // } elseif ($rinfo ['Rtype'] == 2) {
  6233. // $accountType = 4;
  6234. // } elseif ($rinfo ['Rtype'] == 0)
  6235. // $accountType = 3;
  6236. // if (empty ( $accountType ))
  6237. // die ( 'illegal request' );
  6238. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  6239. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  6240. if (empty ( $executeStaff )) {
  6241. $executeStaff = array (
  6242. $this->staff [0] ['sid'] => array (
  6243. 'date' => date ( 'Y-m-d' ),
  6244. 'opinion' => $implementOpinions,
  6245. 'status' => 1
  6246. )
  6247. );
  6248. } else {
  6249. $executeStaff [$this->staff [0] ['sid']] = array (
  6250. 'date' => date ( 'Y-m-d' ),
  6251. 'opinion' => $implementOpinions,
  6252. 'status' => 1
  6253. );
  6254. }
  6255. if (count ( $executeStaff ) == count ( $executeCopy )) {
  6256. $receipt->executeStaff = json_encode ( $executeStaff );
  6257. $receipt->status = 8;
  6258. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  6259. $receipt->status = 9;
  6260. if ($rinfo ['status'] == 6) {
  6261. $receipt->loanDate = date ( "Y-m-d" );
  6262. }
  6263. $receipt->executeDate = date ( "Y-m-d" );
  6264. } else {
  6265. $receipt->executeStaff = json_encode ( $executeStaff );
  6266. }
  6267. //$receipt->amount = $amount;
  6268. $receipt->update ( array (
  6269. 'where' => 'rid=' . $rid
  6270. ) );
  6271. // 公司流水记录
  6272. // Doo::loadModel ( 'wasteBook' );
  6273. // $wasteBook = new wasteBook ();
  6274. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  6275. // // 银行
  6276. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  6277. // $item = array (
  6278. // 'dataID' => $rid,
  6279. // 'expensesType' => 2,
  6280. // 'accountType' => $accountType,
  6281. // 'accountPriceShow' => $amount,
  6282. // 'accountPrice' => - $amount,
  6283. // 'accountBank' => $accountBank,
  6284. // 'category' => $rinfo ['category'] [0] ['title'],
  6285. // 'cid' => $rinfo ['category'] [0] ['cid'],
  6286. // 'name' => $rinfo ['staffDetail'] ['username'],
  6287. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  6288. // 'inputDate' => date ( "Y-m-d H:i:s" )
  6289. // );
  6290. // $wasteBook->setAccountBookStatistics ( $item );
  6291. // }
  6292. }
  6293. //$ridKey = $XDeode->encode ( $rid );
  6294. return "/hisImplement";
  6295. // return "/implement/" . $ridKey . ".html";
  6296. }
  6297. function receiptburEdi() {
  6298. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6299. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  6300. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  6301. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  6302. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  6303. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  6304. if (empty ( $status ))
  6305. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  6306. $vidList = array ();
  6307. $button = 0;
  6308. Doo::loadModel ( 'verify' );
  6309. Doo::loadModel ( 'receipt' );
  6310. Doo::loadModel ( 'staff' );
  6311. $staff = new staff ();
  6312. $receipt = new receipt ();
  6313. $verify = new verify ();
  6314. Doo::loadModel ( 'L_category' );
  6315. $Lcategory = new L_category ();
  6316. Doo::loadModel ( 'enclosur' );
  6317. $enclosur = new enclosur ();
  6318. Doo::loadModel ( 'loanReceipt' );
  6319. $loanReceipt = new loanReceipt ();
  6320. // user verify ID
  6321. $verifyDetail = $verify->find ( array (
  6322. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  6323. 'asArray' => true
  6324. ) );
  6325. foreach ( $verifyDetail as $key => $value ) {
  6326. array_push ( $vidList, $value ['vid'] );
  6327. }
  6328. $vid = implode ( ",", $vidList );
  6329. if (empty ( $verifyDetail ))
  6330. $vid = 0;
  6331. $categoryList = $Lcategory->find ( array (
  6332. 'asArray' => true
  6333. ) );
  6334. $staffList = $staff->find ( array (
  6335. 'where' => 'cid=' . $cid,
  6336. 'asArray' => true
  6337. ) );
  6338. $ap = "";
  6339. if ($status == 4) {
  6340. $ap = 4;
  6341. $status = 2;
  6342. }
  6343. // get Receipt By verifyID status 2
  6344. $receiptList = $receipt->find ( array (
  6345. 'where' => 'rid =' . $rid . ' and status=2',
  6346. 'desc' => 'rid',
  6347. 'asArray' => true
  6348. ) );
  6349. if (empty ( $receiptList )) {
  6350. die ( 'illegal request' );
  6351. }
  6352. $loanList = $loanReceipt->find ( array (
  6353. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  6354. 'desc' => 'rid',
  6355. 'asArray' => true
  6356. ) );
  6357. $data ['explanation'] = '';
  6358. if (! empty ( $loanList ))
  6359. $data ['explanation'] = $loanList [0] ['explanation'];
  6360. $Locate = 0;
  6361. $roleId = 0;
  6362. $button = 0;
  6363. foreach ( $loanList as $key => $value ) {
  6364. $loanList [$key] ['Locate'] = $Locate;
  6365. $Locate ++;
  6366. $loanList [$key] ['reviseDetail'] = array ();
  6367. if (! empty ( $value ['reviseDetail'] ))
  6368. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6369. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6370. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6371. $categoryDetil = $Lcategory->getOne ( array (
  6372. 'where' => 'cid=' . $value ['cid'],
  6373. 'asArray' => true
  6374. ) );
  6375. $loanList [$key] ['category'] = $categoryDetil ['title'];
  6376. // 检测编辑状态
  6377. $verifyList = $verify->getOne ( array (
  6378. 'where' => 'vid=' . $value ['verify'],
  6379. 'asArray' => true
  6380. ) );
  6381. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6382. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6383. Doo::loadModel ( 'role' );
  6384. $role = new role ();
  6385. $flag = true;
  6386. $roleKey = 0;
  6387. $endStaffArray = array ();
  6388. $roleArrayCopy = array ();
  6389. foreach ( $verifyList as $k => $v ) {
  6390. // init verifyStaff
  6391. if ($v [1] == 'ROLE') {
  6392. if (! empty ( $verifyStaff )) {
  6393. $endStaffArray = end ( $verifyStaff );
  6394. }
  6395. $roleVerify = json_decode ( $v [3], true );
  6396. $roleKey = $k;
  6397. $roleArray = array ();
  6398. $rolename = $role->getOne ( array (
  6399. 'where' => 'rid=' . $v [0],
  6400. 'asArray' => true
  6401. ) );
  6402. foreach ( $roleVerify as $o => $p ) {
  6403. $staffID = explode ( '_', $p );
  6404. $staffInfo = $staff->getOne ( array (
  6405. 'where' => 'sid=' . $staffID [0],
  6406. 'asArray' => true
  6407. ) );
  6408. // print_r($staffID);
  6409. $exp = array (
  6410. 0 => $staffInfo ['sid'],
  6411. 1 => $staffID [1],
  6412. 2 => $staffInfo ['avatar'],
  6413. 'date' => '',
  6414. 'date' => '',
  6415. 'opinion' => '',
  6416. 'status' => '',
  6417. 'rolename' => $rolename ['name']
  6418. );
  6419. array_push ( $roleArray, $exp );
  6420. }
  6421. $roleArrayCopy [$v [0]] = $roleArray;
  6422. // $verifyList[$k]['roleArray']=$roleArray;
  6423. }
  6424. $verifyList [$k] ['date'] = "";
  6425. $verifyList [$k] ['opinion'] = "";
  6426. $verifyList [$k] ['status'] = "";
  6427. if (empty ( $verifyStaff )) {
  6428. $verifyList [$k] ['date'] = "";
  6429. $verifyList [$k] ['opinion'] = "";
  6430. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6431. $verifyList [$k] ['status'] = 4;
  6432. $flag = false;
  6433. }
  6434. } else {
  6435. foreach ( $verifyStaff as $m => $u ) {
  6436. if ($v [0] == $m) {
  6437. $verifyList [$k] ['date'] = $u ['date'];
  6438. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6439. $verifyList [$k] ['status'] = $u ['status'];
  6440. $flag = false;
  6441. break;
  6442. }
  6443. }
  6444. $endStaffArray = end ( $verifyStaff );
  6445. if (isset ( $endStaffArray ['ROLE'] )) {
  6446. } else {
  6447. }
  6448. }
  6449. }
  6450. $rolename ['name'] = '';
  6451. if (! empty ( $roleId )) {
  6452. Doo::loadModel ( 'role' );
  6453. $role = new role ();
  6454. $rolename = $role->getOne ( array (
  6455. 'where' => 'rid=' . $roleId,
  6456. 'asArray' => true
  6457. ) );
  6458. }
  6459. if (! empty ( $verifyStaff ))
  6460. $endStaffArray = end ( $verifyStaff );
  6461. $KOP = false;
  6462. foreach ( $roleArrayCopy as $P => $A ) {
  6463. foreach ( $A as $MKI => $AVL ) {
  6464. if (! empty ( $verifyStaff )) {
  6465. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6466. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6467. $button = 4;
  6468. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6469. }
  6470. foreach ( $verifyStaff as $m => $u ) {
  6471. $AVLFK = $AVL [0] . '_R';
  6472. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6473. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6474. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6475. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6476. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6477. break;
  6478. }
  6479. }
  6480. } else {
  6481. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6482. $button = 4;
  6483. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6484. }
  6485. }
  6486. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6487. $KOP = true;
  6488. }
  6489. }
  6490. foreach ( $roleArrayCopy as $k => $v ) {
  6491. foreach ( $verifyList as $m => $n ) {
  6492. if ($n [0] == $k) {
  6493. array_splice ( $verifyList, $m, 1, $v );
  6494. }
  6495. }
  6496. }
  6497. $loanList [$key] ['verifyList'] = $verifyList;
  6498. }
  6499. $htmlLoan = '';
  6500. $data ['loanReceiptDate'] = '';
  6501. if (isset ( $loanList [0] )) {
  6502. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  6503. if ($value ['status'] == 1)
  6504. $htmlLoan .= '<li class="done" >';
  6505. elseif ($value ['status'] == 3)
  6506. $htmlLoan .= '<li class="undone" >';
  6507. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  6508. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  6509. if (isset ( $value ['rolename'] ))
  6510. $htmlLoan .= $value ['rolename'];
  6511. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  6512. }
  6513. $data ['loanDate'] = $loanList [0] ['date'];
  6514. } else {
  6515. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  6516. }
  6517. $data ['htmlLoan'] = $htmlLoan;
  6518. // $data ['LoanReceipt']=$loanList[0];
  6519. // print_r($loanList);
  6520. $Locate = 0;
  6521. $roleId = 0;
  6522. $button = 0;
  6523. if ($ap == 4)
  6524. $status = 4;
  6525. Doo::loadClass ( 'XDeode' );
  6526. $XDeode = new XDeode ( 5 );
  6527. foreach ( $receiptList as $key => $value ) {
  6528. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6529. $receiptList [$key] ['Locate'] = $Locate;
  6530. $Locate ++;
  6531. $receiptList [$key] ['reviseDetail'] = array ();
  6532. // 调整金额 代码调整
  6533. if (! empty ( $value ['reviseDetail'] )) {
  6534. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  6535. foreach ( $reviseDetail as $ry => $re ) {
  6536. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  6537. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  6538. }
  6539. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  6540. // print_r($reviseDetail);
  6541. }
  6542. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6543. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6544. $categoryDetil = $Lcategory->getOne ( array (
  6545. 'where' => 'cid=' . $value ['cid'],
  6546. 'asArray' => true
  6547. ) );
  6548. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6549. // 检测编辑状态
  6550. $verifyList = $verify->getOne ( array (
  6551. 'where' => 'vid=' . $value ['verify'],
  6552. 'asArray' => true
  6553. ) );
  6554. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6555. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6556. Doo::loadModel ( 'role' );
  6557. $role = new role ();
  6558. // print_r($verifyList);
  6559. $flag = true;
  6560. $roleKey = 0;
  6561. $endStaffArray = array ();
  6562. $roleArrayCopy = array ();
  6563. foreach ( $verifyList as $k => $v ) {
  6564. // init verifyStaff
  6565. if ($v [1] == 'ROLE') {
  6566. if (! empty ( $verifyStaff )) {
  6567. $endStaffArray = end ( $verifyStaff );
  6568. if ($v [0] == $endStaffArray ['nextStaff']) {
  6569. $roleId = $v [0];
  6570. }
  6571. }
  6572. $roleVerify = json_decode ( $v [3], true );
  6573. $roleKey = $k;
  6574. $roleArray = array ();
  6575. $rolename = $role->getOne ( array (
  6576. 'where' => 'rid=' . $v [0],
  6577. 'asArray' => true
  6578. ) );
  6579. foreach ( $roleVerify as $o => $p ) {
  6580. $staffID = explode ( '_', $p );
  6581. $staffInfo = $staff->getOne ( array (
  6582. 'where' => 'sid=' . $staffID [0],
  6583. 'asArray' => true
  6584. ) );
  6585. // print_r($staffID);
  6586. $exp = array (
  6587. 0 => $staffInfo ['sid'],
  6588. 1 => $staffID [1],
  6589. 2 => $staffInfo ['avatar'],
  6590. 'date' => '',
  6591. 'date' => '',
  6592. 'opinion' => '',
  6593. 'status' => '',
  6594. 'rolename' => $rolename ['name']
  6595. );
  6596. array_push ( $roleArray, $exp );
  6597. }
  6598. $roleArrayCopy [$v [0]] = $roleArray;
  6599. // $verifyList[$k]['roleArray']=$roleArray;
  6600. }
  6601. // print_r($roleArray);
  6602. $verifyList [$k] ['date'] = "";
  6603. $verifyList [$k] ['opinion'] = "";
  6604. $verifyList [$k] ['status'] = "";
  6605. if (empty ( $verifyStaff )) {
  6606. $verifyList [$k] ['date'] = "";
  6607. $verifyList [$k] ['opinion'] = "";
  6608. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6609. $verifyList [$k] ['status'] = 4;
  6610. $button = 4;
  6611. $flag = false;
  6612. }
  6613. } else {
  6614. foreach ( $verifyStaff as $m => $u ) {
  6615. if ($v [0] == $m) {
  6616. $verifyList [$k] ['date'] = $u ['date'];
  6617. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6618. $verifyList [$k] ['status'] = $u ['status'];
  6619. $flag = false;
  6620. break;
  6621. }
  6622. }
  6623. $endStaffArray = end ( $verifyStaff );
  6624. if (isset ( $endStaffArray ['ROLE'] )) {
  6625. } else {
  6626. $endKey = key ( $verifyStaff );
  6627. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  6628. $button = 4;
  6629. $verifyList [$k] ['status'] = 4;
  6630. }
  6631. }
  6632. }
  6633. }
  6634. $rolename ['name'] = '';
  6635. if (! empty ( $roleId )) {
  6636. Doo::loadModel ( 'role' );
  6637. $role = new role ();
  6638. $rolename = $role->getOne ( array (
  6639. 'where' => 'rid=' . $roleId,
  6640. 'asArray' => true
  6641. ) );
  6642. }
  6643. if (! empty ( $verifyStaff ))
  6644. $endStaffArray = end ( $verifyStaff );
  6645. $KOP = false;
  6646. foreach ( $roleArrayCopy as $P => $A ) {
  6647. foreach ( $A as $MKI => $AVL ) {
  6648. if (! empty ( $verifyStaff )) {
  6649. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6650. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6651. $button = 4;
  6652. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6653. }
  6654. foreach ( $verifyStaff as $m => $u ) {
  6655. $AVLFK = $AVL [0] . '_R';
  6656. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6657. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6658. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6659. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6660. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6661. break;
  6662. }
  6663. }
  6664. } else {
  6665. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6666. $button = 4;
  6667. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6668. }
  6669. }
  6670. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6671. $KOP = true;
  6672. }
  6673. }
  6674. foreach ( $roleArrayCopy as $k => $v ) {
  6675. foreach ( $verifyList as $m => $n ) {
  6676. if ($n [0] == $k) {
  6677. array_splice ( $verifyList, $m, 1, $v );
  6678. }
  6679. }
  6680. }
  6681. // print_r($verifyList);
  6682. $receiptList [$key] ['verifyList'] = $verifyList;
  6683. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6684. 'where' => 'sid=' . $value ['staff'],
  6685. 'asArray' => true
  6686. ) );
  6687. $receiptList [$key] ['button'] = $button;
  6688. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  6689. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  6690. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  6691. $receiptList [$key] ['relust'] = $relust;
  6692. $receiptList [$key] ['relustABS'] = abs ( $relust );
  6693. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  6694. }
  6695. //print_r($receiptList);die;
  6696. // $data['verifyDetail']=$verifyDetail;
  6697. $mothHtml = "";
  6698. for($i = 1; $i <= 12; $i ++) {
  6699. if ($month == $i)
  6700. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6701. else
  6702. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6703. }
  6704. // 获取审批日志
  6705. Doo::loadModel ( 'receiptLog' );
  6706. $receiptLog = new receiptLog ();
  6707. $rlList = array ();
  6708. $rlInfo = $receiptLog->getOne ( array (
  6709. 'where' => 'rid=' . $rid . ' and status=4',
  6710. 'asArray' => true
  6711. ) );
  6712. $tijdate = $receiptLog->getOne ( array (
  6713. 'where' => 'rid=' . $rid . ' and status=2',
  6714. 'asc' => 'rlid',
  6715. 'asArray' => true
  6716. ) );
  6717. if (! empty ( $rlInfo )) {
  6718. $rlList = $receiptLog->find ( array (
  6719. 'where' => 'rid=' . $rid,
  6720. 'asc' => 'rlid',
  6721. 'asArray' => true
  6722. ) );
  6723. }
  6724. // echo $rid;
  6725. // print_r($receiptList);
  6726. $receiptList [0] ['rlList'] = $rlList;
  6727. // print_r($receiptList);
  6728. $enclosurList = $enclosur->find ( array (
  6729. 'where' => 'rid=' . $rid,
  6730. 'asArray' => true
  6731. ) );
  6732. $enclosurHtml = '';
  6733. foreach ( $enclosurList as $value ) {
  6734. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  6735. }
  6736. $data ['enclosurHtml'] = $enclosurHtml;
  6737. $data ['rolename'] = $rolename ['name'];
  6738. $data ['mothHtml'] = $mothHtml;
  6739. $receiptList[0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  6740. $data ['rid'] = $rid;
  6741. $data ['tijdate'] = $tijdate ['date'];
  6742. $data ['receiptList'] = $receiptList;
  6743. $data ['receiptApprovalCount'] = count ( $receiptList );
  6744. $data ['status'] = $status;
  6745. $data ['year'] = $year;
  6746. $data ['categoryList'] = $categoryList;
  6747. $data ['staffList'] = $staffList;
  6748. $data ['cid'] = $cid;
  6749. $data ['sid'] = $sid;
  6750. $data ['ap'] = $ap;
  6751. $data ['memu'] = "receipt";
  6752. $data ['staff'] = $this->staff;
  6753. $data ['receiptMemu'] = 'approvalExpenses';
  6754. $data ['verifyId'] = $this->verifyId;
  6755. $data ['executeId'] = $this->executeId;
  6756. if($receiptList[0]['receiptClass']==1){
  6757. $this->render ( "/receipt/feeAgencyApproval", $data );
  6758. }elseif($receiptList[0]['receiptClass']==2){
  6759. //TODO 行程单2.0
  6760. if(!empty($receiptList[0]['itinerary2'])){
  6761. $this->render ( "/receipt/feeTraveApproval2", $data );
  6762. }else{
  6763. $this->render ( "/receipt/feeTraveApproval", $data );
  6764. }
  6765. }elseif($receiptList[0]['receiptClass']==3){
  6766. $this->render ( "/receipt/feeInternalTrainApproval", $data );
  6767. }else{
  6768. $this->render ( "/admin/receiptburEdi", $data );
  6769. }
  6770. }
  6771. function hisImplement() {
  6772. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6773. if (empty ( $item ))
  6774. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  6775. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  6776. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6777. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  6778. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  6779. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  6780. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  6781. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  6782. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  6783. Doo::loadClass ( 'XDeode' );
  6784. $XDeode = new XDeode ( 5 );
  6785. Doo::loadModel ( 'receipt' );
  6786. $receipt = new receipt ();
  6787. Doo::loadModel ( 'L_category' );
  6788. $Lcategory = new L_category ();
  6789. Doo::loadModel ( 'verify' );
  6790. Doo::loadModel ( 'statistics' );
  6791. $statistics = new statistics ();
  6792. $verify = new verify ();
  6793. Doo::loadModel ( 'staff' );
  6794. $staff = new staff ();
  6795. Doo::loadClass ( 'XDeode' );
  6796. $XDeode = new XDeode ( 5 );
  6797. $XDeode7 = new XDeode ( 7 );
  6798. $cid = $XDeode->decode ( $cidKey );
  6799. $condition = "";
  6800. if ($item == "expenses")
  6801. $condition = " and Rtype=1 ";
  6802. elseif ($item == "receipts")
  6803. $condition = " and Rtype=0 ";
  6804. elseif ($item == "remits")
  6805. $condition = " and Rtype=2 ";
  6806. elseif($item == "train")
  6807. $condition = " and Rtype=3 ";
  6808. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  6809. $sopString = $cidString = "";
  6810. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  6811. if (empty ( $rdate ))
  6812. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  6813. else
  6814. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  6815. if ($status == 'pendImplement') {
  6816. $condition .= ' and (status=1 or status=6) and (executeCopy like "%[\"' . $this->staff [0] ['sid'] . '\"%" and (executeStaff not like "%{\"' . $this->staff [0] ['sid'] . '\"%" or executeStaff is null ) ) ';
  6817. } elseif ($status == 'alerpts') {
  6818. $statusCon = '(status=8 or status=9 )';
  6819. if (empty ( $rdate )){
  6820. $dateCondition = " and Year(date) =" . $year;
  6821. }else{
  6822. $dateCondition = " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  6823. }
  6824. }
  6825. if ($sop != 'SOP')
  6826. $sopString = " and staff=" . $sop;
  6827. if ($cidKey != 'ALL')
  6828. $cidString = " and cid=" . $cid;
  6829. //汇款信息需要提取出来
  6830. if(!empty($receiptOrder)){
  6831. $receiptList = $receipt->find ( array (
  6832. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6833. 'desc' => 'rid',
  6834. 'asArray' => true
  6835. ) );
  6836. // 员工筛选
  6837. $receiptList2 = $receipt->find ( array (
  6838. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6839. 'desc' => 'rid',
  6840. 'asArray' => true
  6841. ) );
  6842. }else{
  6843. $receiptList = $receipt->find ( array (
  6844. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  6845. 'desc' => 'rid',
  6846. 'asArray' => true
  6847. ) );
  6848. // 员工筛选
  6849. $receiptList2 = $receipt->find ( array (
  6850. 'where' => $statusCon . $condition . $dateCondition,
  6851. 'desc' => 'rid',
  6852. 'asArray' => true
  6853. ) );
  6854. }
  6855. $sopStaff = array ();
  6856. foreach ( $receiptList2 as $key => $value ) {
  6857. $staffDetail = $staff->getOne ( array (
  6858. 'select' => 'username',
  6859. 'where' => 'sid=' . $value ['staff'],
  6860. 'asArray' => true
  6861. ) );
  6862. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  6863. }
  6864. // 办事处筛选
  6865. $categoryScreen = array ();
  6866. $categorList = $Lcategory->getCategory ();
  6867. foreach ( $receiptList2 as $key => $value ) {
  6868. foreach ( $categorList as $k => $v ) {
  6869. if ($value ['cid'] == $v ['cid']) {
  6870. $categoryScreen [$v ['cidKey']] = $v ['title'];
  6871. break;
  6872. }
  6873. }
  6874. }
  6875. $categoryScreenHtml = "";
  6876. foreach ( $categoryScreen as $key => $value ) {
  6877. if ($cidKey == $key)
  6878. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6879. else
  6880. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6881. }
  6882. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  6883. $data ['cidKey'] = $cidKey;
  6884. $Locate = 0;
  6885. $roleId = 0;
  6886. $button = 0;
  6887. $staffBatchNumber = 100001;
  6888. $remittanceList = array ();
  6889. foreach ( $receiptList as $key => $value ) {
  6890. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  6891. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6892. $receiptList [$key] ['Texe'] = 'false';
  6893. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  6894. $receiptList [$key] ['Texe'] = 'true';
  6895. }
  6896. $receiptList [$key] ['TRexe'] = 'true';
  6897. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  6898. $receiptList [$key] ['TRexe'] = 'false';
  6899. }
  6900. $receiptList [$key] ['Locate'] = $Locate;
  6901. $Locate ++;
  6902. $receiptList [$key] ['reviseDetail'] = array ();
  6903. if (! empty ( $value ['reviseDetail'] ))
  6904. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6905. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6906. $categoryDetil = $Lcategory->getOne ( array (
  6907. 'where' => 'cid=' . $value ['cid'],
  6908. 'asArray' => true
  6909. ) );
  6910. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6911. // 检测编辑状态
  6912. $verifyList = $verify->getOne ( array (
  6913. 'where' => 'vid=' . $value ['verify'],
  6914. 'asArray' => true
  6915. ) );
  6916. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6917. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6918. Doo::loadModel ( 'role' );
  6919. $role = new role ();
  6920. $flag = true;
  6921. $roleKey = 0;
  6922. $endStaffArray = array ();
  6923. $roleArrayCopy = array ();
  6924. foreach ( $verifyList as $k => $v ) {
  6925. // init verifyStaff
  6926. if ($v [1] == 'ROLE') {
  6927. if (! empty ( $verifyStaff )) {
  6928. $endStaffArray = end ( $verifyStaff );
  6929. }
  6930. $roleVerify = json_decode ( $v [3], true );
  6931. $roleKey = $k;
  6932. $roleArray = array ();
  6933. $rolename = $role->getOne ( array (
  6934. 'where' => 'rid=' . $v [0],
  6935. 'asArray' => true
  6936. ) );
  6937. foreach ( $roleVerify as $o => $p ) {
  6938. $staffID = explode ( '_', $p );
  6939. $staffInfo = $staff->getOne ( array (
  6940. 'where' => 'sid=' . $staffID [0],
  6941. 'asArray' => true
  6942. ) );
  6943. $exp = array (
  6944. 0 => $staffInfo ['sid'],
  6945. 1 => $staffID [1],
  6946. 2 => $staffInfo ['avatar'],
  6947. 'date' => '',
  6948. 'date' => '',
  6949. 'opinion' => '',
  6950. 'status' => '',
  6951. 'rolename' => $rolename ['name']
  6952. );
  6953. array_push ( $roleArray, $exp );
  6954. }
  6955. $roleArrayCopy [$v [0]] = $roleArray;
  6956. }
  6957. $verifyList [$k] ['date'] = "";
  6958. $verifyList [$k] ['opinion'] = "";
  6959. $verifyList [$k] ['status'] = "";
  6960. if (empty ( $verifyStaff )) {
  6961. $verifyList [$k] ['date'] = "";
  6962. $verifyList [$k] ['opinion'] = "";
  6963. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6964. $verifyList [$k] ['status'] = 4;
  6965. $flag = false;
  6966. }
  6967. } else {
  6968. foreach ( $verifyStaff as $m => $u ) {
  6969. if ($v [0] == $m) {
  6970. $verifyList [$k] ['date'] = $u ['date'];
  6971. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6972. $verifyList [$k] ['status'] = $u ['status'];
  6973. $flag = false;
  6974. break;
  6975. }
  6976. }
  6977. $endStaffArray = end ( $verifyStaff );
  6978. }
  6979. }
  6980. $rolename ['name'] = '';
  6981. if (! empty ( $roleId )) {
  6982. Doo::loadModel ( 'role' );
  6983. $role = new role ();
  6984. $rolename = $role->getOne ( array (
  6985. 'where' => 'rid=' . $roleId,
  6986. 'asArray' => true
  6987. ) );
  6988. }
  6989. if (! empty ( $verifyStaff ))
  6990. $endStaffArray = end ( $verifyStaff );
  6991. $KOP = false;
  6992. foreach ( $roleArrayCopy as $P => $A ) {
  6993. foreach ( $A as $MKI => $AVL ) {
  6994. if (! empty ( $verifyStaff )) {
  6995. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6996. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6997. $button = 4;
  6998. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6999. }
  7000. foreach ( $verifyStaff as $m => $u ) {
  7001. $AVLFK = $AVL [0] . '_R';
  7002. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7003. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7004. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7005. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7006. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7007. break;
  7008. }
  7009. }
  7010. } else {
  7011. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7012. $button = 4;
  7013. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7014. }
  7015. }
  7016. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7017. $KOP = true;
  7018. }
  7019. }
  7020. foreach ( $roleArrayCopy as $k => $v ) {
  7021. foreach ( $verifyList as $m => $n ) {
  7022. if ($n [0] == $k) {
  7023. array_splice ( $verifyList, $m, 1, $v );
  7024. }
  7025. }
  7026. }
  7027. $receiptList [$key] ['verifyList'] = $verifyList;
  7028. $staffDetail = $staff->getOne ( array (
  7029. 'where' => 'sid=' . $value ['staff'],
  7030. 'asArray' => true
  7031. ) );
  7032. $receiptList [$key] ['staffDetail'] = $staffDetail;
  7033. $receiptList [$key] ['button'] = $button;
  7034. if ($value['Rtype']==1){
  7035. $receiptList [$key] ['relust'] = $value['sum']-$value['loanSum'];
  7036. $receiptList [$key] ['relustABS'] = abs($receiptList [$key] ['relust']);
  7037. }elseif($value['Rtype']==3){
  7038. // 收入合计
  7039. Doo::loadModel ( 'invoiceTraining' );
  7040. $invoiceTraining = new invoiceTraining ();
  7041. $invoiceTrainingDetail = array (
  7042. 'invoiceArriveAmount' => '0.00',
  7043. 'RIAmount' => '0.00',
  7044. 'invoiceTotalAmount' => '0.00',
  7045. 'invoiceCompanyAmount' => '0.00',
  7046. 'invoiceArriveAmountM'=>'0.00',
  7047. 'invoiceCompanyAmountM'=>'0.00'
  7048. );
  7049. if ($value ['invoiceTrainId'] != 0) {
  7050. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value['invoiceTrainId'] );
  7051. }
  7052. $invoiceArriveAmount = $RIAmount = 0;
  7053. if (! empty ( $invoiceTrainingDetail )) {
  7054. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  7055. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  7056. }
  7057. // 备用金
  7058. $sum = 0;
  7059. if (! empty ( $value ['trainLoanRid'] )) {
  7060. $receiptLoanList = $receipt->getReceiptInRid ( $value ['trainLoanRid'] );
  7061. foreach ($receiptLoanList as $kll=>$vll){
  7062. $sum+=$vll['sum'];
  7063. }
  7064. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $value ['trainLoanRid'] );
  7065. // $sum = $receiptLoanDetailBak ['sum'];
  7066. }
  7067. // 支出项金额详情
  7068. // 项目金额合计
  7069. Doo::loadModel ( 'RItem' );
  7070. $RItem = new RItem ();
  7071. Doo::loadModel ( 'accountItem' );
  7072. $accountItem = new accountItem ();
  7073. // 讲师获得
  7074. Doo::loadModel ( 'RILecturer' );
  7075. $RILecturer = new RILecturer ();
  7076. $RItemList = $RItem->getRItemByRid ( $value['rid'] );
  7077. $RILecturerList = $RILecturer->getRILecturerByRid ( $value['rid'] );
  7078. // 支出项金额详情
  7079. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  7080. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  7081. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  7082. $receiptList [$key] ['payment'] =$payment;
  7083. $receiptList [$key] ['paymentABS'] =sprintf("%.2f",abs($payment));
  7084. }
  7085. // 设置导出汇款execl
  7086. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  7087. $remittanceDetail = array (
  7088. $staffBatchNumber,
  7089. $value ['remittanceName'],
  7090. $value ['bankNumber'],
  7091. $value ['bankName'],
  7092. $value ['remittanceBankType'],
  7093. $value ['coupletNumber'],
  7094. $value ['sum']
  7095. );
  7096. array_push ( $remittanceList, $remittanceDetail );
  7097. $staffBatchNumber ++;
  7098. }
  7099. }
  7100. $data ['remittanceList'] = json_encode ( $remittanceList );
  7101. // print_r($receiptList);
  7102. $mothHtml = "";
  7103. for($i = 1; $i <= 12; $i ++) {
  7104. if ($moth == $i)
  7105. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7106. else
  7107. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7108. }
  7109. $dayHtml = "";
  7110. if ($day != "DAY" || $moth != "MONTH") {
  7111. for($i = 1; $i <= 31; $i ++) {
  7112. if ($day == $i)
  7113. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7114. else
  7115. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7116. }
  7117. }
  7118. $sopHtml = "";
  7119. foreach ( $sopStaff as $key => $value ) {
  7120. if ($sop == $key)
  7121. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  7122. else
  7123. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  7124. }
  7125. $data ['status'] = $status;
  7126. $data ['rdate'] = $rdate;
  7127. $data ['sopHtml'] = $sopHtml;
  7128. $data ['dayHtml'] = $dayHtml;
  7129. $data ['mothHtml'] = $mothHtml;
  7130. $data ['receiptList'] = $receiptList;
  7131. $data ['memu'] = "receipt";
  7132. $data ['staff'] = $this->staff;
  7133. $data ['receiptMemu'] = 'implement';
  7134. $data ['verifyId'] = $this->verifyId;
  7135. $data ['executeId'] = $this->executeId;
  7136. $data ['item'] = $item;
  7137. $data ['year'] = $year;
  7138. $data ['moth'] = $moth;
  7139. $data['receiptOrder']=$receiptOrder;
  7140. $data ['day'] = $day;
  7141. $data ['sop'] = $sop;
  7142. $this->render ( "/admin/hisImplement", $data );
  7143. }
  7144. /**
  7145. * 导出汇款信息的exelc
  7146. */
  7147. function exportRemittance() {
  7148. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  7149. if (empty ( $remittanceInfo ))
  7150. die ( 'illegal request' );
  7151. $title = array (
  7152. '员工编号',
  7153. '姓名',
  7154. '员工账号',
  7155. '员工账户开户行',
  7156. '转账类型',
  7157. '联行号',
  7158. '金额'
  7159. );
  7160. $data = json_decode ( $remittanceInfo, true );
  7161. if (empty ( $data ))
  7162. die ( 'illegal request' );
  7163. Doo::loadClass ( 'receipt.func' );
  7164. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  7165. header ( 'Content-Type:text/html;charset=utf-8' );
  7166. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  7167. }
  7168. function ajaxExamine() {
  7169. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  7170. Doo::loadModel ( 'receipt' );
  7171. $receipt = new receipt ();
  7172. if (! empty ( $rid )) {
  7173. $rLRes = $receipt->find ( array (
  7174. '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,
  7175. 'asArray' => true
  7176. ) );
  7177. if(!empty($rLRes)){
  7178. Doo::loadClass ( 'XDeode' );
  7179. $XDeode = new XDeode ( 7 );
  7180. $rLRes [0]['ridKey'] = $XDeode->encode( $rLRes [0]['rid'] );
  7181. echo json_encode ( array (
  7182. 'status' => 1,
  7183. 'receipt' => $rLRes [0]
  7184. ) );
  7185. die ();
  7186. }else{
  7187. echo json_encode ( array (
  7188. 'status' => 1,
  7189. 'receipt' => array ()
  7190. ) );
  7191. die ();
  7192. }
  7193. }
  7194. echo json_encode ( array (
  7195. 'status' => 0,
  7196. 'receipt' => array ()
  7197. ) );
  7198. die ();
  7199. }
  7200. /*
  7201. * 废弃
  7202. */
  7203. function myReceipt() {
  7204. // all approval past withdraw
  7205. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  7206. if (empty ( $item ))
  7207. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  7208. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7209. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  7210. Doo::loadModel ( 'receipt' );
  7211. $receipt = new receipt ();
  7212. // pre-loaded
  7213. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  7214. // have cache
  7215. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  7216. if (! empty ( $moth )) // yearPage
  7217. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  7218. $this->showCache ( $path );
  7219. }
  7220. Doo::loadModel ( 'L_category' );
  7221. $Lcategory = new L_category ();
  7222. Doo::loadModel ( 'verify' );
  7223. Doo::loadModel ( 'statistics' );
  7224. $statistics = new statistics ();
  7225. $verify = new verify ();
  7226. Doo::loadModel ( 'staff' );
  7227. $staff = new staff ();
  7228. $condition = " and status!=0 ";
  7229. if ($item == "approval")
  7230. $condition = " and status=2 ";
  7231. elseif ($item == "withdraw")
  7232. $condition = " and status=3 ";
  7233. elseif ($item == "past")
  7234. $condition = " and status=1 ";
  7235. elseif ($item == "whdw")
  7236. $condition = " and status=4 ";
  7237. $dateCondition = " and Year(date) =" . $year;
  7238. if (! empty ( $moth )) {
  7239. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  7240. $stList = $statistics->getOne ( array (
  7241. 'select' => 'rePrice ,agPrice',
  7242. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7243. 'asArray' => true
  7244. ) );
  7245. } else
  7246. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  7247. if (empty ( $stList ))
  7248. $stList = array (
  7249. 'rePrice' => 0,
  7250. 'agPrice' => 0
  7251. );
  7252. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  7253. $data ['stList'] = array (
  7254. 'rePrice' => $stList ['rePrice'],
  7255. 'agPrice' => $stList ['agPrice'],
  7256. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  7257. );
  7258. $receiptList = $receipt->find ( array (
  7259. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  7260. 'desc' => 'rid',
  7261. 'asArray' => true
  7262. ) );
  7263. $Locate = 0;
  7264. $roleId = 0;
  7265. $button = 0;
  7266. foreach ( $receiptList as $key => $value ) {
  7267. $receiptList [$key] ['Locate'] = $Locate;
  7268. $Locate ++;
  7269. $receiptList [$key] ['reviseDetail'] = array ();
  7270. if (! empty ( $value ['reviseDetail'] ))
  7271. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7272. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7273. $categoryDetil = $Lcategory->getOne ( array (
  7274. 'where' => 'cid=' . $value ['cid'],
  7275. 'asArray' => true
  7276. ) );
  7277. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7278. // 检测编辑状态
  7279. $verifyList = $verify->getOne ( array (
  7280. 'where' => 'vid=' . $value ['verify'],
  7281. 'asArray' => true
  7282. ) );
  7283. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7284. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7285. Doo::loadModel ( 'role' );
  7286. $role = new role ();
  7287. $flag = true;
  7288. $roleKey = 0;
  7289. $endStaffArray = array ();
  7290. $roleArrayCopy = array ();
  7291. foreach ( $verifyList as $k => $v ) {
  7292. // init verifyStaff
  7293. if ($v [1] == 'ROLE') {
  7294. if (! empty ( $verifyStaff )) {
  7295. $endStaffArray = end ( $verifyStaff );
  7296. // if ($v[0]==$endStaffArray['nextStaff']){
  7297. // $roleId=$v[0];
  7298. // }
  7299. }
  7300. $roleVerify = json_decode ( $v [3], true );
  7301. $roleKey = $k;
  7302. $roleArray = array ();
  7303. $rolename = $role->getOne ( array (
  7304. 'where' => 'rid=' . $v [0],
  7305. 'asArray' => true
  7306. ) );
  7307. foreach ( $roleVerify as $o => $p ) {
  7308. $staffID = explode ( '_', $p );
  7309. $staffInfo = $staff->getOne ( array (
  7310. 'where' => 'sid=' . $staffID [0],
  7311. 'asArray' => true
  7312. ) );
  7313. // print_r($staffID);
  7314. $exp = array (
  7315. 0 => $staffInfo ['sid'],
  7316. 1 => $staffID [1],
  7317. 2 => $staffInfo ['avatar'],
  7318. 'date' => '',
  7319. 'date' => '',
  7320. 'opinion' => '',
  7321. 'status' => '',
  7322. 'rolename' => $rolename ['name']
  7323. );
  7324. array_push ( $roleArray, $exp );
  7325. }
  7326. $roleArrayCopy [$v [0]] = $roleArray;
  7327. // $verifyList[$k]['roleArray']=$roleArray;
  7328. }
  7329. $verifyList [$k] ['date'] = "";
  7330. $verifyList [$k] ['opinion'] = "";
  7331. $verifyList [$k] ['status'] = "";
  7332. if (empty ( $verifyStaff )) {
  7333. $verifyList [$k] ['date'] = "";
  7334. $verifyList [$k] ['opinion'] = "";
  7335. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7336. $verifyList [$k] ['status'] = 4;
  7337. $flag = false;
  7338. }
  7339. } else {
  7340. foreach ( $verifyStaff as $m => $u ) {
  7341. if ($v [0] == $m) {
  7342. $verifyList [$k] ['date'] = $u ['date'];
  7343. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7344. $verifyList [$k] ['status'] = $u ['status'];
  7345. $flag = false;
  7346. break;
  7347. }
  7348. }
  7349. $endStaffArray = end ( $verifyStaff );
  7350. if (isset ( $endStaffArray ['ROLE'] )) {
  7351. } else {
  7352. // $endKey=key($verifyStaff);
  7353. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  7354. // $button=4;
  7355. // $verifyList[$k]['status']=4;
  7356. // }
  7357. }
  7358. }
  7359. }
  7360. $rolename ['name'] = '';
  7361. if (! empty ( $roleId )) {
  7362. Doo::loadModel ( 'role' );
  7363. $role = new role ();
  7364. $rolename = $role->getOne ( array (
  7365. 'where' => 'rid=' . $roleId,
  7366. 'asArray' => true
  7367. ) );
  7368. }
  7369. if (! empty ( $verifyStaff ))
  7370. $endStaffArray = end ( $verifyStaff );
  7371. $KOP = false;
  7372. foreach ( $roleArrayCopy as $P => $A ) {
  7373. foreach ( $A as $MKI => $AVL ) {
  7374. if (! empty ( $verifyStaff )) {
  7375. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7376. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7377. $button = 4;
  7378. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7379. }
  7380. foreach ( $verifyStaff as $m => $u ) {
  7381. $AVLFK = $AVL [0] . '_R';
  7382. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7383. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7384. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7385. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7386. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7387. break;
  7388. }
  7389. }
  7390. } else {
  7391. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7392. $button = 4;
  7393. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7394. }
  7395. }
  7396. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7397. $KOP = true;
  7398. }
  7399. }
  7400. foreach ( $roleArrayCopy as $k => $v ) {
  7401. foreach ( $verifyList as $m => $n ) {
  7402. if ($n [0] == $k) {
  7403. array_splice ( $verifyList, $m, 1, $v );
  7404. }
  7405. }
  7406. }
  7407. $receiptList [$key] ['verifyList'] = $verifyList;
  7408. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7409. 'where' => 'sid=' . $value ['staff'],
  7410. 'asArray' => true
  7411. ) );
  7412. $receiptList [$key] ['button'] = $button;
  7413. }
  7414. // print_r($receiptList);die;
  7415. $mothHtml = "";
  7416. for($i = 1; $i <= 12; $i ++) {
  7417. if ($moth == $i)
  7418. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7419. else
  7420. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7421. }
  7422. $data ['mothHtml'] = $mothHtml;
  7423. $data ['receiptList'] = $receiptList;
  7424. $data ['memu'] = "receipt";
  7425. $data ['staff'] = $this->staff;
  7426. $data ['receiptMemu'] = 'receipt';
  7427. $data ['verifyId'] = $this->verifyId;
  7428. $data ['executeId'] = $this->executeId;
  7429. $data ['item'] = $item;
  7430. $data ['year'] = $year;
  7431. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  7432. // sufficient condition to generate cache
  7433. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  7434. $receiptList = $receipt->find ( array (
  7435. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  7436. 'asArray' => true
  7437. ) );
  7438. if (empty ( $receiptList )) { // generated files
  7439. ob_start ();
  7440. $this->render ( "/admin/saea_myList", $data );
  7441. $this->cacheFile ( $path );
  7442. die ();
  7443. // $content = ob_get_contents();
  7444. // $fp = fopen($path, "w");
  7445. // fwrite($fp, $content);
  7446. // fclose($fp);
  7447. }
  7448. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  7449. $receiptList = $receipt->find ( array (
  7450. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  7451. 'asArray' => true
  7452. ) );
  7453. if (empty ( $receiptList )) { // generated files
  7454. ob_start ();
  7455. $this->render ( "/admin/saea_myList", $data );
  7456. $this->cacheFile ( $path );
  7457. die ();
  7458. }
  7459. }
  7460. }
  7461. $this->render ( "/admin/saea_myList", $data );
  7462. }
  7463. function approvedReceipt() {
  7464. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7465. Doo::loadModel ( 'receipt' );
  7466. Doo::loadModel ( 'receiptDetail' );
  7467. $receipt = new receipt ();
  7468. $receiptDetail = new receiptDetail ();
  7469. Doo::loadModel ( 'statistics' );
  7470. Doo::loadModel ( 'itemStatistics' );
  7471. $statistics = new statistics ();
  7472. $itemStatistics = new itemStatistics ();
  7473. Doo::loadModel ( "verify" );
  7474. $verify = new verify ();
  7475. // 审批状态的判定
  7476. $receiptDetailList = $receipt->getOne ( array (
  7477. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  7478. 'asArray' => true
  7479. ) );
  7480. if (empty ( $receiptDetailList ))
  7481. return "/saeaBorad";
  7482. $verifyDetail = $verify->getOne ( array (
  7483. 'where' => ' vid =' . $receiptDetailList ['verify'],
  7484. 'asArray' => true
  7485. ) );
  7486. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  7487. if (empty ( $receiptDetailList ['nowStaff'] )) {
  7488. $nowStaff = "";
  7489. $nowStaffList = array ();
  7490. if ($verifyDetail [0] [1] == 'ROLE') {
  7491. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7492. foreach ( $vStaffString as $key => $value ) {
  7493. $staffK = explode ( "_", $value );
  7494. array_push ( $nowStaffList, $staffK [0] );
  7495. }
  7496. $nowStaff = implode ( ',', $nowStaffList );
  7497. } else {
  7498. $nowStaff = $verifyDetail [0] [0];
  7499. }
  7500. $receipt->nowStaff = $nowStaff;
  7501. }
  7502. // echo $nowStaff;
  7503. // print_r($verifyDetail);die;
  7504. $receipt->rid = $receiptDetailList ['rid'];
  7505. $receipt->date = date ( "Y-m-d" );
  7506. $receipt->status = 2;
  7507. $receipt->update ();
  7508. $receiptDetail->status = 2;
  7509. $receiptDetail->update ( array (
  7510. 'where' => 'rid=' . $receiptDetailList ['rid']
  7511. ) );
  7512. Doo::loadModel ( "receiptLog" );
  7513. $receiptLog = new receiptLog ();
  7514. Doo::loadModel ( "verify" );
  7515. $verify = new verify ();
  7516. $receiptInfo = $receipt->getOne ( array (
  7517. 'where' => 'rid=' . $rid,
  7518. 'asArray' => true
  7519. ) );
  7520. $vr = $verify->getOne ( array (
  7521. 'where' => 'vid=' . $receiptInfo ['verify'],
  7522. 'asArray' => true
  7523. ) );
  7524. $jd = json_decode ( $vr ['staff'] );
  7525. $roleId = 0;
  7526. foreach ( $jd as $key => $value ) {
  7527. if ($value [1] == 'ROLE') {
  7528. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7529. if ($pos !== false) {
  7530. $roleId = $value [0];
  7531. }
  7532. }
  7533. }
  7534. // 审批日志
  7535. // echo $roleId;die;
  7536. if (! empty ( $roleId )) {
  7537. Doo::loadModel ( "role" );
  7538. $role = new role ();
  7539. $roleInfo = $role->getOne ( array (
  7540. 'where' => 'rid=' . $roleId,
  7541. 'asArray' => true
  7542. ) );
  7543. // $receiptLog->rolename = $roleInfo ['name'];
  7544. }
  7545. $receiptLog->username = $this->staff [0] ['username'];
  7546. $receiptLog->uid = $this->staff [0] ['sid'];
  7547. $receiptLog->date = date ( "Y-m-d" );
  7548. $receiptLog->opinion = '提交审批';
  7549. $receiptLog->img = $this->staff [0] ['avatar'];
  7550. $receiptLog->status = 2;
  7551. $receiptLog->rid = $rid;
  7552. $receiptLog->insert ();
  7553. // statistics item
  7554. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7555. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7556. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7557. $stat = $statistics->getOne ( array (
  7558. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7559. 'asArray' => true
  7560. ) );
  7561. if (empty ( $stat )) {
  7562. $statistics->date = date ( "Y-m-d" );
  7563. $statistics->cid = $this->staff [0] ['cid'];
  7564. $statistics->staff = $this->staff [0] ['sid'];
  7565. $statistics->agPrice = 0;
  7566. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7567. $statistics->insert ();
  7568. } else {
  7569. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7570. $statistics->update ( array (
  7571. 'where' => 'sid=' . $stat ['sid']
  7572. ) );
  7573. }
  7574. return "/expenses";
  7575. }
  7576. function approval() {
  7577. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7578. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7579. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7580. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7581. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7582. if (empty ( $status ))
  7583. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7584. $vidList = array ();
  7585. $button = 0;
  7586. Doo::loadModel ( 'verify' );
  7587. $verify = new verify ();
  7588. Doo::loadModel ( 'receipt' );
  7589. $receipt = new receipt ();
  7590. Doo::loadModel ( 'staff' );
  7591. $staff = new staff ();
  7592. Doo::loadModel ( 'L_category' );
  7593. $Lcategory = new L_category ();
  7594. // user verify ID
  7595. $verifyDetail = $verify->find ( array (
  7596. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7597. 'asArray' => true
  7598. ) );
  7599. foreach ( $verifyDetail as $key => $value ) {
  7600. array_push ( $vidList, $value ['vid'] );
  7601. }
  7602. $vid = implode ( ",", $vidList );
  7603. if (empty ( $verifyDetail ))
  7604. $vid = 0;
  7605. /*
  7606. */
  7607. $dateCondition = " and Year(date) =" . $year;
  7608. if (! empty ( $month ))
  7609. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7610. $categoryList = $Lcategory->find ( array (
  7611. 'asArray' => true
  7612. ) );
  7613. $staffList = $staff->find ( array (
  7614. 'where' => 'cid=' . $cid,
  7615. 'asArray' => true
  7616. ) );
  7617. $cateCondition = "";
  7618. $staffCondition = "";
  7619. $approvalCondition = "";
  7620. if (! empty ( $cid ))
  7621. $cateCondition = ' and cid=' . $cid;
  7622. if (! empty ( $sid )) {
  7623. $staffCondition = ' and staff=' . $sid;
  7624. $cateCondition = "";
  7625. }
  7626. // elseif($status==1){
  7627. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7628. // }
  7629. if ($status == 2) {
  7630. // 查找角色审批人
  7631. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7632. }
  7633. $ap = "";
  7634. if ($status == 4) {
  7635. $ap = 4;
  7636. $status = 2;
  7637. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7638. }
  7639. if ($status == 5) {
  7640. $status = 4;
  7641. $ap = 5;
  7642. }
  7643. // echo $vid;
  7644. // get Receipt By verifyID status 2 .$approvalCondition
  7645. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7646. $receiptList = $receipt->find ( array (
  7647. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7648. 'desc' => 'rid',
  7649. 'asArray' => true
  7650. ) );
  7651. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7652. $Locate = 0;
  7653. if ($ap == 4)
  7654. $status = 4;
  7655. elseif ($ap == 5)
  7656. $status = 5;
  7657. foreach ( $receiptList as $key => $value ) {
  7658. $receiptList [$key] ['Locate'] = $Locate;
  7659. $Locate ++;
  7660. $receiptList [$key] ['reviseDetail'] = array ();
  7661. if (! empty ( $value ['reviseDetail'] ))
  7662. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7663. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7664. $categoryDetil = $Lcategory->getOne ( array (
  7665. 'where' => 'cid=' . $value ['cid'],
  7666. 'asArray' => true
  7667. ) );
  7668. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7669. $verifyList = $verify->getOne ( array (
  7670. 'where' => 'vid=' . $value ['verify'],
  7671. 'asArray' => true
  7672. ) );
  7673. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7674. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7675. foreach ( $verifyList as $k => $v ) {
  7676. // init verifyStaff
  7677. $verifyList [$k] ['date'] = "";
  7678. $verifyList [$k] ['opinion'] = "";
  7679. $verifyList [$k] ['status'] = "";
  7680. if (empty ( $verifyStaff )) {
  7681. $verifyList [$k] ['date'] = "";
  7682. $verifyList [$k] ['opinion'] = "";
  7683. if ($v [0] == $this->staff [0] ['sid']) {
  7684. $verifyList [$k] ['status'] = 4;
  7685. $button = 4;
  7686. }
  7687. } else {
  7688. $flag = true;
  7689. foreach ( $verifyStaff as $m => $u ) {
  7690. if ($v [0] == $m) {
  7691. $verifyList [$k] ['date'] = $u ['date'];
  7692. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7693. $verifyList [$k] ['status'] = $u ['status'];
  7694. $flag = false;
  7695. break;
  7696. }
  7697. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7698. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7699. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7700. }
  7701. if ($flag) { // 检测可编辑
  7702. if ($v [0] == $this->staff [0] ['sid']) {
  7703. $verifyList [$k] ['status'] = 4;
  7704. $button = 4;
  7705. }
  7706. }
  7707. }
  7708. }
  7709. $receiptList [$key] ['verifyList'] = $verifyList;
  7710. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7711. 'where' => 'sid=' . $value ['staff'],
  7712. 'asArray' => true
  7713. ) );
  7714. $receiptList [$key] ['button'] = $button;
  7715. }
  7716. // print_r($receiptList);die;
  7717. // $data['verifyDetail']=$verifyDetail;
  7718. $mothHtml = "";
  7719. for($i = 1; $i <= 12; $i ++) {
  7720. if ($month == $i)
  7721. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7722. else
  7723. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7724. }
  7725. $data ['mothHtml'] = $mothHtml;
  7726. $data ['receiptList'] = $receiptList;
  7727. $data ['receiptApprovalCount'] = count ( $receiptList );
  7728. $data ['status'] = $status;
  7729. $data ['year'] = $year;
  7730. $data ['categoryList'] = $categoryList;
  7731. $data ['staffList'] = $staffList;
  7732. $data ['cid'] = $cid;
  7733. $data ['sid'] = $sid;
  7734. $data ['ap'] = $ap;
  7735. $data ['memu'] = "receipt";
  7736. $data ['staff'] = $this->staff;
  7737. $data ['receiptMemu'] = 'approval';
  7738. $data ['verifyId'] = $this->verifyId;
  7739. $data ['executeId'] = $this->executeId;
  7740. $this->render ( "/admin/saea_reportList", $data );
  7741. }
  7742. function approvalDetails() {
  7743. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7744. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7745. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7746. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7747. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7748. Doo::loadModel ( 'verify' );
  7749. $verify = new verify ();
  7750. Doo::loadModel ( 'receipt' );
  7751. $receipt = new receipt ();
  7752. Doo::loadModel ( 'staff' );
  7753. $staff = new staff ();
  7754. Doo::loadModel ( 'L_category' );
  7755. $Lcategory = new L_category ();
  7756. Doo::loadModel ( 'enclosur' );
  7757. $enclosur = new enclosur ();
  7758. $vidList = array ();
  7759. $verifyDetail = $verify->find ( array (
  7760. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7761. 'asArray' => true
  7762. ) );
  7763. foreach ( $verifyDetail as $key => $value ) {
  7764. array_push ( $vidList, $value ['vid'] );
  7765. }
  7766. $vid = implode ( ",", $vidList );
  7767. if (empty ( $verifyDetail ))
  7768. $vid = 0;
  7769. $categoryList = $Lcategory->find ( array (
  7770. 'asArray' => true
  7771. ) );
  7772. $staffList = $staff->find ( array (
  7773. 'where' => 'cid=' . $cid,
  7774. 'asArray' => true
  7775. ) );
  7776. $ap = 0;
  7777. $receiptList = $receipt->find ( array (
  7778. 'where' => 'rid =' . $rid,
  7779. 'desc' => 'rid',
  7780. 'asArray' => true
  7781. ) );
  7782. $Locate = 0;
  7783. $roleId = 0;
  7784. $button = 0;
  7785. foreach ( $receiptList as $key => $value ) {
  7786. $receiptList [$key] ['Locate'] = $Locate;
  7787. $Locate ++;
  7788. $receiptList [$key] ['reviseDetail'] = array ();
  7789. if (! empty ( $value ['reviseDetail'] ))
  7790. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7791. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7792. $categoryDetil = $Lcategory->getOne ( array (
  7793. 'where' => 'cid=' . $value ['cid'],
  7794. 'asArray' => true
  7795. ) );
  7796. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7797. // 检测编辑状态
  7798. $verifyList = $verify->getOne ( array (
  7799. 'where' => 'vid=' . $value ['verify'],
  7800. 'asArray' => true
  7801. ) );
  7802. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7803. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7804. Doo::loadModel ( 'role' );
  7805. $role = new role ();
  7806. // print_r($verifyList);
  7807. $flag = true;
  7808. $roleKey = 0;
  7809. $endStaffArray = array ();
  7810. $roleArrayCopy = array ();
  7811. foreach ( $verifyList as $k => $v ) {
  7812. // init verifyStaff
  7813. if ($v [1] == 'ROLE') {
  7814. if (! empty ( $verifyStaff )) {
  7815. $endStaffArray = end ( $verifyStaff );
  7816. if ($v [0] == $endStaffArray ['nextStaff']) {
  7817. $roleId = $v [0];
  7818. }
  7819. }
  7820. $roleVerify = json_decode ( $v [3], true );
  7821. $roleKey = $k;
  7822. $roleArray = array ();
  7823. $rolename = $role->getOne ( array (
  7824. 'where' => 'rid=' . $v [0],
  7825. 'asArray' => true
  7826. ) );
  7827. foreach ( $roleVerify as $o => $p ) {
  7828. $staffID = explode ( '_', $p );
  7829. $staffInfo = $staff->getOne ( array (
  7830. 'where' => 'sid=' . $staffID [0],
  7831. 'asArray' => true
  7832. ) );
  7833. // print_r($staffID);
  7834. $exp = array (
  7835. 0 => $staffInfo ['sid'],
  7836. 1 => $staffID [1],
  7837. 2 => $staffInfo ['avatar'],
  7838. 'date' => '',
  7839. 'date' => '',
  7840. 'opinion' => '',
  7841. 'status' => '',
  7842. 'rolename' => $rolename ['name']
  7843. );
  7844. array_push ( $roleArray, $exp );
  7845. }
  7846. $roleArrayCopy [$v [0]] = $roleArray;
  7847. // $verifyList[$k]['roleArray']=$roleArray;
  7848. }
  7849. // print_r($roleArray);
  7850. $verifyList [$k] ['date'] = "";
  7851. $verifyList [$k] ['opinion'] = "";
  7852. $verifyList [$k] ['status'] = "";
  7853. if (empty ( $verifyStaff )) {
  7854. $verifyList [$k] ['date'] = "";
  7855. $verifyList [$k] ['opinion'] = "";
  7856. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7857. $verifyList [$k] ['status'] = 4;
  7858. $button = 4;
  7859. $flag = false;
  7860. }
  7861. } else {
  7862. foreach ( $verifyStaff as $m => $u ) {
  7863. if ($v [0] == $m) {
  7864. $verifyList [$k] ['date'] = $u ['date'];
  7865. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7866. $verifyList [$k] ['status'] = $u ['status'];
  7867. $flag = false;
  7868. break;
  7869. }
  7870. }
  7871. $endStaffArray = end ( $verifyStaff );
  7872. if (isset ( $endStaffArray ['ROLE'] )) {
  7873. } else {
  7874. $endKey = key ( $verifyStaff );
  7875. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7876. $button = 4;
  7877. $verifyList [$k] ['status'] = 4;
  7878. }
  7879. }
  7880. }
  7881. }
  7882. $rolename ['name'] = '';
  7883. if (! empty ( $roleId )) {
  7884. Doo::loadModel ( 'role' );
  7885. $role = new role ();
  7886. $rolename = $role->getOne ( array (
  7887. 'where' => 'rid=' . $roleId,
  7888. 'asArray' => true
  7889. ) );
  7890. }
  7891. if (! empty ( $verifyStaff ))
  7892. $endStaffArray = end ( $verifyStaff );
  7893. $KOP = false;
  7894. foreach ( $roleArrayCopy as $P => $A ) {
  7895. foreach ( $A as $MKI => $AVL ) {
  7896. if (! empty ( $verifyStaff )) {
  7897. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7898. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7899. $button = 4;
  7900. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7901. }
  7902. foreach ( $verifyStaff as $m => $u ) {
  7903. $AVLFK = $AVL [0] . '_R';
  7904. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7905. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7906. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7907. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7908. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7909. break;
  7910. }
  7911. }
  7912. } else {
  7913. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7914. $button = 4;
  7915. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7916. }
  7917. }
  7918. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7919. $KOP = true;
  7920. }
  7921. }
  7922. foreach ( $roleArrayCopy as $k => $v ) {
  7923. foreach ( $verifyList as $m => $n ) {
  7924. if ($n [0] == $k) {
  7925. array_splice ( $verifyList, $m, 1, $v );
  7926. }
  7927. }
  7928. }
  7929. $receiptList [$key] ['verifyList'] = $verifyList;
  7930. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7931. 'where' => 'sid=' . $value ['staff'],
  7932. 'asArray' => true
  7933. ) );
  7934. $receiptList [$key] ['button'] = $button;
  7935. }
  7936. $mothHtml = "";
  7937. for($i = 1; $i <= 12; $i ++) {
  7938. if ($month == $i)
  7939. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7940. else
  7941. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7942. }
  7943. // 获取审批日志
  7944. Doo::loadModel ( 'receiptLog' );
  7945. $receiptLog = new receiptLog ();
  7946. $rlList = array ();
  7947. $rlInfo = $receiptLog->getOne ( array (
  7948. 'where' => 'rid=' . $rid . ' and status=4',
  7949. 'asArray' => true
  7950. ) );
  7951. $tijdate = $receiptLog->getOne ( array (
  7952. 'where' => 'rid=' . $rid . ' and status=2',
  7953. 'asc' => 'rlid',
  7954. 'asArray' => true
  7955. ) );
  7956. if (! empty ( $rlInfo )) {
  7957. $rlList = $receiptLog->find ( array (
  7958. 'where' => 'rid=' . $rid,
  7959. 'asc' => 'rlid',
  7960. 'asArray' => true
  7961. ) );
  7962. }
  7963. $receiptList [0] ['rlList'] = $rlList;
  7964. $enclosurList = $enclosur->find ( array (
  7965. 'where' => 'rid=' . $rid,
  7966. 'asArray' => true
  7967. ) );
  7968. $enclosurHtml = '';
  7969. foreach ( $enclosurList as $value ) {
  7970. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  7971. }
  7972. $data ['enclosurHtml'] = $enclosurHtml;
  7973. $data ['rolename'] = $rolename ['name'];
  7974. $data ['datetij'] = $tijdate ['date'];
  7975. $data ['mothHtml'] = $mothHtml;
  7976. $data ['receiptList'] = $receiptList;
  7977. $data ['receiptApprovalCount'] = count ( $receiptList );
  7978. $data ['year'] = $year;
  7979. $data ['categoryList'] = $categoryList;
  7980. $data ['staffList'] = $staffList;
  7981. $data ['cid'] = $cid;
  7982. $data ['sid'] = $sid;
  7983. $data ['status'] = 0;
  7984. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  7985. $ap = 4;
  7986. } else
  7987. $data ['status'] = $receiptList [0] ['status'];
  7988. if ($receiptList [0] ['status'] == 4) {
  7989. $data ['status'] = 5;
  7990. $ap = 0;
  7991. }
  7992. $data ['ap'] = $ap;
  7993. $data ['memu'] = "receipt";
  7994. $data ['staff'] = $this->staff;
  7995. $data ['receiptMemu'] = 'approval';
  7996. $data ['verifyId'] = $this->verifyId;
  7997. $data ['executeId'] = $this->executeId;
  7998. $this->render ( "/admin/saeaReportListReport", $data );
  7999. }
  8000. function approvalEdi() {
  8001. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8002. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  8003. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8004. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8005. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  8006. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  8007. if (empty ( $status ))
  8008. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  8009. $vidList = array ();
  8010. $button = 0;
  8011. Doo::loadModel ( 'verify' );
  8012. Doo::loadModel ( 'receipt' );
  8013. Doo::loadModel ( 'staff' );
  8014. $staff = new staff ();
  8015. $receipt = new receipt ();
  8016. $verify = new verify ();
  8017. Doo::loadModel ( 'L_category' );
  8018. $Lcategory = new L_category ();
  8019. Doo::loadModel ( 'enclosur' );
  8020. $enclosur = new enclosur ();
  8021. // user verify ID
  8022. $verifyDetail = $verify->find ( array (
  8023. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  8024. 'asArray' => true
  8025. ) );
  8026. foreach ( $verifyDetail as $key => $value ) {
  8027. array_push ( $vidList, $value ['vid'] );
  8028. }
  8029. $vid = implode ( ",", $vidList );
  8030. if (empty ( $verifyDetail ))
  8031. $vid = 0;
  8032. $categoryList = $Lcategory->find ( array (
  8033. 'asArray' => true
  8034. ) );
  8035. $staffList = $staff->find ( array (
  8036. 'where' => 'cid=' . $cid,
  8037. 'asArray' => true
  8038. ) );
  8039. $ap = "";
  8040. if ($status == 4) {
  8041. $ap = 4;
  8042. $status = 2;
  8043. }
  8044. // get Receipt By verifyID status 2
  8045. $receiptList = $receipt->find ( array (
  8046. 'where' => 'rid =' . $rid,
  8047. 'desc' => 'rid',
  8048. 'asArray' => true
  8049. ) );
  8050. $Locate = 0;
  8051. $roleId = 0;
  8052. if ($ap == 4)
  8053. $status = 4;
  8054. foreach ( $receiptList as $key => $value ) {
  8055. $receiptList [$key] ['Locate'] = $Locate;
  8056. $Locate ++;
  8057. $receiptList [$key] ['reviseDetail'] = array ();
  8058. if (! empty ( $value ['reviseDetail'] ))
  8059. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  8060. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  8061. $categoryDetil = $Lcategory->getOne ( array (
  8062. 'where' => 'cid=' . $value ['cid'],
  8063. 'asArray' => true
  8064. ) );
  8065. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  8066. // 检测编辑状态
  8067. $verifyList = $verify->getOne ( array (
  8068. 'where' => 'vid=' . $value ['verify'],
  8069. 'asArray' => true
  8070. ) );
  8071. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  8072. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  8073. // print_r($verifyList);
  8074. //
  8075. // if (empty($verifyStaff)){
  8076. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  8077. // $verifyList[0]['status']=4;$button=4;
  8078. // }
  8079. //
  8080. // }else{
  8081. //
  8082. // }
  8083. // die;
  8084. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  8085. // echo array_search("green",$a);
  8086. //
  8087. Doo::loadModel ( 'role' );
  8088. $role = new role ();
  8089. // print_r($verifyList);
  8090. $flag = true;
  8091. $roleKey = 0;
  8092. $endStaffArray = array ();
  8093. $roleArrayCopy = array ();
  8094. foreach ( $verifyList as $k => $v ) {
  8095. // init verifyStaff
  8096. if ($v [1] == 'ROLE') {
  8097. if (! empty ( $verifyStaff )) {
  8098. $endStaffArray = end ( $verifyStaff );
  8099. if ($v [0] == $endStaffArray ['nextStaff']) {
  8100. $roleId = $v [0];
  8101. }
  8102. }
  8103. $roleVerify = json_decode ( $v [3], true );
  8104. $roleKey = $k;
  8105. $roleArray = array ();
  8106. $rolename = $role->getOne ( array (
  8107. 'where' => 'rid=' . $v [0],
  8108. 'asArray' => true
  8109. ) );
  8110. foreach ( $roleVerify as $o => $p ) {
  8111. $staffID = explode ( '_', $p );
  8112. $staffInfo = $staff->getOne ( array (
  8113. 'where' => 'sid=' . $staffID [0],
  8114. 'asArray' => true
  8115. ) );
  8116. // print_r($staffID);
  8117. $exp = array (
  8118. 0 => $staffInfo ['sid'],
  8119. 1 => $staffID [1],
  8120. 2 => $staffInfo ['avatar'],
  8121. 'date' => '',
  8122. 'date' => '',
  8123. 'opinion' => '',
  8124. 'status' => '',
  8125. 'rolename' => $rolename ['name']
  8126. );
  8127. array_push ( $roleArray, $exp );
  8128. }
  8129. $roleArrayCopy [$v [0]] = $roleArray;
  8130. // $verifyList[$k]['roleArray']=$roleArray;
  8131. }
  8132. // print_r($roleArray);
  8133. $verifyList [$k] ['date'] = "";
  8134. $verifyList [$k] ['opinion'] = "";
  8135. $verifyList [$k] ['status'] = "";
  8136. if (empty ( $verifyStaff )) {
  8137. $verifyList [$k] ['date'] = "";
  8138. $verifyList [$k] ['opinion'] = "";
  8139. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  8140. $verifyList [$k] ['status'] = 4;
  8141. $button = 4;
  8142. $flag = false;
  8143. }
  8144. } else {
  8145. foreach ( $verifyStaff as $m => $u ) {
  8146. if ($v [0] == $m) {
  8147. $verifyList [$k] ['date'] = $u ['date'];
  8148. $verifyList [$k] ['opinion'] = $u ['opinion'];
  8149. $verifyList [$k] ['status'] = $u ['status'];
  8150. $flag = false;
  8151. break;
  8152. }
  8153. }
  8154. $endStaffArray = end ( $verifyStaff );
  8155. if (isset ( $endStaffArray ['ROLE'] )) {
  8156. } else {
  8157. $endKey = key ( $verifyStaff );
  8158. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  8159. $button = 4;
  8160. $verifyList [$k] ['status'] = 4;
  8161. }
  8162. }
  8163. // print_r($endStaffArray);die;
  8164. // if (empty($verifyStaff)){
  8165. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  8166. // $verifyList[$k]['status']=4;$button=4;
  8167. // }
  8168. //
  8169. // }else{
  8170. //
  8171. // }
  8172. // if($flag){//检测可编辑
  8173. // if($v[0]==$this->staff[0]['sid']){
  8174. // $verifyList[$k]['status']=4;$button=4;
  8175. // }
  8176. // }
  8177. }
  8178. }
  8179. $rolename ['name'] = '';
  8180. if (! empty ( $roleId )) {
  8181. Doo::loadModel ( 'role' );
  8182. $role = new role ();
  8183. $rolename = $role->getOne ( array (
  8184. 'where' => 'rid=' . $roleId,
  8185. 'asArray' => true
  8186. ) );
  8187. }
  8188. if (! empty ( $verifyStaff ))
  8189. $endStaffArray = end ( $verifyStaff );
  8190. $KOP = false;
  8191. foreach ( $roleArrayCopy as $P => $A ) {
  8192. foreach ( $A as $MKI => $AVL ) {
  8193. if (! empty ( $verifyStaff )) {
  8194. // &&$rolename['rid']==$endStaffArray['nextStaff']
  8195. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  8196. $button = 4;
  8197. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  8198. }
  8199. foreach ( $verifyStaff as $m => $u ) {
  8200. $AVLFK = $AVL [0] . '_R';
  8201. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  8202. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  8203. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  8204. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  8205. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  8206. break;
  8207. }
  8208. }
  8209. } else {
  8210. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  8211. $button = 4;
  8212. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  8213. }
  8214. }
  8215. // $roleArray[$MKI]['rolename']=$rolename['name'];
  8216. $KOP = true;
  8217. }
  8218. }
  8219. // print_r($roleArrayCopy);
  8220. // echo $roleKey;
  8221. foreach ( $roleArrayCopy as $k => $v ) {
  8222. foreach ( $verifyList as $m => $n ) {
  8223. if ($n [0] == $k) {
  8224. array_splice ( $verifyList, $m, 1, $v );
  8225. }
  8226. }
  8227. }
  8228. // if ($KOP)
  8229. // array_splice($verifyList,$roleKey,1,$roleArray);
  8230. // print_r($verifyList);
  8231. $receiptList [$key] ['verifyList'] = $verifyList;
  8232. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  8233. 'where' => 'sid=' . $value ['staff'],
  8234. 'asArray' => true
  8235. ) );
  8236. $receiptList [$key] ['button'] = $button;
  8237. }
  8238. // $data['verifyDetail']=$verifyDetail;
  8239. $mothHtml = "";
  8240. for($i = 1; $i <= 12; $i ++) {
  8241. if ($month == $i)
  8242. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8243. else
  8244. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8245. }
  8246. // 获取审批日志
  8247. Doo::loadModel ( 'receiptLog' );
  8248. $receiptLog = new receiptLog ();
  8249. $rlList = array ();
  8250. $rlInfo = $receiptLog->getOne ( array (
  8251. 'where' => 'rid=' . $rid . ' and status=4',
  8252. 'asArray' => true
  8253. ) );
  8254. $tijdate = $receiptLog->getOne ( array (
  8255. 'where' => 'rid=' . $rid . ' and status=2',
  8256. 'asc' => 'rlid',
  8257. 'asArray' => true
  8258. ) );
  8259. if (! empty ( $rlInfo )) {
  8260. $rlList = $receiptLog->find ( array (
  8261. 'where' => 'rid=' . $rid,
  8262. 'asc' => 'rlid',
  8263. 'asArray' => true
  8264. ) );
  8265. }
  8266. $receiptList [0] ['rlList'] = $rlList;
  8267. $enclosurList = $enclosur->find ( array (
  8268. 'where' => 'rid=' . $rid,
  8269. 'asArray' => true
  8270. ) );
  8271. $enclosurHtml = '';
  8272. foreach ( $enclosurList as $value ) {
  8273. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  8274. }
  8275. $data ['enclosurHtml'] = $enclosurHtml;
  8276. $data ['rolename'] = $rolename ['name'];
  8277. $data ['datetij'] = $tijdate ['date'];
  8278. $data ['mothHtml'] = $mothHtml;
  8279. $data ['receiptList'] = $receiptList;
  8280. $data ['receiptApprovalCount'] = count ( $receiptList );
  8281. $data ['status'] = $status;
  8282. $data ['year'] = $year;
  8283. $data ['categoryList'] = $categoryList;
  8284. $data ['staffList'] = $staffList;
  8285. $data ['cid'] = $cid;
  8286. $data ['sid'] = $sid;
  8287. $data ['ap'] = $ap;
  8288. $data ['memu'] = "receipt";
  8289. $data ['staff'] = $this->staff;
  8290. $data ['receiptMemu'] = 'approval';
  8291. $data ['verifyId'] = $this->verifyId;
  8292. $data ['executeId'] = $this->executeId;
  8293. $this->render ( "/admin/saeaReportListReport", $data );
  8294. }
  8295. function remittanceHky() {
  8296. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  8297. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  8298. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  8299. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  8300. $page_size = 15;
  8301. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  8302. Doo::loadModel ( 'receipt' );
  8303. $receipt = new receipt ();
  8304. Doo::loadModel ( 'staff' );
  8305. $staff = new staff ();
  8306. $dateCondition = " and Year(executeDate) =" . $year;
  8307. if ($moth != 'MONTH')
  8308. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  8309. if ($day != 'DAY' && $moth != 'MONTH')
  8310. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  8311. $sql = ' (status =8 or status=9 ) and amount>0 ' . $dateCondition;
  8312. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  8313. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  8314. $limit = $pageinfo ['lower'] . ',' . $page_size;
  8315. $dayList = $receipt->find ( array (
  8316. 'select' => 'executeDate,sum(amount) as amount',
  8317. 'where' => $sql,
  8318. 'desc' => 'executeDate',
  8319. 'groupby' => 'executeDate',
  8320. 'limit' => $limit,
  8321. 'asArray' => true
  8322. ) );
  8323. // print_r($dayList);
  8324. foreach ( $dayList as $key => $value ) {
  8325. $remitString = "";
  8326. $receiptList = $receipt->find ( array (
  8327. 'select' => 'rid,executeDate,amount,staff,cid',
  8328. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  8329. 'desc' => 'executeDate',
  8330. 'asArray' => true
  8331. ) );
  8332. foreach ( $receiptList as $k => $v ) {
  8333. $sinfo = $staff->getOne ( array (
  8334. 'select' => 'username,category',
  8335. 'where' => ' sid=' . $v ['staff'],
  8336. 'asArray' => true
  8337. ) );
  8338. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  8339. }
  8340. $dayList [$key] ['staff'] = $remitString;
  8341. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  8342. }
  8343. // print_r($dayList);
  8344. $mothHtml = "";
  8345. for($i = 1; $i <= 12; $i ++) {
  8346. if ($moth == $i)
  8347. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8348. else
  8349. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8350. }
  8351. $dayHtml = "";
  8352. if ($day != "DAY" || $moth != "MONTH") {
  8353. for($i = 1; $i <= 31; $i ++) {
  8354. if ($day == $i)
  8355. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  8356. else
  8357. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  8358. }
  8359. }
  8360. $dateHtml = "";
  8361. $now = date ( "Y" );
  8362. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  8363. if ($YEARD <= $now) {
  8364. $dateHtml .= '<option ';
  8365. if ($year == $YEARD) {
  8366. $dateHtml .= 'selected ';
  8367. }
  8368. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  8369. }
  8370. }
  8371. $data ['dateHtml'] = $dateHtml;
  8372. $data ['page'] = $pageinfo;
  8373. $data ['year'] = $year;
  8374. $data ['moth'] = $moth;
  8375. $data ['day'] = $day;
  8376. $data ['get'] = $get;
  8377. $data ['dayHtml'] = $dayHtml;
  8378. $data ['mothHtml'] = $mothHtml;
  8379. $data ['receiptList'] = $dayList;
  8380. $data ['memu'] = "receipt";
  8381. $data ['staff'] = $this->staff;
  8382. $data ['receiptMemu'] = 'remittanceHky';
  8383. $data ['verifyId'] = $this->verifyId;
  8384. $data ['executeId'] = $this->executeId;
  8385. $this->render ( "/admin/remittanceHky", $data );
  8386. }
  8387. function remittancep() {
  8388. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  8389. Doo::loadModel ( 'receipt' );
  8390. $receipt = new receipt ();
  8391. Doo::loadModel ( 'staff' );
  8392. $staff = new staff ();
  8393. Doo::loadClass ( 'XDeode' );
  8394. $XDeode = new XDeode ( 5 );
  8395. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  8396. $rplist = $receipt->find ( array (
  8397. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8398. 'asArray' => true
  8399. ) );
  8400. $dayList = $receipt->find ( array (
  8401. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8402. 'desc' => 'executeDate',
  8403. 'groupby' => 'staff',
  8404. 'asArray' => true
  8405. ) );
  8406. $html = '';
  8407. foreach ( $dayList as $key => $value ) {
  8408. $sinfo = $staff->getOne ( array (
  8409. 'select' => 'username,category',
  8410. 'where' => ' sid=' . $value ['staff'],
  8411. 'asArray' => true
  8412. ) );
  8413. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  8414. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  8415. $au = 0;
  8416. foreach ( $rplist as $k => $v ) {
  8417. if ($value ['staff'] == $v ['staff']) {
  8418. $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>';
  8419. $au += $v ['amount'];
  8420. }
  8421. }
  8422. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  8423. }
  8424. $data ['html'] = $html;
  8425. $data ['memu'] = "receipt";
  8426. $data ['staff'] = $this->staff;
  8427. $data ['receiptMemu'] = 'remittanceHky';
  8428. $data ['verifyId'] = $this->verifyId;
  8429. $data ['executeId'] = $this->executeId;
  8430. $this->render ( "/admin/remittancep", $data );
  8431. }
  8432. function ajaxGetReceiptDetails() {
  8433. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  8434. Doo::loadClass ( 'XDeode' );
  8435. $XDeode = new XDeode ( 5 );
  8436. $rid = $XDeode->decode ( $rid );
  8437. if (empty ( $rid )) {
  8438. echo json_encode ( array (
  8439. 'status' => 2,
  8440. 'msg' => 'illegal request'
  8441. ) );
  8442. die ();
  8443. }
  8444. Doo::loadModel ( 'receipt' );
  8445. $receipt = new receipt ();
  8446. Doo::loadModel ( 'staff' );
  8447. $staff = new staff ();
  8448. $rinfo = $receipt->getOne ( array (
  8449. 'where' => 'rid= ' . $rid,
  8450. 'asArray' => true
  8451. ) );
  8452. $sinfo = $staff->getOne ( array (
  8453. 'select' => 'username,category',
  8454. 'where' => ' sid=' . $rinfo ['staff'],
  8455. 'asArray' => true
  8456. ) );
  8457. $rinfo ['reviseDetail'] = array ();
  8458. if (! empty ( $rinfo ['reviseDetail'] ))
  8459. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  8460. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  8461. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  8462. $rinfo ['category'] = $sinfo ['category'];
  8463. $verifyStaff = array ();
  8464. if (! empty ( $rinfo ['verifyStaff'] ))
  8465. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  8466. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  8467. $rinfo ['relust'] = $relust;
  8468. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  8469. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  8470. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  8471. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  8472. // 费用执行人相关数据
  8473. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  8474. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  8475. foreach ( $executeCopy as $k => $v ) {
  8476. $executeCopy [$k] ['date'] = '';
  8477. $executeCopy [$k] ['opinion'] = '';
  8478. $executeCopy [$k] ['status'] = '';
  8479. if (! empty ( $executeStaff ))
  8480. foreach ( $executeStaff as $m => $u ) {
  8481. if ($v [0] == $m) {
  8482. $executeCopy [$k] ['date'] = $u ['date'];
  8483. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  8484. $executeCopy [$k] ['status'] = $u ['status'];
  8485. break;
  8486. }
  8487. }
  8488. }
  8489. $rinfo ['executeCopy'] = $executeCopy;
  8490. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8491. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8492. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8493. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8494. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8495. $html .= '<tr><th>' . $value ['name'] . '</th>
  8496. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8497. }
  8498. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8499. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8500. <tr><th class="taC" colspan="2">费用说明</th>
  8501. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8502. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8503. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8504. </tbody></table>';
  8505. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8506. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8507. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8508. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8509. $html .= '<tr><th>' . $value ['name'] . '</th>
  8510. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8511. }
  8512. $html .= '<tr><th class="taR">合计</th>
  8513. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8514. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8515. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8516. $html .= '<tr><th>' . $value ['name'] . '</th>
  8517. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8518. }
  8519. $html .= '<tr><th class="taR">合计</th>
  8520. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8521. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8522. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8523. $html .= '<tr><th>' . $value ['name'] . '</th>
  8524. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8525. }
  8526. $html .= '<tr><th class="taR">合计</th>
  8527. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8528. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8529. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8530. $html .= '<tr><th>' . $value ['name'] . '</th>
  8531. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8532. }
  8533. $html .= '<tr><th class="taR">合计</th>
  8534. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8535. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8536. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8537. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8538. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8539. }
  8540. $html .= '<tr><th class="taR">合计</th>
  8541. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8542. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8543. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8544. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8545. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8546. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8547. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8548. <tr';
  8549. if ($rinfo ['relust'] >= 0) {
  8550. $html .= 'class="success"';
  8551. } else {
  8552. $html .= 'class="error"';
  8553. }
  8554. $html .= '><td class="taR"><b>借款结余</b></td>
  8555. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8556. </tbody></table>
  8557. ';
  8558. }
  8559. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8560. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8561. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8562. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8563. $html .= '<tr><th>' . $value ['name'] . '</th>
  8564. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8565. }
  8566. $html .= '<tr><th class="taR">合计</th>
  8567. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8568. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8569. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8570. <tr><th class="taC" colspan="2">费用说明</th>
  8571. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8572. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8573. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8574. </tbody></table>';
  8575. } else {
  8576. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8577. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8578. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8579. $html .= '<tr><th>' . $value ['name'] . '</th>
  8580. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8581. }
  8582. $html .= '<tr><th class="taR">合计</th>
  8583. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8584. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8585. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8586. $html .= '<tr><th>' . $value ['name'] . '</th>
  8587. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8588. }
  8589. $html .= '<tr><th class="taR">合计</th>
  8590. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8591. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8592. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8593. $html .= '<tr><th>' . $value ['name'] . '</th>
  8594. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8595. }
  8596. $html .= '<tr><th class="taR">合计</th>
  8597. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8598. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8599. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8600. $html .= '<tr><th>' . $value ['name'] . '</th>
  8601. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8602. }
  8603. $html .= '<tr><th class="taR">合计</th>
  8604. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8605. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8606. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8607. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8608. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8609. }
  8610. $html .= '<tr><th class="taR">合计</th>
  8611. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8612. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8613. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8614. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8615. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8616. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8617. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8618. $html .= '</tbody></table>';
  8619. /*
  8620. * <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>
  8621. */
  8622. }
  8623. // print_r($verifyStaff);die;
  8624. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8625. foreach ( $verifyStaff as $key => $value ) {
  8626. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8627. $sinfo = $staff->getOne ( array (
  8628. 'select' => 'username',
  8629. 'where' => ' sid=' . $key,
  8630. 'asArray' => true
  8631. ) );
  8632. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8633. }
  8634. $html .= '</tbody></table>';
  8635. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8636. foreach ( $rinfo ['executeCopy'] as $value ) {
  8637. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8638. }
  8639. $html .= '</tbody></table>';
  8640. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8641. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8642. </tr></table>';
  8643. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8644. echo json_encode ( array (
  8645. 'status' => 1,
  8646. 'html' => $html
  8647. ) );
  8648. die ();
  8649. }
  8650. /**
  8651. * 删除附件
  8652. */
  8653. function ajaxRemEnclousur() {
  8654. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8655. if (empty ( $key ))
  8656. echo json_encode ( array (
  8657. 'status' => 2
  8658. ) );
  8659. Doo::loadModel ( 'enclosur' );
  8660. $enclosur = new enclosur ();
  8661. $enclosur->delEnclosurByEid ( $key );
  8662. echo json_encode ( array (
  8663. 'status' => 1
  8664. ) );
  8665. }
  8666. function remittance() {
  8667. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8668. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8669. Doo::loadModel ( 'receipt' );
  8670. $receipt = new receipt ();
  8671. Doo::loadModel ( 'staff' );
  8672. $staff = new staff ();
  8673. $dateCondition = " and Year(pastDate) =" . $year;
  8674. if (! empty ( $month ))
  8675. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8676. // get Receipt By verifyID status 1
  8677. $receiptList = $receipt->find ( array (
  8678. 'select' => 'sum(sum) as sum,staff,pastDate',
  8679. 'where' => ' status=1' . $dateCondition,
  8680. 'desc' => 'pastDate',
  8681. 'groupby' => 'staff,pastDate',
  8682. 'asArray' => true
  8683. ) );
  8684. $dateList = $receipt->find ( array (
  8685. 'select' => 'pastDate,verifyStaff',
  8686. 'where' => ' status=1' . $dateCondition,
  8687. 'desc' => 'pastDate',
  8688. 'groupby' => 'pastDate',
  8689. 'asArray' => true
  8690. ) );
  8691. $dataList = array ();
  8692. foreach ( $dateList as $d => $a ) {
  8693. $dataList [$a ['pastDate']] = array ();
  8694. $daySum = 0;
  8695. foreach ( $receiptList as $key => $value ) {
  8696. if ($a ['pastDate'] == $value ['pastDate']) {
  8697. $oderList = $receipt->find ( array (
  8698. 'select' => 'receiptOrder',
  8699. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8700. 'asArray' => true
  8701. ) );
  8702. $list = array ();
  8703. $html = "";
  8704. foreach ( $oderList as $v ) {
  8705. array_push ( $list, $v ['receiptOrder'] );
  8706. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8707. }
  8708. $receiptList [$key] ['receiptOrder'] = $html;
  8709. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8710. $sinfo = $staff->getOne ( array (
  8711. 'select' => 'username ',
  8712. 'where' => ' sid=' . $value ['staff'],
  8713. 'asArray' => true
  8714. ) );
  8715. $receiptList [$key] ['username'] = $sinfo ['username'];
  8716. $daySum += $value ['sum'];
  8717. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8718. }
  8719. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8720. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8721. }
  8722. }
  8723. // print_r($dataList);
  8724. $data ['dataList'] = $dataList;
  8725. $mothHtml = "";
  8726. for($i = 1; $i <= 12; $i ++) {
  8727. if ($month == $i)
  8728. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8729. else
  8730. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8731. }
  8732. $data ['year'] = $year;
  8733. $data ['mothHtml'] = $mothHtml;
  8734. $data ['memu'] = "receipt";
  8735. $data ['staff'] = $this->staff;
  8736. $data ['receiptMemu'] = 'approval';
  8737. $data ['verifyId'] = $this->verifyId;
  8738. $data ['executeId'] = $this->executeId;
  8739. $this->render ( "/admin/saeaReportListPay", $data );
  8740. }
  8741. /**
  8742. * 金额调整,提高稳定性
  8743. * @return string
  8744. */
  8745. function revocationAdjustment() {
  8746. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8747. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8748. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8749. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8750. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8751. Doo::loadClass ( 'XDeode' );
  8752. $XDeode = new XDeode ( 5 );
  8753. Doo::loadModel ( 'receipt' );
  8754. $receipt = new receipt ();
  8755. $sid = $XDeode->decode ( $sidKey );
  8756. $rid = $XDeode->decode ( $ridKey );
  8757. $reviseKey = $XDeode->decode ( $reviseKey );
  8758. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8759. die ( 'illegal request' );
  8760. $receiptDetail = $receipt->getOne ( array (
  8761. 'where' => 'rid=' . $rid,
  8762. 'asArray' => true
  8763. ) );
  8764. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8765. die ( 'illegal request' );
  8766. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8767. if (! isset ( $reviseDetail [$reviseKey] ))
  8768. die ( 'illegal request' );
  8769. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8770. unset ( $reviseDetail [$reviseKey] );
  8771. $revisePrice = 0;
  8772. foreach ( $reviseDetail as $key => $value ) {
  8773. $revisePrice += $value ['price'];
  8774. }
  8775. $reviseDetailString = json_encode ( $reviseDetail );
  8776. $receipt->reviseDetail = $reviseDetailString;
  8777. $receipt->sum = $receiptDetail ['sum'] - $price;
  8778. $receipt->revisePrice = $revisePrice;
  8779. $receipt->update ( array (
  8780. 'where' => 'rid=' . $rid
  8781. ) );
  8782. return '/receiptburEdi/' . $rid;
  8783. } else
  8784. die ( 'illegal request2' );
  8785. }
  8786. function updateApprovalReceipt() {
  8787. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8788. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8789. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8790. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8791. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8792. if (! empty ( $rid )) {
  8793. Doo::loadModel ( "verify" );
  8794. $verify = new verify ();
  8795. Doo::loadModel ( "receiptDetail" );
  8796. $receiptDetailObj = new receiptDetail ();
  8797. Doo::loadModel ( "itemStatistics" );
  8798. Doo::loadModel ( "statistics" );
  8799. $statistics = new statistics ();
  8800. $itemStatistics = new itemStatistics ();
  8801. Doo::loadModel ( "receipt" );
  8802. $receipt = new receipt ();
  8803. $receiptDetail = $receipt->getOne ( array (
  8804. 'where' => 'rid=' . $rid . ' and status=2 ',
  8805. 'asArray' => true
  8806. ) );
  8807. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8808. $nsflag = true;
  8809. foreach ( $nslist as $value ) {
  8810. if ($value == $this->staff ['0'] ['sid']) {
  8811. $nsflag = false;
  8812. break;
  8813. }
  8814. }
  8815. if (empty ( $receiptDetail ) || $nsflag)
  8816. return "/approvalExpenses/pendApproval";
  8817. $verifyDetail = $verify->getOne ( array (
  8818. 'where' => ' vid =' . $receiptDetail ['verify'],
  8819. 'asArray' => true
  8820. ) );
  8821. $verifyString = $verifyDetail ['staff'];
  8822. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8823. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8824. if (empty ( $opinion )) {
  8825. if ($status == 3)
  8826. $opinion = "终止";
  8827. else
  8828. $opinion = "同意支付";
  8829. }
  8830. $nowStaff = 0;
  8831. $nowStaffList = array ();
  8832. if (empty ( $verifyStaff )) {
  8833. // 还需加入是否已经进入角色审批
  8834. if ($verifyDetail [0] [1] == 'ROLE') {
  8835. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8836. foreach ( $vStaffString as $key => $value ) {
  8837. $staffK = explode ( "_", $value );
  8838. if ($staffK [0] != $this->staff [0] ['sid'])
  8839. array_push ( $nowStaffList, $staffK [0] );
  8840. }
  8841. // print_r($verifyDetail);
  8842. // die;
  8843. if (! empty ( $nowStaffList )) {
  8844. $nowStaff = implode ( ',', $nowStaffList );
  8845. $verifyStaff = array (
  8846. $this->staff [0] ['sid'] . "_R" => array (
  8847. 'date' => date ( 'Y-m-d' ),
  8848. 'opinion' => $opinion,
  8849. 'status' => $status,
  8850. 'nextStaff' => $verifyDetail [0] [0],
  8851. 'ROLE' => 1
  8852. )
  8853. );
  8854. } else {
  8855. $nowStaff = $verifyDetail [1] [0];
  8856. $verifyStaff = array (
  8857. $this->staff [0] ['sid'] . "_R" => array (
  8858. 'date' => date ( 'Y-m-d' ),
  8859. 'opinion' => $opinion,
  8860. 'status' => $status,
  8861. 'nextStaff' => $verifyDetail [1] [0]
  8862. )
  8863. );
  8864. }
  8865. } else {
  8866. if ($verifyDetail [1] [1] == 'ROLE') {
  8867. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8868. // echo "dd";
  8869. foreach ( $vStaffString as $key => $value ) {
  8870. $staffK = explode ( "_", $value );
  8871. array_push ( $nowStaffList, $staffK [0] );
  8872. }
  8873. $nowStaff = implode ( ',', $nowStaffList );
  8874. $verifyStaff = array (
  8875. $this->staff [0] ['sid'] => array (
  8876. 'date' => date ( 'Y-m-d' ),
  8877. 'opinion' => $opinion,
  8878. 'status' => $status,
  8879. 'nextStaff' => $verifyDetail [1] [0],
  8880. 'ROLE' => 1
  8881. )
  8882. );
  8883. } else {
  8884. $nowStaff = $verifyDetail [1] [0];
  8885. $verifyStaff = array (
  8886. $this->staff [0] ['sid'] => array (
  8887. 'date' => date ( 'Y-m-d' ),
  8888. 'opinion' => $opinion,
  8889. 'status' => $status,
  8890. 'nextStaff' => $verifyDetail [1] [0]
  8891. )
  8892. );
  8893. }
  8894. }
  8895. if ($status == 3)
  8896. $verifyStaff = array (
  8897. 'final' => $status,
  8898. $this->staff [0] ['sid'] => array (
  8899. 'date' => date ( 'Y-m-d' ),
  8900. 'opinion' => $opinion,
  8901. 'status' => $status
  8902. )
  8903. );
  8904. $vStaffString = json_encode ( $verifyStaff );
  8905. $receipt->nowStaff = $nowStaff;
  8906. $receipt->verifyStaff = $vStaffString;
  8907. } else {
  8908. $VS = end ( $verifyStaff );
  8909. // 非角色审批
  8910. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8911. $nextStaff = 0;
  8912. $roleSTF = false;
  8913. foreach ( $verifyDetail as $key => $value ) {
  8914. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8915. if (isset ( $verifyDetail [$key + 1] )) {
  8916. $nextStaff = $verifyDetail [$key + 1] [0];
  8917. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8918. $roleSTF = true;
  8919. }
  8920. break;
  8921. }
  8922. }
  8923. if (! $roleSTF) {
  8924. $nowStaff = $nextStaff;
  8925. $verifyStaff [$this->staff [0] ['sid']] = array (
  8926. 'date' => date ( 'Y-m-d' ),
  8927. 'opinion' => $opinion,
  8928. 'status' => $status,
  8929. 'nextStaff' => $nextStaff
  8930. );
  8931. } else {
  8932. // 获取角色下的所有用户ID
  8933. $nowStaffList = array ();
  8934. foreach ( $verifyDetail as $vfk ) {
  8935. if ($vfk [1] == 'ROLE') {
  8936. $vStaffString = json_decode ( $vfk [3] );
  8937. foreach ( $vStaffString as $key => $value ) {
  8938. $staffK = explode ( "_", $value );
  8939. array_push ( $nowStaffList, $staffK [0] );
  8940. }
  8941. }
  8942. }
  8943. $nowStaff = implode ( ',', $nowStaffList );
  8944. $verifyStaff [$this->staff [0] ['sid']] = array (
  8945. 'date' => date ( 'Y-m-d' ),
  8946. 'opinion' => $opinion,
  8947. 'status' => $status,
  8948. 'nextStaff' => $nextStaff,
  8949. 'ROLE' => 0
  8950. );
  8951. }
  8952. if ($status == 3) {
  8953. $verifyStaff ['final'] = $status;
  8954. $verifyStaff [$this->staff [0] ['sid']] = array (
  8955. 'date' => date ( 'Y-m-d' ),
  8956. 'opinion' => $opinion,
  8957. 'status' => $status
  8958. );
  8959. }
  8960. $vStaffString = json_encode ( $verifyStaff );
  8961. $receipt->nowStaff = $nowStaff;
  8962. $receipt->verifyStaff = $vStaffString;
  8963. }
  8964. // 角色审批
  8965. if (isset ( $VS ['ROLE'] )) {
  8966. // 找出角色人 当前审批角色组
  8967. $verifyJSStaff = array ();
  8968. $nowStaffList2 = array ();
  8969. foreach ( $verifyDetail as $key => $value ) {
  8970. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  8971. $verifyJSStaff = json_decode ( $value [3] );
  8972. foreach ( $verifyJSStaff as $m ) {
  8973. $staffK = explode ( "_", $m );
  8974. array_push ( $nowStaffList2, $staffK [0] );
  8975. }
  8976. // print_r($nowStaffList2);
  8977. }
  8978. }
  8979. $RoleVerifyStaff = array ();
  8980. foreach ( $verifyStaff as $key => $value ) {
  8981. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  8982. foreach ( $nowStaffList2 as $m ) {
  8983. if ($key == $m . "_R")
  8984. $RoleVerifyStaff [$key] = $value;
  8985. }
  8986. }
  8987. }
  8988. // print_r($verifyStaff);
  8989. // print_r($nowStaffList2);
  8990. // print_r($RoleVerifyStaff);
  8991. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  8992. // print_r($verifyJSStaff);
  8993. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  8994. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  8995. // 下一个审批人ID
  8996. $nextStaff = 0;
  8997. $falg = false;
  8998. foreach ( $verifyDetail as $key => $value ) {
  8999. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  9000. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  9001. $falg = true;
  9002. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  9003. $nowStaffList = array ();
  9004. foreach ( $vStaffString as $v ) {
  9005. $staffK = explode ( "_", $v );
  9006. array_push ( $nowStaffList, $staffK [0] );
  9007. }
  9008. $nowStaff = implode ( ',', $nowStaffList );
  9009. $nextStaff = $verifyDetail [$key + 1] [0];
  9010. } elseif (isset ( $verifyDetail [$key + 1] )) {
  9011. $nextStaff = $verifyDetail [$key + 1] [0];
  9012. $nowStaff = $nextStaff;
  9013. } else
  9014. $nowStaff = '';
  9015. break;
  9016. }
  9017. }
  9018. if ($falg)
  9019. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9020. 'date' => date ( 'Y-m-d' ),
  9021. 'opinion' => $opinion,
  9022. 'status' => $status,
  9023. 'nextStaff' => $nextStaff,
  9024. 'ROLE' => 1
  9025. );
  9026. else
  9027. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9028. 'date' => date ( 'Y-m-d' ),
  9029. 'opinion' => $opinion,
  9030. 'status' => $status,
  9031. 'nextStaff' => $nextStaff
  9032. );
  9033. // print_r($verifyStaff);
  9034. // echo $nowStaff;die;
  9035. } else { // 进入下一个角色或者审批人
  9036. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  9037. //
  9038. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  9039. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9040. 'date' => date ( 'Y-m-d' ),
  9041. 'opinion' => $opinion,
  9042. 'status' => $status,
  9043. 'nextStaff' => $VS ['nextStaff'],
  9044. 'ROLE' => 1
  9045. );
  9046. // print_r($verifyStaff);
  9047. // die;
  9048. }
  9049. if ($status == 3) {
  9050. $verifyStaff ['final'] = $status;
  9051. $verifyStaff [$this->staff [0] ['sid']] = array (
  9052. 'date' => date ( 'Y-m-d' ),
  9053. 'opinion' => $opinion,
  9054. 'status' => $status
  9055. );
  9056. }
  9057. $vStaffString = json_encode ( $verifyStaff );
  9058. $receipt->verifyStaff = $vStaffString;
  9059. $receipt->nowStaff = $nowStaff;
  9060. // die;
  9061. // }
  9062. // print_r($verifyStaff);
  9063. // die;
  9064. }
  9065. // print_r($verifyStaff);die;
  9066. }
  9067. // print_r($verifyDetail);
  9068. $roleKey = 0;
  9069. $roleId = 0;
  9070. $verifyDetailCopy = array ();
  9071. foreach ( $verifyDetail as $k => $v ) {
  9072. if ($v [1] == 'ROLE') {
  9073. $roleId = $v [0];
  9074. $roleVerify = json_decode ( $v [3], true );
  9075. $roleKey = $k;
  9076. $roleArray = array ();
  9077. foreach ( $roleVerify as $o => $p ) {
  9078. $staffID = explode ( '_', $p );
  9079. $exp = array (
  9080. 0 => $staffID [0],
  9081. 1 => $staffID [1]
  9082. );
  9083. array_push ( $roleArray, $exp );
  9084. }
  9085. $verifyDetailCopy [$v [0]] = $roleArray;
  9086. }
  9087. }
  9088. // print_r($verifyDetail);
  9089. foreach ( $verifyDetailCopy as $k => $v ) {
  9090. foreach ( $verifyDetail as $m => $n ) {
  9091. if ($n [0] == $k) {
  9092. array_splice ( $verifyDetail, $m, 1, $v );
  9093. }
  9094. }
  9095. }
  9096. // die;
  9097. // if (!empty($roleArray))
  9098. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  9099. // echo $roleId;
  9100. // print_r($verifyStaff);
  9101. // print_r($verifyDetail);
  9102. // die;
  9103. Doo::loadModel ( "receiptLog" );
  9104. $receiptLog = new receiptLog ();
  9105. // 审批日志
  9106. if (! isset ( $verifyStaff ['final'] )) {
  9107. if (! empty ( $roleId )) {
  9108. Doo::loadModel ( "role" );
  9109. $role = new role ();
  9110. $roleInfo = $role->getOne ( array (
  9111. 'where' => 'rid=' . $roleId,
  9112. 'asArray' => true
  9113. ) );
  9114. $receiptLog->rolename = $roleInfo ['name'];
  9115. }
  9116. $receiptLog->username = $this->staff [0] ['username'];
  9117. $receiptLog->uid = $this->staff [0] ['sid'];
  9118. $receiptLog->date = date ( "Y-m-d" );
  9119. $receiptLog->opinion = $opinion;
  9120. $receiptLog->img = $this->staff [0] ['avatar'];
  9121. $receiptLog->status = 1;
  9122. $receiptLog->rid = $rid;
  9123. $receiptLog->insert ();
  9124. }
  9125. if (isset ( $verifyStaff ['final'] )) { // rDetail
  9126. $receipt->verifyBreakup = $verifyString;
  9127. $receipt->status = 3;
  9128. $receiptDetailObj->status = 3;
  9129. $receiptDetailObj->update ( array (
  9130. 'where' => 'rid=' . $rid
  9131. ) );
  9132. if (! empty ( $roleId )) {
  9133. Doo::loadModel ( "role" );
  9134. $role = new role ();
  9135. $roleInfo = $role->getOne ( array (
  9136. 'where' => 'rid=' . $roleId,
  9137. 'asArray' => true
  9138. ) );
  9139. $receiptLog->rolename = $roleInfo ['name'];
  9140. }
  9141. $receiptLog->username = $this->staff [0] ['username'];
  9142. $receiptLog->uid = $this->staff [0] ['sid'];
  9143. $receiptLog->date = date ( "Y-m-d" );
  9144. $receiptLog->opinion = $opinion;
  9145. $receiptLog->img = $this->staff [0] ['avatar'];
  9146. $receiptLog->status = 3;
  9147. $receiptLog->rid = $rid;
  9148. $receiptLog->insert ();
  9149. //删除行程单
  9150. Doo::loadModel ( 'itinerary' );
  9151. $itinerary = new itinerary ();
  9152. $itinerary->delete ( array (
  9153. 'where' => 'rid="' . $rid . '"'
  9154. ) );
  9155. // 微信企业号通知
  9156. $this->setWXMsg ( $rid, 3 );
  9157. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  9158. $receipt->status = 1;
  9159. $reviseSum = 0;
  9160. $receipt->verifyBreakup = $verifyString;
  9161. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  9162. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9163. foreach ( $reviseDetail as $key => $value ) {
  9164. $receiptDetailObj = new receiptDetail ();
  9165. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9166. $receiptDetailObj->item = $value ['description'];
  9167. $receiptDetailObj->itemCategory = "报销金额调整";
  9168. $receiptDetailObj->price = $value ['price'];
  9169. $receiptDetailObj->date = $receiptDetail ['date'];
  9170. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  9171. $receiptDetailObj->rid = $rid;
  9172. $receiptDetailObj->status = 1;
  9173. $receiptDetailObj->insert ();
  9174. $reviseSum += $value ['price'];
  9175. }
  9176. $itemStatistics = new itemStatistics ();
  9177. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  9178. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9179. $itemStatistics->price = $reviseSum;
  9180. $itemStatistics->itemCategory = "报销金额调整";
  9181. $itemStatistics->date = $receiptDetail ['date'];
  9182. $itemStatistics->insert ();
  9183. }
  9184. $receiptDetailObj = new receiptDetail ();
  9185. $receiptDetailObj->status = 1;
  9186. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  9187. $receiptDetailObj->update ( array (
  9188. 'where' => 'rid=' . $rid
  9189. ) );
  9190. $dateArray = explode ( "-", $receiptDetail ['date'] );
  9191. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  9192. $stat = $statistics->getOne ( array (
  9193. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  9194. 'asArray' => true
  9195. ) );
  9196. if (empty ( $stat )) {
  9197. $statistics->date = $receiptDetail ['date'];
  9198. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  9199. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9200. $statistics->agPrice = $receiptDetail ['sum'];
  9201. $statistics->rePrice = $reviseSum;
  9202. $statistics->insert ();
  9203. } else {
  9204. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  9205. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  9206. $statistics->update ( array (
  9207. 'where' => 'sid=' . $stat ['sid']
  9208. ) );
  9209. }
  9210. $dateArray = explode ( "-", $receiptDetail ['date'] );
  9211. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  9212. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  9213. foreach ( $accountItem ['cSum'] as $key => $value ) {
  9214. if ($key == "agencySum") {
  9215. $iStatistics = $itemStatistics->getOne ( array (
  9216. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  9217. 'asArray' => true
  9218. ) );
  9219. if (empty ( $iStatistics )) {
  9220. $itemStatistics->cid = $receiptDetail ['cid'];
  9221. ;
  9222. $itemStatistics->staff = $receiptDetail ['staff'];
  9223. $itemStatistics->price = $value;
  9224. $itemStatistics->itemCategory = $this->AGENCY;
  9225. $itemStatistics->date = $receiptDetail ['date'];
  9226. $itemStatistics->insert ();
  9227. } else {
  9228. if (! empty ( $value )) {
  9229. $itemStatistics->price = $value + $iStatistics ['price'];
  9230. $itemStatistics->update ( array (
  9231. 'where' => 'sid=' . $iStatistics ['sid']
  9232. ) );
  9233. }
  9234. }
  9235. } elseif ($key == "travelSum") {
  9236. $iStatistics = $itemStatistics->getOne ( array (
  9237. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  9238. 'asArray' => true
  9239. ) );
  9240. if (empty ( $iStatistics )) {
  9241. $itemStatistics->cid = $receiptDetail ['cid'];
  9242. $itemStatistics->staff = $receiptDetail ['staff'];
  9243. $itemStatistics->price = $value;
  9244. $itemStatistics->itemCategory = $this->TRAVEL;
  9245. $itemStatistics->date = $receiptDetail ['date'];
  9246. $itemStatistics->insert ();
  9247. } else {
  9248. if (! empty ( $value )) {
  9249. $itemStatistics->price = $value + $iStatistics ['price'];
  9250. $itemStatistics->update ( array (
  9251. 'where' => 'sid=' . $iStatistics ['sid']
  9252. ) );
  9253. }
  9254. }
  9255. } elseif ($key == "trainSum") {
  9256. $iStatistics = $itemStatistics->getOne ( array (
  9257. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  9258. 'asArray' => true
  9259. ) );
  9260. if (empty ( $iStatistics )) {
  9261. $itemStatistics->cid = $receiptDetail ['cid'];
  9262. $itemStatistics->staff = $receiptDetail ['staff'];
  9263. $itemStatistics->price = $value;
  9264. $itemStatistics->itemCategory = $this->TRAIN;
  9265. $itemStatistics->date = $receiptDetail ['date'];
  9266. $itemStatistics->insert ();
  9267. } else {
  9268. if (! empty ( $value )) {
  9269. $itemStatistics->price = $value + $iStatistics ['price'];
  9270. $itemStatistics->update ( array (
  9271. 'where' => 'sid=' . $iStatistics ['sid']
  9272. ) );
  9273. }
  9274. }
  9275. } elseif ($key == "otherSum") {
  9276. $iStatistics = $itemStatistics->getOne ( array (
  9277. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  9278. 'asArray' => true
  9279. ) );
  9280. if (empty ( $iStatistics )) {
  9281. $itemStatistics->cid = $receiptDetail ['cid'];
  9282. $itemStatistics->staff = $receiptDetail ['staff'];
  9283. $itemStatistics->price = $value;
  9284. $itemStatistics->itemCategory = $this->OTHER;
  9285. $itemStatistics->date = $receiptDetail ['date'];
  9286. $itemStatistics->insert ();
  9287. } else {
  9288. if (! empty ( $value )) {
  9289. $itemStatistics->price = $value + $iStatistics ['price'];
  9290. $itemStatistics->update ( array (
  9291. 'where' => 'sid=' . $iStatistics ['sid']
  9292. ) );
  9293. }
  9294. }
  9295. }
  9296. }
  9297. $receipt->pastDate = date ( "Y-m-d" );
  9298. // 微信企业号通知
  9299. $this->setWXMsg ( $rid, 1 );
  9300. }
  9301. //是否有流水
  9302. Doo::loadModel ( 'wasteBook' );
  9303. $wasteBook = new wasteBook ();
  9304. $accountType=3;
  9305. if ($receiptDetail['Rtype']==1){
  9306. $accountType=2;
  9307. }elseif($receiptDetail['Rtype']==2){
  9308. $accountType=4;
  9309. }
  9310. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  9311. if (empty($wbDetail)){
  9312. $rsum=$receiptDetail['sum']-$receiptDetail['loanSum'];
  9313. $receipt->amount = $rsum;//$amount;
  9314. }
  9315. $receipt->update ( array (
  9316. 'where' => ' rid = ' . $rid
  9317. ) );
  9318. // 进入下一条审批费用新加需求
  9319. $vidList = array ();
  9320. $verifyDetail = $verify->find ( array (
  9321. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  9322. 'asArray' => true
  9323. ) );
  9324. foreach ( $verifyDetail as $key => $value ) {
  9325. array_push ( $vidList, $value ['vid'] );
  9326. }
  9327. $vid = implode ( ",", $vidList );
  9328. if (empty ( $verifyDetail ))
  9329. $vid = 0;
  9330. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  9331. $receipt = new receipt ();
  9332. $rd = $receipt->getOne ( array (
  9333. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  9334. 'asc' => 'rid',
  9335. 'asArray' => true
  9336. ) );
  9337. if (empty ( $rd )) {
  9338. return '/approvalExpenses/pendApproval';
  9339. }
  9340. if ($rd ['Rtype'] == 1) {
  9341. if ($rd ['isBK'] == 1) {
  9342. return '/receiptburEdi/' . $rd ['rid'];
  9343. } else {
  9344. return '/expensesEdi/' . $rd ['rid'];
  9345. }
  9346. } elseif ($rd ['Rtype'] == 2) {
  9347. return '/remitApproval/' . $rd ['rid'];
  9348. } else {
  9349. return '/receiptburEdi/' . $rd ['rid'];
  9350. }
  9351. // return "/approvalExpenses/pendApproval";
  9352. }
  9353. }
  9354. function expensesRetreats() {
  9355. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  9356. if (! empty ( $rid )) {
  9357. // 操作记录
  9358. Doo::loadModel ( "receipt" );
  9359. $receipt = new receipt ();
  9360. Doo::loadModel ( "receiptLog" );
  9361. $receiptLog = new receiptLog ();
  9362. Doo::loadModel ( "verify" );
  9363. $verify = new verify ();
  9364. $receiptInfo = $receipt->getOne ( array (
  9365. 'where' => 'rid=' . $rid,
  9366. 'asArray' => true
  9367. ) );
  9368. $vr = $verify->getOne ( array (
  9369. 'where' => 'vid=' . $receiptInfo ['verify'],
  9370. 'asArray' => true
  9371. ) );
  9372. $jd = json_decode ( $vr ['staff'] );
  9373. $roleId = 0;
  9374. foreach ( $jd as $key => $value ) {
  9375. if ($value [1] == 'ROLE') {
  9376. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9377. if ($pos !== false) {
  9378. $roleId = $value [0];
  9379. }
  9380. }
  9381. }
  9382. // 审批日志
  9383. // echo $roleId;die;
  9384. if (! empty ( $roleId )) {
  9385. Doo::loadModel ( "role" );
  9386. $role = new role ();
  9387. $roleInfo = $role->getOne ( array (
  9388. 'where' => 'rid=' . $roleId,
  9389. 'asArray' => true
  9390. ) );
  9391. $receiptLog->rolename = $roleInfo ['name'];
  9392. }
  9393. $receiptLog->username = $this->staff [0] ['username'];
  9394. $receiptLog->uid = $this->staff [0] ['sid'];
  9395. $receiptLog->date = date ( "Y-m-d" );
  9396. $receiptLog->opinion = '撤回';
  9397. $receiptLog->img = $this->staff [0] ['avatar'];
  9398. $receiptLog->status = 4;
  9399. $receiptLog->rid = $rid;
  9400. $receiptLog->insert ();
  9401. $receipt->status = 4;
  9402. $receipt->update ( array (
  9403. 'where' => 'rid=' . $rid
  9404. ) );
  9405. // 微信企业号通知
  9406. $this->setWXMsg ( $rid, 2 );
  9407. }
  9408. // echo "ddd";
  9409. return '/approvalExpenses/pendApproval';
  9410. }
  9411. function updateCheReceipt() {
  9412. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9413. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  9414. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  9415. if (! empty ( $rid )) {
  9416. // 操作记录
  9417. Doo::loadModel ( "receipt" );
  9418. $receipt = new receipt ();
  9419. Doo::loadModel ( "receiptLog" );
  9420. $receiptLog = new receiptLog ();
  9421. Doo::loadModel ( "verify" );
  9422. $verify = new verify ();
  9423. $receiptInfo = $receipt->getOne ( array (
  9424. 'where' => 'rid=' . $rid . ' and status=2',
  9425. 'asArray' => true
  9426. ) );
  9427. if (empty ( $receiptInfo )) {
  9428. echo json_encode ( array (
  9429. 'status' => 2
  9430. ) );
  9431. die ();
  9432. }
  9433. $vr = $verify->getOne ( array (
  9434. 'where' => 'vid=' . $receiptInfo ['verify'],
  9435. 'asArray' => true
  9436. ) );
  9437. $jd = json_decode ( $vr ['staff'] );
  9438. $roleId = 0;
  9439. foreach ( $jd as $key => $value ) {
  9440. if ($value [1] == 'ROLE') {
  9441. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9442. if ($pos !== false) {
  9443. $roleId = $value [0];
  9444. }
  9445. }
  9446. }
  9447. // 审批日志
  9448. // echo $roleId;die;
  9449. if (! empty ( $roleId )) {
  9450. Doo::loadModel ( "role" );
  9451. $role = new role ();
  9452. $roleInfo = $role->getOne ( array (
  9453. 'where' => 'rid=' . $roleId,
  9454. 'asArray' => true
  9455. ) );
  9456. $receiptLog->rolename = $roleInfo ['name'];
  9457. }
  9458. $receiptLog->username = $this->staff [0] ['username'];
  9459. $receiptLog->uid = $this->staff [0] ['sid'];
  9460. $receiptLog->date = date ( "Y-m-d" );
  9461. $receiptLog->opinion = $opinion;
  9462. $receiptLog->img = $this->staff [0] ['avatar'];
  9463. $receiptLog->status = 4;
  9464. $receiptLog->rid = $rid;
  9465. $receiptLog->insert ();
  9466. $receipt->status = 4;
  9467. $receipt->update ( array (
  9468. 'where' => 'rid=' . $rid
  9469. ) );
  9470. // 微信企业号通知
  9471. $this->setWXMsg ( $rid, 2 );
  9472. echo json_encode ( array (
  9473. 'status' => 1
  9474. ) );
  9475. // Header("HTTP/1.1 303 See Other");
  9476. // Header("Location: /approvalExpenses/pendApproval");
  9477. die ();
  9478. }
  9479. echo json_encode ( array (
  9480. 'status' => 2
  9481. ) );
  9482. die ();
  9483. // echo "ddd";
  9484. // return '/saeaBorad';
  9485. }
  9486. function revisePrice() {
  9487. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  9488. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  9489. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9490. // echo $price;die;
  9491. if (! empty ( $rid )) {
  9492. Doo::loadModel ( "receipt" );
  9493. $receipt = new receipt ();
  9494. $receiptDetail = $receipt->getOne ( array (
  9495. 'where' => 'rid=' . $rid . ' and status=2 ',
  9496. 'asArray' => true
  9497. ) );
  9498. if (empty ( $receiptDetail ))
  9499. die ( 'illegal request' );
  9500. $reviseDetail = array ();
  9501. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9502. array_push ( $reviseDetail, array (
  9503. 'sid' => $this->staff [0] ['sid'],
  9504. 'name' => $this->staff [0] ['username'],
  9505. 'description' => $description,
  9506. 'price' => $price
  9507. ) );
  9508. $reviseDetailString = json_encode ( $reviseDetail );
  9509. $receipt->reviseDetail = $reviseDetailString;
  9510. $receipt->revisePrice = $price;
  9511. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9512. } else {
  9513. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9514. array_push ( $reviseDetail, array (
  9515. 'sid' => $this->staff [0] ['sid'],
  9516. 'name' => $this->staff [0] ['username'],
  9517. 'description' => $description,
  9518. 'price' => $price
  9519. ) );
  9520. $reviseDetailString = json_encode ( $reviseDetail );
  9521. $receipt->reviseDetail = $reviseDetailString;
  9522. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9523. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9524. }
  9525. $receipt->update ( array (
  9526. 'where' => 'rid=' . $rid
  9527. ) );
  9528. if ($receiptDetail ['Rtype'] == 1) {
  9529. if ($receiptDetail ['isBK'] == 1) {
  9530. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9531. }
  9532. } elseif ($receiptDetail ['Rtype'] == 2) {
  9533. } else {
  9534. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9535. }
  9536. }
  9537. die ( 'illegal request' );
  9538. }
  9539. function personalCollect() {
  9540. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9541. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9542. $this->showCache ( $path );
  9543. Doo::loadModel ( "receiptDetail" );
  9544. Doo::loadModel ( "itemStatistics" );
  9545. Doo::loadModel ( 'statistics' );
  9546. $statistics = new statistics ();
  9547. $itemStatistics = new itemStatistics ();
  9548. $receiptDetail = new receiptDetail ();
  9549. $receiptCollectList = $receiptDetail->find ( array (
  9550. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9551. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9552. 'groupby' => 'itemCategory,Month(date)',
  9553. 'asArray' => true
  9554. ) );
  9555. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9556. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9557. 'asArray' => true
  9558. ) );
  9559. // create collect html
  9560. $collectArray = array (
  9561. '日常相关费用' => array (),
  9562. '差旅相关费用' => array (),
  9563. '培训班费用' => array (),
  9564. '其他' => array ()
  9565. );
  9566. $adjustment = array ();
  9567. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9568. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9569. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9570. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9571. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9572. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9573. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9574. array_push ( $collectArray ['其他'], $collectHtml );
  9575. $data ['collectArray'] = $collectArray;
  9576. // statistics html
  9577. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9578. if (empty ( $stList ))
  9579. $stList = array (
  9580. 'rePrice' => 0,
  9581. 'agPrice' => 0
  9582. );
  9583. $data ['stList'] = array (
  9584. 'rePrice' => $stList ['rePrice'],
  9585. 'agPrice' => $stList ['agPrice'],
  9586. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9587. );
  9588. // Adjustment price html
  9589. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9590. array_push ( $adjustment, $collectHtml );
  9591. $data ['adjustment'] = $adjustment;
  9592. // total price html
  9593. $collectHtml = "";
  9594. $total = 0;
  9595. for($i = 1; $i <= 12; $i ++) {
  9596. $sumPrice = 0;
  9597. foreach ( $receiptCollectList as $key => $value ) {
  9598. if ($value ['month'] == $i) {
  9599. $sumPrice += $value ['price'];
  9600. }
  9601. }
  9602. if ($sumPrice == 0)
  9603. $collectHtml .= '<td class="taR">-</td>';
  9604. else
  9605. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9606. $total += $sumPrice;
  9607. }
  9608. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9609. $data ['totalPrice'] = $collectHtml;
  9610. $dateHtml = "";
  9611. $now = date ( "Y" );
  9612. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9613. if ($YEARD <= $now) {
  9614. $dateHtml .= '<option ';
  9615. if ($year == $YEARD) {
  9616. $dateHtml .= 'selected ';
  9617. }
  9618. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9619. }
  9620. }
  9621. $data ['dateHtml'] = $dateHtml;
  9622. $data ['year'] = $year;
  9623. $data ['totalYear'] = $total;
  9624. $data ['memu'] = "receipt";
  9625. $data ['staff'] = $this->staff;
  9626. $data ['receiptMemu'] = 'personalCollect';
  9627. $data ['verifyId'] = $this->verifyId;
  9628. $data ['executeId'] = $this->executeId;
  9629. // year staff status 2,4
  9630. if ($year < date ( "Y" )) {
  9631. Doo::loadModel ( 'receipt' );
  9632. $receipt = new receipt ();
  9633. $receiptList = $receipt->find ( array (
  9634. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9635. 'asArray' => true
  9636. ) );
  9637. if (empty ( $receiptList )) {
  9638. ob_start ();
  9639. $this->render ( "/admin/saea_slist_collect", $data );
  9640. $this->cacheFile ( $path );
  9641. die ();
  9642. }
  9643. }
  9644. $this->render ( "/admin/saea_slist_collect", $data );
  9645. }
  9646. function personalCollectDetail() {
  9647. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9648. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9649. $this->showCache ( $path );
  9650. Doo::loadModel ( "receiptDetail" );
  9651. Doo::loadModel ( "itemStatistics" );
  9652. Doo::loadModel ( 'statistics' );
  9653. Doo::loadModel ( 'accountItem' );
  9654. $accountItem = new accountItem ();
  9655. $statistics = new statistics ();
  9656. $itemStatistics = new itemStatistics ();
  9657. $receiptDetail = new receiptDetail ();
  9658. $receiptCollectList = $receiptDetail->find ( array (
  9659. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9660. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9661. 'groupby' => 'item,Month(date)',
  9662. 'asArray' => true
  9663. ) );
  9664. $accountList = $accountItem->find ( array (
  9665. 'asArray' => true
  9666. ) );
  9667. // create CollectDetail HTML
  9668. $collectHtml = array ();
  9669. foreach ( $accountList as $key => $value ) {
  9670. $html = "";
  9671. $asum = 0;
  9672. for($i = 1; $i <= 12; $i ++) {
  9673. $falg = true;
  9674. foreach ( $receiptCollectList as $v ) {
  9675. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9676. $asum += $v ['price'];
  9677. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9678. $falg = false;
  9679. break;
  9680. }
  9681. }
  9682. if ($falg)
  9683. $html .= '<td class="taR">-</td>';
  9684. }
  9685. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9686. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9687. }
  9688. $data ['collectHtml'] = $collectHtml;
  9689. // create Adjustment price html
  9690. $receiptCollectList = $receiptDetail->find ( array (
  9691. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9692. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9693. 'groupby' => 'itemCategory,Month(date)',
  9694. 'asArray' => true
  9695. ) );
  9696. $adjustment = array ();
  9697. $collectArray = array (
  9698. '日常相关费用' => array (),
  9699. '差旅相关费用' => array (),
  9700. '培训班费用' => array (),
  9701. '其他' => array ()
  9702. );
  9703. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9704. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9705. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9706. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9707. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9708. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9709. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9710. array_push ( $collectArray ['其他'], $collectHtml );
  9711. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9712. array_push ( $adjustment, $collectHtml );
  9713. // total price html
  9714. $collectHtml = "";
  9715. $total = 0;
  9716. for($i = 1; $i <= 12; $i ++) {
  9717. $sumPrice = 0;
  9718. foreach ( $receiptCollectList as $key => $value ) {
  9719. if ($value ['month'] == $i) {
  9720. $sumPrice += $value ['price'];
  9721. }
  9722. }
  9723. if ($sumPrice == 0)
  9724. $collectHtml .= '<td class="taR">-</td>';
  9725. else
  9726. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9727. $total += $sumPrice;
  9728. }
  9729. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9730. // statistics html
  9731. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9732. if (empty ( $stList ))
  9733. $stList = array (
  9734. 'rePrice' => 0,
  9735. 'agPrice' => 0
  9736. );
  9737. $data ['stList'] = array (
  9738. 'rePrice' => $stList ['rePrice'],
  9739. 'agPrice' => $stList ['agPrice'],
  9740. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9741. );
  9742. $data ['collectArray'] = $collectArray;
  9743. $data ['adjustment'] = $adjustment;
  9744. $data ['totalPrice'] = $collectHtml;
  9745. $data ['totalYear'] = $total;
  9746. $data ['year'] = $year;
  9747. $dateHtml = "";
  9748. $now = date ( "Y" );
  9749. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9750. if ($YEARD <= $now) {
  9751. $dateHtml .= '<option ';
  9752. if ($year == $YEARD) {
  9753. $dateHtml .= 'selected ';
  9754. }
  9755. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9756. }
  9757. }
  9758. $data ['dateHtml'] = $dateHtml;
  9759. $data ['memu'] = "receipt";
  9760. $data ['staff'] = $this->staff;
  9761. $data ['receiptMemu'] = 'personalCollect';
  9762. $data ['verifyId'] = $this->verifyId;
  9763. $data ['executeId'] = $this->executeId;
  9764. // year staff status 2,4
  9765. if ($year < date ( "Y" )) {
  9766. Doo::loadModel ( 'receipt' );
  9767. $receipt = new receipt ();
  9768. $receiptList = $receipt->find ( array (
  9769. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9770. 'asArray' => true
  9771. ) );
  9772. if (empty ( $receiptList )) {
  9773. ob_start ();
  9774. $this->render ( "/admin/saeaCollectArticles", $data );
  9775. $this->cacheFile ( $path );
  9776. die ();
  9777. }
  9778. }
  9779. $this->render ( "/admin/saeaCollectArticles", $data );
  9780. }
  9781. function companyCategoryCollect() {
  9782. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9783. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9784. $this->showCache ( $path );
  9785. Doo::loadModel ( 'L_category' );
  9786. Doo::loadModel ( 'itemStatistics' );
  9787. Doo::loadModel ( 'statistics' );
  9788. $statistics = new statistics ();
  9789. $Lcategory = new L_category ();
  9790. $itemStatistics = new itemStatistics ();
  9791. Doo::loadModel ( "receiptAuthorityManage" );
  9792. $receiptAuthorityManage = new receiptAuthorityManage ();
  9793. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9794. $cidList = array ();
  9795. foreach ( $imcStaff as $key => $value ) {
  9796. array_push ( $cidList, $value ['cid'] );
  9797. }
  9798. $cidString = implode ( ',', $cidList );
  9799. $LcategoryList = $Lcategory->find ( array (
  9800. 'where' => ' cid in (' . $cidString . ')',
  9801. 'asArray' => true
  9802. ) ); // 'staff='.$this->staff[0]['sid']." and
  9803. $itemStatisticsList = $itemStatistics->find ( array (
  9804. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9805. 'where' => " Year(date)=" . $year,
  9806. 'groupby' => 'cid,Month(date)',
  9807. 'asArray' => true
  9808. ) );
  9809. // ceatre companyCollectHtml
  9810. foreach ( $LcategoryList as $value ) {
  9811. $html = "";
  9812. $asum = 0;
  9813. for($i = 1; $i <= 12; $i ++) {
  9814. $falg = true;
  9815. foreach ( $itemStatisticsList as $v ) {
  9816. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9817. $asum += $v ['price'];
  9818. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9819. $falg = false;
  9820. break;
  9821. }
  9822. }
  9823. if ($falg)
  9824. $html .= '<td class="taR">-</td>';
  9825. }
  9826. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9827. $collectHtml [$value ['title']] = array (
  9828. 'html' => $html,
  9829. 'cid' => $value ['cid']
  9830. );
  9831. }
  9832. $data ['companyHtml'] = $collectHtml;
  9833. // total price html
  9834. $collectHtml = "";
  9835. $total = 0;
  9836. for($i = 1; $i <= 12; $i ++) {
  9837. $sumPrice = 0;
  9838. foreach ( $itemStatisticsList as $key => $value ) {
  9839. if ($value ['month'] == $i) {
  9840. $sumPrice += $value ['price'];
  9841. }
  9842. }
  9843. if ($sumPrice == 0)
  9844. $collectHtml .= '<td class="taR">-</td>';
  9845. else
  9846. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9847. $total += $sumPrice;
  9848. }
  9849. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9850. $data ['companyTotalHtml'] = $collectHtml;
  9851. $data ['total'] = $total;
  9852. // statistics html
  9853. // echo $cidString;
  9854. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9855. if (empty ( $stList ))
  9856. $stList = array (
  9857. 'rePrice' => 0,
  9858. 'agPrice' => 0
  9859. );
  9860. $data ['stList'] = array (
  9861. 'rePrice' => $stList ['rePrice'],
  9862. 'agPrice' => $stList ['agPrice'],
  9863. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9864. );
  9865. $data ['year'] = $year;
  9866. $data ['memu'] = "receipt";
  9867. $data ['staff'] = $this->staff;
  9868. $data ['receiptMemu'] = 'companyCategoryCollect';
  9869. $data ['verifyId'] = $this->verifyId;
  9870. $data ['executeId'] = $this->executeId;
  9871. $dateHtml = "";
  9872. $now = date ( "Y" );
  9873. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9874. if ($YEARD <= $now) {
  9875. $dateHtml .= '<option ';
  9876. if ($year == $YEARD) {
  9877. $dateHtml .= 'selected ';
  9878. }
  9879. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9880. }
  9881. }
  9882. $data ['dateHtml'] = $dateHtml;
  9883. // year staff status 2,4
  9884. if ($year < date ( "Y" )) {
  9885. Doo::loadModel ( 'receipt' );
  9886. $receipt = new receipt ();
  9887. $receiptList = $receipt->find ( array (
  9888. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9889. 'asArray' => true
  9890. ) );
  9891. if (empty ( $receiptList )) {
  9892. ob_start ();
  9893. $this->render ( "/admin/saeaCompanyCollect", $data );
  9894. $this->cacheFile ( $path );
  9895. die ();
  9896. }
  9897. }
  9898. $this->render ( "/admin/saeaCompanyCollect", $data );
  9899. }
  9900. function categoryCollectDetail() {
  9901. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9902. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9903. /* $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9904. $this->showCache ( $path ); */
  9905. Doo::loadModel ( 'statistics' );
  9906. $statistics = new statistics ();
  9907. Doo::loadModel ( "receiptDetail" );
  9908. $receiptDetail = new receiptDetail ();
  9909. Doo::loadModel ( 'L_category' );
  9910. $Lcategory = new L_category ();
  9911. Doo::loadModel ( 'accountItem' );
  9912. $accountItem = new accountItem ();
  9913. Doo::loadModel ( "receiptAuthorityManage" );
  9914. $receiptAuthorityManage = new receiptAuthorityManage ();
  9915. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9916. $cidList = array ();
  9917. foreach ( $imcStaff as $key => $value ) {
  9918. array_push ( $cidList, $value ['cid'] );
  9919. }
  9920. $cidString = implode ( ',', $cidList );
  9921. $LcategoryList = $Lcategory->find ( array (
  9922. 'where' => 'cid in (' . $cidString . ')',
  9923. 'asArray' => true
  9924. ) );
  9925. if ($cid == 0) {
  9926. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9927. if ($cid == 0)
  9928. $cid = $LcategoryList [0] ['cid'];
  9929. }
  9930. $data ['LcategoryList'] = $LcategoryList;
  9931. $receiptCollectList = $receiptDetail->find ( array (
  9932. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9933. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9934. 'groupby' => 'item,Month(pastDate)',
  9935. 'asArray' => true
  9936. ) );
  9937. $accountList = $accountItem->find ( array (
  9938. 'asArray' => true
  9939. ) );
  9940. // create CollectDetail HTML
  9941. $collectHtml = array ();
  9942. foreach ( $accountList as $key => $value ) {
  9943. $html = "";
  9944. $asum = 0;
  9945. for($i = 1; $i <= 12; $i ++) {
  9946. $falg = true;
  9947. foreach ( $receiptCollectList as $v ) {
  9948. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9949. $asum += $v ['price'];
  9950. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9951. $falg = false;
  9952. break;
  9953. }
  9954. }
  9955. if ($falg)
  9956. $html .= '<td class="taR">-</td>';
  9957. }
  9958. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9959. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9960. }
  9961. $data ['collectHtml'] = $collectHtml;
  9962. // create Adjustment price html
  9963. $receiptCollectList = $receiptDetail->find ( array (
  9964. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9965. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9966. 'groupby' => 'itemCategory,Month(pastDate)',
  9967. 'asArray' => true
  9968. ) );
  9969. $adjustment = array ();
  9970. $collectArray = array (
  9971. '日常相关费用' => array (),
  9972. '差旅相关费用' => array (),
  9973. '培训班费用' => array (),
  9974. '内部培训费用'=>array(),
  9975. '其他' => array ()
  9976. );
  9977. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9978. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9979. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9980. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9981. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9982. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9983. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  9984. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  9985. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9986. array_push ( $collectArray ['其他'], $collectHtml );
  9987. $data ['collectArray'] = $collectArray;
  9988. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9989. array_push ( $adjustment, $collectHtml );
  9990. $data ['adjustment'] = $adjustment;
  9991. // total price html
  9992. $collectHtml = "";
  9993. $total = 0;
  9994. for($i = 1; $i <= 12; $i ++) {
  9995. $sumPrice = 0;
  9996. foreach ( $receiptCollectList as $key => $value ) {
  9997. if ($value ['month'] == $i) {
  9998. $sumPrice += $value ['price'];
  9999. }
  10000. }
  10001. if ($sumPrice == 0)
  10002. $collectHtml .= '<td class="taR">-</td>';
  10003. else
  10004. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  10005. $total += $sumPrice;
  10006. }
  10007. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  10008. // statistics html
  10009. $stList = $statistics->statisticsByCid ( $year, $cid );
  10010. if (empty ( $stList ))
  10011. $stList = array (
  10012. 'rePrice' => 0,
  10013. 'agPrice' => 0
  10014. );
  10015. $data ['stList'] = array (
  10016. 'rePrice' => $stList ['rePrice'],
  10017. 'agPrice' => $stList ['agPrice'],
  10018. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10019. );
  10020. $data ['totalYear'] = $total;
  10021. $data ['year'] = $year;
  10022. $data ['cid'] = $cid;
  10023. $data ['memu'] = "receipt";
  10024. $data ['staff'] = $this->staff;
  10025. $data ['receiptMemu'] = 'companyCategoryCollect';
  10026. $data ['verifyId'] = $this->verifyId;
  10027. $data ['executeId'] = $this->executeId;
  10028. // year staff status 2,4
  10029. /* if ($year < date ( "Y" )) {
  10030. Doo::loadModel ( 'receipt' );
  10031. $receipt = new receipt ();
  10032. $receiptList = $receipt->find ( array (
  10033. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  10034. 'asArray' => true
  10035. ) );
  10036. if (empty ( $receiptList )) {
  10037. ob_start ();
  10038. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  10039. $this->cacheFile ( $path );
  10040. die ();
  10041. }
  10042. } */
  10043. $dateHtml = "";
  10044. $now = date ( "Y" );
  10045. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  10046. if ($YEARD <= $now) {
  10047. $dateHtml .= '<option ';
  10048. if ($year == $YEARD) {
  10049. $dateHtml .= 'selected ';
  10050. }
  10051. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  10052. }
  10053. }
  10054. $data ['dateHtml'] = $dateHtml;
  10055. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  10056. }
  10057. function staffCollect() {
  10058. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10059. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  10060. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  10061. // $this->showCache($path);
  10062. Doo::loadModel ( 'statistics' );
  10063. $statistics = new statistics ();
  10064. Doo::loadModel ( "receiptDetail" );
  10065. $receiptDetail = new receiptDetail ();
  10066. Doo::loadModel ( 'L_category' );
  10067. $Lcategory = new L_category ();
  10068. Doo::loadModel ( 'accountItem' );
  10069. $accountItem = new accountItem ();
  10070. Doo::loadModel ( 'staff' );
  10071. $staff = new staff ();
  10072. Doo::loadModel ( 'itemStatistics' );
  10073. $itemStatistics = new itemStatistics ();
  10074. Doo::loadModel ( "receiptAuthorityManage" );
  10075. $receiptAuthorityManage = new receiptAuthorityManage ();
  10076. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  10077. $cidList = array ();
  10078. foreach ( $imcStaff as $key => $value ) {
  10079. array_push ( $cidList, $value ['cid'] );
  10080. }
  10081. $cidString = implode ( ',', $cidList );
  10082. $naturecon='';
  10083. if ($nature=='ONJOB'){
  10084. $naturecon=' and (nature!=4 )';
  10085. }elseif($nature=='LEAVEJOB'){
  10086. $naturecon=' and (nature=4 )';
  10087. }else{
  10088. die ( 'illegal request--nature' );
  10089. }
  10090. // statistics html
  10091. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  10092. if (empty ( $stList ))
  10093. $stList = array (
  10094. 'rePrice' => 0,
  10095. 'agPrice' => 0
  10096. );
  10097. $data ['stList'] = array (
  10098. 'rePrice' => $stList ['rePrice'],
  10099. 'agPrice' => $stList ['agPrice'],
  10100. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10101. );
  10102. // ---
  10103. $staffList = $staff->find ( array (
  10104. 'where' => 'username !="admin" '.$naturecon,
  10105. 'asArray' => true
  10106. ) );
  10107. $LcategoryList = $Lcategory->find ( array (
  10108. 'asArray' => true
  10109. ) ); // 'staff='.$this->staff[0]['sid']." and
  10110. $itemStatisticsList = $itemStatistics->find ( array (
  10111. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10112. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  10113. 'groupby' => 'staff,Month(date)',
  10114. 'asArray' => true
  10115. ) );
  10116. $categoryList = $staff->find ( array (
  10117. 'select' => 'COUNT(*) as count,cid,category',
  10118. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  10119. 'groupby' => 'cid',
  10120. 'asArray' => true
  10121. ) );
  10122. // print_r($itemStatisticsList);die;
  10123. // ceatre companyCollectHtml
  10124. foreach ( $categoryList as $vlu ) {
  10125. $count = $vlu ['count'] + 1;
  10126. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  10127. $m1 = 0;
  10128. $m2 = 0;
  10129. $m3 = 0;
  10130. $m4 = 0;
  10131. $m5 = 0;
  10132. $m6 = 0;
  10133. $m7 = 0;
  10134. $m8 = 0;
  10135. $m9 = 0;
  10136. $m10 = 0;
  10137. $m11 = 0;
  10138. $m12 = 0;
  10139. $m13 = 0;
  10140. foreach ( $staffList as $value ) {
  10141. if ($vlu ['cid'] == $value ['cid']) {
  10142. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  10143. $asum = 0;
  10144. for($i = 1; $i <= 12; $i ++) {
  10145. $falg = true;
  10146. foreach ( $itemStatisticsList as $v ) {
  10147. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  10148. if ($v ['month'] == 1)
  10149. $m1 += $v ['price'];
  10150. if ($v ['month'] == 2)
  10151. $m2 += $v ['price'];
  10152. if ($v ['month'] == 3)
  10153. $m3 += $v ['price'];
  10154. if ($v ['month'] == 4)
  10155. $m4 += $v ['price'];
  10156. if ($v ['month'] == 5)
  10157. $m5 += $v ['price'];
  10158. if ($v ['month'] == 6)
  10159. $m6 += $v ['price'];
  10160. if ($v ['month'] == 7)
  10161. $m7 += $v ['price'];
  10162. if ($v ['month'] == 8)
  10163. $m8 += $v ['price'];
  10164. if ($v ['month'] == 9)
  10165. $m9 += $v ['price'];
  10166. if ($v ['month'] == 10)
  10167. $m10 += $v ['price'];
  10168. if ($v ['month'] == 11)
  10169. $m11 += $v ['price'];
  10170. if ($v ['month'] == 12)
  10171. $m12 += $v ['price'];
  10172. $asum += $v ['price'];
  10173. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  10174. $falg = false;
  10175. break;
  10176. }
  10177. }
  10178. if ($falg)
  10179. $html .= '<td class="taR">-</td>';
  10180. }
  10181. $m13 += $asum;
  10182. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  10183. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  10184. 'html' => $html,
  10185. 'sid' => $value ['sid']
  10186. );
  10187. $html = "";
  10188. }
  10189. }
  10190. $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>
  10191. <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>
  10192. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  10193. $collectHtml [$vlu ['cid']] = array (
  10194. 'html' => $hl,
  10195. 'sid' => ''
  10196. );
  10197. }
  10198. $data ['companyHtml'] = $collectHtml;
  10199. // total price html
  10200. $collectHtml = "";
  10201. $total = 0;
  10202. for($i = 1; $i <= 12; $i ++) {
  10203. $sumPrice = 0;
  10204. foreach ( $itemStatisticsList as $key => $value ) {
  10205. if ($value ['month'] == $i) {
  10206. $sumPrice += $value ['price'];
  10207. }
  10208. }
  10209. if ($sumPrice == 0)
  10210. $collectHtml .= '<td class="taR">-</td>';
  10211. else
  10212. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  10213. $total += $sumPrice;
  10214. }
  10215. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  10216. $data ['companyTotalHtml'] = $collectHtml;
  10217. $data ['total'] = $total;
  10218. $data ['nature'] =$nature;
  10219. $data ['year'] = $year;
  10220. $data ['memu'] = "receipt";
  10221. $data ['staff'] = $this->staff;
  10222. $data ['receiptMemu'] = 'companyCategoryCollect';
  10223. $data ['verifyId'] = $this->verifyId;
  10224. $data ['executeId'] = $this->executeId;
  10225. if ($year <= date ( "Y" )) {
  10226. Doo::loadModel ( 'receipt' );
  10227. $receipt = new receipt ();
  10228. $receiptList = $receipt->find ( array (
  10229. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  10230. 'asArray' => true
  10231. ) );
  10232. if (empty ( $receiptList )) { // generated files
  10233. ob_start ();
  10234. $this->render ( "/admin/saeaStaffCollectB", $data );
  10235. $this->cacheFile ( $path );
  10236. die ();
  10237. }
  10238. }
  10239. $this->render ( "/admin/saeaStaffCollectB", $data );
  10240. }
  10241. function staffCollectBak() {
  10242. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10243. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  10244. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  10245. $this->showCache ( $path );
  10246. Doo::loadModel ( 'statistics' );
  10247. $statistics = new statistics ();
  10248. Doo::loadModel ( "receiptDetail" );
  10249. $receiptDetail = new receiptDetail ();
  10250. Doo::loadModel ( 'L_category' );
  10251. $Lcategory = new L_category ();
  10252. Doo::loadModel ( 'accountItem' );
  10253. $accountItem = new accountItem ();
  10254. Doo::loadModel ( 'staff' );
  10255. $staff = new staff ();
  10256. Doo::loadModel ( 'itemStatistics' );
  10257. $itemStatistics = new itemStatistics ();
  10258. $itemStatisticsList = $itemStatistics->find ( array (
  10259. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10260. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10261. 'groupby' => 'staff,itemCategory,Month(date)',
  10262. 'asArray' => true
  10263. ) );
  10264. $itemCategoryList = $itemStatistics->find ( array (
  10265. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10266. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10267. 'groupby' => 'cid,itemCategory,Month(date)',
  10268. 'asArray' => true
  10269. ) );
  10270. $LcategoryList = $Lcategory->find ( array (
  10271. 'asArray' => true
  10272. ) );
  10273. $staffList = $staff->find ( array (
  10274. 'asArray' => true
  10275. ) );
  10276. $htmlArray = array ();
  10277. foreach ( $LcategoryList as $value ) {
  10278. $htmlArray [$value ['title']] = array ();
  10279. foreach ( $staffList as $v ) {
  10280. if ($value ['cid'] == $v ['cid']) {
  10281. $html = "";
  10282. $falg = true;
  10283. $staffSumPrice = 0;
  10284. foreach ( $itemStatisticsList as $a ) {
  10285. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  10286. if (empty ( $a ['price'] )) {
  10287. $html .= '<td class="taR">-</td>';
  10288. $falg = false;
  10289. break;
  10290. } else {
  10291. $staffSumPrice += $a ['price'];
  10292. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10293. $falg = false;
  10294. break;
  10295. }
  10296. }
  10297. }
  10298. if ($falg) {
  10299. $html .= '<td class="taR">-</td>';
  10300. $falg = true;
  10301. }
  10302. $falg = true;
  10303. foreach ( $itemStatisticsList as $a ) {
  10304. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  10305. if (empty ( $a ['price'] )) {
  10306. $html .= '<td class="taR">-</td>';
  10307. $falg = false;
  10308. break;
  10309. } else {
  10310. $staffSumPrice += $a ['price'];
  10311. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10312. $falg = false;
  10313. break;
  10314. }
  10315. }
  10316. }
  10317. if ($falg) {
  10318. $html .= '<td class="taR">-</td>';
  10319. $falg = true;
  10320. }
  10321. $falg = true;
  10322. foreach ( $itemStatisticsList as $a ) {
  10323. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  10324. if (empty ( $a ['price'] )) {
  10325. $html .= '<td class="taR">-</td>';
  10326. $falg = false;
  10327. break;
  10328. } else {
  10329. $staffSumPrice += $a ['price'];
  10330. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10331. $falg = false;
  10332. break;
  10333. }
  10334. }
  10335. }
  10336. if ($falg) {
  10337. $html .= '<td class="taR">-</td>';
  10338. $falg = true;
  10339. }
  10340. $falg = true;
  10341. foreach ( $itemStatisticsList as $a ) {
  10342. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  10343. if (! empty ( $a ['price'] )) {
  10344. $staffSumPrice += $a ['price'];
  10345. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10346. $falg = false;
  10347. break;
  10348. } else {
  10349. $html .= '<td class="taR">-</td>';
  10350. $falg = false;
  10351. break;
  10352. }
  10353. }
  10354. }
  10355. if ($falg) {
  10356. $html .= '<td class="taR">-</td>';
  10357. $falg = true;
  10358. }
  10359. $falg = true;
  10360. foreach ( $itemStatisticsList as $a ) {
  10361. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  10362. if (! empty ( $a ['price'] )) {
  10363. $staffSumPrice += $a ['price'];
  10364. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10365. $falg = false;
  10366. break;
  10367. } else {
  10368. $html .= '<td class="taR">-</td>';
  10369. $falg = false;
  10370. break;
  10371. }
  10372. }
  10373. }
  10374. if ($falg) {
  10375. $html .= '<td class="taR">-</td>';
  10376. $falg = true;
  10377. }
  10378. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  10379. $htmlArray [$value ['title']] [$v ['username']] = $html;
  10380. }
  10381. }
  10382. /* -- --- */
  10383. // 合计费用
  10384. $cateHtml = "";
  10385. $catePrice = 0;
  10386. $cateFalg = true;
  10387. foreach ( $itemCategoryList as $l ) {
  10388. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  10389. if (empty ( $l ['price'] )) {
  10390. $cateHtml .= '<td class="colGreen taR">-</td>';
  10391. $cateFalg = false;
  10392. break;
  10393. } else {
  10394. $catePrice += $l ['price'];
  10395. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10396. $cateFalg = false;
  10397. break;
  10398. }
  10399. }
  10400. }
  10401. if ($cateFalg) {
  10402. $cateHtml .= '<td class="colGreen taR">-</td>';
  10403. $cateFalg = true;
  10404. }
  10405. $cateFalg = true;
  10406. foreach ( $itemCategoryList as $l ) {
  10407. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  10408. if (empty ( $l ['price'] )) {
  10409. $cateHtml .= '<td class="colGreen taR">-</td>';
  10410. $cateFalg = false;
  10411. break;
  10412. } else {
  10413. $catePrice += $l ['price'];
  10414. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10415. $cateFalg = false;
  10416. break;
  10417. }
  10418. }
  10419. }
  10420. if ($cateFalg) {
  10421. $cateHtml .= '<td class="colGreen taR">-</td>';
  10422. $cateFalg = true;
  10423. }
  10424. $cateFalg = true;
  10425. foreach ( $itemCategoryList as $l ) {
  10426. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  10427. if (empty ( $l ['price'] )) {
  10428. $cateHtml .= '<td class="colGreen taR">-</td>';
  10429. $cateFalg = false;
  10430. break;
  10431. } else {
  10432. $catePrice += $l ['price'];
  10433. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10434. $cateFalg = false;
  10435. break;
  10436. }
  10437. }
  10438. }
  10439. if ($cateFalg) {
  10440. $cateHtml .= '<td class="colGreen taR">-</td>';
  10441. $cateFalg = true;
  10442. }
  10443. $cateFalg = true;
  10444. foreach ( $itemCategoryList as $l ) {
  10445. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  10446. if (empty ( $l ['price'] )) {
  10447. $cateHtml .= '<td class="colGreen taR">-</td>';
  10448. $cateFalg = false;
  10449. break;
  10450. } else {
  10451. $catePrice += $l ['price'];
  10452. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10453. $cateFalg = false;
  10454. break;
  10455. }
  10456. }
  10457. }
  10458. if ($cateFalg) {
  10459. $cateHtml .= '<td class="colGreen taR">-</td>';
  10460. $cateFalg = true;
  10461. }
  10462. $cateFalg = true;
  10463. foreach ( $itemCategoryList as $l ) {
  10464. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  10465. if (empty ( $l ['price'] )) {
  10466. $cateHtml .= '<td class="colGreen taR">-</td>';
  10467. $cateFalg = false;
  10468. break;
  10469. } else {
  10470. $catePrice += $l ['price'];
  10471. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10472. $cateFalg = false;
  10473. break;
  10474. }
  10475. }
  10476. }
  10477. if ($cateFalg) {
  10478. $cateHtml .= '<td class="colGreen taR">-</td>';
  10479. $cateFalg = true;
  10480. }
  10481. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  10482. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  10483. /* -- --- */
  10484. }
  10485. // print_r($htmlArray);die;
  10486. $data ['htmlArray'] = $htmlArray;
  10487. // statistics html
  10488. $stList = $statistics->getOne ( array (
  10489. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  10490. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10491. 'groupby' => 'Month(date)',
  10492. 'asArray' => true
  10493. ) );
  10494. if (empty ( $stList ))
  10495. $stList = array (
  10496. 'rePrice' => 0,
  10497. 'agPrice' => 0
  10498. );
  10499. $data ['stList'] = array (
  10500. 'rePrice' => $stList ['rePrice'],
  10501. 'agPrice' => $stList ['agPrice'],
  10502. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10503. );
  10504. $monthHtml = "";
  10505. for($i = 1; $i <= 12; $i ++) {
  10506. if ($i == $month)
  10507. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  10508. else
  10509. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10510. }
  10511. $data ['monthHtml'] = $monthHtml;
  10512. $data ['year'] = $year;
  10513. $data ['month'] = $month;
  10514. $data ['memu'] = "receipt";
  10515. $data ['staff'] = $this->staff;
  10516. $data ['receiptMemu'] = 'companyCategoryCollect';
  10517. $data ['verifyId'] = $this->verifyId;
  10518. $data ['executeId'] = $this->executeId;
  10519. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10520. Doo::loadModel ( 'receipt' );
  10521. $receipt = new receipt ();
  10522. $receiptList = $receipt->find ( array (
  10523. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10524. 'asArray' => true
  10525. ) );
  10526. if (empty ( $receiptList )) { // generated files
  10527. ob_start ();
  10528. $this->render ( "/admin/saeaStaffCollect", $data );
  10529. $this->cacheFile ( $path );
  10530. die ();
  10531. }
  10532. }
  10533. $this->render ( "/admin/saeaStaffCollect", $data );
  10534. }
  10535. /**
  10536. * 日常收支
  10537. */
  10538. function payments() {
  10539. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10540. Doo::loadModel ( "execute" );
  10541. $execute = new execute ();
  10542. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10543. die ( 'illegal request' );
  10544. }
  10545. Doo::loadModel ( "accountBook" );
  10546. $accountBook = new accountBook ();
  10547. Doo::loadModel ( "accountBookStatistics" );
  10548. $accountBookStatistics = new accountBookStatistics ();
  10549. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10550. $list = $accountBook->getAccountBookByLimit ( 10 );
  10551. $data ['date'] = date ( "Y-m-d" );
  10552. $data ['statisticsList'] = $statisticsList;
  10553. $data ['list'] = $list;
  10554. $data ['memu'] = "receipt";
  10555. $data ['staff'] = $this->staff;
  10556. $data ['receiptMemu'] = 'payments';
  10557. $data ['verifyId'] = $this->verifyId;
  10558. $data ['executeId'] = $this->executeId;
  10559. $this->render ( "/expenses/payments", $data );
  10560. }
  10561. function paymentsIncomeDo() {
  10562. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10563. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10564. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10565. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10566. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10567. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10568. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10569. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10570. Doo::loadClass ( 'XDeode' );
  10571. $XDeode = new XDeode ( 5 );
  10572. Doo::loadModel ( "accountBook" );
  10573. Doo::loadModel ( "accountBookStatistics" );
  10574. Doo::loadModel ( 'wasteBook' );
  10575. // 记录流水时银行的转换
  10576. $accountBank = '';
  10577. if ($receivedBank == '纵横广发') {
  10578. $accountBank = 'CGBDeposit';
  10579. } elseif ($receivedBank == '纵横工行') {
  10580. $accountBank = 'ICBCDeposit';
  10581. } elseif ($receivedBank == '华润银行') {
  10582. $accountBank = 'HUADeposit';
  10583. } elseif ($receivedBank == '个人广发') {
  10584. $accountBank = 'PersonalDeposit';
  10585. }
  10586. if (empty ( $accountBank ))
  10587. die ( 'illegal request-bank' );
  10588. if($accountType == 11 || $accountType == 12){
  10589. if($accountType == 11){
  10590. $receivedBank = '纵横广发';
  10591. }elseif($accountType == 12){
  10592. $receivedBank = '纵横工行';
  10593. }
  10594. // 添加一条收入
  10595. $accountBook = new accountBook ();
  10596. $accountBook->accountType = $accountType;
  10597. $accountBook->accountMsg = $accountMsg;
  10598. $accountBook->receivedPrice = $receivedPrice;
  10599. $accountBook->receivedMsg = $receivedMsg;
  10600. $accountBook->receivedBank = $receivedBank;
  10601. $accountBook->receivedDate = $receivedDate;
  10602. $accountBook->remarks = $remarks;
  10603. $accountBook->expensesType = 1;
  10604. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10605. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10606. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10607. $inComeId = $accountBook->insert ();
  10608. // 收支汇总-添加一条收入日常汇总
  10609. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10610. $accountBookStatistics = new accountBookStatistics ();
  10611. $item = array (
  10612. 'date' => date ( "Y-m-d" ),
  10613. 'accountType' => $abDetail ['accountType'],
  10614. 'accountMsg' => $abDetail ['accountMsg'],
  10615. 'aid' => $abDetail ['aid'],
  10616. 'inComePrice' => $abDetail ['receivedPrice'],
  10617. 'expensesType' => $abDetail ['expensesType']
  10618. );
  10619. $accountBookStatistics->setAccountBookStatistics ( $item );
  10620. //流水支出
  10621. // if($accountBank=='CGBDeposit'){
  10622. // $dailyExpenditureType='8';
  10623. // }elseif($accountBank=='ICBCDeposit'){
  10624. // $dailyExpenditureType='9';
  10625. // }elseif($accountBank=='PersonalDeposit'){
  10626. // $dailyExpenditureType='10';
  10627. // }elseif($accountBank=='HUADeposit'){
  10628. // $dailyExpenditureType='11';
  10629. // }
  10630. //
  10631. // $wasteBook = new wasteBook ();
  10632. // $itemWaste = array (
  10633. // 'expensesType' => 2,
  10634. // 'accountType' => 5,
  10635. // 'accountPriceShow' => $receivedPrice,
  10636. // 'accountPrice' => - $receivedPrice,
  10637. // 'dataID' => $inComeId,
  10638. // 'dailyExpenditureType' => $dailyExpenditureType,
  10639. // 'accountBank' => $accountBank,
  10640. // 'category' => $this->staff [0] ['category'],
  10641. // 'cid' => $this->staff [0] ['cid'],
  10642. // 'name' => $this->staff [0] ['username'],
  10643. // 'sid' => $this->staff [0] ['sid'],
  10644. // 'inputDate' => date ( "Y-m-d H:i:s" )
  10645. // );
  10646. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  10647. // 添加收入流水
  10648. if($accountType == 11){
  10649. $accountBank = 'CGBDeposit';
  10650. }elseif($accountType == 12){
  10651. $accountBank = 'ICBCDeposit';
  10652. }
  10653. $wasteBook = new wasteBook ();
  10654. $itemWaste = array (
  10655. 'accountPriceShow' => $receivedPrice,
  10656. 'accountPrice' => $receivedPrice,
  10657. 'expensesType' => 1,
  10658. 'accountType' => 6, // 流水类型
  10659. 'dataID' => $inComeId,
  10660. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10661. 'accountBank' => $accountBank,
  10662. 'category' => $this->staff [0] ['category'],
  10663. 'cid' => $this->staff [0] ['cid'],
  10664. 'name' => $this->staff [0] ['username'],
  10665. 'sid' => $this->staff [0] ['sid'],
  10666. 'inputDate' => date ( "Y-m-d H:i:s" )
  10667. );
  10668. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10669. }elseif($accountType == 7 || $accountType == 9) { // 收入为理财时特殊处理
  10670. if ($receivedBank == '个人广发') {
  10671. die ( '个人广发 illegal request' );
  10672. }
  10673. // 添加一条收入
  10674. $accountBook = new accountBook ();
  10675. $accountBook->accountType = 10;
  10676. $accountBook->accountMsg = $accountMsg;
  10677. $accountBook->receivedPrice = $receivedPrice;
  10678. $accountBook->receivedMsg = $receivedMsg;
  10679. $accountBook->receivedBank = $receivedBank;
  10680. $accountBook->receivedDate = $receivedDate;
  10681. $accountBook->remarks = $remarks;
  10682. $accountBook->expensesType = 1;
  10683. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10684. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10685. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10686. $inComeId = $accountBook->insert ();
  10687. // 收支汇总-添加一条收入日常汇总
  10688. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10689. $accountBookStatistics = new accountBookStatistics ();
  10690. $item = array (
  10691. 'date' => date ( "Y-m-d" ),
  10692. 'accountType' => $abDetail ['accountType'],
  10693. 'accountMsg' => $abDetail ['accountMsg'],
  10694. 'aid' => $abDetail ['aid'],
  10695. 'inComePrice' => $abDetail ['receivedPrice'],
  10696. 'expensesType' => $abDetail ['expensesType']
  10697. );
  10698. $accountBookStatistics->setAccountBookStatistics ( $item );
  10699. // 添加收入流水
  10700. $wasteBook = new wasteBook ();
  10701. $itemWaste = array (
  10702. 'accountPriceShow' => $receivedPrice,
  10703. 'accountPrice' => $receivedPrice,
  10704. 'expensesType' => 1,
  10705. 'accountType' => 6, // 流水类型
  10706. 'dataID' => $inComeId,
  10707. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10708. 'accountBank' => $accountBank,
  10709. 'category' => $this->staff [0] ['category'],
  10710. 'cid' => $this->staff [0] ['cid'],
  10711. 'name' => $this->staff [0] ['username'],
  10712. 'sid' => $this->staff [0] ['sid'],
  10713. 'inputDate' => date ( "Y-m-d H:i:s" )
  10714. );
  10715. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10716. // 添加一条理财支出
  10717. $accountBank = 'CGBDeposit';
  10718. $expenditureBank = '纵横广发';
  10719. $dailyExpenditureType = 4;
  10720. if ($accountType == 9) {
  10721. $accountBank = 'ICBCDeposit';
  10722. $expenditureBank = '纵横工行';
  10723. $dailyExpenditureType = 6;
  10724. }
  10725. $accountBook = new accountBook ();
  10726. $accountBook->expensesType = 2;
  10727. $accountBook->expenditureType = $dailyExpenditureType;
  10728. $accountBook->expenditureMsg = $accountMsg;
  10729. $accountBook->expenditurePrice = $receivedPrice;
  10730. $accountBook->expenditureBank = $expenditureBank;
  10731. $accountBook->expenditureDate = $receivedDate;
  10732. $accountBook->remarks = $remarks;
  10733. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10734. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10735. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10736. $id = $accountBook->insert ();
  10737. // 收支汇总-添加一条理财支出汇总
  10738. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10739. $accountBookStatistics = new accountBookStatistics ();
  10740. $item = array (
  10741. 'date' => date ( "Y-m-d" ),
  10742. 'accountType' => $abDetail ['accountType'],
  10743. 'accountMsg' => $abDetail ['accountMsg'],
  10744. 'aid' => $abDetail ['aid'],
  10745. 'financingPrice' => - $receivedPrice,
  10746. 'expensesType' => 3
  10747. );
  10748. $accountBookStatistics->setAccountBookStatistics ( $item );
  10749. // 添加一条支出理财流水
  10750. $accountTypeWaste = 5;
  10751. if ($accountMsg == '公司固定') {
  10752. $accountTypeWaste = 9;
  10753. } elseif ($accountMsg == '公司活期') {
  10754. $accountTypeWaste = 10;
  10755. } elseif ($accountMsg == '个人(GR)') {
  10756. $accountBank = 'PersonalDeposit';
  10757. }
  10758. $itemWaste = array (
  10759. 'expensesType' => 2,
  10760. 'accountType' => $accountTypeWaste,
  10761. 'accountPriceShow' => $receivedPrice,
  10762. 'accountPrice' => - $receivedPrice,
  10763. 'dataID' => $id,
  10764. 'dailyExpenditureType' => $dailyExpenditureType,
  10765. 'accountBank' => $accountBank,
  10766. 'category' => $this->staff [0] ['category'],
  10767. 'cid' => $this->staff [0] ['cid'],
  10768. 'name' => $this->staff [0] ['username'],
  10769. 'sid' => $this->staff [0] ['sid'],
  10770. 'inputDate' => date ( "Y-m-d H:i:s" )
  10771. );
  10772. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10773. } elseif ($accountType == 1) {
  10774. // if ($receivedBank == '个人广发')
  10775. // die ( 'illegal request--no man' );
  10776. // 添加一条收入
  10777. $accountBook = new accountBook ();
  10778. $accountBook->accountType = $accountType;
  10779. $accountBook->accountMsg = $accountMsg;
  10780. $accountBook->receivedPrice = $receivedPrice;
  10781. $accountBook->receivedMsg = $receivedMsg;
  10782. $accountBook->receivedBank = $receivedBank;
  10783. $accountBook->receivedDate = $receivedDate;
  10784. $accountBook->remarks = $remarks;
  10785. $accountBook->expensesType = 1;
  10786. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10787. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10788. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10789. $id = $accountBook->insert ();
  10790. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10791. // 收支汇总-添加一条收入日常汇总
  10792. $accountBookStatistics = new accountBookStatistics ();
  10793. $item = array (
  10794. 'date' => date ( "Y-m-d" ),
  10795. 'accountType' => $abDetail ['accountType'],
  10796. 'accountMsg' => $abDetail ['accountMsg'],
  10797. 'aid' => $abDetail ['aid'],
  10798. 'expensesType' => $abDetail ['expensesType']
  10799. );
  10800. if ($abDetail ['accountType'] == 8) {
  10801. $item += array (
  10802. 'inComePrice' => $abDetail ['receivedPrice']
  10803. );
  10804. } else {
  10805. $item += array (
  10806. 'inComePrice' => $abDetail ['receivedPrice']
  10807. );
  10808. }
  10809. $accountBookStatistics->setAccountBookStatistics ( $item );
  10810. // 流水存储方向
  10811. $itemWaste = array (
  10812. 'accountType' => 6
  10813. ); // 流水类型
  10814. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10815. // }else
  10816. if ($accountMsg == '活期理财收益') {
  10817. $itemWaste = array (
  10818. 'accountType' => 10
  10819. ); // 流水类型
  10820. }
  10821. // 添加收入流水
  10822. $wasteBook = new wasteBook ();
  10823. $itemWaste += array (
  10824. 'accountPrice' => $receivedPrice,
  10825. 'accountPriceShow' => $receivedPrice,
  10826. 'expensesType' => 1,
  10827. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10828. 'dataID' => $id,
  10829. 'accountBank' => $accountBank,
  10830. 'category' => $this->staff [0] ['category'],
  10831. 'cid' => $this->staff [0] ['cid'],
  10832. 'name' => $this->staff [0] ['username'],
  10833. 'sid' => $this->staff [0] ['sid'],
  10834. 'inputDate' => date ( "Y-m-d H:i:s" )
  10835. );
  10836. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10837. } else { // 普通日常收入处理
  10838. // 添加一条收入
  10839. $accountBook = new accountBook ();
  10840. $accountBook->accountType = $accountType;
  10841. $accountBook->accountMsg = $accountMsg;
  10842. $accountBook->receivedPrice = $receivedPrice;
  10843. $accountBook->receivedMsg = $receivedMsg;
  10844. $accountBook->receivedBank = $receivedBank;
  10845. $accountBook->receivedDate = $receivedDate;
  10846. $accountBook->remarks = $remarks;
  10847. $accountBook->expensesType = 1;
  10848. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10849. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10850. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10851. $id = $accountBook->insert ();
  10852. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10853. // 收支汇总-添加一条收入日常汇总
  10854. $accountBookStatistics = new accountBookStatistics ();
  10855. $item = array (
  10856. 'date' => date ( "Y-m-d" ),
  10857. 'accountType' => $abDetail ['accountType'],
  10858. 'accountMsg' => $abDetail ['accountMsg'],
  10859. 'aid' => $abDetail ['aid'],
  10860. 'expensesType' => $abDetail ['expensesType']
  10861. );
  10862. if ($abDetail ['accountType'] == 8) {
  10863. $item += array (
  10864. 'inComePrice' => $abDetail ['receivedPrice']
  10865. );
  10866. } else {
  10867. $item += array (
  10868. 'inComePrice' => $abDetail ['receivedPrice']
  10869. );
  10870. }
  10871. $accountBookStatistics->setAccountBookStatistics ( $item );
  10872. // 添加收入流水
  10873. $itemWaste = array (
  10874. 'accountPrice' => $receivedPrice
  10875. );
  10876. if ($receivedBank == '个人广发') {
  10877. $itemWaste = array (
  10878. 'accountPrice' => - $receivedPrice
  10879. );
  10880. }
  10881. $wasteBook = new wasteBook ();
  10882. $itemWaste += array (
  10883. 'accountPriceShow' => $receivedPrice,
  10884. 'expensesType' => 1,
  10885. 'accountType' => 6, // 流水类型
  10886. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10887. 'dataID' => $id,
  10888. 'accountBank' => $accountBank,
  10889. 'category' => $this->staff [0] ['category'],
  10890. 'cid' => $this->staff [0] ['cid'],
  10891. 'name' => $this->staff [0] ['username'],
  10892. 'sid' => $this->staff [0] ['sid'],
  10893. 'inputDate' => date ( "Y-m-d H:i:s" )
  10894. );
  10895. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10896. }
  10897. }
  10898. return '/payments';
  10899. }
  10900. function paymentsExpenditureDo() {
  10901. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10902. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10903. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10904. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10905. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10906. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10907. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10908. // 理财支出特殊处理
  10909. Doo::loadModel ( "accountBook" );
  10910. Doo::loadModel ( "accountBookStatistics" );
  10911. Doo::loadModel ( 'wasteBook' );
  10912. $accountBank = '';
  10913. if ($expenditureBank == '纵横广发') {
  10914. $accountBank = 'CGBDeposit';
  10915. } elseif ($expenditureBank == '纵横工行') {
  10916. $accountBank = 'ICBCDeposit';
  10917. } elseif ($expenditureBank == '华润银行') {
  10918. $accountBank = 'HUADeposit';
  10919. } elseif ($expenditureBank == '个人广发') {
  10920. $accountBank = 'PersonalDeposit';
  10921. }
  10922. if (empty ( $accountBank ))
  10923. die ( 'illegal request' );
  10924. if($expenditureType == 8 || $expenditureType == 9){
  10925. if($expenditureType == 8 ){
  10926. $expenditureBank='纵横广发';
  10927. }elseif($expenditureType == 9){
  10928. $expenditureBank='纵横工行';
  10929. }
  10930. // 添加一笔日常支出
  10931. $accountBook = new accountBook ();
  10932. $accountBook->expensesType = 2;
  10933. $accountBook->expenditureType = $expenditureType;
  10934. $accountBook->expenditureMsg = $expenditureMsg;
  10935. $accountBook->expenditurePrice = $expenditurePrice;
  10936. $accountBook->expenditureBank = $expenditureBank;
  10937. $accountBook->expenditureDate = $expenditureDate;
  10938. $accountBook->remarks = $remarks;
  10939. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10940. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10941. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10942. $expenditureId = $accountBook->insert ();
  10943. // 添加日常支出汇总
  10944. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10945. $accountBookStatistics = new accountBookStatistics ();
  10946. $item = array (
  10947. 'date' => date ( "Y-m-d" ),
  10948. 'expenditureType' => $abDetail ['expenditureType'],
  10949. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10950. 'aid' => $abDetail ['aid'],
  10951. 'payPrice' => $abDetail ['expenditurePrice'],
  10952. 'expensesType' => $abDetail ['expensesType']
  10953. );
  10954. $accountBookStatistics->setAccountBookStatistics ( $item );
  10955. // 公司日常支出流水
  10956. if($expenditureType == 8 ){
  10957. $accountBank = 'CGBDeposit';
  10958. }elseif($expenditureType == 9){
  10959. $accountBank = 'ICBCDeposit';
  10960. }
  10961. if($accountBank=='CGBDeposit'){
  10962. $dailyExpenditureType='8';
  10963. }elseif($accountBank=='ICBCDeposit'){
  10964. $dailyExpenditureType='9';
  10965. }elseif($accountBank=='PersonalDeposit'){
  10966. $dailyExpenditureType='10';
  10967. }elseif($accountBank=='HUADeposit'){
  10968. $dailyExpenditureType='11';
  10969. }
  10970. $wasteBook = new wasteBook ();
  10971. $itemWaste = array (
  10972. 'expensesType' => 2,
  10973. 'accountType' => 5,
  10974. 'dailyExpenditureType' => $dailyExpenditureType,
  10975. 'accountPriceShow' => $expenditurePrice,
  10976. 'accountPrice' => - $expenditurePrice,
  10977. 'dataID' => $expenditureId,
  10978. 'accountBank' => $accountBank,
  10979. 'category' => $this->staff [0] ['category'],
  10980. 'cid' => $this->staff [0] ['cid'],
  10981. 'name' => $this->staff [0] ['username'],
  10982. 'sid' => $this->staff [0] ['sid'],
  10983. 'inputDate' => date ( "Y-m-d H:i:s" )
  10984. );
  10985. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10986. // 添加一笔收入流水
  10987. // if($expenditureType==8){
  10988. // $dailyIncomeType='11';
  10989. // }elseif($expenditureType==9){
  10990. // $dailyIncomeType='12';
  10991. // }
  10992. // $wasteBook = new wasteBook ();
  10993. // $itemWaste = array (
  10994. // 'expensesType' => 1,
  10995. // 'accountType' => 6,
  10996. // 'accountPriceShow' => $expenditurePrice,
  10997. // 'accountPrice' => $expenditurePrice,
  10998. // 'dataID' => $expenditureId,
  10999. //
  11000. // 'dailyIncomeType' => $dailyIncomeType,
  11001. // 'accountBank' => $accountBank,
  11002. // 'category' => $this->staff [0] ['category'],
  11003. // 'cid' => $this->staff [0] ['cid'],
  11004. // 'name' => $this->staff [0] ['username'],
  11005. // 'sid' => $this->staff [0] ['sid'],
  11006. // 'inputDate' => date ( "Y-m-d H:i:s" )
  11007. // );
  11008. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  11009. }elseif ($expenditureType == 4 || $expenditureType == 6) {
  11010. if ($expenditureBank == '个人广发') {
  11011. die ( '个人广发 illegal request' );
  11012. }
  11013. // 添加一笔日常支出
  11014. $accountBook = new accountBook ();
  11015. $accountBook->expensesType = 2;
  11016. $accountBook->expenditureType = 7;
  11017. $accountBook->expenditureMsg = $expenditureMsg;
  11018. $accountBook->expenditurePrice = $expenditurePrice;
  11019. $accountBook->expenditureBank = $expenditureBank;
  11020. $accountBook->expenditureDate = $expenditureDate;
  11021. $accountBook->remarks = $remarks;
  11022. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11023. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11024. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11025. $expenditureId = $accountBook->insert ();
  11026. // 添加日常支出汇总
  11027. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  11028. $accountBookStatistics = new accountBookStatistics ();
  11029. $item = array (
  11030. 'date' => date ( "Y-m-d" ),
  11031. 'expenditureType' => $abDetail ['expenditureType'],
  11032. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11033. 'aid' => $abDetail ['aid'],
  11034. 'payPrice' => $abDetail ['expenditurePrice'],
  11035. 'expensesType' => $abDetail ['expensesType']
  11036. );
  11037. $accountBookStatistics->setAccountBookStatistics ( $item );
  11038. // 公司日常支出流水
  11039. $wasteBook = new wasteBook ();
  11040. $itemWaste = array (
  11041. 'accountPrice' => - $expenditurePrice
  11042. );
  11043. if ($expenditureBank == '个人广发') {
  11044. $itemWaste = array (
  11045. 'accountPrice' => $expenditurePrice
  11046. );
  11047. }
  11048. $itemWaste += array (
  11049. 'expensesType' => 2,
  11050. 'accountType' => 5,
  11051. 'dailyExpenditureType' => $expenditureType,
  11052. 'accountPriceShow' => $expenditurePrice,
  11053. 'accountPrice' => - $expenditurePrice,
  11054. 'dataID' => $expenditureId,
  11055. 'accountBank' => $accountBank,
  11056. 'category' => $this->staff [0] ['category'],
  11057. 'cid' => $this->staff [0] ['cid'],
  11058. 'name' => $this->staff [0] ['username'],
  11059. 'sid' => $this->staff [0] ['sid'],
  11060. 'inputDate' => date ( "Y-m-d H:i:s" )
  11061. );
  11062. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11063. // 添加一笔理财收入
  11064. $accountBank = 'CGBDeposit';
  11065. $dailyIncomeType = 7;
  11066. $receivedBank = '纵横广发';
  11067. if ($expenditureType == 6) {
  11068. $accountBank = 'ICBCDeposit';
  11069. $receivedBank = '纵横工行';
  11070. $dailyIncomeType = 9;
  11071. }
  11072. $accountBook = new accountBook ();
  11073. $accountBook->expensesType = 1;
  11074. $accountBook->accountType = $dailyIncomeType;
  11075. $accountBook->accountMsg = $expenditureMsg;
  11076. $accountBook->receivedPrice = $expenditurePrice;
  11077. $accountBook->receivedBank = $receivedBank;
  11078. $accountBook->receivedDate = $expenditureDate;
  11079. $accountBook->remarks = $remarks;
  11080. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11081. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11082. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11083. $id = $accountBook->insert ();
  11084. // 添加日常理财收入汇总
  11085. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  11086. $accountBookStatistics = new accountBookStatistics ();
  11087. $item = array (
  11088. 'date' => date ( "Y-m-d" ),
  11089. 'expenditureType' => $abDetail ['expenditureType'],
  11090. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11091. 'aid' => $abDetail ['aid'],
  11092. 'financingPrice' => $expenditurePrice,
  11093. 'expensesType' => 3
  11094. );
  11095. $accountBookStatistics->setAccountBookStatistics ( $item );
  11096. // 添加一笔收入流水
  11097. if ($expenditureMsg == '公司固定') {
  11098. $accountTypeWaste = 9;
  11099. } elseif ($expenditureMsg == '公司活期') {
  11100. $accountTypeWaste = 10;
  11101. } elseif ($expenditureMsg == '个人(GR)') {
  11102. $accountBank = 'PersonalDeposit';
  11103. }
  11104. $itemWaste = array (
  11105. 'expensesType' => 1,
  11106. 'accountType' => $accountTypeWaste,
  11107. 'accountPriceShow' => $expenditurePrice,
  11108. 'accountPrice' => $expenditurePrice,
  11109. 'dataID' => $id,
  11110. 'dailyIncomeType' => $dailyIncomeType,
  11111. 'accountBank' => $accountBank,
  11112. 'category' => $this->staff [0] ['category'],
  11113. 'cid' => $this->staff [0] ['cid'],
  11114. 'name' => $this->staff [0] ['username'],
  11115. 'sid' => $this->staff [0] ['sid'],
  11116. 'inputDate' => date ( "Y-m-d H:i:s" )
  11117. );
  11118. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11119. } else {
  11120. // 添加一笔日常支出
  11121. $accountBook = new accountBook ();
  11122. $accountBook->expensesType = 2;
  11123. $accountBook->expenditureType = $expenditureType;
  11124. $accountBook->expenditureMsg = $expenditureMsg;
  11125. $accountBook->expenditurePrice = $expenditurePrice;
  11126. $accountBook->expenditureBank = $expenditureBank;
  11127. $accountBook->expenditureDate = $expenditureDate;
  11128. $accountBook->remarks = $remarks;
  11129. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11130. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11131. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11132. $id = $accountBook->insert ();
  11133. // 添加日常支出汇总
  11134. $abDetail = $accountBook->getAccountBookByAid ( $id );
  11135. $accountBookStatistics = new accountBookStatistics ();
  11136. $item = array (
  11137. 'date' => date ( "Y-m-d" ),
  11138. 'expenditureType' => $abDetail ['expenditureType'],
  11139. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11140. 'aid' => $abDetail ['aid'],
  11141. 'expensesType' => $abDetail ['expensesType']
  11142. );
  11143. if ($expenditureType == 5) {
  11144. $item += array (
  11145. 'payPrice' => - $abDetail ['expenditurePrice']
  11146. );
  11147. } else {
  11148. $item += array (
  11149. 'payPrice' => $abDetail ['expenditurePrice']
  11150. );
  11151. }
  11152. $accountBookStatistics->setAccountBookStatistics ( $item );
  11153. // 公司日常支出流水
  11154. $wasteBook = new wasteBook ();
  11155. $itemWaste = array (
  11156. 'accountPrice' => - $expenditurePrice
  11157. );
  11158. if ($expenditureBank == '个人广发') {
  11159. $itemWaste = array (
  11160. 'accountPrice' => $expenditurePrice
  11161. );
  11162. }
  11163. $itemWaste += array (
  11164. 'expensesType' => 2,
  11165. 'accountType' => 5,
  11166. 'accountPriceShow' => $expenditurePrice,
  11167. 'dataID' => $id,
  11168. 'dailyExpenditureType' => $expenditureType,
  11169. 'accountBank' => $accountBank,
  11170. 'category' => $this->staff [0] ['category'],
  11171. 'cid' => $this->staff [0] ['cid'],
  11172. 'name' => $this->staff [0] ['username'],
  11173. 'sid' => $this->staff [0] ['sid'],
  11174. 'inputDate' => date ( "Y-m-d H:i:s" )
  11175. );
  11176. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11177. }
  11178. }
  11179. return '/payments';
  11180. }
  11181. /**
  11182. * 添加支出
  11183. */
  11184. function paymentsExpenditureDo_() {
  11185. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11186. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11187. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11188. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11189. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11190. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11191. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11192. $dailyExpenditureType = '';
  11193. $accountTypeWaste = 5;
  11194. $accountBank = '';
  11195. if ($expenditureBank == '纵横广发') {
  11196. $accountBank = 'CGBDeposit';
  11197. } elseif ($expenditureBank == '纵横工行') {
  11198. $accountBank = 'ICBCDeposit';
  11199. } elseif ($expenditureBank == '华润银行') {
  11200. $accountBank = 'HUADeposit';
  11201. } elseif ($expenditureBank == '个人广发') {
  11202. $accountBank = 'PersonalDeposit';
  11203. }
  11204. if (empty ( $accountBank ))
  11205. die ( 'illegal request' );
  11206. $itemWaste = array (
  11207. 'accountPrice' => - $expenditurePrice
  11208. );
  11209. if ($expenditureBank == '个人广发') {
  11210. $itemWaste = array (
  11211. 'accountPrice' => $expenditurePrice
  11212. );
  11213. }
  11214. if ($expenditureType == 4 || $expenditureType == 6) {
  11215. $dailyExpenditureType = 4;
  11216. if ($expenditureMsg == '公司固定') {
  11217. $accountTypeWaste = 9;
  11218. } elseif ($expenditureMsg == '公司活期') {
  11219. $accountTypeWaste = 10;
  11220. } elseif ($expenditureMsg == '个人(GR)') {
  11221. $accountBank = 'PersonalDeposit';
  11222. }
  11223. $itemWaste = array (
  11224. 'accountPrice' => $expenditurePrice
  11225. );
  11226. } elseif ($expenditureType == 1) {
  11227. $dailyExpenditureType = 1;
  11228. } elseif ($expenditureType == 2) {
  11229. $dailyExpenditureType = 2;
  11230. } elseif ($expenditureType == 3) {
  11231. $dailyExpenditureType = 3;
  11232. } elseif ($expenditureType == 5) {
  11233. $dailyExpenditureType = 5;
  11234. }
  11235. if (empty ( $dailyExpenditureType ))
  11236. die ( 'illegal request' );
  11237. Doo::loadModel ( "accountBook" );
  11238. $accountBook = new accountBook ();
  11239. $accountBook->expenditureType = $expenditureType;
  11240. $accountBook->expenditureMsg = $expenditureMsg;
  11241. $accountBook->expenditurePrice = $expenditurePrice;
  11242. $accountBook->expenditureBank = $expenditureBank;
  11243. $accountBook->expenditureDate = $expenditureDate;
  11244. $accountBook->remarks = $remarks;
  11245. $accountBook->expensesType = 2;
  11246. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11247. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11248. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11249. $id = $accountBook->insert ();
  11250. //
  11251. $abDetail = $accountBook->getAccountBookByAid ( $id );
  11252. Doo::loadModel ( "accountBookStatistics" );
  11253. $accountBookStatistics = new accountBookStatistics ();
  11254. $item = array (
  11255. 'date' => date ( "Y-m-d" ),
  11256. 'expenditureType' => $abDetail ['expenditureType'],
  11257. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11258. 'aid' => $abDetail ['aid']
  11259. );
  11260. if ($abDetail ['expensesType'] == 2) {
  11261. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  11262. $item += array (
  11263. 'financingPrice' => $expenditurePrice,
  11264. 'expensesType' => 3
  11265. );
  11266. } elseif ($abDetail ['expenditureType'] == 5) {
  11267. $item += array (
  11268. 'payPrice' => $abDetail ['expenditurePrice'],
  11269. 'expensesType' => $abDetail ['expensesType']
  11270. );
  11271. } else {
  11272. $item += array (
  11273. 'payPrice' => $abDetail ['expenditurePrice'],
  11274. 'expensesType' => $abDetail ['expensesType']
  11275. );
  11276. }
  11277. }
  11278. $accountBookStatistics->setAccountBookStatistics ( $item );
  11279. // 公司流水记录
  11280. Doo::loadModel ( 'wasteBook' );
  11281. $wasteBook = new wasteBook ();
  11282. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  11283. // 银行
  11284. if (empty ( $abDetail )) {
  11285. $itemWaste += array (
  11286. 'accountPriceShow' => $expenditurePrice,
  11287. 'dataID' => $id,
  11288. 'expensesType' => 2,
  11289. 'accountType' => $accountTypeWaste,
  11290. 'dailyExpenditureType' => $expenditureType,
  11291. 'accountBank' => $accountBank,
  11292. 'category' => $this->staff [0] ['category'],
  11293. 'cid' => $this->staff [0] ['cid'],
  11294. 'name' => $this->staff [0] ['username'],
  11295. 'sid' => $this->staff [0] ['sid'],
  11296. 'inputDate' => date ( "Y-m-d H:i:s" )
  11297. );
  11298. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11299. }
  11300. // 支出类型为4或者6 需要添加一笔收入和收入流水
  11301. if ($expenditureType == 4 || $expenditureType == 6) {
  11302. $accountBank = 'CGBDeposit';
  11303. $dailyIncomeType = 7;
  11304. $receivedBank = '纵横广发';
  11305. if ($expenditureType == 6) {
  11306. $accountBank = 'ICBCDeposit';
  11307. $receivedBank = '纵横工行';
  11308. $dailyIncomeType = 9;
  11309. }
  11310. // 添加一笔收入
  11311. $accountBook = new accountBook ();
  11312. $accountBook->accountType = $dailyIncomeType;
  11313. $accountBook->accountMsg = $expenditureMsg;
  11314. $accountBook->receivedPrice = $expenditurePrice;
  11315. $accountBook->receivedBank = $receivedBank;
  11316. $accountBook->receivedDate = $expenditureDate;
  11317. $accountBook->remarks = $remarks;
  11318. $accountBook->expensesType = 1;
  11319. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11320. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11321. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11322. $id = $accountBook->insert ();
  11323. // 添加一笔收入流水
  11324. $itemWaste = array (
  11325. 'accountPriceShow' => $expenditurePrice,
  11326. 'accountPrice' => - $expenditurePrice,
  11327. 'dataID' => $id,
  11328. 'expensesType' => 1,
  11329. 'accountType' => $accountTypeWaste,
  11330. 'dailyIncomeType' => $dailyIncomeType,
  11331. 'accountBank' => $accountBank,
  11332. 'category' => $this->staff [0] ['category'],
  11333. 'cid' => $this->staff [0] ['cid'],
  11334. 'name' => $this->staff [0] ['username'],
  11335. 'sid' => $this->staff [0] ['sid'],
  11336. 'inputDate' => date ( "Y-m-d H:i:s" )
  11337. );
  11338. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11339. }
  11340. }
  11341. return '/payments';
  11342. }
  11343. /**
  11344. * 所有收支
  11345. */
  11346. function paymentsAchieve() {
  11347. $page_size = 12;
  11348. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  11349. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  11350. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11351. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  11352. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11353. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11354. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11355. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  11356. Doo::loadModel ( "accountBookStatistics" );
  11357. $accountBookStatistics = new accountBookStatistics ();
  11358. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  11359. $data ['statisticsList'] = $statisticsList;
  11360. Doo::loadModel ( "accountBook" );
  11361. $accountBook = new accountBook ();
  11362. $con = '';
  11363. if ($expensesType == 'INCOME')
  11364. $con = ' and expensesType=1 ';
  11365. elseif ($expensesType == 'PAY')
  11366. $con = ' and expensesType=2 ';
  11367. $dateArr = explode ( ':', $date );
  11368. $D1 = $dateString = '';
  11369. $D2 = '';
  11370. if (! empty ( $date )) {
  11371. $D1 = $dateArr [0];
  11372. if (isset ( $dateArr [1] ))
  11373. $D2 = $dateArr [1];
  11374. else
  11375. $D2 = '';
  11376. $dateString = $D1 . " : " . $D2;
  11377. }
  11378. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11379. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11380. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11381. $con .= ' and inputDate like "%' . $D1 . '%" ';
  11382. if (! empty ( $price ))
  11383. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  11384. if ($submitType == 1) {
  11385. if ($accountType != '') {
  11386. $expenditureType = '';
  11387. $con .= ' and accountType=' . $accountType;
  11388. if (! empty ( $accountMsg ))
  11389. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  11390. }
  11391. } elseif ($submitType == 2) {
  11392. if ($expenditureType != '') {
  11393. $accountType = $accountMsg = '';
  11394. $con .= ' and expenditureType=' . $expenditureType;
  11395. }
  11396. } else {
  11397. $accountType = $accountMsg = $expenditureType = '';
  11398. }
  11399. $sql = "" . $con;
  11400. $action = "paymentsAchieve";
  11401. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  11402. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  11403. $limit = $pageinfo ['lower'] . ',' . $page_size;
  11404. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  11405. $data ['expenditureType'] = $expenditureType;
  11406. $data ['accountMsg'] = $accountMsg;
  11407. $data ['accountType'] = $accountType;
  11408. $data ['inputDate'] = $date;
  11409. $data ['price'] = $price;
  11410. $data ['expensesType'] = $expensesType;
  11411. $data ['page'] = $pageinfo;
  11412. $data ['list'] = $list;
  11413. $data ['memu'] = "receipt";
  11414. $data ['staff'] = $this->staff;
  11415. $data ['receiptMemu'] = 'payments';
  11416. $data ['verifyId'] = $this->verifyId;
  11417. $data ['executeId'] = $this->executeId;
  11418. $this->render ( "/expenses/paymentsAchieve", $data );
  11419. }
  11420. function paymentsIncomeUpdateDo() {
  11421. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11422. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11423. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11424. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  11425. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  11426. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  11427. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  11428. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11429. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  11430. Doo::loadClass ( 'XDeode' );
  11431. $XDeode = new XDeode ( 5 );
  11432. $aid = $XDeode->decode ( $aidKey );
  11433. Doo::loadModel ( "accountBook" );
  11434. $accountBook = new accountBook ();
  11435. //
  11436. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11437. $price = $receivedPrice - $abDetail [inComePrice];
  11438. Doo::loadModel ( "accountBookStatistics" );
  11439. $accountBookStatistics = new accountBookStatistics ();
  11440. if ($abDetail ['accountType'] == 7) {
  11441. $item += array (
  11442. 'date' => date ( "Y-m-d" ),
  11443. 'financingPrice' => - $price,
  11444. 'expensesType' => 3,
  11445. 'aid' => $abDetail ['aid']
  11446. );
  11447. } elseif ($abDetail ['accountType'] == 8) {
  11448. $item += array (
  11449. 'date' => date ( "Y-m-d" ),
  11450. 'expensesType' => $abDetail ['expensesType'],
  11451. 'inComePrice' => - $price,
  11452. 'aid' => $abDetail ['aid']
  11453. );
  11454. } else {
  11455. $item = array (
  11456. 'date' => date ( "Y-m-d" ),
  11457. 'expensesType' => $abDetail ['expensesType'],
  11458. 'inComePrice' => $price,
  11459. 'aid' => $abDetail ['aid']
  11460. );
  11461. }
  11462. $accountBookStatistics->setAccountBookStatistics ( $item );
  11463. $accountBook->accountType = $accountType;
  11464. $accountBook->accountMsg = $accountMsg;
  11465. $accountBook->receivedPrice = $receivedPrice;
  11466. $accountBook->receivedMsg = $receivedMsg;
  11467. $accountBook->receivedBank = $receivedBank;
  11468. $accountBook->receivedDate = $receivedDate;
  11469. $accountBook->remarks = $remarks;
  11470. $accountBook->aid = $aid;
  11471. $accountBook->update ();
  11472. }
  11473. return '/paymentsAchieve';
  11474. }
  11475. function paymentsExpenditureEdiDo() {
  11476. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11477. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11478. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11479. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11480. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11481. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11482. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11483. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11484. Doo::loadClass ( 'XDeode' );
  11485. $XDeode = new XDeode ( 5 );
  11486. $aid = $XDeode->decode ( $aidKey );
  11487. Doo::loadModel ( "accountBook" );
  11488. $accountBook = new accountBook ();
  11489. // 汇总信息
  11490. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11491. $price = $expenditurePrice - $abDetail [expenditurePrice];
  11492. Doo::loadModel ( "accountBookStatistics" );
  11493. $accountBookStatistics = new accountBookStatistics ();
  11494. if ($abDetail ['expenditureType'] == 4) {
  11495. $item += array (
  11496. 'date' => date ( "Y-m-d" ),
  11497. 'financingPrice' => $price,
  11498. 'expensesType' => 3,
  11499. 'aid' => $abDetail ['aid']
  11500. );
  11501. } elseif ($abDetail ['expenditureType'] == 5) {
  11502. $item += array (
  11503. 'date' => date ( "Y-m-d" ),
  11504. 'expensesType' => $abDetail ['expensesType'],
  11505. 'payPrice' => $price,
  11506. 'aid' => $abDetail ['aid']
  11507. );
  11508. } else {
  11509. $item = array (
  11510. 'date' => date ( "Y-m-d" ),
  11511. 'expensesType' => $abDetail ['expensesType'],
  11512. 'payPrice' => $price,
  11513. 'aid' => $abDetail ['aid']
  11514. );
  11515. }
  11516. $accountBookStatistics->setAccountBookStatistics ( $item );
  11517. //
  11518. $accountBook->expenditureType = $expenditureType;
  11519. $accountBook->expenditureMsg = $expenditureMsg;
  11520. $accountBook->expenditurePrice = $expenditurePrice;
  11521. $accountBook->expenditureBank = $expenditureBank;
  11522. $accountBook->remarks = $remarks;
  11523. $accountBook->expenditureDate = $expenditureDate;
  11524. $accountBook->aid = $aid;
  11525. $id = $accountBook->update ();
  11526. }
  11527. return '/paymentsAchieve';
  11528. }
  11529. function paymentsDelDo() {
  11530. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11531. if (! empty ( $aidKey )) {
  11532. Doo::loadClass ( 'XDeode' );
  11533. $XDeode = new XDeode ( 5 );
  11534. $aid = $XDeode->decode ( $aidKey );
  11535. Doo::loadModel ( "accountBook" );
  11536. $accountBook = new accountBook ();
  11537. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11538. if (empty ( $abDetail ))
  11539. die ( 'illegal request' );
  11540. // 删除收支
  11541. Doo::loadModel ( "accountBookStatistics" );
  11542. $accountBookStatistics = new accountBookStatistics ();
  11543. $item = array (
  11544. 'date' => date ( "Y-m-d" ),
  11545. 'aid' => $abDetail ['aid']
  11546. );
  11547. $accountType = '';
  11548. if ($abDetail ['expensesType'] == 1) {
  11549. $accountType = 6;
  11550. if ($abDetail ['accountType'] != 7) {
  11551. $item += array (
  11552. 'expensesType' => $abDetail ['expensesType'],
  11553. 'inComePrice' => - $abDetail ['receivedPrice']
  11554. );
  11555. } else {
  11556. $item += array (
  11557. 'financingPrice' => $abDetail ['receivedPrice'],
  11558. 'expensesType' => 3
  11559. );
  11560. }
  11561. } elseif ($abDetail ['expensesType'] == 2) {
  11562. $accountType = 5;
  11563. if ($abDetail ['accountType'] != 7) {
  11564. $item += array (
  11565. 'expensesType' => $abDetail ['expensesType'],
  11566. 'payPrice' => - $abDetail ['expenditurePrice']
  11567. );
  11568. } else {
  11569. $item += array (
  11570. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11571. 'expensesType' => 3
  11572. );
  11573. }
  11574. }
  11575. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11576. if ($abDetail ['expenditureMsg'] == '公司固定')
  11577. $accountType = 9;
  11578. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11579. $accountType = 10;
  11580. }
  11581. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11582. if ($abDetail ['accountMsg'] == '公司固定')
  11583. $accountType = 9;
  11584. elseif ($abDetail ['accountMsg'] == '公司活期')
  11585. $accountType = 10;
  11586. }
  11587. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11588. $accountType = 10;
  11589. }
  11590. $accountBookStatistics->setAccountBookStatistics ( $item );
  11591. $accountBook->delete ( array (
  11592. 'where' => 'aid=' . $aid,
  11593. 'limit' => 1
  11594. ) );
  11595. // 删除收入流水
  11596. if (! empty ( $accountType )) {
  11597. Doo::loadModel ( 'wasteBook' );
  11598. $wasteBook = new wasteBook ();
  11599. $wasteBook->delete ( array (
  11600. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11601. 'limit' => 1
  11602. ) );
  11603. }
  11604. }
  11605. return '/paymentsAchieve';
  11606. }
  11607. function paymentsCollect() {
  11608. Doo::loadModel ( "execute" );
  11609. $execute = new execute ();
  11610. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11611. die ( 'illegal request' );
  11612. }
  11613. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11614. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11615. Doo::loadModel ( "accountBookStatistics" );
  11616. $accountBookStatistics = new accountBookStatistics ();
  11617. Doo::loadClass ( 'receipt.func' );
  11618. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11619. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11620. $data ['html'] = $html ['html'];
  11621. $data ['inSum'] = $html ['sum'];
  11622. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11623. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11624. $data ['payHtml'] = $html ['html'];
  11625. $data ['paySum'] = $html ['sum'];
  11626. // 余额统计
  11627. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11628. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11629. include './protected/config/wasteBook.conf.php';
  11630. Doo::loadModel ( 'wasteBook' );
  11631. $wasteBook = new wasteBook ();
  11632. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11633. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11634. // 获得年份之前所有金额
  11635. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11636. // print_r($detail);
  11637. // $waste['total'];
  11638. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11639. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11640. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11641. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11642. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11643. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11644. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11645. if (date ( 'Y' ) > $year) {
  11646. $limitMonth = 12;
  11647. }
  11648. for($i = 1; $i <= 12; $i ++) {
  11649. $inComeA = $payB = 0;
  11650. $falg = true;
  11651. foreach ( $inComePay as $key => $value ) {
  11652. if ($value ['month'] == $i) {
  11653. $falg = false;
  11654. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11655. $inSum += $value ['accountPrice'];
  11656. $showInSum += $value ['accountPriceShow'];
  11657. $inComeA = $value ['accountPrice'];
  11658. break;
  11659. }
  11660. }
  11661. if ($falg)
  11662. $inComeHtml .= '<td class="taR">-</td>';
  11663. $payFalg = true;
  11664. foreach ( $pay as $key => $value ) {
  11665. if ($value ['month'] == $i) {
  11666. $payFalg = false;
  11667. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11668. $paySum += $value ['accountPrice'];
  11669. $showPaySum += $value ['accountPriceShow'];
  11670. $payB = $value ['accountPrice'];
  11671. break;
  11672. }
  11673. }
  11674. if ($payFalg)
  11675. $payHtml .= '<td class="taR">-</td>';
  11676. if (empty ( $balanceC ) || $limitMonth < $i)
  11677. $lastBalanceHtml .= '<td class="taR">-</td>';
  11678. else
  11679. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11680. $balanceC = $balanceC + $inComeA + $payB;
  11681. $balanceSum += $balanceC;
  11682. if (empty ( $balanceC ) || $limitMonth < $i)
  11683. $BalanceHtml .= '<td class="taR">-</td>';
  11684. else
  11685. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11686. // 余额统计
  11687. }
  11688. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11689. $data ['inComeHtml'] = $inComeHtml;
  11690. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11691. $data ['payBalanceHtml'] = $payHtml;
  11692. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11693. $data ['BalanceHtml'] = $BalanceHtml;
  11694. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11695. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11696. $mothHtml = "";
  11697. for($i = 1; $i <= 12; $i ++) {
  11698. if ($moth == $i)
  11699. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11700. else
  11701. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11702. }
  11703. $data ['mothHtml'] = $mothHtml;
  11704. $dateHtml = "";
  11705. $now = date ( "Y" );
  11706. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11707. if ($YEARD <= $now) {
  11708. $dateHtml .= '<option ';
  11709. if ($year == $YEARD) {
  11710. $dateHtml .= 'selected ';
  11711. }
  11712. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11713. }
  11714. }
  11715. $data ['dateHtml'] = $dateHtml;
  11716. $data ['year'] = $year;
  11717. $data ['memu'] = "receipt";
  11718. $data ['staff'] = $this->staff;
  11719. $data ['receiptMemu'] = 'paymentsCollect';
  11720. $data ['verifyId'] = $this->verifyId;
  11721. $data ['executeId'] = $this->executeId;
  11722. $this->render ( "/expenses/paymentsCollect", $data );
  11723. }
  11724. function paymentsCollectDay() {
  11725. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11726. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11727. if (empty ( $moth ))
  11728. return 'paymentsCollect';
  11729. Doo::loadModel ( "accountBookStatistics" );
  11730. $accountBookStatistics = new accountBookStatistics ();
  11731. $i = 2;
  11732. $y = 2013;
  11733. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11734. Doo::loadClass ( 'receipt.func' );
  11735. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11736. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11737. $data ['html'] = $html ['html'];
  11738. $data ['inSum'] = $html ['sum'];
  11739. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11740. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11741. $data ['payHtml'] = $html ['html'];
  11742. $data ['paySum'] = $html ['sum'];
  11743. $mothHtml = "";
  11744. for($i = 1; $i <= 12; $i ++) {
  11745. if ($moth == $i)
  11746. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11747. else
  11748. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11749. }
  11750. $data ['mothHtml'] = $mothHtml;
  11751. $data ['year'] = $year;
  11752. // 余额
  11753. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11754. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11755. include './protected/config/wasteBook.conf.php';
  11756. Doo::loadModel ( 'wasteBook' );
  11757. $wasteBook = new wasteBook ();
  11758. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11759. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11760. // 获得年份之前所有金额
  11761. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11762. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11763. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11764. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11765. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11766. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11767. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11768. // $balanceC = 0;
  11769. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11770. $limitDay = date ( 'd' );
  11771. $monthLK = ( int ) date ( 'm' );
  11772. if (date ( 'Y' ) > $year) {
  11773. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11774. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11775. $limitDay = 0;
  11776. }
  11777. for($i = 1; $i <= $day; $i ++) {
  11778. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11779. $inComeA = $payB = 0;
  11780. $falg = true;
  11781. foreach ( $inComePay as $key => $value ) {
  11782. if ($value ['day'] == $i) {
  11783. $falg = false;
  11784. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11785. $inSum += $value ['accountPrice'];
  11786. $showInSum += $value ['accountPriceShow'];
  11787. $inComeA = $value ['accountPrice'];
  11788. break;
  11789. }
  11790. }
  11791. if ($falg)
  11792. $inComeHtml .= '<td class="taR">-</td>';
  11793. $payFalg = true;
  11794. foreach ( $pay as $key => $value ) {
  11795. if ($value ['day'] == $i) {
  11796. $payFalg = false;
  11797. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11798. $paySum += $value ['accountPrice'];
  11799. $showPaySum += $value ['accountPriceShow'];
  11800. $payB = $value ['accountPrice'];
  11801. break;
  11802. }
  11803. }
  11804. if ($payFalg)
  11805. $payHtml .= '<td class="taR">-</td>';
  11806. if (empty ( $balanceC ) || $limitDay < $i)
  11807. $lastBalanceHtml .= '<td class="taR">-</td>';
  11808. else
  11809. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11810. $balanceC = $balanceC + $inComeA + $payB;
  11811. $balanceSum += $balanceC;
  11812. if (empty ( $balanceC ) || $limitDay < $i)
  11813. $BalanceHtml .= '<td class="taR">-</td>';
  11814. else
  11815. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11816. }
  11817. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11818. $data ['inComeHtml'] = $inComeHtml;
  11819. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11820. $data ['payBalanceHtml'] = $payHtml;
  11821. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11822. $data ['BalanceHtml'] = $BalanceHtml;
  11823. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11824. $data ['dayHtml'] = $dayHtml;
  11825. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11826. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11827. $dateHtml = "";
  11828. $now = date ( "Y" );
  11829. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11830. if ($YEARD <= $now) {
  11831. $dateHtml .= '<option ';
  11832. if ($year == $YEARD) {
  11833. $dateHtml .= 'selected ';
  11834. }
  11835. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11836. }
  11837. }
  11838. $data ['dateHtml'] = $dateHtml;
  11839. $data ['memu'] = "receipt";
  11840. $data ['staff'] = $this->staff;
  11841. $data ['receiptMemu'] = 'paymentsCollect';
  11842. $data ['verifyId'] = $this->verifyId;
  11843. $data ['executeId'] = $this->executeId;
  11844. $this->render ( "/expenses/paymentsCollectDay", $data );
  11845. }
  11846. // 公司流水
  11847. function wasteBook() {
  11848. Doo::loadModel ( "execute" );
  11849. $execute = new execute ();
  11850. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11851. die ( 'illegal request' );
  11852. }
  11853. include './protected/config/wasteBook.conf.php';
  11854. Doo::loadModel ( 'wasteBook' );
  11855. $wasteBook = new wasteBook ();
  11856. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11857. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11858. //
  11859. $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'];
  11860. $CGBDeposit_total =$waste ['bank'] ['CGBDeposit']+$waste ['bank'] ['HUADeposit'];
  11861. //$waste ['bank'] ['ICBCDeposit']=sprintf("%.2f", round($waste ['bank'] ['ICBCDeposit'], 2));
  11862. // print_r($waste);
  11863. $data ['waste'] = $waste;
  11864. $data ['total'] = $total;
  11865. $data ['CGBDeposit_total'] = $CGBDeposit_total;
  11866. $data['cashBalance']= $CGBDeposit_total+$waste ['bank'] ['ICBCDeposit']+$waste ['bank'] ['PersonalDeposit']+$waste ['financial'] ['current'] ['CGBDeposit']+$waste ['financial'] ['current'] ['ICBCDeposit'];
  11867. // 月流水数据结构
  11868. $monthStatistics = array ();
  11869. $incomeMothStatistics = array ();
  11870. $expenditureMothStatistics = array ();
  11871. for($i = 1; $i <= 12; $i ++) {
  11872. $month = date ( 'Y' ) . '-' . $i;
  11873. if ($i < 10)
  11874. $month = date ( 'Y' ) . '-0' . $i;
  11875. array_push ( $monthStatistics, $month );
  11876. }
  11877. foreach ( $monthStatistics as $value ) {
  11878. $falg = true;
  11879. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11880. if ($value == $v ['inputDate']) {
  11881. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11882. $falg = false;
  11883. }
  11884. }
  11885. if ($falg) {
  11886. array_push ( $incomeMothStatistics, '' );
  11887. }
  11888. $falgEx = true;
  11889. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11890. if ($value == $v ['inputDate']) {
  11891. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11892. $falg = false;
  11893. }
  11894. }
  11895. if ($falgEx) {
  11896. array_push ( $expenditureMothStatistics, '' );
  11897. }
  11898. }
  11899. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11900. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11901. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11902. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11903. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11904. // print_r($incomeList);
  11905. $data ['expenditureList'] = $expenditureList;
  11906. $data ['incomeList'] = $incomeList;
  11907. $data ['memu'] = "receipt";
  11908. $data ['staff'] = $this->staff;
  11909. $data ['receiptMemu'] = 'wasteBook';
  11910. $data ['verifyId'] = $this->verifyId;
  11911. $data ['executeId'] = $this->executeId;
  11912. $this->render ( "/expenses/wasteBook", $data );
  11913. }
  11914. function wasteBookIncome() {
  11915. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11916. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11917. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11918. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11919. $data ['dailyIncomeType'] = $dailyIncomeType;
  11920. Doo::loadModel ( 'wasteBook' );
  11921. $wasteBook = new wasteBook ();
  11922. Doo::loadModel ( 'L_category' );
  11923. $L_category = new L_category ();
  11924. Doo::loadClass ( 'XDeode' );
  11925. $XDeode = new XDeode ( 5 );
  11926. $year=date("Y");
  11927. $theDay=date("Y-m-d");
  11928. $dateArr = explode ( ':', $date );
  11929. $D1 = '';
  11930. $D2 = '';
  11931. $con = '';
  11932. if (! empty ( $date )) {
  11933. $D1 = $dateArr [0];
  11934. $D2 = $dateArr [1];
  11935. }
  11936. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11937. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11938. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11939. $con = ' and inputDate = "' . $D1 . '"';
  11940. else{
  11941. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  11942. }
  11943. if ($cid != 'ALL') {
  11944. $cid = $XDeode->decode ( $cid );
  11945. $con .= ' and cid = "' . $cid . '"';
  11946. }
  11947. if ($accountType != 'ALL') {
  11948. if ($accountType == 'INVOICE') {
  11949. $con .= ' and (accountType = 7 or accountType = 8)';
  11950. } elseif ($accountType == 'PAYMENTS') {
  11951. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11952. if ($dailyIncomeType != 'ALL') {
  11953. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11954. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11955. }
  11956. }
  11957. }
  11958. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11959. foreach ($incomeList as $key=>$value){
  11960. if(($value['accountType']==6||$value['accountType']==9||$value['accountType']==10)&&$value['synPaymentDate']==0){
  11961. $wasteBook = new wasteBook ();
  11962. $wasteBook->wid = $value['wid'];
  11963. $wasteBook->synPaymentDate = 1;
  11964. $wasteBook->inputDate = $value['data']['receivedDate'];
  11965. $wasteBook->update();
  11966. }
  11967. }
  11968. $sum = 0;$thsDaySum=0;
  11969. foreach ( $incomeList as $key => $value ) {
  11970. $sum += $value ['accountPrice'];
  11971. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  11972. $thsDaySum+=$value ['accountPrice'];
  11973. }
  11974. }
  11975. // print_r($incomeList);
  11976. // 获得办事和部门
  11977. $categoryList = $L_category->getCategory ();
  11978. $data ['accountType'] = $accountType;
  11979. $data ['cid'] = $cid;
  11980. $data ['categoryList'] = $categoryList;
  11981. $data ['sum'] = $sum;
  11982. $data ['incomeList'] = $incomeList;
  11983. $data ['inputDate'] = $date;
  11984. $data['year']=$year;
  11985. $data ['thsDay'] =$theDay;
  11986. $data ['thsDaySum'] =$thsDaySum;
  11987. $data ['memu'] = "receipt";
  11988. $data ['staff'] = $this->staff;
  11989. $data ['receiptMemu'] = 'wasteBook';
  11990. $data ['verifyId'] = $this->verifyId;
  11991. $data ['executeId'] = $this->executeId;
  11992. $this->render ( "/expenses/wasteBookIncome", $data );
  11993. }
  11994. /**
  11995. * 所有支出
  11996. */
  11997. function wasteBookExpenditure() {
  11998. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11999. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  12000. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  12001. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  12002. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  12003. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  12004. $data ['receiptType'] = $receiptType;
  12005. Doo::loadModel ( 'wasteBook' );
  12006. $wasteBook = new wasteBook ();
  12007. Doo::loadModel ( 'L_category' );
  12008. $L_category = new L_category ();
  12009. Doo::loadClass ( 'XDeode' );
  12010. $XDeode = new XDeode ( 5 );
  12011. $year=date("Y");
  12012. $theDay=date("Y-m-d");
  12013. $dateArr = explode ( ':', $date );
  12014. $D1 = '';
  12015. $D2 = '';
  12016. $con = '';
  12017. if (! empty ( $date )) {
  12018. $D1 = $dateArr [0];
  12019. $D2 = $dateArr [1];
  12020. }
  12021. if (! empty ( $D1 ) && ! empty ( $D2 ))
  12022. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  12023. elseif (! empty ( $D1 ) && empty ( $D2 ))
  12024. $con = ' and inputDate = "' . $D1 . '"';
  12025. else{
  12026. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  12027. }
  12028. if ($cid != 'ALL') {
  12029. $cid = $XDeode->decode ( $cid );
  12030. $con .= ' and cid = "' . $cid . '"';
  12031. }
  12032. if ($accountType != 'ALL') {
  12033. if ($accountType == 'INVOICE') {
  12034. $con .= ' and accountType = 11';
  12035. } elseif ($accountType == 'PAYMENTS') {
  12036. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  12037. if ($dailyExpenditureType != 'ALL') {
  12038. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  12039. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  12040. }
  12041. } elseif ($accountType == 'RECEIPT') {
  12042. if ($receiptType == 'ALL') {
  12043. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  12044. } else {
  12045. $receiptType = $XDeode->decode ( $receiptType );
  12046. echo $receiptType;
  12047. if ($receiptType == 1) {
  12048. $con .= ' and (accountType = 1 or accountType=2)';
  12049. } else {
  12050. $con .= ' and accountType = ' . $receiptType;
  12051. }
  12052. }
  12053. }
  12054. }
  12055. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  12056. foreach ($incomeList as $key=>$value){
  12057. if(($value['accountType']==5||$value['accountType']==9||$value['accountType']==10)&&$value['synPaymentDate']==0){
  12058. $wasteBook = new wasteBook ();
  12059. $wasteBook->wid = $value['wid'];
  12060. $wasteBook->synPaymentDate = 1;
  12061. $wasteBook->inputDate = $value['data']['expenditureDate'];
  12062. $wasteBook->update();
  12063. }
  12064. }
  12065. $sum = 0;$thsDaySum=0;
  12066. foreach ( $incomeList as $key => $value ) {
  12067. $sum += $value ['accountPriceShow'];
  12068. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  12069. $thsDaySum+=$value ['accountPriceShow'];
  12070. }
  12071. }
  12072. // print_r($incomeList);
  12073. // 获得办事和部门
  12074. $categoryList = $L_category->getCategory ();
  12075. $data ['accountType'] = $accountType;
  12076. $data ['cid'] = $cid;
  12077. $data ['categoryList'] = $categoryList;
  12078. $data ['sum'] = $sum;
  12079. $data ['incomeList'] = $incomeList;
  12080. $data ['inputDate'] = $date;
  12081. $data['year']=$year;
  12082. $data ['thsDay'] =$theDay;
  12083. $data ['thsDaySum'] =$thsDaySum;
  12084. $data ['memu'] = "receipt";
  12085. $data ['staff'] = $this->staff;
  12086. $data ['receiptMemu'] = 'wasteBook';
  12087. $data ['verifyId'] = $this->verifyId;
  12088. $data ['executeId'] = $this->executeId;
  12089. $this->render ( "/expenses/wasteBookExpenditure", $data );
  12090. }
  12091. function ajaxGetWasteinvoiceReceivables() {
  12092. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12093. Doo::loadClass ( 'XDeode' );
  12094. $XDeode = new XDeode ( 5 );
  12095. $irid = $XDeode->decode ( $serial );
  12096. Doo::loadModel ( 'invoiceReceivables' );
  12097. $invoiceReceivables = new invoiceReceivables ();
  12098. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  12099. echo json_encode ( array (
  12100. 'status' => 1,
  12101. 'detail' => $detail
  12102. ) );
  12103. }
  12104. function ajaxGetPaymentsByAid() {
  12105. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12106. Doo::loadModel ( "accountBook" );
  12107. $accountBook = new accountBook ();
  12108. $detail = $accountBook->getAccountBookByAid ( $serial );
  12109. echo json_encode ( array (
  12110. 'status' => 1,
  12111. 'detail' => $detail
  12112. ) );
  12113. }
  12114. function ajaxGetWasteInvoice() {
  12115. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12116. Doo::loadModel ( 'invoice' );
  12117. $invoice = new invoice ();
  12118. Doo::loadModel ( 'invoiceReceivables' );
  12119. $invoiceReceivables = new invoiceReceivables ();
  12120. $detail = $invoice->getInvoiceByIid ( $serial );
  12121. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  12122. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  12123. echo json_encode ( array (
  12124. 'status' => 1,
  12125. 'detail' => $detail
  12126. ) );
  12127. }
  12128. /**
  12129. */
  12130. function ajaxGetWasteReceipt() {
  12131. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12132. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  12133. Doo::loadModel ( 'receipt' );
  12134. $receipt = new receipt ();
  12135. Doo::loadClass ( 'XDeode' );
  12136. $XDeode = new XDeode ( 5 );
  12137. $rid = $XDeode->decode ( $serial );
  12138. $accountType= $XDeode->decode ( $accountTypeKey );
  12139. // 获得个数据
  12140. $detail = $receipt->getReceiptByRid ( $rid );
  12141. // 初始化
  12142. $detail ['reviseDetail'] = array ();
  12143. if (! empty ( $value ['reviseDetail'] ))
  12144. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  12145. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  12146. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  12147. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  12148. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  12149. // 获得费用html
  12150. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  12151. // 获得费用审批人数据
  12152. $detail = $this->getReceiptApproverHtml ( $detail );
  12153. // 审批执行
  12154. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  12155. <th class="taC" width="90">审批人</th>
  12156. <th class="taC">审批意见</th></tr>';
  12157. foreach ( $detail ['verifyList'] as $key => $value ) {
  12158. $html .= '<tr>
  12159. <td>' . $value [1] . '</td>
  12160. <td>' . $value ['opinion'] . '</td>
  12161. </tr>
  12162. ';
  12163. }
  12164. $html .= ' </tbody></table>';
  12165. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  12166. <th class="taC" width="90">执行人</th>
  12167. <th class="taC">执行意见</th></tr>';
  12168. foreach ( $detail ['executeCopy'] as $key => $value ) {
  12169. $html .= '<tr>
  12170. <td>' . $value [1] . '</td>
  12171. <td>' . $value ['opinion'] . '</td>
  12172. </tr>
  12173. ';
  12174. }
  12175. $html .= ' </tbody></table>';
  12176. if($accountType==1){
  12177. Doo::loadModel ( 'loanReceipt' );
  12178. $loanReceipt = new loanReceipt ();
  12179. $loanList = $loanReceipt->getOne ( array (
  12180. 'where' => 'rid=' . $detail ['loanRid'],
  12181. 'desc' => 'rid',
  12182. 'asArray' => true
  12183. ) );
  12184. $html .= '<table class="table table-bordered table-condensed">
  12185. <tr class="warning">
  12186. <td class="taR"><b>汇款金额</b></td>
  12187. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  12188. </tr>
  12189. </table>';
  12190. }else{
  12191. $html .= '<table class="table table-bordered table-condensed">
  12192. <tr class="warning">
  12193. <td class="taR"><b>汇款金额</b></td>
  12194. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  12195. </tr>
  12196. </table>';
  12197. }
  12198. // print_r($detail['verifyList']);
  12199. // header ( 'Content-Type:text/html;charset=utf-8' );
  12200. // echo $html;
  12201. echo json_encode ( array (
  12202. 'status' => 1,
  12203. 'html' => $html,
  12204. 'detail' => $detail
  12205. ) );
  12206. }
  12207. function getReceiptApproverHtml($detail = array()) {
  12208. Doo::loadModel ( 'loanReceipt' );
  12209. $loanReceipt = new loanReceipt ();
  12210. Doo::loadModel ( 'verify' );
  12211. $verify = new verify ();
  12212. Doo::loadModel ( 'staff' );
  12213. $staff = new staff ();
  12214. if (empty ( $detail ))
  12215. return array ();
  12216. $loanList = $loanReceipt->getOne ( array (
  12217. 'where' => 'rid=' . $detail ['loanRid'],
  12218. 'desc' => 'rid',
  12219. 'asArray' => true
  12220. ) );
  12221. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  12222. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  12223. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  12224. else
  12225. $verifyList ['staff'] = $detail ['verifyBreakup'];
  12226. } else
  12227. $verifyList = $verify->getOne ( array (
  12228. 'where' => 'vid=' . $detail ['verify'],
  12229. 'asArray' => true
  12230. ) );
  12231. $verifyList = json_decode ( $verifyList ['staff'], true );
  12232. Doo::loadModel ( 'role' );
  12233. $role = new role ();
  12234. $roleId = 0;
  12235. $flag = true;
  12236. $roleKey = 0;
  12237. $endStaffArray = array ();
  12238. $roleArrayCopy = array ();
  12239. foreach ( $verifyList as $k => $v ) {
  12240. // init verifyStaff
  12241. if ($v [1] == 'ROLE') {
  12242. if (! empty ( $verifyStaff )) {
  12243. $endStaffArray = end ( $verifyStaff );
  12244. }
  12245. $roleVerify = json_decode ( $v [3], true );
  12246. $roleKey = $k;
  12247. $roleArray = array ();
  12248. $rolename = $role->getOne ( array (
  12249. 'where' => 'rid=' . $v [0],
  12250. 'asArray' => true
  12251. ) );
  12252. foreach ( $roleVerify as $o => $p ) {
  12253. $staffID = explode ( '_', $p );
  12254. $staffInfo = $staff->getOne ( array (
  12255. 'where' => 'sid=' . $staffID [0],
  12256. 'asArray' => true
  12257. ) );
  12258. // print_r($staffID);
  12259. $exp = array (
  12260. 0 => $staffInfo ['sid'],
  12261. 1 => $staffID [1],
  12262. 2 => $staffInfo ['avatar'],
  12263. 'date' => '',
  12264. 'date' => '',
  12265. 'opinion' => '',
  12266. 'status' => '',
  12267. 'rolename' => $rolename ['name']
  12268. );
  12269. array_push ( $roleArray, $exp );
  12270. }
  12271. $roleArrayCopy [$v [0]] = $roleArray;
  12272. // $verifyList[$k]['roleArray']=$roleArray;
  12273. }
  12274. $verifyList [$k] ['date'] = "";
  12275. $verifyList [$k] ['opinion'] = "";
  12276. $verifyList [$k] ['status'] = "";
  12277. if (empty ( $verifyStaff )) {
  12278. $verifyList [$k] ['date'] = "";
  12279. $verifyList [$k] ['opinion'] = "";
  12280. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  12281. $verifyList [$k] ['status'] = 4;
  12282. $flag = false;
  12283. }
  12284. } else {
  12285. foreach ( $verifyStaff as $m => $u ) {
  12286. if ($v [0] == $m) {
  12287. $verifyList [$k] ['date'] = $u ['date'];
  12288. $verifyList [$k] ['opinion'] = $u ['opinion'];
  12289. $verifyList [$k] ['status'] = $u ['status'];
  12290. $flag = false;
  12291. break;
  12292. }
  12293. }
  12294. $endStaffArray = end ( $verifyStaff );
  12295. }
  12296. }
  12297. $rolename ['name'] = '';
  12298. if (! empty ( $roleId )) {
  12299. Doo::loadModel ( 'role' );
  12300. $role = new role ();
  12301. $rolename = $role->getOne ( array (
  12302. 'where' => 'rid=' . $roleId,
  12303. 'asArray' => true
  12304. ) );
  12305. }
  12306. if (! empty ( $verifyStaff ))
  12307. $endStaffArray = end ( $verifyStaff );
  12308. $KOP = false;
  12309. foreach ( $roleArrayCopy as $P => $A ) {
  12310. foreach ( $A as $MKI => $AVL ) {
  12311. if (! empty ( $verifyStaff )) {
  12312. // &&$rolename['rid']==$endStaffArray['nextStaff']
  12313. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  12314. $button = 4;
  12315. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12316. }
  12317. foreach ( $verifyStaff as $m => $u ) {
  12318. $AVLFK = $AVL [0] . '_R';
  12319. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  12320. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  12321. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  12322. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  12323. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  12324. break;
  12325. }
  12326. }
  12327. } else {
  12328. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  12329. $button = 4;
  12330. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12331. }
  12332. }
  12333. // $roleArray[$MKI]['rolename']=$rolename['name'];
  12334. $KOP = true;
  12335. }
  12336. }
  12337. foreach ( $roleArrayCopy as $k => $v ) {
  12338. foreach ( $verifyList as $m => $n ) {
  12339. if ($n [0] == $k) {
  12340. array_splice ( $verifyList, $m, 1, $v );
  12341. }
  12342. }
  12343. }
  12344. // 费用执行人相关数据
  12345. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  12346. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  12347. foreach ( $executeCopy as $k => $v ) {
  12348. $executeCopy [$k] ['date'] = '';
  12349. $executeCopy [$k] ['opinion'] = '';
  12350. $executeCopy [$k] ['status'] = '';
  12351. if (! empty ( $executeStaff ))
  12352. foreach ( $executeStaff as $m => $u ) {
  12353. if ($v [0] == $m) {
  12354. $executeCopy [$k] ['date'] = $u ['date'];
  12355. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  12356. $executeCopy [$k] ['status'] = $u ['status'];
  12357. break;
  12358. }
  12359. }
  12360. }
  12361. $detail ['executeCopy'] = $executeCopy;
  12362. $detail ['verifyList'] = $verifyList;
  12363. return $detail;
  12364. }
  12365. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  12366. if (empty ( $detail ))
  12367. return '';
  12368. $html = '';
  12369. if ($detail ['Rtype'] == 0) { // 报销单
  12370. $html .= '<table class="table table-bordered table-condensed">
  12371. <tbody>
  12372. <tr>
  12373. <th colspan="2" class="taC">日常相关费用</th>
  12374. </tr>';
  12375. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12376. $html .= '
  12377. <tr>
  12378. <th>' . $value ['name'] . '</th>
  12379. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12380. </tr>';
  12381. }
  12382. $html .= '
  12383. <tr>
  12384. <th class="taR">合计</th>
  12385. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12386. </tr>';
  12387. $html .= '<tr>
  12388. <th colspan="2" class="taC">差旅相关费用</th>
  12389. </tr>';
  12390. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12391. $html .= '
  12392. <tr>
  12393. <th>' . $value ['name'] . '</th>
  12394. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12395. </tr>';
  12396. }
  12397. $html .= '
  12398. <tr>
  12399. <th class="taR">合计</th>
  12400. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12401. </tr>';
  12402. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12403. $html .= '<tr>
  12404. <th colspan="2" class="taC">内部培训费用</th>
  12405. </tr>';
  12406. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12407. $html .= '
  12408. <tr>
  12409. <th>' . $value ['name'] . '</th>
  12410. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12411. </tr>';
  12412. }
  12413. $html .= '
  12414. <tr>
  12415. <th class="taR">合计</th>
  12416. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12417. </tr>';
  12418. }
  12419. $html .= '<tr>
  12420. <th colspan="2" class="taC">其他</th>
  12421. </tr>';
  12422. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12423. $html .= '
  12424. <tr>
  12425. <th>' . $value ['name'] . '</th>
  12426. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12427. </tr>';
  12428. }
  12429. $html .= '
  12430. <tr>
  12431. <th class="taR">合计</th>
  12432. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12433. </tr>';
  12434. $html .= '<tr>
  12435. <th colspan="2" class="taC">报销金额调整</th>
  12436. </tr>';
  12437. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12438. $html .= '
  12439. <tr>
  12440. <th>' . $value ['name'] . '</th>
  12441. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12442. </tr>';
  12443. }
  12444. $html .= '
  12445. <tr>
  12446. <th class="taR">合计</th>
  12447. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12448. </tr>';
  12449. $html .= '
  12450. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12451. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12452. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12453. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12454. <tr class="warning">
  12455. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12456. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12457. </tr>
  12458. </tbody>
  12459. </table>';
  12460. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  12461. $html .= '
  12462. <table class="table table-bordered table-condensed">
  12463. <tbody>
  12464. <tr>
  12465. <th colspan="2" class="taC">办事处相关费用</th>
  12466. </tr>';
  12467. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12468. $html .= '
  12469. <tr>
  12470. <th>' . $value ['name'] . '</th>
  12471. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12472. </tr>';
  12473. }
  12474. $html .= '
  12475. <tr>
  12476. <th class="taR">合计</th>
  12477. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12478. </tr>';
  12479. $html .= '
  12480. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12481. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12482. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12483. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12484. <tr class="warning">
  12485. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12486. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12487. </tr>
  12488. </tbody>
  12489. </table>';
  12490. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  12491. Doo::loadModel ( 'loanReceipt' );
  12492. $loanReceipt = new loanReceipt ();
  12493. $loanList = $loanReceipt->getOne ( array (
  12494. 'where' => 'rid=' . $detail ['loanRid'],
  12495. 'desc' => 'rid',
  12496. 'asArray' => true
  12497. ) );
  12498. // print_r($loanList);
  12499. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  12500. $html .= '<table class="table table-bordered table-condensed">
  12501. <tbody>
  12502. <tr>
  12503. <th colspan="2" class="taC">借款费用</th>
  12504. </tr>';
  12505. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  12506. $html .= '<tr>
  12507. <th>' . $value ['name'] . '</th>
  12508. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12509. </tr>';
  12510. }
  12511. $html .= '<tr>
  12512. <th class="taC" colspan="2">产生费用所在办事处</th>
  12513. </tr>
  12514. <tr>
  12515. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  12516. </tr>
  12517. <tr>
  12518. <th class="taC" colspan="2">费用说明</th>
  12519. </tr>
  12520. <tr>
  12521. <td colspan="2">' . $loanList ['explanation'] . '</td>
  12522. </tr>
  12523. <tr class="warning">
  12524. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12525. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12526. </tr>
  12527. </tbody>
  12528. </table>
  12529. ';
  12530. if ( $accountType==2) {
  12531. $balance=$detail ['sum']-$loanList ['sum'];
  12532. $balanceCN=$this->num_to_rmb($balance);
  12533. $html .= '<table class="table table-bordered table-condensed">
  12534. <tbody>
  12535. <tr>
  12536. <th colspan="2" class="taC">日常相关费用</th>
  12537. </tr>';
  12538. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12539. $html .= '
  12540. <tr>
  12541. <th>' . $value ['name'] . '</th>
  12542. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12543. </tr>';
  12544. }
  12545. $html .= '
  12546. <tr>
  12547. <th class="taR">合计</th>
  12548. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12549. </tr>';
  12550. $html .= '<tr>
  12551. <th colspan="2" class="taC">差旅相关费用</th>
  12552. </tr>';
  12553. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12554. $html .= '
  12555. <tr>
  12556. <th>' . $value ['name'] . '</th>
  12557. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12558. </tr>';
  12559. }
  12560. $html .= '
  12561. <tr>
  12562. <th class="taR">合计</th>
  12563. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12564. </tr>';
  12565. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12566. $html .= '<tr>
  12567. <th colspan="2" class="taC">内部培训费用</th>
  12568. </tr>';
  12569. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12570. $html .= '
  12571. <tr>
  12572. <th>' . $value ['name'] . '</th>
  12573. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12574. </tr>';
  12575. }
  12576. $html .= '
  12577. <tr>
  12578. <th class="taR">合计</th>
  12579. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12580. </tr>';
  12581. }
  12582. $html .= '<tr>
  12583. <th colspan="2" class="taC">其他</th>
  12584. </tr>';
  12585. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12586. $html .= '
  12587. <tr>
  12588. <th>' . $value ['name'] . '</th>
  12589. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12590. </tr>';
  12591. }
  12592. $html .= '
  12593. <tr>
  12594. <th class="taR">合计</th>
  12595. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12596. </tr>';
  12597. $html .= '<tr>
  12598. <th colspan="2" class="taC">报销金额调整</th>
  12599. </tr>';
  12600. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12601. $html .= '
  12602. <tr>
  12603. <th>' . $value ['name'] . '</th>
  12604. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12605. </tr>';
  12606. }
  12607. $html .= '
  12608. <tr>
  12609. <th class="taR">合计</th>
  12610. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12611. </tr>';
  12612. $html .= '
  12613. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12614. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12615. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12616. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12617. <tr class="warning">
  12618. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12619. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12620. </tr>
  12621. <tr class="success">
  12622. <td class="taR"><b>借款结余</b></td>
  12623. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12624. </tr>
  12625. </tbody>
  12626. </table>';
  12627. }
  12628. }
  12629. return $html;
  12630. }
  12631. /**
  12632. * 计算流水
  12633. */
  12634. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12635. $bakWaste ['bank'] = array (
  12636. 'CGBDeposit' => 0,
  12637. 'ICBCDeposit' => 0,
  12638. 'HUADeposit' => 0,
  12639. 'PersonalDeposit' => 0
  12640. );
  12641. $bakWaste ['financial'] = array (
  12642. 'current' => array (
  12643. 'CGBDeposit' => 0,
  12644. 'ICBCDeposit' => 0
  12645. ),
  12646. 'fixed' => array (
  12647. 'CGBDeposit' => 0,
  12648. 'ICBCDeposit' => 0
  12649. )
  12650. );
  12651. // 存款
  12652. foreach ( $waste ['bank'] as $key => $value ) {
  12653. // 收入
  12654. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12655. // 广发
  12656. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12657. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12658. }
  12659. // 工商
  12660. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12661. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12662. }
  12663. // 华润
  12664. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12665. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12666. }
  12667. // 个人
  12668. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12669. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12670. }
  12671. }
  12672. }
  12673. foreach ( $waste ['bank'] as $key => $value ) {
  12674. // 支出
  12675. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12676. // 广发
  12677. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12678. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12679. }
  12680. // 工商
  12681. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12682. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12683. }
  12684. // 华润
  12685. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12686. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12687. }
  12688. // 个人
  12689. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12690. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12691. }
  12692. }
  12693. }
  12694. // 活期
  12695. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12696. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12697. // 广发
  12698. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12699. $waste ['financial'] ['current'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12700. }
  12701. // 工商
  12702. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12703. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12704. }
  12705. // 个人
  12706. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12707. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12708. }
  12709. }
  12710. }
  12711. // print_r($inComeStatistics ['fixedStatistics']);
  12712. // 固期
  12713. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12714. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12715. // 广发
  12716. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12717. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12718. }
  12719. // 工商
  12720. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12721. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12722. }
  12723. // 个人
  12724. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12725. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12726. }
  12727. }
  12728. }
  12729. return $waste;
  12730. }
  12731. function lyt() {
  12732. Doo::loadModel ( "receiptDetail" );
  12733. $receiptDetail = new receiptDetail ();
  12734. $receiptCollectList = $receiptDetail->find ( array (
  12735. 'where' => 'status=1 ',
  12736. 'asArray' => true
  12737. ) );
  12738. foreach ( $receiptCollectList as $key => $value ) {
  12739. $receiptDetail = new receiptDetail ();
  12740. $receiptDetail->pastDate = $value ['date'];
  12741. $receiptDetail->update ( array (
  12742. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12743. ) );
  12744. }
  12745. }
  12746. function staffCollectMonthDetail() {
  12747. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12748. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12749. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12750. if (! $year)
  12751. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12752. if (! $month)
  12753. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12754. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12755. if (! $nature){
  12756. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12757. }
  12758. Doo::loadModel ( 'staff' );
  12759. $staff = new staff ();
  12760. Doo::loadModel ( "receiptDetail" );
  12761. $receiptDetail = new receiptDetail ();
  12762. Doo::loadModel ( 'accountItem' );
  12763. $accountItem = new accountItem ();
  12764. Doo::loadModel ( 'statistics' );
  12765. $statistics = new statistics ();
  12766. Doo::loadModel ( "receiptAuthorityManage" );
  12767. $receiptAuthorityManage = new receiptAuthorityManage ();
  12768. $aiList=$accountItem->getAccountItem();
  12769. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12770. $cidList = array ();
  12771. foreach ( $imcStaff as $key => $value ) {
  12772. array_push ( $cidList, $value ['cid'] );
  12773. }
  12774. $cidString = implode ( ',', $cidList );
  12775. $naturecon='';
  12776. if ($nature=='ONJOB'){
  12777. $naturecon=' and (nature!=4 )';
  12778. }elseif($nature=='LEAVEJOB'){
  12779. $naturecon=' and (nature=4 )';
  12780. }else{
  12781. die ( 'illegal request--nature' );
  12782. }
  12783. $staffList = $staff->find ( array (
  12784. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12785. 'asArray' => true
  12786. ) );
  12787. $categoryList = $staff->find ( array (
  12788. 'select' => 'COUNT(*) as count,cid,category',
  12789. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12790. 'groupby' => 'cid',
  12791. 'asArray' => true
  12792. ) );
  12793. $list = array ();
  12794. foreach($aiList as $key=>$value){
  12795. foreach ($value as $v){
  12796. $subtotal[$key][$v['name']]=0;
  12797. }
  12798. }
  12799. foreach ( $categoryList as $vlu ) {
  12800. $s1 = 0;
  12801. $m1 = 0;
  12802. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12803. foreach ( $staffList as $value ) {
  12804. if ($vlu ['cid'] == $value ['cid']) {
  12805. // pastDate
  12806. $receiptCollectList = $receiptDetail->find ( array (
  12807. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12808. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12809. 'groupby' => 'item,Month(pastDate),itemCategory',
  12810. 'asArray' => true
  12811. ) );
  12812. if (! empty ( $receiptCollectList )) {
  12813. $receiptL = array (
  12814. '日常相关费用' => array (),
  12815. '差旅相关费用' => array (),
  12816. '内部培训费用' => array (),
  12817. '培训班费用' => array (),
  12818. '其他' => array ()
  12819. );
  12820. $html = "";
  12821. $psum = 0;
  12822. foreach ( $aiList[$this->AGENCY] as $va ) {
  12823. $falg = true;
  12824. foreach ( $receiptCollectList as $v ) {
  12825. if ($v ['itemCategory'] == '日常相关费用') {
  12826. if ($v ['item'] == $va['name']) {
  12827. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12828. $psum += $v ['price'];
  12829. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12830. $falg = false;
  12831. break;
  12832. }
  12833. }
  12834. }
  12835. if ($falg)
  12836. $html .= '<td class="taR">-</td>';
  12837. }
  12838. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12839. if (! empty ( $psum ))
  12840. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12841. else
  12842. $psum = '<td class="colGreen taR">-</td>';
  12843. $receiptL ['日常相关费用'] = $psum . $html;
  12844. /* ----------------------------------- */
  12845. $html = "";
  12846. $psum = 0;
  12847. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12848. $falg = true;
  12849. foreach ( $receiptCollectList as $v ) {
  12850. if ($v ['itemCategory'] == '差旅相关费用') {
  12851. if ($v ['item'] == $va['name']) {
  12852. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12853. $psum += $v ['price'];
  12854. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12855. $falg = false;
  12856. break;
  12857. }
  12858. }
  12859. }
  12860. if ($falg)
  12861. $html .= '<td class="taR">-</td>';
  12862. }
  12863. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12864. if (! empty ( $psum ))
  12865. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12866. else
  12867. $psum = '<td class="colGreen taR">-</td>';
  12868. $receiptL ['差旅相关费用'] = $psum . $html;
  12869. /* ------------------------------------- */
  12870. $html = "";
  12871. $psum = 0;
  12872. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12873. $falg = true;
  12874. foreach ( $receiptCollectList as $v ) {
  12875. if ($v ['itemCategory'] == '内部培训费用') {
  12876. if ($v ['item'] == $va['name']) {
  12877. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12878. $psum += $v ['price'];
  12879. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12880. $falg = false;
  12881. break;
  12882. }
  12883. }
  12884. }
  12885. if ($falg)
  12886. $html .= '<td class="taR">-</td>';
  12887. }
  12888. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12889. if (! empty ( $psum ))
  12890. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12891. else
  12892. $psum = '<td class="colGreen taR">-</td>';
  12893. $receiptL ['内部培训费用'] = $psum . $html;
  12894. /* ----------------------------------- */
  12895. $html = "";
  12896. $psum = 0;
  12897. foreach ( $aiList[$this->TRAIN] as $va ) {
  12898. $falg = true;
  12899. foreach ( $receiptCollectList as $v ) {
  12900. if ($v ['itemCategory'] == '培训班费用') {
  12901. if ($v ['item'] == $va['name']) {
  12902. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12903. $psum += $v ['price'];
  12904. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12905. $falg = false;
  12906. break;
  12907. }
  12908. }
  12909. }
  12910. if ($falg)
  12911. $html .= '<td class="taR">-</td>';
  12912. }
  12913. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12914. if (! empty ( $psum ))
  12915. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12916. else
  12917. $psum = '<td class="colGreen taR">-</td>';
  12918. $receiptL ['培训班费用'] = $psum . $html;
  12919. /* ------------------------------------- */
  12920. $html = "";
  12921. $psum = 0;
  12922. foreach ( $aiList[$this->OTHER] as $va ) {
  12923. $falg = true;
  12924. foreach ( $receiptCollectList as $v ) {
  12925. if ($v ['itemCategory'] == '其他') {
  12926. if (trim ( $v ['item'] ) == $va['name']) {
  12927. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12928. $psum += $v ['price'];
  12929. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12930. $falg = false;
  12931. break;
  12932. }
  12933. }
  12934. }
  12935. if ($falg)
  12936. $html .= '<td class="taR">-</td>';
  12937. }
  12938. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12939. if (! empty ( $psum ))
  12940. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12941. else
  12942. $psum = '<td class="colGreen taR">-</td>';
  12943. $receiptL ['其他'] = $psum . $html;
  12944. /* ------------------------------------- */
  12945. $html = "";
  12946. $psum = 0;
  12947. foreach ( $receiptCollectList as $v ) {
  12948. if ($v ['itemCategory'] == '报销金额调整') {
  12949. if (! empty ( $v ['price'] )) {
  12950. $psum += $v ['price'];
  12951. }
  12952. }
  12953. }
  12954. $s1 += $psum;
  12955. if (! empty ( $psum ))
  12956. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12957. else
  12958. $psum = '<td class="taR colOrange">-</td>';
  12959. $receiptL ['报销金额调整'] = $psum . $html;
  12960. } else {
  12961. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12962. foreach ( $aiList[$this->AGENCY] as $va ) {
  12963. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12964. }
  12965. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12966. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12967. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12968. }
  12969. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12970. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12971. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12972. }
  12973. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12974. foreach ( $aiList[$this->TRAIN] as $va ) {
  12975. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12976. }
  12977. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12978. foreach ( $aiList[$this->OTHER] as $va ) {
  12979. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12980. }
  12981. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12982. }
  12983. $monthStaffPrice = $receiptDetail->find ( array (
  12984. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12985. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12986. 'groupby' => 'Month(pastDate)',
  12987. 'asArray' => true
  12988. ) );
  12989. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12990. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12991. $m1 += $monthStaffPrice [0] ['price'];
  12992. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12993. } else
  12994. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12995. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12996. $list [$value ['username']] = $receiptL;
  12997. }
  12998. }
  12999. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  13000. foreach ( $aiList[$this->AGENCY] as $va ) {
  13001. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  13002. $subtotal[$this->AGENCY][$va['name']]=0;
  13003. }
  13004. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  13005. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13006. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  13007. $subtotal[$this->TRAVEL][$va['name']]=0;
  13008. }
  13009. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  13010. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13011. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  13012. $subtotal[$this->INTTRAIN][$va['name']]=0;
  13013. }
  13014. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  13015. foreach ( $aiList[$this->TRAIN] as $va ) {
  13016. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  13017. $subtotal[$this->TRAIN][$va['name']]=0;
  13018. }
  13019. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  13020. foreach ( $aiList[$this->OTHER] as $va ) {
  13021. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  13022. $subtotal[$this->OTHER][$va['name']]=0;
  13023. }
  13024. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13025. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13026. $receiptL ['usernameEn'] =false;
  13027. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13028. }
  13029. $data ['list'] = $list;
  13030. // print_r($list);
  13031. $receiptCollectList = $receiptDetail->find ( array (
  13032. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13033. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13034. 'groupby' => 'item,Month(pastDate),itemCategory',
  13035. 'asArray' => true
  13036. ) );
  13037. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13038. // statistics html
  13039. $stList = $statistics->getOne ( array (
  13040. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13041. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13042. 'groupby' => 'Month(date)',
  13043. 'asArray' => true
  13044. ) );
  13045. if (empty ( $stList ))
  13046. $stList = array (
  13047. 'rePrice' => 0,
  13048. 'agPrice' => 0
  13049. );
  13050. $data ['stList'] = array (
  13051. 'rePrice' => $stList ['rePrice'],
  13052. 'agPrice' => $stList ['agPrice'],
  13053. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13054. );
  13055. $monthHtml = "";
  13056. for($i = 1; $i <= 12; $i ++) {
  13057. if ($i == $month)
  13058. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13059. else
  13060. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13061. }
  13062. $data ['monthHtml'] = $monthHtml;
  13063. $data ['year'] = $year;
  13064. $data ['month'] = $month;
  13065. $data ['nature'] = $nature;
  13066. $data ['aiList'] = $aiList;
  13067. $data ['memu'] = "receipt";
  13068. $data ['staff'] = $this->staff;
  13069. $data ['receiptMemu'] = 'companyCategoryCollect';
  13070. $data ['verifyId'] = $this->verifyId;
  13071. $data ['executeId'] = $this->executeId;
  13072. $this->render ( "/admin/staffCollectMonthDetail", $data );
  13073. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13074. }
  13075. function staffCollectMonthDetail2() {
  13076. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13077. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13078. if (! $year)
  13079. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13080. if (! $month)
  13081. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13082. Doo::loadModel ( 'staff' );
  13083. $staff = new staff ();
  13084. Doo::loadModel ( "receiptDetail" );
  13085. $receiptDetail = new receiptDetail ();
  13086. Doo::loadModel ( 'accountItem' );
  13087. $accountItem = new accountItem ();
  13088. Doo::loadModel ( 'statistics' );
  13089. $statistics = new statistics ();
  13090. Doo::loadModel ( 'L_category' );
  13091. $lCategory = new L_category ();
  13092. $staffList = $staff->find ( array (
  13093. 'where' => 'username!="admin"',
  13094. 'asArray' => true
  13095. ) );
  13096. $categoryList = $staff->find ( array (
  13097. 'select' => 'COUNT(*) as count,cid,category',
  13098. 'where' => 'username !="admin"',
  13099. 'groupby' => 'cid',
  13100. 'asArray' => true
  13101. ) );
  13102. $list = array ();
  13103. foreach ( $categoryList as $vlu ) {
  13104. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  13105. $r1 = 0;
  13106. $r2 = 0;
  13107. $r3 = 0;
  13108. $r4 = 0;
  13109. $r5 = 0;
  13110. $r6 = 0;
  13111. $r7 = 0;
  13112. $r8 = 0;
  13113. $r9 = 0;
  13114. $r10 = 0;
  13115. $r11 = 0;
  13116. $r12 = 0;
  13117. $r13 = 0;
  13118. $r14 = 0;
  13119. $r15 = 0;
  13120. $c1 = 0;
  13121. $c2 = 0;
  13122. $c3 = 0;
  13123. $c4 = 0;
  13124. $c5 = 0;
  13125. $c6 = 0;
  13126. $p1 = 0;
  13127. $p2 = 0;
  13128. $p3 = 0;
  13129. $p4 = 0;
  13130. $p5 = 0;
  13131. $p6 = 0;
  13132. $p7 = 0;
  13133. $p8 = 0;
  13134. $p9 = 0;
  13135. $t1 = 0;
  13136. $t2 = 0;
  13137. $t3 = 0;
  13138. $t4 = 0;
  13139. $t5 = 0;
  13140. $s1 = 0;
  13141. $m1 = 0;
  13142. foreach ( $staffList as $value ) {
  13143. if ($vlu ['cid'] == $value ['cid']) {
  13144. $receiptCollectList = $receiptDetail->find ( array (
  13145. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13146. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13147. 'groupby' => 'item,Month(date),itemCategory',
  13148. 'asArray' => true
  13149. ) );
  13150. if (! empty ( $receiptCollectList )) {
  13151. $receiptL = array (
  13152. '日常相关费用' => array (),
  13153. '差旅相关费用' => array (),
  13154. '培训班费用' => array (),
  13155. '其他' => array ()
  13156. );
  13157. $html = "";
  13158. $psum = 0;
  13159. $item = array (
  13160. '市内交通费',
  13161. '市内出租费',
  13162. '办事处房租',
  13163. '电话费',
  13164. '水费',
  13165. '电费',
  13166. '办公费用',
  13167. '邮寄费',
  13168. '其他费用',
  13169. '车辆费用',
  13170. '广告费',
  13171. '团队建设费',
  13172. '物业管理费',
  13173. '宽带费'
  13174. );
  13175. foreach ( $item as $va ) {
  13176. $falg = true;
  13177. foreach ( $receiptCollectList as $v ) {
  13178. if ($v ['itemCategory'] == '日常相关费用') {
  13179. if ($v ['item'] == $va) {
  13180. if ($va == '市内交通费')
  13181. $r1 += $v ['price'];
  13182. if ($va == '市内出租费')
  13183. $r2 += $v ['price'];
  13184. if ($va == '办事处房租')
  13185. $r3 += $v ['price'];
  13186. if ($va == '电话费')
  13187. $r4 += $v ['price'];
  13188. if ($va == '水费')
  13189. $r5 += $v ['price'];
  13190. if ($va == '电费')
  13191. $r6 += $v ['price'];
  13192. if ($va == '办公费用')
  13193. $r7 += $v ['price'];
  13194. if ($va == '邮寄费')
  13195. $r8 += $v ['price'];
  13196. if ($va == '其他费用')
  13197. $r9 += $v ['price'];
  13198. if ($va == '车辆费用')
  13199. $r10 += $v ['price'];
  13200. if ($va == '广告费')
  13201. $r11 += $v ['price'];
  13202. if ($va == '团队建设费')
  13203. $r13 += $v ['price'];
  13204. if ($va == '物业管理费')
  13205. $r14 += $v ['price'];
  13206. if ($va == '宽带费')
  13207. $r15 += $v ['price'];
  13208. $psum += $v ['price'];
  13209. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13210. $falg = false;
  13211. break;
  13212. }
  13213. }
  13214. }
  13215. if ($falg)
  13216. $html .= '<td class="taR">-</td>';
  13217. }
  13218. $r12 += $psum;
  13219. if (! empty ( $psum ))
  13220. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13221. else
  13222. $psum = '<td class="colGreen taR">-</td>';
  13223. $receiptL ['日常相关费用'] = $psum . $html;
  13224. /* ----------------------------------- */
  13225. $html = "";
  13226. $psum = 0;
  13227. $item = array (
  13228. '往来交通费',
  13229. '市内交通费',
  13230. '出差住宿费',
  13231. '出差补助',
  13232. '其他费用'
  13233. );
  13234. foreach ( $item as $va ) {
  13235. $falg = true;
  13236. foreach ( $receiptCollectList as $v ) {
  13237. if ($v ['itemCategory'] == '差旅相关费用') {
  13238. if ($v ['item'] == $va) {
  13239. if ($va == '往来交通费')
  13240. $c1 += $v ['price'];
  13241. if ($va == '市内交通费')
  13242. $c2 += $v ['price'];
  13243. if ($va == '出差住宿费')
  13244. $c3 += $v ['price'];
  13245. if ($va == '出差补助')
  13246. $c4 += $v ['price'];
  13247. if ($va == '其他费用')
  13248. $c5 += $v ['price'];
  13249. $psum += $v ['price'];
  13250. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13251. $falg = false;
  13252. break;
  13253. }
  13254. }
  13255. }
  13256. if ($falg)
  13257. $html .= '<td class="taR">-</td>';
  13258. }
  13259. $c6 += $psum;
  13260. if (! empty ( $psum ))
  13261. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13262. else
  13263. $psum = '<td class="colGreen taR">-</td>';
  13264. $receiptL ['差旅相关费用'] = $psum . $html;
  13265. /* ------------------------------------- */
  13266. $html = "";
  13267. $psum = 0;
  13268. $item = array (
  13269. '场租费',
  13270. '薪酬',
  13271. '住宿费',
  13272. '交通费',
  13273. '餐饮费',
  13274. '办公费',
  13275. '公关费',
  13276. '其他'
  13277. );
  13278. foreach ( $item as $va ) {
  13279. $falg = true;
  13280. foreach ( $receiptCollectList as $v ) {
  13281. if ($v ['itemCategory'] == '培训班费用') {
  13282. if ($v ['item'] == $va) {
  13283. if ($va == '场租费')
  13284. $p1 += $v ['price'];
  13285. if ($va == '薪酬')
  13286. $p2 += $v ['price'];
  13287. if ($va == '住宿费')
  13288. $p3 += $v ['price'];
  13289. if ($va == '交通费')
  13290. $p4 += $v ['price'];
  13291. if ($va == '餐饮费')
  13292. $p5 += $v ['price'];
  13293. if ($va == '办公费')
  13294. $p6 += $v ['price'];
  13295. if ($va == '公关费')
  13296. $p7 += $v ['price'];
  13297. if ($va == '其他')
  13298. $p8 += $v ['price'];
  13299. $psum += $v ['price'];
  13300. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13301. $falg = false;
  13302. break;
  13303. }
  13304. }
  13305. }
  13306. if ($falg)
  13307. $html .= '<td class="taR">-</td>';
  13308. }
  13309. $p9 += $psum;
  13310. if (! empty ( $psum ))
  13311. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13312. else
  13313. $psum = '<td class="colGreen taR">-</td>';
  13314. $receiptL ['培训班费用'] = $psum . $html;
  13315. /* ------------------------------------- */
  13316. $html = "";
  13317. $psum = 0;
  13318. $item = array (
  13319. '公关费',
  13320. '广告费',
  13321. '借款',
  13322. '可自加费用'
  13323. );
  13324. foreach ( $item as $va ) {
  13325. $falg = true;
  13326. foreach ( $receiptCollectList as $v ) {
  13327. if ($v ['itemCategory'] == '其他') {
  13328. if ($v ['item'] == $va) {
  13329. if ($va == '公关费')
  13330. $t1 += $v ['price'];
  13331. if ($va == '广告费')
  13332. $t2 += $v ['price'];
  13333. if ($va == '借款')
  13334. $t3 += $v ['price'];
  13335. if ($va == '可自加费用')
  13336. $t4 += $v ['price'];
  13337. $psum += $v ['price'];
  13338. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13339. $falg = false;
  13340. break;
  13341. }
  13342. }
  13343. }
  13344. if ($falg)
  13345. $html .= '<td class="taR">-</td>';
  13346. }
  13347. $t5 += $psum;
  13348. if (! empty ( $psum ))
  13349. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13350. else
  13351. $psum = '<td class="colGreen taR">-</td>';
  13352. $receiptL ['其他'] = $psum . $html;
  13353. /* ------------------------------------- */
  13354. $html = "";
  13355. $psum = 0;
  13356. foreach ( $receiptCollectList as $v ) {
  13357. if ($v ['itemCategory'] == '报销金额调整') {
  13358. if (! empty ( $v ['price'] )) {
  13359. $psum += $v ['price'];
  13360. }
  13361. }
  13362. }
  13363. $s1 += $psum;
  13364. if (! empty ( $psum ))
  13365. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  13366. else
  13367. $psum = '<td class="taR colOrange">-</td>';
  13368. $receiptL ['报销金额调整'] = $psum . $html;
  13369. } else {
  13370. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13371. <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>';
  13372. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  13373. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13374. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13375. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13376. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13377. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13378. }
  13379. $monthStaffPrice = $receiptDetail->find ( array (
  13380. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13381. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13382. 'asArray' => true
  13383. ) );
  13384. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  13385. $m1 += $monthStaffPrice [0] ['price'];
  13386. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13387. } else
  13388. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13389. $list [$value ['username']] = $receiptL;
  13390. }
  13391. }
  13392. $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>
  13393. <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>
  13394. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  13395. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  13396. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  13397. $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>
  13398. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  13399. $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>';
  13400. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13401. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13402. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13403. }
  13404. $data ['list'] = $list;
  13405. $receiptCollectList = $receiptDetail->find ( array (
  13406. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13407. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13408. 'groupby' => 'item,Month(date),itemCategory',
  13409. 'asArray' => true
  13410. ) );
  13411. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  13412. // statistics html
  13413. $stList = $statistics->getOne ( array (
  13414. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13415. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13416. 'groupby' => 'Month(date)',
  13417. 'asArray' => true
  13418. ) );
  13419. if (empty ( $stList ))
  13420. $stList = array (
  13421. 'rePrice' => 0,
  13422. 'agPrice' => 0
  13423. );
  13424. $data ['stList'] = array (
  13425. 'rePrice' => $stList ['rePrice'],
  13426. 'agPrice' => $stList ['agPrice'],
  13427. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13428. );
  13429. $monthHtml = "";
  13430. for($i = 1; $i <= 12; $i ++) {
  13431. if ($i == $month)
  13432. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13433. else
  13434. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13435. }
  13436. $data ['monthHtml'] = $monthHtml;
  13437. $data ['year'] = $year;
  13438. $data ['month'] = $month;
  13439. $data ['memu'] = "receipt";
  13440. $data ['staff'] = $this->staff;
  13441. $data ['receiptMemu'] = 'companyCategoryCollect';
  13442. $data ['verifyId'] = $this->verifyId;
  13443. $data ['executeId'] = $this->executeId;
  13444. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  13445. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13446. }
  13447. /**
  13448. * 用户报销单列表
  13449. */
  13450. function receiptStatisticsStaffDetail() {
  13451. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13452. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13453. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13454. Doo::loadModel ( "receipt" );
  13455. $receipt = new receipt ();
  13456. Doo::loadModel ( "receiptDetail" );
  13457. $receiptDetail = new receiptDetail ();
  13458. Doo::loadModel ( 'staff' );
  13459. $staff = new staff ();
  13460. Doo::loadModel ( 'accountItem' );
  13461. $accountItem = new accountItem ();
  13462. Doo::loadModel ( 'statistics' );
  13463. $statistics = new statistics ();
  13464. if (! empty ( $username )) {
  13465. $username = addslashes ( urldecode ( $username ) );
  13466. $staffDetail = $staff->getStaffByName ( $username );
  13467. if (empty ( $staffDetail ))
  13468. die ( 'illegal request' );
  13469. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  13470. $itemList = $accountItem->getAccountItem ();
  13471. $itemHtml = '';
  13472. $categoryHtml = '';
  13473. $itemKeyList = array_keys ( $itemList );
  13474. $revisePrice = 0;
  13475. // 报销单内容详情
  13476. foreach ( $list as $key => $value ) {
  13477. $accountItemList = json_decode ( $value ['accountItem'], true );
  13478. $list [$key] ['accountItemList'] = $accountItemList;
  13479. $receiptItemHtml = '';
  13480. foreach ( $itemKeyList as $v ) {
  13481. if ($v == '日常相关费用')
  13482. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  13483. elseif ($v == '差旅相关费用')
  13484. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  13485. elseif ($v == '培训班费用')
  13486. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  13487. elseif ($v == '内部培训费用'){
  13488. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  13489. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  13490. }else{
  13491. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  13492. }
  13493. }elseif ($v == '其他')
  13494. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  13495. foreach ( $itemList [$v] as $ke => $va ) {
  13496. $falg = true;
  13497. if (! empty ( $accountItemList [$v] )) {
  13498. foreach ( $accountItemList [$v] as $ve ) {
  13499. if ($va ['name'] == $ve ['name']) {
  13500. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  13501. $falg = false;
  13502. break;
  13503. }
  13504. }
  13505. }
  13506. if ($falg)
  13507. $receiptItemHtml .= '<td class="taR"></td>';
  13508. }
  13509. }
  13510. // 金额调整和费用查看
  13511. $revisePrice += $value ['revisePrice'];
  13512. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  13513. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  13514. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  13515. }
  13516. // 报销单合计
  13517. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  13518. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  13519. $receiptTotalHtml = '';
  13520. // 报销单项目抬头
  13521. foreach ( $itemKeyList as $value ) {
  13522. $count = count ( $itemList [$value] ) + 1;
  13523. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13524. $categoryHtml .= '<th class="taC">合计</th>';
  13525. $sumfalg=true;
  13526. foreach ( $rtl as $rtlValue ) {
  13527. if ($rtlValue ['itemCategory'] == $value) {
  13528. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13529. $sumfalg=false;
  13530. break;
  13531. }
  13532. }
  13533. if ($sumfalg)
  13534. $receiptTotalHtml .= '<th></th>';
  13535. foreach ( $itemList [$value] as $k => $v ) {
  13536. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13537. // 合计
  13538. $falg = true;
  13539. foreach ( $receiptTotalList as $ve ) {
  13540. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13541. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13542. $falg = false;
  13543. break;
  13544. }
  13545. }
  13546. if ($falg)
  13547. $receiptTotalHtml .= '<th></th>';
  13548. }
  13549. }
  13550. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13551. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13552. if (empty ( $stList ))
  13553. $stList = array (
  13554. 'rePrice' => 0,
  13555. 'agPrice' => 0
  13556. );
  13557. $data ['stList'] = array (
  13558. 'rePrice' => $stList ['rePrice'],
  13559. 'agPrice' => $stList ['agPrice'],
  13560. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13561. );
  13562. $monthHtml = "";
  13563. for($i = 1; $i <= 12; $i ++) {
  13564. if ($i == $month)
  13565. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13566. else
  13567. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13568. }
  13569. $data ['username'] = urlencode ( $username );
  13570. $data ['usernameEN'] = $username;
  13571. $data ['monthHtml'] = $monthHtml;
  13572. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13573. $data ['list'] = $list;
  13574. $data ['categoryHtml'] = $categoryHtml;
  13575. $data ['itemHtml'] = $itemHtml;
  13576. $data ['itemList'] = $itemList;
  13577. $data ['year'] = $year;
  13578. $data ['month'] = $month;
  13579. $data ['memu'] = "receipt";
  13580. $data ['staff'] = $this->staff;
  13581. $data ['receiptMemu'] = 'companyCategoryCollect';
  13582. $data ['verifyId'] = $this->verifyId;
  13583. $data ['executeId'] = $this->executeId;
  13584. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13585. }
  13586. die ( 'illegal request' );
  13587. }
  13588. function companyMonthCollectDetail() {
  13589. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13590. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13591. if (! $year)
  13592. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13593. if (! $month)
  13594. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13595. Doo::loadModel ( 'staff' );
  13596. $staff = new staff ();
  13597. Doo::loadModel ( "receiptDetail" );
  13598. $receiptDetail = new receiptDetail ();
  13599. Doo::loadModel ( 'accountItem' );
  13600. $accountItem = new accountItem ();
  13601. Doo::loadModel ( 'statistics' );
  13602. $statistics = new statistics ();
  13603. Doo::loadModel ( 'L_category' );
  13604. $lCategory = new L_category ();
  13605. $staffList = $staff->find ( array (
  13606. 'where' => 'username!="admin"',
  13607. 'asArray' => true
  13608. ) );
  13609. $categoryList = $lCategory->find ( array (
  13610. 'asArray' => true
  13611. ) );
  13612. $aiList=$accountItem->getAccountItem();
  13613. $list = array ();
  13614. foreach ( $categoryList as $value ) {
  13615. $receiptCollectList = $receiptDetail->find ( array (
  13616. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13617. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13618. 'groupby' => 'item,Month(pastDate),itemCategory',
  13619. 'asArray' => true
  13620. ) );
  13621. if (! empty ( $receiptCollectList )) {
  13622. $receiptL = array (
  13623. '日常相关费用' => array (),
  13624. '差旅相关费用' => array (),
  13625. '内部培训费用' => array (),
  13626. '培训班费用' => array (),
  13627. '其他' => array ()
  13628. );
  13629. $html = "";
  13630. $psum = 0;
  13631. foreach ( $aiList[$this->AGENCY] as $va ) {
  13632. $falg = true;
  13633. foreach ( $receiptCollectList as $v ) {
  13634. if ($v ['itemCategory'] == $this->AGENCY) {
  13635. if ($v ['item'] == $va['name']) {
  13636. $psum += $v ['price'];
  13637. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13638. $falg = false;
  13639. break;
  13640. }
  13641. }
  13642. }
  13643. if ($falg)
  13644. $html .= '<td class="taR">-</td>';
  13645. }
  13646. if (! empty ( $psum ))
  13647. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13648. else
  13649. $psum = '<td class="colGreen taR">-</td>';
  13650. $receiptL [$this->AGENCY] = $psum . $html;
  13651. /* ----------------------------------- */
  13652. $html = "";
  13653. $psum = 0;
  13654. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13655. $falg = true;
  13656. foreach ( $receiptCollectList as $v ) {
  13657. if ($v ['itemCategory'] == $this->TRAVEL) {
  13658. if ($v ['item'] == $va['name']) {
  13659. $psum += $v ['price'];
  13660. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13661. $falg = false;
  13662. break;
  13663. }
  13664. }
  13665. }
  13666. if ($falg)
  13667. $html .= '<td class="taR">-</td>';
  13668. }
  13669. if (! empty ( $psum ))
  13670. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13671. else
  13672. $psum = '<td class="colGreen taR">-</td>';
  13673. $receiptL [$this->TRAVEL] = $psum . $html;
  13674. /* ------------------------------------- */
  13675. $html = "";
  13676. $psum = 0;
  13677. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13678. $falg = true;
  13679. foreach ( $receiptCollectList as $v ) {
  13680. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13681. if ($v ['item'] == $va['name']) {
  13682. $psum += $v ['price'];
  13683. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13684. $falg = false;
  13685. break;
  13686. }
  13687. }
  13688. }
  13689. if ($falg)
  13690. $html .= '<td class="taR">-</td>';
  13691. }
  13692. if (! empty ( $psum ))
  13693. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13694. else
  13695. $psum = '<td class="colGreen taR">-</td>';
  13696. $receiptL [$this->INTTRAIN] = $psum . $html;
  13697. /* ------------------------------------- */
  13698. $html = "";
  13699. $psum = 0;
  13700. foreach ( $aiList[$this->TRAIN] as $va ) {
  13701. $falg = true;
  13702. foreach ( $receiptCollectList as $v ) {
  13703. if ($v ['itemCategory'] == $this->TRAIN) {
  13704. if ($v ['item'] == $va['name']) {
  13705. $psum += $v ['price'];
  13706. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13707. $falg = false;
  13708. break;
  13709. }
  13710. }
  13711. }
  13712. if ($falg)
  13713. $html .= '<td class="taR">-</td>';
  13714. }
  13715. if (! empty ( $psum ))
  13716. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13717. else
  13718. $psum = '<td class="colGreen taR">-</td>';
  13719. $receiptL [$this->TRAIN] = $psum . $html;
  13720. /* ------------------------------------- */
  13721. $html = "";
  13722. $psum = 0;
  13723. foreach ( $aiList[$this->OTHER] as $va ) {
  13724. $falg = true;
  13725. foreach ( $receiptCollectList as $v ) {
  13726. if ($v ['itemCategory'] == $this->OTHER) {
  13727. if ($v ['item'] == $va['name']) {
  13728. $psum += $v ['price'];
  13729. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13730. $falg = false;
  13731. break;
  13732. }
  13733. }
  13734. }
  13735. if ($falg)
  13736. $html .= '<td class="taR">-</td>';
  13737. }
  13738. if (! empty ( $psum ))
  13739. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13740. else
  13741. $psum = '<td class="colGreen taR">-</td>';
  13742. $receiptL [$this->OTHER] = $psum . $html;
  13743. /* ------------------------------------- */
  13744. $html = "";
  13745. $psum = 0;
  13746. foreach ( $receiptCollectList as $v ) {
  13747. if ($v ['itemCategory'] == '报销金额调整') {
  13748. if (! empty ( $v ['price'] ))
  13749. $psum += $v ['price'];
  13750. }
  13751. }
  13752. if (! empty ( $psum ))
  13753. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13754. else
  13755. $psum = '<td class="taR colOrange">-</td>';
  13756. $receiptL ['报销金额调整'] = $psum . $html;
  13757. } else {
  13758. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13759. foreach ( $aiList[$this->AGENCY] as $va ) {
  13760. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13761. }
  13762. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13763. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13764. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13765. }
  13766. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13767. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13768. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13769. }
  13770. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13771. foreach ( $aiList[$this->TRAIN] as $va ) {
  13772. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13773. }
  13774. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13775. foreach ( $aiList[$this->OTHER] as $va ) {
  13776. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13777. }
  13778. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13779. }
  13780. $monthStaffPrice = $receiptDetail->find ( array (
  13781. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13782. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13783. 'asArray' => true
  13784. ) );
  13785. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13786. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13787. else
  13788. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13789. $list [$value ['title']] = $receiptL;
  13790. }
  13791. $data ['list'] = $list;
  13792. $receiptCollectList = $receiptDetail->find ( array (
  13793. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13794. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13795. 'groupby' => 'item,Month(pastDate),itemCategory',
  13796. 'asArray' => true
  13797. ) );
  13798. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13799. //print_r($data['monthPriceHtml']);
  13800. // foreach ($data['monthPriceHtml'] as $value){
  13801. // echo $value;
  13802. // }
  13803. // die;
  13804. // statistics html
  13805. $stList = $statistics->getOne ( array (
  13806. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13807. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13808. 'groupby' => 'Month(date)',
  13809. 'asArray' => true
  13810. ) );
  13811. if (empty ( $stList ))
  13812. $stList = array (
  13813. 'rePrice' => 0,
  13814. 'agPrice' => 0
  13815. );
  13816. $data ['stList'] = array (
  13817. 'rePrice' => $stList ['rePrice'],
  13818. 'agPrice' => $stList ['agPrice'],
  13819. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13820. );
  13821. $monthHtml = "";
  13822. for($i = 1; $i <= 12; $i ++) {
  13823. if ($i == $month)
  13824. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13825. else
  13826. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13827. }
  13828. $data ['aiList'] = $aiList;
  13829. $dateHtml = "";
  13830. $now = date ( "Y" );
  13831. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  13832. if ($YEARD <= $now) {
  13833. $dateHtml .= '<option ';
  13834. if ($year == $YEARD) {
  13835. $dateHtml .= 'selected ';
  13836. }
  13837. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  13838. }
  13839. }
  13840. $data ['dateHtml'] = $dateHtml;
  13841. $data ['monthHtml'] = $monthHtml;
  13842. $data ['year'] = $year;
  13843. $data ['month'] = $month;
  13844. $data ['memu'] = "receipt";
  13845. $data ['staff'] = $this->staff;
  13846. $data ['receiptMemu'] = 'companyCategoryCollect';
  13847. $data ['verifyId'] = $this->verifyId;
  13848. $data ['executeId'] = $this->executeId;
  13849. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13850. }
  13851. function staffCollectDetail() {
  13852. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13853. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13854. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13855. if (! $staffname) {
  13856. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13857. $staffname = urldecode ( $staffname );
  13858. }
  13859. Doo::loadModel ( 'staff' );
  13860. $staff = new staff ();
  13861. Doo::loadModel ( "receiptDetail" );
  13862. $receiptDetail = new receiptDetail ();
  13863. Doo::loadModel ( 'accountItem' );
  13864. $accountItem = new accountItem ();
  13865. Doo::loadModel ( 'statistics' );
  13866. $statistics = new statistics ();
  13867. Doo::loadModel ( 'L_category' );
  13868. $lCategory = new L_category ();
  13869. Doo::loadModel ( "receiptAuthorityManage" );
  13870. $receiptAuthorityManage = new receiptAuthorityManage ();
  13871. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13872. $cidList = array ();
  13873. foreach ( $imcStaff as $key => $value ) {
  13874. array_push ( $cidList, $value ['cid'] );
  13875. }
  13876. $cidString = implode ( ',', $cidList );
  13877. $staffList = $staff->find ( array (
  13878. 'where' => ' cid in (' . $cidString . ')',
  13879. 'asArray' => true
  13880. ) );
  13881. $stHtml = '';
  13882. $stTitle = "";
  13883. $staffId = 0;
  13884. $cid = 0;
  13885. $ocid = 0;
  13886. foreach ( $staffList as $value ) {
  13887. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13888. $stTitle = $value ['category'] . '-' . $value ['username'];
  13889. $staffId = $value ['sid'];
  13890. $cid = $value ['cid'];
  13891. $ocid = $value ['cid'];
  13892. if (! empty ( $value ['othercid'] ))
  13893. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13894. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13895. } elseif ($value ['username'] != 'admin')
  13896. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13897. }
  13898. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13899. 'where' => 'cid in(' . $cid . ')',
  13900. 'asArray' => true
  13901. ) );
  13902. if (empty ( $pcid ))
  13903. $pcid = $ocid;
  13904. $data ['ocid'] = $pcid;
  13905. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13906. $this->showCache ( $path );
  13907. //
  13908. $receiptCollectList = $receiptDetail->find ( array (
  13909. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13910. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13911. 'groupby' => 'item,Month(pastDate),itemCategory',
  13912. 'asArray' => true
  13913. ) );
  13914. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13915. // print_r($receiptCollectList);
  13916. $accountList = $accountItem->find ( array (
  13917. 'asArray' => true
  13918. ) );
  13919. // create CollectDetail HTML
  13920. $collectHtml = array ();
  13921. foreach ( $accountList as $key => $value ) {
  13922. $html = "";
  13923. $asum = 0;
  13924. for($i = 1; $i <= 12; $i ++) {
  13925. $falg = true;
  13926. foreach ( $receiptCollectList as $v ) {
  13927. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13928. if ($v ['item'] == '可自加费用') {
  13929. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13930. }
  13931. $asum += $v ['price'];
  13932. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13933. $falg = false;
  13934. break;
  13935. }
  13936. }
  13937. if ($falg)
  13938. $html .= '<td class="taR">-</td>';
  13939. }
  13940. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13941. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13942. }
  13943. $data ['collectHtml'] = $collectHtml;
  13944. // print_r($collectHtml);
  13945. // create Adjustment price html
  13946. $receiptCollectList = $receiptDetail->find ( array (
  13947. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13948. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13949. 'groupby' => 'itemCategory,Month(pastDate)',
  13950. 'asArray' => true
  13951. ) );
  13952. $adjustment = array ();
  13953. $collectArray = array (
  13954. '日常相关费用' => array (),
  13955. '差旅相关费用' => array (),
  13956. '培训班费用' => array (),
  13957. '内部培训费用'=>array(),
  13958. '其他' => array ()
  13959. );
  13960. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  13961. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  13962. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  13963. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  13964. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  13965. array_push ( $collectArray ['培训班费用'], $collectHtml );
  13966. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  13967. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  13968. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13969. array_push ( $collectArray ['其他'], $collectHtml );
  13970. $data ['collectArray'] = $collectArray;
  13971. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13972. array_push ( $adjustment, $collectHtml );
  13973. $data ['adjustment'] = $adjustment;
  13974. // total price html
  13975. $collectHtml = "";
  13976. $total = 0;
  13977. for($i = 1; $i <= 12; $i ++) {
  13978. $sumPrice = 0;
  13979. foreach ( $receiptCollectList as $key => $value ) {
  13980. if ($value ['month'] == $i) {
  13981. $sumPrice += $value ['price'];
  13982. }
  13983. }
  13984. if ($sumPrice == 0)
  13985. $collectHtml .= '<td class="taR">-</td>';
  13986. else
  13987. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13988. $total += $sumPrice;
  13989. }
  13990. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13991. // statistics html
  13992. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13993. if (empty ( $stList ))
  13994. $stList = array (
  13995. 'rePrice' => 0,
  13996. 'agPrice' => 0
  13997. );
  13998. $data ['stList'] = array (
  13999. 'rePrice' => $stList ['rePrice'],
  14000. 'agPrice' => $stList ['agPrice'],
  14001. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  14002. );
  14003. $data ['totalPrice'] = $collectHtml;
  14004. $data ['totalYear'] = $total;
  14005. $data ['stHtml'] = $stHtml;
  14006. $data ['year'] = $year;
  14007. $data ['stTitle'] = $stTitle;
  14008. $data ['staffname'] = urlencode ( $staffname );
  14009. $data ['memu'] = "receipt";
  14010. $data ['staff'] = $this->staff;
  14011. $data ['receiptMemu'] = 'companyCategoryCollect';
  14012. $data ['verifyId'] = $this->verifyId;
  14013. $data ['executeId'] = $this->executeId;
  14014. if ($year < date ( "Y" )) {
  14015. Doo::loadModel ( 'receipt' );
  14016. $receipt = new receipt ();
  14017. $receiptList = $receipt->find ( array (
  14018. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  14019. 'asArray' => true
  14020. ) );
  14021. if (empty ( $receiptList )) { // generated files
  14022. ob_start ();
  14023. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  14024. $this->cacheFile ( $path );
  14025. die ();
  14026. }
  14027. }
  14028. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  14029. }
  14030. function BUGFLAG() {
  14031. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  14032. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  14033. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  14034. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  14035. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  14036. if (empty ( $status ))
  14037. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  14038. $page_size = 12;
  14039. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  14040. $vidList = array ();
  14041. $button = 0;
  14042. Doo::loadModel ( 'verify' );
  14043. $verify = new verify ();
  14044. Doo::loadModel ( 'receipt' );
  14045. $receipt = new receipt ();
  14046. Doo::loadModel ( 'staff' );
  14047. $staff = new staff ();
  14048. Doo::loadModel ( 'L_category' );
  14049. $Lcategory = new L_category ();
  14050. $dateCondition = " and Year(date) =" . $year;
  14051. if (! empty ( $month ))
  14052. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  14053. $categoryList = $Lcategory->find ( array (
  14054. 'asArray' => true
  14055. ) );
  14056. $staffList = $staff->find ( array (
  14057. 'where' => 'cid=' . $cid,
  14058. 'asArray' => true
  14059. ) );
  14060. $cateCondition = "";
  14061. $staffCondition = "";
  14062. $approvalCondition = "";
  14063. if (! empty ( $cid ))
  14064. $cateCondition = ' and cid=' . $cid;
  14065. if (! empty ( $sid )) {
  14066. $staffCondition = ' and staff=' . $sid;
  14067. $cateCondition = "";
  14068. }
  14069. $approvalCondition = " and status=" . $status;
  14070. if ($status == 2) {
  14071. // 查找角色审批人
  14072. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  14073. }
  14074. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  14075. $approvalCondition = ' and status=2 ';
  14076. }
  14077. if ($status == 1) {
  14078. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  14079. }
  14080. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  14081. $pageinfo ['page'] = array (
  14082. 'previous' => ''
  14083. );
  14084. if ($status == 0) {
  14085. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  14086. $receiptList = $receipt->find ( array (
  14087. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  14088. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  14089. 'desc' => 'rid',
  14090. 'asArray' => true
  14091. ) );
  14092. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  14093. } else
  14094. $receiptList = $receipt->find ( array (
  14095. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  14096. 'desc' => 'rid',
  14097. 'asArray' => true
  14098. ) );
  14099. $rLRes = $receipt->find ( array (
  14100. '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,
  14101. 'desc' => 'rid',
  14102. 'asArray' => true
  14103. ) );
  14104. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  14105. // print_r($pageinfo);
  14106. $Locate = 0;
  14107. foreach ( $receiptList as $key => $value ) {
  14108. $receiptList [$key] ['Locate'] = $Locate;
  14109. $Locate ++;
  14110. $receiptList [$key] ['reviseDetail'] = array ();
  14111. if (! empty ( $value ['reviseDetail'] ))
  14112. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  14113. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  14114. $categoryDetil = $Lcategory->getOne ( array (
  14115. 'where' => 'cid=' . $value ['cid'],
  14116. 'asArray' => true
  14117. ) );
  14118. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  14119. $verifyList = $verify->getOne ( array (
  14120. 'where' => 'vid=' . $value ['verify'],
  14121. 'asArray' => true
  14122. ) );
  14123. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  14124. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  14125. foreach ( $verifyList as $k => $v ) {
  14126. // init verifyStaff
  14127. $verifyList [$k] ['date'] = "";
  14128. $verifyList [$k] ['opinion'] = "";
  14129. $verifyList [$k] ['status'] = "";
  14130. if (empty ( $verifyStaff )) {
  14131. $verifyList [$k] ['date'] = "";
  14132. $verifyList [$k] ['opinion'] = "";
  14133. if ($v [0] == $this->staff [0] ['sid']) {
  14134. $verifyList [$k] ['status'] = 4;
  14135. $button = 4;
  14136. }
  14137. } else {
  14138. $flag = true;
  14139. foreach ( $verifyStaff as $m => $u ) {
  14140. if ($v [0] == $m) {
  14141. $verifyList [$k] ['date'] = $u ['date'];
  14142. $verifyList [$k] ['opinion'] = $u ['opinion'];
  14143. $verifyList [$k] ['status'] = $u ['status'];
  14144. $flag = false;
  14145. break;
  14146. }
  14147. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  14148. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  14149. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  14150. }
  14151. if ($flag) { // 检测可编辑
  14152. if ($v [0] == $this->staff [0] ['sid']) {
  14153. $verifyList [$k] ['status'] = 4;
  14154. $button = 4;
  14155. }
  14156. }
  14157. }
  14158. }
  14159. $receiptList [$key] ['verifyList'] = $verifyList;
  14160. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  14161. 'where' => 'sid=' . $value ['staff'],
  14162. 'asArray' => true
  14163. ) );
  14164. $receiptList [$key] ['button'] = $button;
  14165. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  14166. }
  14167. // print_r($receiptList);die;
  14168. // $data['verifyDetail']=$verifyDetail;
  14169. $mothHtml = "";
  14170. for($i = 1; $i <= 12; $i ++) {
  14171. if ($month == $i)
  14172. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  14173. else
  14174. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  14175. }
  14176. $data ['mothHtml'] = $mothHtml;
  14177. $data ['page'] = $pageinfo;
  14178. $data ['receiptList'] = $receiptList;
  14179. $data ['receiptApprovalCount'] = count ( $rLRes );
  14180. $data ['status'] = $status;
  14181. $data ['year'] = $year;
  14182. $data ['categoryList'] = $categoryList;
  14183. $data ['staffList'] = $staffList;
  14184. $data ['cid'] = $cid;
  14185. $data ['sid'] = $sid;
  14186. // print_r($receiptList);
  14187. $data ['memu'] = "receipt";
  14188. $data ['staff'] = $this->staff;
  14189. $data ['receiptMemu'] = 'approvalExpenses';
  14190. $data ['verifyId'] = $this->verifyId;
  14191. $data ['executeId'] = $this->executeId;
  14192. $this->render ( "/admin/FALG", $data );
  14193. }
  14194. function ajaxGetReceiptOrder() {
  14195. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  14196. if (! empty ( $receiptOrder )) {
  14197. Doo::loadModel ( 'receipt' );
  14198. $receipt = new receipt ();
  14199. Doo::loadModel ( 'staff' );
  14200. $staff = new staff ();
  14201. $receiptInfo = $receipt->getOne ( array (
  14202. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  14203. 'asArray' => true
  14204. ) );
  14205. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  14206. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  14207. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  14208. </tbody></table><table class="table table table-bordered"><tbody>';
  14209. foreach ( $verifyStaff as $key => $value ) {
  14210. $staffInfo = $staff->getOne ( array (
  14211. 'select' => 'username',
  14212. 'where' => ' sid="' . $key . '"',
  14213. 'asArray' => true
  14214. ) );
  14215. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  14216. }
  14217. $html .= '</tbody></table></div></div>';
  14218. echo json_encode ( array (
  14219. 'status' => 1,
  14220. 'receiptHtml' => $html
  14221. ) );
  14222. die ();
  14223. }
  14224. echo json_encode ( array (
  14225. 'status' => 2,
  14226. 'receiptHtml' => ''
  14227. ) );
  14228. die ();
  14229. }
  14230. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  14231. if (! empty ( $receiptCollectList )) {
  14232. $receiptL = array (
  14233. '日常相关费用' => array (),
  14234. '差旅相关费用' => array (),
  14235. '内部培训费用'=>array(),
  14236. '培训班费用' => array (),
  14237. '其他' => array ()
  14238. );
  14239. $html = "";
  14240. $psum = 0;
  14241. foreach ( $aiList[$this->AGENCY] as $value ) {
  14242. $falg = true;
  14243. foreach ( $receiptCollectList as $v ) {
  14244. if ($v ['itemCategory'] == '日常相关费用') {
  14245. if ($v ['item'] == $value['name']) {
  14246. $psum += $v ['price'];
  14247. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14248. $falg = false;
  14249. break;
  14250. }
  14251. }
  14252. }
  14253. if ($falg)
  14254. $html .= '<td class="taR">-</td>';
  14255. }
  14256. if (! empty ( $psum ))
  14257. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14258. else
  14259. $psum = '<td class="colGreen taR">-</td>';
  14260. $receiptL ['日常相关费用'] = $psum . $html;
  14261. /* ----------------------------------- */
  14262. $html = "";
  14263. $psum = 0;
  14264. foreach ( $aiList[$this->TRAVEL] as $value ) {
  14265. $falg = true;
  14266. foreach ( $receiptCollectList as $v ) {
  14267. if ($v ['itemCategory'] == '差旅相关费用') {
  14268. if ($v ['item'] == $value['name']) {
  14269. $psum += $v ['price'];
  14270. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14271. $falg = false;
  14272. break;
  14273. }
  14274. }
  14275. }
  14276. if ($falg)
  14277. $html .= '<td class="taR">-</td>';
  14278. }
  14279. if (! empty ( $psum ))
  14280. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14281. else
  14282. $psum = '<td class="colGreen taR">-</td>';
  14283. $receiptL ['差旅相关费用'] = $psum . $html;
  14284. /* ----------------------------------- */
  14285. $html = "";
  14286. $psum = 0;
  14287. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  14288. $falg = true;
  14289. foreach ( $receiptCollectList as $v ) {
  14290. if ($v ['itemCategory'] == '内部培训费用') {
  14291. if ($v ['item'] == $value['name']) {
  14292. $psum += $v ['price'];
  14293. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14294. $falg = false;
  14295. break;
  14296. }
  14297. }
  14298. }
  14299. if ($falg)
  14300. $html .= '<td class="taR">-</td>';
  14301. }
  14302. if (! empty ( $psum ))
  14303. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14304. else
  14305. $psum = '<td class="colGreen taR">-</td>';
  14306. $receiptL ['内部培训费用'] = $psum . $html;
  14307. /* ------------------------------------- */
  14308. $html = "";
  14309. $psum = 0;
  14310. foreach ( $aiList[$this->TRAIN] as $value ) {
  14311. $falg = true;
  14312. foreach ( $receiptCollectList as $v ) {
  14313. if ($v ['itemCategory'] == '培训班费用') {
  14314. if ($v ['item'] == $value['name']) {
  14315. $psum += $v ['price'];
  14316. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14317. $falg = false;
  14318. break;
  14319. }
  14320. }
  14321. }
  14322. if ($falg)
  14323. $html .= '<td class="taR">-</td>';
  14324. }
  14325. if (! empty ( $psum ))
  14326. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14327. else
  14328. $psum = '<td class="colGreen taR">-</td>';
  14329. $receiptL ['培训班费用'] = $psum . $html;
  14330. /* ------------------------------------- */
  14331. $html = "";
  14332. $psum = 0;
  14333. foreach ( $aiList[$this->OTHER] as $value ) {
  14334. $falg = true;
  14335. foreach ( $receiptCollectList as $v ) {
  14336. if ($v ['itemCategory'] == '其他') {
  14337. if ($v ['item'] == $value['name']) {
  14338. $psum += $v ['price'];
  14339. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14340. $falg = false;
  14341. break;
  14342. }
  14343. }
  14344. }
  14345. if ($falg)
  14346. $html .= '<td class="taR">-</td>';
  14347. }
  14348. if (! empty ( $psum ))
  14349. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14350. else
  14351. $psum = '<td class="colGreen taR">-</td>';
  14352. $receiptL ['其他'] = $psum . $html;
  14353. /* ------------------------------------- */
  14354. $html = "";
  14355. $psum = 0;
  14356. foreach ( $receiptCollectList as $v ) {
  14357. if ($v ['itemCategory'] == '报销金额调整') {
  14358. if (! empty ( $v ['price'] ))
  14359. $psum += $v ['price'];
  14360. }
  14361. }
  14362. if (! empty ( $psum ))
  14363. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  14364. else
  14365. $psum = '<td class="taR colOrange">-</td>';
  14366. $receiptL ['报销金额调整'] = $psum . $html;
  14367. } else {
  14368. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  14369. foreach ( $aiList[$this->AGENCY] as $va ) {
  14370. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  14371. }
  14372. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  14373. foreach ( $aiList[$this->TRAVEL] as $va ) {
  14374. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  14375. }
  14376. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  14377. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  14378. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  14379. }
  14380. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  14381. foreach ( $aiList[$this->TRAIN] as $va ) {
  14382. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  14383. }
  14384. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  14385. foreach ( $aiList[$this->OTHER] as $va ) {
  14386. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  14387. }
  14388. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  14389. }
  14390. return $receiptL;
  14391. }
  14392. function eMail() {
  14393. Doo::loadModel ( 'staff' );
  14394. $staff = new staff ();
  14395. Doo::loadModel ( 'receipt' );
  14396. $receipt = new receipt ();
  14397. Doo::loadModel ( 'L_category' );
  14398. $Lcategory = new L_category ();
  14399. Doo::loadModel ( "verify" );
  14400. $verify = new verify ();
  14401. $staffList = $staff->find ( array (
  14402. 'asArray' => true
  14403. ) );
  14404. foreach ( $staffList as $key => $value ) {
  14405. if ($value ['username'] != 'admin') {
  14406. // 提交人
  14407. $receiptList = $receipt->find ( array (
  14408. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  14409. 'asArray' => true
  14410. ) );
  14411. if (! empty ( $receiptList )) {
  14412. $html = '<br><div><style></style>
  14413. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  14414. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  14415. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14416. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  14417. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14418. <tbody><tr>
  14419. <td style="padding: 0 40px;" align="left">
  14420. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14421. </td></tr><tr>
  14422. <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>
  14423. </tr>
  14424. </tbody> </table></td> </tr> <tr><td>
  14425. <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">
  14426. <tbody> <tr><td>
  14427. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  14428. 以下报销单完成了审批,等着收款吧:</p>
  14429. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  14430. foreach ( $receiptList as $k => $v ) {
  14431. $category = $Lcategory->getOne ( array (
  14432. 'where' => 'cid=' . $v ['cid'],
  14433. 'asArray' => true
  14434. ) );
  14435. $html .= '
  14436. <tr>
  14437. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14438. <td align="left">
  14439. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  14440. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  14441. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  14442. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  14443. </tr>';
  14444. }
  14445. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  14446. <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>
  14447. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  14448. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  14449. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  14450. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14451. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14452. $receipt = new receipt ();
  14453. $receipt->notice = 1;
  14454. $receipt->update ( array (
  14455. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  14456. ) );
  14457. }
  14458. }
  14459. // 审批人
  14460. $verifyList = $verify->find ( array (
  14461. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  14462. 'asArray' => true
  14463. ) );
  14464. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  14465. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  14466. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14467. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  14468. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14469. <tbody><tr><td style="padding: 0 40px;" align="left">
  14470. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14471. </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>
  14472. </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">
  14473. <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>
  14474. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  14475. foreach ( $verifyList as $k => $v ) {
  14476. $receiptList = $receipt->find ( array (
  14477. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  14478. 'asArray' => true
  14479. ) );
  14480. foreach ( $receiptList as $r => $l ) {
  14481. $category = $Lcategory->getOne ( array (
  14482. 'where' => 'cid=' . $l ['cid'],
  14483. 'asArray' => true
  14484. ) );
  14485. $staffDetile = $staff->getOne ( array (
  14486. 'where' => 'sid=' . $l ['staff'],
  14487. 'asArray' => true
  14488. ) );
  14489. $html .= '
  14490. <tr>
  14491. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14492. <td align="left">
  14493. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  14494. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  14495. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  14496. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  14497. </tr>';
  14498. }
  14499. }
  14500. $html .= '
  14501. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  14502. <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>
  14503. </tr></tbody></table></td></tr></tbody></table></div><br>';
  14504. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  14505. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  14506. // $receipt=new receipt();
  14507. // $receipt->notice=1;
  14508. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  14509. }
  14510. }
  14511. }
  14512. }
  14513. function setWXMsg($rid, $type) {
  14514. Doo::loadModel ( "receipt" );
  14515. $receipt = new receipt ();
  14516. $receiptDetail = $receipt->getOne ( array (
  14517. 'where' => 'rid=' . $rid,
  14518. 'asArray' => true
  14519. ) );
  14520. if (! empty ( $receiptDetail )) {
  14521. Doo::loadModel ( 'staff' );
  14522. $staff = new staff ();
  14523. $staffmsg = $staff->getOne ( array (
  14524. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  14525. 'asArray' => TRUE
  14526. ) );
  14527. if (! empty ( $staffmsg ['wxid'] )) {
  14528. require_once (SITE_PATH . '/protected/class/client.php');
  14529. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  14530. $user = $staffmsg ['wxid'];
  14531. $receiptName = '';
  14532. $msg = '';
  14533. switch ($receiptDetail ['Rtype']) {
  14534. case 0 :
  14535. $receiptName = '报销';
  14536. break;
  14537. case 1 :
  14538. $receiptName = '借款';
  14539. break;
  14540. case 2 :
  14541. $receiptName = '对公汇款';
  14542. break;
  14543. }
  14544. switch ($type) {
  14545. case 1 :
  14546. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14547. break;
  14548. case 2 :
  14549. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14550. break;
  14551. case 3 :
  14552. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14553. break;
  14554. }
  14555. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14556. }
  14557. }
  14558. }
  14559. // Email发送函数
  14560. function SMail($toemail, $subject, $contents) {
  14561. Doo::loadClass ( 'class.phpmailer' );
  14562. $mail = new PHPMailer ();
  14563. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14564. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14565. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14566. $mail->Password = "cDO1GjtY1seH"; // 密码
  14567. $mail->CharSet = "UTF8";
  14568. $mail->SMTPAuth = true;
  14569. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14570. $mail->Mailer = "smtp";
  14571. $mail->Port = 25;
  14572. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14573. $mail->MsgHTML ( $contents );
  14574. $mail->AddAddress ( $toemail );
  14575. $mail->CharSet = "UTF-8";
  14576. return $mail->Send ();
  14577. }
  14578. function h5Upload() {
  14579. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14580. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14581. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14582. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14583. header ( "HTTP/1.1 500 Internal Server Error" );
  14584. echo "POST exceeded maximum allowed size.";
  14585. exit ( 0 );
  14586. }
  14587. // Settings
  14588. $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)
  14589. $upload_name = "Filedata";
  14590. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14591. $extension_whitelist = array (
  14592. "doc",
  14593. "txt",
  14594. "jpg",
  14595. "gif",
  14596. "png"
  14597. ); // Allowed file extensions
  14598. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14599. // Other variables
  14600. $MAX_FILENAME_LENGTH = 260;
  14601. $file_name = "";
  14602. $file_extension = "";
  14603. $uploadErrors = array (
  14604. 0 => "文件上传成功",
  14605. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14606. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14607. 3 => "上传的文件仅为部分文件",
  14608. 4 => "没有文件上传",
  14609. 6 => "缺少临时文件夹"
  14610. );
  14611. $nk = time ();
  14612. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14613. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14614. echo "文件无法保存.";
  14615. exit ( 0 );
  14616. }
  14617. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14618. echo json_encode ( array (
  14619. 'filename' => $file_name,
  14620. 'id' => $nk
  14621. ) );
  14622. exit ( 0 );
  14623. }
  14624. function swfupload() {
  14625. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14626. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14627. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14628. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14629. header ( "HTTP/1.1 500 Internal Server Error" );
  14630. echo "POST exceeded maximum allowed size.";
  14631. exit ( 0 );
  14632. }
  14633. // Settings
  14634. $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)
  14635. $upload_name = "Filedata";
  14636. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14637. $extension_whitelist = array (
  14638. "doc",
  14639. "txt",
  14640. "jpg",
  14641. "gif",
  14642. "png"
  14643. ); // Allowed file extensions
  14644. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14645. // Other variables
  14646. $MAX_FILENAME_LENGTH = 260;
  14647. $file_name = "";
  14648. $file_extension = "";
  14649. $uploadErrors = array (
  14650. 0 => "文件上传成功",
  14651. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14652. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14653. 3 => "上传的文件仅为部分文件",
  14654. 4 => "没有文件上传",
  14655. 6 => "缺少临时文件夹"
  14656. );
  14657. $nk = time ();
  14658. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14659. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14660. echo "文件无法保存.";
  14661. exit ( 0 );
  14662. }
  14663. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14664. echo json_encode ( array (
  14665. 'filename' => $file_name,
  14666. 'id' => $nk
  14667. ) );
  14668. exit ( 0 );
  14669. }
  14670. function _GetFileEXT($filename) {
  14671. $pics = explode ( '.', $filename );
  14672. $num = count ( $pics );
  14673. return $pics [$num - 1];
  14674. }
  14675. /**
  14676. * 获取get或者POST值
  14677. * @param string $name 属性名称
  14678. * @return fixed 值
  14679. */
  14680. function get_args($name) {
  14681. if (isset ( $_GET [$name] )) {
  14682. if (is_array ( $_GET [$name] ))
  14683. return $_GET [$name];
  14684. else
  14685. return addslashes ( $_GET [$name] );
  14686. } elseif (isset ( $_POST [$name] )) {
  14687. if (is_array ( $_POST [$name] ))
  14688. return $_POST [$name];
  14689. else
  14690. return addslashes ( $_POST [$name] );
  14691. } else
  14692. return false;
  14693. }
  14694. function num_to_rmb($num) {
  14695. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14696. $c2 = "分角元拾佰仟万拾佰仟亿";
  14697. // 精确到分后面就不要了,所以只留两个小数位
  14698. $num = round ( $num, 2 );
  14699. // 将数字转化为整数
  14700. $num = $num * 100;
  14701. if (strlen ( $num ) > 10) {
  14702. return "金额太大,请检查";
  14703. }
  14704. $i = 0;
  14705. $c = "";
  14706. while ( 1 ) {
  14707. if ($i == 0) {
  14708. // 获取最后一位数字
  14709. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14710. } else {
  14711. $n = $num % 10;
  14712. }
  14713. // 每次将最后一位数字转化为中文
  14714. $p1 = substr ( $c1, 3 * $n, 3 );
  14715. $p2 = substr ( $c2, 3 * $i, 3 );
  14716. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14717. $c = $p1 . $p2 . $c;
  14718. } else {
  14719. $c = $p1 . $c;
  14720. }
  14721. $i = $i + 1;
  14722. // 去掉数字最后一位了
  14723. $num = $num / 10;
  14724. // echo $num.'</br>';
  14725. $num = ( int ) $num;
  14726. // $num =floor($num);
  14727. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14728. // echo $num.'</br>';
  14729. // 结束循环
  14730. if ($num == 0) {
  14731. break;
  14732. }
  14733. }
  14734. // echo $c.'</br>';
  14735. $j = 0;
  14736. $slen = strlen ( $c );
  14737. while ( $j < $slen ) {
  14738. // utf8一个汉字相当3个字符
  14739. $m = substr ( $c, $j, 6 );
  14740. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14741. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14742. $left = substr ( $c, 0, $j );
  14743. $right = substr ( $c, $j + 3 );
  14744. $c = $left . $right;
  14745. $j = $j - 3;
  14746. $slen = $slen - 3;
  14747. }
  14748. $j = $j + 3;
  14749. }
  14750. // 这个是为了去掉类似23.0中最后一个“零”字
  14751. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14752. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14753. }
  14754. // 将处理的汉字加上“整”
  14755. if (empty ( $c )) {
  14756. return "零元整";
  14757. } else {
  14758. return $c . "整";
  14759. }
  14760. }
  14761. /**
  14762. * 获得分页数据
  14763. * @param unknown_type $table
  14764. * @param unknown_type $condition
  14765. * @param unknown_type $on_page
  14766. * @param unknown_type $page_size
  14767. */
  14768. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14769. $page_c = "";
  14770. $page ['previous'] = $this->get_previous ( $on_page );
  14771. $page ['on_page'] = $on_page;
  14772. $total_count = $this->get_table_count ( $table, $condition );
  14773. $total = intval ( $total_count / $page_size );
  14774. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14775. $page ['total_data'] = $total_count;
  14776. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14777. $i = 1;
  14778. $page_max = 1;
  14779. $page_width = 3;
  14780. if ($on_page >= $page_width) {
  14781. $page_max = intval ( $on_page / $page_width ) + 1;
  14782. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14783. }
  14784. for(; $i <= $page ['total_page']; $i ++) {
  14785. if ($i == $on_page)
  14786. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14787. else
  14788. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14789. if ($i == ($page_width * $page_max))
  14790. break;
  14791. }
  14792. $page ['page'] = $page_c;
  14793. $page ['lower'] = (-- $on_page) * $page_size;
  14794. return $page;
  14795. }
  14796. /**
  14797. * 获取总页数
  14798. * @param unknown_type $table
  14799. * @param unknown_type $condition
  14800. */
  14801. public function get_table_count($table = "", $condition = "") {
  14802. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14803. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14804. // echo $sql;die;
  14805. $query = Doo::db ()->query ( $sql );
  14806. $result = $query->fetch ();
  14807. return $result ['count'];
  14808. }
  14809. /**
  14810. * 获取上一页
  14811. * @param unknown_type $on_page
  14812. */
  14813. function get_previous($on_page = 1) {
  14814. return $on_page != 0 ? $on_page - 1 : $on_page;
  14815. }
  14816. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  14817. // 收入合计
  14818. Doo::loadModel ( 'invoiceTraining' );
  14819. $invoiceTraining = new invoiceTraining ();
  14820. Doo::loadModel ( 'receipt' );
  14821. $receipt = new receipt ();
  14822. $invoiceTrainingDetail = array (
  14823. 'invoiceArriveAmount' => '0.00',
  14824. 'RIAmount' => '0.00',
  14825. 'invoiceTotalAmount' => '0.00',
  14826. 'invoiceCompanyAmount' => '0.00',
  14827. 'invoiceArriveAmountM'=>'0.00',
  14828. 'invoiceCompanyAmountM'=>'0.00'
  14829. );
  14830. if ($invoiceTrainId != 0) {
  14831. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  14832. }
  14833. $invoiceArriveAmount = $RIAmount = 0;
  14834. if (! empty ( $invoiceTrainingDetail )) {
  14835. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  14836. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  14837. }
  14838. // 备用金
  14839. $sum = 0;
  14840. if (! empty ( $trainLoanRid )) {
  14841. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  14842. foreach ($receiptLoanList as $key=>$value){
  14843. $sum+=$value['sum'];
  14844. }
  14845. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  14846. // $sum = $receiptLoanDetailBak ['sum'];
  14847. }
  14848. // 支出项金额详情
  14849. // 项目金额合计
  14850. Doo::loadModel ( 'RItem' );
  14851. $RItem = new RItem ();
  14852. Doo::loadModel ( 'accountItem' );
  14853. $accountItem = new accountItem ();
  14854. // 讲师获得
  14855. Doo::loadModel ( 'RILecturer' );
  14856. $RILecturer = new RILecturer ();
  14857. $RItemList = $RItem->getRItemByRid ($rid );
  14858. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  14859. // 支出项金额详情
  14860. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  14861. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  14862. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  14863. return $payment;
  14864. }
  14865. }
  14866. ?>