ReceiptController.php 564 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258
  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. $XDeode9 = new XDeode ( 9 );
  183. $receiptLogList = $receiptLog->getReceiptLogByUid ( $this->staff [0] ['sid'] );
  184. $receiptDetail = $receipt->find ( array (
  185. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=7 or status=5 or status=4 or status=8 and Rtype=1)',
  186. 'desc' => 'rid',
  187. 'asArray' => true
  188. ) );
  189. foreach ( $receiptDetail as $key => $value ) {
  190. $receiptDetail [$key] ['receiptId'] = $XDeode9->encode ( $value ['rid'] );
  191. $receiptDetail [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  192. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  193. $veList = $verify->getOne ( array (
  194. 'where' => 'vid=' . $value ['verify'],
  195. 'asArray' => true
  196. ) );
  197. $v = json_decode ( $veList ['staff'] );
  198. array_push ( $v [0], $veList ['description'] );
  199. foreach ( $v as $n => $m ) {
  200. if ($m ['1'] == 'ROLE') {
  201. $roleInfo = $role->getOne ( array (
  202. 'where' => 'rid=' . $m [0],
  203. 'asArray' => true
  204. ) );
  205. $v [$n] [1] = $roleInfo ['name'];
  206. }
  207. }
  208. $receiptDetail [$key] ['staff'] = $v;
  209. $category = $lCategory->getOne ( array (
  210. 'where' => 'cid=' . $value ['cid'],
  211. 'asArray' => true
  212. ) );
  213. $receiptDetail [$key] ['category'] = $category ['title'];
  214. }
  215. // print_r($receiptLogList);
  216. Doo::loadModel ( 'RAssist' );
  217. $RAssist = new RAssist ();
  218. $receiptExtendList=$RAssist->getRAssistBySid($this->staff[0]['sid']);
  219. //费用项目
  220. $acItem = $accountItem->find ( array ('asArray' => true) );
  221. if ($travel=='success'){
  222. $data ['travel'] =true;
  223. }else{
  224. $data ['travel'] =false;
  225. }
  226. $data ['acItem'] = $acItem;
  227. $data ['receiptExtendList'] = $receiptExtendList;
  228. $data ['receiptLogList'] = $receiptLogList;
  229. $data ['receiptDetail'] = $receiptDetail;
  230. $data ['memu'] = "receipt";
  231. $data ['staff'] = $this->staff;
  232. $data ['receiptMemu'] = 'saeaBorad';
  233. $data ['verifyId'] = $this->verifyId;
  234. $data ['executeId'] = $this->executeId;
  235. $this->render ( "/receipt/receiptFee", $data );
  236. }
  237. /**
  238. * 费用报销单-导流入哪个细分类
  239. */
  240. function receiptFeeDiversion(){
  241. $feeType= $this->get_args ( 'feeType' ) ? $this->get_args ( 'feeType' ) : "";
  242. if($feeType==2){
  243. return '/receipt/feeTravel';
  244. }elseif($feeType==3){
  245. return '/receipt/feeInternalTrain';
  246. }else{
  247. return '/receipt/feeAgency';
  248. }
  249. }
  250. private function _feeData(){
  251. Doo::loadModel ( 'L_category' );
  252. $lCategory = new L_category ();
  253. Doo::loadModel ( 'verify' );
  254. $verify = new verify ();
  255. Doo::loadModel ( 'accountItem' );
  256. $accountItem = new accountItem ();
  257. Doo::loadModel ( "role" );
  258. $role = new role ();
  259. $acItem = $accountItem->find ( array (
  260. 'asArray' => true
  261. ) );
  262. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  263. $data ['category'] = $lCategory->find ( array (
  264. 'asArray' => true
  265. ) );
  266. $data ['itineraryDate'] = $this->_itineraryDateMin();
  267. $data ['veList'] = $veList;
  268. $data ['acItem'] = $acItem;
  269. $data ['memu'] = "receipt";
  270. $data ['staff'] = $this->staff;
  271. $data ['receiptMemu'] = 'saeaBorad';
  272. $data ['verifyId'] = $this->verifyId;
  273. $data ['executeId'] = $this->executeId;
  274. return $data;
  275. }
  276. /**
  277. * 办事处相关费用
  278. */
  279. function feeAgency(){
  280. $data=$this->_feeData();
  281. $this->render ( "/receipt/feeAgency", $data );
  282. }
  283. /**
  284. * 办事处
  285. */
  286. function feeTravel(){
  287. $data=$this->_feeData();
  288. $this->render ( "/receipt/feeTravel", $data );
  289. }
  290. function feeInternalTrain(){
  291. $data=$this->_feeData();
  292. $this->render ( "/receipt/feeInternalTrain", $data );
  293. }
  294. /**
  295. * 添加费用报销单页面
  296. */
  297. function saeaCreate() {
  298. Doo::loadModel ( 'accountItem' );
  299. Doo::loadModel ( 'verify' );
  300. Doo::loadModel ( 'receipt' );
  301. Doo::loadModel ( 'L_category' );
  302. $lCategory = new L_category ();
  303. $receipt = new receipt ();
  304. $verify = new verify ();
  305. $accountItem = new accountItem ();
  306. Doo::loadModel ( "role" );
  307. $role = new role ();
  308. $acItem = $accountItem->find ( array (
  309. 'asArray' => true
  310. ) );
  311. $veList = $verify->getVerifyBySubordinate('RECEIPT');
  312. $data ['category'] = $lCategory->find ( array (
  313. 'asArray' => true
  314. ) );
  315. $data ['veList'] = $veList;
  316. $data ['acItem'] = $acItem;
  317. $data ['memu'] = "receipt";
  318. $data ['staff'] = $this->staff;
  319. $data ['receiptMemu'] = 'saeaBorad';
  320. $data ['verifyId'] = $this->verifyId;
  321. $data ['executeId'] = $this->executeId;
  322. $this->render ( "/admin/saea_create", $data );
  323. }
  324. private function _storageItinerary($itinerary,$rid,$version=2){
  325. $itineraryJson=json_decode($itinerary,true);
  326. Doo::loadModel ( 'itinerary' );
  327. $itinerary = new itinerary ();
  328. $itinerary->delete(array('where' => 'rid=' . $rid ));
  329. if($version==2){
  330. foreach ($itineraryJson as $k=>$v){
  331. foreach ($v as $kk=>$vv){
  332. foreach ($vv as $key=>$value){
  333. if($key==0){
  334. $feeTraveItem=json_encode($value['feeTraveItem']);
  335. $itinerary = new itinerary ();
  336. $itinerary->rid=$rid;
  337. $itinerary->sid=$this->staff [0] ['sid'];
  338. $itinerary->itineraryDate=$value['departuredate'];
  339. $itinerary->itineraryCity=$value['departurecity'];
  340. $itinerary->feeTraveItem='';
  341. $itinerary->itineraryIndex=0;
  342. $itinerary->insert ();
  343. $itinerary = new itinerary ();
  344. $itinerary->rid=$rid;
  345. $itinerary->sid=$this->staff [0] ['sid'];
  346. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  347. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  348. $itinerary->feeTraveItem=$feeTraveItem;
  349. $itinerary->itineraryIndex=1;
  350. $itinerary->insert ();
  351. }else{
  352. $feeTraveItem=json_encode($value['feeTraveItem']);
  353. $itinerary = new itinerary ();
  354. $itinerary->rid=$rid;
  355. $itinerary->sid=$this->staff [0] ['sid'];
  356. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  357. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  358. $itinerary->feeTraveItem=$feeTraveItem;
  359. $itinerary->itineraryIndex=$key+1;
  360. $itinerary->insert ();
  361. }
  362. }
  363. }
  364. }
  365. }elseif($version==1){
  366. foreach ($itineraryJson as $key=>$value){
  367. if($key==0){
  368. $feeTraveItem=json_encode($value['feeTraveItem']);
  369. $itinerary = new itinerary ();
  370. $itinerary->rid=$rid;
  371. $itinerary->sid=$this->staff [0] ['sid'];
  372. $itinerary->itineraryDate=$value['departuredate'];
  373. $itinerary->itineraryCity=$value['departurecity'];
  374. $itinerary->feeTraveItem='';
  375. $itinerary->itineraryIndex=0;
  376. $itinerary->insert ();
  377. $itinerary = new itinerary ();
  378. $itinerary->rid=$rid;
  379. $itinerary->sid=$this->staff [0] ['sid'];
  380. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  381. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  382. $itinerary->feeTraveItem=$feeTraveItem;
  383. $itinerary->itineraryIndex=1;
  384. $itinerary->insert ();
  385. }else{
  386. $feeTraveItem=json_encode($value['feeTraveItem']);
  387. $itinerary = new itinerary ();
  388. $itinerary->rid=$rid;
  389. $itinerary->sid=$this->staff [0] ['sid'];
  390. $itinerary->itineraryDate=substr($value['arrivalsdate'],1);
  391. $itinerary->itineraryCity=substr($value['arrivalscity'],1);
  392. $itinerary->feeTraveItem=$feeTraveItem;
  393. $itinerary->itineraryIndex=$key+1;
  394. $itinerary->insert ();
  395. }
  396. }
  397. }else{
  398. die ( '行程单版本不正确' );
  399. }
  400. }
  401. private function _verificationItinerary($itinerary){
  402. Doo::loadModel ( 'itinerary' );
  403. $itineraryObj = new itinerary ();
  404. if(empty($itinerary)){
  405. header ( 'Content-Type:text/html;charset=utf-8' );
  406. die ( '请填写行程单' );
  407. }
  408. $itineraryJson=json_decode($itinerary,true);
  409. foreach ($itineraryJson as $k=>$v){
  410. foreach ($v as $kk=>$vv){
  411. foreach ($vv as $key=>$value){
  412. if(empty($value['departuredate'])||empty($value['arrivalsdate'])){
  413. header ( 'Content-Type:text/html;charset=utf-8' );
  414. die ( '有行程的日期未设置' );
  415. }
  416. }
  417. }
  418. }
  419. $itineraryDate=array();$sql=array();
  420. foreach ($itineraryJson as $k=>$v){
  421. foreach ($v as $kk=>$vv){
  422. foreach ($vv as $key=>$value){
  423. if($key==0){
  424. array_push($itineraryDate, $value['departuredate']);
  425. array_push($itineraryDate, substr($value['arrivalsdate'],1));
  426. array_push($sql,'?');array_push($sql,'?');
  427. }else{
  428. array_push($itineraryDate, substr($value['arrivalsdate'],1));
  429. array_push($sql,'?');
  430. }
  431. }
  432. }
  433. }
  434. array_push($itineraryDate, $this->staff [0] ['sid']);
  435. $sql=implode(',',$sql);
  436. // $itineraryDate=array();$sql=array();
  437. // foreach ($itineraryJson as $key=>$value){
  438. // if($key==0){
  439. // array_push($itineraryDate, $value['departuredate']);
  440. // array_push($itineraryDate, substr($value['arrivalsdate'],1));
  441. // array_push($sql,'?');array_push($sql,'?');
  442. // }else{
  443. // array_push($itineraryDate, substr($value['arrivalsdate'],1));
  444. // array_push($sql,'?');
  445. // }
  446. // }
  447. // array_push($itineraryDate, $this->staff [0] ['sid']);
  448. // $sql=implode(',',$sql);
  449. if(empty($sql)){
  450. header ( 'Content-Type:text/html;charset=utf-8' );
  451. die ( '请填写行程单-2' );
  452. }
  453. $qualification=array(
  454. 'where' => 'itineraryDate in ('.$sql.') and sid=? ',
  455. 'param' => $itineraryDate,
  456. 'asArray' => TRUE);
  457. $itDateList=$itineraryObj->find($qualification);
  458. if(empty($itDateList)){
  459. return false;
  460. }else{
  461. return true;
  462. }
  463. }
  464. private function _buildFeeData($receiptClass=1,$itinerary=''){
  465. $agency = $this->get_args ( 'agency' );
  466. $travel = $this->get_args ( 'travel' );
  467. $train = $this->get_args ( 'train' );
  468. $other = $this->get_args ( 'other' );
  469. $inttrain = $this->get_args ( 'inttrain' );
  470. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  471. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  472. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  473. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  474. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  475. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  476. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  477. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  478. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  479. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  480. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  481. header ( 'Content-Type:text/html;charset=utf-8' );
  482. die ( '请填写联行号' );
  483. }
  484. if($receiptClass==2){
  485. //TODO 日期检测
  486. if($this->_verificationItinerary($itinerary)){
  487. header ( 'Content-Type:text/html;charset=utf-8' );
  488. die ( '已申请过类此日期的行程' );
  489. }
  490. }
  491. $itinerary=str_replace('\n','<br/>',$itinerary);
  492. Doo::loadModel ( 'receipt' );
  493. Doo::loadModel ( 'receiptDetail' );
  494. Doo::loadModel ( 'accountItem' );
  495. $accountItem = new accountItem ();
  496. $receipt = new receipt ();
  497. Doo::loadModel ( 'enclosur' );
  498. Doo::loadModel ( 'execute' );
  499. $execute = new execute ();
  500. $executeDetail = $execute->getOne ( array (
  501. 'where' => 'mold="报销单执行人"',
  502. 'asArray' => true
  503. ) );
  504. $aItem = $accountItem->find ( array (
  505. 'asArray' => true
  506. ) );
  507. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  508. $ag = $tr = $ta = $ot= $it = 0;
  509. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  510. foreach ( $aItem as $key => $value ) {
  511. if ($value ['category'] == $this->AGENCY) {
  512. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  513. array_push ( $accountJson [$this->AGENCY], array (
  514. 'aid' => $value ['aid'],
  515. 'name' => $value ['name'],
  516. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  517. ) );
  518. $sum += $agency [$ag];
  519. $agencySum += $agency [$ag];
  520. }
  521. $ag ++;
  522. }
  523. if ($value ['category'] == $this->TRAVEL) {
  524. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  525. array_push ( $accountJson [$this->TRAVEL], array (
  526. 'aid' => $value ['aid'],
  527. 'name' => $value ['name'],
  528. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  529. ) );
  530. $sum += $travel [$tr];
  531. $travelSum += $travel [$tr];
  532. }
  533. $tr ++;
  534. }
  535. if ($value ['category'] == $this->TRAIN) {
  536. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  537. array_push ( $accountJson [$this->TRAIN], array (
  538. 'aid' => $value ['aid'],
  539. 'name' => $value ['name'],
  540. 'price' => number_format ( $train [$ta], 2, '.', '' )
  541. ) );
  542. $sum += $train [$ta];
  543. $trainSum += $train [$ta];
  544. }
  545. $ta ++;
  546. }
  547. if ($value ['category'] == $this->INTTRAIN) {
  548. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  549. array_push ( $accountJson [$this->INTTRAIN], array (
  550. 'aid' => $value ['aid'],
  551. 'name' => $value ['name'],
  552. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  553. ) );
  554. $sum += $inttrain [$it];
  555. $inttrainSum += $inttrain [$it];
  556. }
  557. $it ++;
  558. }
  559. if ($value ['category'] == $this->OTHER) {
  560. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  561. array_push ( $accountJson [$this->OTHER], array (
  562. 'aid' => $value ['aid'],
  563. 'name' => $value ['name'],
  564. 'price' => number_format ( $other [$ot], 2, '.', '' )
  565. ) );
  566. $sum += $other [$ot];
  567. $otherSum += $other [$ot];
  568. }
  569. $ot ++;
  570. }
  571. }
  572. $accountJson ['cSum'] = array (
  573. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  574. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  575. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  576. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  577. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  578. );
  579. // 报销单
  580. $receipt->accountItem = json_encode ( $accountJson );
  581. $receipt->staff = $this->staff [0] ['sid'];
  582. $receipt->sum = number_format ( $sum, 2, '.', '' );
  583. $receipt->date = date ( "Y-m-d" );
  584. $receipt->cid = $cid;
  585. $receipt->status = 5;
  586. // 修改审批流程加入角色
  587. $receipt->verify = $verify;
  588. $receipt->executeCopy = $executeDetail ['staff'];
  589. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  590. $order = array (
  591. "\r\n",
  592. "\n",
  593. "\r"
  594. );
  595. $replace = '<br/>';
  596. $explanation = str_replace ( $order, $replace, $explanation );
  597. $receipt->explanation = $explanation;
  598. $receipt->receiptClass = $receiptClass;
  599. $receipt->itinerary2=$itinerary;
  600. $receipt->remittanceName = $remittanceName;
  601. $receipt->bankName = $bankName;
  602. $receipt->bankNumber = $bankNumber;
  603. $receipt->remittanceBankType = $remittanceBankType;
  604. if ($remittanceBankType == 1) {
  605. $receipt->coupletNumber = $coupletNumber;
  606. }
  607. $rid = $receipt->insert ();
  608. //记录行程单
  609. $this->_storageItinerary($itinerary,$rid);
  610. // 附件
  611. if (! empty ( $enclosurName )) {
  612. $enclosurArray = explode ( '-', $enclosurName );
  613. foreach ( $enclosurArray as $value ) {
  614. $enclosur = new enclosur ();
  615. $enclosur->name = $value;
  616. $enclosur->rid = $rid;
  617. $enclosur->insert ();
  618. }
  619. }
  620. // 报销详情
  621. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  622. $receiptDetail = new receiptDetail ();
  623. $receiptDetail->staff = $this->staff [0] ['sid'];
  624. $receiptDetail->item = $value ['name'];
  625. $receiptDetail->itemCategory = $this->AGENCY;
  626. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  627. $receiptDetail->date = date ( "Y-m-d" );
  628. $receiptDetail->cid = $cid;
  629. $receiptDetail->rid = $rid;
  630. $receiptDetail->status = 4;
  631. $receiptDetail->insert ();
  632. }
  633. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  634. $receiptDetail = new receiptDetail ();
  635. $receiptDetail->staff = $this->staff [0] ['sid'];
  636. $receiptDetail->item = $value ['name'];
  637. $receiptDetail->itemCategory = $this->TRAVEL;
  638. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  639. $receiptDetail->date = date ( "Y-m-d" );
  640. $receiptDetail->cid = $cid;
  641. $receiptDetail->rid = $rid;
  642. $receiptDetail->status = 4;
  643. $receiptDetail->insert ();
  644. }
  645. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  646. $receiptDetail = new receiptDetail ();
  647. $receiptDetail->staff = $this->staff [0] ['sid'];
  648. $receiptDetail->item = $value ['name'];
  649. $receiptDetail->itemCategory = $this->TRAIN;
  650. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  651. $receiptDetail->date = date ( "Y-m-d" );
  652. $receiptDetail->cid = $cid;
  653. $receiptDetail->rid = $rid;
  654. $receiptDetail->status = 4;
  655. $receiptDetail->insert ();
  656. }
  657. // 内训
  658. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  659. $receiptDetail = new receiptDetail ();
  660. $receiptDetail->staff = $this->staff [0] ['sid'];
  661. $receiptDetail->item = $value ['name'];
  662. $receiptDetail->itemCategory = $this->INTTRAIN;
  663. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  664. $receiptDetail->date = date ( "Y-m-d" );
  665. $receiptDetail->cid = $cid;
  666. $receiptDetail->rid = $rid;
  667. $receiptDetail->status = 4;
  668. $receiptDetail->insert ();
  669. }
  670. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  671. $receiptDetail = new receiptDetail ();
  672. $receiptDetail->staff = $this->staff [0] ['sid'];
  673. $receiptDetail->item = $value ['name'];
  674. $receiptDetail->itemCategory = $this->OTHER;
  675. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  676. $receiptDetail->date = date ( "Y-m-d" );
  677. $receiptDetail->cid = $cid;
  678. $receiptDetail->rid = $rid;
  679. $receiptDetail->status = 4;
  680. $receiptDetail->insert ();
  681. }
  682. return true;
  683. } else
  684. return false;
  685. }
  686. function addReceipt() {
  687. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  688. if ($this->_buildFeeData(1)) {
  689. return "/saeaBorad";
  690. } else{
  691. die ( 'illegal request' );
  692. }
  693. }
  694. function addFeeTravel(){
  695. $itinerary = $_POST['itinerary'] ? $_POST['itinerary'] : "";
  696. $itineraryList=json_decode($itinerary,true);
  697. // foreach ($itineraryList as $key=>$value){
  698. // if(empty($value['departuredate'])||empty($value['departurecity'])){
  699. // header ( 'Content-Type:text/html;charset=utf-8' );
  700. // die ( '请设置出发地和出发日期' );
  701. // }
  702. // }
  703. if ($this->_buildFeeData(2,$itinerary)) {
  704. return "/saeaBorad?travel=success";
  705. } else{
  706. die ( 'illegal request' );
  707. }
  708. }
  709. function addFeeInternalTrain(){
  710. if ($this->_buildFeeData(3)) {
  711. return "/saeaBorad";
  712. } else{
  713. die ( 'illegal request' );
  714. }
  715. }
  716. function referReceipt() {
  717. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  718. Doo::loadModel ( 'receipt' );
  719. Doo::loadModel ( 'verify' );
  720. $verify = new verify ();
  721. $receipt = new receipt ();
  722. Doo::loadModel ( 'L_category' );
  723. $lCategory = new L_category ();
  724. Doo::loadModel ( "role" );
  725. $role = new role ();
  726. $receiptDetail = $receipt->find ( array (
  727. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and status=5 ',
  728. 'asArray' => true
  729. ) );
  730. if (empty ( $receiptDetail ))
  731. return "/addReceipt";
  732. foreach ( $receiptDetail as $key => $value ) {
  733. $receiptDetail [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  734. $veList = $verify->getOne ( array (
  735. 'where' => 'vid=' . $value ['verify'],
  736. 'asArray' => true
  737. ) );
  738. $v = json_decode ( $veList ['staff'] );
  739. array_push ( $v [0], $veList ['description'] );
  740. foreach ( $v as $n => $m ) {
  741. if ($m ['1'] == 'ROLE') {
  742. $roleInfo = $role->getOne ( array (
  743. 'where' => 'rid=' . $m [0],
  744. 'asArray' => true
  745. ) );
  746. $v [$n] [1] = $roleInfo ['name'];
  747. }
  748. }
  749. $receiptDetail [$key] ['staff'] = $v;
  750. $category = $lCategory->getOne ( array (
  751. 'where' => 'cid=' . $value ['cid'],
  752. 'asArray' => true
  753. ) );
  754. $receiptDetail [$key] ['category'] = $category ['title'];
  755. }
  756. // print_r($receiptDetail);
  757. $data ['receiptDetail'] = $receiptDetail;
  758. $data ['memu'] = "receipt";
  759. $data ['staff'] = $this->staff;
  760. $data ['receiptMemu'] = 'saeaCreate';
  761. $data ['verifyId'] = $this->verifyId;
  762. $data ['executeId'] = $this->executeId;
  763. $this->render ( "/admin/saea_confirm", $data );
  764. }
  765. function editReceipt() {
  766. // edit status 4
  767. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  768. Doo::loadClass ( 'XDeode' );
  769. $XDeode = new XDeode ( 7 );
  770. $rid = $XDeode->decode ( $ridKey );
  771. if (empty ( $rid )) {
  772. die ( 'illegal request-id' );
  773. }
  774. // echo $rid.'sd';
  775. Doo::loadModel ( 'accountItem' );
  776. Doo::loadModel ( 'verify' );
  777. Doo::loadModel ( 'receipt' );
  778. $receipt = new receipt ();
  779. $verify = new verify ();
  780. $accountItem = new accountItem ();
  781. Doo::loadModel ( 'L_category' );
  782. $lCategory = new L_category ();
  783. Doo::loadModel ( "role" );
  784. $role = new role ();
  785. Doo::loadModel ( 'enclosur' );
  786. $enclosur = new enclosur ();
  787. $receiptDetail = $receipt->getOne ( array (
  788. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  789. 'asArray' => true
  790. ) );
  791. if (empty ( $receiptDetail )) {
  792. die ( 'illegal request-emptyData' );
  793. }
  794. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  795. $acItem = $accountItem->find ( array (
  796. 'asArray' => true
  797. ) );
  798. $veList = $verify->getVerifyBySubordinate ( 'RECEIPT' );
  799. // 配置编辑信息
  800. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  801. foreach ( $acItem as $key => $value ) {
  802. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  803. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  804. $acItem [$key] ['price'] = $v ['price'];
  805. }
  806. }
  807. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  808. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  809. $acItem [$key] ['price'] = $v ['price'];
  810. }
  811. }
  812. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  813. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  814. $acItem [$key] ['price'] = $v ['price'];
  815. }
  816. }
  817. // 内训
  818. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  819. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  820. $acItem [$key] ['price'] = $v ['price'];
  821. }
  822. }
  823. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  824. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  825. $acItem [$key] ['price'] = $v ['price'];
  826. }
  827. }
  828. }
  829. //$receiptDetail['itinerary']=str_replace('\n','<br/>',$receiptDetail['itinerary']);
  830. //nl2br($receiptDetail['explanation']);
  831. Doo::loadModel ( 'itinerary' );
  832. $itinerary = new itinerary ();
  833. $itinerary->delete(array('where' => 'rid=' . $receiptDetail['rid'] ));
  834. $receiptDetail['explanation']= str_replace('<br/>',"\n",$receiptDetail['explanation']);
  835. $receiptDetail['itinerary']=str_replace('\n','<br/>',$receiptDetail['itinerary']);
  836. $data ['category'] = $lCategory->find ( array (
  837. 'asArray' => true
  838. ) );
  839. $data ['cSum'] = $accountItemList ['cSum'];
  840. $data ['sum'] = $receiptDetail ['sum'];
  841. $data ['enclosurList'] = $enclosurList;
  842. $data ['receiptDetail'] = $receiptDetail;
  843. $data ['veList'] = $veList;
  844. $data ['acItem'] = $acItem;
  845. $data ['memu'] = "receipt";
  846. $data ['staff'] = $this->staff;
  847. $data ['receiptMemu'] = 'saeaBorad';
  848. $data ['verify'] = $receiptDetail ['verify'];
  849. $data ['verifyId'] = $this->verifyId;
  850. $data ['executeId'] = $this->executeId;
  851. $data ['rid'] = $ridKey;
  852. if($receiptDetail['receiptClass']==1){
  853. $this->render ( "/receipt/feeAgencyEdi", $data );
  854. }elseif($receiptDetail['receiptClass']==2){
  855. if(!empty($receiptDetail['itinerary2'])){
  856. //TODO 报销说明
  857. $this->render ( "/receipt/feeTravelEdi2", $data );
  858. }else{
  859. $this->render ( "/receipt/feeTravelEdi", $data );
  860. }
  861. }elseif($receiptDetail['receiptClass']==3){
  862. $this->render ( "/receipt/feeInternalTrainEdi", $data );
  863. }else{
  864. $this->render ( "/admin/saea_edit", $data );
  865. //die ( 'illegal request-renderHtml' );
  866. }
  867. }
  868. function updateReceipt() {
  869. $agency = $this->get_args ( 'agency' );
  870. $travel = $this->get_args ( 'travel' );
  871. $train = $this->get_args ( 'train' );
  872. $other = $this->get_args ( 'other' );
  873. $inttrain = $this->get_args ( 'inttrain' );
  874. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  875. $traveVer = $this->get_args ( 'traveVer' ) ? $this->get_args ( 'traveVer' ) : "trave2";
  876. $itinerary = $_POST['itinerary'];
  877. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  878. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  879. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  880. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  881. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  882. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  883. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  884. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  885. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  886. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  887. Doo::loadClass ( 'XDeode' );
  888. $XDeode = new XDeode ( 7 );
  889. $rid = $XDeode->decode ( $ridKey );
  890. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  891. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  892. header ( 'Content-Type:text/html;charset=utf-8' );
  893. die ( '请填写联行号' );
  894. }
  895. if($traveVer!='trave1'){
  896. if($receiptClass=='trave'){
  897. //TODO 日期检测
  898. if($this->_verificationItinerary($itinerary)){
  899. header ( 'Content-Type:text/html;charset=utf-8' );
  900. die ( '已申请过类此日期的行程' );
  901. }
  902. }
  903. }
  904. Doo::loadModel ( 'receipt' );
  905. Doo::loadModel ( 'receiptDetail' );
  906. Doo::loadModel ( 'accountItem' );
  907. $accountItem = new accountItem ();
  908. $receipt = new receipt ();
  909. Doo::loadModel ( 'enclosur' );
  910. Doo::loadModel ( 'execute' );
  911. $execute = new execute ();
  912. $receiptDetail = $receipt->getOne ( array (
  913. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  914. 'asArray' => true
  915. ) );
  916. if (empty ( $receiptDetail )) {
  917. return "/saeaBorad";
  918. }
  919. //TODO 存储行程单-兼容旧版本的行程单
  920. $itinerary=str_replace('\n','<br/>',$itinerary);
  921. if(!empty($receiptDetail['itinerary2'])){
  922. $this->_storageItinerary($itinerary,$rid);
  923. }else{
  924. $this->_storageItinerary($itinerary,$rid,1);
  925. }
  926. if ($receiptDetail ['Rtype'] == 1) {
  927. $executeDetail = $execute->getOne ( array (
  928. 'where' => 'mold="借款费用执行人"',
  929. 'asArray' => true
  930. ) );
  931. } else {
  932. $executeDetail = $execute->getOne ( array (
  933. 'where' => 'mold="报销单执行人"',
  934. 'asArray' => true
  935. ) );
  936. }
  937. $aItem = $accountItem->find ( array (
  938. 'asArray' => true
  939. ) );
  940. $accountJson [$this->AGENCY] = $accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  941. $ag = $tr = $ta = $ot = $it = 0;
  942. $sum = $agencySum = $travelSum = $trainSum = $inttrainSum = $otherSum = 0;
  943. foreach ( $aItem as $key => $value ) {
  944. if ($value ['category'] == $this->AGENCY) {
  945. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  946. array_push ( $accountJson [$this->AGENCY], array (
  947. 'aid' => $value ['aid'],
  948. 'name' => $value ['name'],
  949. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  950. ) );
  951. $sum += $agency [$ag];
  952. $agencySum += $agency [$ag];
  953. }
  954. $ag ++;
  955. }
  956. if ($value ['category'] == $this->TRAVEL) {
  957. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  958. array_push ( $accountJson [$this->TRAVEL], array (
  959. 'aid' => $value ['aid'],
  960. 'name' => $value ['name'],
  961. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  962. ) );
  963. $sum += $travel [$tr];
  964. $travelSum += $travel [$tr];
  965. }
  966. $tr ++;
  967. }
  968. if ($value ['category'] == $this->TRAIN) {
  969. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  970. array_push ( $accountJson [$this->TRAIN], array (
  971. 'aid' => $value ['aid'],
  972. 'name' => $value ['name'],
  973. 'price' => number_format ( $train [$ta], 2, '.', '' )
  974. ) );
  975. $sum += $train [$ta];
  976. $trainSum += $train [$ta];
  977. }
  978. $ta ++;
  979. }
  980. if ($value ['category'] == $this->INTTRAIN) {
  981. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  982. array_push ( $accountJson [$this->INTTRAIN], array (
  983. 'aid' => $value ['aid'],
  984. 'name' => $value ['name'],
  985. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  986. ) );
  987. $sum += $inttrain [$it];
  988. $inttrainSum += $inttrain [$it];
  989. }
  990. $it ++;
  991. }
  992. if ($value ['category'] == $this->OTHER) {
  993. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  994. array_push ( $accountJson [$this->OTHER], array (
  995. 'aid' => $value ['aid'],
  996. 'name' => $value ['name'],
  997. 'price' => number_format ( $other [$ot], 2, '.', '' )
  998. ) );
  999. $sum += $other [$ot];
  1000. $otherSum += $other [$ot];
  1001. }
  1002. $ot ++;
  1003. }
  1004. }
  1005. $accountJson ['cSum'] = array (
  1006. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1007. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1008. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1009. 'inttrainSum' => number_format ( $inttrainSum, 2, '.', '' ),
  1010. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1011. );
  1012. // 报销单
  1013. $rid = $receipt->rid = $receiptDetail ['rid'];
  1014. $receipt->accountItem = json_encode ( $accountJson );
  1015. $receipt->staff = $this->staff [0] ['sid'];
  1016. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1017. $receipt->date = date ( "Y-m-d" );
  1018. $receipt->cid = $cid;
  1019. if (($receiptDetail ['status'] != 4)) {
  1020. if ($receiptDetail ['Rtype'] == 1) {
  1021. $receipt->status = 7;
  1022. } else {
  1023. $receipt->status = 5;
  1024. }
  1025. }
  1026. if ($receiptDetail != 4 && ! empty ( $verify ))
  1027. $receipt->verify = $verify;
  1028. $receipt->executeCopy = $executeDetail ['staff'];
  1029. $order = array (
  1030. "\r\n",
  1031. "\n",
  1032. "\r"
  1033. );
  1034. $replace = '<br/>';
  1035. $explanation = str_replace ( $order, $replace, $explanation );
  1036. $receipt->explanation = $explanation;
  1037. if($receiptClass=='trave'){
  1038. if(!empty($receiptDetail['itinerary2'])){//行程单版本
  1039. $receipt->itinerary2=$itinerary;
  1040. }else{
  1041. $receipt->itinerary=$itinerary;
  1042. }
  1043. }
  1044. $receipt->remittanceName = $remittanceName;
  1045. $receipt->bankName = $bankName;
  1046. $receipt->bankNumber = $bankNumber;
  1047. $receipt->remittanceBankType = $remittanceBankType;
  1048. if ($remittanceBankType == 1)
  1049. $receipt->coupletNumber = $coupletNumber;
  1050. $receipt->update ();
  1051. $receiptDetail = new receiptDetail ();
  1052. $receiptDetail->delete ( array (
  1053. 'where' => 'rid=' . $rid
  1054. ) );
  1055. // 报销详情
  1056. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1057. $receiptDetail = new receiptDetail ();
  1058. $receiptDetail->staff = $this->staff [0] ['sid'];
  1059. $receiptDetail->item = $value ['name'];
  1060. $receiptDetail->itemCategory = $this->AGENCY;
  1061. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1062. $receiptDetail->date = date ( "Y-m-d" );
  1063. $receiptDetail->cid = $cid;
  1064. $receiptDetail->rid = $rid;
  1065. $receiptDetail->status = 4;
  1066. $receiptDetail->insert ();
  1067. }
  1068. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  1069. $receiptDetail = new receiptDetail ();
  1070. $receiptDetail->staff = $this->staff [0] ['sid'];
  1071. $receiptDetail->item = $value ['name'];
  1072. $receiptDetail->itemCategory = $this->TRAVEL;
  1073. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1074. $receiptDetail->date = date ( "Y-m-d" );
  1075. $receiptDetail->cid = $cid;
  1076. $receiptDetail->rid = $rid;
  1077. $receiptDetail->status = 4;
  1078. $receiptDetail->insert ();
  1079. }
  1080. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  1081. $receiptDetail = new receiptDetail ();
  1082. $receiptDetail->staff = $this->staff [0] ['sid'];
  1083. $receiptDetail->item = $value ['name'];
  1084. $receiptDetail->itemCategory = $this->TRAIN;
  1085. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1086. $receiptDetail->date = date ( "Y-m-d" );
  1087. $receiptDetail->cid = $cid;
  1088. $receiptDetail->rid = $rid;
  1089. $receiptDetail->status = 4;
  1090. $receiptDetail->insert ();
  1091. }
  1092. // 内训
  1093. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  1094. $receiptDetail = new receiptDetail ();
  1095. $receiptDetail->staff = $this->staff [0] ['sid'];
  1096. $receiptDetail->item = $value ['name'];
  1097. $receiptDetail->itemCategory = $this->INTTRAIN;
  1098. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1099. $receiptDetail->date = date ( "Y-m-d" );
  1100. $receiptDetail->cid = $cid;
  1101. $receiptDetail->rid = $rid;
  1102. $receiptDetail->status = 4;
  1103. $receiptDetail->insert ();
  1104. }
  1105. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  1106. $receiptDetail = new receiptDetail ();
  1107. $receiptDetail->staff = $this->staff [0] ['sid'];
  1108. $receiptDetail->item = $value ['name'];
  1109. $receiptDetail->itemCategory = $this->OTHER;
  1110. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1111. $receiptDetail->date = date ( "Y-m-d" );
  1112. $receiptDetail->cid = $cid;
  1113. $receiptDetail->rid = $rid;
  1114. $receiptDetail->status = 4;
  1115. $receiptDetail->insert ();
  1116. }
  1117. // 附件
  1118. if (! empty ( $enclosurName )) {
  1119. $enclosurArray = explode ( '-', $enclosurName );
  1120. foreach ( $enclosurArray as $value ) {
  1121. $enclosur = new enclosur ();
  1122. $enclosur->name = $value;
  1123. $enclosur->rid = $rid;
  1124. $enclosur->insert ();
  1125. }
  1126. }
  1127. // return "/referReceipt/".$rid;
  1128. }
  1129. return "/saeaBorad";
  1130. }
  1131. function remitAdd() {
  1132. Doo::loadModel ( 'accountItem' );
  1133. Doo::loadModel ( 'verify' );
  1134. Doo::loadModel ( 'receipt' );
  1135. Doo::loadModel ( 'L_category' );
  1136. $lCategory = new L_category ();
  1137. $receipt = new receipt ();
  1138. $verify = new verify ();
  1139. $accountItem = new accountItem ();
  1140. Doo::loadModel ( "role" );
  1141. $role = new role ();
  1142. $acItem = $accountItem->find ( array (
  1143. 'asArray' => true
  1144. ) );
  1145. $veList = $verify->getVerifyBySubordinate('REMIT');
  1146. $data ['category'] = $lCategory->find ( array (
  1147. 'asArray' => true
  1148. ) );
  1149. $data ['veList'] = $veList;
  1150. $data ['acItem'] = $acItem;
  1151. $data ['memu'] = "receipt";
  1152. $data ['staff'] = $this->staff;
  1153. $data ['receiptMemu'] = 'saeaBorad';
  1154. $data ['verifyId'] = $this->verifyId;
  1155. $data ['executeId'] = $this->executeId;
  1156. $this->render ( "/admin/remitAdd", $data );
  1157. }
  1158. function remitAddDo() {
  1159. $agency = $this->get_args ( 'agency' );
  1160. $travel = $this->get_args ( 'travel' );
  1161. $train = $this->get_args ( 'train' );
  1162. $other = $this->get_args ( 'other' );
  1163. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1164. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1165. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1166. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1167. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1168. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1169. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1170. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1171. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1172. // print_r($agency);die;
  1173. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1174. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1175. header ( 'Content-Type:text/html;charset=utf-8' );
  1176. die ( '请填写联行号' );
  1177. }
  1178. Doo::loadModel ( 'receipt' );
  1179. Doo::loadModel ( 'receiptDetail' );
  1180. Doo::loadModel ( 'accountItem' );
  1181. $accountItem = new accountItem ();
  1182. $receipt = new receipt ();
  1183. Doo::loadModel ( 'enclosur' );
  1184. Doo::loadModel ( 'execute' );
  1185. $execute = new execute ();
  1186. $executeDetail = $execute->getOne ( array (
  1187. 'where' => 'mold="对公汇款执行人"',
  1188. 'asArray' => true
  1189. ) );
  1190. // $receiptDetail=$receipt->getOne(array('where'=>'staff='.$this->staff[0]['sid'].' and status=4','asArray'=>true));
  1191. $aItem = $accountItem->find ( array (
  1192. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  1193. 'asArray' => true
  1194. ) );
  1195. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1196. $ag = $tr = $ta = $ot = 0;
  1197. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1198. print_r($aItem);
  1199. foreach ( $aItem as $key => $value ) {
  1200. if ($value ['category'] == $this->AGENCY) {
  1201. if (isset ( $agency [$ag] )) {
  1202. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1203. array_push ( $accountJson [$this->AGENCY], array (
  1204. 'aid' => $value ['aid'],
  1205. 'name' => $value ['name'],
  1206. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1207. ) );
  1208. $sum += $agency [$ag];
  1209. $agencySum += $agency [$ag];
  1210. }
  1211. }
  1212. $ag ++;
  1213. }
  1214. }
  1215. $accountJson ['cSum'] = array (
  1216. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1217. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1218. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1219. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1220. );
  1221. //die;
  1222. // 报销单
  1223. $receipt->accountItem = json_encode ( $accountJson );
  1224. $receipt->staff = $this->staff [0] ['sid'];
  1225. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1226. $receipt->date = date ( "Y-m-d" );
  1227. $receipt->cid = $cid;
  1228. $receipt->status = 5;
  1229. $receipt->Rtype = 2;
  1230. // 修改审批流程加入角色
  1231. $receipt->verify = $verify;
  1232. $receipt->executeCopy = $executeDetail ['staff'];
  1233. $receipt->receiptOrder = "#B" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1234. $order = array (
  1235. "\r\n",
  1236. "\n",
  1237. "\r"
  1238. );
  1239. $replace = '<br/>';
  1240. $explanation = str_replace ( $order, $replace, $explanation );
  1241. $receipt->explanation = $explanation;
  1242. $receipt->remittanceName = $remittanceName;
  1243. $receipt->bankName = $bankName;
  1244. $receipt->bankNumber = $bankNumber;
  1245. $receipt->remittanceBankType = $remittanceBankType;
  1246. if ($remittanceBankType == 1)
  1247. $receipt->coupletNumber = $coupletNumber;
  1248. $rid = $receipt->insert ();
  1249. // 附件
  1250. if (! empty ( $enclosurName )) {
  1251. $enclosurArray = explode ( '-', $enclosurName );
  1252. foreach ( $enclosurArray as $value ) {
  1253. $enclosur = new enclosur ();
  1254. $enclosur->name = $value;
  1255. $enclosur->rid = $rid;
  1256. $enclosur->insert ();
  1257. }
  1258. // print_r($enclosurArray);die;
  1259. }
  1260. // 报销详情
  1261. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1262. $receiptDetail = new receiptDetail ();
  1263. $receiptDetail->staff = $this->staff [0] ['sid'];
  1264. $receiptDetail->item = $value ['name'];
  1265. $receiptDetail->itemCategory = $this->AGENCY;
  1266. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1267. $receiptDetail->date = date ( "Y-m-d" );
  1268. $receiptDetail->cid = $cid;
  1269. $receiptDetail->rid = $rid;
  1270. $receiptDetail->status = 4;
  1271. $receiptDetail->insert ();
  1272. }
  1273. return "/saeaBorad";
  1274. } else
  1275. die ( 'illegal request' );
  1276. }
  1277. function remitEdit() {
  1278. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  1279. Doo::loadClass ( 'XDeode' );
  1280. $XDeode = new XDeode ( 7 );
  1281. $rid = $XDeode->decode ( $ridKey );
  1282. if (! is_numeric ( $rid ))
  1283. die ( 'illegal request' );
  1284. Doo::loadModel ( 'accountItem' );
  1285. Doo::loadModel ( 'verify' );
  1286. Doo::loadModel ( 'receipt' );
  1287. $receipt = new receipt ();
  1288. $verify = new verify ();
  1289. $accountItem = new accountItem ();
  1290. Doo::loadModel ( 'L_category' );
  1291. $lCategory = new L_category ();
  1292. Doo::loadModel ( "role" );
  1293. $role = new role ();
  1294. Doo::loadModel ( 'enclosur' );
  1295. $enclosur = new enclosur ();
  1296. $receiptDetail = $receipt->getOne ( array (
  1297. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=4)',
  1298. 'asArray' => true
  1299. ) );
  1300. if (empty ( $receiptDetail ))
  1301. return "/saeaCreate";
  1302. $enclosurList = $enclosur->getEnclosurByRid ( $receiptDetail ['rid'] );
  1303. $acItem = $accountItem->find ( array (
  1304. 'asArray' => true
  1305. ) );
  1306. $veList = $verify->getVerifyBySubordinate('REMIT');
  1307. // 配置编辑信息
  1308. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  1309. foreach ( $acItem as $key => $value ) {
  1310. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  1311. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  1312. $acItem [$key] ['price'] = $v ['price'];
  1313. }
  1314. }
  1315. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  1316. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  1317. $acItem [$key] ['price'] = $v ['price'];
  1318. }
  1319. }
  1320. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  1321. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  1322. $acItem [$key] ['price'] = $v ['price'];
  1323. }
  1324. }
  1325. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  1326. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  1327. $acItem [$key] ['price'] = $v ['price'];
  1328. }
  1329. }
  1330. }
  1331. $data ['category'] = $lCategory->find ( array (
  1332. 'asArray' => true
  1333. ) );
  1334. $data ['enclosurList'] = $enclosurList;
  1335. $data ['cSum'] = $accountItemList ['cSum'];
  1336. $data ['sum'] = $receiptDetail ['sum'];
  1337. $data ['receiptDetail'] = $receiptDetail;
  1338. $data ['veList'] = $veList;
  1339. $data ['acItem'] = $acItem;
  1340. $data ['memu'] = "receipt";
  1341. $data ['staff'] = $this->staff;
  1342. $data ['receiptMemu'] = 'saeaBorad';
  1343. $data ['verify'] = $receiptDetail ['verify'];
  1344. $data ['verifyId'] = $this->verifyId;
  1345. $data ['executeId'] = $this->executeId;
  1346. $data ['rid'] = $rid;
  1347. $data ['ridKey'] = $ridKey;
  1348. $this->render ( "/admin/remitEdit", $data );
  1349. }
  1350. function remitEdiDo() {
  1351. $agency = $this->get_args ( 'agency' );
  1352. $travel = $this->get_args ( 'travel' );
  1353. $train = $this->get_args ( 'train' );
  1354. $other = $this->get_args ( 'other' );
  1355. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1356. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1357. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1358. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1359. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  1360. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1361. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1362. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1363. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1364. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1365. Doo::loadClass ( 'XDeode' );
  1366. $XDeode = new XDeode ( 7 );
  1367. $rid = $XDeode->decode ( $ridKey );
  1368. if (! empty ( $rid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1369. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1370. header ( 'Content-Type:text/html;charset=utf-8' );
  1371. die ( '请填写联行号' );
  1372. }
  1373. Doo::loadModel ( 'receipt' );
  1374. Doo::loadModel ( 'receiptDetail' );
  1375. Doo::loadModel ( 'accountItem' );
  1376. $accountItem = new accountItem ();
  1377. $receipt = new receipt ();
  1378. Doo::loadModel ( 'enclosur' );
  1379. $enclosur = new enclosur ();
  1380. Doo::loadModel ( 'execute' );
  1381. $execute = new execute ();
  1382. $executeDetail = $execute->getOne ( array (
  1383. 'where' => 'mold="对公汇款执行人"',
  1384. 'asArray' => true
  1385. ) );
  1386. $receiptDetail = $receipt->getOne ( array (
  1387. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=5 or status=7 or status=4)',
  1388. 'asArray' => true
  1389. ) );
  1390. if (empty ( $receiptDetail ))
  1391. return "/saeaBorad";
  1392. $aItem = $accountItem->find ( array (
  1393. 'where' => '(name like "办公费用" or name like "服务器费用" or name like "邮寄费" or name like "其他费用" or name like "公积金" or name like "社保") and category like "'.$this->AGENCY.'"',
  1394. 'asArray' => true
  1395. ) );
  1396. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  1397. $ag = $tr = $ta = $ot = 0;
  1398. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1399. foreach ( $aItem as $key => $value ) {
  1400. if ($value ['category'] == $this->AGENCY) {
  1401. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  1402. array_push ( $accountJson [$this->AGENCY], array (
  1403. 'aid' => $value ['aid'],
  1404. 'name' => $value ['name'],
  1405. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  1406. ) );
  1407. $sum += $agency [$ag];
  1408. $agencySum += $agency [$ag];
  1409. }
  1410. $ag ++;
  1411. }
  1412. }
  1413. $accountJson ['cSum'] = array (
  1414. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  1415. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1416. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1417. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1418. );
  1419. // 报销单
  1420. $rid = $receipt->rid = $receiptDetail ['rid'];
  1421. $receipt->accountItem = json_encode ( $accountJson );
  1422. $receipt->staff = $this->staff [0] ['sid'];
  1423. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1424. $receipt->date = date ( "Y-m-d" );
  1425. $receipt->cid = $cid;
  1426. if ($receiptDetail ['Rtype'] == 1)
  1427. $receipt->status = 7;
  1428. else
  1429. $receipt->status = 5;
  1430. if ($receiptDetail ['status'] != 4 && ! empty ( $verify ))
  1431. $receipt->verify = $verify;
  1432. $receipt->executeCopy = $executeDetail ['staff'];
  1433. $order = array (
  1434. "\r\n",
  1435. "\n",
  1436. "\r"
  1437. );
  1438. $replace = '<br/>';
  1439. $explanation = str_replace ( $order, $replace, $explanation );
  1440. $receipt->explanation = $explanation;
  1441. $receipt->remittanceName = $remittanceName;
  1442. $receipt->bankName = $bankName;
  1443. $receipt->bankNumber = $bankNumber;
  1444. $receipt->remittanceBankType = $remittanceBankType;
  1445. if ($remittanceBankType == 1)
  1446. $receipt->coupletNumber = $coupletNumber;
  1447. $receipt->update ();
  1448. $receiptDetail = new receiptDetail ();
  1449. $receiptDetail->delete ( array (
  1450. 'where' => 'rid=' . $rid
  1451. ) );
  1452. // 报销详情
  1453. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  1454. $receiptDetail = new receiptDetail ();
  1455. $receiptDetail->staff = $this->staff [0] ['sid'];
  1456. $receiptDetail->item = $value ['name'];
  1457. $receiptDetail->itemCategory = $this->AGENCY;
  1458. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  1459. $receiptDetail->date = date ( "Y-m-d" );
  1460. $receiptDetail->cid = $cid;
  1461. $receiptDetail->rid = $rid;
  1462. $receiptDetail->status = 4;
  1463. $receiptDetail->insert ();
  1464. }
  1465. // 附件
  1466. if (! empty ( $enclosurName )) {
  1467. $enclosurArray = explode ( '-', $enclosurName );
  1468. foreach ( $enclosurArray as $value ) {
  1469. $enclosur = new enclosur ();
  1470. $enclosur->name = $value;
  1471. $enclosur->rid = $rid;
  1472. $enclosur->insert ();
  1473. }
  1474. }
  1475. }
  1476. return "/saeaBorad";
  1477. }
  1478. function remitApproval() {
  1479. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1480. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  1481. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  1482. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  1483. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1484. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  1485. if (empty ( $status ))
  1486. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  1487. $vidList = array ();
  1488. $button = 0;
  1489. Doo::loadModel ( 'verify' );
  1490. Doo::loadModel ( 'receipt' );
  1491. Doo::loadModel ( 'staff' );
  1492. $staff = new staff ();
  1493. $receipt = new receipt ();
  1494. $verify = new verify ();
  1495. Doo::loadModel ( 'L_category' );
  1496. $Lcategory = new L_category ();
  1497. Doo::loadModel ( 'enclosur' );
  1498. $enclosur = new enclosur ();
  1499. // user verify ID
  1500. $verifyDetail = $verify->find ( array (
  1501. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  1502. 'asArray' => true
  1503. ) );
  1504. foreach ( $verifyDetail as $key => $value ) {
  1505. array_push ( $vidList, $value ['vid'] );
  1506. }
  1507. $vid = implode ( ",", $vidList );
  1508. if (empty ( $verifyDetail ))
  1509. $vid = 0;
  1510. $categoryList = $Lcategory->find ( array (
  1511. 'asArray' => true
  1512. ) );
  1513. $staffList = $staff->find ( array (
  1514. 'where' => 'cid=' . $cid,
  1515. 'asArray' => true
  1516. ) );
  1517. $ap = "";
  1518. if ($status == 4) {
  1519. $ap = 4;
  1520. $status = 2;
  1521. }
  1522. // get Receipt By verifyID status 2
  1523. $receiptList = $receipt->find ( array (
  1524. 'where' => 'rid =' . $rid . ' and status=2',
  1525. 'desc' => 'rid',
  1526. 'asArray' => true
  1527. ) );
  1528. if (empty ( $receiptList )) {
  1529. die ( 'illegal request' );
  1530. }
  1531. $Locate = 0;
  1532. $roleId = 0;
  1533. if ($ap == 4)
  1534. $status = 4;
  1535. foreach ( $receiptList as $key => $value ) {
  1536. $receiptList [$key] ['Locate'] = $Locate;
  1537. $Locate ++;
  1538. $receiptList [$key] ['reviseDetail'] = array ();
  1539. if (! empty ( $value ['reviseDetail'] ))
  1540. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  1541. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  1542. $categoryDetil = $Lcategory->getOne ( array (
  1543. 'where' => 'cid=' . $value ['cid'],
  1544. 'asArray' => true
  1545. ) );
  1546. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  1547. // 检测编辑状态
  1548. $verifyList = $verify->getOne ( array (
  1549. 'where' => 'vid=' . $value ['verify'],
  1550. 'asArray' => true
  1551. ) );
  1552. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  1553. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  1554. Doo::loadModel ( 'role' );
  1555. $role = new role ();
  1556. // print_r($verifyList);
  1557. $flag = true;
  1558. $roleKey = 0;
  1559. $endStaffArray = array ();
  1560. $roleArrayCopy = array ();
  1561. foreach ( $verifyList as $k => $v ) {
  1562. // init verifyStaff
  1563. if ($v [1] == 'ROLE') {
  1564. if (! empty ( $verifyStaff )) {
  1565. $endStaffArray = end ( $verifyStaff );
  1566. if ($v [0] == $endStaffArray ['nextStaff']) {
  1567. $roleId = $v [0];
  1568. }
  1569. }
  1570. $roleVerify = json_decode ( $v [3], true );
  1571. $roleKey = $k;
  1572. $roleArray = array ();
  1573. $rolename = $role->getOne ( array (
  1574. 'where' => 'rid=' . $v [0],
  1575. 'asArray' => true
  1576. ) );
  1577. foreach ( $roleVerify as $o => $p ) {
  1578. $staffID = explode ( '_', $p );
  1579. $staffInfo = $staff->getOne ( array (
  1580. 'where' => 'sid=' . $staffID [0],
  1581. 'asArray' => true
  1582. ) );
  1583. // print_r($staffID);
  1584. $exp = array (
  1585. 0 => $staffInfo ['sid'],
  1586. 1 => $staffID [1],
  1587. 2 => $staffInfo ['avatar'],
  1588. 'date' => '',
  1589. 'date' => '',
  1590. 'opinion' => '',
  1591. 'status' => '',
  1592. 'rolename' => $rolename ['name']
  1593. );
  1594. array_push ( $roleArray, $exp );
  1595. }
  1596. $roleArrayCopy [$v [0]] = $roleArray;
  1597. // $verifyList[$k]['roleArray']=$roleArray;
  1598. }
  1599. // print_r($roleArray);
  1600. $verifyList [$k] ['date'] = "";
  1601. $verifyList [$k] ['opinion'] = "";
  1602. $verifyList [$k] ['status'] = "";
  1603. if (empty ( $verifyStaff )) {
  1604. $verifyList [$k] ['date'] = "";
  1605. $verifyList [$k] ['opinion'] = "";
  1606. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  1607. $verifyList [$k] ['status'] = 4;
  1608. $button = 4;
  1609. $flag = false;
  1610. }
  1611. } else {
  1612. foreach ( $verifyStaff as $m => $u ) {
  1613. if ($v [0] == $m) {
  1614. $verifyList [$k] ['date'] = $u ['date'];
  1615. $verifyList [$k] ['opinion'] = $u ['opinion'];
  1616. $verifyList [$k] ['status'] = $u ['status'];
  1617. $flag = false;
  1618. break;
  1619. }
  1620. }
  1621. $endStaffArray = end ( $verifyStaff );
  1622. if (isset ( $endStaffArray ['ROLE'] )) {
  1623. } else {
  1624. $endKey = key ( $verifyStaff );
  1625. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  1626. $button = 4;
  1627. $verifyList [$k] ['status'] = 4;
  1628. }
  1629. }
  1630. }
  1631. }
  1632. $rolename ['name'] = '';
  1633. if (! empty ( $roleId )) {
  1634. Doo::loadModel ( 'role' );
  1635. $role = new role ();
  1636. $rolename = $role->getOne ( array (
  1637. 'where' => 'rid=' . $roleId,
  1638. 'asArray' => true
  1639. ) );
  1640. }
  1641. if (! empty ( $verifyStaff ))
  1642. $endStaffArray = end ( $verifyStaff );
  1643. $KOP = false;
  1644. foreach ( $roleArrayCopy as $P => $A ) {
  1645. foreach ( $A as $MKI => $AVL ) {
  1646. if (! empty ( $verifyStaff )) {
  1647. // &&$rolename['rid']==$endStaffArray['nextStaff']
  1648. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  1649. $button = 4;
  1650. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1651. }
  1652. foreach ( $verifyStaff as $m => $u ) {
  1653. $AVLFK = $AVL [0] . '_R';
  1654. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  1655. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  1656. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  1657. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  1658. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  1659. break;
  1660. }
  1661. }
  1662. } else {
  1663. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  1664. $button = 4;
  1665. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  1666. }
  1667. }
  1668. // $roleArray[$MKI]['rolename']=$rolename['name'];
  1669. $KOP = true;
  1670. }
  1671. }
  1672. foreach ( $roleArrayCopy as $k => $v ) {
  1673. foreach ( $verifyList as $m => $n ) {
  1674. if ($n [0] == $k) {
  1675. array_splice ( $verifyList, $m, 1, $v );
  1676. }
  1677. }
  1678. }
  1679. $receiptList [$key] ['verifyList'] = $verifyList;
  1680. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  1681. 'where' => 'sid=' . $value ['staff'],
  1682. 'asArray' => true
  1683. ) );
  1684. $receiptList [$key] ['button'] = $button;
  1685. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  1686. }
  1687. $mothHtml = "";
  1688. for($i = 1; $i <= 12; $i ++) {
  1689. if ($month == $i)
  1690. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  1691. else
  1692. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  1693. }
  1694. // 获取审批日志
  1695. Doo::loadModel ( 'receiptLog' );
  1696. $receiptLog = new receiptLog ();
  1697. $rlList = array ();
  1698. $rlInfo = $receiptLog->getOne ( array (
  1699. 'where' => 'rid=' . $rid . ' and status=4',
  1700. 'asArray' => true
  1701. ) );
  1702. $tijdate = $receiptLog->getOne ( array (
  1703. 'where' => 'rid=' . $rid . ' and status=2',
  1704. 'asc' => 'rlid',
  1705. 'asArray' => true
  1706. ) );
  1707. if (! empty ( $rlInfo )) {
  1708. $rlList = $receiptLog->find ( array (
  1709. 'where' => 'rid=' . $rid,
  1710. 'asc' => 'rlid',
  1711. 'asArray' => true
  1712. ) );
  1713. }
  1714. $receiptList [0] ['rlList'] = $rlList;
  1715. $enclosurList = $enclosur->find ( array (
  1716. 'where' => 'rid=' . $rid,
  1717. 'asArray' => true
  1718. ) );
  1719. $enclosurHtml = '';
  1720. foreach ( $enclosurList as $value ) {
  1721. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  1722. }
  1723. // print_r($receiptList);
  1724. $data ['enclosurHtml'] = $enclosurHtml;
  1725. $data ['rolename'] = $rolename ['name'];
  1726. $data ['datetij'] = $tijdate ['date'];
  1727. $data ['mothHtml'] = $mothHtml;
  1728. $data ['rid'] = $rid;
  1729. $data ['receiptList'] = $receiptList;
  1730. $data ['receiptApprovalCount'] = count ( $receiptList );
  1731. $data ['status'] = $status;
  1732. $data ['year'] = $year;
  1733. $data ['categoryList'] = $categoryList;
  1734. $data ['staffList'] = $staffList;
  1735. $data ['cid'] = $cid;
  1736. $data ['sid'] = $sid;
  1737. $data ['ap'] = $ap;
  1738. $data ['memu'] = "receipt";
  1739. $data ['staff'] = $this->staff;
  1740. $data ['receiptMemu'] = 'approvalExpenses';
  1741. $data ['verifyId'] = $this->verifyId;
  1742. $data ['executeId'] = $this->executeId;
  1743. $this->render ( "/admin/remitApproval", $data );
  1744. }
  1745. function saeaLoanAdd() {
  1746. Doo::loadModel ( 'verify' );
  1747. $verify = new verify ();
  1748. Doo::loadModel ( "role" );
  1749. $role = new role ();
  1750. Doo::loadModel ( 'L_category' );
  1751. $lCategory = new L_category ();
  1752. $veList = $verify->getVerifyBySubordinate('LOAN');
  1753. $data ['category'] = $lCategory->find ( array (
  1754. 'asArray' => true
  1755. ) );
  1756. $data ['veList'] = $veList;
  1757. $data ['memu'] = "receipt";
  1758. $data ['staff'] = $this->staff;
  1759. $data ['receiptMemu'] = 'saeaBorad';
  1760. $data ['verifyId'] = $this->verifyId;
  1761. $data ['executeId'] = $this->executeId;
  1762. $this->render ( "/admin/saeaLoanAdd", $data );
  1763. }
  1764. function saeaLoanAddDo() {
  1765. $agency = $this->get_args ( 'agency' );
  1766. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1767. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1768. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1769. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1770. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1771. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1772. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1773. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1774. // die;
  1775. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1776. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1777. header ( 'Content-Type:text/html;charset=utf-8' );
  1778. die ( '请填写联行号' );
  1779. }
  1780. Doo::loadModel ( 'receipt' );
  1781. Doo::loadModel ( 'receiptDetail' );
  1782. Doo::loadModel ( 'accountItem' );
  1783. $accountItem = new accountItem ();
  1784. $receipt = new receipt ();
  1785. Doo::loadModel ( 'loanReceipt' );
  1786. $loanReceipt = new loanReceipt ();
  1787. Doo::loadModel ( 'execute' );
  1788. $execute = new execute ();
  1789. Doo::loadModel ( 'enclosur' );
  1790. $executeDetail = $execute->getOne ( array (
  1791. 'where' => 'mold="借款执行人"',
  1792. 'asArray' => true
  1793. ) );
  1794. $aItem = $accountItem->find ( array (
  1795. 'asArray' => true
  1796. ) );
  1797. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1798. $ag = $tr = $ta = $ot = 0;
  1799. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1800. array_push ( $accountJson ['借款费用'], array (
  1801. 'aid' => 0,
  1802. 'name' => '申请金额',
  1803. 'price' => number_format ( $agency, 2, '.', '' )
  1804. ) );
  1805. $sum += $agency;
  1806. $agencySum += $agency;
  1807. $accountJson ['cSum'] = array (
  1808. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1809. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1810. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1811. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1812. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1813. );
  1814. // 借款数据备份
  1815. $loanReceipt->loanItem = json_encode ( $accountJson );
  1816. $loanReceipt->staff = $this->staff [0] ['sid'];
  1817. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  1818. $loanReceipt->date = date ( "Y-m-d" );
  1819. $loanReceipt->cid = $cid;
  1820. $loanReceipt->receiptOrder = "#J" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1821. $loanReceipt->status = 5;
  1822. $loanReceipt->Rtype = 1;
  1823. $loanReceipt->verify = $verify;
  1824. $receipt->receiptOrder = $receipt->receiptOrder;
  1825. // 添加HTML换行符
  1826. // var_dump($explanation);
  1827. $order = array (
  1828. "\r\n",
  1829. "\n",
  1830. "\r"
  1831. );
  1832. $replace = '<br/>';
  1833. $explanation = str_replace ( $order, $replace, $explanation );
  1834. // $explanation=str_replace('\r',"<br/>",$explanation);
  1835. // $explanation=str_replace('\r\n',"<br/>",$explanation);
  1836. $loanReceipt->explanation = $explanation;
  1837. $loanRid = $loanReceipt->insert ();
  1838. // 报销单
  1839. $receipt->loanItem = json_encode ( $accountJson );
  1840. $receipt->staff = $this->staff [0] ['sid'];
  1841. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1842. $receipt->date = date ( "Y-m-d" );
  1843. $receipt->cid = $cid;
  1844. // 特殊状态
  1845. $receipt->status = 5;
  1846. $receipt->Rtype = 1;
  1847. $receipt->loanRid = $loanRid;
  1848. // 修改审批流程加入角色
  1849. $receipt->verify = $verify;
  1850. $receipt->executeCopy = $executeDetail ['staff'];
  1851. $receipt->receiptOrder = $loanReceipt->receiptOrder;
  1852. $receipt->explanation = $explanation;
  1853. $receipt->remittanceName = $remittanceName;
  1854. $receipt->bankName = $bankName;
  1855. $receipt->bankNumber = $bankNumber;
  1856. $receipt->remittanceBankType = $remittanceBankType;
  1857. if ($remittanceBankType == 1)
  1858. $receipt->coupletNumber = $coupletNumber;
  1859. $rid = $receipt->insert ();
  1860. return "/saeaBorad";
  1861. } else
  1862. die ( 'illegal request' );
  1863. }
  1864. function saeaLoanEdi() {
  1865. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  1866. Doo::loadClass ( 'XDeode' );
  1867. $XDeode = new XDeode ( 7 );
  1868. $rid = $XDeode->decode ( $ridKey );
  1869. if (! is_numeric ( $rid ))
  1870. die ( 'illegal request' );
  1871. Doo::loadModel ( 'verify' );
  1872. $verify = new verify ();
  1873. Doo::loadModel ( "role" );
  1874. $role = new role ();
  1875. Doo::loadModel ( 'L_category' );
  1876. $lCategory = new L_category ();
  1877. Doo::loadModel ( 'receipt' );
  1878. $receipt = new receipt ();
  1879. $receiptInfo = $receipt->getOne ( array (
  1880. 'where' => 'rid=' . $rid,
  1881. 'asArray' => true
  1882. ) );
  1883. $veList = $verify->find ( array (
  1884. 'where'=>'subordinate like "%LOAN%"',
  1885. 'asArray' => true
  1886. ) );
  1887. foreach ( $veList as $key => $value ) {
  1888. $v = json_decode ( $value ['staff'] );
  1889. $list = array ();
  1890. foreach ( $v as $n => $m ) {
  1891. if ($m ['1'] == 'ROLE') {
  1892. $roleInfo = $role->getOne ( array (
  1893. 'where' => 'rid=' . $m [0],
  1894. 'asArray' => true
  1895. ) );
  1896. $v [$n] [1] = $roleInfo ['name'];
  1897. array_push ( $list, $roleInfo ['name'] );
  1898. } else {
  1899. array_push ( $list, $v [$n] [1] );
  1900. }
  1901. }
  1902. $veList [$key] ['staff'] = implode ( '>', $list );
  1903. }
  1904. $receiptInfo ['loanItem'] = json_decode ( $receiptInfo ['loanItem'], true );
  1905. // print_r($receiptInfo);
  1906. $data ['receiptInfo'] = $receiptInfo;
  1907. $data ['category'] = $lCategory->find ( array (
  1908. 'asArray' => true
  1909. ) );
  1910. $data ['veList'] = $veList;
  1911. $data ['ridKey'] = $ridKey;
  1912. $data ['memu'] = "receipt";
  1913. $data ['staff'] = $this->staff;
  1914. $data ['receiptMemu'] = 'saeaBorad';
  1915. $data ['verifyId'] = $this->verifyId;
  1916. $data ['executeId'] = $this->executeId;
  1917. $this->render ( "/admin/saeaLoanEdi", $data );
  1918. }
  1919. function saeaLoanEdiDo() {
  1920. $ridKey = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : 0;
  1921. $agency = $this->get_args ( 'agency' );
  1922. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  1923. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  1924. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  1925. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  1926. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  1927. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  1928. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  1929. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  1930. // die;
  1931. Doo::loadClass ( 'XDeode' );
  1932. $XDeode = new XDeode ( 7 );
  1933. $rid = $XDeode->decode ( $ridKey );
  1934. if (! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  1935. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  1936. header ( 'Content-Type:text/html;charset=utf-8' );
  1937. die ( '请填写联行号' );
  1938. }
  1939. Doo::loadModel ( 'receipt' );
  1940. Doo::loadModel ( 'receiptDetail' );
  1941. Doo::loadModel ( 'accountItem' );
  1942. $accountItem = new accountItem ();
  1943. $receipt = new receipt ();
  1944. Doo::loadModel ( 'loanReceipt' );
  1945. $loanReceipt = new loanReceipt ();
  1946. Doo::loadModel ( 'enclosur' );
  1947. Doo::loadModel ( 'execute' );
  1948. $execute = new execute ();
  1949. $executeDetail = $execute->getOne ( array (
  1950. 'where' => 'mold="借款执行人"',
  1951. 'asArray' => true
  1952. ) );
  1953. $receiptDetail = $receipt->getOne ( array (
  1954. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=5 or status=4) and rid=' . $rid,
  1955. 'asArray' => true
  1956. ) );
  1957. if (empty ( $receiptDetail ))
  1958. die ( '参数错误' );
  1959. $aItem = $accountItem->find ( array (
  1960. 'asArray' => true
  1961. ) );
  1962. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = $accountJson ['借款费用'] = array ();
  1963. $ag = $tr = $ta = $ot = 0;
  1964. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  1965. array_push ( $accountJson ['借款费用'], array (
  1966. 'aid' => 0,
  1967. 'name' => '申请金额',
  1968. 'price' => number_format ( $agency, 2, '.', '' )
  1969. ) );
  1970. $sum += $agency;
  1971. $agencySum += $agency;
  1972. $accountJson ['cSum'] = array (
  1973. 'loanSum' => number_format ( $agencySum, 2, '.', '' ),
  1974. 'agencySum' => number_format ( 0, 2, '.', '' ),
  1975. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  1976. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  1977. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  1978. );
  1979. // 报销单
  1980. $receipt->loanItem = json_encode ( $accountJson );
  1981. $receipt->sum = number_format ( $sum, 2, '.', '' );
  1982. $receipt->cid = $cid;
  1983. // 特殊状态
  1984. // 修改审批流程加入角色
  1985. if ($receiptDetail ['status'] != 4)
  1986. $receipt->verify = $verify;
  1987. $order = array (
  1988. "\r\n",
  1989. "\n",
  1990. "\r"
  1991. );
  1992. $replace = '<br/>';
  1993. $explanation = str_replace ( $order, $replace, $explanation );
  1994. $receipt->explanation = $explanation;
  1995. $receipt->remittanceName = $remittanceName;
  1996. $receipt->bankName = $bankName;
  1997. $receipt->bankNumber = $bankNumber;
  1998. $receipt->remittanceBankType = $remittanceBankType;
  1999. if ($remittanceBankType == 1)
  2000. $receipt->coupletNumber = $coupletNumber;
  2001. $receipt->update ( array (
  2002. 'where' => 'rid=' . $rid
  2003. ) );
  2004. // 借款数据更新
  2005. $loanReceipt->loanItem = json_encode ( $accountJson );
  2006. $loanReceipt->sum = number_format ( $sum, 2, '.', '' );
  2007. $loanReceipt->cid = $cid;
  2008. if ($receiptDetail ['status'] != 4)
  2009. $loanReceipt->verify = $verify;
  2010. $loanReceipt->explanation = $explanation;
  2011. $receipt->executeCopy = $executeDetail ['staff'];
  2012. $loanReceipt->update ( array (
  2013. 'where' => 'rid=' . $receiptDetail ['loanRid']
  2014. ) );
  2015. }
  2016. return "/saeaBorad";
  2017. }
  2018. function saeaLoanReceiptAdd() {
  2019. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2020. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  2021. Doo::loadModel ( 'receipt' );
  2022. $receipt = new receipt ();
  2023. Doo::loadModel ( 'loanReceipt' );
  2024. $loanReceipt = new loanReceipt ();
  2025. Doo::loadModel ( 'L_category' );
  2026. $Lcategory = new L_category ();
  2027. Doo::loadModel ( 'verify' );
  2028. Doo::loadModel ( 'statistics' );
  2029. $statistics = new statistics ();
  2030. $verify = new verify ();
  2031. Doo::loadModel ( 'staff' );
  2032. $staff = new staff ();
  2033. $receiptDetail = $receipt->getOne ( array (
  2034. 'where' => 'rid=' . $rid,
  2035. 'desc' => 'rid',
  2036. 'asArray' => true
  2037. ) );
  2038. $receiptList = $loanReceipt->find ( array (
  2039. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  2040. 'desc' => 'rid',
  2041. 'asArray' => true
  2042. ) );
  2043. $Locate = 0;
  2044. $roleId = 0;
  2045. $button = 0;
  2046. foreach ( $receiptList as $key => $value ) {
  2047. $receiptList [$key] ['Locate'] = $Locate;
  2048. $Locate ++;
  2049. $receiptList [$key] ['reviseDetail'] = array ();
  2050. if (! empty ( $value ['reviseDetail'] ))
  2051. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2052. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2053. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2054. $categoryDetil = $Lcategory->getOne ( array (
  2055. 'where' => 'cid=' . $value ['cid'],
  2056. 'asArray' => true
  2057. ) );
  2058. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2059. // 检测编辑状态
  2060. $verifyList = $verify->getOne ( array (
  2061. 'where' => 'vid=' . $value ['verify'],
  2062. 'asArray' => true
  2063. ) );
  2064. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2065. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2066. Doo::loadModel ( 'role' );
  2067. $role = new role ();
  2068. $flag = true;
  2069. $roleKey = 0;
  2070. $endStaffArray = array ();
  2071. $roleArrayCopy = array ();
  2072. foreach ( $verifyList as $k => $v ) {
  2073. // init verifyStaff
  2074. if ($v [1] == 'ROLE') {
  2075. if (! empty ( $verifyStaff )) {
  2076. $endStaffArray = end ( $verifyStaff );
  2077. // if ($v[0]==$endStaffArray['nextStaff']){
  2078. // $roleId=$v[0];
  2079. // }
  2080. }
  2081. $roleVerify = json_decode ( $v [3], true );
  2082. $roleKey = $k;
  2083. $roleArray = array ();
  2084. $rolename = $role->getOne ( array (
  2085. 'where' => 'rid=' . $v [0],
  2086. 'asArray' => true
  2087. ) );
  2088. foreach ( $roleVerify as $o => $p ) {
  2089. $staffID = explode ( '_', $p );
  2090. $staffInfo = $staff->getOne ( array (
  2091. 'where' => 'sid=' . $staffID [0],
  2092. 'asArray' => true
  2093. ) );
  2094. // print_r($staffID);
  2095. $exp = array (
  2096. 0 => $staffInfo ['sid'],
  2097. 1 => $staffID [1],
  2098. 2 => $staffInfo ['avatar'],
  2099. 'date' => '',
  2100. 'date' => '',
  2101. 'opinion' => '',
  2102. 'status' => '',
  2103. 'rolename' => $rolename ['name']
  2104. );
  2105. array_push ( $roleArray, $exp );
  2106. }
  2107. $roleArrayCopy [$v [0]] = $roleArray;
  2108. // $verifyList[$k]['roleArray']=$roleArray;
  2109. }
  2110. $verifyList [$k] ['date'] = "";
  2111. $verifyList [$k] ['opinion'] = "";
  2112. $verifyList [$k] ['status'] = "";
  2113. if (empty ( $verifyStaff )) {
  2114. $verifyList [$k] ['date'] = "";
  2115. $verifyList [$k] ['opinion'] = "";
  2116. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2117. $verifyList [$k] ['status'] = 4;
  2118. $flag = false;
  2119. }
  2120. } else {
  2121. foreach ( $verifyStaff as $m => $u ) {
  2122. if ($v [0] == $m) {
  2123. $verifyList [$k] ['date'] = $u ['date'];
  2124. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2125. $verifyList [$k] ['status'] = $u ['status'];
  2126. $flag = false;
  2127. break;
  2128. }
  2129. }
  2130. $endStaffArray = end ( $verifyStaff );
  2131. if (isset ( $endStaffArray ['ROLE'] )) {
  2132. } else {
  2133. // $endKey=key($verifyStaff);
  2134. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2135. // $button=4;
  2136. // $verifyList[$k]['status']=4;
  2137. // }
  2138. }
  2139. }
  2140. }
  2141. $rolename ['name'] = '';
  2142. if (! empty ( $roleId )) {
  2143. Doo::loadModel ( 'role' );
  2144. $role = new role ();
  2145. $rolename = $role->getOne ( array (
  2146. 'where' => 'rid=' . $roleId,
  2147. 'asArray' => true
  2148. ) );
  2149. }
  2150. if (! empty ( $verifyStaff ))
  2151. $endStaffArray = end ( $verifyStaff );
  2152. $KOP = false;
  2153. foreach ( $roleArrayCopy as $P => $A ) {
  2154. foreach ( $A as $MKI => $AVL ) {
  2155. if (! empty ( $verifyStaff )) {
  2156. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2157. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2158. $button = 4;
  2159. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2160. }
  2161. foreach ( $verifyStaff as $m => $u ) {
  2162. $AVLFK = $AVL [0] . '_R';
  2163. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2164. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2165. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2166. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2167. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2168. break;
  2169. }
  2170. }
  2171. } else {
  2172. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2173. $button = 4;
  2174. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2175. }
  2176. }
  2177. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2178. $KOP = true;
  2179. }
  2180. }
  2181. foreach ( $roleArrayCopy as $k => $v ) {
  2182. foreach ( $verifyList as $m => $n ) {
  2183. if ($n [0] == $k) {
  2184. array_splice ( $verifyList, $m, 1, $v );
  2185. }
  2186. }
  2187. }
  2188. $receiptList [$key] ['verifyList'] = $verifyList;
  2189. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2190. 'where' => 'sid=' . $value ['staff'],
  2191. 'asArray' => true
  2192. ) );
  2193. $receiptList [$key] ['button'] = $button;
  2194. //
  2195. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  2196. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2197. }
  2198. $data ['receiptList'] = $receiptList;
  2199. $data ['receiptDetail'] = $receiptDetail;
  2200. Doo::loadModel ( 'L_category' );
  2201. $lCategory = new L_category ();
  2202. Doo::loadModel ( 'accountItem' );
  2203. $accountItem = new accountItem ();
  2204. $acItem = $accountItem->find ( array (
  2205. 'asArray' => true
  2206. ) );
  2207. $veList = $verify->getVerifyBySubordinate('RECEIPT','LOAN');
  2208. $data ['rid'] = $rid;
  2209. $data ['category'] = $lCategory->find ( array (
  2210. 'asArray' => true
  2211. ) );
  2212. $data ['veList'] = $veList;
  2213. $data ['acItem'] = $acItem;
  2214. $data['itineraryDate']=$this->_itineraryDateMin();
  2215. $data ['memu'] = "receipt";
  2216. $data ['staff'] = $this->staff;
  2217. $data ['receiptMemu'] = 'saeaBorad';
  2218. $data ['verifyId'] = $this->verifyId;
  2219. $data ['executeId'] = $this->executeId;
  2220. $data['receiptClass']=$receiptClass;
  2221. if($receiptClass=='trave'){
  2222. $this->render ( "/receipt/feeLoanReceiptTrave", $data );
  2223. }else{
  2224. $this->render ( "/receipt/feeLoanReceipt", $data );
  2225. }
  2226. }
  2227. function saeaLoanReceiptAddDo() {
  2228. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  2229. $agency = $this->get_args ( 'agency' );
  2230. $travel = $this->get_args ( 'travel' );
  2231. $train = $this->get_args ( 'train' );
  2232. $other = $this->get_args ( 'other' );
  2233. $inttrain = $this->get_args ( 'inttrain' );
  2234. $itinerary = $_POST['itinerary'];//$this->get_args ( 'itinerary' ) ? $this->get_args ( 'itinerary' ) : "";
  2235. $receiptClass = $this->get_args ( 'receiptClass' ) ? $this->get_args ( 'receiptClass' ) : "";
  2236. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2237. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  2238. $explanation = $this->get_args ( 'explanation' ) ? $this->get_args ( 'explanation' ) : "";
  2239. $enclosurName = $this->get_args ( 'enclosurName' ) ? $this->get_args ( 'enclosurName' ) : "";
  2240. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2241. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2242. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2243. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2244. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2245. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $explanation ) && ! empty ( $rid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber )) {
  2246. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2247. header ( 'Content-Type:text/html;charset=utf-8' );
  2248. die ( '请填写联行号' );
  2249. }
  2250. if($receiptClass=='agency'){
  2251. $receiptClass=1;
  2252. }elseif($receiptClass=='trave'){
  2253. $receiptClass=2;
  2254. if($this->_verificationItinerary($itinerary)){
  2255. header ( 'Content-Type:text/html;charset=utf-8' );
  2256. die ( '已申请过类此日期的行程' );
  2257. }
  2258. }elseif($receiptClass=='internalTrain'){
  2259. $receiptClass=3;
  2260. }else{
  2261. header ( 'Content-Type:text/html;charset=utf-8' );
  2262. die ( '借款报销单分类不正确' );
  2263. }
  2264. Doo::loadModel ( 'receipt' );
  2265. Doo::loadModel ( 'receiptDetail' );
  2266. Doo::loadModel ( 'accountItem' );
  2267. $accountItem = new accountItem ();
  2268. $receipt = new receipt ();
  2269. Doo::loadModel ( 'enclosur' );
  2270. Doo::loadModel ( 'execute' );
  2271. $execute = new execute ();
  2272. $executeDetail = $execute->getOne ( array (
  2273. 'where' => 'mold="借款费用执行人"',
  2274. 'asArray' => true
  2275. ) );
  2276. $receiptDet = $receipt->getOne ( array (
  2277. 'where' => 'rid=' . $rid,
  2278. 'asArray' => true
  2279. ) );
  2280. // if(!empty($receiptDetail))
  2281. // return "/referReceipt/".$receiptDetail['rid'];
  2282. $aItem = $accountItem->find ( array (
  2283. 'asArray' => true
  2284. ) );
  2285. $accountJson [$this->AGENCY]=$accountJson [$this->INTTRAIN] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  2286. $ag = $tr = $ta = $ot =$it = 0;
  2287. $sum = $agencySum = $travelSum = $trainSum =$inttrainSum= $otherSum = 0;
  2288. foreach ( $aItem as $key => $value ) {
  2289. if ($value ['category'] == $this->AGENCY) {
  2290. if (is_numeric ( $agency [$ag] ) && $agency [$ag] != 0) {
  2291. array_push ( $accountJson [$this->AGENCY], array (
  2292. 'aid' => $value ['aid'],
  2293. 'name' => $value ['name'],
  2294. 'price' => number_format ( $agency [$ag], 2, '.', '' )
  2295. ) );
  2296. $sum += $agency [$ag];
  2297. $agencySum += $agency [$ag];
  2298. }
  2299. $ag ++;
  2300. }
  2301. if ($value ['category'] == $this->TRAVEL) {
  2302. if (is_numeric ( $travel [$tr] ) && $travel [$tr] != 0) {
  2303. array_push ( $accountJson [$this->TRAVEL], array (
  2304. 'aid' => $value ['aid'],
  2305. 'name' => $value ['name'],
  2306. 'price' => number_format ( $travel [$tr], 2, '.', '' )
  2307. ) );
  2308. $sum += $travel [$tr];
  2309. $travelSum += $travel [$tr];
  2310. }
  2311. $tr ++;
  2312. }
  2313. if ($value ['category'] == $this->INTTRAIN) {
  2314. if (is_numeric ( $inttrain [$it] ) && $inttrain [$it] != 0) {
  2315. array_push ( $accountJson [$this->INTTRAIN], array (
  2316. 'aid' => $value ['aid'],
  2317. 'name' => $value ['name'],
  2318. 'price' => number_format ( $inttrain [$it], 2, '.', '' )
  2319. ) );
  2320. $sum += $inttrain [$it];
  2321. $inttrainSum += $inttrain [$it];
  2322. }
  2323. $it ++;
  2324. }
  2325. if ($value ['category'] == $this->TRAIN) {
  2326. if (is_numeric ( $train [$ta] ) && $train [$ta] != 0) {
  2327. array_push ( $accountJson [$this->TRAIN], array (
  2328. 'aid' => $value ['aid'],
  2329. 'name' => $value ['name'],
  2330. 'price' => number_format ( $train [$ta], 2, '.', '' )
  2331. ) );
  2332. $sum += $train [$ta];
  2333. $trainSum += $train [$ta];
  2334. }
  2335. $ta ++;
  2336. }
  2337. if ($value ['category'] == $this->OTHER) {
  2338. if (is_numeric ( $other [$ot] ) && $other [$ot] != 0) {
  2339. array_push ( $accountJson [$this->OTHER], array (
  2340. 'aid' => $value ['aid'],
  2341. 'name' => $value ['name'],
  2342. 'price' => number_format ( $other [$ot], 2, '.', '' )
  2343. ) );
  2344. $sum += $other [$ot];
  2345. $otherSum += $other [$ot];
  2346. }
  2347. $ot ++;
  2348. }
  2349. }
  2350. $accountJson ['cSum'] = array (
  2351. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  2352. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  2353. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  2354. 'inttrainSum'=>number_format ( $inttrainSum, 2, '.', '' ),
  2355. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  2356. );
  2357. // 报销单
  2358. $receipt->accountItem = json_encode ( $accountJson );
  2359. $receipt->staff = $this->staff [0] ['sid'];
  2360. $receipt->loanSum = $receiptDet ['sum'];
  2361. $receipt->sum = number_format ( $sum, 2, '.', '' );
  2362. $receipt->date = date ( "Y-m-d" );
  2363. $receipt->pastDate = '0000-00-00';
  2364. $receipt->cid = $cid;
  2365. $receipt->status = 7;
  2366. $receipt->receiptClass=$receiptClass;
  2367. if($receiptClass==2){
  2368. $receipt->itinerary2=$itinerary;
  2369. $this->_storageItinerary($itinerary, $rid);
  2370. }
  2371. // 修改审批流程加入角色
  2372. $receipt->verify = $verify;
  2373. $receipt->verifyStaff = '';
  2374. $receipt->executeStaff = '';
  2375. $receipt->executeCopy = $executeDetail ['staff'];
  2376. // $receipt->receiptOrder="#B".date("Ymd").mt_rand(1000,9999);
  2377. $receipt->explanation = $explanation;
  2378. $receipt->remittanceName = $remittanceName;
  2379. $receipt->bankName = $bankName;
  2380. $receipt->bankNumber = $bankNumber;
  2381. $receipt->remittanceBankType = $remittanceBankType;
  2382. if ($remittanceBankType == 1)
  2383. $receipt->coupletNumber = $coupletNumber;
  2384. $receipt->update ( array (
  2385. 'where' => 'rid=' . $rid
  2386. ) );
  2387. // 附件
  2388. if (! empty ( $enclosurName )) {
  2389. $enclosurArray = explode ( '-', $enclosurName );
  2390. foreach ( $enclosurArray as $value ) {
  2391. $enclosur = new enclosur ();
  2392. $enclosur->name = $value;
  2393. $enclosur->rid = $rid;
  2394. $enclosur->insert ();
  2395. }
  2396. // print_r($enclosurArray);die;
  2397. }
  2398. // 报销详情
  2399. foreach ( $accountJson [$this->AGENCY] as $key => $value ) {
  2400. $receiptDetail = new receiptDetail ();
  2401. $receiptDetail->staff = $this->staff [0] ['sid'];
  2402. $receiptDetail->item = $value ['name'];
  2403. $receiptDetail->itemCategory = $this->AGENCY;
  2404. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2405. $receiptDetail->date = date ( "Y-m-d" );
  2406. $receiptDetail->cid = $cid;
  2407. $receiptDetail->rid = $rid;
  2408. $receiptDetail->status = 4;
  2409. $receiptDetail->insert ();
  2410. }
  2411. foreach ( $accountJson [$this->TRAVEL] as $key => $value ) {
  2412. $receiptDetail = new receiptDetail ();
  2413. $receiptDetail->staff = $this->staff [0] ['sid'];
  2414. $receiptDetail->item = $value ['name'];
  2415. $receiptDetail->itemCategory = $this->TRAVEL;
  2416. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2417. $receiptDetail->date = date ( "Y-m-d" );
  2418. $receiptDetail->cid = $cid;
  2419. $receiptDetail->rid = $rid;
  2420. $receiptDetail->status = 4;
  2421. $receiptDetail->insert ();
  2422. }
  2423. foreach ( $accountJson [$this->TRAIN] as $key => $value ) {
  2424. $receiptDetail = new receiptDetail ();
  2425. $receiptDetail->staff = $this->staff [0] ['sid'];
  2426. $receiptDetail->item = $value ['name'];
  2427. $receiptDetail->itemCategory = $this->TRAIN;
  2428. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2429. $receiptDetail->date = date ( "Y-m-d" );
  2430. $receiptDetail->cid = $cid;
  2431. $receiptDetail->rid = $rid;
  2432. $receiptDetail->status = 4;
  2433. $receiptDetail->insert ();
  2434. }
  2435. //内训
  2436. foreach ( $accountJson [$this->INTTRAIN] as $key => $value ) {
  2437. $receiptDetail = new receiptDetail ();
  2438. $receiptDetail->staff = $this->staff [0] ['sid'];
  2439. $receiptDetail->item = $value ['name'];
  2440. $receiptDetail->itemCategory = $this->INTTRAIN;
  2441. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2442. $receiptDetail->date = date ( "Y-m-d" );
  2443. $receiptDetail->cid = $cid;
  2444. $receiptDetail->rid = $rid;
  2445. $receiptDetail->status = 4;
  2446. $receiptDetail->insert ();
  2447. }
  2448. foreach ( $accountJson [$this->OTHER] as $key => $value ) {
  2449. $receiptDetail = new receiptDetail ();
  2450. $receiptDetail->staff = $this->staff [0] ['sid'];
  2451. $receiptDetail->item = $value ['name'];
  2452. $receiptDetail->itemCategory = $this->OTHER;
  2453. $receiptDetail->price = number_format ( $value ['price'], 2, '.', '' );
  2454. $receiptDetail->date = date ( "Y-m-d" );
  2455. $receiptDetail->cid = $cid;
  2456. $receiptDetail->rid = $rid;
  2457. $receiptDetail->status = 4;
  2458. $receiptDetail->insert ();
  2459. }
  2460. return "/saeaBorad";
  2461. }
  2462. return "/saeaLoanReceiptAdd/" . $rid;
  2463. }
  2464. function saeaLoanReceiptEdi() {
  2465. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  2466. Doo::loadClass ( 'XDeode' );
  2467. $XDeode = new XDeode ( 7 );
  2468. $rid = $XDeode->decode ( $ridKey );
  2469. if (! is_numeric ( $rid ))
  2470. die ( 'illegal request' );
  2471. Doo::loadModel ( 'accountItem' );
  2472. Doo::loadModel ( 'verify' );
  2473. Doo::loadModel ( 'receipt' );
  2474. $receipt = new receipt ();
  2475. $verify = new verify ();
  2476. $accountItem = new accountItem ();
  2477. Doo::loadModel ( 'L_category' );
  2478. $Lcategory = new L_category ();
  2479. Doo::loadModel ( "role" );
  2480. $role = new role ();
  2481. Doo::loadModel ( 'loanReceipt' );
  2482. $loanReceipt = new loanReceipt ();
  2483. Doo::loadModel ( 'staff' );
  2484. $staff = new staff ();
  2485. $receiptDetail = $receipt->getOne ( array (
  2486. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=7) and rid=' . $rid,
  2487. 'asArray' => true
  2488. ) );
  2489. if (empty ( $receiptDetail ))
  2490. return "/saeaBorad";
  2491. $receiptList = $loanReceipt->find ( array (
  2492. 'where' => 'rid=' . $receiptDetail ['loanRid'],
  2493. 'desc' => 'rid',
  2494. 'asArray' => true
  2495. ) );
  2496. $Locate = 0;
  2497. $roleId = 0;
  2498. $button = 0;
  2499. foreach ( $receiptList as $key => $value ) {
  2500. $receiptList [$key] ['Locate'] = $Locate;
  2501. $Locate ++;
  2502. $receiptList [$key] ['reviseDetail'] = array ();
  2503. if (! empty ( $value ['reviseDetail'] ))
  2504. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  2505. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  2506. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  2507. $categoryDetil = $Lcategory->getOne ( array (
  2508. 'where' => 'cid=' . $value ['cid'],
  2509. 'asArray' => true
  2510. ) );
  2511. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  2512. // 检测编辑状态
  2513. $verifyList = $verify->getOne ( array (
  2514. 'where' => 'vid=' . $value ['verify'],
  2515. 'asArray' => true
  2516. ) );
  2517. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  2518. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  2519. Doo::loadModel ( 'role' );
  2520. $role = new role ();
  2521. $flag = true;
  2522. $roleKey = 0;
  2523. $endStaffArray = array ();
  2524. $roleArrayCopy = array ();
  2525. foreach ( $verifyList as $k => $v ) {
  2526. // init verifyStaff
  2527. if ($v [1] == 'ROLE') {
  2528. if (! empty ( $verifyStaff )) {
  2529. $endStaffArray = end ( $verifyStaff );
  2530. // if ($v[0]==$endStaffArray['nextStaff']){
  2531. // $roleId=$v[0];
  2532. // }
  2533. }
  2534. $roleVerify = json_decode ( $v [3], true );
  2535. $roleKey = $k;
  2536. $roleArray = array ();
  2537. $rolename = $role->getOne ( array (
  2538. 'where' => 'rid=' . $v [0],
  2539. 'asArray' => true
  2540. ) );
  2541. foreach ( $roleVerify as $o => $p ) {
  2542. $staffID = explode ( '_', $p );
  2543. $staffInfo = $staff->getOne ( array (
  2544. 'where' => 'sid=' . $staffID [0],
  2545. 'asArray' => true
  2546. ) );
  2547. // print_r($staffID);
  2548. $exp = array (
  2549. 0 => $staffInfo ['sid'],
  2550. 1 => $staffID [1],
  2551. 2 => $staffInfo ['avatar'],
  2552. 'date' => '',
  2553. 'date' => '',
  2554. 'opinion' => '',
  2555. 'status' => '',
  2556. 'rolename' => $rolename ['name']
  2557. );
  2558. array_push ( $roleArray, $exp );
  2559. }
  2560. $roleArrayCopy [$v [0]] = $roleArray;
  2561. // $verifyList[$k]['roleArray']=$roleArray;
  2562. }
  2563. $verifyList [$k] ['date'] = "";
  2564. $verifyList [$k] ['opinion'] = "";
  2565. $verifyList [$k] ['status'] = "";
  2566. if (empty ( $verifyStaff )) {
  2567. $verifyList [$k] ['date'] = "";
  2568. $verifyList [$k] ['opinion'] = "";
  2569. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  2570. $verifyList [$k] ['status'] = 4;
  2571. $flag = false;
  2572. }
  2573. } else {
  2574. foreach ( $verifyStaff as $m => $u ) {
  2575. if ($v [0] == $m) {
  2576. $verifyList [$k] ['date'] = $u ['date'];
  2577. $verifyList [$k] ['opinion'] = $u ['opinion'];
  2578. $verifyList [$k] ['status'] = $u ['status'];
  2579. $flag = false;
  2580. break;
  2581. }
  2582. }
  2583. $endStaffArray = end ( $verifyStaff );
  2584. if (isset ( $endStaffArray ['ROLE'] )) {
  2585. } else {
  2586. // $endKey=key($verifyStaff);
  2587. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  2588. // $button=4;
  2589. // $verifyList[$k]['status']=4;
  2590. // }
  2591. }
  2592. }
  2593. }
  2594. $rolename ['name'] = '';
  2595. if (! empty ( $roleId )) {
  2596. Doo::loadModel ( 'role' );
  2597. $role = new role ();
  2598. $rolename = $role->getOne ( array (
  2599. 'where' => 'rid=' . $roleId,
  2600. 'asArray' => true
  2601. ) );
  2602. }
  2603. if (! empty ( $verifyStaff ))
  2604. $endStaffArray = end ( $verifyStaff );
  2605. $KOP = false;
  2606. foreach ( $roleArrayCopy as $P => $A ) {
  2607. foreach ( $A as $MKI => $AVL ) {
  2608. if (! empty ( $verifyStaff )) {
  2609. // &&$rolename['rid']==$endStaffArray['nextStaff']
  2610. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  2611. $button = 4;
  2612. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2613. }
  2614. foreach ( $verifyStaff as $m => $u ) {
  2615. $AVLFK = $AVL [0] . '_R';
  2616. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  2617. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  2618. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  2619. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  2620. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  2621. break;
  2622. }
  2623. }
  2624. } else {
  2625. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  2626. $button = 4;
  2627. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  2628. }
  2629. }
  2630. // $roleArray[$MKI]['rolename']=$rolename['name'];
  2631. $KOP = true;
  2632. }
  2633. }
  2634. foreach ( $roleArrayCopy as $k => $v ) {
  2635. foreach ( $verifyList as $m => $n ) {
  2636. if ($n [0] == $k) {
  2637. array_splice ( $verifyList, $m, 1, $v );
  2638. }
  2639. }
  2640. }
  2641. $receiptList [$key] ['verifyList'] = $verifyList;
  2642. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  2643. 'where' => 'sid=' . $value ['staff'],
  2644. 'asArray' => true
  2645. ) );
  2646. $receiptList [$key] ['button'] = $button;
  2647. //
  2648. // $receiptList[$key]['BIGsum']=$this->NumToCNMoney($value['sum']);
  2649. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  2650. }
  2651. $data ['receiptList'] = $receiptList;
  2652. $acItem = $accountItem->find ( array (
  2653. 'asArray' => true
  2654. ) );
  2655. $veList = $verify->find ( array (
  2656. 'asArray' => true
  2657. ) );
  2658. foreach ( $veList as $key => $value ) {
  2659. $v = json_decode ( $value ['staff'] );
  2660. $list = array ();
  2661. foreach ( $v as $n => $m ) {
  2662. if ($m ['1'] == 'ROLE') {
  2663. $roleInfo = $role->getOne ( array (
  2664. 'where' => 'rid=' . $m [0],
  2665. 'asArray' => true
  2666. ) );
  2667. $v [$n] [1] = $roleInfo ['name'];
  2668. array_push ( $list, $roleInfo ['name'] );
  2669. } else {
  2670. array_push ( $list, $v [$n] [1] );
  2671. }
  2672. }
  2673. $veList [$key] ['staff'] = implode ( '>', $list );
  2674. }
  2675. // 配置编辑信息
  2676. $accountItemList = json_decode ( $receiptDetail ['accountItem'], true );
  2677. foreach ( $acItem as $key => $value ) {
  2678. foreach ( $accountItemList [$this->AGENCY] as $k => $v ) {
  2679. if ($acItem [$key] ['category'] == $this->AGENCY && $acItem [$key] ['name'] == $v ['name']) {
  2680. $acItem [$key] ['price'] = $v ['price'];
  2681. }
  2682. }
  2683. foreach ( $accountItemList [$this->TRAIN] as $k => $v ) {
  2684. if ($acItem [$key] ['category'] == $this->TRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2685. $acItem [$key] ['price'] = $v ['price'];
  2686. }
  2687. }
  2688. foreach ( $accountItemList [$this->TRAVEL] as $k => $v ) {
  2689. if ($acItem [$key] ['category'] == $this->TRAVEL && $acItem [$key] ['name'] == $v ['name']) {
  2690. $acItem [$key] ['price'] = $v ['price'];
  2691. }
  2692. }
  2693. //内训
  2694. foreach ( $accountItemList [$this->INTTRAIN] as $k => $v ) {
  2695. if ($acItem [$key] ['category'] == $this->INTTRAIN && $acItem [$key] ['name'] == $v ['name']) {
  2696. $acItem [$key] ['price'] = $v ['price'];
  2697. }
  2698. }
  2699. foreach ( $accountItemList [$this->OTHER] as $k => $v ) {
  2700. if ($acItem [$key] ['category'] == $this->OTHER && $acItem [$key] ['name'] == $v ['name']) {
  2701. $acItem [$key] ['price'] = $v ['price'];
  2702. }
  2703. }
  2704. }
  2705. $data ['category'] = $Lcategory->find ( array (
  2706. 'asArray' => true
  2707. ) );
  2708. $data ['ridKey'] = $ridKey;
  2709. $data ['cSum'] = $accountItemList ['cSum'];
  2710. $data ['sum'] = $receiptDetail ['sum'];
  2711. $data ['receiptDetail'] = $receiptDetail;
  2712. $data ['veList'] = $veList;
  2713. $data ['acItem'] = $acItem;
  2714. $data ['memu'] = "receipt";
  2715. $data ['staff'] = $this->staff;
  2716. $data ['receiptMemu'] = 'saeaBorad';
  2717. $data ['verify'] = $receiptDetail ['verify'];
  2718. $data ['verifyId'] = $this->verifyId;
  2719. $data ['executeId'] = $this->executeId;
  2720. $data ['rid'] = $rid;
  2721. if($receiptDetail['receiptClass']==1){
  2722. $this->render ( "/receipt/feeLoanReceiptAgencyEdi", $data );
  2723. }elseif($receiptDetail['receiptClass']==2){
  2724. Doo::loadModel ( 'itinerary' );
  2725. $itinerary = new itinerary ();
  2726. $itinerary->delete(array('where' => 'rid=' . $receiptDetail['rid'] ));
  2727. $this->render ( "/receipt/feeLoanReceiptTraveEdi", $data );
  2728. }elseif($receiptDetail['receiptClass']==3){
  2729. $this->render ( "/receipt/feeLoanReceiptITEdi", $data );
  2730. }else{
  2731. $this->render ( "/admin/saeaLoanEdiReceipt", $data );
  2732. }
  2733. }
  2734. /**
  2735. * 培训班结算
  2736. */
  2737. function receiptTrainAdd() {
  2738. Doo::loadModel ( 'accountItem' );
  2739. $accountItem = new accountItem ();
  2740. $acItem = $accountItem->find ( array (
  2741. 'asArray' => true
  2742. ) );
  2743. // 审批组
  2744. Doo::loadModel ( 'verify' );
  2745. $verify = new verify ();
  2746. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2747. // 办事处
  2748. Doo::loadModel ( 'L_category' );
  2749. $lCategory = new L_category ();
  2750. $data ['category'] = $lCategory->getCategory ();
  2751. $data ['veList'] = $veList;
  2752. $data ['memu'] = "receipt";
  2753. $data ['staff'] = $this->staff;
  2754. $data ['acItem'] = $acItem;
  2755. $data ['receiptMemu'] = 'saeaBorad';
  2756. $data ['verifyId'] = $this->verifyId;
  2757. $data ['executeId'] = $this->executeId;
  2758. $this->render ( "/receipt/receiptTrainAdd", $data );
  2759. }
  2760. /**
  2761. * 添加培训班结算
  2762. */
  2763. function receiptTrainAddDo() {//include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  2764. // 培训班信息
  2765. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  2766. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  2767. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  2768. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  2769. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  2770. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  2771. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  2772. // 发票信息
  2773. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  2774. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  2775. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  2776. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2777. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  2778. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  2779. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  2780. //&&! empty ( $participants )
  2781. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  2782. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  2783. header ( 'Content-Type:text/html;charset=utf-8' );
  2784. die ( '请填写联行号' );
  2785. }
  2786. Doo::loadModel ( 'execute' );
  2787. $execute = new execute ();
  2788. $executeDetail = $execute->getOne ( array (
  2789. 'where' => 'mold="培训班结算"',
  2790. 'asArray' => true
  2791. ) );
  2792. if (empty ( $executeDetail )) {
  2793. header ( 'Content-Type:text/html;charset=utf-8' );
  2794. die ( '未设置执行人' );
  2795. }
  2796. Doo::loadClass ( 'XDeode' );
  2797. $XDeode = new XDeode ( 5 );
  2798. $cid = $XDeode->decode ( $cid );
  2799. Doo::loadModel ( 'receipt' );
  2800. $receipt = new receipt ();
  2801. Doo::loadModel ( 'receiptTraining' );
  2802. $receiptTraining = new receiptTraining ();
  2803. // 创建费用培训班
  2804. $item = array (
  2805. 'cid' => $this->staff [0] ['cid'],
  2806. 'categoryName' => $this->staff [0] ['category'],
  2807. 'trainName' => $trainName,
  2808. 'trainStartDate' => $trainStartDate,
  2809. 'trainEndDate' => $trainEndDate,
  2810. 'participants' => $participants,
  2811. 'freeParticipants'=>$freeParticipants,
  2812. 'trainAddress' => $trainAddress,
  2813. 'trainRemarks' => $trainRemarks,
  2814. 'creator' => $this->staff [0] ['sid'],
  2815. 'creatorDate' => date ( "Y-m-d H:i:s" )
  2816. );
  2817. $irid = $receiptTraining->addReceiptTraining ( $item );
  2818. // 报销单
  2819. $receipt->status = 5;
  2820. $receipt->trainId = $irid;
  2821. $receipt->Rtype = 3;
  2822. $receipt->staff = $this->staff [0] ['sid'];
  2823. $receipt->cid = $cid;
  2824. $receipt->verify = $verify;
  2825. $receipt->date = date ( "Y-m-d" );
  2826. $receipt->executeCopy = $executeDetail ['staff'];
  2827. $receipt->receiptOrder = "#P" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2828. $receipt->remittanceName = $remittanceName;
  2829. $receipt->bankName = $bankName;
  2830. $receipt->bankNumber = $bankNumber;
  2831. $receipt->remittanceBankType = $remittanceBankType;
  2832. if ($remittanceBankType == 1)
  2833. $receipt->coupletNumber = $coupletNumber;
  2834. $rid = $receipt->insert ();
  2835. $XDeode = new XDeode ( 7 );
  2836. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html";
  2837. } else
  2838. die ( 'illegal request' );
  2839. }
  2840. /**
  2841. * 培训班编辑
  2842. */
  2843. function receiptTrainEdi() {
  2844. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  2845. $trainEdiType = $this->get_args ( 'trainEdiType' ) ? $this->get_args ( 'trainEdiType' ) : "INFO";
  2846. Doo::loadClass ( 'XDeode' );
  2847. $XDeode = new XDeode ( 7 );
  2848. $rid = $XDeode->decode ( $ridKey );
  2849. if (! is_numeric ( $rid ))
  2850. die ( 'illegal request' );
  2851. Doo::loadModel ( 'receipt' );
  2852. $receipt = new receipt ();
  2853. Doo::loadModel ( 'receiptTraining' );
  2854. $receiptTraining = new receiptTraining ();
  2855. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  2856. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)){
  2857. die ('illegal request--status');
  2858. }
  2859. //如有已入账已收款的发票,自动取消办事处已收款
  2860. // Doo::loadModel ( 'RIExtend' );
  2861. // $RIExtend = new RIExtend ();
  2862. // $RIExtendList=$RIExtend->getRIExtendByRid($rid);
  2863. // if (!empty($RIExtendList)){
  2864. // foreach ($RIExtendList as $key=>$value){
  2865. // $RIExtend = new RIExtend ();
  2866. // $RIExtend->delete(array (
  2867. // 'where' => 'iid=' . $value['iid'],
  2868. // 'limit' => 1
  2869. // ));
  2870. // }
  2871. // }
  2872. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  2873. // 汇总表合计
  2874. // 收入合计--加入开票合计
  2875. Doo::loadModel ( 'invoiceTraining' );
  2876. $invoiceTraining = new invoiceTraining ();
  2877. $invoiceTrainingDetail = array (
  2878. 'invoiceArriveAmount' => 0,
  2879. 'RIAmount' => 0,
  2880. 'invoiceTotalAmount' => 0,
  2881. 'invoiceCompanyAmount'=>0
  2882. );
  2883. if ($receiptDetail ['invoiceTrainId'] != 0) {
  2884. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  2885. }
  2886. // print_r($invoiceTrainingDetail);
  2887. $invoiceArriveAmount = $RIAmount = 0;
  2888. if (! empty ( $invoiceTrainingDetail )) {
  2889. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  2890. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  2891. }
  2892. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  2893. //print_r($invoiceTrainingDetail);
  2894. // 支出项目
  2895. Doo::loadModel ( 'accountItem' );
  2896. $accountItem = new accountItem ();
  2897. // 项目金额合计
  2898. Doo::loadModel ( 'RItem' );
  2899. $RItem = new RItem ();
  2900. // 讲师获得
  2901. Doo::loadModel ( 'RILecturer' );
  2902. $RILecturer = new RILecturer ();
  2903. $RItemList = $RItem->getRItemByRid ( $rid );
  2904. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2905. // 支出项金额详情
  2906. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  2907. // print_r($aiData);
  2908. // 利润
  2909. $profit=$invoiceArriveAmount - $aiData ['total'];
  2910. $companyProfit=$profit * 0.6;
  2911. $categoryProfit=$profit * 0.4;
  2912. $data ['profit'] = sprintf("%.2f",$profit);
  2913. $data ['companyProfit'] = sprintf("%.2f",$companyProfit);
  2914. $data ['categoryProfit'] = sprintf("%.2f",$categoryProfit);
  2915. //发票利润
  2916. $data ['invoiceProfit'] = $invoiceTrainingDetail ['invoiceTotalAmount'] - $aiData ['total'];
  2917. //发票公司利润
  2918. $invoiceCompanyProfit=$data ['invoiceProfit'] * 0.6;
  2919. $data ['invoiceCompanyProfit'] = sprintf("%.2f",$invoiceCompanyProfit);
  2920. //办事处利润
  2921. $invoiceCategoryProfit=$data ['invoiceProfit'] * 0.4;
  2922. $data ['invoiceCategoryProfit'] = sprintf("%.2f",$invoiceCategoryProfit);
  2923. // print_r($aiData['dataList']);
  2924. $categoryActualExpenditure= $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  2925. $data ['categoryActualExpenditure'] = sprintf("%.2f",$categoryActualExpenditure);
  2926. // 备用金
  2927. $sum = 0;
  2928. $data ['receiptLoanDetail'] = array (
  2929. 'sum' => '0.00'
  2930. );
  2931. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  2932. //$data ['receiptLoanDetail'] = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2933. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  2934. $sum=0;
  2935. foreach ($receiptLoanList as $key=>$value){
  2936. $sum+=$value['sum'];
  2937. }
  2938. $data ['receiptLoanDetail'] = array (
  2939. 'sum' => $sum
  2940. );
  2941. //$sum = $data ['receiptLoanDetail'] ['sum'];
  2942. }
  2943. $payment=$sum + $RIAmount - $categoryActualExpenditure;
  2944. $data ['payment'] = sprintf("%.2f",$payment);
  2945. $data ['total'] = sprintf("%.2f",$aiData ['total']);
  2946. $data ['aiCount'] = count ( $aiData ['dataList'] ) + 5;
  2947. $data ['aiList'] = $aiData ['dataList'];
  2948. // 占比计算
  2949. if ($invoiceArriveAmount != 0) {
  2950. $data ['totalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceArriveAmount* 100) ;
  2951. $data ['profitProportion'] = sprintf("%.2f",$profit / $invoiceArriveAmount*100) ; //number_format ( $profit / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2952. $data ['sumProportion'] = sprintf("%.2f",$sum / $invoiceArriveAmount*100) ; //number_format ( $sum / $invoiceArriveAmount, 2, '.', '' ) * 100;
  2953. $data ['invoiceTotalAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceArriveAmount*100) ;
  2954. $data ['RIAmountProportion'] = sprintf("%.2f",$data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceArriveAmount*100) ;
  2955. $data ['companyProfitProportion'] = sprintf("%.2f",$companyProfit / $invoiceArriveAmount*100) ;
  2956. $data ['categoryProportion'] = sprintf("%.2f",$categoryProfit / $invoiceArriveAmount*100) ;
  2957. $data ['categoryActualExpenditureProportion'] = sprintf("%.2f",$categoryActualExpenditure / $invoiceArriveAmount*100) ;
  2958. $data ['paymentProportion'] = sprintf("%.2f",$payment / $invoiceArriveAmount*100) ;
  2959. } else {
  2960. $data ['totalProportion'] = $data ['profitProportion'] = $data ['sumProportion'] = $data ['invoiceTotalAmountProportion'] = $data ['RIAmountProportion'] = $data ['companyProfitProportion'] = $data ['categoryActualExpenditureProportion'] = $data ['paymentProportion'] = $data ['categoryProportion'] = 0;
  2961. }
  2962. //发票金额占比计算
  2963. if ($invoiceTrainingDetail ['invoiceTotalAmount'] != 0) {
  2964. //支出
  2965. $data ['invoicetotalProportion'] = sprintf("%.2f",$aiData ['total'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2966. //利润
  2967. $data ['invoiceprofitProportion'] = sprintf("%.2f",$data ['invoiceProfit'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2968. //公司利润
  2969. $data ['invoicecompanyProfitProportion'] = sprintf("%.2f", $invoiceCompanyProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2970. //办事处利润
  2971. $data ['invoicecategoryProportion'] = sprintf("%.2f", $invoiceCategoryProfit / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2972. //公司收款
  2973. $data ['invoiceTotalAmountProportionB'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['invoiceCompanyAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2974. //备用金
  2975. $data ['invoicesumProportion'] = sprintf("%.2f", $sum / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2976. //办事处收款
  2977. $data ['invoiceRIAmountProportion'] = sprintf("%.2f", $data ['invoiceTrainingDetail'] ['RIAmount'] / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2978. //办事处实际支出
  2979. $data ['ICAEP'] = sprintf("%.2f", $categoryActualExpenditure / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2980. //付总部款
  2981. $data ['invoicepaymentProportion'] = sprintf("%.2f", $payment / $invoiceTrainingDetail ['invoiceTotalAmount']* 100) ;
  2982. }else{
  2983. $data ['invoiceprofitProportion'] =$data ['invoiceRIAmountProportion'] =$data ['invoicetotalProportion'] =$data ['invoiceTotalAmountProportionB'] =$data ['invoicesumProportion'] =$data ['ICAEP'] =$data ['invoicepaymentProportion'] =$data ['invoicecompanyProfitProportion'] =$data ['invoicecategoryProportion'] =0;
  2984. }
  2985. //讲师人数
  2986. Doo::loadModel ( 'RILecturer' );
  2987. $RILecturer = new RILecturer ();
  2988. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  2989. $data['lectureCount']=count($RILecturerList);
  2990. // 审批组
  2991. Doo::loadModel ( 'verify' );
  2992. $verify = new verify ();
  2993. $veList = $verify->getVerifyBySubordinate('TRAIN');
  2994. // 办事处
  2995. Doo::loadModel ( 'L_category' );
  2996. $lCategory = new L_category ();
  2997. $data ['category'] = $lCategory->getCategory ();
  2998. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  2999. $data ['receiptDetail'] = $receiptDetail;
  3000. $data ['veList'] = $veList;
  3001. $data ['trainEdiType'] = $trainEdiType;
  3002. $data ['ridKey'] = $ridKey;
  3003. $data ['memu'] = "receipt";
  3004. $data ['staff'] = $this->staff;
  3005. $data ['receiptMemu'] = 'saeaBorad';
  3006. $data ['verifyId'] = $this->verifyId;
  3007. $data ['executeId'] = $this->executeId;
  3008. $this->render ( "/receipt/receiptTrainEdi", $data );
  3009. }
  3010. /**
  3011. * 培训班借款编辑
  3012. */
  3013. function receiptTrainLoanEdi() {
  3014. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3015. Doo::loadClass ( 'XDeode' );
  3016. $XDeode = new XDeode ( 7 );
  3017. $rid = $XDeode->decode ( $ridKey );
  3018. if (! is_numeric ( $rid ))
  3019. die ( 'illegal request' );
  3020. Doo::loadModel ( 'receipt' );
  3021. $receipt = new receipt ();
  3022. Doo::loadModel ( 'receiptTraining' );
  3023. $receiptTraining = new receiptTraining ();
  3024. Doo::loadModel ( 'verify' );
  3025. $verify = new verify ();
  3026. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3027. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  3028. die ();
  3029. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3030. // 借款详情HTML
  3031. // 获得借款信息
  3032. $receiptLoanHtml = '';
  3033. if (! empty ( $receiptDetail ['trainLoanRid'] )) {
  3034. $receiptLoanList = $receipt->getReceiptInRid ( $receiptDetail ['trainLoanRid'] );
  3035. foreach ($receiptLoanList as $key=>$value){
  3036. // 获得某费用单审批信息
  3037. $verifylist = $verify->getVerifyByRid ( $value ['rid'] );
  3038. Doo::loadClass ( 'receipt.func' );
  3039. $extendHtml = '<p><a class="button"
  3040. href="javascript:if(window.confirm(\'确认移除?\'))window.location=\'/receiptTrainLoanRemoveDo/' . $receiptDetail ['ridKey'] . '/' . $value ['ridKey'] . '.html\'" data-toggle="modal">移除借款</a></p>';
  3041. $receiptLoanHtml .= _getReceiptLoanHtml ( $value, $verifylist, $extendHtml );
  3042. }
  3043. }
  3044. $data ['receiptLoanHtml'] = $receiptLoanHtml;
  3045. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3046. $data ['receiptDetail'] = $receiptDetail;
  3047. $data ['trainEdiType'] = "LOAN";
  3048. $data ['ridKey'] = $ridKey;
  3049. $data ['memu'] = "receipt";
  3050. $data ['staff'] = $this->staff;
  3051. $data ['receiptMemu'] = 'saeaBorad';
  3052. $data ['verifyId'] = $this->verifyId;
  3053. $data ['executeId'] = $this->executeId;
  3054. $this->render ( "/receipt/receiptTrainLoanEdi", $data );
  3055. }
  3056. /**
  3057. * 更新培训班结算基本信息
  3058. */
  3059. function receiptTrainInfoEdiDo() {
  3060. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  3061. $rtid = $this->get_args ( 'rtid' ) ? $this->get_args ( 'rtid' ) : "";
  3062. // 培训班信息
  3063. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  3064. $trainStartDate = $this->get_args ( 'trainStartDate' ) ? $this->get_args ( 'trainStartDate' ) : "";
  3065. $trainEndDate = $this->get_args ( 'trainEndDate' ) ? $this->get_args ( 'trainEndDate' ) : "";
  3066. $participants = $this->get_args ( 'participants' ) && is_numeric ( $this->get_args ( 'participants' ) ) ? $this->get_args ( 'participants' ) : 0;
  3067. $freeParticipants = $this->get_args ( 'freeParticipants' ) && is_numeric ( $this->get_args ( 'freeParticipants' ) ) ? $this->get_args ( 'freeParticipants' ) : 0;
  3068. $trainAddress = $this->get_args ( 'trainAddress' ) ? $this->get_args ( 'trainAddress' ) : "";
  3069. $trainRemarks = $this->get_args ( 'trainRemarks' ) ? $this->get_args ( 'trainRemarks' ) : "";
  3070. // 发票信息
  3071. $verify = $this->get_args ( 'verify' ) && is_numeric ( $this->get_args ( 'verify' ) ) ? $this->get_args ( 'verify' ) : 0;
  3072. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  3073. $remittanceName = $this->get_args ( 'remittanceName' ) ? $this->get_args ( 'remittanceName' ) : "";
  3074. $bankName = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3075. $bankNumber = $this->get_args ( 'bankNumber' ) ? $this->get_args ( 'bankNumber' ) : "";
  3076. $coupletNumber = $this->get_args ( 'coupletNumber' ) ? $this->get_args ( 'coupletNumber' ) : "";
  3077. $remittanceBankType = $this->get_args ( 'remittanceBankType' ) && is_numeric ( $this->get_args ( 'remittanceBankType' ) ) ? $this->get_args ( 'remittanceBankType' ) : 0;
  3078. //&& ! empty ( $participants )
  3079. if (! empty ( $verify ) && ! empty ( $cid ) && ! empty ( $remittanceName ) && ! empty ( $bankName ) && ! empty ( $bankNumber ) && ! empty ( $trainName ) && ! empty ( $trainStartDate ) && ! empty ( $trainEndDate ) && ! empty ( $trainAddress )) {
  3080. if ($remittanceBankType == 1 && empty ( $coupletNumber )) {
  3081. header ( 'Content-Type:text/html;charset=utf-8' );
  3082. die ( '请填写联行号' );
  3083. }
  3084. Doo::loadClass ( 'XDeode' );
  3085. $XDeode = new XDeode ( 5 );
  3086. $cid = $XDeode->decode ( $cid );
  3087. $rtid = $XDeode->decode ( $rtid );
  3088. $rid = $XDeode->decode ( $rid );
  3089. if (! is_numeric ( $rtid ) || ! is_numeric ( $rid )) {
  3090. die ( 'illegal request-IdError' );
  3091. }
  3092. Doo::loadModel ( 'receipt' );
  3093. $receipt = new receipt ();
  3094. Doo::loadModel ( 'receiptTraining' );
  3095. $receiptTraining = new receiptTraining ();
  3096. // 更新费用培训班
  3097. $item = array (
  3098. 'rtid' => $rtid,
  3099. 'trainName' => $trainName,
  3100. 'trainStartDate' => $trainStartDate,
  3101. 'trainEndDate' => $trainEndDate,
  3102. 'participants' => $participants,
  3103. 'freeParticipants'=>$freeParticipants,
  3104. 'trainAddress' => $trainAddress,
  3105. 'trainRemarks' => $trainRemarks
  3106. );
  3107. $irid = $receiptTraining->setReceiptTrainByCondition ( $item );
  3108. // 报销单
  3109. $receipt->rid = $rid;
  3110. $receipt->cid = $cid;
  3111. $receipt->verify = $verify;
  3112. $receipt->remittanceName = $remittanceName;
  3113. $receipt->bankName = $bankName;
  3114. $receipt->bankNumber = $bankNumber;
  3115. $receipt->remittanceBankType = $remittanceBankType;
  3116. if ($remittanceBankType == 1)
  3117. $receipt->coupletNumber = $coupletNumber;
  3118. $receipt->update ();
  3119. $XDeode = new XDeode ( 7 );
  3120. return "/receiptTrainEdi/" . $XDeode->encode ( $rid ) . ".html?trainEdiType=INFO";
  3121. } else
  3122. die ( 'illegal request' );
  3123. }
  3124. /**
  3125. * 编辑培训班结算---更新借款
  3126. */
  3127. function receiptTrainLoanEdiDo() {
  3128. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3129. $ridLoanKey = $this->get_args ( 'ridLoanKey' ) ? $this->get_args ( 'ridLoanKey' ) : "";
  3130. if (! empty ( $ridKey ) && ! empty ( $ridLoanKey )) {
  3131. Doo::loadModel ( 'receipt' );
  3132. $receipt = new receipt ();
  3133. Doo::loadClass ( 'XDeode' );
  3134. $XDeode = new XDeode ( 5 );
  3135. $rid = $XDeode->decode ( $ridKey );
  3136. $ridLoan = $XDeode->decode ( $ridLoanKey );
  3137. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  3138. die ( 'illegal request-ridError' );
  3139. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3140. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  3141. // 不合法的数据if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3142. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3143. die ( 'illegal request-receiptError' );
  3144. }
  3145. if ($receiptLoanDetail ['status'] != 8 || $receiptLoanDetail ['Rtype'] != 1) {
  3146. die ( 'illegal request-receipLoantError' );
  3147. }
  3148. // 培训班结算挂钩借款
  3149. $receipt = new receipt ();
  3150. $trainLoanRid=$ridLoan;
  3151. if (!empty($receiptDetail['trainLoanRid'])){
  3152. $trainLoanRid=$receiptDetail['trainLoanRid'].','.$ridLoan;
  3153. }
  3154. $item = array (
  3155. 'rid' => $rid,
  3156. 'trainLoanRid' => $trainLoanRid
  3157. );
  3158. $receipt->setReceiptByCondition ( $item );
  3159. // 更新借款状态变成已挂钩
  3160. $receipt = new receipt ();
  3161. $item = array (
  3162. 'rid' => $ridLoan,
  3163. 'status' => 10,
  3164. 'statusTrain' => 1
  3165. );
  3166. $receipt->setReceiptByCondition ( $item );
  3167. $XDeode = new XDeode ( 7 );
  3168. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  3169. } else
  3170. die ( 'illegal request' );
  3171. }
  3172. /**
  3173. * 编辑培训班结算--移除借款
  3174. */
  3175. function receiptTrainLoanRemoveDo() {
  3176. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : 0;
  3177. $ridLoanKey = isset ( $this->params ['ridLoanKey'] ) ? $this->params ['ridLoanKey'] : 0;
  3178. if (! empty ( $ridKey ) || ! empty ( $ridLoanKey )) {
  3179. Doo::loadModel ( 'receipt' );
  3180. $receipt = new receipt ();
  3181. Doo::loadClass ( 'XDeode' );
  3182. $XDeode = new XDeode ( 5 );
  3183. $rid = $XDeode->decode ( $ridKey );
  3184. $ridLoan = $XDeode->decode ( $ridLoanKey );
  3185. if (! is_numeric ( $rid ) || ! is_numeric ( $ridLoan ))
  3186. die ( 'illegal request-ridError' );
  3187. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3188. $receiptLoanDetail = $receipt->getReceiptByRid ( $ridLoan );
  3189. // 不合法的数据 !($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)
  3190. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3191. die ( 'illegal request-receiptError' );
  3192. }
  3193. if ($receiptLoanDetail ['status'] != 10 || $receiptLoanDetail ['Rtype'] != 1) {
  3194. die ( 'illegal request-receipLoantError' );
  3195. }
  3196. // 培训班结算挂钩借款
  3197. $receipt = new receipt ();
  3198. $trainLoanRidArray=explode(",", $receiptDetail['trainLoanRid']);
  3199. foreach ($trainLoanRidArray as $key=>$value){
  3200. if($value==$ridLoan){
  3201. unset($trainLoanRidArray[$key]);
  3202. }
  3203. }
  3204. $trainLoanRidString=implode(",", $trainLoanRidArray);
  3205. $item = array (
  3206. 'rid' => $rid,
  3207. 'trainLoanRid' => $trainLoanRidString
  3208. );
  3209. $receipt->setReceiptByCondition ( $item );
  3210. // 更新借款状态变成已挂钩
  3211. $receipt = new receipt ();
  3212. $item = array (
  3213. 'rid' => $ridLoan,
  3214. 'status' => 8,
  3215. 'statusTrain' => 0
  3216. );
  3217. $receipt->setReceiptByCondition ( $item );
  3218. $XDeode = new XDeode ( 7 );
  3219. return "/receiptTrainLoanEdi/" . $XDeode->encode ( $rid ) . ".html";
  3220. } else
  3221. die ( 'illegal request' );
  3222. }
  3223. /**
  3224. * 编辑培训班结算 ---开票
  3225. */
  3226. function receiptTrainInvoiceEdi() {
  3227. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3228. Doo::loadClass ( 'XDeode' );
  3229. $XDeode = new XDeode ( 7 );
  3230. $rid = $XDeode->decode ( $ridKey );
  3231. if (! is_numeric ( $rid ))
  3232. die ( 'illegal request' );
  3233. Doo::loadModel ( 'receipt' );
  3234. $receipt = new receipt ();
  3235. Doo::loadModel ( 'receiptTraining' );
  3236. $receiptTraining = new receiptTraining ();
  3237. Doo::loadModel ( 'invoice' );
  3238. $invoice = new invoice ();
  3239. Doo::loadModel ( 'invoiceTraining' );
  3240. $invoiceTraining = new invoiceTraining ();
  3241. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3242. if (! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4))
  3243. die ();
  3244. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3245. $invoiceList = $invoiceTrainingDetail = array ();
  3246. if ($receiptDetail ['invoiceTrainId'] != 0) {
  3247. $invoiceList = $invoice->getInvoicePrintedByItid ( $receiptDetail ['invoiceTrainId'] );
  3248. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $receiptDetail ['invoiceTrainId'] );
  3249. }
  3250. //print_r($invoiceList);
  3251. $data ['invoiceList'] = $invoiceList;
  3252. $data ['invoiceTrainingDetail'] = $invoiceTrainingDetail;
  3253. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3254. $data ['receiptDetail'] = $receiptDetail;
  3255. $data ['trainEdiType'] = "INVOICE";
  3256. $data ['ridKey'] = $ridKey;
  3257. $data ['memu'] = "receipt";
  3258. $data ['staff'] = $this->staff;
  3259. $data ['receiptMemu'] = 'saeaBorad';
  3260. $data ['verifyId'] = $this->verifyId;
  3261. $data ['executeId'] = $this->executeId;
  3262. $this->render ( "/receipt/receiptTrainInvoiceEdi", $data );
  3263. }
  3264. /**
  3265. * 编辑培训班结算---更新开票
  3266. */
  3267. function receiptTrainInvoiceEdiDo() {
  3268. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3269. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : "";
  3270. if (! empty ( $ridKey ) && ! empty ( $itidKey )) {
  3271. Doo::loadModel ( 'receipt' );
  3272. $receipt = new receipt ();
  3273. Doo::loadModel ( 'invoiceTraining' );
  3274. $invoiceTraining = new invoiceTraining ();
  3275. Doo::loadClass ( 'XDeode' );
  3276. $XDeode = new XDeode ( 5 );
  3277. $rid = $XDeode->decode ( $ridKey );
  3278. $itid = $XDeode->decode ( $itidKey );
  3279. if (! is_numeric ( $rid ) || ! is_numeric ( $itid ))
  3280. die ( 'illegal request-idError' );
  3281. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3282. $invoiceTrainDetail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  3283. // 不合法的数据
  3284. if ((! ($receiptDetail ['status'] == 5 || $receiptDetail ['status'] == 4)) || $receiptDetail ['Rtype'] != 3) {
  3285. die ( 'illegal request-receiptError' );
  3286. }
  3287. if (empty ( $invoiceTrainDetail ) || $invoiceTrainDetail ['bindReceipt'] == 1) {
  3288. die ( 'illegal request-receipLoantError' );
  3289. }
  3290. // 培训班结算挂钩借款
  3291. $receipt = new receipt ();
  3292. $item = array (
  3293. 'rid' => $rid,
  3294. 'invoiceTrainId' => $itid
  3295. );
  3296. $receipt->setReceiptByCondition ( $item );
  3297. $invoiceTraining = new invoiceTraining ();
  3298. $item = array (
  3299. 'bindReceipt' => 1,
  3300. 'itid' => $itid
  3301. );
  3302. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3303. $XDeode = new XDeode ( 7 );
  3304. return "/receiptTrainInvoiceEdi/" . $XDeode->encode ( $rid ) . ".html";
  3305. } else
  3306. die ( 'illegal request' );
  3307. }
  3308. /**
  3309. * 更新培训班结算 收款和取消收款
  3310. */
  3311. function receiptTrainReceivables() {
  3312. $doType = isset ( $this->params ['doType'] ) ? $this->params ['doType'] : '';
  3313. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3314. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3315. Doo::loadClass ( 'XDeode' );
  3316. $XDeode = new XDeode ( 5 );
  3317. $rid = $XDeode->decode ( $ridKey );
  3318. $iid = $XDeode->decode ( $iidKey );
  3319. if (! is_numeric ( $rid ) || ! is_numeric ( $iid ))
  3320. die ( 'illegal request-iid' );
  3321. Doo::loadModel ( 'RIExtend' );
  3322. $RIExtend = new RIExtend ();
  3323. if ($doType == 'CONFIRM') {
  3324. $RIExtend->rid = $rid;
  3325. $RIExtend->iid = $iid;
  3326. $RIExtend->RIstatus = 1;
  3327. $RIExtend->insert ();
  3328. echo json_encode ( array (
  3329. 'status' => 1,
  3330. ) );
  3331. die ( );
  3332. } elseif ($doType == 'CANCEL') {
  3333. $RIExtend->delete ( array (
  3334. 'where' => 'rid=' . $rid . ' and iid=' . $iid,
  3335. 'limit' => 1
  3336. ) );
  3337. echo json_encode ( array (
  3338. 'status' => 1,
  3339. ) );
  3340. die ( );
  3341. } else {
  3342. echo json_encode ( array (
  3343. 'status' => 2,
  3344. ) );
  3345. die ( );
  3346. }
  3347. }
  3348. /**
  3349. * 移除挂钩的培训班发票
  3350. */
  3351. function receiptTrainReceivablesDelDo() {
  3352. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3353. $itidKey = $this->get_args ( 'itidKey' ) ? $this->get_args ( 'itidKey' ) : ""; // 发票培训班
  3354. Doo::loadModel ( 'receipt' );
  3355. $receipt = new receipt ();
  3356. Doo::loadModel ( 'RIExtend' );
  3357. $RIExtend = new RIExtend ();
  3358. Doo::loadClass ( 'XDeode' );
  3359. $XDeode = new XDeode ( 5 );
  3360. $rid = $XDeode->decode ( $ridKey );
  3361. $itid = $XDeode->decode ( $itidKey );
  3362. if (is_numeric ( $rid ) && is_numeric ( $itid )) {
  3363. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3364. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3365. die ( 'illegal request-status' );
  3366. }
  3367. $receipt = new receipt ();
  3368. $receipt->rid = $rid;
  3369. $receipt->invoiceTrainId = 0;
  3370. $receipt->update ();
  3371. Doo::loadModel ( 'invoiceTraining' );
  3372. $invoiceTraining = new invoiceTraining ();
  3373. $item = array (
  3374. 'bindReceipt' => 0,
  3375. 'itid' => $itid
  3376. );
  3377. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  3378. $RIExtend->delete ( array (
  3379. 'where' => 'rid=' . $rid
  3380. ) );
  3381. $XDeode = new XDeode ( 7 );
  3382. return '/receiptTrainInvoiceEdi/' . $XDeode->encode ( $rid ) . '.html';
  3383. } else
  3384. die ( 'illegal request-iid' );
  3385. }
  3386. /**
  3387. * 编辑培训班结算
  3388. */
  3389. function receiptTrainItemEdi() {
  3390. //include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  3391. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3392. $name = $this->get_args ( 'name' ) ? $this->get_args ( 'name' ) : '';
  3393. Doo::loadClass ( 'XDeode' );
  3394. $XDeode = new XDeode ( 7 );
  3395. $rid = $XDeode->decode ( $ridKey );
  3396. if (! is_numeric ( $rid ))
  3397. die ( 'illegal request' );
  3398. Doo::loadModel ( 'receipt' );
  3399. $receipt = new receipt ();
  3400. Doo::loadModel ( 'receiptTraining' );
  3401. $receiptTraining = new receiptTraining ();
  3402. Doo::loadModel ( 'RItem' );
  3403. $RItem = new RItem ();
  3404. Doo::loadModel ( 'accountItem' );
  3405. $accountItem = new accountItem ();
  3406. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3407. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3408. die ();
  3409. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3410. $RItemList = $RItem->getRItemByRid ( $rid,$name );
  3411. $aiList = $accountItem->getAccountBookByCategory ( '培训班费用' );//print_r($aiList);
  3412. // foreach ($aiList as $key=>$value){//不需要添加税款,在添加收入时自动添加
  3413. // if($value['name']=='税款'){
  3414. // unset($aiList[$key]);break;
  3415. // }
  3416. // }
  3417. //print_r($RItemList);
  3418. $data ['name'] = $name;
  3419. $data ['RItemList'] = $RItemList;
  3420. $data ['aiList'] = $aiList;
  3421. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3422. $data ['receiptDetail'] = $receiptDetail;
  3423. $data ['trainEdiType'] = "ITEM";
  3424. $data ['ridKey'] = $ridKey;
  3425. $data ['memu'] = "receipt";
  3426. $data ['staff'] = $this->staff;
  3427. $data ['receiptMemu'] = 'saeaBorad';
  3428. $data ['verifyId'] = $this->verifyId;
  3429. $data ['executeId'] = $this->executeId;
  3430. $this->render ( "/receipt/receiptTrainItemEdi", $data );
  3431. }
  3432. /**
  3433. * 添加支出项 需要修改 费用金额合计
  3434. */
  3435. function receiptTrainItemAddDo() {
  3436. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3437. $rtidKey = $this->get_args ( 'rtidKey' ) ? $this->get_args ( 'rtidKey' ) : "";
  3438. // 支出项信息
  3439. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3440. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : 0;
  3441. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3442. $inputer = $this->get_args ( 'inputer' ) ? $this->get_args ( 'inputer' ) : "";
  3443. $describe = $this->get_args ( 'describe' ) ? $this->get_args ( 'describe' ) : "";
  3444. //$identifyingTotal = $this->get_args ( 'identifyingTotal' )&&is_numeric($this->get_args ( 'identifyingTotal' )) ? $this->get_args ( 'identifyingTotal' ) : 0;
  3445. $payType = isset ( $this->params ['payType'] ) ? $this->params ['payType'] : '';
  3446. if (! empty ( $ridKey ) && ! empty ( $item ) && is_numeric( $price ) && ! empty ( $date ) && ! empty ( $inputer )) {
  3447. Doo::loadClass ( 'XDeode' );
  3448. $XDeode = new XDeode ( 5 );
  3449. Doo::loadModel ( 'RItem' );
  3450. $RItem = new RItem ();
  3451. $rid = $XDeode->decode ( $ridKey );
  3452. $rtid= $XDeode->decode ( $rtidKey );
  3453. if (! is_numeric ( $rid )){
  3454. die ( 'illegal request' );
  3455. }
  3456. Doo::loadModel ( 'receiptDetail' );
  3457. $receiptDetail = new receiptDetail ();
  3458. Doo::loadModel ( 'receipt' );
  3459. $receipt = new receipt ();
  3460. Doo::loadModel ( 'receiptTraining' );
  3461. $receiptTraining = new receiptTraining ();
  3462. $rtDetail=$receiptTraining->getReceiptTrainingByRtid($rtid);
  3463. $identifyingTotal=$rtDetail['identifyingTotal']+1;
  3464. $order = array (
  3465. "\r\n",
  3466. "\n",
  3467. "\r"
  3468. );
  3469. $replace = '<br/>';
  3470. $describe = str_replace ( $order, $replace, $describe );
  3471. $itemData = array (
  3472. 'rid' => $rid,
  3473. 'item' => $item,
  3474. 'price' => $price,
  3475. 'date' => $date,
  3476. 'inputer' => $inputer,
  3477. 'describe' => $describe,
  3478. 'creater' => $this->staff['0']['username'],
  3479. 'createrId' => $this->staff['0']['sid'],
  3480. 'creatDate' => date ( "Y-m-d H:i:s" ),
  3481. 'identifying'=>$identifyingTotal
  3482. );
  3483. if($payType=='company'){
  3484. $itemData += array (
  3485. 'payType' => 1
  3486. );
  3487. }
  3488. $RItem->addRItem($itemData, $receipt, $receiptDetail, $rid, $item, $price, $payType);
  3489. //更新支出项标识总数
  3490. $itemData = array (
  3491. 'rtid'=>$rtid,
  3492. 'identifyingTotal'=>$identifyingTotal
  3493. );
  3494. $receiptTraining->setReceiptTrainByCondition($itemData);
  3495. $XDeode = new XDeode ( 7 );
  3496. if($payType=='company'){
  3497. return '/receiptTrainItem/approval/' . $XDeode->encode ( $rid ) . '.html';
  3498. }else{
  3499. return '/receiptTrainItemEdi/' . $XDeode->encode ( $rid ) . '.html';
  3500. }
  3501. } else
  3502. die ( 'illegal request-dataError' );
  3503. }
  3504. /**
  3505. * 培训班结算-讲师
  3506. */
  3507. function receiptTrainLecturerEdi() {
  3508. $ridKey = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  3509. Doo::loadClass ( 'XDeode' );
  3510. $XDeode = new XDeode ( 7 );
  3511. $rid = $XDeode->decode ( $ridKey );
  3512. if (! is_numeric ( $rid ))
  3513. die ( 'illegal request' );
  3514. Doo::loadModel ( 'receipt' );
  3515. $receipt = new receipt ();
  3516. Doo::loadModel ( 'receiptTraining' );
  3517. $receiptTraining = new receiptTraining ();
  3518. Doo::loadModel ( 'RILecturer' );
  3519. $RILecturer = new RILecturer ();
  3520. Doo::loadModel ( 'lecturer' );
  3521. $lecturer = new lecturer ();
  3522. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3523. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4))
  3524. die ();
  3525. $receiptTrainingDetail = $receiptTraining->getReceiptTrainingByRtid ( $receiptDetail ['trainId'] );
  3526. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3527. $lecturerList = $lecturer->getLecturerAll ();
  3528. $INSIDEhtml = $OUTSIDEhtml = '';
  3529. foreach ( $lecturerList as $key => $value ) {
  3530. if ($value ['ltype'] == 'INSIDE') {
  3531. $INSIDEhtml .= '<option value="' . $value ['category'] . '-' . $value ['staff'] . '">' . $value ['category'] . '-' . $value ['staff'] . '</option>';
  3532. } elseif ($value ['ltype'] == 'OUTSIDE') {
  3533. $OUTSIDEhtml .= '<option value="' . $value ['staff'] . '">' . $value ['staff'] . '</option>';
  3534. }
  3535. }
  3536. $data ['INSIDEhtml'] = $INSIDEhtml;
  3537. $data ['OUTSIDEhtml'] = $OUTSIDEhtml;
  3538. // print_r($RItemList);
  3539. $data ['RILecturerList'] = $RILecturerList;
  3540. $data ['receiptTrainingDetail'] = $receiptTrainingDetail;
  3541. $data ['receiptDetail'] = $receiptDetail;
  3542. $data ['trainEdiType'] = "LECTURER";
  3543. $data ['ridKey'] = $ridKey;
  3544. $data ['memu'] = "receipt";
  3545. $data ['staff'] = $this->staff;
  3546. $data ['receiptMemu'] = 'saeaBorad';
  3547. $data ['verifyId'] = $this->verifyId;
  3548. $data ['executeId'] = $this->executeId;
  3549. $this->render ( "/receipt/receiptTrainLecturerEdi", $data );
  3550. }
  3551. /**
  3552. * 添加讲师
  3553. */
  3554. function receiptTrainLecturerAddDo() {
  3555. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3556. // 支出项信息
  3557. $ltype = $this->get_args ( 'ltype' ) ? $this->get_args ( 'ltype' ) : "";
  3558. $lecturerName = $this->get_args ( 'lecturerName' ) ? $this->get_args ( 'lecturerName' ) : "";
  3559. $schoolDay = $this->get_args ( 'schoolDay' ) ? $this->get_args ( 'schoolDay' ) : "";
  3560. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  3561. $taxation = $this->get_args ( 'taxation' ) ? $this->get_args ( 'taxation' ) : "";
  3562. $fees = $this->get_args ( 'fees' ) ? $this->get_args ( 'fees' ) : "";
  3563. if (! empty ( $ridKey ) && ! empty ( $ltype ) && ! empty ( $lecturerName ) && ! empty ( $schoolDay ) && ! empty ( $price )) {
  3564. Doo::loadClass ( 'XDeode' );
  3565. $XDeode = new XDeode ( 5 );
  3566. Doo::loadModel ( 'RILecturer' );
  3567. $RILecturer = new RILecturer ();
  3568. $rid = $XDeode->decode ( $ridKey );
  3569. if (! is_numeric ( $rid ))
  3570. die ( 'illegal request' );
  3571. if ($ltype == 'OUTSIDE' && empty ( $taxation ))
  3572. die ( 'illegal request-taxationError' );
  3573. $RILecturer->rid = $rid;
  3574. $RILecturer->ltype = $ltype;
  3575. if ($ltype == 'OUTSIDE') {
  3576. if ($taxation == 'TAXATION') {
  3577. $RILecturer->taxation = 1;
  3578. } elseif ($taxation == 'NOTAXATION') {
  3579. $RILecturer->taxation = 0;
  3580. }
  3581. }
  3582. $RILecturer->lecturerName = $lecturerName;
  3583. $RILecturer->schoolDay = $schoolDay;
  3584. $RILecturer->price = $price;
  3585. $RILecturer->fees=$fees;
  3586. $RILecturer->insert ();
  3587. // 添加公司汇总
  3588. // 报销详情
  3589. Doo::loadModel ( 'receiptDetail' );
  3590. $receiptDetail = new receiptDetail ();
  3591. Doo::loadModel ( 'receipt' );
  3592. $receipt = new receipt ();
  3593. // 金额总计
  3594. $price = $price * $schoolDay;
  3595. $rInfo = $receipt->getReceiptByRid ( $rid );
  3596. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3597. if (empty ( $rdInfo )) {
  3598. $receiptDetail = new receiptDetail ();
  3599. $receiptDetail->staff = $rInfo ['staff'];
  3600. $receiptDetail->item = '讲课费';
  3601. $receiptDetail->itemCategory = '培训班费用';
  3602. $receiptDetail->price = number_format ( $fees, 2, '.', '' );
  3603. $receiptDetail->date = date ( "Y-m-d" );
  3604. $receiptDetail->cid = $rInfo ['cid'];
  3605. $receiptDetail->rid = $rid;
  3606. $receiptDetail->status = 4;
  3607. $receiptDetail->insert ();
  3608. } else {
  3609. $receiptDetail = new receiptDetail ();
  3610. $rdInfo ['price'] += $fees;
  3611. $receiptDetail->price = $rdInfo ['price'];
  3612. $receiptDetail->update ( array (
  3613. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3614. ) );
  3615. }
  3616. $receipt = new receipt ();
  3617. $receipt->sum=$rInfo['sum']+$fees;
  3618. $receipt->update ( array (
  3619. 'where' => 'rid=' . $rid
  3620. ) );
  3621. $XDeode = new XDeode ( 7 );
  3622. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3623. } else
  3624. die ( 'illegal request' );
  3625. }
  3626. /**
  3627. * 移除讲师
  3628. */
  3629. function receiptTrainLecturerDelDo() {
  3630. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : ""; // 费用 培训班结算
  3631. $rlidKey = $this->get_args ( 'rlidKey' ) ? $this->get_args ( 'rlidKey' ) : ""; // 发票培训班
  3632. Doo::loadModel ( 'receipt' );
  3633. $receipt = new receipt ();
  3634. Doo::loadModel ( 'RILecturer' );
  3635. $RILecturer = new RILecturer ();
  3636. Doo::loadClass ( 'XDeode' );
  3637. $XDeode = new XDeode ( 5 );
  3638. $rid = $XDeode->decode ( $ridKey );
  3639. $rlid = $XDeode->decode ( $rlidKey );
  3640. if (is_numeric ( $rid ) && is_numeric ( $rlid )) {
  3641. $receiptDetail = $receipt->getReceiptByRid ( $rid );
  3642. if (!($receiptDetail ['status'] == 5||$receiptDetail ['status'] == 4)){
  3643. die ( 'illegal request-status' );
  3644. }
  3645. $detail=$RILecturer->getRILecturerByRlid($rlid);
  3646. if (empty($detail)){
  3647. die ( 'illegal request-data' );
  3648. }
  3649. $RILecturer->delete ( array (
  3650. 'where' => 'rid=' . $rid . ' and rlid=' . $rlid
  3651. ) );
  3652. //更新费用合计金额
  3653. $rInfo = $receipt->getReceiptByRid ( $rid );
  3654. $receipt = new receipt ();
  3655. $receipt->sum= $receiptDetail['sum']-$detail['price'];
  3656. $receipt->update ( array (
  3657. 'where' => 'rid=' . $rid
  3658. ) );
  3659. Doo::loadModel ( 'receiptDetail' );
  3660. $receiptDetail = new receiptDetail ();
  3661. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, '讲课费', '培训班费用' );
  3662. $receiptDetail = new receiptDetail ();
  3663. $rdInfo ['price'] -= number_format ( $detail['price'], 2, '.', '' );
  3664. $receiptDetail->price = $rdInfo ['price'];
  3665. $receiptDetail->update ( array (
  3666. 'where' => 'rid=' . $rid . ' and item like "' . '讲课费' . '" and itemCategory like "培训班费用"'
  3667. ) );
  3668. $XDeode = new XDeode ( 7 );
  3669. return '/receiptTrainLecturerEdi/' . $XDeode->encode ( $rid ) . '.html';
  3670. } else
  3671. die ( 'illegal request-iid' );
  3672. }
  3673. /**
  3674. * 培训班提交审批
  3675. */
  3676. function receiptTrainDo() {
  3677. $ridKey = $this->get_args ( 'ridKey' ) ? $this->get_args ( 'ridKey' ) : "";
  3678. Doo::loadClass ( 'XDeode' );
  3679. $XDeode = new XDeode ( 7 );
  3680. $rid = $XDeode->decode ( $ridKey );
  3681. Doo::loadModel ( 'receipt' );
  3682. $receipt = new receipt ();
  3683. Doo::loadModel ( 'receiptDetail' );
  3684. $receiptDetail = new receiptDetail ();
  3685. Doo::loadModel ( 'statistics' );
  3686. $statistics = new statistics ();
  3687. Doo::loadModel ( "verify" );
  3688. $verify = new verify ();
  3689. // 审批状态的判定
  3690. $receiptDetailList = $receipt->getOne ( array (
  3691. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  3692. 'asArray' => true
  3693. ) );
  3694. if (empty ( $receiptDetailList ))
  3695. return "/saeaBorad";
  3696. $verifyDetail = $verify->getOne ( array (
  3697. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3698. 'asArray' => true
  3699. ) );
  3700. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3701. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3702. $nowStaff = "";
  3703. $nowStaffList = array ();
  3704. if ($verifyDetail [0] [1] == 'ROLE') {
  3705. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3706. foreach ( $vStaffString as $key => $value ) {
  3707. $staffK = explode ( "_", $value );
  3708. array_push ( $nowStaffList, $staffK [0] );
  3709. }
  3710. $nowStaff = implode ( ',', $nowStaffList );
  3711. } else {
  3712. $nowStaff = $verifyDetail [0] [0];
  3713. }
  3714. $receipt->nowStaff = $nowStaff;
  3715. }
  3716. // echo $nowStaff;
  3717. // print_r($verifyDetail);die;
  3718. $receipt->rid = $receiptDetailList ['rid'];
  3719. $receipt->date = date ( "Y-m-d" );
  3720. $receipt->status = 2;
  3721. $receipt->update ();
  3722. $receiptDetail->status = 2;
  3723. $receiptDetail->update ( array (
  3724. 'where' => 'rid=' . $receiptDetailList ['rid']
  3725. ) );
  3726. Doo::loadModel ( "receiptLog" );
  3727. $receiptLog = new receiptLog ();
  3728. Doo::loadModel ( "verify" );
  3729. $verify = new verify ();
  3730. $vr = $verify->getOne ( array (
  3731. 'where' => 'vid=' . $receiptDetailList ['verify'],
  3732. 'asArray' => true
  3733. ) );
  3734. $jd = json_decode ( $vr ['staff'] );
  3735. $roleId = 0;
  3736. foreach ( $jd as $key => $value ) {
  3737. if ($value [1] == 'ROLE') {
  3738. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3739. if ($pos !== false) {
  3740. $roleId = $value [0];
  3741. }
  3742. }
  3743. }
  3744. // 审批日志
  3745. // echo $roleId;die;
  3746. if (! empty ( $roleId )) {
  3747. Doo::loadModel ( "role" );
  3748. $role = new role ();
  3749. $roleInfo = $role->getOne ( array (
  3750. 'where' => 'rid=' . $roleId,
  3751. 'asArray' => true
  3752. ) );
  3753. // $receiptLog->rolename = $roleInfo ['name'];
  3754. }
  3755. $receiptLog->username = $this->staff [0] ['username'];
  3756. $receiptLog->uid = $this->staff [0] ['sid'];
  3757. $receiptLog->date = date ( "Y-m-d" );
  3758. $receiptLog->opinion = '提交审批';
  3759. $receiptLog->img = $this->staff [0] ['avatar'];
  3760. $receiptLog->status = 2;
  3761. $receiptLog->rid = $rid;
  3762. $receiptLog->insert ();
  3763. // 写入列表项
  3764. Doo::loadModel ( 'accountItem' );
  3765. $accountItem = new accountItem ();
  3766. $aItem = $accountItem->getAccountBookByCategory ( '培训班费用' );
  3767. // 项目金额合计
  3768. Doo::loadModel ( 'RItem' );
  3769. $RItem = new RItem ();
  3770. // 讲师获得
  3771. Doo::loadModel ( 'RILecturer' );
  3772. $RILecturer = new RILecturer ();
  3773. $RItemList = $RItem->getRItemByRid ( $rid );
  3774. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  3775. // 支出项金额详情
  3776. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, 0 );
  3777. // print_r($aItem);
  3778. // print_r($aiData);
  3779. $accountJson [$this->AGENCY] = $accountJson [$this->TRAVEL] = $accountJson [$this->TRAIN] = $accountJson [$this->OTHER] = array ();
  3780. $ag = $tr = $ta = $ot = 0;
  3781. $sum = $agencySum = $travelSum = $trainSum = $otherSum = 0;
  3782. foreach ( $aItem as $key => $value ) {
  3783. if ($value ['category'] == $this->TRAIN) {
  3784. foreach ( $aiData ['dataList'] as $k => $v ) {
  3785. if ($value ['name'] == $v ['name']) {
  3786. array_push ( $accountJson [$this->TRAIN], array (
  3787. 'aid' => $value ['aid'],
  3788. 'name' => $value ['name'],
  3789. 'price' => number_format ( $v ['price'], 2, '.', '' )
  3790. ) );
  3791. $sum += $v ['price'];
  3792. $trainSum += $v ['price'];
  3793. unset ( $aiData ['dataList'] [$k] );
  3794. break;
  3795. }
  3796. }
  3797. }
  3798. }
  3799. $accountJson ['cSum'] = array (
  3800. 'agencySum' => number_format ( $agencySum, 2, '.', '' ),
  3801. 'travelSum' => number_format ( $travelSum, 2, '.', '' ),
  3802. 'trainSum' => number_format ( $trainSum, 2, '.', '' ),
  3803. 'otherSum' => number_format ( $otherSum, 2, '.', '' )
  3804. );
  3805. // 报销单
  3806. $receipt = new receipt ();
  3807. $receipt->accountItem = json_encode ( $accountJson );
  3808. $receipt->sum = number_format ( $sum, 2, '.', '' );
  3809. $receipt->update ( array (
  3810. 'where' => 'rid=' . $rid
  3811. ) );
  3812. // print_r($accountJson);
  3813. // statistics item 统计写入
  3814. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  3815. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  3816. $accountItem = $accountJson;
  3817. $stat = $statistics->getOne ( array (
  3818. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3819. 'asArray' => true
  3820. ) );
  3821. if (empty ( $stat )) {
  3822. $statistics->date = date ( "Y-m-d" );
  3823. $statistics->cid = $this->staff [0] ['cid'];
  3824. $statistics->staff = $this->staff [0] ['sid'];
  3825. $statistics->agPrice = 0;
  3826. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3827. $statistics->insert ();
  3828. } else {
  3829. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  3830. $statistics->update ( array (
  3831. 'where' => 'sid=' . $stat ['sid']
  3832. ) );
  3833. }
  3834. return "/saeaBorad";
  3835. }
  3836. function confirmation() {
  3837. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  3838. Doo::loadModel ( 'receipt' );
  3839. Doo::loadModel ( 'receiptDetail' );
  3840. $receipt = new receipt ();
  3841. $receiptDetail = new receiptDetail ();
  3842. Doo::loadModel ( 'statistics' );
  3843. Doo::loadModel ( 'itemStatistics' );
  3844. $statistics = new statistics ();
  3845. $itemStatistics = new itemStatistics ();
  3846. Doo::loadModel ( "verify" );
  3847. $verify = new verify ();
  3848. $receiptDetailList = $receipt->getOne ( array (
  3849. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=4 or status=5) and Rtype=1 and rid=' . $rid,
  3850. 'asArray' => true
  3851. ) );
  3852. if (empty ( $receiptDetailList ))
  3853. return "/saeaBorad";
  3854. $verifyDetail = $verify->getOne ( array (
  3855. 'where' => ' vid =' . $receiptDetailList ['verify'],
  3856. 'asArray' => true
  3857. ) );
  3858. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  3859. if (empty ( $receiptDetailList ['nowStaff'] )) {
  3860. $nowStaff = "";
  3861. $nowStaffList = array ();
  3862. if ($verifyDetail [0] [1] == 'ROLE') {
  3863. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  3864. foreach ( $vStaffString as $key => $value ) {
  3865. $staffK = explode ( "_", $value );
  3866. array_push ( $nowStaffList, $staffK [0] );
  3867. }
  3868. $nowStaff = implode ( ',', $nowStaffList );
  3869. } else {
  3870. $nowStaff = $verifyDetail [0] [0];
  3871. }
  3872. $receipt->nowStaff = $nowStaff;
  3873. }
  3874. // echo $nowStaff;
  3875. // print_r($verifyDetail);die;
  3876. $receipt->rid = $receiptDetailList ['rid'];
  3877. $receipt->status = 2;
  3878. $receipt->update ();
  3879. // 操作日志
  3880. Doo::loadModel ( "receiptLog" );
  3881. $receiptLog = new receiptLog ();
  3882. $verify = new verify ();
  3883. $receiptInfo = $receipt->getOne ( array (
  3884. 'where' => 'rid=' . $rid,
  3885. 'asArray' => true
  3886. ) );
  3887. $vr = $verify->getOne ( array (
  3888. 'where' => 'vid=' . $receiptInfo ['verify'],
  3889. 'asArray' => true
  3890. ) );
  3891. $jd = json_decode ( $vr ['staff'] );
  3892. $roleId = 0;
  3893. foreach ( $jd as $key => $value ) {
  3894. if ($value [1] == 'ROLE') {
  3895. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  3896. if ($pos !== false) {
  3897. $roleId = $value [0];
  3898. }
  3899. }
  3900. }
  3901. // 审批日志
  3902. // echo $roleId;die;
  3903. if (! empty ( $roleId )) {
  3904. Doo::loadModel ( "role" );
  3905. $role = new role ();
  3906. $roleInfo = $role->getOne ( array (
  3907. 'where' => 'rid=' . $roleId,
  3908. 'asArray' => true
  3909. ) );
  3910. // $receiptLog->rolename = $roleInfo ['name'];
  3911. }
  3912. $receiptLog->username = $this->staff [0] ['username'];
  3913. $receiptLog->uid = $this->staff [0] ['sid'];
  3914. $receiptLog->date = date ( "Y-m-d" );
  3915. $receiptLog->opinion = '提交审批';
  3916. $receiptLog->img = $this->staff [0] ['avatar'];
  3917. $receiptLog->status = 2;
  3918. $receiptLog->rid = $rid;
  3919. $receiptLog->insert ();
  3920. return "/expenses";
  3921. }
  3922. function expenses() {
  3923. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  3924. if (empty ( $item ))
  3925. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  3926. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3927. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  3928. Doo::loadClass ( 'XDeode' );
  3929. $XDeode = new XDeode ( 7 );
  3930. Doo::loadModel ( 'receipt' );
  3931. $receipt = new receipt ();
  3932. Doo::loadModel ( 'L_category' );
  3933. $Lcategory = new L_category ();
  3934. Doo::loadModel ( 'verify' );
  3935. Doo::loadModel ( 'statistics' );
  3936. $statistics = new statistics ();
  3937. $verify = new verify ();
  3938. Doo::loadModel ( 'staff' );
  3939. $staff = new staff ();
  3940. $condition = "";
  3941. if ($item == "expenses")
  3942. $condition = " and Rtype=1 ";
  3943. elseif ($item == "receipts")
  3944. $condition = " and Rtype=0 ";
  3945. elseif ($item == "remits")
  3946. $condition = " and Rtype=2 ";
  3947. elseif ($item == "train")
  3948. $condition = " and Rtype=3 ";
  3949. $dateCondition = " and Year(date) =" . $year;
  3950. if (! empty ( $moth )) {
  3951. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  3952. $stList = $statistics->getOne ( array (
  3953. 'select' => 'rePrice ,agPrice',
  3954. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  3955. 'asArray' => true
  3956. ) );
  3957. } else
  3958. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  3959. if (empty ( $stList ))
  3960. $stList = array (
  3961. 'rePrice' => 0,
  3962. 'agPrice' => 0
  3963. );
  3964. $noPassSum = $receipt->receiptByYear ( $dateCondition, $this->staff [0] ['sid'] );
  3965. if (! isset ( $noPassSum ['sum'] ))
  3966. $noPassSum ['sum'] = 0;
  3967. $data ['stList'] = array (
  3968. 'rePrice' => $stList ['rePrice'],
  3969. 'agPrice' => $stList ['agPrice'],
  3970. 'skPrice' => ($noPassSum ['sum'])
  3971. );
  3972. $receiptList = $receipt->find ( array (
  3973. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  3974. 'desc' => 'rid',
  3975. 'asArray' => true
  3976. ) );
  3977. $Locate = 0;
  3978. $roleId = 0;
  3979. $button = 0;
  3980. foreach ( $receiptList as $key => $value ) {
  3981. $receiptList[$key]['balance']='';
  3982. if($value['Rtype']==1){
  3983. $receiptList[$key]['balance']=$value['sum']-=$value['loanSum'];
  3984. $receiptList[$key]['balanceABS']=abs($receiptList[$key]['balance']);
  3985. }elseif($value['Rtype']==3){
  3986. $payment=$this->_getReceiptTrainPayment($value['invoiceTrainId'],$value['trainLoanRid'],$value['rid']);
  3987. $receiptList[$key]['payment']=$payment;
  3988. $receiptList[$key]['paymentABS']=abs($payment);
  3989. }
  3990. $receiptList [$key] ['Locate'] = $Locate;
  3991. $Locate ++;
  3992. $receiptList [$key] ['reviseDetail'] = array ();
  3993. if (! empty ( $value ['reviseDetail'] ))
  3994. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  3995. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  3996. $categoryDetil = $Lcategory->getOne ( array (
  3997. 'where' => 'cid=' . $value ['cid'],
  3998. 'asArray' => true
  3999. ) );
  4000. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4001. // 检测编辑状态
  4002. $verifyList = $verify->getOne ( array (
  4003. 'where' => 'vid=' . $value ['verify'],
  4004. 'asArray' => true
  4005. ) );
  4006. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4007. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4008. Doo::loadModel ( 'role' );
  4009. $role = new role ();
  4010. $flag = true;
  4011. $roleKey = 0;
  4012. $endStaffArray = array ();
  4013. $roleArrayCopy = array ();
  4014. foreach ( $verifyList as $k => $v ) {
  4015. // init verifyStaff
  4016. if ($v [1] == 'ROLE') {
  4017. if (! empty ( $verifyStaff )) {
  4018. $endStaffArray = end ( $verifyStaff );
  4019. // if ($v[0]==$endStaffArray['nextStaff']){
  4020. // $roleId=$v[0];
  4021. // }
  4022. }
  4023. $roleVerify = json_decode ( $v [3], true );
  4024. $roleKey = $k;
  4025. $roleArray = array ();
  4026. $rolename = $role->getOne ( array (
  4027. 'where' => 'rid=' . $v [0],
  4028. 'asArray' => true
  4029. ) );
  4030. foreach ( $roleVerify as $o => $p ) {
  4031. $staffID = explode ( '_', $p );
  4032. $staffInfo = $staff->getOne ( array (
  4033. 'where' => 'sid=' . $staffID [0],
  4034. 'asArray' => true
  4035. ) );
  4036. // print_r($staffID);
  4037. $exp = array (
  4038. 0 => $staffInfo ['sid'],
  4039. 1 => $staffID [1],
  4040. 2 => $staffInfo ['avatar'],
  4041. 'date' => '',
  4042. 'date' => '',
  4043. 'opinion' => '',
  4044. 'status' => '',
  4045. 'rolename' => $rolename ['name']
  4046. );
  4047. array_push ( $roleArray, $exp );
  4048. }
  4049. $roleArrayCopy [$v [0]] = $roleArray;
  4050. // $verifyList[$k]['roleArray']=$roleArray;
  4051. }
  4052. $verifyList [$k] ['date'] = "";
  4053. $verifyList [$k] ['opinion'] = "";
  4054. $verifyList [$k] ['status'] = "";
  4055. if (empty ( $verifyStaff )) {
  4056. $verifyList [$k] ['date'] = "";
  4057. $verifyList [$k] ['opinion'] = "";
  4058. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4059. $verifyList [$k] ['status'] = 4;
  4060. $flag = false;
  4061. }
  4062. } else {
  4063. foreach ( $verifyStaff as $m => $u ) {
  4064. if ($v [0] == $m) {
  4065. $verifyList [$k] ['date'] = $u ['date'];
  4066. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4067. $verifyList [$k] ['status'] = $u ['status'];
  4068. $flag = false;
  4069. break;
  4070. }
  4071. }
  4072. $endStaffArray = end ( $verifyStaff );
  4073. if (isset ( $endStaffArray ['ROLE'] )) {
  4074. } else {
  4075. // $endKey=key($verifyStaff);
  4076. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4077. // $button=4;
  4078. // $verifyList[$k]['status']=4;
  4079. // }
  4080. }
  4081. }
  4082. }
  4083. $rolename ['name'] = '';
  4084. if (! empty ( $roleId )) {
  4085. Doo::loadModel ( 'role' );
  4086. $role = new role ();
  4087. $rolename = $role->getOne ( array (
  4088. 'where' => 'rid=' . $roleId,
  4089. 'asArray' => true
  4090. ) );
  4091. }
  4092. if (! empty ( $verifyStaff ))
  4093. $endStaffArray = end ( $verifyStaff );
  4094. $KOP = false;
  4095. foreach ( $roleArrayCopy as $P => $A ) {
  4096. foreach ( $A as $MKI => $AVL ) {
  4097. if (! empty ( $verifyStaff )) {
  4098. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4099. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4100. $button = 4;
  4101. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4102. }
  4103. foreach ( $verifyStaff as $m => $u ) {
  4104. $AVLFK = $AVL [0] . '_R';
  4105. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4106. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4107. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4108. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4109. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4110. break;
  4111. }
  4112. }
  4113. } else {
  4114. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4115. $button = 4;
  4116. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4117. }
  4118. }
  4119. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4120. $KOP = true;
  4121. }
  4122. }
  4123. foreach ( $roleArrayCopy as $k => $v ) {
  4124. foreach ( $verifyList as $m => $n ) {
  4125. if ($n [0] == $k) {
  4126. array_splice ( $verifyList, $m, 1, $v );
  4127. }
  4128. }
  4129. }
  4130. $receiptList [$key] ['verifyList'] = $verifyList;
  4131. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4132. 'where' => 'sid=' . $value ['staff'],
  4133. 'asArray' => true
  4134. ) );
  4135. $receiptList [$key] ['button'] = $button;
  4136. $receiptList [$key] ['ridKey'] =$XDeode->encode( $value ['rid'] );
  4137. }
  4138. // print_r($receiptList);die;
  4139. $mothHtml = "";
  4140. for($i = 1; $i <= 12; $i ++) {
  4141. if ($moth == $i)
  4142. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  4143. else
  4144. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  4145. }
  4146. $dateHtml = "";
  4147. $now = date ( "Y" );
  4148. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  4149. if ($YEARD <= $now) {
  4150. $dateHtml .= '<option ';
  4151. if ($year == $YEARD) {
  4152. $dateHtml .= 'selected ';
  4153. }
  4154. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  4155. }
  4156. }
  4157. $data ['dateHtml'] = $dateHtml;
  4158. $data ['mothHtml'] = $mothHtml;
  4159. $data ['receiptList'] = $receiptList;
  4160. $data ['memu'] = "receipt";
  4161. $data ['staff'] = $this->staff;
  4162. $data ['receiptMemu'] = 'expenses';
  4163. $data ['verifyId'] = $this->verifyId;
  4164. $data ['executeId'] = $this->executeId;
  4165. $data ['item'] = $item;
  4166. $data ['year'] = $year;
  4167. $this->render ( "/admin/expenses", $data );
  4168. }
  4169. function expensesCollect() {
  4170. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  4171. Doo::loadModel ( 'receipt' );
  4172. $receipt = new receipt ();
  4173. Doo::loadModel ( 'L_category' );
  4174. $Lcategory = new L_category ();
  4175. Doo::loadModel ( 'verify' );
  4176. Doo::loadModel ( 'statistics' );
  4177. $statistics = new statistics ();
  4178. $verify = new verify ();
  4179. Doo::loadModel ( 'staff' );
  4180. $staff = new staff ();
  4181. Doo::loadModel ( 'loanReceipt' );
  4182. $loanReceipt = new loanReceipt ();
  4183. $receiptList = $receipt->find ( array (//去掉
  4184. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid,
  4185. 'desc' => 'rid',
  4186. 'asArray' => true
  4187. ) );
  4188. $loanList = $loanReceipt->find ( array (
  4189. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4190. 'desc' => 'rid',
  4191. 'asArray' => true
  4192. ) );
  4193. /*
  4194. * $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;
  4195. */
  4196. $data ['explanation'] = '';
  4197. if (! empty ( $loanList ))
  4198. $data ['explanation'] = $loanList [0] ['explanation'];
  4199. $Locate = 0;
  4200. $roleId = 0;
  4201. $button = 0;
  4202. foreach ( $receiptList as $key => $value ) {
  4203. $receiptList [$key] ['Locate'] = $Locate;
  4204. $Locate ++;
  4205. $receiptList [$key] ['reviseDetail'] = array ();
  4206. if (! empty ( $value ['reviseDetail'] ))
  4207. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4208. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4209. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4210. $categoryDetil = $Lcategory->getOne ( array (
  4211. 'where' => 'cid=' . $value ['cid'],
  4212. 'asArray' => true
  4213. ) );
  4214. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4215. // 检测编辑状态
  4216. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9) {
  4217. if ($value ['status'] == 8 && $value ['Rtype'] == 1)
  4218. $verifyList ['staff'] = $loanList [0] ['verifyBreakup'];
  4219. else
  4220. $verifyList ['staff'] = $value ['verifyBreakup'];
  4221. } else
  4222. $verifyList = $verify->getOne ( array (
  4223. 'where' => 'vid=' . $value ['verify'],
  4224. 'asArray' => true
  4225. ) );
  4226. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4227. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4228. Doo::loadModel ( 'role' );
  4229. $role = new role ();
  4230. $flag = true;
  4231. $roleKey = 0;
  4232. $endStaffArray = array ();
  4233. $roleArrayCopy = array ();
  4234. foreach ( $verifyList as $k => $v ) {
  4235. // init verifyStaff
  4236. if ($v [1] == 'ROLE') {
  4237. if (! empty ( $verifyStaff )) {
  4238. $endStaffArray = end ( $verifyStaff );
  4239. // if ($v[0]==$endStaffArray['nextStaff']){
  4240. // $roleId=$v[0];
  4241. // }
  4242. }
  4243. $roleVerify = json_decode ( $v [3], true );
  4244. $roleKey = $k;
  4245. $roleArray = array ();
  4246. $rolename = $role->getOne ( array (
  4247. 'where' => 'rid=' . $v [0],
  4248. 'asArray' => true
  4249. ) );
  4250. foreach ( $roleVerify as $o => $p ) {
  4251. $staffID = explode ( '_', $p );
  4252. $staffInfo = $staff->getOne ( array (
  4253. 'where' => 'sid=' . $staffID [0],
  4254. 'asArray' => true
  4255. ) );
  4256. // print_r($staffID);
  4257. $exp = array (
  4258. 0 => $staffInfo ['sid'],
  4259. 1 => $staffID [1],
  4260. 2 => $staffInfo ['avatar'],
  4261. 'date' => '',
  4262. 'date' => '',
  4263. 'opinion' => '',
  4264. 'status' => '',
  4265. 'rolename' => $rolename ['name']
  4266. );
  4267. array_push ( $roleArray, $exp );
  4268. }
  4269. $roleArrayCopy [$v [0]] = $roleArray;
  4270. // $verifyList[$k]['roleArray']=$roleArray;
  4271. }
  4272. $verifyList [$k] ['date'] = "";
  4273. $verifyList [$k] ['opinion'] = "";
  4274. $verifyList [$k] ['status'] = "";
  4275. if (empty ( $verifyStaff )) {
  4276. $verifyList [$k] ['date'] = "";
  4277. $verifyList [$k] ['opinion'] = "";
  4278. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4279. $verifyList [$k] ['status'] = 4;
  4280. $flag = false;
  4281. }
  4282. } else {
  4283. foreach ( $verifyStaff as $m => $u ) {
  4284. if ($v [0] == $m) {
  4285. $verifyList [$k] ['date'] = $u ['date'];
  4286. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4287. $verifyList [$k] ['status'] = $u ['status'];
  4288. $flag = false;
  4289. break;
  4290. }
  4291. }
  4292. $endStaffArray = end ( $verifyStaff );
  4293. if (isset ( $endStaffArray ['ROLE'] )) {
  4294. } else {
  4295. // $endKey=key($verifyStaff);
  4296. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4297. // $button=4;
  4298. // $verifyList[$k]['status']=4;
  4299. // }
  4300. }
  4301. }
  4302. }
  4303. $rolename ['name'] = '';
  4304. if (! empty ( $roleId )) {
  4305. Doo::loadModel ( 'role' );
  4306. $role = new role ();
  4307. $rolename = $role->getOne ( array (
  4308. 'where' => 'rid=' . $roleId,
  4309. 'asArray' => true
  4310. ) );
  4311. }
  4312. if (! empty ( $verifyStaff ))
  4313. $endStaffArray = end ( $verifyStaff );
  4314. $KOP = false;
  4315. foreach ( $roleArrayCopy as $P => $A ) {
  4316. foreach ( $A as $MKI => $AVL ) {
  4317. if (! empty ( $verifyStaff )) {
  4318. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4319. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4320. $button = 4;
  4321. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4322. }
  4323. foreach ( $verifyStaff as $m => $u ) {
  4324. $AVLFK = $AVL [0] . '_R';
  4325. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4326. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4327. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4328. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4329. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4330. break;
  4331. }
  4332. }
  4333. } else {
  4334. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4335. $button = 4;
  4336. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4337. }
  4338. }
  4339. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4340. $KOP = true;
  4341. }
  4342. }
  4343. foreach ( $roleArrayCopy as $k => $v ) {
  4344. foreach ( $verifyList as $m => $n ) {
  4345. if ($n [0] == $k) {
  4346. array_splice ( $verifyList, $m, 1, $v );
  4347. }
  4348. }
  4349. }
  4350. // 费用执行人相关数据
  4351. $executeCopy = json_decode ( $value ['executeCopy'], true );
  4352. $executeStaff = json_decode ( $value ['executeStaff'], true );
  4353. foreach ( $executeCopy as $k => $v ) {
  4354. $executeCopy [$k] ['date'] = '';
  4355. $executeCopy [$k] ['opinion'] = '';
  4356. $executeCopy [$k] ['status'] = '';
  4357. if (! empty ( $executeStaff ))
  4358. foreach ( $executeStaff as $m => $u ) {
  4359. if ($v [0] == $m) {
  4360. $executeCopy [$k] ['date'] = $u ['date'];
  4361. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  4362. $executeCopy [$k] ['status'] = $u ['status'];
  4363. break;
  4364. }
  4365. }
  4366. }
  4367. $receiptList [$key] ['executeCopy'] = $executeCopy;
  4368. $receiptList [$key] ['verifyList'] = $verifyList;
  4369. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4370. 'where' => 'sid=' . $value ['staff'],
  4371. 'asArray' => true
  4372. ) );
  4373. $receiptList [$key] ['button'] = $button;
  4374. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  4375. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  4376. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  4377. $receiptList [$key] ['relust'] = $relust;
  4378. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  4379. }
  4380. Doo::loadModel ( 'enclosur' );
  4381. $enclosur = new enclosur ();
  4382. $enclosurList = $enclosur->find ( array (
  4383. 'where' => 'rid=' . $rid,
  4384. 'asArray' => true
  4385. ) );
  4386. $enclosurHtml = '';
  4387. foreach ( $enclosurList as $value ) {
  4388. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  4389. }
  4390. $receiptList[0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  4391. $data ['enclosurHtml'] = $enclosurHtml;
  4392. //print_r($receiptList[0]['accountItem']['内部培训费用']);
  4393. if($receiptList[0]['version']==1){
  4394. require "protected/class/comm_cld.php";
  4395. $receiptList=makeReceiptDataVersion1($receiptList);
  4396. }
  4397. $data ['receiptList'] = $receiptList;
  4398. $data ['memu'] = "receipt";
  4399. $data ['staff'] = $this->staff;
  4400. $data ['receiptMemu'] = 'expenses';
  4401. $data ['verifyId'] = $this->verifyId;
  4402. $data ['executeId'] = $this->executeId;
  4403. if($receiptList[0]['version']==1){
  4404. $this->render ( "/fee/detail/receipt_compatible", $data );
  4405. die;
  4406. }
  4407. if($receiptList[0]['receiptClass']==2){
  4408. if(!empty($receiptList[0]['itinerary2'])){
  4409. $this->render ( "/receipt/feeTraveDetail2", $data );
  4410. }else{
  4411. $this->render ( "/receipt/feeTraveDetail", $data );
  4412. }
  4413. }else{
  4414. $this->render ( "/admin/expensesCollect", $data );
  4415. }
  4416. }
  4417. function approvalExpenses() {
  4418. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  4419. $year = $rdate = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  4420. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4421. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  4422. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  4423. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  4424. // echo $rdate;
  4425. if (empty ( $status ))
  4426. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  4427. $page_size = 8;
  4428. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4429. $vidList = array ();
  4430. $button = 0;
  4431. Doo::loadModel ( 'verify' );
  4432. $verify = new verify ();
  4433. Doo::loadModel ( 'receipt' );
  4434. $receipt = new receipt ();
  4435. Doo::loadModel ( 'staff' );
  4436. $staff = new staff ();
  4437. Doo::loadModel ( 'L_category' );
  4438. $Lcategory = new L_category ();
  4439. // user verify ID
  4440. $verifyDetail = $verify->find ( array (
  4441. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  4442. 'asArray' => true
  4443. ) );
  4444. foreach ( $verifyDetail as $key => $value ) {
  4445. array_push ( $vidList, $value ['vid'] );
  4446. }
  4447. $vid = implode ( ",", $vidList );
  4448. if (empty ( $verifyDetail )){
  4449. $vid = 0;
  4450. }
  4451. $dateCondition = " ";
  4452. // if (! empty ( $month ))
  4453. // $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  4454. if ($status == 'done' || $status == 'termination') {
  4455. if (! empty ( $year )) {
  4456. $dateCondition = " and Year(pastDate) =" . $year;
  4457. if (! empty ( $month ))
  4458. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4459. }
  4460. } elseif ($status == 'finish') {
  4461. if (! empty ( $year )) {
  4462. $dateCondition = " and Year(pastDate) =" . $year;
  4463. if (! empty ( $month ))
  4464. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  4465. }
  4466. }
  4467. // date ( 'Y-m' )
  4468. // if (! empty ( $rdate ) && $status == 'done')
  4469. // $dateCondition = " and date_format(pastDate,'%Y-%m')='" . $rdate . "' ";
  4470. // elseif (! empty ( $rdate ))
  4471. // $dateCondition = " and date_format(date,'%Y-%m')='" . $rdate . "' ";
  4472. $categoryList = $Lcategory->find ( array (
  4473. 'asArray' => true
  4474. ) );
  4475. $staffList = $staff->find ( array (
  4476. 'where' => 'cid=' . $cid,
  4477. 'asArray' => true
  4478. ) );
  4479. $cateCondition = "";
  4480. $staffCondition = "";
  4481. $approvalCondition = "";
  4482. if (! empty ( $cid )) {
  4483. $cateCondition = ' and cid=' . $cid;
  4484. }
  4485. if (! empty ( $sid )) {
  4486. $staffCondition = ' and cid=' . $cid . ' and staff=' . $sid;
  4487. $cateCondition = "";
  4488. }
  4489. $get = "?year=" . $year . "&month=" . $month . "&cid=" . $cid . "&sid=" . $sid;
  4490. if ($status == 'pendApproval') {
  4491. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  4492. }
  4493. if ($status == 'ongoing') {
  4494. $approvalCondition = ' and (status=2 or status=1 or status=6 or status=4) ';
  4495. }
  4496. if ($status == 'done') {
  4497. $approvalCondition = ' and (status=8 or status=9 ) ';
  4498. }
  4499. if ($status == 'termination') {
  4500. $approvalCondition = " and status=3";
  4501. }
  4502. if ($status == 'finish') {
  4503. $approvalCondition = " and (status=1 or status=8 or status=9 or status=10)";
  4504. }
  4505. if($status == 'loan'){
  4506. $approvalCondition = " and (status=8 or status=7) and Rtype=1";
  4507. }
  4508. $pageinfo ['page'] = array (
  4509. 'previous' => ''
  4510. );
  4511. if(!empty($receiptOrder)){
  4512. $pageinfo = $this->get_page ( "CLD_receipt", ' and receiptOrder like "%' . $receiptOrder . '%"', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4513. $receiptList = $receipt->find ( array ( // $dateCondition
  4514. 'where' => 'receiptOrder like "%' . $receiptOrder . '%"',
  4515. 'desc' => 'rid',
  4516. 'asArray' => true
  4517. ) );
  4518. }else{
  4519. if ($status == 'done' || $status == 'termination' || $status == 'finish') { // $dateCondition .
  4520. $pageinfo = $this->get_page ( "CLD_receipt", $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ') and status!=5', $page, $page_size, "approvalExpenses/" . $status, $get, "" );
  4521. $receiptList = $receipt->find ( array ( // $dateCondition.
  4522. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4523. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  4524. 'desc' => 'rid',
  4525. 'asArray' => true
  4526. ) );
  4527. } else {
  4528. $receiptList = $receipt->find ( array ( // $dateCondition
  4529. 'where' => 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . $dateCondition . ' and verify in (' . $vid . ')',
  4530. 'desc' => 'rid',
  4531. 'asArray' => true
  4532. ) );
  4533. // echo 'status!=5 ' . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4534. }
  4535. }
  4536. $rLRes = $receipt->find ( array (
  4537. '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 . ')',
  4538. 'desc' => 'rid',
  4539. 'asArray' => true
  4540. ) );
  4541. // echo 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition . ' and verify in (' . $vid . ')';
  4542. // print_r($receiptList);
  4543. Doo::loadClass ( 'XDeode' );
  4544. $XDeode = new XDeode ( 7 );
  4545. $XDeode9 = new XDeode ( 9 );
  4546. $Locate = 0;
  4547. //
  4548. $reportList = $reportCateList = array ();
  4549. foreach ( $receiptList as $key => $value ) {
  4550. $receiptList [$key] ['rid_cld'] = $XDeode9->encode ( $value ['rid'] );
  4551. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  4552. $receiptList [$key] ['Locate'] = $Locate;
  4553. $Locate ++;
  4554. $receiptList [$key] ['reviseDetail'] = array ();
  4555. if (! empty ( $value ['reviseDetail'] ))
  4556. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4557. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4558. $categoryDetil = $Lcategory->getOne ( array (
  4559. 'where' => 'cid=' . $value ['cid'],
  4560. 'asArray' => true
  4561. ) );
  4562. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4563. $verifyList = $verify->getOne ( array (
  4564. 'where' => 'vid=' . $value ['verify'],
  4565. 'asArray' => true
  4566. ) );
  4567. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4568. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4569. foreach ( $verifyList as $k => $v ) {
  4570. // init verifyStaff
  4571. $verifyList [$k] ['date'] = "";
  4572. $verifyList [$k] ['opinion'] = "";
  4573. $verifyList [$k] ['status'] = "";
  4574. if (empty ( $verifyStaff )) {
  4575. $verifyList [$k] ['date'] = "";
  4576. $verifyList [$k] ['opinion'] = "";
  4577. if ($v [0] == $this->staff [0] ['sid']) {
  4578. $verifyList [$k] ['status'] = 4;
  4579. $button = 4;
  4580. }
  4581. } else {
  4582. $flag = true;
  4583. foreach ( $verifyStaff as $m => $u ) {
  4584. if ($v [0] == $m) {
  4585. $verifyList [$k] ['date'] = $u ['date'];
  4586. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4587. $verifyList [$k] ['status'] = $u ['status'];
  4588. $flag = false;
  4589. break;
  4590. }
  4591. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  4592. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  4593. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  4594. }
  4595. if ($flag) { // 检测可编辑
  4596. if ($v [0] == $this->staff [0] ['sid']) {
  4597. $verifyList [$k] ['status'] = 4;
  4598. $button = 4;
  4599. }
  4600. }
  4601. }
  4602. }
  4603. $receiptList [$key] ['verifyList'] = $verifyList;
  4604. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  4605. 'where' => 'sid=' . $value ['staff'],
  4606. 'asArray' => true
  4607. ) );
  4608. array_push ( $reportList, $receiptList [$key] ['staffDetail'] ['sid'] . '-' . $receiptList [$key] ['staffDetail'] ['username'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4609. array_push ( $reportCateList, $receiptList [$key] ['staffDetail'] ['cid'] . '-' . $receiptList [$key] ['staffDetail'] ['category'] );
  4610. $receiptList [$key] ['button'] = $button;
  4611. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  4612. //获得培训班结算RID 借款费用--已经锁定
  4613. if($value['status']==10){
  4614. $trainRD=$receipt->getReceiptByTrainLoanRid($value['rid']);
  4615. $receiptList [$key]['trainRidKey7']=$trainRD['ridKey7'];
  4616. }
  4617. }
  4618. $reportList = array_unique ( $reportList );
  4619. $reportHtml = '';
  4620. foreach ( $reportList as $key => $value ) {
  4621. $v = explode ( "-", $value );
  4622. $reportHtml .= '<option node-all=\'true\' node-cate=\'' . $v [2] . '\' value="' . $v [1] . '">' . $v [1] . '</option>';
  4623. }
  4624. // print_r($reportList)
  4625. $data ['reportHtml'] = $reportHtml;
  4626. $reportCateList = array_unique ( $reportCateList );
  4627. $reportCateHtml = '';
  4628. foreach ( $reportCateList as $key => $value ) {
  4629. $v = explode ( "-", $value );
  4630. $reportCateHtml .= '<option value="' . $v [1] . '">' . $v [1] . '</option>';
  4631. }
  4632. // $reportHtml.='<option value="ALL">'.$value[''].'</option>';
  4633. $data ['reportCateHtml'] = $reportCateHtml;
  4634. // print_r($receiptList);die;
  4635. // $data['verifyDetail']=$verifyDetail;
  4636. $mothHtml = "";
  4637. for($i = 1; $i <= 12; $i ++) {
  4638. if ($month == $i)
  4639. $mothHtml .= '<option selected value="0' . $i . '">' . $i . '月</option>';
  4640. else
  4641. $mothHtml .= '<option value="0' . $i . '">' . $i . '月</option>';
  4642. }
  4643. $data ['mothHtml'] = $mothHtml;
  4644. $dateHtml = "";
  4645. $now = date ( "Y" );
  4646. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  4647. if ($YEARD <= $now) {
  4648. $dateHtml .= '<option ';
  4649. if ($year == $YEARD) {
  4650. $dateHtml .= 'selected ';
  4651. }
  4652. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  4653. }
  4654. }
  4655. $data ['dateHtml'] = $dateHtml;
  4656. $data ['page'] = $pageinfo;
  4657. $data ['receiptList'] = $receiptList;
  4658. $data ['receiptApprovalCount'] = count ( $rLRes );
  4659. $data ['status'] = $status;
  4660. $data ['year'] = $year;
  4661. $data ['month'] = $month;
  4662. $data ['categoryList'] = $categoryList;
  4663. $data ['staffList'] = $staffList;
  4664. $data ['cid'] = $cid;
  4665. $data ['sid'] = $sid;
  4666. // print_r($receiptList);
  4667. $data['receiptOrder']=$receiptOrder;
  4668. $data ['memu'] = "receipt";
  4669. $data ['staff'] = $this->staff;
  4670. $data ['receiptMemu'] = 'approvalExpenses';
  4671. $data ['verifyId'] = $this->verifyId;
  4672. $data ['executeId'] = $this->executeId;
  4673. $this->render ( "/admin/approvalExpenses", $data );
  4674. }
  4675. private function _expensesDoc(){
  4676. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : '';
  4677. Doo::loadClass ( 'XDeode' );
  4678. $XDeode = new XDeode ( 5 );
  4679. if (! empty ( $rid ) && ! is_numeric ( $rid ))
  4680. $rid = $XDeode->decode ( $rid );
  4681. if (! is_numeric ( $rid ))
  4682. die ( 'illegal request' );
  4683. Doo::loadModel ( 'receipt' );
  4684. $receipt = new receipt ();
  4685. Doo::loadModel ( 'L_category' );
  4686. $Lcategory = new L_category ();
  4687. Doo::loadModel ( 'verify' );
  4688. Doo::loadModel ( 'statistics' );
  4689. $statistics = new statistics ();
  4690. $verify = new verify ();
  4691. Doo::loadModel ( 'staff' );
  4692. $staff = new staff ();
  4693. Doo::loadModel ( 'loanReceipt' );
  4694. $loanReceipt = new loanReceipt ();
  4695. $receiptList = $receipt->find ( array (
  4696. 'where' => ' rid=' . $rid,
  4697. 'desc' => 'rid',
  4698. 'asArray' => true
  4699. ) );
  4700. $loanList = array ();
  4701. if (! empty ( $receiptList ))
  4702. $loanList = $loanReceipt->find ( array (
  4703. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  4704. 'desc' => 'rid',
  4705. 'asArray' => true
  4706. ) );
  4707. $Locate = 0;
  4708. $roleId = 0;
  4709. $button = 0;
  4710. foreach ( $loanList as $key => $value ) {
  4711. $loanList [$key] ['Locate'] = $Locate;
  4712. $Locate ++;
  4713. $loanList [$key] ['reviseDetail'] = array ();
  4714. if (! empty ( $value ['reviseDetail'] ))
  4715. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4716. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4717. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4718. $categoryDetil = $Lcategory->getOne ( array (
  4719. 'where' => 'cid=' . $value ['cid'],
  4720. 'asArray' => true
  4721. ) );
  4722. $loanList [$key] ['category'] = $categoryDetil ['title'];
  4723. // 检测编辑状态
  4724. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 8 || $value ['status'] == 9)
  4725. $verifyList ['staff'] = $value ['verifyBreakup'];
  4726. else
  4727. $verifyList = $verify->getOne ( array (
  4728. 'where' => 'vid=' . $value ['verify'],
  4729. 'asArray' => true
  4730. ) );
  4731. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4732. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4733. Doo::loadModel ( 'role' );
  4734. $role = new role ();
  4735. $flag = true;
  4736. $roleKey = 0;
  4737. $endStaffArray = array ();
  4738. $roleArrayCopy = array ();
  4739. foreach ( $verifyList as $k => $v ) {
  4740. // init verifyStaff
  4741. if ($v [1] == 'ROLE') {
  4742. if (! empty ( $verifyStaff )) {
  4743. $endStaffArray = end ( $verifyStaff );
  4744. // if ($v[0]==$endStaffArray['nextStaff']){
  4745. // $roleId=$v[0];
  4746. // }
  4747. }
  4748. $roleVerify = json_decode ( $v [3], true );
  4749. $roleKey = $k;
  4750. $roleArray = array ();
  4751. $rolename = $role->getOne ( array (
  4752. 'where' => 'rid=' . $v [0],
  4753. 'asArray' => true
  4754. ) );
  4755. foreach ( $roleVerify as $o => $p ) {
  4756. $staffID = explode ( '_', $p );
  4757. $staffInfo = $staff->getOne ( array (
  4758. 'where' => 'sid=' . $staffID [0],
  4759. 'asArray' => true
  4760. ) );
  4761. // print_r($staffID);
  4762. $exp = array (
  4763. 0 => $staffInfo ['sid'],
  4764. 1 => $staffID [1],
  4765. 2 => $staffInfo ['avatar'],
  4766. 'date' => '',
  4767. 'date' => '',
  4768. 'opinion' => '',
  4769. 'status' => '',
  4770. 'rolename' => $rolename ['name']
  4771. );
  4772. array_push ( $roleArray, $exp );
  4773. }
  4774. $roleArrayCopy [$v [0]] = $roleArray;
  4775. // $verifyList[$k]['roleArray']=$roleArray;
  4776. }
  4777. $verifyList [$k] ['date'] = "";
  4778. $verifyList [$k] ['opinion'] = "";
  4779. $verifyList [$k] ['status'] = "";
  4780. if (empty ( $verifyStaff )) {
  4781. $verifyList [$k] ['date'] = "";
  4782. $verifyList [$k] ['opinion'] = "";
  4783. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4784. $verifyList [$k] ['status'] = 4;
  4785. $flag = false;
  4786. }
  4787. } else {
  4788. foreach ( $verifyStaff as $m => $u ) {
  4789. if ($v [0] == $m) {
  4790. $verifyList [$k] ['date'] = $u ['date'];
  4791. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4792. $verifyList [$k] ['status'] = $u ['status'];
  4793. $flag = false;
  4794. break;
  4795. }
  4796. }
  4797. $endStaffArray = end ( $verifyStaff );
  4798. if (isset ( $endStaffArray ['ROLE'] )) {
  4799. } else {
  4800. // $endKey=key($verifyStaff);
  4801. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4802. // $button=4;
  4803. // $verifyList[$k]['status']=4;
  4804. // }
  4805. }
  4806. }
  4807. }
  4808. $rolename ['name'] = '';
  4809. if (! empty ( $roleId )) {
  4810. Doo::loadModel ( 'role' );
  4811. $role = new role ();
  4812. $rolename = $role->getOne ( array (
  4813. 'where' => 'rid=' . $roleId,
  4814. 'asArray' => true
  4815. ) );
  4816. }
  4817. if (! empty ( $verifyStaff ))
  4818. $endStaffArray = end ( $verifyStaff );
  4819. $KOP = false;
  4820. foreach ( $roleArrayCopy as $P => $A ) {
  4821. foreach ( $A as $MKI => $AVL ) {
  4822. if (! empty ( $verifyStaff )) {
  4823. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4824. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4825. $button = 4;
  4826. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4827. }
  4828. foreach ( $verifyStaff as $m => $u ) {
  4829. $AVLFK = $AVL [0] . '_R';
  4830. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4831. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4832. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4833. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4834. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  4835. break;
  4836. }
  4837. }
  4838. } else {
  4839. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  4840. $button = 4;
  4841. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4842. }
  4843. }
  4844. // $roleArray[$MKI]['rolename']=$rolename['name'];
  4845. $KOP = true;
  4846. }
  4847. }
  4848. foreach ( $roleArrayCopy as $k => $v ) {
  4849. foreach ( $verifyList as $m => $n ) {
  4850. if ($n [0] == $k) {
  4851. array_splice ( $verifyList, $m, 1, $v );
  4852. }
  4853. }
  4854. }
  4855. $loanList [$key] ['verifyList'] = $verifyList;
  4856. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  4857. 'where' => 'sid=' . $value ['staff'],
  4858. 'asArray' => true
  4859. ) );
  4860. $loanList [$key] ['button'] = $button;
  4861. //$loanList[$key]['sumCN']=$this->NumToCNMoney($value['sum']);
  4862. }
  4863. $data ['loanList'] = $loanList;
  4864. $data ['explanation'] = '';
  4865. if (! empty ( $loanList )){
  4866. $data ['explanation'] = $loanList [0] ['explanation'];
  4867. }
  4868. //print_r($loanList);
  4869. $Locate = 0;
  4870. $roleId = 0;
  4871. $button = 0;
  4872. foreach ( $receiptList as $key => $value ) {
  4873. $receiptList [$key] ['Locate'] = $Locate;
  4874. $Locate ++;
  4875. $receiptList [$key] ['reviseDetail'] = array ();
  4876. if (! empty ( $value ['reviseDetail'] ))
  4877. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  4878. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  4879. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  4880. $categoryDetil = $Lcategory->getOne ( array (
  4881. 'where' => 'cid=' . $value ['cid'],
  4882. 'asArray' => true
  4883. ) );
  4884. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  4885. // 检测编辑状态
  4886. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  4887. $verifyList ['staff'] = $value ['verifyBreakup'];
  4888. } else
  4889. $verifyList = $verify->getOne ( array (
  4890. 'where' => 'vid=' . $value ['verify'],
  4891. 'asArray' => true
  4892. ) );
  4893. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  4894. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  4895. Doo::loadModel ( 'role' );
  4896. $role = new role ();
  4897. if ($verifyList == NULL)
  4898. $verifyList = array ();
  4899. $flag = true;
  4900. $roleKey = 0;
  4901. $endStaffArray = array ();
  4902. $roleArrayCopy = array ();
  4903. foreach ( $verifyList as $k => $v ) {
  4904. // init verifyStaff
  4905. if ($v [1] == 'ROLE') {
  4906. if (! empty ( $verifyStaff )) {
  4907. $endStaffArray = end ( $verifyStaff );
  4908. // if ($v[0]==$endStaffArray['nextStaff']){
  4909. // $roleId=$v[0];
  4910. // }
  4911. }
  4912. $roleVerify = json_decode ( $v [3], true );
  4913. $roleKey = $k;
  4914. $roleArray = array ();
  4915. $rolename = $role->getOne ( array (
  4916. 'where' => 'rid=' . $v [0],
  4917. 'asArray' => true
  4918. ) );
  4919. foreach ( $roleVerify as $o => $p ) {
  4920. $staffID = explode ( '_', $p );
  4921. $staffInfo = $staff->getOne ( array (
  4922. 'where' => 'sid=' . $staffID [0],
  4923. 'asArray' => true
  4924. ) );
  4925. // print_r($staffID);
  4926. $exp = array (
  4927. 0 => $staffInfo ['sid'],
  4928. 1 => $staffID [1],
  4929. 2 => $staffInfo ['avatar'],
  4930. 'date' => '',
  4931. 'date' => '',
  4932. 'opinion' => '',
  4933. 'status' => '',
  4934. 'rolename' => $rolename ['name']
  4935. );
  4936. array_push ( $roleArray, $exp );
  4937. }
  4938. $roleArrayCopy [$v [0]] = $roleArray;
  4939. // $verifyList[$k]['roleArray']=$roleArray;
  4940. }
  4941. $verifyList [$k] ['date'] = "";
  4942. $verifyList [$k] ['opinion'] = "";
  4943. $verifyList [$k] ['status'] = "";
  4944. if (empty ( $verifyStaff )) {
  4945. $verifyList [$k] ['date'] = "";
  4946. $verifyList [$k] ['opinion'] = "";
  4947. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  4948. $verifyList [$k] ['status'] = 4;
  4949. $flag = false;
  4950. }
  4951. } else {
  4952. foreach ( $verifyStaff as $m => $u ) {
  4953. if ($v [0] == $m) {
  4954. $verifyList [$k] ['date'] = $u ['date'];
  4955. $verifyList [$k] ['opinion'] = $u ['opinion'];
  4956. $verifyList [$k] ['status'] = $u ['status'];
  4957. $flag = false;
  4958. break;
  4959. }
  4960. }
  4961. $endStaffArray = end ( $verifyStaff );
  4962. if (isset ( $endStaffArray ['ROLE'] )) {
  4963. } else {
  4964. // $endKey=key($verifyStaff);
  4965. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  4966. // $button=4;
  4967. // $verifyList[$k]['status']=4;
  4968. // }
  4969. }
  4970. }
  4971. }
  4972. $FC = @$rolename ['name'];
  4973. $rolename ['name'] = '';
  4974. if (! empty ( $roleId )) {
  4975. Doo::loadModel ( 'role' );
  4976. $role = new role ();
  4977. $rolename = $role->getOne ( array (
  4978. 'where' => 'rid=' . $roleId,
  4979. 'asArray' => true
  4980. ) );
  4981. }
  4982. if (! empty ( $verifyStaff ))
  4983. $endStaffArray = end ( $verifyStaff );
  4984. $KOP = false;
  4985. foreach ( $roleArrayCopy as $P => $A ) {
  4986. foreach ( $A as $MKI => $AVL ) {
  4987. if (! empty ( $verifyStaff )) {
  4988. // &&$rolename['rid']==$endStaffArray['nextStaff']
  4989. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  4990. $button = 4;
  4991. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  4992. }
  4993. foreach ( $verifyStaff as $m => $u ) {
  4994. $AVLFK = $AVL [0] . '_R';
  4995. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  4996. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  4997. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  4998. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  4999. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5000. break;
  5001. }
  5002. }
  5003. } else {
  5004. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5005. $button = 4;
  5006. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5007. }
  5008. }
  5009. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5010. $KOP = true;
  5011. }
  5012. }
  5013. foreach ( $roleArrayCopy as $k => $v ) {
  5014. foreach ( $verifyList as $m => $n ) {
  5015. if ($n [0] == $k) {
  5016. array_splice ( $verifyList, $m, 1, $v );
  5017. }
  5018. }
  5019. }
  5020. // 费用执行人相关数据
  5021. $executeCopy = json_decode ( $value ['executeCopy'], true );
  5022. $executeStaff = json_decode ( $value ['executeStaff'], true );
  5023. foreach ( $executeCopy as $k => $v ) {
  5024. $executeCopy [$k] ['date'] = '';
  5025. $executeCopy [$k] ['opinion'] = '';
  5026. $executeCopy [$k] ['status'] = '';
  5027. if (! empty ( $executeStaff ))
  5028. foreach ( $executeStaff as $m => $u ) {
  5029. if ($v [0] == $m) {
  5030. $executeCopy [$k] ['date'] = $u ['date'];
  5031. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  5032. $executeCopy [$k] ['status'] = $u ['status'];
  5033. break;
  5034. }
  5035. }
  5036. }
  5037. $receiptList [$key] ['executeCopy'] = $executeCopy;
  5038. // print_r($verifyList);
  5039. $receiptList [$key] ['verifyList'] = $verifyList;
  5040. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5041. 'where' => 'sid=' . $value ['staff'],
  5042. 'asArray' => true
  5043. ) );
  5044. $receiptList [$key] ['button'] = $button;
  5045. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  5046. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  5047. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  5048. $receiptList [$key] ['relust'] = $relust;
  5049. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  5050. }
  5051. // print_r($receiptList);
  5052. // 获取审批日志
  5053. Doo::loadModel ( 'receiptLog' );
  5054. $receiptLog = new receiptLog ();
  5055. $rlList = array ();
  5056. $rlInfo = $receiptLog->getOne ( array (
  5057. 'where' => 'rid=' . $rid . ' and status=4',
  5058. 'asArray' => true
  5059. ) );
  5060. // $tijdate = $receiptLog->getOne ( array (
  5061. // 'where' => 'rid=' . $rid . ' and status=2',
  5062. // 'asc' => 'rlid',
  5063. // 'asArray' => true
  5064. // ) );
  5065. if (! empty ( $rlInfo )) {
  5066. $rlList = $receiptLog->find ( array (
  5067. 'where' => 'rid=' . $rid,
  5068. 'asc' => 'rlid',
  5069. 'asArray' => true
  5070. ) );
  5071. }
  5072. $RN=array();
  5073. if (!empty( $rolename ['staff'])){
  5074. $RN = @json_decode ( $rolename ['staff'] );
  5075. }
  5076. //
  5077. foreach ( $rlList as $key => $value ) {
  5078. $rlList [$key] ['rolename'] = '';
  5079. foreach ( $RN as $k => $v ) {
  5080. $id = explode ( "_", $v );
  5081. if ($id [0] == $value ['uid']) {
  5082. $rlList [$key] ['rolename'] = $FC;
  5083. break;
  5084. }
  5085. }
  5086. }
  5087. Doo::loadModel ( 'enclosur' );
  5088. $enclosur = new enclosur ();
  5089. $enclosurList = $enclosur->find ( array (
  5090. 'where' => 'rid=' . $rid,
  5091. 'asArray' => true
  5092. ) );
  5093. $enclosurHtml = '';
  5094. foreach ( $enclosurList as $value ) {
  5095. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5096. }
  5097. if($receiptList[0]['version']==1){
  5098. require "protected/class/comm_cld.php";
  5099. $receiptList=makeReceiptDataVersion1($receiptList);
  5100. }
  5101. $data ['enclosurHtml'] = $enclosurHtml;
  5102. $receiptList [0] ['rlList'] = $rlList;
  5103. $data ['receiptList'] = $receiptList;
  5104. $data ['receiptList'][0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  5105. // print_r($receiptList);
  5106. $data ['memu'] = "receipt";
  5107. $data ['staff'] = $this->staff;
  5108. $data ['receiptMemu'] = 'approvalExpenses';
  5109. $data ['verifyId'] = $this->verifyId;
  5110. $data ['executeId'] = $this->executeId;
  5111. return $data;
  5112. }
  5113. function expensesDoc() {
  5114. $data=$this->_expensesDoc();
  5115. if($data['receiptList'][0]['version']==1){
  5116. $this->render ( "/fee/detail/receipt_compatible", $data );
  5117. die;
  5118. }
  5119. if(!empty($data['receiptList'][0]['itinerary2'])){
  5120. $this->render ( "/receipt/feeTraveView", $data );
  5121. }else{
  5122. $this->render ( "/admin/expensesDoc", $data );
  5123. }
  5124. }
  5125. function expensesDocPrint(){
  5126. $data=$this->_expensesDoc();
  5127. if($data['receiptList'][0]['version']==1){
  5128. $this->render ( "/fee/detail/receiptPrint_compatible", $data );
  5129. die;
  5130. }
  5131. $this->render ( "/receipt/expensesDocPrint", $data );
  5132. }
  5133. function expensesEdi() {
  5134. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5135. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  5136. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  5137. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5138. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  5139. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  5140. if (empty ( $status ))
  5141. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  5142. $vidList = array ();
  5143. $button = 0;
  5144. Doo::loadModel ( 'verify' );
  5145. Doo::loadModel ( 'receipt' );
  5146. Doo::loadModel ( 'staff' );
  5147. $staff = new staff ();
  5148. $receipt = new receipt ();
  5149. $verify = new verify ();
  5150. Doo::loadModel ( 'L_category' );
  5151. $Lcategory = new L_category ();
  5152. Doo::loadModel ( 'enclosur' );
  5153. $enclosur = new enclosur ();
  5154. // user verify ID
  5155. $verifyDetail = $verify->find ( array (
  5156. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  5157. 'asArray' => true
  5158. ) );
  5159. foreach ( $verifyDetail as $key => $value ) {
  5160. array_push ( $vidList, $value ['vid'] );
  5161. }
  5162. $vid = implode ( ",", $vidList );
  5163. if (empty ( $verifyDetail ))
  5164. $vid = 0;
  5165. $categoryList = $Lcategory->find ( array (
  5166. 'asArray' => true
  5167. ) );
  5168. $staffList = $staff->find ( array (
  5169. 'where' => 'cid=' . $cid,
  5170. 'asArray' => true
  5171. ) );
  5172. $ap = "";
  5173. if ($status == 4) {
  5174. $ap = 4;
  5175. $status = 2;
  5176. }
  5177. // get Receipt By verifyID status 2
  5178. $receiptList = $receipt->find ( array (
  5179. 'where' => 'rid =' . $rid . ' and status=2',
  5180. 'desc' => 'rid',
  5181. 'asArray' => true
  5182. ) );
  5183. if (empty ( $receiptList )) {
  5184. die ( 'illegal request' );
  5185. }
  5186. $Locate = 0;
  5187. $roleId = 0;
  5188. if ($ap == 4)
  5189. $status = 4;
  5190. foreach ( $receiptList as $key => $value ) {
  5191. $receiptList [$key] ['Locate'] = $Locate;
  5192. $Locate ++;
  5193. $receiptList [$key] ['reviseDetail'] = array ();
  5194. if (! empty ( $value ['reviseDetail'] ))
  5195. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5196. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5197. $categoryDetil = $Lcategory->getOne ( array (
  5198. 'where' => 'cid=' . $value ['cid'],
  5199. 'asArray' => true
  5200. ) );
  5201. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  5202. // 检测编辑状态
  5203. $verifyList = $verify->getOne ( array (
  5204. 'where' => 'vid=' . $value ['verify'],
  5205. 'asArray' => true
  5206. ) );
  5207. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5208. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5209. Doo::loadModel ( 'role' );
  5210. $role = new role ();
  5211. // print_r($verifyList);
  5212. $flag = true;
  5213. $roleKey = 0;
  5214. $endStaffArray = array ();
  5215. $roleArrayCopy = array ();
  5216. foreach ( $verifyList as $k => $v ) {
  5217. // init verifyStaff
  5218. if ($v [1] == 'ROLE') {
  5219. if (! empty ( $verifyStaff )) {
  5220. $endStaffArray = end ( $verifyStaff );
  5221. if ($v [0] == $endStaffArray ['nextStaff']) {
  5222. $roleId = $v [0];
  5223. }
  5224. }
  5225. $roleVerify = json_decode ( $v [3], true );
  5226. $roleKey = $k;
  5227. $roleArray = array ();
  5228. $rolename = $role->getOne ( array (
  5229. 'where' => 'rid=' . $v [0],
  5230. 'asArray' => true
  5231. ) );
  5232. foreach ( $roleVerify as $o => $p ) {
  5233. $staffID = explode ( '_', $p );
  5234. $staffInfo = $staff->getOne ( array (
  5235. 'where' => 'sid=' . $staffID [0],
  5236. 'asArray' => true
  5237. ) );
  5238. // print_r($staffID);
  5239. $exp = array (
  5240. 0 => $staffInfo ['sid'],
  5241. 1 => $staffID [1],
  5242. 2 => $staffInfo ['avatar'],
  5243. 'date' => '',
  5244. 'date' => '',
  5245. 'opinion' => '',
  5246. 'status' => '',
  5247. 'rolename' => $rolename ['name']
  5248. );
  5249. array_push ( $roleArray, $exp );
  5250. }
  5251. $roleArrayCopy [$v [0]] = $roleArray;
  5252. // $verifyList[$k]['roleArray']=$roleArray;
  5253. }
  5254. // print_r($roleArray);
  5255. $verifyList [$k] ['date'] = "";
  5256. $verifyList [$k] ['opinion'] = "";
  5257. $verifyList [$k] ['status'] = "";
  5258. if (empty ( $verifyStaff )) {
  5259. $verifyList [$k] ['date'] = "";
  5260. $verifyList [$k] ['opinion'] = "";
  5261. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5262. $verifyList [$k] ['status'] = 4;
  5263. $button = 4;
  5264. $flag = false;
  5265. }
  5266. } else {
  5267. foreach ( $verifyStaff as $m => $u ) {
  5268. if ($v [0] == $m) {
  5269. $verifyList [$k] ['date'] = $u ['date'];
  5270. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5271. $verifyList [$k] ['status'] = $u ['status'];
  5272. $flag = false;
  5273. break;
  5274. }
  5275. }
  5276. $endStaffArray = end ( $verifyStaff );
  5277. if (isset ( $endStaffArray ['ROLE'] )) {
  5278. } else {
  5279. $endKey = key ( $verifyStaff );
  5280. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  5281. $button = 4;
  5282. $verifyList [$k] ['status'] = 4;
  5283. }
  5284. }
  5285. }
  5286. }
  5287. $rolename ['name'] = '';
  5288. if (! empty ( $roleId )) {
  5289. Doo::loadModel ( 'role' );
  5290. $role = new role ();
  5291. $rolename = $role->getOne ( array (
  5292. 'where' => 'rid=' . $roleId,
  5293. 'asArray' => true
  5294. ) );
  5295. }
  5296. if (! empty ( $verifyStaff ))
  5297. $endStaffArray = end ( $verifyStaff );
  5298. $KOP = false;
  5299. foreach ( $roleArrayCopy as $P => $A ) {
  5300. foreach ( $A as $MKI => $AVL ) {
  5301. if (! empty ( $verifyStaff )) {
  5302. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5303. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5304. $button = 4;
  5305. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5306. }
  5307. foreach ( $verifyStaff as $m => $u ) {
  5308. $AVLFK = $AVL [0] . '_R';
  5309. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5310. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5311. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5312. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5313. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5314. break;
  5315. }
  5316. }
  5317. } else {
  5318. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5319. $button = 4;
  5320. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5321. }
  5322. }
  5323. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5324. $KOP = true;
  5325. }
  5326. }
  5327. // print_r($roleArrayCopy);
  5328. // echo $roleKey;
  5329. foreach ( $roleArrayCopy as $k => $v ) {
  5330. foreach ( $verifyList as $m => $n ) {
  5331. if ($n [0] == $k) {
  5332. array_splice ( $verifyList, $m, 1, $v );
  5333. }
  5334. }
  5335. }
  5336. $receiptList [$key] ['verifyList'] = $verifyList;
  5337. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  5338. 'where' => 'sid=' . $value ['staff'],
  5339. 'asArray' => true
  5340. ) );
  5341. $receiptList [$key] ['button'] = $button;
  5342. $receiptList [$key] ['BIGsum'] = $this->num_to_rmb ( $value ['sum'] );
  5343. }
  5344. // $data['verifyDetail']=$verifyDetail;
  5345. $mothHtml = "";
  5346. for($i = 1; $i <= 12; $i ++) {
  5347. if ($month == $i)
  5348. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  5349. else
  5350. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  5351. }
  5352. // 获取审批日志
  5353. Doo::loadModel ( 'receiptLog' );
  5354. $receiptLog = new receiptLog ();
  5355. $rlList = array ();
  5356. $rlInfo = $receiptLog->getOne ( array (
  5357. 'where' => 'rid=' . $rid . ' and status=4',
  5358. 'asArray' => true
  5359. ) );
  5360. $tijdate = $receiptLog->getOne ( array (
  5361. 'where' => 'rid=' . $rid . ' and status=2',
  5362. 'asc' => 'rlid',
  5363. 'asArray' => true
  5364. ) );
  5365. if (! empty ( $rlInfo )) {
  5366. $rlList = $receiptLog->find ( array (
  5367. 'where' => 'rid=' . $rid,
  5368. 'asc' => 'rlid',
  5369. 'asArray' => true
  5370. ) );
  5371. }
  5372. $receiptList [0] ['rlList'] = $rlList;
  5373. $enclosurList = $enclosur->find ( array (
  5374. 'where' => 'rid=' . $rid,
  5375. 'asArray' => true
  5376. ) );
  5377. $enclosurHtml = '';
  5378. foreach ( $enclosurList as $value ) {
  5379. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  5380. }
  5381. // print_r($receiptList);
  5382. $data ['rid'] = $rid;
  5383. $data ['enclosurHtml'] = $enclosurHtml;
  5384. $data ['rolename'] = $rolename ['name'];
  5385. $data ['datetij'] = $tijdate ['date'];
  5386. $data ['mothHtml'] = $mothHtml;
  5387. $data ['receiptList'] = $receiptList;
  5388. $data ['receiptApprovalCount'] = count ( $receiptList );
  5389. $data ['status'] = $status;
  5390. $data ['year'] = $year;
  5391. $data ['categoryList'] = $categoryList;
  5392. $data ['staffList'] = $staffList;
  5393. $data ['cid'] = $cid;
  5394. $data ['sid'] = $sid;
  5395. $data ['ap'] = $ap;
  5396. $data ['memu'] = "receipt";
  5397. $data ['staff'] = $this->staff;
  5398. $data ['receiptMemu'] = 'approvalExpenses';
  5399. $data ['verifyId'] = $this->verifyId;
  5400. $data ['executeId'] = $this->executeId;
  5401. $this->render ( "/admin/expensesEdi", $data );
  5402. }
  5403. function expensesDefray() {
  5404. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  5405. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  5406. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5407. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  5408. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  5409. if (! empty ( $rid )) {
  5410. Doo::loadModel ( "verify" );
  5411. $verify = new verify ();
  5412. Doo::loadModel ( "receiptDetail" );
  5413. $receiptDetailObj = new receiptDetail ();
  5414. Doo::loadModel ( "itemStatistics" );
  5415. Doo::loadModel ( "statistics" );
  5416. $statistics = new statistics ();
  5417. $itemStatistics = new itemStatistics ();
  5418. Doo::loadModel ( "receipt" );
  5419. $receipt = new receipt ();
  5420. Doo::loadModel ( "loanReceipt" );
  5421. $loanReceipt = new loanReceipt ();
  5422. $receiptDetail = $receipt->getOne ( array (
  5423. 'where' => 'rid=' . $rid . ' and status=2 ',
  5424. 'asArray' => true
  5425. ) );
  5426. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  5427. $nsflag = true;
  5428. foreach ( $nslist as $value ) {
  5429. if ($value == $this->staff ['0'] ['sid']) {
  5430. $nsflag = false;
  5431. break;
  5432. }
  5433. }
  5434. // print_r($nslist);die;
  5435. if (empty ( $receiptDetail ) || $nsflag)
  5436. return "/approvalExpenses/pendApproval";
  5437. $verifyDetail = $verify->getOne ( array (
  5438. 'where' => ' vid =' . $receiptDetail ['verify'],
  5439. 'asArray' => true
  5440. ) );
  5441. $verifyString = $verifyDetail ['staff'];
  5442. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  5443. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  5444. if (empty ( $opinion )) {
  5445. if ($status == 3)
  5446. $opinion = "终止";
  5447. else
  5448. $opinion = "同意支付";
  5449. }
  5450. $nowStaff = 0;
  5451. $nowStaffList = array ();
  5452. if (empty ( $verifyStaff )) {
  5453. // 还需加入是否已经进入角色审批
  5454. if ($verifyDetail [0] [1] == 'ROLE') {
  5455. // print_r($verifyDetail);echo "ddd";
  5456. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  5457. foreach ( $vStaffString as $key => $value ) {
  5458. $staffK = explode ( "_", $value );
  5459. if ($staffK [0] != $this->staff [0] ['sid'])
  5460. array_push ( $nowStaffList, $staffK [0] );
  5461. }
  5462. // print_r($verifyDetail);
  5463. // die;
  5464. if (! empty ( $nowStaffList )) {
  5465. $nowStaff = implode ( ',', $nowStaffList );
  5466. $verifyStaff = array (
  5467. $this->staff [0] ['sid'] . "_R" => array (
  5468. 'date' => date ( 'Y-m-d' ),
  5469. 'opinion' => $opinion,
  5470. 'status' => $status,
  5471. 'nextStaff' => $verifyDetail [0] [0],
  5472. 'ROLE' => 1
  5473. )
  5474. );
  5475. } else {
  5476. $nowStaff = $verifyDetail [1] [0];
  5477. $verifyStaff = array (
  5478. $this->staff [0] ['sid'] . "_R" => array (
  5479. 'date' => date ( 'Y-m-d' ),
  5480. 'opinion' => $opinion,
  5481. 'status' => $status,
  5482. 'nextStaff' => $verifyDetail [1] [0]
  5483. )
  5484. );
  5485. }
  5486. } else {
  5487. if ($verifyDetail [1] [1] == 'ROLE') {
  5488. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  5489. // echo "dd";
  5490. foreach ( $vStaffString as $key => $value ) {
  5491. $staffK = explode ( "_", $value );
  5492. array_push ( $nowStaffList, $staffK [0] );
  5493. }
  5494. $nowStaff = implode ( ',', $nowStaffList );
  5495. $verifyStaff = array (
  5496. $this->staff [0] ['sid'] => array (
  5497. 'date' => date ( 'Y-m-d' ),
  5498. 'opinion' => $opinion,
  5499. 'status' => $status,
  5500. 'nextStaff' => $verifyDetail [1] [0],
  5501. 'ROLE' => 1
  5502. )
  5503. );
  5504. } else {
  5505. $nowStaff = $verifyDetail [1] [0];
  5506. $verifyStaff = array (
  5507. $this->staff [0] ['sid'] => array (
  5508. 'date' => date ( 'Y-m-d' ),
  5509. 'opinion' => $opinion,
  5510. 'status' => $status,
  5511. 'nextStaff' => $verifyDetail [1] [0]
  5512. )
  5513. );
  5514. }
  5515. }
  5516. if ($status == 3)
  5517. $verifyStaff = array (
  5518. 'final' => $status,
  5519. $this->staff [0] ['sid'] => array (
  5520. 'date' => date ( 'Y-m-d' ),
  5521. 'opinion' => $opinion,
  5522. 'status' => $status
  5523. )
  5524. );
  5525. $vStaffString = json_encode ( $verifyStaff );
  5526. $receipt->nowStaff = $nowStaff;
  5527. $receipt->verifyStaff = $vStaffString;
  5528. $loanReceipt->nowStaff = $nowStaff;
  5529. $loanReceipt->verifyStaff = $vStaffString;
  5530. } else {
  5531. $VS = end ( $verifyStaff );
  5532. // 非角色审批
  5533. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  5534. $nextStaff = 0;
  5535. $roleSTF = false;
  5536. foreach ( $verifyDetail as $key => $value ) {
  5537. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  5538. if (isset ( $verifyDetail [$key + 1] )) {
  5539. $nextStaff = $verifyDetail [$key + 1] [0];
  5540. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  5541. $roleSTF = true;
  5542. }
  5543. break;
  5544. }
  5545. }
  5546. if (! $roleSTF) {
  5547. $nowStaff = $nextStaff;
  5548. $verifyStaff [$this->staff [0] ['sid']] = array (
  5549. 'date' => date ( 'Y-m-d' ),
  5550. 'opinion' => $opinion,
  5551. 'status' => $status,
  5552. 'nextStaff' => $nextStaff
  5553. );
  5554. } else {
  5555. // 获取角色下的所有用户ID
  5556. $nowStaffList = array ();
  5557. foreach ( $verifyDetail as $vfk ) {
  5558. if ($vfk [1] == 'ROLE') {
  5559. $vStaffString = json_decode ( $vfk [3] );
  5560. foreach ( $vStaffString as $key => $value ) {
  5561. $staffK = explode ( "_", $value );
  5562. array_push ( $nowStaffList, $staffK [0] );
  5563. }
  5564. }
  5565. }
  5566. $nowStaff = implode ( ',', $nowStaffList );
  5567. $verifyStaff [$this->staff [0] ['sid']] = array (
  5568. 'date' => date ( 'Y-m-d' ),
  5569. 'opinion' => $opinion,
  5570. 'status' => $status,
  5571. 'nextStaff' => $nextStaff,
  5572. 'ROLE' => 0
  5573. );
  5574. }
  5575. if ($status == 3) {
  5576. $verifyStaff ['final'] = $status;
  5577. $verifyStaff [$this->staff [0] ['sid']] = array (
  5578. 'date' => date ( 'Y-m-d' ),
  5579. 'opinion' => $opinion,
  5580. 'status' => $status
  5581. );
  5582. }
  5583. $vStaffString = json_encode ( $verifyStaff );
  5584. $receipt->nowStaff = $nowStaff;
  5585. $receipt->verifyStaff = $vStaffString;
  5586. $loanReceipt->nowStaff = $nowStaff;
  5587. $loanReceipt->verifyStaff = $vStaffString;
  5588. }
  5589. // 角色审批
  5590. if (isset ( $VS ['ROLE'] )) {
  5591. // 找出角色人 当前审批角色组
  5592. $verifyJSStaff = array ();
  5593. $nowStaffList2 = array ();
  5594. foreach ( $verifyDetail as $key => $value ) {
  5595. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  5596. $verifyJSStaff = json_decode ( $value [3] );
  5597. foreach ( $verifyJSStaff as $m ) {
  5598. $staffK = explode ( "_", $m );
  5599. array_push ( $nowStaffList2, $staffK [0] );
  5600. }
  5601. // print_r($nowStaffList2);
  5602. }
  5603. }
  5604. $RoleVerifyStaff = array ();
  5605. foreach ( $verifyStaff as $key => $value ) {
  5606. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  5607. foreach ( $nowStaffList2 as $m ) {
  5608. if ($key == $m . "_R")
  5609. $RoleVerifyStaff [$key] = $value;
  5610. }
  5611. }
  5612. }
  5613. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  5614. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  5615. // 下一个审批人ID
  5616. $nextStaff = 0;
  5617. $falg = false;
  5618. foreach ( $verifyDetail as $key => $value ) {
  5619. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  5620. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  5621. $falg = true;
  5622. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  5623. $nowStaffList = array ();
  5624. foreach ( $vStaffString as $v ) {
  5625. $staffK = explode ( "_", $v );
  5626. array_push ( $nowStaffList, $staffK [0] );
  5627. }
  5628. $nowStaff = implode ( ',', $nowStaffList );
  5629. $nextStaff = $verifyDetail [$key + 1] [0];
  5630. } elseif (isset ( $verifyDetail [$key + 1] )) {
  5631. $nextStaff = $verifyDetail [$key + 1] [0];
  5632. $nowStaff = $nextStaff;
  5633. } else
  5634. $nowStaff = '';
  5635. break;
  5636. }
  5637. }
  5638. if ($falg)
  5639. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5640. 'date' => date ( 'Y-m-d' ),
  5641. 'opinion' => $opinion,
  5642. 'status' => $status,
  5643. 'nextStaff' => $nextStaff,
  5644. 'ROLE' => 1
  5645. );
  5646. else
  5647. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5648. 'date' => date ( 'Y-m-d' ),
  5649. 'opinion' => $opinion,
  5650. 'status' => $status,
  5651. 'nextStaff' => $nextStaff
  5652. );
  5653. // print_r($verifyStaff);
  5654. // echo $nowStaff;die;
  5655. } else { // 进入下一个角色或者审批人
  5656. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  5657. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  5658. 'date' => date ( 'Y-m-d' ),
  5659. 'opinion' => $opinion,
  5660. 'status' => $status,
  5661. 'nextStaff' => $VS ['nextStaff'],
  5662. 'ROLE' => 1
  5663. );
  5664. }
  5665. if ($status == 3) {
  5666. $verifyStaff ['final'] = $status;
  5667. $verifyStaff [$this->staff [0] ['sid']] = array (
  5668. 'date' => date ( 'Y-m-d' ),
  5669. 'opinion' => $opinion,
  5670. 'status' => $status
  5671. );
  5672. }
  5673. $vStaffString = json_encode ( $verifyStaff );
  5674. $receipt->verifyStaff = $vStaffString;
  5675. $receipt->nowStaff = $nowStaff;
  5676. $loanReceipt->nowStaff = $nowStaff;
  5677. $loanReceipt->verifyStaff = $vStaffString;
  5678. }
  5679. // print_r($verifyStaff);die;
  5680. }
  5681. $roleKey = 0;
  5682. $roleId = 0;
  5683. $verifyDetailCopy = array ();
  5684. foreach ( $verifyDetail as $k => $v ) {
  5685. if ($v [1] == 'ROLE') {
  5686. $roleId = $v [0];
  5687. $roleVerify = json_decode ( $v [3], true );
  5688. $roleKey = $k;
  5689. $roleArray = array ();
  5690. foreach ( $roleVerify as $o => $p ) {
  5691. $staffID = explode ( '_', $p );
  5692. $exp = array (
  5693. 0 => $staffID [0],
  5694. 1 => $staffID [1]
  5695. );
  5696. array_push ( $roleArray, $exp );
  5697. }
  5698. $verifyDetailCopy [$v [0]] = $roleArray;
  5699. }
  5700. }
  5701. // print_r($verifyDetail);
  5702. foreach ( $verifyDetailCopy as $k => $v ) {
  5703. foreach ( $verifyDetail as $m => $n ) {
  5704. if ($n [0] == $k) {
  5705. array_splice ( $verifyDetail, $m, 1, $v );
  5706. }
  5707. }
  5708. }
  5709. // 审批日志
  5710. if (! isset ( $verifyStaff ['final'] )) {
  5711. Doo::loadModel ( "receiptLog" );
  5712. $receiptLog = new receiptLog ();
  5713. if (! empty ( $roleId )) {
  5714. Doo::loadModel ( "role" );
  5715. $role = new role ();
  5716. $roleInfo = $role->getOne ( array (
  5717. 'where' => 'rid=' . $roleId,
  5718. 'asArray' => true
  5719. ) );
  5720. $receiptLog->rolename = $roleInfo ['name'];
  5721. }
  5722. $receiptLog->username = $this->staff [0] ['username'];
  5723. $receiptLog->uid = $this->staff [0] ['sid'];
  5724. $receiptLog->date = date ( "Y-m-d" );
  5725. $receiptLog->opinion = $opinion;
  5726. $receiptLog->img = $this->staff [0] ['avatar'];
  5727. $receiptLog->status = 1;
  5728. $receiptLog->rid = $rid;
  5729. $receiptLog->insert ();
  5730. }
  5731. if (isset ( $verifyStaff ['final'] )) { // rDetail
  5732. $receipt->status = 3;
  5733. $receipt->verifyBreakup = $verifyString;
  5734. $receiptDetailObj->status = 3;
  5735. $receiptDetailObj->update ( array (
  5736. 'where' => 'rid=' . $rid
  5737. ) );
  5738. // 微信企业号通知
  5739. $this->setWXMsg ( $rid, 3 );
  5740. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  5741. $receipt->status = 6;
  5742. $receipt->pastDate = date ( "Y-m-d" );
  5743. $receipt->isBK = 1;
  5744. $loanReceipt->verifyBreakup = $verifyString;
  5745. $loanReceipt->status = 1;
  5746. $loanReceipt->pastDate = date ( "Y-m-d" );
  5747. //生成流水后 不更新汇款金额
  5748. Doo::loadModel ( 'wasteBook' );
  5749. $wasteBook = new wasteBook ();
  5750. $wbDetail = $wasteBook->getWateBookByAD ( 1, $rid );
  5751. if (empty($wbDetail)){
  5752. $loanReceipt->amount = $receiptDetail ['amount'];
  5753. }
  5754. $loanReceipt->update ( array (
  5755. 'where' => ' rid = ' . $receiptDetail ['loanRid']
  5756. ) );
  5757. // 微信企业号通知
  5758. $this->setWXMsg ( $rid, 1 );
  5759. }
  5760. $receipt->amount = $receiptDetail['sum'];
  5761. $receipt->update ( array (
  5762. 'where' => ' rid = ' . $rid
  5763. ) );
  5764. // 进入下一条审批费用新加需求
  5765. $vidList = array ();
  5766. $verifyDetail = $verify->find ( array (
  5767. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  5768. 'asArray' => true
  5769. ) );
  5770. foreach ( $verifyDetail as $key => $value ) {
  5771. array_push ( $vidList, $value ['vid'] );
  5772. }
  5773. $vid = implode ( ",", $vidList );
  5774. if (empty ( $verifyDetail ))
  5775. $vid = 0;
  5776. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  5777. $receipt = new receipt ();
  5778. $rd = $receipt->getOne ( array (
  5779. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ')',
  5780. 'asc' => 'rid',
  5781. 'asArray' => true
  5782. ) );
  5783. if (empty ( $rd )) {
  5784. return '/approvalExpenses/pendApproval';
  5785. }
  5786. if ($rd ['Rtype'] == 1) {
  5787. if ($rd ['isBK'] == 1) {
  5788. return '/receiptburEdi/' . $rd ['rid'];
  5789. } else {
  5790. return '/expensesEdi/' . $rd ['rid'];
  5791. }
  5792. } elseif ($rd ['Rtype'] == 2) {
  5793. return '/remitApproval/' . $rd ['rid'];
  5794. } else {
  5795. return '/receiptburEdi/' . $rd ['rid'];
  5796. }
  5797. // return "/approvalExpenses/pendApproval";
  5798. }
  5799. }
  5800. function ajaxExamineExe() {
  5801. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  5802. Doo::loadModel ( 'receipt' );
  5803. $receipt = new receipt ();
  5804. Doo::loadClass ( 'XDeode' );
  5805. $XDeode = new XDeode ( 5 );
  5806. if (! empty ( $rid )) {
  5807. $rLRes = $receipt->find ( array (
  5808. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and executeStaff not like \'%{"' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid!=' . $rid,
  5809. 'asArray' => true
  5810. ) );
  5811. $rLRes [0] ['ridKey'] = $XDeode->encode ( $rLRes [0] ['rid'] );
  5812. echo json_encode ( array (
  5813. 'status' => 1,
  5814. 'receipt' => $rLRes [0]
  5815. ) );
  5816. die ();
  5817. }
  5818. echo json_encode ( array (
  5819. 'status' => 0,
  5820. 'receipt' => array ()
  5821. ) );
  5822. die ();
  5823. }
  5824. function implement() {
  5825. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  5826. $Rtype = isset ( $this->params ['Rtype'] ) ? $this->params ['Rtype'] : '';
  5827. Doo::loadClass ( 'XDeode' );
  5828. $XDeode = new XDeode ( 5 );
  5829. Doo::loadModel ( 'receipt' );
  5830. $receipt = new receipt ();
  5831. Doo::loadModel ( 'L_category' );
  5832. $Lcategory = new L_category ();
  5833. Doo::loadModel ( 'verify' );
  5834. $verify = new verify ();
  5835. Doo::loadModel ( 'staff' );
  5836. $staff = new staff ();
  5837. Doo::loadModel ( "execute" );
  5838. $execute = new execute ();
  5839. $rid = $XDeode->decode ( $rid );
  5840. $receiptList = $receipt->find ( array (
  5841. 'where' => 'executeCopy like \'%["' . $this->staff [0] ['sid'] . '%\' and (status=1 or status=6) and rid=' . $rid,
  5842. 'desc' => 'rid',
  5843. 'asArray' => true
  5844. ) );
  5845. Doo::loadModel ( 'loanReceipt' );
  5846. $loanReceipt = new loanReceipt ();
  5847. // print_r($receiptList);
  5848. $loanList = array ();
  5849. if (! isset ( $receiptList ))
  5850. $loanList = $loanReceipt->find ( array (
  5851. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  5852. 'desc' => 'rid',
  5853. 'asArray' => true
  5854. ) );
  5855. $Locate = 0;
  5856. $roleId = 0;
  5857. $button = 0;
  5858. foreach ( $loanList as $key => $value ) {
  5859. $loanList [$key] ['Locate'] = $Locate;
  5860. $Locate ++;
  5861. $loanList [$key] ['reviseDetail'] = array ();
  5862. if (! empty ( $value ['reviseDetail'] ))
  5863. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  5864. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  5865. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  5866. $categoryDetil = $Lcategory->getOne ( array (
  5867. 'where' => 'cid=' . $value ['cid'],
  5868. 'asArray' => true
  5869. ) );
  5870. $loanList [$key] ['category'] = $categoryDetil ['title'];
  5871. // 检测编辑状态
  5872. $verifyList = $verify->getOne ( array (
  5873. 'where' => 'vid=' . $value ['verify'],
  5874. 'asArray' => true
  5875. ) );
  5876. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  5877. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  5878. Doo::loadModel ( 'role' );
  5879. $role = new role ();
  5880. $flag = true;
  5881. $roleKey = 0;
  5882. $endStaffArray = array ();
  5883. $roleArrayCopy = array ();
  5884. foreach ( $verifyList as $k => $v ) {
  5885. // init verifyStaff
  5886. if ($v [1] == 'ROLE') {
  5887. if (! empty ( $verifyStaff )) {
  5888. $endStaffArray = end ( $verifyStaff );
  5889. // if ($v[0]==$endStaffArray['nextStaff']){
  5890. // $roleId=$v[0];
  5891. // }
  5892. }
  5893. $roleVerify = json_decode ( $v [3], true );
  5894. $roleKey = $k;
  5895. $roleArray = array ();
  5896. $rolename = $role->getOne ( array (
  5897. 'where' => 'rid=' . $v [0],
  5898. 'asArray' => true
  5899. ) );
  5900. foreach ( $roleVerify as $o => $p ) {
  5901. $staffID = explode ( '_', $p );
  5902. $staffInfo = $staff->getOne ( array (
  5903. 'where' => 'sid=' . $staffID [0],
  5904. 'asArray' => true
  5905. ) );
  5906. // print_r($staffID);
  5907. $exp = array (
  5908. 0 => $staffInfo ['sid'],
  5909. 1 => $staffID [1],
  5910. 2 => $staffInfo ['avatar'],
  5911. 'date' => '',
  5912. 'date' => '',
  5913. 'opinion' => '',
  5914. 'status' => '',
  5915. 'rolename' => $rolename ['name']
  5916. );
  5917. array_push ( $roleArray, $exp );
  5918. }
  5919. $roleArrayCopy [$v [0]] = $roleArray;
  5920. // $verifyList[$k]['roleArray']=$roleArray;
  5921. }
  5922. $verifyList [$k] ['date'] = "";
  5923. $verifyList [$k] ['opinion'] = "";
  5924. $verifyList [$k] ['status'] = "";
  5925. if (empty ( $verifyStaff )) {
  5926. $verifyList [$k] ['date'] = "";
  5927. $verifyList [$k] ['opinion'] = "";
  5928. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  5929. $verifyList [$k] ['status'] = 4;
  5930. $flag = false;
  5931. }
  5932. } else {
  5933. foreach ( $verifyStaff as $m => $u ) {
  5934. if ($v [0] == $m) {
  5935. $verifyList [$k] ['date'] = $u ['date'];
  5936. $verifyList [$k] ['opinion'] = $u ['opinion'];
  5937. $verifyList [$k] ['status'] = $u ['status'];
  5938. $flag = false;
  5939. break;
  5940. }
  5941. }
  5942. $endStaffArray = end ( $verifyStaff );
  5943. if (isset ( $endStaffArray ['ROLE'] )) {
  5944. } else {
  5945. // $endKey=key($verifyStaff);
  5946. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  5947. // $button=4;
  5948. // $verifyList[$k]['status']=4;
  5949. // }
  5950. }
  5951. }
  5952. }
  5953. $rolename ['name'] = '';
  5954. if (! empty ( $roleId )) {
  5955. Doo::loadModel ( 'role' );
  5956. $role = new role ();
  5957. $rolename = $role->getOne ( array (
  5958. 'where' => 'rid=' . $roleId,
  5959. 'asArray' => true
  5960. ) );
  5961. }
  5962. if (! empty ( $verifyStaff ))
  5963. $endStaffArray = end ( $verifyStaff );
  5964. $KOP = false;
  5965. foreach ( $roleArrayCopy as $P => $A ) {
  5966. foreach ( $A as $MKI => $AVL ) {
  5967. if (! empty ( $verifyStaff )) {
  5968. // &&$rolename['rid']==$endStaffArray['nextStaff']
  5969. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  5970. $button = 4;
  5971. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5972. }
  5973. foreach ( $verifyStaff as $m => $u ) {
  5974. $AVLFK = $AVL [0] . '_R';
  5975. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  5976. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  5977. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  5978. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  5979. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  5980. break;
  5981. }
  5982. }
  5983. } else {
  5984. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  5985. $button = 4;
  5986. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  5987. }
  5988. }
  5989. // $roleArray[$MKI]['rolename']=$rolename['name'];
  5990. $KOP = true;
  5991. }
  5992. }
  5993. foreach ( $roleArrayCopy as $k => $v ) {
  5994. foreach ( $verifyList as $m => $n ) {
  5995. if ($n [0] == $k) {
  5996. array_splice ( $verifyList, $m, 1, $v );
  5997. }
  5998. }
  5999. }
  6000. $loanList [$key] ['verifyList'] = $verifyList;
  6001. $loanList [$key] ['staffDetail'] = $staff->getOne ( array (
  6002. 'where' => 'sid=' . $value ['staff'],
  6003. 'asArray' => true
  6004. ) );
  6005. }
  6006. $data ['loanList'] = $loanList;
  6007. $Locate = 0;
  6008. $roleId = 0;
  6009. $button = 0;
  6010. Doo::loadClass ( 'XDeode' );
  6011. $XDeode = new XDeode ( 5 );
  6012. foreach ( $receiptList as $key => $value ) {
  6013. $receiptList[$key]['ridKey']=$XDeode->encode ( $value['rid'] );
  6014. $button2 = 0;
  6015. $receiptList [$key] ['Locate'] = $Locate;
  6016. $Locate ++;
  6017. $receiptList [$key] ['reviseDetail'] = array ();
  6018. if (! empty ( $value ['reviseDetail'] ))
  6019. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6020. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6021. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6022. $categoryDetil = $Lcategory->getOne ( array (
  6023. 'where' => 'cid=' . $value ['cid'],
  6024. 'asArray' => true
  6025. ) );
  6026. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6027. $executeList = json_decode ( $value ['executeCopy'], true );
  6028. $executeStaff = array ();
  6029. if (! empty ( $value ['executeStaff'] ))
  6030. $executeStaff = json_decode ( $value ['executeStaff'], true );
  6031. if (isset ( $executeList )) {
  6032. foreach ( $executeList as $op => $lo ) {
  6033. $executeList [$op] ['date'] = "";
  6034. $executeList [$op] ['opinion'] = "";
  6035. $executeList [$op] ['status'] = "";
  6036. foreach ( $executeStaff as $m => $u ) {
  6037. if ($lo [0] == $m) {
  6038. $executeList [$op] ['date'] = $u ['date'];
  6039. $executeList [$op] ['opinion'] = $u ['opinion'];
  6040. $executeList [$op] ['status'] = $u ['status'];
  6041. break;
  6042. }
  6043. }
  6044. if ($this->staff [0] ['sid'] == $lo [0] && empty ( $executeList [$op] ['status'] )) {
  6045. $button2 = 1;
  6046. $executeList [$op] ['status'] = 4;
  6047. }
  6048. }
  6049. }
  6050. // 检测编辑状态
  6051. if ($value ['status'] == 3 || $value ['status'] == 1 || $value ['status'] == 9) {
  6052. $verifyList ['staff'] = $value ['verifyBreakup'];
  6053. } else
  6054. $verifyList = $verify->getOne ( array (
  6055. 'where' => 'vid=' . $value ['verify'],
  6056. 'asArray' => true
  6057. ) );
  6058. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6059. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6060. Doo::loadModel ( 'role' );
  6061. $role = new role ();
  6062. if ($verifyList == NULL)
  6063. $verifyList = array ();
  6064. $flag = true;
  6065. $roleKey = 0;
  6066. $endStaffArray = array ();
  6067. $roleArrayCopy = array ();
  6068. foreach ( $verifyList as $k => $v ) {
  6069. // init verifyStaff
  6070. if ($v [1] == 'ROLE') {
  6071. if (! empty ( $verifyStaff )) {
  6072. $endStaffArray = end ( $verifyStaff );
  6073. // if ($v[0]==$endStaffArray['nextStaff']){
  6074. // $roleId=$v[0];
  6075. // }
  6076. }
  6077. $roleVerify = json_decode ( $v [3], true );
  6078. $roleKey = $k;
  6079. $roleArray = array ();
  6080. $rolename = $role->getOne ( array (
  6081. 'where' => 'rid=' . $v [0],
  6082. 'asArray' => true
  6083. ) );
  6084. foreach ( $roleVerify as $o => $p ) {
  6085. $staffID = explode ( '_', $p );
  6086. $staffInfo = $staff->getOne ( array (
  6087. 'where' => 'sid=' . $staffID [0],
  6088. 'asArray' => true
  6089. ) );
  6090. // print_r($staffID);
  6091. $exp = array (
  6092. 0 => $staffInfo ['sid'],
  6093. 1 => $staffID [1],
  6094. 2 => $staffInfo ['avatar'],
  6095. 'date' => '',
  6096. 'date' => '',
  6097. 'opinion' => '',
  6098. 'status' => '',
  6099. 'rolename' => $rolename ['name']
  6100. );
  6101. array_push ( $roleArray, $exp );
  6102. }
  6103. $roleArrayCopy [$v [0]] = $roleArray;
  6104. // $verifyList[$k]['roleArray']=$roleArray;
  6105. }
  6106. $verifyList [$k] ['date'] = "";
  6107. $verifyList [$k] ['opinion'] = "";
  6108. $verifyList [$k] ['status'] = "";
  6109. if (empty ( $verifyStaff )) {
  6110. $verifyList [$k] ['date'] = "";
  6111. $verifyList [$k] ['opinion'] = "";
  6112. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6113. $verifyList [$k] ['status'] = 4;
  6114. $flag = false;
  6115. }
  6116. } else {
  6117. foreach ( $verifyStaff as $m => $u ) {
  6118. if ($v [0] == $m) {
  6119. $verifyList [$k] ['date'] = $u ['date'];
  6120. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6121. $verifyList [$k] ['status'] = $u ['status'];
  6122. $flag = false;
  6123. break;
  6124. }
  6125. }
  6126. $endStaffArray = end ( $verifyStaff );
  6127. if (isset ( $endStaffArray ['ROLE'] )) {
  6128. } else {
  6129. // $endKey=key($verifyStaff);
  6130. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  6131. // $button=4;
  6132. // $verifyList[$k]['status']=4;
  6133. // }
  6134. }
  6135. }
  6136. }
  6137. $rolename ['name'] = '';
  6138. if (! empty ( $roleId )) {
  6139. Doo::loadModel ( 'role' );
  6140. $role = new role ();
  6141. $rolename = $role->getOne ( array (
  6142. 'where' => 'rid=' . $roleId,
  6143. 'asArray' => true
  6144. ) );
  6145. }
  6146. if (! empty ( $verifyStaff ))
  6147. $endStaffArray = end ( $verifyStaff );
  6148. $KOP = false;
  6149. foreach ( $roleArrayCopy as $P => $A ) {
  6150. foreach ( $A as $MKI => $AVL ) {
  6151. if (! empty ( $verifyStaff )) {
  6152. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6153. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6154. $button = 4;
  6155. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6156. }
  6157. foreach ( $verifyStaff as $m => $u ) {
  6158. $AVLFK = $AVL [0] . '_R';
  6159. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6160. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6161. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6162. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6163. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6164. break;
  6165. }
  6166. }
  6167. } else {
  6168. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6169. $button = 4;
  6170. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6171. }
  6172. }
  6173. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6174. $KOP = true;
  6175. }
  6176. }
  6177. foreach ( $roleArrayCopy as $k => $v ) {
  6178. foreach ( $verifyList as $m => $n ) {
  6179. if ($n [0] == $k) {
  6180. array_splice ( $verifyList, $m, 1, $v );
  6181. }
  6182. }
  6183. }
  6184. $receiptList [$key] ['verifyList'] = $verifyList;
  6185. $receiptList [$key] ['executeList'] = $executeList;
  6186. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6187. 'where' => 'sid=' . $value ['staff'],
  6188. 'asArray' => true
  6189. ) );
  6190. $receiptList [$key] ['button2'] = $button2;
  6191. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  6192. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  6193. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  6194. $receiptList [$key] ['relust'] = $relust;
  6195. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( $relust );
  6196. $receiptList [$key] ['amountABS'] = abs ( $value ['amount'] );
  6197. }
  6198. //执行人是否是最后一位
  6199. $executeCopy = json_decode ( $receiptList [0] ['executeCopy'], true );
  6200. $executeStaff = json_decode ( $receiptList [0] ['executeStaff'], true );
  6201. $executePrimary=count($executeCopy)-1;
  6202. $lastOne=true;
  6203. if($executePrimary!=count($executeStaff)){
  6204. $lastOne=false;
  6205. }
  6206. $data['lastOne']=$lastOne;
  6207. // 是否写入过流水
  6208. $accountType = 0;
  6209. if ($receiptList [0] ['Rtype'] == 0) {
  6210. $accountType = 3;
  6211. } elseif ($receiptList [0] ['Rtype'] == 1) {
  6212. if (!empty($receiptList [0]['accountItem']) )
  6213. $accountType = 2;
  6214. else
  6215. $accountType = 1;
  6216. } elseif ($receiptList [0] ['Rtype'] == 2) {
  6217. $accountType = 4;
  6218. } elseif ($receiptList [0] ['Rtype'] == 3) {
  6219. $accountType = 12;
  6220. }
  6221. Doo::loadModel ( 'wasteBook' );
  6222. $wasteBook = new wasteBook ();
  6223. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $receiptList [0] ['rid'] );
  6224. $data ['wbDetail'] = $wbDetail;
  6225. $wbDetailLoan=array();
  6226. if ($accountType==2){
  6227. $wbDetailLoan = $wasteBook->getWateBookByAD ( 1, $receiptList [0] ['rid'] );
  6228. }
  6229. $data ['wbDetailLoan'] = $wbDetailLoan;
  6230. $data['inputDate']=date ( "Y-m-d H:i:s" );
  6231. //print_r($wbDetail);
  6232. if($receiptList[0]['version']==1){
  6233. require "protected/class/comm_cld.php";
  6234. $receiptList=makeReceiptDataVersion1($receiptList);
  6235. }
  6236. $data ['receiptList'] = $receiptList;
  6237. $data ['memu'] = "receipt";
  6238. $data ['staff'] = $this->staff;
  6239. $data ['receiptMemu'] = 'implement';
  6240. $data ['verifyId'] = $this->verifyId;
  6241. $data ['executeId'] = $this->executeId;
  6242. if($receiptList[0]['version']==1){
  6243. if ($Rtype=="loan"){
  6244. $this->render ( "/fee/implement/loan_compatible", $data );
  6245. }else{
  6246. $this->render ( "/fee/implement/receipt_compatible", $data );
  6247. }
  6248. die;
  6249. }
  6250. if ($Rtype=="loan"){
  6251. $this->render ( "/receipt/receiptImplementLoan", $data );
  6252. }elseif($Rtype=="receipt"){
  6253. if($receiptList[0]['receiptClass']==2){
  6254. //TODO 费用执行行程单2.0
  6255. if(!empty($receiptList[0]['itinerary2'])){
  6256. $this->render ( "/receipt/receiptImplementTrave2", $data );
  6257. }else{
  6258. $this->render ( "/receipt/receiptImplementTrave", $data );
  6259. }
  6260. }else{
  6261. $this->render ( "/receipt/receiptImplement", $data );
  6262. }
  6263. }elseif($Rtype=="public"){
  6264. $this->render ( "/receipt/receiptImplementPublic", $data );
  6265. }else{
  6266. //$this->render ( "/admin/implement", $data );
  6267. }
  6268. }
  6269. function implementDo() {
  6270. $rid = $this->get_args ( 'rid' ) ? $this->get_args ( 'rid' ) : "";
  6271. $implementOpinions = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  6272. // $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : '';
  6273. // $accountBank = $this->get_args ( 'accountBank' ) ? $this->get_args ( 'accountBank' ) : "";
  6274. // $ab = '';
  6275. // if ($accountBank == 'CGBDeposit')
  6276. // $ab = '纵横广发';
  6277. // elseif ($accountBank == 'ICBCDeposit')
  6278. // $ab = '纵横工行';
  6279. // elseif ($accountBank == 'HUADeposit')
  6280. // $ab = '华润银行';
  6281. // elseif ($accountBank == 'PersonalDeposit')
  6282. // $ab = '个人广发';
  6283. // if (empty ( $ab ))
  6284. // die ( 'illegal request--22' );
  6285. if (! empty ( $rid )) {
  6286. Doo::loadModel ( 'receipt' );
  6287. $receipt = new receipt ();
  6288. Doo::loadClass ( 'XDeode' );
  6289. $XDeode = new XDeode ( 5 );
  6290. $rid=$XDeode->decode($rid);
  6291. if (!is_numeric($rid)){
  6292. die;
  6293. }
  6294. // $rinfo = $receipt->getOne ( array (
  6295. // 'where' => 'rid=' . $rid,
  6296. // 'asArray' => true
  6297. // ) );
  6298. $rinfo = $receipt->getReceiptByRid ( $rid );
  6299. // $accountType = '';
  6300. // if ($rinfo ['Rtype'] == 1) {
  6301. // if ($rinfo ['loanRid'] != 0)//判断有问题
  6302. // $accountType = 2;
  6303. // else
  6304. // $accountType = 1;
  6305. // } elseif ($rinfo ['Rtype'] == 2) {
  6306. // $accountType = 4;
  6307. // } elseif ($rinfo ['Rtype'] == 0)
  6308. // $accountType = 3;
  6309. // if (empty ( $accountType ))
  6310. // die ( 'illegal request' );
  6311. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  6312. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  6313. if (empty ( $executeStaff )) {
  6314. $executeStaff = array (
  6315. $this->staff [0] ['sid'] => array (
  6316. 'date' => date ( 'Y-m-d' ),
  6317. 'opinion' => $implementOpinions,
  6318. 'status' => 1
  6319. )
  6320. );
  6321. } else {
  6322. $executeStaff [$this->staff [0] ['sid']] = array (
  6323. 'date' => date ( 'Y-m-d' ),
  6324. 'opinion' => $implementOpinions,
  6325. 'status' => 1
  6326. );
  6327. }
  6328. if (count ( $executeStaff ) == count ( $executeCopy )) {
  6329. $receipt->executeStaff = json_encode ( $executeStaff );
  6330. $receipt->status = 8;
  6331. if ($rinfo ['Rtype'] == 1 && $rinfo ['isBK'] == 1 && $rinfo ['status'] == 1)
  6332. $receipt->status = 9;
  6333. if ($rinfo ['status'] == 6) {
  6334. $receipt->loanDate = date ( "Y-m-d" );
  6335. }
  6336. $receipt->executeDate = date ( "Y-m-d" );
  6337. } else {
  6338. $receipt->executeStaff = json_encode ( $executeStaff );
  6339. }
  6340. //$receipt->amount = $amount;
  6341. $receipt->update ( array (
  6342. 'where' => 'rid=' . $rid
  6343. ) );
  6344. // 公司流水记录
  6345. // Doo::loadModel ( 'wasteBook' );
  6346. // $wasteBook = new wasteBook ();
  6347. // $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountType, $rid );
  6348. // // 银行
  6349. // if (empty ( $abDetail ) && ! empty ( $amount )) {
  6350. // $item = array (
  6351. // 'dataID' => $rid,
  6352. // 'expensesType' => 2,
  6353. // 'accountType' => $accountType,
  6354. // 'accountPriceShow' => $amount,
  6355. // 'accountPrice' => - $amount,
  6356. // 'accountBank' => $accountBank,
  6357. // 'category' => $rinfo ['category'] [0] ['title'],
  6358. // 'cid' => $rinfo ['category'] [0] ['cid'],
  6359. // 'name' => $rinfo ['staffDetail'] ['username'],
  6360. // 'sid' => $rinfo ['staffDetail'] ['sid'],
  6361. // 'inputDate' => date ( "Y-m-d H:i:s" )
  6362. // );
  6363. // $wasteBook->setAccountBookStatistics ( $item );
  6364. // }
  6365. }
  6366. //$ridKey = $XDeode->encode ( $rid );
  6367. return "/hisImplement";
  6368. // return "/implement/" . $ridKey . ".html";
  6369. }
  6370. function receiptburEdi() {
  6371. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  6372. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  6373. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  6374. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  6375. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  6376. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  6377. if (empty ( $status ))
  6378. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  6379. $vidList = array ();
  6380. $button = 0;
  6381. Doo::loadModel ( 'verify' );
  6382. Doo::loadModel ( 'receipt' );
  6383. Doo::loadModel ( 'staff' );
  6384. $staff = new staff ();
  6385. $receipt = new receipt ();
  6386. $verify = new verify ();
  6387. Doo::loadModel ( 'L_category' );
  6388. $Lcategory = new L_category ();
  6389. Doo::loadModel ( 'enclosur' );
  6390. $enclosur = new enclosur ();
  6391. Doo::loadModel ( 'loanReceipt' );
  6392. $loanReceipt = new loanReceipt ();
  6393. // user verify ID
  6394. $verifyDetail = $verify->find ( array (
  6395. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  6396. 'asArray' => true
  6397. ) );
  6398. foreach ( $verifyDetail as $key => $value ) {
  6399. array_push ( $vidList, $value ['vid'] );
  6400. }
  6401. $vid = implode ( ",", $vidList );
  6402. if (empty ( $verifyDetail ))
  6403. $vid = 0;
  6404. $categoryList = $Lcategory->find ( array (
  6405. 'asArray' => true
  6406. ) );
  6407. $staffList = $staff->find ( array (
  6408. 'where' => 'cid=' . $cid,
  6409. 'asArray' => true
  6410. ) );
  6411. $ap = "";
  6412. if ($status == 4) {
  6413. $ap = 4;
  6414. $status = 2;
  6415. }
  6416. // get Receipt By verifyID status 2
  6417. $receiptList = $receipt->find ( array (
  6418. 'where' => 'rid =' . $rid . ' and status=2',
  6419. 'desc' => 'rid',
  6420. 'asArray' => true
  6421. ) );
  6422. if (empty ( $receiptList )) {
  6423. die ( 'illegal request' );
  6424. }
  6425. $loanList = $loanReceipt->find ( array (
  6426. 'where' => 'rid=' . $receiptList [0] ['loanRid'],
  6427. 'desc' => 'rid',
  6428. 'asArray' => true
  6429. ) );
  6430. $data ['explanation'] = '';
  6431. if (! empty ( $loanList ))
  6432. $data ['explanation'] = $loanList [0] ['explanation'];
  6433. $Locate = 0;
  6434. $roleId = 0;
  6435. $button = 0;
  6436. foreach ( $loanList as $key => $value ) {
  6437. $loanList [$key] ['Locate'] = $Locate;
  6438. $Locate ++;
  6439. $loanList [$key] ['reviseDetail'] = array ();
  6440. if (! empty ( $value ['reviseDetail'] ))
  6441. $loanList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6442. $loanList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6443. $loanList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6444. $categoryDetil = $Lcategory->getOne ( array (
  6445. 'where' => 'cid=' . $value ['cid'],
  6446. 'asArray' => true
  6447. ) );
  6448. $loanList [$key] ['category'] = $categoryDetil ['title'];
  6449. // 检测编辑状态
  6450. $verifyList = $verify->getOne ( array (
  6451. 'where' => 'vid=' . $value ['verify'],
  6452. 'asArray' => true
  6453. ) );
  6454. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6455. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6456. Doo::loadModel ( 'role' );
  6457. $role = new role ();
  6458. $flag = true;
  6459. $roleKey = 0;
  6460. $endStaffArray = array ();
  6461. $roleArrayCopy = array ();
  6462. foreach ( $verifyList as $k => $v ) {
  6463. // init verifyStaff
  6464. if ($v [1] == 'ROLE') {
  6465. if (! empty ( $verifyStaff )) {
  6466. $endStaffArray = end ( $verifyStaff );
  6467. }
  6468. $roleVerify = json_decode ( $v [3], true );
  6469. $roleKey = $k;
  6470. $roleArray = array ();
  6471. $rolename = $role->getOne ( array (
  6472. 'where' => 'rid=' . $v [0],
  6473. 'asArray' => true
  6474. ) );
  6475. foreach ( $roleVerify as $o => $p ) {
  6476. $staffID = explode ( '_', $p );
  6477. $staffInfo = $staff->getOne ( array (
  6478. 'where' => 'sid=' . $staffID [0],
  6479. 'asArray' => true
  6480. ) );
  6481. // print_r($staffID);
  6482. $exp = array (
  6483. 0 => $staffInfo ['sid'],
  6484. 1 => $staffID [1],
  6485. 2 => $staffInfo ['avatar'],
  6486. 'date' => '',
  6487. 'date' => '',
  6488. 'opinion' => '',
  6489. 'status' => '',
  6490. 'rolename' => $rolename ['name']
  6491. );
  6492. array_push ( $roleArray, $exp );
  6493. }
  6494. $roleArrayCopy [$v [0]] = $roleArray;
  6495. // $verifyList[$k]['roleArray']=$roleArray;
  6496. }
  6497. $verifyList [$k] ['date'] = "";
  6498. $verifyList [$k] ['opinion'] = "";
  6499. $verifyList [$k] ['status'] = "";
  6500. if (empty ( $verifyStaff )) {
  6501. $verifyList [$k] ['date'] = "";
  6502. $verifyList [$k] ['opinion'] = "";
  6503. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6504. $verifyList [$k] ['status'] = 4;
  6505. $flag = false;
  6506. }
  6507. } else {
  6508. foreach ( $verifyStaff as $m => $u ) {
  6509. if ($v [0] == $m) {
  6510. $verifyList [$k] ['date'] = $u ['date'];
  6511. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6512. $verifyList [$k] ['status'] = $u ['status'];
  6513. $flag = false;
  6514. break;
  6515. }
  6516. }
  6517. $endStaffArray = end ( $verifyStaff );
  6518. if (isset ( $endStaffArray ['ROLE'] )) {
  6519. } else {
  6520. }
  6521. }
  6522. }
  6523. $rolename ['name'] = '';
  6524. if (! empty ( $roleId )) {
  6525. Doo::loadModel ( 'role' );
  6526. $role = new role ();
  6527. $rolename = $role->getOne ( array (
  6528. 'where' => 'rid=' . $roleId,
  6529. 'asArray' => true
  6530. ) );
  6531. }
  6532. if (! empty ( $verifyStaff ))
  6533. $endStaffArray = end ( $verifyStaff );
  6534. $KOP = false;
  6535. foreach ( $roleArrayCopy as $P => $A ) {
  6536. foreach ( $A as $MKI => $AVL ) {
  6537. if (! empty ( $verifyStaff )) {
  6538. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6539. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6540. $button = 4;
  6541. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6542. }
  6543. foreach ( $verifyStaff as $m => $u ) {
  6544. $AVLFK = $AVL [0] . '_R';
  6545. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6546. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6547. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6548. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6549. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6550. break;
  6551. }
  6552. }
  6553. } else {
  6554. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6555. $button = 4;
  6556. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6557. }
  6558. }
  6559. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6560. $KOP = true;
  6561. }
  6562. }
  6563. foreach ( $roleArrayCopy as $k => $v ) {
  6564. foreach ( $verifyList as $m => $n ) {
  6565. if ($n [0] == $k) {
  6566. array_splice ( $verifyList, $m, 1, $v );
  6567. }
  6568. }
  6569. }
  6570. $loanList [$key] ['verifyList'] = $verifyList;
  6571. }
  6572. $htmlLoan = '';
  6573. $data ['loanReceiptDate'] = '';
  6574. if (isset ( $loanList [0] )) {
  6575. foreach ( $loanList [0] ['verifyList'] as $key => $value ) {
  6576. if ($value ['status'] == 1)
  6577. $htmlLoan .= '<li class="done" >';
  6578. elseif ($value ['status'] == 3)
  6579. $htmlLoan .= '<li class="undone" >';
  6580. $htmlLoan .= '<div class="avtra"><img width="32" src="' . $value [2] . '_2.jpg"></div>';
  6581. $htmlLoan .= '<div class="comment"><p class="colGray">' . $value ['1'] . '<span class="fR">' . $value ['date'] . '</span>';
  6582. if (isset ( $value ['rolename'] ))
  6583. $htmlLoan .= $value ['rolename'];
  6584. $htmlLoan .= '</p><p>' . $value ['opinion'] . '</p></div></li>';
  6585. }
  6586. $data ['loanDate'] = $loanList [0] ['date'];
  6587. } else {
  6588. $data ['loanReceiptDate'] = ''; // $loanList [0] ['date'];
  6589. }
  6590. $data ['htmlLoan'] = $htmlLoan;
  6591. // $data ['LoanReceipt']=$loanList[0];
  6592. // print_r($loanList);
  6593. $Locate = 0;
  6594. $roleId = 0;
  6595. $button = 0;
  6596. if ($ap == 4)
  6597. $status = 4;
  6598. Doo::loadClass ( 'XDeode' );
  6599. $XDeode = new XDeode ( 5 );
  6600. foreach ( $receiptList as $key => $value ) {
  6601. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6602. $receiptList [$key] ['Locate'] = $Locate;
  6603. $Locate ++;
  6604. $receiptList [$key] ['reviseDetail'] = array ();
  6605. // 调整金额 代码调整
  6606. if (! empty ( $value ['reviseDetail'] )) {
  6607. $reviseDetail = json_decode ( $value ['reviseDetail'], true );
  6608. foreach ( $reviseDetail as $ry => $re ) {
  6609. $reviseDetail [$ry] ['sidKey'] = $XDeode->encode ( $re ['sid'] );
  6610. $reviseDetail [$ry] ['reviseKey'] = $XDeode->encode ( $ry );
  6611. }
  6612. $receiptList [$key] ['reviseDetail'] = $reviseDetail;
  6613. // print_r($reviseDetail);
  6614. }
  6615. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6616. $receiptList [$key] ['loanItem'] = json_decode ( $value ['loanItem'], true );
  6617. $categoryDetil = $Lcategory->getOne ( array (
  6618. 'where' => 'cid=' . $value ['cid'],
  6619. 'asArray' => true
  6620. ) );
  6621. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6622. // 检测编辑状态
  6623. $verifyList = $verify->getOne ( array (
  6624. 'where' => 'vid=' . $value ['verify'],
  6625. 'asArray' => true
  6626. ) );
  6627. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6628. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6629. Doo::loadModel ( 'role' );
  6630. $role = new role ();
  6631. // print_r($verifyList);
  6632. $flag = true;
  6633. $roleKey = 0;
  6634. $endStaffArray = array ();
  6635. $roleArrayCopy = array ();
  6636. foreach ( $verifyList as $k => $v ) {
  6637. // init verifyStaff
  6638. if ($v [1] == 'ROLE') {
  6639. if (! empty ( $verifyStaff )) {
  6640. $endStaffArray = end ( $verifyStaff );
  6641. if ($v [0] == $endStaffArray ['nextStaff']) {
  6642. $roleId = $v [0];
  6643. }
  6644. }
  6645. $roleVerify = json_decode ( $v [3], true );
  6646. $roleKey = $k;
  6647. $roleArray = array ();
  6648. $rolename = $role->getOne ( array (
  6649. 'where' => 'rid=' . $v [0],
  6650. 'asArray' => true
  6651. ) );
  6652. foreach ( $roleVerify as $o => $p ) {
  6653. $staffID = explode ( '_', $p );
  6654. $staffInfo = $staff->getOne ( array (
  6655. 'where' => 'sid=' . $staffID [0],
  6656. 'asArray' => true
  6657. ) );
  6658. // print_r($staffID);
  6659. $exp = array (
  6660. 0 => $staffInfo ['sid'],
  6661. 1 => $staffID [1],
  6662. 2 => $staffInfo ['avatar'],
  6663. 'date' => '',
  6664. 'date' => '',
  6665. 'opinion' => '',
  6666. 'status' => '',
  6667. 'rolename' => $rolename ['name']
  6668. );
  6669. array_push ( $roleArray, $exp );
  6670. }
  6671. $roleArrayCopy [$v [0]] = $roleArray;
  6672. // $verifyList[$k]['roleArray']=$roleArray;
  6673. }
  6674. // print_r($roleArray);
  6675. $verifyList [$k] ['date'] = "";
  6676. $verifyList [$k] ['opinion'] = "";
  6677. $verifyList [$k] ['status'] = "";
  6678. if (empty ( $verifyStaff )) {
  6679. $verifyList [$k] ['date'] = "";
  6680. $verifyList [$k] ['opinion'] = "";
  6681. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  6682. $verifyList [$k] ['status'] = 4;
  6683. $button = 4;
  6684. $flag = false;
  6685. }
  6686. } else {
  6687. foreach ( $verifyStaff as $m => $u ) {
  6688. if ($v [0] == $m) {
  6689. $verifyList [$k] ['date'] = $u ['date'];
  6690. $verifyList [$k] ['opinion'] = $u ['opinion'];
  6691. $verifyList [$k] ['status'] = $u ['status'];
  6692. $flag = false;
  6693. break;
  6694. }
  6695. }
  6696. $endStaffArray = end ( $verifyStaff );
  6697. if (isset ( $endStaffArray ['ROLE'] )) {
  6698. } else {
  6699. $endKey = key ( $verifyStaff );
  6700. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  6701. $button = 4;
  6702. $verifyList [$k] ['status'] = 4;
  6703. }
  6704. }
  6705. }
  6706. }
  6707. $rolename ['name'] = '';
  6708. if (! empty ( $roleId )) {
  6709. Doo::loadModel ( 'role' );
  6710. $role = new role ();
  6711. $rolename = $role->getOne ( array (
  6712. 'where' => 'rid=' . $roleId,
  6713. 'asArray' => true
  6714. ) );
  6715. }
  6716. if (! empty ( $verifyStaff ))
  6717. $endStaffArray = end ( $verifyStaff );
  6718. $KOP = false;
  6719. foreach ( $roleArrayCopy as $P => $A ) {
  6720. foreach ( $A as $MKI => $AVL ) {
  6721. if (! empty ( $verifyStaff )) {
  6722. // &&$rolename['rid']==$endStaffArray['nextStaff']
  6723. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  6724. $button = 4;
  6725. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6726. }
  6727. foreach ( $verifyStaff as $m => $u ) {
  6728. $AVLFK = $AVL [0] . '_R';
  6729. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  6730. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  6731. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  6732. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  6733. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  6734. break;
  6735. }
  6736. }
  6737. } else {
  6738. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  6739. $button = 4;
  6740. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  6741. }
  6742. }
  6743. // $roleArray[$MKI]['rolename']=$rolename['name'];
  6744. $KOP = true;
  6745. }
  6746. }
  6747. foreach ( $roleArrayCopy as $k => $v ) {
  6748. foreach ( $verifyList as $m => $n ) {
  6749. if ($n [0] == $k) {
  6750. array_splice ( $verifyList, $m, 1, $v );
  6751. }
  6752. }
  6753. }
  6754. // print_r($verifyList);
  6755. $receiptList [$key] ['verifyList'] = $verifyList;
  6756. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  6757. 'where' => 'sid=' . $value ['staff'],
  6758. 'asArray' => true
  6759. ) );
  6760. $receiptList [$key] ['button'] = $button;
  6761. $receiptList [$key] ['loanSumCN'] = $this->num_to_rmb ( $value ['loanSum'] );
  6762. $receiptList [$key] ['sumCN'] = $this->num_to_rmb ( $value ['sum'] );
  6763. $relust = bcsub ( $value ['sum'], $value ['loanSum'], 2 );
  6764. $receiptList [$key] ['relust'] = $relust;
  6765. $receiptList [$key] ['relustABS'] = abs ( $relust );
  6766. $receiptList [$key] ['relustCN'] = $this->num_to_rmb ( abs ( $relust ) );
  6767. }
  6768. //print_r($receiptList);die;
  6769. // $data['verifyDetail']=$verifyDetail;
  6770. $mothHtml = "";
  6771. for($i = 1; $i <= 12; $i ++) {
  6772. if ($month == $i)
  6773. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  6774. else
  6775. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  6776. }
  6777. // 获取审批日志
  6778. Doo::loadModel ( 'receiptLog' );
  6779. $receiptLog = new receiptLog ();
  6780. $rlList = array ();
  6781. $rlInfo = $receiptLog->getOne ( array (
  6782. 'where' => 'rid=' . $rid . ' and status=4',
  6783. 'asArray' => true
  6784. ) );
  6785. $tijdate = $receiptLog->getOne ( array (
  6786. 'where' => 'rid=' . $rid . ' and status=2',
  6787. 'asc' => 'rlid',
  6788. 'asArray' => true
  6789. ) );
  6790. if (! empty ( $rlInfo )) {
  6791. $rlList = $receiptLog->find ( array (
  6792. 'where' => 'rid=' . $rid,
  6793. 'asc' => 'rlid',
  6794. 'asArray' => true
  6795. ) );
  6796. }
  6797. // echo $rid;
  6798. // print_r($receiptList);
  6799. $receiptList [0] ['rlList'] = $rlList;
  6800. // print_r($receiptList);
  6801. $enclosurList = $enclosur->find ( array (
  6802. 'where' => 'rid=' . $rid,
  6803. 'asArray' => true
  6804. ) );
  6805. $enclosurHtml = '';
  6806. foreach ( $enclosurList as $value ) {
  6807. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  6808. }
  6809. $data ['enclosurHtml'] = $enclosurHtml;
  6810. $data ['rolename'] = $rolename ['name'];
  6811. $data ['mothHtml'] = $mothHtml;
  6812. $receiptList[0]['itinerary']=str_replace('\n','<br/>',$receiptList[0]['itinerary']);
  6813. if($receiptList[0]['version']==1){
  6814. require "protected/class/comm_cld.php";
  6815. $receiptList=makeReceiptDataVersion1($receiptList);
  6816. }
  6817. $data ['rid'] = $rid;
  6818. $data ['tijdate'] = $tijdate ['date'];
  6819. $data ['receiptList'] = $receiptList;
  6820. $data ['receiptApprovalCount'] = count ( $receiptList );
  6821. $data ['status'] = $status;
  6822. $data ['year'] = $year;
  6823. $data ['categoryList'] = $categoryList;
  6824. $data ['staffList'] = $staffList;
  6825. $data ['cid'] = $cid;
  6826. $data ['sid'] = $sid;
  6827. $data ['ap'] = $ap;
  6828. $data ['memu'] = "receipt";
  6829. $data ['staff'] = $this->staff;
  6830. $data ['receiptMemu'] = 'approvalExpenses';
  6831. $data ['verifyId'] = $this->verifyId;
  6832. $data ['executeId'] = $this->executeId;
  6833. if($receiptList[0]['version']==1){
  6834. $this->render ( "/fee/approval/receipt_compatible", $data );
  6835. die;
  6836. }
  6837. if($receiptList[0]['receiptClass']==1){
  6838. $this->render ( "/receipt/feeAgencyApproval", $data );
  6839. }elseif($receiptList[0]['receiptClass']==2){
  6840. //TODO 行程单2.0
  6841. if(!empty($receiptList[0]['itinerary2'])){
  6842. $this->render ( "/receipt/feeTraveApproval2", $data );
  6843. }else{
  6844. $this->render ( "/receipt/feeTraveApproval", $data );
  6845. }
  6846. }elseif($receiptList[0]['receiptClass']==3){
  6847. $this->render ( "/receipt/feeInternalTrainApproval", $data );
  6848. }else{
  6849. $this->render ( "/admin/receiptburEdi", $data );
  6850. }
  6851. }
  6852. function hisImplement() {
  6853. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  6854. if (empty ( $item ))
  6855. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "expenses";
  6856. $rdate = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  6857. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  6858. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : 'MONTH';
  6859. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  6860. $sop = $this->get_args ( 'sop' ) ? $this->get_args ( 'sop' ) : 'SOP';
  6861. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'pendImplement';
  6862. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : 'ALL';
  6863. $receiptOrder=$this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) :"";
  6864. Doo::loadClass ( 'XDeode' );
  6865. $XDeode = new XDeode ( 5 );
  6866. Doo::loadModel ( 'receipt' );
  6867. $receipt = new receipt ();
  6868. Doo::loadModel ( 'L_category' );
  6869. $Lcategory = new L_category ();
  6870. Doo::loadModel ( 'verify' );
  6871. Doo::loadModel ( 'statistics' );
  6872. $statistics = new statistics ();
  6873. $verify = new verify ();
  6874. Doo::loadModel ( 'staff' );
  6875. $staff = new staff ();
  6876. Doo::loadClass ( 'XDeode' );
  6877. $XDeode = new XDeode ( 5 );
  6878. $XDeode7 = new XDeode ( 7 );
  6879. $cid = $XDeode->decode ( $cidKey );
  6880. $condition = "";
  6881. if ($item == "expenses")
  6882. $condition = " and Rtype=1 ";
  6883. elseif ($item == "receipts")
  6884. $condition = " and Rtype=0 ";
  6885. elseif ($item == "remits")
  6886. $condition = " and Rtype=2 ";
  6887. elseif($item == "train")
  6888. $condition = " and Rtype=3 ";
  6889. $statusCon = '(status=8 or status=9 or status=1 or status=6 )';
  6890. $sopString = $cidString = "";
  6891. $lastYear = date ( "Y", strtotime ( "-1 year" ) );
  6892. if (empty ( $rdate ))
  6893. $dateCondition = " and (Year(date) =" . $year . " or Year(date) = " . $lastYear . ") ";
  6894. else
  6895. $dateCondition = " and date_format(date,'%Y-%m-%d')='" . $rdate . "' ";
  6896. if ($status == 'pendImplement') {
  6897. $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 ) ) ';
  6898. } elseif ($status == 'alerpts') {
  6899. $statusCon = '(status=8 or status=9 )';
  6900. if (empty ( $rdate )){
  6901. $dateCondition = " and Year(date) =" . $year;
  6902. }else{
  6903. $dateCondition = " and date_format(executeDate,'%Y-%m-%d')='" . $rdate . "' ";
  6904. }
  6905. }
  6906. if ($sop != 'SOP')
  6907. $sopString = " and staff=" . $sop;
  6908. if ($cidKey != 'ALL')
  6909. $cidString = " and cid=" . $cid;
  6910. //汇款信息需要提取出来
  6911. if(!empty($receiptOrder)){
  6912. $receiptList = $receipt->find ( array (
  6913. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6914. 'desc' => 'rid',
  6915. 'asArray' => true
  6916. ) );
  6917. // 员工筛选
  6918. $receiptList2 = $receipt->find ( array (
  6919. 'where' => $statusCon.' and receiptOrder like "%' . $receiptOrder . '%"',
  6920. 'desc' => 'rid',
  6921. 'asArray' => true
  6922. ) );
  6923. }else{
  6924. $receiptList = $receipt->find ( array (
  6925. 'where' => $statusCon . $condition . $dateCondition . $sopString . $cidString,
  6926. 'desc' => 'rid',
  6927. 'asArray' => true
  6928. ) );
  6929. // 员工筛选
  6930. $receiptList2 = $receipt->find ( array (
  6931. 'where' => $statusCon . $condition . $dateCondition,
  6932. 'desc' => 'rid',
  6933. 'asArray' => true
  6934. ) );
  6935. }
  6936. $sopStaff = array ();
  6937. foreach ( $receiptList2 as $key => $value ) {
  6938. $staffDetail = $staff->getOne ( array (
  6939. 'select' => 'username',
  6940. 'where' => 'sid=' . $value ['staff'],
  6941. 'asArray' => true
  6942. ) );
  6943. $sopStaff [$value ['staff']] = $staffDetail ['username'];
  6944. }
  6945. // 办事处筛选
  6946. $categoryScreen = array ();
  6947. $categorList = $Lcategory->getCategory ();
  6948. foreach ( $receiptList2 as $key => $value ) {
  6949. foreach ( $categorList as $k => $v ) {
  6950. if ($value ['cid'] == $v ['cid']) {
  6951. $categoryScreen [$v ['cidKey']] = $v ['title'];
  6952. break;
  6953. }
  6954. }
  6955. }
  6956. $categoryScreenHtml = "";
  6957. foreach ( $categoryScreen as $key => $value ) {
  6958. if ($cidKey == $key)
  6959. $categoryScreenHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  6960. else
  6961. $categoryScreenHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  6962. }
  6963. $data ['categoryScreenHtml'] = $categoryScreenHtml;
  6964. $data ['cidKey'] = $cidKey;
  6965. $Locate = 0;
  6966. $roleId = 0;
  6967. $button = 0;
  6968. $staffBatchNumber = 100001;
  6969. $remittanceList = array ();
  6970. foreach ( $receiptList as $key => $value ) {
  6971. $receiptList [$key] ['ridKey7'] = $XDeode7->encode ( $value ['rid'] );
  6972. $receiptList [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] );
  6973. $receiptList [$key] ['Texe'] = 'false';
  6974. if (strstr ( $value ['executeCopy'], '["' . $this->staff [0] ['sid'] . '"' ) != false) {
  6975. $receiptList [$key] ['Texe'] = 'true';
  6976. }
  6977. $receiptList [$key] ['TRexe'] = 'true';
  6978. if (strstr ( $value ['executeStaff'], '{"' . $this->staff [0] ['sid'] . '"' ) != false) {
  6979. $receiptList [$key] ['TRexe'] = 'false';
  6980. }
  6981. $receiptList [$key] ['Locate'] = $Locate;
  6982. $Locate ++;
  6983. $receiptList [$key] ['reviseDetail'] = array ();
  6984. if (! empty ( $value ['reviseDetail'] ))
  6985. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  6986. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  6987. $categoryDetil = $Lcategory->getOne ( array (
  6988. 'where' => 'cid=' . $value ['cid'],
  6989. 'asArray' => true
  6990. ) );
  6991. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  6992. // 检测编辑状态
  6993. $verifyList = $verify->getOne ( array (
  6994. 'where' => 'vid=' . $value ['verify'],
  6995. 'asArray' => true
  6996. ) );
  6997. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  6998. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  6999. Doo::loadModel ( 'role' );
  7000. $role = new role ();
  7001. $flag = true;
  7002. $roleKey = 0;
  7003. $endStaffArray = array ();
  7004. $roleArrayCopy = array ();
  7005. foreach ( $verifyList as $k => $v ) {
  7006. // init verifyStaff
  7007. if ($v [1] == 'ROLE') {
  7008. if (! empty ( $verifyStaff )) {
  7009. $endStaffArray = end ( $verifyStaff );
  7010. }
  7011. $roleVerify = json_decode ( $v [3], true );
  7012. $roleKey = $k;
  7013. $roleArray = array ();
  7014. $rolename = $role->getOne ( array (
  7015. 'where' => 'rid=' . $v [0],
  7016. 'asArray' => true
  7017. ) );
  7018. foreach ( $roleVerify as $o => $p ) {
  7019. $staffID = explode ( '_', $p );
  7020. $staffInfo = $staff->getOne ( array (
  7021. 'where' => 'sid=' . $staffID [0],
  7022. 'asArray' => true
  7023. ) );
  7024. $exp = array (
  7025. 0 => $staffInfo ['sid'],
  7026. 1 => $staffID [1],
  7027. 2 => $staffInfo ['avatar'],
  7028. 'date' => '',
  7029. 'date' => '',
  7030. 'opinion' => '',
  7031. 'status' => '',
  7032. 'rolename' => $rolename ['name']
  7033. );
  7034. array_push ( $roleArray, $exp );
  7035. }
  7036. $roleArrayCopy [$v [0]] = $roleArray;
  7037. }
  7038. $verifyList [$k] ['date'] = "";
  7039. $verifyList [$k] ['opinion'] = "";
  7040. $verifyList [$k] ['status'] = "";
  7041. if (empty ( $verifyStaff )) {
  7042. $verifyList [$k] ['date'] = "";
  7043. $verifyList [$k] ['opinion'] = "";
  7044. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7045. $verifyList [$k] ['status'] = 4;
  7046. $flag = false;
  7047. }
  7048. } else {
  7049. foreach ( $verifyStaff as $m => $u ) {
  7050. if ($v [0] == $m) {
  7051. $verifyList [$k] ['date'] = $u ['date'];
  7052. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7053. $verifyList [$k] ['status'] = $u ['status'];
  7054. $flag = false;
  7055. break;
  7056. }
  7057. }
  7058. $endStaffArray = end ( $verifyStaff );
  7059. }
  7060. }
  7061. $rolename ['name'] = '';
  7062. if (! empty ( $roleId )) {
  7063. Doo::loadModel ( 'role' );
  7064. $role = new role ();
  7065. $rolename = $role->getOne ( array (
  7066. 'where' => 'rid=' . $roleId,
  7067. 'asArray' => true
  7068. ) );
  7069. }
  7070. if (! empty ( $verifyStaff ))
  7071. $endStaffArray = end ( $verifyStaff );
  7072. $KOP = false;
  7073. foreach ( $roleArrayCopy as $P => $A ) {
  7074. foreach ( $A as $MKI => $AVL ) {
  7075. if (! empty ( $verifyStaff )) {
  7076. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7077. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7078. $button = 4;
  7079. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7080. }
  7081. foreach ( $verifyStaff as $m => $u ) {
  7082. $AVLFK = $AVL [0] . '_R';
  7083. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7084. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7085. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7086. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7087. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7088. break;
  7089. }
  7090. }
  7091. } else {
  7092. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7093. $button = 4;
  7094. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7095. }
  7096. }
  7097. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7098. $KOP = true;
  7099. }
  7100. }
  7101. foreach ( $roleArrayCopy as $k => $v ) {
  7102. foreach ( $verifyList as $m => $n ) {
  7103. if ($n [0] == $k) {
  7104. array_splice ( $verifyList, $m, 1, $v );
  7105. }
  7106. }
  7107. }
  7108. $receiptList [$key] ['verifyList'] = $verifyList;
  7109. $staffDetail = $staff->getOne ( array (
  7110. 'where' => 'sid=' . $value ['staff'],
  7111. 'asArray' => true
  7112. ) );
  7113. $receiptList [$key] ['staffDetail'] = $staffDetail;
  7114. $receiptList [$key] ['button'] = $button;
  7115. if ($value['Rtype']==1){
  7116. $receiptList [$key] ['relust'] = $value['sum']-$value['loanSum'];
  7117. $receiptList [$key] ['relustABS'] = sprintf("%.2f",abs($receiptList [$key] ['relust']));
  7118. }elseif($value['Rtype']==3){
  7119. // 收入合计
  7120. Doo::loadModel ( 'invoiceTraining' );
  7121. $invoiceTraining = new invoiceTraining ();
  7122. $invoiceTrainingDetail = array (
  7123. 'invoiceArriveAmount' => '0.00',
  7124. 'RIAmount' => '0.00',
  7125. 'invoiceTotalAmount' => '0.00',
  7126. 'invoiceCompanyAmount' => '0.00',
  7127. 'invoiceArriveAmountM'=>'0.00',
  7128. 'invoiceCompanyAmountM'=>'0.00'
  7129. );
  7130. if ($value ['invoiceTrainId'] != 0) {
  7131. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value['invoiceTrainId'] );
  7132. }
  7133. $invoiceArriveAmount = $RIAmount = 0;
  7134. if (! empty ( $invoiceTrainingDetail )) {
  7135. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  7136. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  7137. }
  7138. // 备用金
  7139. $sum = 0;
  7140. if (! empty ( $value ['trainLoanRid'] )) {
  7141. $receiptLoanList = $receipt->getReceiptInRid ( $value ['trainLoanRid'] );
  7142. foreach ($receiptLoanList as $kll=>$vll){
  7143. $sum+=$vll['sum'];
  7144. }
  7145. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $value ['trainLoanRid'] );
  7146. // $sum = $receiptLoanDetailBak ['sum'];
  7147. }
  7148. // 支出项金额详情
  7149. // 项目金额合计
  7150. Doo::loadModel ( 'RItem' );
  7151. $RItem = new RItem ();
  7152. Doo::loadModel ( 'accountItem' );
  7153. $accountItem = new accountItem ();
  7154. // 讲师获得
  7155. Doo::loadModel ( 'RILecturer' );
  7156. $RILecturer = new RILecturer ();
  7157. $RItemList = $RItem->getRItemByRid ( $value['rid'] );
  7158. $RILecturerList = $RILecturer->getRILecturerByRid ( $value['rid'] );
  7159. // 支出项金额详情
  7160. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  7161. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  7162. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  7163. $receiptList [$key] ['payment'] =$payment;
  7164. $receiptList [$key] ['paymentABS'] =sprintf("%.2f",abs($payment));
  7165. }
  7166. // 设置导出汇款execl
  7167. if (! empty ( $value ['remittanceName'] ) && ! empty ( $value ['bankName'] ) && ! empty ( $value ['bankNumber'] )) {
  7168. $remittanceDetail = array (
  7169. $staffBatchNumber,
  7170. $value ['remittanceName'],
  7171. $value ['bankNumber'],
  7172. $value ['bankName'],
  7173. $value ['remittanceBankType'],
  7174. $value ['coupletNumber'],
  7175. $value ['sum']
  7176. );
  7177. array_push ( $remittanceList, $remittanceDetail );
  7178. $staffBatchNumber ++;
  7179. }
  7180. }
  7181. $data ['remittanceList'] = json_encode ( $remittanceList );
  7182. // print_r($receiptList);
  7183. $mothHtml = "";
  7184. for($i = 1; $i <= 12; $i ++) {
  7185. if ($moth == $i)
  7186. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7187. else
  7188. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7189. }
  7190. $dayHtml = "";
  7191. if ($day != "DAY" || $moth != "MONTH") {
  7192. for($i = 1; $i <= 31; $i ++) {
  7193. if ($day == $i)
  7194. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  7195. else
  7196. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  7197. }
  7198. }
  7199. $sopHtml = "";
  7200. foreach ( $sopStaff as $key => $value ) {
  7201. if ($sop == $key)
  7202. $sopHtml .= '<option value="' . $key . '" selected >' . $value . '</option>';
  7203. else
  7204. $sopHtml .= '<option value="' . $key . '" >' . $value . '</option>';
  7205. }
  7206. $data ['status'] = $status;
  7207. $data ['rdate'] = $rdate;
  7208. $data ['sopHtml'] = $sopHtml;
  7209. $data ['dayHtml'] = $dayHtml;
  7210. $data ['mothHtml'] = $mothHtml;
  7211. $data ['receiptList'] = $receiptList;
  7212. $data ['memu'] = "receipt";
  7213. $data ['staff'] = $this->staff;
  7214. $data ['receiptMemu'] = 'implement';
  7215. $data ['verifyId'] = $this->verifyId;
  7216. $data ['executeId'] = $this->executeId;
  7217. $data ['item'] = $item;
  7218. $data ['year'] = $year;
  7219. $data ['moth'] = $moth;
  7220. $data['receiptOrder']=$receiptOrder;
  7221. $data ['day'] = $day;
  7222. $data ['sop'] = $sop;
  7223. $this->render ( "/admin/hisImplement", $data );
  7224. }
  7225. /**
  7226. * 导出汇款信息的exelc
  7227. */
  7228. function exportRemittance() {
  7229. $remittanceInfo = $_POST ['remittanceInfo']; // $this->get_args ( 'remittanceInfo' ) ? $this->get_args ( 'remittanceInfo' ) : '';
  7230. if (empty ( $remittanceInfo ))
  7231. die ( 'illegal request' );
  7232. $title = array (
  7233. '员工编号',
  7234. '姓名',
  7235. '员工账号',
  7236. '员工账户开户行',
  7237. '转账类型',
  7238. '联行号',
  7239. '金额'
  7240. );
  7241. $data = json_decode ( $remittanceInfo, true );
  7242. if (empty ( $data ))
  7243. die ( 'illegal request' );
  7244. Doo::loadClass ( 'receipt.func' );
  7245. exportExcel ( $title, $data, '批量日常报销-公司账号', './', true );
  7246. header ( 'Content-Type:text/html;charset=utf-8' );
  7247. die ( '导出' . count ( $data ) . '条数据,<a href="/hisImplement">返回</a>' );
  7248. }
  7249. function ajaxExamine() {
  7250. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  7251. Doo::loadModel ( 'receipt' );
  7252. $receipt = new receipt ();
  7253. if (! empty ( $rid )) {
  7254. $rLRes = $receipt->find ( array (
  7255. '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,
  7256. 'asArray' => true
  7257. ) );
  7258. if(!empty($rLRes)){
  7259. Doo::loadClass ( 'XDeode' );
  7260. $XDeode = new XDeode ( 7 );
  7261. $rLRes [0]['ridKey'] = $XDeode->encode( $rLRes [0]['rid'] );
  7262. echo json_encode ( array (
  7263. 'status' => 1,
  7264. 'receipt' => $rLRes [0]
  7265. ) );
  7266. die ();
  7267. }else{
  7268. echo json_encode ( array (
  7269. 'status' => 1,
  7270. 'receipt' => array ()
  7271. ) );
  7272. die ();
  7273. }
  7274. }
  7275. echo json_encode ( array (
  7276. 'status' => 0,
  7277. 'receipt' => array ()
  7278. ) );
  7279. die ();
  7280. }
  7281. /*
  7282. * 废弃
  7283. */
  7284. function myReceipt() {
  7285. // all approval past withdraw
  7286. $item = isset ( $this->params ['item'] ) ? $this->params ['item'] : "";
  7287. if (empty ( $item ))
  7288. $item = $this->get_args ( 'item' ) ? $this->get_args ( 'item' ) : "";
  7289. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  7290. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  7291. Doo::loadModel ( 'receipt' );
  7292. $receipt = new receipt ();
  7293. // pre-loaded
  7294. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  7295. // have cache
  7296. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . ".htmls";
  7297. if (! empty ( $moth )) // yearPage
  7298. $path = SITE_PATH . $this->MYREVEIPTCACHEPATH . $item . "_" . $year . "_" . $moth . ".htmls";
  7299. $this->showCache ( $path );
  7300. }
  7301. Doo::loadModel ( 'L_category' );
  7302. $Lcategory = new L_category ();
  7303. Doo::loadModel ( 'verify' );
  7304. Doo::loadModel ( 'statistics' );
  7305. $statistics = new statistics ();
  7306. $verify = new verify ();
  7307. Doo::loadModel ( 'staff' );
  7308. $staff = new staff ();
  7309. $condition = " and status!=0 ";
  7310. if ($item == "approval")
  7311. $condition = " and status=2 ";
  7312. elseif ($item == "withdraw")
  7313. $condition = " and status=3 ";
  7314. elseif ($item == "past")
  7315. $condition = " and status=1 ";
  7316. elseif ($item == "whdw")
  7317. $condition = " and status=4 ";
  7318. $dateCondition = " and Year(date) =" . $year;
  7319. if (! empty ( $moth )) {
  7320. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $moth;
  7321. $stList = $statistics->getOne ( array (
  7322. 'select' => 'rePrice ,agPrice',
  7323. 'where' => ' staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7324. 'asArray' => true
  7325. ) );
  7326. } else
  7327. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  7328. if (empty ( $stList ))
  7329. $stList = array (
  7330. 'rePrice' => 0,
  7331. 'agPrice' => 0
  7332. );
  7333. $noPassSum = $receipt->receiptByYear ( $year, $this->staff [0] ['sid'] );
  7334. $data ['stList'] = array (
  7335. 'rePrice' => $stList ['rePrice'],
  7336. 'agPrice' => $stList ['agPrice'],
  7337. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'] - $noPassSum ['sum'])
  7338. );
  7339. $receiptList = $receipt->find ( array (
  7340. 'where' => 'staff=' . $this->staff [0] ['sid'] . $condition . $dateCondition,
  7341. 'desc' => 'rid',
  7342. 'asArray' => true
  7343. ) );
  7344. $Locate = 0;
  7345. $roleId = 0;
  7346. $button = 0;
  7347. foreach ( $receiptList as $key => $value ) {
  7348. $receiptList [$key] ['Locate'] = $Locate;
  7349. $Locate ++;
  7350. $receiptList [$key] ['reviseDetail'] = array ();
  7351. if (! empty ( $value ['reviseDetail'] ))
  7352. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7353. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7354. $categoryDetil = $Lcategory->getOne ( array (
  7355. 'where' => 'cid=' . $value ['cid'],
  7356. 'asArray' => true
  7357. ) );
  7358. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7359. // 检测编辑状态
  7360. $verifyList = $verify->getOne ( array (
  7361. 'where' => 'vid=' . $value ['verify'],
  7362. 'asArray' => true
  7363. ) );
  7364. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7365. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7366. Doo::loadModel ( 'role' );
  7367. $role = new role ();
  7368. $flag = true;
  7369. $roleKey = 0;
  7370. $endStaffArray = array ();
  7371. $roleArrayCopy = array ();
  7372. foreach ( $verifyList as $k => $v ) {
  7373. // init verifyStaff
  7374. if ($v [1] == 'ROLE') {
  7375. if (! empty ( $verifyStaff )) {
  7376. $endStaffArray = end ( $verifyStaff );
  7377. // if ($v[0]==$endStaffArray['nextStaff']){
  7378. // $roleId=$v[0];
  7379. // }
  7380. }
  7381. $roleVerify = json_decode ( $v [3], true );
  7382. $roleKey = $k;
  7383. $roleArray = array ();
  7384. $rolename = $role->getOne ( array (
  7385. 'where' => 'rid=' . $v [0],
  7386. 'asArray' => true
  7387. ) );
  7388. foreach ( $roleVerify as $o => $p ) {
  7389. $staffID = explode ( '_', $p );
  7390. $staffInfo = $staff->getOne ( array (
  7391. 'where' => 'sid=' . $staffID [0],
  7392. 'asArray' => true
  7393. ) );
  7394. // print_r($staffID);
  7395. $exp = array (
  7396. 0 => $staffInfo ['sid'],
  7397. 1 => $staffID [1],
  7398. 2 => $staffInfo ['avatar'],
  7399. 'date' => '',
  7400. 'date' => '',
  7401. 'opinion' => '',
  7402. 'status' => '',
  7403. 'rolename' => $rolename ['name']
  7404. );
  7405. array_push ( $roleArray, $exp );
  7406. }
  7407. $roleArrayCopy [$v [0]] = $roleArray;
  7408. // $verifyList[$k]['roleArray']=$roleArray;
  7409. }
  7410. $verifyList [$k] ['date'] = "";
  7411. $verifyList [$k] ['opinion'] = "";
  7412. $verifyList [$k] ['status'] = "";
  7413. if (empty ( $verifyStaff )) {
  7414. $verifyList [$k] ['date'] = "";
  7415. $verifyList [$k] ['opinion'] = "";
  7416. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7417. $verifyList [$k] ['status'] = 4;
  7418. $flag = false;
  7419. }
  7420. } else {
  7421. foreach ( $verifyStaff as $m => $u ) {
  7422. if ($v [0] == $m) {
  7423. $verifyList [$k] ['date'] = $u ['date'];
  7424. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7425. $verifyList [$k] ['status'] = $u ['status'];
  7426. $flag = false;
  7427. break;
  7428. }
  7429. }
  7430. $endStaffArray = end ( $verifyStaff );
  7431. if (isset ( $endStaffArray ['ROLE'] )) {
  7432. } else {
  7433. // $endKey=key($verifyStaff);
  7434. // if ($v[0]==$endStaffArray['nextStaff']&&$endStaffArray['nextStaff']==$this->staff[0]['sid']){
  7435. // $button=4;
  7436. // $verifyList[$k]['status']=4;
  7437. // }
  7438. }
  7439. }
  7440. }
  7441. $rolename ['name'] = '';
  7442. if (! empty ( $roleId )) {
  7443. Doo::loadModel ( 'role' );
  7444. $role = new role ();
  7445. $rolename = $role->getOne ( array (
  7446. 'where' => 'rid=' . $roleId,
  7447. 'asArray' => true
  7448. ) );
  7449. }
  7450. if (! empty ( $verifyStaff ))
  7451. $endStaffArray = end ( $verifyStaff );
  7452. $KOP = false;
  7453. foreach ( $roleArrayCopy as $P => $A ) {
  7454. foreach ( $A as $MKI => $AVL ) {
  7455. if (! empty ( $verifyStaff )) {
  7456. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7457. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7458. $button = 4;
  7459. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7460. }
  7461. foreach ( $verifyStaff as $m => $u ) {
  7462. $AVLFK = $AVL [0] . '_R';
  7463. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7464. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7465. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7466. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7467. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7468. break;
  7469. }
  7470. }
  7471. } else {
  7472. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7473. $button = 4;
  7474. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7475. }
  7476. }
  7477. // $roleArray[$MKI]['rolename']=$rolename['name'];
  7478. $KOP = true;
  7479. }
  7480. }
  7481. foreach ( $roleArrayCopy as $k => $v ) {
  7482. foreach ( $verifyList as $m => $n ) {
  7483. if ($n [0] == $k) {
  7484. array_splice ( $verifyList, $m, 1, $v );
  7485. }
  7486. }
  7487. }
  7488. $receiptList [$key] ['verifyList'] = $verifyList;
  7489. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7490. 'where' => 'sid=' . $value ['staff'],
  7491. 'asArray' => true
  7492. ) );
  7493. $receiptList [$key] ['button'] = $button;
  7494. }
  7495. // print_r($receiptList);die;
  7496. $mothHtml = "";
  7497. for($i = 1; $i <= 12; $i ++) {
  7498. if ($moth == $i)
  7499. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7500. else
  7501. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7502. }
  7503. $data ['mothHtml'] = $mothHtml;
  7504. $data ['receiptList'] = $receiptList;
  7505. $data ['memu'] = "receipt";
  7506. $data ['staff'] = $this->staff;
  7507. $data ['receiptMemu'] = 'receipt';
  7508. $data ['verifyId'] = $this->verifyId;
  7509. $data ['executeId'] = $this->executeId;
  7510. $data ['item'] = $item;
  7511. $data ['year'] = $year;
  7512. if (! empty ( $item ) && ($item == "past" || $item == "withdraw")) {
  7513. // sufficient condition to generate cache
  7514. if (empty ( $moth ) && ($year < date ( "Y" ))) {
  7515. $receiptList = $receipt->find ( array (
  7516. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  7517. 'asArray' => true
  7518. ) );
  7519. if (empty ( $receiptList )) { // generated files
  7520. ob_start ();
  7521. $this->render ( "/admin/saea_myList", $data );
  7522. $this->cacheFile ( $path );
  7523. die ();
  7524. // $content = ob_get_contents();
  7525. // $fp = fopen($path, "w");
  7526. // fwrite($fp, $content);
  7527. // fclose($fp);
  7528. }
  7529. } elseif (! empty ( $moth ) && ($year <= date ( "Y" )) && ($moth < date ( "m" ))) {
  7530. $receiptList = $receipt->find ( array (
  7531. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $moth,
  7532. 'asArray' => true
  7533. ) );
  7534. if (empty ( $receiptList )) { // generated files
  7535. ob_start ();
  7536. $this->render ( "/admin/saea_myList", $data );
  7537. $this->cacheFile ( $path );
  7538. die ();
  7539. }
  7540. }
  7541. }
  7542. $this->render ( "/admin/saea_myList", $data );
  7543. }
  7544. function approvedReceipt() {
  7545. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7546. Doo::loadModel ( 'receipt' );
  7547. Doo::loadModel ( 'receiptDetail' );
  7548. $receipt = new receipt ();
  7549. $receiptDetail = new receiptDetail ();
  7550. Doo::loadModel ( 'statistics' );
  7551. Doo::loadModel ( 'itemStatistics' );
  7552. $statistics = new statistics ();
  7553. $itemStatistics = new itemStatistics ();
  7554. Doo::loadModel ( "verify" );
  7555. $verify = new verify ();
  7556. // 审批状态的判定
  7557. $receiptDetailList = $receipt->getOne ( array (
  7558. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and rid=' . $rid . ' and (status=4 or status=5 or status=7)',
  7559. 'asArray' => true
  7560. ) );
  7561. if (empty ( $receiptDetailList ))
  7562. return "/saeaBorad";
  7563. $verifyDetail = $verify->getOne ( array (
  7564. 'where' => ' vid =' . $receiptDetailList ['verify'],
  7565. 'asArray' => true
  7566. ) );
  7567. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  7568. if (empty ( $receiptDetailList ['nowStaff'] )) {
  7569. $nowStaff = "";
  7570. $nowStaffList = array ();
  7571. if ($verifyDetail [0] [1] == 'ROLE') {
  7572. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  7573. foreach ( $vStaffString as $key => $value ) {
  7574. $staffK = explode ( "_", $value );
  7575. array_push ( $nowStaffList, $staffK [0] );
  7576. }
  7577. $nowStaff = implode ( ',', $nowStaffList );
  7578. } else {
  7579. $nowStaff = $verifyDetail [0] [0];
  7580. }
  7581. $receipt->nowStaff = $nowStaff;
  7582. }
  7583. // echo $nowStaff;
  7584. // print_r($verifyDetail);die;
  7585. $receipt->rid = $receiptDetailList ['rid'];
  7586. $receipt->date = date ( "Y-m-d" );
  7587. $receipt->status = 2;
  7588. $receipt->update ();
  7589. $receiptDetail->status = 2;
  7590. $receiptDetail->update ( array (
  7591. 'where' => 'rid=' . $receiptDetailList ['rid']
  7592. ) );
  7593. Doo::loadModel ( "receiptLog" );
  7594. $receiptLog = new receiptLog ();
  7595. Doo::loadModel ( "verify" );
  7596. $verify = new verify ();
  7597. $receiptInfo = $receipt->getOne ( array (
  7598. 'where' => 'rid=' . $rid,
  7599. 'asArray' => true
  7600. ) );
  7601. $vr = $verify->getOne ( array (
  7602. 'where' => 'vid=' . $receiptInfo ['verify'],
  7603. 'asArray' => true
  7604. ) );
  7605. $jd = json_decode ( $vr ['staff'] );
  7606. $roleId = 0;
  7607. foreach ( $jd as $key => $value ) {
  7608. if ($value [1] == 'ROLE') {
  7609. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  7610. if ($pos !== false) {
  7611. $roleId = $value [0];
  7612. }
  7613. }
  7614. }
  7615. // 审批日志
  7616. // echo $roleId;die;
  7617. if (! empty ( $roleId )) {
  7618. Doo::loadModel ( "role" );
  7619. $role = new role ();
  7620. $roleInfo = $role->getOne ( array (
  7621. 'where' => 'rid=' . $roleId,
  7622. 'asArray' => true
  7623. ) );
  7624. // $receiptLog->rolename = $roleInfo ['name'];
  7625. }
  7626. $receiptLog->username = $this->staff [0] ['username'];
  7627. $receiptLog->uid = $this->staff [0] ['sid'];
  7628. $receiptLog->date = date ( "Y-m-d" );
  7629. $receiptLog->opinion = '提交审批';
  7630. $receiptLog->img = $this->staff [0] ['avatar'];
  7631. $receiptLog->status = 2;
  7632. $receiptLog->rid = $rid;
  7633. $receiptLog->insert ();
  7634. // statistics item
  7635. $dateArray = explode ( "-", $receiptDetailList ['date'] );
  7636. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  7637. $accountItem = json_decode ( $receiptDetailList ['accountItem'], true );
  7638. $stat = $statistics->getOne ( array (
  7639. 'where' => 'staff=' . $this->staff [0] ['sid'] . $dateCondition,
  7640. 'asArray' => true
  7641. ) );
  7642. if (empty ( $stat )) {
  7643. $statistics->date = date ( "Y-m-d" );
  7644. $statistics->cid = $this->staff [0] ['cid'];
  7645. $statistics->staff = $this->staff [0] ['sid'];
  7646. $statistics->agPrice = 0;
  7647. $statistics->rePrice = $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7648. $statistics->insert ();
  7649. } else {
  7650. $statistics->rePrice = $stat ['rePrice'] + $accountItem ['cSum'] ['agencySum'] + $accountItem ['cSum'] ['travelSum'] + $accountItem ['cSum'] ['trainSum'] + $accountItem ['cSum'] ['otherSum'];
  7651. $statistics->update ( array (
  7652. 'where' => 'sid=' . $stat ['sid']
  7653. ) );
  7654. }
  7655. return "/expenses";
  7656. }
  7657. function approval() {
  7658. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  7659. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7660. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7661. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7662. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7663. if (empty ( $status ))
  7664. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  7665. $vidList = array ();
  7666. $button = 0;
  7667. Doo::loadModel ( 'verify' );
  7668. $verify = new verify ();
  7669. Doo::loadModel ( 'receipt' );
  7670. $receipt = new receipt ();
  7671. Doo::loadModel ( 'staff' );
  7672. $staff = new staff ();
  7673. Doo::loadModel ( 'L_category' );
  7674. $Lcategory = new L_category ();
  7675. // user verify ID
  7676. $verifyDetail = $verify->find ( array (
  7677. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7678. 'asArray' => true
  7679. ) );
  7680. foreach ( $verifyDetail as $key => $value ) {
  7681. array_push ( $vidList, $value ['vid'] );
  7682. }
  7683. $vid = implode ( ",", $vidList );
  7684. if (empty ( $verifyDetail ))
  7685. $vid = 0;
  7686. /*
  7687. */
  7688. $dateCondition = " and Year(date) =" . $year;
  7689. if (! empty ( $month ))
  7690. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  7691. $categoryList = $Lcategory->find ( array (
  7692. 'asArray' => true
  7693. ) );
  7694. $staffList = $staff->find ( array (
  7695. 'where' => 'cid=' . $cid,
  7696. 'asArray' => true
  7697. ) );
  7698. $cateCondition = "";
  7699. $staffCondition = "";
  7700. $approvalCondition = "";
  7701. if (! empty ( $cid ))
  7702. $cateCondition = ' and cid=' . $cid;
  7703. if (! empty ( $sid )) {
  7704. $staffCondition = ' and staff=' . $sid;
  7705. $cateCondition = "";
  7706. }
  7707. // elseif($status==1){
  7708. // $approvalCondition=' and staff='.$this->staff[0]['sid'];
  7709. // }
  7710. if ($status == 2) {
  7711. // 查找角色审批人
  7712. $approvalCondition = ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' ) ';
  7713. }
  7714. $ap = "";
  7715. if ($status == 4) {
  7716. $ap = 4;
  7717. $status = 2;
  7718. $approvalCondition = ' and verifyStaff like "%\"' . $this->staff [0] ['sid'] . '\":{%" ';
  7719. }
  7720. if ($status == 5) {
  7721. $status = 4;
  7722. $ap = 5;
  7723. }
  7724. // echo $vid;
  7725. // get Receipt By verifyID status 2 .$approvalCondition
  7726. // $receiptList=$receipt->find(array('where'=>'verify in('.$vid.') and status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  7727. $receiptList = $receipt->find ( array (
  7728. 'where' => ' status=' . $status . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  7729. 'desc' => 'rid',
  7730. 'asArray' => true
  7731. ) );
  7732. // echo ' status='.$status.$dateCondition.$cateCondition.$staffCondition.$approvalCondition;
  7733. $Locate = 0;
  7734. if ($ap == 4)
  7735. $status = 4;
  7736. elseif ($ap == 5)
  7737. $status = 5;
  7738. foreach ( $receiptList as $key => $value ) {
  7739. $receiptList [$key] ['Locate'] = $Locate;
  7740. $Locate ++;
  7741. $receiptList [$key] ['reviseDetail'] = array ();
  7742. if (! empty ( $value ['reviseDetail'] ))
  7743. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7744. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7745. $categoryDetil = $Lcategory->getOne ( array (
  7746. 'where' => 'cid=' . $value ['cid'],
  7747. 'asArray' => true
  7748. ) );
  7749. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7750. $verifyList = $verify->getOne ( array (
  7751. 'where' => 'vid=' . $value ['verify'],
  7752. 'asArray' => true
  7753. ) );
  7754. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7755. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7756. foreach ( $verifyList as $k => $v ) {
  7757. // init verifyStaff
  7758. $verifyList [$k] ['date'] = "";
  7759. $verifyList [$k] ['opinion'] = "";
  7760. $verifyList [$k] ['status'] = "";
  7761. if (empty ( $verifyStaff )) {
  7762. $verifyList [$k] ['date'] = "";
  7763. $verifyList [$k] ['opinion'] = "";
  7764. if ($v [0] == $this->staff [0] ['sid']) {
  7765. $verifyList [$k] ['status'] = 4;
  7766. $button = 4;
  7767. }
  7768. } else {
  7769. $flag = true;
  7770. foreach ( $verifyStaff as $m => $u ) {
  7771. if ($v [0] == $m) {
  7772. $verifyList [$k] ['date'] = $u ['date'];
  7773. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7774. $verifyList [$k] ['status'] = $u ['status'];
  7775. $flag = false;
  7776. break;
  7777. }
  7778. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  7779. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  7780. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  7781. }
  7782. if ($flag) { // 检测可编辑
  7783. if ($v [0] == $this->staff [0] ['sid']) {
  7784. $verifyList [$k] ['status'] = 4;
  7785. $button = 4;
  7786. }
  7787. }
  7788. }
  7789. }
  7790. $receiptList [$key] ['verifyList'] = $verifyList;
  7791. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  7792. 'where' => 'sid=' . $value ['staff'],
  7793. 'asArray' => true
  7794. ) );
  7795. $receiptList [$key] ['button'] = $button;
  7796. }
  7797. // print_r($receiptList);die;
  7798. // $data['verifyDetail']=$verifyDetail;
  7799. $mothHtml = "";
  7800. for($i = 1; $i <= 12; $i ++) {
  7801. if ($month == $i)
  7802. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  7803. else
  7804. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  7805. }
  7806. $data ['mothHtml'] = $mothHtml;
  7807. $data ['receiptList'] = $receiptList;
  7808. $data ['receiptApprovalCount'] = count ( $receiptList );
  7809. $data ['status'] = $status;
  7810. $data ['year'] = $year;
  7811. $data ['categoryList'] = $categoryList;
  7812. $data ['staffList'] = $staffList;
  7813. $data ['cid'] = $cid;
  7814. $data ['sid'] = $sid;
  7815. $data ['ap'] = $ap;
  7816. $data ['memu'] = "receipt";
  7817. $data ['staff'] = $this->staff;
  7818. $data ['receiptMemu'] = 'approval';
  7819. $data ['verifyId'] = $this->verifyId;
  7820. $data ['executeId'] = $this->executeId;
  7821. $this->render ( "/admin/saea_reportList", $data );
  7822. }
  7823. function approvalDetails() {
  7824. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  7825. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  7826. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  7827. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  7828. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  7829. Doo::loadModel ( 'verify' );
  7830. $verify = new verify ();
  7831. Doo::loadModel ( 'receipt' );
  7832. $receipt = new receipt ();
  7833. Doo::loadModel ( 'staff' );
  7834. $staff = new staff ();
  7835. Doo::loadModel ( 'L_category' );
  7836. $Lcategory = new L_category ();
  7837. Doo::loadModel ( 'enclosur' );
  7838. $enclosur = new enclosur ();
  7839. $vidList = array ();
  7840. $verifyDetail = $verify->find ( array (
  7841. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  7842. 'asArray' => true
  7843. ) );
  7844. foreach ( $verifyDetail as $key => $value ) {
  7845. array_push ( $vidList, $value ['vid'] );
  7846. }
  7847. $vid = implode ( ",", $vidList );
  7848. if (empty ( $verifyDetail ))
  7849. $vid = 0;
  7850. $categoryList = $Lcategory->find ( array (
  7851. 'asArray' => true
  7852. ) );
  7853. $staffList = $staff->find ( array (
  7854. 'where' => 'cid=' . $cid,
  7855. 'asArray' => true
  7856. ) );
  7857. $ap = 0;
  7858. $receiptList = $receipt->find ( array (
  7859. 'where' => 'rid =' . $rid,
  7860. 'desc' => 'rid',
  7861. 'asArray' => true
  7862. ) );
  7863. $Locate = 0;
  7864. $roleId = 0;
  7865. $button = 0;
  7866. foreach ( $receiptList as $key => $value ) {
  7867. $receiptList [$key] ['Locate'] = $Locate;
  7868. $Locate ++;
  7869. $receiptList [$key] ['reviseDetail'] = array ();
  7870. if (! empty ( $value ['reviseDetail'] ))
  7871. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  7872. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  7873. $categoryDetil = $Lcategory->getOne ( array (
  7874. 'where' => 'cid=' . $value ['cid'],
  7875. 'asArray' => true
  7876. ) );
  7877. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  7878. // 检测编辑状态
  7879. $verifyList = $verify->getOne ( array (
  7880. 'where' => 'vid=' . $value ['verify'],
  7881. 'asArray' => true
  7882. ) );
  7883. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  7884. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  7885. Doo::loadModel ( 'role' );
  7886. $role = new role ();
  7887. // print_r($verifyList);
  7888. $flag = true;
  7889. $roleKey = 0;
  7890. $endStaffArray = array ();
  7891. $roleArrayCopy = array ();
  7892. foreach ( $verifyList as $k => $v ) {
  7893. // init verifyStaff
  7894. if ($v [1] == 'ROLE') {
  7895. if (! empty ( $verifyStaff )) {
  7896. $endStaffArray = end ( $verifyStaff );
  7897. if ($v [0] == $endStaffArray ['nextStaff']) {
  7898. $roleId = $v [0];
  7899. }
  7900. }
  7901. $roleVerify = json_decode ( $v [3], true );
  7902. $roleKey = $k;
  7903. $roleArray = array ();
  7904. $rolename = $role->getOne ( array (
  7905. 'where' => 'rid=' . $v [0],
  7906. 'asArray' => true
  7907. ) );
  7908. foreach ( $roleVerify as $o => $p ) {
  7909. $staffID = explode ( '_', $p );
  7910. $staffInfo = $staff->getOne ( array (
  7911. 'where' => 'sid=' . $staffID [0],
  7912. 'asArray' => true
  7913. ) );
  7914. // print_r($staffID);
  7915. $exp = array (
  7916. 0 => $staffInfo ['sid'],
  7917. 1 => $staffID [1],
  7918. 2 => $staffInfo ['avatar'],
  7919. 'date' => '',
  7920. 'date' => '',
  7921. 'opinion' => '',
  7922. 'status' => '',
  7923. 'rolename' => $rolename ['name']
  7924. );
  7925. array_push ( $roleArray, $exp );
  7926. }
  7927. $roleArrayCopy [$v [0]] = $roleArray;
  7928. // $verifyList[$k]['roleArray']=$roleArray;
  7929. }
  7930. // print_r($roleArray);
  7931. $verifyList [$k] ['date'] = "";
  7932. $verifyList [$k] ['opinion'] = "";
  7933. $verifyList [$k] ['status'] = "";
  7934. if (empty ( $verifyStaff )) {
  7935. $verifyList [$k] ['date'] = "";
  7936. $verifyList [$k] ['opinion'] = "";
  7937. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  7938. $verifyList [$k] ['status'] = 4;
  7939. $button = 4;
  7940. $flag = false;
  7941. }
  7942. } else {
  7943. foreach ( $verifyStaff as $m => $u ) {
  7944. if ($v [0] == $m) {
  7945. $verifyList [$k] ['date'] = $u ['date'];
  7946. $verifyList [$k] ['opinion'] = $u ['opinion'];
  7947. $verifyList [$k] ['status'] = $u ['status'];
  7948. $flag = false;
  7949. break;
  7950. }
  7951. }
  7952. $endStaffArray = end ( $verifyStaff );
  7953. if (isset ( $endStaffArray ['ROLE'] )) {
  7954. } else {
  7955. $endKey = key ( $verifyStaff );
  7956. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  7957. $button = 4;
  7958. $verifyList [$k] ['status'] = 4;
  7959. }
  7960. }
  7961. }
  7962. }
  7963. $rolename ['name'] = '';
  7964. if (! empty ( $roleId )) {
  7965. Doo::loadModel ( 'role' );
  7966. $role = new role ();
  7967. $rolename = $role->getOne ( array (
  7968. 'where' => 'rid=' . $roleId,
  7969. 'asArray' => true
  7970. ) );
  7971. }
  7972. if (! empty ( $verifyStaff ))
  7973. $endStaffArray = end ( $verifyStaff );
  7974. $KOP = false;
  7975. foreach ( $roleArrayCopy as $P => $A ) {
  7976. foreach ( $A as $MKI => $AVL ) {
  7977. if (! empty ( $verifyStaff )) {
  7978. // &&$rolename['rid']==$endStaffArray['nextStaff']
  7979. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  7980. $button = 4;
  7981. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7982. }
  7983. foreach ( $verifyStaff as $m => $u ) {
  7984. $AVLFK = $AVL [0] . '_R';
  7985. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  7986. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  7987. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  7988. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  7989. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  7990. break;
  7991. }
  7992. }
  7993. } else {
  7994. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  7995. $button = 4;
  7996. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  7997. }
  7998. }
  7999. // $roleArray[$MKI]['rolename']=$rolename['name'];
  8000. $KOP = true;
  8001. }
  8002. }
  8003. foreach ( $roleArrayCopy as $k => $v ) {
  8004. foreach ( $verifyList as $m => $n ) {
  8005. if ($n [0] == $k) {
  8006. array_splice ( $verifyList, $m, 1, $v );
  8007. }
  8008. }
  8009. }
  8010. $receiptList [$key] ['verifyList'] = $verifyList;
  8011. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  8012. 'where' => 'sid=' . $value ['staff'],
  8013. 'asArray' => true
  8014. ) );
  8015. $receiptList [$key] ['button'] = $button;
  8016. }
  8017. $mothHtml = "";
  8018. for($i = 1; $i <= 12; $i ++) {
  8019. if ($month == $i)
  8020. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8021. else
  8022. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8023. }
  8024. // 获取审批日志
  8025. Doo::loadModel ( 'receiptLog' );
  8026. $receiptLog = new receiptLog ();
  8027. $rlList = array ();
  8028. $rlInfo = $receiptLog->getOne ( array (
  8029. 'where' => 'rid=' . $rid . ' and status=4',
  8030. 'asArray' => true
  8031. ) );
  8032. $tijdate = $receiptLog->getOne ( array (
  8033. 'where' => 'rid=' . $rid . ' and status=2',
  8034. 'asc' => 'rlid',
  8035. 'asArray' => true
  8036. ) );
  8037. if (! empty ( $rlInfo )) {
  8038. $rlList = $receiptLog->find ( array (
  8039. 'where' => 'rid=' . $rid,
  8040. 'asc' => 'rlid',
  8041. 'asArray' => true
  8042. ) );
  8043. }
  8044. $receiptList [0] ['rlList'] = $rlList;
  8045. $enclosurList = $enclosur->find ( array (
  8046. 'where' => 'rid=' . $rid,
  8047. 'asArray' => true
  8048. ) );
  8049. $enclosurHtml = '';
  8050. foreach ( $enclosurList as $value ) {
  8051. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  8052. }
  8053. $data ['enclosurHtml'] = $enclosurHtml;
  8054. $data ['rolename'] = $rolename ['name'];
  8055. $data ['datetij'] = $tijdate ['date'];
  8056. $data ['mothHtml'] = $mothHtml;
  8057. $data ['receiptList'] = $receiptList;
  8058. $data ['receiptApprovalCount'] = count ( $receiptList );
  8059. $data ['year'] = $year;
  8060. $data ['categoryList'] = $categoryList;
  8061. $data ['staffList'] = $staffList;
  8062. $data ['cid'] = $cid;
  8063. $data ['sid'] = $sid;
  8064. $data ['status'] = 0;
  8065. if ($receiptList [0] ['status'] != 1 && $receiptList [0] ['status'] != 3) {
  8066. $ap = 4;
  8067. } else
  8068. $data ['status'] = $receiptList [0] ['status'];
  8069. if ($receiptList [0] ['status'] == 4) {
  8070. $data ['status'] = 5;
  8071. $ap = 0;
  8072. }
  8073. $data ['ap'] = $ap;
  8074. $data ['memu'] = "receipt";
  8075. $data ['staff'] = $this->staff;
  8076. $data ['receiptMemu'] = 'approval';
  8077. $data ['verifyId'] = $this->verifyId;
  8078. $data ['executeId'] = $this->executeId;
  8079. $this->render ( "/admin/saeaReportListReport", $data );
  8080. }
  8081. function approvalEdi() {
  8082. $rid = isset ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  8083. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : '';
  8084. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8085. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8086. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  8087. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  8088. if (empty ( $status ))
  8089. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 2;
  8090. $vidList = array ();
  8091. $button = 0;
  8092. Doo::loadModel ( 'verify' );
  8093. Doo::loadModel ( 'receipt' );
  8094. Doo::loadModel ( 'staff' );
  8095. $staff = new staff ();
  8096. $receipt = new receipt ();
  8097. $verify = new verify ();
  8098. Doo::loadModel ( 'L_category' );
  8099. $Lcategory = new L_category ();
  8100. Doo::loadModel ( 'enclosur' );
  8101. $enclosur = new enclosur ();
  8102. // user verify ID
  8103. $verifyDetail = $verify->find ( array (
  8104. 'where' => 'staff like "%\"' . $this->staff [0] ['sid'] . '%"',
  8105. 'asArray' => true
  8106. ) );
  8107. foreach ( $verifyDetail as $key => $value ) {
  8108. array_push ( $vidList, $value ['vid'] );
  8109. }
  8110. $vid = implode ( ",", $vidList );
  8111. if (empty ( $verifyDetail ))
  8112. $vid = 0;
  8113. $categoryList = $Lcategory->find ( array (
  8114. 'asArray' => true
  8115. ) );
  8116. $staffList = $staff->find ( array (
  8117. 'where' => 'cid=' . $cid,
  8118. 'asArray' => true
  8119. ) );
  8120. $ap = "";
  8121. if ($status == 4) {
  8122. $ap = 4;
  8123. $status = 2;
  8124. }
  8125. // get Receipt By verifyID status 2
  8126. $receiptList = $receipt->find ( array (
  8127. 'where' => 'rid =' . $rid,
  8128. 'desc' => 'rid',
  8129. 'asArray' => true
  8130. ) );
  8131. $Locate = 0;
  8132. $roleId = 0;
  8133. if ($ap == 4)
  8134. $status = 4;
  8135. foreach ( $receiptList as $key => $value ) {
  8136. $receiptList [$key] ['Locate'] = $Locate;
  8137. $Locate ++;
  8138. $receiptList [$key] ['reviseDetail'] = array ();
  8139. if (! empty ( $value ['reviseDetail'] ))
  8140. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  8141. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  8142. $categoryDetil = $Lcategory->getOne ( array (
  8143. 'where' => 'cid=' . $value ['cid'],
  8144. 'asArray' => true
  8145. ) );
  8146. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  8147. // 检测编辑状态
  8148. $verifyList = $verify->getOne ( array (
  8149. 'where' => 'vid=' . $value ['verify'],
  8150. 'asArray' => true
  8151. ) );
  8152. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  8153. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  8154. // print_r($verifyList);
  8155. //
  8156. // if (empty($verifyStaff)){
  8157. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  8158. // $verifyList[0]['status']=4;$button=4;
  8159. // }
  8160. //
  8161. // }else{
  8162. //
  8163. // }
  8164. // die;
  8165. // $a=array("a"=>"red","b"=>"green","c"=>"blue");
  8166. // echo array_search("green",$a);
  8167. //
  8168. Doo::loadModel ( 'role' );
  8169. $role = new role ();
  8170. // print_r($verifyList);
  8171. $flag = true;
  8172. $roleKey = 0;
  8173. $endStaffArray = array ();
  8174. $roleArrayCopy = array ();
  8175. foreach ( $verifyList as $k => $v ) {
  8176. // init verifyStaff
  8177. if ($v [1] == 'ROLE') {
  8178. if (! empty ( $verifyStaff )) {
  8179. $endStaffArray = end ( $verifyStaff );
  8180. if ($v [0] == $endStaffArray ['nextStaff']) {
  8181. $roleId = $v [0];
  8182. }
  8183. }
  8184. $roleVerify = json_decode ( $v [3], true );
  8185. $roleKey = $k;
  8186. $roleArray = array ();
  8187. $rolename = $role->getOne ( array (
  8188. 'where' => 'rid=' . $v [0],
  8189. 'asArray' => true
  8190. ) );
  8191. foreach ( $roleVerify as $o => $p ) {
  8192. $staffID = explode ( '_', $p );
  8193. $staffInfo = $staff->getOne ( array (
  8194. 'where' => 'sid=' . $staffID [0],
  8195. 'asArray' => true
  8196. ) );
  8197. // print_r($staffID);
  8198. $exp = array (
  8199. 0 => $staffInfo ['sid'],
  8200. 1 => $staffID [1],
  8201. 2 => $staffInfo ['avatar'],
  8202. 'date' => '',
  8203. 'date' => '',
  8204. 'opinion' => '',
  8205. 'status' => '',
  8206. 'rolename' => $rolename ['name']
  8207. );
  8208. array_push ( $roleArray, $exp );
  8209. }
  8210. $roleArrayCopy [$v [0]] = $roleArray;
  8211. // $verifyList[$k]['roleArray']=$roleArray;
  8212. }
  8213. // print_r($roleArray);
  8214. $verifyList [$k] ['date'] = "";
  8215. $verifyList [$k] ['opinion'] = "";
  8216. $verifyList [$k] ['status'] = "";
  8217. if (empty ( $verifyStaff )) {
  8218. $verifyList [$k] ['date'] = "";
  8219. $verifyList [$k] ['opinion'] = "";
  8220. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  8221. $verifyList [$k] ['status'] = 4;
  8222. $button = 4;
  8223. $flag = false;
  8224. }
  8225. } else {
  8226. foreach ( $verifyStaff as $m => $u ) {
  8227. if ($v [0] == $m) {
  8228. $verifyList [$k] ['date'] = $u ['date'];
  8229. $verifyList [$k] ['opinion'] = $u ['opinion'];
  8230. $verifyList [$k] ['status'] = $u ['status'];
  8231. $flag = false;
  8232. break;
  8233. }
  8234. }
  8235. $endStaffArray = end ( $verifyStaff );
  8236. if (isset ( $endStaffArray ['ROLE'] )) {
  8237. } else {
  8238. $endKey = key ( $verifyStaff );
  8239. if ($v [0] == $endStaffArray ['nextStaff'] && $endStaffArray ['nextStaff'] == $this->staff [0] ['sid']) {
  8240. $button = 4;
  8241. $verifyList [$k] ['status'] = 4;
  8242. }
  8243. }
  8244. // print_r($endStaffArray);die;
  8245. // if (empty($verifyStaff)){
  8246. // if ($this->staff[0]['sid']==$verifyStaff[0][0]){
  8247. // $verifyList[$k]['status']=4;$button=4;
  8248. // }
  8249. //
  8250. // }else{
  8251. //
  8252. // }
  8253. // if($flag){//检测可编辑
  8254. // if($v[0]==$this->staff[0]['sid']){
  8255. // $verifyList[$k]['status']=4;$button=4;
  8256. // }
  8257. // }
  8258. }
  8259. }
  8260. $rolename ['name'] = '';
  8261. if (! empty ( $roleId )) {
  8262. Doo::loadModel ( 'role' );
  8263. $role = new role ();
  8264. $rolename = $role->getOne ( array (
  8265. 'where' => 'rid=' . $roleId,
  8266. 'asArray' => true
  8267. ) );
  8268. }
  8269. if (! empty ( $verifyStaff ))
  8270. $endStaffArray = end ( $verifyStaff );
  8271. $KOP = false;
  8272. foreach ( $roleArrayCopy as $P => $A ) {
  8273. foreach ( $A as $MKI => $AVL ) {
  8274. if (! empty ( $verifyStaff )) {
  8275. // &&$rolename['rid']==$endStaffArray['nextStaff']
  8276. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  8277. $button = 4;
  8278. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  8279. }
  8280. foreach ( $verifyStaff as $m => $u ) {
  8281. $AVLFK = $AVL [0] . '_R';
  8282. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  8283. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  8284. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  8285. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  8286. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  8287. break;
  8288. }
  8289. }
  8290. } else {
  8291. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  8292. $button = 4;
  8293. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  8294. }
  8295. }
  8296. // $roleArray[$MKI]['rolename']=$rolename['name'];
  8297. $KOP = true;
  8298. }
  8299. }
  8300. // print_r($roleArrayCopy);
  8301. // echo $roleKey;
  8302. foreach ( $roleArrayCopy as $k => $v ) {
  8303. foreach ( $verifyList as $m => $n ) {
  8304. if ($n [0] == $k) {
  8305. array_splice ( $verifyList, $m, 1, $v );
  8306. }
  8307. }
  8308. }
  8309. // if ($KOP)
  8310. // array_splice($verifyList,$roleKey,1,$roleArray);
  8311. // print_r($verifyList);
  8312. $receiptList [$key] ['verifyList'] = $verifyList;
  8313. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  8314. 'where' => 'sid=' . $value ['staff'],
  8315. 'asArray' => true
  8316. ) );
  8317. $receiptList [$key] ['button'] = $button;
  8318. }
  8319. // $data['verifyDetail']=$verifyDetail;
  8320. $mothHtml = "";
  8321. for($i = 1; $i <= 12; $i ++) {
  8322. if ($month == $i)
  8323. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8324. else
  8325. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8326. }
  8327. // 获取审批日志
  8328. Doo::loadModel ( 'receiptLog' );
  8329. $receiptLog = new receiptLog ();
  8330. $rlList = array ();
  8331. $rlInfo = $receiptLog->getOne ( array (
  8332. 'where' => 'rid=' . $rid . ' and status=4',
  8333. 'asArray' => true
  8334. ) );
  8335. $tijdate = $receiptLog->getOne ( array (
  8336. 'where' => 'rid=' . $rid . ' and status=2',
  8337. 'asc' => 'rlid',
  8338. 'asArray' => true
  8339. ) );
  8340. if (! empty ( $rlInfo )) {
  8341. $rlList = $receiptLog->find ( array (
  8342. 'where' => 'rid=' . $rid,
  8343. 'asc' => 'rlid',
  8344. 'asArray' => true
  8345. ) );
  8346. }
  8347. $receiptList [0] ['rlList'] = $rlList;
  8348. $enclosurList = $enclosur->find ( array (
  8349. 'where' => 'rid=' . $rid,
  8350. 'asArray' => true
  8351. ) );
  8352. $enclosurHtml = '';
  8353. foreach ( $enclosurList as $value ) {
  8354. $enclosurHtml .= '<a href="/upload/swfupload/' . $value ['name'] . '" class="sFile" target="_blank">' . $value ['name'] . '</a>';
  8355. }
  8356. $data ['enclosurHtml'] = $enclosurHtml;
  8357. $data ['rolename'] = $rolename ['name'];
  8358. $data ['datetij'] = $tijdate ['date'];
  8359. $data ['mothHtml'] = $mothHtml;
  8360. $data ['receiptList'] = $receiptList;
  8361. $data ['receiptApprovalCount'] = count ( $receiptList );
  8362. $data ['status'] = $status;
  8363. $data ['year'] = $year;
  8364. $data ['categoryList'] = $categoryList;
  8365. $data ['staffList'] = $staffList;
  8366. $data ['cid'] = $cid;
  8367. $data ['sid'] = $sid;
  8368. $data ['ap'] = $ap;
  8369. $data ['memu'] = "receipt";
  8370. $data ['staff'] = $this->staff;
  8371. $data ['receiptMemu'] = 'approval';
  8372. $data ['verifyId'] = $this->verifyId;
  8373. $data ['executeId'] = $this->executeId;
  8374. $this->render ( "/admin/saeaReportListReport", $data );
  8375. }
  8376. function remittanceHky() {
  8377. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  8378. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : date ( "m" );
  8379. $day = $this->get_args ( 'day' ) ? $this->get_args ( 'day' ) : 'DAY';
  8380. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  8381. $page_size = 15;
  8382. $get = "?year=" . $year . "&moth=" . $moth . "&day=" . $day;
  8383. Doo::loadModel ( 'receipt' );
  8384. $receipt = new receipt ();
  8385. Doo::loadModel ( 'staff' );
  8386. $staff = new staff ();
  8387. $dateCondition = " and Year(executeDate) =" . $year;
  8388. if ($moth != 'MONTH')
  8389. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth;
  8390. if ($day != 'DAY' && $moth != 'MONTH')
  8391. $dateCondition = " and Year(executeDate) =" . $year . " and Month(executeDate) = " . $moth . " and day(executeDate)=" . $day;
  8392. $sql = ' (status =8 or status=9 ) and amount>0 ' . $dateCondition;
  8393. $table = '(SELECT count(*) FROM CLD_receipt WHERE ' . $sql . ' group by executeDate ) a ';
  8394. $pageinfo = $this->get_page ( $table, ' ', $page, $page_size, "remittanceHky", $get, "" );
  8395. $limit = $pageinfo ['lower'] . ',' . $page_size;
  8396. $dayList = $receipt->find ( array (
  8397. 'select' => 'executeDate,sum(amount) as amount',
  8398. 'where' => $sql,
  8399. 'desc' => 'executeDate',
  8400. 'groupby' => 'executeDate',
  8401. 'limit' => $limit,
  8402. 'asArray' => true
  8403. ) );
  8404. // print_r($dayList);
  8405. foreach ( $dayList as $key => $value ) {
  8406. $remitString = "";
  8407. $receiptList = $receipt->find ( array (
  8408. 'select' => 'rid,executeDate,amount,staff,cid',
  8409. 'where' => '(status =8 or status=9 ) and amount!=0 and executeDate="' . $value ['executeDate'] . '"',
  8410. 'desc' => 'executeDate',
  8411. 'asArray' => true
  8412. ) );
  8413. foreach ( $receiptList as $k => $v ) {
  8414. $sinfo = $staff->getOne ( array (
  8415. 'select' => 'username,category',
  8416. 'where' => ' sid=' . $v ['staff'],
  8417. 'asArray' => true
  8418. ) );
  8419. $remitString .= $sinfo ['category'] . '-' . $sinfo ['username'] . '(' . $v ['amount'] . ')&nbsp;&nbsp;';
  8420. }
  8421. $dayList [$key] ['staff'] = $remitString;
  8422. $dayList [$key] ['ridKey'] = strtotime ( $value ['executeDate'] );
  8423. }
  8424. // print_r($dayList);
  8425. $mothHtml = "";
  8426. for($i = 1; $i <= 12; $i ++) {
  8427. if ($moth == $i)
  8428. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8429. else
  8430. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8431. }
  8432. $dayHtml = "";
  8433. if ($day != "DAY" || $moth != "MONTH") {
  8434. for($i = 1; $i <= 31; $i ++) {
  8435. if ($day == $i)
  8436. $dayHtml .= '<option value="' . $i . '" selected >' . $i . '日</option>';
  8437. else
  8438. $dayHtml .= '<option value="' . $i . '" >' . $i . '日</option>';
  8439. }
  8440. }
  8441. $dateHtml = "";
  8442. $now = date ( "Y" );
  8443. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  8444. if ($YEARD <= $now) {
  8445. $dateHtml .= '<option ';
  8446. if ($year == $YEARD) {
  8447. $dateHtml .= 'selected ';
  8448. }
  8449. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  8450. }
  8451. }
  8452. $data ['dateHtml'] = $dateHtml;
  8453. $data ['page'] = $pageinfo;
  8454. $data ['year'] = $year;
  8455. $data ['moth'] = $moth;
  8456. $data ['day'] = $day;
  8457. $data ['get'] = $get;
  8458. $data ['dayHtml'] = $dayHtml;
  8459. $data ['mothHtml'] = $mothHtml;
  8460. $data ['receiptList'] = $dayList;
  8461. $data ['memu'] = "receipt";
  8462. $data ['staff'] = $this->staff;
  8463. $data ['receiptMemu'] = 'remittanceHky';
  8464. $data ['verifyId'] = $this->verifyId;
  8465. $data ['executeId'] = $this->executeId;
  8466. $this->render ( "/admin/remittanceHky", $data );
  8467. }
  8468. function remittancep() {
  8469. $timeStamp = isset ( $this->params ['timeStamp'] ) && is_numeric ( $this->params ['timeStamp'] ) ? $this->params ['timeStamp'] : 0;
  8470. Doo::loadModel ( 'receipt' );
  8471. $receipt = new receipt ();
  8472. Doo::loadModel ( 'staff' );
  8473. $staff = new staff ();
  8474. Doo::loadClass ( 'XDeode' );
  8475. $XDeode = new XDeode ( 5 );
  8476. $dateCondition = ' and executeDate="' . date ( 'Y-m-d', $timeStamp ) . '"';
  8477. $rplist = $receipt->find ( array (
  8478. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8479. 'asArray' => true
  8480. ) );
  8481. $dayList = $receipt->find ( array (
  8482. 'where' => ' (status =8 or status=9 ) and amount!=0 ' . $dateCondition,
  8483. 'desc' => 'executeDate',
  8484. 'groupby' => 'staff',
  8485. 'asArray' => true
  8486. ) );
  8487. $html = '';
  8488. foreach ( $dayList as $key => $value ) {
  8489. $sinfo = $staff->getOne ( array (
  8490. 'select' => 'username,category',
  8491. 'where' => ' sid=' . $value ['staff'],
  8492. 'asArray' => true
  8493. ) );
  8494. $html .= '<table class="table table-bordered table-condensed"><thead><tr><th class="taC" colspan="3">' . $sinfo ['category'] . '-' . $sinfo ['username'] . '</th></tr></thead><tbody>
  8495. <tr><td class="taC">费用单号</td><td class="taC">汇款金额</td></tr>';
  8496. $au = 0;
  8497. foreach ( $rplist as $k => $v ) {
  8498. if ($value ['staff'] == $v ['staff']) {
  8499. $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>';
  8500. $au += $v ['amount'];
  8501. }
  8502. }
  8503. $html .= '<tr><td>合计</td><td class="taR"><b>¥' . $au . '</b></td></tr></tbody></table>';
  8504. }
  8505. $data ['html'] = $html;
  8506. $data ['memu'] = "receipt";
  8507. $data ['staff'] = $this->staff;
  8508. $data ['receiptMemu'] = 'remittanceHky';
  8509. $data ['verifyId'] = $this->verifyId;
  8510. $data ['executeId'] = $this->executeId;
  8511. $this->render ( "/admin/remittancep", $data );
  8512. }
  8513. function ajaxGetReceiptDetails() {
  8514. $rid = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  8515. Doo::loadClass ( 'XDeode' );
  8516. $XDeode = new XDeode ( 5 );
  8517. $rid = $XDeode->decode ( $rid );
  8518. if (empty ( $rid )) {
  8519. echo json_encode ( array (
  8520. 'status' => 2,
  8521. 'msg' => 'illegal request'
  8522. ) );
  8523. die ();
  8524. }
  8525. Doo::loadModel ( 'receipt' );
  8526. $receipt = new receipt ();
  8527. Doo::loadModel ( 'staff' );
  8528. $staff = new staff ();
  8529. $rinfo = $receipt->getOne ( array (
  8530. 'where' => 'rid= ' . $rid,
  8531. 'asArray' => true
  8532. ) );
  8533. $sinfo = $staff->getOne ( array (
  8534. 'select' => 'username,category',
  8535. 'where' => ' sid=' . $rinfo ['staff'],
  8536. 'asArray' => true
  8537. ) );
  8538. $rinfo ['reviseDetail'] = array ();
  8539. if (! empty ( $rinfo ['reviseDetail'] ))
  8540. $rinfo ['reviseDetail'] = json_decode ( $rinfo ['reviseDetail'], true );
  8541. $rinfo ['accountItem'] = json_decode ( $rinfo ['accountItem'], true );
  8542. $rinfo ['loanItem'] = json_decode ( $rinfo ['loanItem'], true );
  8543. $rinfo ['category'] = $sinfo ['category'];
  8544. $verifyStaff = array ();
  8545. if (! empty ( $rinfo ['verifyStaff'] ))
  8546. $verifyStaff = json_decode ( $rinfo ['verifyStaff'], true );
  8547. $relust = bcsub ( $rinfo ['sum'], $rinfo ['loanSum'], 2 );
  8548. $rinfo ['relust'] = $relust;
  8549. $rinfo ['relustCN'] = $this->num_to_rmb ( $relust );
  8550. $rinfo ['sumCN'] = $this->num_to_rmb ( $rinfo ['sum'] );
  8551. $rinfo ['loanSumCN'] = $this->num_to_rmb ( $rinfo ['loanSum'] );
  8552. $rinfo ['amountCN'] = $this->num_to_rmb ( $rinfo ['amount'] );
  8553. // 费用执行人相关数据
  8554. $executeCopy = json_decode ( $rinfo ['executeCopy'], true );
  8555. $executeStaff = json_decode ( $rinfo ['executeStaff'], true );
  8556. foreach ( $executeCopy as $k => $v ) {
  8557. $executeCopy [$k] ['date'] = '';
  8558. $executeCopy [$k] ['opinion'] = '';
  8559. $executeCopy [$k] ['status'] = '';
  8560. if (! empty ( $executeStaff ))
  8561. foreach ( $executeStaff as $m => $u ) {
  8562. if ($v [0] == $m) {
  8563. $executeCopy [$k] ['date'] = $u ['date'];
  8564. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  8565. $executeCopy [$k] ['status'] = $u ['status'];
  8566. break;
  8567. }
  8568. }
  8569. }
  8570. $rinfo ['executeCopy'] = $executeCopy;
  8571. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>费用详情</h3></div><div class="modal-body saeaList">';
  8572. if ($rinfo ['Rtype'] == 1) { // 借款费用
  8573. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8574. <tr><th colspan="2" class="taC">借款费用</th></tr>';
  8575. foreach ( $rinfo ['loanItem'] ['借款费用'] as $value ) {
  8576. $html .= '<tr><th>' . $value ['name'] . '</th>
  8577. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8578. }
  8579. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8580. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8581. <tr><th class="taC" colspan="2">费用说明</th>
  8582. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8583. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8584. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['loanSum'] . '</b><br>' . $rinfo ['loanSumCN'] . '</td></tr>
  8585. </tbody></table>';
  8586. if ($rinfo ['loanRid'] != 0 && ! empty ( $rinfo ['accountItem'] )) {
  8587. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8588. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8589. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8590. $html .= '<tr><th>' . $value ['name'] . '</th>
  8591. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8592. }
  8593. $html .= '<tr><th class="taR">合计</th>
  8594. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8595. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8596. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8597. $html .= '<tr><th>' . $value ['name'] . '</th>
  8598. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8599. }
  8600. $html .= '<tr><th class="taR">合计</th>
  8601. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8602. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8603. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8604. $html .= '<tr><th>' . $value ['name'] . '</th>
  8605. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8606. }
  8607. $html .= '<tr><th class="taR">合计</th>
  8608. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8609. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8610. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8611. $html .= '<tr><th>' . $value ['name'] . '</th>
  8612. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8613. }
  8614. $html .= '<tr><th class="taR">合计</th>
  8615. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8616. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8617. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8618. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8619. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8620. }
  8621. $html .= '<tr><th class="taR">合计</th>
  8622. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8623. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8624. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8625. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8626. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8627. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8628. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8629. <tr';
  8630. if ($rinfo ['relust'] >= 0) {
  8631. $html .= 'class="success"';
  8632. } else {
  8633. $html .= 'class="error"';
  8634. }
  8635. $html .= '><td class="taR"><b>借款结余</b></td>
  8636. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['relust'] . '</b><br>' . $rinfo ['relustCN'] . '</td></tr>
  8637. </tbody></table>
  8638. ';
  8639. }
  8640. } elseif ($rinfo ['Rtype'] == 2) { // 对公汇款
  8641. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>
  8642. <tr><th colspan="2" class="taC">办事处相关费用</th></tr>';
  8643. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8644. $html .= '<tr><th>' . $value ['name'] . '</th>
  8645. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8646. }
  8647. $html .= '<tr><th class="taR">合计</th>
  8648. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8649. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8650. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8651. <tr><th class="taC" colspan="2">费用说明</th>
  8652. </tr><tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8653. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次费用合计</b></td>
  8654. <td class="taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>
  8655. </tbody></table>';
  8656. } else {
  8657. $html .= '<table class="table table-bordered table-condensed table-hover"><tbody>';
  8658. $html .= '<tr><th colspan="2" class="taC">日常相关费用</th></tr>';
  8659. foreach ( $rinfo ['accountItem'] ['日常相关费用'] as $value ) {
  8660. $html .= '<tr><th>' . $value ['name'] . '</th>
  8661. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8662. }
  8663. $html .= '<tr><th class="taR">合计</th>
  8664. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['agencySum'] . '</td></tr>';
  8665. $html .= '<tr><th colspan="2" class="taC">差旅相关费用</th></tr>';
  8666. foreach ( $rinfo ['accountItem'] ['差旅相关费用'] as $value ) {
  8667. $html .= '<tr><th>' . $value ['name'] . '</th>
  8668. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8669. }
  8670. $html .= '<tr><th class="taR">合计</th>
  8671. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['travelSum'] . '</td></tr>';
  8672. $html .= '<tr><th colspan="2" class="taC">培训班费用</th></tr>';
  8673. foreach ( $rinfo ['accountItem'] ['培训班费用'] as $value ) {
  8674. $html .= '<tr><th>' . $value ['name'] . '</th>
  8675. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8676. }
  8677. $html .= '<tr><th class="taR">合计</th>
  8678. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['trainSum'] . '</td></tr>';
  8679. $html .= '<tr><th colspan="2" class="taC">其他</th></tr>';
  8680. foreach ( $rinfo ['accountItem'] ['其他'] as $value ) {
  8681. $html .= '<tr><th>' . $value ['name'] . '</th>
  8682. <td width="140" class="taR">¥' . $value ['price'] . '</td></tr>';
  8683. }
  8684. $html .= '<tr><th class="taR">合计</th>
  8685. <td class="colGreen taR">¥' . $rinfo ['accountItem'] ['cSum'] ['otherSum'] . '</td></tr>';
  8686. $html .= '<tr><th colspan="2" class="taC">报销金额调整</th></tr>';
  8687. foreach ( $rinfo ['reviseDetail'] as $value ) {
  8688. $html .= '<tr><th><span class="interval">|</span>' . $value ['name'] . ':' . $value ['description'] . '</th>
  8689. <td class="taR">¥' . $value ['price'] . '</td></tr>';
  8690. }
  8691. $html .= '<tr><th class="taR">合计</th>
  8692. <td class="colGreen taR">¥' . $rinfo ['revisePrice'] . '</td></tr>';
  8693. $html .= '<tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  8694. <tr><th style="text-align:center" colspan="2">' . $rinfo ['category'] . '</th></tr>
  8695. <tr><th class="taC" colspan="2">报销说明</th></tr>
  8696. <tr><td colspan="2">' . $rinfo ['explanation'] . '</td></tr>
  8697. <tr class="warning"><td class="taR"><b>(' . $rinfo ['receiptOrder'] . ')本次报销费用合计</b></td>
  8698. <td class="colGreed taR"><b style="font-size:24px">¥' . $rinfo ['sum'] . '</b><br>' . $rinfo ['sumCN'] . '</td></tr>';
  8699. $html .= '</tbody></table>';
  8700. /*
  8701. * <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>
  8702. */
  8703. }
  8704. // print_r($verifyStaff);die;
  8705. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">审批人</th><th class="taC">审批意见</th></tr>';
  8706. foreach ( $verifyStaff as $key => $value ) {
  8707. $key = trim ( strtr ( $key, '_R', ' ' ) );
  8708. $sinfo = $staff->getOne ( array (
  8709. 'select' => 'username',
  8710. 'where' => ' sid=' . $key,
  8711. 'asArray' => true
  8712. ) );
  8713. $html .= '<tr><td>' . $sinfo ['username'] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8714. }
  8715. $html .= '</tbody></table>';
  8716. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="90">执行人</th><th class="taC">执行意见</th></tr>';
  8717. foreach ( $rinfo ['executeCopy'] as $value ) {
  8718. $html .= '<tr><td>' . $value [1] . '</td><td>' . $value ['opinion'] . '</td></tr>';
  8719. }
  8720. $html .= '</tbody></table>';
  8721. $html .= '<table class="table table-bordered table-condensed"><tr class="warning"><td class="taR"><b>汇款金额</b></td>
  8722. <td width="140" class="taR"><b style="font-size:24px">¥' . $rinfo ['amount'] . '</b><br>' . $rinfo ['amountCN'] . '</td>
  8723. </tr></table>';
  8724. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  8725. echo json_encode ( array (
  8726. 'status' => 1,
  8727. 'html' => $html
  8728. ) );
  8729. die ();
  8730. }
  8731. /**
  8732. * 删除附件
  8733. */
  8734. function ajaxRemEnclousur() {
  8735. $key = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : '';
  8736. if (empty ( $key ))
  8737. echo json_encode ( array (
  8738. 'status' => 2
  8739. ) );
  8740. Doo::loadModel ( 'enclosur' );
  8741. $enclosur = new enclosur ();
  8742. $enclosur->delEnclosurByEid ( $key );
  8743. echo json_encode ( array (
  8744. 'status' => 1
  8745. ) );
  8746. }
  8747. function remittance() {
  8748. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  8749. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  8750. Doo::loadModel ( 'receipt' );
  8751. $receipt = new receipt ();
  8752. Doo::loadModel ( 'staff' );
  8753. $staff = new staff ();
  8754. $dateCondition = " and Year(pastDate) =" . $year;
  8755. if (! empty ( $month ))
  8756. $dateCondition = " and Year(pastDate) =" . $year . " and Month(pastDate) = " . $month;
  8757. // get Receipt By verifyID status 1
  8758. $receiptList = $receipt->find ( array (
  8759. 'select' => 'sum(sum) as sum,staff,pastDate',
  8760. 'where' => ' status=1' . $dateCondition,
  8761. 'desc' => 'pastDate',
  8762. 'groupby' => 'staff,pastDate',
  8763. 'asArray' => true
  8764. ) );
  8765. $dateList = $receipt->find ( array (
  8766. 'select' => 'pastDate,verifyStaff',
  8767. 'where' => ' status=1' . $dateCondition,
  8768. 'desc' => 'pastDate',
  8769. 'groupby' => 'pastDate',
  8770. 'asArray' => true
  8771. ) );
  8772. $dataList = array ();
  8773. foreach ( $dateList as $d => $a ) {
  8774. $dataList [$a ['pastDate']] = array ();
  8775. $daySum = 0;
  8776. foreach ( $receiptList as $key => $value ) {
  8777. if ($a ['pastDate'] == $value ['pastDate']) {
  8778. $oderList = $receipt->find ( array (
  8779. 'select' => 'receiptOrder',
  8780. 'where' => ' status=1 and staff=' . $value ['staff'] . ' and pastDate=\'' . $a ['pastDate'] . '\'',
  8781. 'asArray' => true
  8782. ) );
  8783. $list = array ();
  8784. $html = "";
  8785. foreach ( $oderList as $v ) {
  8786. array_push ( $list, $v ['receiptOrder'] );
  8787. $html .= '<a class="fL" href="#comment" onclick=showOpinion("' . $v ['receiptOrder'] . '") data="" data-toggle="modal">&nbsp;' . $v ['receiptOrder'] . '、</a>';
  8788. }
  8789. $receiptList [$key] ['receiptOrder'] = $html;
  8790. // $receiptList[$key]['receiptOrder']=implode(",", $list);
  8791. $sinfo = $staff->getOne ( array (
  8792. 'select' => 'username ',
  8793. 'where' => ' sid=' . $value ['staff'],
  8794. 'asArray' => true
  8795. ) );
  8796. $receiptList [$key] ['username'] = $sinfo ['username'];
  8797. $daySum += $value ['sum'];
  8798. array_push ( $dataList [$a ['pastDate']], $receiptList [$key] );
  8799. }
  8800. $dataList [$a ['pastDate']] ['9999999'] = number_format ( $daySum, 2 );
  8801. // $dataList[$a['pastDate']]['8888888']=json_decode($a['verifyStaff'],true);
  8802. }
  8803. }
  8804. // print_r($dataList);
  8805. $data ['dataList'] = $dataList;
  8806. $mothHtml = "";
  8807. for($i = 1; $i <= 12; $i ++) {
  8808. if ($month == $i)
  8809. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  8810. else
  8811. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  8812. }
  8813. $data ['year'] = $year;
  8814. $data ['mothHtml'] = $mothHtml;
  8815. $data ['memu'] = "receipt";
  8816. $data ['staff'] = $this->staff;
  8817. $data ['receiptMemu'] = 'approval';
  8818. $data ['verifyId'] = $this->verifyId;
  8819. $data ['executeId'] = $this->executeId;
  8820. $this->render ( "/admin/saeaReportListPay", $data );
  8821. }
  8822. /**
  8823. * 金额调整,提高稳定性
  8824. * @return string
  8825. */
  8826. function revocationAdjustment() {
  8827. $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  8828. $price = isset ( $this->params ['price'] ) && is_numeric ( $this->params ['price'] ) ? $this->params ['price'] : - 99999;
  8829. $ridKey = isset ( $this->params ['ridKey'] ) ? $this->params ['ridKey'] : '';
  8830. $reviseKey = isset ( $this->params ['reviseKey'] ) ? $this->params ['reviseKey'] : '';
  8831. if ((! empty ( $sidKey )) && ($price != - 99999) && (! empty ( $ridKey ) && (! empty ( $reviseKey )))) {
  8832. Doo::loadClass ( 'XDeode' );
  8833. $XDeode = new XDeode ( 5 );
  8834. Doo::loadModel ( 'receipt' );
  8835. $receipt = new receipt ();
  8836. $sid = $XDeode->decode ( $sidKey );
  8837. $rid = $XDeode->decode ( $ridKey );
  8838. $reviseKey = $XDeode->decode ( $reviseKey );
  8839. if (! is_numeric ( $sid ) && ! is_numeric ( $rid ) && ! is_numeric ( $reviseKey ))
  8840. die ( 'illegal request' );
  8841. $receiptDetail = $receipt->getOne ( array (
  8842. 'where' => 'rid=' . $rid,
  8843. 'asArray' => true
  8844. ) );
  8845. if (empty ( $receiptDetail ) || empty ( $receiptDetail ['reviseDetail'] ))
  8846. die ( 'illegal request' );
  8847. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  8848. if (! isset ( $reviseDetail [$reviseKey] ))
  8849. die ( 'illegal request' );
  8850. if ($reviseDetail [$reviseKey] ['sid'] == $sid && $reviseDetail [$reviseKey] ['price'] == $price)
  8851. unset ( $reviseDetail [$reviseKey] );
  8852. $revisePrice = 0;
  8853. foreach ( $reviseDetail as $key => $value ) {
  8854. $revisePrice += $value ['price'];
  8855. }
  8856. $reviseDetailString = json_encode ( $reviseDetail );
  8857. $receipt->reviseDetail = $reviseDetailString;
  8858. $receipt->sum = $receiptDetail ['sum'] - $price;
  8859. $receipt->revisePrice = $revisePrice;
  8860. $receipt->update ( array (
  8861. 'where' => 'rid=' . $rid
  8862. ) );
  8863. return '/receiptburEdi/' . $rid;
  8864. } else
  8865. die ( 'illegal request2' );
  8866. }
  8867. function updateApprovalReceipt() {
  8868. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  8869. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  8870. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  8871. $Locate = $this->get_args ( 'Locate' ) && is_numeric ( $this->get_args ( 'Locate' ) ) ? $this->get_args ( 'Locate' ) : 0;
  8872. $amount = $this->get_args ( 'amount' ) && is_numeric ( $this->get_args ( 'amount' ) ) ? $this->get_args ( 'amount' ) : 0;
  8873. if (! empty ( $rid )) {
  8874. Doo::loadModel ( "verify" );
  8875. $verify = new verify ();
  8876. Doo::loadModel ( "receiptDetail" );
  8877. $receiptDetailObj = new receiptDetail ();
  8878. Doo::loadModel ( "itemStatistics" );
  8879. Doo::loadModel ( "statistics" );
  8880. $statistics = new statistics ();
  8881. $itemStatistics = new itemStatistics ();
  8882. Doo::loadModel ( "receipt" );
  8883. $receipt = new receipt ();
  8884. $receiptDetail = $receipt->getOne ( array (
  8885. 'where' => 'rid=' . $rid . ' and status=2 ',
  8886. 'asArray' => true
  8887. ) );
  8888. $nslist = explode ( ',', $receiptDetail ['nowStaff'] );
  8889. $nsflag = true;
  8890. foreach ( $nslist as $value ) {
  8891. if ($value == $this->staff ['0'] ['sid']) {
  8892. $nsflag = false;
  8893. break;
  8894. }
  8895. }
  8896. if (empty ( $receiptDetail ) || $nsflag)
  8897. return "/approvalExpenses/pendApproval";
  8898. $verifyDetail = $verify->getOne ( array (
  8899. 'where' => ' vid =' . $receiptDetail ['verify'],
  8900. 'asArray' => true
  8901. ) );
  8902. $verifyString = $verifyDetail ['staff'];
  8903. $verifyDetail = json_decode ( $verifyDetail ['staff'], true );
  8904. $verifyStaff = json_decode ( $receiptDetail ['verifyStaff'], true );
  8905. if (empty ( $opinion )) {
  8906. if ($status == 3)
  8907. $opinion = "终止";
  8908. else
  8909. $opinion = "同意支付";
  8910. }
  8911. $nowStaff = 0;
  8912. $nowStaffList = array ();
  8913. if (empty ( $verifyStaff )) {
  8914. // 还需加入是否已经进入角色审批
  8915. if ($verifyDetail [0] [1] == 'ROLE') {
  8916. $vStaffString = json_decode ( $verifyDetail [0] [3] );
  8917. foreach ( $vStaffString as $key => $value ) {
  8918. $staffK = explode ( "_", $value );
  8919. if ($staffK [0] != $this->staff [0] ['sid'])
  8920. array_push ( $nowStaffList, $staffK [0] );
  8921. }
  8922. // print_r($verifyDetail);
  8923. // die;
  8924. if (! empty ( $nowStaffList )) {
  8925. $nowStaff = implode ( ',', $nowStaffList );
  8926. $verifyStaff = array (
  8927. $this->staff [0] ['sid'] . "_R" => array (
  8928. 'date' => date ( 'Y-m-d' ),
  8929. 'opinion' => $opinion,
  8930. 'status' => $status,
  8931. 'nextStaff' => $verifyDetail [0] [0],
  8932. 'ROLE' => 1
  8933. )
  8934. );
  8935. } else {
  8936. $nowStaff = $verifyDetail [1] [0];
  8937. $verifyStaff = array (
  8938. $this->staff [0] ['sid'] . "_R" => array (
  8939. 'date' => date ( 'Y-m-d' ),
  8940. 'opinion' => $opinion,
  8941. 'status' => $status,
  8942. 'nextStaff' => $verifyDetail [1] [0]
  8943. )
  8944. );
  8945. }
  8946. } else {
  8947. if ($verifyDetail [1] [1] == 'ROLE') {
  8948. $vStaffString = json_decode ( $verifyDetail [1] [3] );
  8949. // echo "dd";
  8950. foreach ( $vStaffString as $key => $value ) {
  8951. $staffK = explode ( "_", $value );
  8952. array_push ( $nowStaffList, $staffK [0] );
  8953. }
  8954. $nowStaff = implode ( ',', $nowStaffList );
  8955. $verifyStaff = array (
  8956. $this->staff [0] ['sid'] => array (
  8957. 'date' => date ( 'Y-m-d' ),
  8958. 'opinion' => $opinion,
  8959. 'status' => $status,
  8960. 'nextStaff' => $verifyDetail [1] [0],
  8961. 'ROLE' => 1
  8962. )
  8963. );
  8964. } else {
  8965. $nowStaff = $verifyDetail [1] [0];
  8966. $verifyStaff = array (
  8967. $this->staff [0] ['sid'] => array (
  8968. 'date' => date ( 'Y-m-d' ),
  8969. 'opinion' => $opinion,
  8970. 'status' => $status,
  8971. 'nextStaff' => $verifyDetail [1] [0]
  8972. )
  8973. );
  8974. }
  8975. }
  8976. if ($status == 3)
  8977. $verifyStaff = array (
  8978. 'final' => $status,
  8979. $this->staff [0] ['sid'] => array (
  8980. 'date' => date ( 'Y-m-d' ),
  8981. 'opinion' => $opinion,
  8982. 'status' => $status
  8983. )
  8984. );
  8985. $vStaffString = json_encode ( $verifyStaff );
  8986. $receipt->nowStaff = $nowStaff;
  8987. $receipt->verifyStaff = $vStaffString;
  8988. } else {
  8989. $VS = end ( $verifyStaff );
  8990. // 非角色审批
  8991. if (! array_key_exists ( $this->staff [0] ['sid'], $verifyStaff ) && ! isset ( $VS ['ROLE'] )) {
  8992. $nextStaff = 0;
  8993. $roleSTF = false;
  8994. foreach ( $verifyDetail as $key => $value ) {
  8995. if ($value [0] == $this->staff [0] ['sid'] && $value [1] != 'ROLE') {
  8996. if (isset ( $verifyDetail [$key + 1] )) {
  8997. $nextStaff = $verifyDetail [$key + 1] [0];
  8998. if ($verifyDetail [$key + 1] [1] == 'ROLE')
  8999. $roleSTF = true;
  9000. }
  9001. break;
  9002. }
  9003. }
  9004. if (! $roleSTF) {
  9005. $nowStaff = $nextStaff;
  9006. $verifyStaff [$this->staff [0] ['sid']] = array (
  9007. 'date' => date ( 'Y-m-d' ),
  9008. 'opinion' => $opinion,
  9009. 'status' => $status,
  9010. 'nextStaff' => $nextStaff
  9011. );
  9012. } else {
  9013. // 获取角色下的所有用户ID
  9014. $nowStaffList = array ();
  9015. foreach ( $verifyDetail as $vfk ) {
  9016. if ($vfk [1] == 'ROLE') {
  9017. $vStaffString = json_decode ( $vfk [3] );
  9018. foreach ( $vStaffString as $key => $value ) {
  9019. $staffK = explode ( "_", $value );
  9020. array_push ( $nowStaffList, $staffK [0] );
  9021. }
  9022. }
  9023. }
  9024. $nowStaff = implode ( ',', $nowStaffList );
  9025. $verifyStaff [$this->staff [0] ['sid']] = array (
  9026. 'date' => date ( 'Y-m-d' ),
  9027. 'opinion' => $opinion,
  9028. 'status' => $status,
  9029. 'nextStaff' => $nextStaff,
  9030. 'ROLE' => 0
  9031. );
  9032. }
  9033. if ($status == 3) {
  9034. $verifyStaff ['final'] = $status;
  9035. $verifyStaff [$this->staff [0] ['sid']] = array (
  9036. 'date' => date ( 'Y-m-d' ),
  9037. 'opinion' => $opinion,
  9038. 'status' => $status
  9039. );
  9040. }
  9041. $vStaffString = json_encode ( $verifyStaff );
  9042. $receipt->nowStaff = $nowStaff;
  9043. $receipt->verifyStaff = $vStaffString;
  9044. }
  9045. // 角色审批
  9046. if (isset ( $VS ['ROLE'] )) {
  9047. // 找出角色人 当前审批角色组
  9048. $verifyJSStaff = array ();
  9049. $nowStaffList2 = array ();
  9050. foreach ( $verifyDetail as $key => $value ) {
  9051. if ($value [1] == 'ROLE' && $value [0] == $VS ['nextStaff']) {
  9052. $verifyJSStaff = json_decode ( $value [3] );
  9053. foreach ( $verifyJSStaff as $m ) {
  9054. $staffK = explode ( "_", $m );
  9055. array_push ( $nowStaffList2, $staffK [0] );
  9056. }
  9057. // print_r($nowStaffList2);
  9058. }
  9059. }
  9060. $RoleVerifyStaff = array ();
  9061. foreach ( $verifyStaff as $key => $value ) {
  9062. if (isset ( $value ['ROLE'] ) && $value ['ROLE'] == 1 && $VS ['nextStaff'] == $value ['nextStaff']) {
  9063. foreach ( $nowStaffList2 as $m ) {
  9064. if ($key == $m . "_R")
  9065. $RoleVerifyStaff [$key] = $value;
  9066. }
  9067. }
  9068. }
  9069. // print_r($verifyStaff);
  9070. // print_r($nowStaffList2);
  9071. // print_r($RoleVerifyStaff);
  9072. // if (!array_key_exists($this->staff[0]['sid'],$RoleVerifyStaff)){
  9073. // print_r($verifyJSStaff);
  9074. $jsCount = count ( $verifyJSStaff ) - 1; // echo $jsCount;die;
  9075. if ($jsCount == count ( $RoleVerifyStaff )) { // 或者
  9076. // 下一个审批人ID
  9077. $nextStaff = 0;
  9078. $falg = false;
  9079. foreach ( $verifyDetail as $key => $value ) {
  9080. if ($value [0] == $VS ['nextStaff'] && $value [1] == 'ROLE') {
  9081. if (isset ( $verifyDetail [$key + 1] ) && $verifyDetail [$key + 1] [1] == 'ROLE') {
  9082. $falg = true;
  9083. $vStaffString = json_decode ( $verifyDetail [$key + 1] [3] );
  9084. $nowStaffList = array ();
  9085. foreach ( $vStaffString as $v ) {
  9086. $staffK = explode ( "_", $v );
  9087. array_push ( $nowStaffList, $staffK [0] );
  9088. }
  9089. $nowStaff = implode ( ',', $nowStaffList );
  9090. $nextStaff = $verifyDetail [$key + 1] [0];
  9091. } elseif (isset ( $verifyDetail [$key + 1] )) {
  9092. $nextStaff = $verifyDetail [$key + 1] [0];
  9093. $nowStaff = $nextStaff;
  9094. } else
  9095. $nowStaff = '';
  9096. break;
  9097. }
  9098. }
  9099. if ($falg)
  9100. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9101. 'date' => date ( 'Y-m-d' ),
  9102. 'opinion' => $opinion,
  9103. 'status' => $status,
  9104. 'nextStaff' => $nextStaff,
  9105. 'ROLE' => 1
  9106. );
  9107. else
  9108. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9109. 'date' => date ( 'Y-m-d' ),
  9110. 'opinion' => $opinion,
  9111. 'status' => $status,
  9112. 'nextStaff' => $nextStaff
  9113. );
  9114. // print_r($verifyStaff);
  9115. // echo $nowStaff;die;
  9116. } else { // 进入下一个角色或者审批人
  9117. // echo str_replace($this->staff[0]['sid'], '', $receiptDetail['nowStaff']);
  9118. //
  9119. $nowStaff = str_replace ( $this->staff [0] ['sid'], '', $receiptDetail ['nowStaff'] );
  9120. $verifyStaff [$this->staff [0] ['sid'] . '_R'] = array (
  9121. 'date' => date ( 'Y-m-d' ),
  9122. 'opinion' => $opinion,
  9123. 'status' => $status,
  9124. 'nextStaff' => $VS ['nextStaff'],
  9125. 'ROLE' => 1
  9126. );
  9127. // print_r($verifyStaff);
  9128. // die;
  9129. }
  9130. if ($status == 3) {
  9131. $verifyStaff ['final'] = $status;
  9132. $verifyStaff [$this->staff [0] ['sid']] = array (
  9133. 'date' => date ( 'Y-m-d' ),
  9134. 'opinion' => $opinion,
  9135. 'status' => $status
  9136. );
  9137. }
  9138. $vStaffString = json_encode ( $verifyStaff );
  9139. $receipt->verifyStaff = $vStaffString;
  9140. $receipt->nowStaff = $nowStaff;
  9141. // die;
  9142. // }
  9143. // print_r($verifyStaff);
  9144. // die;
  9145. }
  9146. // print_r($verifyStaff);die;
  9147. }
  9148. // print_r($verifyDetail);
  9149. $roleKey = 0;
  9150. $roleId = 0;
  9151. $verifyDetailCopy = array ();
  9152. foreach ( $verifyDetail as $k => $v ) {
  9153. if ($v [1] == 'ROLE') {
  9154. $roleId = $v [0];
  9155. $roleVerify = json_decode ( $v [3], true );
  9156. $roleKey = $k;
  9157. $roleArray = array ();
  9158. foreach ( $roleVerify as $o => $p ) {
  9159. $staffID = explode ( '_', $p );
  9160. $exp = array (
  9161. 0 => $staffID [0],
  9162. 1 => $staffID [1]
  9163. );
  9164. array_push ( $roleArray, $exp );
  9165. }
  9166. $verifyDetailCopy [$v [0]] = $roleArray;
  9167. }
  9168. }
  9169. // print_r($verifyDetail);
  9170. foreach ( $verifyDetailCopy as $k => $v ) {
  9171. foreach ( $verifyDetail as $m => $n ) {
  9172. if ($n [0] == $k) {
  9173. array_splice ( $verifyDetail, $m, 1, $v );
  9174. }
  9175. }
  9176. }
  9177. // die;
  9178. // if (!empty($roleArray))
  9179. // array_splice($verifyDetail,$roleKey,1,$roleArray);
  9180. // echo $roleId;
  9181. // print_r($verifyStaff);
  9182. // print_r($verifyDetail);
  9183. // die;
  9184. Doo::loadModel ( "receiptLog" );
  9185. $receiptLog = new receiptLog ();
  9186. // 审批日志
  9187. if (! isset ( $verifyStaff ['final'] )) {
  9188. if (! empty ( $roleId )) {
  9189. Doo::loadModel ( "role" );
  9190. $role = new role ();
  9191. $roleInfo = $role->getOne ( array (
  9192. 'where' => 'rid=' . $roleId,
  9193. 'asArray' => true
  9194. ) );
  9195. $receiptLog->rolename = $roleInfo ['name'];
  9196. }
  9197. $receiptLog->username = $this->staff [0] ['username'];
  9198. $receiptLog->uid = $this->staff [0] ['sid'];
  9199. $receiptLog->date = date ( "Y-m-d" );
  9200. $receiptLog->opinion = $opinion;
  9201. $receiptLog->img = $this->staff [0] ['avatar'];
  9202. $receiptLog->status = 1;
  9203. $receiptLog->rid = $rid;
  9204. $receiptLog->insert ();
  9205. }
  9206. if (isset ( $verifyStaff ['final'] )) { // rDetail
  9207. $receipt->verifyBreakup = $verifyString;
  9208. $receipt->status = 3;
  9209. $receiptDetailObj->status = 3;
  9210. $receiptDetailObj->update ( array (
  9211. 'where' => 'rid=' . $rid
  9212. ) );
  9213. if (! empty ( $roleId )) {
  9214. Doo::loadModel ( "role" );
  9215. $role = new role ();
  9216. $roleInfo = $role->getOne ( array (
  9217. 'where' => 'rid=' . $roleId,
  9218. 'asArray' => true
  9219. ) );
  9220. $receiptLog->rolename = $roleInfo ['name'];
  9221. }
  9222. $receiptLog->username = $this->staff [0] ['username'];
  9223. $receiptLog->uid = $this->staff [0] ['sid'];
  9224. $receiptLog->date = date ( "Y-m-d" );
  9225. $receiptLog->opinion = $opinion;
  9226. $receiptLog->img = $this->staff [0] ['avatar'];
  9227. $receiptLog->status = 3;
  9228. $receiptLog->rid = $rid;
  9229. $receiptLog->insert ();
  9230. //删除行程单
  9231. Doo::loadModel ( 'itinerary' );
  9232. $itinerary = new itinerary ();
  9233. $itinerary->delete ( array (
  9234. 'where' => 'rid="' . $rid . '"'
  9235. ) );
  9236. // 微信企业号通知
  9237. $this->setWXMsg ( $rid, 3 );
  9238. } elseif (count ( $verifyStaff ) == count ( $verifyDetail )) { // 要修改 角色的数量
  9239. $receipt->status = 1;
  9240. $reviseSum = 0;
  9241. $receipt->verifyBreakup = $verifyString;
  9242. if (! empty ( $receiptDetail ['reviseDetail'] )) { // statistics item rDetail
  9243. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9244. foreach ( $reviseDetail as $key => $value ) {
  9245. $receiptDetailObj = new receiptDetail ();
  9246. $receiptDetailObj->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9247. $receiptDetailObj->item = $value ['description'];
  9248. $receiptDetailObj->itemCategory = "报销金额调整";
  9249. $receiptDetailObj->price = $value ['price'];
  9250. $receiptDetailObj->date = $receiptDetail ['date'];
  9251. $receiptDetailObj->cid = $this->staff [0] ['cid'];
  9252. $receiptDetailObj->rid = $rid;
  9253. $receiptDetailObj->status = 1;
  9254. $receiptDetailObj->insert ();
  9255. $reviseSum += $value ['price'];
  9256. }
  9257. $itemStatistics = new itemStatistics ();
  9258. $itemStatistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  9259. $itemStatistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9260. $itemStatistics->price = $reviseSum;
  9261. $itemStatistics->itemCategory = "报销金额调整";
  9262. $itemStatistics->date = $receiptDetail ['date'];
  9263. $itemStatistics->insert ();
  9264. }
  9265. $receiptDetailObj = new receiptDetail ();
  9266. $receiptDetailObj->status = 1;
  9267. $receiptDetailObj->pastDate = date ( "Y-m-d" );
  9268. $receiptDetailObj->update ( array (
  9269. 'where' => 'rid=' . $rid
  9270. ) );
  9271. $dateArray = explode ( "-", $receiptDetail ['date'] );
  9272. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  9273. $stat = $statistics->getOne ( array (
  9274. 'where' => 'staff=' . $receiptDetail ['staff'] . $dateCondition,
  9275. 'asArray' => true
  9276. ) );
  9277. if (empty ( $stat )) {
  9278. $statistics->date = $receiptDetail ['date'];
  9279. $statistics->cid = $receiptDetail ['cid']; // $this->staff[0]['cid'];
  9280. $statistics->staff = $receiptDetail ['staff']; // $this->staff[0]['sid'];
  9281. $statistics->agPrice = $receiptDetail ['sum'];
  9282. $statistics->rePrice = $reviseSum;
  9283. $statistics->insert ();
  9284. } else {
  9285. $statistics->agPrice = $stat ['agPrice'] + $receiptDetail ['sum'];
  9286. $statistics->rePrice = $stat ['rePrice'] + $reviseSum;
  9287. $statistics->update ( array (
  9288. 'where' => 'sid=' . $stat ['sid']
  9289. ) );
  9290. }
  9291. $dateArray = explode ( "-", $receiptDetail ['date'] );
  9292. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  9293. $accountItem = json_decode ( $receiptDetail ['accountItem'], true );
  9294. foreach ( $accountItem ['cSum'] as $key => $value ) {
  9295. if ($key == "agencySum") {
  9296. $iStatistics = $itemStatistics->getOne ( array (
  9297. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->AGENCY . '"' . $dateCondition,
  9298. 'asArray' => true
  9299. ) );
  9300. if (empty ( $iStatistics )) {
  9301. $itemStatistics->cid = $receiptDetail ['cid'];
  9302. ;
  9303. $itemStatistics->staff = $receiptDetail ['staff'];
  9304. $itemStatistics->price = $value;
  9305. $itemStatistics->itemCategory = $this->AGENCY;
  9306. $itemStatistics->date = $receiptDetail ['date'];
  9307. $itemStatistics->insert ();
  9308. } else {
  9309. if (! empty ( $value )) {
  9310. $itemStatistics->price = $value + $iStatistics ['price'];
  9311. $itemStatistics->update ( array (
  9312. 'where' => 'sid=' . $iStatistics ['sid']
  9313. ) );
  9314. }
  9315. }
  9316. } elseif ($key == "travelSum") {
  9317. $iStatistics = $itemStatistics->getOne ( array (
  9318. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAVEL . '"' . $dateCondition,
  9319. 'asArray' => true
  9320. ) );
  9321. if (empty ( $iStatistics )) {
  9322. $itemStatistics->cid = $receiptDetail ['cid'];
  9323. $itemStatistics->staff = $receiptDetail ['staff'];
  9324. $itemStatistics->price = $value;
  9325. $itemStatistics->itemCategory = $this->TRAVEL;
  9326. $itemStatistics->date = $receiptDetail ['date'];
  9327. $itemStatistics->insert ();
  9328. } else {
  9329. if (! empty ( $value )) {
  9330. $itemStatistics->price = $value + $iStatistics ['price'];
  9331. $itemStatistics->update ( array (
  9332. 'where' => 'sid=' . $iStatistics ['sid']
  9333. ) );
  9334. }
  9335. }
  9336. } elseif ($key == "trainSum") {
  9337. $iStatistics = $itemStatistics->getOne ( array (
  9338. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->TRAIN . '"' . $dateCondition,
  9339. 'asArray' => true
  9340. ) );
  9341. if (empty ( $iStatistics )) {
  9342. $itemStatistics->cid = $receiptDetail ['cid'];
  9343. $itemStatistics->staff = $receiptDetail ['staff'];
  9344. $itemStatistics->price = $value;
  9345. $itemStatistics->itemCategory = $this->TRAIN;
  9346. $itemStatistics->date = $receiptDetail ['date'];
  9347. $itemStatistics->insert ();
  9348. } else {
  9349. if (! empty ( $value )) {
  9350. $itemStatistics->price = $value + $iStatistics ['price'];
  9351. $itemStatistics->update ( array (
  9352. 'where' => 'sid=' . $iStatistics ['sid']
  9353. ) );
  9354. }
  9355. }
  9356. } elseif ($key == "otherSum") {
  9357. $iStatistics = $itemStatistics->getOne ( array (
  9358. 'where' => 'staff=' . $receiptDetail ['staff'] . ' and itemCategory="' . $this->OTHER . '"' . $dateCondition,
  9359. 'asArray' => true
  9360. ) );
  9361. if (empty ( $iStatistics )) {
  9362. $itemStatistics->cid = $receiptDetail ['cid'];
  9363. $itemStatistics->staff = $receiptDetail ['staff'];
  9364. $itemStatistics->price = $value;
  9365. $itemStatistics->itemCategory = $this->OTHER;
  9366. $itemStatistics->date = $receiptDetail ['date'];
  9367. $itemStatistics->insert ();
  9368. } else {
  9369. if (! empty ( $value )) {
  9370. $itemStatistics->price = $value + $iStatistics ['price'];
  9371. $itemStatistics->update ( array (
  9372. 'where' => 'sid=' . $iStatistics ['sid']
  9373. ) );
  9374. }
  9375. }
  9376. }
  9377. }
  9378. $receipt->pastDate = date ( "Y-m-d" );
  9379. // 微信企业号通知
  9380. $this->setWXMsg ( $rid, 1 );
  9381. }
  9382. //是否有流水
  9383. Doo::loadModel ( 'wasteBook' );
  9384. $wasteBook = new wasteBook ();
  9385. $accountType=3;
  9386. if ($receiptDetail['Rtype']==1){
  9387. $accountType=2;
  9388. }elseif($receiptDetail['Rtype']==2){
  9389. $accountType=4;
  9390. }
  9391. $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $rid );
  9392. if (empty($wbDetail)){
  9393. $rsum=$receiptDetail['sum']-$receiptDetail['loanSum'];
  9394. $receipt->amount = $rsum;//$amount;
  9395. }
  9396. $receipt->update ( array (
  9397. 'where' => ' rid = ' . $rid
  9398. ) );
  9399. // 进入下一条审批费用新加需求
  9400. $vidList = array ();
  9401. $verifyDetail = $verify->find ( array (
  9402. 'where' => ' (staff not like "%\"' . $this->staff [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $this->staff [0] ['sid'] . '\",%" or staff like "%\"' . $this->staff [0] ['sid'] . '\_%" )',
  9403. 'asArray' => true
  9404. ) );
  9405. foreach ( $verifyDetail as $key => $value ) {
  9406. array_push ( $vidList, $value ['vid'] );
  9407. }
  9408. $vid = implode ( ",", $vidList );
  9409. if (empty ( $verifyDetail ))
  9410. $vid = 0;
  9411. $approvalCondition = ' and status=2 and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  9412. $receipt = new receipt ();
  9413. $rd = $receipt->getOne ( array (
  9414. 'where' => 'status!=5 ' . $approvalCondition . ' and verify in(' . $vid . ') and Rtype!=3',
  9415. 'asc' => 'rid',
  9416. 'asArray' => true
  9417. ) );
  9418. if (empty ( $rd )) {
  9419. return '/approvalExpenses/pendApproval';
  9420. }
  9421. if ($rd ['Rtype'] == 1) {
  9422. if ($rd ['isBK'] == 1) {
  9423. return '/receiptburEdi/' . $rd ['rid'];
  9424. } else {
  9425. return '/expensesEdi/' . $rd ['rid'];
  9426. }
  9427. } elseif ($rd ['Rtype'] == 2) {
  9428. return '/remitApproval/' . $rd ['rid'];
  9429. } else {
  9430. return '/receiptburEdi/' . $rd ['rid'];
  9431. }
  9432. // return "/approvalExpenses/pendApproval";
  9433. }
  9434. }
  9435. function expensesRetreats() {
  9436. $rid = isset ( $this->params ['rid'] ) && is_numeric ( $this->params ['rid'] ) ? $this->params ['rid'] : 0;
  9437. if (! empty ( $rid )) {
  9438. // 操作记录
  9439. Doo::loadModel ( "receipt" );
  9440. $receipt = new receipt ();
  9441. Doo::loadModel ( "receiptLog" );
  9442. $receiptLog = new receiptLog ();
  9443. Doo::loadModel ( "verify" );
  9444. $verify = new verify ();
  9445. $receiptInfo = $receipt->getOne ( array (
  9446. 'where' => 'rid=' . $rid,
  9447. 'asArray' => true
  9448. ) );
  9449. $vr = $verify->getOne ( array (
  9450. 'where' => 'vid=' . $receiptInfo ['verify'],
  9451. 'asArray' => true
  9452. ) );
  9453. $jd = json_decode ( $vr ['staff'] );
  9454. $roleId = 0;
  9455. foreach ( $jd as $key => $value ) {
  9456. if ($value [1] == 'ROLE') {
  9457. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9458. if ($pos !== false) {
  9459. $roleId = $value [0];
  9460. }
  9461. }
  9462. }
  9463. // 审批日志
  9464. // echo $roleId;die;
  9465. if (! empty ( $roleId )) {
  9466. Doo::loadModel ( "role" );
  9467. $role = new role ();
  9468. $roleInfo = $role->getOne ( array (
  9469. 'where' => 'rid=' . $roleId,
  9470. 'asArray' => true
  9471. ) );
  9472. $receiptLog->rolename = $roleInfo ['name'];
  9473. }
  9474. $receiptLog->username = $this->staff [0] ['username'];
  9475. $receiptLog->uid = $this->staff [0] ['sid'];
  9476. $receiptLog->date = date ( "Y-m-d" );
  9477. $receiptLog->opinion = '撤回';
  9478. $receiptLog->img = $this->staff [0] ['avatar'];
  9479. $receiptLog->status = 4;
  9480. $receiptLog->rid = $rid;
  9481. $receiptLog->insert ();
  9482. $receipt->status = 4;
  9483. $receipt->update ( array (
  9484. 'where' => 'rid=' . $rid
  9485. ) );
  9486. // 微信企业号通知
  9487. $this->setWXMsg ( $rid, 2 );
  9488. }
  9489. // echo "ddd";
  9490. return '/approvalExpenses/pendApproval';
  9491. }
  9492. function updateCheReceipt() {
  9493. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9494. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  9495. // $rid=isset($this->params['rid'])&&is_numeric($this->params['rid'])?$this->params['rid']:0;
  9496. if (! empty ( $rid )) {
  9497. // 操作记录
  9498. Doo::loadModel ( "receipt" );
  9499. $receipt = new receipt ();
  9500. Doo::loadModel ( "receiptLog" );
  9501. $receiptLog = new receiptLog ();
  9502. Doo::loadModel ( "verify" );
  9503. $verify = new verify ();
  9504. $receiptInfo = $receipt->getOne ( array (
  9505. 'where' => 'rid=' . $rid . ' and status=2',
  9506. 'asArray' => true
  9507. ) );
  9508. if (empty ( $receiptInfo )) {
  9509. echo json_encode ( array (
  9510. 'status' => 2
  9511. ) );
  9512. die ();
  9513. }
  9514. $vr = $verify->getOne ( array (
  9515. 'where' => 'vid=' . $receiptInfo ['verify'],
  9516. 'asArray' => true
  9517. ) );
  9518. $jd = json_decode ( $vr ['staff'] );
  9519. $roleId = 0;
  9520. foreach ( $jd as $key => $value ) {
  9521. if ($value [1] == 'ROLE') {
  9522. $pos = strpos ( $value [3], $this->staff [0] ['sid'] );
  9523. if ($pos !== false) {
  9524. $roleId = $value [0];
  9525. }
  9526. }
  9527. }
  9528. // 审批日志
  9529. // echo $roleId;die;
  9530. if (! empty ( $roleId )) {
  9531. Doo::loadModel ( "role" );
  9532. $role = new role ();
  9533. $roleInfo = $role->getOne ( array (
  9534. 'where' => 'rid=' . $roleId,
  9535. 'asArray' => true
  9536. ) );
  9537. $receiptLog->rolename = $roleInfo ['name'];
  9538. }
  9539. $receiptLog->username = $this->staff [0] ['username'];
  9540. $receiptLog->uid = $this->staff [0] ['sid'];
  9541. $receiptLog->date = date ( "Y-m-d" );
  9542. $receiptLog->opinion = $opinion;
  9543. $receiptLog->img = $this->staff [0] ['avatar'];
  9544. $receiptLog->status = 4;
  9545. $receiptLog->rid = $rid;
  9546. $receiptLog->insert ();
  9547. $receipt->status = 4;
  9548. $receipt->update ( array (
  9549. 'where' => 'rid=' . $rid
  9550. ) );
  9551. // 微信企业号通知
  9552. $this->setWXMsg ( $rid, 2 );
  9553. echo json_encode ( array (
  9554. 'status' => 1
  9555. ) );
  9556. // Header("HTTP/1.1 303 See Other");
  9557. // Header("Location: /approvalExpenses/pendApproval");
  9558. die ();
  9559. }
  9560. echo json_encode ( array (
  9561. 'status' => 2
  9562. ) );
  9563. die ();
  9564. // echo "ddd";
  9565. // return '/saeaBorad';
  9566. }
  9567. function revisePrice() {
  9568. $description = $this->get_args ( 'description' ) ? $this->get_args ( 'description' ) : "";
  9569. $price = $this->get_args ( 'price' ) && is_numeric ( $this->get_args ( 'price' ) ) ? $this->get_args ( 'price' ) : 0;
  9570. $rid = $this->get_args ( 'rid' ) && is_numeric ( $this->get_args ( 'rid' ) ) ? $this->get_args ( 'rid' ) : 0;
  9571. // echo $price;die;
  9572. if (! empty ( $rid )) {
  9573. Doo::loadModel ( "receipt" );
  9574. $receipt = new receipt ();
  9575. $receiptDetail = $receipt->getOne ( array (
  9576. 'where' => 'rid=' . $rid . ' and status=2 ',
  9577. 'asArray' => true
  9578. ) );
  9579. if (empty ( $receiptDetail ))
  9580. die ( 'illegal request' );
  9581. $reviseDetail = array ();
  9582. if (empty ( $receiptDetail ['reviseDetail'] )) {
  9583. array_push ( $reviseDetail, array (
  9584. 'sid' => $this->staff [0] ['sid'],
  9585. 'name' => $this->staff [0] ['username'],
  9586. 'description' => $description,
  9587. 'price' => $price
  9588. ) );
  9589. $reviseDetailString = json_encode ( $reviseDetail );
  9590. $receipt->reviseDetail = $reviseDetailString;
  9591. $receipt->revisePrice = $price;
  9592. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9593. } else {
  9594. $reviseDetail = json_decode ( $receiptDetail ['reviseDetail'], true );
  9595. array_push ( $reviseDetail, array (
  9596. 'sid' => $this->staff [0] ['sid'],
  9597. 'name' => $this->staff [0] ['username'],
  9598. 'description' => $description,
  9599. 'price' => $price
  9600. ) );
  9601. $reviseDetailString = json_encode ( $reviseDetail );
  9602. $receipt->reviseDetail = $reviseDetailString;
  9603. $receipt->revisePrice = round ( $price, 2 ) + round ( $receiptDetail ['revisePrice'], 2 );
  9604. $receipt->sum = bcadd ( $receiptDetail ['sum'], $price, 2 );
  9605. }
  9606. $receipt->update ( array (
  9607. 'where' => 'rid=' . $rid
  9608. ) );
  9609. if ($receiptDetail ['Rtype'] == 1) {
  9610. if ($receiptDetail ['isBK'] == 1) {
  9611. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9612. }
  9613. } elseif ($receiptDetail ['Rtype'] == 2) {
  9614. } else {
  9615. return '/receiptburEdi/' . $receiptDetail ['rid'];
  9616. }
  9617. }
  9618. die ( 'illegal request' );
  9619. }
  9620. function personalCollect() {
  9621. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9622. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollect_" . $year . ".htmls";
  9623. $this->showCache ( $path );
  9624. Doo::loadModel ( "receiptDetail" );
  9625. Doo::loadModel ( "itemStatistics" );
  9626. Doo::loadModel ( 'statistics' );
  9627. $statistics = new statistics ();
  9628. $itemStatistics = new itemStatistics ();
  9629. $receiptDetail = new receiptDetail ();
  9630. $receiptCollectList = $receiptDetail->find ( array (
  9631. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9632. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9633. 'groupby' => 'itemCategory,Month(date)',
  9634. 'asArray' => true
  9635. ) );
  9636. $data ['itemStatisticsList'] = $itemStatistics->find ( array (
  9637. 'where' => 'staff=' . $this->staff [0] ['sid'],
  9638. 'asArray' => true
  9639. ) );
  9640. // create collect html
  9641. $collectArray = array (
  9642. '日常相关费用' => array (),
  9643. '差旅相关费用' => array (),
  9644. '培训班费用' => array (),
  9645. '其他' => array ()
  9646. );
  9647. $adjustment = array ();
  9648. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用' );
  9649. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9650. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用' );
  9651. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9652. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用' );
  9653. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9654. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他' );
  9655. array_push ( $collectArray ['其他'], $collectHtml );
  9656. $data ['collectArray'] = $collectArray;
  9657. // statistics html
  9658. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9659. if (empty ( $stList ))
  9660. $stList = array (
  9661. 'rePrice' => 0,
  9662. 'agPrice' => 0
  9663. );
  9664. $data ['stList'] = array (
  9665. 'rePrice' => $stList ['rePrice'],
  9666. 'agPrice' => $stList ['agPrice'],
  9667. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9668. );
  9669. // Adjustment price html
  9670. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9671. array_push ( $adjustment, $collectHtml );
  9672. $data ['adjustment'] = $adjustment;
  9673. // total price html
  9674. $collectHtml = "";
  9675. $total = 0;
  9676. for($i = 1; $i <= 12; $i ++) {
  9677. $sumPrice = 0;
  9678. foreach ( $receiptCollectList as $key => $value ) {
  9679. if ($value ['month'] == $i) {
  9680. $sumPrice += $value ['price'];
  9681. }
  9682. }
  9683. if ($sumPrice == 0)
  9684. $collectHtml .= '<td class="taR">-</td>';
  9685. else
  9686. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9687. $total += $sumPrice;
  9688. }
  9689. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9690. $data ['totalPrice'] = $collectHtml;
  9691. $dateHtml = "";
  9692. $now = date ( "Y" );
  9693. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9694. if ($YEARD <= $now) {
  9695. $dateHtml .= '<option ';
  9696. if ($year == $YEARD) {
  9697. $dateHtml .= 'selected ';
  9698. }
  9699. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9700. }
  9701. }
  9702. $data ['dateHtml'] = $dateHtml;
  9703. $data ['year'] = $year;
  9704. $data ['totalYear'] = $total;
  9705. $data ['memu'] = "receipt";
  9706. $data ['staff'] = $this->staff;
  9707. $data ['receiptMemu'] = 'personalCollect';
  9708. $data ['verifyId'] = $this->verifyId;
  9709. $data ['executeId'] = $this->executeId;
  9710. // year staff status 2,4
  9711. if ($year < date ( "Y" )) {
  9712. Doo::loadModel ( 'receipt' );
  9713. $receipt = new receipt ();
  9714. $receiptList = $receipt->find ( array (
  9715. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9716. 'asArray' => true
  9717. ) );
  9718. if (empty ( $receiptList )) {
  9719. ob_start ();
  9720. $this->render ( "/admin/saea_slist_collect", $data );
  9721. $this->cacheFile ( $path );
  9722. die ();
  9723. }
  9724. }
  9725. $this->render ( "/admin/saea_slist_collect", $data );
  9726. }
  9727. function personalCollectDetail() {
  9728. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9729. $path = SITE_PATH . $this->PERSONALCOLLECTCACHEPATH . "personalCollectDetail_" . $year . ".htmls";
  9730. $this->showCache ( $path );
  9731. Doo::loadModel ( "receiptDetail" );
  9732. Doo::loadModel ( "itemStatistics" );
  9733. Doo::loadModel ( 'statistics' );
  9734. Doo::loadModel ( 'accountItem' );
  9735. $accountItem = new accountItem ();
  9736. $statistics = new statistics ();
  9737. $itemStatistics = new itemStatistics ();
  9738. $receiptDetail = new receiptDetail ();
  9739. $receiptCollectList = $receiptDetail->find ( array (
  9740. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  9741. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9742. 'groupby' => 'item,Month(date)',
  9743. 'asArray' => true
  9744. ) );
  9745. $accountList = $accountItem->find ( array (
  9746. 'asArray' => true
  9747. ) );
  9748. // create CollectDetail HTML
  9749. $collectHtml = array ();
  9750. foreach ( $accountList as $key => $value ) {
  9751. $html = "";
  9752. $asum = 0;
  9753. for($i = 1; $i <= 12; $i ++) {
  9754. $falg = true;
  9755. foreach ( $receiptCollectList as $v ) {
  9756. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  9757. $asum += $v ['price'];
  9758. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9759. $falg = false;
  9760. break;
  9761. }
  9762. }
  9763. if ($falg)
  9764. $html .= '<td class="taR">-</td>';
  9765. }
  9766. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9767. $collectHtml [$value ['category']] [$value ['name']] = $html;
  9768. }
  9769. $data ['collectHtml'] = $collectHtml;
  9770. // create Adjustment price html
  9771. $receiptCollectList = $receiptDetail->find ( array (
  9772. 'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
  9773. 'where' => 'staff=' . $this->staff [0] ['sid'] . " and status=1 and Year(date)=" . $year,
  9774. 'groupby' => 'itemCategory,Month(date)',
  9775. 'asArray' => true
  9776. ) );
  9777. $adjustment = array ();
  9778. $collectArray = array (
  9779. '日常相关费用' => array (),
  9780. '差旅相关费用' => array (),
  9781. '培训班费用' => array (),
  9782. '其他' => array ()
  9783. );
  9784. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  9785. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  9786. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  9787. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  9788. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  9789. array_push ( $collectArray ['培训班费用'], $collectHtml );
  9790. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  9791. array_push ( $collectArray ['其他'], $collectHtml );
  9792. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  9793. array_push ( $adjustment, $collectHtml );
  9794. // total price html
  9795. $collectHtml = "";
  9796. $total = 0;
  9797. for($i = 1; $i <= 12; $i ++) {
  9798. $sumPrice = 0;
  9799. foreach ( $receiptCollectList as $key => $value ) {
  9800. if ($value ['month'] == $i) {
  9801. $sumPrice += $value ['price'];
  9802. }
  9803. }
  9804. if ($sumPrice == 0)
  9805. $collectHtml .= '<td class="taR">-</td>';
  9806. else
  9807. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9808. $total += $sumPrice;
  9809. }
  9810. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9811. // statistics html
  9812. $stList = $statistics->statisticsByYear ( $year, $this->staff [0] ['sid'] );
  9813. if (empty ( $stList ))
  9814. $stList = array (
  9815. 'rePrice' => 0,
  9816. 'agPrice' => 0
  9817. );
  9818. $data ['stList'] = array (
  9819. 'rePrice' => $stList ['rePrice'],
  9820. 'agPrice' => $stList ['agPrice'],
  9821. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9822. );
  9823. $data ['collectArray'] = $collectArray;
  9824. $data ['adjustment'] = $adjustment;
  9825. $data ['totalPrice'] = $collectHtml;
  9826. $data ['totalYear'] = $total;
  9827. $data ['year'] = $year;
  9828. $dateHtml = "";
  9829. $now = date ( "Y" );
  9830. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9831. if ($YEARD <= $now) {
  9832. $dateHtml .= '<option ';
  9833. if ($year == $YEARD) {
  9834. $dateHtml .= 'selected ';
  9835. }
  9836. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9837. }
  9838. }
  9839. $data ['dateHtml'] = $dateHtml;
  9840. $data ['memu'] = "receipt";
  9841. $data ['staff'] = $this->staff;
  9842. $data ['receiptMemu'] = 'personalCollect';
  9843. $data ['verifyId'] = $this->verifyId;
  9844. $data ['executeId'] = $this->executeId;
  9845. // year staff status 2,4
  9846. if ($year < date ( "Y" )) {
  9847. Doo::loadModel ( 'receipt' );
  9848. $receipt = new receipt ();
  9849. $receiptList = $receipt->find ( array (
  9850. 'where' => 'staff=' . $this->staff [0] ['sid'] . ' and (status=2 or status=4) and Year(date) =' . $year,
  9851. 'asArray' => true
  9852. ) );
  9853. if (empty ( $receiptList )) {
  9854. ob_start ();
  9855. $this->render ( "/admin/saeaCollectArticles", $data );
  9856. $this->cacheFile ( $path );
  9857. die ();
  9858. }
  9859. }
  9860. $this->render ( "/admin/saeaCollectArticles", $data );
  9861. }
  9862. function companyCategoryCollect() {
  9863. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9864. $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollect_" . $year . ".htmls";
  9865. $this->showCache ( $path );
  9866. Doo::loadModel ( 'L_category' );
  9867. Doo::loadModel ( 'itemStatistics' );
  9868. Doo::loadModel ( 'statistics' );
  9869. $statistics = new statistics ();
  9870. $Lcategory = new L_category ();
  9871. $itemStatistics = new itemStatistics ();
  9872. Doo::loadModel ( "receiptAuthorityManage" );
  9873. $receiptAuthorityManage = new receiptAuthorityManage ();
  9874. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9875. $cidList = array ();
  9876. foreach ( $imcStaff as $key => $value ) {
  9877. array_push ( $cidList, $value ['cid'] );
  9878. }
  9879. $cidString = implode ( ',', $cidList );
  9880. $LcategoryList = $Lcategory->find ( array (
  9881. 'where' => ' cid in (' . $cidString . ')',
  9882. 'asArray' => true
  9883. ) ); // 'staff='.$this->staff[0]['sid']." and
  9884. $itemStatisticsList = $itemStatistics->find ( array (
  9885. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  9886. 'where' => " Year(date)=" . $year,
  9887. 'groupby' => 'cid,Month(date)',
  9888. 'asArray' => true
  9889. ) );
  9890. // ceatre companyCollectHtml
  9891. foreach ( $LcategoryList as $value ) {
  9892. $html = "";
  9893. $asum = 0;
  9894. for($i = 1; $i <= 12; $i ++) {
  9895. $falg = true;
  9896. foreach ( $itemStatisticsList as $v ) {
  9897. if ($value ['cid'] == $v ['cid'] && $i == $v ['month']) {
  9898. $asum += $v ['price'];
  9899. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  9900. $falg = false;
  9901. break;
  9902. }
  9903. }
  9904. if ($falg)
  9905. $html .= '<td class="taR">-</td>';
  9906. }
  9907. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  9908. $collectHtml [$value ['title']] = array (
  9909. 'html' => $html,
  9910. 'cid' => $value ['cid']
  9911. );
  9912. }
  9913. $data ['companyHtml'] = $collectHtml;
  9914. // total price html
  9915. $collectHtml = "";
  9916. $total = 0;
  9917. for($i = 1; $i <= 12; $i ++) {
  9918. $sumPrice = 0;
  9919. foreach ( $itemStatisticsList as $key => $value ) {
  9920. if ($value ['month'] == $i) {
  9921. $sumPrice += $value ['price'];
  9922. }
  9923. }
  9924. if ($sumPrice == 0)
  9925. $collectHtml .= '<td class="taR">-</td>';
  9926. else
  9927. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  9928. $total += $sumPrice;
  9929. }
  9930. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  9931. $data ['companyTotalHtml'] = $collectHtml;
  9932. $data ['total'] = $total;
  9933. // statistics html
  9934. // echo $cidString;
  9935. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  9936. if (empty ( $stList ))
  9937. $stList = array (
  9938. 'rePrice' => 0,
  9939. 'agPrice' => 0
  9940. );
  9941. $data ['stList'] = array (
  9942. 'rePrice' => $stList ['rePrice'],
  9943. 'agPrice' => $stList ['agPrice'],
  9944. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  9945. );
  9946. $data ['year'] = $year;
  9947. $data ['memu'] = "receipt";
  9948. $data ['staff'] = $this->staff;
  9949. $data ['receiptMemu'] = 'companyCategoryCollect';
  9950. $data ['verifyId'] = $this->verifyId;
  9951. $data ['executeId'] = $this->executeId;
  9952. $dateHtml = "";
  9953. $now = date ( "Y" );
  9954. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  9955. if ($YEARD <= $now) {
  9956. $dateHtml .= '<option ';
  9957. if ($year == $YEARD) {
  9958. $dateHtml .= 'selected ';
  9959. }
  9960. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  9961. }
  9962. }
  9963. $data ['dateHtml'] = $dateHtml;
  9964. // year staff status 2,4
  9965. if ($year < date ( "Y" )) {
  9966. Doo::loadModel ( 'receipt' );
  9967. $receipt = new receipt ();
  9968. $receiptList = $receipt->find ( array (
  9969. 'where' => 'Year(date) =' . $year . ' and (status=2 or status=4)',
  9970. 'asArray' => true
  9971. ) );
  9972. if (empty ( $receiptList )) {
  9973. ob_start ();
  9974. $this->render ( "/admin/saeaCompanyCollect", $data );
  9975. $this->cacheFile ( $path );
  9976. die ();
  9977. }
  9978. }
  9979. $this->render ( "/admin/saeaCompanyCollect", $data );
  9980. }
  9981. function categoryCollectDetail() {
  9982. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  9983. $cid = isset ( $this->params ['cid'] ) && is_numeric ( $this->params ['cid'] ) ? $this->params ['cid'] : 0;
  9984. /* $path = SITE_PATH . $this->CATEGORYCOLLECTPATH . "categoryCollectDetail_" . $year . "_" . $cid . ".htmls";
  9985. $this->showCache ( $path ); */
  9986. Doo::loadModel ( 'statistics' );
  9987. $statistics = new statistics ();
  9988. Doo::loadModel ( "receiptDetail" );
  9989. $receiptDetail = new receiptDetail ();
  9990. Doo::loadModel ( 'L_category' );
  9991. $Lcategory = new L_category ();
  9992. Doo::loadModel ( 'accountItem' );
  9993. $accountItem = new accountItem ();
  9994. Doo::loadModel ( "receiptAuthorityManage" );
  9995. $receiptAuthorityManage = new receiptAuthorityManage ();
  9996. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  9997. $cidList = array ();
  9998. foreach ( $imcStaff as $key => $value ) {
  9999. array_push ( $cidList, $value ['cid'] );
  10000. }
  10001. $cidString = implode ( ',', $cidList );
  10002. $LcategoryList = $Lcategory->find ( array (
  10003. 'where' => 'cid in (' . $cidString . ')',
  10004. 'asArray' => true
  10005. ) );
  10006. if ($cid == 0) {
  10007. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  10008. if ($cid == 0)
  10009. $cid = $LcategoryList [0] ['cid'];
  10010. }
  10011. $data ['LcategoryList'] = $LcategoryList;
  10012. $receiptCollectList = $receiptDetail->find ( array (
  10013. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  10014. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  10015. 'groupby' => 'item,Month(pastDate)',
  10016. 'asArray' => true
  10017. ) );
  10018. $accountList = $accountItem->find ( array (
  10019. 'asArray' => true
  10020. ) );
  10021. // create CollectDetail HTML
  10022. $collectHtml = array ();
  10023. foreach ( $accountList as $key => $value ) {
  10024. $html = "";
  10025. $asum = 0;
  10026. for($i = 1; $i <= 12; $i ++) {
  10027. $falg = true;
  10028. foreach ( $receiptCollectList as $v ) {
  10029. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  10030. $asum += $v ['price'];
  10031. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  10032. $falg = false;
  10033. break;
  10034. }
  10035. }
  10036. if ($falg)
  10037. $html .= '<td class="taR">-</td>';
  10038. }
  10039. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  10040. $collectHtml [$value ['category']] [$value ['name']] = $html;
  10041. }
  10042. $data ['collectHtml'] = $collectHtml;
  10043. // create Adjustment price html
  10044. $receiptCollectList = $receiptDetail->find ( array (
  10045. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  10046. 'where' => 'cid=' . $cid . " and status=1 and Year(pastDate)=" . $year,
  10047. 'groupby' => 'itemCategory,Month(pastDate)',
  10048. 'asArray' => true
  10049. ) );
  10050. $adjustment = array ();
  10051. $collectArray = array (
  10052. '日常相关费用' => array (),
  10053. '差旅相关费用' => array (),
  10054. '培训班费用' => array (),
  10055. '内部培训费用'=>array(),
  10056. '其他' => array ()
  10057. );
  10058. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  10059. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  10060. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  10061. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  10062. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  10063. array_push ( $collectArray ['培训班费用'], $collectHtml );
  10064. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  10065. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  10066. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  10067. array_push ( $collectArray ['其他'], $collectHtml );
  10068. $data ['collectArray'] = $collectArray;
  10069. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  10070. array_push ( $adjustment, $collectHtml );
  10071. $data ['adjustment'] = $adjustment;
  10072. // total price html
  10073. $collectHtml = "";
  10074. $total = 0;
  10075. for($i = 1; $i <= 12; $i ++) {
  10076. $sumPrice = 0;
  10077. foreach ( $receiptCollectList as $key => $value ) {
  10078. if ($value ['month'] == $i) {
  10079. $sumPrice += $value ['price'];
  10080. }
  10081. }
  10082. if ($sumPrice == 0)
  10083. $collectHtml .= '<td class="taR">-</td>';
  10084. else
  10085. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  10086. $total += $sumPrice;
  10087. }
  10088. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  10089. // statistics html
  10090. $stList = $statistics->statisticsByCid ( $year, $cid );
  10091. if (empty ( $stList ))
  10092. $stList = array (
  10093. 'rePrice' => 0,
  10094. 'agPrice' => 0
  10095. );
  10096. $data ['stList'] = array (
  10097. 'rePrice' => $stList ['rePrice'],
  10098. 'agPrice' => $stList ['agPrice'],
  10099. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10100. );
  10101. $data ['totalYear'] = $total;
  10102. $data ['year'] = $year;
  10103. $data ['cid'] = $cid;
  10104. $data ['memu'] = "receipt";
  10105. $data ['staff'] = $this->staff;
  10106. $data ['receiptMemu'] = 'companyCategoryCollect';
  10107. $data ['verifyId'] = $this->verifyId;
  10108. $data ['executeId'] = $this->executeId;
  10109. // year staff status 2,4
  10110. /* if ($year < date ( "Y" )) {
  10111. Doo::loadModel ( 'receipt' );
  10112. $receipt = new receipt ();
  10113. $receiptList = $receipt->find ( array (
  10114. 'where' => 'Year(date) =' . $year . ' and cid =' . $cid . ' and (status=2 or status=4)',
  10115. 'asArray' => true
  10116. ) );
  10117. if (empty ( $receiptList )) {
  10118. ob_start ();
  10119. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  10120. $this->cacheFile ( $path );
  10121. die ();
  10122. }
  10123. } */
  10124. $dateHtml = "";
  10125. $now = date ( "Y" );
  10126. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  10127. if ($YEARD <= $now) {
  10128. $dateHtml .= '<option ';
  10129. if ($year == $YEARD) {
  10130. $dateHtml .= 'selected ';
  10131. }
  10132. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  10133. }
  10134. }
  10135. $data ['dateHtml'] = $dateHtml;
  10136. $this->render ( "/admin/saeaCategoryCollectDetail", $data );
  10137. }
  10138. function staffCollect() {
  10139. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10140. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : 'ONJOB';//
  10141. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_.htmls";
  10142. // $this->showCache($path);
  10143. Doo::loadModel ( 'statistics' );
  10144. $statistics = new statistics ();
  10145. Doo::loadModel ( "receiptDetail" );
  10146. $receiptDetail = new receiptDetail ();
  10147. Doo::loadModel ( 'L_category' );
  10148. $Lcategory = new L_category ();
  10149. Doo::loadModel ( 'accountItem' );
  10150. $accountItem = new accountItem ();
  10151. Doo::loadModel ( 'staff' );
  10152. $staff = new staff ();
  10153. Doo::loadModel ( 'itemStatistics' );
  10154. $itemStatistics = new itemStatistics ();
  10155. Doo::loadModel ( "receiptAuthorityManage" );
  10156. $receiptAuthorityManage = new receiptAuthorityManage ();
  10157. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  10158. $cidList = array ();
  10159. foreach ( $imcStaff as $key => $value ) {
  10160. array_push ( $cidList, $value ['cid'] );
  10161. }
  10162. $cidString = implode ( ',', $cidList );
  10163. $naturecon='';
  10164. if ($nature=='ONJOB'){
  10165. $naturecon=' and (nature!=4 )';
  10166. }elseif($nature=='LEAVEJOB'){
  10167. $naturecon=' and (nature=4 )';
  10168. }else{
  10169. die ( 'illegal request--nature' );
  10170. }
  10171. // statistics html
  10172. $stList = $statistics->statisticsByComPanyYear ( $year, $this->staff [0] ['sid'], $cidString );
  10173. if (empty ( $stList ))
  10174. $stList = array (
  10175. 'rePrice' => 0,
  10176. 'agPrice' => 0
  10177. );
  10178. $data ['stList'] = array (
  10179. 'rePrice' => $stList ['rePrice'],
  10180. 'agPrice' => $stList ['agPrice'],
  10181. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10182. );
  10183. // ---
  10184. $staffList = $staff->find ( array (
  10185. 'where' => 'username !="admin" '.$naturecon,
  10186. 'asArray' => true
  10187. ) );
  10188. $LcategoryList = $Lcategory->find ( array (
  10189. 'asArray' => true
  10190. ) ); // 'staff='.$this->staff[0]['sid']." and
  10191. $itemStatisticsList = $itemStatistics->find ( array (
  10192. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10193. 'where' => " Year(date)=" . $year . ' and cid in (' . $cidString . ')',
  10194. 'groupby' => 'staff,Month(date)',
  10195. 'asArray' => true
  10196. ) );
  10197. $categoryList = $staff->find ( array (
  10198. 'select' => 'COUNT(*) as count,cid,category',
  10199. 'where' => 'username !="admin" and cid in (' . $cidString . ') '.$naturecon,
  10200. 'groupby' => 'cid',
  10201. 'asArray' => true
  10202. ) );
  10203. // print_r($itemStatisticsList);die;
  10204. // ceatre companyCollectHtml
  10205. foreach ( $categoryList as $vlu ) {
  10206. $count = $vlu ['count'] + 1;
  10207. $html = '<th rowspan="' . $count . '">' . $vlu ['category'] . '</th>';
  10208. $m1 = 0;
  10209. $m2 = 0;
  10210. $m3 = 0;
  10211. $m4 = 0;
  10212. $m5 = 0;
  10213. $m6 = 0;
  10214. $m7 = 0;
  10215. $m8 = 0;
  10216. $m9 = 0;
  10217. $m10 = 0;
  10218. $m11 = 0;
  10219. $m12 = 0;
  10220. $m13 = 0;
  10221. foreach ( $staffList as $value ) {
  10222. if ($vlu ['cid'] == $value ['cid']) {
  10223. $html .= '<td><a href="/staffCollectDetail/' . $value ['username'] . '">' . $value ['username'] . '</a></td>';
  10224. $asum = 0;
  10225. for($i = 1; $i <= 12; $i ++) {
  10226. $falg = true;
  10227. foreach ( $itemStatisticsList as $v ) {
  10228. if ($value ['sid'] == $v ['staff'] && $i == $v ['month']) {
  10229. if ($v ['month'] == 1)
  10230. $m1 += $v ['price'];
  10231. if ($v ['month'] == 2)
  10232. $m2 += $v ['price'];
  10233. if ($v ['month'] == 3)
  10234. $m3 += $v ['price'];
  10235. if ($v ['month'] == 4)
  10236. $m4 += $v ['price'];
  10237. if ($v ['month'] == 5)
  10238. $m5 += $v ['price'];
  10239. if ($v ['month'] == 6)
  10240. $m6 += $v ['price'];
  10241. if ($v ['month'] == 7)
  10242. $m7 += $v ['price'];
  10243. if ($v ['month'] == 8)
  10244. $m8 += $v ['price'];
  10245. if ($v ['month'] == 9)
  10246. $m9 += $v ['price'];
  10247. if ($v ['month'] == 10)
  10248. $m10 += $v ['price'];
  10249. if ($v ['month'] == 11)
  10250. $m11 += $v ['price'];
  10251. if ($v ['month'] == 12)
  10252. $m12 += $v ['price'];
  10253. $asum += $v ['price'];
  10254. $html .= '<td class="taR">¥' . $v ['price'] . '</td>';
  10255. $falg = false;
  10256. break;
  10257. }
  10258. }
  10259. if ($falg)
  10260. $html .= '<td class="taR">-</td>';
  10261. }
  10262. $m13 += $asum;
  10263. $html .= '<td class="taR colGreen"><b>¥' . $asum . '</b></td>';
  10264. $collectHtml [$value ['username'] . '_' . $value ['sid']] = array (
  10265. 'html' => $html,
  10266. 'sid' => $value ['sid']
  10267. );
  10268. $html = "";
  10269. }
  10270. }
  10271. $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>
  10272. <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>
  10273. <td class="taR">¥' . $m12 . '</td><td class="taR">¥' . $m13 . '</td>';
  10274. $collectHtml [$vlu ['cid']] = array (
  10275. 'html' => $hl,
  10276. 'sid' => ''
  10277. );
  10278. }
  10279. $data ['companyHtml'] = $collectHtml;
  10280. // total price html
  10281. $collectHtml = "";
  10282. $total = 0;
  10283. for($i = 1; $i <= 12; $i ++) {
  10284. $sumPrice = 0;
  10285. foreach ( $itemStatisticsList as $key => $value ) {
  10286. if ($value ['month'] == $i) {
  10287. $sumPrice += $value ['price'];
  10288. }
  10289. }
  10290. if ($sumPrice == 0)
  10291. $collectHtml .= '<td class="taR">-</td>';
  10292. else
  10293. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  10294. $total += $sumPrice;
  10295. }
  10296. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  10297. $data ['companyTotalHtml'] = $collectHtml;
  10298. $data ['total'] = $total;
  10299. $data ['nature'] =$nature;
  10300. $data ['year'] = $year;
  10301. $data ['memu'] = "receipt";
  10302. $data ['staff'] = $this->staff;
  10303. $data ['receiptMemu'] = 'companyCategoryCollect';
  10304. $data ['verifyId'] = $this->verifyId;
  10305. $data ['executeId'] = $this->executeId;
  10306. if ($year <= date ( "Y" )) {
  10307. Doo::loadModel ( 'receipt' );
  10308. $receipt = new receipt ();
  10309. $receiptList = $receipt->find ( array (
  10310. 'where' => '(status=2 or status=4) and Year(date) =' . $year,
  10311. 'asArray' => true
  10312. ) );
  10313. if (empty ( $receiptList )) { // generated files
  10314. ob_start ();
  10315. $this->render ( "/admin/saeaStaffCollectB", $data );
  10316. $this->cacheFile ( $path );
  10317. die ();
  10318. }
  10319. }
  10320. $this->render ( "/admin/saeaStaffCollectB", $data );
  10321. }
  10322. function staffCollectBak() {
  10323. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  10324. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : 1;
  10325. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollect_" . $year . "_" . $month . ".htmls";
  10326. $this->showCache ( $path );
  10327. Doo::loadModel ( 'statistics' );
  10328. $statistics = new statistics ();
  10329. Doo::loadModel ( "receiptDetail" );
  10330. $receiptDetail = new receiptDetail ();
  10331. Doo::loadModel ( 'L_category' );
  10332. $Lcategory = new L_category ();
  10333. Doo::loadModel ( 'accountItem' );
  10334. $accountItem = new accountItem ();
  10335. Doo::loadModel ( 'staff' );
  10336. $staff = new staff ();
  10337. Doo::loadModel ( 'itemStatistics' );
  10338. $itemStatistics = new itemStatistics ();
  10339. $itemStatisticsList = $itemStatistics->find ( array (
  10340. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10341. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10342. 'groupby' => 'staff,itemCategory,Month(date)',
  10343. 'asArray' => true
  10344. ) );
  10345. $itemCategoryList = $itemStatistics->find ( array (
  10346. 'select' => 'cid,staff,sum(price) as price,itemCategory,Month(date) as month',
  10347. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10348. 'groupby' => 'cid,itemCategory,Month(date)',
  10349. 'asArray' => true
  10350. ) );
  10351. $LcategoryList = $Lcategory->find ( array (
  10352. 'asArray' => true
  10353. ) );
  10354. $staffList = $staff->find ( array (
  10355. 'asArray' => true
  10356. ) );
  10357. $htmlArray = array ();
  10358. foreach ( $LcategoryList as $value ) {
  10359. $htmlArray [$value ['title']] = array ();
  10360. foreach ( $staffList as $v ) {
  10361. if ($value ['cid'] == $v ['cid']) {
  10362. $html = "";
  10363. $falg = true;
  10364. $staffSumPrice = 0;
  10365. foreach ( $itemStatisticsList as $a ) {
  10366. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "日常相关费用") {
  10367. if (empty ( $a ['price'] )) {
  10368. $html .= '<td class="taR">-</td>';
  10369. $falg = false;
  10370. break;
  10371. } else {
  10372. $staffSumPrice += $a ['price'];
  10373. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10374. $falg = false;
  10375. break;
  10376. }
  10377. }
  10378. }
  10379. if ($falg) {
  10380. $html .= '<td class="taR">-</td>';
  10381. $falg = true;
  10382. }
  10383. $falg = true;
  10384. foreach ( $itemStatisticsList as $a ) {
  10385. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "差旅相关费用") {
  10386. if (empty ( $a ['price'] )) {
  10387. $html .= '<td class="taR">-</td>';
  10388. $falg = false;
  10389. break;
  10390. } else {
  10391. $staffSumPrice += $a ['price'];
  10392. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10393. $falg = false;
  10394. break;
  10395. }
  10396. }
  10397. }
  10398. if ($falg) {
  10399. $html .= '<td class="taR">-</td>';
  10400. $falg = true;
  10401. }
  10402. $falg = true;
  10403. foreach ( $itemStatisticsList as $a ) {
  10404. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "培训班费用") {
  10405. if (empty ( $a ['price'] )) {
  10406. $html .= '<td class="taR">-</td>';
  10407. $falg = false;
  10408. break;
  10409. } else {
  10410. $staffSumPrice += $a ['price'];
  10411. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10412. $falg = false;
  10413. break;
  10414. }
  10415. }
  10416. }
  10417. if ($falg) {
  10418. $html .= '<td class="taR">-</td>';
  10419. $falg = true;
  10420. }
  10421. $falg = true;
  10422. foreach ( $itemStatisticsList as $a ) {
  10423. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "其他") {
  10424. if (! empty ( $a ['price'] )) {
  10425. $staffSumPrice += $a ['price'];
  10426. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10427. $falg = false;
  10428. break;
  10429. } else {
  10430. $html .= '<td class="taR">-</td>';
  10431. $falg = false;
  10432. break;
  10433. }
  10434. }
  10435. }
  10436. if ($falg) {
  10437. $html .= '<td class="taR">-</td>';
  10438. $falg = true;
  10439. }
  10440. $falg = true;
  10441. foreach ( $itemStatisticsList as $a ) {
  10442. if ($v ['sid'] == $a ['staff'] && $a ['itemCategory'] == "报销金额调整") {
  10443. if (! empty ( $a ['price'] )) {
  10444. $staffSumPrice += $a ['price'];
  10445. $html .= '<td class="taR">¥' . $a ['price'] . '</td>';
  10446. $falg = false;
  10447. break;
  10448. } else {
  10449. $html .= '<td class="taR">-</td>';
  10450. $falg = false;
  10451. break;
  10452. }
  10453. }
  10454. }
  10455. if ($falg) {
  10456. $html .= '<td class="taR">-</td>';
  10457. $falg = true;
  10458. }
  10459. $html .= '<td class="colGreen taR">¥' . $staffSumPrice . '</td>';
  10460. $htmlArray [$value ['title']] [$v ['username']] = $html;
  10461. }
  10462. }
  10463. /* -- --- */
  10464. // 合计费用
  10465. $cateHtml = "";
  10466. $catePrice = 0;
  10467. $cateFalg = true;
  10468. foreach ( $itemCategoryList as $l ) {
  10469. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "日常相关费用") {
  10470. if (empty ( $l ['price'] )) {
  10471. $cateHtml .= '<td class="colGreen taR">-</td>';
  10472. $cateFalg = false;
  10473. break;
  10474. } else {
  10475. $catePrice += $l ['price'];
  10476. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10477. $cateFalg = false;
  10478. break;
  10479. }
  10480. }
  10481. }
  10482. if ($cateFalg) {
  10483. $cateHtml .= '<td class="colGreen taR">-</td>';
  10484. $cateFalg = true;
  10485. }
  10486. $cateFalg = true;
  10487. foreach ( $itemCategoryList as $l ) {
  10488. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "差旅相关费用") {
  10489. if (empty ( $l ['price'] )) {
  10490. $cateHtml .= '<td class="colGreen taR">-</td>';
  10491. $cateFalg = false;
  10492. break;
  10493. } else {
  10494. $catePrice += $l ['price'];
  10495. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10496. $cateFalg = false;
  10497. break;
  10498. }
  10499. }
  10500. }
  10501. if ($cateFalg) {
  10502. $cateHtml .= '<td class="colGreen taR">-</td>';
  10503. $cateFalg = true;
  10504. }
  10505. $cateFalg = true;
  10506. foreach ( $itemCategoryList as $l ) {
  10507. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "培训班费用") {
  10508. if (empty ( $l ['price'] )) {
  10509. $cateHtml .= '<td class="colGreen taR">-</td>';
  10510. $cateFalg = false;
  10511. break;
  10512. } else {
  10513. $catePrice += $l ['price'];
  10514. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10515. $cateFalg = false;
  10516. break;
  10517. }
  10518. }
  10519. }
  10520. if ($cateFalg) {
  10521. $cateHtml .= '<td class="colGreen taR">-</td>';
  10522. $cateFalg = true;
  10523. }
  10524. $cateFalg = true;
  10525. foreach ( $itemCategoryList as $l ) {
  10526. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "其他") {
  10527. if (empty ( $l ['price'] )) {
  10528. $cateHtml .= '<td class="colGreen taR">-</td>';
  10529. $cateFalg = false;
  10530. break;
  10531. } else {
  10532. $catePrice += $l ['price'];
  10533. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10534. $cateFalg = false;
  10535. break;
  10536. }
  10537. }
  10538. }
  10539. if ($cateFalg) {
  10540. $cateHtml .= '<td class="colGreen taR">-</td>';
  10541. $cateFalg = true;
  10542. }
  10543. $cateFalg = true;
  10544. foreach ( $itemCategoryList as $l ) {
  10545. if ($value ['cid'] == $l ['cid'] && $l ['itemCategory'] == "报销金额调整") {
  10546. if (empty ( $l ['price'] )) {
  10547. $cateHtml .= '<td class="colGreen taR">-</td>';
  10548. $cateFalg = false;
  10549. break;
  10550. } else {
  10551. $catePrice += $l ['price'];
  10552. $cateHtml .= '<td class="colGreen taR">¥' . $l ['price'] . '</td>';
  10553. $cateFalg = false;
  10554. break;
  10555. }
  10556. }
  10557. }
  10558. if ($cateFalg) {
  10559. $cateHtml .= '<td class="colGreen taR">-</td>';
  10560. $cateFalg = true;
  10561. }
  10562. $cateHtml .= '<td class="colGreen taR">¥' . $catePrice . '</td>';
  10563. $htmlArray [$value ['title']] ['合计'] = $cateHtml;
  10564. /* -- --- */
  10565. }
  10566. // print_r($htmlArray);die;
  10567. $data ['htmlArray'] = $htmlArray;
  10568. // statistics html
  10569. $stList = $statistics->getOne ( array (
  10570. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  10571. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  10572. 'groupby' => 'Month(date)',
  10573. 'asArray' => true
  10574. ) );
  10575. if (empty ( $stList ))
  10576. $stList = array (
  10577. 'rePrice' => 0,
  10578. 'agPrice' => 0
  10579. );
  10580. $data ['stList'] = array (
  10581. 'rePrice' => $stList ['rePrice'],
  10582. 'agPrice' => $stList ['agPrice'],
  10583. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  10584. );
  10585. $monthHtml = "";
  10586. for($i = 1; $i <= 12; $i ++) {
  10587. if ($i == $month)
  10588. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  10589. else
  10590. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  10591. }
  10592. $data ['monthHtml'] = $monthHtml;
  10593. $data ['year'] = $year;
  10594. $data ['month'] = $month;
  10595. $data ['memu'] = "receipt";
  10596. $data ['staff'] = $this->staff;
  10597. $data ['receiptMemu'] = 'companyCategoryCollect';
  10598. $data ['verifyId'] = $this->verifyId;
  10599. $data ['executeId'] = $this->executeId;
  10600. if (! empty ( $month ) && ($year <= date ( "Y" )) && ($month < date ( "m" ))) {
  10601. Doo::loadModel ( 'receipt' );
  10602. $receipt = new receipt ();
  10603. $receiptList = $receipt->find ( array (
  10604. 'where' => '(status=2 or status=4) and Year(date) =' . $year . ' and Month(date) =' . $month,
  10605. 'asArray' => true
  10606. ) );
  10607. if (empty ( $receiptList )) { // generated files
  10608. ob_start ();
  10609. $this->render ( "/admin/saeaStaffCollect", $data );
  10610. $this->cacheFile ( $path );
  10611. die ();
  10612. }
  10613. }
  10614. $this->render ( "/admin/saeaStaffCollect", $data );
  10615. }
  10616. /**
  10617. * 日常收支
  10618. */
  10619. function payments() {
  10620. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  10621. Doo::loadModel ( "execute" );
  10622. $execute = new execute ();
  10623. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  10624. die ( 'illegal request' );
  10625. }
  10626. Doo::loadModel ( "accountBook" );
  10627. $accountBook = new accountBook ();
  10628. Doo::loadModel ( "accountBookStatistics" );
  10629. $accountBookStatistics = new accountBookStatistics ();
  10630. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  10631. $list = $accountBook->getAccountBookByLimit ( 10 );
  10632. $data ['date'] = date ( "Y-m-d" );
  10633. $data ['statisticsList'] = $statisticsList;
  10634. $data ['list'] = $list;
  10635. $data ['memu'] = "receipt";
  10636. $data ['staff'] = $this->staff;
  10637. $data ['receiptMemu'] = 'payments';
  10638. $data ['verifyId'] = $this->verifyId;
  10639. $data ['executeId'] = $this->executeId;
  10640. $this->render ( "/expenses/payments", $data );
  10641. }
  10642. function paymentsIncomeDo() {
  10643. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  10644. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  10645. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  10646. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  10647. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  10648. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  10649. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10650. if (! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  10651. Doo::loadClass ( 'XDeode' );
  10652. $XDeode = new XDeode ( 5 );
  10653. Doo::loadModel ( "accountBook" );
  10654. Doo::loadModel ( "accountBookStatistics" );
  10655. Doo::loadModel ( 'wasteBook' );
  10656. // 记录流水时银行的转换
  10657. $accountBank = '';
  10658. if ($receivedBank == '纵横广发') {
  10659. $accountBank = 'CGBDeposit';
  10660. } elseif ($receivedBank == '纵横工行') {
  10661. $accountBank = 'ICBCDeposit';
  10662. } elseif ($receivedBank == '华润银行') {
  10663. $accountBank = 'HUADeposit';
  10664. } elseif ($receivedBank == '个人广发') {
  10665. $accountBank = 'PersonalDeposit';
  10666. }
  10667. if (empty ( $accountBank ))
  10668. die ( 'illegal request-bank' );
  10669. //TODO -存款功能 提取
  10670. if($accountType == 11 || $accountType == 12){
  10671. if($accountType == 11){
  10672. $receivedBank = '纵横广发';
  10673. }elseif($accountType == 12){
  10674. $receivedBank = '纵横工行';
  10675. }
  10676. // 添加一条收入
  10677. $accountBook = new accountBook ();
  10678. $accountBook->accountType = $accountType;
  10679. $accountBook->accountMsg = $accountMsg;
  10680. $accountBook->receivedPrice = $receivedPrice;
  10681. $accountBook->receivedMsg = $receivedMsg;
  10682. $accountBook->receivedBank = $receivedBank;
  10683. $accountBook->receivedDate = $receivedDate;
  10684. $accountBook->remarks = $remarks;
  10685. $accountBook->expensesType = 1;
  10686. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10687. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10688. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10689. $inComeId = $accountBook->insert ();
  10690. // 收支汇总-添加一条收入日常汇总
  10691. $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  10692. $accountBookStatistics = new accountBookStatistics ();
  10693. $item = array (
  10694. 'date' => date ( "Y-m-d" ),
  10695. 'accountType' => $abDetail ['accountType'],
  10696. 'accountMsg' => $abDetail ['accountMsg'],
  10697. 'aid' => $abDetail ['aid'],
  10698. 'inComePrice' => $abDetail ['receivedPrice'],
  10699. 'expensesType' => $abDetail ['expensesType']
  10700. );
  10701. $accountBookStatistics->setAccountBookStatistics ( $item );
  10702. // 添加收入流水
  10703. if($accountType == 11){
  10704. $accountBank = 'CGBDeposit';
  10705. }elseif($accountType == 12){
  10706. $accountBank = 'ICBCDeposit';
  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' => $receivedDate,
  10722. 'createAt'=>date ( "Y-m-d H:i:s" ),
  10723. 'synPaymentDate'=>1,
  10724. );
  10725. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10726. }
  10727. //TODO --移除理财相关
  10728. // elseif($accountType == 7 || $accountType == 9) { // 收入为理财时特殊处理
  10729. // // if ($receivedBank == '个人广发') {
  10730. // // die ( '个人广发 illegal request' );
  10731. // // }
  10732. // // echo $receivedBank;
  10733. // die;
  10734. // // 添加一条收入
  10735. // $accountBook = new accountBook ();
  10736. // $accountBook->accountType = 10;
  10737. // $accountBook->accountMsg = $accountMsg;
  10738. // $accountBook->receivedPrice = $receivedPrice;
  10739. // $accountBook->receivedMsg = $receivedMsg;
  10740. // $accountBook->receivedBank = $receivedBank;
  10741. // $accountBook->receivedDate = $receivedDate;
  10742. // $accountBook->remarks = $remarks;
  10743. // $accountBook->expensesType = 1;
  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. // $inComeId = $accountBook->insert ();
  10748. // // 收支汇总-添加一条收入日常汇总
  10749. // $abDetail = $accountBook->getAccountBookByAid ( $inComeId );
  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. // 'inComePrice' => $abDetail ['receivedPrice'],
  10757. // 'expensesType' => $abDetail ['expensesType']
  10758. // );
  10759. // $accountBookStatistics->setAccountBookStatistics ( $item );
  10760. // // 添加收入流水
  10761. // $wasteBook = new wasteBook ();
  10762. // $itemWaste = array (
  10763. // 'accountPriceShow' => $receivedPrice,
  10764. // 'accountPrice' => $receivedPrice,
  10765. // 'expensesType' => 1,
  10766. // 'accountType' => 6, // 流水类型
  10767. // 'dataID' => $inComeId,
  10768. // 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10769. // 'accountBank' => $accountBank,
  10770. // 'category' => $this->staff [0] ['category'],
  10771. // 'cid' => $this->staff [0] ['cid'],
  10772. // 'name' => $this->staff [0] ['username'],
  10773. // 'sid' => $this->staff [0] ['sid'],
  10774. // 'inputDate' => date ( "Y-m-d H:i:s" )
  10775. // );
  10776. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  10777. // // 添加一条理财支出
  10778. // $accountBank = 'CGBDeposit';
  10779. // $expenditureBank = '纵横广发';
  10780. // if($accountMsg=='个人(GR)'){
  10781. // $expenditureBank = '个人广发';
  10782. // }
  10783. // $dailyExpenditureType = 4;
  10784. // if ($accountType == 9) {
  10785. // $accountBank = 'ICBCDeposit';
  10786. // $expenditureBank = '纵横工行';
  10787. // $dailyExpenditureType = 6;
  10788. // }
  10789. // $accountBook = new accountBook ();
  10790. // $accountBook->expensesType = 2;
  10791. // $accountBook->expenditureType = $dailyExpenditureType;
  10792. // $accountBook->expenditureMsg = $accountMsg;
  10793. // $accountBook->expenditurePrice = $receivedPrice;
  10794. // $accountBook->expenditureBank = $expenditureBank;
  10795. // $accountBook->expenditureDate = $receivedDate;
  10796. // $accountBook->remarks = $remarks;
  10797. // $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10798. // $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10799. // $accountBook->inputStaff = $this->staff [0] ['sid'];
  10800. // $id = $accountBook->insert ();
  10801. // // 收支汇总-添加一条理财支出汇总
  10802. // $abDetail = $accountBook->getAccountBookByAid ( $id );
  10803. // $accountBookStatistics = new accountBookStatistics ();
  10804. // $item = array (
  10805. // 'date' => date ( "Y-m-d" ),
  10806. // 'accountType' => $abDetail ['accountType'],
  10807. // 'accountMsg' => $abDetail ['accountMsg'],
  10808. // 'aid' => $abDetail ['aid'],
  10809. // 'financingPrice' => - $receivedPrice,
  10810. // 'expensesType' => 3
  10811. // );
  10812. // $accountBookStatistics->setAccountBookStatistics ( $item );
  10813. // //TODO -新增理财为个人时的情况 添加一条支出理财流水
  10814. // $accountTypeWaste = 5;
  10815. // if ($accountMsg == '公司固定') {
  10816. // $accountTypeWaste = 9;
  10817. // } elseif ($accountMsg == '公司活期') {
  10818. // $accountTypeWaste = 10;
  10819. // } elseif ($receivedBank == '个人广发') {
  10820. // $accountTypeWaste = 9;
  10821. // $accountBank = 'ICBCDeposit';
  10822. // }
  10823. // $itemWaste = array (
  10824. // 'expensesType' => 2,
  10825. // 'accountType' => $accountTypeWaste,
  10826. // 'accountPriceShow' => $receivedPrice,
  10827. // 'accountPrice' => - $receivedPrice,
  10828. // 'dataID' => $id,
  10829. // 'dailyExpenditureType' => $dailyExpenditureType,
  10830. // 'accountBank' => $accountBank,
  10831. // 'category' => $this->staff [0] ['category'],
  10832. // 'cid' => $this->staff [0] ['cid'],
  10833. // 'name' => $this->staff [0] ['username'],
  10834. // 'sid' => $this->staff [0] ['sid'],
  10835. // 'inputDate' => date ( "Y-m-d H:i:s" )
  10836. // );
  10837. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  10838. // }
  10839. elseif ($accountType == 1) {
  10840. // if ($receivedBank == '个人广发')
  10841. // die ( 'illegal request--no man' );
  10842. // 添加一条收入
  10843. $accountBook = new accountBook ();
  10844. $accountBook->accountType = $accountType;
  10845. $accountBook->accountMsg = $accountMsg;
  10846. $accountBook->receivedPrice = $receivedPrice;
  10847. $accountBook->receivedMsg = $receivedMsg;
  10848. $accountBook->receivedBank = $receivedBank;
  10849. $accountBook->receivedDate = $receivedDate;
  10850. $accountBook->remarks = $remarks;
  10851. $accountBook->expensesType = 1;
  10852. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10853. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10854. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10855. $id = $accountBook->insert ();
  10856. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10857. // 收支汇总-添加一条收入日常汇总
  10858. $accountBookStatistics = new accountBookStatistics ();
  10859. $item = array (
  10860. 'date' => date ( "Y-m-d" ),
  10861. 'accountType' => $abDetail ['accountType'],
  10862. 'accountMsg' => $abDetail ['accountMsg'],
  10863. 'aid' => $abDetail ['aid'],
  10864. 'expensesType' => $abDetail ['expensesType']
  10865. );
  10866. if ($abDetail ['accountType'] == 8) {
  10867. $item += array (
  10868. 'inComePrice' => $abDetail ['receivedPrice']
  10869. );
  10870. } else {
  10871. $item += array (
  10872. 'inComePrice' => $abDetail ['receivedPrice']
  10873. );
  10874. }
  10875. $accountBookStatistics->setAccountBookStatistics ( $item );
  10876. // 流水存储方向
  10877. $itemWaste = array (
  10878. 'accountType' => 6
  10879. ); // 流水类型
  10880. // if($accountMsg=='银行存款'||$accountMsg=='固定理财收益'){
  10881. // }else
  10882. if ($accountMsg == '活期理财收益') {
  10883. $itemWaste = array (
  10884. 'accountType' => 10
  10885. ); // 流水类型
  10886. }
  10887. // 添加收入流水
  10888. $wasteBook = new wasteBook ();
  10889. $itemWaste += array (
  10890. 'accountPrice' => $receivedPrice,
  10891. 'accountPriceShow' => $receivedPrice,
  10892. 'expensesType' => 1,
  10893. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10894. 'dataID' => $id,
  10895. 'accountBank' => $accountBank,
  10896. 'category' => $this->staff [0] ['category'],
  10897. 'cid' => $this->staff [0] ['cid'],
  10898. 'name' => $this->staff [0] ['username'],
  10899. 'sid' => $this->staff [0] ['sid'],
  10900. 'inputDate' => $receivedDate,
  10901. 'createAt'=>date ( "Y-m-d H:i:s" ),
  10902. 'synPaymentDate'=>1,
  10903. );
  10904. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10905. } else { // 普通日常收入处理
  10906. // 添加一条收入
  10907. $accountBook = new accountBook ();
  10908. $accountBook->accountType = $accountType;
  10909. $accountBook->accountMsg = $accountMsg;
  10910. $accountBook->receivedPrice = $receivedPrice;
  10911. $accountBook->receivedMsg = $receivedMsg;
  10912. $accountBook->receivedBank = $receivedBank;
  10913. $accountBook->receivedDate = $receivedDate;
  10914. $accountBook->remarks = $remarks;
  10915. $accountBook->expensesType = 1;
  10916. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  10917. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  10918. $accountBook->inputStaff = $this->staff [0] ['sid'];
  10919. $id = $accountBook->insert ();
  10920. $abDetail = $accountBook->getAccountBookByAid ( $id );
  10921. // 收支汇总-添加一条收入日常汇总
  10922. $accountBookStatistics = new accountBookStatistics ();
  10923. $item = array (
  10924. 'date' => date ( "Y-m-d" ),
  10925. 'accountType' => $abDetail ['accountType'],
  10926. 'accountMsg' => $abDetail ['accountMsg'],
  10927. 'aid' => $abDetail ['aid'],
  10928. 'expensesType' => $abDetail ['expensesType']
  10929. );
  10930. if ($abDetail ['accountType'] == 8) {
  10931. $item += array (
  10932. 'inComePrice' => $abDetail ['receivedPrice']
  10933. );
  10934. } else {
  10935. $item += array (
  10936. 'inComePrice' => $abDetail ['receivedPrice']
  10937. );
  10938. }
  10939. $accountBookStatistics->setAccountBookStatistics ( $item );
  10940. // 添加收入流水
  10941. // $itemWaste = array (
  10942. // 'accountPrice' => $receivedPrice
  10943. // );
  10944. // if ($receivedBank == '个人广发') {
  10945. // $itemWaste = array (
  10946. // 'accountPrice' => - $receivedPrice
  10947. // );
  10948. // }
  10949. $wasteBook = new wasteBook ();
  10950. $itemWaste = array (
  10951. 'accountPriceShow' => $receivedPrice,
  10952. 'accountPrice' => $receivedPrice,
  10953. 'expensesType' => 1,
  10954. 'accountType' => 6, // 流水类型
  10955. 'dailyIncomeType' => $accountType, // $dailyIncomeType,
  10956. 'dataID' => $id,
  10957. 'accountBank' => $accountBank,
  10958. 'category' => $this->staff [0] ['category'],
  10959. 'cid' => $this->staff [0] ['cid'],
  10960. 'name' => $this->staff [0] ['username'],
  10961. 'sid' => $this->staff [0] ['sid'],
  10962. 'inputDate' => $receivedDate,
  10963. 'createAt'=>date ( "Y-m-d H:i:s" ),
  10964. 'synPaymentDate'=>1,
  10965. );
  10966. $wasteBook->setAccountBookStatistics ( $itemWaste );
  10967. }
  10968. }
  10969. return '/payments';
  10970. }
  10971. function paymentsExpenditureDo() {
  10972. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  10973. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  10974. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  10975. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  10976. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  10977. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  10978. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  10979. // 理财支出特殊处理
  10980. Doo::loadModel ( "accountBook" );
  10981. Doo::loadModel ( "accountBookStatistics" );
  10982. Doo::loadModel ( 'wasteBook' );
  10983. $accountBank = '';
  10984. if ($expenditureBank == '纵横广发') {
  10985. $accountBank = 'CGBDeposit';
  10986. } elseif ($expenditureBank == '纵横工行') {
  10987. $accountBank = 'ICBCDeposit';
  10988. } elseif ($expenditureBank == '华润银行') {
  10989. $accountBank = 'HUADeposit';
  10990. } elseif ($expenditureBank == '个人广发') {
  10991. $accountBank = 'PersonalDeposit';
  10992. }
  10993. if (empty ( $accountBank ))
  10994. die ( 'illegal request' );
  10995. if($expenditureType == 8 || $expenditureType == 9){
  10996. // if($expenditureType == 8 ){
  10997. // $expenditureBank='纵横广发';
  10998. // }elseif($expenditureType == 9){
  10999. // $expenditureBank='纵横工行';
  11000. // }
  11001. // // 添加一笔日常支出
  11002. // $accountBook = new accountBook ();
  11003. // $accountBook->expensesType = 2;
  11004. // $accountBook->expenditureType = $expenditureType;
  11005. // $accountBook->expenditureMsg = $expenditureMsg;
  11006. // $accountBook->expenditurePrice = $expenditurePrice;
  11007. // $accountBook->expenditureBank = $expenditureBank;
  11008. // $accountBook->expenditureDate = $expenditureDate;
  11009. // $accountBook->remarks = $remarks;
  11010. // $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11011. // $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11012. // $accountBook->inputStaff = $this->staff [0] ['sid'];
  11013. // $expenditureId = $accountBook->insert ();
  11014. // // 添加日常支出汇总
  11015. // $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  11016. // $accountBookStatistics = new accountBookStatistics ();
  11017. // $item = array (
  11018. // 'date' => date ( "Y-m-d" ),
  11019. // 'expenditureType' => $abDetail ['expenditureType'],
  11020. // 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11021. // 'aid' => $abDetail ['aid'],
  11022. // 'payPrice' => $abDetail ['expenditurePrice'],
  11023. // 'expensesType' => $abDetail ['expensesType']
  11024. // );
  11025. // $accountBookStatistics->setAccountBookStatistics ( $item );
  11026. // // 公司日常支出流水
  11027. // if($expenditureType == 8 ){
  11028. // $accountBank = 'CGBDeposit';
  11029. // }elseif($expenditureType == 9){
  11030. // $accountBank = 'ICBCDeposit';
  11031. // }
  11032. // if($accountBank=='CGBDeposit'){
  11033. // $dailyExpenditureType='8';
  11034. // }elseif($accountBank=='ICBCDeposit'){
  11035. // $dailyExpenditureType='9';
  11036. // }elseif($accountBank=='PersonalDeposit'){
  11037. // $dailyExpenditureType='10';
  11038. // }elseif($accountBank=='HUADeposit'){
  11039. // $dailyExpenditureType='11';
  11040. // }
  11041. // $wasteBook = new wasteBook ();
  11042. // $itemWaste = array (
  11043. // 'expensesType' => 2,
  11044. // 'accountType' => 5,
  11045. // 'dailyExpenditureType' => $dailyExpenditureType,
  11046. // 'accountPriceShow' => $expenditurePrice,
  11047. // 'accountPrice' => - $expenditurePrice,
  11048. // 'dataID' => $expenditureId,
  11049. // 'accountBank' => $accountBank,
  11050. // 'category' => $this->staff [0] ['category'],
  11051. // 'cid' => $this->staff [0] ['cid'],
  11052. // 'name' => $this->staff [0] ['username'],
  11053. // 'sid' => $this->staff [0] ['sid'],
  11054. // 'inputDate' => date ( "Y-m-d H:i:s" )
  11055. // );
  11056. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  11057. //TODO 日常支出 个人理财情况的相关修改
  11058. }elseif ($expenditureType == 4 || $expenditureType == 6) {
  11059. // if ($expenditureBank == '个人广发') {
  11060. // die ( '个人广发 illegal request' );
  11061. // }
  11062. // echo $expenditureMsg;
  11063. die;
  11064. // // 添加一笔日常支出
  11065. // $accountBook = new accountBook ();
  11066. // $accountBook->expensesType = 2;
  11067. // $accountBook->expenditureType = 7;
  11068. // $accountBook->expenditureMsg = $expenditureMsg;
  11069. // $accountBook->expenditurePrice = $expenditurePrice;
  11070. // $accountBook->expenditureBank = $expenditureBank;
  11071. // $accountBook->expenditureDate = $expenditureDate;
  11072. // $accountBook->remarks = $remarks;
  11073. // $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11074. // $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11075. // $accountBook->inputStaff = $this->staff [0] ['sid'];
  11076. // $expenditureId = $accountBook->insert ();
  11077. // // 添加日常支出汇总
  11078. // $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  11079. // $accountBookStatistics = new accountBookStatistics ();
  11080. // $item = array (
  11081. // 'date' => date ( "Y-m-d" ),
  11082. // 'expenditureType' => $abDetail ['expenditureType'],
  11083. // 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11084. // 'aid' => $abDetail ['aid'],
  11085. // 'payPrice' => $abDetail ['expenditurePrice'],
  11086. // 'expensesType' => $abDetail ['expensesType']
  11087. // );
  11088. // $accountBookStatistics->setAccountBookStatistics ( $item );
  11089. // // 公司日常支出流水
  11090. // $wasteBook = new wasteBook ();
  11091. // $itemWaste = array (
  11092. // 'accountPrice' => - $expenditurePrice
  11093. // );
  11094. // if($expenditureMsg!='个人(GR)'){
  11095. // if ($expenditureBank == '个人广发') {
  11096. // $itemWaste = array (
  11097. // 'accountPrice' => $expenditurePrice
  11098. // );
  11099. // }
  11100. // }
  11101. // $itemWaste += array (
  11102. // 'expensesType' => 2,
  11103. // 'accountType' => 5,
  11104. // 'dailyExpenditureType' => $expenditureType,
  11105. // 'accountPriceShow' => $expenditurePrice,
  11106. // 'accountPrice' => - $expenditurePrice,
  11107. // 'dataID' => $expenditureId,
  11108. // 'accountBank' => $accountBank,
  11109. // 'category' => $this->staff [0] ['category'],
  11110. // 'cid' => $this->staff [0] ['cid'],
  11111. // 'name' => $this->staff [0] ['username'],
  11112. // 'sid' => $this->staff [0] ['sid'],
  11113. // 'inputDate' => date ( "Y-m-d H:i:s" )
  11114. // );
  11115. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  11116. // // 添加一笔理财收入
  11117. // $accountBank = 'CGBDeposit';
  11118. // $dailyIncomeType = 7;
  11119. // $receivedBank = '纵横广发';
  11120. // if ($expenditureType == 6) {
  11121. // $accountBank = 'ICBCDeposit';
  11122. // $receivedBank = '纵横工行';
  11123. // $dailyIncomeType = 9;
  11124. // }elseif($expenditureMsg=='个人(GR)'){
  11125. // $receivedBank = '个人广发';
  11126. // }
  11127. // $accountBook = new accountBook ();
  11128. // $accountBook->expensesType = 1;
  11129. // $accountBook->accountType = $dailyIncomeType;
  11130. // $accountBook->accountMsg = $expenditureMsg;
  11131. // $accountBook->receivedPrice = $expenditurePrice;
  11132. // $accountBook->receivedBank = $receivedBank;
  11133. // $accountBook->receivedDate = $expenditureDate;
  11134. // $accountBook->remarks = $remarks;
  11135. // $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11136. // $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11137. // $accountBook->inputStaff = $this->staff [0] ['sid'];
  11138. // $id = $accountBook->insert ();
  11139. // // 添加日常理财收入汇总
  11140. // $abDetail = $accountBook->getAccountBookByAid ( $expenditureId );
  11141. // $accountBookStatistics = new accountBookStatistics ();
  11142. // $item = array (
  11143. // 'date' => date ( "Y-m-d" ),
  11144. // 'expenditureType' => $abDetail ['expenditureType'],
  11145. // 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11146. // 'aid' => $abDetail ['aid'],
  11147. // 'financingPrice' => $expenditurePrice,
  11148. // 'expensesType' => 3
  11149. // );
  11150. // $accountBookStatistics->setAccountBookStatistics ( $item );
  11151. // //TODO 修改理财收入 添加一笔收入流水
  11152. // if ($expenditureMsg == '公司固定') {
  11153. // $accountTypeWaste = 9;
  11154. // } elseif ($expenditureMsg == '公司活期') {
  11155. // $accountTypeWaste = 10;
  11156. // } elseif ($expenditureMsg == '个人(GR)') {
  11157. // $accountTypeWaste = 9;
  11158. // $accountBank = 'ICBCDeposit';
  11159. // }
  11160. // $itemWaste = array (
  11161. // 'expensesType' => 1,
  11162. // 'accountType' => $accountTypeWaste,
  11163. // 'accountPriceShow' => $expenditurePrice,
  11164. // 'accountPrice' => $expenditurePrice,
  11165. // 'dataID' => $id,
  11166. // 'dailyIncomeType' => $dailyIncomeType,
  11167. // 'accountBank' => $accountBank,
  11168. // 'category' => $this->staff [0] ['category'],
  11169. // 'cid' => $this->staff [0] ['cid'],
  11170. // 'name' => $this->staff [0] ['username'],
  11171. // 'sid' => $this->staff [0] ['sid'],
  11172. // 'inputDate' => date ( "Y-m-d H:i:s" )
  11173. // );
  11174. // $wasteBook->setAccountBookStatistics ( $itemWaste );
  11175. } else {
  11176. // 添加一笔日常支出
  11177. $accountBook = new accountBook ();
  11178. $accountBook->expensesType = 2;
  11179. $accountBook->expenditureType = $expenditureType;
  11180. $accountBook->expenditureMsg = $expenditureMsg;
  11181. $accountBook->expenditurePrice = $expenditurePrice;
  11182. $accountBook->expenditureBank = $expenditureBank;
  11183. $accountBook->expenditureDate = $expenditureDate;
  11184. $accountBook->remarks = $remarks;
  11185. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11186. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11187. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11188. $id = $accountBook->insert ();
  11189. // 添加日常支出汇总
  11190. $abDetail = $accountBook->getAccountBookByAid ( $id );
  11191. $accountBookStatistics = new accountBookStatistics ();
  11192. $item = array (
  11193. 'date' => date ( "Y-m-d" ),
  11194. 'expenditureType' => $abDetail ['expenditureType'],
  11195. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11196. 'aid' => $abDetail ['aid'],
  11197. 'expensesType' => $abDetail ['expensesType']
  11198. );
  11199. if ($expenditureType == 5) {
  11200. $item += array (
  11201. 'payPrice' => - $abDetail ['expenditurePrice']
  11202. );
  11203. } else {
  11204. $item += array (
  11205. 'payPrice' => $abDetail ['expenditurePrice']
  11206. );
  11207. }
  11208. $accountBookStatistics->setAccountBookStatistics ( $item );
  11209. // 公司日常支出流水
  11210. $wasteBook = new wasteBook ();
  11211. $itemWaste = array (
  11212. 'accountPrice' => - $expenditurePrice
  11213. );
  11214. if ($expenditureBank == '个人广发') {
  11215. $itemWaste = array (
  11216. 'accountPrice' => $expenditurePrice
  11217. );
  11218. }
  11219. $itemWaste += array (
  11220. 'expensesType' => 2,
  11221. 'accountType' => 5,
  11222. 'accountPriceShow' => $expenditurePrice,
  11223. 'dataID' => $id,
  11224. 'dailyExpenditureType' => $expenditureType,
  11225. 'accountBank' => $accountBank,
  11226. 'category' => $this->staff [0] ['category'],
  11227. 'cid' => $this->staff [0] ['cid'],
  11228. 'name' => $this->staff [0] ['username'],
  11229. 'sid' => $this->staff [0] ['sid'],
  11230. 'inputDate' => date ( "Y-m-d H:i:s" )
  11231. );
  11232. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11233. }
  11234. }
  11235. return '/payments';
  11236. }
  11237. /**
  11238. * 添加支出
  11239. */
  11240. function paymentsExpenditureDo_() {
  11241. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11242. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11243. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11244. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11245. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11246. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11247. if (! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11248. $dailyExpenditureType = '';
  11249. $accountTypeWaste = 5;
  11250. $accountBank = '';
  11251. if ($expenditureBank == '纵横广发') {
  11252. $accountBank = 'CGBDeposit';
  11253. } elseif ($expenditureBank == '纵横工行') {
  11254. $accountBank = 'ICBCDeposit';
  11255. } elseif ($expenditureBank == '华润银行') {
  11256. $accountBank = 'HUADeposit';
  11257. } elseif ($expenditureBank == '个人广发') {
  11258. $accountBank = 'PersonalDeposit';
  11259. }
  11260. if (empty ( $accountBank ))
  11261. die ( 'illegal request' );
  11262. $itemWaste = array (
  11263. 'accountPrice' => - $expenditurePrice
  11264. );
  11265. if ($expenditureBank == '个人广发') {
  11266. $itemWaste = array (
  11267. 'accountPrice' => $expenditurePrice
  11268. );
  11269. }
  11270. if ($expenditureType == 4 || $expenditureType == 6) {
  11271. $dailyExpenditureType = 4;
  11272. if ($expenditureMsg == '公司固定') {
  11273. $accountTypeWaste = 9;
  11274. } elseif ($expenditureMsg == '公司活期') {
  11275. $accountTypeWaste = 10;
  11276. } elseif ($expenditureMsg == '个人(GR)') {
  11277. $accountBank = 'PersonalDeposit';
  11278. }
  11279. $itemWaste = array (
  11280. 'accountPrice' => $expenditurePrice
  11281. );
  11282. } elseif ($expenditureType == 1) {
  11283. $dailyExpenditureType = 1;
  11284. } elseif ($expenditureType == 2) {
  11285. $dailyExpenditureType = 2;
  11286. } elseif ($expenditureType == 3) {
  11287. $dailyExpenditureType = 3;
  11288. } elseif ($expenditureType == 5) {
  11289. $dailyExpenditureType = 5;
  11290. }
  11291. if (empty ( $dailyExpenditureType ))
  11292. die ( 'illegal request' );
  11293. Doo::loadModel ( "accountBook" );
  11294. $accountBook = new accountBook ();
  11295. $accountBook->expenditureType = $expenditureType;
  11296. $accountBook->expenditureMsg = $expenditureMsg;
  11297. $accountBook->expenditurePrice = $expenditurePrice;
  11298. $accountBook->expenditureBank = $expenditureBank;
  11299. $accountBook->expenditureDate = $expenditureDate;
  11300. $accountBook->remarks = $remarks;
  11301. $accountBook->expensesType = 2;
  11302. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11303. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11304. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11305. $id = $accountBook->insert ();
  11306. //
  11307. $abDetail = $accountBook->getAccountBookByAid ( $id );
  11308. Doo::loadModel ( "accountBookStatistics" );
  11309. $accountBookStatistics = new accountBookStatistics ();
  11310. $item = array (
  11311. 'date' => date ( "Y-m-d" ),
  11312. 'expenditureType' => $abDetail ['expenditureType'],
  11313. 'expenditureMsg' => $abDetail ['expenditureMsg'],
  11314. 'aid' => $abDetail ['aid']
  11315. );
  11316. if ($abDetail ['expensesType'] == 2) {
  11317. if ($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) {
  11318. $item += array (
  11319. 'financingPrice' => $expenditurePrice,
  11320. 'expensesType' => 3
  11321. );
  11322. } elseif ($abDetail ['expenditureType'] == 5) {
  11323. $item += array (
  11324. 'payPrice' => $abDetail ['expenditurePrice'],
  11325. 'expensesType' => $abDetail ['expensesType']
  11326. );
  11327. } else {
  11328. $item += array (
  11329. 'payPrice' => $abDetail ['expenditurePrice'],
  11330. 'expensesType' => $abDetail ['expensesType']
  11331. );
  11332. }
  11333. }
  11334. $accountBookStatistics->setAccountBookStatistics ( $item );
  11335. // 公司流水记录
  11336. Doo::loadModel ( 'wasteBook' );
  11337. $wasteBook = new wasteBook ();
  11338. $abDetail = $wasteBook->getAccountBookByAid ( 2, $accountTypeWaste, $id );
  11339. // 银行
  11340. if (empty ( $abDetail )) {
  11341. $itemWaste += array (
  11342. 'accountPriceShow' => $expenditurePrice,
  11343. 'dataID' => $id,
  11344. 'expensesType' => 2,
  11345. 'accountType' => $accountTypeWaste,
  11346. 'dailyExpenditureType' => $expenditureType,
  11347. 'accountBank' => $accountBank,
  11348. 'category' => $this->staff [0] ['category'],
  11349. 'cid' => $this->staff [0] ['cid'],
  11350. 'name' => $this->staff [0] ['username'],
  11351. 'sid' => $this->staff [0] ['sid'],
  11352. 'inputDate' => date ( "Y-m-d H:i:s" )
  11353. );
  11354. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11355. }
  11356. // 支出类型为4或者6 需要添加一笔收入和收入流水
  11357. if ($expenditureType == 4 || $expenditureType == 6) {
  11358. $accountBank = 'CGBDeposit';
  11359. $dailyIncomeType = 7;
  11360. $receivedBank = '纵横广发';
  11361. if ($expenditureType == 6) {
  11362. $accountBank = 'ICBCDeposit';
  11363. $receivedBank = '纵横工行';
  11364. $dailyIncomeType = 9;
  11365. }
  11366. // 添加一笔收入
  11367. $accountBook = new accountBook ();
  11368. $accountBook->accountType = $dailyIncomeType;
  11369. $accountBook->accountMsg = $expenditureMsg;
  11370. $accountBook->receivedPrice = $expenditurePrice;
  11371. $accountBook->receivedBank = $receivedBank;
  11372. $accountBook->receivedDate = $expenditureDate;
  11373. $accountBook->remarks = $remarks;
  11374. $accountBook->expensesType = 1;
  11375. $accountBook->bookSerial = "#IN" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  11376. $accountBook->inputDate = date ( "Y-m-d H:i:s" );
  11377. $accountBook->inputStaff = $this->staff [0] ['sid'];
  11378. $id = $accountBook->insert ();
  11379. // 添加一笔收入流水
  11380. $itemWaste = array (
  11381. 'accountPriceShow' => $expenditurePrice,
  11382. 'accountPrice' => - $expenditurePrice,
  11383. 'dataID' => $id,
  11384. 'expensesType' => 1,
  11385. 'accountType' => $accountTypeWaste,
  11386. 'dailyIncomeType' => $dailyIncomeType,
  11387. 'accountBank' => $accountBank,
  11388. 'category' => $this->staff [0] ['category'],
  11389. 'cid' => $this->staff [0] ['cid'],
  11390. 'name' => $this->staff [0] ['username'],
  11391. 'sid' => $this->staff [0] ['sid'],
  11392. 'inputDate' => date ( "Y-m-d H:i:s" )
  11393. );
  11394. $wasteBook->setAccountBookStatistics ( $itemWaste );
  11395. }
  11396. }
  11397. return '/payments';
  11398. }
  11399. /**
  11400. * 所有收支
  11401. */
  11402. function paymentsAchieve() {
  11403. $page_size = 12;
  11404. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  11405. $expensesType = isset ( $this->params ['expensesType'] ) ? $this->params ['expensesType'] : 'ALL';
  11406. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  11407. $price = $this->get_args ( 'price' ) ? $this->get_args ( 'price' ) : "";
  11408. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11409. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11410. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11411. $submitType = $this->get_args ( 'submitType' ) ? $this->get_args ( 'submitType' ) : "";
  11412. Doo::loadModel ( "accountBookStatistics" );
  11413. $accountBookStatistics = new accountBookStatistics ();
  11414. $statisticsList = $accountBookStatistics->getStatisticsByMonth ();
  11415. $data ['statisticsList'] = $statisticsList;
  11416. Doo::loadModel ( "accountBook" );
  11417. $accountBook = new accountBook ();
  11418. $con = '';
  11419. if ($expensesType == 'INCOME')
  11420. $con = ' and expensesType=1 ';
  11421. elseif ($expensesType == 'PAY')
  11422. $con = ' and expensesType=2 ';
  11423. $dateArr = explode ( ':', $date );
  11424. $D1 = $dateString = '';
  11425. $D2 = '';
  11426. if (! empty ( $date )) {
  11427. $D1 = $dateArr [0];
  11428. if (isset ( $dateArr [1] ))
  11429. $D2 = $dateArr [1];
  11430. else
  11431. $D2 = '';
  11432. $dateString = $D1 . " : " . $D2;
  11433. }
  11434. if (! empty ( $D1 ) && ! empty ( $D2 ))
  11435. $con .= ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  11436. elseif (! empty ( $D1 ) && empty ( $D2 ))
  11437. $con .= ' and inputDate like "%' . $D1 . '%" ';
  11438. if (! empty ( $price ))
  11439. $con .= ' and (receivedPrice=' . $price . ' or expenditurePrice=' . $price . ')';
  11440. if ($submitType == 1) {
  11441. if ($accountType != '') {
  11442. $expenditureType = '';
  11443. $con .= ' and accountType=' . $accountType;
  11444. if (! empty ( $accountMsg ))
  11445. $con .= ' and (accountType=' . $accountType . ' and accountMsg like "%' . $accountMsg . '%")';
  11446. }
  11447. } elseif ($submitType == 2) {
  11448. if ($expenditureType != '') {
  11449. $accountType = $accountMsg = '';
  11450. $con .= ' and expenditureType=' . $expenditureType;
  11451. }
  11452. } else {
  11453. $accountType = $accountMsg = $expenditureType = '';
  11454. }
  11455. $sql = "" . $con;
  11456. $action = "paymentsAchieve";
  11457. $get = '/' . $expensesType; // "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  11458. $pageinfo = $this->get_page ( "CLD_accountBook", $sql, $page, $page_size, $action, $get, "" );
  11459. $limit = $pageinfo ['lower'] . ',' . $page_size;
  11460. $list = $accountBook->getAccountBookBySql ( $limit, $sql, 'desc' );
  11461. $data ['expenditureType'] = $expenditureType;
  11462. $data ['accountMsg'] = $accountMsg;
  11463. $data ['accountType'] = $accountType;
  11464. $data ['inputDate'] = $date;
  11465. $data ['price'] = $price;
  11466. $data ['expensesType'] = $expensesType;
  11467. $data ['page'] = $pageinfo;
  11468. $data ['list'] = $list;
  11469. $data ['memu'] = "receipt";
  11470. $data ['staff'] = $this->staff;
  11471. $data ['receiptMemu'] = 'payments';
  11472. $data ['verifyId'] = $this->verifyId;
  11473. $data ['executeId'] = $this->executeId;
  11474. $this->render ( "/expenses/paymentsAchieve", $data );
  11475. }
  11476. function paymentsIncomeUpdateDo() {
  11477. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11478. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "";
  11479. $accountMsg = $this->get_args ( 'accountMsg' . $accountType ) ? $this->get_args ( 'accountMsg' . $accountType ) : "";
  11480. $receivedPrice = is_numeric ( $this->get_args ( 'receivedPrice' ) ) ? $this->get_args ( 'receivedPrice' ) : 0;
  11481. $receivedMsg = $this->get_args ( 'receivedMsg' ) ? $this->get_args ( 'receivedMsg' ) : '';
  11482. $receivedBank = $this->get_args ( 'receivedBank' ) ? $this->get_args ( 'receivedBank' ) : '';
  11483. $receivedDate = $this->get_args ( 'receivedDate' ) ? $this->get_args ( 'receivedDate' ) : '';
  11484. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11485. if (! empty ( $aidKey ) && ! empty ( $accountType ) && ! empty ( $receivedPrice ) && ! empty ( $receivedMsg ) && ! empty ( $receivedBank ) && ! empty ( $receivedDate )) {
  11486. Doo::loadClass ( 'XDeode' );
  11487. $XDeode = new XDeode ( 5 );
  11488. $aid = $XDeode->decode ( $aidKey );
  11489. Doo::loadModel ( "accountBook" );
  11490. $accountBook = new accountBook ();
  11491. //
  11492. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11493. $price = $receivedPrice - $abDetail [inComePrice];
  11494. Doo::loadModel ( "accountBookStatistics" );
  11495. $accountBookStatistics = new accountBookStatistics ();
  11496. if ($abDetail ['accountType'] == 7) {
  11497. $item += array (
  11498. 'date' => date ( "Y-m-d" ),
  11499. 'financingPrice' => - $price,
  11500. 'expensesType' => 3,
  11501. 'aid' => $abDetail ['aid']
  11502. );
  11503. } elseif ($abDetail ['accountType'] == 8) {
  11504. $item += array (
  11505. 'date' => date ( "Y-m-d" ),
  11506. 'expensesType' => $abDetail ['expensesType'],
  11507. 'inComePrice' => - $price,
  11508. 'aid' => $abDetail ['aid']
  11509. );
  11510. } else {
  11511. $item = array (
  11512. 'date' => date ( "Y-m-d" ),
  11513. 'expensesType' => $abDetail ['expensesType'],
  11514. 'inComePrice' => $price,
  11515. 'aid' => $abDetail ['aid']
  11516. );
  11517. }
  11518. $accountBookStatistics->setAccountBookStatistics ( $item );
  11519. $accountBook->accountType = $accountType;
  11520. $accountBook->accountMsg = $accountMsg;
  11521. $accountBook->receivedPrice = $receivedPrice;
  11522. $accountBook->receivedMsg = $receivedMsg;
  11523. $accountBook->receivedBank = $receivedBank;
  11524. $accountBook->receivedDate = $receivedDate;
  11525. $accountBook->remarks = $remarks;
  11526. $accountBook->aid = $aid;
  11527. $accountBook->update ();
  11528. }
  11529. return '/paymentsAchieve';
  11530. }
  11531. function paymentsExpenditureEdiDo() {
  11532. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11533. $expenditureType = $this->get_args ( 'expenditureType' ) ? $this->get_args ( 'expenditureType' ) : "";
  11534. $expenditureMsg = $this->get_args ( 'expenditureMsg' . $expenditureType ) ? $this->get_args ( 'expenditureMsg' . $expenditureType ) : "";
  11535. $expenditurePrice = is_numeric ( $this->get_args ( 'expenditurePrice' ) ) ? $this->get_args ( 'expenditurePrice' ) : 0;
  11536. $expenditureBank = $this->get_args ( 'expenditureBank' ) ? $this->get_args ( 'expenditureBank' ) : '';
  11537. $remarks = $this->get_args ( 'remarks' ) ? $this->get_args ( 'remarks' ) : '';
  11538. $expenditureDate = $this->get_args ( 'expenditureDate' ) ? $this->get_args ( 'expenditureDate' ) : '';
  11539. if (! empty ( $aidKey ) && ! empty ( $expenditureType ) && ! empty ( $expenditurePrice ) && ! empty ( $expenditureBank ) && ! empty ( $expenditureDate )) {
  11540. Doo::loadClass ( 'XDeode' );
  11541. $XDeode = new XDeode ( 5 );
  11542. $aid = $XDeode->decode ( $aidKey );
  11543. Doo::loadModel ( "accountBook" );
  11544. $accountBook = new accountBook ();
  11545. // 汇总信息
  11546. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11547. $price = $expenditurePrice - $abDetail [expenditurePrice];
  11548. Doo::loadModel ( "accountBookStatistics" );
  11549. $accountBookStatistics = new accountBookStatistics ();
  11550. if ($abDetail ['expenditureType'] == 4) {
  11551. $item += array (
  11552. 'date' => date ( "Y-m-d" ),
  11553. 'financingPrice' => $price,
  11554. 'expensesType' => 3,
  11555. 'aid' => $abDetail ['aid']
  11556. );
  11557. } elseif ($abDetail ['expenditureType'] == 5) {
  11558. $item += array (
  11559. 'date' => date ( "Y-m-d" ),
  11560. 'expensesType' => $abDetail ['expensesType'],
  11561. 'payPrice' => $price,
  11562. 'aid' => $abDetail ['aid']
  11563. );
  11564. } else {
  11565. $item = array (
  11566. 'date' => date ( "Y-m-d" ),
  11567. 'expensesType' => $abDetail ['expensesType'],
  11568. 'payPrice' => $price,
  11569. 'aid' => $abDetail ['aid']
  11570. );
  11571. }
  11572. $accountBookStatistics->setAccountBookStatistics ( $item );
  11573. //
  11574. $accountBook->expenditureType = $expenditureType;
  11575. $accountBook->expenditureMsg = $expenditureMsg;
  11576. $accountBook->expenditurePrice = $expenditurePrice;
  11577. $accountBook->expenditureBank = $expenditureBank;
  11578. $accountBook->remarks = $remarks;
  11579. $accountBook->expenditureDate = $expenditureDate;
  11580. $accountBook->aid = $aid;
  11581. $id = $accountBook->update ();
  11582. }
  11583. return '/paymentsAchieve';
  11584. }
  11585. function paymentsDelDo() {
  11586. $aidKey = $this->get_args ( 'aidKey' ) ? $this->get_args ( 'aidKey' ) : "";
  11587. if (! empty ( $aidKey )) {
  11588. Doo::loadClass ( 'XDeode' );
  11589. $XDeode = new XDeode ( 5 );
  11590. $aid = $XDeode->decode ( $aidKey );
  11591. Doo::loadModel ( "accountBook" );
  11592. $accountBook = new accountBook ();
  11593. $abDetail = $accountBook->getAccountBookByAid ( $aid );
  11594. if (empty ( $abDetail ))
  11595. die ( 'illegal request' );
  11596. // 删除收支
  11597. Doo::loadModel ( "accountBookStatistics" );
  11598. $accountBookStatistics = new accountBookStatistics ();
  11599. $item = array (
  11600. 'date' => date ( "Y-m-d" ),
  11601. 'aid' => $abDetail ['aid']
  11602. );
  11603. $accountType = '';
  11604. if ($abDetail ['expensesType'] == 1) {
  11605. $accountType = 6;
  11606. if ($abDetail ['accountType'] != 7) {
  11607. $item += array (
  11608. 'expensesType' => $abDetail ['expensesType'],
  11609. 'inComePrice' => - $abDetail ['receivedPrice']
  11610. );
  11611. } else {
  11612. $item += array (
  11613. 'financingPrice' => $abDetail ['receivedPrice'],
  11614. 'expensesType' => 3
  11615. );
  11616. }
  11617. } elseif ($abDetail ['expensesType'] == 2) {
  11618. $accountType = 5;
  11619. if ($abDetail ['accountType'] != 7) {
  11620. $item += array (
  11621. 'expensesType' => $abDetail ['expensesType'],
  11622. 'payPrice' => - $abDetail ['expenditurePrice']
  11623. );
  11624. } else {
  11625. $item += array (
  11626. 'financingPrice' => - $abDetail ['expenditurePrice'],
  11627. 'expensesType' => 3
  11628. );
  11629. }
  11630. }
  11631. if (($abDetail ['expenditureType'] == 4 || $abDetail ['expenditureType'] == 6) && $abDetail ['expensesType'] == 2) {
  11632. if ($abDetail ['expenditureMsg'] == '公司固定')
  11633. $accountType = 9;
  11634. elseif ($abDetail ['expenditureMsg'] == '公司活期')
  11635. $accountType = 10;
  11636. }
  11637. if (($abDetail ['accountType'] == 7 || $abDetail ['accountType'] == 9) && $abDetail ['expensesType'] == 1) {
  11638. if ($abDetail ['accountMsg'] == '公司固定')
  11639. $accountType = 9;
  11640. elseif ($abDetail ['accountMsg'] == '公司活期')
  11641. $accountType = 10;
  11642. }
  11643. if ($abDetail ['accountMsg'] == '活期理财收益') {
  11644. $accountType = 10;
  11645. }
  11646. $accountBookStatistics->setAccountBookStatistics ( $item );
  11647. $accountBook->delete ( array (
  11648. 'where' => 'aid=' . $aid,
  11649. 'limit' => 1
  11650. ) );
  11651. // 删除收入流水
  11652. //TODO 2020-07-23 删除新增理财和银行存款流水
  11653. if (! empty ( $accountType )) {
  11654. Doo::loadModel ( 'wasteBook' );
  11655. $wasteBook = new wasteBook ();
  11656. $wasteBook->delete ( array (
  11657. 'where' => 'dataID=' . $aid . ' and accountType=' . $accountType,
  11658. 'limit' => 1
  11659. ) );
  11660. }
  11661. }
  11662. return '/paymentsAchieve';
  11663. }
  11664. function paymentsCollect() {
  11665. Doo::loadModel ( "execute" );
  11666. $execute = new execute ();
  11667. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11668. die ( 'illegal request' );
  11669. }
  11670. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11671. $moth = $this->get_args ( 'moth' ) ? $this->get_args ( 'moth' ) : "";
  11672. Doo::loadModel ( "accountBookStatistics" );
  11673. $accountBookStatistics = new accountBookStatistics ();
  11674. Doo::loadClass ( 'receipt.func' );
  11675. $statisticsIncome = $accountBookStatistics->getStatisticsByCollect ( $year );
  11676. $html = _getPaymentsCollectByYearHtml ( $statisticsIncome );
  11677. $data ['html'] = $html ['html'];
  11678. $data ['inSum'] = $html ['sum'];
  11679. $statisticsPay = $accountBookStatistics->getStatisticsByCollect ( $year, 2 );
  11680. $html = _getPaymentsCollectPayByYearHtml ( $statisticsPay );
  11681. $data ['payHtml'] = $html ['html'];
  11682. $data ['paySum'] = $html ['sum'];
  11683. // 余额统计
  11684. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1 );
  11685. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2 );
  11686. include './protected/config/wasteBook.conf.php';
  11687. Doo::loadModel ( 'wasteBook' );
  11688. $wasteBook = new wasteBook ();
  11689. $inComePay = $wasteBook->getWasteBookByStatistics ( 1, $year );
  11690. $pay = $wasteBook->getWasteBookByStatistics ( 2, $year );
  11691. // 获得年份之前所有金额
  11692. $detail = $wasteBook->getWasteBookByStatisticsYear ( $year );
  11693. // print_r($detail);
  11694. // $waste['total'];
  11695. $lastBalanceHtml = '<tr><th colspan="2">截至上月余额</th>';
  11696. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11697. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11698. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11699. $inSum = $paySum = $showInSum = $showPaySum = $balanceSum = 0;
  11700. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11701. $limitMonth = date ( 'm' ); // 限制显示月份参数
  11702. if (date ( 'Y' ) > $year) {
  11703. $limitMonth = 12;
  11704. }
  11705. for($i = 1; $i <= 12; $i ++) {
  11706. $inComeA = $payB = 0;
  11707. $falg = true;
  11708. foreach ( $inComePay as $key => $value ) {
  11709. if ($value ['month'] == $i) {
  11710. $falg = false;
  11711. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11712. $inSum += $value ['accountPrice'];
  11713. $showInSum += $value ['accountPriceShow'];
  11714. $inComeA = $value ['accountPrice'];
  11715. break;
  11716. }
  11717. }
  11718. if ($falg)
  11719. $inComeHtml .= '<td class="taR">-</td>';
  11720. $payFalg = true;
  11721. foreach ( $pay as $key => $value ) {
  11722. if ($value ['month'] == $i) {
  11723. $payFalg = false;
  11724. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11725. $paySum += $value ['accountPrice'];
  11726. $showPaySum += $value ['accountPriceShow'];
  11727. $payB = $value ['accountPrice'];
  11728. break;
  11729. }
  11730. }
  11731. if ($payFalg)
  11732. $payHtml .= '<td class="taR">-</td>';
  11733. if (empty ( $balanceC ) || $limitMonth < $i)
  11734. $lastBalanceHtml .= '<td class="taR">-</td>';
  11735. else
  11736. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11737. $balanceC = $balanceC + $inComeA + $payB;
  11738. $balanceSum += $balanceC;
  11739. if (empty ( $balanceC ) || $limitMonth < $i)
  11740. $BalanceHtml .= '<td class="taR">-</td>';
  11741. else
  11742. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11743. // 余额统计
  11744. }
  11745. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11746. $data ['inComeHtml'] = $inComeHtml;
  11747. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11748. $data ['payBalanceHtml'] = $payHtml;
  11749. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11750. $data ['BalanceHtml'] = $BalanceHtml;
  11751. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11752. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11753. $mothHtml = "";
  11754. for($i = 1; $i <= 12; $i ++) {
  11755. if ($moth == $i)
  11756. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11757. else
  11758. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11759. }
  11760. $data ['mothHtml'] = $mothHtml;
  11761. $dateHtml = "";
  11762. $now = date ( "Y" );
  11763. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11764. if ($YEARD <= $now) {
  11765. $dateHtml .= '<option ';
  11766. if ($year == $YEARD) {
  11767. $dateHtml .= 'selected ';
  11768. }
  11769. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11770. }
  11771. }
  11772. $data ['dateHtml'] = $dateHtml;
  11773. $data ['year'] = $year;
  11774. $data ['memu'] = "receipt";
  11775. $data ['staff'] = $this->staff;
  11776. $data ['receiptMemu'] = 'paymentsCollect';
  11777. $data ['verifyId'] = $this->verifyId;
  11778. $data ['executeId'] = $this->executeId;
  11779. $this->render ( "/expenses/paymentsCollect", $data );
  11780. }
  11781. function paymentsCollectDay() {
  11782. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  11783. $moth = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : '';
  11784. if (empty ( $moth ))
  11785. return 'paymentsCollect';
  11786. Doo::loadModel ( "accountBookStatistics" );
  11787. $accountBookStatistics = new accountBookStatistics ();
  11788. $i = 2;
  11789. $y = 2013;
  11790. $day = date ( "t", strtotime ( "$year-$moth" ) );
  11791. Doo::loadClass ( 'receipt.func' );
  11792. $statisticsIncome = $accountBookStatistics->getStatisticsByCollectDay ( $year, 1, $moth );
  11793. $html = _getPaymentsCollectByDayHtml ( $statisticsIncome, $day );
  11794. $data ['html'] = $html ['html'];
  11795. $data ['inSum'] = $html ['sum'];
  11796. $statisticsPay = $accountBookStatistics->getStatisticsByCollectDay ( $year, 2, $moth );
  11797. $html = _getPaymentsCollectPayByDayHtml ( $statisticsPay, $day );
  11798. $data ['payHtml'] = $html ['html'];
  11799. $data ['paySum'] = $html ['sum'];
  11800. $mothHtml = "";
  11801. for($i = 1; $i <= 12; $i ++) {
  11802. if ($moth == $i)
  11803. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  11804. else
  11805. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  11806. }
  11807. $data ['mothHtml'] = $mothHtml;
  11808. $data ['year'] = $year;
  11809. // 余额
  11810. // $inComePay = $accountBookStatistics->getStatisticsByBalance ( $year, 1, $moth );
  11811. // $pay = $accountBookStatistics->getStatisticsByBalance ( $year, 2, $moth );
  11812. include './protected/config/wasteBook.conf.php';
  11813. Doo::loadModel ( 'wasteBook' );
  11814. $wasteBook = new wasteBook ();
  11815. $inComePay = $wasteBook->getStatisticsByDay ( 1, $year, $moth );
  11816. $pay = $wasteBook->getStatisticsByDay ( 2, $year, $moth );
  11817. // 获得年份之前所有金额
  11818. $detail = $wasteBook->getWasteBookByStatisticsDay ( $year, $moth );
  11819. $lastBalanceHtml = '<tr><th colspan="2">截至上日余额</th>';
  11820. $inComeHtml = '<tr><th colspan="2">收入</th>';
  11821. $payHtml = '<tr class="colRed"><th colspan="2">支出</th>';
  11822. $BalanceHtml = '<tr><th colspan="2">余额</th>';
  11823. $dayHtml = '<tr><th class="taC" colspan="2">余额</th>';
  11824. $inSum = $paySum = $showPaySum = $showInSum = $balanceSum = 0;
  11825. // $balanceC = 0;
  11826. $balanceC = $bakBC = $waste ['total'] + $detail [0] ['accountPrice'];
  11827. $limitDay = date ( 'd' );
  11828. $monthLK = ( int ) date ( 'm' );
  11829. if (date ( 'Y' ) > $year) {
  11830. $limitDay = cal_days_in_month ( CAL_GREGORIAN, date ( 'm' ), date ( 'Y' ) );
  11831. } elseif (date ( 'Y' ) <= $year && $monthLK < $moth) {
  11832. $limitDay = 0;
  11833. }
  11834. for($i = 1; $i <= $day; $i ++) {
  11835. $dayHtml .= '<td class="taC">' . $i . '日</td>';
  11836. $inComeA = $payB = 0;
  11837. $falg = true;
  11838. foreach ( $inComePay as $key => $value ) {
  11839. if ($value ['day'] == $i) {
  11840. $falg = false;
  11841. $inComeHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11842. $inSum += $value ['accountPrice'];
  11843. $showInSum += $value ['accountPriceShow'];
  11844. $inComeA = $value ['accountPrice'];
  11845. break;
  11846. }
  11847. }
  11848. if ($falg)
  11849. $inComeHtml .= '<td class="taR">-</td>';
  11850. $payFalg = true;
  11851. foreach ( $pay as $key => $value ) {
  11852. if ($value ['day'] == $i) {
  11853. $payFalg = false;
  11854. $payHtml .= '<td class="taR">' . $value ['accountPriceShow'] . '</td>';
  11855. $paySum += $value ['accountPrice'];
  11856. $showPaySum += $value ['accountPriceShow'];
  11857. $payB = $value ['accountPrice'];
  11858. break;
  11859. }
  11860. }
  11861. if ($payFalg)
  11862. $payHtml .= '<td class="taR">-</td>';
  11863. if (empty ( $balanceC ) || $limitDay < $i)
  11864. $lastBalanceHtml .= '<td class="taR">-</td>';
  11865. else
  11866. $lastBalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11867. $balanceC = $balanceC + $inComeA + $payB;
  11868. $balanceSum += $balanceC;
  11869. if (empty ( $balanceC ) || $limitDay < $i)
  11870. $BalanceHtml .= '<td class="taR">-</td>';
  11871. else
  11872. $BalanceHtml .= '<td class="taR">' . $balanceC . '</td>';
  11873. }
  11874. $inComeHtml .= '<td class="taR colGreen">¥' . $showInSum . '</td></tr>';
  11875. $data ['inComeHtml'] = $inComeHtml;
  11876. $payHtml .= '<td class="taR ">¥' . $showPaySum . '</td></tr>';
  11877. $data ['payBalanceHtml'] = $payHtml;
  11878. $BalanceHtml .= '<td class="taR ">¥' . $balanceC . '</td></tr>';
  11879. $data ['BalanceHtml'] = $BalanceHtml;
  11880. $dayHtml .= '<td class="taR ">总计</td></tr>';
  11881. $data ['dayHtml'] = $dayHtml;
  11882. $lastBalanceHtml .= '<td class="taR ">' . $balanceC . '</td></tr>';
  11883. $data ['lastBalanceHtml'] = $lastBalanceHtml;
  11884. $dateHtml = "";
  11885. $now = date ( "Y" );
  11886. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  11887. if ($YEARD <= $now) {
  11888. $dateHtml .= '<option ';
  11889. if ($year == $YEARD) {
  11890. $dateHtml .= 'selected ';
  11891. }
  11892. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  11893. }
  11894. }
  11895. $data ['dateHtml'] = $dateHtml;
  11896. $data ['memu'] = "receipt";
  11897. $data ['staff'] = $this->staff;
  11898. $data ['receiptMemu'] = 'paymentsCollect';
  11899. $data ['verifyId'] = $this->verifyId;
  11900. $data ['executeId'] = $this->executeId;
  11901. $this->render ( "/expenses/paymentsCollectDay", $data );
  11902. }
  11903. // 公司流水
  11904. function wasteBook() {
  11905. Doo::loadModel ( "execute" );
  11906. $execute = new execute ();
  11907. if (! $execute->isPaymentsShow ( $this->staff [0] ['sid'] )) {
  11908. die ( 'illegal request' );
  11909. }
  11910. include './protected/config/wasteBook.conf.php';
  11911. Doo::loadModel ( 'wasteBook' );
  11912. $wasteBook = new wasteBook ();
  11913. $data ['store']=$waste;
  11914. $inComeStatistics = $wasteBook->getWasteBookStatisticsByIncome ();
  11915. //print_r($waste);
  11916. //1-收入支出流水金额合计
  11917. $waste = $this->getWasteBookStatistics ( $waste, $inComeStatistics );
  11918. //echo $waste['bank']['CGBDeposit'].'</br>';
  11919. //2020-07-20 -理财相关-面板数据
  11920. Doo::loadClass ( 'wasteBook.finances.func' );
  11921. $financesStatistics=$wasteBook->getFinancesStatistics();
  11922. //print_r($waste);
  11923. // 展示使用
  11924. //收入
  11925. //print_r($inComeStatistics);
  11926. $wasteStatistics['CGBDeposit']=0;
  11927. $wasteStatistics['ICBCDeposit']=0;
  11928. $wasteStatistics['HUADeposit']=0;
  11929. $wasteStatistics['PersonalDeposit']=0;
  11930. foreach ($inComeStatistics['incomeStatistics'] as $value ){
  11931. if($value['accountBank']=='CGBDeposit'){
  11932. $wasteStatistics['CGBDeposit']+=$value['accountPrice'];
  11933. }
  11934. if($value['accountBank']=='ICBCDeposit'){
  11935. $wasteStatistics['ICBCDeposit']+=$value['accountPrice'];
  11936. }
  11937. if($value['accountBank']=='HUADeposit'){
  11938. $wasteStatistics['HUADeposit']+=$value['accountPrice'];
  11939. }
  11940. if($value['accountBank']=='PersonalDeposit'){
  11941. $wasteStatistics['PersonalDeposit']+=$value['accountPrice'];
  11942. }
  11943. }
  11944. $data ['wasteStatistics']=$wasteStatistics;
  11945. //支出
  11946. $wasteStatistics['CGBDeposit']=0;
  11947. $wasteStatistics['ICBCDeposit']=0;
  11948. $wasteStatistics['HUADeposit']=0;
  11949. $wasteStatistics['PersonalDeposit']=0;
  11950. foreach ($inComeStatistics['expenditureStatistics'] as $value ){
  11951. if($value['accountBank']=='CGBDeposit'){
  11952. $wasteStatistics['CGBDeposit']+=$value['accountPrice'];
  11953. }
  11954. if($value['accountBank']=='ICBCDeposit'){
  11955. $wasteStatistics['ICBCDeposit']+=$value['accountPrice'];
  11956. }
  11957. if($value['accountBank']=='HUADeposit'){
  11958. $wasteStatistics['HUADeposit']+=$value['accountPrice'];
  11959. }
  11960. if($value['accountBank']=='PersonalDeposit'){
  11961. $wasteStatistics['PersonalDeposit']+=$value['accountPrice'];
  11962. }
  11963. }
  11964. $data ['wastePay']=$wasteStatistics;
  11965. //理财公司账号部分
  11966. $wasteStatistics['CGBDeposit']=0;
  11967. $wasteStatistics['ICBCDeposit']=0;
  11968. $wasteStatistics['HUADeposit']=0;
  11969. $wasteStatistics['PersonalDeposit']=0;
  11970. foreach ($financesStatistics['companyAccount'] as $value ){
  11971. //(纵横广发)广发存款
  11972. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'CGBDeposit') {
  11973. $wasteStatistics['CGBDeposit']+=$value['accountPrice'];
  11974. }
  11975. //工行存款
  11976. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'ICBCDeposit') {
  11977. $wasteStatistics['ICBCDeposit']+=$value['accountPrice'];
  11978. }
  11979. //个人存款
  11980. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'PersonalDeposit') {
  11981. $wasteStatistics['PersonalDeposit']+=$value['accountPrice'];
  11982. }
  11983. }
  11984. $data ['wasteCompanyAccount']=$wasteStatistics;
  11985. //理财部分的金额计算
  11986. $waste =_getFinancesWBS ( $waste, $financesStatistics );
  11987. //echo $waste['bank']['CGBDeposit'].'</br>';;
  11988. //存款面板数据--日常收支改变后的金额汇总
  11989. $bankSavingsStatistics=$wasteBook->getBankSavingsStatistics();
  11990. $waste =_getBankSavingsWBS ( $waste, $bankSavingsStatistics );
  11991. //展示调试BUG-使用
  11992. //print_r($bankSavingsStatistics);
  11993. $wasteStatistics['CGBDeposit']=0;
  11994. $wasteStatistics['ICBCDeposit']=0;
  11995. $wasteStatistics['PersonalDeposit']=0;
  11996. foreach ($bankSavingsStatistics as $value ){
  11997. //(纵横广发)广发存款
  11998. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'CGBDeposit') {
  11999. $wasteStatistics['CGBDeposit']+=$value['accountPrice'];
  12000. }
  12001. //工行存款
  12002. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'ICBCDeposit') {
  12003. $wasteStatistics['ICBCDeposit']+=$value['accountPrice'];
  12004. }
  12005. //个人存款
  12006. if ($value['operatingBankType'] == 2 && $value['accountBank'] == 'PersonalDeposit') {
  12007. $wasteStatistics['PersonalDeposit']+=$value['accountPrice'];
  12008. }
  12009. }
  12010. $data ['wasteNewPay']=$wasteStatistics;
  12011. //echo $waste['bank']['CGBDeposit'].'</br>';;
  12012. //
  12013. $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'];
  12014. $CGBDeposit_total =$waste ['bank'] ['CGBDeposit']+$waste ['bank'] ['HUADeposit'];
  12015. //$waste ['bank'] ['ICBCDeposit']=sprintf("%.2f", round($waste ['bank'] ['ICBCDeposit'], 2));
  12016. // print_r($waste);
  12017. $data ['total'] = number_format($total,2);
  12018. $data ['CGBDeposit_total'] = number_format($CGBDeposit_total,2);
  12019. $cashBalance=$CGBDeposit_total+$waste ['bank'] ['ICBCDeposit']+$waste ['bank'] ['PersonalDeposit']+$waste ['financial'] ['current'] ['CGBDeposit']+$waste ['financial'] ['current'] ['ICBCDeposit'];
  12020. $data['cashBalance']= number_format($cashBalance,2);
  12021. $waste ['bank'] ['CGBDeposit']=sprintf("%.2f", round($waste ['bank'] ['CGBDeposit'], 2));
  12022. $data ['waste'] = $waste;
  12023. // 月流水数据结构
  12024. $monthStatistics = array ();
  12025. $incomeMothStatistics = array ();
  12026. $expenditureMothStatistics = array ();
  12027. for($i = 1; $i <= 12; $i ++) {
  12028. $month = date ( 'Y' ) . '-' . $i;
  12029. if ($i < 10)
  12030. $month = date ( 'Y' ) . '-0' . $i;
  12031. array_push ( $monthStatistics, $month );
  12032. }
  12033. foreach ( $monthStatistics as $value ) {
  12034. $falg = true;
  12035. foreach ( $inComeStatistics ['incomeReport'] as $k => $v ) {
  12036. if ($value == $v ['inputDate']) {
  12037. array_push ( $incomeMothStatistics, $v ['accountPrice'] );
  12038. $falg = false;
  12039. }
  12040. }
  12041. if ($falg) {
  12042. array_push ( $incomeMothStatistics, '' );
  12043. }
  12044. $falgEx = true;
  12045. foreach ( $inComeStatistics ['expenditureReport'] as $k => $v ) {
  12046. if ($value == $v ['inputDate']) {
  12047. array_push ( $expenditureMothStatistics, $v ['accountPrice'] );
  12048. $falg = false;
  12049. }
  12050. }
  12051. if ($falgEx) {
  12052. array_push ( $expenditureMothStatistics, '' );
  12053. }
  12054. }
  12055. $data ['monthStatistics'] = json_encode ( $monthStatistics );
  12056. $data ['incomeMothStatistics'] = json_encode ( $incomeMothStatistics );
  12057. $data ['expenditureMothStatistics'] = json_encode ( $expenditureMothStatistics );
  12058. $expenditureList = $wasteBook->getAccountBookByExpensesType ( 4, 2 );
  12059. $incomeList = $wasteBook->getAccountBookByExpensesType ( 4, 1 );
  12060. // print_r($incomeList);
  12061. $data ['expenditureList'] = $expenditureList;
  12062. $data ['incomeList'] = $incomeList;
  12063. $data ['memu'] = "receipt";
  12064. $data ['staff'] = $this->staff;
  12065. $data ['receiptMemu'] = 'wasteBook';
  12066. $data ['verifyId'] = $this->verifyId;
  12067. $data ['executeId'] = $this->executeId;
  12068. $this->render ( "/expenses/wasteBook", $data );
  12069. }
  12070. function wasteBookIncome() {
  12071. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  12072. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  12073. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  12074. $dailyIncomeType = $this->get_args ( 'dailyIncomeType' ) ? $this->get_args ( 'dailyIncomeType' ) : "ALL";
  12075. $data ['dailyIncomeType'] = $dailyIncomeType;
  12076. Doo::loadModel ( 'wasteBook' );
  12077. $wasteBook = new wasteBook ();
  12078. Doo::loadModel ( 'L_category' );
  12079. $L_category = new L_category ();
  12080. Doo::loadClass ( 'XDeode' );
  12081. $XDeode = new XDeode ( 5 );
  12082. $year=date("Y");
  12083. $theDay=date("Y-m-d");
  12084. $dateArr = explode ( ':', $date );
  12085. $D1 = '';
  12086. $D2 = '';
  12087. $con = '';
  12088. if (! empty ( $date )) {
  12089. $D1 = $dateArr [0];
  12090. $D2 = $dateArr [1];
  12091. }
  12092. if (! empty ( $D1 ) && ! empty ( $D2 ))
  12093. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  12094. elseif (! empty ( $D1 ) && empty ( $D2 ))
  12095. $con = ' and inputDate = "' . $D1 . '"';
  12096. else{
  12097. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  12098. }
  12099. if ($cid != 'ALL') {
  12100. $cid = $XDeode->decode ( $cid );
  12101. $con .= ' and cid = "' . $cid . '"';
  12102. }
  12103. if ($accountType != 'ALL') {
  12104. if ($accountType == 'INVOICE') {
  12105. $con .= ' and (accountType = 7 or accountType = 8)';
  12106. } elseif ($accountType == 'PAYMENTS') {
  12107. $con .= ' and (accountType = 6 or accountType = 9 or accountType = 10)';
  12108. if ($dailyIncomeType != 'ALL') {
  12109. $dailyIncomeType = $XDeode->decode ( $dailyIncomeType );
  12110. $con .= ' and dailyIncomeType = ' . $dailyIncomeType;
  12111. }
  12112. }
  12113. }
  12114. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 1, $con );
  12115. foreach ($incomeList as $key=>$value){
  12116. if(($value['accountType']==6||$value['accountType']==9||$value['accountType']==10)&&$value['synPaymentDate']==0){
  12117. $wasteBook = new wasteBook ();
  12118. $wasteBook->wid = $value['wid'];
  12119. $wasteBook->synPaymentDate = 1;
  12120. $wasteBook->inputDate = $value['data']['receivedDate'];
  12121. $wasteBook->update();
  12122. }
  12123. }
  12124. $sum = 0;$thsDaySum=0;
  12125. foreach ( $incomeList as $key => $value ) {
  12126. $sum += $value ['accountPrice'];
  12127. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  12128. $thsDaySum+=$value ['accountPrice'];
  12129. }
  12130. }
  12131. // print_r($incomeList);
  12132. // 获得办事和部门
  12133. $categoryList = $L_category->getCategory ();
  12134. $data ['accountType'] = $accountType;
  12135. $data ['cid'] = $cid;
  12136. $data ['categoryList'] = $categoryList;
  12137. $data ['sum'] = $sum;
  12138. $data ['incomeList'] = $incomeList;
  12139. $data ['inputDate'] = $date;
  12140. $data['year']=$year;
  12141. $data ['thsDay'] =$theDay;
  12142. $data ['thsDaySum'] =$thsDaySum;
  12143. $data ['memu'] = "receipt";
  12144. $data ['staff'] = $this->staff;
  12145. $data ['receiptMemu'] = 'wasteBook';
  12146. $data ['verifyId'] = $this->verifyId;
  12147. $data ['executeId'] = $this->executeId;
  12148. $this->render ( "/expenses/wasteBookIncome", $data );
  12149. }
  12150. /**
  12151. * 所有支出
  12152. */
  12153. function wasteBookExpenditure() {
  12154. $date = $this->get_args ( 'inputDate' ) ? $this->get_args ( 'inputDate' ) : "";
  12155. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "ALL";
  12156. $accountType = $this->get_args ( 'accountType' ) ? $this->get_args ( 'accountType' ) : "ALL";
  12157. $dailyExpenditureType = $this->get_args ( 'dailyExpenditureType' ) ? $this->get_args ( 'dailyExpenditureType' ) : "ALL";
  12158. $data ['dailyExpenditureType'] = $dailyExpenditureType;
  12159. $receiptType = $this->get_args ( 'receiptType' ) ? $this->get_args ( 'receiptType' ) : "ALL";
  12160. $data ['receiptType'] = $receiptType;
  12161. Doo::loadModel ( 'wasteBook' );
  12162. $wasteBook = new wasteBook ();
  12163. Doo::loadModel ( 'L_category' );
  12164. $L_category = new L_category ();
  12165. Doo::loadClass ( 'XDeode' );
  12166. $XDeode = new XDeode ( 5 );
  12167. $year=date("Y");
  12168. $theDay=date("Y-m-d");
  12169. $dateArr = explode ( ':', $date );
  12170. $D1 = '';
  12171. $D2 = '';
  12172. $con = '';
  12173. if (! empty ( $date )) {
  12174. $D1 = $dateArr [0];
  12175. $D2 = $dateArr [1];
  12176. }
  12177. if (! empty ( $D1 ) && ! empty ( $D2 ))
  12178. $con = ' and inputDate BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  12179. elseif (! empty ( $D1 ) && empty ( $D2 ))
  12180. $con = ' and inputDate = "' . $D1 . '"';
  12181. else{
  12182. $con = ' and DATE_FORMAT(inputDate,"%Y")= "'.$year.'" ';
  12183. }
  12184. if ($cid != 'ALL') {
  12185. $cid = $XDeode->decode ( $cid );
  12186. $con .= ' and cid = "' . $cid . '"';
  12187. }
  12188. if ($accountType != 'ALL') {
  12189. if ($accountType == 'INVOICE') {
  12190. $con .= ' and accountType = 11';
  12191. } elseif ($accountType == 'PAYMENTS') {
  12192. $con .= ' and (accountType = 5 or accountType = 9 or accountType = 10)';
  12193. if ($dailyExpenditureType != 'ALL') {
  12194. $dailyExpenditureType = $XDeode->decode ( $dailyExpenditureType );
  12195. $con .= ' and dailyExpenditureType = ' . $dailyExpenditureType;
  12196. }
  12197. } elseif ($accountType == 'RECEIPT') {
  12198. if ($receiptType == 'ALL') {
  12199. $con .= ' and (accountType = 1 or accountType = 2 or accountType = 3 or accountType = 4)';
  12200. } else {
  12201. $receiptType = $XDeode->decode ( $receiptType );
  12202. echo $receiptType;
  12203. if ($receiptType == 1) {
  12204. $con .= ' and (accountType = 1 or accountType=2)';
  12205. } else {
  12206. $con .= ' and accountType = ' . $receiptType;
  12207. }
  12208. }
  12209. }
  12210. }
  12211. $incomeList = $wasteBook->getAccountBookByExpensesType ( 0, 2, $con );
  12212. foreach ($incomeList as $key=>$value){
  12213. if(($value['accountType']==5||$value['accountType']==9||$value['accountType']==10)&&$value['synPaymentDate']==0){
  12214. $wasteBook = new wasteBook ();
  12215. $wasteBook->wid = $value['wid'];
  12216. $wasteBook->synPaymentDate = 1;
  12217. $wasteBook->inputDate = $value['data']['expenditureDate'];
  12218. $wasteBook->update();
  12219. }
  12220. }
  12221. $sum = 0;$thsDaySum=0;
  12222. foreach ( $incomeList as $key => $value ) {
  12223. $sum += $value ['accountPriceShow'];
  12224. if($theDay==date("Y-m-d",strtotime($value['inputDate']))){
  12225. $thsDaySum+=$value ['accountPriceShow'];
  12226. }
  12227. }
  12228. // print_r($incomeList);
  12229. // 获得办事和部门
  12230. $categoryList = $L_category->getCategory ();
  12231. $data ['accountType'] = $accountType;
  12232. $data ['cid'] = $cid;
  12233. $data ['categoryList'] = $categoryList;
  12234. $data ['sum'] = $sum;
  12235. $data ['incomeList'] = $incomeList;
  12236. $data ['inputDate'] = $date;
  12237. $data['year']=$year;
  12238. $data ['thsDay'] =$theDay;
  12239. $data ['thsDaySum'] =$thsDaySum;
  12240. $data ['memu'] = "receipt";
  12241. $data ['staff'] = $this->staff;
  12242. $data ['receiptMemu'] = 'wasteBook';
  12243. $data ['verifyId'] = $this->verifyId;
  12244. $data ['executeId'] = $this->executeId;
  12245. $this->render ( "/expenses/wasteBookExpenditure", $data );
  12246. }
  12247. function ajaxGetWasteinvoiceReceivables() {
  12248. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12249. Doo::loadClass ( 'XDeode' );
  12250. $XDeode = new XDeode ( 5 );
  12251. $irid = $XDeode->decode ( $serial );
  12252. Doo::loadModel ( 'invoiceReceivables' );
  12253. $invoiceReceivables = new invoiceReceivables ();
  12254. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  12255. echo json_encode ( array (
  12256. 'status' => 1,
  12257. 'detail' => $detail
  12258. ) );
  12259. }
  12260. function ajaxGetPaymentsByAid() {
  12261. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12262. Doo::loadModel ( "accountBook" );
  12263. $accountBook = new accountBook ();
  12264. $detail = $accountBook->getAccountBookByAid ( $serial );
  12265. echo json_encode ( array (
  12266. 'status' => 1,
  12267. 'detail' => $detail
  12268. ) );
  12269. }
  12270. function ajaxGetWasteInvoice() {
  12271. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12272. Doo::loadModel ( 'invoice' );
  12273. $invoice = new invoice ();
  12274. Doo::loadModel ( 'invoiceReceivables' );
  12275. $invoiceReceivables = new invoiceReceivables ();
  12276. $detail = $invoice->getInvoiceByIid ( $serial );
  12277. $detailReceivables = $invoiceReceivables->getInvoiceReceivablesByIrid ( $detail ['irid'] );
  12278. $detail ['receivablesBank'] = $detailReceivables ['receivablesBank'];
  12279. echo json_encode ( array (
  12280. 'status' => 1,
  12281. 'detail' => $detail
  12282. ) );
  12283. }
  12284. /**
  12285. */
  12286. function ajaxGetWasteReceipt() {
  12287. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  12288. $accountTypeKey = $this->get_args ( 'accountTypeKey' ) ? $this->get_args ( 'accountTypeKey' ) : "";
  12289. Doo::loadModel ( 'receipt' );
  12290. $receipt = new receipt ();
  12291. Doo::loadClass ( 'XDeode' );
  12292. $XDeode = new XDeode ( 5 );
  12293. $rid = $XDeode->decode ( $serial );
  12294. $accountType= $XDeode->decode ( $accountTypeKey );
  12295. // 获得个数据
  12296. $detail = $receipt->getReceiptByRid ( $rid );
  12297. // 初始化
  12298. $detail ['reviseDetail'] = array ();
  12299. if (! empty ( $value ['reviseDetail'] ))
  12300. $detail ['reviseDetail'] = json_decode ( $detail ['reviseDetail'], true );
  12301. $detail ['accountItem'] = json_decode ( $detail ['accountItem'], true );
  12302. $detail ['loanItem'] = json_decode ( $detail ['loanItem'], true );
  12303. $detail ['loanSumCN'] = $this->num_to_rmb ( $detail ['loanSum'] );
  12304. $detail ['sumCN'] = $this->num_to_rmb ( $detail ['sum'] );
  12305. // 获得费用html
  12306. $html = $this->getWasteReceiptHtml ( $detail ,$accountType);
  12307. // 获得费用审批人数据
  12308. $detail = $this->getReceiptApproverHtml ( $detail );
  12309. // 审批执行
  12310. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  12311. <th class="taC" width="90">审批人</th>
  12312. <th class="taC">审批意见</th></tr>';
  12313. foreach ( $detail ['verifyList'] as $key => $value ) {
  12314. $html .= '<tr>
  12315. <td>' . $value [1] . '</td>
  12316. <td>' . $value ['opinion'] . '</td>
  12317. </tr>
  12318. ';
  12319. }
  12320. $html .= ' </tbody></table>';
  12321. $html .= '<table class="table table-bordered table-condensed"><tbody><tr>
  12322. <th class="taC" width="90">执行人</th>
  12323. <th class="taC">执行意见</th></tr>';
  12324. foreach ( $detail ['executeCopy'] as $key => $value ) {
  12325. $html .= '<tr>
  12326. <td>' . $value [1] . '</td>
  12327. <td>' . $value ['opinion'] . '</td>
  12328. </tr>
  12329. ';
  12330. }
  12331. $html .= ' </tbody></table>';
  12332. if($accountType==1){
  12333. Doo::loadModel ( 'loanReceipt' );
  12334. $loanReceipt = new loanReceipt ();
  12335. $loanList = $loanReceipt->getOne ( array (
  12336. 'where' => 'rid=' . $detail ['loanRid'],
  12337. 'desc' => 'rid',
  12338. 'asArray' => true
  12339. ) );
  12340. $html .= '<table class="table table-bordered table-condensed">
  12341. <tr class="warning">
  12342. <td class="taR"><b>汇款金额</b></td>
  12343. <td width="140" class="taR"><b style="font-size: 24px">¥'.$loanList['amount'].'</b></td>
  12344. </tr>
  12345. </table>';
  12346. }else{
  12347. $html .= '<table class="table table-bordered table-condensed">
  12348. <tr class="warning">
  12349. <td class="taR"><b>汇款金额</b></td>
  12350. <td width="140" class="taR"><b style="font-size: 24px">¥' . $detail ['amount'] . '</b></td>
  12351. </tr>
  12352. </table>';
  12353. }
  12354. // print_r($detail['verifyList']);
  12355. // header ( 'Content-Type:text/html;charset=utf-8' );
  12356. // echo $html;
  12357. echo json_encode ( array (
  12358. 'status' => 1,
  12359. 'html' => $html,
  12360. 'detail' => $detail
  12361. ) );
  12362. }
  12363. function getReceiptApproverHtml($detail = array()) {
  12364. Doo::loadModel ( 'loanReceipt' );
  12365. $loanReceipt = new loanReceipt ();
  12366. Doo::loadModel ( 'verify' );
  12367. $verify = new verify ();
  12368. Doo::loadModel ( 'staff' );
  12369. $staff = new staff ();
  12370. if (empty ( $detail ))
  12371. return array ();
  12372. $loanList = $loanReceipt->getOne ( array (
  12373. 'where' => 'rid=' . $detail ['loanRid'],
  12374. 'desc' => 'rid',
  12375. 'asArray' => true
  12376. ) );
  12377. if ($detail ['status'] == 3 || $detail ['status'] == 1 || $detail ['status'] == 8 || $detail ['status'] == 9) {
  12378. if ($detail ['status'] == 8 && $detail ['Rtype'] == 1)
  12379. $verifyList ['staff'] = $loanList ['verifyBreakup'];
  12380. else
  12381. $verifyList ['staff'] = $detail ['verifyBreakup'];
  12382. } else
  12383. $verifyList = $verify->getOne ( array (
  12384. 'where' => 'vid=' . $detail ['verify'],
  12385. 'asArray' => true
  12386. ) );
  12387. $verifyList = json_decode ( $verifyList ['staff'], true );
  12388. Doo::loadModel ( 'role' );
  12389. $role = new role ();
  12390. $roleId = 0;
  12391. $flag = true;
  12392. $roleKey = 0;
  12393. $endStaffArray = array ();
  12394. $roleArrayCopy = array ();
  12395. foreach ( $verifyList as $k => $v ) {
  12396. // init verifyStaff
  12397. if ($v [1] == 'ROLE') {
  12398. if (! empty ( $verifyStaff )) {
  12399. $endStaffArray = end ( $verifyStaff );
  12400. }
  12401. $roleVerify = json_decode ( $v [3], true );
  12402. $roleKey = $k;
  12403. $roleArray = array ();
  12404. $rolename = $role->getOne ( array (
  12405. 'where' => 'rid=' . $v [0],
  12406. 'asArray' => true
  12407. ) );
  12408. foreach ( $roleVerify as $o => $p ) {
  12409. $staffID = explode ( '_', $p );
  12410. $staffInfo = $staff->getOne ( array (
  12411. 'where' => 'sid=' . $staffID [0],
  12412. 'asArray' => true
  12413. ) );
  12414. // print_r($staffID);
  12415. $exp = array (
  12416. 0 => $staffInfo ['sid'],
  12417. 1 => $staffID [1],
  12418. 2 => $staffInfo ['avatar'],
  12419. 'date' => '',
  12420. 'date' => '',
  12421. 'opinion' => '',
  12422. 'status' => '',
  12423. 'rolename' => $rolename ['name']
  12424. );
  12425. array_push ( $roleArray, $exp );
  12426. }
  12427. $roleArrayCopy [$v [0]] = $roleArray;
  12428. // $verifyList[$k]['roleArray']=$roleArray;
  12429. }
  12430. $verifyList [$k] ['date'] = "";
  12431. $verifyList [$k] ['opinion'] = "";
  12432. $verifyList [$k] ['status'] = "";
  12433. if (empty ( $verifyStaff )) {
  12434. $verifyList [$k] ['date'] = "";
  12435. $verifyList [$k] ['opinion'] = "";
  12436. if (($verifyList [0] [0] == $this->staff [0] ['sid']) && $flag) {
  12437. $verifyList [$k] ['status'] = 4;
  12438. $flag = false;
  12439. }
  12440. } else {
  12441. foreach ( $verifyStaff as $m => $u ) {
  12442. if ($v [0] == $m) {
  12443. $verifyList [$k] ['date'] = $u ['date'];
  12444. $verifyList [$k] ['opinion'] = $u ['opinion'];
  12445. $verifyList [$k] ['status'] = $u ['status'];
  12446. $flag = false;
  12447. break;
  12448. }
  12449. }
  12450. $endStaffArray = end ( $verifyStaff );
  12451. }
  12452. }
  12453. $rolename ['name'] = '';
  12454. if (! empty ( $roleId )) {
  12455. Doo::loadModel ( 'role' );
  12456. $role = new role ();
  12457. $rolename = $role->getOne ( array (
  12458. 'where' => 'rid=' . $roleId,
  12459. 'asArray' => true
  12460. ) );
  12461. }
  12462. if (! empty ( $verifyStaff ))
  12463. $endStaffArray = end ( $verifyStaff );
  12464. $KOP = false;
  12465. foreach ( $roleArrayCopy as $P => $A ) {
  12466. foreach ( $A as $MKI => $AVL ) {
  12467. if (! empty ( $verifyStaff )) {
  12468. // &&$rolename['rid']==$endStaffArray['nextStaff']
  12469. if ($this->staff [0] ['sid'] == $AVL [0] && isset ( $endStaffArray ['ROLE'] ) && $rolename ['rid'] == $endStaffArray ['nextStaff']) {
  12470. $button = 4;
  12471. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12472. }
  12473. foreach ( $verifyStaff as $m => $u ) {
  12474. $AVLFK = $AVL [0] . '_R';
  12475. // echo $AVLFK.'=='.$m;var_dump($AVLFK==$m);echo '<br/>';
  12476. if (strcmp ( $AVLFK, $m ) == 0) { // &&isset($u['ROLE'])&&$u['ROLE']==1
  12477. $roleArrayCopy [$P] [$MKI] ['date'] = $u ['date'];
  12478. $roleArrayCopy [$P] [$MKI] ['opinion'] = $u ['opinion'];
  12479. $roleArrayCopy [$P] [$MKI] ['status'] = $u ['status'];
  12480. break;
  12481. }
  12482. }
  12483. } else {
  12484. if ($this->staff [0] ['sid'] == $AVL [0] && $verifyList [0] [1] == 'ROLE') {
  12485. $button = 4;
  12486. $roleArrayCopy [$P] [$MKI] ['status'] = 4;
  12487. }
  12488. }
  12489. // $roleArray[$MKI]['rolename']=$rolename['name'];
  12490. $KOP = true;
  12491. }
  12492. }
  12493. foreach ( $roleArrayCopy as $k => $v ) {
  12494. foreach ( $verifyList as $m => $n ) {
  12495. if ($n [0] == $k) {
  12496. array_splice ( $verifyList, $m, 1, $v );
  12497. }
  12498. }
  12499. }
  12500. // 费用执行人相关数据
  12501. $executeCopy = json_decode ( $detail ['executeCopy'], true );
  12502. $executeStaff = json_decode ( $detail ['executeStaff'], true );
  12503. foreach ( $executeCopy as $k => $v ) {
  12504. $executeCopy [$k] ['date'] = '';
  12505. $executeCopy [$k] ['opinion'] = '';
  12506. $executeCopy [$k] ['status'] = '';
  12507. if (! empty ( $executeStaff ))
  12508. foreach ( $executeStaff as $m => $u ) {
  12509. if ($v [0] == $m) {
  12510. $executeCopy [$k] ['date'] = $u ['date'];
  12511. $executeCopy [$k] ['opinion'] = $u ['opinion'];
  12512. $executeCopy [$k] ['status'] = $u ['status'];
  12513. break;
  12514. }
  12515. }
  12516. }
  12517. $detail ['executeCopy'] = $executeCopy;
  12518. $detail ['verifyList'] = $verifyList;
  12519. return $detail;
  12520. }
  12521. function getWasteReceiptHtml($detail = array(),$accountType=1) {
  12522. if (empty ( $detail ))
  12523. return '';
  12524. $html = '';
  12525. if ($detail ['Rtype'] == 0) { // 报销单
  12526. $html .= '<table class="table table-bordered table-condensed">
  12527. <tbody>
  12528. <tr>
  12529. <th colspan="2" class="taC">日常相关费用</th>
  12530. </tr>';
  12531. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12532. $html .= '
  12533. <tr>
  12534. <th>' . $value ['name'] . '</th>
  12535. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12536. </tr>';
  12537. }
  12538. $html .= '
  12539. <tr>
  12540. <th class="taR">合计</th>
  12541. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12542. </tr>';
  12543. $html .= '<tr>
  12544. <th colspan="2" class="taC">差旅相关费用</th>
  12545. </tr>';
  12546. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12547. $html .= '
  12548. <tr>
  12549. <th>' . $value ['name'] . '</th>
  12550. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12551. </tr>';
  12552. }
  12553. $html .= '
  12554. <tr>
  12555. <th class="taR">合计</th>
  12556. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12557. </tr>';
  12558. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12559. $html .= '<tr>
  12560. <th colspan="2" class="taC">内部培训费用</th>
  12561. </tr>';
  12562. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12563. $html .= '
  12564. <tr>
  12565. <th>' . $value ['name'] . '</th>
  12566. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12567. </tr>';
  12568. }
  12569. $html .= '
  12570. <tr>
  12571. <th class="taR">合计</th>
  12572. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12573. </tr>';
  12574. }
  12575. $html .= '<tr>
  12576. <th colspan="2" class="taC">其他</th>
  12577. </tr>';
  12578. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12579. $html .= '
  12580. <tr>
  12581. <th>' . $value ['name'] . '</th>
  12582. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12583. </tr>';
  12584. }
  12585. $html .= '
  12586. <tr>
  12587. <th class="taR">合计</th>
  12588. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12589. </tr>';
  12590. $html .= '<tr>
  12591. <th colspan="2" class="taC">报销金额调整</th>
  12592. </tr>';
  12593. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12594. $html .= '
  12595. <tr>
  12596. <th>' . $value ['name'] . '</th>
  12597. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12598. </tr>';
  12599. }
  12600. $html .= '
  12601. <tr>
  12602. <th class="taR">合计</th>
  12603. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12604. </tr>';
  12605. $html .= '
  12606. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12607. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12608. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12609. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12610. <tr class="warning">
  12611. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12612. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12613. </tr>
  12614. </tbody>
  12615. </table>';
  12616. } elseif ($detail ['Rtype'] == 2) {//对公汇款
  12617. $html .= '
  12618. <table class="table table-bordered table-condensed">
  12619. <tbody>
  12620. <tr>
  12621. <th colspan="2" class="taC">办事处相关费用</th>
  12622. </tr>';
  12623. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12624. $html .= '
  12625. <tr>
  12626. <th>' . $value ['name'] . '</th>
  12627. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12628. </tr>';
  12629. }
  12630. $html .= '
  12631. <tr>
  12632. <th class="taR">合计</th>
  12633. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12634. </tr>';
  12635. $html .= '
  12636. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12637. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12638. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12639. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12640. <tr class="warning">
  12641. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12642. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12643. </tr>
  12644. </tbody>
  12645. </table>';
  12646. } elseif ($detail ['Rtype'] == 1) {//借款 或者借款报销
  12647. Doo::loadModel ( 'loanReceipt' );
  12648. $loanReceipt = new loanReceipt ();
  12649. $loanList = $loanReceipt->getOne ( array (
  12650. 'where' => 'rid=' . $detail ['loanRid'],
  12651. 'desc' => 'rid',
  12652. 'asArray' => true
  12653. ) );
  12654. // print_r($loanList);
  12655. $loanList ['sumCN']=$this->num_to_rmb($loanList ['sum']);
  12656. $html .= '<table class="table table-bordered table-condensed">
  12657. <tbody>
  12658. <tr>
  12659. <th colspan="2" class="taC">借款费用</th>
  12660. </tr>';
  12661. foreach ( $detail ['loanItem'] ['借款费用'] as $key => $value ) {
  12662. $html .= '<tr>
  12663. <th>' . $value ['name'] . '</th>
  12664. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12665. </tr>';
  12666. }
  12667. $html .= '<tr>
  12668. <th class="taC" colspan="2">产生费用所在办事处</th>
  12669. </tr>
  12670. <tr>
  12671. <th style="text-align: center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th>
  12672. </tr>
  12673. <tr>
  12674. <th class="taC" colspan="2">费用说明</th>
  12675. </tr>
  12676. <tr>
  12677. <td colspan="2">' . $loanList ['explanation'] . '</td>
  12678. </tr>
  12679. <tr class="warning">
  12680. <td class="taR"><b>(' . $loanList ['receiptOrder'] . ')本次费用合计</b></td>
  12681. <td class="taR"><b style="font-size: 24px">¥' . $loanList ['sum'] . '</b><br>' . $loanList ['sumCN'] . '</td>
  12682. </tr>
  12683. </tbody>
  12684. </table>
  12685. ';
  12686. if ( $accountType==2) {
  12687. $balance=$detail ['sum']-$loanList ['sum'];
  12688. $balanceCN=$this->num_to_rmb($balance);
  12689. $html .= '<table class="table table-bordered table-condensed">
  12690. <tbody>
  12691. <tr>
  12692. <th colspan="2" class="taC">日常相关费用</th>
  12693. </tr>';
  12694. foreach ( $detail ['accountItem'] ['日常相关费用'] as $key => $value ) {
  12695. $html .= '
  12696. <tr>
  12697. <th>' . $value ['name'] . '</th>
  12698. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12699. </tr>';
  12700. }
  12701. $html .= '
  12702. <tr>
  12703. <th class="taR">合计</th>
  12704. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['agencySum'] . '</td>
  12705. </tr>';
  12706. $html .= '<tr>
  12707. <th colspan="2" class="taC">差旅相关费用</th>
  12708. </tr>';
  12709. foreach ( $detail ['accountItem'] ['差旅相关费用'] as $key => $value ) {
  12710. $html .= '
  12711. <tr>
  12712. <th>' . $value ['name'] . '</th>
  12713. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12714. </tr>';
  12715. }
  12716. $html .= '
  12717. <tr>
  12718. <th class="taR">合计</th>
  12719. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['travelSum'] . '</td>
  12720. </tr>';
  12721. if(isset($detail ['accountItem'] ['内部培训费用'])){
  12722. $html .= '<tr>
  12723. <th colspan="2" class="taC">内部培训费用</th>
  12724. </tr>';
  12725. foreach ( $detail ['accountItem'] ['内部培训费用'] as $key => $value ) {
  12726. $html .= '
  12727. <tr>
  12728. <th>' . $value ['name'] . '</th>
  12729. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12730. </tr>';
  12731. }
  12732. $html .= '
  12733. <tr>
  12734. <th class="taR">合计</th>
  12735. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['inttrainSum'] . '</td>
  12736. </tr>';
  12737. }
  12738. $html .= '<tr>
  12739. <th colspan="2" class="taC">其他</th>
  12740. </tr>';
  12741. foreach ( $detail ['accountItem'] ['其他'] as $key => $value ) {
  12742. $html .= '
  12743. <tr>
  12744. <th>' . $value ['name'] . '</th>
  12745. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12746. </tr>';
  12747. }
  12748. $html .= '
  12749. <tr>
  12750. <th class="taR">合计</th>
  12751. <td class="colGreen taR">¥' . $detail ['accountItem'] ['cSum'] ['otherSum'] . '</td>
  12752. </tr>';
  12753. $html .= '<tr>
  12754. <th colspan="2" class="taC">报销金额调整</th>
  12755. </tr>';
  12756. foreach ( $detail ['reviseDetail'] as $key => $value ) {
  12757. $html .= '
  12758. <tr>
  12759. <th>' . $value ['name'] . '</th>
  12760. <td width="140" class="taR">¥' . $value ['price'] . '</td>
  12761. </tr>';
  12762. }
  12763. $html .= '
  12764. <tr>
  12765. <th class="taR">合计</th>
  12766. <td class="colGreen taR">¥' . $detail ['revisePrice'] . '</td>
  12767. </tr>';
  12768. $html .= '
  12769. <tr><th class="taC" colspan="2">产生费用所在办事处</th></tr>
  12770. <tr><th style="text-align:center" colspan="2">' . $detail ['category'] [0] ['title'] . '</th></tr>
  12771. <tr><th class="taC" colspan="2">报销说明</th></tr>
  12772. <tr><td colspan="2">' . $detail ['explanation'] . '</td></tr>
  12773. <tr class="warning">
  12774. <td class="taR"><b>(' . $detail ['receiptOrder'] . ')本次报销费用合计</b></td>
  12775. <td class="colGreed taR"><b style="font-size: 24px">¥' . $detail ['sum'] . '</b><br>' . $detail ['sumCN'] . '</td>
  12776. </tr>
  12777. <tr class="success">
  12778. <td class="taR"><b>借款结余</b></td>
  12779. <td class="taR"><b style="font-size:24px">¥'.$balance.'</b><br>'.$balanceCN.'</td>
  12780. </tr>
  12781. </tbody>
  12782. </table>';
  12783. }
  12784. }
  12785. return $html;
  12786. }
  12787. /**
  12788. * 计算流水
  12789. */
  12790. function getWasteBookStatistics($waste = array(), $inComeStatistics) {
  12791. $bakWaste ['bank'] = array (
  12792. 'CGBDeposit' => 0,
  12793. 'ICBCDeposit' => 0,
  12794. 'HUADeposit' => 0,
  12795. 'PersonalDeposit' => 0
  12796. );
  12797. $bakWaste ['financial'] = array (
  12798. 'current' => array (
  12799. 'CGBDeposit' => 0,
  12800. 'ICBCDeposit' => 0
  12801. ),
  12802. 'fixed' => array (
  12803. 'CGBDeposit' => 0,
  12804. 'ICBCDeposit' => 0
  12805. )
  12806. );
  12807. // 存款
  12808. foreach ( $waste ['bank'] as $key => $value ) {
  12809. // 收入
  12810. foreach ( $inComeStatistics ['incomeStatistics'] as $k => $v ) {
  12811. // 广发
  12812. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12813. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12814. }
  12815. // 工商
  12816. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12817. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12818. }
  12819. // 华润
  12820. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12821. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12822. }
  12823. // 个人
  12824. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12825. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12826. }
  12827. }
  12828. }
  12829. foreach ( $waste ['bank'] as $key => $value ) {
  12830. // 支出
  12831. foreach ( $inComeStatistics ['expenditureStatistics'] as $k => $v ) {
  12832. // 广发
  12833. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12834. $waste ['bank'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12835. }
  12836. // 工商
  12837. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12838. $waste ['bank'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12839. }
  12840. // 华润
  12841. if ($v ['accountBank'] == 'HUADeposit' && $key == 'HUADeposit') {
  12842. $waste ['bank'] ['HUADeposit'] = $value + $v ['accountPrice'];
  12843. }
  12844. // 个人
  12845. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12846. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12847. }
  12848. }
  12849. }
  12850. // 活期
  12851. foreach ( $waste ['financial'] ['current'] as $key => $value ) {
  12852. foreach ( $inComeStatistics ['currentStatistics'] as $k => $v ) {
  12853. // 广发
  12854. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12855. $waste ['financial'] ['current'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12856. }
  12857. // 工商
  12858. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12859. $waste ['financial'] ['current'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12860. }
  12861. // 个人
  12862. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12863. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12864. }
  12865. }
  12866. }
  12867. // print_r($inComeStatistics ['fixedStatistics']);
  12868. // 固期
  12869. foreach ( $waste ['financial'] ['fixed'] as $key => $value ) {
  12870. foreach ( $inComeStatistics ['fixedStatistics'] as $k => $v ) {
  12871. // 广发
  12872. if ($v ['accountBank'] == 'CGBDeposit' && $key == 'CGBDeposit') {
  12873. $waste ['financial'] ['fixed'] ['CGBDeposit'] = $value + $v ['accountPrice'];
  12874. }
  12875. // 工商---已经转变成个人理财固定代表含义
  12876. if ($v ['accountBank'] == 'ICBCDeposit' && $key == 'ICBCDeposit') {
  12877. $waste ['financial'] ['fixed'] ['ICBCDeposit'] = $value + $v ['accountPrice'];
  12878. }
  12879. // 个人
  12880. if ($v ['accountBank'] == 'PersonalDeposit' && $key == 'PersonalDeposit') {
  12881. $waste ['bank'] ['PersonalDeposit'] = $value + $v ['accountPrice'];
  12882. }
  12883. }
  12884. }
  12885. $waste ['bank'] ['ICBCDeposit'] = sprintf("%.2f", $waste ['bank'] ['ICBCDeposit']);
  12886. return $waste;
  12887. }
  12888. function lyt() {
  12889. Doo::loadModel ( "receiptDetail" );
  12890. $receiptDetail = new receiptDetail ();
  12891. $receiptCollectList = $receiptDetail->find ( array (
  12892. 'where' => 'status=1 ',
  12893. 'asArray' => true
  12894. ) );
  12895. foreach ( $receiptCollectList as $key => $value ) {
  12896. $receiptDetail = new receiptDetail ();
  12897. $receiptDetail->pastDate = $value ['date'];
  12898. $receiptDetail->update ( array (
  12899. 'where' => "rdid= '" . $value ['rdid'] . "'"
  12900. ) );
  12901. }
  12902. }
  12903. function staffCollectMonthDetail() {
  12904. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  12905. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  12906. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  12907. if (! $year)
  12908. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  12909. if (! $month)
  12910. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  12911. $nature = $this->get_args ( 'nature' ) ? $this->get_args ( 'nature' ) : "";
  12912. if (! $nature){
  12913. $nature = isset ( $this->params ['nature'] ) ? $this->params ['nature'] : 'ONJOB';
  12914. }
  12915. Doo::loadModel ( 'staff' );
  12916. $staff = new staff ();
  12917. Doo::loadModel ( "receiptDetail" );
  12918. $receiptDetail = new receiptDetail ();
  12919. Doo::loadModel ( 'accountItem' );
  12920. $accountItem = new accountItem ();
  12921. Doo::loadModel ( 'statistics' );
  12922. $statistics = new statistics ();
  12923. Doo::loadModel ( "receiptAuthorityManage" );
  12924. $receiptAuthorityManage = new receiptAuthorityManage ();
  12925. $aiList=$accountItem->getAccountItem();
  12926. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  12927. $cidList = array ();
  12928. foreach ( $imcStaff as $key => $value ) {
  12929. array_push ( $cidList, $value ['cid'] );
  12930. }
  12931. $cidString = implode ( ',', $cidList );
  12932. $naturecon='';
  12933. if ($nature=='ONJOB'){
  12934. $naturecon=' and (nature!=4 )';
  12935. }elseif($nature=='LEAVEJOB'){
  12936. $naturecon=' and (nature=4 )';
  12937. }else{
  12938. die ( 'illegal request--nature' );
  12939. }
  12940. $staffList = $staff->find ( array (
  12941. 'where' => 'username!="admin" and cid in (' . $cidString . ')'.$naturecon,
  12942. 'asArray' => true
  12943. ) );
  12944. $categoryList = $staff->find ( array (
  12945. 'select' => 'COUNT(*) as count,cid,category',
  12946. 'where' => 'username !="admin" and cid in (' . $cidString . ')'.$naturecon,
  12947. 'groupby' => 'cid',
  12948. 'asArray' => true
  12949. ) );
  12950. $list = array ();
  12951. foreach($aiList as $key=>$value){
  12952. foreach ($value as $v){
  12953. $subtotal[$key][$v['name']]=0;
  12954. }
  12955. }
  12956. foreach ( $categoryList as $vlu ) {
  12957. $s1 = 0;
  12958. $m1 = 0;
  12959. $subtotal[$this->AGENCY]['AGENCY']=$subtotal[$this->TRAVEL]['TRAVEL']=$subtotal[$this->INTTRAIN]['INTTRAIN']=$subtotal[$this->TRAIN]['TRAIN']=$subtotal[$this->OTHER]['OTHER']=0;
  12960. foreach ( $staffList as $value ) {
  12961. if ($vlu ['cid'] == $value ['cid']) {
  12962. // pastDate
  12963. $receiptCollectList = $receiptDetail->find ( array (
  12964. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  12965. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  12966. 'groupby' => 'item,Month(pastDate),itemCategory',
  12967. 'asArray' => true
  12968. ) );
  12969. if (! empty ( $receiptCollectList )) {
  12970. $receiptL = array (
  12971. '日常相关费用' => array (),
  12972. '差旅相关费用' => array (),
  12973. '内部培训费用' => array (),
  12974. '培训班费用' => array (),
  12975. '其他' => array ()
  12976. );
  12977. $html = "";
  12978. $psum = 0;
  12979. foreach ( $aiList[$this->AGENCY] as $va ) {
  12980. $falg = true;
  12981. foreach ( $receiptCollectList as $v ) {
  12982. if ($v ['itemCategory'] == '日常相关费用') {
  12983. if ($v ['item'] == $va['name']) {
  12984. $subtotal[$this->AGENCY][$va['name']]+=$v ['price'];
  12985. $psum += $v ['price'];
  12986. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  12987. $falg = false;
  12988. break;
  12989. }
  12990. }
  12991. }
  12992. if ($falg)
  12993. $html .= '<td class="taR">-</td>';
  12994. }
  12995. $subtotal[$this->AGENCY]['AGENCY'] += $psum;
  12996. if (! empty ( $psum ))
  12997. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  12998. else
  12999. $psum = '<td class="colGreen taR">-</td>';
  13000. $receiptL ['日常相关费用'] = $psum . $html;
  13001. /* ----------------------------------- */
  13002. $html = "";
  13003. $psum = 0;
  13004. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13005. $falg = true;
  13006. foreach ( $receiptCollectList as $v ) {
  13007. if ($v ['itemCategory'] == '差旅相关费用') {
  13008. if ($v ['item'] == $va['name']) {
  13009. $subtotal[$this->TRAVEL][$va['name']]+=$v ['price'];
  13010. $psum += $v ['price'];
  13011. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13012. $falg = false;
  13013. break;
  13014. }
  13015. }
  13016. }
  13017. if ($falg)
  13018. $html .= '<td class="taR">-</td>';
  13019. }
  13020. $subtotal[$this->TRAVEL]['TRAVEL'] += $psum;
  13021. if (! empty ( $psum ))
  13022. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13023. else
  13024. $psum = '<td class="colGreen taR">-</td>';
  13025. $receiptL ['差旅相关费用'] = $psum . $html;
  13026. /* ------------------------------------- */
  13027. $html = "";
  13028. $psum = 0;
  13029. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13030. $falg = true;
  13031. foreach ( $receiptCollectList as $v ) {
  13032. if ($v ['itemCategory'] == '内部培训费用') {
  13033. if ($v ['item'] == $va['name']) {
  13034. $subtotal[$this->INTTRAIN][$va['name']]+=$v ['price'];
  13035. $psum += $v ['price'];
  13036. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13037. $falg = false;
  13038. break;
  13039. }
  13040. }
  13041. }
  13042. if ($falg)
  13043. $html .= '<td class="taR">-</td>';
  13044. }
  13045. $subtotal[$this->INTTRAIN]['INTTRAIN'] += $psum;
  13046. if (! empty ( $psum ))
  13047. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13048. else
  13049. $psum = '<td class="colGreen taR">-</td>';
  13050. $receiptL ['内部培训费用'] = $psum . $html;
  13051. /* ----------------------------------- */
  13052. $html = "";
  13053. $psum = 0;
  13054. foreach ( $aiList[$this->TRAIN] as $va ) {
  13055. $falg = true;
  13056. foreach ( $receiptCollectList as $v ) {
  13057. if ($v ['itemCategory'] == '培训班费用') {
  13058. if ($v ['item'] == $va['name']) {
  13059. $subtotal[$this->TRAIN][$va['name']]+=$v ['price'];
  13060. $psum += $v ['price'];
  13061. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13062. $falg = false;
  13063. break;
  13064. }
  13065. }
  13066. }
  13067. if ($falg)
  13068. $html .= '<td class="taR">-</td>';
  13069. }
  13070. $subtotal[$this->TRAIN]['TRAIN'] += $psum;
  13071. if (! empty ( $psum ))
  13072. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13073. else
  13074. $psum = '<td class="colGreen taR">-</td>';
  13075. $receiptL ['培训班费用'] = $psum . $html;
  13076. /* ------------------------------------- */
  13077. $html = "";
  13078. $psum = 0;
  13079. foreach ( $aiList[$this->OTHER] as $va ) {
  13080. $falg = true;
  13081. foreach ( $receiptCollectList as $v ) {
  13082. if ($v ['itemCategory'] == '其他') {
  13083. if (trim ( $v ['item'] ) == $va['name']) {
  13084. $subtotal[$this->OTHER][$va['name']]+=$v ['price'];
  13085. $psum += $v ['price'];
  13086. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13087. $falg = false;
  13088. break;
  13089. }
  13090. }
  13091. }
  13092. if ($falg)
  13093. $html .= '<td class="taR">-</td>';
  13094. }
  13095. $subtotal[$this->OTHER]['OTHER'] += $psum;
  13096. if (! empty ( $psum ))
  13097. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13098. else
  13099. $psum = '<td class="colGreen taR">-</td>';
  13100. $receiptL ['其他'] = $psum . $html;
  13101. /* ------------------------------------- */
  13102. $html = "";
  13103. $psum = 0;
  13104. foreach ( $receiptCollectList as $v ) {
  13105. if ($v ['itemCategory'] == '报销金额调整') {
  13106. if (! empty ( $v ['price'] )) {
  13107. $psum += $v ['price'];
  13108. }
  13109. }
  13110. }
  13111. $s1 += $psum;
  13112. if (! empty ( $psum ))
  13113. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  13114. else
  13115. $psum = '<td class="taR colOrange">-</td>';
  13116. $receiptL ['报销金额调整'] = $psum . $html;
  13117. } else {
  13118. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13119. foreach ( $aiList[$this->AGENCY] as $va ) {
  13120. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13121. }
  13122. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13123. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13124. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13125. }
  13126. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13127. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13128. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13129. }
  13130. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13131. foreach ( $aiList[$this->TRAIN] as $va ) {
  13132. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13133. }
  13134. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13135. foreach ( $aiList[$this->OTHER] as $va ) {
  13136. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13137. }
  13138. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13139. }
  13140. $monthStaffPrice = $receiptDetail->find ( array (
  13141. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13142. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13143. 'groupby' => 'Month(pastDate)',
  13144. 'asArray' => true
  13145. ) );
  13146. // echo 'staff='.$value['sid']." and status=1 and Year(date)=".$year.' and Month(date)='.$month;
  13147. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  13148. $m1 += $monthStaffPrice [0] ['price'];
  13149. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13150. } else
  13151. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13152. $receiptL ['usernameEn'] = urlencode ( $value ['username'] );
  13153. $list [$value ['username']] = $receiptL;
  13154. }
  13155. }
  13156. $receiptL [$this->AGENCY] ='<td class="colGreen taR">'.$subtotal[$this->AGENCY]['AGENCY'].'</td>';
  13157. foreach ( $aiList[$this->AGENCY] as $va ) {
  13158. $receiptL [$this->AGENCY] .='<td class="taR">' . $subtotal[$this->AGENCY][$va['name']] . '</td>';
  13159. $subtotal[$this->AGENCY][$va['name']]=0;
  13160. }
  13161. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">'.$subtotal[$this->TRAVEL]['TRAVEL'].'</td>';
  13162. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13163. $receiptL [$this->TRAVEL] .='<td class="taR">' . $subtotal[$this->TRAVEL][$va['name']] . '</td>';
  13164. $subtotal[$this->TRAVEL][$va['name']]=0;
  13165. }
  13166. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">'.$subtotal[$this->INTTRAIN]['INTTRAIN'].'</td>';
  13167. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13168. $receiptL [$this->INTTRAIN] .='<td class="taR">' . $subtotal[$this->INTTRAIN][$va['name']] . '</td>';
  13169. $subtotal[$this->INTTRAIN][$va['name']]=0;
  13170. }
  13171. $receiptL [$this->TRAIN] ='<td class="colGreen taR">'.$subtotal[$this->TRAIN]['TRAIN'].'</td>';
  13172. foreach ( $aiList[$this->TRAIN] as $va ) {
  13173. $receiptL [$this->TRAIN] .='<td class="taR">' . $subtotal[$this->TRAIN][$va['name']] . '</td>';
  13174. $subtotal[$this->TRAIN][$va['name']]=0;
  13175. }
  13176. $receiptL [$this->OTHER] ='<td class="colGreen taR">'.$subtotal[$this->OTHER]['OTHER'].'</td>';
  13177. foreach ( $aiList[$this->OTHER] as $va ) {
  13178. $receiptL [$this->OTHER] .='<td class="taR">' . $subtotal[$this->OTHER][$va['name']] . '</td>';
  13179. $subtotal[$this->OTHER][$va['name']]=0;
  13180. }
  13181. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13182. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13183. $receiptL ['usernameEn'] =false;
  13184. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13185. }
  13186. $data ['list'] = $list;
  13187. // print_r($list);
  13188. $receiptCollectList = $receiptDetail->find ( array (
  13189. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13190. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13191. 'groupby' => 'item,Month(pastDate),itemCategory',
  13192. 'asArray' => true
  13193. ) );
  13194. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13195. // statistics html
  13196. $stList = $statistics->getOne ( array (
  13197. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13198. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13199. 'groupby' => 'Month(date)',
  13200. 'asArray' => true
  13201. ) );
  13202. if (empty ( $stList ))
  13203. $stList = array (
  13204. 'rePrice' => 0,
  13205. 'agPrice' => 0
  13206. );
  13207. $data ['stList'] = array (
  13208. 'rePrice' => $stList ['rePrice'],
  13209. 'agPrice' => $stList ['agPrice'],
  13210. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13211. );
  13212. $monthHtml = "";
  13213. for($i = 1; $i <= 12; $i ++) {
  13214. if ($i == $month)
  13215. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13216. else
  13217. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13218. }
  13219. $data ['monthHtml'] = $monthHtml;
  13220. $data ['year'] = $year;
  13221. $data ['month'] = $month;
  13222. $data ['nature'] = $nature;
  13223. $data ['aiList'] = $aiList;
  13224. $data ['memu'] = "receipt";
  13225. $data ['staff'] = $this->staff;
  13226. $data ['receiptMemu'] = 'companyCategoryCollect';
  13227. $data ['verifyId'] = $this->verifyId;
  13228. $data ['executeId'] = $this->executeId;
  13229. $this->render ( "/admin/staffCollectMonthDetail", $data );
  13230. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13231. }
  13232. function staffCollectMonthDetail2() {
  13233. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13234. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13235. if (! $year)
  13236. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13237. if (! $month)
  13238. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13239. Doo::loadModel ( 'staff' );
  13240. $staff = new staff ();
  13241. Doo::loadModel ( "receiptDetail" );
  13242. $receiptDetail = new receiptDetail ();
  13243. Doo::loadModel ( 'accountItem' );
  13244. $accountItem = new accountItem ();
  13245. Doo::loadModel ( 'statistics' );
  13246. $statistics = new statistics ();
  13247. Doo::loadModel ( 'L_category' );
  13248. $lCategory = new L_category ();
  13249. $staffList = $staff->find ( array (
  13250. 'where' => 'username!="admin"',
  13251. 'asArray' => true
  13252. ) );
  13253. $categoryList = $staff->find ( array (
  13254. 'select' => 'COUNT(*) as count,cid,category',
  13255. 'where' => 'username !="admin"',
  13256. 'groupby' => 'cid',
  13257. 'asArray' => true
  13258. ) );
  13259. $list = array ();
  13260. foreach ( $categoryList as $vlu ) {
  13261. // $html='<th rowspan="'.$v['count'].'">'.$v['category'].'</th>';
  13262. $r1 = 0;
  13263. $r2 = 0;
  13264. $r3 = 0;
  13265. $r4 = 0;
  13266. $r5 = 0;
  13267. $r6 = 0;
  13268. $r7 = 0;
  13269. $r8 = 0;
  13270. $r9 = 0;
  13271. $r10 = 0;
  13272. $r11 = 0;
  13273. $r12 = 0;
  13274. $r13 = 0;
  13275. $r14 = 0;
  13276. $r15 = 0;
  13277. $c1 = 0;
  13278. $c2 = 0;
  13279. $c3 = 0;
  13280. $c4 = 0;
  13281. $c5 = 0;
  13282. $c6 = 0;
  13283. $p1 = 0;
  13284. $p2 = 0;
  13285. $p3 = 0;
  13286. $p4 = 0;
  13287. $p5 = 0;
  13288. $p6 = 0;
  13289. $p7 = 0;
  13290. $p8 = 0;
  13291. $p9 = 0;
  13292. $t1 = 0;
  13293. $t2 = 0;
  13294. $t3 = 0;
  13295. $t4 = 0;
  13296. $t5 = 0;
  13297. $s1 = 0;
  13298. $m1 = 0;
  13299. foreach ( $staffList as $value ) {
  13300. if ($vlu ['cid'] == $value ['cid']) {
  13301. $receiptCollectList = $receiptDetail->find ( array (
  13302. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13303. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13304. 'groupby' => 'item,Month(date),itemCategory',
  13305. 'asArray' => true
  13306. ) );
  13307. if (! empty ( $receiptCollectList )) {
  13308. $receiptL = array (
  13309. '日常相关费用' => array (),
  13310. '差旅相关费用' => array (),
  13311. '培训班费用' => array (),
  13312. '其他' => array ()
  13313. );
  13314. $html = "";
  13315. $psum = 0;
  13316. $item = array (
  13317. '市内交通费',
  13318. '市内出租费',
  13319. '办事处房租',
  13320. '电话费',
  13321. '水费',
  13322. '电费',
  13323. '办公费用',
  13324. '邮寄费',
  13325. '其他费用',
  13326. '车辆费用',
  13327. '广告费',
  13328. '团队建设费',
  13329. '物业管理费',
  13330. '宽带费'
  13331. );
  13332. foreach ( $item as $va ) {
  13333. $falg = true;
  13334. foreach ( $receiptCollectList as $v ) {
  13335. if ($v ['itemCategory'] == '日常相关费用') {
  13336. if ($v ['item'] == $va) {
  13337. if ($va == '市内交通费')
  13338. $r1 += $v ['price'];
  13339. if ($va == '市内出租费')
  13340. $r2 += $v ['price'];
  13341. if ($va == '办事处房租')
  13342. $r3 += $v ['price'];
  13343. if ($va == '电话费')
  13344. $r4 += $v ['price'];
  13345. if ($va == '水费')
  13346. $r5 += $v ['price'];
  13347. if ($va == '电费')
  13348. $r6 += $v ['price'];
  13349. if ($va == '办公费用')
  13350. $r7 += $v ['price'];
  13351. if ($va == '邮寄费')
  13352. $r8 += $v ['price'];
  13353. if ($va == '其他费用')
  13354. $r9 += $v ['price'];
  13355. if ($va == '车辆费用')
  13356. $r10 += $v ['price'];
  13357. if ($va == '广告费')
  13358. $r11 += $v ['price'];
  13359. if ($va == '团队建设费')
  13360. $r13 += $v ['price'];
  13361. if ($va == '物业管理费')
  13362. $r14 += $v ['price'];
  13363. if ($va == '宽带费')
  13364. $r15 += $v ['price'];
  13365. $psum += $v ['price'];
  13366. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13367. $falg = false;
  13368. break;
  13369. }
  13370. }
  13371. }
  13372. if ($falg)
  13373. $html .= '<td class="taR">-</td>';
  13374. }
  13375. $r12 += $psum;
  13376. if (! empty ( $psum ))
  13377. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13378. else
  13379. $psum = '<td class="colGreen taR">-</td>';
  13380. $receiptL ['日常相关费用'] = $psum . $html;
  13381. /* ----------------------------------- */
  13382. $html = "";
  13383. $psum = 0;
  13384. $item = array (
  13385. '往来交通费',
  13386. '市内交通费',
  13387. '出差住宿费',
  13388. '出差补助',
  13389. '其他费用'
  13390. );
  13391. foreach ( $item as $va ) {
  13392. $falg = true;
  13393. foreach ( $receiptCollectList as $v ) {
  13394. if ($v ['itemCategory'] == '差旅相关费用') {
  13395. if ($v ['item'] == $va) {
  13396. if ($va == '往来交通费')
  13397. $c1 += $v ['price'];
  13398. if ($va == '市内交通费')
  13399. $c2 += $v ['price'];
  13400. if ($va == '出差住宿费')
  13401. $c3 += $v ['price'];
  13402. if ($va == '出差补助')
  13403. $c4 += $v ['price'];
  13404. if ($va == '其他费用')
  13405. $c5 += $v ['price'];
  13406. $psum += $v ['price'];
  13407. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13408. $falg = false;
  13409. break;
  13410. }
  13411. }
  13412. }
  13413. if ($falg)
  13414. $html .= '<td class="taR">-</td>';
  13415. }
  13416. $c6 += $psum;
  13417. if (! empty ( $psum ))
  13418. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13419. else
  13420. $psum = '<td class="colGreen taR">-</td>';
  13421. $receiptL ['差旅相关费用'] = $psum . $html;
  13422. /* ------------------------------------- */
  13423. $html = "";
  13424. $psum = 0;
  13425. $item = array (
  13426. '场租费',
  13427. '薪酬',
  13428. '住宿费',
  13429. '交通费',
  13430. '餐饮费',
  13431. '办公费',
  13432. '公关费',
  13433. '其他'
  13434. );
  13435. foreach ( $item as $va ) {
  13436. $falg = true;
  13437. foreach ( $receiptCollectList as $v ) {
  13438. if ($v ['itemCategory'] == '培训班费用') {
  13439. if ($v ['item'] == $va) {
  13440. if ($va == '场租费')
  13441. $p1 += $v ['price'];
  13442. if ($va == '薪酬')
  13443. $p2 += $v ['price'];
  13444. if ($va == '住宿费')
  13445. $p3 += $v ['price'];
  13446. if ($va == '交通费')
  13447. $p4 += $v ['price'];
  13448. if ($va == '餐饮费')
  13449. $p5 += $v ['price'];
  13450. if ($va == '办公费')
  13451. $p6 += $v ['price'];
  13452. if ($va == '公关费')
  13453. $p7 += $v ['price'];
  13454. if ($va == '其他')
  13455. $p8 += $v ['price'];
  13456. $psum += $v ['price'];
  13457. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13458. $falg = false;
  13459. break;
  13460. }
  13461. }
  13462. }
  13463. if ($falg)
  13464. $html .= '<td class="taR">-</td>';
  13465. }
  13466. $p9 += $psum;
  13467. if (! empty ( $psum ))
  13468. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13469. else
  13470. $psum = '<td class="colGreen taR">-</td>';
  13471. $receiptL ['培训班费用'] = $psum . $html;
  13472. /* ------------------------------------- */
  13473. $html = "";
  13474. $psum = 0;
  13475. $item = array (
  13476. '公关费',
  13477. '广告费',
  13478. '借款',
  13479. '可自加费用'
  13480. );
  13481. foreach ( $item as $va ) {
  13482. $falg = true;
  13483. foreach ( $receiptCollectList as $v ) {
  13484. if ($v ['itemCategory'] == '其他') {
  13485. if ($v ['item'] == $va) {
  13486. if ($va == '公关费')
  13487. $t1 += $v ['price'];
  13488. if ($va == '广告费')
  13489. $t2 += $v ['price'];
  13490. if ($va == '借款')
  13491. $t3 += $v ['price'];
  13492. if ($va == '可自加费用')
  13493. $t4 += $v ['price'];
  13494. $psum += $v ['price'];
  13495. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13496. $falg = false;
  13497. break;
  13498. }
  13499. }
  13500. }
  13501. if ($falg)
  13502. $html .= '<td class="taR">-</td>';
  13503. }
  13504. $t5 += $psum;
  13505. if (! empty ( $psum ))
  13506. $psum = '<td class="colGreen taR">¥' . $psum . '</td>';
  13507. else
  13508. $psum = '<td class="colGreen taR">-</td>';
  13509. $receiptL ['其他'] = $psum . $html;
  13510. /* ------------------------------------- */
  13511. $html = "";
  13512. $psum = 0;
  13513. foreach ( $receiptCollectList as $v ) {
  13514. if ($v ['itemCategory'] == '报销金额调整') {
  13515. if (! empty ( $v ['price'] )) {
  13516. $psum += $v ['price'];
  13517. }
  13518. }
  13519. }
  13520. $s1 += $psum;
  13521. if (! empty ( $psum ))
  13522. $psum = '<td class="taR colOrange">¥' . $psum . '</td>';
  13523. else
  13524. $psum = '<td class="taR colOrange">-</td>';
  13525. $receiptL ['报销金额调整'] = $psum . $html;
  13526. } else {
  13527. $receiptL ['日常相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13528. <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>';
  13529. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td>
  13530. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13531. $receiptL ['培训班费用'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>
  13532. <td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13533. $receiptL ['其他'] = '<td class="colGreen taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td><td class="taR">-</td>';
  13534. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13535. }
  13536. $monthStaffPrice = $receiptDetail->find ( array (
  13537. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13538. 'where' => 'staff=' . $value ['sid'] . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13539. 'asArray' => true
  13540. ) );
  13541. if (! empty ( $monthStaffPrice [0] ['price'] )) {
  13542. $m1 += $monthStaffPrice [0] ['price'];
  13543. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13544. } else
  13545. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13546. $list [$value ['username']] = $receiptL;
  13547. }
  13548. }
  13549. $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>
  13550. <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>
  13551. <td class="taR">' . $r14 . '</td><td class="taR">' . $r15 . '</td>';
  13552. $receiptL ['差旅相关费用'] = '<td class="colGreen taR">' . $c6 . '</td><td class="taR">' . $c1 . '</td>
  13553. <td class="taR">' . $c2 . '</td><td class="taR">' . $c3 . '</td><td class="taR">' . $c4 . '</td><td class="taR">' . $c5 . '</td>';
  13554. $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>
  13555. <td class="taR">' . $p5 . '</td><td class="taR">' . $p6 . '</td><td class="taR">' . $p7 . '</td><td class="taR">' . $p8 . '</td>';
  13556. $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>';
  13557. $receiptL ['报销金额调整'] = '<td class="taR colOrange">' . $s1 . '</td>';
  13558. $receiptL ['monthStaffPrice'] = '<td><b>¥' . $m1 . '</b></td>';
  13559. $list ['<span class=colRed >' . $vlu ['category'] . '小计</span>'] = $receiptL;
  13560. }
  13561. $data ['list'] = $list;
  13562. $receiptCollectList = $receiptDetail->find ( array (
  13563. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
  13564. 'where' => " status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
  13565. 'groupby' => 'item,Month(date),itemCategory',
  13566. 'asArray' => true
  13567. ) );
  13568. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList );
  13569. // statistics html
  13570. $stList = $statistics->getOne ( array (
  13571. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13572. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13573. 'groupby' => 'Month(date)',
  13574. 'asArray' => true
  13575. ) );
  13576. if (empty ( $stList ))
  13577. $stList = array (
  13578. 'rePrice' => 0,
  13579. 'agPrice' => 0
  13580. );
  13581. $data ['stList'] = array (
  13582. 'rePrice' => $stList ['rePrice'],
  13583. 'agPrice' => $stList ['agPrice'],
  13584. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13585. );
  13586. $monthHtml = "";
  13587. for($i = 1; $i <= 12; $i ++) {
  13588. if ($i == $month)
  13589. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13590. else
  13591. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13592. }
  13593. $data ['monthHtml'] = $monthHtml;
  13594. $data ['year'] = $year;
  13595. $data ['month'] = $month;
  13596. $data ['memu'] = "receipt";
  13597. $data ['staff'] = $this->staff;
  13598. $data ['receiptMemu'] = 'companyCategoryCollect';
  13599. $data ['verifyId'] = $this->verifyId;
  13600. $data ['executeId'] = $this->executeId;
  13601. $this->render ( "/admin/staffCollectMonthDetail2", $data );
  13602. // $this->render ( "/admin/saeaStaffCollectDetail", $data );
  13603. }
  13604. /**
  13605. * 用户报销单列表
  13606. */
  13607. function receiptStatisticsStaffDetail() {
  13608. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13609. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13610. $username = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  13611. Doo::loadModel ( "receipt" );
  13612. $receipt = new receipt ();
  13613. Doo::loadModel ( "receiptDetail" );
  13614. $receiptDetail = new receiptDetail ();
  13615. Doo::loadModel ( 'staff' );
  13616. $staff = new staff ();
  13617. Doo::loadModel ( 'accountItem' );
  13618. $accountItem = new accountItem ();
  13619. Doo::loadModel ( 'statistics' );
  13620. $statistics = new statistics ();
  13621. if (! empty ( $username )) {
  13622. $username = addslashes ( urldecode ( $username ) );
  13623. $staffDetail = $staff->getStaffByName ( $username );
  13624. if (empty ( $staffDetail ))
  13625. die ( 'illegal request' );
  13626. $list = $receipt->getReceiptBySid ( $staffDetail ['sid'], $year, $month );
  13627. $itemList = $accountItem->getAccountItem ();
  13628. $itemHtml = '';
  13629. $categoryHtml = '';
  13630. $itemKeyList = array_keys ( $itemList );
  13631. $revisePrice = 0;
  13632. // 报销单内容详情
  13633. foreach ( $list as $key => $value ) {
  13634. $accountItemList = json_decode ( $value ['accountItem'], true );
  13635. $list [$key] ['accountItemList'] = $accountItemList;
  13636. $receiptItemHtml = '';
  13637. foreach ( $itemKeyList as $v ) {
  13638. if ($v == '日常相关费用')
  13639. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['agencySum'] . '</td>';
  13640. elseif ($v == '差旅相关费用')
  13641. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['travelSum'] . '</td>';
  13642. elseif ($v == '培训班费用')
  13643. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['trainSum'] . '</td>';
  13644. elseif ($v == '内部培训费用'){
  13645. if (isset($accountItemList ['cSum'] ['inttrainSum'])){
  13646. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['inttrainSum'] . '</td>';
  13647. }else{
  13648. $receiptItemHtml .= '<td class="colGreen taR">0</td>';
  13649. }
  13650. }elseif ($v == '其他')
  13651. $receiptItemHtml .= '<td class="colGreen taR">' . $accountItemList ['cSum'] ['otherSum'] . '</td>';
  13652. foreach ( $itemList [$v] as $ke => $va ) {
  13653. $falg = true;
  13654. if (! empty ( $accountItemList [$v] )) {
  13655. foreach ( $accountItemList [$v] as $ve ) {
  13656. if ($va ['name'] == $ve ['name']) {
  13657. $receiptItemHtml .= '<td class="taR">' . $ve ['price'] . '</td>';
  13658. $falg = false;
  13659. break;
  13660. }
  13661. }
  13662. }
  13663. if ($falg)
  13664. $receiptItemHtml .= '<td class="taR"></td>';
  13665. }
  13666. }
  13667. // 金额调整和费用查看
  13668. $revisePrice += $value ['revisePrice'];
  13669. $receiptItemHtml .= '<td class="taR">' . $value ['revisePrice'] . '</td>';
  13670. $receiptItemHtml .= '<td class="taR"><a href="#detail" data-toggle="modal" id="sen'.$key.'" data="' . htmlspecialchars($value ['explanation']) . '" onclick=showExplanation() >查看</a></td>';
  13671. $list [$key] ['receiptItemHtml'] = $receiptItemHtml;
  13672. }
  13673. // 报销单合计
  13674. $receiptTotalList = $receiptDetail->getReceiptTotalItem ( $staffDetail ['sid'], $year, $month );
  13675. $rtl = $receiptDetail->getReceiptTotalItemCategory ( $staffDetail ['sid'], $year, $month );
  13676. $receiptTotalHtml = '';
  13677. // 报销单项目抬头
  13678. foreach ( $itemKeyList as $value ) {
  13679. $count = count ( $itemList [$value] ) + 1;
  13680. $itemHtml .= '<th class="taC" colspan="' . $count . '">' . $value . '</th>';
  13681. $categoryHtml .= '<th class="taC">合计</th>';
  13682. $sumfalg=true;
  13683. foreach ( $rtl as $rtlValue ) {
  13684. if ($rtlValue ['itemCategory'] == $value) {
  13685. $receiptTotalHtml .= '<th>' . $rtlValue ['price'] . '</th>';
  13686. $sumfalg=false;
  13687. break;
  13688. }
  13689. }
  13690. if ($sumfalg)
  13691. $receiptTotalHtml .= '<th></th>';
  13692. foreach ( $itemList [$value] as $k => $v ) {
  13693. $categoryHtml .= '<th class="taC">' . $v ['name'] . '</th>';
  13694. // 合计
  13695. $falg = true;
  13696. foreach ( $receiptTotalList as $ve ) {
  13697. if ($ve ['itemCategory'] == $value && $ve ['item'] == $v ['name']) {
  13698. $receiptTotalHtml .= '<th >' . $ve ['price'] . '</th>';
  13699. $falg = false;
  13700. break;
  13701. }
  13702. }
  13703. if ($falg)
  13704. $receiptTotalHtml .= '<th></th>';
  13705. }
  13706. }
  13707. $receiptTotalHtml .= '<th>' . $revisePrice . '</th>';
  13708. $stList = $statistics->getStatisticsBySid ( $staffDetail ['sid'], $year, $month );
  13709. if (empty ( $stList ))
  13710. $stList = array (
  13711. 'rePrice' => 0,
  13712. 'agPrice' => 0
  13713. );
  13714. $data ['stList'] = array (
  13715. 'rePrice' => $stList ['rePrice'],
  13716. 'agPrice' => $stList ['agPrice'],
  13717. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13718. );
  13719. $monthHtml = "";
  13720. for($i = 1; $i <= 12; $i ++) {
  13721. if ($i == $month)
  13722. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13723. else
  13724. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13725. }
  13726. $data ['username'] = urlencode ( $username );
  13727. $data ['usernameEN'] = $username;
  13728. $data ['monthHtml'] = $monthHtml;
  13729. $data ['receiptTotalHtml'] = $receiptTotalHtml;
  13730. $data ['list'] = $list;
  13731. $data ['categoryHtml'] = $categoryHtml;
  13732. $data ['itemHtml'] = $itemHtml;
  13733. $data ['itemList'] = $itemList;
  13734. $data ['year'] = $year;
  13735. $data ['month'] = $month;
  13736. $data ['memu'] = "receipt";
  13737. $data ['staff'] = $this->staff;
  13738. $data ['receiptMemu'] = 'companyCategoryCollect';
  13739. $data ['verifyId'] = $this->verifyId;
  13740. $data ['executeId'] = $this->executeId;
  13741. $this->render ( "/admin/receiptStatisticsStaffDetail", $data );
  13742. }
  13743. die ( 'illegal request' );
  13744. }
  13745. function companyMonthCollectDetail() {
  13746. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : "";
  13747. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  13748. if (! $year)
  13749. $year = isset ( $this->params ['year'] ) ? $this->params ['year'] : date ( "Y" );
  13750. if (! $month)
  13751. $month = isset ( $this->params ['month'] ) ? $this->params ['month'] : 1;
  13752. Doo::loadModel ( 'staff' );
  13753. $staff = new staff ();
  13754. Doo::loadModel ( "receiptDetail" );
  13755. $receiptDetail = new receiptDetail ();
  13756. Doo::loadModel ( 'accountItem' );
  13757. $accountItem = new accountItem ();
  13758. Doo::loadModel ( 'statistics' );
  13759. $statistics = new statistics ();
  13760. Doo::loadModel ( 'L_category' );
  13761. $lCategory = new L_category ();
  13762. $staffList = $staff->find ( array (
  13763. 'where' => 'username!="admin"',
  13764. 'asArray' => true
  13765. ) );
  13766. $categoryList = $lCategory->find ( array (
  13767. 'asArray' => true
  13768. ) );
  13769. $aiList=$accountItem->getAccountItem();
  13770. $list = array ();
  13771. foreach ( $categoryList as $value ) {
  13772. $receiptCollectList = $receiptDetail->find ( array (
  13773. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13774. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13775. 'groupby' => 'item,Month(pastDate),itemCategory',
  13776. 'asArray' => true
  13777. ) );
  13778. if (! empty ( $receiptCollectList )) {
  13779. $receiptL = array (
  13780. '日常相关费用' => array (),
  13781. '差旅相关费用' => array (),
  13782. '内部培训费用' => array (),
  13783. '培训班费用' => array (),
  13784. '其他' => array ()
  13785. );
  13786. $html = "";
  13787. $psum = 0;
  13788. foreach ( $aiList[$this->AGENCY] as $va ) {
  13789. $falg = true;
  13790. foreach ( $receiptCollectList as $v ) {
  13791. if ($v ['itemCategory'] == $this->AGENCY) {
  13792. if ($v ['item'] == $va['name']) {
  13793. $psum += $v ['price'];
  13794. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13795. $falg = false;
  13796. break;
  13797. }
  13798. }
  13799. }
  13800. if ($falg)
  13801. $html .= '<td class="taR">-</td>';
  13802. }
  13803. if (! empty ( $psum ))
  13804. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13805. else
  13806. $psum = '<td class="colGreen taR">-</td>';
  13807. $receiptL [$this->AGENCY] = $psum . $html;
  13808. /* ----------------------------------- */
  13809. $html = "";
  13810. $psum = 0;
  13811. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13812. $falg = true;
  13813. foreach ( $receiptCollectList as $v ) {
  13814. if ($v ['itemCategory'] == $this->TRAVEL) {
  13815. if ($v ['item'] == $va['name']) {
  13816. $psum += $v ['price'];
  13817. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13818. $falg = false;
  13819. break;
  13820. }
  13821. }
  13822. }
  13823. if ($falg)
  13824. $html .= '<td class="taR">-</td>';
  13825. }
  13826. if (! empty ( $psum ))
  13827. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13828. else
  13829. $psum = '<td class="colGreen taR">-</td>';
  13830. $receiptL [$this->TRAVEL] = $psum . $html;
  13831. /* ------------------------------------- */
  13832. $html = "";
  13833. $psum = 0;
  13834. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13835. $falg = true;
  13836. foreach ( $receiptCollectList as $v ) {
  13837. if ($v ['itemCategory'] == $this->INTTRAIN) {
  13838. if ($v ['item'] == $va['name']) {
  13839. $psum += $v ['price'];
  13840. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13841. $falg = false;
  13842. break;
  13843. }
  13844. }
  13845. }
  13846. if ($falg)
  13847. $html .= '<td class="taR">-</td>';
  13848. }
  13849. if (! empty ( $psum ))
  13850. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13851. else
  13852. $psum = '<td class="colGreen taR">-</td>';
  13853. $receiptL [$this->INTTRAIN] = $psum . $html;
  13854. /* ------------------------------------- */
  13855. $html = "";
  13856. $psum = 0;
  13857. foreach ( $aiList[$this->TRAIN] as $va ) {
  13858. $falg = true;
  13859. foreach ( $receiptCollectList as $v ) {
  13860. if ($v ['itemCategory'] == $this->TRAIN) {
  13861. if ($v ['item'] == $va['name']) {
  13862. $psum += $v ['price'];
  13863. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13864. $falg = false;
  13865. break;
  13866. }
  13867. }
  13868. }
  13869. if ($falg)
  13870. $html .= '<td class="taR">-</td>';
  13871. }
  13872. if (! empty ( $psum ))
  13873. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13874. else
  13875. $psum = '<td class="colGreen taR">-</td>';
  13876. $receiptL [$this->TRAIN] = $psum . $html;
  13877. /* ------------------------------------- */
  13878. $html = "";
  13879. $psum = 0;
  13880. foreach ( $aiList[$this->OTHER] as $va ) {
  13881. $falg = true;
  13882. foreach ( $receiptCollectList as $v ) {
  13883. if ($v ['itemCategory'] == $this->OTHER) {
  13884. if ($v ['item'] == $va['name']) {
  13885. $psum += $v ['price'];
  13886. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  13887. $falg = false;
  13888. break;
  13889. }
  13890. }
  13891. }
  13892. if ($falg)
  13893. $html .= '<td class="taR">-</td>';
  13894. }
  13895. if (! empty ( $psum ))
  13896. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  13897. else
  13898. $psum = '<td class="colGreen taR">-</td>';
  13899. $receiptL [$this->OTHER] = $psum . $html;
  13900. /* ------------------------------------- */
  13901. $html = "";
  13902. $psum = 0;
  13903. foreach ( $receiptCollectList as $v ) {
  13904. if ($v ['itemCategory'] == '报销金额调整') {
  13905. if (! empty ( $v ['price'] ))
  13906. $psum += $v ['price'];
  13907. }
  13908. }
  13909. if (! empty ( $psum ))
  13910. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  13911. else
  13912. $psum = '<td class="taR colOrange">-</td>';
  13913. $receiptL ['报销金额调整'] = $psum . $html;
  13914. } else {
  13915. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  13916. foreach ( $aiList[$this->AGENCY] as $va ) {
  13917. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  13918. }
  13919. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  13920. foreach ( $aiList[$this->TRAVEL] as $va ) {
  13921. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  13922. }
  13923. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  13924. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  13925. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  13926. }
  13927. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  13928. foreach ( $aiList[$this->TRAIN] as $va ) {
  13929. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  13930. }
  13931. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  13932. foreach ( $aiList[$this->OTHER] as $va ) {
  13933. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  13934. }
  13935. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  13936. }
  13937. $monthStaffPrice = $receiptDetail->find ( array (
  13938. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13939. 'where' => 'cid=' . $value ['cid'] . " and status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13940. 'asArray' => true
  13941. ) );
  13942. if (! empty ( $monthStaffPrice [0] ['price'] ))
  13943. $receiptL ['monthStaffPrice'] = '<td><b>' . $monthStaffPrice [0] ['price'] . '</b></td>';
  13944. else
  13945. $receiptL ['monthStaffPrice'] = '<td><b>-</b></td>';
  13946. $list [$value ['title']] = $receiptL;
  13947. }
  13948. $data ['list'] = $list;
  13949. $receiptCollectList = $receiptDetail->find ( array (
  13950. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  13951. 'where' => " status=1 and Year(pastDate)=" . $year . ' and Month(pastDate)=' . $month,
  13952. 'groupby' => 'item,Month(pastDate),itemCategory',
  13953. 'asArray' => true
  13954. ) );
  13955. $data ['monthPriceHtml'] = $this->_getMonthCollectDetail ( $receiptCollectList,$aiList );
  13956. //print_r($data['monthPriceHtml']);
  13957. // foreach ($data['monthPriceHtml'] as $value){
  13958. // echo $value;
  13959. // }
  13960. // die;
  13961. // statistics html
  13962. $stList = $statistics->getOne ( array (
  13963. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  13964. 'where' => 'Month(date)=' . $month . " and Year(date)=" . $year,
  13965. 'groupby' => 'Month(date)',
  13966. 'asArray' => true
  13967. ) );
  13968. if (empty ( $stList ))
  13969. $stList = array (
  13970. 'rePrice' => 0,
  13971. 'agPrice' => 0
  13972. );
  13973. $data ['stList'] = array (
  13974. 'rePrice' => $stList ['rePrice'],
  13975. 'agPrice' => $stList ['agPrice'],
  13976. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  13977. );
  13978. $monthHtml = "";
  13979. for($i = 1; $i <= 12; $i ++) {
  13980. if ($i == $month)
  13981. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  13982. else
  13983. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  13984. }
  13985. $data ['aiList'] = $aiList;
  13986. $dateHtml = "";
  13987. $now = date ( "Y" );
  13988. for($YEARD = 2050; $YEARD >= 2004; $YEARD --) {
  13989. if ($YEARD <= $now) {
  13990. $dateHtml .= '<option ';
  13991. if ($year == $YEARD) {
  13992. $dateHtml .= 'selected ';
  13993. }
  13994. $dateHtml .= 'value="' . $YEARD . '">' . $YEARD . '</option>';
  13995. }
  13996. }
  13997. $data ['dateHtml'] = $dateHtml;
  13998. $data ['monthHtml'] = $monthHtml;
  13999. $data ['year'] = $year;
  14000. $data ['month'] = $month;
  14001. $data ['memu'] = "receipt";
  14002. $data ['staff'] = $this->staff;
  14003. $data ['receiptMemu'] = 'companyCategoryCollect';
  14004. $data ['verifyId'] = $this->verifyId;
  14005. $data ['executeId'] = $this->executeId;
  14006. $this->render ( "/admin/companyMonthCollectDetail", $data );
  14007. }
  14008. function staffCollectDetail() {
  14009. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  14010. $staffname = $this->get_args ( 'username' ) ? $this->get_args ( 'username' ) : "";
  14011. $pcid = $this->get_args ( 'category' ) ? $this->get_args ( 'category' ) : "";
  14012. if (! $staffname) {
  14013. $staffname = isset ( $this->params ['staffname'] ) ? $this->params ['staffname'] : "";
  14014. $staffname = urldecode ( $staffname );
  14015. }
  14016. Doo::loadModel ( 'staff' );
  14017. $staff = new staff ();
  14018. Doo::loadModel ( "receiptDetail" );
  14019. $receiptDetail = new receiptDetail ();
  14020. Doo::loadModel ( 'accountItem' );
  14021. $accountItem = new accountItem ();
  14022. Doo::loadModel ( 'statistics' );
  14023. $statistics = new statistics ();
  14024. Doo::loadModel ( 'L_category' );
  14025. $lCategory = new L_category ();
  14026. Doo::loadModel ( "receiptAuthorityManage" );
  14027. $receiptAuthorityManage = new receiptAuthorityManage ();
  14028. $imcStaff = $receiptAuthorityManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  14029. $cidList = array ();
  14030. foreach ( $imcStaff as $key => $value ) {
  14031. array_push ( $cidList, $value ['cid'] );
  14032. }
  14033. $cidString = implode ( ',', $cidList );
  14034. $staffList = $staff->find ( array (
  14035. 'where' => ' cid in (' . $cidString . ')',
  14036. 'asArray' => true
  14037. ) );
  14038. $stHtml = '';
  14039. $stTitle = "";
  14040. $staffId = 0;
  14041. $cid = 0;
  14042. $ocid = 0;
  14043. foreach ( $staffList as $value ) {
  14044. if ($value ['username'] == $staffname && $value ['username'] != 'admin') {
  14045. $stTitle = $value ['category'] . '-' . $value ['username'];
  14046. $staffId = $value ['sid'];
  14047. $cid = $value ['cid'];
  14048. $ocid = $value ['cid'];
  14049. if (! empty ( $value ['othercid'] ))
  14050. $cid = $value ['cid'] . ',' . $value ['othercid'];
  14051. $stHtml .= '<option selected value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  14052. } elseif ($value ['username'] != 'admin')
  14053. $stHtml .= '<option value="' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  14054. }
  14055. $data ['lCategoryHtml'] = $lCategory->find ( array (
  14056. 'where' => 'cid in(' . $cid . ')',
  14057. 'asArray' => true
  14058. ) );
  14059. if (empty ( $pcid ))
  14060. $pcid = $ocid;
  14061. $data ['ocid'] = $pcid;
  14062. $path = SITE_PATH . $this->STAFFCOLLECTPATH . "staffCollectDetail_" . $year . "_" . $staffId . ".htmls";
  14063. $this->showCache ( $path );
  14064. //
  14065. $receiptCollectList = $receiptDetail->find ( array (
  14066. 'select' => 'staff,item,sum(price) as price,itemCategory,Month(pastDate) as month',
  14067. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  14068. 'groupby' => 'item,Month(pastDate),itemCategory',
  14069. 'asArray' => true
  14070. ) );
  14071. // echo 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year;
  14072. // print_r($receiptCollectList);
  14073. $accountList = $accountItem->find ( array (
  14074. 'asArray' => true
  14075. ) );
  14076. // create CollectDetail HTML
  14077. $collectHtml = array ();
  14078. foreach ( $accountList as $key => $value ) {
  14079. $html = "";
  14080. $asum = 0;
  14081. for($i = 1; $i <= 12; $i ++) {
  14082. $falg = true;
  14083. foreach ( $receiptCollectList as $v ) {
  14084. if ($value ['category'] == $v ['itemCategory'] && $v ['item'] == $value ['name'] && $i == $v ['month']) {
  14085. if ($v ['item'] == '可自加费用') {
  14086. // echo $v ['item'].'/'.$v ['price'].'/'.$v ['month'].$v ['itemCategory'].'<br/>';
  14087. }
  14088. $asum += $v ['price'];
  14089. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14090. $falg = false;
  14091. break;
  14092. }
  14093. }
  14094. if ($falg)
  14095. $html .= '<td class="taR">-</td>';
  14096. }
  14097. $html .= '<td class="taR colGreen"><b>' . $asum . '</b></td>';
  14098. $collectHtml [$value ['category']] [$value ['name']] = $html;
  14099. }
  14100. $data ['collectHtml'] = $collectHtml;
  14101. // print_r($collectHtml);
  14102. // create Adjustment price html
  14103. $receiptCollectList = $receiptDetail->find ( array (
  14104. 'select' => 'staff,sum(price) as price,itemCategory,Month(pastDate) as month',
  14105. 'where' => 'staff=' . $staffId . " and cid=" . $pcid . " and status=1 and Year(pastDate)=" . $year,
  14106. 'groupby' => 'itemCategory,Month(pastDate)',
  14107. 'asArray' => true
  14108. ) );
  14109. $adjustment = array ();
  14110. $collectArray = array (
  14111. '日常相关费用' => array (),
  14112. '差旅相关费用' => array (),
  14113. '培训班费用' => array (),
  14114. '内部培训费用'=>array(),
  14115. '其他' => array ()
  14116. );
  14117. $collectHtml = $this->collectHtml ( $receiptCollectList, '日常相关费用', 'b' );
  14118. array_push ( $collectArray ['日常相关费用'], $collectHtml );
  14119. $collectHtml = $this->collectHtml ( $receiptCollectList, '差旅相关费用', 'b' );
  14120. array_push ( $collectArray ['差旅相关费用'], $collectHtml );
  14121. $collectHtml = $this->collectHtml ( $receiptCollectList, '培训班费用', 'b' );
  14122. array_push ( $collectArray ['培训班费用'], $collectHtml );
  14123. $collectHtml = $this->collectHtml ( $receiptCollectList, '内部培训费用', 'b' );
  14124. array_push ( $collectArray ['内部培训费用'], $collectHtml );
  14125. $collectHtml = $this->collectHtml ( $receiptCollectList, '其他', 'b' );
  14126. array_push ( $collectArray ['其他'], $collectHtml );
  14127. $data ['collectArray'] = $collectArray;
  14128. $collectHtml = $this->collectHtml ( $receiptCollectList, '报销金额调整' );
  14129. array_push ( $adjustment, $collectHtml );
  14130. $data ['adjustment'] = $adjustment;
  14131. // total price html
  14132. $collectHtml = "";
  14133. $total = 0;
  14134. for($i = 1; $i <= 12; $i ++) {
  14135. $sumPrice = 0;
  14136. foreach ( $receiptCollectList as $key => $value ) {
  14137. if ($value ['month'] == $i) {
  14138. $sumPrice += $value ['price'];
  14139. }
  14140. }
  14141. if ($sumPrice == 0)
  14142. $collectHtml .= '<td class="taR">-</td>';
  14143. else
  14144. $collectHtml .= '<td class="taR">¥' . $sumPrice . '</td>';
  14145. $total += $sumPrice;
  14146. }
  14147. $collectHtml .= '<td class="taR colGreen">¥' . $total . '</td>';
  14148. // statistics html
  14149. $stList = $statistics->statisticsByYear ( $year, $staffId );
  14150. if (empty ( $stList ))
  14151. $stList = array (
  14152. 'rePrice' => 0,
  14153. 'agPrice' => 0
  14154. );
  14155. $data ['stList'] = array (
  14156. 'rePrice' => $stList ['rePrice'],
  14157. 'agPrice' => $stList ['agPrice'],
  14158. 'skPrice' => ($stList ['rePrice'] - $stList ['agPrice'])
  14159. );
  14160. $data ['totalPrice'] = $collectHtml;
  14161. $data ['totalYear'] = $total;
  14162. $data ['stHtml'] = $stHtml;
  14163. $data ['year'] = $year;
  14164. $data ['stTitle'] = $stTitle;
  14165. $data ['staffname'] = urlencode ( $staffname );
  14166. $data ['memu'] = "receipt";
  14167. $data ['staff'] = $this->staff;
  14168. $data ['receiptMemu'] = 'companyCategoryCollect';
  14169. $data ['verifyId'] = $this->verifyId;
  14170. $data ['executeId'] = $this->executeId;
  14171. if ($year < date ( "Y" )) {
  14172. Doo::loadModel ( 'receipt' );
  14173. $receipt = new receipt ();
  14174. $receiptList = $receipt->find ( array (
  14175. 'where' => 'staff=' . $staffId . ' and (status=2 or status=4) and Year(date) =' . $year,
  14176. 'asArray' => true
  14177. ) );
  14178. if (empty ( $receiptList )) { // generated files
  14179. ob_start ();
  14180. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  14181. $this->cacheFile ( $path );
  14182. die ();
  14183. }
  14184. }
  14185. $this->render ( "/admin/saeaStaffCollectDetail", $data );
  14186. }
  14187. function BUGFLAG() {
  14188. $status = isset ( $this->params ['status'] ) && is_numeric ( $this->params ['status'] ) ? $this->params ['status'] : 0;
  14189. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( 'Y' );
  14190. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  14191. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  14192. $sid = $this->get_args ( 'sid' ) ? $this->get_args ( 'sid' ) : 0;
  14193. if (empty ( $status ))
  14194. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  14195. $page_size = 12;
  14196. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  14197. $vidList = array ();
  14198. $button = 0;
  14199. Doo::loadModel ( 'verify' );
  14200. $verify = new verify ();
  14201. Doo::loadModel ( 'receipt' );
  14202. $receipt = new receipt ();
  14203. Doo::loadModel ( 'staff' );
  14204. $staff = new staff ();
  14205. Doo::loadModel ( 'L_category' );
  14206. $Lcategory = new L_category ();
  14207. $dateCondition = " and Year(date) =" . $year;
  14208. if (! empty ( $month ))
  14209. $dateCondition = " and Year(date) =" . $year . " and Month(date) = " . $month;
  14210. $categoryList = $Lcategory->find ( array (
  14211. 'asArray' => true
  14212. ) );
  14213. $staffList = $staff->find ( array (
  14214. 'where' => 'cid=' . $cid,
  14215. 'asArray' => true
  14216. ) );
  14217. $cateCondition = "";
  14218. $staffCondition = "";
  14219. $approvalCondition = "";
  14220. if (! empty ( $cid ))
  14221. $cateCondition = ' and cid=' . $cid;
  14222. if (! empty ( $sid )) {
  14223. $staffCondition = ' and staff=' . $sid;
  14224. $cateCondition = "";
  14225. }
  14226. $approvalCondition = " and status=" . $status;
  14227. if ($status == 2) {
  14228. // 查找角色审批人
  14229. $approvalCondition = ' and status=' . $status . ' and (nowStaff like "%,' . $this->staff [0] ['sid'] . '%" or nowStaff like "%' . $this->staff [0] ['sid'] . ',%" or nowStaff=' . $this->staff [0] ['sid'] . ' )';
  14230. }
  14231. if ($status == 5) { // and verifyStaff like "%\"'.$this->staff[0]['sid'].'\":{%"
  14232. $approvalCondition = ' and status=2 ';
  14233. }
  14234. if ($status == 1) {
  14235. $approvalCondition = ' and (status=' . $status . ' or status=6) ';
  14236. }
  14237. // nowStaff like "%'.$this->staff[0]['sid'].'%"
  14238. $pageinfo ['page'] = array (
  14239. 'previous' => ''
  14240. );
  14241. if ($status == 0) {
  14242. $pageinfo = $this->get_page ( "CLD_receipt", $dateCondition . $cateCondition . $staffCondition . ' and status!=5', $page, $page_size, "approvalExpenses", "", "" );
  14243. $receiptList = $receipt->find ( array (
  14244. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition,
  14245. 'limit' => $pageinfo ['lower'] . ',' . $page_size,
  14246. 'desc' => 'rid',
  14247. 'asArray' => true
  14248. ) );
  14249. // echo 'status!=5 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  14250. } else
  14251. $receiptList = $receipt->find ( array (
  14252. 'where' => 'status!=5 ' . $dateCondition . $cateCondition . $staffCondition . $approvalCondition,
  14253. 'desc' => 'rid',
  14254. 'asArray' => true
  14255. ) );
  14256. $rLRes = $receipt->find ( array (
  14257. '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,
  14258. 'desc' => 'rid',
  14259. 'asArray' => true
  14260. ) );
  14261. // echo '1 '.$dateCondition.$cateCondition.$staffCondition.' and verify in ('.$vid.')';
  14262. // print_r($pageinfo);
  14263. $Locate = 0;
  14264. foreach ( $receiptList as $key => $value ) {
  14265. $receiptList [$key] ['Locate'] = $Locate;
  14266. $Locate ++;
  14267. $receiptList [$key] ['reviseDetail'] = array ();
  14268. if (! empty ( $value ['reviseDetail'] ))
  14269. $receiptList [$key] ['reviseDetail'] = json_decode ( $value ['reviseDetail'], true );
  14270. $receiptList [$key] ['accountItem'] = json_decode ( $value ['accountItem'], true );
  14271. $categoryDetil = $Lcategory->getOne ( array (
  14272. 'where' => 'cid=' . $value ['cid'],
  14273. 'asArray' => true
  14274. ) );
  14275. $receiptList [$key] ['category'] = $categoryDetil ['title'];
  14276. $verifyList = $verify->getOne ( array (
  14277. 'where' => 'vid=' . $value ['verify'],
  14278. 'asArray' => true
  14279. ) );
  14280. $verifyList = json_decode ( $verifyList ['staff'], true ); // status opinion
  14281. $verifyStaff = json_decode ( $value ['verifyStaff'], true );
  14282. foreach ( $verifyList as $k => $v ) {
  14283. // init verifyStaff
  14284. $verifyList [$k] ['date'] = "";
  14285. $verifyList [$k] ['opinion'] = "";
  14286. $verifyList [$k] ['status'] = "";
  14287. if (empty ( $verifyStaff )) {
  14288. $verifyList [$k] ['date'] = "";
  14289. $verifyList [$k] ['opinion'] = "";
  14290. if ($v [0] == $this->staff [0] ['sid']) {
  14291. $verifyList [$k] ['status'] = 4;
  14292. $button = 4;
  14293. }
  14294. } else {
  14295. $flag = true;
  14296. foreach ( $verifyStaff as $m => $u ) {
  14297. if ($v [0] == $m) {
  14298. $verifyList [$k] ['date'] = $u ['date'];
  14299. $verifyList [$k] ['opinion'] = $u ['opinion'];
  14300. $verifyList [$k] ['status'] = $u ['status'];
  14301. $flag = false;
  14302. break;
  14303. }
  14304. // elseif($v[0]==$this->staff[0]['sid']){$verifyList[$k]['status']=4;break;}
  14305. // if ($v[0]==$this->staff[0]['sid']&&$m!=$this->staff[0]['sid']){$verifyList[$k]['status']=4;}
  14306. // if($v[0]==$this->staff[0]['sid']&&$v[0]==$m){if ($u['status']!=1&&$u['status']!=3)$button=4;}
  14307. }
  14308. if ($flag) { // 检测可编辑
  14309. if ($v [0] == $this->staff [0] ['sid']) {
  14310. $verifyList [$k] ['status'] = 4;
  14311. $button = 4;
  14312. }
  14313. }
  14314. }
  14315. }
  14316. $receiptList [$key] ['verifyList'] = $verifyList;
  14317. $receiptList [$key] ['staffDetail'] = $staff->getOne ( array (
  14318. 'where' => 'sid=' . $value ['staff'],
  14319. 'asArray' => true
  14320. ) );
  14321. $receiptList [$key] ['button'] = $button;
  14322. $receiptList [$key] ['nowStaffArray'] = explode ( ',', $value ['nowStaff'] );
  14323. }
  14324. // print_r($receiptList);die;
  14325. // $data['verifyDetail']=$verifyDetail;
  14326. $mothHtml = "";
  14327. for($i = 1; $i <= 12; $i ++) {
  14328. if ($month == $i)
  14329. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  14330. else
  14331. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  14332. }
  14333. $data ['mothHtml'] = $mothHtml;
  14334. $data ['page'] = $pageinfo;
  14335. $data ['receiptList'] = $receiptList;
  14336. $data ['receiptApprovalCount'] = count ( $rLRes );
  14337. $data ['status'] = $status;
  14338. $data ['year'] = $year;
  14339. $data ['categoryList'] = $categoryList;
  14340. $data ['staffList'] = $staffList;
  14341. $data ['cid'] = $cid;
  14342. $data ['sid'] = $sid;
  14343. // print_r($receiptList);
  14344. $data ['memu'] = "receipt";
  14345. $data ['staff'] = $this->staff;
  14346. $data ['receiptMemu'] = 'approvalExpenses';
  14347. $data ['verifyId'] = $this->verifyId;
  14348. $data ['executeId'] = $this->executeId;
  14349. $this->render ( "/admin/FALG", $data );
  14350. }
  14351. function ajaxGetReceiptOrder() {
  14352. $receiptOrder = $this->get_args ( 'receiptOrder' ) ? $this->get_args ( 'receiptOrder' ) : "";
  14353. if (! empty ( $receiptOrder )) {
  14354. Doo::loadModel ( 'receipt' );
  14355. $receipt = new receipt ();
  14356. Doo::loadModel ( 'staff' );
  14357. $staff = new staff ();
  14358. $receiptInfo = $receipt->getOne ( array (
  14359. 'where' => ' receiptOrder="' . $receiptOrder . '"',
  14360. 'asArray' => true
  14361. ) );
  14362. $verifyStaff = json_decode ( $receiptInfo ['verifyStaff'], true );
  14363. $html = '<div class="control-group"><div class="controls clearfix"><table class="table table table-bordered"><tbody>
  14364. <tr><td>单号:<b>' . $receiptOrder . '</b></td><td>金额:<b class="colOrange">¥' . $receiptInfo ['sum'] . '</b></td></tr>
  14365. </tbody></table><table class="table table table-bordered"><tbody>';
  14366. foreach ( $verifyStaff as $key => $value ) {
  14367. $staffInfo = $staff->getOne ( array (
  14368. 'select' => 'username',
  14369. 'where' => ' sid="' . $key . '"',
  14370. 'asArray' => true
  14371. ) );
  14372. $html .= '<tr><th width="70">' . $staffInfo ['username'] . '</th><td>' . $value ['opinion'] . '</td></tr>';
  14373. }
  14374. $html .= '</tbody></table></div></div>';
  14375. echo json_encode ( array (
  14376. 'status' => 1,
  14377. 'receiptHtml' => $html
  14378. ) );
  14379. die ();
  14380. }
  14381. echo json_encode ( array (
  14382. 'status' => 2,
  14383. 'receiptHtml' => ''
  14384. ) );
  14385. die ();
  14386. }
  14387. function _getMonthCollectDetail($receiptCollectList,$aiList) {
  14388. if (! empty ( $receiptCollectList )) {
  14389. $receiptL = array (
  14390. '日常相关费用' => array (),
  14391. '差旅相关费用' => array (),
  14392. '内部培训费用'=>array(),
  14393. '培训班费用' => array (),
  14394. '其他' => array ()
  14395. );
  14396. $html = "";
  14397. $psum = 0;
  14398. foreach ( $aiList[$this->AGENCY] as $value ) {
  14399. $falg = true;
  14400. foreach ( $receiptCollectList as $v ) {
  14401. if ($v ['itemCategory'] == '日常相关费用') {
  14402. if ($v ['item'] == $value['name']) {
  14403. $psum += $v ['price'];
  14404. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14405. $falg = false;
  14406. break;
  14407. }
  14408. }
  14409. }
  14410. if ($falg)
  14411. $html .= '<td class="taR">-</td>';
  14412. }
  14413. if (! empty ( $psum ))
  14414. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14415. else
  14416. $psum = '<td class="colGreen taR">-</td>';
  14417. $receiptL ['日常相关费用'] = $psum . $html;
  14418. /* ----------------------------------- */
  14419. $html = "";
  14420. $psum = 0;
  14421. foreach ( $aiList[$this->TRAVEL] as $value ) {
  14422. $falg = true;
  14423. foreach ( $receiptCollectList as $v ) {
  14424. if ($v ['itemCategory'] == '差旅相关费用') {
  14425. if ($v ['item'] == $value['name']) {
  14426. $psum += $v ['price'];
  14427. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14428. $falg = false;
  14429. break;
  14430. }
  14431. }
  14432. }
  14433. if ($falg)
  14434. $html .= '<td class="taR">-</td>';
  14435. }
  14436. if (! empty ( $psum ))
  14437. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14438. else
  14439. $psum = '<td class="colGreen taR">-</td>';
  14440. $receiptL ['差旅相关费用'] = $psum . $html;
  14441. /* ----------------------------------- */
  14442. $html = "";
  14443. $psum = 0;
  14444. foreach ( $aiList[$this->INTTRAIN] as $value ) {
  14445. $falg = true;
  14446. foreach ( $receiptCollectList as $v ) {
  14447. if ($v ['itemCategory'] == '内部培训费用') {
  14448. if ($v ['item'] == $value['name']) {
  14449. $psum += $v ['price'];
  14450. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14451. $falg = false;
  14452. break;
  14453. }
  14454. }
  14455. }
  14456. if ($falg)
  14457. $html .= '<td class="taR">-</td>';
  14458. }
  14459. if (! empty ( $psum ))
  14460. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14461. else
  14462. $psum = '<td class="colGreen taR">-</td>';
  14463. $receiptL ['内部培训费用'] = $psum . $html;
  14464. /* ------------------------------------- */
  14465. $html = "";
  14466. $psum = 0;
  14467. foreach ( $aiList[$this->TRAIN] as $value ) {
  14468. $falg = true;
  14469. foreach ( $receiptCollectList as $v ) {
  14470. if ($v ['itemCategory'] == '培训班费用') {
  14471. if ($v ['item'] == $value['name']) {
  14472. $psum += $v ['price'];
  14473. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14474. $falg = false;
  14475. break;
  14476. }
  14477. }
  14478. }
  14479. if ($falg)
  14480. $html .= '<td class="taR">-</td>';
  14481. }
  14482. if (! empty ( $psum ))
  14483. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14484. else
  14485. $psum = '<td class="colGreen taR">-</td>';
  14486. $receiptL ['培训班费用'] = $psum . $html;
  14487. /* ------------------------------------- */
  14488. $html = "";
  14489. $psum = 0;
  14490. foreach ( $aiList[$this->OTHER] as $value ) {
  14491. $falg = true;
  14492. foreach ( $receiptCollectList as $v ) {
  14493. if ($v ['itemCategory'] == '其他') {
  14494. if ($v ['item'] == $value['name']) {
  14495. $psum += $v ['price'];
  14496. $html .= '<td class="taR">' . $v ['price'] . '</td>';
  14497. $falg = false;
  14498. break;
  14499. }
  14500. }
  14501. }
  14502. if ($falg)
  14503. $html .= '<td class="taR">-</td>';
  14504. }
  14505. if (! empty ( $psum ))
  14506. $psum = '<td class="colGreen taR">' . $psum . '</td>';
  14507. else
  14508. $psum = '<td class="colGreen taR">-</td>';
  14509. $receiptL ['其他'] = $psum . $html;
  14510. /* ------------------------------------- */
  14511. $html = "";
  14512. $psum = 0;
  14513. foreach ( $receiptCollectList as $v ) {
  14514. if ($v ['itemCategory'] == '报销金额调整') {
  14515. if (! empty ( $v ['price'] ))
  14516. $psum += $v ['price'];
  14517. }
  14518. }
  14519. if (! empty ( $psum ))
  14520. $psum = '<td class="taR colOrange">' . $psum . '</td>';
  14521. else
  14522. $psum = '<td class="taR colOrange">-</td>';
  14523. $receiptL ['报销金额调整'] = $psum . $html;
  14524. } else {
  14525. $receiptL [$this->AGENCY] ='<td class="colGreen taR">-</td>';
  14526. foreach ( $aiList[$this->AGENCY] as $va ) {
  14527. $receiptL [$this->AGENCY] .='<td class="taR">-</td>';
  14528. }
  14529. $receiptL [$this->TRAVEL] ='<td class="colGreen taR">-</td>';
  14530. foreach ( $aiList[$this->TRAVEL] as $va ) {
  14531. $receiptL [$this->TRAVEL] .='<td class="taR">-</td>';
  14532. }
  14533. $receiptL [$this->INTTRAIN] ='<td class="colGreen taR">-</td>';
  14534. foreach ( $aiList[$this->INTTRAIN] as $va ) {
  14535. $receiptL [$this->INTTRAIN] .='<td class="taR">-</td>';
  14536. }
  14537. $receiptL [$this->TRAIN] ='<td class="colGreen taR">-</td>';
  14538. foreach ( $aiList[$this->TRAIN] as $va ) {
  14539. $receiptL [$this->TRAIN] .='<td class="taR">-</td>';
  14540. }
  14541. $receiptL [$this->OTHER] ='<td class="colGreen taR">-</td>';
  14542. foreach ( $aiList[$this->OTHER] as $va ) {
  14543. $receiptL [$this->OTHER] .='<td class="taR">-</td>';
  14544. }
  14545. $receiptL ['报销金额调整'] = '<td class="taR colOrange">-</td>';
  14546. }
  14547. return $receiptL;
  14548. }
  14549. function eMail() {
  14550. Doo::loadModel ( 'staff' );
  14551. $staff = new staff ();
  14552. Doo::loadModel ( 'receipt' );
  14553. $receipt = new receipt ();
  14554. Doo::loadModel ( 'L_category' );
  14555. $Lcategory = new L_category ();
  14556. Doo::loadModel ( "verify" );
  14557. $verify = new verify ();
  14558. $staffList = $staff->find ( array (
  14559. 'asArray' => true
  14560. ) );
  14561. foreach ( $staffList as $key => $value ) {
  14562. if ($value ['username'] != 'admin') {
  14563. // 提交人
  14564. $receiptList = $receipt->find ( array (
  14565. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0',
  14566. 'asArray' => true
  14567. ) );
  14568. if (! empty ( $receiptList )) {
  14569. $html = '<br><div><style></style>
  14570. <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0"><tbody>
  14571. <tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody>
  14572. <tr><td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14573. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span>
  14574. </td></tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14575. <tbody><tr>
  14576. <td style="padding: 0 40px;" align="left">
  14577. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14578. </td></tr><tr>
  14579. <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>
  14580. </tr>
  14581. </tbody> </table></td> </tr> <tr><td>
  14582. <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">
  14583. <tbody> <tr><td>
  14584. <p style="margin-top:20px;margin-bottom:10px;margin-left:40px;color:#383838;font-size:18px;font-weight:bold;line-height:36px;">
  14585. 以下报销单完成了审批,等着收款吧:</p>
  14586. </td></tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"> <tbody>';
  14587. foreach ( $receiptList as $k => $v ) {
  14588. $category = $Lcategory->getOne ( array (
  14589. 'where' => 'cid=' . $v ['cid'],
  14590. 'asArray' => true
  14591. ) );
  14592. $html .= '
  14593. <tr>
  14594. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14595. <td align="left">
  14596. <p style="font-size:16px;line-height:22px;margin:0">' . $v ['receiptOrder'] . '</p></td>
  14597. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '</p></td>
  14598. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $v ['sum'] . '元</p></td>
  14599. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $v ['date'] . '</span></td>
  14600. </tr>';
  14601. }
  14602. $html .= ' </tbody></table></td></tr></tbody></table></td></tr>
  14603. <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>
  14604. </tr></tbody></table></td> </tr></tbody></table> </div><br>';
  14605. if (filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) {
  14606. $this->SMail ( $value ['email'], "CLD提醒您,您的报销单已同意支付", $html );
  14607. $this->SMail ( '1971614655@qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14608. $this->SMail ( 'cpthought@vip.qq.com', "CLD提醒您,您的报销单已同意支付", $html );
  14609. $receipt = new receipt ();
  14610. $receipt->notice = 1;
  14611. $receipt->update ( array (
  14612. 'where' => 'staff=' . $value ['sid'] . ' and status=1 and notice=0'
  14613. ) );
  14614. }
  14615. }
  14616. // 审批人
  14617. $verifyList = $verify->find ( array (
  14618. 'where' => " staff like '%[\"" . $value ['sid'] . "\",%'",
  14619. 'asArray' => true
  14620. ) );
  14621. $html = '<br><div><style></style> <table style="background-color:#fff; width:100%;" cellpadding="0" cellspacing="0">
  14622. <tbody><tr><td><table style="background-color:#fff; width:640px;" cellpadding="0" cellspacing="0" align="center"><tbody><tr>
  14623. <td style="background-color:#8E0950;padding:30px 0 40px;" align="center">
  14624. <span style="vertical-align:bottom;font-size:20px;color:#fff;">CLD 邮件提醒</span></td>
  14625. </tr><tr><td><table style="background-color:#fff;border:1px solid #ddd;border-bottom:0px;width:100%;" cellpadding="0" cellspacing="0" align="left">
  14626. <tbody><tr><td style="padding: 0 40px;" align="left">
  14627. <p style="margin-top:40px;margin-bottom:20px;color:#383838;font-size:20px;line-height:32px;">Hi,' . $value ['username'] . '</p>
  14628. </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>
  14629. </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">
  14630. <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>
  14631. </tr><tr><td><table style="width:100%;padding-right:30px;" cellpadding="0" cellspacing="0" align="left"><tbody>';
  14632. foreach ( $verifyList as $k => $v ) {
  14633. $receiptList = $receipt->find ( array (
  14634. 'where' => "verify=" . $v ['vid'] . " and status=2 and verifyStaff not like '%{\"" . $value ['sid'] . "\":%'",
  14635. 'asArray' => true
  14636. ) );
  14637. foreach ( $receiptList as $r => $l ) {
  14638. $category = $Lcategory->getOne ( array (
  14639. 'where' => 'cid=' . $l ['cid'],
  14640. 'asArray' => true
  14641. ) );
  14642. $staffDetile = $staff->getOne ( array (
  14643. 'where' => 'sid=' . $l ['staff'],
  14644. 'asArray' => true
  14645. ) );
  14646. $html .= '
  14647. <tr>
  14648. <td style="border-left:7px solid transparent;" align="left" width="30px"><br></td>
  14649. <td align="left">
  14650. <p style="font-size:16px;line-height:22px;margin:0">' . $l ['receiptOrder'] . '</p></td>
  14651. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">' . $category ['title'] . '-' . $staffDetile ['username'] . '</p></td>
  14652. <td style="" align="left"><p style="font-size:16px;line-height:22px;margin:0">¥' . $l ['sum'] . '元</p></td>
  14653. <td align="right"><span class="past" style="font-size:16px;line-height:22px;">' . $l ['date'] . '</span></td>
  14654. </tr>';
  14655. }
  14656. }
  14657. $html .= '
  14658. </tbody></table></td></tr> </tbody></table></td></tr><tr>
  14659. <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>
  14660. </tr></tbody></table></td></tr></tbody></table></div><br>';
  14661. if ((filter_var ( $value ['email'], FILTER_VALIDATE_EMAIL )) && (! empty ( $verifyList )) && (! empty ( $receiptList ))) {
  14662. $this->SMail ( $value ['email'], "CLD提醒您,有需要你审批的报销单", $html );
  14663. // $receipt=new receipt();
  14664. // $receipt->notice=1;
  14665. // $receipt->update(array('where'=>'staff='.$value['sid'].' and status=1 and notice=0'));
  14666. }
  14667. }
  14668. }
  14669. }
  14670. function setWXMsg($rid, $type) {
  14671. Doo::loadModel ( "receipt" );
  14672. $receipt = new receipt ();
  14673. $receiptDetail = $receipt->getOne ( array (
  14674. 'where' => 'rid=' . $rid,
  14675. 'asArray' => true
  14676. ) );
  14677. if (! empty ( $receiptDetail )) {
  14678. Doo::loadModel ( 'staff' );
  14679. $staff = new staff ();
  14680. $staffmsg = $staff->getOne ( array (
  14681. 'where' => "sid='" . $receiptDetail ['staff'] . "'",
  14682. 'asArray' => TRUE
  14683. ) );
  14684. if (! empty ( $staffmsg ['wxid'] )) {
  14685. require_once (SITE_PATH . '/protected/class/client.php');
  14686. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  14687. $user = $staffmsg ['wxid'];
  14688. $receiptName = '';
  14689. $msg = '';
  14690. switch ($receiptDetail ['Rtype']) {
  14691. case 0 :
  14692. $receiptName = '报销';
  14693. break;
  14694. case 1 :
  14695. $receiptName = '借款';
  14696. break;
  14697. case 2 :
  14698. $receiptName = '对公汇款';
  14699. break;
  14700. }
  14701. switch ($type) {
  14702. case 1 :
  14703. $msg = '太好了,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已同意支付。';
  14704. break;
  14705. case 2 :
  14706. $msg = '注意,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被撤回,请及时处理。';
  14707. break;
  14708. case 3 :
  14709. $msg = '很遗憾,您的' . $receiptName . ' ' . $receiptDetail ['receiptOrder'] . ',¥' . $receiptDetail ['sum'] . ',已被终止。';
  14710. break;
  14711. }
  14712. // $result = $client->SendMsg ( $user, $msg, 'text' );
  14713. }
  14714. }
  14715. }
  14716. // Email发送函数
  14717. function SMail($toemail, $subject, $contents) {
  14718. Doo::loadClass ( 'class.phpmailer' );
  14719. $mail = new PHPMailer ();
  14720. $mail->From = "postmaster@support.zhzdwk.com"; // 发送邮箱全名
  14721. $mail->FromName = "=?UTF-8?B?" . base64_encode ( "CLD" ) . "?="; // 发送人昵称
  14722. $mail->Username = "postmaster@websupport.sendcloud.org"; // 用户名
  14723. $mail->Password = "cDO1GjtY1seH"; // 密码
  14724. $mail->CharSet = "UTF8";
  14725. $mail->SMTPAuth = true;
  14726. $mail->Host = "smtpcloud.sohu.com"; // 邮件主机的smtp地址
  14727. $mail->Mailer = "smtp";
  14728. $mail->Port = 25;
  14729. $mail->Subject = "=?UTF-8?B?" . base64_encode ( $subject ) . "?=";
  14730. $mail->MsgHTML ( $contents );
  14731. $mail->AddAddress ( $toemail );
  14732. $mail->CharSet = "UTF-8";
  14733. return $mail->Send ();
  14734. }
  14735. function h5Upload() {
  14736. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14737. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14738. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14739. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14740. header ( "HTTP/1.1 500 Internal Server Error" );
  14741. echo "POST exceeded maximum allowed size.";
  14742. exit ( 0 );
  14743. }
  14744. // Settings
  14745. $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)
  14746. $upload_name = "Filedata";
  14747. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14748. $extension_whitelist = array (
  14749. "doc",
  14750. "txt",
  14751. "jpg",
  14752. "gif",
  14753. "png"
  14754. ); // Allowed file extensions
  14755. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14756. // Other variables
  14757. $MAX_FILENAME_LENGTH = 260;
  14758. $file_name = "";
  14759. $file_extension = "";
  14760. $uploadErrors = array (
  14761. 0 => "文件上传成功",
  14762. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14763. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14764. 3 => "上传的文件仅为部分文件",
  14765. 4 => "没有文件上传",
  14766. 6 => "缺少临时文件夹"
  14767. );
  14768. $nk = time ();
  14769. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14770. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14771. echo "文件无法保存.";
  14772. exit ( 0 );
  14773. }
  14774. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14775. echo json_encode ( array (
  14776. 'filename' => $file_name,
  14777. 'id' => $nk
  14778. ) );
  14779. exit ( 0 );
  14780. }
  14781. function swfupload() {
  14782. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  14783. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  14784. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  14785. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  14786. header ( "HTTP/1.1 500 Internal Server Error" );
  14787. echo "POST exceeded maximum allowed size.";
  14788. exit ( 0 );
  14789. }
  14790. // Settings
  14791. $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)
  14792. $upload_name = "Filedata";
  14793. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  14794. $extension_whitelist = array (
  14795. "doc",
  14796. "txt",
  14797. "jpg",
  14798. "gif",
  14799. "png"
  14800. ); // Allowed file extensions
  14801. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  14802. // Other variables
  14803. $MAX_FILENAME_LENGTH = 260;
  14804. $file_name = "";
  14805. $file_extension = "";
  14806. $uploadErrors = array (
  14807. 0 => "文件上传成功",
  14808. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  14809. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  14810. 3 => "上传的文件仅为部分文件",
  14811. 4 => "没有文件上传",
  14812. 6 => "缺少临时文件夹"
  14813. );
  14814. $nk = time ();
  14815. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  14816. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  14817. echo "文件无法保存.";
  14818. exit ( 0 );
  14819. }
  14820. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  14821. echo json_encode ( array (
  14822. 'filename' => $file_name,
  14823. 'id' => $nk
  14824. ) );
  14825. exit ( 0 );
  14826. }
  14827. function _GetFileEXT($filename) {
  14828. $pics = explode ( '.', $filename );
  14829. $num = count ( $pics );
  14830. return $pics [$num - 1];
  14831. }
  14832. /**
  14833. * 获取get或者POST值
  14834. * @param string $name 属性名称
  14835. * @return fixed 值
  14836. */
  14837. function get_args($name) {
  14838. if (isset ( $_GET [$name] )) {
  14839. if (is_array ( $_GET [$name] ))
  14840. return $_GET [$name];
  14841. else
  14842. return addslashes ( $_GET [$name] );
  14843. } elseif (isset ( $_POST [$name] )) {
  14844. if (is_array ( $_POST [$name] ))
  14845. return $_POST [$name];
  14846. else
  14847. return addslashes ( $_POST [$name] );
  14848. } else
  14849. return false;
  14850. }
  14851. function num_to_rmb($num) {
  14852. $c1 = "零壹贰叁肆伍陆柒捌玖";
  14853. $c2 = "分角元拾佰仟万拾佰仟亿";
  14854. // 精确到分后面就不要了,所以只留两个小数位
  14855. $num = round ( $num, 2 );
  14856. // 将数字转化为整数
  14857. $num = $num * 100;
  14858. if (strlen ( $num ) > 10) {
  14859. return "金额太大,请检查";
  14860. }
  14861. $i = 0;
  14862. $c = "";
  14863. while ( 1 ) {
  14864. if ($i == 0) {
  14865. // 获取最后一位数字
  14866. $n = substr ( $num, strlen ( $num ) - 1, 1 );
  14867. } else {
  14868. $n = $num % 10;
  14869. }
  14870. // 每次将最后一位数字转化为中文
  14871. $p1 = substr ( $c1, 3 * $n, 3 );
  14872. $p2 = substr ( $c2, 3 * $i, 3 );
  14873. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  14874. $c = $p1 . $p2 . $c;
  14875. } else {
  14876. $c = $p1 . $c;
  14877. }
  14878. $i = $i + 1;
  14879. // 去掉数字最后一位了
  14880. $num = $num / 10;
  14881. // echo $num.'</br>';
  14882. $num = ( int ) $num;
  14883. // $num =floor($num);
  14884. // $num = round ( $num, 0, PHP_ROUND_HALF_DOWN );
  14885. // echo $num.'</br>';
  14886. // 结束循环
  14887. if ($num == 0) {
  14888. break;
  14889. }
  14890. }
  14891. // echo $c.'</br>';
  14892. $j = 0;
  14893. $slen = strlen ( $c );
  14894. while ( $j < $slen ) {
  14895. // utf8一个汉字相当3个字符
  14896. $m = substr ( $c, $j, 6 );
  14897. // 处理数字中很多0的情况,每次循环去掉一个汉字“零”
  14898. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  14899. $left = substr ( $c, 0, $j );
  14900. $right = substr ( $c, $j + 3 );
  14901. $c = $left . $right;
  14902. $j = $j - 3;
  14903. $slen = $slen - 3;
  14904. }
  14905. $j = $j + 3;
  14906. }
  14907. // 这个是为了去掉类似23.0中最后一个“零”字
  14908. if (substr ( $c, strlen ( $c ) - 3, 3 ) == '零') {
  14909. $c = substr ( $c, 0, strlen ( $c ) - 3 );
  14910. }
  14911. // 将处理的汉字加上“整”
  14912. if (empty ( $c )) {
  14913. return "零元整";
  14914. } else {
  14915. return $c . "整";
  14916. }
  14917. }
  14918. /**
  14919. * 获得分页数据
  14920. * @param unknown_type $table
  14921. * @param unknown_type $condition
  14922. * @param unknown_type $on_page
  14923. * @param unknown_type $page_size
  14924. */
  14925. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  14926. $page_c = "";
  14927. $page ['previous'] = $this->get_previous ( $on_page );
  14928. $page ['on_page'] = $on_page;
  14929. $total_count = $this->get_table_count ( $table, $condition );
  14930. $total = intval ( $total_count / $page_size );
  14931. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  14932. $page ['total_data'] = $total_count;
  14933. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  14934. $i = 1;
  14935. $page_max = 1;
  14936. $page_width = 3;
  14937. if ($on_page >= $page_width) {
  14938. $page_max = intval ( $on_page / $page_width ) + 1;
  14939. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  14940. }
  14941. for(; $i <= $page ['total_page']; $i ++) {
  14942. if ($i == $on_page)
  14943. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  14944. else
  14945. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  14946. if ($i == ($page_width * $page_max))
  14947. break;
  14948. }
  14949. $page ['page'] = $page_c;
  14950. $page ['lower'] = (-- $on_page) * $page_size;
  14951. return $page;
  14952. }
  14953. /**
  14954. * 获取总页数
  14955. * @param unknown_type $table
  14956. * @param unknown_type $condition
  14957. */
  14958. public function get_table_count($table = "", $condition = "") {
  14959. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14960. $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  14961. // echo $sql;die;
  14962. $query = Doo::db ()->query ( $sql );
  14963. $result = $query->fetch ();
  14964. return $result ['count'];
  14965. }
  14966. /**
  14967. * 获取上一页
  14968. * @param unknown_type $on_page
  14969. */
  14970. function get_previous($on_page = 1) {
  14971. return $on_page != 0 ? $on_page - 1 : $on_page;
  14972. }
  14973. function _getReceiptTrainPayment($invoiceTrainId,$trainLoanRid,$rid){
  14974. // 收入合计
  14975. Doo::loadModel ( 'invoiceTraining' );
  14976. $invoiceTraining = new invoiceTraining ();
  14977. Doo::loadModel ( 'receipt' );
  14978. $receipt = new receipt ();
  14979. $invoiceTrainingDetail = array (
  14980. 'invoiceArriveAmount' => '0.00',
  14981. 'RIAmount' => '0.00',
  14982. 'invoiceTotalAmount' => '0.00',
  14983. 'invoiceCompanyAmount' => '0.00',
  14984. 'invoiceArriveAmountM'=>'0.00',
  14985. 'invoiceCompanyAmountM'=>'0.00'
  14986. );
  14987. if ($invoiceTrainId != 0) {
  14988. $invoiceTrainingDetail = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceTrainId );
  14989. }
  14990. $invoiceArriveAmount = $RIAmount = 0;
  14991. if (! empty ( $invoiceTrainingDetail )) {
  14992. $invoiceArriveAmount = $invoiceTrainingDetail ['invoiceArriveAmount'];
  14993. $RIAmount = $invoiceTrainingDetail ['RIAmount'];
  14994. }
  14995. // 备用金
  14996. $sum = 0;
  14997. if (! empty ( $trainLoanRid )) {
  14998. $receiptLoanList = $receipt->getReceiptInRid ( $trainLoanRid );
  14999. foreach ($receiptLoanList as $key=>$value){
  15000. $sum+=$value['sum'];
  15001. }
  15002. // $receiptLoanDetailBak = $receipt->getReceiptByRid ( $trainLoanRid );
  15003. // $sum = $receiptLoanDetailBak ['sum'];
  15004. }
  15005. // 支出项金额详情
  15006. // 项目金额合计
  15007. Doo::loadModel ( 'RItem' );
  15008. $RItem = new RItem ();
  15009. Doo::loadModel ( 'accountItem' );
  15010. $accountItem = new accountItem ();
  15011. // 讲师获得
  15012. Doo::loadModel ( 'RILecturer' );
  15013. $RILecturer = new RILecturer ();
  15014. $RItemList = $RItem->getRItemByRid ($rid );
  15015. $RILecturerList = $RILecturer->getRILecturerByRid ( $rid );
  15016. // 支出项金额详情
  15017. $aiData = $accountItem->getTrainingDetail ( $RItemList, $RILecturerList, $invoiceArriveAmount );
  15018. $categoryActualExpenditure = $aiData ['total'] - $aiData ['categoryActualExpenditure'];
  15019. $payment = $sum + $RIAmount - $categoryActualExpenditure;
  15020. return $payment;
  15021. }
  15022. }
  15023. ?>