InvoiceController.php 289 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // var_dump($flag) ;
  64. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  65. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  66. Doo::loadModel ( "invoiceCategoryManage" );
  67. $invoiceCategoryManage = new invoiceCategoryManage ();
  68. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  69. if (empty ( $icm ))
  70. die ( 'illegal request' );
  71. }
  72. // 单独判断应收款访问权限
  73. if ($action == 'invoiceAggregateCompanyDetail') {
  74. Doo::loadModel ( "invoiceCompanyManage" );
  75. $invoiceCompanyManage = new invoiceCompanyManage ();
  76. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  77. if (empty ( $icm ))
  78. die ( 'illegal request' );
  79. }
  80. if (! $flag)
  81. die ( 'illegal request' );
  82. }
  83. function __construct() {
  84. if (isset ( $_COOKIE ["staff"] )) {
  85. if (! empty ( $_COOKIE ["staff"] )) {
  86. Doo::loadModel ( 'staff' );
  87. $staff = new staff ();
  88. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  89. $this->ACTION = $uriPartsOrig [1];
  90. $this->data ['new'] = $this->isInvoiceNew ();
  91. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  92. return "/";
  93. }
  94. }
  95. Doo::loadCore ( 'uri/DooUriRouter' );
  96. $router = new DooUriRouter ();
  97. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  98. if ($routeRs ['1'] != "login") {
  99. header ( 'Content-Type:text/html;charset=utf-8' );
  100. @header ( "Location: /login" );
  101. }
  102. }
  103. function testSend() {
  104. // 测试根据规则发送信息 普通发送
  105. // $pendingApprovalsSid = 41;
  106. // Doo::loadModel ( 'staff' );
  107. // $staff = new staff ();
  108. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  109. // // 发送微信审批通知
  110. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  111. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  112. // Doo::loadModel ( 'staff' );
  113. // $staff = new staff ();
  114. // $toparty = $this->getToparty ( '广东办' );
  115. // $wxList = array ();
  116. // if (! empty ( $toparty )) {
  117. // $userList = $this->getUserByToparty ( $toparty );
  118. // $userCon = implode ( ',', $userList );
  119. // // echo $userCon;
  120. // $sidList = $staff->getStaffByWxid ( $userCon );
  121. // foreach ( $sidList as $key => $value ) {
  122. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  123. // if ($falg) {
  124. // array_push ( $wxList, $value ['wxid'] );
  125. // }
  126. // }
  127. // $wxString = implode ( '|', $wxList );
  128. // print_r ( $wxList );
  129. // echo $wxString;
  130. // }
  131. // 测试发送
  132. /*
  133. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  134. */
  135. // print_r ( $userList );
  136. // $msTouser='caipin|outaozhen';
  137. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  138. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  139. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  140. // $toparty= $this->getToparty('广东办');
  141. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  142. // $toparty = 26;
  143. // $msg = '';
  144. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  145. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  146. }
  147. function invoice() {
  148. Doo::loadModel ( 'invoice' );
  149. $invoice = new invoice ();
  150. Doo::loadModel ( 'express' );
  151. $express = new express ();
  152. $expressList = $express->getExpressByAll ();
  153. $this->data ['expressList'] = $expressList;
  154. // Doo::loadModel ( 'invoiceReceivables' );
  155. // $invoiceReceivables = new invoiceReceivables ();
  156. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  157. Doo::loadClass ( 'XDeode' );
  158. $XDeode = new XDeode ( 5 );
  159. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  160. Doo::loadModel ( 'invoiceStatistics' );
  161. $invoiceStatistics = new invoiceStatistics ();
  162. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  163. // 缓存统计结果
  164. $year = date ( "Y" );
  165. $tmp_date = date ( "Ym" );
  166. $tmp_year = substr ( $tmp_date, 0, 4 );
  167. $tmp_mon = substr ( $tmp_date, 4, 2 );
  168. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  169. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  170. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  171. if (is_file ( $path ))
  172. $htm = file_get_contents ( $path );
  173. else
  174. $htm = $this->showCache ( $path, $sid );
  175. $invoiceList = $invoice->getMyInvoice ( $sid );
  176. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  177. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  178. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  179. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  180. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  181. // print_r($myInvoiceUnAccount);
  182. $this->data ['isMonth'] = $isMonth;
  183. $this->data ['htm'] = $htm;
  184. $this->data ['invoiceList'] = $invoiceList;
  185. $this->data ['receivablesList'] = $list;
  186. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  187. $this->data ['memu'] = "invoice";
  188. $this->data ['staff'] = $this->staff;
  189. $this->data ['receiptMemu'] = 'invoice';
  190. $this->render ( "/admin/invoice", $this->data );
  191. }
  192. function invoiceExpress() {
  193. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  194. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  195. $this->data ['expressCom'] = $expressCom;
  196. $this->data ['expressNumber'] = $expressNumber;
  197. $this->render ( "/admin/invoiceExpress", $this->data );
  198. }
  199. function invoiceAdd() {
  200. Doo::loadModel ( 'L_category' );
  201. $lCategory = new L_category ();
  202. $category = $lCategory->find ( array (
  203. 'asArray' => true
  204. ) );
  205. $this->data ['category'] = $category;
  206. $this->data ['memu'] = "invoice";
  207. $this->data ['staff'] = $this->staff;
  208. $this->data ['receiptMemu'] = 'invoice';
  209. $this->render ( "/admin/invoiceAdd", $this->data );
  210. }
  211. /**
  212. * 提交一份开票申请,并记录下操作日志
  213. *
  214. * @since 1.0.0
  215. * @var integer cid 办事处ID
  216. * @var integer invoiceType 发票类型
  217. * @var integer doPost 是否邮寄
  218. * @var integer invoicePrice 开票金额
  219. * @var string invoiceElement 开票内容
  220. * @var string invoiceTitle 发票抬头
  221. * @var string invoiceCompany 单位名称
  222. * @var string TIN 纳税人识别码
  223. * @var string address 注册地址
  224. * @var string phone 注册电话
  225. * @var string bank 开户银行
  226. * @var string bankAccount 银行账户
  227. * @var string recipients 收件人
  228. * @var string recipientsPhone 收件人手机/电话
  229. * @var string recipientsAddress 收件地址
  230. * @var string mailItems 邮寄物品
  231. * @var string remark 备注
  232. * @return string 返回跳转开票主页路径
  233. */
  234. function invoiceAddDo() {
  235. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  236. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  237. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  238. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  239. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  240. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  241. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  242. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  243. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  244. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  245. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  246. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  247. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  248. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  249. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  250. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  251. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  252. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  253. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  254. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  255. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  256. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  257. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  258. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  259. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  260. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  261. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  262. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  263. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  264. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  265. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  266. /*
  267. * $mailList=array(); array_push($mailList, array('invoice'=>1)); array_push($mailList, array('mailItems'=>$mailItems)); if (!empty($softLock)) array_push($mailList, array('softLock'=>$softLockNum)); if (!empty($contract)) array_push($mailList, array('contract'=>$contractNum)); if (!empty($instructions)) array_push($mailList, array('instructions'=>$instructionsNum)); if (!empty($remittance)) array_push($mailList, array('remittance'=>$remittance)); echo json_encode($mailList) ; print_r($mailList); die;
  268. */
  269. if (empty ( $this->staff [0] ))
  270. die ( 'illegal request' );
  271. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  272. Doo::loadModel ( 'invoice' );
  273. $invoice = new invoice ();
  274. Doo::loadModel ( 'L_category' );
  275. $lCategory = new L_category ();
  276. Doo::loadModel ( 'invoiceManage' );
  277. $invoiceManage = new invoiceManage ();
  278. Doo::loadModel ( 'invoiceOperationLog' );
  279. $invoiceOperationLog = new invoiceOperationLog ();
  280. $categoryDetil = $lCategory->getOne ( array (
  281. 'SELECT' => 'title',
  282. 'where' => 'cid=' . $cid,
  283. 'asArray' => true
  284. ) );
  285. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  286. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  287. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  288. // print_r(current($invoiceManageDetail ['staffList']));
  289. // die;
  290. $moldManage = array ();
  291. foreach ( $invoiceManageList as $key => $value ) {
  292. if ($value ['mold'] == '发票打印')
  293. $moldManage [$value ['mold']] = $value ['staffList'];
  294. elseif ($value ['mold'] == '发票邮寄')
  295. $moldManage [$value ['mold']] = $value ['staffList'];
  296. elseif ($value ['mold'] == '发票退票')
  297. $moldManage [$value ['mold']] = $value ['staffList'];
  298. }
  299. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  300. $item = array (
  301. 'cid' => $cid,
  302. 'categoryName' => $categoryDetil ['title'],
  303. 'invoiceElement' => $invoiceElement,
  304. 'invoiceQuantity' => $invoiceQuantity,
  305. 'invoiceUnitPrice' => $invoiceUnitPrice,
  306. 'invoicePrice' => $invoicePrice,
  307. 'invoiceType' => $invoiceType,
  308. 'doPost' => $doPost,
  309. 'status' => 1,
  310. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  311. 'date' => date ( "Y-m-d H:i:s" ),
  312. 'updateTime' => date ( "Y-m-d H:i:s" ),
  313. 'sid' => $this->staff [0] ['sid'],
  314. 'userName' => $this->staff [0] ['username'],
  315. 'invoiceManage' => $invoiceManageDetail ['staff'],
  316. 'pendingApprovals' => $pendingApprovalsSid,
  317. 'moldManage' => json_encode ( $moldManage ),
  318. 'remark' => $remark
  319. );
  320. if ($invoiceType == 0)
  321. $item += array (
  322. 'invoiceTitle' => $invoiceTitle,
  323. 'TIN' => $TINT,
  324. 'address' => $addressT,
  325. 'phone' => $phoneT,
  326. 'bank' => $bankT,
  327. 'bankAccount' => $bankAccountT
  328. );
  329. else {
  330. $item += array (
  331. 'invoiceCompany' => $invoiceCompany,
  332. 'TIN' => $TIN,
  333. 'address' => $address,
  334. 'phone' => $phone,
  335. 'bank' => $bank,
  336. 'bankAccount' => $bankAccount
  337. );
  338. }
  339. if ($doPost == 1) {
  340. $mailList = array (
  341. 'invoice' => 1,
  342. 'mailItems' => $mailItems
  343. );
  344. if (! empty ( $softLock ))
  345. $mailList += array (
  346. 'softLock' => $softLockNum
  347. );
  348. else
  349. $mailList += array (
  350. 'softLock' => 0
  351. );
  352. if (! empty ( $contract ))
  353. $mailList += array (
  354. 'contract' => $contractNum
  355. );
  356. else
  357. $mailList += array (
  358. 'contract' => 0
  359. );
  360. if (! empty ( $instructions ))
  361. $mailList += array (
  362. 'instructions' => $instructionsNum
  363. );
  364. else
  365. $mailList += array (
  366. 'instructions' => 0
  367. );
  368. if (! empty ( $remittance ))
  369. $mailList += array (
  370. 'remittance' => $remittance
  371. );
  372. else
  373. $mailList += array (
  374. 'remittance' => ''
  375. );
  376. $mailString = '发票x1,备注:' . $mailItems;
  377. if (! empty ( $softLock ))
  378. $mailString .= ',软件锁x' . $softLockNum;
  379. if (! empty ( $contract ))
  380. $mailString .= ',合同x' . $contractNum;
  381. if (! empty ( $instructions ))
  382. $mailString .= ',说明书x' . $instructionsNum;
  383. if (! empty ( $remittance ))
  384. $mailString .= ',汇款账号单';
  385. $item += array (
  386. 'recipients' => $recipients,
  387. 'recipientsPhone' => $recipientsPhone,
  388. 'recipientsAddress' => $recipientsAddress,
  389. 'mailItems' => $mailString,
  390. 'mailItemsJson' => json_encode ( $mailList )
  391. );
  392. }
  393. $iid = $invoice->addInvoice ( $item );
  394. $item = array (
  395. 'date' => date ( "Y-m-d H:i:s" ),
  396. 'operation' => "创建",
  397. 'status' => 1,
  398. 'img' => $this->staff [0] ['avatar'],
  399. 'username' => $this->staff [0] ['username'],
  400. 'uid' => $this->staff [0] ['sid'],
  401. 'category' => $this->staff [0] ['category'],
  402. 'iid' => $iid
  403. );
  404. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  405. $item = array (
  406. 'date' => date ( "Y-m-d H:i:s" ),
  407. 'operation' => "提交审批",
  408. 'status' => 1,
  409. 'img' => $this->staff [0] ['avatar'],
  410. 'username' => $this->staff [0] ['username'],
  411. 'uid' => $this->staff [0] ['sid'],
  412. 'category' => $this->staff [0] ['category'],
  413. 'iid' => $iid
  414. );
  415. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  416. Doo::loadModel ( 'staff' );
  417. $staff = new staff ();
  418. $username2 = $staff->getOne ( array (
  419. 'select' => 'wxid',
  420. 'where' => 'sid=' . $pendingApprovalsSid,
  421. 'asArray' => TRUE
  422. ) );
  423. // 发送微信审批通知
  424. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  425. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  426. }
  427. return "/invoice";
  428. }
  429. function invoiceEdit() {
  430. Doo::loadClass ( 'XDeode' );
  431. $XDeode = new XDeode ( 5 );
  432. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  433. $iid = $XDeode->decode ( $iid );
  434. if (! is_numeric ( $iid ))
  435. die ( 'illegal request' );
  436. Doo::loadModel ( 'invoice' );
  437. $invoice = new invoice ();
  438. Doo::loadModel ( 'invoiceOperationLog' );
  439. $invoiceOperationLog = new invoiceOperationLog ();
  440. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  441. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  442. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  443. $this->data ['operation'] = $operation;
  444. $this->data ['invoiceDetail'] = $invoiceDetail;
  445. $this->data ['memu'] = "invoice";
  446. $this->data ['staff'] = $this->staff;
  447. $this->data ['receiptMemu'] = 'invoice';
  448. $this->render ( "/admin/invoiceEdit", $this->data );
  449. }
  450. /**
  451. * 重新编辑退回的发票
  452. * @return string
  453. */
  454. function invoiceEditDo() {
  455. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  456. Doo::loadModel ( 'invoice' );
  457. $invoice = new invoice ();
  458. $iid = $invoice->authcode ( $iidKey );
  459. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  460. die ( 'illegal request' );
  461. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  462. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  463. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  464. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  465. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  466. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  467. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  468. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  469. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  470. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  471. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  472. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  473. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  474. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  475. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  476. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  477. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  478. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  479. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  480. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  481. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  482. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  483. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  484. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  485. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  486. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  487. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  488. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  489. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  490. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  491. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  492. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  493. Doo::loadModel ( 'invoiceManage' );
  494. $invoiceManage = new invoiceManage ();
  495. Doo::loadModel ( 'invoiceOperationLog' );
  496. $invoiceOperationLog = new invoiceOperationLog ();
  497. $cid = explode ( ':', $cid );
  498. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  499. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  500. $moldManage = array ();
  501. foreach ( $invoiceManageList as $key => $value ) {
  502. if ($value ['mold'] == '发票打印')
  503. $moldManage [$value ['mold']] = $value ['staffList'];
  504. elseif ($value ['mold'] == '发票邮寄')
  505. $moldManage [$value ['mold']] = $value ['staffList'];
  506. elseif ($value ['mold'] == '发票打印')
  507. $moldManage [$value ['mold']] = $value ['staffList'];
  508. }
  509. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  510. $item = array (
  511. 'iid' => $iid,
  512. 'cid' => $cid [0],
  513. 'categoryName' => $cid [1],
  514. 'invoiceElement' => $invoiceElement,
  515. 'invoiceQuantity' => $invoiceQuantity,
  516. 'invoiceUnitPrice' => $invoiceUnitPrice,
  517. 'invoicePrice' => $invoicePrice,
  518. 'invoiceType' => $invoiceType,
  519. 'doPost' => $doPost,
  520. 'status' => 1,
  521. 'updateTime' => date ( "Y-m-d H:i:s" ),
  522. 'remark' => $remark
  523. );
  524. if ($invoiceType == 0)
  525. $item += array (
  526. 'invoiceTitle' => $invoiceTitle,
  527. 'TIN' => $TINT,
  528. 'address' => $addressT,
  529. 'phone' => $phoneT,
  530. 'bank' => $bankT,
  531. 'bankAccount' => $bankAccountT
  532. );
  533. else {
  534. $item += array (
  535. 'invoiceCompany' => $invoiceCompany,
  536. 'TIN' => $TIN,
  537. 'address' => $address,
  538. 'phone' => $phone,
  539. 'bank' => $bank,
  540. 'bankAccount' => $bankAccount
  541. );
  542. }
  543. if ($doPost == 1) {
  544. $mailList = array (
  545. 'invoice' => 1,
  546. 'mailItems' => $mailItems
  547. );
  548. if (! empty ( $softLock ))
  549. $mailList += array (
  550. 'softLock' => $softLockNum
  551. );
  552. else
  553. $mailList += array (
  554. 'softLock' => '0'
  555. );
  556. if (! empty ( $contract ))
  557. $mailList += array (
  558. 'contract' => $contractNum
  559. );
  560. else
  561. $mailList += array (
  562. 'contract' => '0'
  563. );
  564. if (! empty ( $instructions ))
  565. $mailList += array (
  566. 'instructions' => $instructionsNum
  567. );
  568. else
  569. $mailList += array (
  570. 'instructions' => '0'
  571. );
  572. if (! empty ( $remittance ))
  573. $mailList += array (
  574. 'remittance' => $remittance
  575. );
  576. else
  577. $mailList += array (
  578. 'remittance' => ''
  579. );
  580. $mailString = '发票x1,备注:' . $mailItems;
  581. if (! empty ( $softLock ))
  582. $mailString .= ',软件锁x' . $softLockNum;
  583. if (! empty ( $contract ))
  584. $mailString .= ',合同x' . $contractNum;
  585. if (! empty ( $instructions ))
  586. $mailString .= ',说明书x' . $instructionsNum;
  587. if (! empty ( $remittance ))
  588. $mailString .= ',汇款账号单';
  589. $item += array (
  590. 'recipients' => $recipients,
  591. 'recipientsPhone' => $recipientsPhone,
  592. 'recipientsAddress' => $recipientsAddress,
  593. 'mailItems' => $mailString,
  594. 'mailItemsJson' => json_encode ( $mailList )
  595. );
  596. }
  597. $invoice->setInvoiceByCondition ( $item );
  598. $item = array (
  599. 'date' => date ( "Y-m-d H:i:s" ),
  600. 'operation' => "重新提交审批",
  601. 'status' => 1,
  602. 'img' => $this->staff [0] ['avatar'],
  603. 'username' => $this->staff [0] ['username'],
  604. 'uid' => $this->staff [0] ['sid'],
  605. 'category' => $this->staff [0] ['category'],
  606. 'iid' => $iid
  607. );
  608. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  609. }
  610. return "/invoice";
  611. }
  612. /**
  613. * 培训班
  614. */
  615. function invoiceTraining() {
  616. Doo::loadModel ( 'L_category' );
  617. $lCategory = new L_category ();
  618. Doo::loadModel ( 'invoiceTraining' );
  619. $invoiceTraining = new invoiceTraining ();
  620. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  621. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  622. $category = $lCategory->getCategory ();
  623. $itid = array ();
  624. foreach ( $itTodoList as $value ) {
  625. array_push ( $itid, $value ['itid'] );
  626. }
  627. foreach ( $itedList as $value ) {
  628. array_push ( $itid, $value ['itid'] );
  629. }
  630. $itid = implode ( ',', $itid );
  631. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  632. // print_r($itTodoList);
  633. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  634. $this->data ['itTodoList'] = $itTodoList;
  635. $this->data ['itedList'] = $itedList;
  636. $this->data ['category'] = $category;
  637. $this->data ['memu'] = "invoice";
  638. $this->data ['staff'] = $this->staff;
  639. $this->data ['receiptMemu'] = 'invoiceTraining';
  640. $this->render ( "/admin/invoiceTraining", $this->data );
  641. }
  642. /**
  643. * 创建培训班
  644. */
  645. function invoiceTrainingAdd() {
  646. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  647. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  648. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  649. if (empty ( $this->staff [0] ))
  650. die ( 'illegal request' );
  651. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  652. Doo::loadModel ( 'invoiceTraining' );
  653. $invoiceTraining = new invoiceTraining ();
  654. Doo::loadModel ( 'invoice' );
  655. $invoice = new invoice ();
  656. Doo::loadModel ( 'L_category' );
  657. $lCategory = new L_category ();
  658. Doo::loadModel ( 'invoiceManage' );
  659. $invoiceManage = new invoiceManage ();
  660. Doo::loadModel ( 'invoiceOperationLog' );
  661. $invoiceOperationLog = new invoiceOperationLog ();
  662. $item = array (
  663. 'cid' => $cid,
  664. 'trainName' => $trainName,
  665. 'trainDate' => $trainDate,
  666. 'creator' => $this->staff [0] ['sid'],
  667. 'creatorDate' => date ( "Y-m-d H:i:s" )
  668. );
  669. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  670. }
  671. return "/invoiceTraining";
  672. }
  673. /**
  674. * 删除培训班
  675. */
  676. function invoiceTrainingDelDo() {
  677. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  678. if (! empty ( $itid )) {
  679. Doo::loadModel ( 'invoiceTraining' );
  680. $invoiceTraining = new invoiceTraining ();
  681. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  682. }
  683. return "/invoiceTraining";
  684. }
  685. /**
  686. * 培训班详情
  687. */
  688. function invoiceTrainingDetail() {
  689. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  690. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  691. Doo::loadModel ( 'invoiceTraining' );
  692. $invoiceTraining = new invoiceTraining ();
  693. Doo::loadModel ( 'invoiceStore' );
  694. $invoiceStore = new invoiceStore ();
  695. if (empty ( $itid ))
  696. die ( 'illegal request' );
  697. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  698. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid );
  699. // print_r($isList);
  700. $trainlist = array ();
  701. foreach ( $isList as $key => $value ) {
  702. $irDetail = array ();
  703. if ($value ['apStatus'] == 1) {
  704. // array_push ( $irDetail, '' );
  705. array_push ( $irDetail, '<input class="hide" disabled type="checkbox" >' );
  706. } else {
  707. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  708. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  709. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  710. }
  711. array_push ( $irDetail, $value ['invoiceSerial'] );
  712. if ($value ['invoiceType'] == 1)
  713. array_push ( $irDetail, $value ['invoiceCompany'] );
  714. else
  715. array_push ( $irDetail, $value ['invoiceTitle'] );
  716. array_push ( $irDetail, $value ['TIN'] );
  717. array_push ( $irDetail, $value ['userName'] );
  718. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  719. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  720. } else
  721. array_push ( $irDetail, $value ['mailItems'] );
  722. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  723. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  724. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  725. array_push ( $irDetail, $value ['invoiceElement'] );
  726. array_push ( $irDetail, $value ['invoiceQuantity'] );
  727. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  728. if ($value ['invoiceType'] == 1)
  729. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  730. else
  731. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  732. array_push ( $irDetail, $value ['remark'] );
  733. if ($value ['status'] == 1)
  734. array_push ( $irDetail, '审批中' );
  735. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  736. array_push ( $irDetail, '已出票' );
  737. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  738. array_push ( $irDetail, '已入账' );
  739. else
  740. array_push ( $irDetail, '' );
  741. array_push ( $irDetail, $value ['invoiceNo'] );
  742. array_push ( $irDetail, $value ['printTime'] );
  743. $html = '';
  744. foreach ( $value ['invoiceReceivables'] as $value ) {
  745. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  746. }
  747. array_push ( $irDetail, $html );
  748. array_push ( $trainlist, $irDetail );
  749. }
  750. $trainlistJson = json_encode ( $trainlist );
  751. if (empty ( $detail ))
  752. die ( 'illegal request' );
  753. $this->data ['trainStatus'] = $trainStatus;
  754. $this->data ['itid'] = $itid;
  755. $this->data ['trainlistJson'] = $trainlistJson;
  756. $this->data ['iTrainDetail'] = $detail;
  757. $this->data ['memu'] = "invoice";
  758. $this->data ['staff'] = $this->staff;
  759. $this->data ['receiptMemu'] = 'invoiceTraining';
  760. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  761. }
  762. /**
  763. * 上传培训班发票
  764. * @return string
  765. */
  766. function invoiceTrainingUpload() {
  767. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  768. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  769. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  770. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  771. header ( "HTTP/1.1 500 Internal Server Error" );
  772. echo "POST exceeded maximum allowed size.";
  773. exit ( 0 );
  774. }
  775. // Settings
  776. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceTraining/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  777. $upload_name = "Filedata";
  778. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  779. $extension_whitelist = array (
  780. "doc",
  781. "txt",
  782. "jpg",
  783. "gif",
  784. "png"
  785. ); // Allowed file extensions
  786. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  787. // Other variables
  788. $MAX_FILENAME_LENGTH = 260;
  789. $file_name = "";
  790. $file_extension = "";
  791. $uploadErrors = array (
  792. 0 => "文件上传成功",
  793. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  794. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  795. 3 => "上传的文件仅为部分文件",
  796. 4 => "没有文件上传",
  797. 6 => "缺少临时文件夹"
  798. );
  799. $nk = time ();
  800. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  801. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  802. echo "文件无法保存.";
  803. exit ( 0 );
  804. }
  805. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  806. echo json_encode ( array (
  807. 'filename' => $file_name,
  808. 'id' => $nk
  809. ) );
  810. exit ( 0 );
  811. }
  812. /**
  813. * 导入发票临时仓库
  814. */
  815. function invoiceStoreImport() {
  816. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  817. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  818. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  819. if ($path != "" && ! empty ( $trainingKey )) {
  820. Doo::loadModel ( 'invoiceStore' );
  821. Doo::loadModel ( 'staff' );
  822. $staff = new staff ();
  823. Doo::loadModel ( 'invoiceTraining' );
  824. $invoiceTraining = new invoiceTraining ();
  825. Doo::loadClass ( 'XDeode' );
  826. $XDeode = new XDeode ( 5 );
  827. $itid = $XDeode->decode ( $trainingKey );
  828. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  829. $userName = $this->staff [0] ['username'];
  830. $sDetail = $staff->getStaffByName ( $userName );
  831. // die('sdd');
  832. // 可以优化
  833. foreach ( $exlArray as $key => $value ) {
  834. // 开票
  835. $invoice = new invoiceStore ();
  836. $invoice->trainId = $itid;
  837. $invoice->invoiceType = 0;
  838. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  839. $invoice->invoiceType = 1;
  840. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  841. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  842. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  843. $invoice->invoiceTitle = $value ['invoiceTitle'];
  844. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  845. $invoice->invoiceCompany = $value ['invoiceTitle'];
  846. $invoice->userName = $userName;
  847. $invoice->sid = $sDetail ['sid'];
  848. $invoice->cid = $sDetail ['cid'];
  849. $invoice->categoryName = $sDetail ['category'];
  850. $invoice->invoiceElement = $value ['invoiceElement'];
  851. $invoice->remark = $value ['remark'];
  852. // $invoice->date = $value ['date'];
  853. // $invoice->printTime = $value ['date'];
  854. $invoice->ipSource = 1;
  855. $invoice->printStatus = 1;
  856. $invoice->status = 2;
  857. $invoice->postStatus = 1;
  858. $invoice->untreadStatus = 0;
  859. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  860. $invoice->TIN = $value ['TIN'];
  861. $invoice->address = $value ['address'];
  862. $invoice->phone = $value ['phone'];
  863. $invoice->bank = $value ['bank'];
  864. $invoice->bankAccount = $value ['bankAccount'];
  865. $invoice->recipientsAddress = $value ['recipientsAddress'];
  866. $invoice->recipients = $value ['recipients'];
  867. $invoice->recipientsPhone = $value ['recipientsPhone'];
  868. $iid = $invoice->insert ();
  869. }
  870. // 加入发票总数量
  871. $item = array (
  872. 'itid' => $itid,
  873. 'invoiceTotal' => count ( $exlArray )
  874. );
  875. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  876. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  877. }
  878. echo 'no file';
  879. }
  880. /**
  881. * 编辑仓库里的发票
  882. */
  883. function invoiceStoreEdit() {
  884. Doo::loadClass ( 'XDeode' );
  885. $XDeode = new XDeode ( 5 );
  886. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  887. $iid = $XDeode->decode ( $iid );
  888. if (! is_numeric ( $iid ))
  889. die ( 'illegal request' );
  890. Doo::loadModel ( 'invoiceStore' );
  891. $invoiceStore = new invoiceStore ();
  892. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  893. // print_r($invoiceDetail);
  894. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  895. $this->data ['invoiceDetail'] = $invoiceDetail;
  896. $this->data ['memu'] = "invoice";
  897. $this->data ['staff'] = $this->staff;
  898. $this->data ['receiptMemu'] = 'invoiceTraining';
  899. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  900. }
  901. function invoiceStoreEditDo() {
  902. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  903. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  904. Doo::loadModel ( 'invoiceStore' );
  905. $invoice = new invoiceStore ();
  906. Doo::loadClass ( 'XDeode' );
  907. $XDeode = new XDeode ( 5 );
  908. $iid = $XDeode->decode ( $storeKey );
  909. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  910. die ( 'illegal request' );
  911. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  912. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  913. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  914. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  915. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  916. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  917. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  918. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  919. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  920. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  921. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  922. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  923. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  924. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  925. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  926. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  927. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  928. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  929. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  930. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  931. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  932. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  933. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  934. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  935. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  936. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  937. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  938. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  939. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  940. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  941. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  942. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  943. $cid = explode ( ':', $cid );
  944. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  945. $item = array (
  946. 'isid' => $iid,
  947. 'cid' => $cid [0],
  948. 'categoryName' => $cid [1],
  949. 'invoiceElement' => $invoiceElement,
  950. 'invoiceQuantity' => $invoiceQuantity,
  951. 'invoiceUnitPrice' => $invoiceUnitPrice,
  952. 'invoicePrice' => $invoicePrice,
  953. 'invoiceType' => $invoiceType,
  954. 'doPost' => $doPost,
  955. 'status' => 1,
  956. 'updateTime' => date ( "Y-m-d H:i:s" ),
  957. 'remark' => $remark
  958. );
  959. if ($invoiceType == 0)
  960. $item += array (
  961. 'invoiceTitle' => $invoiceTitle,
  962. 'TIN' => $TINT,
  963. 'address' => $addressT,
  964. 'phone' => $phoneT,
  965. 'bank' => $bankT,
  966. 'bankAccount' => $bankAccountT
  967. );
  968. else {
  969. $item += array (
  970. 'invoiceCompany' => $invoiceCompany,
  971. 'TIN' => $TIN,
  972. 'address' => $address,
  973. 'phone' => $phone,
  974. 'bank' => $bank,
  975. 'bankAccount' => $bankAccount
  976. );
  977. }
  978. if ($doPost == 1) {
  979. $mailList = array (
  980. 'invoice' => 1,
  981. 'mailItems' => $mailItems
  982. );
  983. if (! empty ( $softLock ))
  984. $mailList += array (
  985. 'softLock' => $softLockNum
  986. );
  987. else
  988. $mailList += array (
  989. 'softLock' => '0'
  990. );
  991. if (! empty ( $contract ))
  992. $mailList += array (
  993. 'contract' => $contractNum
  994. );
  995. else
  996. $mailList += array (
  997. 'contract' => '0'
  998. );
  999. if (! empty ( $instructions ))
  1000. $mailList += array (
  1001. 'instructions' => $instructionsNum
  1002. );
  1003. else
  1004. $mailList += array (
  1005. 'instructions' => '0'
  1006. );
  1007. if (! empty ( $remittance ))
  1008. $mailList += array (
  1009. 'remittance' => $remittance
  1010. );
  1011. else
  1012. $mailList += array (
  1013. 'remittance' => ''
  1014. );
  1015. $mailString = '发票x1,备注:' . $mailItems;
  1016. if (! empty ( $softLock ))
  1017. $mailString .= ',软件锁x' . $softLockNum;
  1018. if (! empty ( $contract ))
  1019. $mailString .= ',合同x' . $contractNum;
  1020. if (! empty ( $instructions ))
  1021. $mailString .= ',说明书x' . $instructionsNum;
  1022. if (! empty ( $remittance ))
  1023. $mailString .= ',汇款账号单';
  1024. $item += array (
  1025. 'recipients' => $recipients,
  1026. 'recipientsPhone' => $recipientsPhone,
  1027. 'recipientsAddress' => $recipientsAddress,
  1028. 'mailItems' => $mailString,
  1029. 'mailItemsJson' => json_encode ( $mailList )
  1030. );
  1031. }
  1032. $invoice->setInvoiceStoreByCondition ( $item );
  1033. }
  1034. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1035. }
  1036. /**
  1037. *
  1038. * @return string
  1039. */
  1040. function invoiceStoreDelete() {
  1041. Doo::loadClass ( 'XDeode' );
  1042. $XDeode = new XDeode ( 5 );
  1043. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1044. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1045. $isid = $XDeode->decode ( $iStoreKey );
  1046. $itid = $XDeode->decode ( $trainKey );
  1047. if (! is_numeric ( $isid ))
  1048. die ( 'illegal request' );
  1049. Doo::loadModel ( 'invoiceStore' );
  1050. $invoiceStore = new invoiceStore ();
  1051. $invoiceStore->delete ( array (
  1052. 'where' => 'isid=' . $isid,
  1053. 'limit' => 1
  1054. ) );
  1055. Doo::loadModel ( 'invoiceTraining' );
  1056. $invoiceTraining = new invoiceTraining ();
  1057. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1058. $item = array (
  1059. 'itid' => $itid,
  1060. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1061. );
  1062. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1063. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1064. }
  1065. /**
  1066. * 批量删除库里发票
  1067. */
  1068. function invoiceStoreBatchDelete() {
  1069. Doo::loadClass ( 'XDeode' );
  1070. $XDeode = new XDeode ( 5 );
  1071. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1072. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1073. $tid = $XDeode->decode ( $trainKey );
  1074. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1075. die ( 'illegal request' );
  1076. Doo::loadModel ( 'invoiceStore' );
  1077. $isidKeyList = explode ( ',', $storeKey );
  1078. $isidList = array ();
  1079. foreach ( $isidKeyList as $value ) {
  1080. $isid = $XDeode->decode ( $value );
  1081. if (! empty ( $isid ) && is_numeric ( $isid ))
  1082. array_push ( $isidList, $isid );
  1083. }
  1084. $isidString = implode ( ',', $isidList );
  1085. $invoiceStore = new invoiceStore ();
  1086. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1087. $isidList = array ();
  1088. foreach ( $isList as $key => $value ) {
  1089. if ($value ['apStatus'] == 0)
  1090. array_push ( $isidList, $value ['isid'] );
  1091. }
  1092. $isidString = implode ( ',', $isidList );
  1093. // print_r($isList);
  1094. // echo $isidString;
  1095. $invoiceStore = new invoiceStore ();
  1096. $invoiceStore->delete ( array (
  1097. 'where' => "isid in ( " . $isidString . ")",
  1098. 'asArray' => TRUE
  1099. ) );
  1100. Doo::loadModel ( 'invoiceTraining' );
  1101. $invoiceTraining = new invoiceTraining ();
  1102. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1103. $item = array (
  1104. 'itid' => $tid,
  1105. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1106. );
  1107. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1108. // echo $tid;
  1109. // echo $storeKey;
  1110. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1111. }
  1112. /**
  1113. * 仓库发票提交审批
  1114. * @return string
  1115. */
  1116. function invoiceStoreApproval() {
  1117. Doo::loadClass ( 'XDeode' );
  1118. $XDeode = new XDeode ( 5 );
  1119. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1120. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1121. $isid = $XDeode->decode ( $iStoreKey );
  1122. $trainId = $XDeode->decode ( $trainKey );
  1123. if (! is_numeric ( $isid ))
  1124. die ( 'illegal request' );
  1125. Doo::loadModel ( 'invoiceStore' );
  1126. Doo::loadModel ( 'invoice' );
  1127. $invoice = new invoice ();
  1128. // 加入限制必须填写入开票内容和邮寄物品
  1129. $invoiceStore = new invoiceStore ();
  1130. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1131. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1132. header ( 'Content-Type:text/html;charset=utf-8' );
  1133. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1134. }
  1135. // 拷贝插入一条发票数据
  1136. $invoiceStore = new invoiceStore ();
  1137. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1138. $invoiceStore = new invoiceStore ();
  1139. $item = array (
  1140. 'isid' => $isid,
  1141. 'iid' => $iid,
  1142. 'apStatus' => 1
  1143. );
  1144. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1145. Doo::loadModel ( 'invoiceManage' );
  1146. $invoiceManage = new invoiceManage ();
  1147. Doo::loadModel ( 'invoiceOperationLog' );
  1148. $invoiceOperationLog = new invoiceOperationLog ();
  1149. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1150. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1151. $moldManage = array ();
  1152. foreach ( $invoiceManageList as $key => $value ) {
  1153. if ($value ['mold'] == '发票打印')
  1154. $moldManage [$value ['mold']] = $value ['staffList'];
  1155. elseif ($value ['mold'] == '发票邮寄')
  1156. $moldManage [$value ['mold']] = $value ['staffList'];
  1157. elseif ($value ['mold'] == '发票退票')
  1158. $moldManage [$value ['mold']] = $value ['staffList'];
  1159. }
  1160. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1161. $item = array (
  1162. 'iid' => $iid,
  1163. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1164. 'date' => date ( "Y-m-d H:i:s" ),
  1165. 'status' => 1,
  1166. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1167. 'trainId' => $trainId,
  1168. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1169. 'moldManage' => json_encode ( $moldManage ),
  1170. 'pendingApprovals' => $pendingApprovalsSid
  1171. );
  1172. $invoice->setInvoiceByCondition ( $item );
  1173. Doo::loadModel ( 'invoiceTraining' );
  1174. $invoiceTraining = new invoiceTraining ();
  1175. $item = array (
  1176. 'itid' => $trainId,
  1177. 'submitStatus' => 1
  1178. );
  1179. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1180. $item = array (
  1181. 'date' => date ( "Y-m-d H:i:s" ),
  1182. 'operation' => "创建",
  1183. 'status' => 1,
  1184. 'img' => $this->staff [0] ['avatar'],
  1185. 'username' => $this->staff [0] ['username'],
  1186. 'uid' => $this->staff [0] ['sid'],
  1187. 'category' => $this->staff [0] ['category'],
  1188. 'iid' => $iid
  1189. );
  1190. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1191. $item = array (
  1192. 'date' => date ( "Y-m-d H:i:s" ),
  1193. 'operation' => "提交审批",
  1194. 'status' => 1,
  1195. 'img' => $this->staff [0] ['avatar'],
  1196. 'username' => $this->staff [0] ['username'],
  1197. 'uid' => $this->staff [0] ['sid'],
  1198. 'category' => $this->staff [0] ['category'],
  1199. 'iid' => $iid
  1200. );
  1201. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1202. Doo::loadModel ( 'staff' );
  1203. $staff = new staff ();
  1204. $username2 = $staff->getOne ( array (
  1205. 'select' => 'wxid',
  1206. 'where' => 'sid=' . $pendingApprovalsSid,
  1207. 'asArray' => TRUE
  1208. ) );
  1209. // 发送微信审批通知
  1210. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1211. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1212. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1213. }
  1214. /**
  1215. * 批量提交发票
  1216. * @return string
  1217. */
  1218. function invoiceStoreBatchApproval() {
  1219. Doo::loadClass ( 'XDeode' );
  1220. $XDeode = new XDeode ( 5 );
  1221. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1222. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1223. $trainId = $XDeode->decode ( $trainKey );
  1224. $isidKeyList = explode ( ',', $storeKey );
  1225. $isidList = array ();
  1226. foreach ( $isidKeyList as $value ) {
  1227. $isid = $XDeode->decode ( $value );
  1228. if (! empty ( $isid ) && is_numeric ( $isid ))
  1229. array_push ( $isidList, $isid );
  1230. }
  1231. $isidString = implode ( ',', $isidList );
  1232. if (! is_numeric ( $trainId ))
  1233. die ( 'illegal request' );
  1234. Doo::loadModel ( 'invoiceStore' );
  1235. Doo::loadModel ( 'invoice' );
  1236. // 判断哪些已经加入审批过
  1237. // 加入限制必须填写入开票内容和邮寄物品
  1238. $invoiceStore = new invoiceStore ();
  1239. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1240. foreach ( $isList as $key => $value ) {
  1241. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1242. header ( 'Content-Type:text/html;charset=utf-8' );
  1243. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1244. }
  1245. }
  1246. // 拷贝插入一条发票数据
  1247. $invoiceStore = new invoiceStore ();
  1248. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1249. $invoiceStore = new invoiceStore ();
  1250. $item = array (
  1251. 'apStatus' => 1
  1252. );
  1253. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1254. // 获得正式发票ID
  1255. $invoice = new invoice ();
  1256. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1257. $sqlList = array ();
  1258. $iidString = '';
  1259. $iida = array ();
  1260. foreach ( $iidList as $key => $value ) {
  1261. $sqlList [$value ['isid']] = $value ['iid'];
  1262. array_push ( $iida, $value ['iid'] );
  1263. }
  1264. $iidString = implode ( ',', $iida );
  1265. $ids = implode ( ',', array_keys ( $sqlList ) );
  1266. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1267. foreach ( $sqlList as $id => $ordinal ) {
  1268. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1269. }
  1270. $sql .= "END WHERE isid IN ($ids)";
  1271. $invoiceStore = new invoiceStore ();
  1272. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1273. Doo::loadModel ( 'invoiceManage' );
  1274. $invoiceManage = new invoiceManage ();
  1275. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1276. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1277. $moldManage = array ();
  1278. foreach ( $invoiceManageList as $key => $value ) {
  1279. if ($value ['mold'] == '发票打印')
  1280. $moldManage [$value ['mold']] = $value ['staffList'];
  1281. elseif ($value ['mold'] == '发票邮寄')
  1282. $moldManage [$value ['mold']] = $value ['staffList'];
  1283. elseif ($value ['mold'] == '发票退票')
  1284. $moldManage [$value ['mold']] = $value ['staffList'];
  1285. }
  1286. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1287. // 批量更新发票信息
  1288. $item = array (
  1289. 'date' => date ( "Y-m-d H:i:s" ),
  1290. 'status' => 1,
  1291. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1292. 'trainId' => $trainId,
  1293. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1294. 'moldManage' => json_encode ( $moldManage ),
  1295. 'pendingApprovals' => $pendingApprovalsSid
  1296. );
  1297. $invoice = new invoice ();
  1298. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1299. // 批量更新发票序列号
  1300. $sqlList = array ();
  1301. foreach ( $iida as $value ) {
  1302. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1303. }
  1304. $ids = implode ( ',', array_keys ( $sqlList ) );
  1305. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1306. foreach ( $sqlList as $id => $ordinal ) {
  1307. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1308. }
  1309. $sql .= "END WHERE iid IN ($ids)";
  1310. $invoiceStore = new invoiceStore ();
  1311. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1312. // 批量生产操作日志
  1313. Doo::loadModel ( 'invoiceOperationLog' );
  1314. $sqlList = array ();
  1315. foreach ( $iida as $key => $value ) {
  1316. $sql = '("' . date ( "Y-m-d H:i:s" ) . '","创建","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '"),
  1317. ("' . date ( "Y-m-d H:i:s" ) . '","提交审批","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '") ';
  1318. array_push ( $sqlList, $sql );
  1319. }
  1320. $iolSql = implode ( ',', $sqlList );
  1321. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1322. $invoiceOperationLog = new invoiceOperationLog ();
  1323. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1324. Doo::loadModel ( 'invoiceTraining' );
  1325. $invoiceTraining = new invoiceTraining ();
  1326. $item = array (
  1327. 'itid' => $trainId,
  1328. 'submitStatus' => 1
  1329. );
  1330. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1331. Doo::loadModel ( 'staff' );
  1332. $staff = new staff ();
  1333. $username2 = $staff->getOne ( array (
  1334. 'select' => 'wxid',
  1335. 'where' => 'sid=' . $pendingApprovalsSid,
  1336. 'asArray' => TRUE
  1337. ) );
  1338. // 发送微信审批通知
  1339. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1340. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1341. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1342. }
  1343. /**
  1344. */
  1345. function invoiceStoreMailItemSet() {
  1346. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1347. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1348. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1349. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1350. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1351. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1352. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1353. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1354. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1355. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1356. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1357. Doo::loadClass ( 'XDeode' );
  1358. $XDeode = new XDeode ( 5 );
  1359. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1360. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1361. $isid = $XDeode->decode ( $storeKey );
  1362. $trainId = $XDeode->decode ( $trainKey );
  1363. if (! is_numeric ( $isid ))
  1364. die ( 'illegal request' );
  1365. Doo::loadModel ( 'invoiceStore' );
  1366. $invoiceStore = new invoiceStore ();
  1367. $mailList = array (
  1368. 'invoice' => 1,
  1369. 'mailItems' => $mailItems
  1370. );
  1371. if (! empty ( $softLock ))
  1372. $mailList += array (
  1373. 'softLock' => $softLockNum
  1374. );
  1375. else
  1376. $mailList += array (
  1377. 'softLock' => 0
  1378. );
  1379. if (! empty ( $contract ))
  1380. $mailList += array (
  1381. 'contract' => $contractNum
  1382. );
  1383. else
  1384. $mailList += array (
  1385. 'contract' => 0
  1386. );
  1387. if (! empty ( $instructions ))
  1388. $mailList += array (
  1389. 'instructions' => $instructionsNum
  1390. );
  1391. else
  1392. $mailList += array (
  1393. 'instructions' => 0
  1394. );
  1395. if (! empty ( $remittance ))
  1396. $mailList += array (
  1397. 'remittance' => $remittance
  1398. );
  1399. else
  1400. $mailList += array (
  1401. 'remittance' => ''
  1402. );
  1403. $mailString = '发票x1,备注:' . $mailItems;
  1404. if (! empty ( $softLock ))
  1405. $mailString .= ',软件锁x' . $softLockNum;
  1406. if (! empty ( $contract ))
  1407. $mailString .= ',合同x' . $contractNum;
  1408. if (! empty ( $instructions ))
  1409. $mailString .= ',说明书x' . $instructionsNum;
  1410. if (! empty ( $remittance ))
  1411. $mailString .= ',汇款账号单';
  1412. $item = array (
  1413. 'isid' => $isid,
  1414. 'doPost' => 1,
  1415. 'mailItems' => $mailString,
  1416. 'mailItemsJson' => json_encode ( $mailList )
  1417. );
  1418. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1419. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1420. }
  1421. /**
  1422. * 批量设置邮寄物品
  1423. */
  1424. function invoiceStoreBatchMailItemSet() {
  1425. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1426. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1427. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1428. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1429. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1430. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1431. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1432. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1433. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1434. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1435. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1436. Doo::loadClass ( 'XDeode' );
  1437. $XDeode = new XDeode ( 5 );
  1438. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1439. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1440. $isidKeyList = explode ( ',', $storeKey );
  1441. $isidList = array ();
  1442. foreach ( $isidKeyList as $value ) {
  1443. $isid = $XDeode->decode ( $value );
  1444. if (! empty ( $isid ) && is_numeric ( $isid ))
  1445. array_push ( $isidList, $isid );
  1446. }
  1447. $isidString = implode ( ',', $isidList );
  1448. $trainId = $XDeode->decode ( $trainKey );
  1449. if (! is_numeric ( $isid ))
  1450. die ( 'illegal request' );
  1451. Doo::loadModel ( 'invoiceStore' );
  1452. $invoiceStore = new invoiceStore ();
  1453. $mailList = array (
  1454. 'invoice' => 1,
  1455. 'mailItems' => $mailItems
  1456. );
  1457. if (! empty ( $softLock ))
  1458. $mailList += array (
  1459. 'softLock' => $softLockNum
  1460. );
  1461. else
  1462. $mailList += array (
  1463. 'softLock' => 0
  1464. );
  1465. if (! empty ( $contract ))
  1466. $mailList += array (
  1467. 'contract' => $contractNum
  1468. );
  1469. else
  1470. $mailList += array (
  1471. 'contract' => 0
  1472. );
  1473. if (! empty ( $instructions ))
  1474. $mailList += array (
  1475. 'instructions' => $instructionsNum
  1476. );
  1477. else
  1478. $mailList += array (
  1479. 'instructions' => 0
  1480. );
  1481. if (! empty ( $remittance ))
  1482. $mailList += array (
  1483. 'remittance' => $remittance
  1484. );
  1485. else
  1486. $mailList += array (
  1487. 'remittance' => ''
  1488. );
  1489. $mailString = '发票x1,备注:' . $mailItems;
  1490. if (! empty ( $softLock ))
  1491. $mailString .= ',软件锁x' . $softLockNum;
  1492. if (! empty ( $contract ))
  1493. $mailString .= ',合同x' . $contractNum;
  1494. if (! empty ( $instructions ))
  1495. $mailString .= ',说明书x' . $instructionsNum;
  1496. if (! empty ( $remittance ))
  1497. $mailString .= ',汇款账号单';
  1498. $item = array (
  1499. 'doPost' => 1,
  1500. 'mailItems' => $mailString,
  1501. 'mailItemsJson' => json_encode ( $mailList )
  1502. );
  1503. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1504. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1505. }
  1506. /**
  1507. * 废弃
  1508. */
  1509. function ajaxGetMailItemByIstore() {
  1510. Doo::loadClass ( 'XDeode' );
  1511. $XDeode = new XDeode ( 5 );
  1512. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1513. $isid = $XDeode->decode ( $storeKey );
  1514. if (! is_numeric ( $isid ))
  1515. die ( 'illegal request' );
  1516. Doo::loadModel ( 'invoiceStore' );
  1517. $invoiceStore = new invoiceStore ();
  1518. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1519. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1520. echo json_encode ( $isDetail ['mailItemsJson'] );
  1521. exit ();
  1522. }
  1523. /**
  1524. * 终止开票
  1525. */
  1526. function invoiceDroppedDo() {
  1527. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1528. Doo::loadModel ( 'invoice' );
  1529. $invoice = new invoice ();
  1530. Doo::loadModel ( 'invoiceOperationLog' );
  1531. $invoiceOperationLog = new invoiceOperationLog ();
  1532. $iid = $invoice->authcode ( $droppedIidKey );
  1533. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1534. die ( 'illegal request' );
  1535. $item = array (
  1536. 'iid' => $iid,
  1537. 'status' => 4,
  1538. 'updateTime' => date ( "Y-m-d H:i:s" )
  1539. );
  1540. $invoice->setInvoiceByCondition ( $item );
  1541. $item = array (
  1542. 'date' => date ( "Y-m-d H:i:s" ),
  1543. 'operation' => '终止了开票',
  1544. 'status' => 4,
  1545. 'img' => $this->staff [0] ['avatar'],
  1546. 'username' => $this->staff [0] ['username'],
  1547. 'uid' => $this->staff [0] ['sid'],
  1548. 'category' => $this->staff [0] ['category'],
  1549. 'iid' => $iid
  1550. );
  1551. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1552. return "/invoice";
  1553. }
  1554. /**
  1555. * 更新退票的邮寄信息
  1556. */
  1557. function invoiceUntreadMailDo() {
  1558. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1559. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1560. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1561. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1562. Doo::loadModel ( 'invoice' );
  1563. $invoice = new invoice ();
  1564. $iid = $invoice->authcode ( $untreadIidKey );
  1565. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1566. die ( 'illegal request' );
  1567. $item = array (
  1568. 'iid' => $iid,
  1569. 'untreadCompany' => $untreadCompany,
  1570. 'untreadNumber' => $untreadNumber,
  1571. 'untreadItems' => $untreadItems
  1572. );
  1573. $invoice->setInvoiceByCondition ( $item );
  1574. return "/invoice";
  1575. }
  1576. /**
  1577. * 申请退票 --
  1578. */
  1579. function invoiceUntreadDo() {
  1580. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1581. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1582. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1583. Doo::loadModel ( 'invoice' );
  1584. $invoice = new invoice ();
  1585. Doo::loadModel ( 'invoiceOperationLog' );
  1586. $invoiceOperationLog = new invoiceOperationLog ();
  1587. Doo::loadModel ( 'invoiceReceivables' );
  1588. $invoiceReceivables = new invoiceReceivables ();
  1589. $iid = $invoice->authcode ( $untreadIidKey );
  1590. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1591. die ( 'illegal request' );
  1592. /*
  1593. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1594. */
  1595. $item = array (
  1596. 'iid' => $iid,
  1597. 'untreadStatus' => 1,
  1598. 'untreadReason' => $untreadReason,
  1599. 'untreadPost' => $untreadPost,
  1600. 'updateTime' => date ( "Y-m-d H:i:s" )
  1601. );
  1602. $invoice->setInvoiceByCondition ( $item );
  1603. $item = array (
  1604. 'date' => date ( "Y-m-d H:i:s" ),
  1605. 'operation' => '申请退票',
  1606. 'status' => 7,
  1607. 'img' => $this->staff [0] ['avatar'],
  1608. 'username' => $this->staff [0] ['username'],
  1609. 'uid' => $this->staff [0] ['sid'],
  1610. 'category' => $this->staff [0] ['category'],
  1611. 'iid' => $iid
  1612. );
  1613. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1614. return "/invoice";
  1615. }
  1616. /**
  1617. * 删除已终止的开票
  1618. */
  1619. function invoiceDelDo() {
  1620. Doo::loadModel ( 'invoice' );
  1621. $invoice = new invoice ();
  1622. Doo::loadModel ( 'invoiceOperationLog' );
  1623. $invoiceOperationLog = new invoiceOperationLog ();
  1624. Doo::loadClass ( 'XDeode' );
  1625. $XDeode = new XDeode ( 5 );
  1626. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1627. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1628. $iid = $XDeode->decode ( $iid );
  1629. Doo::loadModel ( 'invoiceStore' );
  1630. $invoiceStore = new invoiceStore ();
  1631. if (! is_numeric ( $iid ))
  1632. die ( 'illegal request' );
  1633. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1634. if (empty ( $invoiceDetail ))
  1635. die ( 'illegal request' );
  1636. $item = array (
  1637. 'iid' => $iid,
  1638. 'isDelete' => 1,
  1639. 'updateTime' => date ( "Y-m-d H:i:s" )
  1640. );
  1641. $invoice->setInvoiceByCondition ( $item );
  1642. $item = array (
  1643. 'date' => date ( "Y-m-d H:i:s" ),
  1644. 'operation' => '删除了已终止的发票',
  1645. 'status' => 4,
  1646. 'img' => $this->staff [0] ['avatar'],
  1647. 'username' => $this->staff [0] ['username'],
  1648. 'uid' => $this->staff [0] ['sid'],
  1649. 'category' => $this->staff [0] ['category'],
  1650. 'iid' => $iid
  1651. );
  1652. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1653. // 删除培训班发票仓库里的发票
  1654. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1655. return "/invoice";
  1656. }
  1657. function invoiceApproval() {
  1658. Doo::loadModel ( 'invoice' );
  1659. $invoice = new invoice ();
  1660. Doo::loadClass ( 'XDeode' );
  1661. $XDeode = new XDeode ( 5 );
  1662. Doo::loadModel ( 'staff' );
  1663. $staff = new staff ();
  1664. $invoiceList = $invoice->find ( array (
  1665. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1666. 'desc' => 'iid',
  1667. 'limit' => 10,
  1668. 'asArray' => true
  1669. ) );
  1670. foreach ( $invoiceList as $key => $value ) {
  1671. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1672. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1673. if (! empty ( $lastApprover )) {
  1674. $lastApproverKey = array_keys ( $lastApprover );
  1675. $lastApprover = end ( $lastApprover );
  1676. $staffDetail = $staff->getOne ( array (
  1677. 'where' => 'sid=' . end ( $lastApproverKey ),
  1678. 'asArray' => true
  1679. ) );
  1680. $lastApprover ['username'] = $staffDetail ['username'];
  1681. }
  1682. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1683. }
  1684. $ilist = $invoice->getInvoiceByProcessStatus ();
  1685. foreach ( $ilist as $key => $value ) {
  1686. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1687. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1688. if (! empty ( $lastApprover )) {
  1689. $lastApproverKey = array_keys ( $lastApprover );
  1690. $lastApprover = end ( $lastApprover );
  1691. $staffDetail = $staff->getOne ( array (
  1692. 'where' => 'sid=' . end ( $lastApproverKey ),
  1693. 'asArray' => true
  1694. ) );
  1695. $lastApprover ['username'] = $staffDetail ['username'];
  1696. }
  1697. $ilist [$key] ['lastApprover'] = $lastApprover;
  1698. }
  1699. // print_r($ilist);
  1700. $this->data ['invoiceList'] = $invoiceList;
  1701. $this->data ['ilist'] = $ilist;
  1702. $this->data ['memu'] = "invoice";
  1703. $this->data ['staff'] = $this->staff;
  1704. $this->data ['receiptMemu'] = 'invoiceApproval';
  1705. $this->render ( "/admin/invoiceApproval", $this->data );
  1706. }
  1707. function invoiceDetail() {
  1708. Doo::loadClass ( 'XDeode' );
  1709. $XDeode = new XDeode ( 5 );
  1710. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1711. $iid = $XDeode->decode ( $iid );
  1712. if (! is_numeric ( $iid ))
  1713. die ( 'illegal request' );
  1714. Doo::loadModel ( 'invoice' );
  1715. $invoice = new invoice ();
  1716. Doo::loadModel ( 'invoiceOperationLog' );
  1717. $invoiceOperationLog = new invoiceOperationLog ();
  1718. $invoiceDetail = $invoice->getOne ( array (
  1719. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1720. 'asArray' => true
  1721. ) );
  1722. if (empty ( $invoiceDetail ))
  1723. die ( 'illegal request' );
  1724. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1725. $this->data ['invoiceDetail'] = $invoiceDetail;
  1726. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1727. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1728. $this->data ['memu'] = "invoice";
  1729. $this->data ['staff'] = $this->staff;
  1730. $this->data ['receiptMemu'] = 'invoiceApproval';
  1731. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1732. }
  1733. /**
  1734. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1735. *
  1736. * @since 1.0.0
  1737. * @var integer iid 开票ID 已加密
  1738. * @var integer status 发票审批状态
  1739. * @var integer opintion 审批发票的意见
  1740. * @return string 如操作成功返回审批首页
  1741. */
  1742. function invoiceApprovalDo() {
  1743. Doo::loadModel ( 'invoice' );
  1744. $invoice = new invoice ();
  1745. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1746. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1747. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1748. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  1749. $iid = $invoice->authcode ( $iid );
  1750. if (! is_numeric ( $iid ))
  1751. die ( 'illegal request' );
  1752. // && ! empty ( $opinion )
  1753. if (! empty ( $iid ) && ! empty ( $status )) {
  1754. if (! ($status == 2 || $status == 3 || $status == 4))
  1755. die ( 'illegal request' );
  1756. Doo::loadModel ( 'invoiceOperationLog' );
  1757. $invoiceOperationLog = new invoiceOperationLog ();
  1758. $invoiceDetail = $invoice->getOne ( array (
  1759. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1760. 'asArray' => true
  1761. ) );
  1762. if (empty ( $invoiceDetail ))
  1763. die ( 'illegal request' );
  1764. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1765. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1766. if ($status == 3) {
  1767. $invoice->status = $status;
  1768. $item = array (
  1769. 'operation' => $opinion
  1770. );
  1771. } else {
  1772. if (empty ( $processApprovals )) {
  1773. $processApprovals = array (
  1774. $this->staff [0] ['sid'] => array (
  1775. 'date' => date ( "Y-m-d H:i:s" ),
  1776. 'opinion' => $opinion,
  1777. 'status' => $status
  1778. )
  1779. );
  1780. // var_dump(next($invoiceManage));
  1781. $nextInvoiceManage = next ( $invoiceManage );
  1782. // print_r($nextInvoiceManage);
  1783. if ($status != 4 && $nextInvoiceManage !== false)
  1784. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1785. $invoice->processApprovals = json_encode ( $processApprovals );
  1786. // var_dump($invoice);
  1787. // print_r($invoiceManage);
  1788. } else {
  1789. $processApprovals [$this->staff [0] ['sid']] = array (
  1790. 'date' => date ( "Y-m-d H:i:s" ),
  1791. 'opinion' => $opinion,
  1792. 'status' => $status
  1793. );
  1794. $pendingApprovals = 0;
  1795. foreach ( $invoiceManage as $key => $value ) {
  1796. if ($value [0] == $this->staff [0] ['sid']) {
  1797. if (isset ( $invoiceManage [$key + 1] ))
  1798. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1799. break;
  1800. }
  1801. }
  1802. if ($status != 4 && ! empty ( $pendingApprovals ))
  1803. $invoice->pendingApprovals = $pendingApprovals;
  1804. $invoice->processApprovals = json_encode ( $processApprovals );
  1805. }
  1806. $item = array (
  1807. 'operation' => $opinion
  1808. );
  1809. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1810. $invoice->status = $status;
  1811. $invoice->pendingApprovals = 0;
  1812. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1813. } elseif ($status == 4) {
  1814. $invoice->status = $status;
  1815. $item = array (
  1816. 'operation' => $opinion
  1817. );
  1818. }
  1819. }
  1820. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  1821. $invoice->update ( array (
  1822. 'where' => 'iid=' . $iid
  1823. ) );
  1824. $item += array (
  1825. 'date' => date ( "Y-m-d H:i:s" ),
  1826. 'img' => $this->staff [0] ['avatar'],
  1827. 'username' => $this->staff [0] ['username'],
  1828. 'uid' => $this->staff [0] ['sid'],
  1829. 'category' => $this->staff [0] ['category'],
  1830. 'status' => $status,
  1831. 'iid' => $iid
  1832. );
  1833. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1834. if (empty ( $divApproval ))
  1835. return '/invoiceApproval';
  1836. else
  1837. return '/invoiceApprovalAchieve/PEND';
  1838. }
  1839. die ( 'illegal request' );
  1840. }
  1841. /**
  1842. * 展示需要打印的发票数据
  1843. *
  1844. * @since 1.0.0
  1845. */
  1846. function invoicePrint() {
  1847. Doo::loadModel ( 'invoice' );
  1848. $invoice = new invoice ();
  1849. Doo::loadClass ( 'XDeode' );
  1850. $XDeode = new XDeode ( 5 );
  1851. Doo::loadModel ( 'staff' );
  1852. $staff = new staff ();
  1853. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  1854. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  1855. foreach ( $toPrint as $key => $value ) {
  1856. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1857. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1858. if (! empty ( $lastApprover )) {
  1859. $lastApproverKey = array_keys ( $lastApprover );
  1860. $lastApprover = end ( $lastApprover );
  1861. $staffDetail = $staff->getOne ( array (
  1862. 'where' => 'sid=' . end ( $lastApproverKey ),
  1863. 'asArray' => true
  1864. ) );
  1865. $lastApprover ['username'] = $staffDetail ['username'];
  1866. }
  1867. $toPrint [$key] ['lastApprover'] = $lastApprover;
  1868. }
  1869. foreach ( $printed as $key => $value ) {
  1870. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1871. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1872. if (! empty ( $lastApprover )) {
  1873. $lastApproverKey = array_keys ( $lastApprover );
  1874. $lastApprover = end ( $lastApprover );
  1875. $staffDetail = $staff->getOne ( array (
  1876. 'where' => 'sid=' . end ( $lastApproverKey ),
  1877. 'asArray' => true
  1878. ) );
  1879. $lastApprover ['username'] = $staffDetail ['username'];
  1880. }
  1881. $printed [$key] ['lastApprover'] = $lastApprover;
  1882. }
  1883. $this->data ['printed'] = $printed;
  1884. $this->data ['toPrint'] = $toPrint;
  1885. $this->data ['memu'] = "invoice";
  1886. $this->data ['staff'] = $this->staff;
  1887. $this->data ['receiptMemu'] = 'invoicePrint';
  1888. $this->render ( "/admin/invoicePrint", $this->data );
  1889. }
  1890. /**
  1891. * 展示发票打印的详情页面
  1892. *
  1893. * @since 1.0.0
  1894. */
  1895. function invoicePrintDetail() {
  1896. Doo::loadClass ( 'XDeode' );
  1897. $XDeode = new XDeode ( 5 );
  1898. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1899. $iid = $XDeode->decode ( $iid );
  1900. if (! is_numeric ( $iid ))
  1901. die ( 'illegal request' );
  1902. Doo::loadModel ( 'invoice' );
  1903. $invoice = new invoice ();
  1904. Doo::loadModel ( 'invoiceOperationLog' );
  1905. $invoiceOperationLog = new invoiceOperationLog ();
  1906. Doo::loadModel ( 'invoicePaper' );
  1907. $invoicePaper = new invoicePaper ();
  1908. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  1909. if (empty ( $invoiceDetail ))
  1910. die ( 'illegal request' );
  1911. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  1912. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1913. $this->data ['invoicePaperList'] = $invoicePaperList;
  1914. $this->data ['invoiceDetail'] = $invoiceDetail;
  1915. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1916. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1917. $this->data ['memu'] = "invoice";
  1918. $this->data ['staff'] = $this->staff;
  1919. $this->data ['receiptMemu'] = 'invoicePrint';
  1920. $this->render ( "/admin/invoicePrintDetail", $this->data );
  1921. }
  1922. /**
  1923. * 所有待打印 发票
  1924. */
  1925. function invoicePrintStayAchieve() {
  1926. Doo::loadModel ( 'invoice' );
  1927. $invoice = new invoice ();
  1928. Doo::loadClass ( 'XDeode' );
  1929. $XDeode = new XDeode ( 5 );
  1930. Doo::loadModel ( 'staff' );
  1931. $staff = new staff ();
  1932. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  1933. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  1934. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  1935. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  1936. Doo::loadModel ( 'invoiceTraining' );
  1937. $invoiceTraining = new invoiceTraining ();
  1938. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  1939. $page_size = 12;
  1940. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1941. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  1942. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  1943. $get = "/" . $status;
  1944. $con = ' and status=2 ';
  1945. if ($status == 'TOPRINT')
  1946. $con = ' and status=2 and printStatus=0 ';
  1947. elseif ($status == 'PRINTED')
  1948. $con = ' and status=2 and printStatus=1';
  1949. if ($invoiceType == 'ORDINARY')
  1950. $con .= ' and invoiceType=0 ';
  1951. elseif ($invoiceType == 'SPECIAL')
  1952. $con .= ' and invoiceType=1 ';
  1953. if ($invoiceTrain == 'ORDINARY')
  1954. $con .= ' and trainId=0 ';
  1955. elseif ($invoiceTrain == 'TRAIN')
  1956. $con .= ' and trainId!=0 ';
  1957. if ($invoiceTrainName != 'ALL') {
  1958. $trainId = $XDeode->decode ( $invoiceTrainName );
  1959. if (is_numeric ( $trainId ))
  1960. $con .= ' and trainId =' . $trainId;
  1961. }
  1962. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1963. $dateArr = explode ( ':', $date );
  1964. $D1 = '';
  1965. $D2 = '';
  1966. if (! empty ( $date )) {
  1967. $D1 = $dateArr [0];
  1968. $D2 = $dateArr [1];
  1969. }
  1970. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  1971. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  1972. if (! empty ( $MebSea )) {
  1973. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  1974. }
  1975. $pageinfo ['page'] = array (
  1976. 'previous' => ''
  1977. );
  1978. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  1979. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  1980. $action = "invoicePrintStayAchieve";
  1981. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1982. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1983. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  1984. $this->data ['trainList'] = $trainList;
  1985. $this->data ['invoiceType'] = $invoiceType;
  1986. $this->data ['invoiceTrain'] = $invoiceTrain;
  1987. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  1988. $this->data ['MebSeaEn'] = $MebSea;
  1989. $this->data ['MebSea'] = urlencode ( $MebSea );
  1990. $this->data ['get'] = $get;
  1991. $this->data ['page'] = $pageinfo;
  1992. $this->data ['date'] = $date;
  1993. $this->data ['status'] = $status;
  1994. $this->data ['memu'] = "invoice";
  1995. $this->data ['staff'] = $this->staff;
  1996. foreach ( $list as $key => $value ) {
  1997. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1998. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1999. if (! empty ( $lastApprover )) {
  2000. $lastApproverKey = array_keys ( $lastApprover );
  2001. $lastApprover = end ( $lastApprover );
  2002. $staffDetail = $staff->getOne ( array (
  2003. 'where' => 'sid=' . end ( $lastApproverKey ),
  2004. 'asArray' => true
  2005. ) );
  2006. $lastApprover ['username'] = $staffDetail ['username'];
  2007. }
  2008. $list [$key] ['lastApprover'] = $lastApprover;
  2009. }
  2010. $this->data ['receiptMemu'] = 'invoicePrint';
  2011. $this->data ['list'] = $list;
  2012. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2013. }
  2014. /**
  2015. * 填写票号并完成打印
  2016. * @since 1.0.0
  2017. */
  2018. function invoicePrintDo() {
  2019. Doo::loadModel ( 'invoice' );
  2020. $invoice = new invoice ();
  2021. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2022. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2023. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2024. $iid = $invoice->authcode ( $iid );
  2025. if (! is_numeric ( $iid ))
  2026. die ( 'illegal request' );
  2027. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2028. Doo::loadModel ( 'invoiceOperationLog' );
  2029. $invoiceOperationLog = new invoiceOperationLog ();
  2030. Doo::loadModel ( 'invoiceStatistics' );
  2031. $invoiceStatistics = new invoiceStatistics ();
  2032. $XDeode = new XDeode ( 5 );
  2033. Doo::loadModel ( 'invoicePaper' );
  2034. $invoicePaper = new invoicePaper ();
  2035. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2036. if (empty ( $invoicePrintDetail ))
  2037. die ( 'illegal request' );
  2038. //
  2039. $ipid = $XDeode->decode ( $invoiceNo );
  2040. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2041. if (empty ( $paperDetail ))
  2042. die ( 'illegal request' );
  2043. $invoicePaper = new invoicePaper ();
  2044. $item = array (
  2045. 'iid' => $iid,
  2046. 'ipid' => $ipid
  2047. );
  2048. $invoicePaper->setInvoicePaperByCondition ( $item );
  2049. $item = array (
  2050. 'iid' => $iid,
  2051. 'printStatus' => 1,
  2052. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2053. 'printer' => $this->staff [0] ['username'],
  2054. 'printTime' => date ( "Y-m-d H:i:s" ),
  2055. 'invoiceNo' => $paperDetail ['invoiceNo']
  2056. );
  2057. $invoice->setInvoiceByCondition ( $item );
  2058. $item = array (
  2059. 'date' => date ( "Y-m-d H:i:s" ),
  2060. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2061. 'status' => 5,
  2062. 'img' => $this->staff [0] ['avatar'],
  2063. 'username' => $this->staff [0] ['username'],
  2064. 'uid' => $this->staff [0] ['sid'],
  2065. 'category' => $this->staff [0] ['category'],
  2066. 'iid' => $iid
  2067. );
  2068. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2069. // 去统计--负票不汇总
  2070. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2071. $item = array (
  2072. 'date' => date ( "Y-m-d H:i:s" ),
  2073. 'priceClass' => 1,
  2074. 'cid' => $invoicePrintDetail ['cid'],
  2075. 'staff' => $invoicePrintDetail ['sid'],
  2076. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2077. );
  2078. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2079. }
  2080. // 发送通知信息到微信-去除
  2081. // $this->setWXMsg($iid,'PRINT');
  2082. // 申请人获取微信通知
  2083. Doo::loadModel ( 'staff' );
  2084. $staff = new staff ();
  2085. Doo::loadClass ( 'XDeode' );
  2086. $XDeode = new XDeode ( 5 );
  2087. $username2 = $staff->getOne ( array (
  2088. 'select' => 'wxid',
  2089. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2090. 'asArray' => TRUE
  2091. ) );
  2092. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2093. $msg = '';
  2094. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2095. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2096. if (empty ( $invoicePrintType ))
  2097. return "/invoicePrint";
  2098. else
  2099. return "/invoicePrintStayAchieve";
  2100. }
  2101. }
  2102. /**
  2103. * 需要邮寄的发票
  2104. * @since 1.0.0
  2105. */
  2106. function invoicePost() {
  2107. Doo::loadModel ( 'invoice' );
  2108. $invoice = new invoice ();
  2109. Doo::loadModel ( 'express' );
  2110. $express = new express ();
  2111. $invoicePost = $invoice->getPostByInvoice ();
  2112. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2113. $expressList = $express->getExpressByAll ();
  2114. $invoicePostExpress = "";
  2115. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2116. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2117. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2118. $this->data ['expressList'] = $expressList;
  2119. $this->data ['invoicePost'] = $invoicePost;
  2120. $this->data ['invoicePosted'] = $invoicePosted;
  2121. $this->data ['memu'] = "invoice";
  2122. $this->data ['staff'] = $this->staff;
  2123. $this->data ['receiptMemu'] = 'invoicePost';
  2124. $this->render ( "/admin/invoicePost", $this->data );
  2125. }
  2126. /**
  2127. * 添加发票邮寄信息
  2128. */
  2129. function invoiceExpressAddDo() {
  2130. Doo::loadModel ( 'invoice' );
  2131. $invoice = new invoice ();
  2132. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2133. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2134. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2135. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2136. $iid = $iid = $invoice->authcode ( $iid );
  2137. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2138. die ( 'illegal request' );
  2139. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2140. setcookie ( 'invoicePostExpress', $expressNumber );
  2141. $item = array (
  2142. 'iid' => $iid,
  2143. 'postStatus' => 1,
  2144. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2145. 'postTime' => date ( "Y-m-d H:i:s" ),
  2146. 'expressCompany' => $expressCompany,
  2147. 'expressNumber' => $expressNumber,
  2148. 'actualItems' => $actualItems,
  2149. 'poster' => $this->staff [0] ['username']
  2150. );
  2151. $invoice->setInvoiceByCondition ( $item );
  2152. // 微信通知-去掉
  2153. // $this->setWXMsg ( $iid );
  2154. Doo::loadModel ( 'staff' );
  2155. $staff = new staff ();
  2156. Doo::loadClass ( 'XDeode' );
  2157. $XDeode = new XDeode ( 5 );
  2158. $username2 = $staff->getOne ( array (
  2159. 'select' => 'wxid',
  2160. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2161. 'asArray' => TRUE
  2162. ) );
  2163. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2164. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2165. if (empty ( $expCom ))
  2166. $expCom [0] = '';
  2167. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2168. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2169. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2170. return '/invoicePost';
  2171. }
  2172. function invoiceExpressUpdateDo() {
  2173. Doo::loadModel ( 'invoice' );
  2174. $invoice = new invoice ();
  2175. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2176. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2177. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2178. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2179. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2180. $iid = $invoice->authcode ( $iid );
  2181. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2182. die ( 'illegal request' );
  2183. $item = array (
  2184. 'iid' => $iid,
  2185. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2186. 'expressCompany' => $expressCompany,
  2187. 'expressNumber' => $expressNumber,
  2188. 'actualItems' => $actualItems,
  2189. 'poster' => $this->staff [0] ['username']
  2190. );
  2191. $invoice->setInvoiceByCondition ( $item );
  2192. return $action;
  2193. }
  2194. /**
  2195. * 可退票管理
  2196. */
  2197. function invoiceUntreadIsAchieve() {
  2198. Doo::loadModel ( 'invoice' );
  2199. $invoice = new invoice ();
  2200. Doo::loadClass ( 'XDeode' );
  2201. $XDeode = new XDeode ( 5 );
  2202. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2203. $page_size = 18;
  2204. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2205. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2206. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2207. $dateArr = explode ( ':', $date );
  2208. $D1 = '';
  2209. $D2 = '';
  2210. if (! empty ( $date )) {
  2211. $D1 = $dateArr [0];
  2212. $D2 = $dateArr [1];
  2213. }
  2214. $con = '';
  2215. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2216. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2217. // if ($date == 'MONTHO')
  2218. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2219. // elseif ($date == 'MONTHT')
  2220. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2221. // elseif ($date == 'MONTHY')
  2222. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2223. if (! empty ( $MebSea )) {
  2224. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2225. }
  2226. $pageinfo ['page'] = array (
  2227. 'previous' => ''
  2228. );
  2229. // printStatus=1 and
  2230. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2231. $action = "invoiceUntreadIsAchieve";
  2232. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2233. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2234. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2235. // print_r($list);
  2236. $this->data ['MebSeaEn'] = $MebSea;
  2237. // $this->data ['MebSea'] = urlencode ( $MebSea );
  2238. $this->data ['get'] = $get;
  2239. $this->data ['page'] = $pageinfo;
  2240. $this->data ['date'] = $date;
  2241. $this->data ['list'] = $list;
  2242. $this->data ['memu'] = "invoice";
  2243. $this->data ['staff'] = $this->staff;
  2244. $this->data ['receiptMemu'] = 'invoice';
  2245. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2246. }
  2247. /**
  2248. * 退票处理页面
  2249. */
  2250. function invoiceUntread() {
  2251. Doo::loadModel ( 'invoice' );
  2252. $invoice = new invoice ();
  2253. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  2254. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2255. foreach ( $establishedInvoice as $key => $value ) {
  2256. // months
  2257. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2258. $nowDate = strtotime ( 'now' );
  2259. $establishedInvoice [$key] ['lossShow'] = false;
  2260. if ($lossDate < $nowDate)
  2261. $establishedInvoice [$key] ['lossShow'] = true;
  2262. }
  2263. $this->data ['untreadInvoice'] = $untreadInvoice;
  2264. $this->data ['establishedInvoice'] = $establishedInvoice;
  2265. $this->data ['memu'] = "invoice";
  2266. $this->data ['staff'] = $this->staff;
  2267. $this->data ['receiptMemu'] = 'invoiceUntread';
  2268. $this->render ( "/admin/invoiceUntread", $this->data );
  2269. }
  2270. /**
  2271. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2272. */
  2273. function invoiceUntreadEstablishedDo() {
  2274. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2275. Doo::loadModel ( 'invoice' );
  2276. $invoice = new invoice ();
  2277. Doo::loadModel ( 'invoiceOperationLog' );
  2278. $invoiceOperationLog = new invoiceOperationLog ();
  2279. Doo::loadModel ( 'invoiceReceivables' );
  2280. Doo::loadModel ( 'invoiceStatistics' );
  2281. $iid = $invoice->authcode ( $untreadIidKey );
  2282. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2283. die ( 'illegal request' );
  2284. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2285. if ($invoiceDetails ['untreadStatus'] != 1)
  2286. die ( 'illegal request' );
  2287. $item = array (
  2288. 'iid' => $iid,
  2289. // 'irid'=>'',
  2290. 'untreadStatus' => 2,
  2291. 'updateTime' => date ( "Y-m-d H:i:s" )
  2292. );
  2293. $invoice->setInvoiceByCondition ( $item );
  2294. $item = array (
  2295. 'date' => date ( "Y-m-d H:i:s" ),
  2296. 'operation' => '已确认退票',
  2297. 'status' => 6,
  2298. 'img' => $this->staff [0] ['avatar'],
  2299. 'username' => $this->staff [0] ['username'],
  2300. 'uid' => $this->staff [0] ['sid'],
  2301. 'category' => $this->staff [0] ['category'],
  2302. 'iid' => $iid
  2303. );
  2304. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2305. // 收款解绑以及入账扣除 收款扣除
  2306. if (! empty ( $invoiceDetails ['irid'] )) {
  2307. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2308. foreach ( $iridList as $value ) {
  2309. $invoiceReceivables = new invoiceReceivables ();
  2310. $irDetails = $invoiceReceivables->getOne ( array (
  2311. 'where' => " irid=" . $value . ' and bindStatus=1',
  2312. 'asArray' => TRUE
  2313. ) );
  2314. $item = array (
  2315. 'irid' => $value,
  2316. 'bindStatus' => 0,
  2317. 'untreadStatus' => 1,
  2318. 'untreadStaff' => $invoiceDetails ['userName'],
  2319. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2320. 'iid' => 0
  2321. );
  2322. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2323. if (! empty ( $irDetails )) {
  2324. // 扣除入账
  2325. $invoiceStatistics = new invoiceStatistics ();
  2326. $item = array (
  2327. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2328. 'priceClass' => 3,
  2329. 'cid' => $invoiceDetails ['cid'],
  2330. 'staff' => $invoiceDetails ['sid'],
  2331. 'accountPrice' => - $irDetails ['receivablesPrice']
  2332. );
  2333. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2334. // 扣除收款
  2335. $invoiceStatistics = new invoiceStatistics ();
  2336. $item = array (
  2337. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2338. 'priceClass' => 2,
  2339. 'cid' => $invoiceDetails ['cid'],
  2340. 'staff' => $invoiceDetails ['sid'],
  2341. 'irid' => $irDetails ['irid'],
  2342. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2343. );
  2344. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2345. }
  2346. }
  2347. }
  2348. return "/invoiceUntread";
  2349. }
  2350. /**
  2351. * 建立负票,关联原来发票
  2352. */
  2353. function invoiceLossDo() {
  2354. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2355. if (! empty ( $iidKey )) {
  2356. Doo::loadClass ( 'XDeode' );
  2357. $XDeode = new XDeode ( 5 );
  2358. Doo::loadModel ( 'invoice' );
  2359. $invoice = new invoice ();
  2360. Doo::loadModel ( 'invoiceOperationLog' );
  2361. $invoiceOperationLog = new invoiceOperationLog ();
  2362. $iidKey = $XDeode->decode ( $iidKey );
  2363. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2364. // 拷贝插入一条发票数据
  2365. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2366. // 更新负票
  2367. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2368. $invoice = new invoice ();
  2369. $item = array (
  2370. 'iid' => $iid,
  2371. 'sid' => $this->staff [0] ['sid'],
  2372. 'userName' => $this->staff [0] ['username'],
  2373. 'cid' => $this->staff [0] ['cid'],
  2374. 'categoryName' => $this->staff [0] ['category'],
  2375. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2376. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2377. 'invoiceSerial' => $invoiceSerial,
  2378. 'invoiceNo' => '',
  2379. 'printStatus' => 0,
  2380. 'untreadStatus' => 4,
  2381. // 关联发票号
  2382. 'lossIid' => $invoiceDetail ['iid']
  2383. );
  2384. $invoice->setInvoiceByCondition ( $item );
  2385. // 更新原发票
  2386. $invoice = new invoice ();
  2387. $item = array (
  2388. 'iid' => $invoiceDetail ['iid'],
  2389. 'lossIid' => $iid
  2390. );
  2391. $invoice->setInvoiceByCondition ( $item );
  2392. // 操作日志
  2393. $item = array (
  2394. 'date' => date ( "Y-m-d H:i:s" ),
  2395. 'operation' => "创建负票" . $invoiceSerial,
  2396. 'status' => 12,
  2397. 'img' => $this->staff [0] ['avatar'],
  2398. 'username' => $this->staff [0] ['username'],
  2399. 'uid' => $this->staff [0] ['sid'],
  2400. 'category' => $this->staff [0] ['category'],
  2401. 'iid' => $iid
  2402. );
  2403. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2404. // print_r($invoiceDetail);
  2405. // echo $iid;die;
  2406. }
  2407. return '/invoiceUntread';
  2408. }
  2409. /**
  2410. * 上传银行到账 收款文件
  2411. */
  2412. function invoiceReceivablesBankUpload() {
  2413. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2414. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2415. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2416. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2417. header ( "HTTP/1.1 500 Internal Server Error" );
  2418. echo "POST exceeded maximum allowed size.";
  2419. exit ( 0 );
  2420. }
  2421. // Settings
  2422. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  2423. $upload_name = "Filedata";
  2424. $file_name = "";
  2425. $nk = time ();
  2426. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2427. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2428. echo "文件无法保存.";
  2429. exit ( 0 );
  2430. }
  2431. echo json_encode ( array (
  2432. 'filename' => $file_name,
  2433. 'id' => $nk
  2434. ) );
  2435. exit ( 0 );
  2436. }
  2437. /**
  2438. * 解析银行到账收款execl并导入库中
  2439. */
  2440. function invoiceReceivablesImport() {
  2441. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2442. if ($path != "") {
  2443. Doo::loadModel ( 'invoiceReceivables' );
  2444. $invoiceReceivables = new invoiceReceivables ();
  2445. Doo::loadClass ( 'invoice.func' );
  2446. Doo::loadModel ( 'invoiceROLog' );
  2447. $invoiceROLog = new invoiceROLog ();
  2448. Doo::loadModel ( 'invoiceStatistics' );
  2449. $invoiceStatistics = new invoiceStatistics ();
  2450. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2451. $bankBatchNumber = 'BBN_' . time ();
  2452. Doo::db ()->beginTransaction ();
  2453. // 批量存储收款--由于必须获得收款ID,
  2454. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2455. VALUES ';
  2456. $date = date ( "Y-m-d" );
  2457. $receivablesList = array ();
  2458. foreach ( $exlArray as $key => $value ) {
  2459. $receivablesSql = '(' . $value ["receivablesPrice"] . ',' . $value ["receivablesPrice"] . ',"' . $value ["receivablesMessage"] . '",' . '"#SK' . date ( "Ymd" ) . mt_rand ( 1000, 9999 ) . '","' . $value ["receivablesBank"] . '","' . $value ["receivablesDate"] . '","' . $this->staff [0] ['username'] . '","' . $date . '","PUBLIC","PUBLIC","' . $bankBatchNumber . '","' . $value ["receivablesMessage"] . '")';
  2460. array_push ( $receivablesList, $receivablesSql );
  2461. }
  2462. $sql = $sql . implode ( ',', $receivablesList );
  2463. // echo $sql;
  2464. Doo::db ()->query ( $sql );
  2465. // 批量存储收款统计
  2466. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2467. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2468. // 没有irid 回滚所有操作
  2469. if (empty ( $iridList )) {
  2470. Doo::db ()->rollBack ();
  2471. header ( 'Content-Type:text/html;charset=utf-8' );
  2472. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2473. }
  2474. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2475. VALUES ';
  2476. $statisticsList = array ();
  2477. foreach ( $iridList as $value ) {
  2478. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2479. array_push ( $statisticsList, $statisticsSql );
  2480. }
  2481. $sql = $sql . implode ( ',', $statisticsList );
  2482. Doo::db ()->query ( $sql );
  2483. // 批量存储操作日志
  2484. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2485. VALUES ';
  2486. $ROLogList = array ();
  2487. foreach ( $iridList as $value ) {
  2488. $ROLogSql = '("' . $this->staff [0] ['username'] . ' 转入 公共待认领款项","' . $date . '",1,"' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value ['irid'] . '")';
  2489. array_push ( $ROLogList, $ROLogSql );
  2490. }
  2491. $sql = $sql . implode ( ',', $ROLogList );
  2492. Doo::db ()->query ( $sql );
  2493. Doo::db ()->commit ();
  2494. return "/invoiceReceivables";
  2495. }
  2496. echo 'no file';
  2497. }
  2498. function invoiceReceivables() {
  2499. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2500. Doo::loadModel ( 'L_category' );
  2501. $lCategory = new L_category ();
  2502. Doo::loadModel ( 'staff' );
  2503. $staff = new staff ();
  2504. Doo::loadModel ( 'invoiceReceivables' );
  2505. $invoiceReceivables = new invoiceReceivables ();
  2506. Doo::loadModel ( 'invoice' );
  2507. $invoice = new invoice ();
  2508. Doo::loadClass ( 'XDeode' );
  2509. $XDeode = new XDeode ( 5 );
  2510. $category = $lCategory->getCategory ();
  2511. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2512. $sql = 'bindStatus=1 and iid!=0';
  2513. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2514. // 获取未入账发票
  2515. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2516. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2517. foreach ( $invoiceUnAccount as $key => $value ) {
  2518. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2519. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2520. if (! empty ( $lastApprover )) {
  2521. $lastApproverKey = array_keys ( $lastApprover );
  2522. $lastApprover = end ( $lastApprover );
  2523. $staffDetail = $staff->getOne ( array (
  2524. 'where' => 'sid=' . end ( $lastApproverKey ),
  2525. 'asArray' => true
  2526. ) );
  2527. $lastApprover ['username'] = $staffDetail ['username'];
  2528. }
  2529. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2530. }
  2531. foreach ( $invoiceExistAccount as $key => $value ) {
  2532. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2533. if (empty ( $irList ))
  2534. $irList [0] ['sumPrice'] = 0;
  2535. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2536. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2537. $invoiceExistAccount [$key] ['balance'] = $balance;
  2538. }
  2539. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2540. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2541. $this->data ['halfList'] = $halfList;
  2542. $this->data ['halfCount'] = count ( $halfList );
  2543. // print_r($receivablesList);
  2544. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2545. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2546. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2547. $this->data ['receivablesInput'] = $receivablesInput;
  2548. $this->data ['year'] = date ( 'Y' );
  2549. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2550. $this->data ['receivablesList'] = $receivablesList;
  2551. $this->data ['staffList'] = $staffList;
  2552. $this->data ['category'] = $category;
  2553. $this->data ['memu'] = "invoice";
  2554. $this->data ['staff'] = $this->staff;
  2555. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2556. $this->render ( "/admin/invoiceReceivables", $this->data );
  2557. }
  2558. /**
  2559. * 设置收款认领地区
  2560. */
  2561. function setInvoiceReceivablesClaim() {
  2562. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2563. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2564. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2565. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2566. Doo::loadModel ( 'invoiceReceivables' );
  2567. $invoiceReceivables = new invoiceReceivables ();
  2568. Doo::loadClass ( 'XDeode' );
  2569. $XDeode = new XDeode ( 5 );
  2570. Doo::loadModel ( 'invoiceROLog' );
  2571. $invoiceROLog = new invoiceROLog ();
  2572. $irid = $XDeode->decode ( $iridKey );
  2573. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2574. if (empty ( $irDetail ))
  2575. die ( 'illegal request' );
  2576. $item = array (
  2577. 'irid' => $irid,
  2578. 'receivablesCategory' => $receivablesCategory
  2579. );
  2580. if ($receivablesCategory != 'PUBLIC') {
  2581. $item += array (
  2582. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2583. 'inputType' => 1
  2584. );
  2585. }
  2586. $invoiceReceivables = new invoiceReceivables ();
  2587. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2588. // 收款操作日志
  2589. $item = array (
  2590. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2591. 'date' => date ( "Y-m-d" ),
  2592. 'status' => 1,
  2593. 'img' => $this->staff [0] ['avatar'],
  2594. 'username' => $this->staff [0] ['username'],
  2595. 'uid' => $this->staff [0] ['sid'],
  2596. 'category' => $this->staff [0] ['category'],
  2597. 'irid' => $irid
  2598. );
  2599. $invoiceROLog->setInvoiceROLog ( $item );
  2600. if (empty ( $action ))
  2601. return '/invoiceReceivables';
  2602. else
  2603. return "/invoiceReceivablesAS";
  2604. }
  2605. die ( 'illegal request' );
  2606. }
  2607. /**
  2608. * 新添加收款直接入账发票
  2609. */
  2610. function invoiceCompareClaimPrice() {
  2611. // 收款录入
  2612. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2613. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2614. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2615. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2616. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2617. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2618. Doo::loadModel ( 'invoiceReceivables' );
  2619. $invoiceReceivables = new invoiceReceivables ();
  2620. Doo::loadModel ( 'invoiceROLog' );
  2621. $invoiceROLog = new invoiceROLog ();
  2622. Doo::loadModel ( 'invoiceStatistics' );
  2623. Doo::loadModel ( 'invoice' );
  2624. $invoice = new invoice ();
  2625. Doo::loadClass ( 'XDeode' );
  2626. $XDeode = new XDeode ( 5 );
  2627. Doo::loadModel ( 'invoiceOperationLog' );
  2628. $invoiceOperationLog = new invoiceOperationLog ();
  2629. $iidKey = $XDeode->decode ( $iidKey );
  2630. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2631. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2632. die ( 'illegal request' );
  2633. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2634. // 收款录入 并绑定发票
  2635. Doo::db ()->beginTransaction ();
  2636. $bindStatus = 0;
  2637. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2638. $bindStatus = 1;
  2639. $item = array (
  2640. 'bindStatus' => $bindStatus,
  2641. 'iid' => $invoiceDetail ['iid'],
  2642. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2643. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2644. 'receivablesPrice' => $receivablesPrice,
  2645. 'OriginalPrice' => $receivablesPrice,
  2646. 'receivablesMessage' => $receivablesMessage,
  2647. 'receivablesSerial' => $receivablesSerial,
  2648. 'receivablesBank' => $receivablesBank,
  2649. 'receivablesDate' => $receivablesDate,
  2650. 'inputStaff' => $this->staff [0] ['username'],
  2651. 'accountClerk' => $this->staff [0] ['username'],
  2652. 'date' => date ( "Y-m-d" ),
  2653. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2654. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2655. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2656. );
  2657. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2658. $item = array ();
  2659. // 收款操作日志
  2660. $item = array (
  2661. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2662. );
  2663. $item += array (
  2664. 'date' => date ( "Y-m-d" ),
  2665. 'status' => 1,
  2666. 'img' => $this->staff [0] ['avatar'],
  2667. 'username' => $this->staff [0] ['username'],
  2668. 'uid' => $this->staff [0] ['sid'],
  2669. 'category' => $this->staff [0] ['category'],
  2670. 'irid' => $irid
  2671. );
  2672. $invoiceROLog->setInvoiceROLog ( $item );
  2673. // 收款统计
  2674. $invoiceStatistics = new invoiceStatistics ();
  2675. $item = array (
  2676. 'date' => $receivablesDate,
  2677. 'priceClass' => 2,
  2678. 'irid' => $irid,
  2679. 'cid' => $invoiceDetail ['cid'],
  2680. 'staff' => $invoiceDetail ['sid'],
  2681. 'receivablesPrice' => $receivablesPrice
  2682. );
  2683. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2684. // 收款 入 发票
  2685. $detail = $invoiceDetail;
  2686. $iridString = "";
  2687. if (empty ( $detail ['irid'] ))
  2688. $iridString = $irid;
  2689. else
  2690. $iridString = $detail ['irid'] . ',' . $irid;
  2691. $item = array (
  2692. 'irid' => $iridString,
  2693. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2694. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2695. 'iid' => $detail ['iid']
  2696. );
  2697. $invoiceReceivables = new invoiceReceivables ();
  2698. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2699. if ($detail ['invoicePrice'] <= $sum)
  2700. $item += array (
  2701. 'untreadStatus' => 3
  2702. );
  2703. $invoice->setInvoiceByCondition ( $item );
  2704. // 操作日志
  2705. $item = array (
  2706. 'date' => date ( "Y-m-d H:i:s" ),
  2707. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  2708. 'status' => 8,
  2709. 'img' => $this->staff [0] ['avatar'],
  2710. 'username' => $this->staff [0] ['username'],
  2711. 'uid' => $this->staff [0] ['sid'],
  2712. 'category' => $this->staff [0] ['category'],
  2713. 'iid' => $detail ['iid']
  2714. );
  2715. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2716. // 入账汇总
  2717. $invoiceStatistics = new invoiceStatistics ();
  2718. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  2719. // $accountPrice = 0;
  2720. // foreach ( $list as $key => $value ) {
  2721. // $accountPrice += $value ['receivablesPrice'];
  2722. // }
  2723. $item = array (
  2724. 'date' => $receivablesDate,
  2725. 'priceClass' => 3,
  2726. 'cid' => $invoiceDetail ['cid'],
  2727. 'staff' => $invoiceDetail ['sid'],
  2728. 'accountPrice' => $receivablesPrice
  2729. );
  2730. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2731. Doo::db ()->commit ();
  2732. }
  2733. return '/invoiceReceivables';
  2734. }
  2735. /**
  2736. * 检索未入账发票数据 function sir() { }
  2737. */
  2738. /**
  2739. * 录入收款数据
  2740. * @return string
  2741. */
  2742. function invoiceReceivablesDo() {
  2743. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2744. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2745. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2746. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2747. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2748. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2749. Doo::loadModel ( 'invoiceReceivables' );
  2750. $invoiceReceivables = new invoiceReceivables ();
  2751. Doo::loadModel ( 'invoiceROLog' );
  2752. $invoiceROLog = new invoiceROLog ();
  2753. Doo::loadModel ( 'invoiceStatistics' );
  2754. $invoiceStatistics = new invoiceStatistics ();
  2755. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  2756. $item = array (
  2757. 'receivablesPrice' => $receivablesPrice,
  2758. 'OriginalPrice' => $receivablesPrice,
  2759. 'receivablesMessage' => $receivablesMessage,
  2760. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  2761. 'receivablesBank' => $receivablesBank,
  2762. 'receivablesDate' => $receivablesDate,
  2763. 'inputStaff' => $this->staff [0] ['username'],
  2764. 'date' => date ( "Y-m-d" ),
  2765. 'receivablesCategory' => $receivablesCategory,
  2766. 'receivablesStaff' => $receivablesStaff
  2767. );
  2768. if ($receivablesCategory != 'PUBLIC') {
  2769. $item += array (
  2770. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2771. 'inputType' => 1
  2772. );
  2773. }
  2774. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2775. $item = array ();
  2776. // 收款操作日志
  2777. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2778. $item = array (
  2779. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2780. );
  2781. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2782. $item = array (
  2783. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2784. );
  2785. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2786. $receivablesStaff = explode ( '-', $receivablesStaff );
  2787. $item = array (
  2788. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2789. );
  2790. }
  2791. $item += array (
  2792. 'date' => date ( "Y-m-d" ),
  2793. 'status' => 1,
  2794. 'img' => $this->staff [0] ['avatar'],
  2795. 'username' => $this->staff [0] ['username'],
  2796. 'uid' => $this->staff [0] ['sid'],
  2797. 'category' => $this->staff [0] ['category'],
  2798. 'irid' => $irid
  2799. );
  2800. $invoiceROLog->setInvoiceROLog ( $item );
  2801. $item = array (
  2802. 'date' => $receivablesDate,
  2803. 'priceClass' => 2,
  2804. 'irid' => $irid,
  2805. 'receivablesPrice' => $receivablesPrice
  2806. );
  2807. if ($receivablesCategory != 'PUBLIC') {
  2808. $receivablesCategory = explode ( ":", $receivablesCategory );
  2809. $item += array (
  2810. 'cid' => $receivablesCategory [0]
  2811. );
  2812. }
  2813. if ($receivablesStaff2 != 'PUBLIC') {
  2814. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  2815. $item += array (
  2816. 'staff' => $receivablesStaff [0]
  2817. );
  2818. }
  2819. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2820. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  2821. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  2822. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  2823. if ($toparty != 0)
  2824. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  2825. }
  2826. return "/invoiceReceivables";
  2827. }
  2828. /**
  2829. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  2830. */
  2831. function invoiceReceivablesClaim() {
  2832. Doo::loadModel ( 'invoiceReceivables' );
  2833. $invoiceReceivables = new invoiceReceivables ();
  2834. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2835. $this->data ['receivablesList'] = $receivablesList;
  2836. $this->data ['memu'] = "invoice";
  2837. $this->data ['staff'] = $this->staff;
  2838. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  2839. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  2840. }
  2841. function invoiceReceivablesTitleMarkSet() {
  2842. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2843. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2844. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  2845. die ( 'illegal request' );
  2846. Doo::loadModel ( 'invoiceReceivables' );
  2847. $invoiceReceivables = new invoiceReceivables ();
  2848. Doo::loadClass ( 'XDeode' );
  2849. $XDeode = new XDeode ( 5 );
  2850. $irid = $XDeode->decode ( $iridKey );
  2851. if (! is_numeric ( $irid ))
  2852. die ( 'illegal request' );
  2853. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  2854. $invoiceReceivables->update ( array (
  2855. 'where' => 'irid = ' . $irid
  2856. ) );
  2857. return '/invoiceReceivablesClaim';
  2858. }
  2859. /**
  2860. * 更新收款相关数据
  2861. */
  2862. function invoiceReceivablesUpdateClaim() {
  2863. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2864. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2865. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2866. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2867. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2868. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2869. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2870. if (empty ( $claimKey ))
  2871. die ( 'illegal request' );
  2872. Doo::loadModel ( 'invoiceReceivables' );
  2873. $invoiceReceivables = new invoiceReceivables ();
  2874. Doo::loadModel ( 'invoiceROLog' );
  2875. $invoiceROLog = new invoiceROLog ();
  2876. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  2877. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2878. if (empty ( $detail ))
  2879. die ( 'illegal request' );
  2880. $invoiceReceivables = new invoiceReceivables ();
  2881. $item = array (
  2882. 'irid' => $detail ['irid']
  2883. );
  2884. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2885. $item += array (
  2886. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2887. );
  2888. }
  2889. if (! empty ( $receivablesCategory ))
  2890. $item += array (
  2891. 'receivablesCategory' => $receivablesCategory
  2892. );
  2893. if (! empty ( $receivablesStaff ))
  2894. $item += array (
  2895. 'receivablesStaff' => $receivablesStaff
  2896. );
  2897. if (! empty ( $receivablesPrice ))
  2898. $item += array (
  2899. 'receivablesPrice' => $receivablesPrice
  2900. );
  2901. if (! empty ( $receivablesMessage ))
  2902. $item += array (
  2903. 'receivablesMessage' => $receivablesMessage
  2904. );
  2905. if (! empty ( $receivablesBank ))
  2906. $item += array (
  2907. 'receivablesBank' => $receivablesBank
  2908. );
  2909. if (! empty ( $receivablesDate ))
  2910. $item += array (
  2911. 'receivablesDate' => $receivablesDate
  2912. );
  2913. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2914. // 收款操作日志
  2915. $item = array ();
  2916. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2917. $item = array (
  2918. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2919. );
  2920. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2921. $item = array (
  2922. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2923. );
  2924. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2925. $receivablesStaff = explode ( '-', $receivablesStaff );
  2926. $item = array (
  2927. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2928. );
  2929. }
  2930. $item += array (
  2931. 'date' => date ( "Y-m-d" ),
  2932. 'status' => 1,
  2933. 'img' => $this->staff [0] ['avatar'],
  2934. 'username' => $this->staff [0] ['username'],
  2935. 'uid' => $this->staff [0] ['sid'],
  2936. 'category' => $this->staff [0] ['category'],
  2937. 'irid' => $detail ['irid']
  2938. );
  2939. $invoiceROLog->setInvoiceROLog ( $item );
  2940. return '/invoiceReceivablesAS';
  2941. }
  2942. function invoiceReceivablesDelete() {
  2943. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2944. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  2945. if ($skll!='删除到款')
  2946. die ( 'illegal request' );
  2947. if (empty ( $claimKey ))
  2948. die ( 'illegal request' );
  2949. Doo::loadModel ( 'invoiceReceivables' );
  2950. $invoiceReceivables = new invoiceReceivables ();
  2951. $con = ' and bindStatus=0 ';
  2952. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2953. if (empty ( $detail ))
  2954. die ( 'illegal request' );
  2955. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  2956. //扣除收款汇总信息 汇总
  2957. Doo::loadModel ( 'invoiceStatistics' );
  2958. $invoiceStatistics = new invoiceStatistics ();
  2959. $item = array (
  2960. 'date' => $detail['receivablesDate'],
  2961. 'priceClass' => 2,
  2962. 'irid' => $detail['irid'],
  2963. 'receivablesPrice' => -$detail['receivablesPrice']
  2964. );
  2965. if ($detail['receivablesCategory'] != 'PUBLIC') {
  2966. $receivablesCategory = explode ( ":", $detail['receivablesCategory'] );
  2967. $item += array (
  2968. 'cid' => $receivablesCategory [0]
  2969. );
  2970. }
  2971. if ($detail['receivablesStaff'] != 'PUBLIC') {
  2972. $receivablesStaff = explode ( "-", $detail['receivablesStaff'] );
  2973. $item += array (
  2974. 'staff' => $receivablesStaff [0]
  2975. );
  2976. }
  2977. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2978. return '/invoiceReceivablesAS';
  2979. }
  2980. /**
  2981. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  2982. */
  2983. function invoiceReceivablesAscription() {
  2984. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2985. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2986. Doo::loadModel ( 'invoiceReceivables' );
  2987. $invoiceReceivables = new invoiceReceivables ();
  2988. Doo::loadModel ( 'invoiceROLog' );
  2989. $invoiceROLog = new invoiceROLog ();
  2990. Doo::loadModel ( 'invoiceStatistics' );
  2991. $invoiceStatistics = new invoiceStatistics ();
  2992. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2993. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  2994. $item = array (
  2995. 'irid' => $detail ['irid'],
  2996. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  2997. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  2998. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2999. 'recepitTitleMark' => $recepitTitleMark,
  3000. 'source' => 1
  3001. );
  3002. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3003. $item = array (
  3004. 'date' => date ( "Y-m-d" ),
  3005. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3006. 'status' => 2,
  3007. 'img' => $this->staff [0] ['avatar'],
  3008. 'username' => $this->staff [0] ['username'],
  3009. 'uid' => $this->staff [0] ['sid'],
  3010. 'category' => $this->staff [0] ['category'],
  3011. 'irid' => $irid
  3012. );
  3013. $invoiceROLog->setInvoiceROLog ( $item );
  3014. $item = array (
  3015. 'cid' => $this->staff [0] ['cid'],
  3016. 'staff' => $this->staff [0] ['sid']
  3017. );
  3018. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3019. }
  3020. return "/invoiceReceivablesClaim";
  3021. }
  3022. /**
  3023. */
  3024. function invoiceMyReceivables() {
  3025. Doo::loadModel ( 'invoiceReceivables' );
  3026. $invoiceReceivables = new invoiceReceivables ();
  3027. Doo::loadModel ( 'invoiceStatistics' );
  3028. $invoiceStatistics = new invoiceStatistics ();
  3029. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3030. $year = date ( "Y" );
  3031. $tmp_date = date ( "Ym" );
  3032. $tmp_year = substr ( $tmp_date, 0, 4 );
  3033. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3034. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3035. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3036. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3037. $htm = $this->showCache ( $path );
  3038. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3039. $this->data ['isMonth'] = $isMonth;
  3040. $this->data ['htm'] = $htm;
  3041. $this->data ['list'] = $list;
  3042. $this->data ['memu'] = "invoice";
  3043. $this->data ['staff'] = $this->staff;
  3044. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3045. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3046. }
  3047. /**
  3048. * 纸票管理
  3049. */
  3050. function invoicePaper() {
  3051. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3052. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3053. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3054. $this->data ['dateString'] = $date;
  3055. $this->data ['status'] = $status;
  3056. $this->data ['invoiceType'] = $invoiceType;
  3057. $this->data ['memu'] = "invoice";
  3058. $this->data ['staff'] = $this->staff;
  3059. $this->data ['receiptMemu'] = 'invoicePaper';
  3060. $this->render ( "/admin/invoicePaper", $this->data );
  3061. }
  3062. /**
  3063. * 获得纸票分页数据
  3064. */
  3065. function ajaxGetinvoicePaperAchieve() {
  3066. Doo::loadModel ( 'invoicePaper' );
  3067. $invoicePaper = new invoicePaper ();
  3068. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3069. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3070. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3071. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3072. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3073. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3074. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3075. $MebSea = $this->get_args ( 'search' );
  3076. $MebSea = $MebSea ['value'];
  3077. $page_size = $length;
  3078. $con = '';
  3079. if ($status == 'ALL')
  3080. $con = ' where 1 ';
  3081. elseif ($status == 'PRINTED')
  3082. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=1 ';
  3083. elseif ($status == 'UNPRINT')
  3084. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=0 ';
  3085. elseif ($status == 'TICKET')
  3086. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3087. if ($invoiceType == 'ORDINARY')
  3088. $con .= ' and a.invoiceType=0 ';
  3089. elseif ($invoiceType == 'SPECIAL')
  3090. $con .= ' and a.invoiceType=1 ';
  3091. $dateArr = explode ( ':', $date );
  3092. $D1 = $dateString = '';
  3093. $D2 = '';
  3094. if (! empty ( $date )) {
  3095. $D1 = $dateArr [0];
  3096. if (isset ( $dateArr [1] ))
  3097. $D2 = $dateArr [1];
  3098. else
  3099. $D2 = '';
  3100. $dateString = $D1 . " : " . $D2;
  3101. }
  3102. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3103. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3104. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3105. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3106. if (! empty ( $MebSea ))
  3107. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3108. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3109. $sql = ' ' . $con;
  3110. $limit = $page . ',' . $page_size;
  3111. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3112. $paperList = array ();
  3113. foreach ( $list as $key => $value ) {
  3114. $irDetail = array ();
  3115. if ($value ['iid'] == 0)
  3116. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3117. else
  3118. array_push ( $irDetail, '' );
  3119. array_push ( $irDetail, $value ['invoiceCode'] );
  3120. array_push ( $irDetail, $value ['invoiceNo'] );
  3121. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3122. if ($value ['invoiceType'] == 1)
  3123. array_push ( $irDetail, $value ['invoiceCompany'] );
  3124. else
  3125. array_push ( $irDetail, $value ['invoiceTitle'] );
  3126. if ($value ['invoiceType'] == 1)
  3127. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3128. else
  3129. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3130. array_push ( $irDetail, $value ['invoiceElement'] );
  3131. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3132. array_push ( $irDetail, $value ['printTime'] );
  3133. array_push ( $paperList, $irDetail );
  3134. }
  3135. // $approvalListJson = json_encode ( $approvalList );
  3136. $recordsFiltered = $invoiceTotal;
  3137. echo json_encode ( array (
  3138. "draw" => intval ( $draw ),
  3139. "recordsTotal" => intval ( $invoiceTotal ),
  3140. "recordsFiltered" => intval ( $recordsFiltered ),
  3141. "data" => $paperList
  3142. ), JSON_UNESCAPED_UNICODE );
  3143. }
  3144. function invoicePaperDel() {
  3145. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3146. $XDeode = new XDeode ( 5 );
  3147. $ipid = $XDeode->decode ( $ipidKey );
  3148. if (empty ( $ipid ))
  3149. die ( 'illegal request' );
  3150. Doo::loadModel ( 'invoicePaper' );
  3151. $invoicePaper = new invoicePaper ();
  3152. $invoicePaper->delete ( array (
  3153. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3154. 'limit' => 1
  3155. ) );
  3156. return '/invoicePaper';
  3157. }
  3158. /**
  3159. * 添加纸质发票号
  3160. */
  3161. function invoicePaperAdd() {
  3162. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3163. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3164. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3165. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3166. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3167. $sum = $invoiceNoStart + $invoiceNoTotal;
  3168. if (empty ( $sum ))
  3169. die ( 'illegal request' );
  3170. Doo::db ()->beginTransaction ();
  3171. // 批量存储纸质发票
  3172. $date = date ( "Y-m-d H:i:s" );
  3173. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3174. VALUES ';
  3175. $paperList = array ();
  3176. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3177. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $invoiceNoStart . '","' . $date . '")';
  3178. array_push ( $paperList, $paperSql );
  3179. }
  3180. if (empty ( $paperList ))
  3181. die ( 'illegal request' );
  3182. $sql = $sql . implode ( ',', $paperList );
  3183. Doo::db ()->query ( $sql );
  3184. Doo::db ()->commit ();
  3185. return 'invoicePaper';
  3186. }
  3187. die ( 'illegal request' );
  3188. }
  3189. /**
  3190. * 收款绑定发票 ,一个收款只能绑定一个发票
  3191. */
  3192. function invoiceBindReceivables() {
  3193. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3194. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3195. Doo::loadModel ( 'invoice' );
  3196. $invoice = new invoice ();
  3197. Doo::loadModel ( 'invoiceReceivables' );
  3198. $invoiceReceivables = new invoiceReceivables ();
  3199. Doo::loadModel ( 'invoiceOperationLog' );
  3200. $invoiceOperationLog = new invoiceOperationLog ();
  3201. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3202. die ( 'illegal request' );
  3203. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3204. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3205. if (empty ( $detail ) && empty ( $detailM ))
  3206. die ( 'illegal request' );
  3207. if ($detail ['untreadStatus'] == 3)
  3208. die ( 'illegal request' );
  3209. // 修改 绑定状态改为 金额
  3210. $invoiceReceivables = new invoiceReceivables ();
  3211. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3212. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3213. $item = array (
  3214. 'bindPrice' => $invoicePrice
  3215. );
  3216. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3217. $item = array (
  3218. 'bindPrice' => $invoicePrice,
  3219. 'bindStatus' => 1,
  3220. 'bindDate' => date ( "Y-m-d H:i:s" )
  3221. );
  3222. } else {
  3223. die ( 'illegal request' );
  3224. }
  3225. if ($detailM ['iid'] == 0) {
  3226. $item += array (
  3227. 'iid' => $detail ['iid']
  3228. );
  3229. } else {
  3230. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3231. array_push ( $iidExtend, $detail ['iid'] );
  3232. $item += array (
  3233. 'iidExtend' => implode ( ',', $iidExtend )
  3234. );
  3235. }
  3236. $item += array (
  3237. 'irid' => $detailM ['irid'],
  3238. 'accountClerk' => $this->staff [0] ['username']
  3239. );
  3240. // 如何没有人收款 则自动绑定收款
  3241. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3242. $item += array (
  3243. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3244. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3245. );
  3246. }
  3247. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3248. $iridString = "";
  3249. if (empty ( $detail ['irid'] ))
  3250. $iridString = $detailM ['irid'];
  3251. else
  3252. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3253. $item = array (
  3254. 'iid' => $detail ['iid'],
  3255. 'irid' => $iridString
  3256. );
  3257. $invoiceReceivables = new invoiceReceivables ();
  3258. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3259. if ($detail ['invoicePrice'] <= $sum)
  3260. $item += array (
  3261. 'untreadStatus' => 3,
  3262. 'bindTime' => date ( "Y-m-d H:i:s" )
  3263. );
  3264. // print_r($item);
  3265. // echo $sum;die;
  3266. $invoice->setInvoiceByCondition ( $item );
  3267. // 操作日志
  3268. $item = array (
  3269. 'date' => date ( "Y-m-d H:i:s" ),
  3270. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3271. 'status' => 8,
  3272. 'img' => $this->staff [0] ['avatar'],
  3273. 'username' => $this->staff [0] ['username'],
  3274. 'uid' => $this->staff [0] ['sid'],
  3275. 'category' => $this->staff [0] ['category'],
  3276. 'iid' => $detail ['iid']
  3277. );
  3278. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3279. Doo::loadModel ( 'invoiceStatistics' );
  3280. $invoiceStatistics = new invoiceStatistics ();
  3281. $item = array (
  3282. 'date' => $detailM ['receivablesDate'],
  3283. 'priceClass' => 3,
  3284. 'cid' => $detail ['cid'],
  3285. 'staff' => $detail ['sid'],
  3286. 'accountPrice' => $detailM ['receivablesPrice']
  3287. );
  3288. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3289. return "/invoiceReceivables";
  3290. }
  3291. /**
  3292. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 function invoiceEnterReceivables() { $invoiceKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; // $invoiceClaim = $this->get_args ( 'invoiceClaim' ) ? $this->get_args ( 'invoiceClaim' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); Doo::loadModel ( 'invoiceStatistics' ); $invoiceStatistics = new invoiceStatistics (); Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); $detail = $invoice->getInvoiceByIid ( $invoiceKey ); if (empty ( $detail )) die ( 'illegal request' ); if (empty ( $detail ['irid'] )) die ( 'illegal request' ); $item = array ( 'untreadStatus' => 3, 'updateTime' => date ( "Y-m-d H:i:s" ), 'iid' => $detail ['iid'] ); $invoice->setInvoiceByCondition ( $item ); // 操作日志 $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'operation' => "发票" . $detail ['invoiceSerial'] . "收款完成", 'status' => 9, 'img' => $this->staff [0] ['avatar'], 'username' => $this->staff [0] ['username'], 'uid' => $this->staff [0] ['sid'], 'category' => $this->staff [0] ['category'], 'iid' => $detail ['iid'] ); $invoiceOperationLog->setInvoiceOperationLog ( $item ); $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] ); $accountPrice = 0; foreach ( $list as $key => $value ) { $accountPrice += $value ['receivablesPrice']; } $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'priceClass' => 3, 'cid' => $this->staff [0] ['cid'], 'staff' => $this->staff [0] ['sid'], 'accountPrice' => $accountPrice ); $invoiceStatistics->setInvoiceStatisticsByCondition ( $item ); return "/invoice"; }
  3293. */
  3294. function invoiceAggregate() {
  3295. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3296. Doo::loadModel ( 'invoiceStatistics' );
  3297. $invoiceStatistics = new invoiceStatistics ();
  3298. Doo::loadModel ( 'L_category' );
  3299. $Lcategory = new L_category ();
  3300. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3301. $LcategoryList = $Lcategory->getCategory ();
  3302. // print_r($isList);
  3303. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3304. foreach ( $LcategoryList as $key => $value ) {
  3305. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3306. $month = 1;
  3307. $invoicePriceYear = 0;
  3308. $receivablesPriceYear = 0;
  3309. $accountPriceYear = 0;
  3310. for(; $month <= 12; $month ++) {
  3311. $flag = true;
  3312. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3313. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3314. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3315. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3316. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3317. ';
  3318. $invoicePriceYear += $v ['invoicePrice'];
  3319. $receivablesPriceYear += $v ['receivablesPrice'];
  3320. $accountPriceYear += $v ['accountPrice'];
  3321. $flag = false;
  3322. break;
  3323. }
  3324. }
  3325. if ($flag)
  3326. $html .= '<td class="taR"></td>
  3327. <td class="taR"></td>
  3328. <td class="taR"><b></b></td>
  3329. ';
  3330. }
  3331. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3332. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3333. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3334. ';
  3335. $html .= '</tr>';
  3336. }
  3337. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3338. $invoicePriceYear = 0;
  3339. $receivablesPriceYear = 0;
  3340. $accountPriceYear = 0;
  3341. for($month = 1; $month <= 12; $month ++) {
  3342. $flag = true;
  3343. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3344. if ($month == $v ['month']) {
  3345. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3346. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3347. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3348. ';
  3349. $invoicePriceYear += $v ['invoicePrice'];
  3350. $receivablesPriceYear += $v ['receivablesPrice'];
  3351. $accountPriceYear += $v ['accountPrice'];
  3352. $flag = false;
  3353. break;
  3354. }
  3355. }
  3356. if ($flag) {
  3357. $html .= '<td class="taR"></td>
  3358. <td class="taR"></td>
  3359. <td class="taR"><b></b></td>
  3360. ';
  3361. }
  3362. }
  3363. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3364. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3365. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3366. ';
  3367. $html .= '</tr>';
  3368. // print_r($isList);
  3369. $this->data ['html'] = $html;
  3370. $this->data ['LcategoryList'] = $LcategoryList;
  3371. $this->data ['isList'] = $isList;
  3372. $this->data ['year'] = $year;
  3373. $this->data ['memu'] = "invoice";
  3374. $this->data ['staff'] = $this->staff;
  3375. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3376. $this->render ( "/admin/invoiceAggregate", $this->data );
  3377. }
  3378. function invoiceAggregateStaff() {
  3379. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3380. Doo::loadModel ( 'invoiceStatistics' );
  3381. $invoiceStatistics = new invoiceStatistics ();
  3382. Doo::loadModel ( 'L_category' );
  3383. $Lcategory = new L_category ();
  3384. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3385. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3386. $cStaff = $Lcategory->getCategoryStaff ();
  3387. $html = '';
  3388. foreach ( $cStaff as $key => $value ) {
  3389. $categoryFir = true;
  3390. foreach ( $value ['staff'] as $k => $v ) {
  3391. if ($categoryFir) {
  3392. $width = count ( $value ['staff'] ) + 1;
  3393. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3394. $categoryFir = false;
  3395. } else
  3396. $html .= '<tr>';
  3397. $html .= '<th>' . $v ['username'] . '</th>';
  3398. $invoicePriceStaffYear = 0;
  3399. $receivablesPriceStaffYear = 0;
  3400. $accountPriceStaffYear = 0;
  3401. for($month = 1; $month <= 12; $month ++) {
  3402. $flag = true;
  3403. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3404. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3405. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3406. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3407. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3408. ';
  3409. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3410. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3411. $accountPriceStaffYear += $slv ['accountPrice'];
  3412. $flag = false;
  3413. break;
  3414. }
  3415. }
  3416. if ($flag)
  3417. $html .= '<td class="taR"></td>
  3418. <td class="taR"></td>
  3419. <td class="taR"><b></b></td>
  3420. ';
  3421. }
  3422. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3423. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3424. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3425. ';
  3426. }
  3427. $html .= '</tr>';
  3428. // 小计
  3429. if (! empty ( $value ['staff'] )) {
  3430. $html .= '<tr><th class="taR">小计</th>';
  3431. $invoicePriceStaffYear = 0;
  3432. $receivablesPriceStaffYear = 0;
  3433. $accountPriceStaffYear = 0;
  3434. for($month = 1; $month <= 12; $month ++) {
  3435. $flag = true;
  3436. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3437. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3438. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3439. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3440. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3441. ';
  3442. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3443. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3444. $accountPriceStaffYear += $slv ['accountPrice'];
  3445. $flag = false;
  3446. break;
  3447. }
  3448. }
  3449. if ($flag)
  3450. $html .= '<td class="taR"></td>
  3451. <td class="taR"></td>
  3452. <td class="taR"><b></b></td>
  3453. ';
  3454. }
  3455. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3456. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3457. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3458. ';
  3459. $html .= '</tr>';
  3460. }
  3461. }
  3462. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3463. $invoicePriceYear = 0;
  3464. $receivablesPriceYear = 0;
  3465. $accountPriceYear = 0;
  3466. for($month = 1; $month <= 12; $month ++) {
  3467. $flag = true;
  3468. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3469. if ($month == $v ['month']) {
  3470. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3471. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3472. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3473. ';
  3474. $invoicePriceYear += $v ['invoicePrice'];
  3475. $receivablesPriceYear += $v ['receivablesPrice'];
  3476. $accountPriceYear += $v ['accountPrice'];
  3477. $flag = false;
  3478. break;
  3479. }
  3480. }
  3481. if ($flag)
  3482. $html .= '<td class="taR"></td>
  3483. <td class="taR"></td>
  3484. <td class="taR"><b></b></td>
  3485. ';
  3486. }
  3487. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3488. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3489. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3490. ';
  3491. $html .= '</tr>';
  3492. $this->data ['html'] = $html;
  3493. $this->data ['isList'] = $toteList;
  3494. $this->data ['year'] = $year;
  3495. $this->data ['memu'] = "invoice";
  3496. $this->data ['staff'] = $this->staff;
  3497. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3498. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3499. }
  3500. function invoiceAggregateCategory() {
  3501. Doo::loadClass ( 'XDeode' );
  3502. $XDeode = new XDeode ( 5 );
  3503. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3504. $cid = $XDeode->decode ( $cid );
  3505. if (! is_numeric ( $cid ))
  3506. die ( 'illegal request' );
  3507. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3508. Doo::loadModel ( 'invoiceStatistics' );
  3509. $invoiceStatistics = new invoiceStatistics ();
  3510. Doo::loadModel ( 'staff' );
  3511. $staff = new staff ();
  3512. $list = $staff->getStaffByCid ( $cid );
  3513. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3514. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3515. if (empty ( $list ))
  3516. die ( '该办事处没有成员' );
  3517. $htmlA = $htmlB = $htmlC = $html = '';
  3518. foreach ( $list as $key => $value ) {
  3519. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3520. $htmlB = '<tr><th class="taC">收款</th>';
  3521. $htmlC = '<tr><th class="taC">入账</th>';
  3522. $invoicePriceStaffYear = 0;
  3523. $receivablesPriceStaffYear = 0;
  3524. $accountPriceStaffYear = 0;
  3525. for($month = 1; $month <= 12; $month ++) {
  3526. $flag = true;
  3527. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3528. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3529. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3530. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3531. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3532. $invoicePriceStaffYear += $v ['invoicePrice'];
  3533. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3534. $accountPriceStaffYear += $v ['accountPrice'];
  3535. $flag = false;
  3536. break;
  3537. }
  3538. }
  3539. if ($flag) {
  3540. $htmlA .= '<td class="taR">-</td>';
  3541. $htmlB .= '<td class="taR">-</td>';
  3542. $htmlC .= '<td class="taR"><b>-</b></td>';
  3543. }
  3544. }
  3545. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3546. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3547. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3548. $htmlA .= '</tr>';
  3549. $htmlB .= '</tr>';
  3550. $htmlC .= '</tr>';
  3551. $html .= $htmlA . $htmlB . $htmlC;
  3552. }
  3553. $htmlA = $htmlB = $htmlC = "";
  3554. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3555. $htmlB = '<tr><th class="taC">收款</th>';
  3556. $htmlC = '<tr><th class="taC">入账</th>';
  3557. $invoicePriceStaffYear = 0;
  3558. $receivablesPriceStaffYear = 0;
  3559. $accountPriceStaffYear = 0;
  3560. for($month = 1; $month <= 12; $month ++) {
  3561. $flag = true;
  3562. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3563. if ($month == $v ['month']) {
  3564. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3565. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3566. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3567. $invoicePriceStaffYear += $v ['invoicePrice'];
  3568. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3569. $accountPriceStaffYear += $v ['accountPrice'];
  3570. $flag = false;
  3571. break;
  3572. }
  3573. }
  3574. if ($flag) {
  3575. $htmlA .= '<td class="taR">-</td>';
  3576. $htmlB .= '<td class="taR">-</td>';
  3577. $htmlC .= '<td class="taR"><b>-</b></td>';
  3578. }
  3579. }
  3580. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3581. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3582. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3583. $htmlA .= '</tr>';
  3584. $htmlB .= '</tr>';
  3585. $htmlC .= '</tr>';
  3586. $html .= $htmlA . $htmlB . $htmlC;
  3587. $this->data ['html'] = $html;
  3588. $this->data ['cidKey'] = $cidKey;
  3589. $this->data ['slist'] = $list;
  3590. $this->data ['isList'] = $toteList;
  3591. $this->data ['year'] = $year;
  3592. $this->data ['memu'] = "invoice";
  3593. $this->data ['staff'] = $this->staff;
  3594. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3595. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3596. }
  3597. /**
  3598. * 办事处汇总信息
  3599. */
  3600. function invoiceAggregateCategoryDetail() {
  3601. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  3602. Doo::loadClass ( 'XDeode' );
  3603. $XDeode = new XDeode ( 5 );
  3604. Doo::loadModel ( 'invoiceStatistics' );
  3605. $invoiceStatistics = new invoiceStatistics ();
  3606. Doo::loadModel ( 'L_category' );
  3607. $category = new L_category ();
  3608. Doo::loadModel ( 'invoice' );
  3609. $invoice = new invoice ();
  3610. Doo::loadModel ( 'staff' );
  3611. $staff = new staff ();
  3612. Doo::loadModel ( "invoiceCategoryManage" );
  3613. $invoiceCategoryManage = new invoiceCategoryManage ();
  3614. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3615. $cidList = array ();
  3616. foreach ( $imcStaff as $key => $value ) {
  3617. array_push ( $cidList, $value ['cid'] );
  3618. if (empty ( $cidKey ))
  3619. $cidKey = $XDeode->encode ( $value ['cid'] );
  3620. }
  3621. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  3622. $cid = $XDeode->decode ( $cidKey );
  3623. $month = date ( "m", strtotime ( "-1 month" ) );
  3624. $redis = new Redis ();
  3625. $redis->connect ( '127.0.0.1', '6379' );
  3626. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  3627. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  3628. if (empty ( $redisValue )) {
  3629. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  3630. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  3631. // 获得办事处人员下的汇总
  3632. $slist = $staff->getStaffByCid ( $cid );
  3633. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $month ); // 上一个月的汇总
  3634. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  3635. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  3636. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  3637. foreach ( $slist as $key => $value ) {
  3638. $slist [$key] ['invoicePrice'] = 0;
  3639. $slist [$key] ['receivablesPrice'] = 0;
  3640. $slist [$key] ['accountPrice'] = 0;
  3641. $slist [$key] ['invoiceAllPrice'] = 0;
  3642. $slist [$key] ['receivablesAllPrice'] = 0;
  3643. $slist [$key] ['accountAllPrice'] = 0;
  3644. $slist [$key] ['schedule'] = 0;
  3645. $slist [$key] ['invoiceMonthPrice'] = 0;
  3646. $slist [$key] ['receivablesMonthPrice'] = 0;
  3647. $slist [$key] ['accountMonthPrice'] = 0;
  3648. foreach ( $ismsbMonth as $y => $l ) {
  3649. if ($value ['sid'] == $l ['staff']) {
  3650. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  3651. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  3652. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  3653. }
  3654. }
  3655. foreach ( $ismsb as $k => $v ) {
  3656. if ($value ['sid'] == $v ['staff']) {
  3657. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  3658. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  3659. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  3660. }
  3661. }
  3662. foreach ( $ISAS as $e => $a ) {
  3663. if ($value ['sid'] == $a ['staff']) {
  3664. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  3665. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  3666. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  3667. }
  3668. }
  3669. if (isset ( $scheduleStaff [$value ['sid']] ))
  3670. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  3671. }
  3672. $this->data ['cidKey'] = $cidKey;
  3673. $schedule = ( int ) ($schedule * 100);
  3674. $this->data ['slist'] = $slist;
  3675. $this->data ['isMC'] = $isMC;
  3676. $this->data ['schedule'] = $schedule;
  3677. $slist = json_encode ( $slist );
  3678. $isMC = json_encode ( $isMC );
  3679. $schedule = json_encode ( $schedule );
  3680. $redis->lpush ( $redisKey, $slist );
  3681. $redis->lpush ( $redisKey, $isMC );
  3682. $redis->lpush ( $redisKey, $schedule );
  3683. } else {
  3684. $this->data ['cidKey'] = $cidKey;
  3685. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  3686. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  3687. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  3688. }
  3689. $this->data ['month'] = $month;
  3690. $this->data ['categoryList'] = $categoryList;
  3691. $this->data ['memu'] = "invoice";
  3692. $this->data ['staff'] = $this->staff;
  3693. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3694. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  3695. }
  3696. /**
  3697. * 办事处人员汇总详情
  3698. */
  3699. function invoiceAggregateStaffDetail() {
  3700. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3701. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  3702. Doo::loadClass ( 'XDeode' );
  3703. $XDeode = new XDeode ( 5 );
  3704. Doo::loadModel ( 'invoice' );
  3705. $invoice = new invoice ();
  3706. Doo::loadModel ( 'staff' );
  3707. $staff = new staff ();
  3708. Doo::loadModel ( "invoiceCategoryManage" );
  3709. $invoiceCategoryManage = new invoiceCategoryManage ();
  3710. $sid = $XDeode->decode ( $sidKey );
  3711. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3712. $cidList = array ();
  3713. foreach ( $imcStaff as $key => $value ) {
  3714. array_push ( $cidList, $value ['cid'] );
  3715. if (empty ( $cidKey ))
  3716. $cidKey = $XDeode->encode ( $value ['cid'] );
  3717. }
  3718. $cidString = implode ( ',', $cidList );
  3719. $staffList = $staff->getStaffInCid ( $cidString );
  3720. $staffDetail = $staff->getStaffBySid ( $sid );
  3721. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3722. $page_size = 18;
  3723. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3724. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3725. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3726. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3727. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3728. $dateArr = explode ( ':', $date );
  3729. $D1 = '';
  3730. $D2 = '';
  3731. if (! empty ( $date )) {
  3732. $D1 = $dateArr [0] . " 00:00:00 ";
  3733. if (isset ( $dateArr [1] ))
  3734. $D2 = $dateArr [1] . " 23:59:59 ";
  3735. else
  3736. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3737. // $D2 = $dateArr [1];
  3738. }
  3739. $con = ' status=2 ';
  3740. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3741. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3742. if ($status == 'UNRECORD')
  3743. $con .= ' and printStatus=1 and untreadStatus=0';
  3744. elseif ($status == 'RECORD')
  3745. $con .= ' and printStatus=1 and untreadStatus=3';
  3746. elseif ($status == 'BOUNCED')
  3747. $con .= ' and untreadStatus=2';
  3748. elseif ($status == 'PARTRECORD')
  3749. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  3750. elseif ($status == 'All') {
  3751. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  3752. }
  3753. $con .= ' and sid=' . $sid;
  3754. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  3755. if (! empty ( $MebSea )) {
  3756. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  3757. }
  3758. $pageinfo ['page'] = array (
  3759. 'previous' => ''
  3760. );
  3761. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  3762. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3763. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  3764. $this->data ['staffDetail'] = $staffDetail;
  3765. $this->data ['staffList'] = $staffList;
  3766. $this->data ['MebSeaEn'] = $MebSea;
  3767. $this->data ['MebSea'] = urlencode ( $MebSea );
  3768. $this->data ['date'] = $date;
  3769. $this->data ['page'] = $pageinfo;
  3770. $this->data ['get'] = $get;
  3771. $this->data ['list'] = $list;
  3772. $this->data ['status'] = $status;
  3773. $this->data ['sidKey'] = $sidKey;
  3774. $this->data ['memu'] = "invoice";
  3775. $this->data ['staff'] = $this->staff;
  3776. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3777. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  3778. }
  3779. /**
  3780. * 办事处人员汇总收款情
  3781. */
  3782. function invoiceAggregateStaffReceivablesDetail() {
  3783. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3784. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3785. Doo::loadModel ( 'invoiceReceivables' );
  3786. $invoiceReceivables = new invoiceReceivables ();
  3787. Doo::loadModel ( 'staff' );
  3788. $staff = new staff ();
  3789. Doo::loadModel ( "invoiceCategoryManage" );
  3790. $invoiceCategoryManage = new invoiceCategoryManage ();
  3791. Doo::loadClass ( 'XDeode' );
  3792. $XDeode = new XDeode ( 5 );
  3793. $sid = $XDeode->decode ( $sidKey );
  3794. $staffDetail = $staff->getStaffBySid ( $sid );
  3795. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3796. $cidList = array ();
  3797. foreach ( $imcStaff as $key => $value ) {
  3798. array_push ( $cidList, $value ['cid'] );
  3799. if (empty ( $cidKey ))
  3800. $cidKey = $XDeode->encode ( $value ['cid'] );
  3801. }
  3802. $cidString = implode ( ',', $cidList );
  3803. $staffList = $staff->getStaffInCid ( $cidString );
  3804. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3805. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  3806. $page_size = 10;
  3807. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3808. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3809. if ($timeType == "BINDOTP") {
  3810. $status = 'Credited';
  3811. }
  3812. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3813. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3814. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3815. $dateArr = explode ( ':', $date );
  3816. $D1 = '';
  3817. $D2 = '';
  3818. if (! empty ( $date )) {
  3819. $D1 = $dateArr [0] . " 00:00:00 ";
  3820. if (isset ( $dateArr [1] ))
  3821. $D2 = $dateArr [1] . " 23:59:59 ";
  3822. else
  3823. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3824. }
  3825. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  3826. $descField = 'a.bindDate';
  3827. if ($timeType == 'CREATE')
  3828. $descField = 'a.date';
  3829. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3830. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3831. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3832. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  3833. if ($status == 'Unclaimed')
  3834. $con .= ' and a.bindStatus=0';
  3835. elseif ($status == 'Credited')
  3836. $con .= ' and a.bindStatus=1';
  3837. elseif ($status == 'Claim')
  3838. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  3839. elseif ($status == 'BBN')
  3840. $con .= ' and a.bindPrice>a.receivablesPrice';
  3841. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  3842. if (! empty ( $MebSea )) {
  3843. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  3844. }
  3845. $pageinfo ['page'] = array (
  3846. 'previous' => ''
  3847. );
  3848. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  3849. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  3850. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  3851. where ' . $con . ' group by a.irid ';
  3852. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  3853. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3854. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  3855. foreach ( $list as $key => $value ) {
  3856. $list [$key] ['category'] = '';
  3857. if ($value ['receivablesCategory'] != 'PUBLIC') {
  3858. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  3859. $list [$key] ['category'] = $receivablesCategory [1];
  3860. }
  3861. }
  3862. // print_r($list);
  3863. $this->data ['staffDetail'] = $staffDetail;
  3864. $this->data ['sidKey'] = $sidKey;
  3865. $this->data ['staffList'] = $staffList;
  3866. $this->data ['timeType'] = $timeType;
  3867. $this->data ['MebSeaEn'] = $MebSea;
  3868. $this->data ['MebSea'] = urlencode ( $MebSea );
  3869. $this->data ['date'] = $date;
  3870. $this->data ['page'] = $pageinfo;
  3871. $this->data ['get'] = $get;
  3872. $this->data ['list'] = $list;
  3873. $this->data ['status'] = $status;
  3874. $this->data ['memu'] = "invoice";
  3875. $this->data ['staff'] = $this->staff;
  3876. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3877. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  3878. }
  3879. function invoiceAchieve() {
  3880. Doo::loadModel ( 'invoice' );
  3881. $invoice = new invoice ();
  3882. Doo::loadClass ( 'XDeode' );
  3883. $XDeode = new XDeode ( 5 );
  3884. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3885. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3886. $page_size = 18;
  3887. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3888. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3889. $get = "/" . $date;
  3890. $con = '';
  3891. if ($date == 'MONTHO')
  3892. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3893. elseif ($date == 'MONTHT')
  3894. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3895. elseif ($date == 'MONTHY')
  3896. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3897. if (! empty ( $MebSea )) {
  3898. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3899. $get .= "/" . $MebSea;
  3900. }
  3901. $pageinfo ['page'] = array (
  3902. 'previous' => ''
  3903. );
  3904. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  3905. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  3906. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3907. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3908. // print_r($pageinfo);
  3909. $this->data ['MebSeaEn'] = $MebSea;
  3910. $this->data ['MebSea'] = urlencode ( $MebSea );
  3911. $this->data ['get'] = $get;
  3912. $this->data ['page'] = $pageinfo;
  3913. $this->data ['list'] = $list;
  3914. $this->data ['date'] = $date;
  3915. $this->data ['memu'] = "invoice";
  3916. $this->data ['staff'] = $this->staff;
  3917. $this->data ['receiptMemu'] = 'invoice';
  3918. $this->render ( "/admin/invoiceAchieve", $this->data );
  3919. }
  3920. function invoiceMyUnAccountAchieve() {
  3921. Doo::loadModel ( 'invoice' );
  3922. $invoice = new invoice ();
  3923. Doo::loadClass ( 'XDeode' );
  3924. $XDeode = new XDeode ( 5 );
  3925. Doo::loadModel ( 'staff' );
  3926. $staff = new staff ();
  3927. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3928. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3929. $page_size = 18;
  3930. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3931. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3932. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3933. $dateArr = explode ( ':', $date );
  3934. $D1 = '';
  3935. $D2 = '';
  3936. if (! empty ( $date )) {
  3937. $D1 = $dateArr [0];
  3938. $D2 = $dateArr [1];
  3939. }
  3940. $con = '';
  3941. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3942. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3943. if (! empty ( $MebSea )) {
  3944. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3945. }
  3946. $pageinfo ['page'] = array (
  3947. 'previous' => ''
  3948. );
  3949. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  3950. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  3951. $action = "invoiceMyUnAccountAchieve";
  3952. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  3953. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3954. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3955. Doo::loadModel ( 'express' );
  3956. $express = new express ();
  3957. $expressList = $express->getExpressByAll ();
  3958. $this->data ['expressList'] = $expressList;
  3959. // print_r($list);
  3960. $this->data ['MebSeaEn'] = $MebSea;
  3961. $this->data ['get'] = $get;
  3962. $this->data ['page'] = $pageinfo;
  3963. $this->data ['date'] = $date;
  3964. $this->data ['list'] = $list;
  3965. $this->data ['memu'] = "invoice";
  3966. $this->data ['staff'] = $this->staff;
  3967. $this->data ['receiptMemu'] = 'invoice';
  3968. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  3969. }
  3970. function invoiceReceivablesAchieve() {
  3971. Doo::loadModel ( 'invoiceReceivables' );
  3972. $invoiceReceivables = new invoiceReceivables ();
  3973. Doo::loadClass ( 'XDeode' );
  3974. $XDeode = new XDeode ( 5 );
  3975. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3976. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3977. $page_size = 12;
  3978. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3979. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3980. $get = "/" . $date;
  3981. $con = '';
  3982. if ($date == 'MONTHO')
  3983. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3984. elseif ($date == 'MONTHT')
  3985. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3986. elseif ($date == 'MONTHY')
  3987. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3988. if (! empty ( $MebSea )) {
  3989. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  3990. $get .= "/" . $MebSea;
  3991. }
  3992. $pageinfo ['page'] = array (
  3993. 'previous' => ''
  3994. );
  3995. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  3996. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  3997. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3998. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  3999. // print_r($pageinfo);
  4000. $this->data ['MebSeaEn'] = $MebSea;
  4001. $this->data ['MebSea'] = urlencode ( $MebSea );
  4002. $this->data ['get'] = $get;
  4003. $this->data ['page'] = $pageinfo;
  4004. $this->data ['list'] = $list;
  4005. $this->data ['date'] = $date;
  4006. $this->data ['memu'] = "invoice";
  4007. $this->data ['staff'] = $this->staff;
  4008. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4009. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4010. }
  4011. /**
  4012. * 收款解绑
  4013. */
  4014. function invoiceUnBundLing() {
  4015. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4016. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4017. Doo::loadModel ( 'invoice' );
  4018. $invoice = new invoice ();
  4019. Doo::loadModel ( 'invoiceReceivables' );
  4020. $invoiceReceivables = new invoiceReceivables ();
  4021. Doo::loadModel ( 'invoiceOperationLog' );
  4022. $invoiceOperationLog = new invoiceOperationLog ();
  4023. Doo::loadModel ( 'invoiceROLog' );
  4024. $invoiceROLog = new invoiceROLog ();
  4025. Doo::loadModel ( 'invoiceStatistics' );
  4026. Doo::loadClass ( 'XDeode' );
  4027. $XDeode = new XDeode ( 5 );
  4028. if (empty ( $iidKey ))
  4029. die ( 'illegal request' );
  4030. $iid = $XDeode->decode ( $iidKey );
  4031. $irid = $invoice->authcode ( $unBundKey );
  4032. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4033. die ( 'illegal request' );
  4034. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4035. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4036. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4037. die ( 'illegal request' );
  4038. // 收款
  4039. $item = array (
  4040. 'irid' => $irDetails ['irid'],
  4041. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4042. 'bindStatus' => 0
  4043. );
  4044. if ($irDetails ['iid'] == $iid)
  4045. $item += array (
  4046. 'iid' => 0
  4047. );
  4048. else {
  4049. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4050. foreach ( $iidExtend as $key => $value ) {
  4051. if ($value == $iid)
  4052. unset ( $iidExtend [$key] );
  4053. }
  4054. $iidExtend = implode ( ',', $iidExtend );
  4055. $item += array (
  4056. 'iidExtend' => $iidExtend
  4057. );
  4058. }
  4059. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4060. // 收款操作日志
  4061. $item = array (
  4062. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4063. 'date' => date ( "Y-m-d" ),
  4064. 'status' => 3,
  4065. 'img' => $this->staff [0] ['avatar'],
  4066. 'username' => $this->staff [0] ['username'],
  4067. 'uid' => $this->staff [0] ['sid'],
  4068. 'category' => $this->staff [0] ['category'],
  4069. 'irid' => $irid
  4070. );
  4071. $invoiceROLog->setInvoiceROLog ( $item );
  4072. // 扣除入账统计金额
  4073. $invoiceStatistics = new invoiceStatistics ();
  4074. $item = array (
  4075. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4076. 'priceClass' => 3,
  4077. 'cid' => $invoiceDetails ['cid'],
  4078. 'staff' => $invoiceDetails ['sid'],
  4079. 'accountPrice' => - $irDetails ['receivablesPrice']
  4080. );
  4081. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4082. // 扣除收款统计金额
  4083. $invoiceStatistics = new invoiceStatistics ();
  4084. $item = array (
  4085. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4086. 'priceClass' => 2,
  4087. 'cid' => $invoiceDetails ['cid'],
  4088. 'staff' => $invoiceDetails ['sid'],
  4089. 'irid' => $irDetails ['irid'],
  4090. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4091. );
  4092. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4093. // 发票解绑去收款ID
  4094. $iridString = $invoiceDetails ['irid'];
  4095. if (! empty ( $invoiceDetails ['irid'] )) {
  4096. $list = explode ( ',', $invoiceDetails ['irid'] );
  4097. foreach ( $list as $key => $value ) {
  4098. if ($value == $irDetails ['irid']) {
  4099. unset ( $list [$key] );
  4100. break;
  4101. }
  4102. }
  4103. $iridString = implode ( ",", $list );
  4104. }
  4105. $item = array (
  4106. 'iid' => $invoiceDetails ['iid'],
  4107. 'irid' => $iridString,
  4108. 'updateTime' => date ( "Y-m-d H:i:s" )
  4109. );
  4110. if ($invoiceDetails ['untreadStatus'] == 3)
  4111. $item += array (
  4112. 'untreadStatus' => 0
  4113. );
  4114. $invoice->setInvoiceByCondition ( $item );
  4115. $item = array (
  4116. 'date' => date ( "Y-m-d H:i:s" ),
  4117. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4118. 'status' => 11,
  4119. 'img' => $this->staff [0] ['avatar'],
  4120. 'username' => $this->staff [0] ['username'],
  4121. 'uid' => $this->staff [0] ['sid'],
  4122. 'category' => $this->staff [0] ['category'],
  4123. 'iid' => $invoiceDetails ['iid']
  4124. );
  4125. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4126. return "/invoiceReceivablesAS";
  4127. }
  4128. /**
  4129. * 或者该收款下的所以发票
  4130. */
  4131. function ajaxGetInvoiceReceivablesByInvoice() {
  4132. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4133. Doo::loadModel ( 'invoice' );
  4134. $invoice = new invoice ();
  4135. Doo::loadModel ( 'invoiceReceivables' );
  4136. $invoiceReceivables = new invoiceReceivables ();
  4137. $irid = $invoice->authcode ( $irid );
  4138. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4139. die ( 'illegal request' );
  4140. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4141. $iidString = $irDetails ['iid'];
  4142. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4143. if (! empty ( $irDetails ['iidExtend'] ))
  4144. $iidString .= ',' . implode ( ',', $iidExtend );
  4145. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4146. $html = "";
  4147. foreach ( $invoiceList as $key => $value ) {
  4148. $title = $value ['invoiceTitle'];
  4149. if (! empty ( $value ['invoiceCompany'] ))
  4150. $title = $value ['invoiceCompany'];
  4151. $html .= '<tr><td>' . $value ['invoiceSerial'] . '</td><td>¥' . $value ['invoicePrice'] . '</td><td>' . $title . '</td><td>' . $value ['invoiceElement'] . '</td><td><input type="radio" name="iidKey" value="' . $value ['iidKey'] . '"></td></tr>';
  4152. }
  4153. echo json_encode ( array (
  4154. 'status' => 1,
  4155. 'html' => $html
  4156. ) );
  4157. }
  4158. /**
  4159. * 发票管理
  4160. */
  4161. function invoiceAS() {
  4162. Doo::loadModel ( 'invoice' );
  4163. $invoice = new invoice ();
  4164. Doo::loadModel ( 'invoiceReceivables' );
  4165. $invoiceReceivables = new invoiceReceivables ();
  4166. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4167. $page_size = 18;
  4168. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4169. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4170. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4171. $dateArr = explode ( ':', $date );
  4172. $D1 = '';
  4173. $D2 = '';
  4174. if (! empty ( $date )) {
  4175. $D1 = $dateArr [0] . " 00:00:00 ";
  4176. if (isset ( $dateArr [1] ))
  4177. $D2 = $dateArr [1] . " 23:59:59 ";
  4178. else
  4179. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4180. // $D2 = $dateArr [1];
  4181. }
  4182. $con = ' status=2 ';
  4183. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4184. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4185. if ($status == 'UNRECORD')
  4186. $con .= ' and printStatus=1 and untreadStatus=0';
  4187. elseif ($status == 'RECORD')
  4188. $con .= ' and printStatus=1 and untreadStatus=3';
  4189. elseif ($status == 'BOUNCED')
  4190. $con .= ' and untreadStatus=2';
  4191. elseif ($status == 'PARTRECORD')
  4192. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4193. elseif ($status == 'All') {
  4194. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4195. }
  4196. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4197. if (! empty ( $MebSea )) {
  4198. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4199. }
  4200. $pageinfo ['page'] = array (
  4201. 'previous' => ''
  4202. );
  4203. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4204. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4205. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4206. $this->data ['MebSeaEn'] = $MebSea;
  4207. $this->data ['MebSea'] = urlencode ( $MebSea );
  4208. $this->data ['date'] = $date;
  4209. $this->data ['page'] = $pageinfo;
  4210. $this->data ['get'] = $get;
  4211. $this->data ['list'] = $list;
  4212. $this->data ['status'] = $status;
  4213. $this->data ['memu'] = "invoice";
  4214. $this->data ['staff'] = $this->staff;
  4215. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4216. $this->render ( "/admin/invoiceAS", $this->data );
  4217. }
  4218. /**
  4219. * 收款管理
  4220. */
  4221. function invoiceReceivablesAS() {
  4222. Doo::loadModel ( 'invoiceReceivables' );
  4223. $invoiceReceivables = new invoiceReceivables ();
  4224. Doo::loadModel ( 'L_category' );
  4225. $lCategory = new L_category ();
  4226. $category = $lCategory->getCategory ();
  4227. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4228. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4229. $page_size = 10;
  4230. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4231. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4232. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4233. $dateArr = explode ( ':', $date );
  4234. $D1 = '';
  4235. $D2 = '';
  4236. if (! empty ( $date )) {
  4237. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4238. if (isset ( $dateArr [1] ))
  4239. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4240. else
  4241. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4242. }
  4243. $descField = 'a.receivablesDate';
  4244. if ($timeType == 'CREATE')
  4245. $descField = 'a.date';
  4246. $con = '1';
  4247. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4248. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4249. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4250. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4251. if ($status == 'Unclaimed')
  4252. $con .= ' and a.bindStatus=0';
  4253. elseif ($status == 'Credited')
  4254. $con .= ' and a.bindStatus=1';
  4255. elseif ($status == 'Claim')
  4256. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4257. elseif ($status == 'BBN')
  4258. $con .= ' and a.bankBatchNumber!=""';
  4259. elseif ($status == 'REFUND')
  4260. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4261. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4262. if (! empty ( $MebSea )) {
  4263. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4264. }
  4265. $pageinfo ['page'] = array (
  4266. 'previous' => ''
  4267. );
  4268. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4269. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4270. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4271. where ' . $con . ' group by a.irid ';
  4272. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4273. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4274. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4275. foreach ( $list as $key => $value ) {
  4276. $list [$key] ['category'] = '';
  4277. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4278. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4279. $list [$key] ['category'] = $receivablesCategory [1];
  4280. }
  4281. }
  4282. // print_r($list);
  4283. $this->data ['category'] = $category;
  4284. $this->data ['timeType'] = $timeType;
  4285. $this->data ['MebSeaEn'] = $MebSea;
  4286. $this->data ['MebSea'] = urlencode ( $MebSea );
  4287. $this->data ['date'] = $date;
  4288. $this->data ['page'] = $pageinfo;
  4289. $this->data ['get'] = $get;
  4290. $this->data ['list'] = $list;
  4291. $this->data ['status'] = $status;
  4292. $this->data ['memu'] = "invoice";
  4293. $this->data ['staff'] = $this->staff;
  4294. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4295. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4296. }
  4297. /**
  4298. * 删除一条收款
  4299. */
  4300. function delInvoiceReceivables() {
  4301. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4302. if (empty ( $iridKey ))
  4303. die ( 'illegal request' );
  4304. Doo::loadClass ( 'XDeode' );
  4305. $XDeode = new XDeode ( 5 );
  4306. $irid = $XDeode->decode ( $iridKey );
  4307. Doo::loadModel ( 'invoiceReceivables' );
  4308. $invoiceReceivables = new invoiceReceivables ();
  4309. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4310. if (empty ( $detail ))
  4311. die ( 'illegal request' );
  4312. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4313. //扣除收款汇总信息 汇总
  4314. Doo::loadModel ( 'invoiceStatistics' );
  4315. $invoiceStatistics = new invoiceStatistics ();
  4316. $item = array (
  4317. 'date' => $detail['receivablesDate'],
  4318. 'priceClass' => 2,
  4319. 'irid' => $detail['irid'],
  4320. 'receivablesPrice' => -$detail['receivablesPrice']
  4321. );
  4322. if ($detail['receivablesCategory'] != 'PUBLIC') {
  4323. $receivablesCategory = explode ( ":", $detail['receivablesCategory'] );
  4324. $item += array (
  4325. 'cid' => $receivablesCategory [0]
  4326. );
  4327. }
  4328. if ($detail['receivablesStaff'] != 'PUBLIC') {
  4329. $receivablesStaff = explode ( "-", $detail['receivablesStaff'] );
  4330. $item += array (
  4331. 'staff' => $receivablesStaff [0]
  4332. );
  4333. }
  4334. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4335. return '/invoiceReceivablesAS';
  4336. }
  4337. /**
  4338. * 添加退款信息
  4339. */
  4340. function setInvoiceReceivablesRefund() {
  4341. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4342. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4343. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4344. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4345. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4346. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4347. if($refundPrice<0)
  4348. die ( 'illegal request' );
  4349. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4350. Doo::loadModel ( 'invoiceReceivables' );
  4351. $invoiceReceivables = new invoiceReceivables ();
  4352. Doo::loadModel ( 'invoiceRefund' );
  4353. $invoiceRefund = new invoiceRefund ();
  4354. $irid = $invoiceReceivables->authcode ( $iridKey );
  4355. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4356. if($irDetail ['receivablesPrice'] < $refundPrice)
  4357. die ( 'illegal request' );
  4358. $invoiceReceivables = new invoiceReceivables ();
  4359. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4360. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4361. ';
  4362. $item = array (
  4363. 'irid' => $irid,
  4364. 'refundCompany' => $refundCompany,
  4365. 'refundNumber' => $refundNumber,
  4366. 'refundPrice' => $refundPrice,
  4367. 'refundRemarks' =>$refundRemarks,
  4368. 'refundLog' => $refundLog
  4369. );
  4370. if ($refundType == 1) {
  4371. $item += array (
  4372. 'refundType' => $refundType,
  4373. 'receivablesPrice' => $irDetail ['receivablesPrice'] -$refundPrice,
  4374. 'bindStatus' => 2
  4375. );
  4376. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4377. $item += array (
  4378. 'refundType' => 1,
  4379. 'receivablesPrice' => $irDetail ['receivablesPrice'] -$refundPrice,
  4380. 'bindStatus' => 2
  4381. );
  4382. } else {
  4383. $item += array (
  4384. 'refundType' => $refundType,
  4385. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4386. );
  4387. }
  4388. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4389. // 添加退款记录
  4390. $item = array (
  4391. 'irid' => $irid,
  4392. 'refundType' => $refundType,
  4393. 'refundCompany' => $refundCompany,
  4394. 'refundNumber' => $refundNumber,
  4395. 'refundPrice' => $refundPrice,
  4396. 'refundLog' => $refundLog,
  4397. 'refundRemarks'=>$refundRemarks,
  4398. 'date' => date ( "Y-m-d H:i:s" )
  4399. );
  4400. $invoiceRefund->addInvoiceRefund ( $item );
  4401. //扣除收款汇总信息 汇总
  4402. Doo::loadModel ( 'invoiceStatistics' );
  4403. $invoiceStatistics = new invoiceStatistics ();
  4404. $item = array (
  4405. 'date' => $irDetail['receivablesDate'],
  4406. 'priceClass' => 2,
  4407. 'irid' => $irDetail['irid'],
  4408. 'receivablesPrice' => -$refundPrice
  4409. );
  4410. if ($irDetail['receivablesCategory'] != 'PUBLIC') {
  4411. $receivablesCategory = explode ( ":", $irDetail['receivablesCategory'] );
  4412. $item += array (
  4413. 'cid' => $receivablesCategory [0]
  4414. );
  4415. }
  4416. if ($irDetail['receivablesStaff'] != 'PUBLIC') {
  4417. $receivablesStaff = explode ( "-", $irDetail['receivablesStaff'] );
  4418. $item += array (
  4419. 'staff' => $receivablesStaff [0]
  4420. );
  4421. }
  4422. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4423. return '/invoiceReceivablesAS';
  4424. }
  4425. die ( 'illegal request' );
  4426. }
  4427. function ajaxCheckInvoiceReceivablesRefund(){
  4428. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4429. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4430. if($refundPrice<0){
  4431. echo json_encode ( array (
  4432. 'error' => '金额不能为负'
  4433. ) );
  4434. die ();
  4435. }
  4436. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4437. Doo::loadModel ( 'invoiceReceivables' );
  4438. $invoiceReceivables = new invoiceReceivables ();
  4439. $irid = $invoiceReceivables->authcode ( $iridKey );
  4440. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4441. if($irDetail ['receivablesPrice'] < $refundPrice){
  4442. echo json_encode ( array (
  4443. 'error' => '退款金额不能超过收款金额'
  4444. ) );
  4445. die ();
  4446. }
  4447. echo json_encode ( array (
  4448. 'ok' => '可以使用!'
  4449. ) );
  4450. die ();
  4451. }
  4452. }
  4453. /**
  4454. * 获得收款退款信息
  4455. */
  4456. function getRefundByDetail() {
  4457. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4458. Doo::loadModel ( 'invoiceReceivables' );
  4459. $invoiceReceivables = new invoiceReceivables ();
  4460. if (! empty ( $iridKey )) {
  4461. $irid = $invoiceReceivables->authcode ( $iridKey );
  4462. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4463. echo json_encode ( array (
  4464. 'status' => 1,
  4465. 'irDetail' => $irDetail
  4466. ) );
  4467. die ();
  4468. }
  4469. echo json_encode ( array (
  4470. 'status' => 2
  4471. ) );
  4472. }
  4473. /**
  4474. * 根据收款序列号获得收款退款信息
  4475. */
  4476. function ajaxGetInvoiceReceivablesBySerial() {
  4477. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  4478. if (! empty ( $receivablesSerial )) {
  4479. Doo::loadModel ( 'invoiceReceivables' );
  4480. $invoiceReceivables = new invoiceReceivables ();
  4481. //, ' and refundLog=""'
  4482. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  4483. $html = '';
  4484. if (! empty ( $irDetail ))
  4485. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  4486. <td>' . $irDetail ['receivablesMessage'] . '</td>
  4487. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  4488. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  4489. <td>' . $irDetail ['recepitTitleMark'] . '
  4490. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  4491. </td>';
  4492. echo json_encode ( array (
  4493. 'status' => 1,
  4494. 'html' => $html,
  4495. 'irDetail' => $irDetail
  4496. ) );
  4497. die ();
  4498. }
  4499. echo json_encode ( array (
  4500. 'status' => 2
  4501. ) );
  4502. }
  4503. /**
  4504. * 绑定新收款
  4505. */
  4506. function relationNewInvoiceReceivables() {
  4507. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  4508. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4509. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  4510. Doo::loadModel ( 'invoiceReceivables' );
  4511. $invoiceReceivables = new invoiceReceivables ();
  4512. Doo::loadClass ( 'XDeode' );
  4513. $XDeode = new XDeode ( 5 );
  4514. $irid = $XDeode->decode ( $iridKey );
  4515. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  4516. echo $irid . 'bbb' . $iridOld;
  4517. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  4518. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4519. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  4520. die ( 'illegal request' );
  4521. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  4522. <br/>' . date ( "Y-m-d H:i:s" ) . '
  4523. ';
  4524. $invoiceReceivables = new invoiceReceivables ();
  4525. $item = array (
  4526. 'irid' => $iridOld,
  4527. 'relationIrid' => $irid,
  4528. 'relationLog' => $relationLog
  4529. );
  4530. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4531. return '/invoiceReceivablesAS';
  4532. }
  4533. die ( 'illegal request' );
  4534. }
  4535. // function invoiceApprovalAchieve() {
  4536. // Doo::loadModel ( 'invoice' );
  4537. // $invoice = new invoice ();
  4538. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4539. // $page_size = 12;
  4540. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4541. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4542. // $get = "/" . $date;
  4543. // $con = '';
  4544. // if ($date == 'MONTHO')
  4545. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4546. // elseif ($date == 'MONTHT')
  4547. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4548. // elseif ($date == 'MONTHY')
  4549. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4550. // if (! empty ( $MebSea )) {
  4551. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4552. // $get .= "/" . $MebSea;
  4553. // }
  4554. // $pageinfo ['page'] = array (
  4555. // 'previous' => ''
  4556. // );
  4557. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  4558. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4559. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  4560. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4561. // // print_r($list);
  4562. // $this->data ['MebSeaEn'] = $MebSea;
  4563. // $this->data ['MebSea'] = urlencode ( $MebSea );
  4564. // $this->data ['get'] = $get;
  4565. // $this->data ['page'] = $pageinfo;
  4566. // $this->data ['list'] = $list;
  4567. // $this->data ['date'] = $date;
  4568. // $this->data ['memu'] = "invoice";
  4569. // $this->data ['staff'] = $this->staff;
  4570. // $this->data ['receiptMemu'] = 'invoiceApproval';
  4571. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4572. // }
  4573. /**
  4574. * 获得审批发票的信息以及审批页面
  4575. */
  4576. function ajaxGetInvoiceApprovalDetail() {
  4577. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4578. if (empty ( $serial )) {
  4579. echo json_encode ( array (
  4580. 'status' => 2,
  4581. 'msg' => 'illegal request'
  4582. ) );
  4583. die ();
  4584. }
  4585. Doo::loadModel ( 'invoice' );
  4586. $invoice = new invoice ();
  4587. Doo::loadModel ( 'invoiceOperationLog' );
  4588. $invoiceOperationLog = new invoiceOperationLog ();
  4589. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4590. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4591. if (empty ( $detail ))
  4592. $html = '';
  4593. else {
  4594. $html = '
  4595. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  4596. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4597. <input type="hidden" name="status" value="">
  4598. <input type="hidden" name="divApproval" value="divApproval">
  4599. <div class="modal-dialog modal-lg">
  4600. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  4601. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4602. <tr>
  4603. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  4604. </tr>
  4605. <tr>
  4606. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4607. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4608. </tr>
  4609. <tr>
  4610. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4611. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4612. </tr>
  4613. <tr>
  4614. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4615. </td>
  4616. </tr>
  4617. <tr>
  4618. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4619. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4620. </tr>
  4621. <tr>
  4622. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4623. </tr></tbody></table>';
  4624. if ($detail ['invoiceType'] == 0)
  4625. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4626. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4627. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4628. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4629. </tr>';
  4630. else
  4631. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4632. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4633. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4634. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4635. ';
  4636. $html .= '<tr>
  4637. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4638. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4639. </tr>
  4640. <tr>
  4641. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4642. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4643. </tr></tbody></table>';
  4644. if ($detail ['doPost'] == 1) {
  4645. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4646. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4647. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4648. </tr><tr>
  4649. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4650. </tr><tr>
  4651. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4652. </tr>
  4653. ';
  4654. if ($detail ['expressCom'] == 'SF')
  4655. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="http://www.sf-express.com/cn/sc/dynamic_function/waybill/#search/bill-number/">' . $detail ['expressNumber'] . '</a> </td></tr>';
  4656. else
  4657. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="/invoiceExpress/' . $detail ['expressCom'] . '/' . $detail ['expressNumber'] . '.html">' . $detail ['expressNumber'] . '</a> </td></tr>';
  4658. $html .= '</tbody></table>';
  4659. }
  4660. if (! empty ( $invoiceOperationLogList )) {
  4661. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4662. foreach ( $invoiceOperationLogList as $key => $value ) {
  4663. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4664. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4665. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4666. if ($value ['status'] == 2) {
  4667. $html .= '<span class="colGreen">同意</span>';
  4668. } elseif ($value ['status'] == 3) {
  4669. $html .= '<span class="colOrange">退回</span>';
  4670. } elseif ($value ['status'] == 5) {
  4671. $html .= '<span class="colGreen">打印</span>';
  4672. } elseif ($value ['status'] == 4) {
  4673. $html .= '<span class="colRed">终止</span>';
  4674. }
  4675. $html .= $value ['operation'] . '</p></blockquote>';
  4676. }
  4677. }
  4678. $html .= '</td></tr></tbody></table>';
  4679. }
  4680. $html .= '</div><div class="modal-footer">
  4681. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  4682. <a href="javascript:void(0)" node-approval="approval" diss-data="3" class="button btn-back" data-placement="top" data-toggle="ctooltip" data-original-title="上报人修改后重新审批">退回</a>
  4683. <a href="javascript:void(0)" node-approval="approval" diss-data="4" class="button btn-undone" data-placement="top" data-toggle="ctooltip" data-original-title="终止发票申请">终止</a>
  4684. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  4685. </form>
  4686. <script type="text/javascript">
  4687. $("a[node-approval^=\'approval\']").click(function() {
  4688. $("input[name=\'status\']").val($(this).attr("diss-data"));
  4689. $("form[name=\'invoiceApproval\']").submit();
  4690. });
  4691. </script>
  4692. ';
  4693. }
  4694. echo json_encode ( array (
  4695. 'status' => 1,
  4696. 'html' => $html
  4697. ) );
  4698. die ();
  4699. }
  4700. /**
  4701. * 获得审批发票分页数据
  4702. */
  4703. function ajaxGetinvoiceApprovalAchieve() {
  4704. Doo::loadModel ( 'invoice' );
  4705. $invoice = new invoice ();
  4706. Doo::loadModel ( 'staff' );
  4707. $staff = new staff ();
  4708. Doo::loadClass ( 'XDeode' );
  4709. $XDeode = new XDeode ( 5 );
  4710. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  4711. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4712. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4713. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4714. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4715. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  4716. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  4717. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  4718. $MebSea = $this->get_args ( 'search' );
  4719. $MebSea = $MebSea ['value'];
  4720. $page_size = $length;
  4721. $con = '';
  4722. if ($status == 'ALL')
  4723. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  4724. elseif ($status == 'PEND')
  4725. $con = ' isDelete=0 and status=1';
  4726. elseif ($status == 'APPROVED')
  4727. $con = ' isDelete=0 and status=2';
  4728. if ($invoiceType == 'ORDINARY')
  4729. $con .= ' and invoiceType=0 ';
  4730. elseif ($invoiceType == 'SPECIAL')
  4731. $con .= ' and invoiceType=1 ';
  4732. if ($invoiceTrain == 'ORDINARY')
  4733. $con .= ' and trainId=0 ';
  4734. elseif ($invoiceTrain == 'TRAIN')
  4735. $con .= ' and trainId!=0 ';
  4736. if ($invoiceTrainName != 'ALL') {
  4737. $trainId = $XDeode->decode ( $invoiceTrainName );
  4738. if (is_numeric ( $trainId ))
  4739. $con .= ' and trainId =' . $trainId;
  4740. }
  4741. $dateArr = explode ( ':', $date );
  4742. $D1 = $dateString = '';
  4743. $D2 = '';
  4744. if (! empty ( $date )) {
  4745. $D1 = $dateArr [0];
  4746. if (isset ( $dateArr [1] ))
  4747. $D2 = $dateArr [1];
  4748. else
  4749. $D2 = '';
  4750. $dateString = $D1 . " : " . $D2;
  4751. }
  4752. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4753. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4754. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4755. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  4756. if (! empty ( $MebSea ))
  4757. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  4758. // /
  4759. $pageinfo ['page'] = array (
  4760. 'previous' => ''
  4761. );
  4762. $sql = ' ' . $con;
  4763. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  4764. $limit = $page . ',' . $page_size;
  4765. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4766. $approvalList = array ();
  4767. $html = '
  4768. <script type="text/javascript">
  4769. </script>
  4770. ';
  4771. foreach ( $list as $key => $value ) {
  4772. $irDetail = array ();
  4773. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  4774. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  4775. } else
  4776. array_push ( $irDetail, '' );
  4777. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  4778. if ($value ['invoiceType'] == 1)
  4779. array_push ( $irDetail, $value ['invoiceCompany'] );
  4780. else
  4781. array_push ( $irDetail, $value ['invoiceTitle'] );
  4782. array_push ( $irDetail, $value ['TIN'] );
  4783. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  4784. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  4785. array_push ( $irDetail, $value ['remark'] );
  4786. array_push ( $irDetail, $value ['invoiceElement'] );
  4787. array_push ( $irDetail, $value ['invoiceQuantity'] );
  4788. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  4789. if ($value ['invoiceType'] == 1)
  4790. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  4791. else
  4792. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  4793. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  4794. array_push ( $irDetail, $value ['recipientsAddress'] );
  4795. array_push ( $irDetail, $value ['mailItems'] );
  4796. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  4797. $fchtml = $value ['OL'] ['operation'];
  4798. if (count ( $list ) == $page_size)
  4799. $fchtml = $value ['OL'] ['operation'] . $html;
  4800. // 最后的审批意见
  4801. array_push ( $irDetail, $fchtml );
  4802. if ($value ['status'] == 2)
  4803. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4804. elseif ($value ['status'] == 3)
  4805. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4806. elseif ($value ['status'] == 4)
  4807. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4808. else
  4809. array_push ( $irDetail, '' );
  4810. array_push ( $approvalList, $irDetail );
  4811. }
  4812. // $approvalListJson = json_encode ( $approvalList );
  4813. $recordsFiltered = $pageinfo ['total_data'];
  4814. echo json_encode ( array (
  4815. "draw" => intval ( $draw ),
  4816. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  4817. "recordsFiltered" => intval ( $recordsFiltered ),
  4818. "data" => $approvalList
  4819. ), JSON_UNESCAPED_UNICODE );
  4820. }
  4821. /**
  4822. * 审批发票查看更多--重构
  4823. */
  4824. function invoiceApprovalAchieve() {
  4825. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  4826. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4827. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4828. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4829. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4830. Doo::loadModel ( 'invoiceTraining' );
  4831. $invoiceTraining = new invoiceTraining ();
  4832. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  4833. $this->data ['trainList'] = $trainList;
  4834. $this->data ['dateString'] = $date;
  4835. $this->data ['status'] = $status;
  4836. $this->data ['invoiceType'] = $invoiceType;
  4837. $this->data ['invoiceTrain'] = $invoiceTrain;
  4838. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  4839. $this->data ['memu'] = "invoice";
  4840. $this->data ['staff'] = $this->staff;
  4841. $this->data ['receiptMemu'] = 'invoiceApproval';
  4842. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4843. }
  4844. function invoiceTAchieve() {
  4845. Doo::loadModel ( 'invoice' );
  4846. $invoice = new invoice ();
  4847. Doo::loadClass ( 'XDeode' );
  4848. $XDeode = new XDeode ( 5 );
  4849. Doo::loadModel ( 'staff' );
  4850. $staff = new staff ();
  4851. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4852. $page_size = 12;
  4853. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4854. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4855. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4856. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4857. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4858. Doo::loadModel ( 'invoiceTraining' );
  4859. $invoiceTraining = new invoiceTraining ();
  4860. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  4861. $get = "/" . $date;
  4862. $con = '';
  4863. if ($date == 'MONTHO')
  4864. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4865. elseif ($date == 'MONTHT')
  4866. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4867. elseif ($date == 'MONTHY')
  4868. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4869. if ($invoiceType == 'ORDINARY')
  4870. $con .= ' and invoiceType=0 ';
  4871. elseif ($invoiceType == 'SPECIAL')
  4872. $con .= ' and invoiceType=1 ';
  4873. if ($invoiceTrain == 'ORDINARY')
  4874. $con .= ' and trainId=0 ';
  4875. elseif ($invoiceTrain == 'TRAIN')
  4876. $con .= ' and trainId!=0 ';
  4877. if ($invoiceTrainName != 'ALL') {
  4878. $trainId = $XDeode->decode ( $invoiceTrainName );
  4879. if (is_numeric ( $trainId ))
  4880. $con .= ' and trainId =' . $trainId;
  4881. }
  4882. if (! empty ( $MebSea )) {
  4883. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4884. $get .= "/" . $MebSea;
  4885. }
  4886. $pageinfo ['page'] = array (
  4887. 'previous' => ''
  4888. );
  4889. $sql = "";
  4890. $action = "";
  4891. if ($this->ACTION == 'invoicePrintAchieve') {
  4892. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  4893. $action = "invoicePrintAchieve";
  4894. } elseif ($this->ACTION == 'invoicePostAchieve') {
  4895. // and untreadStatus=0
  4896. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  4897. $action = "invoicePostAchieve";
  4898. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  4899. $sql = " untreadStatus=2 and status=2 " . $con;
  4900. $action = "invoiceUntreadAchieve";
  4901. }
  4902. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4903. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4904. $this->data ['MebSeaEn'] = $MebSea;
  4905. $this->data ['MebSea'] = urlencode ( $MebSea );
  4906. $this->data ['get'] = $get;
  4907. $this->data ['page'] = $pageinfo;
  4908. $this->data ['trainList'] = $trainList;
  4909. $this->data ['invoiceType'] = $invoiceType;
  4910. $this->data ['invoiceTrain'] = $invoiceTrain;
  4911. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  4912. $this->data ['date'] = $date;
  4913. $this->data ['memu'] = "invoice";
  4914. $this->data ['staff'] = $this->staff;
  4915. if ($this->ACTION == 'invoicePrintAchieve') {
  4916. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  4917. $this->data ['receiptMemu'] = 'invoicePrint';
  4918. $this->data ['list'] = $list;
  4919. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  4920. } elseif ($this->ACTION == 'invoicePostAchieve') {
  4921. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4922. Doo::loadModel ( 'express' );
  4923. $express = new express ();
  4924. $expressList = $express->getExpressByAll ();
  4925. $this->data ['expressList'] = $expressList;
  4926. $this->data ['receiptMemu'] = 'invoicePost';
  4927. $this->data ['list'] = $list;
  4928. $this->render ( "/admin/invoicePostAchieve", $this->data );
  4929. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  4930. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4931. $this->data ['receiptMemu'] = 'invoiceUntread';
  4932. $this->data ['list'] = $list;
  4933. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  4934. }
  4935. }
  4936. /**
  4937. * 公司应收款
  4938. */
  4939. function invoiceAggregateCompanyDetail() {
  4940. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4941. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4942. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  4943. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4944. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  4945. Doo::loadClass ( 'XDeode' );
  4946. $XDeode = new XDeode ( 5 );
  4947. Doo::loadModel ( 'invoice' );
  4948. $invoice = new invoice ();
  4949. Doo::loadModel ( 'staff' );
  4950. $staff = new staff ();
  4951. Doo::loadModel ( "invoiceCompanyManage" );
  4952. $invoiceCompanyManage = new invoiceCompanyManage ();
  4953. Doo::loadModel ( 'L_category' );
  4954. $category = new L_category ();
  4955. $sid = '';
  4956. if (! empty ( $sidKey ))
  4957. $sid = $XDeode->decode ( $sidKey );
  4958. $staffDetail = $staff->getStaffBySid ( $sid );
  4959. $cid = '';
  4960. if (! empty ( $cidKey ))
  4961. $cid = $XDeode->decode ( $cidKey );
  4962. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4963. $cidList = array ();
  4964. foreach ( $imcStaff as $key => $value ) {
  4965. array_push ( $cidList, $value ['cid'] );
  4966. }
  4967. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4968. $cidString = implode ( ',', $cidList );
  4969. if (empty ( $cid ))
  4970. $staffList = $staff->getStaffInCid ( $cidString );
  4971. else
  4972. $staffList = $staff->getStaffByCid ( $cid ); //
  4973. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4974. $page_size = 25;
  4975. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4976. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4977. $con = ' status=2 and untreadStatus!=2 ';
  4978. $statisticsCon = '';
  4979. if (! empty ( $year ) && is_numeric ( $year ))
  4980. $con .= ' and Year(printTime)=' . $year . '';
  4981. if (! empty ( $month ) && is_numeric ( $month ))
  4982. $con .= ' and Month(printTime)="' . $month . '" ';
  4983. if ($status == 'UNRECORD')
  4984. $con .= ' and printStatus=1 and untreadStatus=0';
  4985. elseif ($status == 'RECORD')
  4986. $con .= ' and printStatus=1 and untreadStatus=3';
  4987. elseif ($status == 'BOUNCED')
  4988. $con .= ' and untreadStatus=2';
  4989. elseif ($status == 'PARTRECORD')
  4990. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4991. elseif ($status == 'All') {
  4992. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  4993. }
  4994. if (! empty ( $sid ) && is_numeric ( $sid ))
  4995. $con .= ' and sid=' . $sid;
  4996. if (! empty ( $cid ) && is_numeric ( $cid ))
  4997. $con .= ' and cid=' . $cid;
  4998. else
  4999. $con .= ' and cid in (' . $cidString . ')';
  5000. // 开票内容筛选
  5001. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5002. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5003. }
  5004. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5005. if (! empty ( $MebSea )) {
  5006. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5007. }
  5008. $pageinfo ['page'] = array (
  5009. 'previous' => ''
  5010. );
  5011. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5012. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5013. // 应收款合计
  5014. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5015. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5016. $monthHtml = "";
  5017. if ($year != "ALL") {
  5018. for($i = 1; $i <= 12; $i ++) {
  5019. if ($i == $month)
  5020. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5021. else
  5022. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5023. }
  5024. }
  5025. $this->data ['monthHtml'] = $monthHtml;
  5026. $this->data ['year'] = $year;
  5027. $this->data ['month'] = $month;
  5028. $this->data ['ics'] = $ics;
  5029. $this->data ['cidKey'] = $cidKey;
  5030. $this->data ['sid'] = $sid;
  5031. $this->data ['staffDetail'] = $staffDetail;
  5032. $this->data ['staffList'] = $staffList;
  5033. $this->data ['MebSeaEn'] = $MebSea;
  5034. $this->data ['MebSea'] = urlencode ( $MebSea );
  5035. $this->data ['invoiceDetail'] = array (
  5036. 'invoiceElement' => $invoiceElement
  5037. );
  5038. $this->data ['page'] = $pageinfo;
  5039. $this->data ['get'] = $get;
  5040. $this->data ['list'] = $list;
  5041. $this->data ['status'] = $status;
  5042. $this->data ['categoryList'] = $categoryList;
  5043. $this->data ['memu'] = "invoice";
  5044. $this->data ['staff'] = $this->staff;
  5045. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5046. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5047. }
  5048. /**
  5049. * 获取一条收款信息
  5050. */
  5051. function ajaxGetInvoiceReceivables() {
  5052. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5053. Doo::loadModel ( 'invoiceReceivables' );
  5054. $invoiceReceivables = new invoiceReceivables ();
  5055. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5056. echo json_encode ( array (
  5057. 'status' => 1,
  5058. 'detail' => $detail
  5059. ) );
  5060. }
  5061. /**
  5062. * 异步获取办事处用户
  5063. */
  5064. function ajaxGetStaffByCategory() {
  5065. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5066. Doo::loadModel ( 'staff' );
  5067. $staff = new staff ();
  5068. if ($cid == "PUBLIC") {
  5069. echo json_encode ( array (
  5070. 'status' => 1,
  5071. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5072. ) );
  5073. die ();
  5074. }
  5075. if (! is_numeric ( $cid )) {
  5076. echo json_encode ( array (
  5077. 'status' => 0,
  5078. 'msg' => 'illegal request'
  5079. ) );
  5080. die ();
  5081. }
  5082. $staffList = $staff->getStaffByCid ( $cid );
  5083. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5084. foreach ( $staffList as $key => $value ) {
  5085. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5086. }
  5087. echo json_encode ( array (
  5088. 'status' => 1,
  5089. 'html' => $html
  5090. ) );
  5091. }
  5092. /**
  5093. * 异步获取一条发票的邮寄信息
  5094. */
  5095. function ajaxGetInvoicePostDetail() {
  5096. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5097. Doo::loadModel ( 'invoice' );
  5098. $invoice = new invoice ();
  5099. $iid = $invoice->authcode ( $iid );
  5100. Doo::loadModel ( 'express' );
  5101. $express = new express ();
  5102. $expressList = $express->getExpressByAll ();
  5103. if (! is_numeric ( $iid )) {
  5104. echo json_encode ( array (
  5105. 'status' => 0,
  5106. 'msg' => 'illegal request'
  5107. ) );
  5108. die ();
  5109. }
  5110. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5111. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5112. $html = "";
  5113. foreach ( $expressList as $key => $value ) {
  5114. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5115. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5116. else
  5117. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5118. }
  5119. $invoiceDetail ['eaHtml'] = $html;
  5120. echo json_encode ( array (
  5121. 'status' => 1,
  5122. 'invoiceDetail' => $invoiceDetail
  5123. ) );
  5124. }
  5125. /**
  5126. *
  5127. * @deprecated --需求变更 废弃 function ajaxCompareClaimPrice() { $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : ""; $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); $detail = $invoice->getInvoiceByIid ( $invoiceKey ); $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); if (empty ( $detail ) || empty ( $detailM )) { echo json_encode ( array ( 'status' => 2, 'msg' => '非法请求,请重新登录' ) ); die (); } $iridString = ""; if (empty ( $detail ['irid'] )) $iridString = $detailM ['irid']; else $iridString = $detail ['irid'] . ',' . $detailM ['irid']; $item = array ( 'irid' => $iridString, 'bindTime' => date ( "Y-m-d H:i:s" ), 'updateTime' => date ( "Y-m-d H:i:s" ), 'iid' => $detail ['iid'] ); $invoice->setInvoiceByCondition ( $item ); // 操作日志 $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'operation' => "收款入账" . $detailM ['receivablesSerial'] . "到发票" . $detail ['invoiceSerial'], 'status' => 8, 'img' => $this->staff [0] ['avatar'], 'username' => $this->staff [0] ['username'], 'uid' => $this->staff [0] ['sid'], 'category' => $this->staff [0] ['category'], 'iid' => $detail ['iid'] ); $invoiceOperationLog->setInvoiceOperationLog ( $item ); $item = array ( 'iid' => $detail ['iid'], 'irid' => $detailM ['irid'], 'bindDate' => date ( "Y-m-d H:i:s" ), 'bindStatus' => 1 ); $invoiceReceivables->setInvoiceReceivablesByCondition ( $item ); $price = 0; $priceStatus = 0; $isReceivables = 0; $invoiceReceivables = new invoiceReceivables (); $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString ); if (! empty ( $list )) $isReceivables = 1; $receivablesPrice = 0; foreach ( $list as $key => $value ) { $receivablesPrice += $value ['receivablesPrice']; } if ($receivablesPrice > $detail ['invoicePrice']) { $price = $receivablesPrice - $detail ['invoicePrice']; $priceStatus = 1; } elseif ($receivablesPrice < $detail ['invoicePrice']) { $price = $detail ['invoicePrice'] - $receivablesPrice; $priceStatus = 2; } echo json_encode ( array ( 'status' => 1, 'html' => '<tr><td>¥' . $detailM ['receivablesPrice'] . '</td><td>' . $detailM ['receivablesMessage'] . '</td><td>' . $detailM ['receivablesBank'] . '</td> <td>' . $detailM ['receivablesDate'] . '</td><td><a node-remove="Da' . $detailM ['iridKey'] . '" href="javascript:void(0);">移除</a></td></tr> <script> $(\'a[node-remove="Da' . $detailM ['iridKey'] . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var iridKey="' . $detailM ["iridEn"] . '"; var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("移除处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxReceivablesRemove"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { key : iridKey, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[data-invoice=\"myReceivables\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> ', 'price' => $price, 'priceStatus' => $priceStatus, 'isReceivables' => $isReceivables ) ); }
  5128. */
  5129. /**
  5130. *
  5131. * @deprecated 从发票中移除已经入账的收款 --需求变更 废弃 function ajaxReceivablesRemove() { $iridKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); Doo::loadModel ( 'invoiceOperationLog' ); $invoiceOperationLog = new invoiceOperationLog (); $detail = $invoice->getInvoiceByIid ( $invoiceKey ); $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridKey ); // echo $detail['irid']."<br/>"; $invoiceIrid = explode ( ",", $detail ['irid'] ); foreach ( $invoiceIrid as $key => $value ) { if ($value == $detailM ['irid']) unset ( $invoiceIrid [$key] ); } $invoiceIrid = implode ( ",", $invoiceIrid ); // echo $invoiceIrid."ddd"; // print_r($invoiceIrid); $item = array ( 'irid' => $invoiceIrid, 'iid' => $detail ['iid'] ); $invoice->setInvoiceByCondition ( $item ); $item = array ( 'iid' => 0, 'irid' => $detailM ['irid'], 'bindDate' => '', 'bindStatus' => 0 ); $invoiceReceivables->setInvoiceReceivablesByCondition ( $item ); // 操作日志 $item = array ( 'date' => date ( "Y-m-d H:i:s" ), 'operation' => "收款移除" . $detailM ['receivablesSerial'], 'status' => 10, 'img' => $this->staff [0] ['avatar'], 'username' => $this->staff [0] ['username'], 'uid' => $this->staff [0] ['sid'], 'category' => $this->staff [0] ['category'], 'iid' => $detail ['iid'] ); $invoiceOperationLog->setInvoiceOperationLog ( $item ); $price = 0; $priceStatus = 0; $isReceivables = 0; $invoiceReceivables = new invoiceReceivables (); $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $invoiceIrid ); if (! empty ( $list )) $isReceivables = 1; $receivablesPrice = 0; foreach ( $list as $key => $value ) { $receivablesPrice += $value ['receivablesPrice']; } if ($receivablesPrice > $detail ['invoicePrice']) { $price = $receivablesPrice - $detail ['invoicePrice']; $priceStatus = 1; } elseif ($receivablesPrice < $detail ['invoicePrice']) { $price = $detail ['invoicePrice'] - $receivablesPrice; $priceStatus = 2; } echo json_encode ( array ( 'status' => 1, 'html' => '<tr id="' . $detailM ['receivablesSerial'] . '" > <td>¥' . $detailM ['receivablesPrice'] . '</td> <td>' . $detailM ['receivablesMessage'] . '</td> <td>' . $detailM ['receivablesBank'] . '</td> <td>' . $detailM ['receivablesDate'] . '</td><td> <a href="javascript:void(0)" node-Claim="true_' . $detailM ['iridKey'] . '" p-data="' . $detailM ['iridEn'] . '" name="invoiceClaim" class="button">入账</a> </td></tr> <script> $(\'a[node-Claim="true_' . $detailM ['iridKey'] . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("入账处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxCompareClaimPrice"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { irid : irid, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[box-enter=\"true\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> ', 'price' => $price, 'priceStatus' => $priceStatus, 'isReceivables' => $isReceivables ) ); }
  5132. */
  5133. /**
  5134. * 我的收款中 选择哪个发票入账,进行金额判断
  5135. */
  5136. function ajaxCompareInvoicePrice() {
  5137. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5138. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5139. Doo::loadModel ( 'invoice' );
  5140. $invoice = new invoice ();
  5141. Doo::loadModel ( 'invoiceReceivables' );
  5142. $invoiceReceivables = new invoiceReceivables ();
  5143. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5144. $keyList = explode ( ';', $claimKey );
  5145. $receivablesPrice = 0;
  5146. foreach ( $keyList as $key => $value ) {
  5147. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5148. $receivablesPrice += $detailM ['receivablesPrice'];
  5149. }
  5150. if ($receivablesPrice > $detail ['invoicePrice']) {
  5151. $price = $receivablesPrice - $detail ['invoicePrice'];
  5152. echo json_encode ( array (
  5153. 'status' => 1,
  5154. 'price' => $price
  5155. ) );
  5156. } else
  5157. echo json_encode ( array (
  5158. 'status' => 2
  5159. ) );
  5160. }
  5161. /**
  5162. * 获得打印发票
  5163. */
  5164. function ajaxGetInvoiceInfoByPrint() {
  5165. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5166. if (empty ( $serial )) {
  5167. echo json_encode ( array (
  5168. 'status' => 2,
  5169. 'msg' => 'illegal request'
  5170. ) );
  5171. die ();
  5172. }
  5173. Doo::loadModel ( 'invoice' );
  5174. $invoice = new invoice ();
  5175. Doo::loadModel ( 'invoiceOperationLog' );
  5176. $invoiceOperationLog = new invoiceOperationLog ();
  5177. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5178. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5179. Doo::loadModel ( 'invoicePaper' );
  5180. $invoicePaper = new invoicePaper ();
  5181. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5182. if (empty ( $detail ))
  5183. $html = '';
  5184. else {
  5185. $html = '
  5186. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5187. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5188. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5189. <div class="modal-dialog modal-lg">
  5190. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5191. <div class="modal-body saeaList">
  5192. <table class="table table-bordered table-condensed"><tbody>
  5193. <tr>
  5194. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5195. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5196. </tr>
  5197. <tr>
  5198. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5199. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5200. </tr>
  5201. <tr>
  5202. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5203. </td>
  5204. </tr>
  5205. <tr>
  5206. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5207. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5208. </tr>
  5209. <tr>
  5210. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5211. </tr></tbody></table>';
  5212. if ($detail ['invoiceType'] == 0)
  5213. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5214. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5215. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5216. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5217. </tr>';
  5218. else
  5219. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5220. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5221. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5222. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5223. ';
  5224. $html .= '<tr>
  5225. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5226. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5227. </tr>
  5228. <tr>
  5229. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5230. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5231. </tr></tbody></table>';
  5232. if ($detail ['doPost'] == 1)
  5233. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5234. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5235. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5236. </tr><tr>
  5237. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5238. </tr><tr>
  5239. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5240. </tr></tbody></table>';
  5241. if (! empty ( $invoiceOperationLogList )) {
  5242. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5243. foreach ( $invoiceOperationLogList as $key => $value ) {
  5244. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5245. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5246. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5247. if ($value ['status'] == 2) {
  5248. $html .= '<span class="colGreen">同意</span>';
  5249. } elseif ($value ['status'] == 3) {
  5250. $html .= '<span class="colOrange">退回</span>';
  5251. } elseif ($value ['status'] == 5) {
  5252. $html .= '<span class="colGreen">打印</span>';
  5253. } elseif ($value ['status'] == 4) {
  5254. $html .= '<span class="colRed">终止</span>';
  5255. }
  5256. $html .= $value ['operation'] . '</p></blockquote>';
  5257. }
  5258. }
  5259. $html .= '</td>
  5260. <td><span class="colRed">*</span>
  5261. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5262. foreach ( $invoicePaperList as $key => $value ) {
  5263. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5264. }
  5265. $html .= '</select>
  5266. <span class="red" id="p-msg"></span>
  5267. </td>
  5268. </tr></tbody></table>';
  5269. }
  5270. $html .= '</div><div class="modal-footer"><button type="submit" class="button btn-green" data-toggle="modal">完成打印</button><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div>
  5271. </div></div></form>
  5272. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5273. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5274. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5275. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5276. ';
  5277. }
  5278. echo json_encode ( array (
  5279. 'status' => 1,
  5280. 'html' => $html
  5281. ) );
  5282. die ();
  5283. }
  5284. /**
  5285. * @ 获得与我有关收款数据 --需求变更 废弃 function ajaxGetReceivalblesByStaff() { $iid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; Doo::loadModel ( 'invoiceReceivables' ); $invoiceReceivables = new invoiceReceivables (); Doo::loadModel ( 'invoice' ); $invoice = new invoice (); $detail = $invoice->getInvoiceByIid ( $iid ); $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] ); $html = ""; $i = 1; foreach ( $list ['myClaim'] as $key => $value ) { $html .= '<tr id="' . $value ['receivablesSerial'] . '" > <td>¥' . $value ['receivablesPrice'] . '</td> <td>' . $value ['receivablesMessage'] . '</td> <td>' . $value ['receivablesBank'] . '</td> <td>' . $value ['receivablesDate'] . '</td>'; $html .= '<td> <a href="javascript:void(0)" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim" class="button">入账</a> </td></tr> <script> $(\'a[node-Claim="true_' . $i . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("入账处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxCompareClaimPrice"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { irid : irid, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[box-enter=\"true\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> '; $i ++; } $html2 = ""; $list2 = $invoiceReceivables->getInvoiceReceivablesByIid ( $iid, 1 ); foreach ( $list2 as $key => $value ) { $html2 .= '<tr id="' . $value ['receivablesSerial'] . '" > <td>¥' . $value ['receivablesPrice'] . '</td> <td>' . $value ['receivablesMessage'] . '</td> <td>' . $value ['receivablesBank'] . '</td> <td>' . $value ['receivablesDate'] . '</td>'; $html2 .= '<td> <a href="javascript:void(0)" node-remove="Da' . $value ['iridKey'] . '" >移除</a> </td></tr> <script> $(\'a[node-remove="Da' . $value ['iridKey'] . '"]\').click(function() { var invoiceKey=$("input[name=\'key\']").val(); var irid= $(this).attr("p-data"); var iridKey="' . $value ["iidKey"] . '"; var element=($(this)); $("p[node-loading=\"true\"]").show(); $("p[node-loading=\"true\"]").html("移除处理中..."); $("p[node-msg=\"true2\"]").hide(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxReceivablesRemove"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { key : iridKey, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '"); if (data.status == 1) { $(element).parent().parent().remove(); $("tbody[data-invoice=\"myReceivables\"]").append(data.html); $("p[node-loading=\"true\"]").hide(); if(data.priceStatus == 1){ $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); }else if(data.priceStatus == 2&& data.isReceivables != 0){ $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }else if(data.status == 2){ $("p[node-loading=\"true\"]").html(data.msg); } }, error : function(err) { } }); }); </script> '; $i ++; } $price = 0; $priceStatus = 0; $isReceivables = 0; $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] ); if (! empty ( $list )) $isReceivables = 1; $receivablesPrice = 0; foreach ( $list as $key => $value ) { $receivablesPrice += $value ['receivablesPrice']; } if ($receivablesPrice > $detail ['invoicePrice']) { $price = $receivablesPrice - $detail ['invoicePrice']; $priceStatus = 1; } elseif ($receivablesPrice < $detail ['invoicePrice']) { $price = $detail ['invoicePrice'] - $receivablesPrice; $priceStatus = 2; } echo json_encode ( array ( 'status' => 1, 'html' => $html, 'html2' => $html2, 'price' => $price, 'priceStatus' => $priceStatus, 'isReceivables' => $isReceivables ) ); }
  5286. */
  5287. function ajaxGetInvoiceInfoByType() {
  5288. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5289. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5290. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5291. if (empty ( $serial )) {
  5292. echo json_encode ( array (
  5293. 'status' => 2,
  5294. 'msg' => 'illegal request'
  5295. ) );
  5296. die ();
  5297. }
  5298. if ($type == 'INVOICE') {
  5299. Doo::loadModel ( 'invoice' );
  5300. $invoice = new invoice ();
  5301. Doo::loadModel ( 'invoiceOperationLog' );
  5302. $invoiceOperationLog = new invoiceOperationLog ();
  5303. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5304. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5305. if (empty ( $detail ))
  5306. $html = '';
  5307. else {
  5308. $html = '
  5309. <div class="modal-dialog modal-lg">
  5310. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5311. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5312. <tr>
  5313. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5314. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5315. </tr>
  5316. <tr>
  5317. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5318. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5319. </tr>
  5320. <tr>
  5321. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5322. </td>
  5323. </tr>
  5324. <tr>
  5325. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5326. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5327. </tr>
  5328. <tr>
  5329. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5330. </tr></tbody></table>';
  5331. if ($detail ['invoiceType'] == 0)
  5332. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5333. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5334. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5335. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5336. </tr>';
  5337. else
  5338. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5339. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5340. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5341. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5342. ';
  5343. $html .= '<tr>
  5344. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5345. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5346. </tr>
  5347. <tr>
  5348. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5349. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5350. </tr></tbody></table>';
  5351. if ($detail ['doPost'] == 1) {
  5352. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5353. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5354. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5355. </tr><tr>
  5356. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5357. </tr><tr>
  5358. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5359. </tr>
  5360. ';
  5361. if ($detail ['expressCom'] == 'SF')
  5362. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="http://www.sf-express.com/cn/sc/dynamic_function/waybill/#search/bill-number/">' . $detail ['expressNumber'] . '</a> </td></tr>';
  5363. else
  5364. $html .= '<tr><th class="taC" width="150">快递单号</th><td colspan="3">' . $detail ['expressCompany'] . ' <a target="_blank" href="/invoiceExpress/' . $detail ['expressCom'] . '/' . $detail ['expressNumber'] . '.html">' . $detail ['expressNumber'] . '</a> </td></tr>';
  5365. $html .= '</tbody></table>';
  5366. }
  5367. if (! empty ( $invoiceOperationLogList )) {
  5368. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5369. foreach ( $invoiceOperationLogList as $key => $value ) {
  5370. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5371. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5372. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5373. if ($value ['status'] == 2) {
  5374. $html .= '<span class="colGreen">同意</span>';
  5375. } elseif ($value ['status'] == 3) {
  5376. $html .= '<span class="colOrange">退回</span>';
  5377. } elseif ($value ['status'] == 5) {
  5378. $html .= '<span class="colGreen">打印</span>';
  5379. } elseif ($value ['status'] == 4) {
  5380. $html .= '<span class="colRed">终止</span>';
  5381. }
  5382. $html .= $value ['operation'] . '</p></blockquote>';
  5383. }
  5384. }
  5385. $html .= '</td></tr></tbody></table>';
  5386. }
  5387. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5388. }
  5389. echo json_encode ( array (
  5390. 'status' => 1,
  5391. 'html' => $html
  5392. ) );
  5393. die ();
  5394. } elseif ($type == 'RECEIVABLES') {
  5395. Doo::loadModel ( 'invoiceReceivables' );
  5396. $invoiceReceivables = new invoiceReceivables ();
  5397. Doo::loadModel ( 'invoiceRefund' );
  5398. $invoiceRefund = new invoiceRefund ();
  5399. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5400. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5401. if (empty ( $detail ))
  5402. $html = '';
  5403. else {
  5404. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5405. <table class="table table-bordered table-condensed">
  5406. <tbody><tr>
  5407. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  5408. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  5409. </tr><tr>
  5410. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5411. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  5412. </tr>
  5413. <tr>
  5414. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  5415. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  5416. </tr>
  5417. <tr>
  5418. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  5419. </tr>
  5420. </tbody></table>';
  5421. if (! empty ( $ireList )) {
  5422. $html .= '
  5423. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  5424. <tr>
  5425. <th class="taC">退款单位名称</th>
  5426. <th class="taC">退款的账号</th>
  5427. <th class="taC">退款金额</th>
  5428. <th class="taC">退款</th>
  5429. <th class="taC">备注</th>
  5430. </tr>
  5431. ';
  5432. foreach ( $ireList as $key => $value ) {
  5433. $refundLogList=explode("<br/>",$value['refundLog']);
  5434. $html .= '<tr>
  5435. <td>' . $value ['refundCompany'] . '</td>
  5436. <td>' . $value ['refundNumber'] . '</td>
  5437. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  5438. <td>' . $refundLogList [0].$refundLogList [2] . '</td>
  5439. <td>' . $value ['refundRemarks'] . '</td>
  5440. </tr>
  5441. ';
  5442. }
  5443. }
  5444. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5445. }
  5446. echo json_encode ( array (
  5447. 'status' => 1,
  5448. 'html' => $html
  5449. ) );
  5450. die ();
  5451. } elseif ($type == 'IRTC') {
  5452. Doo::loadModel ( 'invoice' );
  5453. $invoice = new invoice ();
  5454. Doo::loadModel ( 'invoiceOperationLog' );
  5455. $invoiceOperationLog = new invoiceOperationLog ();
  5456. Doo::loadModel ( 'invoiceReceivables' );
  5457. $invoiceReceivables = new invoiceReceivables ();
  5458. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5459. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5460. if (empty ( $detail ))
  5461. $html = '';
  5462. else {
  5463. $receivablesPriceedHtml = '';
  5464. $receivablesPrice = $detail ['invoicePrice'];
  5465. if (! empty ( $detail ['irid'] )) {
  5466. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  5467. if (empty ( $irList ))
  5468. $irList [0] ['sumPrice'] = 0;
  5469. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  5470. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  5471. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  5472. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  5473. </tr></tbody></table>';
  5474. $receivablesPrice = $balance;
  5475. }
  5476. if ($loss)
  5477. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  5478. $html = $receivablesPriceedHtml . '
  5479. <table class="table table-bordered table-condensed"><tbody>
  5480. <tr>
  5481. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5482. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5483. </tr>
  5484. <tr>
  5485. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5486. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5487. </tr>
  5488. <tr>
  5489. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  5490. </tr>
  5491. <tr>
  5492. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5493. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5494. </tr>
  5495. <tr>
  5496. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5497. </tr></tbody></table>';
  5498. if ($detail ['invoiceType'] == 0) {
  5499. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5500. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5501. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5502. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5503. </tr>';
  5504. $receivablesMessage = $detail ['invoiceTitle'];
  5505. } else {
  5506. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5507. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5508. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5509. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5510. ';
  5511. $receivablesMessage = $detail ['invoiceCompany'];
  5512. }
  5513. $html .= '<tr>
  5514. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5515. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5516. </tr>
  5517. <tr>
  5518. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  5519. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  5520. </tr></tbody></table>';
  5521. if ($detail ['doPost'] == 1)
  5522. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5523. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5524. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5525. </tr><tr>
  5526. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5527. </tr><tr>
  5528. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5529. </tr></tbody></table>';
  5530. if (! empty ( $invoiceOperationLogList )) {
  5531. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5532. foreach ( $invoiceOperationLogList as $key => $value ) {
  5533. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5534. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5535. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5536. if ($value ['status'] == 2) {
  5537. $html .= '<span class="colGreen">同意</span>';
  5538. } elseif ($value ['status'] == 3) {
  5539. $html .= '<span class="colOrange">退回</span>';
  5540. } elseif ($value ['status'] == 5) {
  5541. $html .= '<span class="colGreen">打印</span>';
  5542. }
  5543. $html .= $value ['operation'] . '</p></blockquote>';
  5544. }
  5545. }
  5546. $html .= '</td></tr></tbody></table>';
  5547. }
  5548. }
  5549. echo json_encode ( array (
  5550. 'status' => 1,
  5551. 'html' => $html,
  5552. 'receivablesPrice' => $receivablesPrice,
  5553. 'receivablesMessage' => $receivablesMessage,
  5554. 'receivablesDate' => date ( "Y-m-d" ),
  5555. 'iidKey' => $serial
  5556. ) );
  5557. die ();
  5558. }
  5559. }
  5560. function ajaxGetInvoiceReceivablesByStaff() {
  5561. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  5562. if (empty ( $postData )) {
  5563. echo json_encode ( array (
  5564. 'status' => 2,
  5565. 'msg' => 'illegal request'
  5566. ) );
  5567. die ();
  5568. }
  5569. Doo::loadModel ( 'invoiceReceivables' );
  5570. $invoiceReceivables = new invoiceReceivables ();
  5571. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  5572. if (empty ( $detail )) {
  5573. echo json_encode ( array (
  5574. 'status' => 2,
  5575. 'msg' => 'illegal request'
  5576. ) );
  5577. die ();
  5578. }
  5579. Doo::loadModel ( 'L_category' );
  5580. $lCategory = new L_category ();
  5581. Doo::loadModel ( 'staff' );
  5582. $staff = new staff ();
  5583. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  5584. $category = $lCategory->getCategory ();
  5585. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  5586. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  5587. foreach ( $category as $key => $value ) {
  5588. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5589. if ($value ['cid'] == $detail ['cid'])
  5590. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5591. }
  5592. foreach ( $staffList as $key => $value ) {
  5593. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5594. if ($value ['sid'] == $detail ['sid'])
  5595. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5596. }
  5597. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  5598. echo json_encode ( array (
  5599. 'status' => 1,
  5600. 'categoryHtml' => $categoryHtml,
  5601. 'staffHtml' => $staffHtml,
  5602. 'rbankHtml' => $rbankHtml,
  5603. 'detail' => $detail
  5604. ) );
  5605. }
  5606. function ajaxGetInvoiceReceivablesByIrid() {
  5607. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  5608. if (empty ( $irid )) {
  5609. echo json_encode ( array (
  5610. 'status' => 2,
  5611. 'msg' => 'illegal request'
  5612. ) );
  5613. die ();
  5614. }
  5615. Doo::loadModel ( 'invoiceReceivables' );
  5616. $invoiceReceivables = new invoiceReceivables ();
  5617. Doo::loadModel ( 'invoice' );
  5618. $invoice = new invoice ();
  5619. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  5620. $flag = true;
  5621. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  5622. $bakDetail = array ();
  5623. if ($flag === false) {
  5624. array_push ( $bakDetail, $invoiceDetail );
  5625. $invoiceDetail = $bakDetail;
  5626. }
  5627. $receivablesHtml = '<table class="table table-bordered table-condensed"><tbody><tr><th class="taC" width="70">收款金额</th><th class="taC">银行到账信息</th><th class="taC">银行/到账时间</th><th class="taC">收款认领</th><th class="taC">开票单位</th></tr>
  5628. <tr>
  5629. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5630. <td>' . $detail ['receivablesMessage'] . '</td>
  5631. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  5632. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  5633. <td>' . $detail ['recepitTitleMark'] . '</td>
  5634. </tr></tbody></table>';
  5635. $isInvoice = false;
  5636. $invoiceHtml = '';
  5637. if (empty ( $invoiceDetail )) {
  5638. $isInvoice = true;
  5639. } else {
  5640. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5641. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  5642. foreach ( $invoiceDetail as $key => $value ) {
  5643. $invoiceHtml .= '<tr>';
  5644. if (! empty ( $value ['invoiceType'] )) {
  5645. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5646. } else {
  5647. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5648. }
  5649. if (! empty ( $value ['invoiceType'] )) {
  5650. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5651. } else {
  5652. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5653. }
  5654. $invoiceHtml .= '
  5655. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5656. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5657. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  5658. </tr>
  5659. ';
  5660. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  5661. if (empty ( $irList ))
  5662. $irList [0] ['sumPrice'] = 0;
  5663. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  5664. $priceString = '';
  5665. if ($balance < $detail ['receivablesPrice']) {
  5666. $priceString = '收款金额超过开票金额,';
  5667. }
  5668. if ($balance > $detail ['receivablesPrice']) {
  5669. $priceString = '收款金额低于开票金额,';
  5670. }
  5671. }
  5672. $invoiceHtml .= '
  5673. <script>
  5674. $(\'a[bind-receivables^="ir"]\').click(function() {
  5675. var data = $(this).attr("data-ikey");
  5676. $("input[name=\'invoiceKey\']").val(data);
  5677. var invoiceKey=data;
  5678. if(invoiceKey==""){
  5679. alert("入账错误,请重新刷新页面");
  5680. return false;
  5681. }
  5682. if(window.confirm("' . $priceString . '确定入账吗?")){
  5683. $("#IBR").submit();
  5684. }else{
  5685. return false;
  5686. }
  5687. });
  5688. </script>
  5689. ';
  5690. $invoiceHtml .= '</tbody></table>';
  5691. }
  5692. echo json_encode ( array (
  5693. 'status' => 1,
  5694. 'irkey' => $detail ['iridEn'],
  5695. 'receivablesHtml' => $receivablesHtml,
  5696. 'isInvoice' => $isInvoice,
  5697. 'invoiceHtml' => $invoiceHtml
  5698. ) );
  5699. }
  5700. function ajaxGetInvoiceReceivablesByTitle() {
  5701. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  5702. if (empty ( $title )) {
  5703. echo json_encode ( array (
  5704. 'status' => 2,
  5705. 'msg' => 'illegal request'
  5706. ) );
  5707. die ();
  5708. }
  5709. Doo::loadModel ( 'invoice' );
  5710. $invoice = new invoice ();
  5711. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  5712. $invoiceHtml = '';
  5713. if (! empty ( $invoiceDetail )) {
  5714. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5715. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  5716. foreach ( $invoiceDetail as $key => $value ) {
  5717. if (! empty ( $value ['invoiceType'] )) {
  5718. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5719. } else {
  5720. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5721. }
  5722. if (! empty ( $value ['invoiceType'] )) {
  5723. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5724. } else {
  5725. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5726. }
  5727. $invoiceHtml .= '
  5728. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5729. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5730. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  5731. </tr>
  5732. ';
  5733. }
  5734. $invoiceHtml .= '</tbody></table>
  5735. <script>
  5736. $(\'a[bind-receivables^="ir"]\').click(function() {
  5737. var data = $(this).attr("data-ikey");
  5738. $("input[name=\'invoiceKey\']").val(data);
  5739. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  5740. if(invoiceKey==""){
  5741. alert("入账错误,请重新刷新页面");
  5742. return false;
  5743. }
  5744. if(window.confirm("确定入账吗?")){
  5745. $("#IBR").submit();
  5746. }else{
  5747. return false;
  5748. }
  5749. });
  5750. </script>
  5751. ';
  5752. }
  5753. echo json_encode ( array (
  5754. 'status' => 1,
  5755. 'invoiceHtml' => $invoiceHtml
  5756. ) );
  5757. }
  5758. function ajaxInvoicePushNotice() {
  5759. Doo::loadModel ( 'invoice' );
  5760. $invoice = new invoice ();
  5761. $approval = $invoice->getOne ( array (
  5762. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  5763. 'desc' => 'iid',
  5764. 'asArray' => true
  5765. ) );
  5766. $isNotice = false;
  5767. if (! empty ( $approval ))
  5768. $isNotice = true;
  5769. $response = array (
  5770. 'error' => 0,
  5771. 'isNotice' => $isNotice
  5772. );
  5773. echo json_encode ( $response );
  5774. exit ();
  5775. }
  5776. public function ajaxCheckInvoiceNoUniqueness() {
  5777. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  5778. Doo::loadModel ( 'invoice' );
  5779. $invoice = new invoice ();
  5780. if (! empty ( $invoiceNo )) {
  5781. Doo::loadModel ( 'invoicePaper' );
  5782. $invoicePaper = new invoicePaper ();
  5783. Doo::loadClass ( 'XDeode' );
  5784. $XDeode = new XDeode ( 5 );
  5785. $ipid = $XDeode->decode ( $invoiceNo );
  5786. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  5787. $info = $invoice->getOne ( array (
  5788. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  5789. 'asArray' => TRUE
  5790. ) );
  5791. if (! empty ( $info )) {
  5792. echo json_encode ( array (
  5793. 'error' => '发票号已存在'
  5794. ) );
  5795. die ();
  5796. } else
  5797. echo json_encode ( array (
  5798. 'ok' => '可以使用!'
  5799. ) );
  5800. die ();
  5801. }
  5802. }
  5803. function ajaxCheckInvoicePrice() {
  5804. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  5805. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5806. Doo::loadModel ( 'invoice' );
  5807. $invoice = new invoice ();
  5808. Doo::loadModel ( 'invoiceReceivables' );
  5809. $invoiceReceivables = new invoiceReceivables ();
  5810. Doo::loadClass ( 'XDeode' );
  5811. $XDeode = new XDeode ( 5 );
  5812. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  5813. $iidKey = $XDeode->decode ( $iidKey );
  5814. $info = $invoice->getInvoiceByIid ( $iidKey );
  5815. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  5816. if (empty ( $irList ))
  5817. $irList [0] ['sumPrice'] = 0;
  5818. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  5819. if ($balance < $receivablesPrice) {
  5820. echo json_encode ( array (
  5821. 'error' => '收款金额超过开票金额。'
  5822. ) );
  5823. die ();
  5824. }
  5825. if ($balance > $receivablesPrice) {
  5826. echo json_encode ( array (
  5827. 'error' => '收款金额低于开票金额。'
  5828. ) );
  5829. die ();
  5830. }
  5831. }
  5832. }
  5833. /**
  5834. * 旧输入导入
  5835. */
  5836. function importInvoice() {
  5837. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  5838. $data ['emsg'] = "";
  5839. if ($emsg != "")
  5840. $data ['emsg'] = "请填写完整的数据";
  5841. $data ['time'] = time ();
  5842. $this->render ( "/admin/invoiceImport", $data );
  5843. }
  5844. function uploadInvoice() {
  5845. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  5846. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  5847. $file = $_FILES ['Filedata'] ['tmp_name'];
  5848. $error = false;
  5849. if (! is_uploaded_file ( $file )) {
  5850. $error = '400 Bad Request';
  5851. }
  5852. if ($error) {
  5853. header ( 'HTTP/1.0 ' . $error );
  5854. die ( 'Error ' . $error );
  5855. } else {
  5856. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  5857. $this->IoHandler = new IoHandler ();
  5858. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  5859. // $filedir=$_POST['time'];
  5860. // 调用定义物理路径
  5861. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  5862. $this->IoHandler->MakeDir ( $t );
  5863. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  5864. if ($filename != 'xlsx')
  5865. return "";
  5866. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  5867. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  5868. $upload_dir = $t . "/" . $upload_file;
  5869. $k = move_uploaded_file ( $file, $upload_dir );
  5870. if ($k) {
  5871. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  5872. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  5873. }
  5874. }
  5875. }
  5876. }
  5877. function importInvoiceDo() {
  5878. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  5879. if ($path != "") {
  5880. Doo::loadModel ( 'invoice' );
  5881. Doo::loadModel ( 'staff' );
  5882. $staff = new staff ();
  5883. Doo::loadModel ( 'invoiceStatistics' );
  5884. Doo::loadModel ( 'invoiceOperationLog' );
  5885. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  5886. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  5887. // print_r ( $exlArray );
  5888. // die ();
  5889. // echo json_encode($exlArray);die;
  5890. foreach ( $exlArray as $key => $value ) {
  5891. // 开票
  5892. $invoice = new invoice ();
  5893. $invoice->invoiceNo = $value ['invoiceNo'];
  5894. $invoice->invoiceType = 0;
  5895. if ($value ['invoiceType'] == '专')
  5896. $invoice->invoiceType = 1;
  5897. $invoice->invoicePrice = $value ['invoicePrice'];
  5898. $invoice->invoiceQuantity = 1;
  5899. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  5900. $invoice->invoiceTitle = $value ['invoiceTitle'];
  5901. if ($value ['invoiceType'] == '专')
  5902. $invoice->invoiceCompany = $value ['invoiceTitle'];
  5903. $invoice->userName = $value ['userName'];
  5904. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  5905. $invoice->sid = $sDetail ['sid'];
  5906. $invoice->cid = $sDetail ['cid'];
  5907. $invoice->categoryName = $sDetail ['category'];
  5908. $invoice->invoiceElement = $value ['invoiceElement'];
  5909. $invoice->remark = $value ['remark'];
  5910. $invoice->date = $value ['date'];
  5911. $invoice->printTime = $value ['date'];
  5912. $invoice->ipSource = 1;
  5913. $invoice->printStatus = 1;
  5914. $invoice->status = 2;
  5915. $invoice->postStatus = 1;
  5916. $invoice->untreadStatus = 0;
  5917. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  5918. $iid = $invoice->insert ();
  5919. // 汇总
  5920. $invoiceStatistics = new invoiceStatistics ();
  5921. //
  5922. $item = array (
  5923. 'date' => $value ['date'],
  5924. 'priceClass' => 1,
  5925. 'cid' => $sDetail ['cid'],
  5926. 'staff' => $sDetail ['sid'],
  5927. 'invoicePrice' => $value ['invoicePrice']
  5928. );
  5929. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5930. $invoiceOperationLog = new invoiceOperationLog ();
  5931. $item = array (
  5932. 'date' => date ( "Y-m-d H:i:s" ),
  5933. 'operation' => date ( "Y-m-d" ) . " 导入",
  5934. 'status' => 1,
  5935. 'img' => $sDetail ['avatar'],
  5936. 'username' => $sDetail ['username'],
  5937. 'uid' => $sDetail ['sid'],
  5938. 'category' => $sDetail ['category'],
  5939. 'iid' => $iid
  5940. );
  5941. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5942. }
  5943. return '/importInvoice?count=' . count ( $exlArray );
  5944. // return "/keyonline";
  5945. }
  5946. echo 'no file';
  5947. }
  5948. function importInvoiceReceivables() {
  5949. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  5950. $data ['emsg'] = "";
  5951. if ($emsg != "")
  5952. $data ['emsg'] = "请填写完整的数据";
  5953. $data ['time'] = time ();
  5954. $this->render ( "/admin/invoiceReceivablesImport", $data );
  5955. }
  5956. // 导入入账数据
  5957. function importInvoiceReceivablesDo() {
  5958. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  5959. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  5960. if ($path != "") {
  5961. Doo::loadModel ( 'invoiceReceivables' );
  5962. Doo::loadModel ( 'invoice' );
  5963. Doo::loadModel ( 'staff' );
  5964. $staff = new staff ();
  5965. Doo::loadModel ( 'invoiceStatistics' );
  5966. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  5967. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  5968. // print_r ( $exlArray );
  5969. // die ();
  5970. // echo json_encode($exlArray);die;
  5971. foreach ( $exlArray as $key => $value ) {
  5972. // 收款
  5973. $invoiceReceivables = new invoiceReceivables ();
  5974. $invoice = new invoice ();
  5975. $invoiceReceivables->bindStatus = 1;
  5976. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  5977. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  5978. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  5979. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  5980. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  5981. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  5982. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  5983. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  5984. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  5985. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  5986. $invoiceReceivables->iid = $iDetail ['iid'];
  5987. $irid = $invoiceReceivables->insert ();
  5988. // 发票绑定收款
  5989. $detail = $iDetail;
  5990. $iridString = "";
  5991. if (empty ( $detail ['irid'] ))
  5992. $iridString = $irid;
  5993. else
  5994. $iridString = $detail ['irid'] . ',' . $irid;
  5995. $item = array (
  5996. 'irid' => $iridString,
  5997. 'iid' => $detail ['iid']
  5998. );
  5999. $invoice->setInvoiceByCondition ( $item );
  6000. // 汇总
  6001. $invoiceStatistics = new invoiceStatistics ();
  6002. // 扣除入账统计金额
  6003. $item = array (
  6004. 'date' => $value ['receivablesDate'],
  6005. 'priceClass' => 3,
  6006. 'cid' => $sDetail ['cid'],
  6007. 'staff' => $sDetail ['sid'],
  6008. // 'irid' => $irid,
  6009. 'accountPrice' => $value ['receivablesPrice']
  6010. );
  6011. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6012. }
  6013. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6014. echo 'data count ' . count ( $exlArray );
  6015. die ();
  6016. // return "/keyonline";
  6017. }
  6018. echo 'no file';
  6019. }
  6020. function formatExcelToArrayTrain($file_url = "") {
  6021. if (! file_exists ( $file_url )) {
  6022. return array ();
  6023. }
  6024. // Doo::loadClass ( 'PHPExcel' );
  6025. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6026. $PHPExcel = new PHPExcel ();
  6027. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6028. if (! $PHPReader->canRead ( $file_url )) {
  6029. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6030. if (! $PHPReader->canRead ( $file_url )) {
  6031. echo 'no Excel';
  6032. return;
  6033. }
  6034. }
  6035. $PHPExcel = $PHPReader->load ( $file_url );
  6036. /* * 读取excel文件中的第一个工作表 */
  6037. $currentSheet = $PHPExcel->getSheet ( 0 );
  6038. /* * 取得最大的列号 */
  6039. $allColumn = $currentSheet->getHighestColumn ();
  6040. /* * 取得一共有多少行 */
  6041. $allRow = $currentSheet->getHighestRow ();
  6042. $excel_array = array ();
  6043. // die($file_url);
  6044. $conk = 2;
  6045. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6046. $excel_column = array ();
  6047. // 后期改进
  6048. if ($allColumn == 'AM')
  6049. $allColumn = 'Z';
  6050. /* * 从第A列开始输出 */
  6051. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6052. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6053. if ($val instanceof PHPExcel_RichText)
  6054. $val = $val->__toString ();
  6055. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6056. // $val = "'" . addslashes ( $val ) . "'";
  6057. if ($currentColumn == 'A') {
  6058. $excel_column ['invoiceTitle'] = $val;
  6059. } elseif ($currentColumn == 'B')
  6060. $excel_column ['invoiceType'] = $val;
  6061. elseif ($currentColumn == 'C') {
  6062. $excel_column ['TIN'] = $val;
  6063. } elseif ($currentColumn == 'D') {
  6064. $excel_column ['address'] = $val;
  6065. } elseif ($currentColumn == 'E') {
  6066. $excel_column ['phone'] = $val;
  6067. } elseif ($currentColumn == 'F') {
  6068. $excel_column ['bank'] = $val;
  6069. } elseif ($currentColumn == 'G') {
  6070. $excel_column ['bankAccount'] = $val;
  6071. } elseif ($currentColumn == 'H') {
  6072. $excel_column ['invoiceElement'] = $val;
  6073. } elseif ($currentColumn == 'I') {
  6074. $excel_column ['invoiceQuantity'] = $val;
  6075. } elseif ($currentColumn == 'J') {
  6076. $excel_column ['invoiceUnitPrice'] = $val;
  6077. } elseif ($currentColumn == 'K') {
  6078. $excel_column ['remark'] = $val;
  6079. } elseif ($currentColumn == 'L') {
  6080. $excel_column ['recipientsAddress'] = $val;
  6081. } elseif ($currentColumn == 'M') {
  6082. $excel_column ['recipients'] = $val;
  6083. } elseif ($currentColumn == 'N') {
  6084. $excel_column ['recipientsPhone'] = $val;
  6085. }
  6086. }
  6087. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6088. array_push ( $excel_array, $excel_column );
  6089. }
  6090. return $excel_array;
  6091. }
  6092. /**
  6093. * 格式化excel文件为数组
  6094. * @param unknown_type $file_url
  6095. * @param unknown_type $mcid
  6096. */
  6097. function _format_excel_to_array($file_url = "", $sType = "") {
  6098. if (! file_exists ( $file_url )) {
  6099. return array ();
  6100. }
  6101. Doo::loadClass ( 'PHPExcel' );
  6102. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6103. $PHPExcel = new PHPExcel ();
  6104. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6105. if (! $PHPReader->canRead ( $file_url )) {
  6106. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6107. if (! $PHPReader->canRead ( $file_url )) {
  6108. echo 'no Excel';
  6109. return;
  6110. }
  6111. }
  6112. $PHPExcel = $PHPReader->load ( $file_url );
  6113. /* * 读取excel文件中的第一个工作表 */
  6114. $currentSheet = $PHPExcel->getSheet ( 0 );
  6115. /* * 取得最大的列号 */
  6116. $allColumn = $currentSheet->getHighestColumn ();
  6117. /* * 取得一共有多少行 */
  6118. $allRow = $currentSheet->getHighestRow ();
  6119. $excel_array = array ();
  6120. // die($file_url);
  6121. $conk = 2;
  6122. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6123. $excel_column = array ();
  6124. // 后期改进
  6125. if ($allColumn == 'AM')
  6126. $allColumn = 'Z';
  6127. /* * 从第A列开始输出 */
  6128. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6129. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6130. if ($val instanceof PHPExcel_RichText)
  6131. $val = $val->__toString ();
  6132. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6133. // $val = "'" . addslashes ( $val ) . "'";
  6134. if ($sType == 'invoiceReceivables') {
  6135. if ($currentColumn == 'A')
  6136. $excel_column ['invoiceNo'] = $val;
  6137. elseif ($currentColumn == 'B')
  6138. $excel_column ['receivablesPrice'] = $val;
  6139. elseif ($currentColumn == 'C') {
  6140. $excel_column ['receivablesMessage'] = $val;
  6141. } elseif ($currentColumn == 'D') {
  6142. $excel_column ['receivablesBank'] = $val;
  6143. } elseif ($currentColumn == 'E') {
  6144. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6145. } elseif ($currentColumn == 'F') {
  6146. $excel_column ['receivablesStaff'] = $val;
  6147. } elseif ($currentColumn == 'G') {
  6148. $excel_column ['sourcePrice'] = $val;
  6149. }
  6150. } elseif ($sType == "invoiceTrain") {
  6151. if ($currentColumn == 'A') {
  6152. $excel_column ['invoiceTitle'] = $val;
  6153. } elseif ($currentColumn == 'B')
  6154. $excel_column ['invoiceType'] = $val;
  6155. elseif ($currentColumn == 'C') {
  6156. $excel_column ['TIN'] = $val;
  6157. } elseif ($currentColumn == 'D') {
  6158. $excel_column ['address'] = $val;
  6159. } elseif ($currentColumn == 'E') {
  6160. $excel_column ['phone'] = $val;
  6161. } elseif ($currentColumn == 'F') {
  6162. $excel_column ['bank'] = $val;
  6163. } elseif ($currentColumn == 'G') {
  6164. $excel_column ['bankAccount'] = $val;
  6165. } elseif ($currentColumn == 'H') {
  6166. $excel_column ['invoiceElement'] = $val;
  6167. } elseif ($currentColumn == 'I') {
  6168. $excel_column ['invoiceQuantity'] = $val;
  6169. } elseif ($currentColumn == 'J') {
  6170. $excel_column ['invoiceUnitPrice'] = $val;
  6171. } elseif ($currentColumn == 'K') {
  6172. $excel_column ['remark'] = $val;
  6173. } elseif ($currentColumn == 'L') {
  6174. $excel_column ['recipientsAddress'] = $val;
  6175. } elseif ($currentColumn == 'M') {
  6176. $excel_column ['recipients'] = $val;
  6177. } elseif ($currentColumn == 'N') {
  6178. $excel_column ['recipientsPhone'] = $val;
  6179. }
  6180. } else {
  6181. if ($currentColumn == 'A')
  6182. $excel_column ['invoiceNo'] = $val;
  6183. elseif ($currentColumn == 'B')
  6184. $excel_column ['invoiceType'] = $val;
  6185. elseif ($currentColumn == 'C') {
  6186. $excel_column ['invoicePrice'] = $val;
  6187. } elseif ($currentColumn == 'D') {
  6188. $excel_column ['invoiceTitle'] = $val;
  6189. } elseif ($currentColumn == 'E') {
  6190. $excel_column ['userName'] = $val;
  6191. } elseif ($currentColumn == 'F') {
  6192. $excel_column ['categoryName'] = $val;
  6193. } elseif ($currentColumn == 'G') {
  6194. $excel_column ['invoiceElement'] = $val;
  6195. } elseif ($currentColumn == 'H') {
  6196. $excel_column ['remark'] = $val;
  6197. } elseif ($currentColumn == 'I') {
  6198. $excel_column ['date'] = $this->excelTime ( $val );
  6199. }
  6200. }
  6201. }
  6202. array_push ( $excel_array, $excel_column );
  6203. }
  6204. return $excel_array;
  6205. }
  6206. function excelTime($date, $time = false) {
  6207. if (function_exists ( 'GregorianToJD' )) {
  6208. if (is_numeric ( $date )) {
  6209. $jd = GregorianToJD ( 1, 1, 1970 );
  6210. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6211. $date = explode ( '/', $gregorian );
  6212. $date_str = str_pad ( $date [2], 4, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [0], 2, '0', STR_PAD_LEFT ) . "-" . str_pad ( $date [1], 2, '0', STR_PAD_LEFT ) . ($time ? " 00:00:00" : '');
  6213. return $date_str;
  6214. }
  6215. } else {
  6216. $date = $date > 25568 ? $date + 1 : 25569;
  6217. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6218. $ofs = (70 * 365 + 17 + 2) * 86400;
  6219. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6220. }
  6221. return $date;
  6222. }
  6223. /**
  6224. * 旧输入导入
  6225. */
  6226. function _GetFileEXT($filename) {
  6227. $pics = explode ( '.', $filename );
  6228. $num = count ( $pics );
  6229. return $pics [$num - 1];
  6230. }
  6231. function showCache($path = "", $sid = 0) {
  6232. // if (file_exists ( $path )) {
  6233. // $htm = file_get_contents ( $path );
  6234. // } else {
  6235. Doo::loadModel ( 'invoiceStatistics' );
  6236. $invoiceStatistics = new invoiceStatistics ();
  6237. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6238. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6239. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6240. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6241. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6242. /*
  6243. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6244. */
  6245. file_put_contents ( $path, $htm );
  6246. // }
  6247. return $htm;
  6248. }
  6249. /**
  6250. * 获取get或者POST值
  6251. *
  6252. * @param string $name 属性名称
  6253. * @return fixed 值
  6254. */
  6255. function get_args($name) {
  6256. if (isset ( $_GET [$name] )) {
  6257. if (is_array ( $_GET [$name] ))
  6258. return $_GET [$name];
  6259. else
  6260. return addslashes ( $_GET [$name] );
  6261. } elseif (isset ( $_POST [$name] )) {
  6262. if (is_array ( $_POST [$name] ))
  6263. return $_POST [$name];
  6264. else
  6265. return addslashes ( $_POST [$name] );
  6266. } else
  6267. return false;
  6268. }
  6269. function SafeFilter(&$arr) {
  6270. $ra = Array (
  6271. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6272. '/script/',
  6273. '/javascript/',
  6274. '/vbscript/',
  6275. '/expression/',
  6276. '/applet/',
  6277. '/meta/',
  6278. '/xml/',
  6279. '/blink/',
  6280. '/link/',
  6281. '/style/',
  6282. '/embed/',
  6283. '/object/',
  6284. '/frame/',
  6285. '/layer/',
  6286. '/title/',
  6287. '/bgsound/',
  6288. '/base/',
  6289. '/onload/',
  6290. '/onunload/',
  6291. '/onchange/',
  6292. '/onsubmit/',
  6293. '/onreset/',
  6294. '/onselect/',
  6295. '/onblur/',
  6296. '/onfocus/',
  6297. '/onabort/',
  6298. '/onkeydown/',
  6299. '/onkeypress/',
  6300. '/onkeyup/',
  6301. '/onclick/',
  6302. '/ondblclick/',
  6303. '/onmousedown/',
  6304. '/onmousemove/',
  6305. '/onmouseout/',
  6306. '/onmouseover/',
  6307. '/onmouseup/',
  6308. '/onunload/'
  6309. );
  6310. if (is_array ( $arr )) {
  6311. foreach ( $arr as $key => $value ) {
  6312. if (! is_array ( $value )) {
  6313. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6314. {
  6315. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6316. }
  6317. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6318. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6319. } else {
  6320. SafeFilter ( $arr [$key] );
  6321. }
  6322. }
  6323. }
  6324. }
  6325. /**
  6326. * Escape String
  6327. *
  6328. * @access public
  6329. * @param string
  6330. * @param bool whether or not the string will be used in a LIKE condition
  6331. * @return string
  6332. */
  6333. function escape_str($str, $like = FALSE) {
  6334. if (is_array ( $str )) {
  6335. foreach ( $str as $key => $val ) {
  6336. $str [$key] = $this->escape_str ( $val, $like );
  6337. }
  6338. return $str;
  6339. }
  6340. var_dump ( Doo::db ()->getDbObject () );
  6341. die ();
  6342. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6343. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6344. } elseif (function_exists ( 'mysql_escape_string' )) {
  6345. $str = mysql_escape_string ( $str );
  6346. } else {
  6347. $str = addslashes ( $str );
  6348. }
  6349. // escape LIKE condition wildcards
  6350. if ($like === TRUE) {
  6351. $str = str_replace ( array (
  6352. '%',
  6353. '_'
  6354. ), array (
  6355. '\\%',
  6356. '\\_'
  6357. ), $str );
  6358. }
  6359. return $str;
  6360. }
  6361. /**
  6362. * 获得分页数据
  6363. * @param unknown_type $table
  6364. * @param unknown_type $condition
  6365. * @param unknown_type $on_page
  6366. * @param unknown_type $page_size
  6367. */
  6368. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6369. $page_c = "";
  6370. $page ['previous'] = $this->get_previous ( $on_page );
  6371. $page ['on_page'] = $on_page;
  6372. $total_count = $this->get_table_count ( $table, $condition );
  6373. $total = intval ( $total_count / $page_size );
  6374. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6375. $page ['total_data'] = $total_count;
  6376. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6377. $i = 1;
  6378. $page_max = 1;
  6379. $page_width = 3;
  6380. if ($on_page >= $page_width) {
  6381. $page_max = intval ( $on_page / $page_width ) + 1;
  6382. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6383. }
  6384. for(; $i <= $page ['total_page']; $i ++) {
  6385. if ($i == $on_page)
  6386. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6387. else
  6388. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6389. if ($i == ($page_width * $page_max))
  6390. break;
  6391. }
  6392. $page ['page'] = $page_c;
  6393. $page ['lower'] = (-- $on_page) * $page_size;
  6394. return $page;
  6395. }
  6396. /**
  6397. * 获取上一页
  6398. * @param unknown_type $on_page
  6399. */
  6400. function get_previous($on_page = 1) {
  6401. return $on_page != 0 ? $on_page - 1 : $on_page;
  6402. }
  6403. /**
  6404. * 获取总页数
  6405. * @param unknown_type $table
  6406. * @param unknown_type $condition
  6407. */
  6408. public function get_table_count($table = "", $condition = "") {
  6409. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6410. $sql = "select count(*) as count from " . $table . " where " . $condition;
  6411. // echo $sql;die;
  6412. $query = Doo::db ()->query ( $sql );
  6413. $result = $query->fetch ();
  6414. return $result ['count'];
  6415. }
  6416. /**
  6417. * 获得分页数据
  6418. * @param unknown_type $table
  6419. * @param unknown_type $condition
  6420. * @param unknown_type $on_page
  6421. * @param unknown_type $page_size
  6422. */
  6423. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6424. $page_c = "";
  6425. $page ['previous'] = $this->get_previous ( $on_page );
  6426. $page ['on_page'] = $on_page;
  6427. $total_count = $this->getTableCountBySql ( $sql );
  6428. $total = intval ( $total_count / $page_size );
  6429. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6430. $page ['total_data'] = $total_count;
  6431. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6432. $i = 1;
  6433. $page_max = 1;
  6434. $page_width = 3;
  6435. if ($on_page >= $page_width) {
  6436. $page_max = intval ( $on_page / $page_width ) + 1;
  6437. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6438. }
  6439. for(; $i <= $page ['total_page']; $i ++) {
  6440. if ($i == $on_page)
  6441. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6442. else
  6443. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6444. if ($i == ($page_width * $page_max))
  6445. break;
  6446. }
  6447. $page ['page'] = $page_c;
  6448. $page ['lower'] = (-- $on_page) * $page_size;
  6449. return $page;
  6450. }
  6451. /**
  6452. * 获得总页数 sql
  6453. * @param string $type
  6454. * @return boolean[]
  6455. */
  6456. public function getTableCountBySql($sql = "") {
  6457. $query = Doo::db ()->query ( $sql );
  6458. $result = $query->fetchAll ();
  6459. return count ( $result );
  6460. }
  6461. function isInvoiceNew($type = "GLOBAL") {
  6462. Doo::loadModel ( 'invoice' );
  6463. $invoice = new invoice ();
  6464. Doo::loadModel ( 'invoiceReceivables' );
  6465. $invoiceReceivables = new invoiceReceivables ();
  6466. Doo::loadModel ( 'staff' );
  6467. $staff = new staff ();
  6468. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  6469. // 我的发票待处理
  6470. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  6471. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  6472. 'desc' => 'iid',
  6473. 'asArray' => TRUE
  6474. ) );
  6475. // 我的收款待入账
  6476. /*
  6477. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  6478. */
  6479. // 发票审批
  6480. $approval = $invoice->getOne ( array (
  6481. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  6482. 'desc' => 'iid',
  6483. 'asArray' => true
  6484. ) );
  6485. // 发票邮寄
  6486. $post = $invoice->getOne ( array (
  6487. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  6488. 'asArray' => TRUE
  6489. ) );
  6490. // 发票打印
  6491. $print = $invoice->getOne ( array (
  6492. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  6493. 'desc' => 'iid',
  6494. 'asArray' => TRUE
  6495. ) );
  6496. // 发票退票 printStatus=1 and
  6497. $untread = $invoice->getOne ( array (
  6498. 'where' => " untreadStatus=1 and status=2 ",
  6499. 'asArray' => TRUE
  6500. ) );
  6501. $new = array (
  6502. 'GLOBAL' => FALSE,
  6503. 'pendingInvoice' => FALSE,
  6504. // 'myClaim' => FALSE,
  6505. 'approval' => FALSE,
  6506. 'post' => FALSE,
  6507. 'print' => FALSE,
  6508. 'untread' => FALSE
  6509. );
  6510. // || ! empty ( $myClaim )
  6511. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  6512. $new ['GLOBAL'] = TRUE;
  6513. if (! empty ( $pendingInvoice ))
  6514. $new ['pendingInvoice'] = TRUE;
  6515. // if (! empty ( $myClaim ))
  6516. // $new ['myClaim'] = TRUE;
  6517. if (! empty ( $approval ))
  6518. $new ['approval'] = TRUE;
  6519. if (! empty ( $post ))
  6520. $new ['post'] = TRUE;
  6521. if (! empty ( $print ))
  6522. $new ['print'] = TRUE;
  6523. if (! empty ( $untread ))
  6524. $new ['untread'] = TRUE;
  6525. return $new;
  6526. }
  6527. function setWXMsg($rid, $typeMsg = '') {
  6528. Doo::loadModel ( 'invoice' );
  6529. $invoice = new invoice ();
  6530. $invoiceDetail = $invoice->getOne ( array (
  6531. 'where' => 'iid=' . $rid,
  6532. 'asArray' => true
  6533. ) );
  6534. if (! empty ( $invoiceDetail )) {
  6535. Doo::loadModel ( 'staff' );
  6536. $staff = new staff ();
  6537. $staffmsg = $staff->getOne ( array (
  6538. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  6539. 'asArray' => TRUE
  6540. ) );
  6541. if (! empty ( $staffmsg ['wxid'] )) {
  6542. require_once (SITE_PATH . '/protected/class/client.php');
  6543. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  6544. $user = $staffmsg ['wxid'];
  6545. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  6546. if (empty ( $expCom ))
  6547. $expCom [0] = '';
  6548. $msg = "";
  6549. if (empty ( $typeMsg ))
  6550. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  6551. elseif ($typeMsg == "PRINT")
  6552. $msg = '太好了,您的发票已打印完成。';
  6553. $result = $client->SendMsg ( $user, $msg, 'text' );
  6554. }
  6555. }
  6556. }
  6557. /**
  6558. * 获取微信部门
  6559. * @param string $category
  6560. * @return number|mixed
  6561. */
  6562. function getToparty($category = '') {
  6563. $token = $this->getAccessToken (); //
  6564. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  6565. $toparty = 0;
  6566. foreach ( $result ['department'] as $key => $value ) {
  6567. if ($value ['name'] == $category)
  6568. $toparty = $value ['id'];
  6569. }
  6570. return $toparty;
  6571. }
  6572. /**
  6573. * 获得某部门下的用户
  6574. * @param string $toparty
  6575. */
  6576. function getUserByToparty($toparty = '') {
  6577. $token = $this->getAccessToken (); //
  6578. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  6579. $userList = array ();
  6580. foreach ( $result ['userlist'] as $key => $value ) {
  6581. array_push ( $userList, "'" . $value ['userid'] . "'" );
  6582. }
  6583. return $userList;
  6584. }
  6585. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  6586. $token = $this->getAccessToken ();
  6587. if ($text == 'text') {
  6588. $data = '{
  6589. "touser": "' . $toparty . '",
  6590. "toparty": "",
  6591. "totag": "",
  6592. "msgtype": "text",
  6593. "agentid": 1000002,
  6594. "text": {
  6595. "content": "' . $msg . '"
  6596. },
  6597. "safe":0
  6598. }';
  6599. }
  6600. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6601. if ($result->errmsg != 'ok') {
  6602. return 0;
  6603. } else {
  6604. return 1;
  6605. }
  6606. }
  6607. /**
  6608. * 获得可以发送微信用户列表
  6609. * @param string $category
  6610. * @return string
  6611. */
  6612. function getWxidByCategory($category = "") {
  6613. if (empty ( $category ))
  6614. return "";
  6615. Doo::loadModel ( 'staff' );
  6616. $staff = new staff ();
  6617. $toparty = $this->getToparty ( $category );
  6618. $wxList = array ();
  6619. $wxString = "";
  6620. if (! empty ( $toparty )) {
  6621. $userList = $this->getUserByToparty ( $toparty );
  6622. $userCon = implode ( ',', $userList );
  6623. // echo $userCon;
  6624. $sidList = $staff->getStaffByWxid ( $userCon );
  6625. foreach ( $sidList as $key => $value ) {
  6626. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  6627. if ($falg) {
  6628. array_push ( $wxList, $value ['wxid'] );
  6629. }
  6630. }
  6631. $wxString = implode ( '|', $wxList );
  6632. }
  6633. return $wxString;
  6634. }
  6635. /**
  6636. * 读取发送信息规则判断是否需要发送
  6637. * @param number $sid
  6638. * @param string $sendType
  6639. * @return boolean
  6640. */
  6641. function isSendNotification($sid = 0, $sendType = '') {
  6642. Doo::loadModel ( "notificationConf" );
  6643. $notificationConf = new notificationConf ();
  6644. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  6645. $conf = array ();
  6646. $sendFlag = true;
  6647. if (! empty ( $detail )) {
  6648. $conf = json_decode ( $detail ['conf'], true );
  6649. if (! empty ( $sendType )) {
  6650. if (isset ( $conf [$sendType] )) {
  6651. if ($conf [$sendType] == "CLOSE")
  6652. $sendFlag = false;
  6653. elseif ($conf [$sendType] == "Weekend") {
  6654. $day = date ( "w" );
  6655. if (1 <= $day && 5 >= $day)
  6656. $sendFlag = false;
  6657. } elseif ($conf [$sendType] == "OneToFriday") {
  6658. $day = date ( "w" );
  6659. if (0 == $day || 6 == $day)
  6660. $sendFlag = false;
  6661. }
  6662. }
  6663. } else
  6664. $sendFlag = false;
  6665. }
  6666. return $sendFlag;
  6667. }
  6668. /**
  6669. * 根据规则发送信息
  6670. * @param unknown $msg
  6671. * @param unknown $title
  6672. * @param unknown $url
  6673. * @param unknown $user
  6674. * @param string $text
  6675. * @return number
  6676. */
  6677. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  6678. $token = $this->getAccessToken ();
  6679. $falg = $this->isSendNotification ( $sid, $sendType );
  6680. // if ($text == 'text') {
  6681. // $data = '{
  6682. // "touser": "' . $user . '",
  6683. // "toparty": "",
  6684. // "totag": "",
  6685. // "msgtype": "text",
  6686. // "agentid": 1000002,
  6687. // "text": {
  6688. // "content": "' . $msg . '"
  6689. // },
  6690. // "safe":0
  6691. // }';
  6692. // } else {
  6693. $data = '{
  6694. "touser": "' . $user . '",
  6695. "toparty": "",
  6696. "totag": "",
  6697. "msgtype": "news",
  6698. "agentid": 1000002,
  6699. "news": {
  6700. "articles":[
  6701. {
  6702. "title": "' . $title . '",
  6703. "description": "' . $msg . '",
  6704. "url": "' . $url . '",
  6705. "picurl": ""
  6706. }
  6707. ]
  6708. }
  6709. }';
  6710. // }
  6711. if ($falg) {
  6712. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6713. if ($result->errmsg != 'ok') {
  6714. return 0;
  6715. } else {
  6716. return 1;
  6717. }
  6718. } else
  6719. return 0;
  6720. }
  6721. private function getAccessToken() {
  6722. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  6723. // $file = './access_token.txt';
  6724. // $data = json_decode ( file_get_contents ( $file ) );
  6725. // if ($data->expire_time < time () or ! $data->expire_time) {
  6726. // 如果是企业号用以下URL获取access_token
  6727. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  6728. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  6729. $res = json_decode ( $this->httpGet ( $url ) );
  6730. $access_token = $res->access_token;
  6731. // echo $access_token;
  6732. // if ($access_token) {
  6733. // $data->expire_time = time () + 7000;
  6734. // $data->access_token = $access_token;
  6735. // $fp = fopen ( $file, "w" );
  6736. // fwrite ( $fp, json_encode ( $data ) );
  6737. // fclose ( $fp );
  6738. // }
  6739. // } else {
  6740. // $access_token = $data->access_token;
  6741. // }
  6742. return $access_token;
  6743. }
  6744. private function httpGet($url) {
  6745. $curl = curl_init ();
  6746. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6747. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6748. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6749. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6750. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6751. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6752. curl_setopt ( $curl, CURLOPT_URL, $url );
  6753. $res = curl_exec ( $curl );
  6754. curl_close ( $curl );
  6755. return $res;
  6756. }
  6757. private function httpPost($url, $data) {
  6758. $curl = curl_init ();
  6759. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6760. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6761. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6762. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6763. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6764. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6765. curl_setopt ( $curl, CURLOPT_URL, $url );
  6766. curl_setopt ( $curl, CURLOPT_POST, 1 );
  6767. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  6768. $res = curl_exec ( $curl );
  6769. curl_close ( $curl );
  6770. return $res;
  6771. }
  6772. }
  6773. ?>