ReceiptController.php 557 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060
  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. header ( 'Content-Type:text/html;charset=utf-8' );
  404. die ( '请填写行程单' );
  405. }
  406. $itineraryJson=json_decode($itinerary,true);
  407. foreach ($itineraryJson as $k=>$v){
  408. foreach ($v as $kk=>$vv){
  409. foreach ($vv as $key=>$value){
  410. if(empty($value['departuredate'])||empty($value['arrivalsdate'])){
  411. header ( 'Content-Type:text/html;charset=utf-8' );
  412. die ( '有行程的日期未设置' );
  413. }
  414. }
  415. }
  416. }
  417. $itineraryDate=array();$sql=array();
  418. foreach ($itineraryJson as $k=>$v){
  419. foreach ($v as $kk=>$vv){
  420. foreach ($vv as $key=>$value){
  421. if($key==0){
  422. array_push($itineraryDate, $value['departuredate']);
  423. array_push($itineraryDate, substr($value['arrivalsdate'],1));
  424. array_push($sql,'?');array_push($sql,'?');
  425. }else{
  426. array_push($itineraryDate, substr($value['arrivalsdate'],1));
  427. array_push($sql,'?');
  428. }
  429. }
  430. }
  431. }
  432. array_push($itineraryDate, $this->staff [0] ['sid']);
  433. $sql=implode(',',$sql);
  434. // $itineraryDate=array();$sql=array();
  435. // foreach ($itineraryJson as $key=>$value){
  436. // if($key==0){
  437. // array_push($itineraryDate, $value['departuredate']);
  438. // array_push($itineraryDate, substr($value['arrivalsdate'],1));
  439. // array_push($sql,'?');array_push($sql,'?');
  440. // }else{
  441. // array_push($itineraryDate, substr($value['arrivalsdate'],1));
  442. // array_push($sql,'?');
  443. // }
  444. // }
  445. // array_push($itineraryDate, $this->staff [0] ['sid']);
  446. // $sql=implode(',',$sql);
  447. if(empty($sql)){
  448. header ( 'Content-Type:text/html;charset=utf-8' );
  449. die ( '请填写行程单-2' );
  450. }
  451. $qualification=array(
  452. 'where' => 'itineraryDate in ('.$sql.') and sid=? ',
  453. 'param' => $itineraryDate,
  454. 'asArray' => TRUE);
  455. $itDateList=$itineraryObj->find($qualification);
  456. if(empty($itDateList)){
  457. return false;
  458. }else{
  459. return true;
  460. }
  461. }
  462. private function _buildFeeData($receiptClass=1,$itinerary=''){
  463. $agency = $this->get_args ( 'agency' );
  464. $travel = $this->get_args ( 'travel' );
  465. $train = $this->get_args ( 'train' );
  466. $other = $this->get_args ( 'other' );
  467. $inttrain = $this->get_args ( 'inttrain' );
  468. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  469. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  470. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  471. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  472. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  473. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  474. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  475. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  476. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  477. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  478. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  479. header ( 'Content-Type:text/html;charset=utf-8' );
  480. die ( '请填写联行号' );
  481. }
  482. if($receiptClass==2){
  483. //TODO 日期检测
  484. if($this->_verificationItinerary($itinerary)){
  485. header ( 'Content-Type:text/html;charset=utf-8' );
  486. die ( '已申请过类此日期的行程' );
  487. }
  488. }
  489. $itinerary=str_replace('\n','<br/>',$itinerary);
  490. Doo::loadModel ( 'receipt' );
  491. Doo::loadModel ( 'receiptDetail' );
  492. Doo::loadModel ( 'accountItem' );
  493. $accountItem = new accountItem ();
  494. $receipt = new receipt ();
  495. Doo::loadModel ( 'enclosur' );
  496. Doo::loadModel ( 'execute' );
  497. $execute = new execute ();
  498. $executeDetail = $execute->getOne ( array (
  499. 'where' => 'mold="报销单执行人"',
  500. 'asArray' => true
  501. ) );
  502. $aItem = $accountItem->find ( array (
  503. 'asArray' => true
  504. ) );
  505. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  506. $ag = $tr = $ta = $ot= $it = 0;
  507. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  508. foreach ( $aItem as $key => $value ) {
  509. if ($value ['category'] == $this->AGENCY) {
  510. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  511. array_push ( $accountJson [$this->AGENCY], array (
  512. 'aid' => $value ['aid'],
  513. 'name' => $value ['name'],
  514. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  515. ) );
  516. $sum += $agency [$ag];
  517. $agencySum += $agency [$ag];
  518. }
  519. $ag ++;
  520. }
  521. if ($value ['category'] == $this->TRAVEL) {
  522. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  523. array_push ( $accountJson [$this->TRAVEL], array (
  524. 'aid' => $value ['aid'],
  525. 'name' => $value ['name'],
  526. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  527. ) );
  528. $sum += $travel [$tr];
  529. $travelSum += $travel [$tr];
  530. }
  531. $tr ++;
  532. }
  533. if ($value ['category'] == $this->TRAIN) {
  534. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  535. array_push ( $accountJson [$this->TRAIN], array (
  536. 'aid' => $value ['aid'],
  537. 'name' => $value ['name'],
  538. 'price' => number_format ( $train [$ta], 2, '.', '' )
  539. ) );
  540. $sum += $train [$ta];
  541. $trainSum += $train [$ta];
  542. }
  543. $ta ++;
  544. }
  545. if ($value ['category'] == $this->INTTRAIN) {
  546. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  547. array_push ( $accountJson [$this->INTTRAIN], array (
  548. 'aid' => $value ['aid'],
  549. 'name' => $value ['name'],
  550. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  551. ) );
  552. $sum += $inttrain [$it];
  553. $inttrainSum += $inttrain [$it];
  554. }
  555. $it ++;
  556. }
  557. if ($value ['category'] == $this->OTHER) {
  558. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  559. array_push ( $accountJson [$this->OTHER], array (
  560. 'aid' => $value ['aid'],
  561. 'name' => $value ['name'],
  562. 'price' => number_format ( $other [$ot], 2, '.', '' )
  563. ) );
  564. $sum += $other [$ot];
  565. $otherSum += $other [$ot];
  566. }
  567. $ot ++;
  568. }
  569. }
  570. $accountJson ['cSum'] = array (
  571. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  572. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  573. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  574. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  575. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  576. );
  577. // 报销单
  578. $receipt->accountItem = json_encode ( $accountJson );
  579. $receipt->staff = $this->staff [0] ['sid'];
  580. $receipt->sum = number_format ( $sum, 2, '.', '' );
  581. $receipt->date = date ( "Y-m-d" );
  582. $receipt->cid = $cid;
  583. $receipt->status = 5;
  584. // 修改审批流程加入角色
  585. $receipt->verify = $verify;
  586. $receipt->executeCopy = $executeDetail ['staff'];
  587. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  588. $order = array (
  589. "\r\n",
  590. "\n",
  591. "\r"
  592. );
  593. $replace = '<br/>';
  594. $explanation = str_replace ( $order, $replace, $explanation );
  595. $receipt->explanation = $explanation;
  596. $receipt->receiptClass = $receiptClass;
  597. $receipt->itinerary2=$itinerary;
  598. $receipt->remittanceName = $remittanceName;
  599. $receipt->bankName = $bankName;
  600. $receipt->bankNumber = $bankNumber;
  601. $receipt->remittanceBankType = $remittanceBankType;
  602. if ($remittanceBankType == 1) {
  603. $receipt->coupletNumber = $coupletNumber;
  604. }
  605. $rid = $receipt->insert ();
  606. //记录行程单
  607. $this->_storageItinerary($itinerary,$rid);
  608. // 附件
  609. if (! empty ( $enclosurName )) {
  610. $enclosurArray = explode ( '-', $enclosurName );
  611. foreach ( $enclosurArray as $value ) {
  612. $enclosur = new enclosur ();
  613. $enclosur->name = $value;
  614. $enclosur->rid = $rid;
  615. $enclosur->insert ();
  616. }
  617. }
  618. // 报销详情
  619. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  620. $receiptDetail = new receiptDetail ();
  621. $receiptDetail->staff = $this->staff [0] ['sid'];
  622. $receiptDetail->item = $value ['name'];
  623. $receiptDetail->itemCategory = $this->AGENCY;
  624. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  625. $receiptDetail->date = date ( "Y-m-d" );
  626. $receiptDetail->cid = $cid;
  627. $receiptDetail->rid = $rid;
  628. $receiptDetail->status = 4;
  629. $receiptDetail->insert ();
  630. }
  631. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  632. $receiptDetail = new receiptDetail ();
  633. $receiptDetail->staff = $this->staff [0] ['sid'];
  634. $receiptDetail->item = $value ['name'];
  635. $receiptDetail->itemCategory = $this->TRAVEL;
  636. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  637. $receiptDetail->date = date ( "Y-m-d" );
  638. $receiptDetail->cid = $cid;
  639. $receiptDetail->rid = $rid;
  640. $receiptDetail->status = 4;
  641. $receiptDetail->insert ();
  642. }
  643. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  644. $receiptDetail = new receiptDetail ();
  645. $receiptDetail->staff = $this->staff [0] ['sid'];
  646. $receiptDetail->item = $value ['name'];
  647. $receiptDetail->itemCategory = $this->TRAIN;
  648. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  649. $receiptDetail->date = date ( "Y-m-d" );
  650. $receiptDetail->cid = $cid;
  651. $receiptDetail->rid = $rid;
  652. $receiptDetail->status = 4;
  653. $receiptDetail->insert ();
  654. }
  655. // 内训
  656. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  657. $receiptDetail = new receiptDetail ();
  658. $receiptDetail->staff = $this->staff [0] ['sid'];
  659. $receiptDetail->item = $value ['name'];
  660. $receiptDetail->itemCategory = $this->INTTRAIN;
  661. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  662. $receiptDetail->date = date ( "Y-m-d" );
  663. $receiptDetail->cid = $cid;
  664. $receiptDetail->rid = $rid;
  665. $receiptDetail->status = 4;
  666. $receiptDetail->insert ();
  667. }
  668. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  669. $receiptDetail = new receiptDetail ();
  670. $receiptDetail->staff = $this->staff [0] ['sid'];
  671. $receiptDetail->item = $value ['name'];
  672. $receiptDetail->itemCategory = $this->OTHER;
  673. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  674. $receiptDetail->date = date ( "Y-m-d" );
  675. $receiptDetail->cid = $cid;
  676. $receiptDetail->rid = $rid;
  677. $receiptDetail->status = 4;
  678. $receiptDetail->insert ();
  679. }
  680. return true;
  681. } else
  682. return false;
  683. }
  684. function addReceipt() {
  685. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  686. if ($this->_buildFeeData(1)) {
  687. return "/saeaBorad";
  688. } else{
  689. die ( 'illegal request' );
  690. }
  691. }
  692. function addFeeTravel(){
  693. $itinerary = $_POST['itinerary'] ? $_POST['itinerary'] : "";
  694. $itineraryList=json_decode($itinerary,true);
  695. // foreach ($itineraryList as $key=>$value){
  696. // if(empty($value['departuredate'])||empty($value['departurecity'])){
  697. // header ( 'Content-Type:text/html;charset=utf-8' );
  698. // die ( '请设置出发地和出发日期' );
  699. // }
  700. // }
  701. if ($this->_buildFeeData(2,$itinerary)) {
  702. return "/saeaBorad?travel=success";
  703. } else{
  704. die ( 'illegal request' );
  705. }
  706. }
  707. function addFeeInternalTrain(){
  708. if ($this->_buildFeeData(3)) {
  709. return "/saeaBorad";
  710. } else{
  711. die ( 'illegal request' );
  712. }
  713. }
  714. function referReceipt() {
  715. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  716. Doo::loadModel ( 'receipt' );
  717. Doo::loadModel ( 'verify' );
  718. $verify = new verify ();
  719. $receipt = new receipt ();
  720. Doo::loadModel ( 'L_category' );
  721. $lCategory = new L_category ();
  722. Doo::loadModel ( "role" );
  723. $role = new role ();
  724. $receiptDetail = $receipt->find ( array (
  725. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  726. 'asArray' => true
  727. ) );
  728. if (empty ( $receiptDetail ))
  729. return "/addReceipt";
  730. foreach ( $receiptDetail as $key => $value ) {
  731. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  732. $veList = $verify->getOne ( array (
  733. 'where' => 'vid=' . $value ['verify'],
  734. 'asArray' => true
  735. ) );
  736. $v = json_decode ( $veList ['staff'] );
  737. array_push ( $v [0], $veList ['description'] );
  738. foreach ( $v as $n => $m ) {
  739. if ($m ['1'] == 'ROLE') {
  740. $roleInfo = $role->getOne ( array (
  741. 'where' => 'rid=' . $m [0],
  742. 'asArray' => true
  743. ) );
  744. $v [$n] [1] = $roleInfo ['name'];
  745. }
  746. }
  747. $receiptDetail [$key] ['staff'] = $v;
  748. $category = $lCategory->getOne ( array (
  749. 'where' => 'cid=' . $value ['cid'],
  750. 'asArray' => true
  751. ) );
  752. $receiptDetail [$key] ['category'] = $category ['title'];
  753. }
  754. // print_r($receiptDetail);
  755. $data ['receiptDetail'] = $receiptDetail;
  756. $data ['memu'] = "receipt";
  757. $data ['staff'] = $this->staff;
  758. $data ['receiptMemu'] = 'saeaCreate';
  759. $data ['verifyId'] = $this->verifyId;
  760. $data ['executeId'] = $this->executeId;
  761. $this->render ( "/admin/saea_confirm", $data );
  762. }
  763. function editReceipt() {
  764. // edit status 4
  765. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  766. Doo::loadClass ( 'XDeode' );
  767. $XDeode = new XDeode ( 7 );
  768. $rid = $XDeode->decode ( $ridKey );
  769. if (empty ( $rid )) {
  770. die ( 'illegal request-id' );
  771. }
  772. // echo $rid.'sd';
  773. Doo::loadModel ( 'accountItem' );
  774. Doo::loadModel ( 'verify' );
  775. Doo::loadModel ( 'receipt' );
  776. $receipt = new receipt ();
  777. $verify = new verify ();
  778. $accountItem = new accountItem ();
  779. Doo::loadModel ( 'L_category' );
  780. $lCategory = new L_category ();
  781. Doo::loadModel ( "role" );
  782. $role = new role ();
  783. Doo::loadModel ( 'enclosur' );
  784. $enclosur = new enclosur ();
  785. $receiptDetail = $receipt->getOne ( array (
  786. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  787. 'asArray' => true
  788. ) );
  789. if (empty ( $receiptDetail )) {
  790. die ( 'illegal request-emptyData' );
  791. }
  792. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  793. $acItem = $accountItem->find ( array (
  794. 'asArray' => true
  795. ) );
  796. $veList = $verify->getVerifyBySubordinate ( 'RECEIPT' );
  797. // 配置编辑信息
  798. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  799. foreach ( $acItem as $key => $value ) {
  800. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  801. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  802. $acItem [$key] ['price'] = $v ['price'];
  803. }
  804. }
  805. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  806. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  807. $acItem [$key] ['price'] = $v ['price'];
  808. }
  809. }
  810. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  811. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  812. $acItem [$key] ['price'] = $v ['price'];
  813. }
  814. }
  815. // 内训
  816. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  817. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  818. $acItem [$key] ['price'] = $v ['price'];
  819. }
  820. }
  821. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  822. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  823. $acItem [$key] ['price'] = $v ['price'];
  824. }
  825. }
  826. }
  827. //$receiptDetail['itinerary']=str_replace('\n','<br/>',$receiptDetail['itinerary']);
  828. //nl2br($receiptDetail['explanation']);
  829. Doo::loadModel ( 'itinerary' );
  830. $itinerary = new itinerary ();
  831. $itinerary->delete(array('where' => 'rid=' . $receiptDetail['rid'] ));
  832. $receiptDetail['explanation']= str_replace('<br/>',"\n",$receiptDetail['explanation']);
  833. $receiptDetail['itinerary']=str_replace('\n','<br/>',$receiptDetail['itinerary']);
  834. $data ['category'] = $lCategory->find ( array (
  835. 'asArray' => true
  836. ) );
  837. $data ['cSum'] = $accountItemList ['cSum'];
  838. $data ['sum'] = $receiptDetail ['sum'];
  839. $data ['enclosurList'] = $enclosurList;
  840. $data ['receiptDetail'] = $receiptDetail;
  841. $data ['veList'] = $veList;
  842. $data ['acItem'] = $acItem;
  843. $data ['memu'] = "receipt";
  844. $data ['staff'] = $this->staff;
  845. $data ['receiptMemu'] = 'saeaBorad';
  846. $data ['verify'] = $receiptDetail ['verify'];
  847. $data ['verifyId'] = $this->verifyId;
  848. $data ['executeId'] = $this->executeId;
  849. $data ['rid'] = $ridKey;
  850. if($receiptDetail['receiptClass']==1){
  851. $this->render ( "/receipt/feeAgencyEdi", $data );
  852. }elseif($receiptDetail['receiptClass']==2){
  853. if(!empty($receiptDetail['itinerary2'])){
  854. //TODO 报销说明
  855. $this->render ( "/receipt/feeTravelEdi2", $data );
  856. }else{
  857. $this->render ( "/receipt/feeTravelEdi", $data );
  858. }
  859. }elseif($receiptDetail['receiptClass']==3){
  860. $this->render ( "/receipt/feeInternalTrainEdi", $data );
  861. }else{
  862. $this->render ( "/admin/saea_edit", $data );
  863. //die ( 'illegal request-renderHtml' );
  864. }
  865. }
  866. function updateReceipt() {
  867. $agency = $this->get_args ( 'agency' );
  868. $travel = $this->get_args ( 'travel' );
  869. $train = $this->get_args ( 'train' );
  870. $other = $this->get_args ( 'other' );
  871. $inttrain = $this->get_args ( 'inttrain' );
  872. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  873. $traveVer = $this->get_args ( 'traveVer' ) ? $this->get_args ( 'traveVer' ) : "trave2";
  874. $itinerary = $_POST['itinerary'];
  875. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  876. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  877. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  878. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  879. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  880. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  881. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  882. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  883. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  884. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  885. Doo::loadClass ( 'XDeode' );
  886. $XDeode = new XDeode ( 7 );
  887. $rid = $XDeode->decode ( $ridKey );
  888. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  889. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  890. header ( 'Content-Type:text/html;charset=utf-8' );
  891. die ( '请填写联行号' );
  892. }
  893. if($traveVer!='trave1'){
  894. if($receiptClass=='trave'){
  895. //TODO 日期检测
  896. if($this->_verificationItinerary($itinerary)){
  897. header ( 'Content-Type:text/html;charset=utf-8' );
  898. die ( '已申请过类此日期的行程' );
  899. }
  900. }
  901. }
  902. Doo::loadModel ( 'receipt' );
  903. Doo::loadModel ( 'receiptDetail' );
  904. Doo::loadModel ( 'accountItem' );
  905. $accountItem = new accountItem ();
  906. $receipt = new receipt ();
  907. Doo::loadModel ( 'enclosur' );
  908. Doo::loadModel ( 'execute' );
  909. $execute = new execute ();
  910. $receiptDetail = $receipt->getOne ( array (
  911. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  912. 'asArray' => true
  913. ) );
  914. if (empty ( $receiptDetail )) {
  915. return "/saeaBorad";
  916. }
  917. //TODO 存储行程单-兼容旧版本的行程单
  918. $itinerary=str_replace('\n','<br/>',$itinerary);
  919. if(!empty($receiptDetail['itinerary2'])){
  920. $this->_storageItinerary($itinerary,$rid);
  921. }else{
  922. $this->_storageItinerary($itinerary,$rid,1);
  923. }
  924. if ($receiptDetail ['Rtype'] == 1) {
  925. $executeDetail = $execute->getOne ( array (
  926. 'where' => 'mold="借款费用执行人"',
  927. 'asArray' => true
  928. ) );
  929. } else {
  930. $executeDetail = $execute->getOne ( array (
  931. 'where' => 'mold="报销单执行人"',
  932. 'asArray' => true
  933. ) );
  934. }
  935. $aItem = $accountItem->find ( array (
  936. 'asArray' => true
  937. ) );
  938. $accountJson [$this->AGENCY] = $accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  939. $ag = $tr = $ta = $ot = $it = 0;
  940. $sum = $agencySum = $travelSum = $trainSum = $inttrainSum = $otherSum = 0;
  941. foreach ( $aItem as $key => $value ) {
  942. if ($value ['category'] == $this->AGENCY) {
  943. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  944. array_push ( $accountJson [$this->AGENCY], array (
  945. 'aid' => $value ['aid'],
  946. 'name' => $value ['name'],
  947. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  948. ) );
  949. $sum += $agency [$ag];
  950. $agencySum += $agency [$ag];
  951. }
  952. $ag ++;
  953. }
  954. if ($value ['category'] == $this->TRAVEL) {
  955. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  956. array_push ( $accountJson [$this->TRAVEL], array (
  957. 'aid' => $value ['aid'],
  958. 'name' => $value ['name'],
  959. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  960. ) );
  961. $sum += $travel [$tr];
  962. $travelSum += $travel [$tr];
  963. }
  964. $tr ++;
  965. }
  966. if ($value ['category'] == $this->TRAIN) {
  967. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  968. array_push ( $accountJson [$this->TRAIN], array (
  969. 'aid' => $value ['aid'],
  970. 'name' => $value ['name'],
  971. 'price' => number_format ( $train [$ta], 2, '.', '' )
  972. ) );
  973. $sum += $train [$ta];
  974. $trainSum += $train [$ta];
  975. }
  976. $ta ++;
  977. }
  978. if ($value ['category'] == $this->INTTRAIN) {
  979. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  980. array_push ( $accountJson [$this->INTTRAIN], array (
  981. 'aid' => $value ['aid'],
  982. 'name' => $value ['name'],
  983. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  984. ) );
  985. $sum += $inttrain [$it];
  986. $inttrainSum += $inttrain [$it];
  987. }
  988. $it ++;
  989. }
  990. if ($value ['category'] == $this->OTHER) {
  991. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  992. array_push ( $accountJson [$this->OTHER], array (
  993. 'aid' => $value ['aid'],
  994. 'name' => $value ['name'],
  995. 'price' => number_format ( $other [$ot], 2, '.', '' )
  996. ) );
  997. $sum += $other [$ot];
  998. $otherSum += $other [$ot];
  999. }
  1000. $ot ++;
  1001. }
  1002. }
  1003. $accountJson ['cSum'] = array (
  1004. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1005. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1006. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1007. 'inttrainSum' => number_format ( $inttrainSum, 2, '.', '' ),
  1008. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1009. );
  1010. // 报销单
  1011. $rid = $receipt->rid = $receiptDetail ['rid'];
  1012. $receipt->accountItem = json_encode ( $accountJson );
  1013. $receipt->staff = $this->staff [0] ['sid'];
  1014. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1015. $receipt->date = date ( "Y-m-d" );
  1016. $receipt->cid = $cid;
  1017. if (($receiptDetail ['status'] != 4)) {
  1018. if ($receiptDetail ['Rtype'] == 1) {
  1019. $receipt->status = 7;
  1020. } else {
  1021. $receipt->status = 5;
  1022. }
  1023. }
  1024. if ($receiptDetail != 4 && ! empty ( $verify ))
  1025. $receipt->verify = $verify;
  1026. $receipt->executeCopy = $executeDetail ['staff'];
  1027. $order = array (
  1028. "\r\n",
  1029. "\n",
  1030. "\r"
  1031. );
  1032. $replace = '<br/>';
  1033. $explanation = str_replace ( $order, $replace, $explanation );
  1034. $receipt->explanation = $explanation;
  1035. if($receiptClass=='trave'){
  1036. if(!empty($receiptDetail['itinerary2'])){//行程单版本
  1037. $receipt->itinerary2=$itinerary;
  1038. }else{
  1039. $receipt->itinerary=$itinerary;
  1040. }
  1041. }
  1042. $receipt->remittanceName = $remittanceName;
  1043. $receipt->bankName = $bankName;
  1044. $receipt->bankNumber = $bankNumber;
  1045. $receipt->remittanceBankType = $remittanceBankType;
  1046. if ($remittanceBankType == 1)
  1047. $receipt->coupletNumber = $coupletNumber;
  1048. $receipt->update ();
  1049. $receiptDetail = new receiptDetail ();
  1050. $receiptDetail->delete ( array (
  1051. 'where' => 'rid=' . $rid
  1052. ) );
  1053. // 报销详情
  1054. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1055. $receiptDetail = new receiptDetail ();
  1056. $receiptDetail->staff = $this->staff [0] ['sid'];
  1057. $receiptDetail->item = $value ['name'];
  1058. $receiptDetail->itemCategory = $this->AGENCY;
  1059. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1060. $receiptDetail->date = date ( "Y-m-d" );
  1061. $receiptDetail->cid = $cid;
  1062. $receiptDetail->rid = $rid;
  1063. $receiptDetail->status = 4;
  1064. $receiptDetail->insert ();
  1065. }
  1066. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1067. $receiptDetail = new receiptDetail ();
  1068. $receiptDetail->staff = $this->staff [0] ['sid'];
  1069. $receiptDetail->item = $value ['name'];
  1070. $receiptDetail->itemCategory = $this->TRAVEL;
  1071. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1072. $receiptDetail->date = date ( "Y-m-d" );
  1073. $receiptDetail->cid = $cid;
  1074. $receiptDetail->rid = $rid;
  1075. $receiptDetail->status = 4;
  1076. $receiptDetail->insert ();
  1077. }
  1078. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1079. $receiptDetail = new receiptDetail ();
  1080. $receiptDetail->staff = $this->staff [0] ['sid'];
  1081. $receiptDetail->item = $value ['name'];
  1082. $receiptDetail->itemCategory = $this->TRAIN;
  1083. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1084. $receiptDetail->date = date ( "Y-m-d" );
  1085. $receiptDetail->cid = $cid;
  1086. $receiptDetail->rid = $rid;
  1087. $receiptDetail->status = 4;
  1088. $receiptDetail->insert ();
  1089. }
  1090. // 内训
  1091. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1092. $receiptDetail = new receiptDetail ();
  1093. $receiptDetail->staff = $this->staff [0] ['sid'];
  1094. $receiptDetail->item = $value ['name'];
  1095. $receiptDetail->itemCategory = $this->INTTRAIN;
  1096. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1097. $receiptDetail->date = date ( "Y-m-d" );
  1098. $receiptDetail->cid = $cid;
  1099. $receiptDetail->rid = $rid;
  1100. $receiptDetail->status = 4;
  1101. $receiptDetail->insert ();
  1102. }
  1103. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1104. $receiptDetail = new receiptDetail ();
  1105. $receiptDetail->staff = $this->staff [0] ['sid'];
  1106. $receiptDetail->item = $value ['name'];
  1107. $receiptDetail->itemCategory = $this->OTHER;
  1108. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1109. $receiptDetail->date = date ( "Y-m-d" );
  1110. $receiptDetail->cid = $cid;
  1111. $receiptDetail->rid = $rid;
  1112. $receiptDetail->status = 4;
  1113. $receiptDetail->insert ();
  1114. }
  1115. // 附件
  1116. if (! empty ( $enclosurName )) {
  1117. $enclosurArray = explode ( '-', $enclosurName );
  1118. foreach ( $enclosurArray as $value ) {
  1119. $enclosur = new enclosur ();
  1120. $enclosur->name = $value;
  1121. $enclosur->rid = $rid;
  1122. $enclosur->insert ();
  1123. }
  1124. }
  1125. // return "/referReceipt/".$rid;
  1126. }
  1127. return "/saeaBorad";
  1128. }
  1129. function remitAdd() {
  1130. Doo::loadModel ( 'accountItem' );
  1131. Doo::loadModel ( 'verify' );
  1132. Doo::loadModel ( 'receipt' );
  1133. Doo::loadModel ( 'L_category' );
  1134. $lCategory = new L_category ();
  1135. $receipt = new receipt ();
  1136. $verify = new verify ();
  1137. $accountItem = new accountItem ();
  1138. Doo::loadModel ( "role" );
  1139. $role = new role ();
  1140. $acItem = $accountItem->find ( array (
  1141. 'asArray' => true
  1142. ) );
  1143. $veList = $verify->getVerifyBySubordinate('REMIT');
  1144. $data ['category'] = $lCategory->find ( array (
  1145. 'asArray' => true
  1146. ) );
  1147. $data ['veList'] = $veList;
  1148. $data ['acItem'] = $acItem;
  1149. $data ['memu'] = "receipt";
  1150. $data ['staff'] = $this->staff;
  1151. $data ['receiptMemu'] = 'saeaBorad';
  1152. $data ['verifyId'] = $this->verifyId;
  1153. $data ['executeId'] = $this->executeId;
  1154. $this->render ( "/admin/remitAdd", $data );
  1155. }
  1156. function remitAddDo() {
  1157. $agency = $this->get_args ( 'agency' );
  1158. $travel = $this->get_args ( 'travel' );
  1159. $train = $this->get_args ( 'train' );
  1160. $other = $this->get_args ( 'other' );
  1161. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1162. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1163. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1164. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1165. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1166. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1167. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1168. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1169. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1170. // print_r($agency);die;
  1171. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1172. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1173. header ( 'Content-Type:text/html;charset=utf-8' );
  1174. die ( '请填写联行号' );
  1175. }
  1176. Doo::loadModel ( 'receipt' );
  1177. Doo::loadModel ( 'receiptDetail' );
  1178. Doo::loadModel ( 'accountItem' );
  1179. $accountItem = new accountItem ();
  1180. $receipt = new receipt ();
  1181. Doo::loadModel ( 'enclosur' );
  1182. Doo::loadModel ( 'execute' );
  1183. $execute = new execute ();
  1184. $executeDetail = $execute->getOne ( array (
  1185. 'where' => 'mold="对公汇款执行人"',
  1186. 'asArray' => true
  1187. ) );
  1188. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  1189. $aItem = $accountItem->find ( array (
  1190. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  1191. 'asArray' => true
  1192. ) );
  1193. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1194. $ag = $tr = $ta = $ot = 0;
  1195. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1196. print_r($aItem);
  1197. foreach ( $aItem as $key => $value ) {
  1198. if ($value ['category'] == $this->AGENCY) {
  1199. if (isset ( $agency [$ag] )) {
  1200. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1201. array_push ( $accountJson [$this->AGENCY], array (
  1202. 'aid' => $value ['aid'],
  1203. 'name' => $value ['name'],
  1204. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1205. ) );
  1206. $sum += $agency [$ag];
  1207. $agencySum += $agency [$ag];
  1208. }
  1209. }
  1210. $ag ++;
  1211. }
  1212. }
  1213. $accountJson ['cSum'] = array (
  1214. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1215. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1216. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1217. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1218. );
  1219. //die;
  1220. // 报销单
  1221. $receipt->accountItem = json_encode ( $accountJson );
  1222. $receipt->staff = $this->staff [0] ['sid'];
  1223. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1224. $receipt->date = date ( "Y-m-d" );
  1225. $receipt->cid = $cid;
  1226. $receipt->status = 5;
  1227. $receipt->Rtype = 2;
  1228. // 修改审批流程加入角色
  1229. $receipt->verify = $verify;
  1230. $receipt->executeCopy = $executeDetail ['staff'];
  1231. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1232. $order = array (
  1233. "\r\n",
  1234. "\n",
  1235. "\r"
  1236. );
  1237. $replace = '<br/>';
  1238. $explanation = str_replace ( $order, $replace, $explanation );
  1239. $receipt->explanation = $explanation;
  1240. $receipt->remittanceName = $remittanceName;
  1241. $receipt->bankName = $bankName;
  1242. $receipt->bankNumber = $bankNumber;
  1243. $receipt->remittanceBankType = $remittanceBankType;
  1244. if ($remittanceBankType == 1)
  1245. $receipt->coupletNumber = $coupletNumber;
  1246. $rid = $receipt->insert ();
  1247. // 附件
  1248. if (! empty ( $enclosurName )) {
  1249. $enclosurArray = explode ( '-', $enclosurName );
  1250. foreach ( $enclosurArray as $value ) {
  1251. $enclosur = new enclosur ();
  1252. $enclosur->name = $value;
  1253. $enclosur->rid = $rid;
  1254. $enclosur->insert ();
  1255. }
  1256. // print_r($enclosurArray);die;
  1257. }
  1258. // 报销详情
  1259. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1260. $receiptDetail = new receiptDetail ();
  1261. $receiptDetail->staff = $this->staff [0] ['sid'];
  1262. $receiptDetail->item = $value ['name'];
  1263. $receiptDetail->itemCategory = $this->AGENCY;
  1264. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1265. $receiptDetail->date = date ( "Y-m-d" );
  1266. $receiptDetail->cid = $cid;
  1267. $receiptDetail->rid = $rid;
  1268. $receiptDetail->status = 4;
  1269. $receiptDetail->insert ();
  1270. }
  1271. return "/saeaBorad";
  1272. } else
  1273. die ( 'illegal request' );
  1274. }
  1275. function remitEdit() {
  1276. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1277. Doo::loadClass ( 'XDeode' );
  1278. $XDeode = new XDeode ( 7 );
  1279. $rid = $XDeode->decode ( $ridKey );
  1280. if (! is_numeric ( $rid ))
  1281. die ( 'illegal request' );
  1282. Doo::loadModel ( 'accountItem' );
  1283. Doo::loadModel ( 'verify' );
  1284. Doo::loadModel ( 'receipt' );
  1285. $receipt = new receipt ();
  1286. $verify = new verify ();
  1287. $accountItem = new accountItem ();
  1288. Doo::loadModel ( 'L_category' );
  1289. $lCategory = new L_category ();
  1290. Doo::loadModel ( "role" );
  1291. $role = new role ();
  1292. Doo::loadModel ( 'enclosur' );
  1293. $enclosur = new enclosur ();
  1294. $receiptDetail = $receipt->getOne ( array (
  1295. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  1296. 'asArray' => true
  1297. ) );
  1298. if (empty ( $receiptDetail ))
  1299. return "/saeaCreate";
  1300. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  1301. $acItem = $accountItem->find ( array (
  1302. 'asArray' => true
  1303. ) );
  1304. $veList = $verify->getVerifyBySubordinate('REMIT');
  1305. // 配置编辑信息
  1306. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1307. foreach ( $acItem as $key => $value ) {
  1308. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1309. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1310. $acItem [$key] ['price'] = $v ['price'];
  1311. }
  1312. }
  1313. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1314. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1315. $acItem [$key] ['price'] = $v ['price'];
  1316. }
  1317. }
  1318. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1319. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1320. $acItem [$key] ['price'] = $v ['price'];
  1321. }
  1322. }
  1323. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1324. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1325. $acItem [$key] ['price'] = $v ['price'];
  1326. }
  1327. }
  1328. }
  1329. $data ['category'] = $lCategory->find ( array (
  1330. 'asArray' => true
  1331. ) );
  1332. $data ['enclosurList'] = $enclosurList;
  1333. $data ['cSum'] = $accountItemList ['cSum'];
  1334. $data ['sum'] = $receiptDetail ['sum'];
  1335. $data ['receiptDetail'] = $receiptDetail;
  1336. $data ['veList'] = $veList;
  1337. $data ['acItem'] = $acItem;
  1338. $data ['memu'] = "receipt";
  1339. $data ['staff'] = $this->staff;
  1340. $data ['receiptMemu'] = 'saeaBorad';
  1341. $data ['verify'] = $receiptDetail ['verify'];
  1342. $data ['verifyId'] = $this->verifyId;
  1343. $data ['executeId'] = $this->executeId;
  1344. $data ['rid'] = $rid;
  1345. $data ['ridKey'] = $ridKey;
  1346. $this->render ( "/admin/remitEdit", $data );
  1347. }
  1348. function remitEdiDo() {
  1349. $agency = $this->get_args ( 'agency' );
  1350. $travel = $this->get_args ( 'travel' );
  1351. $train = $this->get_args ( 'train' );
  1352. $other = $this->get_args ( 'other' );
  1353. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1354. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1355. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1356. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1357. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1358. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1359. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1360. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1361. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1362. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1363. Doo::loadClass ( 'XDeode' );
  1364. $XDeode = new XDeode ( 7 );
  1365. $rid = $XDeode->decode ( $ridKey );
  1366. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1367. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1368. header ( 'Content-Type:text/html;charset=utf-8' );
  1369. die ( '请填写联行号' );
  1370. }
  1371. Doo::loadModel ( 'receipt' );
  1372. Doo::loadModel ( 'receiptDetail' );
  1373. Doo::loadModel ( 'accountItem' );
  1374. $accountItem = new accountItem ();
  1375. $receipt = new receipt ();
  1376. Doo::loadModel ( 'enclosur' );
  1377. $enclosur = new enclosur ();
  1378. Doo::loadModel ( 'execute' );
  1379. $execute = new execute ();
  1380. $executeDetail = $execute->getOne ( array (
  1381. 'where' => 'mold="对公汇款执行人"',
  1382. 'asArray' => true
  1383. ) );
  1384. $receiptDetail = $receipt->getOne ( array (
  1385. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  1386. 'asArray' => true
  1387. ) );
  1388. if (empty ( $receiptDetail ))
  1389. return "/saeaBorad";
  1390. $aItem = $accountItem->find ( array (
  1391. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  1392. 'asArray' => true
  1393. ) );
  1394. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1395. $ag = $tr = $ta = $ot = 0;
  1396. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1397. foreach ( $aItem as $key => $value ) {
  1398. if ($value ['category'] == $this->AGENCY) {
  1399. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1400. array_push ( $accountJson [$this->AGENCY], array (
  1401. 'aid' => $value ['aid'],
  1402. 'name' => $value ['name'],
  1403. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1404. ) );
  1405. $sum += $agency [$ag];
  1406. $agencySum += $agency [$ag];
  1407. }
  1408. $ag ++;
  1409. }
  1410. }
  1411. $accountJson ['cSum'] = array (
  1412. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1413. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1414. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1415. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1416. );
  1417. // 报销单
  1418. $rid = $receipt->rid = $receiptDetail ['rid'];
  1419. $receipt->accountItem = json_encode ( $accountJson );
  1420. $receipt->staff = $this->staff [0] ['sid'];
  1421. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1422. $receipt->date = date ( "Y-m-d" );
  1423. $receipt->cid = $cid;
  1424. if ($receiptDetail ['Rtype'] == 1)
  1425. $receipt->status = 7;
  1426. else
  1427. $receipt->status = 5;
  1428. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  1429. $receipt->verify = $verify;
  1430. $receipt->executeCopy = $executeDetail ['staff'];
  1431. $order = array (
  1432. "\r\n",
  1433. "\n",
  1434. "\r"
  1435. );
  1436. $replace = '<br/>';
  1437. $explanation = str_replace ( $order, $replace, $explanation );
  1438. $receipt->explanation = $explanation;
  1439. $receipt->remittanceName = $remittanceName;
  1440. $receipt->bankName = $bankName;
  1441. $receipt->bankNumber = $bankNumber;
  1442. $receipt->remittanceBankType = $remittanceBankType;
  1443. if ($remittanceBankType == 1)
  1444. $receipt->coupletNumber = $coupletNumber;
  1445. $receipt->update ();
  1446. $receiptDetail = new receiptDetail ();
  1447. $receiptDetail->delete ( array (
  1448. 'where' => 'rid=' . $rid
  1449. ) );
  1450. // 报销详情
  1451. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1452. $receiptDetail = new receiptDetail ();
  1453. $receiptDetail->staff = $this->staff [0] ['sid'];
  1454. $receiptDetail->item = $value ['name'];
  1455. $receiptDetail->itemCategory = $this->AGENCY;
  1456. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1457. $receiptDetail->date = date ( "Y-m-d" );
  1458. $receiptDetail->cid = $cid;
  1459. $receiptDetail->rid = $rid;
  1460. $receiptDetail->status = 4;
  1461. $receiptDetail->insert ();
  1462. }
  1463. // 附件
  1464. if (! empty ( $enclosurName )) {
  1465. $enclosurArray = explode ( '-', $enclosurName );
  1466. foreach ( $enclosurArray as $value ) {
  1467. $enclosur = new enclosur ();
  1468. $enclosur->name = $value;
  1469. $enclosur->rid = $rid;
  1470. $enclosur->insert ();
  1471. }
  1472. }
  1473. }
  1474. return "/saeaBorad";
  1475. }
  1476. function remitApproval() {
  1477. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1478. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  1479. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  1480. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  1481. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1482. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  1483. if (empty ( $status ))
  1484. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  1485. $vidList = array ();
  1486. $button = 0;
  1487. Doo::loadModel ( 'verify' );
  1488. Doo::loadModel ( 'receipt' );
  1489. Doo::loadModel ( 'staff' );
  1490. $staff = new staff ();
  1491. $receipt = new receipt ();
  1492. $verify = new verify ();
  1493. Doo::loadModel ( 'L_category' );
  1494. $Lcategory = new L_category ();
  1495. Doo::loadModel ( 'enclosur' );
  1496. $enclosur = new enclosur ();
  1497. // user verify ID
  1498. $verifyDetail = $verify->find ( array (
  1499. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  1500. 'asArray' => true
  1501. ) );
  1502. foreach ( $verifyDetail as $key => $value ) {
  1503. array_push ( $vidList, $value ['vid'] );
  1504. }
  1505. $vid = implode ( ",", $vidList );
  1506. if (empty ( $verifyDetail ))
  1507. $vid = 0;
  1508. $categoryList = $Lcategory->find ( array (
  1509. 'asArray' => true
  1510. ) );
  1511. $staffList = $staff->find ( array (
  1512. 'where' => 'cid=' . $cid,
  1513. 'asArray' => true
  1514. ) );
  1515. $ap = "";
  1516. if ($status == 4) {
  1517. $ap = 4;
  1518. $status = 2;
  1519. }
  1520. // get Receipt By verifyID status 2
  1521. $receiptList = $receipt->find ( array (
  1522. 'where' => 'rid =' . $rid . ' and status=2',
  1523. 'desc' => 'rid',
  1524. 'asArray' => true
  1525. ) );
  1526. if (empty ( $receiptList )) {
  1527. die ( 'illegal request' );
  1528. }
  1529. $Locate = 0;
  1530. $roleId = 0;
  1531. if ($ap == 4)
  1532. $status = 4;
  1533. foreach ( $receiptList as $key => $value ) {
  1534. $receiptList [$key] ['Locate'] = $Locate;
  1535. $Locate ++;
  1536. $receiptList [$key] ['reviseDetail'] = array ();
  1537. if (! empty ( $value ['reviseDetail'] ))
  1538. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1539. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1540. $categoryDetil = $Lcategory->getOne ( array (
  1541. 'where' => 'cid=' . $value ['cid'],
  1542. 'asArray' => true
  1543. ) );
  1544. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1545. // 检测编辑状态
  1546. $verifyList = $verify->getOne ( array (
  1547. 'where' => 'vid=' . $value ['verify'],
  1548. 'asArray' => true
  1549. ) );
  1550. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1551. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1552. Doo::loadModel ( 'role' );
  1553. $role = new role ();
  1554. // print_r($verifyList);
  1555. $flag = true;
  1556. $roleKey = 0;
  1557. $endStaffArray = array ();
  1558. $roleArrayCopy = array ();
  1559. foreach ( $verifyList as $k => $v ) {
  1560. // init verifyStaff
  1561. if ($v [1] == 'ROLE') {
  1562. if (! empty ( $verifyStaff )) {
  1563. $endStaffArray = end ( $verifyStaff );
  1564. if ($v [0] == $endStaffArray ['nextStaff']) {
  1565. $roleId = $v [0];
  1566. }
  1567. }
  1568. $roleVerify = json_decode ( $v [3], true );
  1569. $roleKey = $k;
  1570. $roleArray = array ();
  1571. $rolename = $role->getOne ( array (
  1572. 'where' => 'rid=' . $v [0],
  1573. 'asArray' => true
  1574. ) );
  1575. foreach ( $roleVerify as $o => $p ) {
  1576. $staffID = explode ( '_', $p );
  1577. $staffInfo = $staff->getOne ( array (
  1578. 'where' => 'sid=' . $staffID [0],
  1579. 'asArray' => true
  1580. ) );
  1581. // print_r($staffID);
  1582. $exp = array (
  1583. 0 => $staffInfo ['sid'],
  1584. 1 => $staffID [1],
  1585. 2 => $staffInfo ['avatar'],
  1586. 'date' => '',
  1587. 'date' => '',
  1588. 'opinion' => '',
  1589. 'status' => '',
  1590. 'rolename' => $rolename ['name']
  1591. );
  1592. array_push ( $roleArray, $exp );
  1593. }
  1594. $roleArrayCopy [$v [0]] = $roleArray;
  1595. // $verifyList[$k]['roleArray']=$roleArray;
  1596. }
  1597. // print_r($roleArray);
  1598. $verifyList [$k] ['date'] = "";
  1599. $verifyList [$k] ['opinion'] = "";
  1600. $verifyList [$k] ['status'] = "";
  1601. if (empty ( $verifyStaff )) {
  1602. $verifyList [$k] ['date'] = "";
  1603. $verifyList [$k] ['opinion'] = "";
  1604. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1605. $verifyList [$k] ['status'] = 4;
  1606. $button = 4;
  1607. $flag = false;
  1608. }
  1609. } else {
  1610. foreach ( $verifyStaff as $m => $u ) {
  1611. if ($v [0] == $m) {
  1612. $verifyList [$k] ['date'] = $u ['date'];
  1613. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1614. $verifyList [$k] ['status'] = $u ['status'];
  1615. $flag = false;
  1616. break;
  1617. }
  1618. }
  1619. $endStaffArray = end ( $verifyStaff );
  1620. if (isset ( $endStaffArray ['ROLE'] )) {
  1621. } else {
  1622. $endKey = key ( $verifyStaff );
  1623. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  1624. $button = 4;
  1625. $verifyList [$k] ['status'] = 4;
  1626. }
  1627. }
  1628. }
  1629. }
  1630. $rolename ['name'] = '';
  1631. if (! empty ( $roleId )) {
  1632. Doo::loadModel ( 'role' );
  1633. $role = new role ();
  1634. $rolename = $role->getOne ( array (
  1635. 'where' => 'rid=' . $roleId,
  1636. 'asArray' => true
  1637. ) );
  1638. }
  1639. if (! empty ( $verifyStaff ))
  1640. $endStaffArray = end ( $verifyStaff );
  1641. $KOP = false;
  1642. foreach ( $roleArrayCopy as $P => $A ) {
  1643. foreach ( $A as $MKI => $AVL ) {
  1644. if (! empty ( $verifyStaff )) {
  1645. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1646. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1647. $button = 4;
  1648. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1649. }
  1650. foreach ( $verifyStaff as $m => $u ) {
  1651. $AVLFK = $AVL [0] . '_R';
  1652. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1653. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1654. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1655. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1656. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1657. break;
  1658. }
  1659. }
  1660. } else {
  1661. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1662. $button = 4;
  1663. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1664. }
  1665. }
  1666. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1667. $KOP = true;
  1668. }
  1669. }
  1670. foreach ( $roleArrayCopy as $k => $v ) {
  1671. foreach ( $verifyList as $m => $n ) {
  1672. if ($n [0] == $k) {
  1673. array_splice ( $verifyList, $m, 1, $v );
  1674. }
  1675. }
  1676. }
  1677. $receiptList [$key] ['verifyList'] = $verifyList;
  1678. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1679. 'where' => 'sid=' . $value ['staff'],
  1680. 'asArray' => true
  1681. ) );
  1682. $receiptList [$key] ['button'] = $button;
  1683. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1684. }
  1685. $mothHtml = "";
  1686. for($i = 1; $i <= 12; $i ++) {
  1687. if ($month == $i)
  1688. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  1689. else
  1690. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  1691. }
  1692. // 获取审批日志
  1693. Doo::loadModel ( 'receiptLog' );
  1694. $receiptLog = new receiptLog ();
  1695. $rlList = array ();
  1696. $rlInfo = $receiptLog->getOne ( array (
  1697. 'where' => 'rid=' . $rid . ' and status=4',
  1698. 'asArray' => true
  1699. ) );
  1700. $tijdate = $receiptLog->getOne ( array (
  1701. 'where' => 'rid=' . $rid . ' and status=2',
  1702. 'asc' => 'rlid',
  1703. 'asArray' => true
  1704. ) );
  1705. if (! empty ( $rlInfo )) {
  1706. $rlList = $receiptLog->find ( array (
  1707. 'where' => 'rid=' . $rid,
  1708. 'asc' => 'rlid',
  1709. 'asArray' => true
  1710. ) );
  1711. }
  1712. $receiptList [0] ['rlList'] = $rlList;
  1713. $enclosurList = $enclosur->find ( array (
  1714. 'where' => 'rid=' . $rid,
  1715. 'asArray' => true
  1716. ) );
  1717. $enclosurHtml = '';
  1718. foreach ( $enclosurList as $value ) {
  1719. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  1720. }
  1721. // print_r($receiptList);
  1722. $data ['enclosurHtml'] = $enclosurHtml;
  1723. $data ['rolename'] = $rolename ['name'];
  1724. $data ['datetij'] = $tijdate ['date'];
  1725. $data ['mothHtml'] = $mothHtml;
  1726. $data ['rid'] = $rid;
  1727. $data ['receiptList'] = $receiptList;
  1728. $data ['receiptApprovalCount'] = count ( $receiptList );
  1729. $data ['status'] = $status;
  1730. $data ['year'] = $year;
  1731. $data ['categoryList'] = $categoryList;
  1732. $data ['staffList'] = $staffList;
  1733. $data ['cid'] = $cid;
  1734. $data ['sid'] = $sid;
  1735. $data ['ap'] = $ap;
  1736. $data ['memu'] = "receipt";
  1737. $data ['staff'] = $this->staff;
  1738. $data ['receiptMemu'] = 'approvalExpenses';
  1739. $data ['verifyId'] = $this->verifyId;
  1740. $data ['executeId'] = $this->executeId;
  1741. $this->render ( "/admin/remitApproval", $data );
  1742. }
  1743. function saeaLoanAdd() {
  1744. Doo::loadModel ( 'verify' );
  1745. $verify = new verify ();
  1746. Doo::loadModel ( "role" );
  1747. $role = new role ();
  1748. Doo::loadModel ( 'L_category' );
  1749. $lCategory = new L_category ();
  1750. $veList = $verify->getVerifyBySubordinate('LOAN');
  1751. $data ['category'] = $lCategory->find ( array (
  1752. 'asArray' => true
  1753. ) );
  1754. $data ['veList'] = $veList;
  1755. $data ['memu'] = "receipt";
  1756. $data ['staff'] = $this->staff;
  1757. $data ['receiptMemu'] = 'saeaBorad';
  1758. $data ['verifyId'] = $this->verifyId;
  1759. $data ['executeId'] = $this->executeId;
  1760. $this->render ( "/admin/saeaLoanAdd", $data );
  1761. }
  1762. function saeaLoanAddDo() {
  1763. $agency = $this->get_args ( 'agency' );
  1764. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1765. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1766. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1767. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1768. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1769. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1770. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1771. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1772. // die;
  1773. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1774. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1775. header ( 'Content-Type:text/html;charset=utf-8' );
  1776. die ( '请填写联行号' );
  1777. }
  1778. Doo::loadModel ( 'receipt' );
  1779. Doo::loadModel ( 'receiptDetail' );
  1780. Doo::loadModel ( 'accountItem' );
  1781. $accountItem = new accountItem ();
  1782. $receipt = new receipt ();
  1783. Doo::loadModel ( 'loanReceipt' );
  1784. $loanReceipt = new loanReceipt ();
  1785. Doo::loadModel ( 'execute' );
  1786. $execute = new execute ();
  1787. Doo::loadModel ( 'enclosur' );
  1788. $executeDetail = $execute->getOne ( array (
  1789. 'where' => 'mold="借款执行人"',
  1790. 'asArray' => true
  1791. ) );
  1792. $aItem = $accountItem->find ( array (
  1793. 'asArray' => true
  1794. ) );
  1795. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1796. $ag = $tr = $ta = $ot = 0;
  1797. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1798. array_push ( $accountJson ['借款费用'], array (
  1799. 'aid' => 0,
  1800. 'name' => '申请金额',
  1801. 'price' => number_format ( $agency, 2, '.', '' )
  1802. ) );
  1803. $sum += $agency;
  1804. $agencySum += $agency;
  1805. $accountJson ['cSum'] = array (
  1806. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1807. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1808. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1809. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1810. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1811. );
  1812. // 借款数据备份
  1813. $loanReceipt->loanItem = json_encode ( $accountJson );
  1814. $loanReceipt->staff = $this->staff [0] ['sid'];
  1815. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1816. $loanReceipt->date = date ( "Y-m-d" );
  1817. $loanReceipt->cid = $cid;
  1818. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1819. $loanReceipt->status = 5;
  1820. $loanReceipt->Rtype = 1;
  1821. $loanReceipt->verify = $verify;
  1822. $receipt->receiptOrder = $receipt->receiptOrder;
  1823. // 添加HTML换行符
  1824. // var_dump($explanation);
  1825. $order = array (
  1826. "\r\n",
  1827. "\n",
  1828. "\r"
  1829. );
  1830. $replace = '<br/>';
  1831. $explanation = str_replace ( $order, $replace, $explanation );
  1832. // $explanation=str_replace('\r',"<br/>",$explanation);
  1833. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  1834. $loanReceipt->explanation = $explanation;
  1835. $loanRid = $loanReceipt->insert ();
  1836. // 报销单
  1837. $receipt->loanItem = json_encode ( $accountJson );
  1838. $receipt->staff = $this->staff [0] ['sid'];
  1839. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1840. $receipt->date = date ( "Y-m-d" );
  1841. $receipt->cid = $cid;
  1842. // 特殊状态
  1843. $receipt->status = 5;
  1844. $receipt->Rtype = 1;
  1845. $receipt->loanRid = $loanRid;
  1846. // 修改审批流程加入角色
  1847. $receipt->verify = $verify;
  1848. $receipt->executeCopy = $executeDetail ['staff'];
  1849. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  1850. $receipt->explanation = $explanation;
  1851. $receipt->remittanceName = $remittanceName;
  1852. $receipt->bankName = $bankName;
  1853. $receipt->bankNumber = $bankNumber;
  1854. $receipt->remittanceBankType = $remittanceBankType;
  1855. if ($remittanceBankType == 1)
  1856. $receipt->coupletNumber = $coupletNumber;
  1857. $rid = $receipt->insert ();
  1858. return "/saeaBorad";
  1859. } else
  1860. die ( 'illegal request' );
  1861. }
  1862. function saeaLoanEdi() {
  1863. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1864. Doo::loadClass ( 'XDeode' );
  1865. $XDeode = new XDeode ( 7 );
  1866. $rid = $XDeode->decode ( $ridKey );
  1867. if (! is_numeric ( $rid ))
  1868. die ( 'illegal request' );
  1869. Doo::loadModel ( 'verify' );
  1870. $verify = new verify ();
  1871. Doo::loadModel ( "role" );
  1872. $role = new role ();
  1873. Doo::loadModel ( 'L_category' );
  1874. $lCategory = new L_category ();
  1875. Doo::loadModel ( 'receipt' );
  1876. $receipt = new receipt ();
  1877. $receiptInfo = $receipt->getOne ( array (
  1878. 'where' => 'rid=' . $rid,
  1879. 'asArray' => true
  1880. ) );
  1881. $veList = $verify->find ( array (
  1882. 'where'=>'subordinate like "%LOAN%"',
  1883. 'asArray' => true
  1884. ) );
  1885. foreach ( $veList as $key => $value ) {
  1886. $v = json_decode ( $value ['staff'] );
  1887. $list = array ();
  1888. foreach ( $v as $n => $m ) {
  1889. if ($m ['1'] == 'ROLE') {
  1890. $roleInfo = $role->getOne ( array (
  1891. 'where' => 'rid=' . $m [0],
  1892. 'asArray' => true
  1893. ) );
  1894. $v [$n] [1] = $roleInfo ['name'];
  1895. array_push ( $list, $roleInfo ['name'] );
  1896. } else {
  1897. array_push ( $list, $v [$n] [1] );
  1898. }
  1899. }
  1900. $veList [$key] ['staff'] = implode ( '>', $list );
  1901. }
  1902. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  1903. // print_r($receiptInfo);
  1904. $data ['receiptInfo'] = $receiptInfo;
  1905. $data ['category'] = $lCategory->find ( array (
  1906. 'asArray' => true
  1907. ) );
  1908. $data ['veList'] = $veList;
  1909. $data ['ridKey'] = $ridKey;
  1910. $data ['memu'] = "receipt";
  1911. $data ['staff'] = $this->staff;
  1912. $data ['receiptMemu'] = 'saeaBorad';
  1913. $data ['verifyId'] = $this->verifyId;
  1914. $data ['executeId'] = $this->executeId;
  1915. $this->render ( "/admin/saeaLoanEdi", $data );
  1916. }
  1917. function saeaLoanEdiDo() {
  1918. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1919. $agency = $this->get_args ( 'agency' );
  1920. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1921. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1922. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1923. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1924. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1925. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1926. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1927. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1928. // die;
  1929. Doo::loadClass ( 'XDeode' );
  1930. $XDeode = new XDeode ( 7 );
  1931. $rid = $XDeode->decode ( $ridKey );
  1932. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1933. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1934. header ( 'Content-Type:text/html;charset=utf-8' );
  1935. die ( '请填写联行号' );
  1936. }
  1937. Doo::loadModel ( 'receipt' );
  1938. Doo::loadModel ( 'receiptDetail' );
  1939. Doo::loadModel ( 'accountItem' );
  1940. $accountItem = new accountItem ();
  1941. $receipt = new receipt ();
  1942. Doo::loadModel ( 'loanReceipt' );
  1943. $loanReceipt = new loanReceipt ();
  1944. Doo::loadModel ( 'enclosur' );
  1945. Doo::loadModel ( 'execute' );
  1946. $execute = new execute ();
  1947. $executeDetail = $execute->getOne ( array (
  1948. 'where' => 'mold="借款执行人"',
  1949. 'asArray' => true
  1950. ) );
  1951. $receiptDetail = $receipt->getOne ( array (
  1952. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1953. 'asArray' => true
  1954. ) );
  1955. if (empty ( $receiptDetail ))
  1956. die ( '参数错误' );
  1957. $aItem = $accountItem->find ( array (
  1958. 'asArray' => true
  1959. ) );
  1960. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1961. $ag = $tr = $ta = $ot = 0;
  1962. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1963. array_push ( $accountJson ['借款费用'], array (
  1964. 'aid' => 0,
  1965. 'name' => '申请金额',
  1966. 'price' => number_format ( $agency, 2, '.', '' )
  1967. ) );
  1968. $sum += $agency;
  1969. $agencySum += $agency;
  1970. $accountJson ['cSum'] = array (
  1971. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1972. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1973. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1974. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1975. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1976. );
  1977. // 报销单
  1978. $receipt->loanItem = json_encode ( $accountJson );
  1979. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1980. $receipt->cid = $cid;
  1981. // 特殊状态
  1982. // 修改审批流程加入角色
  1983. if ($receiptDetail ['status'] != 4)
  1984. $receipt->verify = $verify;
  1985. $order = array (
  1986. "\r\n",
  1987. "\n",
  1988. "\r"
  1989. );
  1990. $replace = '<br/>';
  1991. $explanation = str_replace ( $order, $replace, $explanation );
  1992. $receipt->explanation = $explanation;
  1993. $receipt->remittanceName = $remittanceName;
  1994. $receipt->bankName = $bankName;
  1995. $receipt->bankNumber = $bankNumber;
  1996. $receipt->remittanceBankType = $remittanceBankType;
  1997. if ($remittanceBankType == 1)
  1998. $receipt->coupletNumber = $coupletNumber;
  1999. $receipt->update ( array (
  2000. 'where' => 'rid=' . $rid
  2001. ) );
  2002. // 借款数据更新
  2003. $loanReceipt->loanItem = json_encode ( $accountJson );
  2004. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  2005. $loanReceipt->cid = $cid;
  2006. if ($receiptDetail ['status'] != 4)
  2007. $loanReceipt->verify = $verify;
  2008. $loanReceipt->explanation = $explanation;
  2009. $receipt->executeCopy = $executeDetail ['staff'];
  2010. $loanReceipt->update ( array (
  2011. 'where' => 'rid=' . $receiptDetail ['loanRid']
  2012. ) );
  2013. }
  2014. return "/saeaBorad";
  2015. }
  2016. function saeaLoanReceiptAdd() {
  2017. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2018. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  2019. Doo::loadModel ( 'receipt' );
  2020. $receipt = new receipt ();
  2021. Doo::loadModel ( 'loanReceipt' );
  2022. $loanReceipt = new loanReceipt ();
  2023. Doo::loadModel ( 'L_category' );
  2024. $Lcategory = new L_category ();
  2025. Doo::loadModel ( 'verify' );
  2026. Doo::loadModel ( 'statistics' );
  2027. $statistics = new statistics ();
  2028. $verify = new verify ();
  2029. Doo::loadModel ( 'staff' );
  2030. $staff = new staff ();
  2031. $receiptDetail = $receipt->getOne ( array (
  2032. 'where' => 'rid=' . $rid,
  2033. 'desc' => 'rid',
  2034. 'asArray' => true
  2035. ) );
  2036. $receiptList = $loanReceipt->find ( array (
  2037. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  2038. 'desc' => 'rid',
  2039. 'asArray' => true
  2040. ) );
  2041. $Locate = 0;
  2042. $roleId = 0;
  2043. $button = 0;
  2044. foreach ( $receiptList as $key => $value ) {
  2045. $receiptList [$key] ['Locate'] = $Locate;
  2046. $Locate ++;
  2047. $receiptList [$key] ['reviseDetail'] = array ();
  2048. if (! empty ( $value ['reviseDetail'] ))
  2049. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2050. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2051. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2052. $categoryDetil = $Lcategory->getOne ( array (
  2053. 'where' => 'cid=' . $value ['cid'],
  2054. 'asArray' => true
  2055. ) );
  2056. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2057. // 检测编辑状态
  2058. $verifyList = $verify->getOne ( array (
  2059. 'where' => 'vid=' . $value ['verify'],
  2060. 'asArray' => true
  2061. ) );
  2062. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2063. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2064. Doo::loadModel ( 'role' );
  2065. $role = new role ();
  2066. $flag = true;
  2067. $roleKey = 0;
  2068. $endStaffArray = array ();
  2069. $roleArrayCopy = array ();
  2070. foreach ( $verifyList as $k => $v ) {
  2071. // init verifyStaff
  2072. if ($v [1] == 'ROLE') {
  2073. if (! empty ( $verifyStaff )) {
  2074. $endStaffArray = end ( $verifyStaff );
  2075. // if ($v[0]==$endStaffArray['nextStaff']){
  2076. // $roleId=$v[0];
  2077. // }
  2078. }
  2079. $roleVerify = json_decode ( $v [3], true );
  2080. $roleKey = $k;
  2081. $roleArray = array ();
  2082. $rolename = $role->getOne ( array (
  2083. 'where' => 'rid=' . $v [0],
  2084. 'asArray' => true
  2085. ) );
  2086. foreach ( $roleVerify as $o => $p ) {
  2087. $staffID = explode ( '_', $p );
  2088. $staffInfo = $staff->getOne ( array (
  2089. 'where' => 'sid=' . $staffID [0],
  2090. 'asArray' => true
  2091. ) );
  2092. // print_r($staffID);
  2093. $exp = array (
  2094. 0 => $staffInfo ['sid'],
  2095. 1 => $staffID [1],
  2096. 2 => $staffInfo ['avatar'],
  2097. 'date' => '',
  2098. 'date' => '',
  2099. 'opinion' => '',
  2100. 'status' => '',
  2101. 'rolename' => $rolename ['name']
  2102. );
  2103. array_push ( $roleArray, $exp );
  2104. }
  2105. $roleArrayCopy [$v [0]] = $roleArray;
  2106. // $verifyList[$k]['roleArray']=$roleArray;
  2107. }
  2108. $verifyList [$k] ['date'] = "";
  2109. $verifyList [$k] ['opinion'] = "";
  2110. $verifyList [$k] ['status'] = "";
  2111. if (empty ( $verifyStaff )) {
  2112. $verifyList [$k] ['date'] = "";
  2113. $verifyList [$k] ['opinion'] = "";
  2114. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2115. $verifyList [$k] ['status'] = 4;
  2116. $flag = false;
  2117. }
  2118. } else {
  2119. foreach ( $verifyStaff as $m => $u ) {
  2120. if ($v [0] == $m) {
  2121. $verifyList [$k] ['date'] = $u ['date'];
  2122. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2123. $verifyList [$k] ['status'] = $u ['status'];
  2124. $flag = false;
  2125. break;
  2126. }
  2127. }
  2128. $endStaffArray = end ( $verifyStaff );
  2129. if (isset ( $endStaffArray ['ROLE'] )) {
  2130. } else {
  2131. // $endKey=key($verifyStaff);
  2132. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2133. // $button=4;
  2134. // $verifyList[$k]['status']=4;
  2135. // }
  2136. }
  2137. }
  2138. }
  2139. $rolename ['name'] = '';
  2140. if (! empty ( $roleId )) {
  2141. Doo::loadModel ( 'role' );
  2142. $role = new role ();
  2143. $rolename = $role->getOne ( array (
  2144. 'where' => 'rid=' . $roleId,
  2145. 'asArray' => true
  2146. ) );
  2147. }
  2148. if (! empty ( $verifyStaff ))
  2149. $endStaffArray = end ( $verifyStaff );
  2150. $KOP = false;
  2151. foreach ( $roleArrayCopy as $P => $A ) {
  2152. foreach ( $A as $MKI => $AVL ) {
  2153. if (! empty ( $verifyStaff )) {
  2154. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2155. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2156. $button = 4;
  2157. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2158. }
  2159. foreach ( $verifyStaff as $m => $u ) {
  2160. $AVLFK = $AVL [0] . '_R';
  2161. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2162. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2163. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2164. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2165. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2166. break;
  2167. }
  2168. }
  2169. } else {
  2170. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2171. $button = 4;
  2172. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2173. }
  2174. }
  2175. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2176. $KOP = true;
  2177. }
  2178. }
  2179. foreach ( $roleArrayCopy as $k => $v ) {
  2180. foreach ( $verifyList as $m => $n ) {
  2181. if ($n [0] == $k) {
  2182. array_splice ( $verifyList, $m, 1, $v );
  2183. }
  2184. }
  2185. }
  2186. $receiptList [$key] ['verifyList'] = $verifyList;
  2187. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2188. 'where' => 'sid=' . $value ['staff'],
  2189. 'asArray' => true
  2190. ) );
  2191. $receiptList [$key] ['button'] = $button;
  2192. //
  2193. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  2194. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2195. }
  2196. $data ['receiptList'] = $receiptList;
  2197. $data ['receiptDetail'] = $receiptDetail;
  2198. Doo::loadModel ( 'L_category' );
  2199. $lCategory = new L_category ();
  2200. Doo::loadModel ( 'accountItem' );
  2201. $accountItem = new accountItem ();
  2202. $acItem = $accountItem->find ( array (
  2203. 'asArray' => true
  2204. ) );
  2205. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  2206. $data ['rid'] = $rid;
  2207. $data ['category'] = $lCategory->find ( array (
  2208. 'asArray' => true
  2209. ) );
  2210. $data ['veList'] = $veList;
  2211. $data ['acItem'] = $acItem;
  2212. $data['itineraryDate']=$this->_itineraryDateMin();
  2213. $data ['memu'] = "receipt";
  2214. $data ['staff'] = $this->staff;
  2215. $data ['receiptMemu'] = 'saeaBorad';
  2216. $data ['verifyId'] = $this->verifyId;
  2217. $data ['executeId'] = $this->executeId;
  2218. $data['receiptClass']=$receiptClass;
  2219. if($receiptClass=='trave'){
  2220. $this->render ( "/receipt/feeLoanReceiptTrave", $data );
  2221. }else{
  2222. $this->render ( "/receipt/feeLoanReceipt", $data );
  2223. }
  2224. }
  2225. function saeaLoanReceiptAddDo() {
  2226. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  2227. $agency = $this->get_args ( 'agency' );
  2228. $travel = $this->get_args ( 'travel' );
  2229. $train = $this->get_args ( 'train' );
  2230. $other = $this->get_args ( 'other' );
  2231. $inttrain = $this->get_args ( 'inttrain' );
  2232. $itinerary = $_POST['itinerary'];//$this->get_args ( 'itinerary' ) ? $this->get_args ( 'itinerary' ) : "";
  2233. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  2234. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2235. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  2236. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  2237. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  2238. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2239. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2240. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2241. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2242. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2243. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  2244. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2245. header ( 'Content-Type:text/html;charset=utf-8' );
  2246. die ( '请填写联行号' );
  2247. }
  2248. if($receiptClass=='agency'){
  2249. $receiptClass=1;
  2250. }elseif($receiptClass=='trave'){
  2251. $receiptClass=2;
  2252. if($this->_verificationItinerary($itinerary)){
  2253. header ( 'Content-Type:text/html;charset=utf-8' );
  2254. die ( '已申请过类此日期的行程' );
  2255. }
  2256. }elseif($receiptClass=='internalTrain'){
  2257. $receiptClass=3;
  2258. }else{
  2259. header ( 'Content-Type:text/html;charset=utf-8' );
  2260. die ( '借款报销单分类不正确' );
  2261. }
  2262. Doo::loadModel ( 'receipt' );
  2263. Doo::loadModel ( 'receiptDetail' );
  2264. Doo::loadModel ( 'accountItem' );
  2265. $accountItem = new accountItem ();
  2266. $receipt = new receipt ();
  2267. Doo::loadModel ( 'enclosur' );
  2268. Doo::loadModel ( 'execute' );
  2269. $execute = new execute ();
  2270. $executeDetail = $execute->getOne ( array (
  2271. 'where' => 'mold="借款费用执行人"',
  2272. 'asArray' => true
  2273. ) );
  2274. $receiptDet = $receipt->getOne ( array (
  2275. 'where' => 'rid=' . $rid,
  2276. 'asArray' => true
  2277. ) );
  2278. // if(!empty($receiptDetail))
  2279. // return "/referReceipt/".$receiptDetail['rid'];
  2280. $aItem = $accountItem->find ( array (
  2281. 'asArray' => true
  2282. ) );
  2283. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2284. $ag = $tr = $ta = $ot =$it = 0;
  2285. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  2286. foreach ( $aItem as $key => $value ) {
  2287. if ($value ['category'] == $this->AGENCY) {
  2288. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  2289. array_push ( $accountJson [$this->AGENCY], array (
  2290. 'aid' => $value ['aid'],
  2291. 'name' => $value ['name'],
  2292. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  2293. ) );
  2294. $sum += $agency [$ag];
  2295. $agencySum += $agency [$ag];
  2296. }
  2297. $ag ++;
  2298. }
  2299. if ($value ['category'] == $this->TRAVEL) {
  2300. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  2301. array_push ( $accountJson [$this->TRAVEL], array (
  2302. 'aid' => $value ['aid'],
  2303. 'name' => $value ['name'],
  2304. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  2305. ) );
  2306. $sum += $travel [$tr];
  2307. $travelSum += $travel [$tr];
  2308. }
  2309. $tr ++;
  2310. }
  2311. if ($value ['category'] == $this->INTTRAIN) {
  2312. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  2313. array_push ( $accountJson [$this->INTTRAIN], array (
  2314. 'aid' => $value ['aid'],
  2315. 'name' => $value ['name'],
  2316. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  2317. ) );
  2318. $sum += $inttrain [$it];
  2319. $inttrainSum += $inttrain [$it];
  2320. }
  2321. $it ++;
  2322. }
  2323. if ($value ['category'] == $this->TRAIN) {
  2324. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  2325. array_push ( $accountJson [$this->TRAIN], array (
  2326. 'aid' => $value ['aid'],
  2327. 'name' => $value ['name'],
  2328. 'price' => number_format ( $train [$ta], 2, '.', '' )
  2329. ) );
  2330. $sum += $train [$ta];
  2331. $trainSum += $train [$ta];
  2332. }
  2333. $ta ++;
  2334. }
  2335. if ($value ['category'] == $this->OTHER) {
  2336. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  2337. array_push ( $accountJson [$this->OTHER], array (
  2338. 'aid' => $value ['aid'],
  2339. 'name' => $value ['name'],
  2340. 'price' => number_format ( $other [$ot], 2, '.', '' )
  2341. ) );
  2342. $sum += $other [$ot];
  2343. $otherSum += $other [$ot];
  2344. }
  2345. $ot ++;
  2346. }
  2347. }
  2348. $accountJson ['cSum'] = array (
  2349. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2350. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2351. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2352. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  2353. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2354. );
  2355. // 报销单
  2356. $receipt->accountItem = json_encode ( $accountJson );
  2357. $receipt->staff = $this->staff [0] ['sid'];
  2358. $receipt->loanSum = $receiptDet ['sum'];
  2359. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2360. $receipt->date = date ( "Y-m-d" );
  2361. $receipt->pastDate = '0000-00-00';
  2362. $receipt->cid = $cid;
  2363. $receipt->status = 7;
  2364. $receipt->receiptClass=$receiptClass;
  2365. if($receiptClass==2){
  2366. $receipt->itinerary=$itinerary;
  2367. $this->_storageItinerary($itinerary, $rid);
  2368. }
  2369. // 修改审批流程加入角色
  2370. $receipt->verify = $verify;
  2371. $receipt->verifyStaff = '';
  2372. $receipt->executeStaff = '';
  2373. $receipt->executeCopy = $executeDetail ['staff'];
  2374. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  2375. $receipt->explanation = $explanation;
  2376. $receipt->remittanceName = $remittanceName;
  2377. $receipt->bankName = $bankName;
  2378. $receipt->bankNumber = $bankNumber;
  2379. $receipt->remittanceBankType = $remittanceBankType;
  2380. if ($remittanceBankType == 1)
  2381. $receipt->coupletNumber = $coupletNumber;
  2382. $receipt->update ( array (
  2383. 'where' => 'rid=' . $rid
  2384. ) );
  2385. // 附件
  2386. if (! empty ( $enclosurName )) {
  2387. $enclosurArray = explode ( '-', $enclosurName );
  2388. foreach ( $enclosurArray as $value ) {
  2389. $enclosur = new enclosur ();
  2390. $enclosur->name = $value;
  2391. $enclosur->rid = $rid;
  2392. $enclosur->insert ();
  2393. }
  2394. // print_r($enclosurArray);die;
  2395. }
  2396. // 报销详情
  2397. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  2398. $receiptDetail = new receiptDetail ();
  2399. $receiptDetail->staff = $this->staff [0] ['sid'];
  2400. $receiptDetail->item = $value ['name'];
  2401. $receiptDetail->itemCategory = $this->AGENCY;
  2402. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2403. $receiptDetail->date = date ( "Y-m-d" );
  2404. $receiptDetail->cid = $cid;
  2405. $receiptDetail->rid = $rid;
  2406. $receiptDetail->status = 4;
  2407. $receiptDetail->insert ();
  2408. }
  2409. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  2410. $receiptDetail = new receiptDetail ();
  2411. $receiptDetail->staff = $this->staff [0] ['sid'];
  2412. $receiptDetail->item = $value ['name'];
  2413. $receiptDetail->itemCategory = $this->TRAVEL;
  2414. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2415. $receiptDetail->date = date ( "Y-m-d" );
  2416. $receiptDetail->cid = $cid;
  2417. $receiptDetail->rid = $rid;
  2418. $receiptDetail->status = 4;
  2419. $receiptDetail->insert ();
  2420. }
  2421. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  2422. $receiptDetail = new receiptDetail ();
  2423. $receiptDetail->staff = $this->staff [0] ['sid'];
  2424. $receiptDetail->item = $value ['name'];
  2425. $receiptDetail->itemCategory = $this->TRAIN;
  2426. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2427. $receiptDetail->date = date ( "Y-m-d" );
  2428. $receiptDetail->cid = $cid;
  2429. $receiptDetail->rid = $rid;
  2430. $receiptDetail->status = 4;
  2431. $receiptDetail->insert ();
  2432. }
  2433. //内训
  2434. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  2435. $receiptDetail = new receiptDetail ();
  2436. $receiptDetail->staff = $this->staff [0] ['sid'];
  2437. $receiptDetail->item = $value ['name'];
  2438. $receiptDetail->itemCategory = $this->INTTRAIN;
  2439. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2440. $receiptDetail->date = date ( "Y-m-d" );
  2441. $receiptDetail->cid = $cid;
  2442. $receiptDetail->rid = $rid;
  2443. $receiptDetail->status = 4;
  2444. $receiptDetail->insert ();
  2445. }
  2446. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  2447. $receiptDetail = new receiptDetail ();
  2448. $receiptDetail->staff = $this->staff [0] ['sid'];
  2449. $receiptDetail->item = $value ['name'];
  2450. $receiptDetail->itemCategory = $this->OTHER;
  2451. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2452. $receiptDetail->date = date ( "Y-m-d" );
  2453. $receiptDetail->cid = $cid;
  2454. $receiptDetail->rid = $rid;
  2455. $receiptDetail->status = 4;
  2456. $receiptDetail->insert ();
  2457. }
  2458. return "/saeaBorad";
  2459. }
  2460. return "/saeaLoanReceiptAdd/" . $rid;
  2461. }
  2462. function saeaLoanReceiptEdi() {
  2463. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2464. Doo::loadClass ( 'XDeode' );
  2465. $XDeode = new XDeode ( 7 );
  2466. $rid = $XDeode->decode ( $ridKey );
  2467. if (! is_numeric ( $rid ))
  2468. die ( 'illegal request' );
  2469. Doo::loadModel ( 'accountItem' );
  2470. Doo::loadModel ( 'verify' );
  2471. Doo::loadModel ( 'receipt' );
  2472. $receipt = new receipt ();
  2473. $verify = new verify ();
  2474. $accountItem = new accountItem ();
  2475. Doo::loadModel ( 'L_category' );
  2476. $Lcategory = new L_category ();
  2477. Doo::loadModel ( "role" );
  2478. $role = new role ();
  2479. Doo::loadModel ( 'loanReceipt' );
  2480. $loanReceipt = new loanReceipt ();
  2481. Doo::loadModel ( 'staff' );
  2482. $staff = new staff ();
  2483. $receiptDetail = $receipt->getOne ( array (
  2484. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  2485. 'asArray' => true
  2486. ) );
  2487. if (empty ( $receiptDetail ))
  2488. return "/saeaBorad";
  2489. $receiptList = $loanReceipt->find ( array (
  2490. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  2491. 'desc' => 'rid',
  2492. 'asArray' => true
  2493. ) );
  2494. $Locate = 0;
  2495. $roleId = 0;
  2496. $button = 0;
  2497. foreach ( $receiptList as $key => $value ) {
  2498. $receiptList [$key] ['Locate'] = $Locate;
  2499. $Locate ++;
  2500. $receiptList [$key] ['reviseDetail'] = array ();
  2501. if (! empty ( $value ['reviseDetail'] ))
  2502. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2503. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2504. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2505. $categoryDetil = $Lcategory->getOne ( array (
  2506. 'where' => 'cid=' . $value ['cid'],
  2507. 'asArray' => true
  2508. ) );
  2509. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2510. // 检测编辑状态
  2511. $verifyList = $verify->getOne ( array (
  2512. 'where' => 'vid=' . $value ['verify'],
  2513. 'asArray' => true
  2514. ) );
  2515. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2516. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2517. Doo::loadModel ( 'role' );
  2518. $role = new role ();
  2519. $flag = true;
  2520. $roleKey = 0;
  2521. $endStaffArray = array ();
  2522. $roleArrayCopy = array ();
  2523. foreach ( $verifyList as $k => $v ) {
  2524. // init verifyStaff
  2525. if ($v [1] == 'ROLE') {
  2526. if (! empty ( $verifyStaff )) {
  2527. $endStaffArray = end ( $verifyStaff );
  2528. // if ($v[0]==$endStaffArray['nextStaff']){
  2529. // $roleId=$v[0];
  2530. // }
  2531. }
  2532. $roleVerify = json_decode ( $v [3], true );
  2533. $roleKey = $k;
  2534. $roleArray = array ();
  2535. $rolename = $role->getOne ( array (
  2536. 'where' => 'rid=' . $v [0],
  2537. 'asArray' => true
  2538. ) );
  2539. foreach ( $roleVerify as $o => $p ) {
  2540. $staffID = explode ( '_', $p );
  2541. $staffInfo = $staff->getOne ( array (
  2542. 'where' => 'sid=' . $staffID [0],
  2543. 'asArray' => true
  2544. ) );
  2545. // print_r($staffID);
  2546. $exp = array (
  2547. 0 => $staffInfo ['sid'],
  2548. 1 => $staffID [1],
  2549. 2 => $staffInfo ['avatar'],
  2550. 'date' => '',
  2551. 'date' => '',
  2552. 'opinion' => '',
  2553. 'status' => '',
  2554. 'rolename' => $rolename ['name']
  2555. );
  2556. array_push ( $roleArray, $exp );
  2557. }
  2558. $roleArrayCopy [$v [0]] = $roleArray;
  2559. // $verifyList[$k]['roleArray']=$roleArray;
  2560. }
  2561. $verifyList [$k] ['date'] = "";
  2562. $verifyList [$k] ['opinion'] = "";
  2563. $verifyList [$k] ['status'] = "";
  2564. if (empty ( $verifyStaff )) {
  2565. $verifyList [$k] ['date'] = "";
  2566. $verifyList [$k] ['opinion'] = "";
  2567. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2568. $verifyList [$k] ['status'] = 4;
  2569. $flag = false;
  2570. }
  2571. } else {
  2572. foreach ( $verifyStaff as $m => $u ) {
  2573. if ($v [0] == $m) {
  2574. $verifyList [$k] ['date'] = $u ['date'];
  2575. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2576. $verifyList [$k] ['status'] = $u ['status'];
  2577. $flag = false;
  2578. break;
  2579. }
  2580. }
  2581. $endStaffArray = end ( $verifyStaff );
  2582. if (isset ( $endStaffArray ['ROLE'] )) {
  2583. } else {
  2584. // $endKey=key($verifyStaff);
  2585. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2586. // $button=4;
  2587. // $verifyList[$k]['status']=4;
  2588. // }
  2589. }
  2590. }
  2591. }
  2592. $rolename ['name'] = '';
  2593. if (! empty ( $roleId )) {
  2594. Doo::loadModel ( 'role' );
  2595. $role = new role ();
  2596. $rolename = $role->getOne ( array (
  2597. 'where' => 'rid=' . $roleId,
  2598. 'asArray' => true
  2599. ) );
  2600. }
  2601. if (! empty ( $verifyStaff ))
  2602. $endStaffArray = end ( $verifyStaff );
  2603. $KOP = false;
  2604. foreach ( $roleArrayCopy as $P => $A ) {
  2605. foreach ( $A as $MKI => $AVL ) {
  2606. if (! empty ( $verifyStaff )) {
  2607. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2608. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2609. $button = 4;
  2610. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2611. }
  2612. foreach ( $verifyStaff as $m => $u ) {
  2613. $AVLFK = $AVL [0] . '_R';
  2614. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2615. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2616. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2617. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2618. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2619. break;
  2620. }
  2621. }
  2622. } else {
  2623. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2624. $button = 4;
  2625. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2626. }
  2627. }
  2628. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2629. $KOP = true;
  2630. }
  2631. }
  2632. foreach ( $roleArrayCopy as $k => $v ) {
  2633. foreach ( $verifyList as $m => $n ) {
  2634. if ($n [0] == $k) {
  2635. array_splice ( $verifyList, $m, 1, $v );
  2636. }
  2637. }
  2638. }
  2639. $receiptList [$key] ['verifyList'] = $verifyList;
  2640. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2641. 'where' => 'sid=' . $value ['staff'],
  2642. 'asArray' => true
  2643. ) );
  2644. $receiptList [$key] ['button'] = $button;
  2645. //
  2646. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  2647. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2648. }
  2649. $data ['receiptList'] = $receiptList;
  2650. $acItem = $accountItem->find ( array (
  2651. 'asArray' => true
  2652. ) );
  2653. $veList = $verify->find ( array (
  2654. 'asArray' => true
  2655. ) );
  2656. foreach ( $veList as $key => $value ) {
  2657. $v = json_decode ( $value ['staff'] );
  2658. $list = array ();
  2659. foreach ( $v as $n => $m ) {
  2660. if ($m ['1'] == 'ROLE') {
  2661. $roleInfo = $role->getOne ( array (
  2662. 'where' => 'rid=' . $m [0],
  2663. 'asArray' => true
  2664. ) );
  2665. $v [$n] [1] = $roleInfo ['name'];
  2666. array_push ( $list, $roleInfo ['name'] );
  2667. } else {
  2668. array_push ( $list, $v [$n] [1] );
  2669. }
  2670. }
  2671. $veList [$key] ['staff'] = implode ( '>', $list );
  2672. }
  2673. // 配置编辑信息
  2674. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  2675. foreach ( $acItem as $key => $value ) {
  2676. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  2677. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  2678. $acItem [$key] ['price'] = $v ['price'];
  2679. }
  2680. }
  2681. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  2682. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2683. $acItem [$key] ['price'] = $v ['price'];
  2684. }
  2685. }
  2686. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  2687. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  2688. $acItem [$key] ['price'] = $v ['price'];
  2689. }
  2690. }
  2691. //内训
  2692. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  2693. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2694. $acItem [$key] ['price'] = $v ['price'];
  2695. }
  2696. }
  2697. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  2698. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  2699. $acItem [$key] ['price'] = $v ['price'];
  2700. }
  2701. }
  2702. }
  2703. $data ['category'] = $Lcategory->find ( array (
  2704. 'asArray' => true
  2705. ) );
  2706. $data ['ridKey'] = $ridKey;
  2707. $data ['cSum'] = $accountItemList ['cSum'];
  2708. $data ['sum'] = $receiptDetail ['sum'];
  2709. $data ['receiptDetail'] = $receiptDetail;
  2710. $data ['veList'] = $veList;
  2711. $data ['acItem'] = $acItem;
  2712. $data ['memu'] = "receipt";
  2713. $data ['staff'] = $this->staff;
  2714. $data ['receiptMemu'] = 'saeaBorad';
  2715. $data ['verify'] = $receiptDetail ['verify'];
  2716. $data ['verifyId'] = $this->verifyId;
  2717. $data ['executeId'] = $this->executeId;
  2718. $data ['rid'] = $rid;
  2719. if($receiptDetail['receiptClass']==1){
  2720. $this->render ( "/receipt/feeLoanReceiptAgencyEdi", $data );
  2721. }elseif($receiptDetail['receiptClass']==2){
  2722. $this->render ( "/receipt/feeLoanReceiptTraveEdi", $data );
  2723. }elseif($receiptDetail['receiptClass']==3){
  2724. $this->render ( "/receipt/feeLoanReceiptITEdi", $data );
  2725. }else{
  2726. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  2727. }
  2728. }
  2729. /**
  2730. * 培训班结算
  2731. */
  2732. function receiptTrainAdd() {
  2733. Doo::loadModel ( 'accountItem' );
  2734. $accountItem = new accountItem ();
  2735. $acItem = $accountItem->find ( array (
  2736. 'asArray' => true
  2737. ) );
  2738. // 审批组
  2739. Doo::loadModel ( 'verify' );
  2740. $verify = new verify ();
  2741. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2742. // 办事处
  2743. Doo::loadModel ( 'L_category' );
  2744. $lCategory = new L_category ();
  2745. $data ['category'] = $lCategory->getCategory ();
  2746. $data ['veList'] = $veList;
  2747. $data ['memu'] = "receipt";
  2748. $data ['staff'] = $this->staff;
  2749. $data ['acItem'] = $acItem;
  2750. $data ['receiptMemu'] = 'saeaBorad';
  2751. $data ['verifyId'] = $this->verifyId;
  2752. $data ['executeId'] = $this->executeId;
  2753. $this->render ( "/receipt/receiptTrainAdd", $data );
  2754. }
  2755. /**
  2756. * 添加培训班结算
  2757. */
  2758. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  2759. // 培训班信息
  2760. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2761. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2762. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2763. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2764. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  2765. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2766. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2767. // 发票信息
  2768. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2769. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2770. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2771. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2772. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2773. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2774. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2775. //&&! empty ( $participants )
  2776. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  2777. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2778. header ( 'Content-Type:text/html;charset=utf-8' );
  2779. die ( '请填写联行号' );
  2780. }
  2781. Doo::loadModel ( 'execute' );
  2782. $execute = new execute ();
  2783. $executeDetail = $execute->getOne ( array (
  2784. 'where' => 'mold="培训班结算"',
  2785. 'asArray' => true
  2786. ) );
  2787. if (empty ( $executeDetail )) {
  2788. header ( 'Content-Type:text/html;charset=utf-8' );
  2789. die ( '未设置执行人' );
  2790. }
  2791. Doo::loadClass ( 'XDeode' );
  2792. $XDeode = new XDeode ( 5 );
  2793. $cid = $XDeode->decode ( $cid );
  2794. Doo::loadModel ( 'receipt' );
  2795. $receipt = new receipt ();
  2796. Doo::loadModel ( 'receiptTraining' );
  2797. $receiptTraining = new receiptTraining ();
  2798. // 创建费用培训班
  2799. $item = array (
  2800. 'cid' => $this->staff [0] ['cid'],
  2801. 'categoryName' => $this->staff [0] ['category'],
  2802. 'trainName' => $trainName,
  2803. 'trainStartDate' => $trainStartDate,
  2804. 'trainEndDate' => $trainEndDate,
  2805. 'participants' => $participants,
  2806. 'freeParticipants'=>$freeParticipants,
  2807. 'trainAddress' => $trainAddress,
  2808. 'trainRemarks' => $trainRemarks,
  2809. 'creator' => $this->staff [0] ['sid'],
  2810. 'creatorDate' => date ( "Y-m-d H:i:s" )
  2811. );
  2812. $irid = $receiptTraining->addReceiptTraining ( $item );
  2813. // 报销单
  2814. $receipt->status = 5;
  2815. $receipt->trainId = $irid;
  2816. $receipt->Rtype = 3;
  2817. $receipt->staff = $this->staff [0] ['sid'];
  2818. $receipt->cid = $cid;
  2819. $receipt->verify = $verify;
  2820. $receipt->date = date ( "Y-m-d" );
  2821. $receipt->executeCopy = $executeDetail ['staff'];
  2822. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2823. $receipt->remittanceName = $remittanceName;
  2824. $receipt->bankName = $bankName;
  2825. $receipt->bankNumber = $bankNumber;
  2826. $receipt->remittanceBankType = $remittanceBankType;
  2827. if ($remittanceBankType == 1)
  2828. $receipt->coupletNumber = $coupletNumber;
  2829. $rid = $receipt->insert ();
  2830. $XDeode = new XDeode ( 7 );
  2831. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  2832. } else
  2833. die ( 'illegal request' );
  2834. }
  2835. /**
  2836. * 培训班编辑
  2837. */
  2838. function receiptTrainEdi() {
  2839. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2840. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  2841. Doo::loadClass ( 'XDeode' );
  2842. $XDeode = new XDeode ( 7 );
  2843. $rid = $XDeode->decode ( $ridKey );
  2844. if (! is_numeric ( $rid ))
  2845. die ( 'illegal request' );
  2846. Doo::loadModel ( 'receipt' );
  2847. $receipt = new receipt ();
  2848. Doo::loadModel ( 'receiptTraining' );
  2849. $receiptTraining = new receiptTraining ();
  2850. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2851. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  2852. die ('illegal request--status');
  2853. }
  2854. //如有已入账已收款的发票,自动取消办事处已收款
  2855. // Doo::loadModel ( 'RIExtend' );
  2856. // $RIExtend = new RIExtend ();
  2857. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  2858. // if (!empty($RIExtendList)){
  2859. // foreach ($RIExtendList as $key=>$value){
  2860. // $RIExtend = new RIExtend ();
  2861. // $RIExtend->delete(array (
  2862. // 'where' => 'iid=' . $value['iid'],
  2863. // 'limit' => 1
  2864. // ));
  2865. // }
  2866. // }
  2867. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2868. // 汇总表合计
  2869. // 收入合计--加入开票合计
  2870. Doo::loadModel ( 'invoiceTraining' );
  2871. $invoiceTraining = new invoiceTraining ();
  2872. $invoiceTrainingDetail = array (
  2873. 'invoiceArriveAmount' => 0,
  2874. 'RIAmount' => 0,
  2875. 'invoiceTotalAmount' => 0,
  2876. 'invoiceCompanyAmount'=>0
  2877. );
  2878. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2879. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2880. }
  2881. // print_r($invoiceTrainingDetail);
  2882. $invoiceArriveAmount = $RIAmount = 0;
  2883. if (! empty ( $invoiceTrainingDetail )) {
  2884. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  2885. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  2886. }
  2887. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2888. //print_r($invoiceTrainingDetail);
  2889. // 支出项目
  2890. Doo::loadModel ( 'accountItem' );
  2891. $accountItem = new accountItem ();
  2892. // 项目金额合计
  2893. Doo::loadModel ( 'RItem' );
  2894. $RItem = new RItem ();
  2895. // 讲师获得
  2896. Doo::loadModel ( 'RILecturer' );
  2897. $RILecturer = new RILecturer ();
  2898. $RItemList = $RItem->getRItemByRid ( $rid );
  2899. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2900. // 支出项金额详情
  2901. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  2902. // print_r($aiData);
  2903. // 利润
  2904. $profit=$invoiceArriveAmount - $aiData ['total'];
  2905. $companyProfit=$profit * 0.6;
  2906. $categoryProfit=$profit * 0.4;
  2907. $data ['profit'] = sprintf("%.2f",$profit);
  2908. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  2909. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  2910. //发票利润
  2911. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  2912. //发票公司利润
  2913. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  2914. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  2915. //办事处利润
  2916. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  2917. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  2918. // print_r($aiData['dataList']);
  2919. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  2920. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  2921. // 备用金
  2922. $sum = 0;
  2923. $data ['receiptLoanDetail'] = array (
  2924. 'sum' => '0.00'
  2925. );
  2926. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2927. //$data ['receiptLoanDetail'] = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2928. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2929. $sum=0;
  2930. foreach ($receiptLoanList as $key=>$value){
  2931. $sum+=$value['sum'];
  2932. }
  2933. $data ['receiptLoanDetail'] = array (
  2934. 'sum' => $sum
  2935. );
  2936. //$sum = $data ['receiptLoanDetail'] ['sum'];
  2937. }
  2938. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  2939. $data ['payment'] = sprintf("%.2f",$payment);
  2940. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  2941. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  2942. $data ['aiList'] = $aiData ['dataList'];
  2943. // 占比计算
  2944. if ($invoiceArriveAmount != 0) {
  2945. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  2946. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2947. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2948. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  2949. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  2950. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  2951. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  2952. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  2953. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  2954. } else {
  2955. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  2956. }
  2957. //发票金额占比计算
  2958. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  2959. //支出
  2960. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2961. //利润
  2962. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2963. //公司利润
  2964. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2965. //办事处利润
  2966. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2967. //公司收款
  2968. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2969. //备用金
  2970. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2971. //办事处收款
  2972. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2973. //办事处实际支出
  2974. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2975. //付总部款
  2976. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2977. }else{
  2978. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2979. }
  2980. //讲师人数
  2981. Doo::loadModel ( 'RILecturer' );
  2982. $RILecturer = new RILecturer ();
  2983. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2984. $data['lectureCount']=count($RILecturerList);
  2985. // 审批组
  2986. Doo::loadModel ( 'verify' );
  2987. $verify = new verify ();
  2988. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2989. // 办事处
  2990. Doo::loadModel ( 'L_category' );
  2991. $lCategory = new L_category ();
  2992. $data ['category'] = $lCategory->getCategory ();
  2993. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2994. $data ['receiptDetail'] = $receiptDetail;
  2995. $data ['veList'] = $veList;
  2996. $data ['trainEdiType'] = $trainEdiType;
  2997. $data ['ridKey'] = $ridKey;
  2998. $data ['memu'] = "receipt";
  2999. $data ['staff'] = $this->staff;
  3000. $data ['receiptMemu'] = 'saeaBorad';
  3001. $data ['verifyId'] = $this->verifyId;
  3002. $data ['executeId'] = $this->executeId;
  3003. $this->render ( "/receipt/receiptTrainEdi", $data );
  3004. }
  3005. /**
  3006. * 培训班借款编辑
  3007. */
  3008. function receiptTrainLoanEdi() {
  3009. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3010. Doo::loadClass ( 'XDeode' );
  3011. $XDeode = new XDeode ( 7 );
  3012. $rid = $XDeode->decode ( $ridKey );
  3013. if (! is_numeric ( $rid ))
  3014. die ( 'illegal request' );
  3015. Doo::loadModel ( 'receipt' );
  3016. $receipt = new receipt ();
  3017. Doo::loadModel ( 'receiptTraining' );
  3018. $receiptTraining = new receiptTraining ();
  3019. Doo::loadModel ( 'verify' );
  3020. $verify = new verify ();
  3021. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3022. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  3023. die ();
  3024. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3025. // 借款详情HTML
  3026. // 获得借款信息
  3027. $receiptLoanHtml = '';
  3028. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  3029. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  3030. foreach ($receiptLoanList as $key=>$value){
  3031. // 获得某费用单审批信息
  3032. $verifylist = $verify->getVerifyByRid ( $value ['rid'] );
  3033. Doo::loadClass ( 'receipt.func' );
  3034. $extendHtml = '<p><a class="button"
  3035. href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $value ['ridKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  3036. $receiptLoanHtml .= _getReceiptLoanHtml ( $value, $verifylist, $extendHtml );
  3037. }
  3038. }
  3039. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  3040. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3041. $data ['receiptDetail'] = $receiptDetail;
  3042. $data ['trainEdiType'] = "LOAN";
  3043. $data ['ridKey'] = $ridKey;
  3044. $data ['memu'] = "receipt";
  3045. $data ['staff'] = $this->staff;
  3046. $data ['receiptMemu'] = 'saeaBorad';
  3047. $data ['verifyId'] = $this->verifyId;
  3048. $data ['executeId'] = $this->executeId;
  3049. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  3050. }
  3051. /**
  3052. * 更新培训班结算基本信息
  3053. */
  3054. function receiptTrainInfoEdiDo() {
  3055. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  3056. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  3057. // 培训班信息
  3058. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  3059. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  3060. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  3061. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  3062. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  3063. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  3064. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  3065. // 发票信息
  3066. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  3067. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3068. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  3069. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3070. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  3071. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  3072. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  3073. //&& ! empty ( $participants )
  3074. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  3075. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  3076. header ( 'Content-Type:text/html;charset=utf-8' );
  3077. die ( '请填写联行号' );
  3078. }
  3079. Doo::loadClass ( 'XDeode' );
  3080. $XDeode = new XDeode ( 5 );
  3081. $cid = $XDeode->decode ( $cid );
  3082. $rtid = $XDeode->decode ( $rtid );
  3083. $rid = $XDeode->decode ( $rid );
  3084. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  3085. die ( 'illegal request-IdError' );
  3086. }
  3087. Doo::loadModel ( 'receipt' );
  3088. $receipt = new receipt ();
  3089. Doo::loadModel ( 'receiptTraining' );
  3090. $receiptTraining = new receiptTraining ();
  3091. // 更新费用培训班
  3092. $item = array (
  3093. 'rtid' => $rtid,
  3094. 'trainName' => $trainName,
  3095. 'trainStartDate' => $trainStartDate,
  3096. 'trainEndDate' => $trainEndDate,
  3097. 'participants' => $participants,
  3098. 'freeParticipants'=>$freeParticipants,
  3099. 'trainAddress' => $trainAddress,
  3100. 'trainRemarks' => $trainRemarks
  3101. );
  3102. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  3103. // 报销单
  3104. $receipt->rid = $rid;
  3105. $receipt->cid = $cid;
  3106. $receipt->verify = $verify;
  3107. $receipt->remittanceName = $remittanceName;
  3108. $receipt->bankName = $bankName;
  3109. $receipt->bankNumber = $bankNumber;
  3110. $receipt->remittanceBankType = $remittanceBankType;
  3111. if ($remittanceBankType == 1)
  3112. $receipt->coupletNumber = $coupletNumber;
  3113. $receipt->update ();
  3114. $XDeode = new XDeode ( 7 );
  3115. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  3116. } else
  3117. die ( 'illegal request' );
  3118. }
  3119. /**
  3120. * 编辑培训班结算---更新借款
  3121. */
  3122. function receiptTrainLoanEdiDo() {
  3123. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3124. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  3125. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  3126. Doo::loadModel ( 'receipt' );
  3127. $receipt = new receipt ();
  3128. Doo::loadClass ( 'XDeode' );
  3129. $XDeode = new XDeode ( 5 );
  3130. $rid = $XDeode->decode ( $ridKey );
  3131. $ridLoan = $XDeode->decode ( $ridLoanKey );
  3132. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  3133. die ( 'illegal request-ridError' );
  3134. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3135. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  3136. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3137. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3138. die ( 'illegal request-receiptError' );
  3139. }
  3140. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  3141. die ( 'illegal request-receipLoantError' );
  3142. }
  3143. // 培训班结算挂钩借款
  3144. $receipt = new receipt ();
  3145. $trainLoanRid=$ridLoan;
  3146. if (!empty($receiptDetail['trainLoanRid'])){
  3147. $trainLoanRid=$receiptDetail['trainLoanRid'].','.$ridLoan;
  3148. }
  3149. $item = array (
  3150. 'rid' => $rid,
  3151. 'trainLoanRid' => $trainLoanRid
  3152. );
  3153. $receipt->setReceiptByCondition ( $item );
  3154. // 更新借款状态变成已挂钩
  3155. $receipt = new receipt ();
  3156. $item = array (
  3157. 'rid' => $ridLoan,
  3158. 'status' => 10,
  3159. 'statusTrain' => 1
  3160. );
  3161. $receipt->setReceiptByCondition ( $item );
  3162. $XDeode = new XDeode ( 7 );
  3163. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  3164. } else
  3165. die ( 'illegal request' );
  3166. }
  3167. /**
  3168. * 编辑培训班结算--移除借款
  3169. */
  3170. function receiptTrainLoanRemoveDo() {
  3171. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  3172. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  3173. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  3174. Doo::loadModel ( 'receipt' );
  3175. $receipt = new receipt ();
  3176. Doo::loadClass ( 'XDeode' );
  3177. $XDeode = new XDeode ( 5 );
  3178. $rid = $XDeode->decode ( $ridKey );
  3179. $ridLoan = $XDeode->decode ( $ridLoanKey );
  3180. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  3181. die ( 'illegal request-ridError' );
  3182. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3183. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  3184. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  3185. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3186. die ( 'illegal request-receiptError' );
  3187. }
  3188. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  3189. die ( 'illegal request-receipLoantError' );
  3190. }
  3191. // 培训班结算挂钩借款
  3192. $receipt = new receipt ();
  3193. $trainLoanRidArray=explode(",", $receiptDetail['trainLoanRid']);
  3194. foreach ($trainLoanRidArray as $key=>$value){
  3195. if($value==$ridLoan){
  3196. unset($trainLoanRidArray[$key]);
  3197. }
  3198. }
  3199. $trainLoanRidString=implode(",", $trainLoanRidArray);
  3200. $item = array (
  3201. 'rid' => $rid,
  3202. 'trainLoanRid' => $trainLoanRidString
  3203. );
  3204. $receipt->setReceiptByCondition ( $item );
  3205. // 更新借款状态变成已挂钩
  3206. $receipt = new receipt ();
  3207. $item = array (
  3208. 'rid' => $ridLoan,
  3209. 'status' => 8,
  3210. 'statusTrain' => 0
  3211. );
  3212. $receipt->setReceiptByCondition ( $item );
  3213. $XDeode = new XDeode ( 7 );
  3214. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  3215. } else
  3216. die ( 'illegal request' );
  3217. }
  3218. /**
  3219. * 编辑培训班结算 ---开票
  3220. */
  3221. function receiptTrainInvoiceEdi() {
  3222. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3223. Doo::loadClass ( 'XDeode' );
  3224. $XDeode = new XDeode ( 7 );
  3225. $rid = $XDeode->decode ( $ridKey );
  3226. if (! is_numeric ( $rid ))
  3227. die ( 'illegal request' );
  3228. Doo::loadModel ( 'receipt' );
  3229. $receipt = new receipt ();
  3230. Doo::loadModel ( 'receiptTraining' );
  3231. $receiptTraining = new receiptTraining ();
  3232. Doo::loadModel ( 'invoice' );
  3233. $invoice = new invoice ();
  3234. Doo::loadModel ( 'invoiceTraining' );
  3235. $invoiceTraining = new invoiceTraining ();
  3236. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3237. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  3238. die ();
  3239. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3240. $invoiceList = $invoiceTrainingDetail = array ();
  3241. if ($receiptDetail ['invoiceTrainId'] != 0) {
  3242. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  3243. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  3244. }
  3245. //print_r($invoiceList);
  3246. $data ['invoiceList'] = $invoiceList;
  3247. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  3248. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3249. $data ['receiptDetail'] = $receiptDetail;
  3250. $data ['trainEdiType'] = "INVOICE";
  3251. $data ['ridKey'] = $ridKey;
  3252. $data ['memu'] = "receipt";
  3253. $data ['staff'] = $this->staff;
  3254. $data ['receiptMemu'] = 'saeaBorad';
  3255. $data ['verifyId'] = $this->verifyId;
  3256. $data ['executeId'] = $this->executeId;
  3257. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  3258. }
  3259. /**
  3260. * 编辑培训班结算---更新开票
  3261. */
  3262. function receiptTrainInvoiceEdiDo() {
  3263. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3264. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  3265. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  3266. Doo::loadModel ( 'receipt' );
  3267. $receipt = new receipt ();
  3268. Doo::loadModel ( 'invoiceTraining' );
  3269. $invoiceTraining = new invoiceTraining ();
  3270. Doo::loadClass ( 'XDeode' );
  3271. $XDeode = new XDeode ( 5 );
  3272. $rid = $XDeode->decode ( $ridKey );
  3273. $itid = $XDeode->decode ( $itidKey );
  3274. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  3275. die ( 'illegal request-idError' );
  3276. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3277. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  3278. // 不合法的数据
  3279. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3280. die ( 'illegal request-receiptError' );
  3281. }
  3282. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  3283. die ( 'illegal request-receipLoantError' );
  3284. }
  3285. // 培训班结算挂钩借款
  3286. $receipt = new receipt ();
  3287. $item = array (
  3288. 'rid' => $rid,
  3289. 'invoiceTrainId' => $itid
  3290. );
  3291. $receipt->setReceiptByCondition ( $item );
  3292. $invoiceTraining = new invoiceTraining ();
  3293. $item = array (
  3294. 'bindReceipt' => 1,
  3295. 'itid' => $itid
  3296. );
  3297. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3298. $XDeode = new XDeode ( 7 );
  3299. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  3300. } else
  3301. die ( 'illegal request' );
  3302. }
  3303. /**
  3304. * 更新培训班结算 收款和取消收款
  3305. */
  3306. function receiptTrainReceivables() {
  3307. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  3308. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3309. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3310. Doo::loadClass ( 'XDeode' );
  3311. $XDeode = new XDeode ( 5 );
  3312. $rid = $XDeode->decode ( $ridKey );
  3313. $iid = $XDeode->decode ( $iidKey );
  3314. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  3315. die ( 'illegal request-iid' );
  3316. Doo::loadModel ( 'RIExtend' );
  3317. $RIExtend = new RIExtend ();
  3318. if ($doType == 'CONFIRM') {
  3319. $RIExtend->rid = $rid;
  3320. $RIExtend->iid = $iid;
  3321. $RIExtend->RIstatus = 1;
  3322. $RIExtend->insert ();
  3323. echo json_encode ( array (
  3324. 'status' => 1,
  3325. ) );
  3326. die ( );
  3327. } elseif ($doType == 'CANCEL') {
  3328. $RIExtend->delete ( array (
  3329. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  3330. 'limit' => 1
  3331. ) );
  3332. echo json_encode ( array (
  3333. 'status' => 1,
  3334. ) );
  3335. die ( );
  3336. } else {
  3337. echo json_encode ( array (
  3338. 'status' => 2,
  3339. ) );
  3340. die ( );
  3341. }
  3342. }
  3343. /**
  3344. * 移除挂钩的培训班发票
  3345. */
  3346. function receiptTrainReceivablesDelDo() {
  3347. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3348. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  3349. Doo::loadModel ( 'receipt' );
  3350. $receipt = new receipt ();
  3351. Doo::loadModel ( 'RIExtend' );
  3352. $RIExtend = new RIExtend ();
  3353. Doo::loadClass ( 'XDeode' );
  3354. $XDeode = new XDeode ( 5 );
  3355. $rid = $XDeode->decode ( $ridKey );
  3356. $itid = $XDeode->decode ( $itidKey );
  3357. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  3358. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3359. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3360. die ( 'illegal request-status' );
  3361. }
  3362. $receipt = new receipt ();
  3363. $receipt->rid = $rid;
  3364. $receipt->invoiceTrainId = 0;
  3365. $receipt->update ();
  3366. Doo::loadModel ( 'invoiceTraining' );
  3367. $invoiceTraining = new invoiceTraining ();
  3368. $item = array (
  3369. 'bindReceipt' => 0,
  3370. 'itid' => $itid
  3371. );
  3372. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3373. $RIExtend->delete ( array (
  3374. 'where' => 'rid=' . $rid
  3375. ) );
  3376. $XDeode = new XDeode ( 7 );
  3377. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  3378. } else
  3379. die ( 'illegal request-iid' );
  3380. }
  3381. /**
  3382. * 编辑培训班结算
  3383. */
  3384. function receiptTrainItemEdi() {
  3385. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3386. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3387. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  3388. Doo::loadClass ( 'XDeode' );
  3389. $XDeode = new XDeode ( 7 );
  3390. $rid = $XDeode->decode ( $ridKey );
  3391. if (! is_numeric ( $rid ))
  3392. die ( 'illegal request' );
  3393. Doo::loadModel ( 'receipt' );
  3394. $receipt = new receipt ();
  3395. Doo::loadModel ( 'receiptTraining' );
  3396. $receiptTraining = new receiptTraining ();
  3397. Doo::loadModel ( 'RItem' );
  3398. $RItem = new RItem ();
  3399. Doo::loadModel ( 'accountItem' );
  3400. $accountItem = new accountItem ();
  3401. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3402. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3403. die ();
  3404. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3405. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  3406. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  3407. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  3408. // if($value['name']=='税款'){
  3409. // unset($aiList[$key]);break;
  3410. // }
  3411. // }
  3412. //print_r($RItemList);
  3413. $data ['name'] = $name;
  3414. $data ['RItemList'] = $RItemList;
  3415. $data ['aiList'] = $aiList;
  3416. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3417. $data ['receiptDetail'] = $receiptDetail;
  3418. $data ['trainEdiType'] = "ITEM";
  3419. $data ['ridKey'] = $ridKey;
  3420. $data ['memu'] = "receipt";
  3421. $data ['staff'] = $this->staff;
  3422. $data ['receiptMemu'] = 'saeaBorad';
  3423. $data ['verifyId'] = $this->verifyId;
  3424. $data ['executeId'] = $this->executeId;
  3425. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  3426. }
  3427. /**
  3428. * 添加支出项 需要修改 费用金额合计
  3429. */
  3430. function receiptTrainItemAddDo() {
  3431. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3432. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  3433. // 支出项信息
  3434. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3435. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  3436. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3437. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  3438. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  3439. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  3440. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  3441. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  3442. Doo::loadClass ( 'XDeode' );
  3443. $XDeode = new XDeode ( 5 );
  3444. Doo::loadModel ( 'RItem' );
  3445. $RItem = new RItem ();
  3446. $rid = $XDeode->decode ( $ridKey );
  3447. $rtid= $XDeode->decode ( $rtidKey );
  3448. if (! is_numeric ( $rid )){
  3449. die ( 'illegal request' );
  3450. }
  3451. Doo::loadModel ( 'receiptDetail' );
  3452. $receiptDetail = new receiptDetail ();
  3453. Doo::loadModel ( 'receipt' );
  3454. $receipt = new receipt ();
  3455. Doo::loadModel ( 'receiptTraining' );
  3456. $receiptTraining = new receiptTraining ();
  3457. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  3458. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  3459. $order = array (
  3460. "\r\n",
  3461. "\n",
  3462. "\r"
  3463. );
  3464. $replace = '<br/>';
  3465. $describe = str_replace ( $order, $replace, $describe );
  3466. $itemData = array (
  3467. 'rid' => $rid,
  3468. 'item' => $item,
  3469. 'price' => $price,
  3470. 'date' => $date,
  3471. 'inputer' => $inputer,
  3472. 'describe' => $describe,
  3473. 'creater' => $this->staff['0']['username'],
  3474. 'createrId' => $this->staff['0']['sid'],
  3475. 'creatDate' => date ( "Y-m-d H:i:s" ),
  3476. 'identifying'=>$identifyingTotal
  3477. );
  3478. if($payType=='company'){
  3479. $itemData += array (
  3480. 'payType' => 1
  3481. );
  3482. }
  3483. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  3484. //更新支出项标识总数
  3485. $itemData = array (
  3486. 'rtid'=>$rtid,
  3487. 'identifyingTotal'=>$identifyingTotal
  3488. );
  3489. $receiptTraining->setReceiptTrainByCondition($itemData);
  3490. $XDeode = new XDeode ( 7 );
  3491. if($payType=='company'){
  3492. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  3493. }else{
  3494. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  3495. }
  3496. } else
  3497. die ( 'illegal request-dataError' );
  3498. }
  3499. /**
  3500. * 培训班结算-讲师
  3501. */
  3502. function receiptTrainLecturerEdi() {
  3503. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3504. Doo::loadClass ( 'XDeode' );
  3505. $XDeode = new XDeode ( 7 );
  3506. $rid = $XDeode->decode ( $ridKey );
  3507. if (! is_numeric ( $rid ))
  3508. die ( 'illegal request' );
  3509. Doo::loadModel ( 'receipt' );
  3510. $receipt = new receipt ();
  3511. Doo::loadModel ( 'receiptTraining' );
  3512. $receiptTraining = new receiptTraining ();
  3513. Doo::loadModel ( 'RILecturer' );
  3514. $RILecturer = new RILecturer ();
  3515. Doo::loadModel ( 'lecturer' );
  3516. $lecturer = new lecturer ();
  3517. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3518. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3519. die ();
  3520. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3521. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3522. $lecturerList = $lecturer->getLecturerAll ();
  3523. $INSIDEhtml = $OUTSIDEhtml = '';
  3524. foreach ( $lecturerList as $key => $value ) {
  3525. if ($value ['ltype'] == 'INSIDE') {
  3526. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  3527. } elseif ($value ['ltype'] == 'OUTSIDE') {
  3528. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  3529. }
  3530. }
  3531. $data ['INSIDEhtml'] = $INSIDEhtml;
  3532. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  3533. // print_r($RItemList);
  3534. $data ['RILecturerList'] = $RILecturerList;
  3535. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3536. $data ['receiptDetail'] = $receiptDetail;
  3537. $data ['trainEdiType'] = "LECTURER";
  3538. $data ['ridKey'] = $ridKey;
  3539. $data ['memu'] = "receipt";
  3540. $data ['staff'] = $this->staff;
  3541. $data ['receiptMemu'] = 'saeaBorad';
  3542. $data ['verifyId'] = $this->verifyId;
  3543. $data ['executeId'] = $this->executeId;
  3544. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  3545. }
  3546. /**
  3547. * 添加讲师
  3548. */
  3549. function receiptTrainLecturerAddDo() {
  3550. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3551. // 支出项信息
  3552. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  3553. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  3554. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  3555. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  3556. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  3557. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  3558. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  3559. Doo::loadClass ( 'XDeode' );
  3560. $XDeode = new XDeode ( 5 );
  3561. Doo::loadModel ( 'RILecturer' );
  3562. $RILecturer = new RILecturer ();
  3563. $rid = $XDeode->decode ( $ridKey );
  3564. if (! is_numeric ( $rid ))
  3565. die ( 'illegal request' );
  3566. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  3567. die ( 'illegal request-taxationError' );
  3568. $RILecturer->rid = $rid;
  3569. $RILecturer->ltype = $ltype;
  3570. if ($ltype == 'OUTSIDE') {
  3571. if ($taxation == 'TAXATION') {
  3572. $RILecturer->taxation = 1;
  3573. } elseif ($taxation == 'NOTAXATION') {
  3574. $RILecturer->taxation = 0;
  3575. }
  3576. }
  3577. $RILecturer->lecturerName = $lecturerName;
  3578. $RILecturer->schoolDay = $schoolDay;
  3579. $RILecturer->price = $price;
  3580. $RILecturer->fees=$fees;
  3581. $RILecturer->insert ();
  3582. // 添加公司汇总
  3583. // 报销详情
  3584. Doo::loadModel ( 'receiptDetail' );
  3585. $receiptDetail = new receiptDetail ();
  3586. Doo::loadModel ( 'receipt' );
  3587. $receipt = new receipt ();
  3588. // 金额总计
  3589. $price = $price * $schoolDay;
  3590. $rInfo = $receipt->getReceiptByRid ( $rid );
  3591. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3592. if (empty ( $rdInfo )) {
  3593. $receiptDetail = new receiptDetail ();
  3594. $receiptDetail->staff = $rInfo ['staff'];
  3595. $receiptDetail->item = '讲课费';
  3596. $receiptDetail->itemCategory = '培训班费用';
  3597. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  3598. $receiptDetail->date = date ( "Y-m-d" );
  3599. $receiptDetail->cid = $rInfo ['cid'];
  3600. $receiptDetail->rid = $rid;
  3601. $receiptDetail->status = 4;
  3602. $receiptDetail->insert ();
  3603. } else {
  3604. $receiptDetail = new receiptDetail ();
  3605. $rdInfo ['price'] += $fees;
  3606. $receiptDetail->price = $rdInfo ['price'];
  3607. $receiptDetail->update ( array (
  3608. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3609. ) );
  3610. }
  3611. $receipt = new receipt ();
  3612. $receipt->sum=$rInfo['sum']+$fees;
  3613. $receipt->update ( array (
  3614. 'where' => 'rid=' . $rid
  3615. ) );
  3616. $XDeode = new XDeode ( 7 );
  3617. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3618. } else
  3619. die ( 'illegal request' );
  3620. }
  3621. /**
  3622. * 移除讲师
  3623. */
  3624. function receiptTrainLecturerDelDo() {
  3625. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3626. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  3627. Doo::loadModel ( 'receipt' );
  3628. $receipt = new receipt ();
  3629. Doo::loadModel ( 'RILecturer' );
  3630. $RILecturer = new RILecturer ();
  3631. Doo::loadClass ( 'XDeode' );
  3632. $XDeode = new XDeode ( 5 );
  3633. $rid = $XDeode->decode ( $ridKey );
  3634. $rlid = $XDeode->decode ( $rlidKey );
  3635. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  3636. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3637. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3638. die ( 'illegal request-status' );
  3639. }
  3640. $detail=$RILecturer->getRILecturerByRlid($rlid);
  3641. if (empty($detail)){
  3642. die ( 'illegal request-data' );
  3643. }
  3644. $RILecturer->delete ( array (
  3645. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  3646. ) );
  3647. //更新费用合计金额
  3648. $rInfo = $receipt->getReceiptByRid ( $rid );
  3649. $receipt = new receipt ();
  3650. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  3651. $receipt->update ( array (
  3652. 'where' => 'rid=' . $rid
  3653. ) );
  3654. Doo::loadModel ( 'receiptDetail' );
  3655. $receiptDetail = new receiptDetail ();
  3656. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3657. $receiptDetail = new receiptDetail ();
  3658. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  3659. $receiptDetail->price = $rdInfo ['price'];
  3660. $receiptDetail->update ( array (
  3661. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3662. ) );
  3663. $XDeode = new XDeode ( 7 );
  3664. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3665. } else
  3666. die ( 'illegal request-iid' );
  3667. }
  3668. /**
  3669. * 培训班提交审批
  3670. */
  3671. function receiptTrainDo() {
  3672. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3673. Doo::loadClass ( 'XDeode' );
  3674. $XDeode = new XDeode ( 7 );
  3675. $rid = $XDeode->decode ( $ridKey );
  3676. Doo::loadModel ( 'receipt' );
  3677. $receipt = new receipt ();
  3678. Doo::loadModel ( 'receiptDetail' );
  3679. $receiptDetail = new receiptDetail ();
  3680. Doo::loadModel ( 'statistics' );
  3681. $statistics = new statistics ();
  3682. Doo::loadModel ( "verify" );
  3683. $verify = new verify ();
  3684. // 审批状态的判定
  3685. $receiptDetailList = $receipt->getOne ( array (
  3686. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  3687. 'asArray' => true
  3688. ) );
  3689. if (empty ( $receiptDetailList ))
  3690. return "/saeaBorad";
  3691. $verifyDetail = $verify->getOne ( array (
  3692. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3693. 'asArray' => true
  3694. ) );
  3695. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3696. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3697. $nowStaff = "";
  3698. $nowStaffList = array ();
  3699. if ($verifyDetail [0] [1] == 'ROLE') {
  3700. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3701. foreach ( $vStaffString as $key => $value ) {
  3702. $staffK = explode ( "_", $value );
  3703. array_push ( $nowStaffList, $staffK [0] );
  3704. }
  3705. $nowStaff = implode ( ',', $nowStaffList );
  3706. } else {
  3707. $nowStaff = $verifyDetail [0] [0];
  3708. }
  3709. $receipt->nowStaff = $nowStaff;
  3710. }
  3711. // echo $nowStaff;
  3712. // print_r($verifyDetail);die;
  3713. $receipt->rid = $receiptDetailList ['rid'];
  3714. $receipt->date = date ( "Y-m-d" );
  3715. $receipt->status = 2;
  3716. $receipt->update ();
  3717. $receiptDetail->status = 2;
  3718. $receiptDetail->update ( array (
  3719. 'where' => 'rid=' . $receiptDetailList ['rid']
  3720. ) );
  3721. Doo::loadModel ( "receiptLog" );
  3722. $receiptLog = new receiptLog ();
  3723. Doo::loadModel ( "verify" );
  3724. $verify = new verify ();
  3725. $vr = $verify->getOne ( array (
  3726. 'where' => 'vid=' . $receiptDetailList ['verify'],
  3727. 'asArray' => true
  3728. ) );
  3729. $jd = json_decode ( $vr ['staff'] );
  3730. $roleId = 0;
  3731. foreach ( $jd as $key => $value ) {
  3732. if ($value [1] == 'ROLE') {
  3733. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3734. if ($pos !== false) {
  3735. $roleId = $value [0];
  3736. }
  3737. }
  3738. }
  3739. // 审批日志
  3740. // echo $roleId;die;
  3741. if (! empty ( $roleId )) {
  3742. Doo::loadModel ( "role" );
  3743. $role = new role ();
  3744. $roleInfo = $role->getOne ( array (
  3745. 'where' => 'rid=' . $roleId,
  3746. 'asArray' => true
  3747. ) );
  3748. // $receiptLog->rolename = $roleInfo ['name'];
  3749. }
  3750. $receiptLog->username = $this->staff [0] ['username'];
  3751. $receiptLog->uid = $this->staff [0] ['sid'];
  3752. $receiptLog->date = date ( "Y-m-d" );
  3753. $receiptLog->opinion = '提交审批';
  3754. $receiptLog->img = $this->staff [0] ['avatar'];
  3755. $receiptLog->status = 2;
  3756. $receiptLog->rid = $rid;
  3757. $receiptLog->insert ();
  3758. // 写入列表项
  3759. Doo::loadModel ( 'accountItem' );
  3760. $accountItem = new accountItem ();
  3761. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  3762. // 项目金额合计
  3763. Doo::loadModel ( 'RItem' );
  3764. $RItem = new RItem ();
  3765. // 讲师获得
  3766. Doo::loadModel ( 'RILecturer' );
  3767. $RILecturer = new RILecturer ();
  3768. $RItemList = $RItem->getRItemByRid ( $rid );
  3769. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3770. // 支出项金额详情
  3771. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  3772. // print_r($aItem);
  3773. // print_r($aiData);
  3774. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  3775. $ag = $tr = $ta = $ot = 0;
  3776. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  3777. foreach ( $aItem as $key => $value ) {
  3778. if ($value ['category'] == $this->TRAIN) {
  3779. foreach ( $aiData ['dataList'] as $k => $v ) {
  3780. if ($value ['name'] == $v ['name']) {
  3781. array_push ( $accountJson [$this->TRAIN], array (
  3782. 'aid' => $value ['aid'],
  3783. 'name' => $value ['name'],
  3784. 'price' => number_format ( $v ['price'], 2, '.', '' )
  3785. ) );
  3786. $sum += $v ['price'];
  3787. $trainSum += $v ['price'];
  3788. unset ( $aiData ['dataList'] [$k] );
  3789. break;
  3790. }
  3791. }
  3792. }
  3793. }
  3794. $accountJson ['cSum'] = array (
  3795. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  3796. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  3797. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  3798. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  3799. );
  3800. // 报销单
  3801. $receipt = new receipt ();
  3802. $receipt->accountItem = json_encode ( $accountJson );
  3803. $receipt->sum = number_format ( $sum, 2, '.', '' );
  3804. $receipt->update ( array (
  3805. 'where' => 'rid=' . $rid
  3806. ) );
  3807. // print_r($accountJson);
  3808. // statistics item 统计写入
  3809. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  3810. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  3811. $accountItem = $accountJson;
  3812. $stat = $statistics->getOne ( array (
  3813. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3814. 'asArray' => true
  3815. ) );
  3816. if (empty ( $stat )) {
  3817. $statistics->date = date ( "Y-m-d" );
  3818. $statistics->cid = $this->staff [0] ['cid'];
  3819. $statistics->staff = $this->staff [0] ['sid'];
  3820. $statistics->agPrice = 0;
  3821. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3822. $statistics->insert ();
  3823. } else {
  3824. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3825. $statistics->update ( array (
  3826. 'where' => 'sid=' . $stat ['sid']
  3827. ) );
  3828. }
  3829. return "/saeaBorad";
  3830. }
  3831. function confirmation() {
  3832. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3833. Doo::loadModel ( 'receipt' );
  3834. Doo::loadModel ( 'receiptDetail' );
  3835. $receipt = new receipt ();
  3836. $receiptDetail = new receiptDetail ();
  3837. Doo::loadModel ( 'statistics' );
  3838. Doo::loadModel ( 'itemStatistics' );
  3839. $statistics = new statistics ();
  3840. $itemStatistics = new itemStatistics ();
  3841. Doo::loadModel ( "verify" );
  3842. $verify = new verify ();
  3843. $receiptDetailList = $receipt->getOne ( array (
  3844. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  3845. 'asArray' => true
  3846. ) );
  3847. if (empty ( $receiptDetailList ))
  3848. return "/saeaBorad";
  3849. $verifyDetail = $verify->getOne ( array (
  3850. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3851. 'asArray' => true
  3852. ) );
  3853. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3854. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3855. $nowStaff = "";
  3856. $nowStaffList = array ();
  3857. if ($verifyDetail [0] [1] == 'ROLE') {
  3858. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3859. foreach ( $vStaffString as $key => $value ) {
  3860. $staffK = explode ( "_", $value );
  3861. array_push ( $nowStaffList, $staffK [0] );
  3862. }
  3863. $nowStaff = implode ( ',', $nowStaffList );
  3864. } else {
  3865. $nowStaff = $verifyDetail [0] [0];
  3866. }
  3867. $receipt->nowStaff = $nowStaff;
  3868. }
  3869. // echo $nowStaff;
  3870. // print_r($verifyDetail);die;
  3871. $receipt->rid = $receiptDetailList ['rid'];
  3872. $receipt->status = 2;
  3873. $receipt->update ();
  3874. // 操作日志
  3875. Doo::loadModel ( "receiptLog" );
  3876. $receiptLog = new receiptLog ();
  3877. $verify = new verify ();
  3878. $receiptInfo = $receipt->getOne ( array (
  3879. 'where' => 'rid=' . $rid,
  3880. 'asArray' => true
  3881. ) );
  3882. $vr = $verify->getOne ( array (
  3883. 'where' => 'vid=' . $receiptInfo ['verify'],
  3884. 'asArray' => true
  3885. ) );
  3886. $jd = json_decode ( $vr ['staff'] );
  3887. $roleId = 0;
  3888. foreach ( $jd as $key => $value ) {
  3889. if ($value [1] == 'ROLE') {
  3890. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3891. if ($pos !== false) {
  3892. $roleId = $value [0];
  3893. }
  3894. }
  3895. }
  3896. // 审批日志
  3897. // echo $roleId;die;
  3898. if (! empty ( $roleId )) {
  3899. Doo::loadModel ( "role" );
  3900. $role = new role ();
  3901. $roleInfo = $role->getOne ( array (
  3902. 'where' => 'rid=' . $roleId,
  3903. 'asArray' => true
  3904. ) );
  3905. // $receiptLog->rolename = $roleInfo ['name'];
  3906. }
  3907. $receiptLog->username = $this->staff [0] ['username'];
  3908. $receiptLog->uid = $this->staff [0] ['sid'];
  3909. $receiptLog->date = date ( "Y-m-d" );
  3910. $receiptLog->opinion = '提交审批';
  3911. $receiptLog->img = $this->staff [0] ['avatar'];
  3912. $receiptLog->status = 2;
  3913. $receiptLog->rid = $rid;
  3914. $receiptLog->insert ();
  3915. return "/expenses";
  3916. }
  3917. function expenses() {
  3918. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  3919. if (empty ( $item ))
  3920. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3921. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3922. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  3923. Doo::loadClass ( 'XDeode' );
  3924. $XDeode = new XDeode ( 7 );
  3925. Doo::loadModel ( 'receipt' );
  3926. $receipt = new receipt ();
  3927. Doo::loadModel ( 'L_category' );
  3928. $Lcategory = new L_category ();
  3929. Doo::loadModel ( 'verify' );
  3930. Doo::loadModel ( 'statistics' );
  3931. $statistics = new statistics ();
  3932. $verify = new verify ();
  3933. Doo::loadModel ( 'staff' );
  3934. $staff = new staff ();
  3935. $condition = "";
  3936. if ($item == "expenses")
  3937. $condition = " and Rtype=1 ";
  3938. elseif ($item == "receipts")
  3939. $condition = " and Rtype=0 ";
  3940. elseif ($item == "remits")
  3941. $condition = " and Rtype=2 ";
  3942. elseif ($item == "train")
  3943. $condition = " and Rtype=3 ";
  3944. $dateCondition = " and Year(date) =" . $year;
  3945. if (! empty ( $moth )) {
  3946. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  3947. $stList = $statistics->getOne ( array (
  3948. 'select' => 'rePrice ,agPrice',
  3949. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3950. 'asArray' => true
  3951. ) );
  3952. } else
  3953. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  3954. if (empty ( $stList ))
  3955. $stList = array (
  3956. 'rePrice' => 0,
  3957. 'agPrice' => 0
  3958. );
  3959. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  3960. if (! isset ( $noPassSum ['sum'] ))
  3961. $noPassSum ['sum'] = 0;
  3962. $data ['stList'] = array (
  3963. 'rePrice' => $stList ['rePrice'],
  3964. 'agPrice' => $stList ['agPrice'],
  3965. 'skPrice' => ($noPassSum ['sum'])
  3966. );
  3967. $receiptList = $receipt->find ( array (
  3968. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  3969. 'desc' => 'rid',
  3970. 'asArray' => true
  3971. ) );
  3972. $Locate = 0;
  3973. $roleId = 0;
  3974. $button = 0;
  3975. foreach ( $receiptList as $key => $value ) {
  3976. $receiptList[$key]['balance']='';
  3977. if($value['Rtype']==1){
  3978. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  3979. $receiptList[$key]['balanceABS']=abs($receiptList[$key]['balance']);
  3980. }elseif($value['Rtype']==3){
  3981. $payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
  3982. $receiptList[$key]['payment']=$payment;
  3983. $receiptList[$key]['paymentABS']=abs($payment);
  3984. }
  3985. $receiptList [$key] ['Locate'] = $Locate;
  3986. $Locate ++;
  3987. $receiptList [$key] ['reviseDetail'] = array ();
  3988. if (! empty ( $value ['reviseDetail'] ))
  3989. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3990. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3991. $categoryDetil = $Lcategory->getOne ( array (
  3992. 'where' => 'cid=' . $value ['cid'],
  3993. 'asArray' => true
  3994. ) );
  3995. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  3996. // 检测编辑状态
  3997. $verifyList = $verify->getOne ( array (
  3998. 'where' => 'vid=' . $value ['verify'],
  3999. 'asArray' => true
  4000. ) );
  4001. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4002. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4003. Doo::loadModel ( 'role' );
  4004. $role = new role ();
  4005. $flag = true;
  4006. $roleKey = 0;
  4007. $endStaffArray = array ();
  4008. $roleArrayCopy = array ();
  4009. foreach ( $verifyList as $k => $v ) {
  4010. // init verifyStaff
  4011. if ($v [1] == 'ROLE') {
  4012. if (! empty ( $verifyStaff )) {
  4013. $endStaffArray = end ( $verifyStaff );
  4014. // if ($v[0]==$endStaffArray['nextStaff']){
  4015. // $roleId=$v[0];
  4016. // }
  4017. }
  4018. $roleVerify = json_decode ( $v [3], true );
  4019. $roleKey = $k;
  4020. $roleArray = array ();
  4021. $rolename = $role->getOne ( array (
  4022. 'where' => 'rid=' . $v [0],
  4023. 'asArray' => true
  4024. ) );
  4025. foreach ( $roleVerify as $o => $p ) {
  4026. $staffID = explode ( '_', $p );
  4027. $staffInfo = $staff->getOne ( array (
  4028. 'where' => 'sid=' . $staffID [0],
  4029. 'asArray' => true
  4030. ) );
  4031. // print_r($staffID);
  4032. $exp = array (
  4033. 0 => $staffInfo ['sid'],
  4034. 1 => $staffID [1],
  4035. 2 => $staffInfo ['avatar'],
  4036. 'date' => '',
  4037. 'date' => '',
  4038. 'opinion' => '',
  4039. 'status' => '',
  4040. 'rolename' => $rolename ['name']
  4041. );
  4042. array_push ( $roleArray, $exp );
  4043. }
  4044. $roleArrayCopy [$v [0]] = $roleArray;
  4045. // $verifyList[$k]['roleArray']=$roleArray;
  4046. }
  4047. $verifyList [$k] ['date'] = "";
  4048. $verifyList [$k] ['opinion'] = "";
  4049. $verifyList [$k] ['status'] = "";
  4050. if (empty ( $verifyStaff )) {
  4051. $verifyList [$k] ['date'] = "";
  4052. $verifyList [$k] ['opinion'] = "";
  4053. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4054. $verifyList [$k] ['status'] = 4;
  4055. $flag = false;
  4056. }
  4057. } else {
  4058. foreach ( $verifyStaff as $m => $u ) {
  4059. if ($v [0] == $m) {
  4060. $verifyList [$k] ['date'] = $u ['date'];
  4061. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4062. $verifyList [$k] ['status'] = $u ['status'];
  4063. $flag = false;
  4064. break;
  4065. }
  4066. }
  4067. $endStaffArray = end ( $verifyStaff );
  4068. if (isset ( $endStaffArray ['ROLE'] )) {
  4069. } else {
  4070. // $endKey=key($verifyStaff);
  4071. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4072. // $button=4;
  4073. // $verifyList[$k]['status']=4;
  4074. // }
  4075. }
  4076. }
  4077. }
  4078. $rolename ['name'] = '';
  4079. if (! empty ( $roleId )) {
  4080. Doo::loadModel ( 'role' );
  4081. $role = new role ();
  4082. $rolename = $role->getOne ( array (
  4083. 'where' => 'rid=' . $roleId,
  4084. 'asArray' => true
  4085. ) );
  4086. }
  4087. if (! empty ( $verifyStaff ))
  4088. $endStaffArray = end ( $verifyStaff );
  4089. $KOP = false;
  4090. foreach ( $roleArrayCopy as $P => $A ) {
  4091. foreach ( $A as $MKI => $AVL ) {
  4092. if (! empty ( $verifyStaff )) {
  4093. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4094. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4095. $button = 4;
  4096. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4097. }
  4098. foreach ( $verifyStaff as $m => $u ) {
  4099. $AVLFK = $AVL [0] . '_R';
  4100. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4101. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4102. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4103. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4104. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4105. break;
  4106. }
  4107. }
  4108. } else {
  4109. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4110. $button = 4;
  4111. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4112. }
  4113. }
  4114. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4115. $KOP = true;
  4116. }
  4117. }
  4118. foreach ( $roleArrayCopy as $k => $v ) {
  4119. foreach ( $verifyList as $m => $n ) {
  4120. if ($n [0] == $k) {
  4121. array_splice ( $verifyList, $m, 1, $v );
  4122. }
  4123. }
  4124. }
  4125. $receiptList [$key] ['verifyList'] = $verifyList;
  4126. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4127. 'where' => 'sid=' . $value ['staff'],
  4128. 'asArray' => true
  4129. ) );
  4130. $receiptList [$key] ['button'] = $button;
  4131. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  4132. }
  4133. // print_r($receiptList);die;
  4134. $mothHtml = "";
  4135. for($i = 1; $i <= 12; $i ++) {
  4136. if ($moth == $i)
  4137. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4138. else
  4139. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4140. }
  4141. $dateHtml = "";
  4142. $now = date ( "Y" );
  4143. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  4144. if ($YEARD <= $now) {
  4145. $dateHtml .= '<option ';
  4146. if ($year == $YEARD) {
  4147. $dateHtml .= 'selected ';
  4148. }
  4149. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  4150. }
  4151. }
  4152. $data ['dateHtml'] = $dateHtml;
  4153. $data ['mothHtml'] = $mothHtml;
  4154. $data ['receiptList'] = $receiptList;
  4155. $data ['memu'] = "receipt";
  4156. $data ['staff'] = $this->staff;
  4157. $data ['receiptMemu'] = 'expenses';
  4158. $data ['verifyId'] = $this->verifyId;
  4159. $data ['executeId'] = $this->executeId;
  4160. $data ['item'] = $item;
  4161. $data ['year'] = $year;
  4162. $this->render ( "/admin/expenses", $data );
  4163. }
  4164. function expensesCollect() {
  4165. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4166. Doo::loadModel ( 'receipt' );
  4167. $receipt = new receipt ();
  4168. Doo::loadModel ( 'L_category' );
  4169. $Lcategory = new L_category ();
  4170. Doo::loadModel ( 'verify' );
  4171. Doo::loadModel ( 'statistics' );
  4172. $statistics = new statistics ();
  4173. $verify = new verify ();
  4174. Doo::loadModel ( 'staff' );
  4175. $staff = new staff ();
  4176. Doo::loadModel ( 'loanReceipt' );
  4177. $loanReceipt = new loanReceipt ();
  4178. $receiptList = $receipt->find ( array (//去掉
  4179. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  4180. 'desc' => 'rid',
  4181. 'asArray' => true
  4182. ) );
  4183. $loanList = $loanReceipt->find ( array (
  4184. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4185. 'desc' => 'rid',
  4186. 'asArray' => true
  4187. ) );
  4188. /*
  4189. * $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;
  4190. */
  4191. $data ['explanation'] = '';
  4192. if (! empty ( $loanList ))
  4193. $data ['explanation'] = $loanList [0] ['explanation'];
  4194. $Locate = 0;
  4195. $roleId = 0;
  4196. $button = 0;
  4197. foreach ( $receiptList as $key => $value ) {
  4198. $receiptList [$key] ['Locate'] = $Locate;
  4199. $Locate ++;
  4200. $receiptList [$key] ['reviseDetail'] = array ();
  4201. if (! empty ( $value ['reviseDetail'] ))
  4202. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4203. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4204. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4205. $categoryDetil = $Lcategory->getOne ( array (
  4206. 'where' => 'cid=' . $value ['cid'],
  4207. 'asArray' => true
  4208. ) );
  4209. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4210. // 检测编辑状态
  4211. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  4212. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  4213. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  4214. else
  4215. $verifyList ['staff'] = $value ['verifyBreakup'];
  4216. } else
  4217. $verifyList = $verify->getOne ( array (
  4218. 'where' => 'vid=' . $value ['verify'],
  4219. 'asArray' => true
  4220. ) );
  4221. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4222. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4223. Doo::loadModel ( 'role' );
  4224. $role = new role ();
  4225. $flag = true;
  4226. $roleKey = 0;
  4227. $endStaffArray = array ();
  4228. $roleArrayCopy = array ();
  4229. foreach ( $verifyList as $k => $v ) {
  4230. // init verifyStaff
  4231. if ($v [1] == 'ROLE') {
  4232. if (! empty ( $verifyStaff )) {
  4233. $endStaffArray = end ( $verifyStaff );
  4234. // if ($v[0]==$endStaffArray['nextStaff']){
  4235. // $roleId=$v[0];
  4236. // }
  4237. }
  4238. $roleVerify = json_decode ( $v [3], true );
  4239. $roleKey = $k;
  4240. $roleArray = array ();
  4241. $rolename = $role->getOne ( array (
  4242. 'where' => 'rid=' . $v [0],
  4243. 'asArray' => true
  4244. ) );
  4245. foreach ( $roleVerify as $o => $p ) {
  4246. $staffID = explode ( '_', $p );
  4247. $staffInfo = $staff->getOne ( array (
  4248. 'where' => 'sid=' . $staffID [0],
  4249. 'asArray' => true
  4250. ) );
  4251. // print_r($staffID);
  4252. $exp = array (
  4253. 0 => $staffInfo ['sid'],
  4254. 1 => $staffID [1],
  4255. 2 => $staffInfo ['avatar'],
  4256. 'date' => '',
  4257. 'date' => '',
  4258. 'opinion' => '',
  4259. 'status' => '',
  4260. 'rolename' => $rolename ['name']
  4261. );
  4262. array_push ( $roleArray, $exp );
  4263. }
  4264. $roleArrayCopy [$v [0]] = $roleArray;
  4265. // $verifyList[$k]['roleArray']=$roleArray;
  4266. }
  4267. $verifyList [$k] ['date'] = "";
  4268. $verifyList [$k] ['opinion'] = "";
  4269. $verifyList [$k] ['status'] = "";
  4270. if (empty ( $verifyStaff )) {
  4271. $verifyList [$k] ['date'] = "";
  4272. $verifyList [$k] ['opinion'] = "";
  4273. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4274. $verifyList [$k] ['status'] = 4;
  4275. $flag = false;
  4276. }
  4277. } else {
  4278. foreach ( $verifyStaff as $m => $u ) {
  4279. if ($v [0] == $m) {
  4280. $verifyList [$k] ['date'] = $u ['date'];
  4281. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4282. $verifyList [$k] ['status'] = $u ['status'];
  4283. $flag = false;
  4284. break;
  4285. }
  4286. }
  4287. $endStaffArray = end ( $verifyStaff );
  4288. if (isset ( $endStaffArray ['ROLE'] )) {
  4289. } else {
  4290. // $endKey=key($verifyStaff);
  4291. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4292. // $button=4;
  4293. // $verifyList[$k]['status']=4;
  4294. // }
  4295. }
  4296. }
  4297. }
  4298. $rolename ['name'] = '';
  4299. if (! empty ( $roleId )) {
  4300. Doo::loadModel ( 'role' );
  4301. $role = new role ();
  4302. $rolename = $role->getOne ( array (
  4303. 'where' => 'rid=' . $roleId,
  4304. 'asArray' => true
  4305. ) );
  4306. }
  4307. if (! empty ( $verifyStaff ))
  4308. $endStaffArray = end ( $verifyStaff );
  4309. $KOP = false;
  4310. foreach ( $roleArrayCopy as $P => $A ) {
  4311. foreach ( $A as $MKI => $AVL ) {
  4312. if (! empty ( $verifyStaff )) {
  4313. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4314. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4315. $button = 4;
  4316. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4317. }
  4318. foreach ( $verifyStaff as $m => $u ) {
  4319. $AVLFK = $AVL [0] . '_R';
  4320. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4321. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4322. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4323. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4324. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4325. break;
  4326. }
  4327. }
  4328. } else {
  4329. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4330. $button = 4;
  4331. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4332. }
  4333. }
  4334. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4335. $KOP = true;
  4336. }
  4337. }
  4338. foreach ( $roleArrayCopy as $k => $v ) {
  4339. foreach ( $verifyList as $m => $n ) {
  4340. if ($n [0] == $k) {
  4341. array_splice ( $verifyList, $m, 1, $v );
  4342. }
  4343. }
  4344. }
  4345. // 费用执行人相关数据
  4346. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4347. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4348. foreach ( $executeCopy as $k => $v ) {
  4349. $executeCopy [$k] ['date'] = '';
  4350. $executeCopy [$k] ['opinion'] = '';
  4351. $executeCopy [$k] ['status'] = '';
  4352. if (! empty ( $executeStaff ))
  4353. foreach ( $executeStaff as $m => $u ) {
  4354. if ($v [0] == $m) {
  4355. $executeCopy [$k] ['date'] = $u ['date'];
  4356. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4357. $executeCopy [$k] ['status'] = $u ['status'];
  4358. break;
  4359. }
  4360. }
  4361. }
  4362. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4363. $receiptList [$key] ['verifyList'] = $verifyList;
  4364. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4365. 'where' => 'sid=' . $value ['staff'],
  4366. 'asArray' => true
  4367. ) );
  4368. $receiptList [$key] ['button'] = $button;
  4369. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4370. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4371. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4372. $receiptList [$key] ['relust'] = $relust;
  4373. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4374. }
  4375. Doo::loadModel ( 'enclosur' );
  4376. $enclosur = new enclosur ();
  4377. $enclosurList = $enclosur->find ( array (
  4378. 'where' => 'rid=' . $rid,
  4379. 'asArray' => true
  4380. ) );
  4381. $enclosurHtml = '';
  4382. foreach ( $enclosurList as $value ) {
  4383. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4384. }
  4385. $receiptList[0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  4386. $data ['enclosurHtml'] = $enclosurHtml;
  4387. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  4388. $data ['receiptList'] = $receiptList;
  4389. $data ['memu'] = "receipt";
  4390. $data ['staff'] = $this->staff;
  4391. $data ['receiptMemu'] = 'expenses';
  4392. $data ['verifyId'] = $this->verifyId;
  4393. $data ['executeId'] = $this->executeId;
  4394. if($receiptList[0]['receiptClass']==2){
  4395. if(!empty($receiptList[0]['itinerary2'])){
  4396. $this->render ( "/receipt/feeTraveDetail2", $data );
  4397. }else{
  4398. $this->render ( "/receipt/feeTraveDetail", $data );
  4399. }
  4400. }else{
  4401. $this->render ( "/admin/expensesCollect", $data );
  4402. }
  4403. }
  4404. function approvalExpenses() {
  4405. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  4406. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4407. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4408. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4409. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4410. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  4411. // echo $rdate;
  4412. if (empty ( $status ))
  4413. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4414. $page_size = 8;
  4415. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4416. $vidList = array ();
  4417. $button = 0;
  4418. Doo::loadModel ( 'verify' );
  4419. $verify = new verify ();
  4420. Doo::loadModel ( 'receipt' );
  4421. $receipt = new receipt ();
  4422. Doo::loadModel ( 'staff' );
  4423. $staff = new staff ();
  4424. Doo::loadModel ( 'L_category' );
  4425. $Lcategory = new L_category ();
  4426. // user verify ID
  4427. $verifyDetail = $verify->find ( array (
  4428. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4429. 'asArray' => true
  4430. ) );
  4431. foreach ( $verifyDetail as $key => $value ) {
  4432. array_push ( $vidList, $value ['vid'] );
  4433. }
  4434. $vid = implode ( ",", $vidList );
  4435. if (empty ( $verifyDetail ))
  4436. $vid = 0;
  4437. // if ($status==0)
  4438. // $dateCondition="";
  4439. // else
  4440. $dateCondition = " ";
  4441. // if (! empty ( $month ))
  4442. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  4443. if ($status == 'done' || $status == 'termination') {
  4444. if (! empty ( $year )) {
  4445. $dateCondition = " and Year(pastDate) =" . $year;
  4446. if (! empty ( $month ))
  4447. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4448. }
  4449. } elseif ($status == 'finish') {
  4450. if (! empty ( $year )) {
  4451. $dateCondition = " and Year(pastDate) =" . $year;
  4452. if (! empty ( $month ))
  4453. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4454. }
  4455. }
  4456. // date ( 'Y-m' )
  4457. // if (! empty ( $rdate ) && $status == 'done')
  4458. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  4459. // elseif (! empty ( $rdate ))
  4460. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  4461. $categoryList = $Lcategory->find ( array (
  4462. 'asArray' => true
  4463. ) );
  4464. $staffList = $staff->find ( array (
  4465. 'where' => 'cid=' . $cid,
  4466. 'asArray' => true
  4467. ) );
  4468. $cateCondition = "";
  4469. $staffCondition = "";
  4470. $approvalCondition = "";
  4471. if (! empty ( $cid )) {
  4472. $cateCondition = ' and cid=' . $cid;
  4473. }
  4474. if (! empty ( $sid )) {
  4475. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  4476. $cateCondition = "";
  4477. }
  4478. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  4479. if ($status == 'pendApproval') {
  4480. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4481. }
  4482. if ($status == 'ongoing') {
  4483. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  4484. }
  4485. if ($status == 'done') {
  4486. $approvalCondition = ' and (status=8 or status=9 ) ';
  4487. }
  4488. if ($status == 'termination') {
  4489. $approvalCondition = " and status=3";
  4490. }
  4491. if ($status == 'finish') {
  4492. $approvalCondition = " and (status=1 or status=8 or status=9 or status=10)";
  4493. }
  4494. $pageinfo ['page'] = array (
  4495. 'previous' => ''
  4496. );
  4497. if(!empty($receiptOrder)){
  4498. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4499. $receiptList = $receipt->find ( array ( // $dateCondition
  4500. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  4501. 'desc' => 'rid',
  4502. 'asArray' => true
  4503. ) );
  4504. }else{
  4505. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  4506. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4507. $receiptList = $receipt->find ( array ( // $dateCondition.
  4508. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4509. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  4510. 'desc' => 'rid',
  4511. 'asArray' => true
  4512. ) );
  4513. } else {
  4514. $receiptList = $receipt->find ( array ( // $dateCondition
  4515. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4516. 'desc' => 'rid',
  4517. 'asArray' => true
  4518. ) );
  4519. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4520. }
  4521. }
  4522. $rLRes = $receipt->find ( array (
  4523. '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 . ')',
  4524. 'desc' => 'rid',
  4525. 'asArray' => true
  4526. ) );
  4527. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4528. // print_r($receiptList);
  4529. Doo::loadClass ( 'XDeode' );
  4530. $XDeode = new XDeode ( 7 );
  4531. $Locate = 0;
  4532. //
  4533. $reportList = $reportCateList = array ();
  4534. foreach ( $receiptList as $key => $value ) {
  4535. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  4536. $receiptList [$key] ['Locate'] = $Locate;
  4537. $Locate ++;
  4538. $receiptList [$key] ['reviseDetail'] = array ();
  4539. if (! empty ( $value ['reviseDetail'] ))
  4540. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4541. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4542. $categoryDetil = $Lcategory->getOne ( array (
  4543. 'where' => 'cid=' . $value ['cid'],
  4544. 'asArray' => true
  4545. ) );
  4546. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4547. $verifyList = $verify->getOne ( array (
  4548. 'where' => 'vid=' . $value ['verify'],
  4549. 'asArray' => true
  4550. ) );
  4551. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4552. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4553. foreach ( $verifyList as $k => $v ) {
  4554. // init verifyStaff
  4555. $verifyList [$k] ['date'] = "";
  4556. $verifyList [$k] ['opinion'] = "";
  4557. $verifyList [$k] ['status'] = "";
  4558. if (empty ( $verifyStaff )) {
  4559. $verifyList [$k] ['date'] = "";
  4560. $verifyList [$k] ['opinion'] = "";
  4561. if ($v [0] == $this->staff [0] ['sid']) {
  4562. $verifyList [$k] ['status'] = 4;
  4563. $button = 4;
  4564. }
  4565. } else {
  4566. $flag = true;
  4567. foreach ( $verifyStaff as $m => $u ) {
  4568. if ($v [0] == $m) {
  4569. $verifyList [$k] ['date'] = $u ['date'];
  4570. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4571. $verifyList [$k] ['status'] = $u ['status'];
  4572. $flag = false;
  4573. break;
  4574. }
  4575. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4576. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4577. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4578. }
  4579. if ($flag) { // 检测可编辑
  4580. if ($v [0] == $this->staff [0] ['sid']) {
  4581. $verifyList [$k] ['status'] = 4;
  4582. $button = 4;
  4583. }
  4584. }
  4585. }
  4586. }
  4587. $receiptList [$key] ['verifyList'] = $verifyList;
  4588. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4589. 'where' => 'sid=' . $value ['staff'],
  4590. 'asArray' => true
  4591. ) );
  4592. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4593. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4594. $receiptList [$key] ['button'] = $button;
  4595. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  4596. //获得培训班结算RID 借款费用--已经锁定
  4597. if($value['status']==10){
  4598. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  4599. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  4600. }
  4601. }
  4602. $reportList = array_unique ( $reportList );
  4603. $reportHtml = '';
  4604. foreach ( $reportList as $key => $value ) {
  4605. $v = explode ( "-", $value );
  4606. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  4607. }
  4608. // print_r($reportList)
  4609. $data ['reportHtml'] = $reportHtml;
  4610. $reportCateList = array_unique ( $reportCateList );
  4611. $reportCateHtml = '';
  4612. foreach ( $reportCateList as $key => $value ) {
  4613. $v = explode ( "-", $value );
  4614. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  4615. }
  4616. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  4617. $data ['reportCateHtml'] = $reportCateHtml;
  4618. // print_r($receiptList);die;
  4619. // $data['verifyDetail']=$verifyDetail;
  4620. $mothHtml = "";
  4621. for($i = 1; $i <= 12; $i ++) {
  4622. if ($month == $i)
  4623. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  4624. else
  4625. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  4626. }
  4627. $data ['mothHtml'] = $mothHtml;
  4628. $dateHtml = "";
  4629. $now = date ( "Y" );
  4630. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  4631. if ($YEARD <= $now) {
  4632. $dateHtml .= '<option ';
  4633. if ($year == $YEARD) {
  4634. $dateHtml .= 'selected ';
  4635. }
  4636. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  4637. }
  4638. }
  4639. $data ['dateHtml'] = $dateHtml;
  4640. $data ['page'] = $pageinfo;
  4641. $data ['receiptList'] = $receiptList;
  4642. $data ['receiptApprovalCount'] = count ( $rLRes );
  4643. $data ['status'] = $status;
  4644. $data ['year'] = $year;
  4645. $data ['month'] = $month;
  4646. $data ['categoryList'] = $categoryList;
  4647. $data ['staffList'] = $staffList;
  4648. $data ['cid'] = $cid;
  4649. $data ['sid'] = $sid;
  4650. // print_r($receiptList);
  4651. $data['receiptOrder']=$receiptOrder;
  4652. $data ['memu'] = "receipt";
  4653. $data ['staff'] = $this->staff;
  4654. $data ['receiptMemu'] = 'approvalExpenses';
  4655. $data ['verifyId'] = $this->verifyId;
  4656. $data ['executeId'] = $this->executeId;
  4657. $this->render ( "/admin/approvalExpenses", $data );
  4658. }
  4659. private function _expensesDoc(){
  4660. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  4661. Doo::loadClass ( 'XDeode' );
  4662. $XDeode = new XDeode ( 5 );
  4663. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  4664. $rid = $XDeode->decode ( $rid );
  4665. if (! is_numeric ( $rid ))
  4666. die ( 'illegal request' );
  4667. Doo::loadModel ( 'receipt' );
  4668. $receipt = new receipt ();
  4669. Doo::loadModel ( 'L_category' );
  4670. $Lcategory = new L_category ();
  4671. Doo::loadModel ( 'verify' );
  4672. Doo::loadModel ( 'statistics' );
  4673. $statistics = new statistics ();
  4674. $verify = new verify ();
  4675. Doo::loadModel ( 'staff' );
  4676. $staff = new staff ();
  4677. Doo::loadModel ( 'loanReceipt' );
  4678. $loanReceipt = new loanReceipt ();
  4679. $receiptList = $receipt->find ( array (
  4680. 'where' => ' rid=' . $rid,
  4681. 'desc' => 'rid',
  4682. 'asArray' => true
  4683. ) );
  4684. $loanList = array ();
  4685. if (! empty ( $receiptList ))
  4686. $loanList = $loanReceipt->find ( array (
  4687. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4688. 'desc' => 'rid',
  4689. 'asArray' => true
  4690. ) );
  4691. $Locate = 0;
  4692. $roleId = 0;
  4693. $button = 0;
  4694. foreach ( $loanList as $key => $value ) {
  4695. $loanList [$key] ['Locate'] = $Locate;
  4696. $Locate ++;
  4697. $loanList [$key] ['reviseDetail'] = array ();
  4698. if (! empty ( $value ['reviseDetail'] ))
  4699. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4700. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4701. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4702. $categoryDetil = $Lcategory->getOne ( array (
  4703. 'where' => 'cid=' . $value ['cid'],
  4704. 'asArray' => true
  4705. ) );
  4706. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4707. // 检测编辑状态
  4708. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  4709. $verifyList ['staff'] = $value ['verifyBreakup'];
  4710. else
  4711. $verifyList = $verify->getOne ( array (
  4712. 'where' => 'vid=' . $value ['verify'],
  4713. 'asArray' => true
  4714. ) );
  4715. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4716. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4717. Doo::loadModel ( 'role' );
  4718. $role = new role ();
  4719. $flag = true;
  4720. $roleKey = 0;
  4721. $endStaffArray = array ();
  4722. $roleArrayCopy = array ();
  4723. foreach ( $verifyList as $k => $v ) {
  4724. // init verifyStaff
  4725. if ($v [1] == 'ROLE') {
  4726. if (! empty ( $verifyStaff )) {
  4727. $endStaffArray = end ( $verifyStaff );
  4728. // if ($v[0]==$endStaffArray['nextStaff']){
  4729. // $roleId=$v[0];
  4730. // }
  4731. }
  4732. $roleVerify = json_decode ( $v [3], true );
  4733. $roleKey = $k;
  4734. $roleArray = array ();
  4735. $rolename = $role->getOne ( array (
  4736. 'where' => 'rid=' . $v [0],
  4737. 'asArray' => true
  4738. ) );
  4739. foreach ( $roleVerify as $o => $p ) {
  4740. $staffID = explode ( '_', $p );
  4741. $staffInfo = $staff->getOne ( array (
  4742. 'where' => 'sid=' . $staffID [0],
  4743. 'asArray' => true
  4744. ) );
  4745. // print_r($staffID);
  4746. $exp = array (
  4747. 0 => $staffInfo ['sid'],
  4748. 1 => $staffID [1],
  4749. 2 => $staffInfo ['avatar'],
  4750. 'date' => '',
  4751. 'date' => '',
  4752. 'opinion' => '',
  4753. 'status' => '',
  4754. 'rolename' => $rolename ['name']
  4755. );
  4756. array_push ( $roleArray, $exp );
  4757. }
  4758. $roleArrayCopy [$v [0]] = $roleArray;
  4759. // $verifyList[$k]['roleArray']=$roleArray;
  4760. }
  4761. $verifyList [$k] ['date'] = "";
  4762. $verifyList [$k] ['opinion'] = "";
  4763. $verifyList [$k] ['status'] = "";
  4764. if (empty ( $verifyStaff )) {
  4765. $verifyList [$k] ['date'] = "";
  4766. $verifyList [$k] ['opinion'] = "";
  4767. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4768. $verifyList [$k] ['status'] = 4;
  4769. $flag = false;
  4770. }
  4771. } else {
  4772. foreach ( $verifyStaff as $m => $u ) {
  4773. if ($v [0] == $m) {
  4774. $verifyList [$k] ['date'] = $u ['date'];
  4775. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4776. $verifyList [$k] ['status'] = $u ['status'];
  4777. $flag = false;
  4778. break;
  4779. }
  4780. }
  4781. $endStaffArray = end ( $verifyStaff );
  4782. if (isset ( $endStaffArray ['ROLE'] )) {
  4783. } else {
  4784. // $endKey=key($verifyStaff);
  4785. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4786. // $button=4;
  4787. // $verifyList[$k]['status']=4;
  4788. // }
  4789. }
  4790. }
  4791. }
  4792. $rolename ['name'] = '';
  4793. if (! empty ( $roleId )) {
  4794. Doo::loadModel ( 'role' );
  4795. $role = new role ();
  4796. $rolename = $role->getOne ( array (
  4797. 'where' => 'rid=' . $roleId,
  4798. 'asArray' => true
  4799. ) );
  4800. }
  4801. if (! empty ( $verifyStaff ))
  4802. $endStaffArray = end ( $verifyStaff );
  4803. $KOP = false;
  4804. foreach ( $roleArrayCopy as $P => $A ) {
  4805. foreach ( $A as $MKI => $AVL ) {
  4806. if (! empty ( $verifyStaff )) {
  4807. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4808. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4809. $button = 4;
  4810. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4811. }
  4812. foreach ( $verifyStaff as $m => $u ) {
  4813. $AVLFK = $AVL [0] . '_R';
  4814. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4815. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4816. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4817. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4818. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4819. break;
  4820. }
  4821. }
  4822. } else {
  4823. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4824. $button = 4;
  4825. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4826. }
  4827. }
  4828. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4829. $KOP = true;
  4830. }
  4831. }
  4832. foreach ( $roleArrayCopy as $k => $v ) {
  4833. foreach ( $verifyList as $m => $n ) {
  4834. if ($n [0] == $k) {
  4835. array_splice ( $verifyList, $m, 1, $v );
  4836. }
  4837. }
  4838. }
  4839. $loanList [$key] ['verifyList'] = $verifyList;
  4840. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4841. 'where' => 'sid=' . $value ['staff'],
  4842. 'asArray' => true
  4843. ) );
  4844. $loanList [$key] ['button'] = $button;
  4845. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  4846. }
  4847. $data ['loanList'] = $loanList;
  4848. //print_r($loanList);
  4849. $Locate = 0;
  4850. $roleId = 0;
  4851. $button = 0;
  4852. foreach ( $receiptList as $key => $value ) {
  4853. $receiptList [$key] ['Locate'] = $Locate;
  4854. $Locate ++;
  4855. $receiptList [$key] ['reviseDetail'] = array ();
  4856. if (! empty ( $value ['reviseDetail'] ))
  4857. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4858. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4859. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4860. $categoryDetil = $Lcategory->getOne ( array (
  4861. 'where' => 'cid=' . $value ['cid'],
  4862. 'asArray' => true
  4863. ) );
  4864. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4865. // 检测编辑状态
  4866. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  4867. $verifyList ['staff'] = $value ['verifyBreakup'];
  4868. } else
  4869. $verifyList = $verify->getOne ( array (
  4870. 'where' => 'vid=' . $value ['verify'],
  4871. 'asArray' => true
  4872. ) );
  4873. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4874. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4875. Doo::loadModel ( 'role' );
  4876. $role = new role ();
  4877. if ($verifyList == NULL)
  4878. $verifyList = array ();
  4879. $flag = true;
  4880. $roleKey = 0;
  4881. $endStaffArray = array ();
  4882. $roleArrayCopy = array ();
  4883. foreach ( $verifyList as $k => $v ) {
  4884. // init verifyStaff
  4885. if ($v [1] == 'ROLE') {
  4886. if (! empty ( $verifyStaff )) {
  4887. $endStaffArray = end ( $verifyStaff );
  4888. // if ($v[0]==$endStaffArray['nextStaff']){
  4889. // $roleId=$v[0];
  4890. // }
  4891. }
  4892. $roleVerify = json_decode ( $v [3], true );
  4893. $roleKey = $k;
  4894. $roleArray = array ();
  4895. $rolename = $role->getOne ( array (
  4896. 'where' => 'rid=' . $v [0],
  4897. 'asArray' => true
  4898. ) );
  4899. foreach ( $roleVerify as $o => $p ) {
  4900. $staffID = explode ( '_', $p );
  4901. $staffInfo = $staff->getOne ( array (
  4902. 'where' => 'sid=' . $staffID [0],
  4903. 'asArray' => true
  4904. ) );
  4905. // print_r($staffID);
  4906. $exp = array (
  4907. 0 => $staffInfo ['sid'],
  4908. 1 => $staffID [1],
  4909. 2 => $staffInfo ['avatar'],
  4910. 'date' => '',
  4911. 'date' => '',
  4912. 'opinion' => '',
  4913. 'status' => '',
  4914. 'rolename' => $rolename ['name']
  4915. );
  4916. array_push ( $roleArray, $exp );
  4917. }
  4918. $roleArrayCopy [$v [0]] = $roleArray;
  4919. // $verifyList[$k]['roleArray']=$roleArray;
  4920. }
  4921. $verifyList [$k] ['date'] = "";
  4922. $verifyList [$k] ['opinion'] = "";
  4923. $verifyList [$k] ['status'] = "";
  4924. if (empty ( $verifyStaff )) {
  4925. $verifyList [$k] ['date'] = "";
  4926. $verifyList [$k] ['opinion'] = "";
  4927. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4928. $verifyList [$k] ['status'] = 4;
  4929. $flag = false;
  4930. }
  4931. } else {
  4932. foreach ( $verifyStaff as $m => $u ) {
  4933. if ($v [0] == $m) {
  4934. $verifyList [$k] ['date'] = $u ['date'];
  4935. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4936. $verifyList [$k] ['status'] = $u ['status'];
  4937. $flag = false;
  4938. break;
  4939. }
  4940. }
  4941. $endStaffArray = end ( $verifyStaff );
  4942. if (isset ( $endStaffArray ['ROLE'] )) {
  4943. } else {
  4944. // $endKey=key($verifyStaff);
  4945. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4946. // $button=4;
  4947. // $verifyList[$k]['status']=4;
  4948. // }
  4949. }
  4950. }
  4951. }
  4952. $FC = @$rolename ['name'];
  4953. $rolename ['name'] = '';
  4954. if (! empty ( $roleId )) {
  4955. Doo::loadModel ( 'role' );
  4956. $role = new role ();
  4957. $rolename = $role->getOne ( array (
  4958. 'where' => 'rid=' . $roleId,
  4959. 'asArray' => true
  4960. ) );
  4961. }
  4962. if (! empty ( $verifyStaff ))
  4963. $endStaffArray = end ( $verifyStaff );
  4964. $KOP = false;
  4965. foreach ( $roleArrayCopy as $P => $A ) {
  4966. foreach ( $A as $MKI => $AVL ) {
  4967. if (! empty ( $verifyStaff )) {
  4968. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4969. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4970. $button = 4;
  4971. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4972. }
  4973. foreach ( $verifyStaff as $m => $u ) {
  4974. $AVLFK = $AVL [0] . '_R';
  4975. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4976. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4977. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4978. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4979. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4980. break;
  4981. }
  4982. }
  4983. } else {
  4984. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4985. $button = 4;
  4986. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4987. }
  4988. }
  4989. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4990. $KOP = true;
  4991. }
  4992. }
  4993. foreach ( $roleArrayCopy as $k => $v ) {
  4994. foreach ( $verifyList as $m => $n ) {
  4995. if ($n [0] == $k) {
  4996. array_splice ( $verifyList, $m, 1, $v );
  4997. }
  4998. }
  4999. }
  5000. // 费用执行人相关数据
  5001. $executeCopy = json_decode ( $value ['executeCopy'], true );
  5002. $executeStaff = json_decode ( $value ['executeStaff'], true );
  5003. foreach ( $executeCopy as $k => $v ) {
  5004. $executeCopy [$k] ['date'] = '';
  5005. $executeCopy [$k] ['opinion'] = '';
  5006. $executeCopy [$k] ['status'] = '';
  5007. if (! empty ( $executeStaff ))
  5008. foreach ( $executeStaff as $m => $u ) {
  5009. if ($v [0] == $m) {
  5010. $executeCopy [$k] ['date'] = $u ['date'];
  5011. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  5012. $executeCopy [$k] ['status'] = $u ['status'];
  5013. break;
  5014. }
  5015. }
  5016. }
  5017. $receiptList [$key] ['executeCopy'] = $executeCopy;
  5018. // print_r($verifyList);
  5019. $receiptList [$key] ['verifyList'] = $verifyList;
  5020. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5021. 'where' => 'sid=' . $value ['staff'],
  5022. 'asArray' => true
  5023. ) );
  5024. $receiptList [$key] ['button'] = $button;
  5025. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5026. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5027. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5028. $receiptList [$key] ['relust'] = $relust;
  5029. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5030. }
  5031. // print_r($receiptList);
  5032. // 获取审批日志
  5033. Doo::loadModel ( 'receiptLog' );
  5034. $receiptLog = new receiptLog ();
  5035. $rlList = array ();
  5036. $rlInfo = $receiptLog->getOne ( array (
  5037. 'where' => 'rid=' . $rid . ' and status=4',
  5038. 'asArray' => true
  5039. ) );
  5040. // $tijdate = $receiptLog->getOne ( array (
  5041. // 'where' => 'rid=' . $rid . ' and status=2',
  5042. // 'asc' => 'rlid',
  5043. // 'asArray' => true
  5044. // ) );
  5045. if (! empty ( $rlInfo )) {
  5046. $rlList = $receiptLog->find ( array (
  5047. 'where' => 'rid=' . $rid,
  5048. 'asc' => 'rlid',
  5049. 'asArray' => true
  5050. ) );
  5051. }
  5052. $RN=array();
  5053. if (!empty( $rolename ['staff'])){
  5054. $RN = @json_decode ( $rolename ['staff'] );
  5055. }
  5056. //
  5057. foreach ( $rlList as $key => $value ) {
  5058. $rlList [$key] ['rolename'] = '';
  5059. foreach ( $RN as $k => $v ) {
  5060. $id = explode ( "_", $v );
  5061. if ($id [0] == $value ['uid']) {
  5062. $rlList [$key] ['rolename'] = $FC;
  5063. break;
  5064. }
  5065. }
  5066. }
  5067. Doo::loadModel ( 'enclosur' );
  5068. $enclosur = new enclosur ();
  5069. $enclosurList = $enclosur->find ( array (
  5070. 'where' => 'rid=' . $rid,
  5071. 'asArray' => true
  5072. ) );
  5073. $enclosurHtml = '';
  5074. foreach ( $enclosurList as $value ) {
  5075. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5076. }
  5077. $data ['enclosurHtml'] = $enclosurHtml;
  5078. $receiptList [0] ['rlList'] = $rlList;
  5079. $data ['receiptList'] = $receiptList;
  5080. $data ['receiptList'][0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  5081. // print_r($receiptList);
  5082. $data ['memu'] = "receipt";
  5083. $data ['staff'] = $this->staff;
  5084. $data ['receiptMemu'] = 'approvalExpenses';
  5085. $data ['verifyId'] = $this->verifyId;
  5086. $data ['executeId'] = $this->executeId;
  5087. return $data;
  5088. }
  5089. function expensesDoc() {
  5090. $data=$this->_expensesDoc();
  5091. if(!empty($data['receiptList'][0]['itinerary2'])){
  5092. $this->render ( "/receipt/feeTraveView", $data );
  5093. }else{
  5094. $this->render ( "/admin/expensesDoc", $data );
  5095. }
  5096. }
  5097. function expensesDocPrint(){
  5098. $data=$this->_expensesDoc();
  5099. $this->render ( "/receipt/expensesDocPrint", $data );
  5100. }
  5101. function expensesEdi() {
  5102. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5103. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5104. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5105. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5106. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5107. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5108. if (empty ( $status ))
  5109. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5110. $vidList = array ();
  5111. $button = 0;
  5112. Doo::loadModel ( 'verify' );
  5113. Doo::loadModel ( 'receipt' );
  5114. Doo::loadModel ( 'staff' );
  5115. $staff = new staff ();
  5116. $receipt = new receipt ();
  5117. $verify = new verify ();
  5118. Doo::loadModel ( 'L_category' );
  5119. $Lcategory = new L_category ();
  5120. Doo::loadModel ( 'enclosur' );
  5121. $enclosur = new enclosur ();
  5122. // user verify ID
  5123. $verifyDetail = $verify->find ( array (
  5124. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5125. 'asArray' => true
  5126. ) );
  5127. foreach ( $verifyDetail as $key => $value ) {
  5128. array_push ( $vidList, $value ['vid'] );
  5129. }
  5130. $vid = implode ( ",", $vidList );
  5131. if (empty ( $verifyDetail ))
  5132. $vid = 0;
  5133. $categoryList = $Lcategory->find ( array (
  5134. 'asArray' => true
  5135. ) );
  5136. $staffList = $staff->find ( array (
  5137. 'where' => 'cid=' . $cid,
  5138. 'asArray' => true
  5139. ) );
  5140. $ap = "";
  5141. if ($status == 4) {
  5142. $ap = 4;
  5143. $status = 2;
  5144. }
  5145. // get Receipt By verifyID status 2
  5146. $receiptList = $receipt->find ( array (
  5147. 'where' => 'rid =' . $rid . ' and status=2',
  5148. 'desc' => 'rid',
  5149. 'asArray' => true
  5150. ) );
  5151. if (empty ( $receiptList )) {
  5152. die ( 'illegal request' );
  5153. }
  5154. $Locate = 0;
  5155. $roleId = 0;
  5156. if ($ap == 4)
  5157. $status = 4;
  5158. foreach ( $receiptList as $key => $value ) {
  5159. $receiptList [$key] ['Locate'] = $Locate;
  5160. $Locate ++;
  5161. $receiptList [$key] ['reviseDetail'] = array ();
  5162. if (! empty ( $value ['reviseDetail'] ))
  5163. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5164. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5165. $categoryDetil = $Lcategory->getOne ( array (
  5166. 'where' => 'cid=' . $value ['cid'],
  5167. 'asArray' => true
  5168. ) );
  5169. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5170. // 检测编辑状态
  5171. $verifyList = $verify->getOne ( array (
  5172. 'where' => 'vid=' . $value ['verify'],
  5173. 'asArray' => true
  5174. ) );
  5175. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5176. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5177. Doo::loadModel ( 'role' );
  5178. $role = new role ();
  5179. // print_r($verifyList);
  5180. $flag = true;
  5181. $roleKey = 0;
  5182. $endStaffArray = array ();
  5183. $roleArrayCopy = array ();
  5184. foreach ( $verifyList as $k => $v ) {
  5185. // init verifyStaff
  5186. if ($v [1] == 'ROLE') {
  5187. if (! empty ( $verifyStaff )) {
  5188. $endStaffArray = end ( $verifyStaff );
  5189. if ($v [0] == $endStaffArray ['nextStaff']) {
  5190. $roleId = $v [0];
  5191. }
  5192. }
  5193. $roleVerify = json_decode ( $v [3], true );
  5194. $roleKey = $k;
  5195. $roleArray = array ();
  5196. $rolename = $role->getOne ( array (
  5197. 'where' => 'rid=' . $v [0],
  5198. 'asArray' => true
  5199. ) );
  5200. foreach ( $roleVerify as $o => $p ) {
  5201. $staffID = explode ( '_', $p );
  5202. $staffInfo = $staff->getOne ( array (
  5203. 'where' => 'sid=' . $staffID [0],
  5204. 'asArray' => true
  5205. ) );
  5206. // print_r($staffID);
  5207. $exp = array (
  5208. 0 => $staffInfo ['sid'],
  5209. 1 => $staffID [1],
  5210. 2 => $staffInfo ['avatar'],
  5211. 'date' => '',
  5212. 'date' => '',
  5213. 'opinion' => '',
  5214. 'status' => '',
  5215. 'rolename' => $rolename ['name']
  5216. );
  5217. array_push ( $roleArray, $exp );
  5218. }
  5219. $roleArrayCopy [$v [0]] = $roleArray;
  5220. // $verifyList[$k]['roleArray']=$roleArray;
  5221. }
  5222. // print_r($roleArray);
  5223. $verifyList [$k] ['date'] = "";
  5224. $verifyList [$k] ['opinion'] = "";
  5225. $verifyList [$k] ['status'] = "";
  5226. if (empty ( $verifyStaff )) {
  5227. $verifyList [$k] ['date'] = "";
  5228. $verifyList [$k] ['opinion'] = "";
  5229. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5230. $verifyList [$k] ['status'] = 4;
  5231. $button = 4;
  5232. $flag = false;
  5233. }
  5234. } else {
  5235. foreach ( $verifyStaff as $m => $u ) {
  5236. if ($v [0] == $m) {
  5237. $verifyList [$k] ['date'] = $u ['date'];
  5238. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5239. $verifyList [$k] ['status'] = $u ['status'];
  5240. $flag = false;
  5241. break;
  5242. }
  5243. }
  5244. $endStaffArray = end ( $verifyStaff );
  5245. if (isset ( $endStaffArray ['ROLE'] )) {
  5246. } else {
  5247. $endKey = key ( $verifyStaff );
  5248. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5249. $button = 4;
  5250. $verifyList [$k] ['status'] = 4;
  5251. }
  5252. }
  5253. }
  5254. }
  5255. $rolename ['name'] = '';
  5256. if (! empty ( $roleId )) {
  5257. Doo::loadModel ( 'role' );
  5258. $role = new role ();
  5259. $rolename = $role->getOne ( array (
  5260. 'where' => 'rid=' . $roleId,
  5261. 'asArray' => true
  5262. ) );
  5263. }
  5264. if (! empty ( $verifyStaff ))
  5265. $endStaffArray = end ( $verifyStaff );
  5266. $KOP = false;
  5267. foreach ( $roleArrayCopy as $P => $A ) {
  5268. foreach ( $A as $MKI => $AVL ) {
  5269. if (! empty ( $verifyStaff )) {
  5270. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5271. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5272. $button = 4;
  5273. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5274. }
  5275. foreach ( $verifyStaff as $m => $u ) {
  5276. $AVLFK = $AVL [0] . '_R';
  5277. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5278. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5279. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5280. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5281. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5282. break;
  5283. }
  5284. }
  5285. } else {
  5286. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5287. $button = 4;
  5288. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5289. }
  5290. }
  5291. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5292. $KOP = true;
  5293. }
  5294. }
  5295. // print_r($roleArrayCopy);
  5296. // echo $roleKey;
  5297. foreach ( $roleArrayCopy as $k => $v ) {
  5298. foreach ( $verifyList as $m => $n ) {
  5299. if ($n [0] == $k) {
  5300. array_splice ( $verifyList, $m, 1, $v );
  5301. }
  5302. }
  5303. }
  5304. $receiptList [$key] ['verifyList'] = $verifyList;
  5305. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5306. 'where' => 'sid=' . $value ['staff'],
  5307. 'asArray' => true
  5308. ) );
  5309. $receiptList [$key] ['button'] = $button;
  5310. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  5311. }
  5312. // $data['verifyDetail']=$verifyDetail;
  5313. $mothHtml = "";
  5314. for($i = 1; $i <= 12; $i ++) {
  5315. if ($month == $i)
  5316. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5317. else
  5318. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5319. }
  5320. // 获取审批日志
  5321. Doo::loadModel ( 'receiptLog' );
  5322. $receiptLog = new receiptLog ();
  5323. $rlList = array ();
  5324. $rlInfo = $receiptLog->getOne ( array (
  5325. 'where' => 'rid=' . $rid . ' and status=4',
  5326. 'asArray' => true
  5327. ) );
  5328. $tijdate = $receiptLog->getOne ( array (
  5329. 'where' => 'rid=' . $rid . ' and status=2',
  5330. 'asc' => 'rlid',
  5331. 'asArray' => true
  5332. ) );
  5333. if (! empty ( $rlInfo )) {
  5334. $rlList = $receiptLog->find ( array (
  5335. 'where' => 'rid=' . $rid,
  5336. 'asc' => 'rlid',
  5337. 'asArray' => true
  5338. ) );
  5339. }
  5340. $receiptList [0] ['rlList'] = $rlList;
  5341. $enclosurList = $enclosur->find ( array (
  5342. 'where' => 'rid=' . $rid,
  5343. 'asArray' => true
  5344. ) );
  5345. $enclosurHtml = '';
  5346. foreach ( $enclosurList as $value ) {
  5347. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5348. }
  5349. // print_r($receiptList);
  5350. $data ['rid'] = $rid;
  5351. $data ['enclosurHtml'] = $enclosurHtml;
  5352. $data ['rolename'] = $rolename ['name'];
  5353. $data ['datetij'] = $tijdate ['date'];
  5354. $data ['mothHtml'] = $mothHtml;
  5355. $data ['receiptList'] = $receiptList;
  5356. $data ['receiptApprovalCount'] = count ( $receiptList );
  5357. $data ['status'] = $status;
  5358. $data ['year'] = $year;
  5359. $data ['categoryList'] = $categoryList;
  5360. $data ['staffList'] = $staffList;
  5361. $data ['cid'] = $cid;
  5362. $data ['sid'] = $sid;
  5363. $data ['ap'] = $ap;
  5364. $data ['memu'] = "receipt";
  5365. $data ['staff'] = $this->staff;
  5366. $data ['receiptMemu'] = 'approvalExpenses';
  5367. $data ['verifyId'] = $this->verifyId;
  5368. $data ['executeId'] = $this->executeId;
  5369. $this->render ( "/admin/expensesEdi", $data );
  5370. }
  5371. function expensesDefray() {
  5372. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5373. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  5374. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5375. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  5376. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  5377. if (! empty ( $rid )) {
  5378. Doo::loadModel ( "verify" );
  5379. $verify = new verify ();
  5380. Doo::loadModel ( "receiptDetail" );
  5381. $receiptDetailObj = new receiptDetail ();
  5382. Doo::loadModel ( "itemStatistics" );
  5383. Doo::loadModel ( "statistics" );
  5384. $statistics = new statistics ();
  5385. $itemStatistics = new itemStatistics ();
  5386. Doo::loadModel ( "receipt" );
  5387. $receipt = new receipt ();
  5388. Doo::loadModel ( "loanReceipt" );
  5389. $loanReceipt = new loanReceipt ();
  5390. $receiptDetail = $receipt->getOne ( array (
  5391. 'where' => 'rid=' . $rid . ' and status=2 ',
  5392. 'asArray' => true
  5393. ) );
  5394. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  5395. $nsflag = true;
  5396. foreach ( $nslist as $value ) {
  5397. if ($value == $this->staff ['0'] ['sid']) {
  5398. $nsflag = false;
  5399. break;
  5400. }
  5401. }
  5402. // print_r($nslist);die;
  5403. if (empty ( $receiptDetail ) || $nsflag)
  5404. return "/approvalExpenses/pendApproval";
  5405. $verifyDetail = $verify->getOne ( array (
  5406. 'where' => ' vid =' . $receiptDetail ['verify'],
  5407. 'asArray' => true
  5408. ) );
  5409. $verifyString = $verifyDetail ['staff'];
  5410. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  5411. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  5412. if (empty ( $opinion )) {
  5413. if ($status == 3)
  5414. $opinion = "终止";
  5415. else
  5416. $opinion = "同意支付";
  5417. }
  5418. $nowStaff = 0;
  5419. $nowStaffList = array ();
  5420. if (empty ( $verifyStaff )) {
  5421. // 还需加入是否已经进入角色审批
  5422. if ($verifyDetail [0] [1] == 'ROLE') {
  5423. // print_r($verifyDetail);echo "ddd";
  5424. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  5425. foreach ( $vStaffString as $key => $value ) {
  5426. $staffK = explode ( "_", $value );
  5427. if ($staffK [0] != $this->staff [0] ['sid'])
  5428. array_push ( $nowStaffList, $staffK [0] );
  5429. }
  5430. // print_r($verifyDetail);
  5431. // die;
  5432. if (! empty ( $nowStaffList )) {
  5433. $nowStaff = implode ( ',', $nowStaffList );
  5434. $verifyStaff = array (
  5435. $this->staff [0] ['sid'] . "_R" => array (
  5436. 'date' => date ( 'Y-m-d' ),
  5437. 'opinion' => $opinion,
  5438. 'status' => $status,
  5439. 'nextStaff' => $verifyDetail [0] [0],
  5440. 'ROLE' => 1
  5441. )
  5442. );
  5443. } else {
  5444. $nowStaff = $verifyDetail [1] [0];
  5445. $verifyStaff = array (
  5446. $this->staff [0] ['sid'] . "_R" => array (
  5447. 'date' => date ( 'Y-m-d' ),
  5448. 'opinion' => $opinion,
  5449. 'status' => $status,
  5450. 'nextStaff' => $verifyDetail [1] [0]
  5451. )
  5452. );
  5453. }
  5454. } else {
  5455. if ($verifyDetail [1] [1] == 'ROLE') {
  5456. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  5457. // echo "dd";
  5458. foreach ( $vStaffString as $key => $value ) {
  5459. $staffK = explode ( "_", $value );
  5460. array_push ( $nowStaffList, $staffK [0] );
  5461. }
  5462. $nowStaff = implode ( ',', $nowStaffList );
  5463. $verifyStaff = array (
  5464. $this->staff [0] ['sid'] => array (
  5465. 'date' => date ( 'Y-m-d' ),
  5466. 'opinion' => $opinion,
  5467. 'status' => $status,
  5468. 'nextStaff' => $verifyDetail [1] [0],
  5469. 'ROLE' => 1
  5470. )
  5471. );
  5472. } else {
  5473. $nowStaff = $verifyDetail [1] [0];
  5474. $verifyStaff = array (
  5475. $this->staff [0] ['sid'] => array (
  5476. 'date' => date ( 'Y-m-d' ),
  5477. 'opinion' => $opinion,
  5478. 'status' => $status,
  5479. 'nextStaff' => $verifyDetail [1] [0]
  5480. )
  5481. );
  5482. }
  5483. }
  5484. if ($status == 3)
  5485. $verifyStaff = array (
  5486. 'final' => $status,
  5487. $this->staff [0] ['sid'] => array (
  5488. 'date' => date ( 'Y-m-d' ),
  5489. 'opinion' => $opinion,
  5490. 'status' => $status
  5491. )
  5492. );
  5493. $vStaffString = json_encode ( $verifyStaff );
  5494. $receipt->nowStaff = $nowStaff;
  5495. $receipt->verifyStaff = $vStaffString;
  5496. $loanReceipt->nowStaff = $nowStaff;
  5497. $loanReceipt->verifyStaff = $vStaffString;
  5498. } else {
  5499. $VS = end ( $verifyStaff );
  5500. // 非角色审批
  5501. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  5502. $nextStaff = 0;
  5503. $roleSTF = false;
  5504. foreach ( $verifyDetail as $key => $value ) {
  5505. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  5506. if (isset ( $verifyDetail [$key + 1] )) {
  5507. $nextStaff = $verifyDetail [$key + 1] [0];
  5508. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  5509. $roleSTF = true;
  5510. }
  5511. break;
  5512. }
  5513. }
  5514. if (! $roleSTF) {
  5515. $nowStaff = $nextStaff;
  5516. $verifyStaff [$this->staff [0] ['sid']] = array (
  5517. 'date' => date ( 'Y-m-d' ),
  5518. 'opinion' => $opinion,
  5519. 'status' => $status,
  5520. 'nextStaff' => $nextStaff
  5521. );
  5522. } else {
  5523. // 获取角色下的所有用户ID
  5524. $nowStaffList = array ();
  5525. foreach ( $verifyDetail as $vfk ) {
  5526. if ($vfk [1] == 'ROLE') {
  5527. $vStaffString = json_decode ( $vfk [3] );
  5528. foreach ( $vStaffString as $key => $value ) {
  5529. $staffK = explode ( "_", $value );
  5530. array_push ( $nowStaffList, $staffK [0] );
  5531. }
  5532. }
  5533. }
  5534. $nowStaff = implode ( ',', $nowStaffList );
  5535. $verifyStaff [$this->staff [0] ['sid']] = array (
  5536. 'date' => date ( 'Y-m-d' ),
  5537. 'opinion' => $opinion,
  5538. 'status' => $status,
  5539. 'nextStaff' => $nextStaff,
  5540. 'ROLE' => 0
  5541. );
  5542. }
  5543. if ($status == 3) {
  5544. $verifyStaff ['final'] = $status;
  5545. $verifyStaff [$this->staff [0] ['sid']] = array (
  5546. 'date' => date ( 'Y-m-d' ),
  5547. 'opinion' => $opinion,
  5548. 'status' => $status
  5549. );
  5550. }
  5551. $vStaffString = json_encode ( $verifyStaff );
  5552. $receipt->nowStaff = $nowStaff;
  5553. $receipt->verifyStaff = $vStaffString;
  5554. $loanReceipt->nowStaff = $nowStaff;
  5555. $loanReceipt->verifyStaff = $vStaffString;
  5556. }
  5557. // 角色审批
  5558. if (isset ( $VS ['ROLE'] )) {
  5559. // 找出角色人 当前审批角色组
  5560. $verifyJSStaff = array ();
  5561. $nowStaffList2 = array ();
  5562. foreach ( $verifyDetail as $key => $value ) {
  5563. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  5564. $verifyJSStaff = json_decode ( $value [3] );
  5565. foreach ( $verifyJSStaff as $m ) {
  5566. $staffK = explode ( "_", $m );
  5567. array_push ( $nowStaffList2, $staffK [0] );
  5568. }
  5569. // print_r($nowStaffList2);
  5570. }
  5571. }
  5572. $RoleVerifyStaff = array ();
  5573. foreach ( $verifyStaff as $key => $value ) {
  5574. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  5575. foreach ( $nowStaffList2 as $m ) {
  5576. if ($key == $m . "_R")
  5577. $RoleVerifyStaff [$key] = $value;
  5578. }
  5579. }
  5580. }
  5581. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  5582. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  5583. // 下一个审批人ID
  5584. $nextStaff = 0;
  5585. $falg = false;
  5586. foreach ( $verifyDetail as $key => $value ) {
  5587. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  5588. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  5589. $falg = true;
  5590. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  5591. $nowStaffList = array ();
  5592. foreach ( $vStaffString as $v ) {
  5593. $staffK = explode ( "_", $v );
  5594. array_push ( $nowStaffList, $staffK [0] );
  5595. }
  5596. $nowStaff = implode ( ',', $nowStaffList );
  5597. $nextStaff = $verifyDetail [$key + 1] [0];
  5598. } elseif (isset ( $verifyDetail [$key + 1] )) {
  5599. $nextStaff = $verifyDetail [$key + 1] [0];
  5600. $nowStaff = $nextStaff;
  5601. } else
  5602. $nowStaff = '';
  5603. break;
  5604. }
  5605. }
  5606. if ($falg)
  5607. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5608. 'date' => date ( 'Y-m-d' ),
  5609. 'opinion' => $opinion,
  5610. 'status' => $status,
  5611. 'nextStaff' => $nextStaff,
  5612. 'ROLE' => 1
  5613. );
  5614. else
  5615. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5616. 'date' => date ( 'Y-m-d' ),
  5617. 'opinion' => $opinion,
  5618. 'status' => $status,
  5619. 'nextStaff' => $nextStaff
  5620. );
  5621. // print_r($verifyStaff);
  5622. // echo $nowStaff;die;
  5623. } else { // 进入下一个角色或者审批人
  5624. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  5625. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5626. 'date' => date ( 'Y-m-d' ),
  5627. 'opinion' => $opinion,
  5628. 'status' => $status,
  5629. 'nextStaff' => $VS ['nextStaff'],
  5630. 'ROLE' => 1
  5631. );
  5632. }
  5633. if ($status == 3) {
  5634. $verifyStaff ['final'] = $status;
  5635. $verifyStaff [$this->staff [0] ['sid']] = array (
  5636. 'date' => date ( 'Y-m-d' ),
  5637. 'opinion' => $opinion,
  5638. 'status' => $status
  5639. );
  5640. }
  5641. $vStaffString = json_encode ( $verifyStaff );
  5642. $receipt->verifyStaff = $vStaffString;
  5643. $receipt->nowStaff = $nowStaff;
  5644. $loanReceipt->nowStaff = $nowStaff;
  5645. $loanReceipt->verifyStaff = $vStaffString;
  5646. }
  5647. // print_r($verifyStaff);die;
  5648. }
  5649. $roleKey = 0;
  5650. $roleId = 0;
  5651. $verifyDetailCopy = array ();
  5652. foreach ( $verifyDetail as $k => $v ) {
  5653. if ($v [1] == 'ROLE') {
  5654. $roleId = $v [0];
  5655. $roleVerify = json_decode ( $v [3], true );
  5656. $roleKey = $k;
  5657. $roleArray = array ();
  5658. foreach ( $roleVerify as $o => $p ) {
  5659. $staffID = explode ( '_', $p );
  5660. $exp = array (
  5661. 0 => $staffID [0],
  5662. 1 => $staffID [1]
  5663. );
  5664. array_push ( $roleArray, $exp );
  5665. }
  5666. $verifyDetailCopy [$v [0]] = $roleArray;
  5667. }
  5668. }
  5669. // print_r($verifyDetail);
  5670. foreach ( $verifyDetailCopy as $k => $v ) {
  5671. foreach ( $verifyDetail as $m => $n ) {
  5672. if ($n [0] == $k) {
  5673. array_splice ( $verifyDetail, $m, 1, $v );
  5674. }
  5675. }
  5676. }
  5677. // 审批日志
  5678. if (! isset ( $verifyStaff ['final'] )) {
  5679. Doo::loadModel ( "receiptLog" );
  5680. $receiptLog = new receiptLog ();
  5681. if (! empty ( $roleId )) {
  5682. Doo::loadModel ( "role" );
  5683. $role = new role ();
  5684. $roleInfo = $role->getOne ( array (
  5685. 'where' => 'rid=' . $roleId,
  5686. 'asArray' => true
  5687. ) );
  5688. $receiptLog->rolename = $roleInfo ['name'];
  5689. }
  5690. $receiptLog->username = $this->staff [0] ['username'];
  5691. $receiptLog->uid = $this->staff [0] ['sid'];
  5692. $receiptLog->date = date ( "Y-m-d" );
  5693. $receiptLog->opinion = $opinion;
  5694. $receiptLog->img = $this->staff [0] ['avatar'];
  5695. $receiptLog->status = 1;
  5696. $receiptLog->rid = $rid;
  5697. $receiptLog->insert ();
  5698. }
  5699. if (isset ( $verifyStaff ['final'] )) { // rDetail
  5700. $receipt->status = 3;
  5701. $receipt->verifyBreakup = $verifyString;
  5702. $receiptDetailObj->status = 3;
  5703. $receiptDetailObj->update ( array (
  5704. 'where' => 'rid=' . $rid
  5705. ) );
  5706. // 微信企业号通知
  5707. $this->setWXMsg ( $rid, 3 );
  5708. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  5709. $receipt->status = 6;
  5710. $receipt->pastDate = date ( "Y-m-d" );
  5711. $receipt->isBK = 1;
  5712. $loanReceipt->verifyBreakup = $verifyString;
  5713. $loanReceipt->status = 1;
  5714. $loanReceipt->pastDate = date ( "Y-m-d" );
  5715. //生成流水后 不更新汇款金额
  5716. Doo::loadModel ( 'wasteBook' );
  5717. $wasteBook = new wasteBook ();
  5718. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  5719. if (empty($wbDetail)){
  5720. $loanReceipt->amount = $receiptDetail ['amount'];
  5721. }
  5722. $loanReceipt->update ( array (
  5723. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  5724. ) );
  5725. // 微信企业号通知
  5726. $this->setWXMsg ( $rid, 1 );
  5727. }
  5728. $receipt->amount = $receiptDetail['sum'];
  5729. $receipt->update ( array (
  5730. 'where' => ' rid = ' . $rid
  5731. ) );
  5732. // 进入下一条审批费用新加需求
  5733. $vidList = array ();
  5734. $verifyDetail = $verify->find ( array (
  5735. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  5736. 'asArray' => true
  5737. ) );
  5738. foreach ( $verifyDetail as $key => $value ) {
  5739. array_push ( $vidList, $value ['vid'] );
  5740. }
  5741. $vid = implode ( ",", $vidList );
  5742. if (empty ( $verifyDetail ))
  5743. $vid = 0;
  5744. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  5745. $receipt = new receipt ();
  5746. $rd = $receipt->getOne ( array (
  5747. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  5748. 'asc' => 'rid',
  5749. 'asArray' => true
  5750. ) );
  5751. if (empty ( $rd )) {
  5752. return '/approvalExpenses/pendApproval';
  5753. }
  5754. if ($rd ['Rtype'] == 1) {
  5755. if ($rd ['isBK'] == 1) {
  5756. return '/receiptburEdi/' . $rd ['rid'];
  5757. } else {
  5758. return '/expensesEdi/' . $rd ['rid'];
  5759. }
  5760. } elseif ($rd ['Rtype'] == 2) {
  5761. return '/remitApproval/' . $rd ['rid'];
  5762. } else {
  5763. return '/receiptburEdi/' . $rd ['rid'];
  5764. }
  5765. // return "/approvalExpenses/pendApproval";
  5766. }
  5767. }
  5768. function ajaxExamineExe() {
  5769. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5770. Doo::loadModel ( 'receipt' );
  5771. $receipt = new receipt ();
  5772. Doo::loadClass ( 'XDeode' );
  5773. $XDeode = new XDeode ( 5 );
  5774. if (! empty ( $rid )) {
  5775. $rLRes = $receipt->find ( array (
  5776. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  5777. 'asArray' => true
  5778. ) );
  5779. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  5780. echo json_encode ( array (
  5781. 'status' => 1,
  5782. 'receipt' => $rLRes [0]
  5783. ) );
  5784. die ();
  5785. }
  5786. echo json_encode ( array (
  5787. 'status' => 0,
  5788. 'receipt' => array ()
  5789. ) );
  5790. die ();
  5791. }
  5792. function implement() {
  5793. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5794. $Rtype = isset ( $this->params ['Rtype'] ) ? $this->params ['Rtype'] : '';
  5795. Doo::loadClass ( 'XDeode' );
  5796. $XDeode = new XDeode ( 5 );
  5797. Doo::loadModel ( 'receipt' );
  5798. $receipt = new receipt ();
  5799. Doo::loadModel ( 'L_category' );
  5800. $Lcategory = new L_category ();
  5801. Doo::loadModel ( 'verify' );
  5802. $verify = new verify ();
  5803. Doo::loadModel ( 'staff' );
  5804. $staff = new staff ();
  5805. Doo::loadModel ( "execute" );
  5806. $execute = new execute ();
  5807. $rid = $XDeode->decode ( $rid );
  5808. $receiptList = $receipt->find ( array (
  5809. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  5810. 'desc' => 'rid',
  5811. 'asArray' => true
  5812. ) );
  5813. Doo::loadModel ( 'loanReceipt' );
  5814. $loanReceipt = new loanReceipt ();
  5815. // print_r($receiptList);
  5816. $loanList = array ();
  5817. if (! isset ( $receiptList ))
  5818. $loanList = $loanReceipt->find ( array (
  5819. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5820. 'desc' => 'rid',
  5821. 'asArray' => true
  5822. ) );
  5823. $Locate = 0;
  5824. $roleId = 0;
  5825. $button = 0;
  5826. foreach ( $loanList as $key => $value ) {
  5827. $loanList [$key] ['Locate'] = $Locate;
  5828. $Locate ++;
  5829. $loanList [$key] ['reviseDetail'] = array ();
  5830. if (! empty ( $value ['reviseDetail'] ))
  5831. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5832. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5833. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5834. $categoryDetil = $Lcategory->getOne ( array (
  5835. 'where' => 'cid=' . $value ['cid'],
  5836. 'asArray' => true
  5837. ) );
  5838. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5839. // 检测编辑状态
  5840. $verifyList = $verify->getOne ( array (
  5841. 'where' => 'vid=' . $value ['verify'],
  5842. 'asArray' => true
  5843. ) );
  5844. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5845. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5846. Doo::loadModel ( 'role' );
  5847. $role = new role ();
  5848. $flag = true;
  5849. $roleKey = 0;
  5850. $endStaffArray = array ();
  5851. $roleArrayCopy = array ();
  5852. foreach ( $verifyList as $k => $v ) {
  5853. // init verifyStaff
  5854. if ($v [1] == 'ROLE') {
  5855. if (! empty ( $verifyStaff )) {
  5856. $endStaffArray = end ( $verifyStaff );
  5857. // if ($v[0]==$endStaffArray['nextStaff']){
  5858. // $roleId=$v[0];
  5859. // }
  5860. }
  5861. $roleVerify = json_decode ( $v [3], true );
  5862. $roleKey = $k;
  5863. $roleArray = array ();
  5864. $rolename = $role->getOne ( array (
  5865. 'where' => 'rid=' . $v [0],
  5866. 'asArray' => true
  5867. ) );
  5868. foreach ( $roleVerify as $o => $p ) {
  5869. $staffID = explode ( '_', $p );
  5870. $staffInfo = $staff->getOne ( array (
  5871. 'where' => 'sid=' . $staffID [0],
  5872. 'asArray' => true
  5873. ) );
  5874. // print_r($staffID);
  5875. $exp = array (
  5876. 0 => $staffInfo ['sid'],
  5877. 1 => $staffID [1],
  5878. 2 => $staffInfo ['avatar'],
  5879. 'date' => '',
  5880. 'date' => '',
  5881. 'opinion' => '',
  5882. 'status' => '',
  5883. 'rolename' => $rolename ['name']
  5884. );
  5885. array_push ( $roleArray, $exp );
  5886. }
  5887. $roleArrayCopy [$v [0]] = $roleArray;
  5888. // $verifyList[$k]['roleArray']=$roleArray;
  5889. }
  5890. $verifyList [$k] ['date'] = "";
  5891. $verifyList [$k] ['opinion'] = "";
  5892. $verifyList [$k] ['status'] = "";
  5893. if (empty ( $verifyStaff )) {
  5894. $verifyList [$k] ['date'] = "";
  5895. $verifyList [$k] ['opinion'] = "";
  5896. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5897. $verifyList [$k] ['status'] = 4;
  5898. $flag = false;
  5899. }
  5900. } else {
  5901. foreach ( $verifyStaff as $m => $u ) {
  5902. if ($v [0] == $m) {
  5903. $verifyList [$k] ['date'] = $u ['date'];
  5904. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5905. $verifyList [$k] ['status'] = $u ['status'];
  5906. $flag = false;
  5907. break;
  5908. }
  5909. }
  5910. $endStaffArray = end ( $verifyStaff );
  5911. if (isset ( $endStaffArray ['ROLE'] )) {
  5912. } else {
  5913. // $endKey=key($verifyStaff);
  5914. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5915. // $button=4;
  5916. // $verifyList[$k]['status']=4;
  5917. // }
  5918. }
  5919. }
  5920. }
  5921. $rolename ['name'] = '';
  5922. if (! empty ( $roleId )) {
  5923. Doo::loadModel ( 'role' );
  5924. $role = new role ();
  5925. $rolename = $role->getOne ( array (
  5926. 'where' => 'rid=' . $roleId,
  5927. 'asArray' => true
  5928. ) );
  5929. }
  5930. if (! empty ( $verifyStaff ))
  5931. $endStaffArray = end ( $verifyStaff );
  5932. $KOP = false;
  5933. foreach ( $roleArrayCopy as $P => $A ) {
  5934. foreach ( $A as $MKI => $AVL ) {
  5935. if (! empty ( $verifyStaff )) {
  5936. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5937. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5938. $button = 4;
  5939. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5940. }
  5941. foreach ( $verifyStaff as $m => $u ) {
  5942. $AVLFK = $AVL [0] . '_R';
  5943. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5944. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5945. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5946. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5947. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5948. break;
  5949. }
  5950. }
  5951. } else {
  5952. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5953. $button = 4;
  5954. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5955. }
  5956. }
  5957. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5958. $KOP = true;
  5959. }
  5960. }
  5961. foreach ( $roleArrayCopy as $k => $v ) {
  5962. foreach ( $verifyList as $m => $n ) {
  5963. if ($n [0] == $k) {
  5964. array_splice ( $verifyList, $m, 1, $v );
  5965. }
  5966. }
  5967. }
  5968. $loanList [$key] ['verifyList'] = $verifyList;
  5969. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  5970. 'where' => 'sid=' . $value ['staff'],
  5971. 'asArray' => true
  5972. ) );
  5973. }
  5974. $data ['loanList'] = $loanList;
  5975. $Locate = 0;
  5976. $roleId = 0;
  5977. $button = 0;
  5978. Doo::loadClass ( 'XDeode' );
  5979. $XDeode = new XDeode ( 5 );
  5980. foreach ( $receiptList as $key => $value ) {
  5981. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  5982. $button2 = 0;
  5983. $receiptList [$key] ['Locate'] = $Locate;
  5984. $Locate ++;
  5985. $receiptList [$key] ['reviseDetail'] = array ();
  5986. if (! empty ( $value ['reviseDetail'] ))
  5987. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5988. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5989. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5990. $categoryDetil = $Lcategory->getOne ( array (
  5991. 'where' => 'cid=' . $value ['cid'],
  5992. 'asArray' => true
  5993. ) );
  5994. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5995. $executeList = json_decode ( $value ['executeCopy'], true );
  5996. $executeStaff = array ();
  5997. if (! empty ( $value ['executeStaff'] ))
  5998. $executeStaff = json_decode ( $value ['executeStaff'], true );
  5999. if (isset ( $executeList )) {
  6000. foreach ( $executeList as $op => $lo ) {
  6001. $executeList [$op] ['date'] = "";
  6002. $executeList [$op] ['opinion'] = "";
  6003. $executeList [$op] ['status'] = "";
  6004. foreach ( $executeStaff as $m => $u ) {
  6005. if ($lo [0] == $m) {
  6006. $executeList [$op] ['date'] = $u ['date'];
  6007. $executeList [$op] ['opinion'] = $u ['opinion'];
  6008. $executeList [$op] ['status'] = $u ['status'];
  6009. break;
  6010. }
  6011. }
  6012. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  6013. $button2 = 1;
  6014. $executeList [$op] ['status'] = 4;
  6015. }
  6016. }
  6017. }
  6018. // 检测编辑状态
  6019. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  6020. $verifyList ['staff'] = $value ['verifyBreakup'];
  6021. } else
  6022. $verifyList = $verify->getOne ( array (
  6023. 'where' => 'vid=' . $value ['verify'],
  6024. 'asArray' => true
  6025. ) );
  6026. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6027. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6028. Doo::loadModel ( 'role' );
  6029. $role = new role ();
  6030. if ($verifyList == NULL)
  6031. $verifyList = array ();
  6032. $flag = true;
  6033. $roleKey = 0;
  6034. $endStaffArray = array ();
  6035. $roleArrayCopy = array ();
  6036. foreach ( $verifyList as $k => $v ) {
  6037. // init verifyStaff
  6038. if ($v [1] == 'ROLE') {
  6039. if (! empty ( $verifyStaff )) {
  6040. $endStaffArray = end ( $verifyStaff );
  6041. // if ($v[0]==$endStaffArray['nextStaff']){
  6042. // $roleId=$v[0];
  6043. // }
  6044. }
  6045. $roleVerify = json_decode ( $v [3], true );
  6046. $roleKey = $k;
  6047. $roleArray = array ();
  6048. $rolename = $role->getOne ( array (
  6049. 'where' => 'rid=' . $v [0],
  6050. 'asArray' => true
  6051. ) );
  6052. foreach ( $roleVerify as $o => $p ) {
  6053. $staffID = explode ( '_', $p );
  6054. $staffInfo = $staff->getOne ( array (
  6055. 'where' => 'sid=' . $staffID [0],
  6056. 'asArray' => true
  6057. ) );
  6058. // print_r($staffID);
  6059. $exp = array (
  6060. 0 => $staffInfo ['sid'],
  6061. 1 => $staffID [1],
  6062. 2 => $staffInfo ['avatar'],
  6063. 'date' => '',
  6064. 'date' => '',
  6065. 'opinion' => '',
  6066. 'status' => '',
  6067. 'rolename' => $rolename ['name']
  6068. );
  6069. array_push ( $roleArray, $exp );
  6070. }
  6071. $roleArrayCopy [$v [0]] = $roleArray;
  6072. // $verifyList[$k]['roleArray']=$roleArray;
  6073. }
  6074. $verifyList [$k] ['date'] = "";
  6075. $verifyList [$k] ['opinion'] = "";
  6076. $verifyList [$k] ['status'] = "";
  6077. if (empty ( $verifyStaff )) {
  6078. $verifyList [$k] ['date'] = "";
  6079. $verifyList [$k] ['opinion'] = "";
  6080. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6081. $verifyList [$k] ['status'] = 4;
  6082. $flag = false;
  6083. }
  6084. } else {
  6085. foreach ( $verifyStaff as $m => $u ) {
  6086. if ($v [0] == $m) {
  6087. $verifyList [$k] ['date'] = $u ['date'];
  6088. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6089. $verifyList [$k] ['status'] = $u ['status'];
  6090. $flag = false;
  6091. break;
  6092. }
  6093. }
  6094. $endStaffArray = end ( $verifyStaff );
  6095. if (isset ( $endStaffArray ['ROLE'] )) {
  6096. } else {
  6097. // $endKey=key($verifyStaff);
  6098. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6099. // $button=4;
  6100. // $verifyList[$k]['status']=4;
  6101. // }
  6102. }
  6103. }
  6104. }
  6105. $rolename ['name'] = '';
  6106. if (! empty ( $roleId )) {
  6107. Doo::loadModel ( 'role' );
  6108. $role = new role ();
  6109. $rolename = $role->getOne ( array (
  6110. 'where' => 'rid=' . $roleId,
  6111. 'asArray' => true
  6112. ) );
  6113. }
  6114. if (! empty ( $verifyStaff ))
  6115. $endStaffArray = end ( $verifyStaff );
  6116. $KOP = false;
  6117. foreach ( $roleArrayCopy as $P => $A ) {
  6118. foreach ( $A as $MKI => $AVL ) {
  6119. if (! empty ( $verifyStaff )) {
  6120. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6121. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6122. $button = 4;
  6123. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6124. }
  6125. foreach ( $verifyStaff as $m => $u ) {
  6126. $AVLFK = $AVL [0] . '_R';
  6127. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6128. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6129. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6130. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6131. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6132. break;
  6133. }
  6134. }
  6135. } else {
  6136. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6137. $button = 4;
  6138. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6139. }
  6140. }
  6141. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6142. $KOP = true;
  6143. }
  6144. }
  6145. foreach ( $roleArrayCopy as $k => $v ) {
  6146. foreach ( $verifyList as $m => $n ) {
  6147. if ($n [0] == $k) {
  6148. array_splice ( $verifyList, $m, 1, $v );
  6149. }
  6150. }
  6151. }
  6152. $receiptList [$key] ['verifyList'] = $verifyList;
  6153. $receiptList [$key] ['executeList'] = $executeList;
  6154. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6155. 'where' => 'sid=' . $value ['staff'],
  6156. 'asArray' => true
  6157. ) );
  6158. $receiptList [$key] ['button2'] = $button2;
  6159. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  6160. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  6161. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  6162. $receiptList [$key] ['relust'] = $relust;
  6163. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  6164. $receiptList [$key] ['amountABS'] = abs ( $value ['amount'] );
  6165. }
  6166. //执行人是否是最后一位
  6167. $executeCopy = json_decode ( $receiptList [0] ['executeCopy'], true );
  6168. $executeStaff = json_decode ( $receiptList [0] ['executeStaff'], true );
  6169. $executePrimary=count($executeCopy)-1;
  6170. $lastOne=true;
  6171. if($executePrimary!=count($executeStaff)){
  6172. $lastOne=false;
  6173. }
  6174. $data['lastOne']=$lastOne;
  6175. // 是否写入过流水
  6176. $accountType = 0;
  6177. if ($receiptList [0] ['Rtype'] == 0) {
  6178. $accountType = 3;
  6179. } elseif ($receiptList [0] ['Rtype'] == 1) {
  6180. if (!empty($receiptList [0]['accountItem']) )
  6181. $accountType = 2;
  6182. else
  6183. $accountType = 1;
  6184. } elseif ($receiptList [0] ['Rtype'] == 2) {
  6185. $accountType = 4;
  6186. } elseif ($receiptList [0] ['Rtype'] == 3) {
  6187. $accountType = 12;
  6188. }
  6189. Doo::loadModel ( 'wasteBook' );
  6190. $wasteBook = new wasteBook ();
  6191. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  6192. $data ['wbDetail'] = $wbDetail;
  6193. $wbDetailLoan=array();
  6194. if ($accountType==2){
  6195. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  6196. }
  6197. $data ['wbDetailLoan'] = $wbDetailLoan;
  6198. $data['inputDate']=date ( "Y-m-d H:i:s" );
  6199. //print_r($wbDetail);
  6200. $data ['receiptList'] = $receiptList;
  6201. $data ['memu'] = "receipt";
  6202. $data ['staff'] = $this->staff;
  6203. $data ['receiptMemu'] = 'implement';
  6204. $data ['verifyId'] = $this->verifyId;
  6205. $data ['executeId'] = $this->executeId;
  6206. if ($Rtype=="loan"){
  6207. $this->render ( "/receipt/receiptImplementLoan", $data );
  6208. }elseif($Rtype=="receipt"){
  6209. if($receiptList[0]['receiptClass']==2){
  6210. //TODO 费用执行行程单2.0
  6211. if(!empty($receiptList[0]['itinerary2'])){
  6212. $this->render ( "/receipt/receiptImplementTrave2", $data );
  6213. }else{
  6214. $this->render ( "/receipt/receiptImplementTrave", $data );
  6215. }
  6216. }else{
  6217. $this->render ( "/receipt/receiptImplement", $data );
  6218. }
  6219. }elseif($Rtype=="public"){
  6220. $this->render ( "/receipt/receiptImplementPublic", $data );
  6221. }else{
  6222. //$this->render ( "/admin/implement", $data );
  6223. }
  6224. }
  6225. function implementDo() {
  6226. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  6227. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  6228. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  6229. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  6230. // $ab = '';
  6231. // if ($accountBank == 'CGBDeposit')
  6232. // $ab = '纵横广发';
  6233. // elseif ($accountBank == 'ICBCDeposit')
  6234. // $ab = '纵横工行';
  6235. // elseif ($accountBank == 'HUADeposit')
  6236. // $ab = '华润银行';
  6237. // elseif ($accountBank == 'PersonalDeposit')
  6238. // $ab = '个人广发';
  6239. // if (empty ( $ab ))
  6240. // die ( 'illegal request--22' );
  6241. if (! empty ( $rid )) {
  6242. Doo::loadModel ( 'receipt' );
  6243. $receipt = new receipt ();
  6244. Doo::loadClass ( 'XDeode' );
  6245. $XDeode = new XDeode ( 5 );
  6246. $rid=$XDeode->decode($rid);
  6247. if (!is_numeric($rid)){
  6248. die;
  6249. }
  6250. // $rinfo = $receipt->getOne ( array (
  6251. // 'where' => 'rid=' . $rid,
  6252. // 'asArray' => true
  6253. // ) );
  6254. $rinfo = $receipt->getReceiptByRid ( $rid );
  6255. // $accountType = '';
  6256. // if ($rinfo ['Rtype'] == 1) {
  6257. // if ($rinfo ['loanRid'] != 0)//判断有问题
  6258. // $accountType = 2;
  6259. // else
  6260. // $accountType = 1;
  6261. // } elseif ($rinfo ['Rtype'] == 2) {
  6262. // $accountType = 4;
  6263. // } elseif ($rinfo ['Rtype'] == 0)
  6264. // $accountType = 3;
  6265. // if (empty ( $accountType ))
  6266. // die ( 'illegal request' );
  6267. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  6268. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  6269. if (empty ( $executeStaff )) {
  6270. $executeStaff = array (
  6271. $this->staff [0] ['sid'] => array (
  6272. 'date' => date ( 'Y-m-d' ),
  6273. 'opinion' => $implementOpinions,
  6274. 'status' => 1
  6275. )
  6276. );
  6277. } else {
  6278. $executeStaff [$this->staff [0] ['sid']] = array (
  6279. 'date' => date ( 'Y-m-d' ),
  6280. 'opinion' => $implementOpinions,
  6281. 'status' => 1
  6282. );
  6283. }
  6284. if (count ( $executeStaff ) == count ( $executeCopy )) {
  6285. $receipt->executeStaff = json_encode ( $executeStaff );
  6286. $receipt->status = 8;
  6287. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  6288. $receipt->status = 9;
  6289. if ($rinfo ['status'] == 6) {
  6290. $receipt->loanDate = date ( "Y-m-d" );
  6291. }
  6292. $receipt->executeDate = date ( "Y-m-d" );
  6293. } else {
  6294. $receipt->executeStaff = json_encode ( $executeStaff );
  6295. }
  6296. //$receipt->amount = $amount;
  6297. $receipt->update ( array (
  6298. 'where' => 'rid=' . $rid
  6299. ) );
  6300. // 公司流水记录
  6301. // Doo::loadModel ( 'wasteBook' );
  6302. // $wasteBook = new wasteBook ();
  6303. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  6304. // // 银行
  6305. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  6306. // $item = array (
  6307. // 'dataID' => $rid,
  6308. // 'expensesType' => 2,
  6309. // 'accountType' => $accountType,
  6310. // 'accountPriceShow' => $amount,
  6311. // 'accountPrice' => - $amount,
  6312. // 'accountBank' => $accountBank,
  6313. // 'category' => $rinfo ['category'] [0] ['title'],
  6314. // 'cid' => $rinfo ['category'] [0] ['cid'],
  6315. // 'name' => $rinfo ['staffDetail'] ['username'],
  6316. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  6317. // 'inputDate' => date ( "Y-m-d H:i:s" )
  6318. // );
  6319. // $wasteBook->setAccountBookStatistics ( $item );
  6320. // }
  6321. }
  6322. //$ridKey = $XDeode->encode ( $rid );
  6323. return "/hisImplement";
  6324. // return "/implement/" . $ridKey . ".html";
  6325. }
  6326. function receiptburEdi() {
  6327. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6328. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  6329. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  6330. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  6331. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  6332. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  6333. if (empty ( $status ))
  6334. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  6335. $vidList = array ();
  6336. $button = 0;
  6337. Doo::loadModel ( 'verify' );
  6338. Doo::loadModel ( 'receipt' );
  6339. Doo::loadModel ( 'staff' );
  6340. $staff = new staff ();
  6341. $receipt = new receipt ();
  6342. $verify = new verify ();
  6343. Doo::loadModel ( 'L_category' );
  6344. $Lcategory = new L_category ();
  6345. Doo::loadModel ( 'enclosur' );
  6346. $enclosur = new enclosur ();
  6347. Doo::loadModel ( 'loanReceipt' );
  6348. $loanReceipt = new loanReceipt ();
  6349. // user verify ID
  6350. $verifyDetail = $verify->find ( array (
  6351. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  6352. 'asArray' => true
  6353. ) );
  6354. foreach ( $verifyDetail as $key => $value ) {
  6355. array_push ( $vidList, $value ['vid'] );
  6356. }
  6357. $vid = implode ( ",", $vidList );
  6358. if (empty ( $verifyDetail ))
  6359. $vid = 0;
  6360. $categoryList = $Lcategory->find ( array (
  6361. 'asArray' => true
  6362. ) );
  6363. $staffList = $staff->find ( array (
  6364. 'where' => 'cid=' . $cid,
  6365. 'asArray' => true
  6366. ) );
  6367. $ap = "";
  6368. if ($status == 4) {
  6369. $ap = 4;
  6370. $status = 2;
  6371. }
  6372. // get Receipt By verifyID status 2
  6373. $receiptList = $receipt->find ( array (
  6374. 'where' => 'rid =' . $rid . ' and status=2',
  6375. 'desc' => 'rid',
  6376. 'asArray' => true
  6377. ) );
  6378. if (empty ( $receiptList )) {
  6379. die ( 'illegal request' );
  6380. }
  6381. $loanList = $loanReceipt->find ( array (
  6382. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  6383. 'desc' => 'rid',
  6384. 'asArray' => true
  6385. ) );
  6386. $data ['explanation'] = '';
  6387. if (! empty ( $loanList ))
  6388. $data ['explanation'] = $loanList [0] ['explanation'];
  6389. $Locate = 0;
  6390. $roleId = 0;
  6391. $button = 0;
  6392. foreach ( $loanList as $key => $value ) {
  6393. $loanList [$key] ['Locate'] = $Locate;
  6394. $Locate ++;
  6395. $loanList [$key] ['reviseDetail'] = array ();
  6396. if (! empty ( $value ['reviseDetail'] ))
  6397. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6398. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6399. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6400. $categoryDetil = $Lcategory->getOne ( array (
  6401. 'where' => 'cid=' . $value ['cid'],
  6402. 'asArray' => true
  6403. ) );
  6404. $loanList [$key] ['category'] = $categoryDetil ['title'];
  6405. // 检测编辑状态
  6406. $verifyList = $verify->getOne ( array (
  6407. 'where' => 'vid=' . $value ['verify'],
  6408. 'asArray' => true
  6409. ) );
  6410. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6411. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6412. Doo::loadModel ( 'role' );
  6413. $role = new role ();
  6414. $flag = true;
  6415. $roleKey = 0;
  6416. $endStaffArray = array ();
  6417. $roleArrayCopy = array ();
  6418. foreach ( $verifyList as $k => $v ) {
  6419. // init verifyStaff
  6420. if ($v [1] == 'ROLE') {
  6421. if (! empty ( $verifyStaff )) {
  6422. $endStaffArray = end ( $verifyStaff );
  6423. }
  6424. $roleVerify = json_decode ( $v [3], true );
  6425. $roleKey = $k;
  6426. $roleArray = array ();
  6427. $rolename = $role->getOne ( array (
  6428. 'where' => 'rid=' . $v [0],
  6429. 'asArray' => true
  6430. ) );
  6431. foreach ( $roleVerify as $o => $p ) {
  6432. $staffID = explode ( '_', $p );
  6433. $staffInfo = $staff->getOne ( array (
  6434. 'where' => 'sid=' . $staffID [0],
  6435. 'asArray' => true
  6436. ) );
  6437. // print_r($staffID);
  6438. $exp = array (
  6439. 0 => $staffInfo ['sid'],
  6440. 1 => $staffID [1],
  6441. 2 => $staffInfo ['avatar'],
  6442. 'date' => '',
  6443. 'date' => '',
  6444. 'opinion' => '',
  6445. 'status' => '',
  6446. 'rolename' => $rolename ['name']
  6447. );
  6448. array_push ( $roleArray, $exp );
  6449. }
  6450. $roleArrayCopy [$v [0]] = $roleArray;
  6451. // $verifyList[$k]['roleArray']=$roleArray;
  6452. }
  6453. $verifyList [$k] ['date'] = "";
  6454. $verifyList [$k] ['opinion'] = "";
  6455. $verifyList [$k] ['status'] = "";
  6456. if (empty ( $verifyStaff )) {
  6457. $verifyList [$k] ['date'] = "";
  6458. $verifyList [$k] ['opinion'] = "";
  6459. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6460. $verifyList [$k] ['status'] = 4;
  6461. $flag = false;
  6462. }
  6463. } else {
  6464. foreach ( $verifyStaff as $m => $u ) {
  6465. if ($v [0] == $m) {
  6466. $verifyList [$k] ['date'] = $u ['date'];
  6467. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6468. $verifyList [$k] ['status'] = $u ['status'];
  6469. $flag = false;
  6470. break;
  6471. }
  6472. }
  6473. $endStaffArray = end ( $verifyStaff );
  6474. if (isset ( $endStaffArray ['ROLE'] )) {
  6475. } else {
  6476. }
  6477. }
  6478. }
  6479. $rolename ['name'] = '';
  6480. if (! empty ( $roleId )) {
  6481. Doo::loadModel ( 'role' );
  6482. $role = new role ();
  6483. $rolename = $role->getOne ( array (
  6484. 'where' => 'rid=' . $roleId,
  6485. 'asArray' => true
  6486. ) );
  6487. }
  6488. if (! empty ( $verifyStaff ))
  6489. $endStaffArray = end ( $verifyStaff );
  6490. $KOP = false;
  6491. foreach ( $roleArrayCopy as $P => $A ) {
  6492. foreach ( $A as $MKI => $AVL ) {
  6493. if (! empty ( $verifyStaff )) {
  6494. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6495. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6496. $button = 4;
  6497. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6498. }
  6499. foreach ( $verifyStaff as $m => $u ) {
  6500. $AVLFK = $AVL [0] . '_R';
  6501. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6502. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6503. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6504. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6505. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6506. break;
  6507. }
  6508. }
  6509. } else {
  6510. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6511. $button = 4;
  6512. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6513. }
  6514. }
  6515. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6516. $KOP = true;
  6517. }
  6518. }
  6519. foreach ( $roleArrayCopy as $k => $v ) {
  6520. foreach ( $verifyList as $m => $n ) {
  6521. if ($n [0] == $k) {
  6522. array_splice ( $verifyList, $m, 1, $v );
  6523. }
  6524. }
  6525. }
  6526. $loanList [$key] ['verifyList'] = $verifyList;
  6527. }
  6528. $htmlLoan = '';
  6529. $data ['loanReceiptDate'] = '';
  6530. if (isset ( $loanList [0] )) {
  6531. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  6532. if ($value ['status'] == 1)
  6533. $htmlLoan .= '<li class="done" >';
  6534. elseif ($value ['status'] == 3)
  6535. $htmlLoan .= '<li class="undone" >';
  6536. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  6537. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  6538. if (isset ( $value ['rolename'] ))
  6539. $htmlLoan .= $value ['rolename'];
  6540. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  6541. }
  6542. $data ['loanDate'] = $loanList [0] ['date'];
  6543. } else {
  6544. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  6545. }
  6546. $data ['htmlLoan'] = $htmlLoan;
  6547. // $data ['LoanReceipt']=$loanList[0];
  6548. // print_r($loanList);
  6549. $Locate = 0;
  6550. $roleId = 0;
  6551. $button = 0;
  6552. if ($ap == 4)
  6553. $status = 4;
  6554. Doo::loadClass ( 'XDeode' );
  6555. $XDeode = new XDeode ( 5 );
  6556. foreach ( $receiptList as $key => $value ) {
  6557. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6558. $receiptList [$key] ['Locate'] = $Locate;
  6559. $Locate ++;
  6560. $receiptList [$key] ['reviseDetail'] = array ();
  6561. // 调整金额 代码调整
  6562. if (! empty ( $value ['reviseDetail'] )) {
  6563. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  6564. foreach ( $reviseDetail as $ry => $re ) {
  6565. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  6566. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  6567. }
  6568. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  6569. // print_r($reviseDetail);
  6570. }
  6571. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6572. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6573. $categoryDetil = $Lcategory->getOne ( array (
  6574. 'where' => 'cid=' . $value ['cid'],
  6575. 'asArray' => true
  6576. ) );
  6577. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6578. // 检测编辑状态
  6579. $verifyList = $verify->getOne ( array (
  6580. 'where' => 'vid=' . $value ['verify'],
  6581. 'asArray' => true
  6582. ) );
  6583. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6584. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6585. Doo::loadModel ( 'role' );
  6586. $role = new role ();
  6587. // print_r($verifyList);
  6588. $flag = true;
  6589. $roleKey = 0;
  6590. $endStaffArray = array ();
  6591. $roleArrayCopy = array ();
  6592. foreach ( $verifyList as $k => $v ) {
  6593. // init verifyStaff
  6594. if ($v [1] == 'ROLE') {
  6595. if (! empty ( $verifyStaff )) {
  6596. $endStaffArray = end ( $verifyStaff );
  6597. if ($v [0] == $endStaffArray ['nextStaff']) {
  6598. $roleId = $v [0];
  6599. }
  6600. }
  6601. $roleVerify = json_decode ( $v [3], true );
  6602. $roleKey = $k;
  6603. $roleArray = array ();
  6604. $rolename = $role->getOne ( array (
  6605. 'where' => 'rid=' . $v [0],
  6606. 'asArray' => true
  6607. ) );
  6608. foreach ( $roleVerify as $o => $p ) {
  6609. $staffID = explode ( '_', $p );
  6610. $staffInfo = $staff->getOne ( array (
  6611. 'where' => 'sid=' . $staffID [0],
  6612. 'asArray' => true
  6613. ) );
  6614. // print_r($staffID);
  6615. $exp = array (
  6616. 0 => $staffInfo ['sid'],
  6617. 1 => $staffID [1],
  6618. 2 => $staffInfo ['avatar'],
  6619. 'date' => '',
  6620. 'date' => '',
  6621. 'opinion' => '',
  6622. 'status' => '',
  6623. 'rolename' => $rolename ['name']
  6624. );
  6625. array_push ( $roleArray, $exp );
  6626. }
  6627. $roleArrayCopy [$v [0]] = $roleArray;
  6628. // $verifyList[$k]['roleArray']=$roleArray;
  6629. }
  6630. // print_r($roleArray);
  6631. $verifyList [$k] ['date'] = "";
  6632. $verifyList [$k] ['opinion'] = "";
  6633. $verifyList [$k] ['status'] = "";
  6634. if (empty ( $verifyStaff )) {
  6635. $verifyList [$k] ['date'] = "";
  6636. $verifyList [$k] ['opinion'] = "";
  6637. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6638. $verifyList [$k] ['status'] = 4;
  6639. $button = 4;
  6640. $flag = false;
  6641. }
  6642. } else {
  6643. foreach ( $verifyStaff as $m => $u ) {
  6644. if ($v [0] == $m) {
  6645. $verifyList [$k] ['date'] = $u ['date'];
  6646. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6647. $verifyList [$k] ['status'] = $u ['status'];
  6648. $flag = false;
  6649. break;
  6650. }
  6651. }
  6652. $endStaffArray = end ( $verifyStaff );
  6653. if (isset ( $endStaffArray ['ROLE'] )) {
  6654. } else {
  6655. $endKey = key ( $verifyStaff );
  6656. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  6657. $button = 4;
  6658. $verifyList [$k] ['status'] = 4;
  6659. }
  6660. }
  6661. }
  6662. }
  6663. $rolename ['name'] = '';
  6664. if (! empty ( $roleId )) {
  6665. Doo::loadModel ( 'role' );
  6666. $role = new role ();
  6667. $rolename = $role->getOne ( array (
  6668. 'where' => 'rid=' . $roleId,
  6669. 'asArray' => true
  6670. ) );
  6671. }
  6672. if (! empty ( $verifyStaff ))
  6673. $endStaffArray = end ( $verifyStaff );
  6674. $KOP = false;
  6675. foreach ( $roleArrayCopy as $P => $A ) {
  6676. foreach ( $A as $MKI => $AVL ) {
  6677. if (! empty ( $verifyStaff )) {
  6678. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6679. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6680. $button = 4;
  6681. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6682. }
  6683. foreach ( $verifyStaff as $m => $u ) {
  6684. $AVLFK = $AVL [0] . '_R';
  6685. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6686. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6687. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6688. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6689. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6690. break;
  6691. }
  6692. }
  6693. } else {
  6694. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6695. $button = 4;
  6696. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6697. }
  6698. }
  6699. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6700. $KOP = true;
  6701. }
  6702. }
  6703. foreach ( $roleArrayCopy as $k => $v ) {
  6704. foreach ( $verifyList as $m => $n ) {
  6705. if ($n [0] == $k) {
  6706. array_splice ( $verifyList, $m, 1, $v );
  6707. }
  6708. }
  6709. }
  6710. // print_r($verifyList);
  6711. $receiptList [$key] ['verifyList'] = $verifyList;
  6712. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6713. 'where' => 'sid=' . $value ['staff'],
  6714. 'asArray' => true
  6715. ) );
  6716. $receiptList [$key] ['button'] = $button;
  6717. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  6718. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  6719. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  6720. $receiptList [$key] ['relust'] = $relust;
  6721. $receiptList [$key] ['relustABS'] = abs ( $relust );
  6722. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  6723. }
  6724. //print_r($receiptList);die;
  6725. // $data['verifyDetail']=$verifyDetail;
  6726. $mothHtml = "";
  6727. for($i = 1; $i <= 12; $i ++) {
  6728. if ($month == $i)
  6729. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6730. else
  6731. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6732. }
  6733. // 获取审批日志
  6734. Doo::loadModel ( 'receiptLog' );
  6735. $receiptLog = new receiptLog ();
  6736. $rlList = array ();
  6737. $rlInfo = $receiptLog->getOne ( array (
  6738. 'where' => 'rid=' . $rid . ' and status=4',
  6739. 'asArray' => true
  6740. ) );
  6741. $tijdate = $receiptLog->getOne ( array (
  6742. 'where' => 'rid=' . $rid . ' and status=2',
  6743. 'asc' => 'rlid',
  6744. 'asArray' => true
  6745. ) );
  6746. if (! empty ( $rlInfo )) {
  6747. $rlList = $receiptLog->find ( array (
  6748. 'where' => 'rid=' . $rid,
  6749. 'asc' => 'rlid',
  6750. 'asArray' => true
  6751. ) );
  6752. }
  6753. // echo $rid;
  6754. // print_r($receiptList);
  6755. $receiptList [0] ['rlList'] = $rlList;
  6756. // print_r($receiptList);
  6757. $enclosurList = $enclosur->find ( array (
  6758. 'where' => 'rid=' . $rid,
  6759. 'asArray' => true
  6760. ) );
  6761. $enclosurHtml = '';
  6762. foreach ( $enclosurList as $value ) {
  6763. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  6764. }
  6765. $data ['enclosurHtml'] = $enclosurHtml;
  6766. $data ['rolename'] = $rolename ['name'];
  6767. $data ['mothHtml'] = $mothHtml;
  6768. $receiptList[0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  6769. $data ['rid'] = $rid;
  6770. $data ['tijdate'] = $tijdate ['date'];
  6771. $data ['receiptList'] = $receiptList;
  6772. $data ['receiptApprovalCount'] = count ( $receiptList );
  6773. $data ['status'] = $status;
  6774. $data ['year'] = $year;
  6775. $data ['categoryList'] = $categoryList;
  6776. $data ['staffList'] = $staffList;
  6777. $data ['cid'] = $cid;
  6778. $data ['sid'] = $sid;
  6779. $data ['ap'] = $ap;
  6780. $data ['memu'] = "receipt";
  6781. $data ['staff'] = $this->staff;
  6782. $data ['receiptMemu'] = 'approvalExpenses';
  6783. $data ['verifyId'] = $this->verifyId;
  6784. $data ['executeId'] = $this->executeId;
  6785. if($receiptList[0]['receiptClass']==1){
  6786. $this->render ( "/receipt/feeAgencyApproval", $data );
  6787. }elseif($receiptList[0]['receiptClass']==2){
  6788. //TODO 行程单2.0
  6789. if(!empty($receiptList[0]['itinerary2'])){
  6790. $this->render ( "/receipt/feeTraveApproval2", $data );
  6791. }else{
  6792. $this->render ( "/receipt/feeTraveApproval", $data );
  6793. }
  6794. }elseif($receiptList[0]['receiptClass']==3){
  6795. $this->render ( "/receipt/feeInternalTrainApproval", $data );
  6796. }else{
  6797. $this->render ( "/admin/receiptburEdi", $data );
  6798. }
  6799. }
  6800. function hisImplement() {
  6801. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6802. if (empty ( $item ))
  6803. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  6804. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  6805. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6806. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  6807. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  6808. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  6809. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  6810. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  6811. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  6812. Doo::loadClass ( 'XDeode' );
  6813. $XDeode = new XDeode ( 5 );
  6814. Doo::loadModel ( 'receipt' );
  6815. $receipt = new receipt ();
  6816. Doo::loadModel ( 'L_category' );
  6817. $Lcategory = new L_category ();
  6818. Doo::loadModel ( 'verify' );
  6819. Doo::loadModel ( 'statistics' );
  6820. $statistics = new statistics ();
  6821. $verify = new verify ();
  6822. Doo::loadModel ( 'staff' );
  6823. $staff = new staff ();
  6824. Doo::loadClass ( 'XDeode' );
  6825. $XDeode = new XDeode ( 5 );
  6826. $XDeode7 = new XDeode ( 7 );
  6827. $cid = $XDeode->decode ( $cidKey );
  6828. $condition = "";
  6829. if ($item == "expenses")
  6830. $condition = " and Rtype=1 ";
  6831. elseif ($item == "receipts")
  6832. $condition = " and Rtype=0 ";
  6833. elseif ($item == "remits")
  6834. $condition = " and Rtype=2 ";
  6835. elseif($item == "train")
  6836. $condition = " and Rtype=3 ";
  6837. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  6838. $sopString = $cidString = "";
  6839. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  6840. if (empty ( $rdate ))
  6841. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  6842. else
  6843. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  6844. if ($status == 'pendImplement') {
  6845. $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 ) ) ';
  6846. } elseif ($status == 'alerpts') {
  6847. $statusCon = '(status=8 or status=9 )';
  6848. if (empty ( $rdate )){
  6849. $dateCondition = " and Year(date) =" . $year;
  6850. }else{
  6851. $dateCondition = " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  6852. }
  6853. }
  6854. if ($sop != 'SOP')
  6855. $sopString = " and staff=" . $sop;
  6856. if ($cidKey != 'ALL')
  6857. $cidString = " and cid=" . $cid;
  6858. //汇款信息需要提取出来
  6859. if(!empty($receiptOrder)){
  6860. $receiptList = $receipt->find ( array (
  6861. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6862. 'desc' => 'rid',
  6863. 'asArray' => true
  6864. ) );
  6865. // 员工筛选
  6866. $receiptList2 = $receipt->find ( array (
  6867. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6868. 'desc' => 'rid',
  6869. 'asArray' => true
  6870. ) );
  6871. }else{
  6872. $receiptList = $receipt->find ( array (
  6873. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  6874. 'desc' => 'rid',
  6875. 'asArray' => true
  6876. ) );
  6877. // 员工筛选
  6878. $receiptList2 = $receipt->find ( array (
  6879. 'where' => $statusCon . $condition . $dateCondition,
  6880. 'desc' => 'rid',
  6881. 'asArray' => true
  6882. ) );
  6883. }
  6884. $sopStaff = array ();
  6885. foreach ( $receiptList2 as $key => $value ) {
  6886. $staffDetail = $staff->getOne ( array (
  6887. 'select' => 'username',
  6888. 'where' => 'sid=' . $value ['staff'],
  6889. 'asArray' => true
  6890. ) );
  6891. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  6892. }
  6893. // 办事处筛选
  6894. $categoryScreen = array ();
  6895. $categorList = $Lcategory->getCategory ();
  6896. foreach ( $receiptList2 as $key => $value ) {
  6897. foreach ( $categorList as $k => $v ) {
  6898. if ($value ['cid'] == $v ['cid']) {
  6899. $categoryScreen [$v ['cidKey']] = $v ['title'];
  6900. break;
  6901. }
  6902. }
  6903. }
  6904. $categoryScreenHtml = "";
  6905. foreach ( $categoryScreen as $key => $value ) {
  6906. if ($cidKey == $key)
  6907. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6908. else
  6909. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6910. }
  6911. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  6912. $data ['cidKey'] = $cidKey;
  6913. $Locate = 0;
  6914. $roleId = 0;
  6915. $button = 0;
  6916. $staffBatchNumber = 100001;
  6917. $remittanceList = array ();
  6918. foreach ( $receiptList as $key => $value ) {
  6919. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  6920. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6921. $receiptList [$key] ['Texe'] = 'false';
  6922. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  6923. $receiptList [$key] ['Texe'] = 'true';
  6924. }
  6925. $receiptList [$key] ['TRexe'] = 'true';
  6926. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  6927. $receiptList [$key] ['TRexe'] = 'false';
  6928. }
  6929. $receiptList [$key] ['Locate'] = $Locate;
  6930. $Locate ++;
  6931. $receiptList [$key] ['reviseDetail'] = array ();
  6932. if (! empty ( $value ['reviseDetail'] ))
  6933. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6934. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6935. $categoryDetil = $Lcategory->getOne ( array (
  6936. 'where' => 'cid=' . $value ['cid'],
  6937. 'asArray' => true
  6938. ) );
  6939. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6940. // 检测编辑状态
  6941. $verifyList = $verify->getOne ( array (
  6942. 'where' => 'vid=' . $value ['verify'],
  6943. 'asArray' => true
  6944. ) );
  6945. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6946. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6947. Doo::loadModel ( 'role' );
  6948. $role = new role ();
  6949. $flag = true;
  6950. $roleKey = 0;
  6951. $endStaffArray = array ();
  6952. $roleArrayCopy = array ();
  6953. foreach ( $verifyList as $k => $v ) {
  6954. // init verifyStaff
  6955. if ($v [1] == 'ROLE') {
  6956. if (! empty ( $verifyStaff )) {
  6957. $endStaffArray = end ( $verifyStaff );
  6958. }
  6959. $roleVerify = json_decode ( $v [3], true );
  6960. $roleKey = $k;
  6961. $roleArray = array ();
  6962. $rolename = $role->getOne ( array (
  6963. 'where' => 'rid=' . $v [0],
  6964. 'asArray' => true
  6965. ) );
  6966. foreach ( $roleVerify as $o => $p ) {
  6967. $staffID = explode ( '_', $p );
  6968. $staffInfo = $staff->getOne ( array (
  6969. 'where' => 'sid=' . $staffID [0],
  6970. 'asArray' => true
  6971. ) );
  6972. $exp = array (
  6973. 0 => $staffInfo ['sid'],
  6974. 1 => $staffID [1],
  6975. 2 => $staffInfo ['avatar'],
  6976. 'date' => '',
  6977. 'date' => '',
  6978. 'opinion' => '',
  6979. 'status' => '',
  6980. 'rolename' => $rolename ['name']
  6981. );
  6982. array_push ( $roleArray, $exp );
  6983. }
  6984. $roleArrayCopy [$v [0]] = $roleArray;
  6985. }
  6986. $verifyList [$k] ['date'] = "";
  6987. $verifyList [$k] ['opinion'] = "";
  6988. $verifyList [$k] ['status'] = "";
  6989. if (empty ( $verifyStaff )) {
  6990. $verifyList [$k] ['date'] = "";
  6991. $verifyList [$k] ['opinion'] = "";
  6992. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6993. $verifyList [$k] ['status'] = 4;
  6994. $flag = false;
  6995. }
  6996. } else {
  6997. foreach ( $verifyStaff as $m => $u ) {
  6998. if ($v [0] == $m) {
  6999. $verifyList [$k] ['date'] = $u ['date'];
  7000. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7001. $verifyList [$k] ['status'] = $u ['status'];
  7002. $flag = false;
  7003. break;
  7004. }
  7005. }
  7006. $endStaffArray = end ( $verifyStaff );
  7007. }
  7008. }
  7009. $rolename ['name'] = '';
  7010. if (! empty ( $roleId )) {
  7011. Doo::loadModel ( 'role' );
  7012. $role = new role ();
  7013. $rolename = $role->getOne ( array (
  7014. 'where' => 'rid=' . $roleId,
  7015. 'asArray' => true
  7016. ) );
  7017. }
  7018. if (! empty ( $verifyStaff ))
  7019. $endStaffArray = end ( $verifyStaff );
  7020. $KOP = false;
  7021. foreach ( $roleArrayCopy as $P => $A ) {
  7022. foreach ( $A as $MKI => $AVL ) {
  7023. if (! empty ( $verifyStaff )) {
  7024. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7025. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7026. $button = 4;
  7027. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7028. }
  7029. foreach ( $verifyStaff as $m => $u ) {
  7030. $AVLFK = $AVL [0] . '_R';
  7031. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7032. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7033. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7034. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7035. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7036. break;
  7037. }
  7038. }
  7039. } else {
  7040. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7041. $button = 4;
  7042. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7043. }
  7044. }
  7045. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7046. $KOP = true;
  7047. }
  7048. }
  7049. foreach ( $roleArrayCopy as $k => $v ) {
  7050. foreach ( $verifyList as $m => $n ) {
  7051. if ($n [0] == $k) {
  7052. array_splice ( $verifyList, $m, 1, $v );
  7053. }
  7054. }
  7055. }
  7056. $receiptList [$key] ['verifyList'] = $verifyList;
  7057. $staffDetail = $staff->getOne ( array (
  7058. 'where' => 'sid=' . $value ['staff'],
  7059. 'asArray' => true
  7060. ) );
  7061. $receiptList [$key] ['staffDetail'] = $staffDetail;
  7062. $receiptList [$key] ['button'] = $button;
  7063. if ($value['Rtype']==1){
  7064. $receiptList [$key] ['relust'] = $value['sum']-$value['loanSum'];
  7065. $receiptList [$key] ['relustABS'] = sprintf("%.2f",abs($receiptList [$key] ['relust']));
  7066. }elseif($value['Rtype']==3){
  7067. // 收入合计
  7068. Doo::loadModel ( 'invoiceTraining' );
  7069. $invoiceTraining = new invoiceTraining ();
  7070. $invoiceTrainingDetail = array (
  7071. 'invoiceArriveAmount' => '0.00',
  7072. 'RIAmount' => '0.00',
  7073. 'invoiceTotalAmount' => '0.00',
  7074. 'invoiceCompanyAmount' => '0.00',
  7075. 'invoiceArriveAmountM'=>'0.00',
  7076. 'invoiceCompanyAmountM'=>'0.00'
  7077. );
  7078. if ($value ['invoiceTrainId'] != 0) {
  7079. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value['invoiceTrainId'] );
  7080. }
  7081. $invoiceArriveAmount = $RIAmount = 0;
  7082. if (! empty ( $invoiceTrainingDetail )) {
  7083. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  7084. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  7085. }
  7086. // 备用金
  7087. $sum = 0;
  7088. if (! empty ( $value ['trainLoanRid'] )) {
  7089. $receiptLoanList = $receipt->getReceiptInRid ( $value ['trainLoanRid'] );
  7090. foreach ($receiptLoanList as $kll=>$vll){
  7091. $sum+=$vll['sum'];
  7092. }
  7093. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $value ['trainLoanRid'] );
  7094. // $sum = $receiptLoanDetailBak ['sum'];
  7095. }
  7096. // 支出项金额详情
  7097. // 项目金额合计
  7098. Doo::loadModel ( 'RItem' );
  7099. $RItem = new RItem ();
  7100. Doo::loadModel ( 'accountItem' );
  7101. $accountItem = new accountItem ();
  7102. // 讲师获得
  7103. Doo::loadModel ( 'RILecturer' );
  7104. $RILecturer = new RILecturer ();
  7105. $RItemList = $RItem->getRItemByRid ( $value['rid'] );
  7106. $RILecturerList = $RILecturer->getRILecturerByRid ( $value['rid'] );
  7107. // 支出项金额详情
  7108. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  7109. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  7110. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  7111. $receiptList [$key] ['payment'] =$payment;
  7112. $receiptList [$key] ['paymentABS'] =sprintf("%.2f",abs($payment));
  7113. }
  7114. // 设置导出汇款execl
  7115. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  7116. $remittanceDetail = array (
  7117. $staffBatchNumber,
  7118. $value ['remittanceName'],
  7119. $value ['bankNumber'],
  7120. $value ['bankName'],
  7121. $value ['remittanceBankType'],
  7122. $value ['coupletNumber'],
  7123. $value ['sum']
  7124. );
  7125. array_push ( $remittanceList, $remittanceDetail );
  7126. $staffBatchNumber ++;
  7127. }
  7128. }
  7129. $data ['remittanceList'] = json_encode ( $remittanceList );
  7130. // print_r($receiptList);
  7131. $mothHtml = "";
  7132. for($i = 1; $i <= 12; $i ++) {
  7133. if ($moth == $i)
  7134. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7135. else
  7136. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7137. }
  7138. $dayHtml = "";
  7139. if ($day != "DAY" || $moth != "MONTH") {
  7140. for($i = 1; $i <= 31; $i ++) {
  7141. if ($day == $i)
  7142. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7143. else
  7144. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7145. }
  7146. }
  7147. $sopHtml = "";
  7148. foreach ( $sopStaff as $key => $value ) {
  7149. if ($sop == $key)
  7150. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  7151. else
  7152. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  7153. }
  7154. $data ['status'] = $status;
  7155. $data ['rdate'] = $rdate;
  7156. $data ['sopHtml'] = $sopHtml;
  7157. $data ['dayHtml'] = $dayHtml;
  7158. $data ['mothHtml'] = $mothHtml;
  7159. $data ['receiptList'] = $receiptList;
  7160. $data ['memu'] = "receipt";
  7161. $data ['staff'] = $this->staff;
  7162. $data ['receiptMemu'] = 'implement';
  7163. $data ['verifyId'] = $this->verifyId;
  7164. $data ['executeId'] = $this->executeId;
  7165. $data ['item'] = $item;
  7166. $data ['year'] = $year;
  7167. $data ['moth'] = $moth;
  7168. $data['receiptOrder']=$receiptOrder;
  7169. $data ['day'] = $day;
  7170. $data ['sop'] = $sop;
  7171. $this->render ( "/admin/hisImplement", $data );
  7172. }
  7173. /**
  7174. * 导出汇款信息的exelc
  7175. */
  7176. function exportRemittance() {
  7177. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  7178. if (empty ( $remittanceInfo ))
  7179. die ( 'illegal request' );
  7180. $title = array (
  7181. '员工编号',
  7182. '姓名',
  7183. '员工账号',
  7184. '员工账户开户行',
  7185. '转账类型',
  7186. '联行号',
  7187. '金额'
  7188. );
  7189. $data = json_decode ( $remittanceInfo, true );
  7190. if (empty ( $data ))
  7191. die ( 'illegal request' );
  7192. Doo::loadClass ( 'receipt.func' );
  7193. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  7194. header ( 'Content-Type:text/html;charset=utf-8' );
  7195. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  7196. }
  7197. function ajaxExamine() {
  7198. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  7199. Doo::loadModel ( 'receipt' );
  7200. $receipt = new receipt ();
  7201. if (! empty ( $rid )) {
  7202. $rLRes = $receipt->find ( array (
  7203. '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,
  7204. 'asArray' => true
  7205. ) );
  7206. if(!empty($rLRes)){
  7207. Doo::loadClass ( 'XDeode' );
  7208. $XDeode = new XDeode ( 7 );
  7209. $rLRes [0]['ridKey'] = $XDeode->encode( $rLRes [0]['rid'] );
  7210. echo json_encode ( array (
  7211. 'status' => 1,
  7212. 'receipt' => $rLRes [0]
  7213. ) );
  7214. die ();
  7215. }else{
  7216. echo json_encode ( array (
  7217. 'status' => 1,
  7218. 'receipt' => array ()
  7219. ) );
  7220. die ();
  7221. }
  7222. }
  7223. echo json_encode ( array (
  7224. 'status' => 0,
  7225. 'receipt' => array ()
  7226. ) );
  7227. die ();
  7228. }
  7229. /*
  7230. * 废弃
  7231. */
  7232. function myReceipt() {
  7233. // all approval past withdraw
  7234. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  7235. if (empty ( $item ))
  7236. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  7237. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7238. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  7239. Doo::loadModel ( 'receipt' );
  7240. $receipt = new receipt ();
  7241. // pre-loaded
  7242. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  7243. // have cache
  7244. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  7245. if (! empty ( $moth )) // yearPage
  7246. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  7247. $this->showCache ( $path );
  7248. }
  7249. Doo::loadModel ( 'L_category' );
  7250. $Lcategory = new L_category ();
  7251. Doo::loadModel ( 'verify' );
  7252. Doo::loadModel ( 'statistics' );
  7253. $statistics = new statistics ();
  7254. $verify = new verify ();
  7255. Doo::loadModel ( 'staff' );
  7256. $staff = new staff ();
  7257. $condition = " and status!=0 ";
  7258. if ($item == "approval")
  7259. $condition = " and status=2 ";
  7260. elseif ($item == "withdraw")
  7261. $condition = " and status=3 ";
  7262. elseif ($item == "past")
  7263. $condition = " and status=1 ";
  7264. elseif ($item == "whdw")
  7265. $condition = " and status=4 ";
  7266. $dateCondition = " and Year(date) =" . $year;
  7267. if (! empty ( $moth )) {
  7268. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  7269. $stList = $statistics->getOne ( array (
  7270. 'select' => 'rePrice ,agPrice',
  7271. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7272. 'asArray' => true
  7273. ) );
  7274. } else
  7275. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  7276. if (empty ( $stList ))
  7277. $stList = array (
  7278. 'rePrice' => 0,
  7279. 'agPrice' => 0
  7280. );
  7281. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  7282. $data ['stList'] = array (
  7283. 'rePrice' => $stList ['rePrice'],
  7284. 'agPrice' => $stList ['agPrice'],
  7285. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  7286. );
  7287. $receiptList = $receipt->find ( array (
  7288. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  7289. 'desc' => 'rid',
  7290. 'asArray' => true
  7291. ) );
  7292. $Locate = 0;
  7293. $roleId = 0;
  7294. $button = 0;
  7295. foreach ( $receiptList as $key => $value ) {
  7296. $receiptList [$key] ['Locate'] = $Locate;
  7297. $Locate ++;
  7298. $receiptList [$key] ['reviseDetail'] = array ();
  7299. if (! empty ( $value ['reviseDetail'] ))
  7300. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7301. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7302. $categoryDetil = $Lcategory->getOne ( array (
  7303. 'where' => 'cid=' . $value ['cid'],
  7304. 'asArray' => true
  7305. ) );
  7306. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7307. // 检测编辑状态
  7308. $verifyList = $verify->getOne ( array (
  7309. 'where' => 'vid=' . $value ['verify'],
  7310. 'asArray' => true
  7311. ) );
  7312. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7313. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7314. Doo::loadModel ( 'role' );
  7315. $role = new role ();
  7316. $flag = true;
  7317. $roleKey = 0;
  7318. $endStaffArray = array ();
  7319. $roleArrayCopy = array ();
  7320. foreach ( $verifyList as $k => $v ) {
  7321. // init verifyStaff
  7322. if ($v [1] == 'ROLE') {
  7323. if (! empty ( $verifyStaff )) {
  7324. $endStaffArray = end ( $verifyStaff );
  7325. // if ($v[0]==$endStaffArray['nextStaff']){
  7326. // $roleId=$v[0];
  7327. // }
  7328. }
  7329. $roleVerify = json_decode ( $v [3], true );
  7330. $roleKey = $k;
  7331. $roleArray = array ();
  7332. $rolename = $role->getOne ( array (
  7333. 'where' => 'rid=' . $v [0],
  7334. 'asArray' => true
  7335. ) );
  7336. foreach ( $roleVerify as $o => $p ) {
  7337. $staffID = explode ( '_', $p );
  7338. $staffInfo = $staff->getOne ( array (
  7339. 'where' => 'sid=' . $staffID [0],
  7340. 'asArray' => true
  7341. ) );
  7342. // print_r($staffID);
  7343. $exp = array (
  7344. 0 => $staffInfo ['sid'],
  7345. 1 => $staffID [1],
  7346. 2 => $staffInfo ['avatar'],
  7347. 'date' => '',
  7348. 'date' => '',
  7349. 'opinion' => '',
  7350. 'status' => '',
  7351. 'rolename' => $rolename ['name']
  7352. );
  7353. array_push ( $roleArray, $exp );
  7354. }
  7355. $roleArrayCopy [$v [0]] = $roleArray;
  7356. // $verifyList[$k]['roleArray']=$roleArray;
  7357. }
  7358. $verifyList [$k] ['date'] = "";
  7359. $verifyList [$k] ['opinion'] = "";
  7360. $verifyList [$k] ['status'] = "";
  7361. if (empty ( $verifyStaff )) {
  7362. $verifyList [$k] ['date'] = "";
  7363. $verifyList [$k] ['opinion'] = "";
  7364. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7365. $verifyList [$k] ['status'] = 4;
  7366. $flag = false;
  7367. }
  7368. } else {
  7369. foreach ( $verifyStaff as $m => $u ) {
  7370. if ($v [0] == $m) {
  7371. $verifyList [$k] ['date'] = $u ['date'];
  7372. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7373. $verifyList [$k] ['status'] = $u ['status'];
  7374. $flag = false;
  7375. break;
  7376. }
  7377. }
  7378. $endStaffArray = end ( $verifyStaff );
  7379. if (isset ( $endStaffArray ['ROLE'] )) {
  7380. } else {
  7381. // $endKey=key($verifyStaff);
  7382. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  7383. // $button=4;
  7384. // $verifyList[$k]['status']=4;
  7385. // }
  7386. }
  7387. }
  7388. }
  7389. $rolename ['name'] = '';
  7390. if (! empty ( $roleId )) {
  7391. Doo::loadModel ( 'role' );
  7392. $role = new role ();
  7393. $rolename = $role->getOne ( array (
  7394. 'where' => 'rid=' . $roleId,
  7395. 'asArray' => true
  7396. ) );
  7397. }
  7398. if (! empty ( $verifyStaff ))
  7399. $endStaffArray = end ( $verifyStaff );
  7400. $KOP = false;
  7401. foreach ( $roleArrayCopy as $P => $A ) {
  7402. foreach ( $A as $MKI => $AVL ) {
  7403. if (! empty ( $verifyStaff )) {
  7404. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7405. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7406. $button = 4;
  7407. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7408. }
  7409. foreach ( $verifyStaff as $m => $u ) {
  7410. $AVLFK = $AVL [0] . '_R';
  7411. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7412. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7413. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7414. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7415. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7416. break;
  7417. }
  7418. }
  7419. } else {
  7420. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7421. $button = 4;
  7422. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7423. }
  7424. }
  7425. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7426. $KOP = true;
  7427. }
  7428. }
  7429. foreach ( $roleArrayCopy as $k => $v ) {
  7430. foreach ( $verifyList as $m => $n ) {
  7431. if ($n [0] == $k) {
  7432. array_splice ( $verifyList, $m, 1, $v );
  7433. }
  7434. }
  7435. }
  7436. $receiptList [$key] ['verifyList'] = $verifyList;
  7437. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7438. 'where' => 'sid=' . $value ['staff'],
  7439. 'asArray' => true
  7440. ) );
  7441. $receiptList [$key] ['button'] = $button;
  7442. }
  7443. // print_r($receiptList);die;
  7444. $mothHtml = "";
  7445. for($i = 1; $i <= 12; $i ++) {
  7446. if ($moth == $i)
  7447. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7448. else
  7449. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7450. }
  7451. $data ['mothHtml'] = $mothHtml;
  7452. $data ['receiptList'] = $receiptList;
  7453. $data ['memu'] = "receipt";
  7454. $data ['staff'] = $this->staff;
  7455. $data ['receiptMemu'] = 'receipt';
  7456. $data ['verifyId'] = $this->verifyId;
  7457. $data ['executeId'] = $this->executeId;
  7458. $data ['item'] = $item;
  7459. $data ['year'] = $year;
  7460. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  7461. // sufficient condition to generate cache
  7462. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  7463. $receiptList = $receipt->find ( array (
  7464. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  7465. 'asArray' => true
  7466. ) );
  7467. if (empty ( $receiptList )) { // generated files
  7468. ob_start ();
  7469. $this->render ( "/admin/saea_myList", $data );
  7470. $this->cacheFile ( $path );
  7471. die ();
  7472. // $content = ob_get_contents();
  7473. // $fp = fopen($path, "w");
  7474. // fwrite($fp, $content);
  7475. // fclose($fp);
  7476. }
  7477. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  7478. $receiptList = $receipt->find ( array (
  7479. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  7480. 'asArray' => true
  7481. ) );
  7482. if (empty ( $receiptList )) { // generated files
  7483. ob_start ();
  7484. $this->render ( "/admin/saea_myList", $data );
  7485. $this->cacheFile ( $path );
  7486. die ();
  7487. }
  7488. }
  7489. }
  7490. $this->render ( "/admin/saea_myList", $data );
  7491. }
  7492. function approvedReceipt() {
  7493. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7494. Doo::loadModel ( 'receipt' );
  7495. Doo::loadModel ( 'receiptDetail' );
  7496. $receipt = new receipt ();
  7497. $receiptDetail = new receiptDetail ();
  7498. Doo::loadModel ( 'statistics' );
  7499. Doo::loadModel ( 'itemStatistics' );
  7500. $statistics = new statistics ();
  7501. $itemStatistics = new itemStatistics ();
  7502. Doo::loadModel ( "verify" );
  7503. $verify = new verify ();
  7504. // 审批状态的判定
  7505. $receiptDetailList = $receipt->getOne ( array (
  7506. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  7507. 'asArray' => true
  7508. ) );
  7509. if (empty ( $receiptDetailList ))
  7510. return "/saeaBorad";
  7511. $verifyDetail = $verify->getOne ( array (
  7512. 'where' => ' vid =' . $receiptDetailList ['verify'],
  7513. 'asArray' => true
  7514. ) );
  7515. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  7516. if (empty ( $receiptDetailList ['nowStaff'] )) {
  7517. $nowStaff = "";
  7518. $nowStaffList = array ();
  7519. if ($verifyDetail [0] [1] == 'ROLE') {
  7520. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7521. foreach ( $vStaffString as $key => $value ) {
  7522. $staffK = explode ( "_", $value );
  7523. array_push ( $nowStaffList, $staffK [0] );
  7524. }
  7525. $nowStaff = implode ( ',', $nowStaffList );
  7526. } else {
  7527. $nowStaff = $verifyDetail [0] [0];
  7528. }
  7529. $receipt->nowStaff = $nowStaff;
  7530. }
  7531. // echo $nowStaff;
  7532. // print_r($verifyDetail);die;
  7533. $receipt->rid = $receiptDetailList ['rid'];
  7534. $receipt->date = date ( "Y-m-d" );
  7535. $receipt->status = 2;
  7536. $receipt->update ();
  7537. $receiptDetail->status = 2;
  7538. $receiptDetail->update ( array (
  7539. 'where' => 'rid=' . $receiptDetailList ['rid']
  7540. ) );
  7541. Doo::loadModel ( "receiptLog" );
  7542. $receiptLog = new receiptLog ();
  7543. Doo::loadModel ( "verify" );
  7544. $verify = new verify ();
  7545. $receiptInfo = $receipt->getOne ( array (
  7546. 'where' => 'rid=' . $rid,
  7547. 'asArray' => true
  7548. ) );
  7549. $vr = $verify->getOne ( array (
  7550. 'where' => 'vid=' . $receiptInfo ['verify'],
  7551. 'asArray' => true
  7552. ) );
  7553. $jd = json_decode ( $vr ['staff'] );
  7554. $roleId = 0;
  7555. foreach ( $jd as $key => $value ) {
  7556. if ($value [1] == 'ROLE') {
  7557. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7558. if ($pos !== false) {
  7559. $roleId = $value [0];
  7560. }
  7561. }
  7562. }
  7563. // 审批日志
  7564. // echo $roleId;die;
  7565. if (! empty ( $roleId )) {
  7566. Doo::loadModel ( "role" );
  7567. $role = new role ();
  7568. $roleInfo = $role->getOne ( array (
  7569. 'where' => 'rid=' . $roleId,
  7570. 'asArray' => true
  7571. ) );
  7572. // $receiptLog->rolename = $roleInfo ['name'];
  7573. }
  7574. $receiptLog->username = $this->staff [0] ['username'];
  7575. $receiptLog->uid = $this->staff [0] ['sid'];
  7576. $receiptLog->date = date ( "Y-m-d" );
  7577. $receiptLog->opinion = '提交审批';
  7578. $receiptLog->img = $this->staff [0] ['avatar'];
  7579. $receiptLog->status = 2;
  7580. $receiptLog->rid = $rid;
  7581. $receiptLog->insert ();
  7582. // statistics item
  7583. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7584. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7585. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7586. $stat = $statistics->getOne ( array (
  7587. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7588. 'asArray' => true
  7589. ) );
  7590. if (empty ( $stat )) {
  7591. $statistics->date = date ( "Y-m-d" );
  7592. $statistics->cid = $this->staff [0] ['cid'];
  7593. $statistics->staff = $this->staff [0] ['sid'];
  7594. $statistics->agPrice = 0;
  7595. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7596. $statistics->insert ();
  7597. } else {
  7598. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7599. $statistics->update ( array (
  7600. 'where' => 'sid=' . $stat ['sid']
  7601. ) );
  7602. }
  7603. return "/expenses";
  7604. }
  7605. function approval() {
  7606. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7607. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7608. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7609. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7610. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7611. if (empty ( $status ))
  7612. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7613. $vidList = array ();
  7614. $button = 0;
  7615. Doo::loadModel ( 'verify' );
  7616. $verify = new verify ();
  7617. Doo::loadModel ( 'receipt' );
  7618. $receipt = new receipt ();
  7619. Doo::loadModel ( 'staff' );
  7620. $staff = new staff ();
  7621. Doo::loadModel ( 'L_category' );
  7622. $Lcategory = new L_category ();
  7623. // user verify ID
  7624. $verifyDetail = $verify->find ( array (
  7625. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7626. 'asArray' => true
  7627. ) );
  7628. foreach ( $verifyDetail as $key => $value ) {
  7629. array_push ( $vidList, $value ['vid'] );
  7630. }
  7631. $vid = implode ( ",", $vidList );
  7632. if (empty ( $verifyDetail ))
  7633. $vid = 0;
  7634. /*
  7635. */
  7636. $dateCondition = " and Year(date) =" . $year;
  7637. if (! empty ( $month ))
  7638. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7639. $categoryList = $Lcategory->find ( array (
  7640. 'asArray' => true
  7641. ) );
  7642. $staffList = $staff->find ( array (
  7643. 'where' => 'cid=' . $cid,
  7644. 'asArray' => true
  7645. ) );
  7646. $cateCondition = "";
  7647. $staffCondition = "";
  7648. $approvalCondition = "";
  7649. if (! empty ( $cid ))
  7650. $cateCondition = ' and cid=' . $cid;
  7651. if (! empty ( $sid )) {
  7652. $staffCondition = ' and staff=' . $sid;
  7653. $cateCondition = "";
  7654. }
  7655. // elseif($status==1){
  7656. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7657. // }
  7658. if ($status == 2) {
  7659. // 查找角色审批人
  7660. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7661. }
  7662. $ap = "";
  7663. if ($status == 4) {
  7664. $ap = 4;
  7665. $status = 2;
  7666. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7667. }
  7668. if ($status == 5) {
  7669. $status = 4;
  7670. $ap = 5;
  7671. }
  7672. // echo $vid;
  7673. // get Receipt By verifyID status 2 .$approvalCondition
  7674. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7675. $receiptList = $receipt->find ( array (
  7676. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7677. 'desc' => 'rid',
  7678. 'asArray' => true
  7679. ) );
  7680. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7681. $Locate = 0;
  7682. if ($ap == 4)
  7683. $status = 4;
  7684. elseif ($ap == 5)
  7685. $status = 5;
  7686. foreach ( $receiptList as $key => $value ) {
  7687. $receiptList [$key] ['Locate'] = $Locate;
  7688. $Locate ++;
  7689. $receiptList [$key] ['reviseDetail'] = array ();
  7690. if (! empty ( $value ['reviseDetail'] ))
  7691. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7692. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7693. $categoryDetil = $Lcategory->getOne ( array (
  7694. 'where' => 'cid=' . $value ['cid'],
  7695. 'asArray' => true
  7696. ) );
  7697. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7698. $verifyList = $verify->getOne ( array (
  7699. 'where' => 'vid=' . $value ['verify'],
  7700. 'asArray' => true
  7701. ) );
  7702. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7703. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7704. foreach ( $verifyList as $k => $v ) {
  7705. // init verifyStaff
  7706. $verifyList [$k] ['date'] = "";
  7707. $verifyList [$k] ['opinion'] = "";
  7708. $verifyList [$k] ['status'] = "";
  7709. if (empty ( $verifyStaff )) {
  7710. $verifyList [$k] ['date'] = "";
  7711. $verifyList [$k] ['opinion'] = "";
  7712. if ($v [0] == $this->staff [0] ['sid']) {
  7713. $verifyList [$k] ['status'] = 4;
  7714. $button = 4;
  7715. }
  7716. } else {
  7717. $flag = true;
  7718. foreach ( $verifyStaff as $m => $u ) {
  7719. if ($v [0] == $m) {
  7720. $verifyList [$k] ['date'] = $u ['date'];
  7721. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7722. $verifyList [$k] ['status'] = $u ['status'];
  7723. $flag = false;
  7724. break;
  7725. }
  7726. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7727. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7728. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7729. }
  7730. if ($flag) { // 检测可编辑
  7731. if ($v [0] == $this->staff [0] ['sid']) {
  7732. $verifyList [$k] ['status'] = 4;
  7733. $button = 4;
  7734. }
  7735. }
  7736. }
  7737. }
  7738. $receiptList [$key] ['verifyList'] = $verifyList;
  7739. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7740. 'where' => 'sid=' . $value ['staff'],
  7741. 'asArray' => true
  7742. ) );
  7743. $receiptList [$key] ['button'] = $button;
  7744. }
  7745. // print_r($receiptList);die;
  7746. // $data['verifyDetail']=$verifyDetail;
  7747. $mothHtml = "";
  7748. for($i = 1; $i <= 12; $i ++) {
  7749. if ($month == $i)
  7750. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7751. else
  7752. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7753. }
  7754. $data ['mothHtml'] = $mothHtml;
  7755. $data ['receiptList'] = $receiptList;
  7756. $data ['receiptApprovalCount'] = count ( $receiptList );
  7757. $data ['status'] = $status;
  7758. $data ['year'] = $year;
  7759. $data ['categoryList'] = $categoryList;
  7760. $data ['staffList'] = $staffList;
  7761. $data ['cid'] = $cid;
  7762. $data ['sid'] = $sid;
  7763. $data ['ap'] = $ap;
  7764. $data ['memu'] = "receipt";
  7765. $data ['staff'] = $this->staff;
  7766. $data ['receiptMemu'] = 'approval';
  7767. $data ['verifyId'] = $this->verifyId;
  7768. $data ['executeId'] = $this->executeId;
  7769. $this->render ( "/admin/saea_reportList", $data );
  7770. }
  7771. function approvalDetails() {
  7772. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7773. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7774. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7775. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7776. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7777. Doo::loadModel ( 'verify' );
  7778. $verify = new verify ();
  7779. Doo::loadModel ( 'receipt' );
  7780. $receipt = new receipt ();
  7781. Doo::loadModel ( 'staff' );
  7782. $staff = new staff ();
  7783. Doo::loadModel ( 'L_category' );
  7784. $Lcategory = new L_category ();
  7785. Doo::loadModel ( 'enclosur' );
  7786. $enclosur = new enclosur ();
  7787. $vidList = array ();
  7788. $verifyDetail = $verify->find ( array (
  7789. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7790. 'asArray' => true
  7791. ) );
  7792. foreach ( $verifyDetail as $key => $value ) {
  7793. array_push ( $vidList, $value ['vid'] );
  7794. }
  7795. $vid = implode ( ",", $vidList );
  7796. if (empty ( $verifyDetail ))
  7797. $vid = 0;
  7798. $categoryList = $Lcategory->find ( array (
  7799. 'asArray' => true
  7800. ) );
  7801. $staffList = $staff->find ( array (
  7802. 'where' => 'cid=' . $cid,
  7803. 'asArray' => true
  7804. ) );
  7805. $ap = 0;
  7806. $receiptList = $receipt->find ( array (
  7807. 'where' => 'rid =' . $rid,
  7808. 'desc' => 'rid',
  7809. 'asArray' => true
  7810. ) );
  7811. $Locate = 0;
  7812. $roleId = 0;
  7813. $button = 0;
  7814. foreach ( $receiptList as $key => $value ) {
  7815. $receiptList [$key] ['Locate'] = $Locate;
  7816. $Locate ++;
  7817. $receiptList [$key] ['reviseDetail'] = array ();
  7818. if (! empty ( $value ['reviseDetail'] ))
  7819. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7820. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7821. $categoryDetil = $Lcategory->getOne ( array (
  7822. 'where' => 'cid=' . $value ['cid'],
  7823. 'asArray' => true
  7824. ) );
  7825. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7826. // 检测编辑状态
  7827. $verifyList = $verify->getOne ( array (
  7828. 'where' => 'vid=' . $value ['verify'],
  7829. 'asArray' => true
  7830. ) );
  7831. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7832. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7833. Doo::loadModel ( 'role' );
  7834. $role = new role ();
  7835. // print_r($verifyList);
  7836. $flag = true;
  7837. $roleKey = 0;
  7838. $endStaffArray = array ();
  7839. $roleArrayCopy = array ();
  7840. foreach ( $verifyList as $k => $v ) {
  7841. // init verifyStaff
  7842. if ($v [1] == 'ROLE') {
  7843. if (! empty ( $verifyStaff )) {
  7844. $endStaffArray = end ( $verifyStaff );
  7845. if ($v [0] == $endStaffArray ['nextStaff']) {
  7846. $roleId = $v [0];
  7847. }
  7848. }
  7849. $roleVerify = json_decode ( $v [3], true );
  7850. $roleKey = $k;
  7851. $roleArray = array ();
  7852. $rolename = $role->getOne ( array (
  7853. 'where' => 'rid=' . $v [0],
  7854. 'asArray' => true
  7855. ) );
  7856. foreach ( $roleVerify as $o => $p ) {
  7857. $staffID = explode ( '_', $p );
  7858. $staffInfo = $staff->getOne ( array (
  7859. 'where' => 'sid=' . $staffID [0],
  7860. 'asArray' => true
  7861. ) );
  7862. // print_r($staffID);
  7863. $exp = array (
  7864. 0 => $staffInfo ['sid'],
  7865. 1 => $staffID [1],
  7866. 2 => $staffInfo ['avatar'],
  7867. 'date' => '',
  7868. 'date' => '',
  7869. 'opinion' => '',
  7870. 'status' => '',
  7871. 'rolename' => $rolename ['name']
  7872. );
  7873. array_push ( $roleArray, $exp );
  7874. }
  7875. $roleArrayCopy [$v [0]] = $roleArray;
  7876. // $verifyList[$k]['roleArray']=$roleArray;
  7877. }
  7878. // print_r($roleArray);
  7879. $verifyList [$k] ['date'] = "";
  7880. $verifyList [$k] ['opinion'] = "";
  7881. $verifyList [$k] ['status'] = "";
  7882. if (empty ( $verifyStaff )) {
  7883. $verifyList [$k] ['date'] = "";
  7884. $verifyList [$k] ['opinion'] = "";
  7885. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7886. $verifyList [$k] ['status'] = 4;
  7887. $button = 4;
  7888. $flag = false;
  7889. }
  7890. } else {
  7891. foreach ( $verifyStaff as $m => $u ) {
  7892. if ($v [0] == $m) {
  7893. $verifyList [$k] ['date'] = $u ['date'];
  7894. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7895. $verifyList [$k] ['status'] = $u ['status'];
  7896. $flag = false;
  7897. break;
  7898. }
  7899. }
  7900. $endStaffArray = end ( $verifyStaff );
  7901. if (isset ( $endStaffArray ['ROLE'] )) {
  7902. } else {
  7903. $endKey = key ( $verifyStaff );
  7904. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7905. $button = 4;
  7906. $verifyList [$k] ['status'] = 4;
  7907. }
  7908. }
  7909. }
  7910. }
  7911. $rolename ['name'] = '';
  7912. if (! empty ( $roleId )) {
  7913. Doo::loadModel ( 'role' );
  7914. $role = new role ();
  7915. $rolename = $role->getOne ( array (
  7916. 'where' => 'rid=' . $roleId,
  7917. 'asArray' => true
  7918. ) );
  7919. }
  7920. if (! empty ( $verifyStaff ))
  7921. $endStaffArray = end ( $verifyStaff );
  7922. $KOP = false;
  7923. foreach ( $roleArrayCopy as $P => $A ) {
  7924. foreach ( $A as $MKI => $AVL ) {
  7925. if (! empty ( $verifyStaff )) {
  7926. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7927. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7928. $button = 4;
  7929. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7930. }
  7931. foreach ( $verifyStaff as $m => $u ) {
  7932. $AVLFK = $AVL [0] . '_R';
  7933. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7934. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7935. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7936. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7937. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7938. break;
  7939. }
  7940. }
  7941. } else {
  7942. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7943. $button = 4;
  7944. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7945. }
  7946. }
  7947. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7948. $KOP = true;
  7949. }
  7950. }
  7951. foreach ( $roleArrayCopy as $k => $v ) {
  7952. foreach ( $verifyList as $m => $n ) {
  7953. if ($n [0] == $k) {
  7954. array_splice ( $verifyList, $m, 1, $v );
  7955. }
  7956. }
  7957. }
  7958. $receiptList [$key] ['verifyList'] = $verifyList;
  7959. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7960. 'where' => 'sid=' . $value ['staff'],
  7961. 'asArray' => true
  7962. ) );
  7963. $receiptList [$key] ['button'] = $button;
  7964. }
  7965. $mothHtml = "";
  7966. for($i = 1; $i <= 12; $i ++) {
  7967. if ($month == $i)
  7968. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7969. else
  7970. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7971. }
  7972. // 获取审批日志
  7973. Doo::loadModel ( 'receiptLog' );
  7974. $receiptLog = new receiptLog ();
  7975. $rlList = array ();
  7976. $rlInfo = $receiptLog->getOne ( array (
  7977. 'where' => 'rid=' . $rid . ' and status=4',
  7978. 'asArray' => true
  7979. ) );
  7980. $tijdate = $receiptLog->getOne ( array (
  7981. 'where' => 'rid=' . $rid . ' and status=2',
  7982. 'asc' => 'rlid',
  7983. 'asArray' => true
  7984. ) );
  7985. if (! empty ( $rlInfo )) {
  7986. $rlList = $receiptLog->find ( array (
  7987. 'where' => 'rid=' . $rid,
  7988. 'asc' => 'rlid',
  7989. 'asArray' => true
  7990. ) );
  7991. }
  7992. $receiptList [0] ['rlList'] = $rlList;
  7993. $enclosurList = $enclosur->find ( array (
  7994. 'where' => 'rid=' . $rid,
  7995. 'asArray' => true
  7996. ) );
  7997. $enclosurHtml = '';
  7998. foreach ( $enclosurList as $value ) {
  7999. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  8000. }
  8001. $data ['enclosurHtml'] = $enclosurHtml;
  8002. $data ['rolename'] = $rolename ['name'];
  8003. $data ['datetij'] = $tijdate ['date'];
  8004. $data ['mothHtml'] = $mothHtml;
  8005. $data ['receiptList'] = $receiptList;
  8006. $data ['receiptApprovalCount'] = count ( $receiptList );
  8007. $data ['year'] = $year;
  8008. $data ['categoryList'] = $categoryList;
  8009. $data ['staffList'] = $staffList;
  8010. $data ['cid'] = $cid;
  8011. $data ['sid'] = $sid;
  8012. $data ['status'] = 0;
  8013. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  8014. $ap = 4;
  8015. } else
  8016. $data ['status'] = $receiptList [0] ['status'];
  8017. if ($receiptList [0] ['status'] == 4) {
  8018. $data ['status'] = 5;
  8019. $ap = 0;
  8020. }
  8021. $data ['ap'] = $ap;
  8022. $data ['memu'] = "receipt";
  8023. $data ['staff'] = $this->staff;
  8024. $data ['receiptMemu'] = 'approval';
  8025. $data ['verifyId'] = $this->verifyId;
  8026. $data ['executeId'] = $this->executeId;
  8027. $this->render ( "/admin/saeaReportListReport", $data );
  8028. }
  8029. function approvalEdi() {
  8030. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8031. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  8032. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8033. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8034. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  8035. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  8036. if (empty ( $status ))
  8037. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  8038. $vidList = array ();
  8039. $button = 0;
  8040. Doo::loadModel ( 'verify' );
  8041. Doo::loadModel ( 'receipt' );
  8042. Doo::loadModel ( 'staff' );
  8043. $staff = new staff ();
  8044. $receipt = new receipt ();
  8045. $verify = new verify ();
  8046. Doo::loadModel ( 'L_category' );
  8047. $Lcategory = new L_category ();
  8048. Doo::loadModel ( 'enclosur' );
  8049. $enclosur = new enclosur ();
  8050. // user verify ID
  8051. $verifyDetail = $verify->find ( array (
  8052. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  8053. 'asArray' => true
  8054. ) );
  8055. foreach ( $verifyDetail as $key => $value ) {
  8056. array_push ( $vidList, $value ['vid'] );
  8057. }
  8058. $vid = implode ( ",", $vidList );
  8059. if (empty ( $verifyDetail ))
  8060. $vid = 0;
  8061. $categoryList = $Lcategory->find ( array (
  8062. 'asArray' => true
  8063. ) );
  8064. $staffList = $staff->find ( array (
  8065. 'where' => 'cid=' . $cid,
  8066. 'asArray' => true
  8067. ) );
  8068. $ap = "";
  8069. if ($status == 4) {
  8070. $ap = 4;
  8071. $status = 2;
  8072. }
  8073. // get Receipt By verifyID status 2
  8074. $receiptList = $receipt->find ( array (
  8075. 'where' => 'rid =' . $rid,
  8076. 'desc' => 'rid',
  8077. 'asArray' => true
  8078. ) );
  8079. $Locate = 0;
  8080. $roleId = 0;
  8081. if ($ap == 4)
  8082. $status = 4;
  8083. foreach ( $receiptList as $key => $value ) {
  8084. $receiptList [$key] ['Locate'] = $Locate;
  8085. $Locate ++;
  8086. $receiptList [$key] ['reviseDetail'] = array ();
  8087. if (! empty ( $value ['reviseDetail'] ))
  8088. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  8089. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  8090. $categoryDetil = $Lcategory->getOne ( array (
  8091. 'where' => 'cid=' . $value ['cid'],
  8092. 'asArray' => true
  8093. ) );
  8094. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  8095. // 检测编辑状态
  8096. $verifyList = $verify->getOne ( array (
  8097. 'where' => 'vid=' . $value ['verify'],
  8098. 'asArray' => true
  8099. ) );
  8100. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  8101. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  8102. // print_r($verifyList);
  8103. //
  8104. // if (empty($verifyStaff)){
  8105. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  8106. // $verifyList[0]['status']=4;$button=4;
  8107. // }
  8108. //
  8109. // }else{
  8110. //
  8111. // }
  8112. // die;
  8113. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  8114. // echo array_search("green",$a);
  8115. //
  8116. Doo::loadModel ( 'role' );
  8117. $role = new role ();
  8118. // print_r($verifyList);
  8119. $flag = true;
  8120. $roleKey = 0;
  8121. $endStaffArray = array ();
  8122. $roleArrayCopy = array ();
  8123. foreach ( $verifyList as $k => $v ) {
  8124. // init verifyStaff
  8125. if ($v [1] == 'ROLE') {
  8126. if (! empty ( $verifyStaff )) {
  8127. $endStaffArray = end ( $verifyStaff );
  8128. if ($v [0] == $endStaffArray ['nextStaff']) {
  8129. $roleId = $v [0];
  8130. }
  8131. }
  8132. $roleVerify = json_decode ( $v [3], true );
  8133. $roleKey = $k;
  8134. $roleArray = array ();
  8135. $rolename = $role->getOne ( array (
  8136. 'where' => 'rid=' . $v [0],
  8137. 'asArray' => true
  8138. ) );
  8139. foreach ( $roleVerify as $o => $p ) {
  8140. $staffID = explode ( '_', $p );
  8141. $staffInfo = $staff->getOne ( array (
  8142. 'where' => 'sid=' . $staffID [0],
  8143. 'asArray' => true
  8144. ) );
  8145. // print_r($staffID);
  8146. $exp = array (
  8147. 0 => $staffInfo ['sid'],
  8148. 1 => $staffID [1],
  8149. 2 => $staffInfo ['avatar'],
  8150. 'date' => '',
  8151. 'date' => '',
  8152. 'opinion' => '',
  8153. 'status' => '',
  8154. 'rolename' => $rolename ['name']
  8155. );
  8156. array_push ( $roleArray, $exp );
  8157. }
  8158. $roleArrayCopy [$v [0]] = $roleArray;
  8159. // $verifyList[$k]['roleArray']=$roleArray;
  8160. }
  8161. // print_r($roleArray);
  8162. $verifyList [$k] ['date'] = "";
  8163. $verifyList [$k] ['opinion'] = "";
  8164. $verifyList [$k] ['status'] = "";
  8165. if (empty ( $verifyStaff )) {
  8166. $verifyList [$k] ['date'] = "";
  8167. $verifyList [$k] ['opinion'] = "";
  8168. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  8169. $verifyList [$k] ['status'] = 4;
  8170. $button = 4;
  8171. $flag = false;
  8172. }
  8173. } else {
  8174. foreach ( $verifyStaff as $m => $u ) {
  8175. if ($v [0] == $m) {
  8176. $verifyList [$k] ['date'] = $u ['date'];
  8177. $verifyList [$k] ['opinion'] = $u ['opinion'];
  8178. $verifyList [$k] ['status'] = $u ['status'];
  8179. $flag = false;
  8180. break;
  8181. }
  8182. }
  8183. $endStaffArray = end ( $verifyStaff );
  8184. if (isset ( $endStaffArray ['ROLE'] )) {
  8185. } else {
  8186. $endKey = key ( $verifyStaff );
  8187. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  8188. $button = 4;
  8189. $verifyList [$k] ['status'] = 4;
  8190. }
  8191. }
  8192. // print_r($endStaffArray);die;
  8193. // if (empty($verifyStaff)){
  8194. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  8195. // $verifyList[$k]['status']=4;$button=4;
  8196. // }
  8197. //
  8198. // }else{
  8199. //
  8200. // }
  8201. // if($flag){//检测可编辑
  8202. // if($v[0]==$this->staff[0]['sid']){
  8203. // $verifyList[$k]['status']=4;$button=4;
  8204. // }
  8205. // }
  8206. }
  8207. }
  8208. $rolename ['name'] = '';
  8209. if (! empty ( $roleId )) {
  8210. Doo::loadModel ( 'role' );
  8211. $role = new role ();
  8212. $rolename = $role->getOne ( array (
  8213. 'where' => 'rid=' . $roleId,
  8214. 'asArray' => true
  8215. ) );
  8216. }
  8217. if (! empty ( $verifyStaff ))
  8218. $endStaffArray = end ( $verifyStaff );
  8219. $KOP = false;
  8220. foreach ( $roleArrayCopy as $P => $A ) {
  8221. foreach ( $A as $MKI => $AVL ) {
  8222. if (! empty ( $verifyStaff )) {
  8223. // &&$rolename['rid']==$endStaffArray['nextStaff']
  8224. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  8225. $button = 4;
  8226. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  8227. }
  8228. foreach ( $verifyStaff as $m => $u ) {
  8229. $AVLFK = $AVL [0] . '_R';
  8230. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  8231. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  8232. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  8233. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  8234. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  8235. break;
  8236. }
  8237. }
  8238. } else {
  8239. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  8240. $button = 4;
  8241. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  8242. }
  8243. }
  8244. // $roleArray[$MKI]['rolename']=$rolename['name'];
  8245. $KOP = true;
  8246. }
  8247. }
  8248. // print_r($roleArrayCopy);
  8249. // echo $roleKey;
  8250. foreach ( $roleArrayCopy as $k => $v ) {
  8251. foreach ( $verifyList as $m => $n ) {
  8252. if ($n [0] == $k) {
  8253. array_splice ( $verifyList, $m, 1, $v );
  8254. }
  8255. }
  8256. }
  8257. // if ($KOP)
  8258. // array_splice($verifyList,$roleKey,1,$roleArray);
  8259. // print_r($verifyList);
  8260. $receiptList [$key] ['verifyList'] = $verifyList;
  8261. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  8262. 'where' => 'sid=' . $value ['staff'],
  8263. 'asArray' => true
  8264. ) );
  8265. $receiptList [$key] ['button'] = $button;
  8266. }
  8267. // $data['verifyDetail']=$verifyDetail;
  8268. $mothHtml = "";
  8269. for($i = 1; $i <= 12; $i ++) {
  8270. if ($month == $i)
  8271. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8272. else
  8273. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8274. }
  8275. // 获取审批日志
  8276. Doo::loadModel ( 'receiptLog' );
  8277. $receiptLog = new receiptLog ();
  8278. $rlList = array ();
  8279. $rlInfo = $receiptLog->getOne ( array (
  8280. 'where' => 'rid=' . $rid . ' and status=4',
  8281. 'asArray' => true
  8282. ) );
  8283. $tijdate = $receiptLog->getOne ( array (
  8284. 'where' => 'rid=' . $rid . ' and status=2',
  8285. 'asc' => 'rlid',
  8286. 'asArray' => true
  8287. ) );
  8288. if (! empty ( $rlInfo )) {
  8289. $rlList = $receiptLog->find ( array (
  8290. 'where' => 'rid=' . $rid,
  8291. 'asc' => 'rlid',
  8292. 'asArray' => true
  8293. ) );
  8294. }
  8295. $receiptList [0] ['rlList'] = $rlList;
  8296. $enclosurList = $enclosur->find ( array (
  8297. 'where' => 'rid=' . $rid,
  8298. 'asArray' => true
  8299. ) );
  8300. $enclosurHtml = '';
  8301. foreach ( $enclosurList as $value ) {
  8302. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  8303. }
  8304. $data ['enclosurHtml'] = $enclosurHtml;
  8305. $data ['rolename'] = $rolename ['name'];
  8306. $data ['datetij'] = $tijdate ['date'];
  8307. $data ['mothHtml'] = $mothHtml;
  8308. $data ['receiptList'] = $receiptList;
  8309. $data ['receiptApprovalCount'] = count ( $receiptList );
  8310. $data ['status'] = $status;
  8311. $data ['year'] = $year;
  8312. $data ['categoryList'] = $categoryList;
  8313. $data ['staffList'] = $staffList;
  8314. $data ['cid'] = $cid;
  8315. $data ['sid'] = $sid;
  8316. $data ['ap'] = $ap;
  8317. $data ['memu'] = "receipt";
  8318. $data ['staff'] = $this->staff;
  8319. $data ['receiptMemu'] = 'approval';
  8320. $data ['verifyId'] = $this->verifyId;
  8321. $data ['executeId'] = $this->executeId;
  8322. $this->render ( "/admin/saeaReportListReport", $data );
  8323. }
  8324. function remittanceHky() {
  8325. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  8326. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  8327. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  8328. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  8329. $page_size = 15;
  8330. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  8331. Doo::loadModel ( 'receipt' );
  8332. $receipt = new receipt ();
  8333. Doo::loadModel ( 'staff' );
  8334. $staff = new staff ();
  8335. $dateCondition = " and Year(executeDate) =" . $year;
  8336. if ($moth != 'MONTH')
  8337. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  8338. if ($day != 'DAY' && $moth != 'MONTH')
  8339. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  8340. $sql = ' (status =8 or status=9 ) and amount>0 ' . $dateCondition;
  8341. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  8342. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  8343. $limit = $pageinfo ['lower'] . ',' . $page_size;
  8344. $dayList = $receipt->find ( array (
  8345. 'select' => 'executeDate,sum(amount) as amount',
  8346. 'where' => $sql,
  8347. 'desc' => 'executeDate',
  8348. 'groupby' => 'executeDate',
  8349. 'limit' => $limit,
  8350. 'asArray' => true
  8351. ) );
  8352. // print_r($dayList);
  8353. foreach ( $dayList as $key => $value ) {
  8354. $remitString = "";
  8355. $receiptList = $receipt->find ( array (
  8356. 'select' => 'rid,executeDate,amount,staff,cid',
  8357. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  8358. 'desc' => 'executeDate',
  8359. 'asArray' => true
  8360. ) );
  8361. foreach ( $receiptList as $k => $v ) {
  8362. $sinfo = $staff->getOne ( array (
  8363. 'select' => 'username,category',
  8364. 'where' => ' sid=' . $v ['staff'],
  8365. 'asArray' => true
  8366. ) );
  8367. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  8368. }
  8369. $dayList [$key] ['staff'] = $remitString;
  8370. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  8371. }
  8372. // print_r($dayList);
  8373. $mothHtml = "";
  8374. for($i = 1; $i <= 12; $i ++) {
  8375. if ($moth == $i)
  8376. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8377. else
  8378. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8379. }
  8380. $dayHtml = "";
  8381. if ($day != "DAY" || $moth != "MONTH") {
  8382. for($i = 1; $i <= 31; $i ++) {
  8383. if ($day == $i)
  8384. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  8385. else
  8386. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  8387. }
  8388. }
  8389. $dateHtml = "";
  8390. $now = date ( "Y" );
  8391. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  8392. if ($YEARD <= $now) {
  8393. $dateHtml .= '<option ';
  8394. if ($year == $YEARD) {
  8395. $dateHtml .= 'selected ';
  8396. }
  8397. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  8398. }
  8399. }
  8400. $data ['dateHtml'] = $dateHtml;
  8401. $data ['page'] = $pageinfo;
  8402. $data ['year'] = $year;
  8403. $data ['moth'] = $moth;
  8404. $data ['day'] = $day;
  8405. $data ['get'] = $get;
  8406. $data ['dayHtml'] = $dayHtml;
  8407. $data ['mothHtml'] = $mothHtml;
  8408. $data ['receiptList'] = $dayList;
  8409. $data ['memu'] = "receipt";
  8410. $data ['staff'] = $this->staff;
  8411. $data ['receiptMemu'] = 'remittanceHky';
  8412. $data ['verifyId'] = $this->verifyId;
  8413. $data ['executeId'] = $this->executeId;
  8414. $this->render ( "/admin/remittanceHky", $data );
  8415. }
  8416. function remittancep() {
  8417. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  8418. Doo::loadModel ( 'receipt' );
  8419. $receipt = new receipt ();
  8420. Doo::loadModel ( 'staff' );
  8421. $staff = new staff ();
  8422. Doo::loadClass ( 'XDeode' );
  8423. $XDeode = new XDeode ( 5 );
  8424. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  8425. $rplist = $receipt->find ( array (
  8426. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8427. 'asArray' => true
  8428. ) );
  8429. $dayList = $receipt->find ( array (
  8430. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8431. 'desc' => 'executeDate',
  8432. 'groupby' => 'staff',
  8433. 'asArray' => true
  8434. ) );
  8435. $html = '';
  8436. foreach ( $dayList as $key => $value ) {
  8437. $sinfo = $staff->getOne ( array (
  8438. 'select' => 'username,category',
  8439. 'where' => ' sid=' . $value ['staff'],
  8440. 'asArray' => true
  8441. ) );
  8442. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  8443. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  8444. $au = 0;
  8445. foreach ( $rplist as $k => $v ) {
  8446. if ($value ['staff'] == $v ['staff']) {
  8447. $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>';
  8448. $au += $v ['amount'];
  8449. }
  8450. }
  8451. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  8452. }
  8453. $data ['html'] = $html;
  8454. $data ['memu'] = "receipt";
  8455. $data ['staff'] = $this->staff;
  8456. $data ['receiptMemu'] = 'remittanceHky';
  8457. $data ['verifyId'] = $this->verifyId;
  8458. $data ['executeId'] = $this->executeId;
  8459. $this->render ( "/admin/remittancep", $data );
  8460. }
  8461. function ajaxGetReceiptDetails() {
  8462. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  8463. Doo::loadClass ( 'XDeode' );
  8464. $XDeode = new XDeode ( 5 );
  8465. $rid = $XDeode->decode ( $rid );
  8466. if (empty ( $rid )) {
  8467. echo json_encode ( array (
  8468. 'status' => 2,
  8469. 'msg' => 'illegal request'
  8470. ) );
  8471. die ();
  8472. }
  8473. Doo::loadModel ( 'receipt' );
  8474. $receipt = new receipt ();
  8475. Doo::loadModel ( 'staff' );
  8476. $staff = new staff ();
  8477. $rinfo = $receipt->getOne ( array (
  8478. 'where' => 'rid= ' . $rid,
  8479. 'asArray' => true
  8480. ) );
  8481. $sinfo = $staff->getOne ( array (
  8482. 'select' => 'username,category',
  8483. 'where' => ' sid=' . $rinfo ['staff'],
  8484. 'asArray' => true
  8485. ) );
  8486. $rinfo ['reviseDetail'] = array ();
  8487. if (! empty ( $rinfo ['reviseDetail'] ))
  8488. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  8489. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  8490. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  8491. $rinfo ['category'] = $sinfo ['category'];
  8492. $verifyStaff = array ();
  8493. if (! empty ( $rinfo ['verifyStaff'] ))
  8494. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  8495. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  8496. $rinfo ['relust'] = $relust;
  8497. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  8498. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  8499. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  8500. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  8501. // 费用执行人相关数据
  8502. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  8503. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  8504. foreach ( $executeCopy as $k => $v ) {
  8505. $executeCopy [$k] ['date'] = '';
  8506. $executeCopy [$k] ['opinion'] = '';
  8507. $executeCopy [$k] ['status'] = '';
  8508. if (! empty ( $executeStaff ))
  8509. foreach ( $executeStaff as $m => $u ) {
  8510. if ($v [0] == $m) {
  8511. $executeCopy [$k] ['date'] = $u ['date'];
  8512. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  8513. $executeCopy [$k] ['status'] = $u ['status'];
  8514. break;
  8515. }
  8516. }
  8517. }
  8518. $rinfo ['executeCopy'] = $executeCopy;
  8519. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8520. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8521. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8522. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8523. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8524. $html .= '<tr><th>' . $value ['name'] . '</th>
  8525. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8526. }
  8527. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8528. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8529. <tr><th class="taC" colspan="2">费用说明</th>
  8530. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8531. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8532. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8533. </tbody></table>';
  8534. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8535. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8536. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8537. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8538. $html .= '<tr><th>' . $value ['name'] . '</th>
  8539. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8540. }
  8541. $html .= '<tr><th class="taR">合计</th>
  8542. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8543. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8544. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8545. $html .= '<tr><th>' . $value ['name'] . '</th>
  8546. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8547. }
  8548. $html .= '<tr><th class="taR">合计</th>
  8549. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8550. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8551. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8552. $html .= '<tr><th>' . $value ['name'] . '</th>
  8553. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8554. }
  8555. $html .= '<tr><th class="taR">合计</th>
  8556. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8557. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8558. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8559. $html .= '<tr><th>' . $value ['name'] . '</th>
  8560. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8561. }
  8562. $html .= '<tr><th class="taR">合计</th>
  8563. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8564. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8565. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8566. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8567. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8568. }
  8569. $html .= '<tr><th class="taR">合计</th>
  8570. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8571. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8572. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8573. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8574. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8575. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8576. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8577. <tr';
  8578. if ($rinfo ['relust'] >= 0) {
  8579. $html .= 'class="success"';
  8580. } else {
  8581. $html .= 'class="error"';
  8582. }
  8583. $html .= '><td class="taR"><b>借款结余</b></td>
  8584. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8585. </tbody></table>
  8586. ';
  8587. }
  8588. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8589. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8590. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8591. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8592. $html .= '<tr><th>' . $value ['name'] . '</th>
  8593. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8594. }
  8595. $html .= '<tr><th class="taR">合计</th>
  8596. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8597. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8598. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8599. <tr><th class="taC" colspan="2">费用说明</th>
  8600. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8601. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8602. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8603. </tbody></table>';
  8604. } else {
  8605. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8606. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8607. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8608. $html .= '<tr><th>' . $value ['name'] . '</th>
  8609. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8610. }
  8611. $html .= '<tr><th class="taR">合计</th>
  8612. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8613. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8614. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8615. $html .= '<tr><th>' . $value ['name'] . '</th>
  8616. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8617. }
  8618. $html .= '<tr><th class="taR">合计</th>
  8619. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8620. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8621. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8622. $html .= '<tr><th>' . $value ['name'] . '</th>
  8623. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8624. }
  8625. $html .= '<tr><th class="taR">合计</th>
  8626. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8627. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8628. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8629. $html .= '<tr><th>' . $value ['name'] . '</th>
  8630. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8631. }
  8632. $html .= '<tr><th class="taR">合计</th>
  8633. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8634. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8635. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8636. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8637. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8638. }
  8639. $html .= '<tr><th class="taR">合计</th>
  8640. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8641. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8642. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8643. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8644. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8645. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8646. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8647. $html .= '</tbody></table>';
  8648. /*
  8649. * <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>
  8650. */
  8651. }
  8652. // print_r($verifyStaff);die;
  8653. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8654. foreach ( $verifyStaff as $key => $value ) {
  8655. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8656. $sinfo = $staff->getOne ( array (
  8657. 'select' => 'username',
  8658. 'where' => ' sid=' . $key,
  8659. 'asArray' => true
  8660. ) );
  8661. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8662. }
  8663. $html .= '</tbody></table>';
  8664. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8665. foreach ( $rinfo ['executeCopy'] as $value ) {
  8666. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8667. }
  8668. $html .= '</tbody></table>';
  8669. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8670. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8671. </tr></table>';
  8672. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8673. echo json_encode ( array (
  8674. 'status' => 1,
  8675. 'html' => $html
  8676. ) );
  8677. die ();
  8678. }
  8679. /**
  8680. * 删除附件
  8681. */
  8682. function ajaxRemEnclousur() {
  8683. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8684. if (empty ( $key ))
  8685. echo json_encode ( array (
  8686. 'status' => 2
  8687. ) );
  8688. Doo::loadModel ( 'enclosur' );
  8689. $enclosur = new enclosur ();
  8690. $enclosur->delEnclosurByEid ( $key );
  8691. echo json_encode ( array (
  8692. 'status' => 1
  8693. ) );
  8694. }
  8695. function remittance() {
  8696. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8697. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8698. Doo::loadModel ( 'receipt' );
  8699. $receipt = new receipt ();
  8700. Doo::loadModel ( 'staff' );
  8701. $staff = new staff ();
  8702. $dateCondition = " and Year(pastDate) =" . $year;
  8703. if (! empty ( $month ))
  8704. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8705. // get Receipt By verifyID status 1
  8706. $receiptList = $receipt->find ( array (
  8707. 'select' => 'sum(sum) as sum,staff,pastDate',
  8708. 'where' => ' status=1' . $dateCondition,
  8709. 'desc' => 'pastDate',
  8710. 'groupby' => 'staff,pastDate',
  8711. 'asArray' => true
  8712. ) );
  8713. $dateList = $receipt->find ( array (
  8714. 'select' => 'pastDate,verifyStaff',
  8715. 'where' => ' status=1' . $dateCondition,
  8716. 'desc' => 'pastDate',
  8717. 'groupby' => 'pastDate',
  8718. 'asArray' => true
  8719. ) );
  8720. $dataList = array ();
  8721. foreach ( $dateList as $d => $a ) {
  8722. $dataList [$a ['pastDate']] = array ();
  8723. $daySum = 0;
  8724. foreach ( $receiptList as $key => $value ) {
  8725. if ($a ['pastDate'] == $value ['pastDate']) {
  8726. $oderList = $receipt->find ( array (
  8727. 'select' => 'receiptOrder',
  8728. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8729. 'asArray' => true
  8730. ) );
  8731. $list = array ();
  8732. $html = "";
  8733. foreach ( $oderList as $v ) {
  8734. array_push ( $list, $v ['receiptOrder'] );
  8735. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8736. }
  8737. $receiptList [$key] ['receiptOrder'] = $html;
  8738. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8739. $sinfo = $staff->getOne ( array (
  8740. 'select' => 'username ',
  8741. 'where' => ' sid=' . $value ['staff'],
  8742. 'asArray' => true
  8743. ) );
  8744. $receiptList [$key] ['username'] = $sinfo ['username'];
  8745. $daySum += $value ['sum'];
  8746. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8747. }
  8748. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8749. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8750. }
  8751. }
  8752. // print_r($dataList);
  8753. $data ['dataList'] = $dataList;
  8754. $mothHtml = "";
  8755. for($i = 1; $i <= 12; $i ++) {
  8756. if ($month == $i)
  8757. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8758. else
  8759. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8760. }
  8761. $data ['year'] = $year;
  8762. $data ['mothHtml'] = $mothHtml;
  8763. $data ['memu'] = "receipt";
  8764. $data ['staff'] = $this->staff;
  8765. $data ['receiptMemu'] = 'approval';
  8766. $data ['verifyId'] = $this->verifyId;
  8767. $data ['executeId'] = $this->executeId;
  8768. $this->render ( "/admin/saeaReportListPay", $data );
  8769. }
  8770. /**
  8771. * 金额调整,提高稳定性
  8772. * @return string
  8773. */
  8774. function revocationAdjustment() {
  8775. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8776. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8777. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8778. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8779. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8780. Doo::loadClass ( 'XDeode' );
  8781. $XDeode = new XDeode ( 5 );
  8782. Doo::loadModel ( 'receipt' );
  8783. $receipt = new receipt ();
  8784. $sid = $XDeode->decode ( $sidKey );
  8785. $rid = $XDeode->decode ( $ridKey );
  8786. $reviseKey = $XDeode->decode ( $reviseKey );
  8787. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8788. die ( 'illegal request' );
  8789. $receiptDetail = $receipt->getOne ( array (
  8790. 'where' => 'rid=' . $rid,
  8791. 'asArray' => true
  8792. ) );
  8793. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8794. die ( 'illegal request' );
  8795. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8796. if (! isset ( $reviseDetail [$reviseKey] ))
  8797. die ( 'illegal request' );
  8798. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8799. unset ( $reviseDetail [$reviseKey] );
  8800. $revisePrice = 0;
  8801. foreach ( $reviseDetail as $key => $value ) {
  8802. $revisePrice += $value ['price'];
  8803. }
  8804. $reviseDetailString = json_encode ( $reviseDetail );
  8805. $receipt->reviseDetail = $reviseDetailString;
  8806. $receipt->sum = $receiptDetail ['sum'] - $price;
  8807. $receipt->revisePrice = $revisePrice;
  8808. $receipt->update ( array (
  8809. 'where' => 'rid=' . $rid
  8810. ) );
  8811. return '/receiptburEdi/' . $rid;
  8812. } else
  8813. die ( 'illegal request2' );
  8814. }
  8815. function updateApprovalReceipt() {
  8816. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8817. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8818. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8819. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8820. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8821. if (! empty ( $rid )) {
  8822. Doo::loadModel ( "verify" );
  8823. $verify = new verify ();
  8824. Doo::loadModel ( "receiptDetail" );
  8825. $receiptDetailObj = new receiptDetail ();
  8826. Doo::loadModel ( "itemStatistics" );
  8827. Doo::loadModel ( "statistics" );
  8828. $statistics = new statistics ();
  8829. $itemStatistics = new itemStatistics ();
  8830. Doo::loadModel ( "receipt" );
  8831. $receipt = new receipt ();
  8832. $receiptDetail = $receipt->getOne ( array (
  8833. 'where' => 'rid=' . $rid . ' and status=2 ',
  8834. 'asArray' => true
  8835. ) );
  8836. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8837. $nsflag = true;
  8838. foreach ( $nslist as $value ) {
  8839. if ($value == $this->staff ['0'] ['sid']) {
  8840. $nsflag = false;
  8841. break;
  8842. }
  8843. }
  8844. if (empty ( $receiptDetail ) || $nsflag)
  8845. return "/approvalExpenses/pendApproval";
  8846. $verifyDetail = $verify->getOne ( array (
  8847. 'where' => ' vid =' . $receiptDetail ['verify'],
  8848. 'asArray' => true
  8849. ) );
  8850. $verifyString = $verifyDetail ['staff'];
  8851. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8852. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8853. if (empty ( $opinion )) {
  8854. if ($status == 3)
  8855. $opinion = "终止";
  8856. else
  8857. $opinion = "同意支付";
  8858. }
  8859. $nowStaff = 0;
  8860. $nowStaffList = array ();
  8861. if (empty ( $verifyStaff )) {
  8862. // 还需加入是否已经进入角色审批
  8863. if ($verifyDetail [0] [1] == 'ROLE') {
  8864. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8865. foreach ( $vStaffString as $key => $value ) {
  8866. $staffK = explode ( "_", $value );
  8867. if ($staffK [0] != $this->staff [0] ['sid'])
  8868. array_push ( $nowStaffList, $staffK [0] );
  8869. }
  8870. // print_r($verifyDetail);
  8871. // die;
  8872. if (! empty ( $nowStaffList )) {
  8873. $nowStaff = implode ( ',', $nowStaffList );
  8874. $verifyStaff = array (
  8875. $this->staff [0] ['sid'] . "_R" => array (
  8876. 'date' => date ( 'Y-m-d' ),
  8877. 'opinion' => $opinion,
  8878. 'status' => $status,
  8879. 'nextStaff' => $verifyDetail [0] [0],
  8880. 'ROLE' => 1
  8881. )
  8882. );
  8883. } else {
  8884. $nowStaff = $verifyDetail [1] [0];
  8885. $verifyStaff = array (
  8886. $this->staff [0] ['sid'] . "_R" => array (
  8887. 'date' => date ( 'Y-m-d' ),
  8888. 'opinion' => $opinion,
  8889. 'status' => $status,
  8890. 'nextStaff' => $verifyDetail [1] [0]
  8891. )
  8892. );
  8893. }
  8894. } else {
  8895. if ($verifyDetail [1] [1] == 'ROLE') {
  8896. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8897. // echo "dd";
  8898. foreach ( $vStaffString as $key => $value ) {
  8899. $staffK = explode ( "_", $value );
  8900. array_push ( $nowStaffList, $staffK [0] );
  8901. }
  8902. $nowStaff = implode ( ',', $nowStaffList );
  8903. $verifyStaff = array (
  8904. $this->staff [0] ['sid'] => array (
  8905. 'date' => date ( 'Y-m-d' ),
  8906. 'opinion' => $opinion,
  8907. 'status' => $status,
  8908. 'nextStaff' => $verifyDetail [1] [0],
  8909. 'ROLE' => 1
  8910. )
  8911. );
  8912. } else {
  8913. $nowStaff = $verifyDetail [1] [0];
  8914. $verifyStaff = array (
  8915. $this->staff [0] ['sid'] => array (
  8916. 'date' => date ( 'Y-m-d' ),
  8917. 'opinion' => $opinion,
  8918. 'status' => $status,
  8919. 'nextStaff' => $verifyDetail [1] [0]
  8920. )
  8921. );
  8922. }
  8923. }
  8924. if ($status == 3)
  8925. $verifyStaff = array (
  8926. 'final' => $status,
  8927. $this->staff [0] ['sid'] => array (
  8928. 'date' => date ( 'Y-m-d' ),
  8929. 'opinion' => $opinion,
  8930. 'status' => $status
  8931. )
  8932. );
  8933. $vStaffString = json_encode ( $verifyStaff );
  8934. $receipt->nowStaff = $nowStaff;
  8935. $receipt->verifyStaff = $vStaffString;
  8936. } else {
  8937. $VS = end ( $verifyStaff );
  8938. // 非角色审批
  8939. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8940. $nextStaff = 0;
  8941. $roleSTF = false;
  8942. foreach ( $verifyDetail as $key => $value ) {
  8943. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8944. if (isset ( $verifyDetail [$key + 1] )) {
  8945. $nextStaff = $verifyDetail [$key + 1] [0];
  8946. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8947. $roleSTF = true;
  8948. }
  8949. break;
  8950. }
  8951. }
  8952. if (! $roleSTF) {
  8953. $nowStaff = $nextStaff;
  8954. $verifyStaff [$this->staff [0] ['sid']] = array (
  8955. 'date' => date ( 'Y-m-d' ),
  8956. 'opinion' => $opinion,
  8957. 'status' => $status,
  8958. 'nextStaff' => $nextStaff
  8959. );
  8960. } else {
  8961. // 获取角色下的所有用户ID
  8962. $nowStaffList = array ();
  8963. foreach ( $verifyDetail as $vfk ) {
  8964. if ($vfk [1] == 'ROLE') {
  8965. $vStaffString = json_decode ( $vfk [3] );
  8966. foreach ( $vStaffString as $key => $value ) {
  8967. $staffK = explode ( "_", $value );
  8968. array_push ( $nowStaffList, $staffK [0] );
  8969. }
  8970. }
  8971. }
  8972. $nowStaff = implode ( ',', $nowStaffList );
  8973. $verifyStaff [$this->staff [0] ['sid']] = array (
  8974. 'date' => date ( 'Y-m-d' ),
  8975. 'opinion' => $opinion,
  8976. 'status' => $status,
  8977. 'nextStaff' => $nextStaff,
  8978. 'ROLE' => 0
  8979. );
  8980. }
  8981. if ($status == 3) {
  8982. $verifyStaff ['final'] = $status;
  8983. $verifyStaff [$this->staff [0] ['sid']] = array (
  8984. 'date' => date ( 'Y-m-d' ),
  8985. 'opinion' => $opinion,
  8986. 'status' => $status
  8987. );
  8988. }
  8989. $vStaffString = json_encode ( $verifyStaff );
  8990. $receipt->nowStaff = $nowStaff;
  8991. $receipt->verifyStaff = $vStaffString;
  8992. }
  8993. // 角色审批
  8994. if (isset ( $VS ['ROLE'] )) {
  8995. // 找出角色人 当前审批角色组
  8996. $verifyJSStaff = array ();
  8997. $nowStaffList2 = array ();
  8998. foreach ( $verifyDetail as $key => $value ) {
  8999. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  9000. $verifyJSStaff = json_decode ( $value [3] );
  9001. foreach ( $verifyJSStaff as $m ) {
  9002. $staffK = explode ( "_", $m );
  9003. array_push ( $nowStaffList2, $staffK [0] );
  9004. }
  9005. // print_r($nowStaffList2);
  9006. }
  9007. }
  9008. $RoleVerifyStaff = array ();
  9009. foreach ( $verifyStaff as $key => $value ) {
  9010. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  9011. foreach ( $nowStaffList2 as $m ) {
  9012. if ($key == $m . "_R")
  9013. $RoleVerifyStaff [$key] = $value;
  9014. }
  9015. }
  9016. }
  9017. // print_r($verifyStaff);
  9018. // print_r($nowStaffList2);
  9019. // print_r($RoleVerifyStaff);
  9020. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  9021. // print_r($verifyJSStaff);
  9022. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  9023. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  9024. // 下一个审批人ID
  9025. $nextStaff = 0;
  9026. $falg = false;
  9027. foreach ( $verifyDetail as $key => $value ) {
  9028. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  9029. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  9030. $falg = true;
  9031. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  9032. $nowStaffList = array ();
  9033. foreach ( $vStaffString as $v ) {
  9034. $staffK = explode ( "_", $v );
  9035. array_push ( $nowStaffList, $staffK [0] );
  9036. }
  9037. $nowStaff = implode ( ',', $nowStaffList );
  9038. $nextStaff = $verifyDetail [$key + 1] [0];
  9039. } elseif (isset ( $verifyDetail [$key + 1] )) {
  9040. $nextStaff = $verifyDetail [$key + 1] [0];
  9041. $nowStaff = $nextStaff;
  9042. } else
  9043. $nowStaff = '';
  9044. break;
  9045. }
  9046. }
  9047. if ($falg)
  9048. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9049. 'date' => date ( 'Y-m-d' ),
  9050. 'opinion' => $opinion,
  9051. 'status' => $status,
  9052. 'nextStaff' => $nextStaff,
  9053. 'ROLE' => 1
  9054. );
  9055. else
  9056. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9057. 'date' => date ( 'Y-m-d' ),
  9058. 'opinion' => $opinion,
  9059. 'status' => $status,
  9060. 'nextStaff' => $nextStaff
  9061. );
  9062. // print_r($verifyStaff);
  9063. // echo $nowStaff;die;
  9064. } else { // 进入下一个角色或者审批人
  9065. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  9066. //
  9067. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  9068. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9069. 'date' => date ( 'Y-m-d' ),
  9070. 'opinion' => $opinion,
  9071. 'status' => $status,
  9072. 'nextStaff' => $VS ['nextStaff'],
  9073. 'ROLE' => 1
  9074. );
  9075. // print_r($verifyStaff);
  9076. // die;
  9077. }
  9078. if ($status == 3) {
  9079. $verifyStaff ['final'] = $status;
  9080. $verifyStaff [$this->staff [0] ['sid']] = array (
  9081. 'date' => date ( 'Y-m-d' ),
  9082. 'opinion' => $opinion,
  9083. 'status' => $status
  9084. );
  9085. }
  9086. $vStaffString = json_encode ( $verifyStaff );
  9087. $receipt->verifyStaff = $vStaffString;
  9088. $receipt->nowStaff = $nowStaff;
  9089. // die;
  9090. // }
  9091. // print_r($verifyStaff);
  9092. // die;
  9093. }
  9094. // print_r($verifyStaff);die;
  9095. }
  9096. // print_r($verifyDetail);
  9097. $roleKey = 0;
  9098. $roleId = 0;
  9099. $verifyDetailCopy = array ();
  9100. foreach ( $verifyDetail as $k => $v ) {
  9101. if ($v [1] == 'ROLE') {
  9102. $roleId = $v [0];
  9103. $roleVerify = json_decode ( $v [3], true );
  9104. $roleKey = $k;
  9105. $roleArray = array ();
  9106. foreach ( $roleVerify as $o => $p ) {
  9107. $staffID = explode ( '_', $p );
  9108. $exp = array (
  9109. 0 => $staffID [0],
  9110. 1 => $staffID [1]
  9111. );
  9112. array_push ( $roleArray, $exp );
  9113. }
  9114. $verifyDetailCopy [$v [0]] = $roleArray;
  9115. }
  9116. }
  9117. // print_r($verifyDetail);
  9118. foreach ( $verifyDetailCopy as $k => $v ) {
  9119. foreach ( $verifyDetail as $m => $n ) {
  9120. if ($n [0] == $k) {
  9121. array_splice ( $verifyDetail, $m, 1, $v );
  9122. }
  9123. }
  9124. }
  9125. // die;
  9126. // if (!empty($roleArray))
  9127. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  9128. // echo $roleId;
  9129. // print_r($verifyStaff);
  9130. // print_r($verifyDetail);
  9131. // die;
  9132. Doo::loadModel ( "receiptLog" );
  9133. $receiptLog = new receiptLog ();
  9134. // 审批日志
  9135. if (! isset ( $verifyStaff ['final'] )) {
  9136. if (! empty ( $roleId )) {
  9137. Doo::loadModel ( "role" );
  9138. $role = new role ();
  9139. $roleInfo = $role->getOne ( array (
  9140. 'where' => 'rid=' . $roleId,
  9141. 'asArray' => true
  9142. ) );
  9143. $receiptLog->rolename = $roleInfo ['name'];
  9144. }
  9145. $receiptLog->username = $this->staff [0] ['username'];
  9146. $receiptLog->uid = $this->staff [0] ['sid'];
  9147. $receiptLog->date = date ( "Y-m-d" );
  9148. $receiptLog->opinion = $opinion;
  9149. $receiptLog->img = $this->staff [0] ['avatar'];
  9150. $receiptLog->status = 1;
  9151. $receiptLog->rid = $rid;
  9152. $receiptLog->insert ();
  9153. }
  9154. if (isset ( $verifyStaff ['final'] )) { // rDetail
  9155. $receipt->verifyBreakup = $verifyString;
  9156. $receipt->status = 3;
  9157. $receiptDetailObj->status = 3;
  9158. $receiptDetailObj->update ( array (
  9159. 'where' => 'rid=' . $rid
  9160. ) );
  9161. if (! empty ( $roleId )) {
  9162. Doo::loadModel ( "role" );
  9163. $role = new role ();
  9164. $roleInfo = $role->getOne ( array (
  9165. 'where' => 'rid=' . $roleId,
  9166. 'asArray' => true
  9167. ) );
  9168. $receiptLog->rolename = $roleInfo ['name'];
  9169. }
  9170. $receiptLog->username = $this->staff [0] ['username'];
  9171. $receiptLog->uid = $this->staff [0] ['sid'];
  9172. $receiptLog->date = date ( "Y-m-d" );
  9173. $receiptLog->opinion = $opinion;
  9174. $receiptLog->img = $this->staff [0] ['avatar'];
  9175. $receiptLog->status = 3;
  9176. $receiptLog->rid = $rid;
  9177. $receiptLog->insert ();
  9178. //删除行程单
  9179. Doo::loadModel ( 'itinerary' );
  9180. $itinerary = new itinerary ();
  9181. $itinerary->delete ( array (
  9182. 'where' => 'rid="' . $rid . '"'
  9183. ) );
  9184. // 微信企业号通知
  9185. $this->setWXMsg ( $rid, 3 );
  9186. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  9187. $receipt->status = 1;
  9188. $reviseSum = 0;
  9189. $receipt->verifyBreakup = $verifyString;
  9190. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  9191. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9192. foreach ( $reviseDetail as $key => $value ) {
  9193. $receiptDetailObj = new receiptDetail ();
  9194. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9195. $receiptDetailObj->item = $value ['description'];
  9196. $receiptDetailObj->itemCategory = "报销金额调整";
  9197. $receiptDetailObj->price = $value ['price'];
  9198. $receiptDetailObj->date = $receiptDetail ['date'];
  9199. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  9200. $receiptDetailObj->rid = $rid;
  9201. $receiptDetailObj->status = 1;
  9202. $receiptDetailObj->insert ();
  9203. $reviseSum += $value ['price'];
  9204. }
  9205. $itemStatistics = new itemStatistics ();
  9206. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  9207. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9208. $itemStatistics->price = $reviseSum;
  9209. $itemStatistics->itemCategory = "报销金额调整";
  9210. $itemStatistics->date = $receiptDetail ['date'];
  9211. $itemStatistics->insert ();
  9212. }
  9213. $receiptDetailObj = new receiptDetail ();
  9214. $receiptDetailObj->status = 1;
  9215. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  9216. $receiptDetailObj->update ( array (
  9217. 'where' => 'rid=' . $rid
  9218. ) );
  9219. $dateArray = explode ( "-", $receiptDetail ['date'] );
  9220. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  9221. $stat = $statistics->getOne ( array (
  9222. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  9223. 'asArray' => true
  9224. ) );
  9225. if (empty ( $stat )) {
  9226. $statistics->date = $receiptDetail ['date'];
  9227. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  9228. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9229. $statistics->agPrice = $receiptDetail ['sum'];
  9230. $statistics->rePrice = $reviseSum;
  9231. $statistics->insert ();
  9232. } else {
  9233. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  9234. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  9235. $statistics->update ( array (
  9236. 'where' => 'sid=' . $stat ['sid']
  9237. ) );
  9238. }
  9239. $dateArray = explode ( "-", $receiptDetail ['date'] );
  9240. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  9241. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  9242. foreach ( $accountItem ['cSum'] as $key => $value ) {
  9243. if ($key == "agencySum") {
  9244. $iStatistics = $itemStatistics->getOne ( array (
  9245. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  9246. 'asArray' => true
  9247. ) );
  9248. if (empty ( $iStatistics )) {
  9249. $itemStatistics->cid = $receiptDetail ['cid'];
  9250. ;
  9251. $itemStatistics->staff = $receiptDetail ['staff'];
  9252. $itemStatistics->price = $value;
  9253. $itemStatistics->itemCategory = $this->AGENCY;
  9254. $itemStatistics->date = $receiptDetail ['date'];
  9255. $itemStatistics->insert ();
  9256. } else {
  9257. if (! empty ( $value )) {
  9258. $itemStatistics->price = $value + $iStatistics ['price'];
  9259. $itemStatistics->update ( array (
  9260. 'where' => 'sid=' . $iStatistics ['sid']
  9261. ) );
  9262. }
  9263. }
  9264. } elseif ($key == "travelSum") {
  9265. $iStatistics = $itemStatistics->getOne ( array (
  9266. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  9267. 'asArray' => true
  9268. ) );
  9269. if (empty ( $iStatistics )) {
  9270. $itemStatistics->cid = $receiptDetail ['cid'];
  9271. $itemStatistics->staff = $receiptDetail ['staff'];
  9272. $itemStatistics->price = $value;
  9273. $itemStatistics->itemCategory = $this->TRAVEL;
  9274. $itemStatistics->date = $receiptDetail ['date'];
  9275. $itemStatistics->insert ();
  9276. } else {
  9277. if (! empty ( $value )) {
  9278. $itemStatistics->price = $value + $iStatistics ['price'];
  9279. $itemStatistics->update ( array (
  9280. 'where' => 'sid=' . $iStatistics ['sid']
  9281. ) );
  9282. }
  9283. }
  9284. } elseif ($key == "trainSum") {
  9285. $iStatistics = $itemStatistics->getOne ( array (
  9286. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  9287. 'asArray' => true
  9288. ) );
  9289. if (empty ( $iStatistics )) {
  9290. $itemStatistics->cid = $receiptDetail ['cid'];
  9291. $itemStatistics->staff = $receiptDetail ['staff'];
  9292. $itemStatistics->price = $value;
  9293. $itemStatistics->itemCategory = $this->TRAIN;
  9294. $itemStatistics->date = $receiptDetail ['date'];
  9295. $itemStatistics->insert ();
  9296. } else {
  9297. if (! empty ( $value )) {
  9298. $itemStatistics->price = $value + $iStatistics ['price'];
  9299. $itemStatistics->update ( array (
  9300. 'where' => 'sid=' . $iStatistics ['sid']
  9301. ) );
  9302. }
  9303. }
  9304. } elseif ($key == "otherSum") {
  9305. $iStatistics = $itemStatistics->getOne ( array (
  9306. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  9307. 'asArray' => true
  9308. ) );
  9309. if (empty ( $iStatistics )) {
  9310. $itemStatistics->cid = $receiptDetail ['cid'];
  9311. $itemStatistics->staff = $receiptDetail ['staff'];
  9312. $itemStatistics->price = $value;
  9313. $itemStatistics->itemCategory = $this->OTHER;
  9314. $itemStatistics->date = $receiptDetail ['date'];
  9315. $itemStatistics->insert ();
  9316. } else {
  9317. if (! empty ( $value )) {
  9318. $itemStatistics->price = $value + $iStatistics ['price'];
  9319. $itemStatistics->update ( array (
  9320. 'where' => 'sid=' . $iStatistics ['sid']
  9321. ) );
  9322. }
  9323. }
  9324. }
  9325. }
  9326. $receipt->pastDate = date ( "Y-m-d" );
  9327. // 微信企业号通知
  9328. $this->setWXMsg ( $rid, 1 );
  9329. }
  9330. //是否有流水
  9331. Doo::loadModel ( 'wasteBook' );
  9332. $wasteBook = new wasteBook ();
  9333. $accountType=3;
  9334. if ($receiptDetail['Rtype']==1){
  9335. $accountType=2;
  9336. }elseif($receiptDetail['Rtype']==2){
  9337. $accountType=4;
  9338. }
  9339. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  9340. if (empty($wbDetail)){
  9341. $rsum=$receiptDetail['sum']-$receiptDetail['loanSum'];
  9342. $receipt->amount = $rsum;//$amount;
  9343. }
  9344. $receipt->update ( array (
  9345. 'where' => ' rid = ' . $rid
  9346. ) );
  9347. // 进入下一条审批费用新加需求
  9348. $vidList = array ();
  9349. $verifyDetail = $verify->find ( array (
  9350. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  9351. 'asArray' => true
  9352. ) );
  9353. foreach ( $verifyDetail as $key => $value ) {
  9354. array_push ( $vidList, $value ['vid'] );
  9355. }
  9356. $vid = implode ( ",", $vidList );
  9357. if (empty ( $verifyDetail ))
  9358. $vid = 0;
  9359. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  9360. $receipt = new receipt ();
  9361. $rd = $receipt->getOne ( array (
  9362. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  9363. 'asc' => 'rid',
  9364. 'asArray' => true
  9365. ) );
  9366. if (empty ( $rd )) {
  9367. return '/approvalExpenses/pendApproval';
  9368. }
  9369. if ($rd ['Rtype'] == 1) {
  9370. if ($rd ['isBK'] == 1) {
  9371. return '/receiptburEdi/' . $rd ['rid'];
  9372. } else {
  9373. return '/expensesEdi/' . $rd ['rid'];
  9374. }
  9375. } elseif ($rd ['Rtype'] == 2) {
  9376. return '/remitApproval/' . $rd ['rid'];
  9377. } else {
  9378. return '/receiptburEdi/' . $rd ['rid'];
  9379. }
  9380. // return "/approvalExpenses/pendApproval";
  9381. }
  9382. }
  9383. function expensesRetreats() {
  9384. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  9385. if (! empty ( $rid )) {
  9386. // 操作记录
  9387. Doo::loadModel ( "receipt" );
  9388. $receipt = new receipt ();
  9389. Doo::loadModel ( "receiptLog" );
  9390. $receiptLog = new receiptLog ();
  9391. Doo::loadModel ( "verify" );
  9392. $verify = new verify ();
  9393. $receiptInfo = $receipt->getOne ( array (
  9394. 'where' => 'rid=' . $rid,
  9395. 'asArray' => true
  9396. ) );
  9397. $vr = $verify->getOne ( array (
  9398. 'where' => 'vid=' . $receiptInfo ['verify'],
  9399. 'asArray' => true
  9400. ) );
  9401. $jd = json_decode ( $vr ['staff'] );
  9402. $roleId = 0;
  9403. foreach ( $jd as $key => $value ) {
  9404. if ($value [1] == 'ROLE') {
  9405. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9406. if ($pos !== false) {
  9407. $roleId = $value [0];
  9408. }
  9409. }
  9410. }
  9411. // 审批日志
  9412. // echo $roleId;die;
  9413. if (! empty ( $roleId )) {
  9414. Doo::loadModel ( "role" );
  9415. $role = new role ();
  9416. $roleInfo = $role->getOne ( array (
  9417. 'where' => 'rid=' . $roleId,
  9418. 'asArray' => true
  9419. ) );
  9420. $receiptLog->rolename = $roleInfo ['name'];
  9421. }
  9422. $receiptLog->username = $this->staff [0] ['username'];
  9423. $receiptLog->uid = $this->staff [0] ['sid'];
  9424. $receiptLog->date = date ( "Y-m-d" );
  9425. $receiptLog->opinion = '撤回';
  9426. $receiptLog->img = $this->staff [0] ['avatar'];
  9427. $receiptLog->status = 4;
  9428. $receiptLog->rid = $rid;
  9429. $receiptLog->insert ();
  9430. $receipt->status = 4;
  9431. $receipt->update ( array (
  9432. 'where' => 'rid=' . $rid
  9433. ) );
  9434. // 微信企业号通知
  9435. $this->setWXMsg ( $rid, 2 );
  9436. }
  9437. // echo "ddd";
  9438. return '/approvalExpenses/pendApproval';
  9439. }
  9440. function updateCheReceipt() {
  9441. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9442. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  9443. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  9444. if (! empty ( $rid )) {
  9445. // 操作记录
  9446. Doo::loadModel ( "receipt" );
  9447. $receipt = new receipt ();
  9448. Doo::loadModel ( "receiptLog" );
  9449. $receiptLog = new receiptLog ();
  9450. Doo::loadModel ( "verify" );
  9451. $verify = new verify ();
  9452. $receiptInfo = $receipt->getOne ( array (
  9453. 'where' => 'rid=' . $rid . ' and status=2',
  9454. 'asArray' => true
  9455. ) );
  9456. if (empty ( $receiptInfo )) {
  9457. echo json_encode ( array (
  9458. 'status' => 2
  9459. ) );
  9460. die ();
  9461. }
  9462. $vr = $verify->getOne ( array (
  9463. 'where' => 'vid=' . $receiptInfo ['verify'],
  9464. 'asArray' => true
  9465. ) );
  9466. $jd = json_decode ( $vr ['staff'] );
  9467. $roleId = 0;
  9468. foreach ( $jd as $key => $value ) {
  9469. if ($value [1] == 'ROLE') {
  9470. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9471. if ($pos !== false) {
  9472. $roleId = $value [0];
  9473. }
  9474. }
  9475. }
  9476. // 审批日志
  9477. // echo $roleId;die;
  9478. if (! empty ( $roleId )) {
  9479. Doo::loadModel ( "role" );
  9480. $role = new role ();
  9481. $roleInfo = $role->getOne ( array (
  9482. 'where' => 'rid=' . $roleId,
  9483. 'asArray' => true
  9484. ) );
  9485. $receiptLog->rolename = $roleInfo ['name'];
  9486. }
  9487. $receiptLog->username = $this->staff [0] ['username'];
  9488. $receiptLog->uid = $this->staff [0] ['sid'];
  9489. $receiptLog->date = date ( "Y-m-d" );
  9490. $receiptLog->opinion = $opinion;
  9491. $receiptLog->img = $this->staff [0] ['avatar'];
  9492. $receiptLog->status = 4;
  9493. $receiptLog->rid = $rid;
  9494. $receiptLog->insert ();
  9495. $receipt->status = 4;
  9496. $receipt->update ( array (
  9497. 'where' => 'rid=' . $rid
  9498. ) );
  9499. // 微信企业号通知
  9500. $this->setWXMsg ( $rid, 2 );
  9501. echo json_encode ( array (
  9502. 'status' => 1
  9503. ) );
  9504. // Header("HTTP/1.1 303 See Other");
  9505. // Header("Location: /approvalExpenses/pendApproval");
  9506. die ();
  9507. }
  9508. echo json_encode ( array (
  9509. 'status' => 2
  9510. ) );
  9511. die ();
  9512. // echo "ddd";
  9513. // return '/saeaBorad';
  9514. }
  9515. function revisePrice() {
  9516. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  9517. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  9518. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9519. // echo $price;die;
  9520. if (! empty ( $rid )) {
  9521. Doo::loadModel ( "receipt" );
  9522. $receipt = new receipt ();
  9523. $receiptDetail = $receipt->getOne ( array (
  9524. 'where' => 'rid=' . $rid . ' and status=2 ',
  9525. 'asArray' => true
  9526. ) );
  9527. if (empty ( $receiptDetail ))
  9528. die ( 'illegal request' );
  9529. $reviseDetail = array ();
  9530. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9531. array_push ( $reviseDetail, array (
  9532. 'sid' => $this->staff [0] ['sid'],
  9533. 'name' => $this->staff [0] ['username'],
  9534. 'description' => $description,
  9535. 'price' => $price
  9536. ) );
  9537. $reviseDetailString = json_encode ( $reviseDetail );
  9538. $receipt->reviseDetail = $reviseDetailString;
  9539. $receipt->revisePrice = $price;
  9540. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9541. } else {
  9542. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9543. array_push ( $reviseDetail, array (
  9544. 'sid' => $this->staff [0] ['sid'],
  9545. 'name' => $this->staff [0] ['username'],
  9546. 'description' => $description,
  9547. 'price' => $price
  9548. ) );
  9549. $reviseDetailString = json_encode ( $reviseDetail );
  9550. $receipt->reviseDetail = $reviseDetailString;
  9551. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9552. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9553. }
  9554. $receipt->update ( array (
  9555. 'where' => 'rid=' . $rid
  9556. ) );
  9557. if ($receiptDetail ['Rtype'] == 1) {
  9558. if ($receiptDetail ['isBK'] == 1) {
  9559. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9560. }
  9561. } elseif ($receiptDetail ['Rtype'] == 2) {
  9562. } else {
  9563. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9564. }
  9565. }
  9566. die ( 'illegal request' );
  9567. }
  9568. function personalCollect() {
  9569. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9570. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9571. $this->showCache ( $path );
  9572. Doo::loadModel ( "receiptDetail" );
  9573. Doo::loadModel ( "itemStatistics" );
  9574. Doo::loadModel ( 'statistics' );
  9575. $statistics = new statistics ();
  9576. $itemStatistics = new itemStatistics ();
  9577. $receiptDetail = new receiptDetail ();
  9578. $receiptCollectList = $receiptDetail->find ( array (
  9579. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9580. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9581. 'groupby' => 'itemCategory,Month(date)',
  9582. 'asArray' => true
  9583. ) );
  9584. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9585. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9586. 'asArray' => true
  9587. ) );
  9588. // create collect html
  9589. $collectArray = array (
  9590. '日常相关费用' => array (),
  9591. '差旅相关费用' => array (),
  9592. '培训班费用' => array (),
  9593. '其他' => array ()
  9594. );
  9595. $adjustment = array ();
  9596. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9597. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9598. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9599. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9600. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9601. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9602. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9603. array_push ( $collectArray ['其他'], $collectHtml );
  9604. $data ['collectArray'] = $collectArray;
  9605. // statistics html
  9606. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9607. if (empty ( $stList ))
  9608. $stList = array (
  9609. 'rePrice' => 0,
  9610. 'agPrice' => 0
  9611. );
  9612. $data ['stList'] = array (
  9613. 'rePrice' => $stList ['rePrice'],
  9614. 'agPrice' => $stList ['agPrice'],
  9615. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9616. );
  9617. // Adjustment price html
  9618. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9619. array_push ( $adjustment, $collectHtml );
  9620. $data ['adjustment'] = $adjustment;
  9621. // total price html
  9622. $collectHtml = "";
  9623. $total = 0;
  9624. for($i = 1; $i <= 12; $i ++) {
  9625. $sumPrice = 0;
  9626. foreach ( $receiptCollectList as $key => $value ) {
  9627. if ($value ['month'] == $i) {
  9628. $sumPrice += $value ['price'];
  9629. }
  9630. }
  9631. if ($sumPrice == 0)
  9632. $collectHtml .= '<td class="taR">-</td>';
  9633. else
  9634. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9635. $total += $sumPrice;
  9636. }
  9637. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9638. $data ['totalPrice'] = $collectHtml;
  9639. $dateHtml = "";
  9640. $now = date ( "Y" );
  9641. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9642. if ($YEARD <= $now) {
  9643. $dateHtml .= '<option ';
  9644. if ($year == $YEARD) {
  9645. $dateHtml .= 'selected ';
  9646. }
  9647. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9648. }
  9649. }
  9650. $data ['dateHtml'] = $dateHtml;
  9651. $data ['year'] = $year;
  9652. $data ['totalYear'] = $total;
  9653. $data ['memu'] = "receipt";
  9654. $data ['staff'] = $this->staff;
  9655. $data ['receiptMemu'] = 'personalCollect';
  9656. $data ['verifyId'] = $this->verifyId;
  9657. $data ['executeId'] = $this->executeId;
  9658. // year staff status 2,4
  9659. if ($year < date ( "Y" )) {
  9660. Doo::loadModel ( 'receipt' );
  9661. $receipt = new receipt ();
  9662. $receiptList = $receipt->find ( array (
  9663. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9664. 'asArray' => true
  9665. ) );
  9666. if (empty ( $receiptList )) {
  9667. ob_start ();
  9668. $this->render ( "/admin/saea_slist_collect", $data );
  9669. $this->cacheFile ( $path );
  9670. die ();
  9671. }
  9672. }
  9673. $this->render ( "/admin/saea_slist_collect", $data );
  9674. }
  9675. function personalCollectDetail() {
  9676. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9677. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9678. $this->showCache ( $path );
  9679. Doo::loadModel ( "receiptDetail" );
  9680. Doo::loadModel ( "itemStatistics" );
  9681. Doo::loadModel ( 'statistics' );
  9682. Doo::loadModel ( 'accountItem' );
  9683. $accountItem = new accountItem ();
  9684. $statistics = new statistics ();
  9685. $itemStatistics = new itemStatistics ();
  9686. $receiptDetail = new receiptDetail ();
  9687. $receiptCollectList = $receiptDetail->find ( array (
  9688. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9689. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9690. 'groupby' => 'item,Month(date)',
  9691. 'asArray' => true
  9692. ) );
  9693. $accountList = $accountItem->find ( array (
  9694. 'asArray' => true
  9695. ) );
  9696. // create CollectDetail HTML
  9697. $collectHtml = array ();
  9698. foreach ( $accountList as $key => $value ) {
  9699. $html = "";
  9700. $asum = 0;
  9701. for($i = 1; $i <= 12; $i ++) {
  9702. $falg = true;
  9703. foreach ( $receiptCollectList as $v ) {
  9704. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9705. $asum += $v ['price'];
  9706. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9707. $falg = false;
  9708. break;
  9709. }
  9710. }
  9711. if ($falg)
  9712. $html .= '<td class="taR">-</td>';
  9713. }
  9714. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9715. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9716. }
  9717. $data ['collectHtml'] = $collectHtml;
  9718. // create Adjustment price html
  9719. $receiptCollectList = $receiptDetail->find ( array (
  9720. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9721. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9722. 'groupby' => 'itemCategory,Month(date)',
  9723. 'asArray' => true
  9724. ) );
  9725. $adjustment = array ();
  9726. $collectArray = array (
  9727. '日常相关费用' => array (),
  9728. '差旅相关费用' => array (),
  9729. '培训班费用' => array (),
  9730. '其他' => array ()
  9731. );
  9732. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9733. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9734. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9735. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9736. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9737. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9738. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9739. array_push ( $collectArray ['其他'], $collectHtml );
  9740. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9741. array_push ( $adjustment, $collectHtml );
  9742. // total price html
  9743. $collectHtml = "";
  9744. $total = 0;
  9745. for($i = 1; $i <= 12; $i ++) {
  9746. $sumPrice = 0;
  9747. foreach ( $receiptCollectList as $key => $value ) {
  9748. if ($value ['month'] == $i) {
  9749. $sumPrice += $value ['price'];
  9750. }
  9751. }
  9752. if ($sumPrice == 0)
  9753. $collectHtml .= '<td class="taR">-</td>';
  9754. else
  9755. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9756. $total += $sumPrice;
  9757. }
  9758. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9759. // statistics html
  9760. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9761. if (empty ( $stList ))
  9762. $stList = array (
  9763. 'rePrice' => 0,
  9764. 'agPrice' => 0
  9765. );
  9766. $data ['stList'] = array (
  9767. 'rePrice' => $stList ['rePrice'],
  9768. 'agPrice' => $stList ['agPrice'],
  9769. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9770. );
  9771. $data ['collectArray'] = $collectArray;
  9772. $data ['adjustment'] = $adjustment;
  9773. $data ['totalPrice'] = $collectHtml;
  9774. $data ['totalYear'] = $total;
  9775. $data ['year'] = $year;
  9776. $dateHtml = "";
  9777. $now = date ( "Y" );
  9778. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9779. if ($YEARD <= $now) {
  9780. $dateHtml .= '<option ';
  9781. if ($year == $YEARD) {
  9782. $dateHtml .= 'selected ';
  9783. }
  9784. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9785. }
  9786. }
  9787. $data ['dateHtml'] = $dateHtml;
  9788. $data ['memu'] = "receipt";
  9789. $data ['staff'] = $this->staff;
  9790. $data ['receiptMemu'] = 'personalCollect';
  9791. $data ['verifyId'] = $this->verifyId;
  9792. $data ['executeId'] = $this->executeId;
  9793. // year staff status 2,4
  9794. if ($year < date ( "Y" )) {
  9795. Doo::loadModel ( 'receipt' );
  9796. $receipt = new receipt ();
  9797. $receiptList = $receipt->find ( array (
  9798. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9799. 'asArray' => true
  9800. ) );
  9801. if (empty ( $receiptList )) {
  9802. ob_start ();
  9803. $this->render ( "/admin/saeaCollectArticles", $data );
  9804. $this->cacheFile ( $path );
  9805. die ();
  9806. }
  9807. }
  9808. $this->render ( "/admin/saeaCollectArticles", $data );
  9809. }
  9810. function companyCategoryCollect() {
  9811. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9812. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9813. $this->showCache ( $path );
  9814. Doo::loadModel ( 'L_category' );
  9815. Doo::loadModel ( 'itemStatistics' );
  9816. Doo::loadModel ( 'statistics' );
  9817. $statistics = new statistics ();
  9818. $Lcategory = new L_category ();
  9819. $itemStatistics = new itemStatistics ();
  9820. Doo::loadModel ( "receiptAuthorityManage" );
  9821. $receiptAuthorityManage = new receiptAuthorityManage ();
  9822. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9823. $cidList = array ();
  9824. foreach ( $imcStaff as $key => $value ) {
  9825. array_push ( $cidList, $value ['cid'] );
  9826. }
  9827. $cidString = implode ( ',', $cidList );
  9828. $LcategoryList = $Lcategory->find ( array (
  9829. 'where' => ' cid in (' . $cidString . ')',
  9830. 'asArray' => true
  9831. ) ); // 'staff='.$this->staff[0]['sid']." and
  9832. $itemStatisticsList = $itemStatistics->find ( array (
  9833. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9834. 'where' => " Year(date)=" . $year,
  9835. 'groupby' => 'cid,Month(date)',
  9836. 'asArray' => true
  9837. ) );
  9838. // ceatre companyCollectHtml
  9839. foreach ( $LcategoryList as $value ) {
  9840. $html = "";
  9841. $asum = 0;
  9842. for($i = 1; $i <= 12; $i ++) {
  9843. $falg = true;
  9844. foreach ( $itemStatisticsList as $v ) {
  9845. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9846. $asum += $v ['price'];
  9847. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9848. $falg = false;
  9849. break;
  9850. }
  9851. }
  9852. if ($falg)
  9853. $html .= '<td class="taR">-</td>';
  9854. }
  9855. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9856. $collectHtml [$value ['title']] = array (
  9857. 'html' => $html,
  9858. 'cid' => $value ['cid']
  9859. );
  9860. }
  9861. $data ['companyHtml'] = $collectHtml;
  9862. // total price html
  9863. $collectHtml = "";
  9864. $total = 0;
  9865. for($i = 1; $i <= 12; $i ++) {
  9866. $sumPrice = 0;
  9867. foreach ( $itemStatisticsList as $key => $value ) {
  9868. if ($value ['month'] == $i) {
  9869. $sumPrice += $value ['price'];
  9870. }
  9871. }
  9872. if ($sumPrice == 0)
  9873. $collectHtml .= '<td class="taR">-</td>';
  9874. else
  9875. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9876. $total += $sumPrice;
  9877. }
  9878. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9879. $data ['companyTotalHtml'] = $collectHtml;
  9880. $data ['total'] = $total;
  9881. // statistics html
  9882. // echo $cidString;
  9883. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9884. if (empty ( $stList ))
  9885. $stList = array (
  9886. 'rePrice' => 0,
  9887. 'agPrice' => 0
  9888. );
  9889. $data ['stList'] = array (
  9890. 'rePrice' => $stList ['rePrice'],
  9891. 'agPrice' => $stList ['agPrice'],
  9892. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9893. );
  9894. $data ['year'] = $year;
  9895. $data ['memu'] = "receipt";
  9896. $data ['staff'] = $this->staff;
  9897. $data ['receiptMemu'] = 'companyCategoryCollect';
  9898. $data ['verifyId'] = $this->verifyId;
  9899. $data ['executeId'] = $this->executeId;
  9900. $dateHtml = "";
  9901. $now = date ( "Y" );
  9902. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9903. if ($YEARD <= $now) {
  9904. $dateHtml .= '<option ';
  9905. if ($year == $YEARD) {
  9906. $dateHtml .= 'selected ';
  9907. }
  9908. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9909. }
  9910. }
  9911. $data ['dateHtml'] = $dateHtml;
  9912. // year staff status 2,4
  9913. if ($year < date ( "Y" )) {
  9914. Doo::loadModel ( 'receipt' );
  9915. $receipt = new receipt ();
  9916. $receiptList = $receipt->find ( array (
  9917. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9918. 'asArray' => true
  9919. ) );
  9920. if (empty ( $receiptList )) {
  9921. ob_start ();
  9922. $this->render ( "/admin/saeaCompanyCollect", $data );
  9923. $this->cacheFile ( $path );
  9924. die ();
  9925. }
  9926. }
  9927. $this->render ( "/admin/saeaCompanyCollect", $data );
  9928. }
  9929. function categoryCollectDetail() {
  9930. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9931. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9932. /* $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9933. $this->showCache ( $path ); */
  9934. Doo::loadModel ( 'statistics' );
  9935. $statistics = new statistics ();
  9936. Doo::loadModel ( "receiptDetail" );
  9937. $receiptDetail = new receiptDetail ();
  9938. Doo::loadModel ( 'L_category' );
  9939. $Lcategory = new L_category ();
  9940. Doo::loadModel ( 'accountItem' );
  9941. $accountItem = new accountItem ();
  9942. Doo::loadModel ( "receiptAuthorityManage" );
  9943. $receiptAuthorityManage = new receiptAuthorityManage ();
  9944. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9945. $cidList = array ();
  9946. foreach ( $imcStaff as $key => $value ) {
  9947. array_push ( $cidList, $value ['cid'] );
  9948. }
  9949. $cidString = implode ( ',', $cidList );
  9950. $LcategoryList = $Lcategory->find ( array (
  9951. 'where' => 'cid in (' . $cidString . ')',
  9952. 'asArray' => true
  9953. ) );
  9954. if ($cid == 0) {
  9955. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  9956. if ($cid == 0)
  9957. $cid = $LcategoryList [0] ['cid'];
  9958. }
  9959. $data ['LcategoryList'] = $LcategoryList;
  9960. $receiptCollectList = $receiptDetail->find ( array (
  9961. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  9962. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9963. 'groupby' => 'item,Month(pastDate)',
  9964. 'asArray' => true
  9965. ) );
  9966. $accountList = $accountItem->find ( array (
  9967. 'asArray' => true
  9968. ) );
  9969. // create CollectDetail HTML
  9970. $collectHtml = array ();
  9971. foreach ( $accountList as $key => $value ) {
  9972. $html = "";
  9973. $asum = 0;
  9974. for($i = 1; $i <= 12; $i ++) {
  9975. $falg = true;
  9976. foreach ( $receiptCollectList as $v ) {
  9977. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9978. $asum += $v ['price'];
  9979. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9980. $falg = false;
  9981. break;
  9982. }
  9983. }
  9984. if ($falg)
  9985. $html .= '<td class="taR">-</td>';
  9986. }
  9987. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9988. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9989. }
  9990. $data ['collectHtml'] = $collectHtml;
  9991. // create Adjustment price html
  9992. $receiptCollectList = $receiptDetail->find ( array (
  9993. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  9994. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  9995. 'groupby' => 'itemCategory,Month(pastDate)',
  9996. 'asArray' => true
  9997. ) );
  9998. $adjustment = array ();
  9999. $collectArray = array (
  10000. '日常相关费用' => array (),
  10001. '差旅相关费用' => array (),
  10002. '培训班费用' => array (),
  10003. '内部培训费用'=>array(),
  10004. '其他' => array ()
  10005. );
  10006. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  10007. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  10008. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  10009. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  10010. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  10011. array_push ( $collectArray ['培训班费用'], $collectHtml );
  10012. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  10013. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  10014. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  10015. array_push ( $collectArray ['其他'], $collectHtml );
  10016. $data ['collectArray'] = $collectArray;
  10017. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  10018. array_push ( $adjustment, $collectHtml );
  10019. $data ['adjustment'] = $adjustment;
  10020. // total price html
  10021. $collectHtml = "";
  10022. $total = 0;
  10023. for($i = 1; $i <= 12; $i ++) {
  10024. $sumPrice = 0;
  10025. foreach ( $receiptCollectList as $key => $value ) {
  10026. if ($value ['month'] == $i) {
  10027. $sumPrice += $value ['price'];
  10028. }
  10029. }
  10030. if ($sumPrice == 0)
  10031. $collectHtml .= '<td class="taR">-</td>';
  10032. else
  10033. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  10034. $total += $sumPrice;
  10035. }
  10036. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  10037. // statistics html
  10038. $stList = $statistics->statisticsByCid ( $year, $cid );
  10039. if (empty ( $stList ))
  10040. $stList = array (
  10041. 'rePrice' => 0,
  10042. 'agPrice' => 0
  10043. );
  10044. $data ['stList'] = array (
  10045. 'rePrice' => $stList ['rePrice'],
  10046. 'agPrice' => $stList ['agPrice'],
  10047. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10048. );
  10049. $data ['totalYear'] = $total;
  10050. $data ['year'] = $year;
  10051. $data ['cid'] = $cid;
  10052. $data ['memu'] = "receipt";
  10053. $data ['staff'] = $this->staff;
  10054. $data ['receiptMemu'] = 'companyCategoryCollect';
  10055. $data ['verifyId'] = $this->verifyId;
  10056. $data ['executeId'] = $this->executeId;
  10057. // year staff status 2,4
  10058. /* if ($year < date ( "Y" )) {
  10059. Doo::loadModel ( 'receipt' );
  10060. $receipt = new receipt ();
  10061. $receiptList = $receipt->find ( array (
  10062. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  10063. 'asArray' => true
  10064. ) );
  10065. if (empty ( $receiptList )) {
  10066. ob_start ();
  10067. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  10068. $this->cacheFile ( $path );
  10069. die ();
  10070. }
  10071. } */
  10072. $dateHtml = "";
  10073. $now = date ( "Y" );
  10074. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  10075. if ($YEARD <= $now) {
  10076. $dateHtml .= '<option ';
  10077. if ($year == $YEARD) {
  10078. $dateHtml .= 'selected ';
  10079. }
  10080. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  10081. }
  10082. }
  10083. $data ['dateHtml'] = $dateHtml;
  10084. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  10085. }
  10086. function staffCollect() {
  10087. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10088. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  10089. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  10090. // $this->showCache($path);
  10091. Doo::loadModel ( 'statistics' );
  10092. $statistics = new statistics ();
  10093. Doo::loadModel ( "receiptDetail" );
  10094. $receiptDetail = new receiptDetail ();
  10095. Doo::loadModel ( 'L_category' );
  10096. $Lcategory = new L_category ();
  10097. Doo::loadModel ( 'accountItem' );
  10098. $accountItem = new accountItem ();
  10099. Doo::loadModel ( 'staff' );
  10100. $staff = new staff ();
  10101. Doo::loadModel ( 'itemStatistics' );
  10102. $itemStatistics = new itemStatistics ();
  10103. Doo::loadModel ( "receiptAuthorityManage" );
  10104. $receiptAuthorityManage = new receiptAuthorityManage ();
  10105. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  10106. $cidList = array ();
  10107. foreach ( $imcStaff as $key => $value ) {
  10108. array_push ( $cidList, $value ['cid'] );
  10109. }
  10110. $cidString = implode ( ',', $cidList );
  10111. $naturecon='';
  10112. if ($nature=='ONJOB'){
  10113. $naturecon=' and (nature!=4 )';
  10114. }elseif($nature=='LEAVEJOB'){
  10115. $naturecon=' and (nature=4 )';
  10116. }else{
  10117. die ( 'illegal request--nature' );
  10118. }
  10119. // statistics html
  10120. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  10121. if (empty ( $stList ))
  10122. $stList = array (
  10123. 'rePrice' => 0,
  10124. 'agPrice' => 0
  10125. );
  10126. $data ['stList'] = array (
  10127. 'rePrice' => $stList ['rePrice'],
  10128. 'agPrice' => $stList ['agPrice'],
  10129. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10130. );
  10131. // ---
  10132. $staffList = $staff->find ( array (
  10133. 'where' => 'username !="admin" '.$naturecon,
  10134. 'asArray' => true
  10135. ) );
  10136. $LcategoryList = $Lcategory->find ( array (
  10137. 'asArray' => true
  10138. ) ); // 'staff='.$this->staff[0]['sid']." and
  10139. $itemStatisticsList = $itemStatistics->find ( array (
  10140. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10141. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  10142. 'groupby' => 'staff,Month(date)',
  10143. 'asArray' => true
  10144. ) );
  10145. $categoryList = $staff->find ( array (
  10146. 'select' => 'COUNT(*) as count,cid,category',
  10147. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  10148. 'groupby' => 'cid',
  10149. 'asArray' => true
  10150. ) );
  10151. // print_r($itemStatisticsList);die;
  10152. // ceatre companyCollectHtml
  10153. foreach ( $categoryList as $vlu ) {
  10154. $count = $vlu ['count'] + 1;
  10155. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  10156. $m1 = 0;
  10157. $m2 = 0;
  10158. $m3 = 0;
  10159. $m4 = 0;
  10160. $m5 = 0;
  10161. $m6 = 0;
  10162. $m7 = 0;
  10163. $m8 = 0;
  10164. $m9 = 0;
  10165. $m10 = 0;
  10166. $m11 = 0;
  10167. $m12 = 0;
  10168. $m13 = 0;
  10169. foreach ( $staffList as $value ) {
  10170. if ($vlu ['cid'] == $value ['cid']) {
  10171. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  10172. $asum = 0;
  10173. for($i = 1; $i <= 12; $i ++) {
  10174. $falg = true;
  10175. foreach ( $itemStatisticsList as $v ) {
  10176. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  10177. if ($v ['month'] == 1)
  10178. $m1 += $v ['price'];
  10179. if ($v ['month'] == 2)
  10180. $m2 += $v ['price'];
  10181. if ($v ['month'] == 3)
  10182. $m3 += $v ['price'];
  10183. if ($v ['month'] == 4)
  10184. $m4 += $v ['price'];
  10185. if ($v ['month'] == 5)
  10186. $m5 += $v ['price'];
  10187. if ($v ['month'] == 6)
  10188. $m6 += $v ['price'];
  10189. if ($v ['month'] == 7)
  10190. $m7 += $v ['price'];
  10191. if ($v ['month'] == 8)
  10192. $m8 += $v ['price'];
  10193. if ($v ['month'] == 9)
  10194. $m9 += $v ['price'];
  10195. if ($v ['month'] == 10)
  10196. $m10 += $v ['price'];
  10197. if ($v ['month'] == 11)
  10198. $m11 += $v ['price'];
  10199. if ($v ['month'] == 12)
  10200. $m12 += $v ['price'];
  10201. $asum += $v ['price'];
  10202. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  10203. $falg = false;
  10204. break;
  10205. }
  10206. }
  10207. if ($falg)
  10208. $html .= '<td class="taR">-</td>';
  10209. }
  10210. $m13 += $asum;
  10211. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  10212. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  10213. 'html' => $html,
  10214. 'sid' => $value ['sid']
  10215. );
  10216. $html = "";
  10217. }
  10218. }
  10219. $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>
  10220. <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>
  10221. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  10222. $collectHtml [$vlu ['cid']] = array (
  10223. 'html' => $hl,
  10224. 'sid' => ''
  10225. );
  10226. }
  10227. $data ['companyHtml'] = $collectHtml;
  10228. // total price html
  10229. $collectHtml = "";
  10230. $total = 0;
  10231. for($i = 1; $i <= 12; $i ++) {
  10232. $sumPrice = 0;
  10233. foreach ( $itemStatisticsList as $key => $value ) {
  10234. if ($value ['month'] == $i) {
  10235. $sumPrice += $value ['price'];
  10236. }
  10237. }
  10238. if ($sumPrice == 0)
  10239. $collectHtml .= '<td class="taR">-</td>';
  10240. else
  10241. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  10242. $total += $sumPrice;
  10243. }
  10244. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  10245. $data ['companyTotalHtml'] = $collectHtml;
  10246. $data ['total'] = $total;
  10247. $data ['nature'] =$nature;
  10248. $data ['year'] = $year;
  10249. $data ['memu'] = "receipt";
  10250. $data ['staff'] = $this->staff;
  10251. $data ['receiptMemu'] = 'companyCategoryCollect';
  10252. $data ['verifyId'] = $this->verifyId;
  10253. $data ['executeId'] = $this->executeId;
  10254. if ($year <= date ( "Y" )) {
  10255. Doo::loadModel ( 'receipt' );
  10256. $receipt = new receipt ();
  10257. $receiptList = $receipt->find ( array (
  10258. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  10259. 'asArray' => true
  10260. ) );
  10261. if (empty ( $receiptList )) { // generated files
  10262. ob_start ();
  10263. $this->render ( "/admin/saeaStaffCollectB", $data );
  10264. $this->cacheFile ( $path );
  10265. die ();
  10266. }
  10267. }
  10268. $this->render ( "/admin/saeaStaffCollectB", $data );
  10269. }
  10270. function staffCollectBak() {
  10271. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10272. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  10273. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  10274. $this->showCache ( $path );
  10275. Doo::loadModel ( 'statistics' );
  10276. $statistics = new statistics ();
  10277. Doo::loadModel ( "receiptDetail" );
  10278. $receiptDetail = new receiptDetail ();
  10279. Doo::loadModel ( 'L_category' );
  10280. $Lcategory = new L_category ();
  10281. Doo::loadModel ( 'accountItem' );
  10282. $accountItem = new accountItem ();
  10283. Doo::loadModel ( 'staff' );
  10284. $staff = new staff ();
  10285. Doo::loadModel ( 'itemStatistics' );
  10286. $itemStatistics = new itemStatistics ();
  10287. $itemStatisticsList = $itemStatistics->find ( array (
  10288. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10289. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10290. 'groupby' => 'staff,itemCategory,Month(date)',
  10291. 'asArray' => true
  10292. ) );
  10293. $itemCategoryList = $itemStatistics->find ( array (
  10294. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10295. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10296. 'groupby' => 'cid,itemCategory,Month(date)',
  10297. 'asArray' => true
  10298. ) );
  10299. $LcategoryList = $Lcategory->find ( array (
  10300. 'asArray' => true
  10301. ) );
  10302. $staffList = $staff->find ( array (
  10303. 'asArray' => true
  10304. ) );
  10305. $htmlArray = array ();
  10306. foreach ( $LcategoryList as $value ) {
  10307. $htmlArray [$value ['title']] = array ();
  10308. foreach ( $staffList as $v ) {
  10309. if ($value ['cid'] == $v ['cid']) {
  10310. $html = "";
  10311. $falg = true;
  10312. $staffSumPrice = 0;
  10313. foreach ( $itemStatisticsList as $a ) {
  10314. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  10315. if (empty ( $a ['price'] )) {
  10316. $html .= '<td class="taR">-</td>';
  10317. $falg = false;
  10318. break;
  10319. } else {
  10320. $staffSumPrice += $a ['price'];
  10321. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10322. $falg = false;
  10323. break;
  10324. }
  10325. }
  10326. }
  10327. if ($falg) {
  10328. $html .= '<td class="taR">-</td>';
  10329. $falg = true;
  10330. }
  10331. $falg = true;
  10332. foreach ( $itemStatisticsList as $a ) {
  10333. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  10334. if (empty ( $a ['price'] )) {
  10335. $html .= '<td class="taR">-</td>';
  10336. $falg = false;
  10337. break;
  10338. } else {
  10339. $staffSumPrice += $a ['price'];
  10340. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10341. $falg = false;
  10342. break;
  10343. }
  10344. }
  10345. }
  10346. if ($falg) {
  10347. $html .= '<td class="taR">-</td>';
  10348. $falg = true;
  10349. }
  10350. $falg = true;
  10351. foreach ( $itemStatisticsList as $a ) {
  10352. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  10353. if (empty ( $a ['price'] )) {
  10354. $html .= '<td class="taR">-</td>';
  10355. $falg = false;
  10356. break;
  10357. } else {
  10358. $staffSumPrice += $a ['price'];
  10359. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10360. $falg = false;
  10361. break;
  10362. }
  10363. }
  10364. }
  10365. if ($falg) {
  10366. $html .= '<td class="taR">-</td>';
  10367. $falg = true;
  10368. }
  10369. $falg = true;
  10370. foreach ( $itemStatisticsList as $a ) {
  10371. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  10372. if (! empty ( $a ['price'] )) {
  10373. $staffSumPrice += $a ['price'];
  10374. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10375. $falg = false;
  10376. break;
  10377. } else {
  10378. $html .= '<td class="taR">-</td>';
  10379. $falg = false;
  10380. break;
  10381. }
  10382. }
  10383. }
  10384. if ($falg) {
  10385. $html .= '<td class="taR">-</td>';
  10386. $falg = true;
  10387. }
  10388. $falg = true;
  10389. foreach ( $itemStatisticsList as $a ) {
  10390. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  10391. if (! empty ( $a ['price'] )) {
  10392. $staffSumPrice += $a ['price'];
  10393. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10394. $falg = false;
  10395. break;
  10396. } else {
  10397. $html .= '<td class="taR">-</td>';
  10398. $falg = false;
  10399. break;
  10400. }
  10401. }
  10402. }
  10403. if ($falg) {
  10404. $html .= '<td class="taR">-</td>';
  10405. $falg = true;
  10406. }
  10407. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  10408. $htmlArray [$value ['title']] [$v ['username']] = $html;
  10409. }
  10410. }
  10411. /* -- --- */
  10412. // 合计费用
  10413. $cateHtml = "";
  10414. $catePrice = 0;
  10415. $cateFalg = true;
  10416. foreach ( $itemCategoryList as $l ) {
  10417. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  10418. if (empty ( $l ['price'] )) {
  10419. $cateHtml .= '<td class="colGreen taR">-</td>';
  10420. $cateFalg = false;
  10421. break;
  10422. } else {
  10423. $catePrice += $l ['price'];
  10424. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10425. $cateFalg = false;
  10426. break;
  10427. }
  10428. }
  10429. }
  10430. if ($cateFalg) {
  10431. $cateHtml .= '<td class="colGreen taR">-</td>';
  10432. $cateFalg = true;
  10433. }
  10434. $cateFalg = true;
  10435. foreach ( $itemCategoryList as $l ) {
  10436. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  10437. if (empty ( $l ['price'] )) {
  10438. $cateHtml .= '<td class="colGreen taR">-</td>';
  10439. $cateFalg = false;
  10440. break;
  10441. } else {
  10442. $catePrice += $l ['price'];
  10443. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10444. $cateFalg = false;
  10445. break;
  10446. }
  10447. }
  10448. }
  10449. if ($cateFalg) {
  10450. $cateHtml .= '<td class="colGreen taR">-</td>';
  10451. $cateFalg = true;
  10452. }
  10453. $cateFalg = true;
  10454. foreach ( $itemCategoryList as $l ) {
  10455. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  10456. if (empty ( $l ['price'] )) {
  10457. $cateHtml .= '<td class="colGreen taR">-</td>';
  10458. $cateFalg = false;
  10459. break;
  10460. } else {
  10461. $catePrice += $l ['price'];
  10462. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10463. $cateFalg = false;
  10464. break;
  10465. }
  10466. }
  10467. }
  10468. if ($cateFalg) {
  10469. $cateHtml .= '<td class="colGreen taR">-</td>';
  10470. $cateFalg = true;
  10471. }
  10472. $cateFalg = true;
  10473. foreach ( $itemCategoryList as $l ) {
  10474. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  10475. if (empty ( $l ['price'] )) {
  10476. $cateHtml .= '<td class="colGreen taR">-</td>';
  10477. $cateFalg = false;
  10478. break;
  10479. } else {
  10480. $catePrice += $l ['price'];
  10481. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10482. $cateFalg = false;
  10483. break;
  10484. }
  10485. }
  10486. }
  10487. if ($cateFalg) {
  10488. $cateHtml .= '<td class="colGreen taR">-</td>';
  10489. $cateFalg = true;
  10490. }
  10491. $cateFalg = true;
  10492. foreach ( $itemCategoryList as $l ) {
  10493. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  10494. if (empty ( $l ['price'] )) {
  10495. $cateHtml .= '<td class="colGreen taR">-</td>';
  10496. $cateFalg = false;
  10497. break;
  10498. } else {
  10499. $catePrice += $l ['price'];
  10500. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10501. $cateFalg = false;
  10502. break;
  10503. }
  10504. }
  10505. }
  10506. if ($cateFalg) {
  10507. $cateHtml .= '<td class="colGreen taR">-</td>';
  10508. $cateFalg = true;
  10509. }
  10510. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  10511. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  10512. /* -- --- */
  10513. }
  10514. // print_r($htmlArray);die;
  10515. $data ['htmlArray'] = $htmlArray;
  10516. // statistics html
  10517. $stList = $statistics->getOne ( array (
  10518. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  10519. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10520. 'groupby' => 'Month(date)',
  10521. 'asArray' => true
  10522. ) );
  10523. if (empty ( $stList ))
  10524. $stList = array (
  10525. 'rePrice' => 0,
  10526. 'agPrice' => 0
  10527. );
  10528. $data ['stList'] = array (
  10529. 'rePrice' => $stList ['rePrice'],
  10530. 'agPrice' => $stList ['agPrice'],
  10531. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10532. );
  10533. $monthHtml = "";
  10534. for($i = 1; $i <= 12; $i ++) {
  10535. if ($i == $month)
  10536. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  10537. else
  10538. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10539. }
  10540. $data ['monthHtml'] = $monthHtml;
  10541. $data ['year'] = $year;
  10542. $data ['month'] = $month;
  10543. $data ['memu'] = "receipt";
  10544. $data ['staff'] = $this->staff;
  10545. $data ['receiptMemu'] = 'companyCategoryCollect';
  10546. $data ['verifyId'] = $this->verifyId;
  10547. $data ['executeId'] = $this->executeId;
  10548. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10549. Doo::loadModel ( 'receipt' );
  10550. $receipt = new receipt ();
  10551. $receiptList = $receipt->find ( array (
  10552. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10553. 'asArray' => true
  10554. ) );
  10555. if (empty ( $receiptList )) { // generated files
  10556. ob_start ();
  10557. $this->render ( "/admin/saeaStaffCollect", $data );
  10558. $this->cacheFile ( $path );
  10559. die ();
  10560. }
  10561. }
  10562. $this->render ( "/admin/saeaStaffCollect", $data );
  10563. }
  10564. /**
  10565. * 日常收支
  10566. */
  10567. function payments() {
  10568. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10569. Doo::loadModel ( "execute" );
  10570. $execute = new execute ();
  10571. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10572. die ( 'illegal request' );
  10573. }
  10574. Doo::loadModel ( "accountBook" );
  10575. $accountBook = new accountBook ();
  10576. Doo::loadModel ( "accountBookStatistics" );
  10577. $accountBookStatistics = new accountBookStatistics ();
  10578. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10579. $list = $accountBook->getAccountBookByLimit ( 10 );
  10580. $data ['date'] = date ( "Y-m-d" );
  10581. $data ['statisticsList'] = $statisticsList;
  10582. $data ['list'] = $list;
  10583. $data ['memu'] = "receipt";
  10584. $data ['staff'] = $this->staff;
  10585. $data ['receiptMemu'] = 'payments';
  10586. $data ['verifyId'] = $this->verifyId;
  10587. $data ['executeId'] = $this->executeId;
  10588. $this->render ( "/expenses/payments", $data );
  10589. }
  10590. function paymentsIncomeDo() {
  10591. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10592. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10593. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10594. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10595. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10596. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10597. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10598. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10599. Doo::loadClass ( 'XDeode' );
  10600. $XDeode = new XDeode ( 5 );
  10601. Doo::loadModel ( "accountBook" );
  10602. Doo::loadModel ( "accountBookStatistics" );
  10603. Doo::loadModel ( 'wasteBook' );
  10604. // 记录流水时银行的转换
  10605. $accountBank = '';
  10606. if ($receivedBank == '纵横广发') {
  10607. $accountBank = 'CGBDeposit';
  10608. } elseif ($receivedBank == '纵横工行') {
  10609. $accountBank = 'ICBCDeposit';
  10610. } elseif ($receivedBank == '华润银行') {
  10611. $accountBank = 'HUADeposit';
  10612. } elseif ($receivedBank == '个人广发') {
  10613. $accountBank = 'PersonalDeposit';
  10614. }
  10615. if (empty ( $accountBank ))
  10616. die ( 'illegal request-bank' );
  10617. //TODO -存款功能 提取
  10618. if($accountType == 11 || $accountType == 12){
  10619. if($accountType == 11){
  10620. $receivedBank = '纵横广发';
  10621. }elseif($accountType == 12){
  10622. $receivedBank = '纵横工行';
  10623. }
  10624. // 添加一条收入
  10625. $accountBook = new accountBook ();
  10626. $accountBook->accountType = $accountType;
  10627. $accountBook->accountMsg = $accountMsg;
  10628. $accountBook->receivedPrice = $receivedPrice;
  10629. $accountBook->receivedMsg = $receivedMsg;
  10630. $accountBook->receivedBank = $receivedBank;
  10631. $accountBook->receivedDate = $receivedDate;
  10632. $accountBook->remarks = $remarks;
  10633. $accountBook->expensesType = 1;
  10634. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10635. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10636. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10637. $inComeId = $accountBook->insert ();
  10638. // 收支汇总-添加一条收入日常汇总
  10639. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10640. $accountBookStatistics = new accountBookStatistics ();
  10641. $item = array (
  10642. 'date' => date ( "Y-m-d" ),
  10643. 'accountType' => $abDetail ['accountType'],
  10644. 'accountMsg' => $abDetail ['accountMsg'],
  10645. 'aid' => $abDetail ['aid'],
  10646. 'inComePrice' => $abDetail ['receivedPrice'],
  10647. 'expensesType' => $abDetail ['expensesType']
  10648. );
  10649. $accountBookStatistics->setAccountBookStatistics ( $item );
  10650. // 添加收入流水
  10651. if($accountType == 11){
  10652. $accountBank = 'CGBDeposit';
  10653. }elseif($accountType == 12){
  10654. $accountBank = 'ICBCDeposit';
  10655. }
  10656. $wasteBook = new wasteBook ();
  10657. $itemWaste = array (
  10658. 'accountPriceShow' => $receivedPrice,
  10659. 'accountPrice' => $receivedPrice,
  10660. 'expensesType' => 1,
  10661. 'accountType' => 6, // 流水类型
  10662. 'dataID' => $inComeId,
  10663. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10664. 'accountBank' => $accountBank,
  10665. 'category' => $this->staff [0] ['category'],
  10666. 'cid' => $this->staff [0] ['cid'],
  10667. 'name' => $this->staff [0] ['username'],
  10668. 'sid' => $this->staff [0] ['sid'],
  10669. 'inputDate' => $receivedDate,
  10670. 'createAt'=>date ( "Y-m-d H:i:s" ),
  10671. 'synPaymentDate'=>1,
  10672. );
  10673. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10674. //TODO --移除理财相关
  10675. }elseif($accountType == 7 || $accountType == 9) { // 收入为理财时特殊处理
  10676. // if ($receivedBank == '个人广发') {
  10677. // die ( '个人广发 illegal request' );
  10678. // }
  10679. // echo $receivedBank;
  10680. // die;
  10681. // 添加一条收入
  10682. $accountBook = new accountBook ();
  10683. $accountBook->accountType = 10;
  10684. $accountBook->accountMsg = $accountMsg;
  10685. $accountBook->receivedPrice = $receivedPrice;
  10686. $accountBook->receivedMsg = $receivedMsg;
  10687. $accountBook->receivedBank = $receivedBank;
  10688. $accountBook->receivedDate = $receivedDate;
  10689. $accountBook->remarks = $remarks;
  10690. $accountBook->expensesType = 1;
  10691. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10692. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10693. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10694. $inComeId = $accountBook->insert ();
  10695. // 收支汇总-添加一条收入日常汇总
  10696. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10697. $accountBookStatistics = new accountBookStatistics ();
  10698. $item = array (
  10699. 'date' => date ( "Y-m-d" ),
  10700. 'accountType' => $abDetail ['accountType'],
  10701. 'accountMsg' => $abDetail ['accountMsg'],
  10702. 'aid' => $abDetail ['aid'],
  10703. 'inComePrice' => $abDetail ['receivedPrice'],
  10704. 'expensesType' => $abDetail ['expensesType']
  10705. );
  10706. $accountBookStatistics->setAccountBookStatistics ( $item );
  10707. // 添加收入流水
  10708. $wasteBook = new wasteBook ();
  10709. $itemWaste = array (
  10710. 'accountPriceShow' => $receivedPrice,
  10711. 'accountPrice' => $receivedPrice,
  10712. 'expensesType' => 1,
  10713. 'accountType' => 6, // 流水类型
  10714. 'dataID' => $inComeId,
  10715. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10716. 'accountBank' => $accountBank,
  10717. 'category' => $this->staff [0] ['category'],
  10718. 'cid' => $this->staff [0] ['cid'],
  10719. 'name' => $this->staff [0] ['username'],
  10720. 'sid' => $this->staff [0] ['sid'],
  10721. 'inputDate' => date ( "Y-m-d H:i:s" )
  10722. );
  10723. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10724. // 添加一条理财支出
  10725. $accountBank = 'CGBDeposit';
  10726. $expenditureBank = '纵横广发';
  10727. if($accountMsg=='个人(GR)'){
  10728. $expenditureBank = '个人广发';
  10729. }
  10730. $dailyExpenditureType = 4;
  10731. if ($accountType == 9) {
  10732. $accountBank = 'ICBCDeposit';
  10733. $expenditureBank = '纵横工行';
  10734. $dailyExpenditureType = 6;
  10735. }
  10736. $accountBook = new accountBook ();
  10737. $accountBook->expensesType = 2;
  10738. $accountBook->expenditureType = $dailyExpenditureType;
  10739. $accountBook->expenditureMsg = $accountMsg;
  10740. $accountBook->expenditurePrice = $receivedPrice;
  10741. $accountBook->expenditureBank = $expenditureBank;
  10742. $accountBook->expenditureDate = $receivedDate;
  10743. $accountBook->remarks = $remarks;
  10744. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10745. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10746. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10747. $id = $accountBook->insert ();
  10748. // 收支汇总-添加一条理财支出汇总
  10749. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10750. $accountBookStatistics = new accountBookStatistics ();
  10751. $item = array (
  10752. 'date' => date ( "Y-m-d" ),
  10753. 'accountType' => $abDetail ['accountType'],
  10754. 'accountMsg' => $abDetail ['accountMsg'],
  10755. 'aid' => $abDetail ['aid'],
  10756. 'financingPrice' => - $receivedPrice,
  10757. 'expensesType' => 3
  10758. );
  10759. $accountBookStatistics->setAccountBookStatistics ( $item );
  10760. //TODO -新增理财为个人时的情况 添加一条支出理财流水
  10761. $accountTypeWaste = 5;
  10762. if ($accountMsg == '公司固定') {
  10763. $accountTypeWaste = 9;
  10764. } elseif ($accountMsg == '公司活期') {
  10765. $accountTypeWaste = 10;
  10766. } elseif ($receivedBank == '个人广发') {
  10767. $accountTypeWaste = 9;
  10768. $accountBank = 'ICBCDeposit';
  10769. }
  10770. $itemWaste = array (
  10771. 'expensesType' => 2,
  10772. 'accountType' => $accountTypeWaste,
  10773. 'accountPriceShow' => $receivedPrice,
  10774. 'accountPrice' => - $receivedPrice,
  10775. 'dataID' => $id,
  10776. 'dailyExpenditureType' => $dailyExpenditureType,
  10777. 'accountBank' => $accountBank,
  10778. 'category' => $this->staff [0] ['category'],
  10779. 'cid' => $this->staff [0] ['cid'],
  10780. 'name' => $this->staff [0] ['username'],
  10781. 'sid' => $this->staff [0] ['sid'],
  10782. 'inputDate' => date ( "Y-m-d H:i:s" )
  10783. );
  10784. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10785. } elseif ($accountType == 1) {
  10786. // if ($receivedBank == '个人广发')
  10787. // die ( 'illegal request--no man' );
  10788. // 添加一条收入
  10789. $accountBook = new accountBook ();
  10790. $accountBook->accountType = $accountType;
  10791. $accountBook->accountMsg = $accountMsg;
  10792. $accountBook->receivedPrice = $receivedPrice;
  10793. $accountBook->receivedMsg = $receivedMsg;
  10794. $accountBook->receivedBank = $receivedBank;
  10795. $accountBook->receivedDate = $receivedDate;
  10796. $accountBook->remarks = $remarks;
  10797. $accountBook->expensesType = 1;
  10798. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10799. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10800. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10801. $id = $accountBook->insert ();
  10802. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10803. // 收支汇总-添加一条收入日常汇总
  10804. $accountBookStatistics = new accountBookStatistics ();
  10805. $item = array (
  10806. 'date' => date ( "Y-m-d" ),
  10807. 'accountType' => $abDetail ['accountType'],
  10808. 'accountMsg' => $abDetail ['accountMsg'],
  10809. 'aid' => $abDetail ['aid'],
  10810. 'expensesType' => $abDetail ['expensesType']
  10811. );
  10812. if ($abDetail ['accountType'] == 8) {
  10813. $item += array (
  10814. 'inComePrice' => $abDetail ['receivedPrice']
  10815. );
  10816. } else {
  10817. $item += array (
  10818. 'inComePrice' => $abDetail ['receivedPrice']
  10819. );
  10820. }
  10821. $accountBookStatistics->setAccountBookStatistics ( $item );
  10822. // 流水存储方向
  10823. $itemWaste = array (
  10824. 'accountType' => 6
  10825. ); // 流水类型
  10826. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10827. // }else
  10828. if ($accountMsg == '活期理财收益') {
  10829. $itemWaste = array (
  10830. 'accountType' => 10
  10831. ); // 流水类型
  10832. }
  10833. // 添加收入流水
  10834. $wasteBook = new wasteBook ();
  10835. $itemWaste += array (
  10836. 'accountPrice' => $receivedPrice,
  10837. 'accountPriceShow' => $receivedPrice,
  10838. 'expensesType' => 1,
  10839. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10840. 'dataID' => $id,
  10841. 'accountBank' => $accountBank,
  10842. 'category' => $this->staff [0] ['category'],
  10843. 'cid' => $this->staff [0] ['cid'],
  10844. 'name' => $this->staff [0] ['username'],
  10845. 'sid' => $this->staff [0] ['sid'],
  10846. 'inputDate' => $receivedDate,
  10847. 'createAt'=>date ( "Y-m-d H:i:s" ),
  10848. 'synPaymentDate'=>1,
  10849. );
  10850. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10851. } else { // 普通日常收入处理
  10852. // 添加一条收入
  10853. $accountBook = new accountBook ();
  10854. $accountBook->accountType = $accountType;
  10855. $accountBook->accountMsg = $accountMsg;
  10856. $accountBook->receivedPrice = $receivedPrice;
  10857. $accountBook->receivedMsg = $receivedMsg;
  10858. $accountBook->receivedBank = $receivedBank;
  10859. $accountBook->receivedDate = $receivedDate;
  10860. $accountBook->remarks = $remarks;
  10861. $accountBook->expensesType = 1;
  10862. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10863. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10864. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10865. $id = $accountBook->insert ();
  10866. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10867. // 收支汇总-添加一条收入日常汇总
  10868. $accountBookStatistics = new accountBookStatistics ();
  10869. $item = array (
  10870. 'date' => date ( "Y-m-d" ),
  10871. 'accountType' => $abDetail ['accountType'],
  10872. 'accountMsg' => $abDetail ['accountMsg'],
  10873. 'aid' => $abDetail ['aid'],
  10874. 'expensesType' => $abDetail ['expensesType']
  10875. );
  10876. if ($abDetail ['accountType'] == 8) {
  10877. $item += array (
  10878. 'inComePrice' => $abDetail ['receivedPrice']
  10879. );
  10880. } else {
  10881. $item += array (
  10882. 'inComePrice' => $abDetail ['receivedPrice']
  10883. );
  10884. }
  10885. $accountBookStatistics->setAccountBookStatistics ( $item );
  10886. // 添加收入流水
  10887. $itemWaste = array (
  10888. 'accountPrice' => $receivedPrice
  10889. );
  10890. if ($receivedBank == '个人广发') {
  10891. $itemWaste = array (
  10892. 'accountPrice' => - $receivedPrice
  10893. );
  10894. }
  10895. $wasteBook = new wasteBook ();
  10896. $itemWaste += array (
  10897. 'accountPriceShow' => $receivedPrice,
  10898. 'expensesType' => 1,
  10899. 'accountType' => 6, // 流水类型
  10900. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10901. 'dataID' => $id,
  10902. 'accountBank' => $accountBank,
  10903. 'category' => $this->staff [0] ['category'],
  10904. 'cid' => $this->staff [0] ['cid'],
  10905. 'name' => $this->staff [0] ['username'],
  10906. 'sid' => $this->staff [0] ['sid'],
  10907. 'inputDate' => $receivedDate,
  10908. 'createAt'=>date ( "Y-m-d H:i:s" ),
  10909. 'synPaymentDate'=>1,
  10910. );
  10911. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10912. }
  10913. }
  10914. return '/payments';
  10915. }
  10916. function paymentsExpenditureDo() {
  10917. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10918. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10919. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10920. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10921. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10922. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10923. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10924. // 理财支出特殊处理
  10925. Doo::loadModel ( "accountBook" );
  10926. Doo::loadModel ( "accountBookStatistics" );
  10927. Doo::loadModel ( 'wasteBook' );
  10928. $accountBank = '';
  10929. if ($expenditureBank == '纵横广发') {
  10930. $accountBank = 'CGBDeposit';
  10931. } elseif ($expenditureBank == '纵横工行') {
  10932. $accountBank = 'ICBCDeposit';
  10933. } elseif ($expenditureBank == '华润银行') {
  10934. $accountBank = 'HUADeposit';
  10935. } elseif ($expenditureBank == '个人广发') {
  10936. $accountBank = 'PersonalDeposit';
  10937. }
  10938. if (empty ( $accountBank ))
  10939. die ( 'illegal request' );
  10940. if($expenditureType == 8 || $expenditureType == 9){
  10941. if($expenditureType == 8 ){
  10942. $expenditureBank='纵横广发';
  10943. }elseif($expenditureType == 9){
  10944. $expenditureBank='纵横工行';
  10945. }
  10946. // 添加一笔日常支出
  10947. $accountBook = new accountBook ();
  10948. $accountBook->expensesType = 2;
  10949. $accountBook->expenditureType = $expenditureType;
  10950. $accountBook->expenditureMsg = $expenditureMsg;
  10951. $accountBook->expenditurePrice = $expenditurePrice;
  10952. $accountBook->expenditureBank = $expenditureBank;
  10953. $accountBook->expenditureDate = $expenditureDate;
  10954. $accountBook->remarks = $remarks;
  10955. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10956. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10957. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10958. $expenditureId = $accountBook->insert ();
  10959. // 添加日常支出汇总
  10960. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  10961. $accountBookStatistics = new accountBookStatistics ();
  10962. $item = array (
  10963. 'date' => date ( "Y-m-d" ),
  10964. 'expenditureType' => $abDetail ['expenditureType'],
  10965. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  10966. 'aid' => $abDetail ['aid'],
  10967. 'payPrice' => $abDetail ['expenditurePrice'],
  10968. 'expensesType' => $abDetail ['expensesType']
  10969. );
  10970. $accountBookStatistics->setAccountBookStatistics ( $item );
  10971. // 公司日常支出流水
  10972. if($expenditureType == 8 ){
  10973. $accountBank = 'CGBDeposit';
  10974. }elseif($expenditureType == 9){
  10975. $accountBank = 'ICBCDeposit';
  10976. }
  10977. if($accountBank=='CGBDeposit'){
  10978. $dailyExpenditureType='8';
  10979. }elseif($accountBank=='ICBCDeposit'){
  10980. $dailyExpenditureType='9';
  10981. }elseif($accountBank=='PersonalDeposit'){
  10982. $dailyExpenditureType='10';
  10983. }elseif($accountBank=='HUADeposit'){
  10984. $dailyExpenditureType='11';
  10985. }
  10986. $wasteBook = new wasteBook ();
  10987. $itemWaste = array (
  10988. 'expensesType' => 2,
  10989. 'accountType' => 5,
  10990. 'dailyExpenditureType' => $dailyExpenditureType,
  10991. 'accountPriceShow' => $expenditurePrice,
  10992. 'accountPrice' => - $expenditurePrice,
  10993. 'dataID' => $expenditureId,
  10994. 'accountBank' => $accountBank,
  10995. 'category' => $this->staff [0] ['category'],
  10996. 'cid' => $this->staff [0] ['cid'],
  10997. 'name' => $this->staff [0] ['username'],
  10998. 'sid' => $this->staff [0] ['sid'],
  10999. 'inputDate' => date ( "Y-m-d H:i:s" )
  11000. );
  11001. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11002. //TODO 日常支出 个人理财情况的相关修改
  11003. }elseif ($expenditureType == 4 || $expenditureType == 6) {
  11004. // if ($expenditureBank == '个人广发') {
  11005. // die ( '个人广发 illegal request' );
  11006. // }
  11007. // echo $expenditureMsg;
  11008. // die;
  11009. // 添加一笔日常支出
  11010. $accountBook = new accountBook ();
  11011. $accountBook->expensesType = 2;
  11012. $accountBook->expenditureType = 7;
  11013. $accountBook->expenditureMsg = $expenditureMsg;
  11014. $accountBook->expenditurePrice = $expenditurePrice;
  11015. $accountBook->expenditureBank = $expenditureBank;
  11016. $accountBook->expenditureDate = $expenditureDate;
  11017. $accountBook->remarks = $remarks;
  11018. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11019. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11020. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11021. $expenditureId = $accountBook->insert ();
  11022. // 添加日常支出汇总
  11023. $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  11024. $accountBookStatistics = new accountBookStatistics ();
  11025. $item = array (
  11026. 'date' => date ( "Y-m-d" ),
  11027. 'expenditureType' => $abDetail ['expenditureType'],
  11028. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11029. 'aid' => $abDetail ['aid'],
  11030. 'payPrice' => $abDetail ['expenditurePrice'],
  11031. 'expensesType' => $abDetail ['expensesType']
  11032. );
  11033. $accountBookStatistics->setAccountBookStatistics ( $item );
  11034. // 公司日常支出流水
  11035. $wasteBook = new wasteBook ();
  11036. $itemWaste = array (
  11037. 'accountPrice' => - $expenditurePrice
  11038. );
  11039. if($expenditureMsg!='个人(GR)'){
  11040. if ($expenditureBank == '个人广发') {
  11041. $itemWaste = array (
  11042. 'accountPrice' => $expenditurePrice
  11043. );
  11044. }
  11045. }
  11046. $itemWaste += array (
  11047. 'expensesType' => 2,
  11048. 'accountType' => 5,
  11049. 'dailyExpenditureType' => $expenditureType,
  11050. 'accountPriceShow' => $expenditurePrice,
  11051. 'accountPrice' => - $expenditurePrice,
  11052. 'dataID' => $expenditureId,
  11053. 'accountBank' => $accountBank,
  11054. 'category' => $this->staff [0] ['category'],
  11055. 'cid' => $this->staff [0] ['cid'],
  11056. 'name' => $this->staff [0] ['username'],
  11057. 'sid' => $this->staff [0] ['sid'],
  11058. 'inputDate' => date ( "Y-m-d H:i:s" )
  11059. );
  11060. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11061. // 添加一笔理财收入
  11062. $accountBank = 'CGBDeposit';
  11063. $dailyIncomeType = 7;
  11064. $receivedBank = '纵横广发';
  11065. if ($expenditureType == 6) {
  11066. $accountBank = 'ICBCDeposit';
  11067. $receivedBank = '纵横工行';
  11068. $dailyIncomeType = 9;
  11069. }elseif($expenditureMsg=='个人(GR)'){
  11070. $receivedBank = '个人广发';
  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. //TODO 修改理财收入 添加一笔收入流水
  11097. if ($expenditureMsg == '公司固定') {
  11098. $accountTypeWaste = 9;
  11099. } elseif ($expenditureMsg == '公司活期') {
  11100. $accountTypeWaste = 10;
  11101. } elseif ($expenditureMsg == '个人(GR)') {
  11102. $accountTypeWaste = 9;
  11103. $accountBank = 'ICBCDeposit';
  11104. }
  11105. $itemWaste = array (
  11106. 'expensesType' => 1,
  11107. 'accountType' => $accountTypeWaste,
  11108. 'accountPriceShow' => $expenditurePrice,
  11109. 'accountPrice' => $expenditurePrice,
  11110. 'dataID' => $id,
  11111. 'dailyIncomeType' => $dailyIncomeType,
  11112. 'accountBank' => $accountBank,
  11113. 'category' => $this->staff [0] ['category'],
  11114. 'cid' => $this->staff [0] ['cid'],
  11115. 'name' => $this->staff [0] ['username'],
  11116. 'sid' => $this->staff [0] ['sid'],
  11117. 'inputDate' => date ( "Y-m-d H:i:s" )
  11118. );
  11119. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11120. } else {
  11121. // 添加一笔日常支出
  11122. $accountBook = new accountBook ();
  11123. $accountBook->expensesType = 2;
  11124. $accountBook->expenditureType = $expenditureType;
  11125. $accountBook->expenditureMsg = $expenditureMsg;
  11126. $accountBook->expenditurePrice = $expenditurePrice;
  11127. $accountBook->expenditureBank = $expenditureBank;
  11128. $accountBook->expenditureDate = $expenditureDate;
  11129. $accountBook->remarks = $remarks;
  11130. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11131. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11132. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11133. $id = $accountBook->insert ();
  11134. // 添加日常支出汇总
  11135. $abDetail = $accountBook->getAccountBookByAid ( $id );
  11136. $accountBookStatistics = new accountBookStatistics ();
  11137. $item = array (
  11138. 'date' => date ( "Y-m-d" ),
  11139. 'expenditureType' => $abDetail ['expenditureType'],
  11140. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11141. 'aid' => $abDetail ['aid'],
  11142. 'expensesType' => $abDetail ['expensesType']
  11143. );
  11144. if ($expenditureType == 5) {
  11145. $item += array (
  11146. 'payPrice' => - $abDetail ['expenditurePrice']
  11147. );
  11148. } else {
  11149. $item += array (
  11150. 'payPrice' => $abDetail ['expenditurePrice']
  11151. );
  11152. }
  11153. $accountBookStatistics->setAccountBookStatistics ( $item );
  11154. // 公司日常支出流水
  11155. $wasteBook = new wasteBook ();
  11156. $itemWaste = array (
  11157. 'accountPrice' => - $expenditurePrice
  11158. );
  11159. if ($expenditureBank == '个人广发') {
  11160. $itemWaste = array (
  11161. 'accountPrice' => $expenditurePrice
  11162. );
  11163. }
  11164. $itemWaste += array (
  11165. 'expensesType' => 2,
  11166. 'accountType' => 5,
  11167. 'accountPriceShow' => $expenditurePrice,
  11168. 'dataID' => $id,
  11169. 'dailyExpenditureType' => $expenditureType,
  11170. 'accountBank' => $accountBank,
  11171. 'category' => $this->staff [0] ['category'],
  11172. 'cid' => $this->staff [0] ['cid'],
  11173. 'name' => $this->staff [0] ['username'],
  11174. 'sid' => $this->staff [0] ['sid'],
  11175. 'inputDate' => date ( "Y-m-d H:i:s" )
  11176. );
  11177. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11178. }
  11179. }
  11180. return '/payments';
  11181. }
  11182. /**
  11183. * 添加支出
  11184. */
  11185. function paymentsExpenditureDo_() {
  11186. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11187. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11188. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11189. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11190. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11191. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11192. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11193. $dailyExpenditureType = '';
  11194. $accountTypeWaste = 5;
  11195. $accountBank = '';
  11196. if ($expenditureBank == '纵横广发') {
  11197. $accountBank = 'CGBDeposit';
  11198. } elseif ($expenditureBank == '纵横工行') {
  11199. $accountBank = 'ICBCDeposit';
  11200. } elseif ($expenditureBank == '华润银行') {
  11201. $accountBank = 'HUADeposit';
  11202. } elseif ($expenditureBank == '个人广发') {
  11203. $accountBank = 'PersonalDeposit';
  11204. }
  11205. if (empty ( $accountBank ))
  11206. die ( 'illegal request' );
  11207. $itemWaste = array (
  11208. 'accountPrice' => - $expenditurePrice
  11209. );
  11210. if ($expenditureBank == '个人广发') {
  11211. $itemWaste = array (
  11212. 'accountPrice' => $expenditurePrice
  11213. );
  11214. }
  11215. if ($expenditureType == 4 || $expenditureType == 6) {
  11216. $dailyExpenditureType = 4;
  11217. if ($expenditureMsg == '公司固定') {
  11218. $accountTypeWaste = 9;
  11219. } elseif ($expenditureMsg == '公司活期') {
  11220. $accountTypeWaste = 10;
  11221. } elseif ($expenditureMsg == '个人(GR)') {
  11222. $accountBank = 'PersonalDeposit';
  11223. }
  11224. $itemWaste = array (
  11225. 'accountPrice' => $expenditurePrice
  11226. );
  11227. } elseif ($expenditureType == 1) {
  11228. $dailyExpenditureType = 1;
  11229. } elseif ($expenditureType == 2) {
  11230. $dailyExpenditureType = 2;
  11231. } elseif ($expenditureType == 3) {
  11232. $dailyExpenditureType = 3;
  11233. } elseif ($expenditureType == 5) {
  11234. $dailyExpenditureType = 5;
  11235. }
  11236. if (empty ( $dailyExpenditureType ))
  11237. die ( 'illegal request' );
  11238. Doo::loadModel ( "accountBook" );
  11239. $accountBook = new accountBook ();
  11240. $accountBook->expenditureType = $expenditureType;
  11241. $accountBook->expenditureMsg = $expenditureMsg;
  11242. $accountBook->expenditurePrice = $expenditurePrice;
  11243. $accountBook->expenditureBank = $expenditureBank;
  11244. $accountBook->expenditureDate = $expenditureDate;
  11245. $accountBook->remarks = $remarks;
  11246. $accountBook->expensesType = 2;
  11247. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11248. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11249. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11250. $id = $accountBook->insert ();
  11251. //
  11252. $abDetail = $accountBook->getAccountBookByAid ( $id );
  11253. Doo::loadModel ( "accountBookStatistics" );
  11254. $accountBookStatistics = new accountBookStatistics ();
  11255. $item = array (
  11256. 'date' => date ( "Y-m-d" ),
  11257. 'expenditureType' => $abDetail ['expenditureType'],
  11258. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11259. 'aid' => $abDetail ['aid']
  11260. );
  11261. if ($abDetail ['expensesType'] == 2) {
  11262. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  11263. $item += array (
  11264. 'financingPrice' => $expenditurePrice,
  11265. 'expensesType' => 3
  11266. );
  11267. } elseif ($abDetail ['expenditureType'] == 5) {
  11268. $item += array (
  11269. 'payPrice' => $abDetail ['expenditurePrice'],
  11270. 'expensesType' => $abDetail ['expensesType']
  11271. );
  11272. } else {
  11273. $item += array (
  11274. 'payPrice' => $abDetail ['expenditurePrice'],
  11275. 'expensesType' => $abDetail ['expensesType']
  11276. );
  11277. }
  11278. }
  11279. $accountBookStatistics->setAccountBookStatistics ( $item );
  11280. // 公司流水记录
  11281. Doo::loadModel ( 'wasteBook' );
  11282. $wasteBook = new wasteBook ();
  11283. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  11284. // 银行
  11285. if (empty ( $abDetail )) {
  11286. $itemWaste += array (
  11287. 'accountPriceShow' => $expenditurePrice,
  11288. 'dataID' => $id,
  11289. 'expensesType' => 2,
  11290. 'accountType' => $accountTypeWaste,
  11291. 'dailyExpenditureType' => $expenditureType,
  11292. 'accountBank' => $accountBank,
  11293. 'category' => $this->staff [0] ['category'],
  11294. 'cid' => $this->staff [0] ['cid'],
  11295. 'name' => $this->staff [0] ['username'],
  11296. 'sid' => $this->staff [0] ['sid'],
  11297. 'inputDate' => date ( "Y-m-d H:i:s" )
  11298. );
  11299. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11300. }
  11301. // 支出类型为4或者6 需要添加一笔收入和收入流水
  11302. if ($expenditureType == 4 || $expenditureType == 6) {
  11303. $accountBank = 'CGBDeposit';
  11304. $dailyIncomeType = 7;
  11305. $receivedBank = '纵横广发';
  11306. if ($expenditureType == 6) {
  11307. $accountBank = 'ICBCDeposit';
  11308. $receivedBank = '纵横工行';
  11309. $dailyIncomeType = 9;
  11310. }
  11311. // 添加一笔收入
  11312. $accountBook = new accountBook ();
  11313. $accountBook->accountType = $dailyIncomeType;
  11314. $accountBook->accountMsg = $expenditureMsg;
  11315. $accountBook->receivedPrice = $expenditurePrice;
  11316. $accountBook->receivedBank = $receivedBank;
  11317. $accountBook->receivedDate = $expenditureDate;
  11318. $accountBook->remarks = $remarks;
  11319. $accountBook->expensesType = 1;
  11320. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11321. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11322. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11323. $id = $accountBook->insert ();
  11324. // 添加一笔收入流水
  11325. $itemWaste = array (
  11326. 'accountPriceShow' => $expenditurePrice,
  11327. 'accountPrice' => - $expenditurePrice,
  11328. 'dataID' => $id,
  11329. 'expensesType' => 1,
  11330. 'accountType' => $accountTypeWaste,
  11331. 'dailyIncomeType' => $dailyIncomeType,
  11332. 'accountBank' => $accountBank,
  11333. 'category' => $this->staff [0] ['category'],
  11334. 'cid' => $this->staff [0] ['cid'],
  11335. 'name' => $this->staff [0] ['username'],
  11336. 'sid' => $this->staff [0] ['sid'],
  11337. 'inputDate' => date ( "Y-m-d H:i:s" )
  11338. );
  11339. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11340. }
  11341. }
  11342. return '/payments';
  11343. }
  11344. /**
  11345. * 所有收支
  11346. */
  11347. function paymentsAchieve() {
  11348. $page_size = 12;
  11349. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  11350. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  11351. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11352. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  11353. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11354. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11355. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11356. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  11357. Doo::loadModel ( "accountBookStatistics" );
  11358. $accountBookStatistics = new accountBookStatistics ();
  11359. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  11360. $data ['statisticsList'] = $statisticsList;
  11361. Doo::loadModel ( "accountBook" );
  11362. $accountBook = new accountBook ();
  11363. $con = '';
  11364. if ($expensesType == 'INCOME')
  11365. $con = ' and expensesType=1 ';
  11366. elseif ($expensesType == 'PAY')
  11367. $con = ' and expensesType=2 ';
  11368. $dateArr = explode ( ':', $date );
  11369. $D1 = $dateString = '';
  11370. $D2 = '';
  11371. if (! empty ( $date )) {
  11372. $D1 = $dateArr [0];
  11373. if (isset ( $dateArr [1] ))
  11374. $D2 = $dateArr [1];
  11375. else
  11376. $D2 = '';
  11377. $dateString = $D1 . " : " . $D2;
  11378. }
  11379. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11380. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11381. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11382. $con .= ' and inputDate like "%' . $D1 . '%" ';
  11383. if (! empty ( $price ))
  11384. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  11385. if ($submitType == 1) {
  11386. if ($accountType != '') {
  11387. $expenditureType = '';
  11388. $con .= ' and accountType=' . $accountType;
  11389. if (! empty ( $accountMsg ))
  11390. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  11391. }
  11392. } elseif ($submitType == 2) {
  11393. if ($expenditureType != '') {
  11394. $accountType = $accountMsg = '';
  11395. $con .= ' and expenditureType=' . $expenditureType;
  11396. }
  11397. } else {
  11398. $accountType = $accountMsg = $expenditureType = '';
  11399. }
  11400. $sql = "" . $con;
  11401. $action = "paymentsAchieve";
  11402. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  11403. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  11404. $limit = $pageinfo ['lower'] . ',' . $page_size;
  11405. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  11406. $data ['expenditureType'] = $expenditureType;
  11407. $data ['accountMsg'] = $accountMsg;
  11408. $data ['accountType'] = $accountType;
  11409. $data ['inputDate'] = $date;
  11410. $data ['price'] = $price;
  11411. $data ['expensesType'] = $expensesType;
  11412. $data ['page'] = $pageinfo;
  11413. $data ['list'] = $list;
  11414. $data ['memu'] = "receipt";
  11415. $data ['staff'] = $this->staff;
  11416. $data ['receiptMemu'] = 'payments';
  11417. $data ['verifyId'] = $this->verifyId;
  11418. $data ['executeId'] = $this->executeId;
  11419. $this->render ( "/expenses/paymentsAchieve", $data );
  11420. }
  11421. function paymentsIncomeUpdateDo() {
  11422. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11423. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11424. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11425. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  11426. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  11427. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  11428. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  11429. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11430. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  11431. Doo::loadClass ( 'XDeode' );
  11432. $XDeode = new XDeode ( 5 );
  11433. $aid = $XDeode->decode ( $aidKey );
  11434. Doo::loadModel ( "accountBook" );
  11435. $accountBook = new accountBook ();
  11436. //
  11437. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11438. $price = $receivedPrice - $abDetail [inComePrice];
  11439. Doo::loadModel ( "accountBookStatistics" );
  11440. $accountBookStatistics = new accountBookStatistics ();
  11441. if ($abDetail ['accountType'] == 7) {
  11442. $item += array (
  11443. 'date' => date ( "Y-m-d" ),
  11444. 'financingPrice' => - $price,
  11445. 'expensesType' => 3,
  11446. 'aid' => $abDetail ['aid']
  11447. );
  11448. } elseif ($abDetail ['accountType'] == 8) {
  11449. $item += array (
  11450. 'date' => date ( "Y-m-d" ),
  11451. 'expensesType' => $abDetail ['expensesType'],
  11452. 'inComePrice' => - $price,
  11453. 'aid' => $abDetail ['aid']
  11454. );
  11455. } else {
  11456. $item = array (
  11457. 'date' => date ( "Y-m-d" ),
  11458. 'expensesType' => $abDetail ['expensesType'],
  11459. 'inComePrice' => $price,
  11460. 'aid' => $abDetail ['aid']
  11461. );
  11462. }
  11463. $accountBookStatistics->setAccountBookStatistics ( $item );
  11464. $accountBook->accountType = $accountType;
  11465. $accountBook->accountMsg = $accountMsg;
  11466. $accountBook->receivedPrice = $receivedPrice;
  11467. $accountBook->receivedMsg = $receivedMsg;
  11468. $accountBook->receivedBank = $receivedBank;
  11469. $accountBook->receivedDate = $receivedDate;
  11470. $accountBook->remarks = $remarks;
  11471. $accountBook->aid = $aid;
  11472. $accountBook->update ();
  11473. }
  11474. return '/paymentsAchieve';
  11475. }
  11476. function paymentsExpenditureEdiDo() {
  11477. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11478. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11479. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11480. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11481. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11482. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11483. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11484. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11485. Doo::loadClass ( 'XDeode' );
  11486. $XDeode = new XDeode ( 5 );
  11487. $aid = $XDeode->decode ( $aidKey );
  11488. Doo::loadModel ( "accountBook" );
  11489. $accountBook = new accountBook ();
  11490. // 汇总信息
  11491. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11492. $price = $expenditurePrice - $abDetail [expenditurePrice];
  11493. Doo::loadModel ( "accountBookStatistics" );
  11494. $accountBookStatistics = new accountBookStatistics ();
  11495. if ($abDetail ['expenditureType'] == 4) {
  11496. $item += array (
  11497. 'date' => date ( "Y-m-d" ),
  11498. 'financingPrice' => $price,
  11499. 'expensesType' => 3,
  11500. 'aid' => $abDetail ['aid']
  11501. );
  11502. } elseif ($abDetail ['expenditureType'] == 5) {
  11503. $item += array (
  11504. 'date' => date ( "Y-m-d" ),
  11505. 'expensesType' => $abDetail ['expensesType'],
  11506. 'payPrice' => $price,
  11507. 'aid' => $abDetail ['aid']
  11508. );
  11509. } else {
  11510. $item = array (
  11511. 'date' => date ( "Y-m-d" ),
  11512. 'expensesType' => $abDetail ['expensesType'],
  11513. 'payPrice' => $price,
  11514. 'aid' => $abDetail ['aid']
  11515. );
  11516. }
  11517. $accountBookStatistics->setAccountBookStatistics ( $item );
  11518. //
  11519. $accountBook->expenditureType = $expenditureType;
  11520. $accountBook->expenditureMsg = $expenditureMsg;
  11521. $accountBook->expenditurePrice = $expenditurePrice;
  11522. $accountBook->expenditureBank = $expenditureBank;
  11523. $accountBook->remarks = $remarks;
  11524. $accountBook->expenditureDate = $expenditureDate;
  11525. $accountBook->aid = $aid;
  11526. $id = $accountBook->update ();
  11527. }
  11528. return '/paymentsAchieve';
  11529. }
  11530. function paymentsDelDo() {
  11531. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11532. if (! empty ( $aidKey )) {
  11533. Doo::loadClass ( 'XDeode' );
  11534. $XDeode = new XDeode ( 5 );
  11535. $aid = $XDeode->decode ( $aidKey );
  11536. Doo::loadModel ( "accountBook" );
  11537. $accountBook = new accountBook ();
  11538. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11539. if (empty ( $abDetail ))
  11540. die ( 'illegal request' );
  11541. // 删除收支
  11542. Doo::loadModel ( "accountBookStatistics" );
  11543. $accountBookStatistics = new accountBookStatistics ();
  11544. $item = array (
  11545. 'date' => date ( "Y-m-d" ),
  11546. 'aid' => $abDetail ['aid']
  11547. );
  11548. $accountType = '';
  11549. if ($abDetail ['expensesType'] == 1) {
  11550. $accountType = 6;
  11551. if ($abDetail ['accountType'] != 7) {
  11552. $item += array (
  11553. 'expensesType' => $abDetail ['expensesType'],
  11554. 'inComePrice' => - $abDetail ['receivedPrice']
  11555. );
  11556. } else {
  11557. $item += array (
  11558. 'financingPrice' => $abDetail ['receivedPrice'],
  11559. 'expensesType' => 3
  11560. );
  11561. }
  11562. } elseif ($abDetail ['expensesType'] == 2) {
  11563. $accountType = 5;
  11564. if ($abDetail ['accountType'] != 7) {
  11565. $item += array (
  11566. 'expensesType' => $abDetail ['expensesType'],
  11567. 'payPrice' => - $abDetail ['expenditurePrice']
  11568. );
  11569. } else {
  11570. $item += array (
  11571. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11572. 'expensesType' => 3
  11573. );
  11574. }
  11575. }
  11576. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11577. if ($abDetail ['expenditureMsg'] == '公司固定')
  11578. $accountType = 9;
  11579. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11580. $accountType = 10;
  11581. }
  11582. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11583. if ($abDetail ['accountMsg'] == '公司固定')
  11584. $accountType = 9;
  11585. elseif ($abDetail ['accountMsg'] == '公司活期')
  11586. $accountType = 10;
  11587. }
  11588. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11589. $accountType = 10;
  11590. }
  11591. $accountBookStatistics->setAccountBookStatistics ( $item );
  11592. $accountBook->delete ( array (
  11593. 'where' => 'aid=' . $aid,
  11594. 'limit' => 1
  11595. ) );
  11596. // 删除收入流水
  11597. if (! empty ( $accountType )) {
  11598. Doo::loadModel ( 'wasteBook' );
  11599. $wasteBook = new wasteBook ();
  11600. $wasteBook->delete ( array (
  11601. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11602. 'limit' => 1
  11603. ) );
  11604. }
  11605. }
  11606. return '/paymentsAchieve';
  11607. }
  11608. function paymentsCollect() {
  11609. Doo::loadModel ( "execute" );
  11610. $execute = new execute ();
  11611. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11612. die ( 'illegal request' );
  11613. }
  11614. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11615. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11616. Doo::loadModel ( "accountBookStatistics" );
  11617. $accountBookStatistics = new accountBookStatistics ();
  11618. Doo::loadClass ( 'receipt.func' );
  11619. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11620. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11621. $data ['html'] = $html ['html'];
  11622. $data ['inSum'] = $html ['sum'];
  11623. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11624. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11625. $data ['payHtml'] = $html ['html'];
  11626. $data ['paySum'] = $html ['sum'];
  11627. // 余额统计
  11628. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11629. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11630. include './protected/config/wasteBook.conf.php';
  11631. Doo::loadModel ( 'wasteBook' );
  11632. $wasteBook = new wasteBook ();
  11633. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11634. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11635. // 获得年份之前所有金额
  11636. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11637. // print_r($detail);
  11638. // $waste['total'];
  11639. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11640. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11641. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11642. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11643. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11644. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11645. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11646. if (date ( 'Y' ) > $year) {
  11647. $limitMonth = 12;
  11648. }
  11649. for($i = 1; $i <= 12; $i ++) {
  11650. $inComeA = $payB = 0;
  11651. $falg = true;
  11652. foreach ( $inComePay as $key => $value ) {
  11653. if ($value ['month'] == $i) {
  11654. $falg = false;
  11655. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11656. $inSum += $value ['accountPrice'];
  11657. $showInSum += $value ['accountPriceShow'];
  11658. $inComeA = $value ['accountPrice'];
  11659. break;
  11660. }
  11661. }
  11662. if ($falg)
  11663. $inComeHtml .= '<td class="taR">-</td>';
  11664. $payFalg = true;
  11665. foreach ( $pay as $key => $value ) {
  11666. if ($value ['month'] == $i) {
  11667. $payFalg = false;
  11668. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11669. $paySum += $value ['accountPrice'];
  11670. $showPaySum += $value ['accountPriceShow'];
  11671. $payB = $value ['accountPrice'];
  11672. break;
  11673. }
  11674. }
  11675. if ($payFalg)
  11676. $payHtml .= '<td class="taR">-</td>';
  11677. if (empty ( $balanceC ) || $limitMonth < $i)
  11678. $lastBalanceHtml .= '<td class="taR">-</td>';
  11679. else
  11680. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11681. $balanceC = $balanceC + $inComeA + $payB;
  11682. $balanceSum += $balanceC;
  11683. if (empty ( $balanceC ) || $limitMonth < $i)
  11684. $BalanceHtml .= '<td class="taR">-</td>';
  11685. else
  11686. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11687. // 余额统计
  11688. }
  11689. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11690. $data ['inComeHtml'] = $inComeHtml;
  11691. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11692. $data ['payBalanceHtml'] = $payHtml;
  11693. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11694. $data ['BalanceHtml'] = $BalanceHtml;
  11695. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11696. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11697. $mothHtml = "";
  11698. for($i = 1; $i <= 12; $i ++) {
  11699. if ($moth == $i)
  11700. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11701. else
  11702. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11703. }
  11704. $data ['mothHtml'] = $mothHtml;
  11705. $dateHtml = "";
  11706. $now = date ( "Y" );
  11707. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11708. if ($YEARD <= $now) {
  11709. $dateHtml .= '<option ';
  11710. if ($year == $YEARD) {
  11711. $dateHtml .= 'selected ';
  11712. }
  11713. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11714. }
  11715. }
  11716. $data ['dateHtml'] = $dateHtml;
  11717. $data ['year'] = $year;
  11718. $data ['memu'] = "receipt";
  11719. $data ['staff'] = $this->staff;
  11720. $data ['receiptMemu'] = 'paymentsCollect';
  11721. $data ['verifyId'] = $this->verifyId;
  11722. $data ['executeId'] = $this->executeId;
  11723. $this->render ( "/expenses/paymentsCollect", $data );
  11724. }
  11725. function paymentsCollectDay() {
  11726. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11727. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11728. if (empty ( $moth ))
  11729. return 'paymentsCollect';
  11730. Doo::loadModel ( "accountBookStatistics" );
  11731. $accountBookStatistics = new accountBookStatistics ();
  11732. $i = 2;
  11733. $y = 2013;
  11734. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11735. Doo::loadClass ( 'receipt.func' );
  11736. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11737. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11738. $data ['html'] = $html ['html'];
  11739. $data ['inSum'] = $html ['sum'];
  11740. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11741. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11742. $data ['payHtml'] = $html ['html'];
  11743. $data ['paySum'] = $html ['sum'];
  11744. $mothHtml = "";
  11745. for($i = 1; $i <= 12; $i ++) {
  11746. if ($moth == $i)
  11747. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11748. else
  11749. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11750. }
  11751. $data ['mothHtml'] = $mothHtml;
  11752. $data ['year'] = $year;
  11753. // 余额
  11754. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11755. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11756. include './protected/config/wasteBook.conf.php';
  11757. Doo::loadModel ( 'wasteBook' );
  11758. $wasteBook = new wasteBook ();
  11759. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11760. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11761. // 获得年份之前所有金额
  11762. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11763. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11764. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11765. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11766. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11767. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11768. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11769. // $balanceC = 0;
  11770. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11771. $limitDay = date ( 'd' );
  11772. $monthLK = ( int ) date ( 'm' );
  11773. if (date ( 'Y' ) > $year) {
  11774. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11775. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11776. $limitDay = 0;
  11777. }
  11778. for($i = 1; $i <= $day; $i ++) {
  11779. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11780. $inComeA = $payB = 0;
  11781. $falg = true;
  11782. foreach ( $inComePay as $key => $value ) {
  11783. if ($value ['day'] == $i) {
  11784. $falg = false;
  11785. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11786. $inSum += $value ['accountPrice'];
  11787. $showInSum += $value ['accountPriceShow'];
  11788. $inComeA = $value ['accountPrice'];
  11789. break;
  11790. }
  11791. }
  11792. if ($falg)
  11793. $inComeHtml .= '<td class="taR">-</td>';
  11794. $payFalg = true;
  11795. foreach ( $pay as $key => $value ) {
  11796. if ($value ['day'] == $i) {
  11797. $payFalg = false;
  11798. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11799. $paySum += $value ['accountPrice'];
  11800. $showPaySum += $value ['accountPriceShow'];
  11801. $payB = $value ['accountPrice'];
  11802. break;
  11803. }
  11804. }
  11805. if ($payFalg)
  11806. $payHtml .= '<td class="taR">-</td>';
  11807. if (empty ( $balanceC ) || $limitDay < $i)
  11808. $lastBalanceHtml .= '<td class="taR">-</td>';
  11809. else
  11810. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11811. $balanceC = $balanceC + $inComeA + $payB;
  11812. $balanceSum += $balanceC;
  11813. if (empty ( $balanceC ) || $limitDay < $i)
  11814. $BalanceHtml .= '<td class="taR">-</td>';
  11815. else
  11816. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11817. }
  11818. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11819. $data ['inComeHtml'] = $inComeHtml;
  11820. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11821. $data ['payBalanceHtml'] = $payHtml;
  11822. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11823. $data ['BalanceHtml'] = $BalanceHtml;
  11824. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11825. $data ['dayHtml'] = $dayHtml;
  11826. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11827. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11828. $dateHtml = "";
  11829. $now = date ( "Y" );
  11830. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11831. if ($YEARD <= $now) {
  11832. $dateHtml .= '<option ';
  11833. if ($year == $YEARD) {
  11834. $dateHtml .= 'selected ';
  11835. }
  11836. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11837. }
  11838. }
  11839. $data ['dateHtml'] = $dateHtml;
  11840. $data ['memu'] = "receipt";
  11841. $data ['staff'] = $this->staff;
  11842. $data ['receiptMemu'] = 'paymentsCollect';
  11843. $data ['verifyId'] = $this->verifyId;
  11844. $data ['executeId'] = $this->executeId;
  11845. $this->render ( "/expenses/paymentsCollectDay", $data );
  11846. }
  11847. // 公司流水
  11848. function wasteBook() {
  11849. Doo::loadModel ( "execute" );
  11850. $execute = new execute ();
  11851. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11852. die ( 'illegal request' );
  11853. }
  11854. include './protected/config/wasteBook.conf.php';
  11855. Doo::loadModel ( 'wasteBook' );
  11856. $wasteBook = new wasteBook ();
  11857. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11858. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11859. //
  11860. $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'];
  11861. $CGBDeposit_total =$waste ['bank'] ['CGBDeposit']+$waste ['bank'] ['HUADeposit'];
  11862. //$waste ['bank'] ['ICBCDeposit']=sprintf("%.2f", round($waste ['bank'] ['ICBCDeposit'], 2));
  11863. // print_r($waste);
  11864. $data ['waste'] = $waste;
  11865. $data ['total'] = $total;
  11866. $data ['CGBDeposit_total'] = $CGBDeposit_total;
  11867. $data['cashBalance']= $CGBDeposit_total+$waste ['bank'] ['ICBCDeposit']+$waste ['bank'] ['PersonalDeposit']+$waste ['financial'] ['current'] ['CGBDeposit']+$waste ['financial'] ['current'] ['ICBCDeposit'];
  11868. // 月流水数据结构
  11869. $monthStatistics = array ();
  11870. $incomeMothStatistics = array ();
  11871. $expenditureMothStatistics = array ();
  11872. for($i = 1; $i <= 12; $i ++) {
  11873. $month = date ( 'Y' ) . '-' . $i;
  11874. if ($i < 10)
  11875. $month = date ( 'Y' ) . '-0' . $i;
  11876. array_push ( $monthStatistics, $month );
  11877. }
  11878. foreach ( $monthStatistics as $value ) {
  11879. $falg = true;
  11880. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  11881. if ($value == $v ['inputDate']) {
  11882. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  11883. $falg = false;
  11884. }
  11885. }
  11886. if ($falg) {
  11887. array_push ( $incomeMothStatistics, '' );
  11888. }
  11889. $falgEx = true;
  11890. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  11891. if ($value == $v ['inputDate']) {
  11892. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  11893. $falg = false;
  11894. }
  11895. }
  11896. if ($falgEx) {
  11897. array_push ( $expenditureMothStatistics, '' );
  11898. }
  11899. }
  11900. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  11901. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  11902. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  11903. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  11904. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  11905. // print_r($incomeList);
  11906. $data ['expenditureList'] = $expenditureList;
  11907. $data ['incomeList'] = $incomeList;
  11908. $data ['memu'] = "receipt";
  11909. $data ['staff'] = $this->staff;
  11910. $data ['receiptMemu'] = 'wasteBook';
  11911. $data ['verifyId'] = $this->verifyId;
  11912. $data ['executeId'] = $this->executeId;
  11913. $this->render ( "/expenses/wasteBook", $data );
  11914. }
  11915. function wasteBookIncome() {
  11916. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11917. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  11918. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  11919. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  11920. $data ['dailyIncomeType'] = $dailyIncomeType;
  11921. Doo::loadModel ( 'wasteBook' );
  11922. $wasteBook = new wasteBook ();
  11923. Doo::loadModel ( 'L_category' );
  11924. $L_category = new L_category ();
  11925. Doo::loadClass ( 'XDeode' );
  11926. $XDeode = new XDeode ( 5 );
  11927. $year=date("Y");
  11928. $theDay=date("Y-m-d");
  11929. $dateArr = explode ( ':', $date );
  11930. $D1 = '';
  11931. $D2 = '';
  11932. $con = '';
  11933. if (! empty ( $date )) {
  11934. $D1 = $dateArr [0];
  11935. $D2 = $dateArr [1];
  11936. }
  11937. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11938. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11939. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11940. $con = ' and inputDate = "' . $D1 . '"';
  11941. else{
  11942. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  11943. }
  11944. if ($cid != 'ALL') {
  11945. $cid = $XDeode->decode ( $cid );
  11946. $con .= ' and cid = "' . $cid . '"';
  11947. }
  11948. if ($accountType != 'ALL') {
  11949. if ($accountType == 'INVOICE') {
  11950. $con .= ' and (accountType = 7 or accountType = 8)';
  11951. } elseif ($accountType == 'PAYMENTS') {
  11952. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  11953. if ($dailyIncomeType != 'ALL') {
  11954. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  11955. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  11956. }
  11957. }
  11958. }
  11959. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  11960. foreach ($incomeList as $key=>$value){
  11961. if(($value['accountType']==6||$value['accountType']==9||$value['accountType']==10)&&$value['synPaymentDate']==0){
  11962. $wasteBook = new wasteBook ();
  11963. $wasteBook->wid = $value['wid'];
  11964. $wasteBook->synPaymentDate = 1;
  11965. $wasteBook->inputDate = $value['data']['receivedDate'];
  11966. $wasteBook->update();
  11967. }
  11968. }
  11969. $sum = 0;$thsDaySum=0;
  11970. foreach ( $incomeList as $key => $value ) {
  11971. $sum += $value ['accountPrice'];
  11972. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  11973. $thsDaySum+=$value ['accountPrice'];
  11974. }
  11975. }
  11976. // print_r($incomeList);
  11977. // 获得办事和部门
  11978. $categoryList = $L_category->getCategory ();
  11979. $data ['accountType'] = $accountType;
  11980. $data ['cid'] = $cid;
  11981. $data ['categoryList'] = $categoryList;
  11982. $data ['sum'] = $sum;
  11983. $data ['incomeList'] = $incomeList;
  11984. $data ['inputDate'] = $date;
  11985. $data['year']=$year;
  11986. $data ['thsDay'] =$theDay;
  11987. $data ['thsDaySum'] =$thsDaySum;
  11988. $data ['memu'] = "receipt";
  11989. $data ['staff'] = $this->staff;
  11990. $data ['receiptMemu'] = 'wasteBook';
  11991. $data ['verifyId'] = $this->verifyId;
  11992. $data ['executeId'] = $this->executeId;
  11993. $this->render ( "/expenses/wasteBookIncome", $data );
  11994. }
  11995. /**
  11996. * 所有支出
  11997. */
  11998. function wasteBookExpenditure() {
  11999. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  12000. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  12001. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  12002. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  12003. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  12004. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  12005. $data ['receiptType'] = $receiptType;
  12006. Doo::loadModel ( 'wasteBook' );
  12007. $wasteBook = new wasteBook ();
  12008. Doo::loadModel ( 'L_category' );
  12009. $L_category = new L_category ();
  12010. Doo::loadClass ( 'XDeode' );
  12011. $XDeode = new XDeode ( 5 );
  12012. $year=date("Y");
  12013. $theDay=date("Y-m-d");
  12014. $dateArr = explode ( ':', $date );
  12015. $D1 = '';
  12016. $D2 = '';
  12017. $con = '';
  12018. if (! empty ( $date )) {
  12019. $D1 = $dateArr [0];
  12020. $D2 = $dateArr [1];
  12021. }
  12022. if (! empty ( $D1 ) && ! empty ( $D2 ))
  12023. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  12024. elseif (! empty ( $D1 ) && empty ( $D2 ))
  12025. $con = ' and inputDate = "' . $D1 . '"';
  12026. else{
  12027. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  12028. }
  12029. if ($cid != 'ALL') {
  12030. $cid = $XDeode->decode ( $cid );
  12031. $con .= ' and cid = "' . $cid . '"';
  12032. }
  12033. if ($accountType != 'ALL') {
  12034. if ($accountType == 'INVOICE') {
  12035. $con .= ' and accountType = 11';
  12036. } elseif ($accountType == 'PAYMENTS') {
  12037. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  12038. if ($dailyExpenditureType != 'ALL') {
  12039. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  12040. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  12041. }
  12042. } elseif ($accountType == 'RECEIPT') {
  12043. if ($receiptType == 'ALL') {
  12044. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  12045. } else {
  12046. $receiptType = $XDeode->decode ( $receiptType );
  12047. echo $receiptType;
  12048. if ($receiptType == 1) {
  12049. $con .= ' and (accountType = 1 or accountType=2)';
  12050. } else {
  12051. $con .= ' and accountType = ' . $receiptType;
  12052. }
  12053. }
  12054. }
  12055. }
  12056. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  12057. foreach ($incomeList as $key=>$value){
  12058. if(($value['accountType']==5||$value['accountType']==9||$value['accountType']==10)&&$value['synPaymentDate']==0){
  12059. $wasteBook = new wasteBook ();
  12060. $wasteBook->wid = $value['wid'];
  12061. $wasteBook->synPaymentDate = 1;
  12062. $wasteBook->inputDate = $value['data']['expenditureDate'];
  12063. $wasteBook->update();
  12064. }
  12065. }
  12066. $sum = 0;$thsDaySum=0;
  12067. foreach ( $incomeList as $key => $value ) {
  12068. $sum += $value ['accountPriceShow'];
  12069. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  12070. $thsDaySum+=$value ['accountPriceShow'];
  12071. }
  12072. }
  12073. // print_r($incomeList);
  12074. // 获得办事和部门
  12075. $categoryList = $L_category->getCategory ();
  12076. $data ['accountType'] = $accountType;
  12077. $data ['cid'] = $cid;
  12078. $data ['categoryList'] = $categoryList;
  12079. $data ['sum'] = $sum;
  12080. $data ['incomeList'] = $incomeList;
  12081. $data ['inputDate'] = $date;
  12082. $data['year']=$year;
  12083. $data ['thsDay'] =$theDay;
  12084. $data ['thsDaySum'] =$thsDaySum;
  12085. $data ['memu'] = "receipt";
  12086. $data ['staff'] = $this->staff;
  12087. $data ['receiptMemu'] = 'wasteBook';
  12088. $data ['verifyId'] = $this->verifyId;
  12089. $data ['executeId'] = $this->executeId;
  12090. $this->render ( "/expenses/wasteBookExpenditure", $data );
  12091. }
  12092. function ajaxGetWasteinvoiceReceivables() {
  12093. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12094. Doo::loadClass ( 'XDeode' );
  12095. $XDeode = new XDeode ( 5 );
  12096. $irid = $XDeode->decode ( $serial );
  12097. Doo::loadModel ( 'invoiceReceivables' );
  12098. $invoiceReceivables = new invoiceReceivables ();
  12099. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  12100. echo json_encode ( array (
  12101. 'status' => 1,
  12102. 'detail' => $detail
  12103. ) );
  12104. }
  12105. function ajaxGetPaymentsByAid() {
  12106. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12107. Doo::loadModel ( "accountBook" );
  12108. $accountBook = new accountBook ();
  12109. $detail = $accountBook->getAccountBookByAid ( $serial );
  12110. echo json_encode ( array (
  12111. 'status' => 1,
  12112. 'detail' => $detail
  12113. ) );
  12114. }
  12115. function ajaxGetWasteInvoice() {
  12116. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12117. Doo::loadModel ( 'invoice' );
  12118. $invoice = new invoice ();
  12119. Doo::loadModel ( 'invoiceReceivables' );
  12120. $invoiceReceivables = new invoiceReceivables ();
  12121. $detail = $invoice->getInvoiceByIid ( $serial );
  12122. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  12123. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  12124. echo json_encode ( array (
  12125. 'status' => 1,
  12126. 'detail' => $detail
  12127. ) );
  12128. }
  12129. /**
  12130. */
  12131. function ajaxGetWasteReceipt() {
  12132. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12133. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  12134. Doo::loadModel ( 'receipt' );
  12135. $receipt = new receipt ();
  12136. Doo::loadClass ( 'XDeode' );
  12137. $XDeode = new XDeode ( 5 );
  12138. $rid = $XDeode->decode ( $serial );
  12139. $accountType= $XDeode->decode ( $accountTypeKey );
  12140. // 获得个数据
  12141. $detail = $receipt->getReceiptByRid ( $rid );
  12142. // 初始化
  12143. $detail ['reviseDetail'] = array ();
  12144. if (! empty ( $value ['reviseDetail'] ))
  12145. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  12146. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  12147. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  12148. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  12149. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  12150. // 获得费用html
  12151. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  12152. // 获得费用审批人数据
  12153. $detail = $this->getReceiptApproverHtml ( $detail );
  12154. // 审批执行
  12155. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  12156. <th class="taC" width="90">审批人</th>
  12157. <th class="taC">审批意见</th></tr>';
  12158. foreach ( $detail ['verifyList'] as $key => $value ) {
  12159. $html .= '<tr>
  12160. <td>' . $value [1] . '</td>
  12161. <td>' . $value ['opinion'] . '</td>
  12162. </tr>
  12163. ';
  12164. }
  12165. $html .= ' </tbody></table>';
  12166. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  12167. <th class="taC" width="90">执行人</th>
  12168. <th class="taC">执行意见</th></tr>';
  12169. foreach ( $detail ['executeCopy'] as $key => $value ) {
  12170. $html .= '<tr>
  12171. <td>' . $value [1] . '</td>
  12172. <td>' . $value ['opinion'] . '</td>
  12173. </tr>
  12174. ';
  12175. }
  12176. $html .= ' </tbody></table>';
  12177. if($accountType==1){
  12178. Doo::loadModel ( 'loanReceipt' );
  12179. $loanReceipt = new loanReceipt ();
  12180. $loanList = $loanReceipt->getOne ( array (
  12181. 'where' => 'rid=' . $detail ['loanRid'],
  12182. 'desc' => 'rid',
  12183. 'asArray' => true
  12184. ) );
  12185. $html .= '<table class="table table-bordered table-condensed">
  12186. <tr class="warning">
  12187. <td class="taR"><b>汇款金额</b></td>
  12188. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  12189. </tr>
  12190. </table>';
  12191. }else{
  12192. $html .= '<table class="table table-bordered table-condensed">
  12193. <tr class="warning">
  12194. <td class="taR"><b>汇款金额</b></td>
  12195. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  12196. </tr>
  12197. </table>';
  12198. }
  12199. // print_r($detail['verifyList']);
  12200. // header ( 'Content-Type:text/html;charset=utf-8' );
  12201. // echo $html;
  12202. echo json_encode ( array (
  12203. 'status' => 1,
  12204. 'html' => $html,
  12205. 'detail' => $detail
  12206. ) );
  12207. }
  12208. function getReceiptApproverHtml($detail = array()) {
  12209. Doo::loadModel ( 'loanReceipt' );
  12210. $loanReceipt = new loanReceipt ();
  12211. Doo::loadModel ( 'verify' );
  12212. $verify = new verify ();
  12213. Doo::loadModel ( 'staff' );
  12214. $staff = new staff ();
  12215. if (empty ( $detail ))
  12216. return array ();
  12217. $loanList = $loanReceipt->getOne ( array (
  12218. 'where' => 'rid=' . $detail ['loanRid'],
  12219. 'desc' => 'rid',
  12220. 'asArray' => true
  12221. ) );
  12222. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  12223. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  12224. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  12225. else
  12226. $verifyList ['staff'] = $detail ['verifyBreakup'];
  12227. } else
  12228. $verifyList = $verify->getOne ( array (
  12229. 'where' => 'vid=' . $detail ['verify'],
  12230. 'asArray' => true
  12231. ) );
  12232. $verifyList = json_decode ( $verifyList ['staff'], true );
  12233. Doo::loadModel ( 'role' );
  12234. $role = new role ();
  12235. $roleId = 0;
  12236. $flag = true;
  12237. $roleKey = 0;
  12238. $endStaffArray = array ();
  12239. $roleArrayCopy = array ();
  12240. foreach ( $verifyList as $k => $v ) {
  12241. // init verifyStaff
  12242. if ($v [1] == 'ROLE') {
  12243. if (! empty ( $verifyStaff )) {
  12244. $endStaffArray = end ( $verifyStaff );
  12245. }
  12246. $roleVerify = json_decode ( $v [3], true );
  12247. $roleKey = $k;
  12248. $roleArray = array ();
  12249. $rolename = $role->getOne ( array (
  12250. 'where' => 'rid=' . $v [0],
  12251. 'asArray' => true
  12252. ) );
  12253. foreach ( $roleVerify as $o => $p ) {
  12254. $staffID = explode ( '_', $p );
  12255. $staffInfo = $staff->getOne ( array (
  12256. 'where' => 'sid=' . $staffID [0],
  12257. 'asArray' => true
  12258. ) );
  12259. // print_r($staffID);
  12260. $exp = array (
  12261. 0 => $staffInfo ['sid'],
  12262. 1 => $staffID [1],
  12263. 2 => $staffInfo ['avatar'],
  12264. 'date' => '',
  12265. 'date' => '',
  12266. 'opinion' => '',
  12267. 'status' => '',
  12268. 'rolename' => $rolename ['name']
  12269. );
  12270. array_push ( $roleArray, $exp );
  12271. }
  12272. $roleArrayCopy [$v [0]] = $roleArray;
  12273. // $verifyList[$k]['roleArray']=$roleArray;
  12274. }
  12275. $verifyList [$k] ['date'] = "";
  12276. $verifyList [$k] ['opinion'] = "";
  12277. $verifyList [$k] ['status'] = "";
  12278. if (empty ( $verifyStaff )) {
  12279. $verifyList [$k] ['date'] = "";
  12280. $verifyList [$k] ['opinion'] = "";
  12281. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  12282. $verifyList [$k] ['status'] = 4;
  12283. $flag = false;
  12284. }
  12285. } else {
  12286. foreach ( $verifyStaff as $m => $u ) {
  12287. if ($v [0] == $m) {
  12288. $verifyList [$k] ['date'] = $u ['date'];
  12289. $verifyList [$k] ['opinion'] = $u ['opinion'];
  12290. $verifyList [$k] ['status'] = $u ['status'];
  12291. $flag = false;
  12292. break;
  12293. }
  12294. }
  12295. $endStaffArray = end ( $verifyStaff );
  12296. }
  12297. }
  12298. $rolename ['name'] = '';
  12299. if (! empty ( $roleId )) {
  12300. Doo::loadModel ( 'role' );
  12301. $role = new role ();
  12302. $rolename = $role->getOne ( array (
  12303. 'where' => 'rid=' . $roleId,
  12304. 'asArray' => true
  12305. ) );
  12306. }
  12307. if (! empty ( $verifyStaff ))
  12308. $endStaffArray = end ( $verifyStaff );
  12309. $KOP = false;
  12310. foreach ( $roleArrayCopy as $P => $A ) {
  12311. foreach ( $A as $MKI => $AVL ) {
  12312. if (! empty ( $verifyStaff )) {
  12313. // &&$rolename['rid']==$endStaffArray['nextStaff']
  12314. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  12315. $button = 4;
  12316. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12317. }
  12318. foreach ( $verifyStaff as $m => $u ) {
  12319. $AVLFK = $AVL [0] . '_R';
  12320. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  12321. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  12322. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  12323. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  12324. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  12325. break;
  12326. }
  12327. }
  12328. } else {
  12329. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  12330. $button = 4;
  12331. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12332. }
  12333. }
  12334. // $roleArray[$MKI]['rolename']=$rolename['name'];
  12335. $KOP = true;
  12336. }
  12337. }
  12338. foreach ( $roleArrayCopy as $k => $v ) {
  12339. foreach ( $verifyList as $m => $n ) {
  12340. if ($n [0] == $k) {
  12341. array_splice ( $verifyList, $m, 1, $v );
  12342. }
  12343. }
  12344. }
  12345. // 费用执行人相关数据
  12346. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  12347. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  12348. foreach ( $executeCopy as $k => $v ) {
  12349. $executeCopy [$k] ['date'] = '';
  12350. $executeCopy [$k] ['opinion'] = '';
  12351. $executeCopy [$k] ['status'] = '';
  12352. if (! empty ( $executeStaff ))
  12353. foreach ( $executeStaff as $m => $u ) {
  12354. if ($v [0] == $m) {
  12355. $executeCopy [$k] ['date'] = $u ['date'];
  12356. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  12357. $executeCopy [$k] ['status'] = $u ['status'];
  12358. break;
  12359. }
  12360. }
  12361. }
  12362. $detail ['executeCopy'] = $executeCopy;
  12363. $detail ['verifyList'] = $verifyList;
  12364. return $detail;
  12365. }
  12366. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  12367. if (empty ( $detail ))
  12368. return '';
  12369. $html = '';
  12370. if ($detail ['Rtype'] == 0) { // 报销单
  12371. $html .= '<table class="table table-bordered table-condensed">
  12372. <tbody>
  12373. <tr>
  12374. <th colspan="2" class="taC">日常相关费用</th>
  12375. </tr>';
  12376. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12377. $html .= '
  12378. <tr>
  12379. <th>' . $value ['name'] . '</th>
  12380. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12381. </tr>';
  12382. }
  12383. $html .= '
  12384. <tr>
  12385. <th class="taR">合计</th>
  12386. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12387. </tr>';
  12388. $html .= '<tr>
  12389. <th colspan="2" class="taC">差旅相关费用</th>
  12390. </tr>';
  12391. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12392. $html .= '
  12393. <tr>
  12394. <th>' . $value ['name'] . '</th>
  12395. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12396. </tr>';
  12397. }
  12398. $html .= '
  12399. <tr>
  12400. <th class="taR">合计</th>
  12401. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12402. </tr>';
  12403. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12404. $html .= '<tr>
  12405. <th colspan="2" class="taC">内部培训费用</th>
  12406. </tr>';
  12407. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12408. $html .= '
  12409. <tr>
  12410. <th>' . $value ['name'] . '</th>
  12411. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12412. </tr>';
  12413. }
  12414. $html .= '
  12415. <tr>
  12416. <th class="taR">合计</th>
  12417. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12418. </tr>';
  12419. }
  12420. $html .= '<tr>
  12421. <th colspan="2" class="taC">其他</th>
  12422. </tr>';
  12423. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12424. $html .= '
  12425. <tr>
  12426. <th>' . $value ['name'] . '</th>
  12427. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12428. </tr>';
  12429. }
  12430. $html .= '
  12431. <tr>
  12432. <th class="taR">合计</th>
  12433. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12434. </tr>';
  12435. $html .= '<tr>
  12436. <th colspan="2" class="taC">报销金额调整</th>
  12437. </tr>';
  12438. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12439. $html .= '
  12440. <tr>
  12441. <th>' . $value ['name'] . '</th>
  12442. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12443. </tr>';
  12444. }
  12445. $html .= '
  12446. <tr>
  12447. <th class="taR">合计</th>
  12448. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12449. </tr>';
  12450. $html .= '
  12451. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12452. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12453. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12454. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12455. <tr class="warning">
  12456. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12457. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12458. </tr>
  12459. </tbody>
  12460. </table>';
  12461. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  12462. $html .= '
  12463. <table class="table table-bordered table-condensed">
  12464. <tbody>
  12465. <tr>
  12466. <th colspan="2" class="taC">办事处相关费用</th>
  12467. </tr>';
  12468. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12469. $html .= '
  12470. <tr>
  12471. <th>' . $value ['name'] . '</th>
  12472. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12473. </tr>';
  12474. }
  12475. $html .= '
  12476. <tr>
  12477. <th class="taR">合计</th>
  12478. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12479. </tr>';
  12480. $html .= '
  12481. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12482. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12483. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12484. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12485. <tr class="warning">
  12486. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12487. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12488. </tr>
  12489. </tbody>
  12490. </table>';
  12491. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  12492. Doo::loadModel ( 'loanReceipt' );
  12493. $loanReceipt = new loanReceipt ();
  12494. $loanList = $loanReceipt->getOne ( array (
  12495. 'where' => 'rid=' . $detail ['loanRid'],
  12496. 'desc' => 'rid',
  12497. 'asArray' => true
  12498. ) );
  12499. // print_r($loanList);
  12500. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  12501. $html .= '<table class="table table-bordered table-condensed">
  12502. <tbody>
  12503. <tr>
  12504. <th colspan="2" class="taC">借款费用</th>
  12505. </tr>';
  12506. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  12507. $html .= '<tr>
  12508. <th>' . $value ['name'] . '</th>
  12509. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12510. </tr>';
  12511. }
  12512. $html .= '<tr>
  12513. <th class="taC" colspan="2">产生费用所在办事处</th>
  12514. </tr>
  12515. <tr>
  12516. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  12517. </tr>
  12518. <tr>
  12519. <th class="taC" colspan="2">费用说明</th>
  12520. </tr>
  12521. <tr>
  12522. <td colspan="2">' . $loanList ['explanation'] . '</td>
  12523. </tr>
  12524. <tr class="warning">
  12525. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12526. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12527. </tr>
  12528. </tbody>
  12529. </table>
  12530. ';
  12531. if ( $accountType==2) {
  12532. $balance=$detail ['sum']-$loanList ['sum'];
  12533. $balanceCN=$this->num_to_rmb($balance);
  12534. $html .= '<table class="table table-bordered table-condensed">
  12535. <tbody>
  12536. <tr>
  12537. <th colspan="2" class="taC">日常相关费用</th>
  12538. </tr>';
  12539. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12540. $html .= '
  12541. <tr>
  12542. <th>' . $value ['name'] . '</th>
  12543. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12544. </tr>';
  12545. }
  12546. $html .= '
  12547. <tr>
  12548. <th class="taR">合计</th>
  12549. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12550. </tr>';
  12551. $html .= '<tr>
  12552. <th colspan="2" class="taC">差旅相关费用</th>
  12553. </tr>';
  12554. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12555. $html .= '
  12556. <tr>
  12557. <th>' . $value ['name'] . '</th>
  12558. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12559. </tr>';
  12560. }
  12561. $html .= '
  12562. <tr>
  12563. <th class="taR">合计</th>
  12564. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12565. </tr>';
  12566. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12567. $html .= '<tr>
  12568. <th colspan="2" class="taC">内部培训费用</th>
  12569. </tr>';
  12570. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12571. $html .= '
  12572. <tr>
  12573. <th>' . $value ['name'] . '</th>
  12574. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12575. </tr>';
  12576. }
  12577. $html .= '
  12578. <tr>
  12579. <th class="taR">合计</th>
  12580. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12581. </tr>';
  12582. }
  12583. $html .= '<tr>
  12584. <th colspan="2" class="taC">其他</th>
  12585. </tr>';
  12586. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12587. $html .= '
  12588. <tr>
  12589. <th>' . $value ['name'] . '</th>
  12590. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12591. </tr>';
  12592. }
  12593. $html .= '
  12594. <tr>
  12595. <th class="taR">合计</th>
  12596. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12597. </tr>';
  12598. $html .= '<tr>
  12599. <th colspan="2" class="taC">报销金额调整</th>
  12600. </tr>';
  12601. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12602. $html .= '
  12603. <tr>
  12604. <th>' . $value ['name'] . '</th>
  12605. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12606. </tr>';
  12607. }
  12608. $html .= '
  12609. <tr>
  12610. <th class="taR">合计</th>
  12611. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12612. </tr>';
  12613. $html .= '
  12614. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12615. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12616. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12617. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12618. <tr class="warning">
  12619. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12620. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12621. </tr>
  12622. <tr class="success">
  12623. <td class="taR"><b>借款结余</b></td>
  12624. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12625. </tr>
  12626. </tbody>
  12627. </table>';
  12628. }
  12629. }
  12630. return $html;
  12631. }
  12632. /**
  12633. * 计算流水
  12634. */
  12635. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12636. $bakWaste ['bank'] = array (
  12637. 'CGBDeposit' => 0,
  12638. 'ICBCDeposit' => 0,
  12639. 'HUADeposit' => 0,
  12640. 'PersonalDeposit' => 0
  12641. );
  12642. $bakWaste ['financial'] = array (
  12643. 'current' => array (
  12644. 'CGBDeposit' => 0,
  12645. 'ICBCDeposit' => 0
  12646. ),
  12647. 'fixed' => array (
  12648. 'CGBDeposit' => 0,
  12649. 'ICBCDeposit' => 0
  12650. )
  12651. );
  12652. // 存款
  12653. foreach ( $waste ['bank'] as $key => $value ) {
  12654. // 收入
  12655. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12656. // 广发
  12657. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12658. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12659. }
  12660. // 工商
  12661. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12662. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12663. }
  12664. // 华润
  12665. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12666. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12667. }
  12668. // 个人
  12669. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12670. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12671. }
  12672. }
  12673. }
  12674. foreach ( $waste ['bank'] as $key => $value ) {
  12675. // 支出
  12676. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12677. // 广发
  12678. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12679. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12680. }
  12681. // 工商
  12682. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12683. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12684. }
  12685. // 华润
  12686. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12687. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12688. }
  12689. // 个人
  12690. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12691. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12692. }
  12693. }
  12694. }
  12695. // 活期
  12696. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12697. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12698. // 广发
  12699. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12700. $waste ['financial'] ['current'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12701. }
  12702. // 工商
  12703. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12704. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12705. }
  12706. // 个人
  12707. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12708. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12709. }
  12710. }
  12711. }
  12712. // print_r($inComeStatistics ['fixedStatistics']);
  12713. // 固期
  12714. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12715. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12716. // 广发
  12717. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12718. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12719. }
  12720. // 工商---已经转变成个人理财固定代表含义
  12721. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12722. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12723. }
  12724. // 个人
  12725. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12726. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12727. }
  12728. }
  12729. }
  12730. $waste ['bank'] ['ICBCDeposit'] = sprintf("%.2f", $waste ['bank'] ['ICBCDeposit']);
  12731. return $waste;
  12732. }
  12733. function lyt() {
  12734. Doo::loadModel ( "receiptDetail" );
  12735. $receiptDetail = new receiptDetail ();
  12736. $receiptCollectList = $receiptDetail->find ( array (
  12737. 'where' => 'status=1 ',
  12738. 'asArray' => true
  12739. ) );
  12740. foreach ( $receiptCollectList as $key => $value ) {
  12741. $receiptDetail = new receiptDetail ();
  12742. $receiptDetail->pastDate = $value ['date'];
  12743. $receiptDetail->update ( array (
  12744. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12745. ) );
  12746. }
  12747. }
  12748. function staffCollectMonthDetail() {
  12749. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12750. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12751. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12752. if (! $year)
  12753. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12754. if (! $month)
  12755. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12756. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12757. if (! $nature){
  12758. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12759. }
  12760. Doo::loadModel ( 'staff' );
  12761. $staff = new staff ();
  12762. Doo::loadModel ( "receiptDetail" );
  12763. $receiptDetail = new receiptDetail ();
  12764. Doo::loadModel ( 'accountItem' );
  12765. $accountItem = new accountItem ();
  12766. Doo::loadModel ( 'statistics' );
  12767. $statistics = new statistics ();
  12768. Doo::loadModel ( "receiptAuthorityManage" );
  12769. $receiptAuthorityManage = new receiptAuthorityManage ();
  12770. $aiList=$accountItem->getAccountItem();
  12771. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12772. $cidList = array ();
  12773. foreach ( $imcStaff as $key => $value ) {
  12774. array_push ( $cidList, $value ['cid'] );
  12775. }
  12776. $cidString = implode ( ',', $cidList );
  12777. $naturecon='';
  12778. if ($nature=='ONJOB'){
  12779. $naturecon=' and (nature!=4 )';
  12780. }elseif($nature=='LEAVEJOB'){
  12781. $naturecon=' and (nature=4 )';
  12782. }else{
  12783. die ( 'illegal request--nature' );
  12784. }
  12785. $staffList = $staff->find ( array (
  12786. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12787. 'asArray' => true
  12788. ) );
  12789. $categoryList = $staff->find ( array (
  12790. 'select' => 'COUNT(*) as count,cid,category',
  12791. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12792. 'groupby' => 'cid',
  12793. 'asArray' => true
  12794. ) );
  12795. $list = array ();
  12796. foreach($aiList as $key=>$value){
  12797. foreach ($value as $v){
  12798. $subtotal[$key][$v['name']]=0;
  12799. }
  12800. }
  12801. foreach ( $categoryList as $vlu ) {
  12802. $s1 = 0;
  12803. $m1 = 0;
  12804. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12805. foreach ( $staffList as $value ) {
  12806. if ($vlu ['cid'] == $value ['cid']) {
  12807. // pastDate
  12808. $receiptCollectList = $receiptDetail->find ( array (
  12809. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12810. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12811. 'groupby' => 'item,Month(pastDate),itemCategory',
  12812. 'asArray' => true
  12813. ) );
  12814. if (! empty ( $receiptCollectList )) {
  12815. $receiptL = array (
  12816. '日常相关费用' => array (),
  12817. '差旅相关费用' => array (),
  12818. '内部培训费用' => array (),
  12819. '培训班费用' => array (),
  12820. '其他' => array ()
  12821. );
  12822. $html = "";
  12823. $psum = 0;
  12824. foreach ( $aiList[$this->AGENCY] as $va ) {
  12825. $falg = true;
  12826. foreach ( $receiptCollectList as $v ) {
  12827. if ($v ['itemCategory'] == '日常相关费用') {
  12828. if ($v ['item'] == $va['name']) {
  12829. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12830. $psum += $v ['price'];
  12831. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12832. $falg = false;
  12833. break;
  12834. }
  12835. }
  12836. }
  12837. if ($falg)
  12838. $html .= '<td class="taR">-</td>';
  12839. }
  12840. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12841. if (! empty ( $psum ))
  12842. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12843. else
  12844. $psum = '<td class="colGreen taR">-</td>';
  12845. $receiptL ['日常相关费用'] = $psum . $html;
  12846. /* ----------------------------------- */
  12847. $html = "";
  12848. $psum = 0;
  12849. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12850. $falg = true;
  12851. foreach ( $receiptCollectList as $v ) {
  12852. if ($v ['itemCategory'] == '差旅相关费用') {
  12853. if ($v ['item'] == $va['name']) {
  12854. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  12855. $psum += $v ['price'];
  12856. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12857. $falg = false;
  12858. break;
  12859. }
  12860. }
  12861. }
  12862. if ($falg)
  12863. $html .= '<td class="taR">-</td>';
  12864. }
  12865. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  12866. if (! empty ( $psum ))
  12867. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12868. else
  12869. $psum = '<td class="colGreen taR">-</td>';
  12870. $receiptL ['差旅相关费用'] = $psum . $html;
  12871. /* ------------------------------------- */
  12872. $html = "";
  12873. $psum = 0;
  12874. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12875. $falg = true;
  12876. foreach ( $receiptCollectList as $v ) {
  12877. if ($v ['itemCategory'] == '内部培训费用') {
  12878. if ($v ['item'] == $va['name']) {
  12879. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  12880. $psum += $v ['price'];
  12881. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12882. $falg = false;
  12883. break;
  12884. }
  12885. }
  12886. }
  12887. if ($falg)
  12888. $html .= '<td class="taR">-</td>';
  12889. }
  12890. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  12891. if (! empty ( $psum ))
  12892. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12893. else
  12894. $psum = '<td class="colGreen taR">-</td>';
  12895. $receiptL ['内部培训费用'] = $psum . $html;
  12896. /* ----------------------------------- */
  12897. $html = "";
  12898. $psum = 0;
  12899. foreach ( $aiList[$this->TRAIN] as $va ) {
  12900. $falg = true;
  12901. foreach ( $receiptCollectList as $v ) {
  12902. if ($v ['itemCategory'] == '培训班费用') {
  12903. if ($v ['item'] == $va['name']) {
  12904. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  12905. $psum += $v ['price'];
  12906. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12907. $falg = false;
  12908. break;
  12909. }
  12910. }
  12911. }
  12912. if ($falg)
  12913. $html .= '<td class="taR">-</td>';
  12914. }
  12915. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  12916. if (! empty ( $psum ))
  12917. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12918. else
  12919. $psum = '<td class="colGreen taR">-</td>';
  12920. $receiptL ['培训班费用'] = $psum . $html;
  12921. /* ------------------------------------- */
  12922. $html = "";
  12923. $psum = 0;
  12924. foreach ( $aiList[$this->OTHER] as $va ) {
  12925. $falg = true;
  12926. foreach ( $receiptCollectList as $v ) {
  12927. if ($v ['itemCategory'] == '其他') {
  12928. if (trim ( $v ['item'] ) == $va['name']) {
  12929. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  12930. $psum += $v ['price'];
  12931. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12932. $falg = false;
  12933. break;
  12934. }
  12935. }
  12936. }
  12937. if ($falg)
  12938. $html .= '<td class="taR">-</td>';
  12939. }
  12940. $subtotal[$this->OTHER]['OTHER'] += $psum;
  12941. if (! empty ( $psum ))
  12942. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12943. else
  12944. $psum = '<td class="colGreen taR">-</td>';
  12945. $receiptL ['其他'] = $psum . $html;
  12946. /* ------------------------------------- */
  12947. $html = "";
  12948. $psum = 0;
  12949. foreach ( $receiptCollectList as $v ) {
  12950. if ($v ['itemCategory'] == '报销金额调整') {
  12951. if (! empty ( $v ['price'] )) {
  12952. $psum += $v ['price'];
  12953. }
  12954. }
  12955. }
  12956. $s1 += $psum;
  12957. if (! empty ( $psum ))
  12958. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  12959. else
  12960. $psum = '<td class="taR colOrange">-</td>';
  12961. $receiptL ['报销金额调整'] = $psum . $html;
  12962. } else {
  12963. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  12964. foreach ( $aiList[$this->AGENCY] as $va ) {
  12965. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  12966. }
  12967. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  12968. foreach ( $aiList[$this->TRAVEL] as $va ) {
  12969. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  12970. }
  12971. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  12972. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  12973. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  12974. }
  12975. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  12976. foreach ( $aiList[$this->TRAIN] as $va ) {
  12977. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  12978. }
  12979. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  12980. foreach ( $aiList[$this->OTHER] as $va ) {
  12981. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  12982. }
  12983. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  12984. }
  12985. $monthStaffPrice = $receiptDetail->find ( array (
  12986. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12987. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12988. 'groupby' => 'Month(pastDate)',
  12989. 'asArray' => true
  12990. ) );
  12991. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  12992. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  12993. $m1 += $monthStaffPrice [0] ['price'];
  12994. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  12995. } else
  12996. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  12997. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  12998. $list [$value ['username']] = $receiptL;
  12999. }
  13000. }
  13001. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  13002. foreach ( $aiList[$this->AGENCY] as $va ) {
  13003. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  13004. $subtotal[$this->AGENCY][$va['name']]=0;
  13005. }
  13006. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  13007. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13008. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  13009. $subtotal[$this->TRAVEL][$va['name']]=0;
  13010. }
  13011. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  13012. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13013. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  13014. $subtotal[$this->INTTRAIN][$va['name']]=0;
  13015. }
  13016. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  13017. foreach ( $aiList[$this->TRAIN] as $va ) {
  13018. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  13019. $subtotal[$this->TRAIN][$va['name']]=0;
  13020. }
  13021. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  13022. foreach ( $aiList[$this->OTHER] as $va ) {
  13023. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  13024. $subtotal[$this->OTHER][$va['name']]=0;
  13025. }
  13026. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13027. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13028. $receiptL ['usernameEn'] =false;
  13029. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13030. }
  13031. $data ['list'] = $list;
  13032. // print_r($list);
  13033. $receiptCollectList = $receiptDetail->find ( array (
  13034. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13035. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13036. 'groupby' => 'item,Month(pastDate),itemCategory',
  13037. 'asArray' => true
  13038. ) );
  13039. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13040. // statistics html
  13041. $stList = $statistics->getOne ( array (
  13042. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13043. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13044. 'groupby' => 'Month(date)',
  13045. 'asArray' => true
  13046. ) );
  13047. if (empty ( $stList ))
  13048. $stList = array (
  13049. 'rePrice' => 0,
  13050. 'agPrice' => 0
  13051. );
  13052. $data ['stList'] = array (
  13053. 'rePrice' => $stList ['rePrice'],
  13054. 'agPrice' => $stList ['agPrice'],
  13055. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13056. );
  13057. $monthHtml = "";
  13058. for($i = 1; $i <= 12; $i ++) {
  13059. if ($i == $month)
  13060. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13061. else
  13062. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13063. }
  13064. $data ['monthHtml'] = $monthHtml;
  13065. $data ['year'] = $year;
  13066. $data ['month'] = $month;
  13067. $data ['nature'] = $nature;
  13068. $data ['aiList'] = $aiList;
  13069. $data ['memu'] = "receipt";
  13070. $data ['staff'] = $this->staff;
  13071. $data ['receiptMemu'] = 'companyCategoryCollect';
  13072. $data ['verifyId'] = $this->verifyId;
  13073. $data ['executeId'] = $this->executeId;
  13074. $this->render ( "/admin/staffCollectMonthDetail", $data );
  13075. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13076. }
  13077. function staffCollectMonthDetail2() {
  13078. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13079. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13080. if (! $year)
  13081. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13082. if (! $month)
  13083. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13084. Doo::loadModel ( 'staff' );
  13085. $staff = new staff ();
  13086. Doo::loadModel ( "receiptDetail" );
  13087. $receiptDetail = new receiptDetail ();
  13088. Doo::loadModel ( 'accountItem' );
  13089. $accountItem = new accountItem ();
  13090. Doo::loadModel ( 'statistics' );
  13091. $statistics = new statistics ();
  13092. Doo::loadModel ( 'L_category' );
  13093. $lCategory = new L_category ();
  13094. $staffList = $staff->find ( array (
  13095. 'where' => 'username!="admin"',
  13096. 'asArray' => true
  13097. ) );
  13098. $categoryList = $staff->find ( array (
  13099. 'select' => 'COUNT(*) as count,cid,category',
  13100. 'where' => 'username !="admin"',
  13101. 'groupby' => 'cid',
  13102. 'asArray' => true
  13103. ) );
  13104. $list = array ();
  13105. foreach ( $categoryList as $vlu ) {
  13106. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  13107. $r1 = 0;
  13108. $r2 = 0;
  13109. $r3 = 0;
  13110. $r4 = 0;
  13111. $r5 = 0;
  13112. $r6 = 0;
  13113. $r7 = 0;
  13114. $r8 = 0;
  13115. $r9 = 0;
  13116. $r10 = 0;
  13117. $r11 = 0;
  13118. $r12 = 0;
  13119. $r13 = 0;
  13120. $r14 = 0;
  13121. $r15 = 0;
  13122. $c1 = 0;
  13123. $c2 = 0;
  13124. $c3 = 0;
  13125. $c4 = 0;
  13126. $c5 = 0;
  13127. $c6 = 0;
  13128. $p1 = 0;
  13129. $p2 = 0;
  13130. $p3 = 0;
  13131. $p4 = 0;
  13132. $p5 = 0;
  13133. $p6 = 0;
  13134. $p7 = 0;
  13135. $p8 = 0;
  13136. $p9 = 0;
  13137. $t1 = 0;
  13138. $t2 = 0;
  13139. $t3 = 0;
  13140. $t4 = 0;
  13141. $t5 = 0;
  13142. $s1 = 0;
  13143. $m1 = 0;
  13144. foreach ( $staffList as $value ) {
  13145. if ($vlu ['cid'] == $value ['cid']) {
  13146. $receiptCollectList = $receiptDetail->find ( array (
  13147. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13148. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13149. 'groupby' => 'item,Month(date),itemCategory',
  13150. 'asArray' => true
  13151. ) );
  13152. if (! empty ( $receiptCollectList )) {
  13153. $receiptL = array (
  13154. '日常相关费用' => array (),
  13155. '差旅相关费用' => array (),
  13156. '培训班费用' => array (),
  13157. '其他' => array ()
  13158. );
  13159. $html = "";
  13160. $psum = 0;
  13161. $item = array (
  13162. '市内交通费',
  13163. '市内出租费',
  13164. '办事处房租',
  13165. '电话费',
  13166. '水费',
  13167. '电费',
  13168. '办公费用',
  13169. '邮寄费',
  13170. '其他费用',
  13171. '车辆费用',
  13172. '广告费',
  13173. '团队建设费',
  13174. '物业管理费',
  13175. '宽带费'
  13176. );
  13177. foreach ( $item as $va ) {
  13178. $falg = true;
  13179. foreach ( $receiptCollectList as $v ) {
  13180. if ($v ['itemCategory'] == '日常相关费用') {
  13181. if ($v ['item'] == $va) {
  13182. if ($va == '市内交通费')
  13183. $r1 += $v ['price'];
  13184. if ($va == '市内出租费')
  13185. $r2 += $v ['price'];
  13186. if ($va == '办事处房租')
  13187. $r3 += $v ['price'];
  13188. if ($va == '电话费')
  13189. $r4 += $v ['price'];
  13190. if ($va == '水费')
  13191. $r5 += $v ['price'];
  13192. if ($va == '电费')
  13193. $r6 += $v ['price'];
  13194. if ($va == '办公费用')
  13195. $r7 += $v ['price'];
  13196. if ($va == '邮寄费')
  13197. $r8 += $v ['price'];
  13198. if ($va == '其他费用')
  13199. $r9 += $v ['price'];
  13200. if ($va == '车辆费用')
  13201. $r10 += $v ['price'];
  13202. if ($va == '广告费')
  13203. $r11 += $v ['price'];
  13204. if ($va == '团队建设费')
  13205. $r13 += $v ['price'];
  13206. if ($va == '物业管理费')
  13207. $r14 += $v ['price'];
  13208. if ($va == '宽带费')
  13209. $r15 += $v ['price'];
  13210. $psum += $v ['price'];
  13211. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13212. $falg = false;
  13213. break;
  13214. }
  13215. }
  13216. }
  13217. if ($falg)
  13218. $html .= '<td class="taR">-</td>';
  13219. }
  13220. $r12 += $psum;
  13221. if (! empty ( $psum ))
  13222. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13223. else
  13224. $psum = '<td class="colGreen taR">-</td>';
  13225. $receiptL ['日常相关费用'] = $psum . $html;
  13226. /* ----------------------------------- */
  13227. $html = "";
  13228. $psum = 0;
  13229. $item = array (
  13230. '往来交通费',
  13231. '市内交通费',
  13232. '出差住宿费',
  13233. '出差补助',
  13234. '其他费用'
  13235. );
  13236. foreach ( $item as $va ) {
  13237. $falg = true;
  13238. foreach ( $receiptCollectList as $v ) {
  13239. if ($v ['itemCategory'] == '差旅相关费用') {
  13240. if ($v ['item'] == $va) {
  13241. if ($va == '往来交通费')
  13242. $c1 += $v ['price'];
  13243. if ($va == '市内交通费')
  13244. $c2 += $v ['price'];
  13245. if ($va == '出差住宿费')
  13246. $c3 += $v ['price'];
  13247. if ($va == '出差补助')
  13248. $c4 += $v ['price'];
  13249. if ($va == '其他费用')
  13250. $c5 += $v ['price'];
  13251. $psum += $v ['price'];
  13252. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13253. $falg = false;
  13254. break;
  13255. }
  13256. }
  13257. }
  13258. if ($falg)
  13259. $html .= '<td class="taR">-</td>';
  13260. }
  13261. $c6 += $psum;
  13262. if (! empty ( $psum ))
  13263. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13264. else
  13265. $psum = '<td class="colGreen taR">-</td>';
  13266. $receiptL ['差旅相关费用'] = $psum . $html;
  13267. /* ------------------------------------- */
  13268. $html = "";
  13269. $psum = 0;
  13270. $item = array (
  13271. '场租费',
  13272. '薪酬',
  13273. '住宿费',
  13274. '交通费',
  13275. '餐饮费',
  13276. '办公费',
  13277. '公关费',
  13278. '其他'
  13279. );
  13280. foreach ( $item as $va ) {
  13281. $falg = true;
  13282. foreach ( $receiptCollectList as $v ) {
  13283. if ($v ['itemCategory'] == '培训班费用') {
  13284. if ($v ['item'] == $va) {
  13285. if ($va == '场租费')
  13286. $p1 += $v ['price'];
  13287. if ($va == '薪酬')
  13288. $p2 += $v ['price'];
  13289. if ($va == '住宿费')
  13290. $p3 += $v ['price'];
  13291. if ($va == '交通费')
  13292. $p4 += $v ['price'];
  13293. if ($va == '餐饮费')
  13294. $p5 += $v ['price'];
  13295. if ($va == '办公费')
  13296. $p6 += $v ['price'];
  13297. if ($va == '公关费')
  13298. $p7 += $v ['price'];
  13299. if ($va == '其他')
  13300. $p8 += $v ['price'];
  13301. $psum += $v ['price'];
  13302. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13303. $falg = false;
  13304. break;
  13305. }
  13306. }
  13307. }
  13308. if ($falg)
  13309. $html .= '<td class="taR">-</td>';
  13310. }
  13311. $p9 += $psum;
  13312. if (! empty ( $psum ))
  13313. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13314. else
  13315. $psum = '<td class="colGreen taR">-</td>';
  13316. $receiptL ['培训班费用'] = $psum . $html;
  13317. /* ------------------------------------- */
  13318. $html = "";
  13319. $psum = 0;
  13320. $item = array (
  13321. '公关费',
  13322. '广告费',
  13323. '借款',
  13324. '可自加费用'
  13325. );
  13326. foreach ( $item as $va ) {
  13327. $falg = true;
  13328. foreach ( $receiptCollectList as $v ) {
  13329. if ($v ['itemCategory'] == '其他') {
  13330. if ($v ['item'] == $va) {
  13331. if ($va == '公关费')
  13332. $t1 += $v ['price'];
  13333. if ($va == '广告费')
  13334. $t2 += $v ['price'];
  13335. if ($va == '借款')
  13336. $t3 += $v ['price'];
  13337. if ($va == '可自加费用')
  13338. $t4 += $v ['price'];
  13339. $psum += $v ['price'];
  13340. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13341. $falg = false;
  13342. break;
  13343. }
  13344. }
  13345. }
  13346. if ($falg)
  13347. $html .= '<td class="taR">-</td>';
  13348. }
  13349. $t5 += $psum;
  13350. if (! empty ( $psum ))
  13351. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13352. else
  13353. $psum = '<td class="colGreen taR">-</td>';
  13354. $receiptL ['其他'] = $psum . $html;
  13355. /* ------------------------------------- */
  13356. $html = "";
  13357. $psum = 0;
  13358. foreach ( $receiptCollectList as $v ) {
  13359. if ($v ['itemCategory'] == '报销金额调整') {
  13360. if (! empty ( $v ['price'] )) {
  13361. $psum += $v ['price'];
  13362. }
  13363. }
  13364. }
  13365. $s1 += $psum;
  13366. if (! empty ( $psum ))
  13367. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  13368. else
  13369. $psum = '<td class="taR colOrange">-</td>';
  13370. $receiptL ['报销金额调整'] = $psum . $html;
  13371. } else {
  13372. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13373. <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>';
  13374. $receiptL ['差旅相关费用'] = '<td class="colGreen 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. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13378. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13379. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13380. }
  13381. $monthStaffPrice = $receiptDetail->find ( array (
  13382. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13383. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13384. 'asArray' => true
  13385. ) );
  13386. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  13387. $m1 += $monthStaffPrice [0] ['price'];
  13388. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13389. } else
  13390. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13391. $list [$value ['username']] = $receiptL;
  13392. }
  13393. }
  13394. $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>
  13395. <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>
  13396. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  13397. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  13398. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  13399. $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>
  13400. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  13401. $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>';
  13402. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13403. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13404. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13405. }
  13406. $data ['list'] = $list;
  13407. $receiptCollectList = $receiptDetail->find ( array (
  13408. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13409. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13410. 'groupby' => 'item,Month(date),itemCategory',
  13411. 'asArray' => true
  13412. ) );
  13413. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  13414. // statistics html
  13415. $stList = $statistics->getOne ( array (
  13416. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13417. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13418. 'groupby' => 'Month(date)',
  13419. 'asArray' => true
  13420. ) );
  13421. if (empty ( $stList ))
  13422. $stList = array (
  13423. 'rePrice' => 0,
  13424. 'agPrice' => 0
  13425. );
  13426. $data ['stList'] = array (
  13427. 'rePrice' => $stList ['rePrice'],
  13428. 'agPrice' => $stList ['agPrice'],
  13429. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13430. );
  13431. $monthHtml = "";
  13432. for($i = 1; $i <= 12; $i ++) {
  13433. if ($i == $month)
  13434. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13435. else
  13436. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13437. }
  13438. $data ['monthHtml'] = $monthHtml;
  13439. $data ['year'] = $year;
  13440. $data ['month'] = $month;
  13441. $data ['memu'] = "receipt";
  13442. $data ['staff'] = $this->staff;
  13443. $data ['receiptMemu'] = 'companyCategoryCollect';
  13444. $data ['verifyId'] = $this->verifyId;
  13445. $data ['executeId'] = $this->executeId;
  13446. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  13447. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13448. }
  13449. /**
  13450. * 用户报销单列表
  13451. */
  13452. function receiptStatisticsStaffDetail() {
  13453. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13454. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13455. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13456. Doo::loadModel ( "receipt" );
  13457. $receipt = new receipt ();
  13458. Doo::loadModel ( "receiptDetail" );
  13459. $receiptDetail = new receiptDetail ();
  13460. Doo::loadModel ( 'staff' );
  13461. $staff = new staff ();
  13462. Doo::loadModel ( 'accountItem' );
  13463. $accountItem = new accountItem ();
  13464. Doo::loadModel ( 'statistics' );
  13465. $statistics = new statistics ();
  13466. if (! empty ( $username )) {
  13467. $username = addslashes ( urldecode ( $username ) );
  13468. $staffDetail = $staff->getStaffByName ( $username );
  13469. if (empty ( $staffDetail ))
  13470. die ( 'illegal request' );
  13471. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  13472. $itemList = $accountItem->getAccountItem ();
  13473. $itemHtml = '';
  13474. $categoryHtml = '';
  13475. $itemKeyList = array_keys ( $itemList );
  13476. $revisePrice = 0;
  13477. // 报销单内容详情
  13478. foreach ( $list as $key => $value ) {
  13479. $accountItemList = json_decode ( $value ['accountItem'], true );
  13480. $list [$key] ['accountItemList'] = $accountItemList;
  13481. $receiptItemHtml = '';
  13482. foreach ( $itemKeyList as $v ) {
  13483. if ($v == '日常相关费用')
  13484. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  13485. elseif ($v == '差旅相关费用')
  13486. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  13487. elseif ($v == '培训班费用')
  13488. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  13489. elseif ($v == '内部培训费用'){
  13490. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  13491. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  13492. }else{
  13493. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  13494. }
  13495. }elseif ($v == '其他')
  13496. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  13497. foreach ( $itemList [$v] as $ke => $va ) {
  13498. $falg = true;
  13499. if (! empty ( $accountItemList [$v] )) {
  13500. foreach ( $accountItemList [$v] as $ve ) {
  13501. if ($va ['name'] == $ve ['name']) {
  13502. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  13503. $falg = false;
  13504. break;
  13505. }
  13506. }
  13507. }
  13508. if ($falg)
  13509. $receiptItemHtml .= '<td class="taR"></td>';
  13510. }
  13511. }
  13512. // 金额调整和费用查看
  13513. $revisePrice += $value ['revisePrice'];
  13514. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  13515. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  13516. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  13517. }
  13518. // 报销单合计
  13519. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  13520. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  13521. $receiptTotalHtml = '';
  13522. // 报销单项目抬头
  13523. foreach ( $itemKeyList as $value ) {
  13524. $count = count ( $itemList [$value] ) + 1;
  13525. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13526. $categoryHtml .= '<th class="taC">合计</th>';
  13527. $sumfalg=true;
  13528. foreach ( $rtl as $rtlValue ) {
  13529. if ($rtlValue ['itemCategory'] == $value) {
  13530. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13531. $sumfalg=false;
  13532. break;
  13533. }
  13534. }
  13535. if ($sumfalg)
  13536. $receiptTotalHtml .= '<th></th>';
  13537. foreach ( $itemList [$value] as $k => $v ) {
  13538. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13539. // 合计
  13540. $falg = true;
  13541. foreach ( $receiptTotalList as $ve ) {
  13542. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13543. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13544. $falg = false;
  13545. break;
  13546. }
  13547. }
  13548. if ($falg)
  13549. $receiptTotalHtml .= '<th></th>';
  13550. }
  13551. }
  13552. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13553. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13554. if (empty ( $stList ))
  13555. $stList = array (
  13556. 'rePrice' => 0,
  13557. 'agPrice' => 0
  13558. );
  13559. $data ['stList'] = array (
  13560. 'rePrice' => $stList ['rePrice'],
  13561. 'agPrice' => $stList ['agPrice'],
  13562. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13563. );
  13564. $monthHtml = "";
  13565. for($i = 1; $i <= 12; $i ++) {
  13566. if ($i == $month)
  13567. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13568. else
  13569. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13570. }
  13571. $data ['username'] = urlencode ( $username );
  13572. $data ['usernameEN'] = $username;
  13573. $data ['monthHtml'] = $monthHtml;
  13574. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13575. $data ['list'] = $list;
  13576. $data ['categoryHtml'] = $categoryHtml;
  13577. $data ['itemHtml'] = $itemHtml;
  13578. $data ['itemList'] = $itemList;
  13579. $data ['year'] = $year;
  13580. $data ['month'] = $month;
  13581. $data ['memu'] = "receipt";
  13582. $data ['staff'] = $this->staff;
  13583. $data ['receiptMemu'] = 'companyCategoryCollect';
  13584. $data ['verifyId'] = $this->verifyId;
  13585. $data ['executeId'] = $this->executeId;
  13586. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13587. }
  13588. die ( 'illegal request' );
  13589. }
  13590. function companyMonthCollectDetail() {
  13591. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13592. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13593. if (! $year)
  13594. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13595. if (! $month)
  13596. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13597. Doo::loadModel ( 'staff' );
  13598. $staff = new staff ();
  13599. Doo::loadModel ( "receiptDetail" );
  13600. $receiptDetail = new receiptDetail ();
  13601. Doo::loadModel ( 'accountItem' );
  13602. $accountItem = new accountItem ();
  13603. Doo::loadModel ( 'statistics' );
  13604. $statistics = new statistics ();
  13605. Doo::loadModel ( 'L_category' );
  13606. $lCategory = new L_category ();
  13607. $staffList = $staff->find ( array (
  13608. 'where' => 'username!="admin"',
  13609. 'asArray' => true
  13610. ) );
  13611. $categoryList = $lCategory->find ( array (
  13612. 'asArray' => true
  13613. ) );
  13614. $aiList=$accountItem->getAccountItem();
  13615. $list = array ();
  13616. foreach ( $categoryList as $value ) {
  13617. $receiptCollectList = $receiptDetail->find ( array (
  13618. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13619. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13620. 'groupby' => 'item,Month(pastDate),itemCategory',
  13621. 'asArray' => true
  13622. ) );
  13623. if (! empty ( $receiptCollectList )) {
  13624. $receiptL = array (
  13625. '日常相关费用' => array (),
  13626. '差旅相关费用' => array (),
  13627. '内部培训费用' => array (),
  13628. '培训班费用' => array (),
  13629. '其他' => array ()
  13630. );
  13631. $html = "";
  13632. $psum = 0;
  13633. foreach ( $aiList[$this->AGENCY] as $va ) {
  13634. $falg = true;
  13635. foreach ( $receiptCollectList as $v ) {
  13636. if ($v ['itemCategory'] == $this->AGENCY) {
  13637. if ($v ['item'] == $va['name']) {
  13638. $psum += $v ['price'];
  13639. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13640. $falg = false;
  13641. break;
  13642. }
  13643. }
  13644. }
  13645. if ($falg)
  13646. $html .= '<td class="taR">-</td>';
  13647. }
  13648. if (! empty ( $psum ))
  13649. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13650. else
  13651. $psum = '<td class="colGreen taR">-</td>';
  13652. $receiptL [$this->AGENCY] = $psum . $html;
  13653. /* ----------------------------------- */
  13654. $html = "";
  13655. $psum = 0;
  13656. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13657. $falg = true;
  13658. foreach ( $receiptCollectList as $v ) {
  13659. if ($v ['itemCategory'] == $this->TRAVEL) {
  13660. if ($v ['item'] == $va['name']) {
  13661. $psum += $v ['price'];
  13662. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13663. $falg = false;
  13664. break;
  13665. }
  13666. }
  13667. }
  13668. if ($falg)
  13669. $html .= '<td class="taR">-</td>';
  13670. }
  13671. if (! empty ( $psum ))
  13672. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13673. else
  13674. $psum = '<td class="colGreen taR">-</td>';
  13675. $receiptL [$this->TRAVEL] = $psum . $html;
  13676. /* ------------------------------------- */
  13677. $html = "";
  13678. $psum = 0;
  13679. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13680. $falg = true;
  13681. foreach ( $receiptCollectList as $v ) {
  13682. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13683. if ($v ['item'] == $va['name']) {
  13684. $psum += $v ['price'];
  13685. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13686. $falg = false;
  13687. break;
  13688. }
  13689. }
  13690. }
  13691. if ($falg)
  13692. $html .= '<td class="taR">-</td>';
  13693. }
  13694. if (! empty ( $psum ))
  13695. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13696. else
  13697. $psum = '<td class="colGreen taR">-</td>';
  13698. $receiptL [$this->INTTRAIN] = $psum . $html;
  13699. /* ------------------------------------- */
  13700. $html = "";
  13701. $psum = 0;
  13702. foreach ( $aiList[$this->TRAIN] as $va ) {
  13703. $falg = true;
  13704. foreach ( $receiptCollectList as $v ) {
  13705. if ($v ['itemCategory'] == $this->TRAIN) {
  13706. if ($v ['item'] == $va['name']) {
  13707. $psum += $v ['price'];
  13708. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13709. $falg = false;
  13710. break;
  13711. }
  13712. }
  13713. }
  13714. if ($falg)
  13715. $html .= '<td class="taR">-</td>';
  13716. }
  13717. if (! empty ( $psum ))
  13718. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13719. else
  13720. $psum = '<td class="colGreen taR">-</td>';
  13721. $receiptL [$this->TRAIN] = $psum . $html;
  13722. /* ------------------------------------- */
  13723. $html = "";
  13724. $psum = 0;
  13725. foreach ( $aiList[$this->OTHER] as $va ) {
  13726. $falg = true;
  13727. foreach ( $receiptCollectList as $v ) {
  13728. if ($v ['itemCategory'] == $this->OTHER) {
  13729. if ($v ['item'] == $va['name']) {
  13730. $psum += $v ['price'];
  13731. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13732. $falg = false;
  13733. break;
  13734. }
  13735. }
  13736. }
  13737. if ($falg)
  13738. $html .= '<td class="taR">-</td>';
  13739. }
  13740. if (! empty ( $psum ))
  13741. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13742. else
  13743. $psum = '<td class="colGreen taR">-</td>';
  13744. $receiptL [$this->OTHER] = $psum . $html;
  13745. /* ------------------------------------- */
  13746. $html = "";
  13747. $psum = 0;
  13748. foreach ( $receiptCollectList as $v ) {
  13749. if ($v ['itemCategory'] == '报销金额调整') {
  13750. if (! empty ( $v ['price'] ))
  13751. $psum += $v ['price'];
  13752. }
  13753. }
  13754. if (! empty ( $psum ))
  13755. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13756. else
  13757. $psum = '<td class="taR colOrange">-</td>';
  13758. $receiptL ['报销金额调整'] = $psum . $html;
  13759. } else {
  13760. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13761. foreach ( $aiList[$this->AGENCY] as $va ) {
  13762. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13763. }
  13764. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13765. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13766. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13767. }
  13768. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13769. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13770. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13771. }
  13772. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13773. foreach ( $aiList[$this->TRAIN] as $va ) {
  13774. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13775. }
  13776. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13777. foreach ( $aiList[$this->OTHER] as $va ) {
  13778. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13779. }
  13780. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13781. }
  13782. $monthStaffPrice = $receiptDetail->find ( array (
  13783. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13784. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13785. 'asArray' => true
  13786. ) );
  13787. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13788. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13789. else
  13790. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13791. $list [$value ['title']] = $receiptL;
  13792. }
  13793. $data ['list'] = $list;
  13794. $receiptCollectList = $receiptDetail->find ( array (
  13795. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13796. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13797. 'groupby' => 'item,Month(pastDate),itemCategory',
  13798. 'asArray' => true
  13799. ) );
  13800. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13801. //print_r($data['monthPriceHtml']);
  13802. // foreach ($data['monthPriceHtml'] as $value){
  13803. // echo $value;
  13804. // }
  13805. // die;
  13806. // statistics html
  13807. $stList = $statistics->getOne ( array (
  13808. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13809. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13810. 'groupby' => 'Month(date)',
  13811. 'asArray' => true
  13812. ) );
  13813. if (empty ( $stList ))
  13814. $stList = array (
  13815. 'rePrice' => 0,
  13816. 'agPrice' => 0
  13817. );
  13818. $data ['stList'] = array (
  13819. 'rePrice' => $stList ['rePrice'],
  13820. 'agPrice' => $stList ['agPrice'],
  13821. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13822. );
  13823. $monthHtml = "";
  13824. for($i = 1; $i <= 12; $i ++) {
  13825. if ($i == $month)
  13826. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13827. else
  13828. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13829. }
  13830. $data ['aiList'] = $aiList;
  13831. $dateHtml = "";
  13832. $now = date ( "Y" );
  13833. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  13834. if ($YEARD <= $now) {
  13835. $dateHtml .= '<option ';
  13836. if ($year == $YEARD) {
  13837. $dateHtml .= 'selected ';
  13838. }
  13839. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  13840. }
  13841. }
  13842. $data ['dateHtml'] = $dateHtml;
  13843. $data ['monthHtml'] = $monthHtml;
  13844. $data ['year'] = $year;
  13845. $data ['month'] = $month;
  13846. $data ['memu'] = "receipt";
  13847. $data ['staff'] = $this->staff;
  13848. $data ['receiptMemu'] = 'companyCategoryCollect';
  13849. $data ['verifyId'] = $this->verifyId;
  13850. $data ['executeId'] = $this->executeId;
  13851. $this->render ( "/admin/companyMonthCollectDetail", $data );
  13852. }
  13853. function staffCollectDetail() {
  13854. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  13855. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13856. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  13857. if (! $staffname) {
  13858. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  13859. $staffname = urldecode ( $staffname );
  13860. }
  13861. Doo::loadModel ( 'staff' );
  13862. $staff = new staff ();
  13863. Doo::loadModel ( "receiptDetail" );
  13864. $receiptDetail = new receiptDetail ();
  13865. Doo::loadModel ( 'accountItem' );
  13866. $accountItem = new accountItem ();
  13867. Doo::loadModel ( 'statistics' );
  13868. $statistics = new statistics ();
  13869. Doo::loadModel ( 'L_category' );
  13870. $lCategory = new L_category ();
  13871. Doo::loadModel ( "receiptAuthorityManage" );
  13872. $receiptAuthorityManage = new receiptAuthorityManage ();
  13873. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  13874. $cidList = array ();
  13875. foreach ( $imcStaff as $key => $value ) {
  13876. array_push ( $cidList, $value ['cid'] );
  13877. }
  13878. $cidString = implode ( ',', $cidList );
  13879. $staffList = $staff->find ( array (
  13880. 'where' => ' cid in (' . $cidString . ')',
  13881. 'asArray' => true
  13882. ) );
  13883. $stHtml = '';
  13884. $stTitle = "";
  13885. $staffId = 0;
  13886. $cid = 0;
  13887. $ocid = 0;
  13888. foreach ( $staffList as $value ) {
  13889. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  13890. $stTitle = $value ['category'] . '-' . $value ['username'];
  13891. $staffId = $value ['sid'];
  13892. $cid = $value ['cid'];
  13893. $ocid = $value ['cid'];
  13894. if (! empty ( $value ['othercid'] ))
  13895. $cid = $value ['cid'] . ',' . $value ['othercid'];
  13896. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13897. } elseif ($value ['username'] != 'admin')
  13898. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  13899. }
  13900. $data ['lCategoryHtml'] = $lCategory->find ( array (
  13901. 'where' => 'cid in(' . $cid . ')',
  13902. 'asArray' => true
  13903. ) );
  13904. if (empty ( $pcid ))
  13905. $pcid = $ocid;
  13906. $data ['ocid'] = $pcid;
  13907. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  13908. $this->showCache ( $path );
  13909. //
  13910. $receiptCollectList = $receiptDetail->find ( array (
  13911. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13912. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13913. 'groupby' => 'item,Month(pastDate),itemCategory',
  13914. 'asArray' => true
  13915. ) );
  13916. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  13917. // print_r($receiptCollectList);
  13918. $accountList = $accountItem->find ( array (
  13919. 'asArray' => true
  13920. ) );
  13921. // create CollectDetail HTML
  13922. $collectHtml = array ();
  13923. foreach ( $accountList as $key => $value ) {
  13924. $html = "";
  13925. $asum = 0;
  13926. for($i = 1; $i <= 12; $i ++) {
  13927. $falg = true;
  13928. foreach ( $receiptCollectList as $v ) {
  13929. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  13930. if ($v ['item'] == '可自加费用') {
  13931. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  13932. }
  13933. $asum += $v ['price'];
  13934. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13935. $falg = false;
  13936. break;
  13937. }
  13938. }
  13939. if ($falg)
  13940. $html .= '<td class="taR">-</td>';
  13941. }
  13942. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  13943. $collectHtml [$value ['category']] [$value ['name']] = $html;
  13944. }
  13945. $data ['collectHtml'] = $collectHtml;
  13946. // print_r($collectHtml);
  13947. // create Adjustment price html
  13948. $receiptCollectList = $receiptDetail->find ( array (
  13949. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  13950. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  13951. 'groupby' => 'itemCategory,Month(pastDate)',
  13952. 'asArray' => true
  13953. ) );
  13954. $adjustment = array ();
  13955. $collectArray = array (
  13956. '日常相关费用' => array (),
  13957. '差旅相关费用' => array (),
  13958. '培训班费用' => array (),
  13959. '内部培训费用'=>array(),
  13960. '其他' => array ()
  13961. );
  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. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  13971. array_push ( $collectArray ['其他'], $collectHtml );
  13972. $data ['collectArray'] = $collectArray;
  13973. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  13974. array_push ( $adjustment, $collectHtml );
  13975. $data ['adjustment'] = $adjustment;
  13976. // total price html
  13977. $collectHtml = "";
  13978. $total = 0;
  13979. for($i = 1; $i <= 12; $i ++) {
  13980. $sumPrice = 0;
  13981. foreach ( $receiptCollectList as $key => $value ) {
  13982. if ($value ['month'] == $i) {
  13983. $sumPrice += $value ['price'];
  13984. }
  13985. }
  13986. if ($sumPrice == 0)
  13987. $collectHtml .= '<td class="taR">-</td>';
  13988. else
  13989. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  13990. $total += $sumPrice;
  13991. }
  13992. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  13993. // statistics html
  13994. $stList = $statistics->statisticsByYear ( $year, $staffId );
  13995. if (empty ( $stList ))
  13996. $stList = array (
  13997. 'rePrice' => 0,
  13998. 'agPrice' => 0
  13999. );
  14000. $data ['stList'] = array (
  14001. 'rePrice' => $stList ['rePrice'],
  14002. 'agPrice' => $stList ['agPrice'],
  14003. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  14004. );
  14005. $data ['totalPrice'] = $collectHtml;
  14006. $data ['totalYear'] = $total;
  14007. $data ['stHtml'] = $stHtml;
  14008. $data ['year'] = $year;
  14009. $data ['stTitle'] = $stTitle;
  14010. $data ['staffname'] = urlencode ( $staffname );
  14011. $data ['memu'] = "receipt";
  14012. $data ['staff'] = $this->staff;
  14013. $data ['receiptMemu'] = 'companyCategoryCollect';
  14014. $data ['verifyId'] = $this->verifyId;
  14015. $data ['executeId'] = $this->executeId;
  14016. if ($year < date ( "Y" )) {
  14017. Doo::loadModel ( 'receipt' );
  14018. $receipt = new receipt ();
  14019. $receiptList = $receipt->find ( array (
  14020. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  14021. 'asArray' => true
  14022. ) );
  14023. if (empty ( $receiptList )) { // generated files
  14024. ob_start ();
  14025. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  14026. $this->cacheFile ( $path );
  14027. die ();
  14028. }
  14029. }
  14030. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  14031. }
  14032. function BUGFLAG() {
  14033. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  14034. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  14035. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  14036. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  14037. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  14038. if (empty ( $status ))
  14039. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  14040. $page_size = 12;
  14041. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  14042. $vidList = array ();
  14043. $button = 0;
  14044. Doo::loadModel ( 'verify' );
  14045. $verify = new verify ();
  14046. Doo::loadModel ( 'receipt' );
  14047. $receipt = new receipt ();
  14048. Doo::loadModel ( 'staff' );
  14049. $staff = new staff ();
  14050. Doo::loadModel ( 'L_category' );
  14051. $Lcategory = new L_category ();
  14052. $dateCondition = " and Year(date) =" . $year;
  14053. if (! empty ( $month ))
  14054. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  14055. $categoryList = $Lcategory->find ( array (
  14056. 'asArray' => true
  14057. ) );
  14058. $staffList = $staff->find ( array (
  14059. 'where' => 'cid=' . $cid,
  14060. 'asArray' => true
  14061. ) );
  14062. $cateCondition = "";
  14063. $staffCondition = "";
  14064. $approvalCondition = "";
  14065. if (! empty ( $cid ))
  14066. $cateCondition = ' and cid=' . $cid;
  14067. if (! empty ( $sid )) {
  14068. $staffCondition = ' and staff=' . $sid;
  14069. $cateCondition = "";
  14070. }
  14071. $approvalCondition = " and status=" . $status;
  14072. if ($status == 2) {
  14073. // 查找角色审批人
  14074. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  14075. }
  14076. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  14077. $approvalCondition = ' and status=2 ';
  14078. }
  14079. if ($status == 1) {
  14080. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  14081. }
  14082. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  14083. $pageinfo ['page'] = array (
  14084. 'previous' => ''
  14085. );
  14086. if ($status == 0) {
  14087. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  14088. $receiptList = $receipt->find ( array (
  14089. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  14090. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  14091. 'desc' => 'rid',
  14092. 'asArray' => true
  14093. ) );
  14094. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  14095. } else
  14096. $receiptList = $receipt->find ( array (
  14097. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  14098. 'desc' => 'rid',
  14099. 'asArray' => true
  14100. ) );
  14101. $rLRes = $receipt->find ( array (
  14102. '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,
  14103. 'desc' => 'rid',
  14104. 'asArray' => true
  14105. ) );
  14106. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  14107. // print_r($pageinfo);
  14108. $Locate = 0;
  14109. foreach ( $receiptList as $key => $value ) {
  14110. $receiptList [$key] ['Locate'] = $Locate;
  14111. $Locate ++;
  14112. $receiptList [$key] ['reviseDetail'] = array ();
  14113. if (! empty ( $value ['reviseDetail'] ))
  14114. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  14115. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  14116. $categoryDetil = $Lcategory->getOne ( array (
  14117. 'where' => 'cid=' . $value ['cid'],
  14118. 'asArray' => true
  14119. ) );
  14120. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  14121. $verifyList = $verify->getOne ( array (
  14122. 'where' => 'vid=' . $value ['verify'],
  14123. 'asArray' => true
  14124. ) );
  14125. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  14126. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  14127. foreach ( $verifyList as $k => $v ) {
  14128. // init verifyStaff
  14129. $verifyList [$k] ['date'] = "";
  14130. $verifyList [$k] ['opinion'] = "";
  14131. $verifyList [$k] ['status'] = "";
  14132. if (empty ( $verifyStaff )) {
  14133. $verifyList [$k] ['date'] = "";
  14134. $verifyList [$k] ['opinion'] = "";
  14135. if ($v [0] == $this->staff [0] ['sid']) {
  14136. $verifyList [$k] ['status'] = 4;
  14137. $button = 4;
  14138. }
  14139. } else {
  14140. $flag = true;
  14141. foreach ( $verifyStaff as $m => $u ) {
  14142. if ($v [0] == $m) {
  14143. $verifyList [$k] ['date'] = $u ['date'];
  14144. $verifyList [$k] ['opinion'] = $u ['opinion'];
  14145. $verifyList [$k] ['status'] = $u ['status'];
  14146. $flag = false;
  14147. break;
  14148. }
  14149. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  14150. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  14151. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  14152. }
  14153. if ($flag) { // 检测可编辑
  14154. if ($v [0] == $this->staff [0] ['sid']) {
  14155. $verifyList [$k] ['status'] = 4;
  14156. $button = 4;
  14157. }
  14158. }
  14159. }
  14160. }
  14161. $receiptList [$key] ['verifyList'] = $verifyList;
  14162. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  14163. 'where' => 'sid=' . $value ['staff'],
  14164. 'asArray' => true
  14165. ) );
  14166. $receiptList [$key] ['button'] = $button;
  14167. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  14168. }
  14169. // print_r($receiptList);die;
  14170. // $data['verifyDetail']=$verifyDetail;
  14171. $mothHtml = "";
  14172. for($i = 1; $i <= 12; $i ++) {
  14173. if ($month == $i)
  14174. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  14175. else
  14176. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  14177. }
  14178. $data ['mothHtml'] = $mothHtml;
  14179. $data ['page'] = $pageinfo;
  14180. $data ['receiptList'] = $receiptList;
  14181. $data ['receiptApprovalCount'] = count ( $rLRes );
  14182. $data ['status'] = $status;
  14183. $data ['year'] = $year;
  14184. $data ['categoryList'] = $categoryList;
  14185. $data ['staffList'] = $staffList;
  14186. $data ['cid'] = $cid;
  14187. $data ['sid'] = $sid;
  14188. // print_r($receiptList);
  14189. $data ['memu'] = "receipt";
  14190. $data ['staff'] = $this->staff;
  14191. $data ['receiptMemu'] = 'approvalExpenses';
  14192. $data ['verifyId'] = $this->verifyId;
  14193. $data ['executeId'] = $this->executeId;
  14194. $this->render ( "/admin/FALG", $data );
  14195. }
  14196. function ajaxGetReceiptOrder() {
  14197. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  14198. if (! empty ( $receiptOrder )) {
  14199. Doo::loadModel ( 'receipt' );
  14200. $receipt = new receipt ();
  14201. Doo::loadModel ( 'staff' );
  14202. $staff = new staff ();
  14203. $receiptInfo = $receipt->getOne ( array (
  14204. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  14205. 'asArray' => true
  14206. ) );
  14207. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  14208. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  14209. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  14210. </tbody></table><table class="table table table-bordered"><tbody>';
  14211. foreach ( $verifyStaff as $key => $value ) {
  14212. $staffInfo = $staff->getOne ( array (
  14213. 'select' => 'username',
  14214. 'where' => ' sid="' . $key . '"',
  14215. 'asArray' => true
  14216. ) );
  14217. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  14218. }
  14219. $html .= '</tbody></table></div></div>';
  14220. echo json_encode ( array (
  14221. 'status' => 1,
  14222. 'receiptHtml' => $html
  14223. ) );
  14224. die ();
  14225. }
  14226. echo json_encode ( array (
  14227. 'status' => 2,
  14228. 'receiptHtml' => ''
  14229. ) );
  14230. die ();
  14231. }
  14232. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  14233. if (! empty ( $receiptCollectList )) {
  14234. $receiptL = array (
  14235. '日常相关费用' => array (),
  14236. '差旅相关费用' => array (),
  14237. '内部培训费用'=>array(),
  14238. '培训班费用' => array (),
  14239. '其他' => array ()
  14240. );
  14241. $html = "";
  14242. $psum = 0;
  14243. foreach ( $aiList[$this->AGENCY] as $value ) {
  14244. $falg = true;
  14245. foreach ( $receiptCollectList as $v ) {
  14246. if ($v ['itemCategory'] == '日常相关费用') {
  14247. if ($v ['item'] == $value['name']) {
  14248. $psum += $v ['price'];
  14249. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14250. $falg = false;
  14251. break;
  14252. }
  14253. }
  14254. }
  14255. if ($falg)
  14256. $html .= '<td class="taR">-</td>';
  14257. }
  14258. if (! empty ( $psum ))
  14259. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14260. else
  14261. $psum = '<td class="colGreen taR">-</td>';
  14262. $receiptL ['日常相关费用'] = $psum . $html;
  14263. /* ----------------------------------- */
  14264. $html = "";
  14265. $psum = 0;
  14266. foreach ( $aiList[$this->TRAVEL] as $value ) {
  14267. $falg = true;
  14268. foreach ( $receiptCollectList as $v ) {
  14269. if ($v ['itemCategory'] == '差旅相关费用') {
  14270. if ($v ['item'] == $value['name']) {
  14271. $psum += $v ['price'];
  14272. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14273. $falg = false;
  14274. break;
  14275. }
  14276. }
  14277. }
  14278. if ($falg)
  14279. $html .= '<td class="taR">-</td>';
  14280. }
  14281. if (! empty ( $psum ))
  14282. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14283. else
  14284. $psum = '<td class="colGreen taR">-</td>';
  14285. $receiptL ['差旅相关费用'] = $psum . $html;
  14286. /* ----------------------------------- */
  14287. $html = "";
  14288. $psum = 0;
  14289. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  14290. $falg = true;
  14291. foreach ( $receiptCollectList as $v ) {
  14292. if ($v ['itemCategory'] == '内部培训费用') {
  14293. if ($v ['item'] == $value['name']) {
  14294. $psum += $v ['price'];
  14295. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14296. $falg = false;
  14297. break;
  14298. }
  14299. }
  14300. }
  14301. if ($falg)
  14302. $html .= '<td class="taR">-</td>';
  14303. }
  14304. if (! empty ( $psum ))
  14305. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14306. else
  14307. $psum = '<td class="colGreen taR">-</td>';
  14308. $receiptL ['内部培训费用'] = $psum . $html;
  14309. /* ------------------------------------- */
  14310. $html = "";
  14311. $psum = 0;
  14312. foreach ( $aiList[$this->TRAIN] as $value ) {
  14313. $falg = true;
  14314. foreach ( $receiptCollectList as $v ) {
  14315. if ($v ['itemCategory'] == '培训班费用') {
  14316. if ($v ['item'] == $value['name']) {
  14317. $psum += $v ['price'];
  14318. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14319. $falg = false;
  14320. break;
  14321. }
  14322. }
  14323. }
  14324. if ($falg)
  14325. $html .= '<td class="taR">-</td>';
  14326. }
  14327. if (! empty ( $psum ))
  14328. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14329. else
  14330. $psum = '<td class="colGreen taR">-</td>';
  14331. $receiptL ['培训班费用'] = $psum . $html;
  14332. /* ------------------------------------- */
  14333. $html = "";
  14334. $psum = 0;
  14335. foreach ( $aiList[$this->OTHER] as $value ) {
  14336. $falg = true;
  14337. foreach ( $receiptCollectList as $v ) {
  14338. if ($v ['itemCategory'] == '其他') {
  14339. if ($v ['item'] == $value['name']) {
  14340. $psum += $v ['price'];
  14341. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14342. $falg = false;
  14343. break;
  14344. }
  14345. }
  14346. }
  14347. if ($falg)
  14348. $html .= '<td class="taR">-</td>';
  14349. }
  14350. if (! empty ( $psum ))
  14351. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14352. else
  14353. $psum = '<td class="colGreen taR">-</td>';
  14354. $receiptL ['其他'] = $psum . $html;
  14355. /* ------------------------------------- */
  14356. $html = "";
  14357. $psum = 0;
  14358. foreach ( $receiptCollectList as $v ) {
  14359. if ($v ['itemCategory'] == '报销金额调整') {
  14360. if (! empty ( $v ['price'] ))
  14361. $psum += $v ['price'];
  14362. }
  14363. }
  14364. if (! empty ( $psum ))
  14365. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  14366. else
  14367. $psum = '<td class="taR colOrange">-</td>';
  14368. $receiptL ['报销金额调整'] = $psum . $html;
  14369. } else {
  14370. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  14371. foreach ( $aiList[$this->AGENCY] as $va ) {
  14372. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  14373. }
  14374. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  14375. foreach ( $aiList[$this->TRAVEL] as $va ) {
  14376. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  14377. }
  14378. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  14379. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  14380. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  14381. }
  14382. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  14383. foreach ( $aiList[$this->TRAIN] as $va ) {
  14384. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  14385. }
  14386. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  14387. foreach ( $aiList[$this->OTHER] as $va ) {
  14388. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  14389. }
  14390. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  14391. }
  14392. return $receiptL;
  14393. }
  14394. function eMail() {
  14395. Doo::loadModel ( 'staff' );
  14396. $staff = new staff ();
  14397. Doo::loadModel ( 'receipt' );
  14398. $receipt = new receipt ();
  14399. Doo::loadModel ( 'L_category' );
  14400. $Lcategory = new L_category ();
  14401. Doo::loadModel ( "verify" );
  14402. $verify = new verify ();
  14403. $staffList = $staff->find ( array (
  14404. 'asArray' => true
  14405. ) );
  14406. foreach ( $staffList as $key => $value ) {
  14407. if ($value ['username'] != 'admin') {
  14408. // 提交人
  14409. $receiptList = $receipt->find ( array (
  14410. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  14411. 'asArray' => true
  14412. ) );
  14413. if (! empty ( $receiptList )) {
  14414. $html = '<br><div><style></style>
  14415. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  14416. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  14417. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14418. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  14419. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14420. <tbody><tr>
  14421. <td style="padding: 0 40px;" align="left">
  14422. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14423. </td></tr><tr>
  14424. <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>
  14425. </tr>
  14426. </tbody> </table></td> </tr> <tr><td>
  14427. <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">
  14428. <tbody> <tr><td>
  14429. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  14430. 以下报销单完成了审批,等着收款吧:</p>
  14431. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  14432. foreach ( $receiptList as $k => $v ) {
  14433. $category = $Lcategory->getOne ( array (
  14434. 'where' => 'cid=' . $v ['cid'],
  14435. 'asArray' => true
  14436. ) );
  14437. $html .= '
  14438. <tr>
  14439. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14440. <td align="left">
  14441. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  14442. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  14443. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  14444. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  14445. </tr>';
  14446. }
  14447. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  14448. <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>
  14449. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  14450. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  14451. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  14452. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14453. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14454. $receipt = new receipt ();
  14455. $receipt->notice = 1;
  14456. $receipt->update ( array (
  14457. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  14458. ) );
  14459. }
  14460. }
  14461. // 审批人
  14462. $verifyList = $verify->find ( array (
  14463. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  14464. 'asArray' => true
  14465. ) );
  14466. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  14467. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  14468. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14469. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  14470. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14471. <tbody><tr><td style="padding: 0 40px;" align="left">
  14472. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14473. </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>
  14474. </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">
  14475. <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>
  14476. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  14477. foreach ( $verifyList as $k => $v ) {
  14478. $receiptList = $receipt->find ( array (
  14479. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  14480. 'asArray' => true
  14481. ) );
  14482. foreach ( $receiptList as $r => $l ) {
  14483. $category = $Lcategory->getOne ( array (
  14484. 'where' => 'cid=' . $l ['cid'],
  14485. 'asArray' => true
  14486. ) );
  14487. $staffDetile = $staff->getOne ( array (
  14488. 'where' => 'sid=' . $l ['staff'],
  14489. 'asArray' => true
  14490. ) );
  14491. $html .= '
  14492. <tr>
  14493. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14494. <td align="left">
  14495. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  14496. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  14497. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  14498. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  14499. </tr>';
  14500. }
  14501. }
  14502. $html .= '
  14503. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  14504. <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>
  14505. </tr></tbody></table></td></tr></tbody></table></div><br>';
  14506. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  14507. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  14508. // $receipt=new receipt();
  14509. // $receipt->notice=1;
  14510. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  14511. }
  14512. }
  14513. }
  14514. }
  14515. function setWXMsg($rid, $type) {
  14516. Doo::loadModel ( "receipt" );
  14517. $receipt = new receipt ();
  14518. $receiptDetail = $receipt->getOne ( array (
  14519. 'where' => 'rid=' . $rid,
  14520. 'asArray' => true
  14521. ) );
  14522. if (! empty ( $receiptDetail )) {
  14523. Doo::loadModel ( 'staff' );
  14524. $staff = new staff ();
  14525. $staffmsg = $staff->getOne ( array (
  14526. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  14527. 'asArray' => TRUE
  14528. ) );
  14529. if (! empty ( $staffmsg ['wxid'] )) {
  14530. require_once (SITE_PATH . '/protected/class/client.php');
  14531. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  14532. $user = $staffmsg ['wxid'];
  14533. $receiptName = '';
  14534. $msg = '';
  14535. switch ($receiptDetail ['Rtype']) {
  14536. case 0 :
  14537. $receiptName = '报销';
  14538. break;
  14539. case 1 :
  14540. $receiptName = '借款';
  14541. break;
  14542. case 2 :
  14543. $receiptName = '对公汇款';
  14544. break;
  14545. }
  14546. switch ($type) {
  14547. case 1 :
  14548. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14549. break;
  14550. case 2 :
  14551. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14552. break;
  14553. case 3 :
  14554. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14555. break;
  14556. }
  14557. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14558. }
  14559. }
  14560. }
  14561. // Email发送函数
  14562. function SMail($toemail, $subject, $contents) {
  14563. Doo::loadClass ( 'class.phpmailer' );
  14564. $mail = new PHPMailer ();
  14565. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14566. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14567. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14568. $mail->Password = "cDO1GjtY1seH"; // 密码
  14569. $mail->CharSet = "UTF8";
  14570. $mail->SMTPAuth = true;
  14571. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14572. $mail->Mailer = "smtp";
  14573. $mail->Port = 25;
  14574. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14575. $mail->MsgHTML ( $contents );
  14576. $mail->AddAddress ( $toemail );
  14577. $mail->CharSet = "UTF-8";
  14578. return $mail->Send ();
  14579. }
  14580. function h5Upload() {
  14581. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14582. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14583. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14584. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14585. header ( "HTTP/1.1 500 Internal Server Error" );
  14586. echo "POST exceeded maximum allowed size.";
  14587. exit ( 0 );
  14588. }
  14589. // Settings
  14590. $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)
  14591. $upload_name = "Filedata";
  14592. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14593. $extension_whitelist = array (
  14594. "doc",
  14595. "txt",
  14596. "jpg",
  14597. "gif",
  14598. "png"
  14599. ); // Allowed file extensions
  14600. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14601. // Other variables
  14602. $MAX_FILENAME_LENGTH = 260;
  14603. $file_name = "";
  14604. $file_extension = "";
  14605. $uploadErrors = array (
  14606. 0 => "文件上传成功",
  14607. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14608. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14609. 3 => "上传的文件仅为部分文件",
  14610. 4 => "没有文件上传",
  14611. 6 => "缺少临时文件夹"
  14612. );
  14613. $nk = time ();
  14614. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14615. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14616. echo "文件无法保存.";
  14617. exit ( 0 );
  14618. }
  14619. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14620. echo json_encode ( array (
  14621. 'filename' => $file_name,
  14622. 'id' => $nk
  14623. ) );
  14624. exit ( 0 );
  14625. }
  14626. function swfupload() {
  14627. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14628. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14629. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14630. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14631. header ( "HTTP/1.1 500 Internal Server Error" );
  14632. echo "POST exceeded maximum allowed size.";
  14633. exit ( 0 );
  14634. }
  14635. // Settings
  14636. $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)
  14637. $upload_name = "Filedata";
  14638. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14639. $extension_whitelist = array (
  14640. "doc",
  14641. "txt",
  14642. "jpg",
  14643. "gif",
  14644. "png"
  14645. ); // Allowed file extensions
  14646. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14647. // Other variables
  14648. $MAX_FILENAME_LENGTH = 260;
  14649. $file_name = "";
  14650. $file_extension = "";
  14651. $uploadErrors = array (
  14652. 0 => "文件上传成功",
  14653. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14654. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14655. 3 => "上传的文件仅为部分文件",
  14656. 4 => "没有文件上传",
  14657. 6 => "缺少临时文件夹"
  14658. );
  14659. $nk = time ();
  14660. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14661. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14662. echo "文件无法保存.";
  14663. exit ( 0 );
  14664. }
  14665. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14666. echo json_encode ( array (
  14667. 'filename' => $file_name,
  14668. 'id' => $nk
  14669. ) );
  14670. exit ( 0 );
  14671. }
  14672. function _GetFileEXT($filename) {
  14673. $pics = explode ( '.', $filename );
  14674. $num = count ( $pics );
  14675. return $pics [$num - 1];
  14676. }
  14677. /**
  14678. * 获取get或者POST值
  14679. * @param string $name 属性名称
  14680. * @return fixed 值
  14681. */
  14682. function get_args($name) {
  14683. if (isset ( $_GET [$name] )) {
  14684. if (is_array ( $_GET [$name] ))
  14685. return $_GET [$name];
  14686. else
  14687. return addslashes ( $_GET [$name] );
  14688. } elseif (isset ( $_POST [$name] )) {
  14689. if (is_array ( $_POST [$name] ))
  14690. return $_POST [$name];
  14691. else
  14692. return addslashes ( $_POST [$name] );
  14693. } else
  14694. return false;
  14695. }
  14696. function num_to_rmb($num) {
  14697. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14698. $c2 = "分角元拾佰仟万拾佰仟亿";
  14699. // 精确到分后面就不要了,所以只留两个小数位
  14700. $num = round ( $num, 2 );
  14701. // 将数字转化为整数
  14702. $num = $num * 100;
  14703. if (strlen ( $num ) > 10) {
  14704. return "金额太大,请检查";
  14705. }
  14706. $i = 0;
  14707. $c = "";
  14708. while ( 1 ) {
  14709. if ($i == 0) {
  14710. // 获取最后一位数字
  14711. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14712. } else {
  14713. $n = $num % 10;
  14714. }
  14715. // 每次将最后一位数字转化为中文
  14716. $p1 = substr ( $c1, 3 * $n, 3 );
  14717. $p2 = substr ( $c2, 3 * $i, 3 );
  14718. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14719. $c = $p1 . $p2 . $c;
  14720. } else {
  14721. $c = $p1 . $c;
  14722. }
  14723. $i = $i + 1;
  14724. // 去掉数字最后一位了
  14725. $num = $num / 10;
  14726. // echo $num.'</br>';
  14727. $num = ( int ) $num;
  14728. // $num =floor($num);
  14729. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14730. // echo $num.'</br>';
  14731. // 结束循环
  14732. if ($num == 0) {
  14733. break;
  14734. }
  14735. }
  14736. // echo $c.'</br>';
  14737. $j = 0;
  14738. $slen = strlen ( $c );
  14739. while ( $j < $slen ) {
  14740. // utf8一个汉字相当3个字符
  14741. $m = substr ( $c, $j, 6 );
  14742. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14743. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14744. $left = substr ( $c, 0, $j );
  14745. $right = substr ( $c, $j + 3 );
  14746. $c = $left . $right;
  14747. $j = $j - 3;
  14748. $slen = $slen - 3;
  14749. }
  14750. $j = $j + 3;
  14751. }
  14752. // 这个是为了去掉类似23.0中最后一个“零”字
  14753. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14754. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14755. }
  14756. // 将处理的汉字加上“整”
  14757. if (empty ( $c )) {
  14758. return "零元整";
  14759. } else {
  14760. return $c . "整";
  14761. }
  14762. }
  14763. /**
  14764. * 获得分页数据
  14765. * @param unknown_type $table
  14766. * @param unknown_type $condition
  14767. * @param unknown_type $on_page
  14768. * @param unknown_type $page_size
  14769. */
  14770. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14771. $page_c = "";
  14772. $page ['previous'] = $this->get_previous ( $on_page );
  14773. $page ['on_page'] = $on_page;
  14774. $total_count = $this->get_table_count ( $table, $condition );
  14775. $total = intval ( $total_count / $page_size );
  14776. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14777. $page ['total_data'] = $total_count;
  14778. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14779. $i = 1;
  14780. $page_max = 1;
  14781. $page_width = 3;
  14782. if ($on_page >= $page_width) {
  14783. $page_max = intval ( $on_page / $page_width ) + 1;
  14784. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14785. }
  14786. for(; $i <= $page ['total_page']; $i ++) {
  14787. if ($i == $on_page)
  14788. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14789. else
  14790. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14791. if ($i == ($page_width * $page_max))
  14792. break;
  14793. }
  14794. $page ['page'] = $page_c;
  14795. $page ['lower'] = (-- $on_page) * $page_size;
  14796. return $page;
  14797. }
  14798. /**
  14799. * 获取总页数
  14800. * @param unknown_type $table
  14801. * @param unknown_type $condition
  14802. */
  14803. public function get_table_count($table = "", $condition = "") {
  14804. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14805. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14806. // echo $sql;die;
  14807. $query = Doo::db ()->query ( $sql );
  14808. $result = $query->fetch ();
  14809. return $result ['count'];
  14810. }
  14811. /**
  14812. * 获取上一页
  14813. * @param unknown_type $on_page
  14814. */
  14815. function get_previous($on_page = 1) {
  14816. return $on_page != 0 ? $on_page - 1 : $on_page;
  14817. }
  14818. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  14819. // 收入合计
  14820. Doo::loadModel ( 'invoiceTraining' );
  14821. $invoiceTraining = new invoiceTraining ();
  14822. Doo::loadModel ( 'receipt' );
  14823. $receipt = new receipt ();
  14824. $invoiceTrainingDetail = array (
  14825. 'invoiceArriveAmount' => '0.00',
  14826. 'RIAmount' => '0.00',
  14827. 'invoiceTotalAmount' => '0.00',
  14828. 'invoiceCompanyAmount' => '0.00',
  14829. 'invoiceArriveAmountM'=>'0.00',
  14830. 'invoiceCompanyAmountM'=>'0.00'
  14831. );
  14832. if ($invoiceTrainId != 0) {
  14833. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  14834. }
  14835. $invoiceArriveAmount = $RIAmount = 0;
  14836. if (! empty ( $invoiceTrainingDetail )) {
  14837. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  14838. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  14839. }
  14840. // 备用金
  14841. $sum = 0;
  14842. if (! empty ( $trainLoanRid )) {
  14843. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  14844. foreach ($receiptLoanList as $key=>$value){
  14845. $sum+=$value['sum'];
  14846. }
  14847. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  14848. // $sum = $receiptLoanDetailBak ['sum'];
  14849. }
  14850. // 支出项金额详情
  14851. // 项目金额合计
  14852. Doo::loadModel ( 'RItem' );
  14853. $RItem = new RItem ();
  14854. Doo::loadModel ( 'accountItem' );
  14855. $accountItem = new accountItem ();
  14856. // 讲师获得
  14857. Doo::loadModel ( 'RILecturer' );
  14858. $RILecturer = new RILecturer ();
  14859. $RItemList = $RItem->getRItemByRid ($rid );
  14860. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  14861. // 支出项金额详情
  14862. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  14863. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  14864. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  14865. return $payment;
  14866. }
  14867. }
  14868. ?>