InvoiceController.php 274 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384
  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. if (! $flag)
  73. die ( 'illegal request' );
  74. }
  75. function __construct() {
  76. if (isset ( $_COOKIE ["staff"] )) {
  77. if (! empty ( $_COOKIE ["staff"] )) {
  78. Doo::loadModel ( 'staff' );
  79. $staff = new staff ();
  80. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  81. $this->ACTION = $uriPartsOrig [1];
  82. $this->data ['new'] = $this->isInvoiceNew ();
  83. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  84. return "/";
  85. }
  86. }
  87. Doo::loadCore ( 'uri/DooUriRouter' );
  88. $router = new DooUriRouter ();
  89. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  90. if ($routeRs ['1'] != "login") {
  91. header ( 'Content-Type:text/html;charset=utf-8' );
  92. @header ( "Location: /login" );
  93. }
  94. }
  95. function testSend() {
  96. // 测试根据规则发送信息 普通发送
  97. // $pendingApprovalsSid = 41;
  98. // Doo::loadModel ( 'staff' );
  99. // $staff = new staff ();
  100. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  101. // // 发送微信审批通知
  102. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  103. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  104. // Doo::loadModel ( 'staff' );
  105. // $staff = new staff ();
  106. // $toparty = $this->getToparty ( '广东办' );
  107. // $wxList = array ();
  108. // if (! empty ( $toparty )) {
  109. // $userList = $this->getUserByToparty ( $toparty );
  110. // $userCon = implode ( ',', $userList );
  111. // // echo $userCon;
  112. // $sidList = $staff->getStaffByWxid ( $userCon );
  113. // foreach ( $sidList as $key => $value ) {
  114. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  115. // if ($falg) {
  116. // array_push ( $wxList, $value ['wxid'] );
  117. // }
  118. // }
  119. // $wxString = implode ( '|', $wxList );
  120. // print_r ( $wxList );
  121. // echo $wxString;
  122. // }
  123. // 测试发送
  124. /*
  125. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  126. */
  127. // print_r ( $userList );
  128. // $msTouser='caipin|outaozhen';
  129. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  130. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  131. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  132. // $toparty= $this->getToparty('广东办');
  133. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  134. // $toparty = 26;
  135. // $msg = '';
  136. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  137. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  138. }
  139. function invoice() {
  140. Doo::loadModel ( 'invoice' );
  141. $invoice = new invoice ();
  142. Doo::loadModel ( 'express' );
  143. $express = new express ();
  144. $expressList = $express->getExpressByAll ();
  145. $this->data ['expressList'] = $expressList;
  146. // Doo::loadModel ( 'invoiceReceivables' );
  147. // $invoiceReceivables = new invoiceReceivables ();
  148. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  149. Doo::loadClass ( 'XDeode' );
  150. $XDeode = new XDeode ( 5 );
  151. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  152. Doo::loadModel ( 'invoiceStatistics' );
  153. $invoiceStatistics = new invoiceStatistics ();
  154. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  155. // 缓存统计结果
  156. $year = date ( "Y" );
  157. $tmp_date = date ( "Ym" );
  158. $tmp_year = substr ( $tmp_date, 0, 4 );
  159. $tmp_mon = substr ( $tmp_date, 4, 2 );
  160. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  161. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  162. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  163. if (is_file ( $path ))
  164. $htm = file_get_contents ( $path );
  165. else
  166. $htm = $this->showCache ( $path, $sid );
  167. $invoiceList = $invoice->getMyInvoice ( $sid );
  168. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  169. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  170. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  171. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  172. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  173. // print_r($myInvoiceUnAccount);
  174. $this->data ['isMonth'] = $isMonth;
  175. $this->data ['htm'] = $htm;
  176. $this->data ['invoiceList'] = $invoiceList;
  177. $this->data ['receivablesList'] = $list;
  178. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  179. $this->data ['memu'] = "invoice";
  180. $this->data ['staff'] = $this->staff;
  181. $this->data ['receiptMemu'] = 'invoice';
  182. $this->render ( "/admin/invoice", $this->data );
  183. }
  184. function invoiceExpress() {
  185. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  186. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  187. $this->data ['expressCom'] = $expressCom;
  188. $this->data ['expressNumber'] = $expressNumber;
  189. $this->render ( "/admin/invoiceExpress", $this->data );
  190. }
  191. function invoiceAdd() {
  192. Doo::loadModel ( 'L_category' );
  193. $lCategory = new L_category ();
  194. $category = $lCategory->find ( array (
  195. 'asArray' => true
  196. ) );
  197. $this->data ['category'] = $category;
  198. $this->data ['memu'] = "invoice";
  199. $this->data ['staff'] = $this->staff;
  200. $this->data ['receiptMemu'] = 'invoice';
  201. $this->render ( "/admin/invoiceAdd", $this->data );
  202. }
  203. /**
  204. * 提交一份开票申请,并记录下操作日志
  205. *
  206. * @since 1.0.0
  207. * @var integer cid 办事处ID
  208. * @var integer invoiceType 发票类型
  209. * @var integer doPost 是否邮寄
  210. * @var integer invoicePrice 开票金额
  211. * @var string invoiceElement 开票内容
  212. * @var string invoiceTitle 发票抬头
  213. * @var string invoiceCompany 单位名称
  214. * @var string TIN 纳税人识别码
  215. * @var string address 注册地址
  216. * @var string phone 注册电话
  217. * @var string bank 开户银行
  218. * @var string bankAccount 银行账户
  219. * @var string recipients 收件人
  220. * @var string recipientsPhone 收件人手机/电话
  221. * @var string recipientsAddress 收件地址
  222. * @var string mailItems 邮寄物品
  223. * @var string remark 备注
  224. * @return string 返回跳转开票主页路径
  225. */
  226. function invoiceAddDo() {
  227. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  228. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  229. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  230. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  231. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  232. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  233. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  234. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  235. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  236. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  237. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  238. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  239. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  240. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  241. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  242. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  243. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  244. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  245. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  246. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  247. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  248. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  249. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  250. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  251. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  252. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  253. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  254. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  255. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  256. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  257. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  258. /*
  259. * $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;
  260. */
  261. if (empty ( $this->staff [0] ))
  262. die ( 'illegal request' );
  263. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  264. Doo::loadModel ( 'invoice' );
  265. $invoice = new invoice ();
  266. Doo::loadModel ( 'L_category' );
  267. $lCategory = new L_category ();
  268. Doo::loadModel ( 'invoiceManage' );
  269. $invoiceManage = new invoiceManage ();
  270. Doo::loadModel ( 'invoiceOperationLog' );
  271. $invoiceOperationLog = new invoiceOperationLog ();
  272. $categoryDetil = $lCategory->getOne ( array (
  273. 'SELECT' => 'title',
  274. 'where' => 'cid=' . $cid,
  275. 'asArray' => true
  276. ) );
  277. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  278. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  279. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  280. // print_r(current($invoiceManageDetail ['staffList']));
  281. // die;
  282. $moldManage = array ();
  283. foreach ( $invoiceManageList as $key => $value ) {
  284. if ($value ['mold'] == '发票打印')
  285. $moldManage [$value ['mold']] = $value ['staffList'];
  286. elseif ($value ['mold'] == '发票邮寄')
  287. $moldManage [$value ['mold']] = $value ['staffList'];
  288. elseif ($value ['mold'] == '发票退票')
  289. $moldManage [$value ['mold']] = $value ['staffList'];
  290. }
  291. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  292. $item = array (
  293. 'cid' => $cid,
  294. 'categoryName' => $categoryDetil ['title'],
  295. 'invoiceElement' => $invoiceElement,
  296. 'invoiceQuantity' => $invoiceQuantity,
  297. 'invoiceUnitPrice' => $invoiceUnitPrice,
  298. 'invoicePrice' => $invoicePrice,
  299. 'invoiceType' => $invoiceType,
  300. 'doPost' => $doPost,
  301. 'status' => 1,
  302. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  303. 'date' => date ( "Y-m-d H:i:s" ),
  304. 'updateTime' => date ( "Y-m-d H:i:s" ),
  305. 'sid' => $this->staff [0] ['sid'],
  306. 'userName' => $this->staff [0] ['username'],
  307. 'invoiceManage' => $invoiceManageDetail ['staff'],
  308. 'pendingApprovals' => $pendingApprovalsSid,
  309. 'moldManage' => json_encode ( $moldManage ),
  310. 'remark' => $remark
  311. );
  312. if ($invoiceType == 0)
  313. $item += array (
  314. 'invoiceTitle' => $invoiceTitle,
  315. 'TIN' => $TINT,
  316. 'address' => $addressT,
  317. 'phone' => $phoneT,
  318. 'bank' => $bankT,
  319. 'bankAccount' => $bankAccountT
  320. );
  321. else {
  322. $item += array (
  323. 'invoiceCompany' => $invoiceCompany,
  324. 'TIN' => $TIN,
  325. 'address' => $address,
  326. 'phone' => $phone,
  327. 'bank' => $bank,
  328. 'bankAccount' => $bankAccount
  329. );
  330. }
  331. if ($doPost == 1) {
  332. $mailList = array (
  333. 'invoice' => 1,
  334. 'mailItems' => $mailItems
  335. );
  336. if (! empty ( $softLock ))
  337. $mailList += array (
  338. 'softLock' => $softLockNum
  339. );
  340. else
  341. $mailList += array (
  342. 'softLock' => 0
  343. );
  344. if (! empty ( $contract ))
  345. $mailList += array (
  346. 'contract' => $contractNum
  347. );
  348. else
  349. $mailList += array (
  350. 'contract' => 0
  351. );
  352. if (! empty ( $instructions ))
  353. $mailList += array (
  354. 'instructions' => $instructionsNum
  355. );
  356. else
  357. $mailList += array (
  358. 'instructions' => 0
  359. );
  360. if (! empty ( $remittance ))
  361. $mailList += array (
  362. 'remittance' => $remittance
  363. );
  364. else
  365. $mailList += array (
  366. 'remittance' => ''
  367. );
  368. $mailString = '发票x1,备注:' . $mailItems;
  369. if (! empty ( $softLock ))
  370. $mailString .= ',软件锁x' . $softLockNum;
  371. if (! empty ( $contract ))
  372. $mailString .= ',合同x' . $contractNum;
  373. if (! empty ( $instructions ))
  374. $mailString .= ',说明书x' . $instructionsNum;
  375. if (! empty ( $remittance ))
  376. $mailString .= ',汇款账号单';
  377. $item += array (
  378. 'recipients' => $recipients,
  379. 'recipientsPhone' => $recipientsPhone,
  380. 'recipientsAddress' => $recipientsAddress,
  381. 'mailItems' => $mailString,
  382. 'mailItemsJson' => json_encode ( $mailList )
  383. );
  384. }
  385. $iid = $invoice->addInvoice ( $item );
  386. $item = array (
  387. 'date' => date ( "Y-m-d H:i:s" ),
  388. 'operation' => "创建",
  389. 'status' => 1,
  390. 'img' => $this->staff [0] ['avatar'],
  391. 'username' => $this->staff [0] ['username'],
  392. 'uid' => $this->staff [0] ['sid'],
  393. 'category' => $this->staff [0] ['category'],
  394. 'iid' => $iid
  395. );
  396. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  397. $item = array (
  398. 'date' => date ( "Y-m-d H:i:s" ),
  399. 'operation' => "提交审批",
  400. 'status' => 1,
  401. 'img' => $this->staff [0] ['avatar'],
  402. 'username' => $this->staff [0] ['username'],
  403. 'uid' => $this->staff [0] ['sid'],
  404. 'category' => $this->staff [0] ['category'],
  405. 'iid' => $iid
  406. );
  407. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  408. Doo::loadModel ( 'staff' );
  409. $staff = new staff ();
  410. $username2 = $staff->getOne ( array (
  411. 'select' => 'wxid',
  412. 'where' => 'sid=' . $pendingApprovalsSid,
  413. 'asArray' => TRUE
  414. ) );
  415. // 发送微信审批通知
  416. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  417. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  418. }
  419. return "/invoice";
  420. }
  421. function invoiceEdit() {
  422. Doo::loadClass ( 'XDeode' );
  423. $XDeode = new XDeode ( 5 );
  424. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  425. $iid = $XDeode->decode ( $iid );
  426. if (! is_numeric ( $iid ))
  427. die ( 'illegal request' );
  428. Doo::loadModel ( 'invoice' );
  429. $invoice = new invoice ();
  430. Doo::loadModel ( 'invoiceOperationLog' );
  431. $invoiceOperationLog = new invoiceOperationLog ();
  432. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  433. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  434. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  435. $this->data ['operation'] = $operation;
  436. $this->data ['invoiceDetail'] = $invoiceDetail;
  437. $this->data ['memu'] = "invoice";
  438. $this->data ['staff'] = $this->staff;
  439. $this->data ['receiptMemu'] = 'invoice';
  440. $this->render ( "/admin/invoiceEdit", $this->data );
  441. }
  442. /**
  443. * 重新编辑退回的发票
  444. * @return string
  445. */
  446. function invoiceEditDo() {
  447. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  448. Doo::loadModel ( 'invoice' );
  449. $invoice = new invoice ();
  450. $iid = $invoice->authcode ( $iidKey );
  451. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  452. die ( 'illegal request' );
  453. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  454. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  455. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  456. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  457. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  458. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  459. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  460. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  461. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  462. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  463. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  464. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  465. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  466. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  467. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  468. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  469. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  470. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  471. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  472. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  473. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  474. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  475. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  476. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  477. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  478. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  479. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  480. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  481. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  482. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  483. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  484. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  485. Doo::loadModel ( 'invoiceManage' );
  486. $invoiceManage = new invoiceManage ();
  487. Doo::loadModel ( 'invoiceOperationLog' );
  488. $invoiceOperationLog = new invoiceOperationLog ();
  489. $cid = explode ( ':', $cid );
  490. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  491. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  492. $moldManage = array ();
  493. foreach ( $invoiceManageList as $key => $value ) {
  494. if ($value ['mold'] == '发票打印')
  495. $moldManage [$value ['mold']] = $value ['staffList'];
  496. elseif ($value ['mold'] == '发票邮寄')
  497. $moldManage [$value ['mold']] = $value ['staffList'];
  498. elseif ($value ['mold'] == '发票打印')
  499. $moldManage [$value ['mold']] = $value ['staffList'];
  500. }
  501. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  502. $item = array (
  503. 'iid' => $iid,
  504. 'cid' => $cid [0],
  505. 'categoryName' => $cid [1],
  506. 'invoiceElement' => $invoiceElement,
  507. 'invoiceQuantity' => $invoiceQuantity,
  508. 'invoiceUnitPrice' => $invoiceUnitPrice,
  509. 'invoicePrice' => $invoicePrice,
  510. 'invoiceType' => $invoiceType,
  511. 'doPost' => $doPost,
  512. 'status' => 1,
  513. 'updateTime' => date ( "Y-m-d H:i:s" ),
  514. 'remark' => $remark
  515. );
  516. if ($invoiceType == 0)
  517. $item += array (
  518. 'invoiceTitle' => $invoiceTitle,
  519. 'TIN' => $TINT,
  520. 'address' => $addressT,
  521. 'phone' => $phoneT,
  522. 'bank' => $bankT,
  523. 'bankAccount' => $bankAccountT
  524. );
  525. else {
  526. $item += array (
  527. 'invoiceCompany' => $invoiceCompany,
  528. 'TIN' => $TIN,
  529. 'address' => $address,
  530. 'phone' => $phone,
  531. 'bank' => $bank,
  532. 'bankAccount' => $bankAccount
  533. );
  534. }
  535. if ($doPost == 1) {
  536. $mailList = array (
  537. 'invoice' => 1,
  538. 'mailItems' => $mailItems
  539. );
  540. if (! empty ( $softLock ))
  541. $mailList += array (
  542. 'softLock' => $softLockNum
  543. );
  544. else
  545. $mailList += array (
  546. 'softLock' => '0'
  547. );
  548. if (! empty ( $contract ))
  549. $mailList += array (
  550. 'contract' => $contractNum
  551. );
  552. else
  553. $mailList += array (
  554. 'contract' => '0'
  555. );
  556. if (! empty ( $instructions ))
  557. $mailList += array (
  558. 'instructions' => $instructionsNum
  559. );
  560. else
  561. $mailList += array (
  562. 'instructions' => '0'
  563. );
  564. if (! empty ( $remittance ))
  565. $mailList += array (
  566. 'remittance' => $remittance
  567. );
  568. else
  569. $mailList += array (
  570. 'remittance' => ''
  571. );
  572. $mailString = '发票x1,备注:' . $mailItems;
  573. if (! empty ( $softLock ))
  574. $mailString .= ',软件锁x' . $softLockNum;
  575. if (! empty ( $contract ))
  576. $mailString .= ',合同x' . $contractNum;
  577. if (! empty ( $instructions ))
  578. $mailString .= ',说明书x' . $instructionsNum;
  579. if (! empty ( $remittance ))
  580. $mailString .= ',汇款账号单';
  581. $item += array (
  582. 'recipients' => $recipients,
  583. 'recipientsPhone' => $recipientsPhone,
  584. 'recipientsAddress' => $recipientsAddress,
  585. 'mailItems' => $mailString,
  586. 'mailItemsJson' => json_encode ( $mailList )
  587. );
  588. }
  589. $invoice->setInvoiceByCondition ( $item );
  590. $item = array (
  591. 'date' => date ( "Y-m-d H:i:s" ),
  592. 'operation' => "重新提交审批",
  593. 'status' => 1,
  594. 'img' => $this->staff [0] ['avatar'],
  595. 'username' => $this->staff [0] ['username'],
  596. 'uid' => $this->staff [0] ['sid'],
  597. 'category' => $this->staff [0] ['category'],
  598. 'iid' => $iid
  599. );
  600. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  601. }
  602. return "/invoice";
  603. }
  604. /**
  605. * 培训班
  606. */
  607. function invoiceTraining() {
  608. Doo::loadModel ( 'L_category' );
  609. $lCategory = new L_category ();
  610. Doo::loadModel ( 'invoiceTraining' );
  611. $invoiceTraining = new invoiceTraining ();
  612. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  613. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  614. $category = $lCategory->getCategory ();
  615. $itid = array ();
  616. foreach ( $itTodoList as $value ) {
  617. array_push ( $itid, $value ['itid'] );
  618. }
  619. foreach ( $itedList as $value ) {
  620. array_push ( $itid, $value ['itid'] );
  621. }
  622. $itid = implode ( ',', $itid );
  623. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  624. // print_r($itTodoList);
  625. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  626. $this->data ['itTodoList'] = $itTodoList;
  627. $this->data ['itedList'] = $itedList;
  628. $this->data ['category'] = $category;
  629. $this->data ['memu'] = "invoice";
  630. $this->data ['staff'] = $this->staff;
  631. $this->data ['receiptMemu'] = 'invoiceTraining';
  632. $this->render ( "/admin/invoiceTraining", $this->data );
  633. }
  634. /**
  635. * 创建培训班
  636. */
  637. function invoiceTrainingAdd() {
  638. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  639. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  640. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  641. if (empty ( $this->staff [0] ))
  642. die ( 'illegal request' );
  643. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  644. Doo::loadModel ( 'invoiceTraining' );
  645. $invoiceTraining = new invoiceTraining ();
  646. Doo::loadModel ( 'invoice' );
  647. $invoice = new invoice ();
  648. Doo::loadModel ( 'L_category' );
  649. $lCategory = new L_category ();
  650. Doo::loadModel ( 'invoiceManage' );
  651. $invoiceManage = new invoiceManage ();
  652. Doo::loadModel ( 'invoiceOperationLog' );
  653. $invoiceOperationLog = new invoiceOperationLog ();
  654. $item = array (
  655. 'cid' => $cid,
  656. 'trainName' => $trainName,
  657. 'trainDate' => $trainDate,
  658. 'creator' => $this->staff [0] ['sid'],
  659. 'creatorDate' => date ( "Y-m-d H:i:s" )
  660. );
  661. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  662. }
  663. return "/invoiceTraining";
  664. }
  665. /**
  666. * 删除培训班
  667. */
  668. function invoiceTrainingDelDo() {
  669. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  670. if (! empty ( $itid )) {
  671. Doo::loadModel ( 'invoiceTraining' );
  672. $invoiceTraining = new invoiceTraining ();
  673. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  674. }
  675. return "/invoiceTraining";
  676. }
  677. /**
  678. * 培训班详情
  679. */
  680. function invoiceTrainingDetail() {
  681. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  682. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  683. Doo::loadModel ( 'invoiceTraining' );
  684. $invoiceTraining = new invoiceTraining ();
  685. Doo::loadModel ( 'invoiceStore' );
  686. $invoiceStore = new invoiceStore ();
  687. if (empty ( $itid ))
  688. die ( 'illegal request' );
  689. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  690. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid );
  691. // print_r($isList);
  692. $trainlist = array ();
  693. foreach ( $isList as $key => $value ) {
  694. $irDetail = array ();
  695. if ($value ['apStatus'] == 1) {
  696. // array_push ( $irDetail, '' );
  697. array_push ( $irDetail, '<input class="hide" disabled type="checkbox" >' );
  698. } else {
  699. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  700. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  701. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  702. }
  703. array_push ( $irDetail, $value ['invoiceSerial'] );
  704. if ($value ['invoiceType'] == 1)
  705. array_push ( $irDetail, $value ['invoiceCompany'] );
  706. else
  707. array_push ( $irDetail, $value ['invoiceTitle'] );
  708. array_push ( $irDetail, $value ['TIN'] );
  709. array_push ( $irDetail, $value ['userName'] );
  710. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  711. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  712. } else
  713. array_push ( $irDetail, $value ['mailItems'] );
  714. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  715. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  716. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  717. array_push ( $irDetail, $value ['invoiceElement'] );
  718. array_push ( $irDetail, $value ['invoiceQuantity'] );
  719. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  720. if ($value ['invoiceType'] == 1)
  721. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  722. else
  723. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  724. array_push ( $irDetail, $value ['remark'] );
  725. if ($value ['status'] == 1)
  726. array_push ( $irDetail, '审批中' );
  727. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  728. array_push ( $irDetail, '已出票' );
  729. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  730. array_push ( $irDetail, '已入账' );
  731. else
  732. array_push ( $irDetail, '' );
  733. array_push ( $irDetail, $value ['invoiceNo'] );
  734. array_push ( $irDetail, $value ['printTime'] );
  735. $html = '';
  736. foreach ( $value ['invoiceReceivables'] as $value ) {
  737. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  738. }
  739. array_push ( $irDetail, $html );
  740. array_push ( $trainlist, $irDetail );
  741. }
  742. $trainlistJson = json_encode ( $trainlist );
  743. if (empty ( $detail ))
  744. die ( 'illegal request' );
  745. $this->data ['trainStatus'] = $trainStatus;
  746. $this->data ['itid'] = $itid;
  747. $this->data ['trainlistJson'] = $trainlistJson;
  748. $this->data ['iTrainDetail'] = $detail;
  749. $this->data ['memu'] = "invoice";
  750. $this->data ['staff'] = $this->staff;
  751. $this->data ['receiptMemu'] = 'invoiceTraining';
  752. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  753. }
  754. /**
  755. * 上传培训班发票
  756. * @return string
  757. */
  758. function invoiceTrainingUpload() {
  759. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  760. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  761. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  762. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  763. header ( "HTTP/1.1 500 Internal Server Error" );
  764. echo "POST exceeded maximum allowed size.";
  765. exit ( 0 );
  766. }
  767. // Settings
  768. $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)
  769. $upload_name = "Filedata";
  770. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  771. $extension_whitelist = array (
  772. "doc",
  773. "txt",
  774. "jpg",
  775. "gif",
  776. "png"
  777. ); // Allowed file extensions
  778. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  779. // Other variables
  780. $MAX_FILENAME_LENGTH = 260;
  781. $file_name = "";
  782. $file_extension = "";
  783. $uploadErrors = array (
  784. 0 => "文件上传成功",
  785. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  786. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  787. 3 => "上传的文件仅为部分文件",
  788. 4 => "没有文件上传",
  789. 6 => "缺少临时文件夹"
  790. );
  791. $nk = time ();
  792. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  793. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  794. echo "文件无法保存.";
  795. exit ( 0 );
  796. }
  797. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  798. echo json_encode ( array (
  799. 'filename' => $file_name,
  800. 'id' => $nk
  801. ) );
  802. exit ( 0 );
  803. }
  804. /**
  805. * 导入发票临时仓库
  806. */
  807. function invoiceStoreImport() {
  808. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  809. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  810. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  811. if ($path != "" && ! empty ( $trainingKey )) {
  812. Doo::loadModel ( 'invoiceStore' );
  813. Doo::loadModel ( 'staff' );
  814. $staff = new staff ();
  815. Doo::loadModel ( 'invoiceTraining' );
  816. $invoiceTraining = new invoiceTraining ();
  817. Doo::loadClass ( 'XDeode' );
  818. $XDeode = new XDeode ( 5 );
  819. $itid = $XDeode->decode ( $trainingKey );
  820. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  821. $userName = $this->staff [0] ['username'];
  822. $sDetail = $staff->getStaffByName ( $userName );
  823. // die('sdd');
  824. // 可以优化
  825. foreach ( $exlArray as $key => $value ) {
  826. // 开票
  827. $invoice = new invoiceStore ();
  828. $invoice->trainId = $itid;
  829. $invoice->invoiceType = 0;
  830. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  831. $invoice->invoiceType = 1;
  832. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  833. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  834. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  835. $invoice->invoiceTitle = $value ['invoiceTitle'];
  836. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  837. $invoice->invoiceCompany = $value ['invoiceTitle'];
  838. $invoice->userName = $userName;
  839. $invoice->sid = $sDetail ['sid'];
  840. $invoice->cid = $sDetail ['cid'];
  841. $invoice->categoryName = $sDetail ['category'];
  842. $invoice->invoiceElement = $value ['invoiceElement'];
  843. $invoice->remark = $value ['remark'];
  844. // $invoice->date = $value ['date'];
  845. // $invoice->printTime = $value ['date'];
  846. $invoice->ipSource = 1;
  847. $invoice->printStatus = 1;
  848. $invoice->status = 2;
  849. $invoice->postStatus = 1;
  850. $invoice->untreadStatus = 0;
  851. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  852. $invoice->TIN = $value ['TIN'];
  853. $invoice->address = $value ['address'];
  854. $invoice->phone = $value ['phone'];
  855. $invoice->bank = $value ['bank'];
  856. $invoice->bankAccount = $value ['bankAccount'];
  857. $invoice->recipientsAddress = $value ['recipientsAddress'];
  858. $invoice->recipients = $value ['recipients'];
  859. $invoice->recipientsPhone = $value ['recipientsPhone'];
  860. $iid = $invoice->insert ();
  861. }
  862. // 加入发票总数量
  863. $item = array (
  864. 'itid' => $itid,
  865. 'invoiceTotal' => count ( $exlArray )
  866. );
  867. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  868. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  869. }
  870. echo 'no file';
  871. }
  872. /**
  873. * 编辑仓库里的发票
  874. */
  875. function invoiceStoreEdit() {
  876. Doo::loadClass ( 'XDeode' );
  877. $XDeode = new XDeode ( 5 );
  878. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  879. $iid = $XDeode->decode ( $iid );
  880. if (! is_numeric ( $iid ))
  881. die ( 'illegal request' );
  882. Doo::loadModel ( 'invoiceStore' );
  883. $invoiceStore = new invoiceStore ();
  884. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  885. // print_r($invoiceDetail);
  886. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  887. $this->data ['invoiceDetail'] = $invoiceDetail;
  888. $this->data ['memu'] = "invoice";
  889. $this->data ['staff'] = $this->staff;
  890. $this->data ['receiptMemu'] = 'invoiceTraining';
  891. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  892. }
  893. function invoiceStoreEditDo() {
  894. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  895. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  896. Doo::loadModel ( 'invoiceStore' );
  897. $invoice = new invoiceStore ();
  898. Doo::loadClass ( 'XDeode' );
  899. $XDeode = new XDeode ( 5 );
  900. $iid = $XDeode->decode ( $storeKey );
  901. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  902. die ( 'illegal request' );
  903. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  904. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  905. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  906. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  907. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  908. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  909. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  910. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  911. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  912. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  913. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  914. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  915. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  916. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  917. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  918. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  919. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  920. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  921. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  922. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  923. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  924. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  925. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  926. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  927. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  928. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  929. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  930. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  931. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  932. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  933. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  934. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  935. $cid = explode ( ':', $cid );
  936. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  937. $item = array (
  938. 'isid' => $iid,
  939. 'cid' => $cid [0],
  940. 'categoryName' => $cid [1],
  941. 'invoiceElement' => $invoiceElement,
  942. 'invoiceQuantity' => $invoiceQuantity,
  943. 'invoiceUnitPrice' => $invoiceUnitPrice,
  944. 'invoicePrice' => $invoicePrice,
  945. 'invoiceType' => $invoiceType,
  946. 'doPost' => $doPost,
  947. 'status' => 1,
  948. 'updateTime' => date ( "Y-m-d H:i:s" ),
  949. 'remark' => $remark
  950. );
  951. if ($invoiceType == 0)
  952. $item += array (
  953. 'invoiceTitle' => $invoiceTitle,
  954. 'TIN' => $TINT,
  955. 'address' => $addressT,
  956. 'phone' => $phoneT,
  957. 'bank' => $bankT,
  958. 'bankAccount' => $bankAccountT
  959. );
  960. else {
  961. $item += array (
  962. 'invoiceCompany' => $invoiceCompany,
  963. 'TIN' => $TIN,
  964. 'address' => $address,
  965. 'phone' => $phone,
  966. 'bank' => $bank,
  967. 'bankAccount' => $bankAccount
  968. );
  969. }
  970. if ($doPost == 1) {
  971. $mailList = array (
  972. 'invoice' => 1,
  973. 'mailItems' => $mailItems
  974. );
  975. if (! empty ( $softLock ))
  976. $mailList += array (
  977. 'softLock' => $softLockNum
  978. );
  979. else
  980. $mailList += array (
  981. 'softLock' => '0'
  982. );
  983. if (! empty ( $contract ))
  984. $mailList += array (
  985. 'contract' => $contractNum
  986. );
  987. else
  988. $mailList += array (
  989. 'contract' => '0'
  990. );
  991. if (! empty ( $instructions ))
  992. $mailList += array (
  993. 'instructions' => $instructionsNum
  994. );
  995. else
  996. $mailList += array (
  997. 'instructions' => '0'
  998. );
  999. if (! empty ( $remittance ))
  1000. $mailList += array (
  1001. 'remittance' => $remittance
  1002. );
  1003. else
  1004. $mailList += array (
  1005. 'remittance' => ''
  1006. );
  1007. $mailString = '发票x1,备注:' . $mailItems;
  1008. if (! empty ( $softLock ))
  1009. $mailString .= ',软件锁x' . $softLockNum;
  1010. if (! empty ( $contract ))
  1011. $mailString .= ',合同x' . $contractNum;
  1012. if (! empty ( $instructions ))
  1013. $mailString .= ',说明书x' . $instructionsNum;
  1014. if (! empty ( $remittance ))
  1015. $mailString .= ',汇款账号单';
  1016. $item += array (
  1017. 'recipients' => $recipients,
  1018. 'recipientsPhone' => $recipientsPhone,
  1019. 'recipientsAddress' => $recipientsAddress,
  1020. 'mailItems' => $mailString,
  1021. 'mailItemsJson' => json_encode ( $mailList )
  1022. );
  1023. }
  1024. $invoice->setInvoiceStoreByCondition ( $item );
  1025. }
  1026. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1027. }
  1028. /**
  1029. *
  1030. * @return string
  1031. */
  1032. function invoiceStoreDelete() {
  1033. Doo::loadClass ( 'XDeode' );
  1034. $XDeode = new XDeode ( 5 );
  1035. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1036. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1037. $isid = $XDeode->decode ( $iStoreKey );
  1038. $itid = $XDeode->decode ( $trainKey );
  1039. if (! is_numeric ( $isid ))
  1040. die ( 'illegal request' );
  1041. Doo::loadModel ( 'invoiceStore' );
  1042. $invoiceStore = new invoiceStore ();
  1043. $invoiceStore->delete ( array (
  1044. 'where' => 'isid=' . $isid,
  1045. 'limit' => 1
  1046. ) );
  1047. Doo::loadModel ( 'invoiceTraining' );
  1048. $invoiceTraining = new invoiceTraining ();
  1049. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1050. $item = array (
  1051. 'itid' => $itid,
  1052. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1053. );
  1054. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1055. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1056. }
  1057. /**
  1058. * 批量删除库里发票
  1059. */
  1060. function invoiceStoreBatchDelete() {
  1061. Doo::loadClass ( 'XDeode' );
  1062. $XDeode = new XDeode ( 5 );
  1063. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1064. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1065. $tid = $XDeode->decode ( $trainKey );
  1066. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1067. die ( 'illegal request' );
  1068. Doo::loadModel ( 'invoiceStore' );
  1069. $isidKeyList = explode ( ',', $storeKey );
  1070. $isidList = array ();
  1071. foreach ( $isidKeyList as $value ) {
  1072. $isid = $XDeode->decode ( $value );
  1073. if (! empty ( $isid ) && is_numeric ( $isid ))
  1074. array_push ( $isidList, $isid );
  1075. }
  1076. $isidString = implode ( ',', $isidList );
  1077. $invoiceStore = new invoiceStore ();
  1078. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1079. $isidList = array ();
  1080. foreach ( $isList as $key => $value ) {
  1081. if ($value ['apStatus'] == 0)
  1082. array_push ( $isidList, $value ['isid'] );
  1083. }
  1084. $isidString = implode ( ',', $isidList );
  1085. // print_r($isList);
  1086. // echo $isidString;
  1087. $invoiceStore = new invoiceStore ();
  1088. $invoiceStore->delete ( array (
  1089. 'where' => "isid in ( " . $isidString . ")",
  1090. 'asArray' => TRUE
  1091. ) );
  1092. Doo::loadModel ( 'invoiceTraining' );
  1093. $invoiceTraining = new invoiceTraining ();
  1094. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1095. $item = array (
  1096. 'itid' => $tid,
  1097. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1098. );
  1099. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1100. // echo $tid;
  1101. // echo $storeKey;
  1102. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1103. }
  1104. /**
  1105. * 仓库发票提交审批
  1106. * @return string
  1107. */
  1108. function invoiceStoreApproval() {
  1109. Doo::loadClass ( 'XDeode' );
  1110. $XDeode = new XDeode ( 5 );
  1111. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1112. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1113. $isid = $XDeode->decode ( $iStoreKey );
  1114. $trainId = $XDeode->decode ( $trainKey );
  1115. if (! is_numeric ( $isid ))
  1116. die ( 'illegal request' );
  1117. Doo::loadModel ( 'invoiceStore' );
  1118. Doo::loadModel ( 'invoice' );
  1119. $invoice = new invoice ();
  1120. // 加入限制必须填写入开票内容和邮寄物品
  1121. $invoiceStore = new invoiceStore ();
  1122. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1123. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1124. header ( 'Content-Type:text/html;charset=utf-8' );
  1125. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1126. }
  1127. // 拷贝插入一条发票数据
  1128. $invoiceStore = new invoiceStore ();
  1129. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1130. $invoiceStore = new invoiceStore ();
  1131. $item = array (
  1132. 'isid' => $isid,
  1133. 'iid' => $iid,
  1134. 'apStatus' => 1
  1135. );
  1136. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1137. Doo::loadModel ( 'invoiceManage' );
  1138. $invoiceManage = new invoiceManage ();
  1139. Doo::loadModel ( 'invoiceOperationLog' );
  1140. $invoiceOperationLog = new invoiceOperationLog ();
  1141. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1142. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1143. $moldManage = array ();
  1144. foreach ( $invoiceManageList as $key => $value ) {
  1145. if ($value ['mold'] == '发票打印')
  1146. $moldManage [$value ['mold']] = $value ['staffList'];
  1147. elseif ($value ['mold'] == '发票邮寄')
  1148. $moldManage [$value ['mold']] = $value ['staffList'];
  1149. elseif ($value ['mold'] == '发票退票')
  1150. $moldManage [$value ['mold']] = $value ['staffList'];
  1151. }
  1152. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1153. $item = array (
  1154. 'iid' => $iid,
  1155. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1156. 'date' => date ( "Y-m-d H:i:s" ),
  1157. 'status' => 1,
  1158. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1159. 'trainId' => $trainId,
  1160. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1161. 'moldManage' => json_encode ( $moldManage ),
  1162. 'pendingApprovals' => $pendingApprovalsSid
  1163. );
  1164. $invoice->setInvoiceByCondition ( $item );
  1165. Doo::loadModel ( 'invoiceTraining' );
  1166. $invoiceTraining = new invoiceTraining ();
  1167. $item = array (
  1168. 'itid' => $trainId,
  1169. 'submitStatus' => 1
  1170. );
  1171. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1172. $item = array (
  1173. 'date' => date ( "Y-m-d H:i:s" ),
  1174. 'operation' => "创建",
  1175. 'status' => 1,
  1176. 'img' => $this->staff [0] ['avatar'],
  1177. 'username' => $this->staff [0] ['username'],
  1178. 'uid' => $this->staff [0] ['sid'],
  1179. 'category' => $this->staff [0] ['category'],
  1180. 'iid' => $iid
  1181. );
  1182. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1183. $item = array (
  1184. 'date' => date ( "Y-m-d H:i:s" ),
  1185. 'operation' => "提交审批",
  1186. 'status' => 1,
  1187. 'img' => $this->staff [0] ['avatar'],
  1188. 'username' => $this->staff [0] ['username'],
  1189. 'uid' => $this->staff [0] ['sid'],
  1190. 'category' => $this->staff [0] ['category'],
  1191. 'iid' => $iid
  1192. );
  1193. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1194. Doo::loadModel ( 'staff' );
  1195. $staff = new staff ();
  1196. $username2 = $staff->getOne ( array (
  1197. 'select' => 'wxid',
  1198. 'where' => 'sid=' . $pendingApprovalsSid,
  1199. 'asArray' => TRUE
  1200. ) );
  1201. // 发送微信审批通知
  1202. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1203. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1204. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1205. }
  1206. /**
  1207. * 批量提交发票
  1208. * @return string
  1209. */
  1210. function invoiceStoreBatchApproval() {
  1211. Doo::loadClass ( 'XDeode' );
  1212. $XDeode = new XDeode ( 5 );
  1213. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1214. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1215. $trainId = $XDeode->decode ( $trainKey );
  1216. $isidKeyList = explode ( ',', $storeKey );
  1217. $isidList = array ();
  1218. foreach ( $isidKeyList as $value ) {
  1219. $isid = $XDeode->decode ( $value );
  1220. if (! empty ( $isid ) && is_numeric ( $isid ))
  1221. array_push ( $isidList, $isid );
  1222. }
  1223. $isidString = implode ( ',', $isidList );
  1224. if (! is_numeric ( $trainId ))
  1225. die ( 'illegal request' );
  1226. Doo::loadModel ( 'invoiceStore' );
  1227. Doo::loadModel ( 'invoice' );
  1228. // 判断哪些已经加入审批过
  1229. // 加入限制必须填写入开票内容和邮寄物品
  1230. $invoiceStore = new invoiceStore ();
  1231. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1232. foreach ( $isList as $key => $value ) {
  1233. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1234. header ( 'Content-Type:text/html;charset=utf-8' );
  1235. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1236. }
  1237. }
  1238. // 拷贝插入一条发票数据
  1239. $invoiceStore = new invoiceStore ();
  1240. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1241. $invoiceStore = new invoiceStore ();
  1242. $item = array (
  1243. 'apStatus' => 1
  1244. );
  1245. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1246. // 获得正式发票ID
  1247. $invoice = new invoice ();
  1248. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1249. $sqlList = array ();
  1250. $iidString = '';
  1251. $iida = array ();
  1252. foreach ( $iidList as $key => $value ) {
  1253. $sqlList [$value ['isid']] = $value ['iid'];
  1254. array_push ( $iida, $value ['iid'] );
  1255. }
  1256. $iidString = implode ( ',', $iida );
  1257. $ids = implode ( ',', array_keys ( $sqlList ) );
  1258. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1259. foreach ( $sqlList as $id => $ordinal ) {
  1260. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1261. }
  1262. $sql .= "END WHERE isid IN ($ids)";
  1263. $invoiceStore = new invoiceStore ();
  1264. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1265. Doo::loadModel ( 'invoiceManage' );
  1266. $invoiceManage = new invoiceManage ();
  1267. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1268. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1269. $moldManage = array ();
  1270. foreach ( $invoiceManageList as $key => $value ) {
  1271. if ($value ['mold'] == '发票打印')
  1272. $moldManage [$value ['mold']] = $value ['staffList'];
  1273. elseif ($value ['mold'] == '发票邮寄')
  1274. $moldManage [$value ['mold']] = $value ['staffList'];
  1275. elseif ($value ['mold'] == '发票退票')
  1276. $moldManage [$value ['mold']] = $value ['staffList'];
  1277. }
  1278. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1279. // 批量更新发票信息
  1280. $item = array (
  1281. 'date' => date ( "Y-m-d H:i:s" ),
  1282. 'status' => 1,
  1283. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1284. 'trainId' => $trainId,
  1285. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1286. 'moldManage' => json_encode ( $moldManage ),
  1287. 'pendingApprovals' => $pendingApprovalsSid
  1288. );
  1289. $invoice = new invoice ();
  1290. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1291. // 批量更新发票序列号
  1292. $sqlList = array ();
  1293. foreach ( $iida as $value ) {
  1294. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1295. }
  1296. $ids = implode ( ',', array_keys ( $sqlList ) );
  1297. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1298. foreach ( $sqlList as $id => $ordinal ) {
  1299. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1300. }
  1301. $sql .= "END WHERE iid IN ($ids)";
  1302. $invoiceStore = new invoiceStore ();
  1303. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1304. // 批量生产操作日志
  1305. Doo::loadModel ( 'invoiceOperationLog' );
  1306. $sqlList = array ();
  1307. foreach ( $iida as $key => $value ) {
  1308. $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 . '"),
  1309. ("' . 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 . '") ';
  1310. array_push ( $sqlList, $sql );
  1311. }
  1312. $iolSql = implode ( ',', $sqlList );
  1313. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1314. $invoiceOperationLog = new invoiceOperationLog ();
  1315. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1316. Doo::loadModel ( 'invoiceTraining' );
  1317. $invoiceTraining = new invoiceTraining ();
  1318. $item = array (
  1319. 'itid' => $trainId,
  1320. 'submitStatus' => 1
  1321. );
  1322. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1323. Doo::loadModel ( 'staff' );
  1324. $staff = new staff ();
  1325. $username2 = $staff->getOne ( array (
  1326. 'select' => 'wxid',
  1327. 'where' => 'sid=' . $pendingApprovalsSid,
  1328. 'asArray' => TRUE
  1329. ) );
  1330. // 发送微信审批通知
  1331. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1332. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1333. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1334. }
  1335. /**
  1336. */
  1337. function invoiceStoreMailItemSet() {
  1338. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1339. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1340. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1341. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1342. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1343. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1344. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1345. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1346. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1347. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1348. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1349. Doo::loadClass ( 'XDeode' );
  1350. $XDeode = new XDeode ( 5 );
  1351. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1352. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1353. $isid = $XDeode->decode ( $storeKey );
  1354. $trainId = $XDeode->decode ( $trainKey );
  1355. if (! is_numeric ( $isid ))
  1356. die ( 'illegal request' );
  1357. Doo::loadModel ( 'invoiceStore' );
  1358. $invoiceStore = new invoiceStore ();
  1359. $mailList = array (
  1360. 'invoice' => 1,
  1361. 'mailItems' => $mailItems
  1362. );
  1363. if (! empty ( $softLock ))
  1364. $mailList += array (
  1365. 'softLock' => $softLockNum
  1366. );
  1367. else
  1368. $mailList += array (
  1369. 'softLock' => 0
  1370. );
  1371. if (! empty ( $contract ))
  1372. $mailList += array (
  1373. 'contract' => $contractNum
  1374. );
  1375. else
  1376. $mailList += array (
  1377. 'contract' => 0
  1378. );
  1379. if (! empty ( $instructions ))
  1380. $mailList += array (
  1381. 'instructions' => $instructionsNum
  1382. );
  1383. else
  1384. $mailList += array (
  1385. 'instructions' => 0
  1386. );
  1387. if (! empty ( $remittance ))
  1388. $mailList += array (
  1389. 'remittance' => $remittance
  1390. );
  1391. else
  1392. $mailList += array (
  1393. 'remittance' => ''
  1394. );
  1395. $mailString = '发票x1,备注:' . $mailItems;
  1396. if (! empty ( $softLock ))
  1397. $mailString .= ',软件锁x' . $softLockNum;
  1398. if (! empty ( $contract ))
  1399. $mailString .= ',合同x' . $contractNum;
  1400. if (! empty ( $instructions ))
  1401. $mailString .= ',说明书x' . $instructionsNum;
  1402. if (! empty ( $remittance ))
  1403. $mailString .= ',汇款账号单';
  1404. $item = array (
  1405. 'isid' => $isid,
  1406. 'doPost' => 1,
  1407. 'mailItems' => $mailString,
  1408. 'mailItemsJson' => json_encode ( $mailList )
  1409. );
  1410. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1411. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1412. }
  1413. /**
  1414. * 批量设置邮寄物品
  1415. */
  1416. function invoiceStoreBatchMailItemSet() {
  1417. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1418. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1419. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1420. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1421. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1422. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1423. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1424. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1425. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1426. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1427. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1428. Doo::loadClass ( 'XDeode' );
  1429. $XDeode = new XDeode ( 5 );
  1430. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1431. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1432. $isidKeyList = explode ( ',', $storeKey );
  1433. $isidList = array ();
  1434. foreach ( $isidKeyList as $value ) {
  1435. $isid = $XDeode->decode ( $value );
  1436. if (! empty ( $isid ) && is_numeric ( $isid ))
  1437. array_push ( $isidList, $isid );
  1438. }
  1439. $isidString = implode ( ',', $isidList );
  1440. $trainId = $XDeode->decode ( $trainKey );
  1441. if (! is_numeric ( $isid ))
  1442. die ( 'illegal request' );
  1443. Doo::loadModel ( 'invoiceStore' );
  1444. $invoiceStore = new invoiceStore ();
  1445. $mailList = array (
  1446. 'invoice' => 1,
  1447. 'mailItems' => $mailItems
  1448. );
  1449. if (! empty ( $softLock ))
  1450. $mailList += array (
  1451. 'softLock' => $softLockNum
  1452. );
  1453. else
  1454. $mailList += array (
  1455. 'softLock' => 0
  1456. );
  1457. if (! empty ( $contract ))
  1458. $mailList += array (
  1459. 'contract' => $contractNum
  1460. );
  1461. else
  1462. $mailList += array (
  1463. 'contract' => 0
  1464. );
  1465. if (! empty ( $instructions ))
  1466. $mailList += array (
  1467. 'instructions' => $instructionsNum
  1468. );
  1469. else
  1470. $mailList += array (
  1471. 'instructions' => 0
  1472. );
  1473. if (! empty ( $remittance ))
  1474. $mailList += array (
  1475. 'remittance' => $remittance
  1476. );
  1477. else
  1478. $mailList += array (
  1479. 'remittance' => ''
  1480. );
  1481. $mailString = '发票x1,备注:' . $mailItems;
  1482. if (! empty ( $softLock ))
  1483. $mailString .= ',软件锁x' . $softLockNum;
  1484. if (! empty ( $contract ))
  1485. $mailString .= ',合同x' . $contractNum;
  1486. if (! empty ( $instructions ))
  1487. $mailString .= ',说明书x' . $instructionsNum;
  1488. if (! empty ( $remittance ))
  1489. $mailString .= ',汇款账号单';
  1490. $item = array (
  1491. 'doPost' => 1,
  1492. 'mailItems' => $mailString,
  1493. 'mailItemsJson' => json_encode ( $mailList )
  1494. );
  1495. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1496. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1497. }
  1498. /**
  1499. * 废弃
  1500. */
  1501. function ajaxGetMailItemByIstore() {
  1502. Doo::loadClass ( 'XDeode' );
  1503. $XDeode = new XDeode ( 5 );
  1504. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1505. $isid = $XDeode->decode ( $storeKey );
  1506. if (! is_numeric ( $isid ))
  1507. die ( 'illegal request' );
  1508. Doo::loadModel ( 'invoiceStore' );
  1509. $invoiceStore = new invoiceStore ();
  1510. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1511. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1512. echo json_encode ( $isDetail ['mailItemsJson'] );
  1513. exit ();
  1514. }
  1515. /**
  1516. * 终止开票
  1517. */
  1518. function invoiceDroppedDo() {
  1519. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1520. Doo::loadModel ( 'invoice' );
  1521. $invoice = new invoice ();
  1522. Doo::loadModel ( 'invoiceOperationLog' );
  1523. $invoiceOperationLog = new invoiceOperationLog ();
  1524. $iid = $invoice->authcode ( $droppedIidKey );
  1525. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1526. die ( 'illegal request' );
  1527. $item = array (
  1528. 'iid' => $iid,
  1529. 'status' => 4,
  1530. 'updateTime' => date ( "Y-m-d H:i:s" )
  1531. );
  1532. $invoice->setInvoiceByCondition ( $item );
  1533. $item = array (
  1534. 'date' => date ( "Y-m-d H:i:s" ),
  1535. 'operation' => '终止了开票',
  1536. 'status' => 4,
  1537. 'img' => $this->staff [0] ['avatar'],
  1538. 'username' => $this->staff [0] ['username'],
  1539. 'uid' => $this->staff [0] ['sid'],
  1540. 'category' => $this->staff [0] ['category'],
  1541. 'iid' => $iid
  1542. );
  1543. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1544. return "/invoice";
  1545. }
  1546. /**
  1547. * 更新退票的邮寄信息
  1548. */
  1549. function invoiceUntreadMailDo() {
  1550. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1551. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1552. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1553. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1554. Doo::loadModel ( 'invoice' );
  1555. $invoice = new invoice ();
  1556. $iid = $invoice->authcode ( $untreadIidKey );
  1557. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1558. die ( 'illegal request' );
  1559. $item = array (
  1560. 'iid' => $iid,
  1561. 'untreadCompany' => $untreadCompany,
  1562. 'untreadNumber' => $untreadNumber,
  1563. 'untreadItems' => $untreadItems
  1564. );
  1565. $invoice->setInvoiceByCondition ( $item );
  1566. return "/invoice";
  1567. }
  1568. /**
  1569. * 申请退票 --
  1570. */
  1571. function invoiceUntreadDo() {
  1572. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1573. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1574. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1575. Doo::loadModel ( 'invoice' );
  1576. $invoice = new invoice ();
  1577. Doo::loadModel ( 'invoiceOperationLog' );
  1578. $invoiceOperationLog = new invoiceOperationLog ();
  1579. Doo::loadModel ( 'invoiceReceivables' );
  1580. $invoiceReceivables = new invoiceReceivables ();
  1581. $iid = $invoice->authcode ( $untreadIidKey );
  1582. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1583. die ( 'illegal request' );
  1584. /*
  1585. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1586. */
  1587. $item = array (
  1588. 'iid' => $iid,
  1589. 'untreadStatus' => 1,
  1590. 'untreadReason' => $untreadReason,
  1591. 'untreadPost' => $untreadPost,
  1592. 'updateTime' => date ( "Y-m-d H:i:s" )
  1593. );
  1594. $invoice->setInvoiceByCondition ( $item );
  1595. $item = array (
  1596. 'date' => date ( "Y-m-d H:i:s" ),
  1597. 'operation' => '申请退票',
  1598. 'status' => 7,
  1599. 'img' => $this->staff [0] ['avatar'],
  1600. 'username' => $this->staff [0] ['username'],
  1601. 'uid' => $this->staff [0] ['sid'],
  1602. 'category' => $this->staff [0] ['category'],
  1603. 'iid' => $iid
  1604. );
  1605. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1606. return "/invoice";
  1607. }
  1608. /**
  1609. * 删除已终止的开票
  1610. */
  1611. function invoiceDelDo() {
  1612. Doo::loadModel ( 'invoice' );
  1613. $invoice = new invoice ();
  1614. Doo::loadModel ( 'invoiceOperationLog' );
  1615. $invoiceOperationLog = new invoiceOperationLog ();
  1616. Doo::loadClass ( 'XDeode' );
  1617. $XDeode = new XDeode ( 5 );
  1618. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1619. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1620. $iid = $XDeode->decode ( $iid );
  1621. Doo::loadModel ( 'invoiceStore' );
  1622. $invoiceStore = new invoiceStore ();
  1623. if (! is_numeric ( $iid ))
  1624. die ( 'illegal request' );
  1625. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1626. if (empty ( $invoiceDetail ))
  1627. die ( 'illegal request' );
  1628. $item = array (
  1629. 'iid' => $iid,
  1630. 'isDelete' => 1,
  1631. 'updateTime' => date ( "Y-m-d H:i:s" )
  1632. );
  1633. $invoice->setInvoiceByCondition ( $item );
  1634. $item = array (
  1635. 'date' => date ( "Y-m-d H:i:s" ),
  1636. 'operation' => '删除了已终止的发票',
  1637. 'status' => 4,
  1638. 'img' => $this->staff [0] ['avatar'],
  1639. 'username' => $this->staff [0] ['username'],
  1640. 'uid' => $this->staff [0] ['sid'],
  1641. 'category' => $this->staff [0] ['category'],
  1642. 'iid' => $iid
  1643. );
  1644. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1645. // 删除培训班发票仓库里的发票
  1646. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1647. return "/invoice";
  1648. }
  1649. function invoiceApproval() {
  1650. Doo::loadModel ( 'invoice' );
  1651. $invoice = new invoice ();
  1652. Doo::loadClass ( 'XDeode' );
  1653. $XDeode = new XDeode ( 5 );
  1654. Doo::loadModel ( 'staff' );
  1655. $staff = new staff ();
  1656. $invoiceList = $invoice->find ( array (
  1657. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1658. 'desc' => 'iid',
  1659. 'limit' => 10,
  1660. 'asArray' => true
  1661. ) );
  1662. foreach ( $invoiceList as $key => $value ) {
  1663. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1664. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1665. if (! empty ( $lastApprover )) {
  1666. $lastApproverKey = array_keys ( $lastApprover );
  1667. $lastApprover = end ( $lastApprover );
  1668. $staffDetail = $staff->getOne ( array (
  1669. 'where' => 'sid=' . end ( $lastApproverKey ),
  1670. 'asArray' => true
  1671. ) );
  1672. $lastApprover ['username'] = $staffDetail ['username'];
  1673. }
  1674. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1675. }
  1676. $ilist = $invoice->getInvoiceByProcessStatus ();
  1677. foreach ( $ilist as $key => $value ) {
  1678. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1679. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1680. if (! empty ( $lastApprover )) {
  1681. $lastApproverKey = array_keys ( $lastApprover );
  1682. $lastApprover = end ( $lastApprover );
  1683. $staffDetail = $staff->getOne ( array (
  1684. 'where' => 'sid=' . end ( $lastApproverKey ),
  1685. 'asArray' => true
  1686. ) );
  1687. $lastApprover ['username'] = $staffDetail ['username'];
  1688. }
  1689. $ilist [$key] ['lastApprover'] = $lastApprover;
  1690. }
  1691. // print_r($ilist);
  1692. $this->data ['invoiceList'] = $invoiceList;
  1693. $this->data ['ilist'] = $ilist;
  1694. $this->data ['memu'] = "invoice";
  1695. $this->data ['staff'] = $this->staff;
  1696. $this->data ['receiptMemu'] = 'invoiceApproval';
  1697. $this->render ( "/admin/invoiceApproval", $this->data );
  1698. }
  1699. function invoiceDetail() {
  1700. Doo::loadClass ( 'XDeode' );
  1701. $XDeode = new XDeode ( 5 );
  1702. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1703. $iid = $XDeode->decode ( $iid );
  1704. if (! is_numeric ( $iid ))
  1705. die ( 'illegal request' );
  1706. Doo::loadModel ( 'invoice' );
  1707. $invoice = new invoice ();
  1708. Doo::loadModel ( 'invoiceOperationLog' );
  1709. $invoiceOperationLog = new invoiceOperationLog ();
  1710. $invoiceDetail = $invoice->getOne ( array (
  1711. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1712. 'asArray' => true
  1713. ) );
  1714. if (empty ( $invoiceDetail ))
  1715. die ( 'illegal request' );
  1716. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1717. $this->data ['invoiceDetail'] = $invoiceDetail;
  1718. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1719. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1720. $this->data ['memu'] = "invoice";
  1721. $this->data ['staff'] = $this->staff;
  1722. $this->data ['receiptMemu'] = 'invoiceApproval';
  1723. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1724. }
  1725. /**
  1726. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1727. *
  1728. * @since 1.0.0
  1729. * @var integer iid 开票ID 已加密
  1730. * @var integer status 发票审批状态
  1731. * @var integer opintion 审批发票的意见
  1732. * @return string 如操作成功返回审批首页
  1733. */
  1734. function invoiceApprovalDo() {
  1735. Doo::loadModel ( 'invoice' );
  1736. $invoice = new invoice ();
  1737. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1738. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1739. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1740. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  1741. $iid = $invoice->authcode ( $iid );
  1742. if (! is_numeric ( $iid ))
  1743. die ( 'illegal request' );
  1744. // && ! empty ( $opinion )
  1745. if (! empty ( $iid ) && ! empty ( $status )) {
  1746. if (! ($status == 2 || $status == 3 || $status == 4))
  1747. die ( 'illegal request' );
  1748. Doo::loadModel ( 'invoiceOperationLog' );
  1749. $invoiceOperationLog = new invoiceOperationLog ();
  1750. $invoiceDetail = $invoice->getOne ( array (
  1751. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1752. 'asArray' => true
  1753. ) );
  1754. if (empty ( $invoiceDetail ))
  1755. die ( 'illegal request' );
  1756. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1757. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1758. if ($status == 3) {
  1759. $invoice->status = $status;
  1760. $item = array (
  1761. 'operation' => $opinion
  1762. );
  1763. } else {
  1764. if (empty ( $processApprovals )) {
  1765. $processApprovals = array (
  1766. $this->staff [0] ['sid'] => array (
  1767. 'date' => date ( "Y-m-d H:i:s" ),
  1768. 'opinion' => $opinion,
  1769. 'status' => $status
  1770. )
  1771. );
  1772. // var_dump(next($invoiceManage));
  1773. $nextInvoiceManage = next ( $invoiceManage );
  1774. // print_r($nextInvoiceManage);
  1775. if ($status != 4 && $nextInvoiceManage !== false)
  1776. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1777. $invoice->processApprovals = json_encode ( $processApprovals );
  1778. // var_dump($invoice);
  1779. // print_r($invoiceManage);
  1780. } else {
  1781. $processApprovals [$this->staff [0] ['sid']] = array (
  1782. 'date' => date ( "Y-m-d H:i:s" ),
  1783. 'opinion' => $opinion,
  1784. 'status' => $status
  1785. );
  1786. $pendingApprovals = 0;
  1787. foreach ( $invoiceManage as $key => $value ) {
  1788. if ($value [0] == $this->staff [0] ['sid']) {
  1789. if (isset ( $invoiceManage [$key + 1] ))
  1790. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1791. break;
  1792. }
  1793. }
  1794. if ($status != 4 && ! empty ( $pendingApprovals ))
  1795. $invoice->pendingApprovals = $pendingApprovals;
  1796. $invoice->processApprovals = json_encode ( $processApprovals );
  1797. }
  1798. $item = array (
  1799. 'operation' => $opinion
  1800. );
  1801. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1802. $invoice->status = $status;
  1803. $invoice->pendingApprovals = 0;
  1804. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1805. } elseif ($status == 4) {
  1806. $invoice->status = $status;
  1807. $item = array (
  1808. 'operation' => $opinion
  1809. );
  1810. }
  1811. }
  1812. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  1813. $invoice->update ( array (
  1814. 'where' => 'iid=' . $iid
  1815. ) );
  1816. $item += array (
  1817. 'date' => date ( "Y-m-d H:i:s" ),
  1818. 'img' => $this->staff [0] ['avatar'],
  1819. 'username' => $this->staff [0] ['username'],
  1820. 'uid' => $this->staff [0] ['sid'],
  1821. 'category' => $this->staff [0] ['category'],
  1822. 'status' => $status,
  1823. 'iid' => $iid
  1824. );
  1825. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1826. if (empty ( $divApproval ))
  1827. return '/invoiceApproval';
  1828. else
  1829. return '/invoiceApprovalAchieve';
  1830. }
  1831. die ( 'illegal request' );
  1832. }
  1833. /**
  1834. * 展示需要打印的发票数据
  1835. *
  1836. * @since 1.0.0
  1837. */
  1838. function invoicePrint() {
  1839. Doo::loadModel ( 'invoice' );
  1840. $invoice = new invoice ();
  1841. Doo::loadClass ( 'XDeode' );
  1842. $XDeode = new XDeode ( 5 );
  1843. Doo::loadModel ( 'staff' );
  1844. $staff = new staff ();
  1845. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  1846. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  1847. foreach ( $toPrint as $key => $value ) {
  1848. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1849. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1850. if (! empty ( $lastApprover )) {
  1851. $lastApproverKey = array_keys ( $lastApprover );
  1852. $lastApprover = end ( $lastApprover );
  1853. $staffDetail = $staff->getOne ( array (
  1854. 'where' => 'sid=' . end ( $lastApproverKey ),
  1855. 'asArray' => true
  1856. ) );
  1857. $lastApprover ['username'] = $staffDetail ['username'];
  1858. }
  1859. $toPrint [$key] ['lastApprover'] = $lastApprover;
  1860. }
  1861. foreach ( $printed as $key => $value ) {
  1862. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1863. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1864. if (! empty ( $lastApprover )) {
  1865. $lastApproverKey = array_keys ( $lastApprover );
  1866. $lastApprover = end ( $lastApprover );
  1867. $staffDetail = $staff->getOne ( array (
  1868. 'where' => 'sid=' . end ( $lastApproverKey ),
  1869. 'asArray' => true
  1870. ) );
  1871. $lastApprover ['username'] = $staffDetail ['username'];
  1872. }
  1873. $printed [$key] ['lastApprover'] = $lastApprover;
  1874. }
  1875. $this->data ['printed'] = $printed;
  1876. $this->data ['toPrint'] = $toPrint;
  1877. $this->data ['memu'] = "invoice";
  1878. $this->data ['staff'] = $this->staff;
  1879. $this->data ['receiptMemu'] = 'invoicePrint';
  1880. $this->render ( "/admin/invoicePrint", $this->data );
  1881. }
  1882. /**
  1883. * 展示发票打印的详情页面
  1884. *
  1885. * @since 1.0.0
  1886. */
  1887. function invoicePrintDetail() {
  1888. Doo::loadClass ( 'XDeode' );
  1889. $XDeode = new XDeode ( 5 );
  1890. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1891. $iid = $XDeode->decode ( $iid );
  1892. if (! is_numeric ( $iid ))
  1893. die ( 'illegal request' );
  1894. Doo::loadModel ( 'invoice' );
  1895. $invoice = new invoice ();
  1896. Doo::loadModel ( 'invoiceOperationLog' );
  1897. $invoiceOperationLog = new invoiceOperationLog ();
  1898. Doo::loadModel ( 'invoicePaper' );
  1899. $invoicePaper = new invoicePaper ();
  1900. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  1901. if (empty ( $invoiceDetail ))
  1902. die ( 'illegal request' );
  1903. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  1904. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1905. $this->data ['invoicePaperList'] = $invoicePaperList;
  1906. $this->data ['invoiceDetail'] = $invoiceDetail;
  1907. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1908. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1909. $this->data ['memu'] = "invoice";
  1910. $this->data ['staff'] = $this->staff;
  1911. $this->data ['receiptMemu'] = 'invoicePrint';
  1912. $this->render ( "/admin/invoicePrintDetail", $this->data );
  1913. }
  1914. /**
  1915. * 所有待打印 发票
  1916. */
  1917. function invoicePrintStayAchieve() {
  1918. Doo::loadModel ( 'invoice' );
  1919. $invoice = new invoice ();
  1920. Doo::loadClass ( 'XDeode' );
  1921. $XDeode = new XDeode ( 5 );
  1922. Doo::loadModel ( 'staff' );
  1923. $staff = new staff ();
  1924. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  1925. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  1926. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  1927. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  1928. Doo::loadModel ( 'invoiceTraining' );
  1929. $invoiceTraining = new invoiceTraining ();
  1930. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  1931. $page_size = 12;
  1932. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1933. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  1934. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  1935. $get = "/" . $status;
  1936. $con = ' and status=2 ';
  1937. if ($status == 'TOPRINT')
  1938. $con = ' and status=2 and printStatus=0 ';
  1939. elseif ($status == 'PRINTED')
  1940. $con = ' and status=2 and printStatus=1';
  1941. if ($invoiceType == 'ORDINARY')
  1942. $con .= ' and invoiceType=0 ';
  1943. elseif ($invoiceType == 'SPECIAL')
  1944. $con .= ' and invoiceType=1 ';
  1945. if ($invoiceTrain == 'ORDINARY')
  1946. $con .= ' and trainId=0 ';
  1947. elseif ($invoiceTrain == 'TRAIN')
  1948. $con .= ' and trainId!=0 ';
  1949. if ($invoiceTrainName != 'ALL') {
  1950. $trainId = $XDeode->decode ( $invoiceTrainName );
  1951. if (is_numeric ( $trainId ))
  1952. $con .= ' and trainId =' . $trainId;
  1953. }
  1954. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1955. $dateArr = explode ( ':', $date );
  1956. $D1 = '';
  1957. $D2 = '';
  1958. if (! empty ( $date )) {
  1959. $D1 = $dateArr [0];
  1960. $D2 = $dateArr [1];
  1961. }
  1962. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  1963. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  1964. if (! empty ( $MebSea )) {
  1965. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1966. }
  1967. $pageinfo ['page'] = array (
  1968. 'previous' => ''
  1969. );
  1970. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  1971. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  1972. $action = "invoicePrintStayAchieve";
  1973. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1974. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1975. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  1976. $this->data ['trainList'] = $trainList;
  1977. $this->data ['invoiceType'] = $invoiceType;
  1978. $this->data ['invoiceTrain'] = $invoiceTrain;
  1979. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  1980. $this->data ['MebSeaEn'] = $MebSea;
  1981. $this->data ['MebSea'] = urlencode ( $MebSea );
  1982. $this->data ['get'] = $get;
  1983. $this->data ['page'] = $pageinfo;
  1984. $this->data ['date'] = $date;
  1985. $this->data ['status'] = $status;
  1986. $this->data ['memu'] = "invoice";
  1987. $this->data ['staff'] = $this->staff;
  1988. foreach ( $list as $key => $value ) {
  1989. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1990. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1991. if (! empty ( $lastApprover )) {
  1992. $lastApproverKey = array_keys ( $lastApprover );
  1993. $lastApprover = end ( $lastApprover );
  1994. $staffDetail = $staff->getOne ( array (
  1995. 'where' => 'sid=' . end ( $lastApproverKey ),
  1996. 'asArray' => true
  1997. ) );
  1998. $lastApprover ['username'] = $staffDetail ['username'];
  1999. }
  2000. $list [$key] ['lastApprover'] = $lastApprover;
  2001. }
  2002. $this->data ['receiptMemu'] = 'invoicePrint';
  2003. $this->data ['list'] = $list;
  2004. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2005. }
  2006. /**
  2007. * 填写票号并完成打印
  2008. * @since 1.0.0
  2009. */
  2010. function invoicePrintDo() {
  2011. Doo::loadModel ( 'invoice' );
  2012. $invoice = new invoice ();
  2013. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2014. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2015. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2016. $iid = $invoice->authcode ( $iid );
  2017. if (! is_numeric ( $iid ))
  2018. die ( 'illegal request' );
  2019. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2020. Doo::loadModel ( 'invoiceOperationLog' );
  2021. $invoiceOperationLog = new invoiceOperationLog ();
  2022. Doo::loadModel ( 'invoiceStatistics' );
  2023. $invoiceStatistics = new invoiceStatistics ();
  2024. $XDeode = new XDeode ( 5 );
  2025. Doo::loadModel ( 'invoicePaper' );
  2026. $invoicePaper = new invoicePaper ();
  2027. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2028. if (empty ( $invoicePrintDetail ))
  2029. die ( 'illegal request' );
  2030. //
  2031. $ipid = $XDeode->decode ( $invoiceNo );
  2032. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2033. if (empty ( $paperDetail ))
  2034. die ( 'illegal request' );
  2035. $invoicePaper = new invoicePaper ();
  2036. $item = array (
  2037. 'iid' => $iid,
  2038. 'ipid' => $ipid
  2039. );
  2040. $invoicePaper->setInvoicePaperByCondition ( $item );
  2041. $item = array (
  2042. 'iid' => $iid,
  2043. 'printStatus' => 1,
  2044. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2045. 'printer' => $this->staff [0] ['username'],
  2046. 'printTime' => date ( "Y-m-d H:i:s" ),
  2047. 'invoiceNo' => $paperDetail ['invoiceNo']
  2048. );
  2049. $invoice->setInvoiceByCondition ( $item );
  2050. $item = array (
  2051. 'date' => date ( "Y-m-d H:i:s" ),
  2052. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2053. 'status' => 5,
  2054. 'img' => $this->staff [0] ['avatar'],
  2055. 'username' => $this->staff [0] ['username'],
  2056. 'uid' => $this->staff [0] ['sid'],
  2057. 'category' => $this->staff [0] ['category'],
  2058. 'iid' => $iid
  2059. );
  2060. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2061. // 去统计--负票不汇总
  2062. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2063. $item = array (
  2064. 'date' => date ( "Y-m-d H:i:s" ),
  2065. 'priceClass' => 1,
  2066. 'cid' => $invoicePrintDetail ['cid'],
  2067. 'staff' => $invoicePrintDetail ['sid'],
  2068. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2069. );
  2070. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2071. }
  2072. // 发送通知信息到微信-去除
  2073. // $this->setWXMsg($iid,'PRINT');
  2074. // 申请人获取微信通知
  2075. Doo::loadModel ( 'staff' );
  2076. $staff = new staff ();
  2077. Doo::loadClass ( 'XDeode' );
  2078. $XDeode = new XDeode ( 5 );
  2079. $username2 = $staff->getOne ( array (
  2080. 'select' => 'wxid',
  2081. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2082. 'asArray' => TRUE
  2083. ) );
  2084. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2085. $msg = '';
  2086. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2087. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2088. if (empty ( $invoicePrintType ))
  2089. return "/invoicePrint";
  2090. else
  2091. return "/invoicePrintStayAchieve";
  2092. }
  2093. }
  2094. /**
  2095. * 需要邮寄的发票
  2096. * @since 1.0.0
  2097. */
  2098. function invoicePost() {
  2099. Doo::loadModel ( 'invoice' );
  2100. $invoice = new invoice ();
  2101. Doo::loadModel ( 'express' );
  2102. $express = new express ();
  2103. $invoicePost = $invoice->getPostByInvoice ();
  2104. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2105. $expressList = $express->getExpressByAll ();
  2106. $invoicePostExpress = "";
  2107. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2108. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2109. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2110. $this->data ['expressList'] = $expressList;
  2111. $this->data ['invoicePost'] = $invoicePost;
  2112. $this->data ['invoicePosted'] = $invoicePosted;
  2113. $this->data ['memu'] = "invoice";
  2114. $this->data ['staff'] = $this->staff;
  2115. $this->data ['receiptMemu'] = 'invoicePost';
  2116. $this->render ( "/admin/invoicePost", $this->data );
  2117. }
  2118. /**
  2119. * 添加发票邮寄信息
  2120. */
  2121. function invoiceExpressAddDo() {
  2122. Doo::loadModel ( 'invoice' );
  2123. $invoice = new invoice ();
  2124. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2125. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2126. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2127. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2128. $iid = $iid = $invoice->authcode ( $iid );
  2129. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2130. die ( 'illegal request' );
  2131. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2132. setcookie ( 'invoicePostExpress', $expressNumber );
  2133. $item = array (
  2134. 'iid' => $iid,
  2135. 'postStatus' => 1,
  2136. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2137. 'postTime' => date ( "Y-m-d H:i:s" ),
  2138. 'expressCompany' => $expressCompany,
  2139. 'expressNumber' => $expressNumber,
  2140. 'actualItems' => $actualItems,
  2141. 'poster' => $this->staff [0] ['username']
  2142. );
  2143. $invoice->setInvoiceByCondition ( $item );
  2144. // 微信通知-去掉
  2145. // $this->setWXMsg ( $iid );
  2146. Doo::loadModel ( 'staff' );
  2147. $staff = new staff ();
  2148. Doo::loadClass ( 'XDeode' );
  2149. $XDeode = new XDeode ( 5 );
  2150. $username2 = $staff->getOne ( array (
  2151. 'select' => 'wxid',
  2152. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2153. 'asArray' => TRUE
  2154. ) );
  2155. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2156. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2157. if (empty ( $expCom ))
  2158. $expCom [0] = '';
  2159. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2160. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2161. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2162. return '/invoicePost';
  2163. }
  2164. function invoiceExpressUpdateDo() {
  2165. Doo::loadModel ( 'invoice' );
  2166. $invoice = new invoice ();
  2167. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2168. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2169. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2170. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2171. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2172. $iid = $invoice->authcode ( $iid );
  2173. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2174. die ( 'illegal request' );
  2175. $item = array (
  2176. 'iid' => $iid,
  2177. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2178. 'expressCompany' => $expressCompany,
  2179. 'expressNumber' => $expressNumber,
  2180. 'actualItems' => $actualItems,
  2181. 'poster' => $this->staff [0] ['username']
  2182. );
  2183. $invoice->setInvoiceByCondition ( $item );
  2184. return $action;
  2185. }
  2186. /**
  2187. * 可退票管理
  2188. */
  2189. function invoiceUntreadIsAchieve() {
  2190. Doo::loadModel ( 'invoice' );
  2191. $invoice = new invoice ();
  2192. Doo::loadClass ( 'XDeode' );
  2193. $XDeode = new XDeode ( 5 );
  2194. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2195. $page_size = 18;
  2196. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2197. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2198. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2199. $dateArr = explode ( ':', $date );
  2200. $D1 = '';
  2201. $D2 = '';
  2202. if (! empty ( $date )) {
  2203. $D1 = $dateArr [0];
  2204. $D2 = $dateArr [1];
  2205. }
  2206. $con = '';
  2207. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2208. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2209. // if ($date == 'MONTHO')
  2210. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2211. // elseif ($date == 'MONTHT')
  2212. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2213. // elseif ($date == 'MONTHY')
  2214. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2215. if (! empty ( $MebSea )) {
  2216. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2217. }
  2218. $pageinfo ['page'] = array (
  2219. 'previous' => ''
  2220. );
  2221. // printStatus=1 and
  2222. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2223. $action = "invoiceUntreadIsAchieve";
  2224. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2225. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2226. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2227. // print_r($list);
  2228. $this->data ['MebSeaEn'] = $MebSea;
  2229. // $this->data ['MebSea'] = urlencode ( $MebSea );
  2230. $this->data ['get'] = $get;
  2231. $this->data ['page'] = $pageinfo;
  2232. $this->data ['date'] = $date;
  2233. $this->data ['list'] = $list;
  2234. $this->data ['memu'] = "invoice";
  2235. $this->data ['staff'] = $this->staff;
  2236. $this->data ['receiptMemu'] = 'invoice';
  2237. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2238. }
  2239. /**
  2240. * 退票处理页面
  2241. */
  2242. function invoiceUntread() {
  2243. Doo::loadModel ( 'invoice' );
  2244. $invoice = new invoice ();
  2245. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  2246. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2247. foreach ( $establishedInvoice as $key => $value ) {
  2248. // months
  2249. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2250. $nowDate = strtotime ( 'now' );
  2251. $establishedInvoice [$key] ['lossShow'] = false;
  2252. if ($lossDate < $nowDate)
  2253. $establishedInvoice [$key] ['lossShow'] = true;
  2254. }
  2255. $this->data ['untreadInvoice'] = $untreadInvoice;
  2256. $this->data ['establishedInvoice'] = $establishedInvoice;
  2257. $this->data ['memu'] = "invoice";
  2258. $this->data ['staff'] = $this->staff;
  2259. $this->data ['receiptMemu'] = 'invoiceUntread';
  2260. $this->render ( "/admin/invoiceUntread", $this->data );
  2261. }
  2262. /**
  2263. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2264. */
  2265. function invoiceUntreadEstablishedDo() {
  2266. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2267. Doo::loadModel ( 'invoice' );
  2268. $invoice = new invoice ();
  2269. Doo::loadModel ( 'invoiceOperationLog' );
  2270. $invoiceOperationLog = new invoiceOperationLog ();
  2271. Doo::loadModel ( 'invoiceReceivables' );
  2272. Doo::loadModel ( 'invoiceStatistics' );
  2273. $iid = $invoice->authcode ( $untreadIidKey );
  2274. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2275. die ( 'illegal request' );
  2276. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2277. if ($invoiceDetails ['untreadStatus'] != 1)
  2278. die ( 'illegal request' );
  2279. $item = array (
  2280. 'iid' => $iid,
  2281. // 'irid'=>'',
  2282. 'untreadStatus' => 2,
  2283. 'updateTime' => date ( "Y-m-d H:i:s" )
  2284. );
  2285. $invoice->setInvoiceByCondition ( $item );
  2286. $item = array (
  2287. 'date' => date ( "Y-m-d H:i:s" ),
  2288. 'operation' => '已确认退票',
  2289. 'status' => 6,
  2290. 'img' => $this->staff [0] ['avatar'],
  2291. 'username' => $this->staff [0] ['username'],
  2292. 'uid' => $this->staff [0] ['sid'],
  2293. 'category' => $this->staff [0] ['category'],
  2294. 'iid' => $iid
  2295. );
  2296. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2297. // 收款解绑以及入账扣除 收款扣除
  2298. if (! empty ( $invoiceDetails ['irid'] )) {
  2299. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2300. foreach ( $iridList as $value ) {
  2301. $invoiceReceivables = new invoiceReceivables ();
  2302. $irDetails = $invoiceReceivables->getOne ( array (
  2303. 'where' => " irid=" . $value . ' and bindStatus=1',
  2304. 'asArray' => TRUE
  2305. ) );
  2306. $item = array (
  2307. 'irid' => $value,
  2308. 'bindStatus' => 0,
  2309. 'untreadStatus' => 1,
  2310. 'untreadStaff' => $invoiceDetails ['userName'],
  2311. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2312. 'iid' => 0
  2313. );
  2314. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2315. if (! empty ( $irDetails )) {
  2316. // 扣除入账
  2317. $invoiceStatistics = new invoiceStatistics ();
  2318. $item = array (
  2319. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2320. 'priceClass' => 3,
  2321. 'cid' => $invoiceDetails ['cid'],
  2322. 'staff' => $invoiceDetails ['sid'],
  2323. 'accountPrice' => - $irDetails ['receivablesPrice']
  2324. );
  2325. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2326. // 扣除收款
  2327. $invoiceStatistics = new invoiceStatistics ();
  2328. $item = array (
  2329. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2330. 'priceClass' => 2,
  2331. 'cid' => $invoiceDetails ['cid'],
  2332. 'staff' => $invoiceDetails ['sid'],
  2333. 'irid' => $irDetails ['irid'],
  2334. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2335. );
  2336. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2337. }
  2338. }
  2339. }
  2340. return "/invoiceUntread";
  2341. }
  2342. /**
  2343. * 建立负票,关联原来发票
  2344. */
  2345. function invoiceLossDo() {
  2346. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2347. if (! empty ( $iidKey )) {
  2348. Doo::loadClass ( 'XDeode' );
  2349. $XDeode = new XDeode ( 5 );
  2350. Doo::loadModel ( 'invoice' );
  2351. $invoice = new invoice ();
  2352. Doo::loadModel ( 'invoiceOperationLog' );
  2353. $invoiceOperationLog = new invoiceOperationLog ();
  2354. $iidKey = $XDeode->decode ( $iidKey );
  2355. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2356. // 拷贝插入一条发票数据
  2357. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2358. // 更新负票
  2359. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2360. $invoice = new invoice ();
  2361. $item = array (
  2362. 'iid' => $iid,
  2363. 'sid' => $this->staff [0] ['sid'],
  2364. 'userName' => $this->staff [0] ['username'],
  2365. 'cid' => $this->staff [0] ['cid'],
  2366. 'categoryName' => $this->staff [0] ['category'],
  2367. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2368. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2369. 'invoiceSerial' => $invoiceSerial,
  2370. 'invoiceNo' => '',
  2371. 'printStatus' => 0,
  2372. 'untreadStatus' => 4,
  2373. // 关联发票号
  2374. 'lossIid' => $invoiceDetail ['iid']
  2375. );
  2376. $invoice->setInvoiceByCondition ( $item );
  2377. // 更新原发票
  2378. $invoice = new invoice ();
  2379. $item = array (
  2380. 'iid' => $invoiceDetail ['iid'],
  2381. 'lossIid' => $iid
  2382. );
  2383. $invoice->setInvoiceByCondition ( $item );
  2384. // 操作日志
  2385. $item = array (
  2386. 'date' => date ( "Y-m-d H:i:s" ),
  2387. 'operation' => "创建负票" . $invoiceSerial,
  2388. 'status' => 12,
  2389. 'img' => $this->staff [0] ['avatar'],
  2390. 'username' => $this->staff [0] ['username'],
  2391. 'uid' => $this->staff [0] ['sid'],
  2392. 'category' => $this->staff [0] ['category'],
  2393. 'iid' => $iid
  2394. );
  2395. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2396. // print_r($invoiceDetail);
  2397. // echo $iid;die;
  2398. }
  2399. return '/invoiceUntread';
  2400. }
  2401. /**
  2402. * 上传银行到账 收款文件
  2403. */
  2404. function invoiceReceivablesBankUpload() {
  2405. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2406. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2407. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2408. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2409. header ( "HTTP/1.1 500 Internal Server Error" );
  2410. echo "POST exceeded maximum allowed size.";
  2411. exit ( 0 );
  2412. }
  2413. // Settings
  2414. $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)
  2415. $upload_name = "Filedata";
  2416. $file_name = "";
  2417. $nk = time ();
  2418. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2419. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2420. echo "文件无法保存.";
  2421. exit ( 0 );
  2422. }
  2423. echo json_encode ( array (
  2424. 'filename' => $file_name,
  2425. 'id' => $nk
  2426. ) );
  2427. exit ( 0 );
  2428. }
  2429. /**
  2430. * 解析银行到账收款execl并导入库中
  2431. */
  2432. function invoiceReceivablesImport() {
  2433. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2434. if ($path != "") {
  2435. Doo::loadModel ( 'invoiceReceivables' );
  2436. $invoiceReceivables = new invoiceReceivables ();
  2437. Doo::loadClass ( 'invoice.func' );
  2438. Doo::loadModel ( 'invoiceROLog' );
  2439. $invoiceROLog = new invoiceROLog ();
  2440. Doo::loadModel ( 'invoiceStatistics' );
  2441. $invoiceStatistics = new invoiceStatistics ();
  2442. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2443. $bankBatchNumber = 'BBN_' . time ();
  2444. Doo::db ()->beginTransaction ();
  2445. // 批量存储收款--由于必须获得收款ID,
  2446. $sql = 'INSERT INTO CLD_invoiceReceivables (receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2447. VALUES ';
  2448. $date = date ( "Y-m-d" );
  2449. $receivablesList = array ();
  2450. foreach ( $exlArray as $key => $value ) {
  2451. $receivablesSql = '(' . $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"] . '")';
  2452. array_push ( $receivablesList, $receivablesSql );
  2453. }
  2454. $sql = $sql . implode ( ',', $receivablesList );
  2455. // echo $sql;
  2456. Doo::db ()->query ( $sql );
  2457. // 批量存储收款统计
  2458. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2459. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2460. // 没有irid 回滚所有操作
  2461. if (empty ( $iridList )) {
  2462. Doo::db ()->rollBack ();
  2463. header ( 'Content-Type:text/html;charset=utf-8' );
  2464. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2465. }
  2466. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2467. VALUES ';
  2468. $statisticsList = array ();
  2469. foreach ( $iridList as $value ) {
  2470. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2471. array_push ( $statisticsList, $statisticsSql );
  2472. }
  2473. $sql = $sql . implode ( ',', $statisticsList );
  2474. Doo::db ()->query ( $sql );
  2475. // 批量存储操作日志
  2476. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2477. VALUES ';
  2478. $ROLogList = array ();
  2479. foreach ( $iridList as $value ) {
  2480. $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'] . '")';
  2481. array_push ( $ROLogList, $ROLogSql );
  2482. }
  2483. $sql = $sql . implode ( ',', $ROLogList );
  2484. Doo::db ()->query ( $sql );
  2485. Doo::db ()->commit ();
  2486. return "/invoiceReceivables";
  2487. }
  2488. echo 'no file';
  2489. }
  2490. function invoiceReceivables() {
  2491. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2492. Doo::loadModel ( 'L_category' );
  2493. $lCategory = new L_category ();
  2494. Doo::loadModel ( 'staff' );
  2495. $staff = new staff ();
  2496. Doo::loadModel ( 'invoiceReceivables' );
  2497. $invoiceReceivables = new invoiceReceivables ();
  2498. Doo::loadModel ( 'invoice' );
  2499. $invoice = new invoice ();
  2500. Doo::loadClass ( 'XDeode' );
  2501. $XDeode = new XDeode ( 5 );
  2502. $category = $lCategory->getCategory ();
  2503. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2504. $sql = 'bindStatus=1 and iid!=0';
  2505. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2506. // 获取未入账发票
  2507. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2508. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2509. foreach ( $invoiceUnAccount as $key => $value ) {
  2510. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2511. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2512. if (! empty ( $lastApprover )) {
  2513. $lastApproverKey = array_keys ( $lastApprover );
  2514. $lastApprover = end ( $lastApprover );
  2515. $staffDetail = $staff->getOne ( array (
  2516. 'where' => 'sid=' . end ( $lastApproverKey ),
  2517. 'asArray' => true
  2518. ) );
  2519. $lastApprover ['username'] = $staffDetail ['username'];
  2520. }
  2521. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2522. }
  2523. foreach ( $invoiceExistAccount as $key => $value ) {
  2524. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2525. if (empty ( $irList ))
  2526. $irList [0] ['sumPrice'] = 0;
  2527. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2528. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2529. $invoiceExistAccount [$key] ['balance'] = $balance;
  2530. }
  2531. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2532. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2533. $this->data ['halfList'] = $halfList;
  2534. $this->data ['halfCount'] = count ( $halfList );
  2535. // print_r($receivablesList);
  2536. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2537. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2538. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2539. $this->data ['receivablesInput'] = $receivablesInput;
  2540. $this->data ['year'] = date ( 'Y' );
  2541. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2542. $this->data ['receivablesList'] = $receivablesList;
  2543. $this->data ['staffList'] = $staffList;
  2544. $this->data ['category'] = $category;
  2545. $this->data ['memu'] = "invoice";
  2546. $this->data ['staff'] = $this->staff;
  2547. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2548. $this->render ( "/admin/invoiceReceivables", $this->data );
  2549. }
  2550. /**
  2551. * 设置收款认领地区
  2552. */
  2553. function setInvoiceReceivablesClaim() {
  2554. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2555. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2556. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2557. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2558. Doo::loadModel ( 'invoiceReceivables' );
  2559. $invoiceReceivables = new invoiceReceivables ();
  2560. Doo::loadClass ( 'XDeode' );
  2561. $XDeode = new XDeode ( 5 );
  2562. Doo::loadModel ( 'invoiceROLog' );
  2563. $invoiceROLog = new invoiceROLog ();
  2564. $irid = $XDeode->decode ( $iridKey );
  2565. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2566. if (empty ( $irDetail ))
  2567. die ( 'illegal request' );
  2568. $item = array (
  2569. 'irid' => $irid,
  2570. 'receivablesCategory' => $receivablesCategory
  2571. );
  2572. if ($receivablesCategory != 'PUBLIC') {
  2573. $item += array (
  2574. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2575. 'inputType' => 1
  2576. );
  2577. }
  2578. $invoiceReceivables = new invoiceReceivables ();
  2579. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2580. // 收款操作日志
  2581. $item = array (
  2582. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2583. 'date' => date ( "Y-m-d" ),
  2584. 'status' => 1,
  2585. 'img' => $this->staff [0] ['avatar'],
  2586. 'username' => $this->staff [0] ['username'],
  2587. 'uid' => $this->staff [0] ['sid'],
  2588. 'category' => $this->staff [0] ['category'],
  2589. 'irid' => $irid
  2590. );
  2591. $invoiceROLog->setInvoiceROLog ( $item );
  2592. if (empty ( $action ))
  2593. return '/invoiceReceivables';
  2594. else
  2595. return "/invoiceReceivablesAS";
  2596. }
  2597. die ( 'illegal request' );
  2598. }
  2599. /**
  2600. * 新添加收款直接入账发票
  2601. */
  2602. function invoiceCompareClaimPrice() {
  2603. // 收款录入
  2604. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2605. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2606. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2607. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2608. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2609. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2610. Doo::loadModel ( 'invoiceReceivables' );
  2611. $invoiceReceivables = new invoiceReceivables ();
  2612. Doo::loadModel ( 'invoiceROLog' );
  2613. $invoiceROLog = new invoiceROLog ();
  2614. Doo::loadModel ( 'invoiceStatistics' );
  2615. Doo::loadModel ( 'invoice' );
  2616. $invoice = new invoice ();
  2617. Doo::loadClass ( 'XDeode' );
  2618. $XDeode = new XDeode ( 5 );
  2619. Doo::loadModel ( 'invoiceOperationLog' );
  2620. $invoiceOperationLog = new invoiceOperationLog ();
  2621. $iidKey = $XDeode->decode ( $iidKey );
  2622. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2623. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2624. die ( 'illegal request' );
  2625. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2626. // 收款录入 并绑定发票
  2627. Doo::db ()->beginTransaction ();
  2628. $bindStatus = 0;
  2629. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2630. $bindStatus = 1;
  2631. $item = array (
  2632. 'bindStatus' => $bindStatus,
  2633. 'iid' => $invoiceDetail ['iid'],
  2634. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2635. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2636. 'receivablesPrice' => $receivablesPrice,
  2637. 'receivablesMessage' => $receivablesMessage,
  2638. 'receivablesSerial' => $receivablesSerial,
  2639. 'receivablesBank' => $receivablesBank,
  2640. 'receivablesDate' => $receivablesDate,
  2641. 'inputStaff' => $this->staff [0] ['username'],
  2642. 'accountClerk' => $this->staff [0] ['username'],
  2643. 'date' => date ( "Y-m-d" ),
  2644. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2645. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2646. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2647. );
  2648. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2649. $item = array ();
  2650. // 收款操作日志
  2651. $item = array (
  2652. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2653. );
  2654. $item += array (
  2655. 'date' => date ( "Y-m-d" ),
  2656. 'status' => 1,
  2657. 'img' => $this->staff [0] ['avatar'],
  2658. 'username' => $this->staff [0] ['username'],
  2659. 'uid' => $this->staff [0] ['sid'],
  2660. 'category' => $this->staff [0] ['category'],
  2661. 'irid' => $irid
  2662. );
  2663. $invoiceROLog->setInvoiceROLog ( $item );
  2664. // 收款统计
  2665. $invoiceStatistics = new invoiceStatistics ();
  2666. $item = array (
  2667. 'date' => $receivablesDate,
  2668. 'priceClass' => 2,
  2669. 'irid' => $irid,
  2670. 'cid' => $invoiceDetail ['cid'],
  2671. 'staff' => $invoiceDetail ['sid'],
  2672. 'receivablesPrice' => $receivablesPrice
  2673. );
  2674. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2675. // 收款 入 发票
  2676. $detail = $invoiceDetail;
  2677. $iridString = "";
  2678. if (empty ( $detail ['irid'] ))
  2679. $iridString = $irid;
  2680. else
  2681. $iridString = $detail ['irid'] . ',' . $irid;
  2682. $item = array (
  2683. 'irid' => $iridString,
  2684. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2685. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2686. 'iid' => $detail ['iid']
  2687. );
  2688. $invoiceReceivables = new invoiceReceivables ();
  2689. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2690. if ($detail ['invoicePrice'] <= $sum)
  2691. $item += array (
  2692. 'untreadStatus' => 3
  2693. );
  2694. $invoice->setInvoiceByCondition ( $item );
  2695. // 操作日志
  2696. $item = array (
  2697. 'date' => date ( "Y-m-d H:i:s" ),
  2698. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  2699. 'status' => 8,
  2700. 'img' => $this->staff [0] ['avatar'],
  2701. 'username' => $this->staff [0] ['username'],
  2702. 'uid' => $this->staff [0] ['sid'],
  2703. 'category' => $this->staff [0] ['category'],
  2704. 'iid' => $detail ['iid']
  2705. );
  2706. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2707. // 入账汇总
  2708. $invoiceStatistics = new invoiceStatistics ();
  2709. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  2710. // $accountPrice = 0;
  2711. // foreach ( $list as $key => $value ) {
  2712. // $accountPrice += $value ['receivablesPrice'];
  2713. // }
  2714. $item = array (
  2715. 'date' => $receivablesDate,
  2716. 'priceClass' => 3,
  2717. 'cid' => $invoiceDetail ['cid'],
  2718. 'staff' => $invoiceDetail ['sid'],
  2719. 'accountPrice' => $receivablesPrice
  2720. );
  2721. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2722. Doo::db ()->commit ();
  2723. }
  2724. return '/invoiceReceivables';
  2725. }
  2726. /**
  2727. * 检索未入账发票数据 function sir() { }
  2728. */
  2729. /**
  2730. * 录入收款数据
  2731. * @return string
  2732. */
  2733. function invoiceReceivablesDo() {
  2734. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2735. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2736. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2737. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2738. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2739. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2740. Doo::loadModel ( 'invoiceReceivables' );
  2741. $invoiceReceivables = new invoiceReceivables ();
  2742. Doo::loadModel ( 'invoiceROLog' );
  2743. $invoiceROLog = new invoiceROLog ();
  2744. Doo::loadModel ( 'invoiceStatistics' );
  2745. $invoiceStatistics = new invoiceStatistics ();
  2746. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  2747. $item = array (
  2748. 'receivablesPrice' => $receivablesPrice,
  2749. 'receivablesMessage' => $receivablesMessage,
  2750. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  2751. 'receivablesBank' => $receivablesBank,
  2752. 'receivablesDate' => $receivablesDate,
  2753. 'inputStaff' => $this->staff [0] ['username'],
  2754. 'date' => date ( "Y-m-d" ),
  2755. 'receivablesCategory' => $receivablesCategory,
  2756. 'receivablesStaff' => $receivablesStaff
  2757. );
  2758. if ($receivablesCategory != 'PUBLIC') {
  2759. $item += array (
  2760. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2761. 'inputType' => 1
  2762. );
  2763. }
  2764. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2765. $item = array ();
  2766. // 收款操作日志
  2767. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2768. $item = array (
  2769. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2770. );
  2771. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2772. $item = array (
  2773. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2774. );
  2775. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2776. $receivablesStaff = explode ( '-', $receivablesStaff );
  2777. $item = array (
  2778. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2779. );
  2780. }
  2781. $item += array (
  2782. 'date' => date ( "Y-m-d" ),
  2783. 'status' => 1,
  2784. 'img' => $this->staff [0] ['avatar'],
  2785. 'username' => $this->staff [0] ['username'],
  2786. 'uid' => $this->staff [0] ['sid'],
  2787. 'category' => $this->staff [0] ['category'],
  2788. 'irid' => $irid
  2789. );
  2790. $invoiceROLog->setInvoiceROLog ( $item );
  2791. $item = array (
  2792. 'date' => $receivablesDate,
  2793. 'priceClass' => 2,
  2794. 'irid' => $irid,
  2795. 'receivablesPrice' => $receivablesPrice
  2796. );
  2797. if ($receivablesCategory != 'PUBLIC') {
  2798. $receivablesCategory = explode ( ":", $receivablesCategory );
  2799. $item += array (
  2800. 'cid' => $receivablesCategory [0]
  2801. );
  2802. }
  2803. if ($receivablesStaff2 != 'PUBLIC') {
  2804. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  2805. $item += array (
  2806. 'staff' => $receivablesStaff [0]
  2807. );
  2808. }
  2809. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2810. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  2811. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  2812. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  2813. if ($toparty != 0)
  2814. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  2815. }
  2816. return "/invoiceReceivables";
  2817. }
  2818. /**
  2819. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  2820. */
  2821. function invoiceReceivablesClaim() {
  2822. Doo::loadModel ( 'invoiceReceivables' );
  2823. $invoiceReceivables = new invoiceReceivables ();
  2824. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2825. $this->data ['receivablesList'] = $receivablesList;
  2826. $this->data ['memu'] = "invoice";
  2827. $this->data ['staff'] = $this->staff;
  2828. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  2829. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  2830. }
  2831. function invoiceReceivablesTitleMarkSet() {
  2832. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2833. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2834. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  2835. die ( 'illegal request' );
  2836. Doo::loadModel ( 'invoiceReceivables' );
  2837. $invoiceReceivables = new invoiceReceivables ();
  2838. Doo::loadClass ( 'XDeode' );
  2839. $XDeode = new XDeode ( 5 );
  2840. $irid = $XDeode->decode ( $iridKey );
  2841. if (! is_numeric ( $irid ))
  2842. die ( 'illegal request' );
  2843. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  2844. $invoiceReceivables->update ( array (
  2845. 'where' => 'irid = ' . $irid
  2846. ) );
  2847. return '/invoiceReceivablesClaim';
  2848. }
  2849. /**
  2850. * 更新收款相关数据
  2851. */
  2852. function invoiceReceivablesUpdateClaim() {
  2853. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2854. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2855. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2856. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2857. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2858. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2859. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2860. if (empty ( $claimKey ))
  2861. die ( 'illegal request' );
  2862. Doo::loadModel ( 'invoiceReceivables' );
  2863. $invoiceReceivables = new invoiceReceivables ();
  2864. Doo::loadModel ( 'invoiceROLog' );
  2865. $invoiceROLog = new invoiceROLog ();
  2866. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  2867. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2868. if (empty ( $detail ))
  2869. die ( 'illegal request' );
  2870. $invoiceReceivables = new invoiceReceivables ();
  2871. $item = array (
  2872. 'irid' => $detail ['irid']
  2873. );
  2874. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2875. $item += array (
  2876. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2877. );
  2878. }
  2879. if (! empty ( $receivablesCategory ))
  2880. $item += array (
  2881. 'receivablesCategory' => $receivablesCategory
  2882. );
  2883. if (! empty ( $receivablesStaff ))
  2884. $item += array (
  2885. 'receivablesStaff' => $receivablesStaff
  2886. );
  2887. if (! empty ( $receivablesPrice ))
  2888. $item += array (
  2889. 'receivablesPrice' => $receivablesPrice
  2890. );
  2891. if (! empty ( $receivablesMessage ))
  2892. $item += array (
  2893. 'receivablesMessage' => $receivablesMessage
  2894. );
  2895. if (! empty ( $receivablesBank ))
  2896. $item += array (
  2897. 'receivablesBank' => $receivablesBank
  2898. );
  2899. if (! empty ( $receivablesDate ))
  2900. $item += array (
  2901. 'receivablesDate' => $receivablesDate
  2902. );
  2903. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2904. // 收款操作日志
  2905. $item = array ();
  2906. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2907. $item = array (
  2908. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2909. );
  2910. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2911. $item = array (
  2912. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2913. );
  2914. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2915. $receivablesStaff = explode ( '-', $receivablesStaff );
  2916. $item = array (
  2917. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2918. );
  2919. }
  2920. $item += array (
  2921. 'date' => date ( "Y-m-d" ),
  2922. 'status' => 1,
  2923. 'img' => $this->staff [0] ['avatar'],
  2924. 'username' => $this->staff [0] ['username'],
  2925. 'uid' => $this->staff [0] ['sid'],
  2926. 'category' => $this->staff [0] ['category'],
  2927. 'irid' => $detail ['irid']
  2928. );
  2929. $invoiceROLog->setInvoiceROLog ( $item );
  2930. return '/invoiceReceivablesAS';
  2931. }
  2932. function invoiceReceivablesDelete() {
  2933. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2934. if (empty ( $claimKey ))
  2935. die ( 'illegal request' );
  2936. Doo::loadModel ( 'invoiceReceivables' );
  2937. $invoiceReceivables = new invoiceReceivables ();
  2938. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  2939. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2940. if (empty ( $detail ))
  2941. die ( 'illegal request' );
  2942. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  2943. return '/invoiceReceivablesAS';
  2944. }
  2945. /**
  2946. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  2947. */
  2948. function invoiceReceivablesAscription() {
  2949. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2950. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2951. Doo::loadModel ( 'invoiceReceivables' );
  2952. $invoiceReceivables = new invoiceReceivables ();
  2953. Doo::loadModel ( 'invoiceROLog' );
  2954. $invoiceROLog = new invoiceROLog ();
  2955. Doo::loadModel ( 'invoiceStatistics' );
  2956. $invoiceStatistics = new invoiceStatistics ();
  2957. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2958. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  2959. $item = array (
  2960. 'irid' => $detail ['irid'],
  2961. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  2962. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  2963. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2964. 'recepitTitleMark' => $recepitTitleMark,
  2965. 'source' => 1
  2966. );
  2967. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2968. $item = array (
  2969. 'date' => date ( "Y-m-d" ),
  2970. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  2971. 'status' => 2,
  2972. 'img' => $this->staff [0] ['avatar'],
  2973. 'username' => $this->staff [0] ['username'],
  2974. 'uid' => $this->staff [0] ['sid'],
  2975. 'category' => $this->staff [0] ['category'],
  2976. 'irid' => $irid
  2977. );
  2978. $invoiceROLog->setInvoiceROLog ( $item );
  2979. $item = array (
  2980. 'cid' => $this->staff [0] ['cid'],
  2981. 'staff' => $this->staff [0] ['sid']
  2982. );
  2983. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  2984. }
  2985. return "/invoiceReceivablesClaim";
  2986. }
  2987. /**
  2988. */
  2989. function invoiceMyReceivables() {
  2990. Doo::loadModel ( 'invoiceReceivables' );
  2991. $invoiceReceivables = new invoiceReceivables ();
  2992. Doo::loadModel ( 'invoiceStatistics' );
  2993. $invoiceStatistics = new invoiceStatistics ();
  2994. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  2995. $year = date ( "Y" );
  2996. $tmp_date = date ( "Ym" );
  2997. $tmp_year = substr ( $tmp_date, 0, 4 );
  2998. $tmp_mon = substr ( $tmp_date, 4, 2 );
  2999. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3000. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3001. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3002. $htm = $this->showCache ( $path );
  3003. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3004. $this->data ['isMonth'] = $isMonth;
  3005. $this->data ['htm'] = $htm;
  3006. $this->data ['list'] = $list;
  3007. $this->data ['memu'] = "invoice";
  3008. $this->data ['staff'] = $this->staff;
  3009. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3010. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3011. }
  3012. /**
  3013. * 纸票管理
  3014. */
  3015. function invoicePaper() {
  3016. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3017. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3018. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3019. $this->data ['dateString'] = $date;
  3020. $this->data ['status'] = $status;
  3021. $this->data ['invoiceType'] = $invoiceType;
  3022. $this->data ['memu'] = "invoice";
  3023. $this->data ['staff'] = $this->staff;
  3024. $this->data ['receiptMemu'] = 'invoicePaper';
  3025. $this->render ( "/admin/invoicePaper", $this->data );
  3026. }
  3027. /**
  3028. * 获得纸票分页数据
  3029. */
  3030. function ajaxGetinvoicePaperAchieve() {
  3031. Doo::loadModel ( 'invoicePaper' );
  3032. $invoicePaper = new invoicePaper ();
  3033. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3034. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3035. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3036. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3037. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3038. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3039. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3040. $MebSea = $this->get_args ( 'search' );
  3041. $MebSea = $MebSea ['value'];
  3042. $page_size = $length;
  3043. $con = '';
  3044. if ($status == 'ALL')
  3045. $con = ' where 1 ';
  3046. elseif ($status == 'PRINTED')
  3047. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=1 ';
  3048. elseif ($status == 'UNPRINT')
  3049. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=0 ';
  3050. elseif ($status == 'TICKET')
  3051. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3052. if ($invoiceType == 'ORDINARY')
  3053. $con .= ' and a.invoiceType=0 ';
  3054. elseif ($invoiceType == 'SPECIAL')
  3055. $con .= ' and a.invoiceType=1 ';
  3056. $dateArr = explode ( ':', $date );
  3057. $D1 = $dateString = '';
  3058. $D2 = '';
  3059. if (! empty ( $date )) {
  3060. $D1 = $dateArr [0];
  3061. if (isset ( $dateArr [1] ))
  3062. $D2 = $dateArr [1];
  3063. else
  3064. $D2 = '';
  3065. $dateString = $D1 . " : " . $D2;
  3066. }
  3067. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3068. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3069. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3070. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3071. if (! empty ( $MebSea ))
  3072. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3073. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3074. $sql = ' ' . $con;
  3075. $limit = $page . ',' . $page_size;
  3076. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3077. $paperList = array ();
  3078. foreach ( $list as $key => $value ) {
  3079. $irDetail = array ();
  3080. if ($value ['iid'] == 0)
  3081. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3082. else
  3083. array_push ( $irDetail, '' );
  3084. array_push ( $irDetail, $value ['invoiceCode'] );
  3085. array_push ( $irDetail, $value ['invoiceNo'] );
  3086. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3087. if ($value ['invoiceType'] == 1)
  3088. array_push ( $irDetail, $value ['invoiceCompany'] );
  3089. else
  3090. array_push ( $irDetail, $value ['invoiceTitle'] );
  3091. if ($value ['invoiceType'] == 1)
  3092. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3093. else
  3094. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3095. array_push ( $irDetail, $value ['invoiceElement'] );
  3096. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3097. array_push ( $irDetail, $value ['printTime'] );
  3098. array_push ( $paperList, $irDetail );
  3099. }
  3100. // $approvalListJson = json_encode ( $approvalList );
  3101. $recordsFiltered = $invoiceTotal;
  3102. echo json_encode ( array (
  3103. "draw" => intval ( $draw ),
  3104. "recordsTotal" => intval ( $invoiceTotal ),
  3105. "recordsFiltered" => intval ( $recordsFiltered ),
  3106. "data" => $paperList
  3107. ), JSON_UNESCAPED_UNICODE );
  3108. }
  3109. function invoicePaperDel() {
  3110. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3111. $XDeode = new XDeode ( 5 );
  3112. $ipid = $XDeode->decode ( $ipidKey );
  3113. if (empty ( $ipid ))
  3114. die ( 'illegal request' );
  3115. Doo::loadModel ( 'invoicePaper' );
  3116. $invoicePaper = new invoicePaper ();
  3117. $invoicePaper->delete ( array (
  3118. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3119. 'limit' => 1
  3120. ) );
  3121. return '/invoicePaper';
  3122. }
  3123. /**
  3124. * 添加纸质发票号
  3125. */
  3126. function invoicePaperAdd() {
  3127. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3128. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3129. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3130. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3131. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3132. $sum = $invoiceNoStart + $invoiceNoTotal;
  3133. if (empty ( $sum ))
  3134. die ( 'illegal request' );
  3135. Doo::db ()->beginTransaction ();
  3136. // 批量存储纸质发票
  3137. $date = date ( "Y-m-d H:i:s" );
  3138. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3139. VALUES ';
  3140. $paperList = array ();
  3141. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3142. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $invoiceNoStart . '","' . $date . '")';
  3143. array_push ( $paperList, $paperSql );
  3144. }
  3145. if (empty ( $paperList ))
  3146. die ( 'illegal request' );
  3147. $sql = $sql . implode ( ',', $paperList );
  3148. Doo::db ()->query ( $sql );
  3149. Doo::db ()->commit ();
  3150. return 'invoicePaper';
  3151. }
  3152. die ( 'illegal request' );
  3153. }
  3154. /**
  3155. * 收款绑定发票 ,一个收款只能绑定一个发票
  3156. */
  3157. function invoiceBindReceivables() {
  3158. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3159. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3160. Doo::loadModel ( 'invoice' );
  3161. $invoice = new invoice ();
  3162. Doo::loadModel ( 'invoiceReceivables' );
  3163. $invoiceReceivables = new invoiceReceivables ();
  3164. Doo::loadModel ( 'invoiceOperationLog' );
  3165. $invoiceOperationLog = new invoiceOperationLog ();
  3166. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3167. die ( 'illegal request' );
  3168. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3169. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3170. if (empty ( $detail ) && empty ( $detailM ))
  3171. die ( 'illegal request' );
  3172. if ($detail ['untreadStatus'] == 3)
  3173. die ( 'illegal request' );
  3174. // 修改 绑定状态改为 金额
  3175. $invoiceReceivables = new invoiceReceivables ();
  3176. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3177. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3178. $item = array (
  3179. 'bindPrice' => $invoicePrice
  3180. );
  3181. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3182. $item = array (
  3183. 'bindPrice' => $invoicePrice,
  3184. 'bindStatus' => 1,
  3185. 'bindDate' => date ( "Y-m-d H:i:s" )
  3186. );
  3187. } else {
  3188. die ( 'illegal request' );
  3189. }
  3190. if ($detailM ['iid'] == 0) {
  3191. $item += array (
  3192. 'iid' => $detail ['iid']
  3193. );
  3194. } else {
  3195. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3196. array_push ( $iidExtend, $detail ['iid'] );
  3197. $item += array (
  3198. 'iidExtend' => implode ( ',', $iidExtend )
  3199. );
  3200. }
  3201. $item += array (
  3202. 'irid' => $detailM ['irid'],
  3203. 'accountClerk' => $this->staff [0] ['username']
  3204. );
  3205. // 如何没有人收款 则自动绑定收款
  3206. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3207. $item += array (
  3208. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3209. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3210. );
  3211. }
  3212. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3213. $iridString = "";
  3214. if (empty ( $detail ['irid'] ))
  3215. $iridString = $detailM ['irid'];
  3216. else
  3217. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3218. $item = array (
  3219. 'iid' => $detail ['iid'],
  3220. 'irid' => $iridString
  3221. );
  3222. $invoiceReceivables = new invoiceReceivables ();
  3223. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3224. if ($detail ['invoicePrice'] <= $sum)
  3225. $item += array (
  3226. 'untreadStatus' => 3,
  3227. 'bindTime' => date ( "Y-m-d H:i:s" )
  3228. );
  3229. // print_r($item);
  3230. // echo $sum;die;
  3231. $invoice->setInvoiceByCondition ( $item );
  3232. // 操作日志
  3233. $item = array (
  3234. 'date' => date ( "Y-m-d H:i:s" ),
  3235. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3236. 'status' => 8,
  3237. 'img' => $this->staff [0] ['avatar'],
  3238. 'username' => $this->staff [0] ['username'],
  3239. 'uid' => $this->staff [0] ['sid'],
  3240. 'category' => $this->staff [0] ['category'],
  3241. 'iid' => $detail ['iid']
  3242. );
  3243. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3244. Doo::loadModel ( 'invoiceStatistics' );
  3245. $invoiceStatistics = new invoiceStatistics ();
  3246. $item = array (
  3247. 'date' => $detailM ['receivablesDate'],
  3248. 'priceClass' => 3,
  3249. 'cid' => $detail ['cid'],
  3250. 'staff' => $detail ['sid'],
  3251. 'accountPrice' => $detailM ['receivablesPrice']
  3252. );
  3253. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3254. return "/invoiceReceivables";
  3255. }
  3256. /**
  3257. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3258. */
  3259. function invoiceAggregate() {
  3260. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3261. Doo::loadModel ( 'invoiceStatistics' );
  3262. $invoiceStatistics = new invoiceStatistics ();
  3263. Doo::loadModel ( 'L_category' );
  3264. $Lcategory = new L_category ();
  3265. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3266. $LcategoryList = $Lcategory->getCategory ();
  3267. // print_r($isList);
  3268. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3269. foreach ( $LcategoryList as $key => $value ) {
  3270. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3271. $month = 1;
  3272. $invoicePriceYear = 0;
  3273. $receivablesPriceYear = 0;
  3274. $accountPriceYear = 0;
  3275. for(; $month <= 12; $month ++) {
  3276. $flag = true;
  3277. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3278. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3279. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3280. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3281. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3282. ';
  3283. $invoicePriceYear += $v ['invoicePrice'];
  3284. $receivablesPriceYear += $v ['receivablesPrice'];
  3285. $accountPriceYear += $v ['accountPrice'];
  3286. $flag = false;
  3287. break;
  3288. }
  3289. }
  3290. if ($flag)
  3291. $html .= '<td class="taR"></td>
  3292. <td class="taR"></td>
  3293. <td class="taR"><b></b></td>
  3294. ';
  3295. }
  3296. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3297. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3298. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3299. ';
  3300. $html .= '</tr>';
  3301. }
  3302. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3303. $invoicePriceYear = 0;
  3304. $receivablesPriceYear = 0;
  3305. $accountPriceYear = 0;
  3306. for($month = 1; $month <= 12; $month ++) {
  3307. $flag = true;
  3308. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3309. if ($month == $v ['month']) {
  3310. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3311. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3312. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3313. ';
  3314. $invoicePriceYear += $v ['invoicePrice'];
  3315. $receivablesPriceYear += $v ['receivablesPrice'];
  3316. $accountPriceYear += $v ['accountPrice'];
  3317. $flag = false;
  3318. break;
  3319. }
  3320. }
  3321. if ($flag) {
  3322. $html .= '<td class="taR"></td>
  3323. <td class="taR"></td>
  3324. <td class="taR"><b></b></td>
  3325. ';
  3326. }
  3327. }
  3328. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3329. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3330. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3331. ';
  3332. $html .= '</tr>';
  3333. // print_r($isList);
  3334. $this->data ['html'] = $html;
  3335. $this->data ['LcategoryList'] = $LcategoryList;
  3336. $this->data ['isList'] = $isList;
  3337. $this->data ['year'] = $year;
  3338. $this->data ['memu'] = "invoice";
  3339. $this->data ['staff'] = $this->staff;
  3340. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3341. $this->render ( "/admin/invoiceAggregate", $this->data );
  3342. }
  3343. function invoiceAggregateStaff() {
  3344. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3345. Doo::loadModel ( 'invoiceStatistics' );
  3346. $invoiceStatistics = new invoiceStatistics ();
  3347. Doo::loadModel ( 'L_category' );
  3348. $Lcategory = new L_category ();
  3349. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3350. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3351. $cStaff = $Lcategory->getCategoryStaff ();
  3352. $html = '';
  3353. foreach ( $cStaff as $key => $value ) {
  3354. $categoryFir = true;
  3355. foreach ( $value ['staff'] as $k => $v ) {
  3356. if ($categoryFir) {
  3357. $width = count ( $value ['staff'] ) + 1;
  3358. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3359. $categoryFir = false;
  3360. } else
  3361. $html .= '<tr>';
  3362. $html .= '<th>' . $v ['username'] . '</th>';
  3363. $invoicePriceStaffYear = 0;
  3364. $receivablesPriceStaffYear = 0;
  3365. $accountPriceStaffYear = 0;
  3366. for($month = 1; $month <= 12; $month ++) {
  3367. $flag = true;
  3368. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3369. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3370. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3371. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3372. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3373. ';
  3374. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3375. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3376. $accountPriceStaffYear += $slv ['accountPrice'];
  3377. $flag = false;
  3378. break;
  3379. }
  3380. }
  3381. if ($flag)
  3382. $html .= '<td class="taR"></td>
  3383. <td class="taR"></td>
  3384. <td class="taR"><b></b></td>
  3385. ';
  3386. }
  3387. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3388. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3389. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3390. ';
  3391. }
  3392. $html .= '</tr>';
  3393. // 小计
  3394. if (! empty ( $value ['staff'] )) {
  3395. $html .= '<tr><th class="taR">小计</th>';
  3396. $invoicePriceStaffYear = 0;
  3397. $receivablesPriceStaffYear = 0;
  3398. $accountPriceStaffYear = 0;
  3399. for($month = 1; $month <= 12; $month ++) {
  3400. $flag = true;
  3401. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3402. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3403. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3404. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3405. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3406. ';
  3407. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3408. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3409. $accountPriceStaffYear += $slv ['accountPrice'];
  3410. $flag = false;
  3411. break;
  3412. }
  3413. }
  3414. if ($flag)
  3415. $html .= '<td class="taR"></td>
  3416. <td class="taR"></td>
  3417. <td class="taR"><b></b></td>
  3418. ';
  3419. }
  3420. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3421. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3422. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3423. ';
  3424. $html .= '</tr>';
  3425. }
  3426. }
  3427. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3428. $invoicePriceYear = 0;
  3429. $receivablesPriceYear = 0;
  3430. $accountPriceYear = 0;
  3431. for($month = 1; $month <= 12; $month ++) {
  3432. $flag = true;
  3433. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3434. if ($month == $v ['month']) {
  3435. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3436. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3437. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3438. ';
  3439. $invoicePriceYear += $v ['invoicePrice'];
  3440. $receivablesPriceYear += $v ['receivablesPrice'];
  3441. $accountPriceYear += $v ['accountPrice'];
  3442. $flag = false;
  3443. break;
  3444. }
  3445. }
  3446. if ($flag)
  3447. $html .= '<td class="taR"></td>
  3448. <td class="taR"></td>
  3449. <td class="taR"><b></b></td>
  3450. ';
  3451. }
  3452. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3453. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3454. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3455. ';
  3456. $html .= '</tr>';
  3457. $this->data ['html'] = $html;
  3458. $this->data ['isList'] = $toteList;
  3459. $this->data ['year'] = $year;
  3460. $this->data ['memu'] = "invoice";
  3461. $this->data ['staff'] = $this->staff;
  3462. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3463. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3464. }
  3465. function invoiceAggregateCategory() {
  3466. Doo::loadClass ( 'XDeode' );
  3467. $XDeode = new XDeode ( 5 );
  3468. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3469. $cid = $XDeode->decode ( $cid );
  3470. if (! is_numeric ( $cid ))
  3471. die ( 'illegal request' );
  3472. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3473. Doo::loadModel ( 'invoiceStatistics' );
  3474. $invoiceStatistics = new invoiceStatistics ();
  3475. Doo::loadModel ( 'staff' );
  3476. $staff = new staff ();
  3477. $list = $staff->getStaffByCid ( $cid );
  3478. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3479. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3480. if (empty ( $list ))
  3481. die ( '该办事处没有成员' );
  3482. $htmlA = $htmlB = $htmlC = $html = '';
  3483. foreach ( $list as $key => $value ) {
  3484. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3485. $htmlB = '<tr><th class="taC">收款</th>';
  3486. $htmlC = '<tr><th class="taC">入账</th>';
  3487. $invoicePriceStaffYear = 0;
  3488. $receivablesPriceStaffYear = 0;
  3489. $accountPriceStaffYear = 0;
  3490. for($month = 1; $month <= 12; $month ++) {
  3491. $flag = true;
  3492. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3493. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3494. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3495. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3496. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3497. $invoicePriceStaffYear += $v ['invoicePrice'];
  3498. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3499. $accountPriceStaffYear += $v ['accountPrice'];
  3500. $flag = false;
  3501. break;
  3502. }
  3503. }
  3504. if ($flag) {
  3505. $htmlA .= '<td class="taR">-</td>';
  3506. $htmlB .= '<td class="taR">-</td>';
  3507. $htmlC .= '<td class="taR"><b>-</b></td>';
  3508. }
  3509. }
  3510. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3511. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3512. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3513. $htmlA .= '</tr>';
  3514. $htmlB .= '</tr>';
  3515. $htmlC .= '</tr>';
  3516. $html .= $htmlA . $htmlB . $htmlC;
  3517. }
  3518. $htmlA = $htmlB = $htmlC = "";
  3519. $htmlA = '<tr><th rowspan="3">月合计</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 ['statisticsMonth'] as $k => $v ) {
  3528. if ($month == $v ['month']) {
  3529. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3530. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3531. $htmlC .= '<td class="taR colGreen"><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. $this->data ['html'] = $html;
  3553. $this->data ['cidKey'] = $cidKey;
  3554. $this->data ['slist'] = $list;
  3555. $this->data ['isList'] = $toteList;
  3556. $this->data ['year'] = $year;
  3557. $this->data ['memu'] = "invoice";
  3558. $this->data ['staff'] = $this->staff;
  3559. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3560. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3561. }
  3562. /**
  3563. * 办事处汇总信息
  3564. */
  3565. function invoiceAggregateCategoryDetail() {
  3566. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  3567. Doo::loadClass ( 'XDeode' );
  3568. $XDeode = new XDeode ( 5 );
  3569. Doo::loadModel ( 'invoiceStatistics' );
  3570. $invoiceStatistics = new invoiceStatistics ();
  3571. Doo::loadModel ( 'L_category' );
  3572. $category = new L_category ();
  3573. Doo::loadModel ( 'invoice' );
  3574. $invoice = new invoice ();
  3575. Doo::loadModel ( 'staff' );
  3576. $staff = new staff ();
  3577. Doo::loadModel ( "invoiceCategoryManage" );
  3578. $invoiceCategoryManage = new invoiceCategoryManage ();
  3579. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3580. $cidList = array ();
  3581. foreach ( $imcStaff as $key => $value ) {
  3582. array_push ( $cidList, $value ['cid'] );
  3583. if (empty ( $cidKey ))
  3584. $cidKey = $XDeode->encode ( $value ['cid'] );
  3585. }
  3586. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  3587. $cid = $XDeode->decode ( $cidKey );
  3588. $month = date ( "m", strtotime ( "-1 month" ) );
  3589. $redis = new Redis ();
  3590. $redis->connect ( '127.0.0.1', '6379' );
  3591. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  3592. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  3593. if (empty ( $redisValue )) {
  3594. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  3595. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  3596. // 获得办事处人员下的汇总
  3597. $slist = $staff->getStaffByCid ( $cid );
  3598. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $month ); // 上一个月的汇总
  3599. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  3600. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  3601. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  3602. foreach ( $slist as $key => $value ) {
  3603. $slist [$key] ['invoicePrice'] = 0;
  3604. $slist [$key] ['receivablesPrice'] = 0;
  3605. $slist [$key] ['accountPrice'] = 0;
  3606. $slist [$key] ['invoiceAllPrice'] = 0;
  3607. $slist [$key] ['receivablesAllPrice'] = 0;
  3608. $slist [$key] ['accountAllPrice'] = 0;
  3609. $slist [$key] ['schedule'] = 0;
  3610. $slist [$key] ['invoiceMonthPrice'] = 0;
  3611. $slist [$key] ['receivablesMonthPrice'] = 0;
  3612. $slist [$key] ['accountMonthPrice'] = 0;
  3613. foreach ( $ismsbMonth as $y => $l ) {
  3614. if ($value ['sid'] == $l ['staff']) {
  3615. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  3616. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  3617. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  3618. }
  3619. }
  3620. foreach ( $ismsb as $k => $v ) {
  3621. if ($value ['sid'] == $v ['staff']) {
  3622. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  3623. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  3624. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  3625. }
  3626. }
  3627. foreach ( $ISAS as $e => $a ) {
  3628. if ($value ['sid'] == $a ['staff']) {
  3629. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  3630. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  3631. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  3632. }
  3633. }
  3634. if (isset ( $scheduleStaff [$value ['sid']] ))
  3635. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  3636. }
  3637. $this->data ['cidKey'] = $cidKey;
  3638. $schedule = ( int ) ($schedule * 100);
  3639. $this->data ['slist'] = $slist;
  3640. $this->data ['isMC'] = $isMC;
  3641. $this->data ['schedule'] = $schedule;
  3642. $slist = json_encode ( $slist );
  3643. $isMC = json_encode ( $isMC );
  3644. $schedule = json_encode ( $schedule );
  3645. $redis->lpush ( $redisKey, $slist );
  3646. $redis->lpush ( $redisKey, $isMC );
  3647. $redis->lpush ( $redisKey, $schedule );
  3648. } else {
  3649. $this->data ['cidKey'] = $cidKey;
  3650. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  3651. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  3652. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  3653. }
  3654. $this->data ['month'] = $month;
  3655. $this->data ['categoryList'] = $categoryList;
  3656. $this->data ['memu'] = "invoice";
  3657. $this->data ['staff'] = $this->staff;
  3658. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3659. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  3660. }
  3661. /**
  3662. * 办事处人员汇总详情
  3663. */
  3664. function invoiceAggregateStaffDetail() {
  3665. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3666. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  3667. Doo::loadClass ( 'XDeode' );
  3668. $XDeode = new XDeode ( 5 );
  3669. Doo::loadModel ( 'invoice' );
  3670. $invoice = new invoice ();
  3671. Doo::loadModel ( 'staff' );
  3672. $staff = new staff ();
  3673. Doo::loadModel ( "invoiceCategoryManage" );
  3674. $invoiceCategoryManage = new invoiceCategoryManage ();
  3675. $sid = $XDeode->decode ( $sidKey );
  3676. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3677. $cidList = array ();
  3678. foreach ( $imcStaff as $key => $value ) {
  3679. array_push ( $cidList, $value ['cid'] );
  3680. if (empty ( $cidKey ))
  3681. $cidKey = $XDeode->encode ( $value ['cid'] );
  3682. }
  3683. $cidString = implode ( ',', $cidList );
  3684. $staffList = $staff->getStaffInCid ( $cidString );
  3685. $staffDetail = $staff->getStaffBySid ( $sid );
  3686. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3687. $page_size = 18;
  3688. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3689. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3690. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3691. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3692. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3693. $dateArr = explode ( ':', $date );
  3694. $D1 = '';
  3695. $D2 = '';
  3696. if (! empty ( $date )) {
  3697. $D1 = $dateArr [0] . " 00:00:00 ";
  3698. if (isset ( $dateArr [1] ))
  3699. $D2 = $dateArr [1] . " 23:59:59 ";
  3700. else
  3701. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3702. // $D2 = $dateArr [1];
  3703. }
  3704. $con = ' status=2 ';
  3705. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3706. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3707. if ($status == 'UNRECORD')
  3708. $con .= ' and printStatus=1 and untreadStatus=0';
  3709. elseif ($status == 'RECORD')
  3710. $con .= ' and printStatus=1 and untreadStatus=3';
  3711. elseif ($status == 'BOUNCED')
  3712. $con .= ' and untreadStatus=2';
  3713. elseif ($status == 'PARTRECORD')
  3714. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  3715. elseif ($status == 'All') {
  3716. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  3717. }
  3718. $con .= ' and sid=' . $sid;
  3719. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  3720. if (! empty ( $MebSea )) {
  3721. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  3722. }
  3723. $pageinfo ['page'] = array (
  3724. 'previous' => ''
  3725. );
  3726. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  3727. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3728. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  3729. $this->data ['staffDetail'] = $staffDetail;
  3730. $this->data ['staffList'] = $staffList;
  3731. $this->data ['MebSeaEn'] = $MebSea;
  3732. $this->data ['MebSea'] = urlencode ( $MebSea );
  3733. $this->data ['date'] = $date;
  3734. $this->data ['page'] = $pageinfo;
  3735. $this->data ['get'] = $get;
  3736. $this->data ['list'] = $list;
  3737. $this->data ['status'] = $status;
  3738. $this->data ['sidKey'] = $sidKey;
  3739. $this->data ['memu'] = "invoice";
  3740. $this->data ['staff'] = $this->staff;
  3741. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3742. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  3743. }
  3744. /**
  3745. * 办事处人员汇总收款情
  3746. */
  3747. function invoiceAggregateStaffReceivablesDetail() {
  3748. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3749. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3750. Doo::loadModel ( 'invoiceReceivables' );
  3751. $invoiceReceivables = new invoiceReceivables ();
  3752. Doo::loadModel ( 'staff' );
  3753. $staff = new staff ();
  3754. Doo::loadModel ( "invoiceCategoryManage" );
  3755. $invoiceCategoryManage = new invoiceCategoryManage ();
  3756. Doo::loadClass ( 'XDeode' );
  3757. $XDeode = new XDeode ( 5 );
  3758. $sid = $XDeode->decode ( $sidKey );
  3759. $staffDetail = $staff->getStaffBySid ( $sid );
  3760. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3761. $cidList = array ();
  3762. foreach ( $imcStaff as $key => $value ) {
  3763. array_push ( $cidList, $value ['cid'] );
  3764. if (empty ( $cidKey ))
  3765. $cidKey = $XDeode->encode ( $value ['cid'] );
  3766. }
  3767. $cidString = implode ( ',', $cidList );
  3768. $staffList = $staff->getStaffInCid ( $cidString );
  3769. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3770. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  3771. $page_size = 10;
  3772. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3773. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3774. if ($timeType == "BINDOTP") {
  3775. $status = 'Credited';
  3776. }
  3777. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3778. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3779. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3780. $dateArr = explode ( ':', $date );
  3781. $D1 = '';
  3782. $D2 = '';
  3783. if (! empty ( $date )) {
  3784. $D1 = $dateArr [0] . " 00:00:00 ";
  3785. if (isset ( $dateArr [1] ))
  3786. $D2 = $dateArr [1] . " 23:59:59 ";
  3787. else
  3788. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3789. }
  3790. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  3791. $descField = 'a.bindDate';
  3792. if ($timeType == 'CREATE')
  3793. $descField = 'a.date';
  3794. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3795. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3796. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3797. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  3798. if ($status == 'Unclaimed')
  3799. $con .= ' and a.bindStatus=0';
  3800. elseif ($status == 'Credited')
  3801. $con .= ' and a.bindStatus=1';
  3802. elseif ($status == 'Claim')
  3803. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  3804. elseif ($status == 'BBN')
  3805. $con .= ' and a.bindPrice>a.receivablesPrice';
  3806. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  3807. if (! empty ( $MebSea )) {
  3808. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  3809. }
  3810. $pageinfo ['page'] = array (
  3811. 'previous' => ''
  3812. );
  3813. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  3814. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  3815. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  3816. where ' . $con . ' group by a.irid ';
  3817. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  3818. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3819. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  3820. foreach ( $list as $key => $value ) {
  3821. $list [$key] ['category'] = '';
  3822. if ($value ['receivablesCategory'] != 'PUBLIC') {
  3823. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  3824. $list [$key] ['category'] = $receivablesCategory [1];
  3825. }
  3826. }
  3827. // print_r($list);
  3828. $this->data ['staffDetail'] = $staffDetail;
  3829. $this->data ['sidKey'] = $sidKey;
  3830. $this->data ['staffList'] = $staffList;
  3831. $this->data ['timeType'] = $timeType;
  3832. $this->data ['MebSeaEn'] = $MebSea;
  3833. $this->data ['MebSea'] = urlencode ( $MebSea );
  3834. $this->data ['date'] = $date;
  3835. $this->data ['page'] = $pageinfo;
  3836. $this->data ['get'] = $get;
  3837. $this->data ['list'] = $list;
  3838. $this->data ['status'] = $status;
  3839. $this->data ['memu'] = "invoice";
  3840. $this->data ['staff'] = $this->staff;
  3841. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3842. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  3843. }
  3844. function invoiceAchieve() {
  3845. Doo::loadModel ( 'invoice' );
  3846. $invoice = new invoice ();
  3847. Doo::loadClass ( 'XDeode' );
  3848. $XDeode = new XDeode ( 5 );
  3849. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3850. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3851. $page_size = 18;
  3852. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3853. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3854. $get = "/" . $date;
  3855. $con = '';
  3856. if ($date == 'MONTHO')
  3857. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3858. elseif ($date == 'MONTHT')
  3859. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3860. elseif ($date == 'MONTHY')
  3861. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3862. if (! empty ( $MebSea )) {
  3863. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3864. $get .= "/" . $MebSea;
  3865. }
  3866. $pageinfo ['page'] = array (
  3867. 'previous' => ''
  3868. );
  3869. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  3870. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  3871. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3872. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3873. // print_r($pageinfo);
  3874. $this->data ['MebSeaEn'] = $MebSea;
  3875. $this->data ['MebSea'] = urlencode ( $MebSea );
  3876. $this->data ['get'] = $get;
  3877. $this->data ['page'] = $pageinfo;
  3878. $this->data ['list'] = $list;
  3879. $this->data ['date'] = $date;
  3880. $this->data ['memu'] = "invoice";
  3881. $this->data ['staff'] = $this->staff;
  3882. $this->data ['receiptMemu'] = 'invoice';
  3883. $this->render ( "/admin/invoiceAchieve", $this->data );
  3884. }
  3885. function invoiceMyUnAccountAchieve() {
  3886. Doo::loadModel ( 'invoice' );
  3887. $invoice = new invoice ();
  3888. Doo::loadClass ( 'XDeode' );
  3889. $XDeode = new XDeode ( 5 );
  3890. Doo::loadModel ( 'staff' );
  3891. $staff = new staff ();
  3892. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3893. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3894. $page_size = 18;
  3895. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3896. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3897. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3898. $dateArr = explode ( ':', $date );
  3899. $D1 = '';
  3900. $D2 = '';
  3901. if (! empty ( $date )) {
  3902. $D1 = $dateArr [0];
  3903. $D2 = $dateArr [1];
  3904. }
  3905. $con = '';
  3906. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3907. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3908. if (! empty ( $MebSea )) {
  3909. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3910. }
  3911. $pageinfo ['page'] = array (
  3912. 'previous' => ''
  3913. );
  3914. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  3915. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  3916. $action = "invoiceMyUnAccountAchieve";
  3917. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  3918. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3919. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3920. Doo::loadModel ( 'express' );
  3921. $express = new express ();
  3922. $expressList = $express->getExpressByAll ();
  3923. $this->data ['expressList'] = $expressList;
  3924. // print_r($list);
  3925. $this->data ['MebSeaEn'] = $MebSea;
  3926. $this->data ['get'] = $get;
  3927. $this->data ['page'] = $pageinfo;
  3928. $this->data ['date'] = $date;
  3929. $this->data ['list'] = $list;
  3930. $this->data ['memu'] = "invoice";
  3931. $this->data ['staff'] = $this->staff;
  3932. $this->data ['receiptMemu'] = 'invoice';
  3933. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  3934. }
  3935. function invoiceReceivablesAchieve() {
  3936. Doo::loadModel ( 'invoiceReceivables' );
  3937. $invoiceReceivables = new invoiceReceivables ();
  3938. Doo::loadClass ( 'XDeode' );
  3939. $XDeode = new XDeode ( 5 );
  3940. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3941. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3942. $page_size = 12;
  3943. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3944. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3945. $get = "/" . $date;
  3946. $con = '';
  3947. if ($date == 'MONTHO')
  3948. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3949. elseif ($date == 'MONTHT')
  3950. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3951. elseif ($date == 'MONTHY')
  3952. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3953. if (! empty ( $MebSea )) {
  3954. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  3955. $get .= "/" . $MebSea;
  3956. }
  3957. $pageinfo ['page'] = array (
  3958. 'previous' => ''
  3959. );
  3960. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  3961. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  3962. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3963. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  3964. // print_r($pageinfo);
  3965. $this->data ['MebSeaEn'] = $MebSea;
  3966. $this->data ['MebSea'] = urlencode ( $MebSea );
  3967. $this->data ['get'] = $get;
  3968. $this->data ['page'] = $pageinfo;
  3969. $this->data ['list'] = $list;
  3970. $this->data ['date'] = $date;
  3971. $this->data ['memu'] = "invoice";
  3972. $this->data ['staff'] = $this->staff;
  3973. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3974. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  3975. }
  3976. /**
  3977. * 收款解绑
  3978. */
  3979. function invoiceUnBundLing() {
  3980. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  3981. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  3982. Doo::loadModel ( 'invoice' );
  3983. $invoice = new invoice ();
  3984. Doo::loadModel ( 'invoiceReceivables' );
  3985. $invoiceReceivables = new invoiceReceivables ();
  3986. Doo::loadModel ( 'invoiceOperationLog' );
  3987. $invoiceOperationLog = new invoiceOperationLog ();
  3988. Doo::loadModel ( 'invoiceROLog' );
  3989. $invoiceROLog = new invoiceROLog ();
  3990. Doo::loadModel ( 'invoiceStatistics' );
  3991. Doo::loadClass ( 'XDeode' );
  3992. $XDeode = new XDeode ( 5 );
  3993. if (empty ( $iidKey ))
  3994. die ( 'illegal request' );
  3995. $iid = $XDeode->decode ( $iidKey );
  3996. $irid = $invoice->authcode ( $unBundKey );
  3997. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  3998. die ( 'illegal request' );
  3999. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4000. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4001. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4002. die ( 'illegal request' );
  4003. // 收款
  4004. $item = array (
  4005. 'irid' => $irDetails ['irid'],
  4006. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4007. 'bindStatus' => 0
  4008. );
  4009. if ($irDetails ['iid'] == $iid)
  4010. $item += array (
  4011. 'iid' => 0
  4012. );
  4013. else {
  4014. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4015. foreach ( $iidExtend as $key => $value ) {
  4016. if ($value == $iid)
  4017. unset ( $iidExtend [$key] );
  4018. }
  4019. $iidExtend = implode ( ',', $iidExtend );
  4020. $item += array (
  4021. 'iidExtend' => $iidExtend
  4022. );
  4023. }
  4024. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4025. // 收款操作日志
  4026. $item = array (
  4027. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4028. 'date' => date ( "Y-m-d" ),
  4029. 'status' => 3,
  4030. 'img' => $this->staff [0] ['avatar'],
  4031. 'username' => $this->staff [0] ['username'],
  4032. 'uid' => $this->staff [0] ['sid'],
  4033. 'category' => $this->staff [0] ['category'],
  4034. 'irid' => $irid
  4035. );
  4036. $invoiceROLog->setInvoiceROLog ( $item );
  4037. // 扣除入账统计金额
  4038. $invoiceStatistics = new invoiceStatistics ();
  4039. $item = array (
  4040. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4041. 'priceClass' => 3,
  4042. 'cid' => $invoiceDetails ['cid'],
  4043. 'staff' => $invoiceDetails ['sid'],
  4044. 'accountPrice' => - $irDetails ['receivablesPrice']
  4045. );
  4046. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4047. // 扣除收款统计金额
  4048. $invoiceStatistics = new invoiceStatistics ();
  4049. $item = array (
  4050. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4051. 'priceClass' => 2,
  4052. 'cid' => $invoiceDetails ['cid'],
  4053. 'staff' => $invoiceDetails ['sid'],
  4054. 'irid' => $irDetails ['irid'],
  4055. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4056. );
  4057. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4058. // 发票解绑去收款ID
  4059. $iridString = $invoiceDetails ['irid'];
  4060. if (! empty ( $invoiceDetails ['irid'] )) {
  4061. $list = explode ( ',', $invoiceDetails ['irid'] );
  4062. foreach ( $list as $key => $value ) {
  4063. if ($value == $irDetails ['irid']) {
  4064. unset ( $list [$key] );
  4065. break;
  4066. }
  4067. }
  4068. $iridString = implode ( ",", $list );
  4069. }
  4070. $item = array (
  4071. 'iid' => $invoiceDetails ['iid'],
  4072. 'irid' => $iridString,
  4073. 'updateTime' => date ( "Y-m-d H:i:s" )
  4074. );
  4075. if ($invoiceDetails ['untreadStatus'] == 3)
  4076. $item += array (
  4077. 'untreadStatus' => 0
  4078. );
  4079. $invoice->setInvoiceByCondition ( $item );
  4080. $item = array (
  4081. 'date' => date ( "Y-m-d H:i:s" ),
  4082. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4083. 'status' => 11,
  4084. 'img' => $this->staff [0] ['avatar'],
  4085. 'username' => $this->staff [0] ['username'],
  4086. 'uid' => $this->staff [0] ['sid'],
  4087. 'category' => $this->staff [0] ['category'],
  4088. 'iid' => $invoiceDetails ['iid']
  4089. );
  4090. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4091. return "/invoiceReceivablesAS";
  4092. }
  4093. /**
  4094. * 或者该收款下的所以发票
  4095. */
  4096. function ajaxGetInvoiceReceivablesByInvoice() {
  4097. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4098. Doo::loadModel ( 'invoice' );
  4099. $invoice = new invoice ();
  4100. Doo::loadModel ( 'invoiceReceivables' );
  4101. $invoiceReceivables = new invoiceReceivables ();
  4102. $irid = $invoice->authcode ( $irid );
  4103. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4104. die ( 'illegal request' );
  4105. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4106. $iidString = $irDetails ['iid'];
  4107. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4108. if (! empty ( $irDetails ['iidExtend'] ))
  4109. $iidString .= ',' . implode ( ',', $iidExtend );
  4110. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4111. $html = "";
  4112. foreach ( $invoiceList as $key => $value ) {
  4113. $title = $value ['invoiceTitle'];
  4114. if (! empty ( $value ['invoiceCompany'] ))
  4115. $title = $value ['invoiceCompany'];
  4116. $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>';
  4117. }
  4118. echo json_encode ( array (
  4119. 'status' => 1,
  4120. 'html' => $html
  4121. ) );
  4122. }
  4123. /**
  4124. * 发票管理
  4125. */
  4126. function invoiceAS() {
  4127. Doo::loadModel ( 'invoice' );
  4128. $invoice = new invoice ();
  4129. Doo::loadModel ( 'invoiceReceivables' );
  4130. $invoiceReceivables = new invoiceReceivables ();
  4131. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4132. $page_size = 18;
  4133. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4134. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4135. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4136. $dateArr = explode ( ':', $date );
  4137. $D1 = '';
  4138. $D2 = '';
  4139. if (! empty ( $date )) {
  4140. $D1 = $dateArr [0] . " 00:00:00 ";
  4141. if (isset ( $dateArr [1] ))
  4142. $D2 = $dateArr [1] . " 23:59:59 ";
  4143. else
  4144. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4145. // $D2 = $dateArr [1];
  4146. }
  4147. $con = ' status=2 ';
  4148. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4149. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4150. if ($status == 'UNRECORD')
  4151. $con .= ' and printStatus=1 and untreadStatus=0';
  4152. elseif ($status == 'RECORD')
  4153. $con .= ' and printStatus=1 and untreadStatus=3';
  4154. elseif ($status == 'BOUNCED')
  4155. $con .= ' and untreadStatus=2';
  4156. elseif ($status == 'PARTRECORD')
  4157. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4158. elseif ($status == 'All') {
  4159. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4160. }
  4161. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4162. if (! empty ( $MebSea )) {
  4163. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4164. }
  4165. $pageinfo ['page'] = array (
  4166. 'previous' => ''
  4167. );
  4168. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4169. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4170. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4171. $this->data ['MebSeaEn'] = $MebSea;
  4172. $this->data ['MebSea'] = urlencode ( $MebSea );
  4173. $this->data ['date'] = $date;
  4174. $this->data ['page'] = $pageinfo;
  4175. $this->data ['get'] = $get;
  4176. $this->data ['list'] = $list;
  4177. $this->data ['status'] = $status;
  4178. $this->data ['memu'] = "invoice";
  4179. $this->data ['staff'] = $this->staff;
  4180. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4181. $this->render ( "/admin/invoiceAS", $this->data );
  4182. }
  4183. /**
  4184. * 收款管理
  4185. */
  4186. function invoiceReceivablesAS() {
  4187. Doo::loadModel ( 'invoiceReceivables' );
  4188. $invoiceReceivables = new invoiceReceivables ();
  4189. Doo::loadModel ( 'L_category' );
  4190. $lCategory = new L_category ();
  4191. $category = $lCategory->getCategory ();
  4192. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4193. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4194. $page_size = 10;
  4195. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4196. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4197. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4198. $dateArr = explode ( ':', $date );
  4199. $D1 = '';
  4200. $D2 = '';
  4201. if (! empty ( $date )) {
  4202. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4203. if (isset ( $dateArr [1] ))
  4204. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4205. else
  4206. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4207. }
  4208. $descField = 'a.receivablesDate';
  4209. if ($timeType == 'CREATE')
  4210. $descField = 'a.date';
  4211. $con = '1';
  4212. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4213. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4214. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4215. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4216. if ($status == 'Unclaimed')
  4217. $con .= ' and a.bindStatus=0';
  4218. elseif ($status == 'Credited')
  4219. $con .= ' and a.bindStatus=1';
  4220. elseif ($status == 'Claim')
  4221. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4222. elseif ($status == 'BBN')
  4223. $con .= ' and a.bankBatchNumber!=""';
  4224. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4225. if (! empty ( $MebSea )) {
  4226. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4227. }
  4228. $pageinfo ['page'] = array (
  4229. 'previous' => ''
  4230. );
  4231. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4232. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4233. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4234. where ' . $con . ' group by a.irid ';
  4235. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4236. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4237. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4238. foreach ( $list as $key => $value ) {
  4239. $list [$key] ['category'] = '';
  4240. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4241. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4242. $list [$key] ['category'] = $receivablesCategory [1];
  4243. }
  4244. }
  4245. // print_r($list);
  4246. $this->data ['category'] = $category;
  4247. $this->data ['timeType'] = $timeType;
  4248. $this->data ['MebSeaEn'] = $MebSea;
  4249. $this->data ['MebSea'] = urlencode ( $MebSea );
  4250. $this->data ['date'] = $date;
  4251. $this->data ['page'] = $pageinfo;
  4252. $this->data ['get'] = $get;
  4253. $this->data ['list'] = $list;
  4254. $this->data ['status'] = $status;
  4255. $this->data ['memu'] = "invoice";
  4256. $this->data ['staff'] = $this->staff;
  4257. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4258. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4259. }
  4260. // function invoiceApprovalAchieve() {
  4261. // Doo::loadModel ( 'invoice' );
  4262. // $invoice = new invoice ();
  4263. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4264. // $page_size = 12;
  4265. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4266. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4267. // $get = "/" . $date;
  4268. // $con = '';
  4269. // if ($date == 'MONTHO')
  4270. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4271. // elseif ($date == 'MONTHT')
  4272. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4273. // elseif ($date == 'MONTHY')
  4274. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4275. // if (! empty ( $MebSea )) {
  4276. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4277. // $get .= "/" . $MebSea;
  4278. // }
  4279. // $pageinfo ['page'] = array (
  4280. // 'previous' => ''
  4281. // );
  4282. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  4283. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4284. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  4285. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4286. // // print_r($list);
  4287. // $this->data ['MebSeaEn'] = $MebSea;
  4288. // $this->data ['MebSea'] = urlencode ( $MebSea );
  4289. // $this->data ['get'] = $get;
  4290. // $this->data ['page'] = $pageinfo;
  4291. // $this->data ['list'] = $list;
  4292. // $this->data ['date'] = $date;
  4293. // $this->data ['memu'] = "invoice";
  4294. // $this->data ['staff'] = $this->staff;
  4295. // $this->data ['receiptMemu'] = 'invoiceApproval';
  4296. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4297. // }
  4298. /**
  4299. * 获得审批发票的信息以及审批页面
  4300. */
  4301. function ajaxGetInvoiceApprovalDetail() {
  4302. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4303. if (empty ( $serial )) {
  4304. echo json_encode ( array (
  4305. 'status' => 2,
  4306. 'msg' => 'illegal request'
  4307. ) );
  4308. die ();
  4309. }
  4310. Doo::loadModel ( 'invoice' );
  4311. $invoice = new invoice ();
  4312. Doo::loadModel ( 'invoiceOperationLog' );
  4313. $invoiceOperationLog = new invoiceOperationLog ();
  4314. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4315. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4316. if (empty ( $detail ))
  4317. $html = '';
  4318. else {
  4319. $html = '
  4320. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  4321. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4322. <input type="hidden" name="status" value="">
  4323. <input type="hidden" name="divApproval" value="divApproval">
  4324. <div class="modal-dialog modal-lg">
  4325. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  4326. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4327. <tr>
  4328. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  4329. </tr>
  4330. <tr>
  4331. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4332. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4333. </tr>
  4334. <tr>
  4335. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4336. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4337. </tr>
  4338. <tr>
  4339. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4340. </td>
  4341. </tr>
  4342. <tr>
  4343. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4344. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4345. </tr>
  4346. <tr>
  4347. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4348. </tr></tbody></table>';
  4349. if ($detail ['invoiceType'] == 0)
  4350. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4351. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4352. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4353. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4354. </tr>';
  4355. else
  4356. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4357. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4358. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4359. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4360. ';
  4361. $html .= '<tr>
  4362. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4363. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4364. </tr>
  4365. <tr>
  4366. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4367. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4368. </tr></tbody></table>';
  4369. if ($detail ['doPost'] == 1) {
  4370. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4371. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4372. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4373. </tr><tr>
  4374. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4375. </tr><tr>
  4376. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4377. </tr>
  4378. ';
  4379. if ($detail ['expressCom'] == 'SF')
  4380. $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>';
  4381. else
  4382. $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>';
  4383. $html .= '</tbody></table>';
  4384. }
  4385. if (! empty ( $invoiceOperationLogList )) {
  4386. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4387. foreach ( $invoiceOperationLogList as $key => $value ) {
  4388. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4389. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4390. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4391. if ($value ['status'] == 2) {
  4392. $html .= '<span class="colGreen">同意</span>';
  4393. } elseif ($value ['status'] == 3) {
  4394. $html .= '<span class="colOrange">退回</span>';
  4395. } elseif ($value ['status'] == 5) {
  4396. $html .= '<span class="colGreen">打印</span>';
  4397. } elseif ($value ['status'] == 4) {
  4398. $html .= '<span class="colRed">终止</span>';
  4399. }
  4400. $html .= $value ['operation'] . '</p></blockquote>';
  4401. }
  4402. }
  4403. $html .= '</td></tr></tbody></table>';
  4404. }
  4405. $html .= '</div><div class="modal-footer">
  4406. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  4407. <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>
  4408. <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>
  4409. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  4410. </form>
  4411. <script type="text/javascript">
  4412. $("a[node-approval^=\'approval\']").click(function() {
  4413. $("input[name=\'status\']").val($(this).attr("diss-data"));
  4414. $("form[name=\'invoiceApproval\']").submit();
  4415. });
  4416. </script>
  4417. ';
  4418. }
  4419. echo json_encode ( array (
  4420. 'status' => 1,
  4421. 'html' => $html
  4422. ) );
  4423. die ();
  4424. }
  4425. /**
  4426. * 获得审批发票分页数据
  4427. */
  4428. function ajaxGetinvoiceApprovalAchieve() {
  4429. Doo::loadModel ( 'invoice' );
  4430. $invoice = new invoice ();
  4431. Doo::loadModel ( 'staff' );
  4432. $staff = new staff ();
  4433. Doo::loadClass ( 'XDeode' );
  4434. $XDeode = new XDeode ( 5 );
  4435. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  4436. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4437. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4438. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4439. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4440. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  4441. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  4442. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  4443. $MebSea = $this->get_args ( 'search' );
  4444. $MebSea = $MebSea ['value'];
  4445. $page_size = $length;
  4446. $con = '';
  4447. if ($status == 'ALL')
  4448. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  4449. elseif ($status == 'PEND')
  4450. $con = ' isDelete=0 and status=1';
  4451. elseif ($status == 'APPROVED')
  4452. $con = ' isDelete=0 and status=2';
  4453. if ($invoiceType == 'ORDINARY')
  4454. $con .= ' and invoiceType=0 ';
  4455. elseif ($invoiceType == 'SPECIAL')
  4456. $con .= ' and invoiceType=1 ';
  4457. if ($invoiceTrain == 'ORDINARY')
  4458. $con .= ' and trainId=0 ';
  4459. elseif ($invoiceTrain == 'TRAIN')
  4460. $con .= ' and trainId!=0 ';
  4461. if ($invoiceTrainName != 'ALL') {
  4462. $trainId = $XDeode->decode ( $invoiceTrainName );
  4463. if (is_numeric ( $trainId ))
  4464. $con .= ' and trainId =' . $trainId;
  4465. }
  4466. $dateArr = explode ( ':', $date );
  4467. $D1 = $dateString = '';
  4468. $D2 = '';
  4469. if (! empty ( $date )) {
  4470. $D1 = $dateArr [0];
  4471. if (isset ( $dateArr [1] ))
  4472. $D2 = $dateArr [1];
  4473. else
  4474. $D2 = '';
  4475. $dateString = $D1 . " : " . $D2;
  4476. }
  4477. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4478. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4479. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4480. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  4481. if (! empty ( $MebSea ))
  4482. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  4483. // /
  4484. $pageinfo ['page'] = array (
  4485. 'previous' => ''
  4486. );
  4487. $sql = ' ' . $con;
  4488. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  4489. $limit = $page . ',' . $page_size;
  4490. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4491. $approvalList = array ();
  4492. $html = '
  4493. <script type="text/javascript">
  4494. </script>
  4495. ';
  4496. foreach ( $list as $key => $value ) {
  4497. $irDetail = array ();
  4498. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  4499. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  4500. } else
  4501. array_push ( $irDetail, '' );
  4502. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  4503. if ($value ['invoiceType'] == 1)
  4504. array_push ( $irDetail, $value ['invoiceCompany'] );
  4505. else
  4506. array_push ( $irDetail, $value ['invoiceTitle'] );
  4507. array_push ( $irDetail, $value ['TIN'] );
  4508. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  4509. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  4510. array_push ( $irDetail, $value ['remark'] );
  4511. array_push ( $irDetail, $value ['invoiceElement'] );
  4512. array_push ( $irDetail, $value ['invoiceQuantity'] );
  4513. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  4514. if ($value ['invoiceType'] == 1)
  4515. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  4516. else
  4517. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  4518. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  4519. array_push ( $irDetail, $value ['recipientsAddress'] );
  4520. array_push ( $irDetail, $value ['mailItems'] );
  4521. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  4522. $fchtml = $value ['OL'] ['operation'];
  4523. if (count ( $list ) == $page_size)
  4524. $fchtml = $value ['OL'] ['operation'] . $html;
  4525. // 最后的审批意见
  4526. array_push ( $irDetail, $fchtml );
  4527. if ($value ['status'] == 2)
  4528. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4529. elseif ($value ['status'] == 3)
  4530. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4531. elseif ($value ['status'] == 4)
  4532. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4533. else
  4534. array_push ( $irDetail, '' );
  4535. array_push ( $approvalList, $irDetail );
  4536. }
  4537. // $approvalListJson = json_encode ( $approvalList );
  4538. $recordsFiltered = $pageinfo ['total_data'];
  4539. echo json_encode ( array (
  4540. "draw" => intval ( $draw ),
  4541. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  4542. "recordsFiltered" => intval ( $recordsFiltered ),
  4543. "data" => $approvalList
  4544. ), JSON_UNESCAPED_UNICODE );
  4545. }
  4546. /**
  4547. * 审批发票查看更多--重构
  4548. */
  4549. function invoiceApprovalAchieve() {
  4550. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  4551. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4552. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4553. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4554. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4555. Doo::loadModel ( 'invoiceTraining' );
  4556. $invoiceTraining = new invoiceTraining ();
  4557. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  4558. $this->data ['trainList'] = $trainList;
  4559. $this->data ['dateString'] = $date;
  4560. $this->data ['status'] = $status;
  4561. $this->data ['invoiceType'] = $invoiceType;
  4562. $this->data ['invoiceTrain'] = $invoiceTrain;
  4563. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  4564. $this->data ['memu'] = "invoice";
  4565. $this->data ['staff'] = $this->staff;
  4566. $this->data ['receiptMemu'] = 'invoiceApproval';
  4567. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4568. }
  4569. function invoiceTAchieve() {
  4570. Doo::loadModel ( 'invoice' );
  4571. $invoice = new invoice ();
  4572. Doo::loadClass ( 'XDeode' );
  4573. $XDeode = new XDeode ( 5 );
  4574. Doo::loadModel ( 'staff' );
  4575. $staff = new staff ();
  4576. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4577. $page_size = 12;
  4578. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4579. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4580. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4581. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4582. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4583. Doo::loadModel ( 'invoiceTraining' );
  4584. $invoiceTraining = new invoiceTraining ();
  4585. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  4586. $get = "/" . $date;
  4587. $con = '';
  4588. if ($date == 'MONTHO')
  4589. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4590. elseif ($date == 'MONTHT')
  4591. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4592. elseif ($date == 'MONTHY')
  4593. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4594. if ($invoiceType == 'ORDINARY')
  4595. $con .= ' and invoiceType=0 ';
  4596. elseif ($invoiceType == 'SPECIAL')
  4597. $con .= ' and invoiceType=1 ';
  4598. if ($invoiceTrain == 'ORDINARY')
  4599. $con .= ' and trainId=0 ';
  4600. elseif ($invoiceTrain == 'TRAIN')
  4601. $con .= ' and trainId!=0 ';
  4602. if ($invoiceTrainName != 'ALL') {
  4603. $trainId = $XDeode->decode ( $invoiceTrainName );
  4604. if (is_numeric ( $trainId ))
  4605. $con .= ' and trainId =' . $trainId;
  4606. }
  4607. if (! empty ( $MebSea )) {
  4608. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4609. $get .= "/" . $MebSea;
  4610. }
  4611. $pageinfo ['page'] = array (
  4612. 'previous' => ''
  4613. );
  4614. $sql = "";
  4615. $action = "";
  4616. if ($this->ACTION == 'invoicePrintAchieve') {
  4617. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  4618. $action = "invoicePrintAchieve";
  4619. } elseif ($this->ACTION == 'invoicePostAchieve') {
  4620. // and untreadStatus=0
  4621. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  4622. $action = "invoicePostAchieve";
  4623. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  4624. $sql = " untreadStatus=2 and status=2 " . $con;
  4625. $action = "invoiceUntreadAchieve";
  4626. }
  4627. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4628. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4629. $this->data ['MebSeaEn'] = $MebSea;
  4630. $this->data ['MebSea'] = urlencode ( $MebSea );
  4631. $this->data ['get'] = $get;
  4632. $this->data ['page'] = $pageinfo;
  4633. $this->data ['trainList'] = $trainList;
  4634. $this->data ['invoiceType'] = $invoiceType;
  4635. $this->data ['invoiceTrain'] = $invoiceTrain;
  4636. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  4637. $this->data ['date'] = $date;
  4638. $this->data ['memu'] = "invoice";
  4639. $this->data ['staff'] = $this->staff;
  4640. if ($this->ACTION == 'invoicePrintAchieve') {
  4641. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  4642. $this->data ['receiptMemu'] = 'invoicePrint';
  4643. $this->data ['list'] = $list;
  4644. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  4645. } elseif ($this->ACTION == 'invoicePostAchieve') {
  4646. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4647. Doo::loadModel ( 'express' );
  4648. $express = new express ();
  4649. $expressList = $express->getExpressByAll ();
  4650. $this->data ['expressList'] = $expressList;
  4651. $this->data ['receiptMemu'] = 'invoicePost';
  4652. $this->data ['list'] = $list;
  4653. $this->render ( "/admin/invoicePostAchieve", $this->data );
  4654. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  4655. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4656. $this->data ['receiptMemu'] = 'invoiceUntread';
  4657. $this->data ['list'] = $list;
  4658. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  4659. }
  4660. }
  4661. /**
  4662. *
  4663. * @deprecated 获得与我有关可收款的发票 废弃 function ajaxGetInvoiceByStaff() { $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : ""; Doo::loadModel ( 'invoice' ); $invoice = new invoice (); $list = $invoice->getInvoiceByReceivables ( $this->staff [0] ['sid'] ); $html = ""; $i = 1; foreach ( $list as $key => $value ) { $html .= '<tr> <td>' . $value ['invoiceElement'] . '</td> <td>¥' . $value ['invoicePrice'] . '</td>'; if (! empty ( $value ['invoiceType'] )) { $html .= '<td>增值税专用发票</td> <td>' . $value ['invoiceCompany'] . '</td>'; } else { $html .= '<td>增值税普通发票</td> <td>' . $value ['invoiceTitle'] . '</td>'; } $html .= '<td><label><input type="radio" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim"> 使用Ta</label></td></tr> <script> $(\'input[node-Claim="true_' . $i . '"]\').click(function() { var invoiceKey= $(this).attr("p-data"); var claimKey=$("input[name=\'key\']").val(); $("p[node-msg=\"true\"]").hide(); var url = "/ajaxCompareInvoicePrice"; $.ajax({ url : url, type : "post", cache : false, dataType : "json", data : { claimKey : claimKey, invoiceKey:invoiceKey }, global : true, success : function(data) { $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '"); if (data.status == 1) { $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。"); $("p[node-msg=\"true\"]").show(); } }, error : function(err) { } }); }); </script> '; $i ++; } echo json_encode ( array ( 'status' => 1, 'html' => $html ) ); }
  4664. */
  4665. /**
  4666. * 获取一条收款信息
  4667. */
  4668. function ajaxGetInvoiceReceivables() {
  4669. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4670. Doo::loadModel ( 'invoiceReceivables' );
  4671. $invoiceReceivables = new invoiceReceivables ();
  4672. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4673. echo json_encode ( array (
  4674. 'status' => 1,
  4675. 'detail' => $detail
  4676. ) );
  4677. }
  4678. /**
  4679. * 异步获取办事处用户
  4680. */
  4681. function ajaxGetStaffByCategory() {
  4682. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  4683. Doo::loadModel ( 'staff' );
  4684. $staff = new staff ();
  4685. if ($cid == "PUBLIC") {
  4686. echo json_encode ( array (
  4687. 'status' => 1,
  4688. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  4689. ) );
  4690. die ();
  4691. }
  4692. if (! is_numeric ( $cid )) {
  4693. echo json_encode ( array (
  4694. 'status' => 0,
  4695. 'msg' => 'illegal request'
  4696. ) );
  4697. die ();
  4698. }
  4699. $staffList = $staff->getStaffByCid ( $cid );
  4700. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  4701. foreach ( $staffList as $key => $value ) {
  4702. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  4703. }
  4704. echo json_encode ( array (
  4705. 'status' => 1,
  4706. 'html' => $html
  4707. ) );
  4708. }
  4709. /**
  4710. * 异步获取一条发票的邮寄信息
  4711. */
  4712. function ajaxGetInvoicePostDetail() {
  4713. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  4714. Doo::loadModel ( 'invoice' );
  4715. $invoice = new invoice ();
  4716. $iid = $invoice->authcode ( $iid );
  4717. Doo::loadModel ( 'express' );
  4718. $express = new express ();
  4719. $expressList = $express->getExpressByAll ();
  4720. if (! is_numeric ( $iid )) {
  4721. echo json_encode ( array (
  4722. 'status' => 0,
  4723. 'msg' => 'illegal request'
  4724. ) );
  4725. die ();
  4726. }
  4727. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  4728. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  4729. $html = "";
  4730. foreach ( $expressList as $key => $value ) {
  4731. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  4732. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  4733. else
  4734. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  4735. }
  4736. $invoiceDetail ['eaHtml'] = $html;
  4737. echo json_encode ( array (
  4738. 'status' => 1,
  4739. 'invoiceDetail' => $invoiceDetail
  4740. ) );
  4741. }
  4742. /**
  4743. *
  4744. * @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 ) ); }
  4745. */
  4746. /**
  4747. *
  4748. * @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 ) ); }
  4749. */
  4750. /**
  4751. * 我的收款中 选择哪个发票入账,进行金额判断
  4752. */
  4753. function ajaxCompareInvoicePrice() {
  4754. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  4755. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4756. Doo::loadModel ( 'invoice' );
  4757. $invoice = new invoice ();
  4758. Doo::loadModel ( 'invoiceReceivables' );
  4759. $invoiceReceivables = new invoiceReceivables ();
  4760. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4761. $keyList = explode ( ';', $claimKey );
  4762. $receivablesPrice = 0;
  4763. foreach ( $keyList as $key => $value ) {
  4764. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  4765. $receivablesPrice += $detailM ['receivablesPrice'];
  4766. }
  4767. if ($receivablesPrice > $detail ['invoicePrice']) {
  4768. $price = $receivablesPrice - $detail ['invoicePrice'];
  4769. echo json_encode ( array (
  4770. 'status' => 1,
  4771. 'price' => $price
  4772. ) );
  4773. } else
  4774. echo json_encode ( array (
  4775. 'status' => 2
  4776. ) );
  4777. }
  4778. /**
  4779. * 获得打印发票
  4780. */
  4781. function ajaxGetInvoiceInfoByPrint() {
  4782. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4783. if (empty ( $serial )) {
  4784. echo json_encode ( array (
  4785. 'status' => 2,
  4786. 'msg' => 'illegal request'
  4787. ) );
  4788. die ();
  4789. }
  4790. Doo::loadModel ( 'invoice' );
  4791. $invoice = new invoice ();
  4792. Doo::loadModel ( 'invoiceOperationLog' );
  4793. $invoiceOperationLog = new invoiceOperationLog ();
  4794. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4795. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4796. Doo::loadModel ( 'invoicePaper' );
  4797. $invoicePaper = new invoicePaper ();
  4798. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  4799. if (empty ( $detail ))
  4800. $html = '';
  4801. else {
  4802. $html = '
  4803. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  4804. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4805. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  4806. <div class="modal-dialog modal-lg">
  4807. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  4808. <div class="modal-body saeaList">
  4809. <table class="table table-bordered table-condensed"><tbody>
  4810. <tr>
  4811. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4812. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4813. </tr>
  4814. <tr>
  4815. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4816. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4817. </tr>
  4818. <tr>
  4819. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4820. </td>
  4821. </tr>
  4822. <tr>
  4823. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4824. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4825. </tr>
  4826. <tr>
  4827. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4828. </tr></tbody></table>';
  4829. if ($detail ['invoiceType'] == 0)
  4830. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4831. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4832. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4833. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4834. </tr>';
  4835. else
  4836. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4837. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4838. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4839. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4840. ';
  4841. $html .= '<tr>
  4842. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4843. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4844. </tr>
  4845. <tr>
  4846. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4847. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4848. </tr></tbody></table>';
  4849. if ($detail ['doPost'] == 1)
  4850. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4851. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4852. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4853. </tr><tr>
  4854. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4855. </tr><tr>
  4856. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4857. </tr></tbody></table>';
  4858. if (! empty ( $invoiceOperationLogList )) {
  4859. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  4860. foreach ( $invoiceOperationLogList as $key => $value ) {
  4861. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4862. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4863. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4864. if ($value ['status'] == 2) {
  4865. $html .= '<span class="colGreen">同意</span>';
  4866. } elseif ($value ['status'] == 3) {
  4867. $html .= '<span class="colOrange">退回</span>';
  4868. } elseif ($value ['status'] == 5) {
  4869. $html .= '<span class="colGreen">打印</span>';
  4870. } elseif ($value ['status'] == 4) {
  4871. $html .= '<span class="colRed">终止</span>';
  4872. }
  4873. $html .= $value ['operation'] . '</p></blockquote>';
  4874. }
  4875. }
  4876. $html .= '</td>
  4877. <td><span class="colRed">*</span>
  4878. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  4879. foreach ( $invoicePaperList as $key => $value ) {
  4880. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  4881. }
  4882. $html .= '</select>
  4883. <span class="red" id="p-msg"></span>
  4884. </td>
  4885. </tr></tbody></table>';
  4886. }
  4887. $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>
  4888. </div></div></form>
  4889. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  4890. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  4891. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  4892. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  4893. ';
  4894. }
  4895. echo json_encode ( array (
  4896. 'status' => 1,
  4897. 'html' => $html
  4898. ) );
  4899. die ();
  4900. }
  4901. /**
  4902. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  4903. */
  4904. function ajaxGetInvoiceInfoByType() {
  4905. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  4906. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4907. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  4908. if (empty ( $serial )) {
  4909. echo json_encode ( array (
  4910. 'status' => 2,
  4911. 'msg' => 'illegal request'
  4912. ) );
  4913. die ();
  4914. }
  4915. if ($type == 'INVOICE') {
  4916. Doo::loadModel ( 'invoice' );
  4917. $invoice = new invoice ();
  4918. Doo::loadModel ( 'invoiceOperationLog' );
  4919. $invoiceOperationLog = new invoiceOperationLog ();
  4920. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4921. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4922. if (empty ( $detail ))
  4923. $html = '';
  4924. else {
  4925. $html = '
  4926. <div class="modal-dialog modal-lg">
  4927. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  4928. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4929. <tr>
  4930. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4931. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4932. </tr>
  4933. <tr>
  4934. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4935. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4936. </tr>
  4937. <tr>
  4938. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4939. </td>
  4940. </tr>
  4941. <tr>
  4942. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4943. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4944. </tr>
  4945. <tr>
  4946. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4947. </tr></tbody></table>';
  4948. if ($detail ['invoiceType'] == 0)
  4949. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4950. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4951. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4952. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4953. </tr>';
  4954. else
  4955. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4956. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4957. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4958. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4959. ';
  4960. $html .= '<tr>
  4961. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4962. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4963. </tr>
  4964. <tr>
  4965. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4966. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4967. </tr></tbody></table>';
  4968. if ($detail ['doPost'] == 1) {
  4969. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4970. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4971. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4972. </tr><tr>
  4973. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4974. </tr><tr>
  4975. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4976. </tr>
  4977. ';
  4978. if ($detail ['expressCom'] == 'SF')
  4979. $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>';
  4980. else
  4981. $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>';
  4982. $html .= '</tbody></table>';
  4983. }
  4984. if (! empty ( $invoiceOperationLogList )) {
  4985. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4986. foreach ( $invoiceOperationLogList as $key => $value ) {
  4987. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4988. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4989. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4990. if ($value ['status'] == 2) {
  4991. $html .= '<span class="colGreen">同意</span>';
  4992. } elseif ($value ['status'] == 3) {
  4993. $html .= '<span class="colOrange">退回</span>';
  4994. } elseif ($value ['status'] == 5) {
  4995. $html .= '<span class="colGreen">打印</span>';
  4996. } elseif ($value ['status'] == 4) {
  4997. $html .= '<span class="colRed">终止</span>';
  4998. }
  4999. $html .= $value ['operation'] . '</p></blockquote>';
  5000. }
  5001. }
  5002. $html .= '</td></tr></tbody></table>';
  5003. }
  5004. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5005. }
  5006. echo json_encode ( array (
  5007. 'status' => 1,
  5008. 'html' => $html
  5009. ) );
  5010. die ();
  5011. } elseif ($type == 'RECEIVABLES') {
  5012. Doo::loadModel ( 'invoiceReceivables' );
  5013. $invoiceReceivables = new invoiceReceivables ();
  5014. //
  5015. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5016. if (empty ( $detail ))
  5017. $html = '';
  5018. else {
  5019. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList"><table class="table table-bordered table-condensed">
  5020. <tbody><tr>
  5021. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  5022. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  5023. </tr><tr>
  5024. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5025. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  5026. </tr>
  5027. <tr>
  5028. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  5029. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  5030. </tr>
  5031. <tr>
  5032. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  5033. </tr>
  5034. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5035. }
  5036. echo json_encode ( array (
  5037. 'status' => 1,
  5038. 'html' => $html
  5039. ) );
  5040. die ();
  5041. } elseif ($type == 'IRTC') {
  5042. Doo::loadModel ( 'invoice' );
  5043. $invoice = new invoice ();
  5044. Doo::loadModel ( 'invoiceOperationLog' );
  5045. $invoiceOperationLog = new invoiceOperationLog ();
  5046. Doo::loadModel ( 'invoiceReceivables' );
  5047. $invoiceReceivables = new invoiceReceivables ();
  5048. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5049. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5050. if (empty ( $detail ))
  5051. $html = '';
  5052. else {
  5053. $receivablesPriceedHtml = '';
  5054. $receivablesPrice = $detail ['invoicePrice'];
  5055. if (! empty ( $detail ['irid'] )) {
  5056. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  5057. if (empty ( $irList ))
  5058. $irList [0] ['sumPrice'] = 0;
  5059. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  5060. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  5061. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  5062. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  5063. </tr></tbody></table>';
  5064. $receivablesPrice = $balance;
  5065. }
  5066. if ($loss)
  5067. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  5068. $html = $receivablesPriceedHtml . '
  5069. <table class="table table-bordered table-condensed"><tbody>
  5070. <tr>
  5071. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5072. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5073. </tr>
  5074. <tr>
  5075. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5076. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5077. </tr>
  5078. <tr>
  5079. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  5080. </tr>
  5081. <tr>
  5082. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5083. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5084. </tr>
  5085. <tr>
  5086. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5087. </tr></tbody></table>';
  5088. if ($detail ['invoiceType'] == 0) {
  5089. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5090. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5091. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5092. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5093. </tr>';
  5094. $receivablesMessage = $detail ['invoiceTitle'];
  5095. } else {
  5096. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5097. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5098. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5099. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5100. ';
  5101. $receivablesMessage = $detail ['invoiceCompany'];
  5102. }
  5103. $html .= '<tr>
  5104. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5105. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5106. </tr>
  5107. <tr>
  5108. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  5109. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  5110. </tr></tbody></table>';
  5111. if ($detail ['doPost'] == 1)
  5112. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5113. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5114. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5115. </tr><tr>
  5116. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5117. </tr><tr>
  5118. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5119. </tr></tbody></table>';
  5120. if (! empty ( $invoiceOperationLogList )) {
  5121. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5122. foreach ( $invoiceOperationLogList as $key => $value ) {
  5123. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5124. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5125. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5126. if ($value ['status'] == 2) {
  5127. $html .= '<span class="colGreen">同意</span>';
  5128. } elseif ($value ['status'] == 3) {
  5129. $html .= '<span class="colOrange">退回</span>';
  5130. } elseif ($value ['status'] == 5) {
  5131. $html .= '<span class="colGreen">打印</span>';
  5132. }
  5133. $html .= $value ['operation'] . '</p></blockquote>';
  5134. }
  5135. }
  5136. $html .= '</td></tr></tbody></table>';
  5137. }
  5138. }
  5139. echo json_encode ( array (
  5140. 'status' => 1,
  5141. 'html' => $html,
  5142. 'receivablesPrice' => $receivablesPrice,
  5143. 'receivablesMessage' => $receivablesMessage,
  5144. 'receivablesDate' => date ( "Y-m-d" ),
  5145. 'iidKey' => $serial
  5146. ) );
  5147. die ();
  5148. }
  5149. }
  5150. function ajaxGetInvoiceReceivablesByStaff() {
  5151. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  5152. if (empty ( $postData )) {
  5153. echo json_encode ( array (
  5154. 'status' => 2,
  5155. 'msg' => 'illegal request'
  5156. ) );
  5157. die ();
  5158. }
  5159. Doo::loadModel ( 'invoiceReceivables' );
  5160. $invoiceReceivables = new invoiceReceivables ();
  5161. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  5162. if (empty ( $detail )) {
  5163. echo json_encode ( array (
  5164. 'status' => 2,
  5165. 'msg' => 'illegal request'
  5166. ) );
  5167. die ();
  5168. }
  5169. Doo::loadModel ( 'L_category' );
  5170. $lCategory = new L_category ();
  5171. Doo::loadModel ( 'staff' );
  5172. $staff = new staff ();
  5173. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  5174. $category = $lCategory->getCategory ();
  5175. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  5176. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  5177. foreach ( $category as $key => $value ) {
  5178. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5179. if ($value ['cid'] == $detail ['cid'])
  5180. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5181. }
  5182. foreach ( $staffList as $key => $value ) {
  5183. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5184. if ($value ['sid'] == $detail ['sid'])
  5185. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5186. }
  5187. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  5188. echo json_encode ( array (
  5189. 'status' => 1,
  5190. 'categoryHtml' => $categoryHtml,
  5191. 'staffHtml' => $staffHtml,
  5192. 'rbankHtml' => $rbankHtml,
  5193. 'detail' => $detail
  5194. ) );
  5195. }
  5196. function ajaxGetInvoiceReceivablesByIrid() {
  5197. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  5198. if (empty ( $irid )) {
  5199. echo json_encode ( array (
  5200. 'status' => 2,
  5201. 'msg' => 'illegal request'
  5202. ) );
  5203. die ();
  5204. }
  5205. Doo::loadModel ( 'invoiceReceivables' );
  5206. $invoiceReceivables = new invoiceReceivables ();
  5207. Doo::loadModel ( 'invoice' );
  5208. $invoice = new invoice ();
  5209. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  5210. $flag = true;
  5211. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  5212. $bakDetail = array ();
  5213. if ($flag === false) {
  5214. array_push ( $bakDetail, $invoiceDetail );
  5215. $invoiceDetail = $bakDetail;
  5216. }
  5217. $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>
  5218. <tr>
  5219. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5220. <td>' . $detail ['receivablesMessage'] . '</td>
  5221. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  5222. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  5223. <td>' . $detail ['recepitTitleMark'] . '</td>
  5224. </tr></tbody></table>';
  5225. $isInvoice = false;
  5226. $invoiceHtml = '';
  5227. if (empty ( $invoiceDetail )) {
  5228. $isInvoice = true;
  5229. } else {
  5230. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5231. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  5232. foreach ( $invoiceDetail as $key => $value ) {
  5233. $invoiceHtml .= '<tr>';
  5234. if (! empty ( $value ['invoiceType'] )) {
  5235. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5236. } else {
  5237. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5238. }
  5239. if (! empty ( $value ['invoiceType'] )) {
  5240. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5241. } else {
  5242. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5243. }
  5244. $invoiceHtml .= '
  5245. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5246. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5247. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  5248. </tr>
  5249. ';
  5250. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  5251. if (empty ( $irList ))
  5252. $irList [0] ['sumPrice'] = 0;
  5253. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  5254. $priceString = '';
  5255. if ($balance < $detail ['receivablesPrice']) {
  5256. $priceString = '收款金额超过开票金额,';
  5257. }
  5258. if ($balance > $detail ['receivablesPrice']) {
  5259. $priceString = '收款金额低于开票金额,';
  5260. }
  5261. }
  5262. $invoiceHtml .= '
  5263. <script>
  5264. $(\'a[bind-receivables^="ir"]\').click(function() {
  5265. var data = $(this).attr("data-ikey");
  5266. $("input[name=\'invoiceKey\']").val(data);
  5267. var invoiceKey=data;
  5268. if(invoiceKey==""){
  5269. alert("入账错误,请重新刷新页面");
  5270. return false;
  5271. }
  5272. if(window.confirm("' . $priceString . '确定入账吗?")){
  5273. $("#IBR").submit();
  5274. }else{
  5275. return false;
  5276. }
  5277. });
  5278. </script>
  5279. ';
  5280. $invoiceHtml .= '</tbody></table>';
  5281. }
  5282. echo json_encode ( array (
  5283. 'status' => 1,
  5284. 'irkey' => $detail ['iridEn'],
  5285. 'receivablesHtml' => $receivablesHtml,
  5286. 'isInvoice' => $isInvoice,
  5287. 'invoiceHtml' => $invoiceHtml
  5288. ) );
  5289. }
  5290. function ajaxGetInvoiceReceivablesByTitle() {
  5291. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  5292. if (empty ( $title )) {
  5293. echo json_encode ( array (
  5294. 'status' => 2,
  5295. 'msg' => 'illegal request'
  5296. ) );
  5297. die ();
  5298. }
  5299. Doo::loadModel ( 'invoice' );
  5300. $invoice = new invoice ();
  5301. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  5302. $invoiceHtml = '';
  5303. if (! empty ( $invoiceDetail )) {
  5304. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5305. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  5306. foreach ( $invoiceDetail as $key => $value ) {
  5307. if (! empty ( $value ['invoiceType'] )) {
  5308. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5309. } else {
  5310. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5311. }
  5312. if (! empty ( $value ['invoiceType'] )) {
  5313. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5314. } else {
  5315. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5316. }
  5317. $invoiceHtml .= '
  5318. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5319. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5320. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  5321. </tr>
  5322. ';
  5323. }
  5324. $invoiceHtml .= '</tbody></table>
  5325. <script>
  5326. $(\'a[bind-receivables^="ir"]\').click(function() {
  5327. var data = $(this).attr("data-ikey");
  5328. $("input[name=\'invoiceKey\']").val(data);
  5329. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  5330. if(invoiceKey==""){
  5331. alert("入账错误,请重新刷新页面");
  5332. return false;
  5333. }
  5334. if(window.confirm("确定入账吗?")){
  5335. $("#IBR").submit();
  5336. }else{
  5337. return false;
  5338. }
  5339. });
  5340. </script>
  5341. ';
  5342. }
  5343. echo json_encode ( array (
  5344. 'status' => 1,
  5345. 'invoiceHtml' => $invoiceHtml
  5346. ) );
  5347. }
  5348. function ajaxInvoicePushNotice() {
  5349. Doo::loadModel ( 'invoice' );
  5350. $invoice = new invoice ();
  5351. $approval = $invoice->getOne ( array (
  5352. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  5353. 'desc' => 'iid',
  5354. 'asArray' => true
  5355. ) );
  5356. $isNotice = false;
  5357. if (! empty ( $approval ))
  5358. $isNotice = true;
  5359. $response = array (
  5360. 'error' => 0,
  5361. 'isNotice' => $isNotice
  5362. );
  5363. echo json_encode ( $response );
  5364. exit ();
  5365. }
  5366. public function ajaxCheckInvoiceNoUniqueness() {
  5367. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  5368. Doo::loadModel ( 'invoice' );
  5369. $invoice = new invoice ();
  5370. if (! empty ( $invoiceNo )) {
  5371. Doo::loadModel ( 'invoicePaper' );
  5372. $invoicePaper = new invoicePaper ();
  5373. Doo::loadClass ( 'XDeode' );
  5374. $XDeode = new XDeode ( 5 );
  5375. $ipid = $XDeode->decode ( $invoiceNo );
  5376. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  5377. $info = $invoice->getOne ( array (
  5378. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  5379. 'asArray' => TRUE
  5380. ) );
  5381. if (! empty ( $info )) {
  5382. echo json_encode ( array (
  5383. 'error' => '发票号已存在'
  5384. ) );
  5385. die ();
  5386. } else
  5387. echo json_encode ( array (
  5388. 'ok' => '可以使用!'
  5389. ) );
  5390. die ();
  5391. }
  5392. }
  5393. function ajaxCheckInvoicePrice() {
  5394. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  5395. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5396. Doo::loadModel ( 'invoice' );
  5397. $invoice = new invoice ();
  5398. Doo::loadModel ( 'invoiceReceivables' );
  5399. $invoiceReceivables = new invoiceReceivables ();
  5400. Doo::loadClass ( 'XDeode' );
  5401. $XDeode = new XDeode ( 5 );
  5402. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  5403. $iidKey = $XDeode->decode ( $iidKey );
  5404. $info = $invoice->getInvoiceByIid ( $iidKey );
  5405. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  5406. if (empty ( $irList ))
  5407. $irList [0] ['sumPrice'] = 0;
  5408. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  5409. if ($balance < $receivablesPrice) {
  5410. echo json_encode ( array (
  5411. 'error' => '收款金额超过开票金额。'
  5412. ) );
  5413. die ();
  5414. }
  5415. if ($balance > $receivablesPrice) {
  5416. echo json_encode ( array (
  5417. 'error' => '收款金额低于开票金额。'
  5418. ) );
  5419. die ();
  5420. }
  5421. }
  5422. }
  5423. /**
  5424. * 旧输入导入
  5425. */
  5426. function importInvoice() {
  5427. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  5428. $data ['emsg'] = "";
  5429. if ($emsg != "")
  5430. $data ['emsg'] = "请填写完整的数据";
  5431. $data ['time'] = time ();
  5432. $this->render ( "/admin/invoiceImport", $data );
  5433. }
  5434. function uploadInvoice() {
  5435. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  5436. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  5437. $file = $_FILES ['Filedata'] ['tmp_name'];
  5438. $error = false;
  5439. if (! is_uploaded_file ( $file )) {
  5440. $error = '400 Bad Request';
  5441. }
  5442. if ($error) {
  5443. header ( 'HTTP/1.0 ' . $error );
  5444. die ( 'Error ' . $error );
  5445. } else {
  5446. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  5447. $this->IoHandler = new IoHandler ();
  5448. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  5449. // $filedir=$_POST['time'];
  5450. // 调用定义物理路径
  5451. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  5452. $this->IoHandler->MakeDir ( $t );
  5453. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  5454. if ($filename != 'xlsx')
  5455. return "";
  5456. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  5457. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  5458. $upload_dir = $t . "/" . $upload_file;
  5459. $k = move_uploaded_file ( $file, $upload_dir );
  5460. if ($k) {
  5461. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  5462. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  5463. }
  5464. }
  5465. }
  5466. }
  5467. function importInvoiceDo() {
  5468. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  5469. if ($path != "") {
  5470. Doo::loadModel ( 'invoice' );
  5471. Doo::loadModel ( 'staff' );
  5472. $staff = new staff ();
  5473. Doo::loadModel ( 'invoiceStatistics' );
  5474. Doo::loadModel ( 'invoiceOperationLog' );
  5475. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  5476. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  5477. // print_r ( $exlArray );
  5478. // die ();
  5479. // echo json_encode($exlArray);die;
  5480. foreach ( $exlArray as $key => $value ) {
  5481. // 开票
  5482. $invoice = new invoice ();
  5483. $invoice->invoiceNo = $value ['invoiceNo'];
  5484. $invoice->invoiceType = 0;
  5485. if ($value ['invoiceType'] == '专')
  5486. $invoice->invoiceType = 1;
  5487. $invoice->invoicePrice = $value ['invoicePrice'];
  5488. $invoice->invoiceQuantity = 1;
  5489. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  5490. $invoice->invoiceTitle = $value ['invoiceTitle'];
  5491. if ($value ['invoiceType'] == '专')
  5492. $invoice->invoiceCompany = $value ['invoiceTitle'];
  5493. $invoice->userName = $value ['userName'];
  5494. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  5495. $invoice->sid = $sDetail ['sid'];
  5496. $invoice->cid = $sDetail ['cid'];
  5497. $invoice->categoryName = $sDetail ['category'];
  5498. $invoice->invoiceElement = $value ['invoiceElement'];
  5499. $invoice->remark = $value ['remark'];
  5500. $invoice->date = $value ['date'];
  5501. $invoice->printTime = $value ['date'];
  5502. $invoice->ipSource = 1;
  5503. $invoice->printStatus = 1;
  5504. $invoice->status = 2;
  5505. $invoice->postStatus = 1;
  5506. $invoice->untreadStatus = 0;
  5507. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  5508. $iid = $invoice->insert ();
  5509. // 汇总
  5510. $invoiceStatistics = new invoiceStatistics ();
  5511. //
  5512. $item = array (
  5513. 'date' => $value ['date'],
  5514. 'priceClass' => 1,
  5515. 'cid' => $sDetail ['cid'],
  5516. 'staff' => $sDetail ['sid'],
  5517. 'invoicePrice' => $value ['invoicePrice']
  5518. );
  5519. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5520. $invoiceOperationLog = new invoiceOperationLog ();
  5521. $item = array (
  5522. 'date' => date ( "Y-m-d H:i:s" ),
  5523. 'operation' => date ( "Y-m-d" ) . " 导入",
  5524. 'status' => 1,
  5525. 'img' => $sDetail ['avatar'],
  5526. 'username' => $sDetail ['username'],
  5527. 'uid' => $sDetail ['sid'],
  5528. 'category' => $sDetail ['category'],
  5529. 'iid' => $iid
  5530. );
  5531. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5532. }
  5533. return '/importInvoice?count=' . count ( $exlArray );
  5534. // return "/keyonline";
  5535. }
  5536. echo 'no file';
  5537. }
  5538. function importInvoiceReceivables() {
  5539. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  5540. $data ['emsg'] = "";
  5541. if ($emsg != "")
  5542. $data ['emsg'] = "请填写完整的数据";
  5543. $data ['time'] = time ();
  5544. $this->render ( "/admin/invoiceReceivablesImport", $data );
  5545. }
  5546. // 导入入账数据
  5547. function importInvoiceReceivablesDo() {
  5548. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  5549. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  5550. if ($path != "") {
  5551. Doo::loadModel ( 'invoiceReceivables' );
  5552. Doo::loadModel ( 'invoice' );
  5553. Doo::loadModel ( 'staff' );
  5554. $staff = new staff ();
  5555. Doo::loadModel ( 'invoiceStatistics' );
  5556. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  5557. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  5558. // print_r ( $exlArray );
  5559. // die ();
  5560. // echo json_encode($exlArray);die;
  5561. foreach ( $exlArray as $key => $value ) {
  5562. // 收款
  5563. $invoiceReceivables = new invoiceReceivables ();
  5564. $invoice = new invoice ();
  5565. $invoiceReceivables->bindStatus = 1;
  5566. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  5567. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  5568. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  5569. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  5570. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  5571. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  5572. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  5573. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  5574. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  5575. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  5576. $invoiceReceivables->iid = $iDetail ['iid'];
  5577. $irid = $invoiceReceivables->insert ();
  5578. // 发票绑定收款
  5579. $detail = $iDetail;
  5580. $iridString = "";
  5581. if (empty ( $detail ['irid'] ))
  5582. $iridString = $irid;
  5583. else
  5584. $iridString = $detail ['irid'] . ',' . $irid;
  5585. $item = array (
  5586. 'irid' => $iridString,
  5587. 'iid' => $detail ['iid']
  5588. );
  5589. $invoice->setInvoiceByCondition ( $item );
  5590. // 汇总
  5591. $invoiceStatistics = new invoiceStatistics ();
  5592. // 扣除入账统计金额
  5593. $item = array (
  5594. 'date' => $value ['receivablesDate'],
  5595. 'priceClass' => 3,
  5596. 'cid' => $sDetail ['cid'],
  5597. 'staff' => $sDetail ['sid'],
  5598. // 'irid' => $irid,
  5599. 'accountPrice' => $value ['receivablesPrice']
  5600. );
  5601. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5602. }
  5603. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  5604. echo 'data count ' . count ( $exlArray );
  5605. die ();
  5606. // return "/keyonline";
  5607. }
  5608. echo 'no file';
  5609. }
  5610. function formatExcelToArrayTrain($file_url = "") {
  5611. if (! file_exists ( $file_url )) {
  5612. return array ();
  5613. }
  5614. // Doo::loadClass ( 'PHPExcel' );
  5615. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  5616. $PHPExcel = new PHPExcel ();
  5617. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  5618. if (! $PHPReader->canRead ( $file_url )) {
  5619. $PHPReader = new PHPExcel_Reader_Excel5 ();
  5620. if (! $PHPReader->canRead ( $file_url )) {
  5621. echo 'no Excel';
  5622. return;
  5623. }
  5624. }
  5625. $PHPExcel = $PHPReader->load ( $file_url );
  5626. /* * 读取excel文件中的第一个工作表 */
  5627. $currentSheet = $PHPExcel->getSheet ( 0 );
  5628. /* * 取得最大的列号 */
  5629. $allColumn = $currentSheet->getHighestColumn ();
  5630. /* * 取得一共有多少行 */
  5631. $allRow = $currentSheet->getHighestRow ();
  5632. $excel_array = array ();
  5633. // die($file_url);
  5634. $conk = 2;
  5635. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  5636. $excel_column = array ();
  5637. // 后期改进
  5638. if ($allColumn == 'AM')
  5639. $allColumn = 'Z';
  5640. /* * 从第A列开始输出 */
  5641. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  5642. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  5643. if ($val instanceof PHPExcel_RichText)
  5644. $val = $val->__toString ();
  5645. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  5646. // $val = "'" . addslashes ( $val ) . "'";
  5647. if ($currentColumn == 'A') {
  5648. $excel_column ['invoiceTitle'] = $val;
  5649. } elseif ($currentColumn == 'B')
  5650. $excel_column ['invoiceType'] = $val;
  5651. elseif ($currentColumn == 'C') {
  5652. $excel_column ['TIN'] = $val;
  5653. } elseif ($currentColumn == 'D') {
  5654. $excel_column ['address'] = $val;
  5655. } elseif ($currentColumn == 'E') {
  5656. $excel_column ['phone'] = $val;
  5657. } elseif ($currentColumn == 'F') {
  5658. $excel_column ['bank'] = $val;
  5659. } elseif ($currentColumn == 'G') {
  5660. $excel_column ['bankAccount'] = $val;
  5661. } elseif ($currentColumn == 'H') {
  5662. $excel_column ['invoiceElement'] = $val;
  5663. } elseif ($currentColumn == 'I') {
  5664. $excel_column ['invoiceQuantity'] = $val;
  5665. } elseif ($currentColumn == 'J') {
  5666. $excel_column ['invoiceUnitPrice'] = $val;
  5667. } elseif ($currentColumn == 'K') {
  5668. $excel_column ['remark'] = $val;
  5669. } elseif ($currentColumn == 'L') {
  5670. $excel_column ['recipientsAddress'] = $val;
  5671. } elseif ($currentColumn == 'M') {
  5672. $excel_column ['recipients'] = $val;
  5673. } elseif ($currentColumn == 'N') {
  5674. $excel_column ['recipientsPhone'] = $val;
  5675. }
  5676. }
  5677. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  5678. array_push ( $excel_array, $excel_column );
  5679. }
  5680. return $excel_array;
  5681. }
  5682. /**
  5683. * 格式化excel文件为数组
  5684. * @param unknown_type $file_url
  5685. * @param unknown_type $mcid
  5686. */
  5687. function _format_excel_to_array($file_url = "", $sType = "") {
  5688. if (! file_exists ( $file_url )) {
  5689. return array ();
  5690. }
  5691. Doo::loadClass ( 'PHPExcel' );
  5692. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  5693. $PHPExcel = new PHPExcel ();
  5694. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  5695. if (! $PHPReader->canRead ( $file_url )) {
  5696. $PHPReader = new PHPExcel_Reader_Excel5 ();
  5697. if (! $PHPReader->canRead ( $file_url )) {
  5698. echo 'no Excel';
  5699. return;
  5700. }
  5701. }
  5702. $PHPExcel = $PHPReader->load ( $file_url );
  5703. /* * 读取excel文件中的第一个工作表 */
  5704. $currentSheet = $PHPExcel->getSheet ( 0 );
  5705. /* * 取得最大的列号 */
  5706. $allColumn = $currentSheet->getHighestColumn ();
  5707. /* * 取得一共有多少行 */
  5708. $allRow = $currentSheet->getHighestRow ();
  5709. $excel_array = array ();
  5710. // die($file_url);
  5711. $conk = 2;
  5712. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  5713. $excel_column = array ();
  5714. // 后期改进
  5715. if ($allColumn == 'AM')
  5716. $allColumn = 'Z';
  5717. /* * 从第A列开始输出 */
  5718. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  5719. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  5720. if ($val instanceof PHPExcel_RichText)
  5721. $val = $val->__toString ();
  5722. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  5723. // $val = "'" . addslashes ( $val ) . "'";
  5724. if ($sType == 'invoiceReceivables') {
  5725. if ($currentColumn == 'A')
  5726. $excel_column ['invoiceNo'] = $val;
  5727. elseif ($currentColumn == 'B')
  5728. $excel_column ['receivablesPrice'] = $val;
  5729. elseif ($currentColumn == 'C') {
  5730. $excel_column ['receivablesMessage'] = $val;
  5731. } elseif ($currentColumn == 'D') {
  5732. $excel_column ['receivablesBank'] = $val;
  5733. } elseif ($currentColumn == 'E') {
  5734. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  5735. } elseif ($currentColumn == 'F') {
  5736. $excel_column ['receivablesStaff'] = $val;
  5737. } elseif ($currentColumn == 'G') {
  5738. $excel_column ['sourcePrice'] = $val;
  5739. }
  5740. } elseif ($sType == "invoiceTrain") {
  5741. if ($currentColumn == 'A') {
  5742. $excel_column ['invoiceTitle'] = $val;
  5743. } elseif ($currentColumn == 'B')
  5744. $excel_column ['invoiceType'] = $val;
  5745. elseif ($currentColumn == 'C') {
  5746. $excel_column ['TIN'] = $val;
  5747. } elseif ($currentColumn == 'D') {
  5748. $excel_column ['address'] = $val;
  5749. } elseif ($currentColumn == 'E') {
  5750. $excel_column ['phone'] = $val;
  5751. } elseif ($currentColumn == 'F') {
  5752. $excel_column ['bank'] = $val;
  5753. } elseif ($currentColumn == 'G') {
  5754. $excel_column ['bankAccount'] = $val;
  5755. } elseif ($currentColumn == 'H') {
  5756. $excel_column ['invoiceElement'] = $val;
  5757. } elseif ($currentColumn == 'I') {
  5758. $excel_column ['invoiceQuantity'] = $val;
  5759. } elseif ($currentColumn == 'J') {
  5760. $excel_column ['invoiceUnitPrice'] = $val;
  5761. } elseif ($currentColumn == 'K') {
  5762. $excel_column ['remark'] = $val;
  5763. } elseif ($currentColumn == 'L') {
  5764. $excel_column ['recipientsAddress'] = $val;
  5765. } elseif ($currentColumn == 'M') {
  5766. $excel_column ['recipients'] = $val;
  5767. } elseif ($currentColumn == 'N') {
  5768. $excel_column ['recipientsPhone'] = $val;
  5769. }
  5770. } else {
  5771. if ($currentColumn == 'A')
  5772. $excel_column ['invoiceNo'] = $val;
  5773. elseif ($currentColumn == 'B')
  5774. $excel_column ['invoiceType'] = $val;
  5775. elseif ($currentColumn == 'C') {
  5776. $excel_column ['invoicePrice'] = $val;
  5777. } elseif ($currentColumn == 'D') {
  5778. $excel_column ['invoiceTitle'] = $val;
  5779. } elseif ($currentColumn == 'E') {
  5780. $excel_column ['userName'] = $val;
  5781. } elseif ($currentColumn == 'F') {
  5782. $excel_column ['categoryName'] = $val;
  5783. } elseif ($currentColumn == 'G') {
  5784. $excel_column ['invoiceElement'] = $val;
  5785. } elseif ($currentColumn == 'H') {
  5786. $excel_column ['remark'] = $val;
  5787. } elseif ($currentColumn == 'I') {
  5788. $excel_column ['date'] = $this->excelTime ( $val );
  5789. }
  5790. }
  5791. }
  5792. array_push ( $excel_array, $excel_column );
  5793. }
  5794. return $excel_array;
  5795. }
  5796. function excelTime($date, $time = false) {
  5797. if (function_exists ( 'GregorianToJD' )) {
  5798. if (is_numeric ( $date )) {
  5799. $jd = GregorianToJD ( 1, 1, 1970 );
  5800. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  5801. $date = explode ( '/', $gregorian );
  5802. $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" : '');
  5803. return $date_str;
  5804. }
  5805. } else {
  5806. $date = $date > 25568 ? $date + 1 : 25569;
  5807. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  5808. $ofs = (70 * 365 + 17 + 2) * 86400;
  5809. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  5810. }
  5811. return $date;
  5812. }
  5813. /**
  5814. * 旧输入导入
  5815. */
  5816. function _GetFileEXT($filename) {
  5817. $pics = explode ( '.', $filename );
  5818. $num = count ( $pics );
  5819. return $pics [$num - 1];
  5820. }
  5821. function showCache($path = "", $sid = 0) {
  5822. // if (file_exists ( $path )) {
  5823. // $htm = file_get_contents ( $path );
  5824. // } else {
  5825. Doo::loadModel ( 'invoiceStatistics' );
  5826. $invoiceStatistics = new invoiceStatistics ();
  5827. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  5828. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  5829. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  5830. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  5831. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  5832. /*
  5833. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  5834. */
  5835. file_put_contents ( $path, $htm );
  5836. // }
  5837. return $htm;
  5838. }
  5839. /**
  5840. * 获取get或者POST值
  5841. *
  5842. * @param string $name 属性名称
  5843. * @return fixed 值
  5844. */
  5845. function get_args($name) {
  5846. if (isset ( $_GET [$name] )) {
  5847. if (is_array ( $_GET [$name] ))
  5848. return $_GET [$name];
  5849. else
  5850. return addslashes ( $_GET [$name] );
  5851. } elseif (isset ( $_POST [$name] )) {
  5852. if (is_array ( $_POST [$name] ))
  5853. return $_POST [$name];
  5854. else
  5855. return addslashes ( $_POST [$name] );
  5856. } else
  5857. return false;
  5858. }
  5859. function SafeFilter(&$arr) {
  5860. $ra = Array (
  5861. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  5862. '/script/',
  5863. '/javascript/',
  5864. '/vbscript/',
  5865. '/expression/',
  5866. '/applet/',
  5867. '/meta/',
  5868. '/xml/',
  5869. '/blink/',
  5870. '/link/',
  5871. '/style/',
  5872. '/embed/',
  5873. '/object/',
  5874. '/frame/',
  5875. '/layer/',
  5876. '/title/',
  5877. '/bgsound/',
  5878. '/base/',
  5879. '/onload/',
  5880. '/onunload/',
  5881. '/onchange/',
  5882. '/onsubmit/',
  5883. '/onreset/',
  5884. '/onselect/',
  5885. '/onblur/',
  5886. '/onfocus/',
  5887. '/onabort/',
  5888. '/onkeydown/',
  5889. '/onkeypress/',
  5890. '/onkeyup/',
  5891. '/onclick/',
  5892. '/ondblclick/',
  5893. '/onmousedown/',
  5894. '/onmousemove/',
  5895. '/onmouseout/',
  5896. '/onmouseover/',
  5897. '/onmouseup/',
  5898. '/onunload/'
  5899. );
  5900. if (is_array ( $arr )) {
  5901. foreach ( $arr as $key => $value ) {
  5902. if (! is_array ( $value )) {
  5903. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  5904. {
  5905. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  5906. }
  5907. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  5908. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  5909. } else {
  5910. SafeFilter ( $arr [$key] );
  5911. }
  5912. }
  5913. }
  5914. }
  5915. /**
  5916. * Escape String
  5917. *
  5918. * @access public
  5919. * @param string
  5920. * @param bool whether or not the string will be used in a LIKE condition
  5921. * @return string
  5922. */
  5923. function escape_str($str, $like = FALSE) {
  5924. if (is_array ( $str )) {
  5925. foreach ( $str as $key => $val ) {
  5926. $str [$key] = $this->escape_str ( $val, $like );
  5927. }
  5928. return $str;
  5929. }
  5930. var_dump ( Doo::db ()->getDbObject () );
  5931. die ();
  5932. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  5933. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  5934. } elseif (function_exists ( 'mysql_escape_string' )) {
  5935. $str = mysql_escape_string ( $str );
  5936. } else {
  5937. $str = addslashes ( $str );
  5938. }
  5939. // escape LIKE condition wildcards
  5940. if ($like === TRUE) {
  5941. $str = str_replace ( array (
  5942. '%',
  5943. '_'
  5944. ), array (
  5945. '\\%',
  5946. '\\_'
  5947. ), $str );
  5948. }
  5949. return $str;
  5950. }
  5951. /**
  5952. * 获得分页数据
  5953. * @param unknown_type $table
  5954. * @param unknown_type $condition
  5955. * @param unknown_type $on_page
  5956. * @param unknown_type $page_size
  5957. */
  5958. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  5959. $page_c = "";
  5960. $page ['previous'] = $this->get_previous ( $on_page );
  5961. $page ['on_page'] = $on_page;
  5962. $total_count = $this->get_table_count ( $table, $condition );
  5963. $total = intval ( $total_count / $page_size );
  5964. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  5965. $page ['total_data'] = $total_count;
  5966. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  5967. $i = 1;
  5968. $page_max = 1;
  5969. $page_width = 3;
  5970. if ($on_page >= $page_width) {
  5971. $page_max = intval ( $on_page / $page_width ) + 1;
  5972. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  5973. }
  5974. for(; $i <= $page ['total_page']; $i ++) {
  5975. if ($i == $on_page)
  5976. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  5977. else
  5978. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  5979. if ($i == ($page_width * $page_max))
  5980. break;
  5981. }
  5982. $page ['page'] = $page_c;
  5983. $page ['lower'] = (-- $on_page) * $page_size;
  5984. return $page;
  5985. }
  5986. /**
  5987. * 获取上一页
  5988. * @param unknown_type $on_page
  5989. */
  5990. function get_previous($on_page = 1) {
  5991. return $on_page != 0 ? $on_page - 1 : $on_page;
  5992. }
  5993. /**
  5994. * 获取总页数
  5995. * @param unknown_type $table
  5996. * @param unknown_type $condition
  5997. */
  5998. public function get_table_count($table = "", $condition = "") {
  5999. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6000. $sql = "select count(*) as count from " . $table . " where " . $condition;
  6001. // echo $sql;die;
  6002. $query = Doo::db ()->query ( $sql );
  6003. $result = $query->fetch ();
  6004. return $result ['count'];
  6005. }
  6006. /**
  6007. * 获得分页数据
  6008. * @param unknown_type $table
  6009. * @param unknown_type $condition
  6010. * @param unknown_type $on_page
  6011. * @param unknown_type $page_size
  6012. */
  6013. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6014. $page_c = "";
  6015. $page ['previous'] = $this->get_previous ( $on_page );
  6016. $page ['on_page'] = $on_page;
  6017. $total_count = $this->getTableCountBySql ( $sql );
  6018. $total = intval ( $total_count / $page_size );
  6019. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6020. $page ['total_data'] = $total_count;
  6021. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6022. $i = 1;
  6023. $page_max = 1;
  6024. $page_width = 3;
  6025. if ($on_page >= $page_width) {
  6026. $page_max = intval ( $on_page / $page_width ) + 1;
  6027. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6028. }
  6029. for(; $i <= $page ['total_page']; $i ++) {
  6030. if ($i == $on_page)
  6031. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6032. else
  6033. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6034. if ($i == ($page_width * $page_max))
  6035. break;
  6036. }
  6037. $page ['page'] = $page_c;
  6038. $page ['lower'] = (-- $on_page) * $page_size;
  6039. return $page;
  6040. }
  6041. /**
  6042. * 获得总页数 sql
  6043. * @param string $type
  6044. * @return boolean[]
  6045. */
  6046. public function getTableCountBySql($sql = "") {
  6047. $query = Doo::db ()->query ( $sql );
  6048. $result = $query->fetchAll ();
  6049. return count ( $result );
  6050. }
  6051. function isInvoiceNew($type = "GLOBAL") {
  6052. Doo::loadModel ( 'invoice' );
  6053. $invoice = new invoice ();
  6054. Doo::loadModel ( 'invoiceReceivables' );
  6055. $invoiceReceivables = new invoiceReceivables ();
  6056. Doo::loadModel ( 'staff' );
  6057. $staff = new staff ();
  6058. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  6059. // 我的发票待处理
  6060. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  6061. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  6062. 'desc' => 'iid',
  6063. 'asArray' => TRUE
  6064. ) );
  6065. // 我的收款待入账
  6066. /*
  6067. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  6068. */
  6069. // 发票审批
  6070. $approval = $invoice->getOne ( array (
  6071. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  6072. 'desc' => 'iid',
  6073. 'asArray' => true
  6074. ) );
  6075. // 发票邮寄
  6076. $post = $invoice->getOne ( array (
  6077. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  6078. 'asArray' => TRUE
  6079. ) );
  6080. // 发票打印
  6081. $print = $invoice->getOne ( array (
  6082. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  6083. 'desc' => 'iid',
  6084. 'asArray' => TRUE
  6085. ) );
  6086. // 发票退票 printStatus=1 and
  6087. $untread = $invoice->getOne ( array (
  6088. 'where' => " untreadStatus=1 and status=2 ",
  6089. 'asArray' => TRUE
  6090. ) );
  6091. $new = array (
  6092. 'GLOBAL' => FALSE,
  6093. 'pendingInvoice' => FALSE,
  6094. // 'myClaim' => FALSE,
  6095. 'approval' => FALSE,
  6096. 'post' => FALSE,
  6097. 'print' => FALSE,
  6098. 'untread' => FALSE
  6099. );
  6100. // || ! empty ( $myClaim )
  6101. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  6102. $new ['GLOBAL'] = TRUE;
  6103. if (! empty ( $pendingInvoice ))
  6104. $new ['pendingInvoice'] = TRUE;
  6105. // if (! empty ( $myClaim ))
  6106. // $new ['myClaim'] = TRUE;
  6107. if (! empty ( $approval ))
  6108. $new ['approval'] = TRUE;
  6109. if (! empty ( $post ))
  6110. $new ['post'] = TRUE;
  6111. if (! empty ( $print ))
  6112. $new ['print'] = TRUE;
  6113. if (! empty ( $untread ))
  6114. $new ['untread'] = TRUE;
  6115. return $new;
  6116. }
  6117. function setWXMsg($rid, $typeMsg = '') {
  6118. Doo::loadModel ( 'invoice' );
  6119. $invoice = new invoice ();
  6120. $invoiceDetail = $invoice->getOne ( array (
  6121. 'where' => 'iid=' . $rid,
  6122. 'asArray' => true
  6123. ) );
  6124. if (! empty ( $invoiceDetail )) {
  6125. Doo::loadModel ( 'staff' );
  6126. $staff = new staff ();
  6127. $staffmsg = $staff->getOne ( array (
  6128. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  6129. 'asArray' => TRUE
  6130. ) );
  6131. if (! empty ( $staffmsg ['wxid'] )) {
  6132. require_once (SITE_PATH . '/protected/class/client.php');
  6133. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  6134. $user = $staffmsg ['wxid'];
  6135. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  6136. if (empty ( $expCom ))
  6137. $expCom [0] = '';
  6138. $msg = "";
  6139. if (empty ( $typeMsg ))
  6140. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  6141. elseif ($typeMsg == "PRINT")
  6142. $msg = '太好了,您的发票已打印完成。';
  6143. $result = $client->SendMsg ( $user, $msg, 'text' );
  6144. }
  6145. }
  6146. }
  6147. /**
  6148. * 获取微信部门
  6149. * @param string $category
  6150. * @return number|mixed
  6151. */
  6152. function getToparty($category = '') {
  6153. $token = $this->getAccessToken (); //
  6154. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  6155. $toparty = 0;
  6156. foreach ( $result ['department'] as $key => $value ) {
  6157. if ($value ['name'] == $category)
  6158. $toparty = $value ['id'];
  6159. }
  6160. return $toparty;
  6161. }
  6162. /**
  6163. * 获得某部门下的用户
  6164. * @param string $toparty
  6165. */
  6166. function getUserByToparty($toparty = '') {
  6167. $token = $this->getAccessToken (); //
  6168. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  6169. $userList = array ();
  6170. foreach ( $result ['userlist'] as $key => $value ) {
  6171. array_push ( $userList, "'" . $value ['userid'] . "'" );
  6172. }
  6173. return $userList;
  6174. }
  6175. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  6176. $token = $this->getAccessToken ();
  6177. if ($text == 'text') {
  6178. $data = '{
  6179. "touser": "' . $toparty . '",
  6180. "toparty": "",
  6181. "totag": "",
  6182. "msgtype": "text",
  6183. "agentid": 1000002,
  6184. "text": {
  6185. "content": "' . $msg . '"
  6186. },
  6187. "safe":0
  6188. }';
  6189. }
  6190. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6191. if ($result->errmsg != 'ok') {
  6192. return 0;
  6193. } else {
  6194. return 1;
  6195. }
  6196. }
  6197. /**
  6198. * 获得可以发送微信用户列表
  6199. * @param string $category
  6200. * @return string
  6201. */
  6202. function getWxidByCategory($category = "") {
  6203. if (empty ( $category ))
  6204. return "";
  6205. Doo::loadModel ( 'staff' );
  6206. $staff = new staff ();
  6207. $toparty = $this->getToparty ( $category );
  6208. $wxList = array ();
  6209. $wxString = "";
  6210. if (! empty ( $toparty )) {
  6211. $userList = $this->getUserByToparty ( $toparty );
  6212. $userCon = implode ( ',', $userList );
  6213. // echo $userCon;
  6214. $sidList = $staff->getStaffByWxid ( $userCon );
  6215. foreach ( $sidList as $key => $value ) {
  6216. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  6217. if ($falg) {
  6218. array_push ( $wxList, $value ['wxid'] );
  6219. }
  6220. }
  6221. $wxString = implode ( '|', $wxList );
  6222. }
  6223. return $wxString;
  6224. }
  6225. /**
  6226. * 读取发送信息规则判断是否需要发送
  6227. * @param number $sid
  6228. * @param string $sendType
  6229. * @return boolean
  6230. */
  6231. function isSendNotification($sid = 0, $sendType = '') {
  6232. Doo::loadModel ( "notificationConf" );
  6233. $notificationConf = new notificationConf ();
  6234. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  6235. $conf = array ();
  6236. $sendFlag = true;
  6237. if (! empty ( $detail )) {
  6238. $conf = json_decode ( $detail ['conf'], true );
  6239. if (! empty ( $sendType )) {
  6240. if (isset ( $conf [$sendType] )) {
  6241. if ($conf [$sendType] == "CLOSE")
  6242. $sendFlag = false;
  6243. elseif ($conf [$sendType] == "Weekend") {
  6244. $day = date ( "w" );
  6245. if (1 <= $day && 5 >= $day)
  6246. $sendFlag = false;
  6247. } elseif ($conf [$sendType] == "OneToFriday") {
  6248. $day = date ( "w" );
  6249. if (0 == $day || 6 == $day)
  6250. $sendFlag = false;
  6251. }
  6252. }
  6253. } else
  6254. $sendFlag = false;
  6255. }
  6256. return $sendFlag;
  6257. }
  6258. /**
  6259. * 根据规则发送信息
  6260. * @param unknown $msg
  6261. * @param unknown $title
  6262. * @param unknown $url
  6263. * @param unknown $user
  6264. * @param string $text
  6265. * @return number
  6266. */
  6267. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  6268. $token = $this->getAccessToken ();
  6269. $falg = $this->isSendNotification ( $sid, $sendType );
  6270. // if ($text == 'text') {
  6271. // $data = '{
  6272. // "touser": "' . $user . '",
  6273. // "toparty": "",
  6274. // "totag": "",
  6275. // "msgtype": "text",
  6276. // "agentid": 1000002,
  6277. // "text": {
  6278. // "content": "' . $msg . '"
  6279. // },
  6280. // "safe":0
  6281. // }';
  6282. // } else {
  6283. $data = '{
  6284. "touser": "' . $user . '",
  6285. "toparty": "",
  6286. "totag": "",
  6287. "msgtype": "news",
  6288. "agentid": 1000002,
  6289. "news": {
  6290. "articles":[
  6291. {
  6292. "title": "' . $title . '",
  6293. "description": "' . $msg . '",
  6294. "url": "' . $url . '",
  6295. "picurl": ""
  6296. }
  6297. ]
  6298. }
  6299. }';
  6300. // }
  6301. if ($falg) {
  6302. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6303. if ($result->errmsg != 'ok') {
  6304. return 0;
  6305. } else {
  6306. return 1;
  6307. }
  6308. } else
  6309. return 0;
  6310. }
  6311. private function getAccessToken() {
  6312. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  6313. // $file = './access_token.txt';
  6314. // $data = json_decode ( file_get_contents ( $file ) );
  6315. // if ($data->expire_time < time () or ! $data->expire_time) {
  6316. // 如果是企业号用以下URL获取access_token
  6317. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  6318. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  6319. $res = json_decode ( $this->httpGet ( $url ) );
  6320. $access_token = $res->access_token;
  6321. // echo $access_token;
  6322. // if ($access_token) {
  6323. // $data->expire_time = time () + 7000;
  6324. // $data->access_token = $access_token;
  6325. // $fp = fopen ( $file, "w" );
  6326. // fwrite ( $fp, json_encode ( $data ) );
  6327. // fclose ( $fp );
  6328. // }
  6329. // } else {
  6330. // $access_token = $data->access_token;
  6331. // }
  6332. return $access_token;
  6333. }
  6334. private function httpGet($url) {
  6335. $curl = curl_init ();
  6336. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6337. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6338. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6339. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6340. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6341. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6342. curl_setopt ( $curl, CURLOPT_URL, $url );
  6343. $res = curl_exec ( $curl );
  6344. curl_close ( $curl );
  6345. return $res;
  6346. }
  6347. private function httpPost($url, $data) {
  6348. $curl = curl_init ();
  6349. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6350. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6351. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6352. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6353. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6354. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6355. curl_setopt ( $curl, CURLOPT_URL, $url );
  6356. curl_setopt ( $curl, CURLOPT_POST, 1 );
  6357. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  6358. $res = curl_exec ( $curl );
  6359. curl_close ( $curl );
  6360. return $res;
  6361. }
  6362. }
  6363. ?>