InvoiceController.php 234 KB

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