InvoiceController.php 234 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385
  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. function invoiceReceivablesTitleMarkSet(){
  2644. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2645. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2646. if(empty($iridKey)||empty($recepitTitleMark))
  2647. die ( 'illegal request' );
  2648. Doo::loadModel ( 'invoiceReceivables' );
  2649. $invoiceReceivables = new invoiceReceivables ();
  2650. Doo::loadClass ( 'XDeode' );
  2651. $XDeode = new XDeode ( 5 );
  2652. $irid=$XDeode->decode($iridKey);
  2653. if (!is_numeric($irid))
  2654. die ( 'illegal request' );
  2655. $invoiceReceivables->recepitTitleMark=$recepitTitleMark;
  2656. $invoiceReceivables->update ( array (
  2657. 'where' => 'irid = ' . $irid
  2658. ) );
  2659. return '/invoiceReceivablesClaim';
  2660. }
  2661. /**
  2662. * 更新收款相关数据
  2663. */
  2664. function invoiceReceivablesUpdateClaim() {
  2665. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2666. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2667. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2668. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2669. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2670. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2671. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2672. if (empty ( $claimKey ))
  2673. die ( 'illegal request' );
  2674. Doo::loadModel ( 'invoiceReceivables' );
  2675. $invoiceReceivables = new invoiceReceivables ();
  2676. Doo::loadModel ( 'invoiceROLog' );
  2677. $invoiceROLog = new invoiceROLog ();
  2678. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  2679. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2680. if (empty ( $detail ))
  2681. die ( 'illegal request' );
  2682. $invoiceReceivables = new invoiceReceivables ();
  2683. $item = array (
  2684. 'irid' => $detail ['irid']
  2685. );
  2686. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2687. $item += array (
  2688. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2689. );
  2690. }
  2691. if (! empty ( $receivablesCategory ))
  2692. $item += array (
  2693. 'receivablesCategory' => $receivablesCategory
  2694. );
  2695. if (! empty ( $receivablesStaff ))
  2696. $item += array (
  2697. 'receivablesStaff' => $receivablesStaff
  2698. );
  2699. if (! empty ( $receivablesPrice ))
  2700. $item += array (
  2701. 'receivablesPrice' => $receivablesPrice
  2702. );
  2703. if (! empty ( $receivablesMessage ))
  2704. $item += array (
  2705. 'receivablesMessage' => $receivablesMessage
  2706. );
  2707. if (! empty ( $receivablesBank ))
  2708. $item += array (
  2709. 'receivablesBank' => $receivablesBank
  2710. );
  2711. if (! empty ( $receivablesDate ))
  2712. $item += array (
  2713. 'receivablesDate' => $receivablesDate
  2714. );
  2715. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2716. // 收款操作日志
  2717. $item = array ();
  2718. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2719. $item = array (
  2720. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2721. );
  2722. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2723. $item = array (
  2724. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2725. );
  2726. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2727. $receivablesStaff = explode ( '-', $receivablesStaff );
  2728. $item = array (
  2729. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2730. );
  2731. }
  2732. $item += array (
  2733. 'date' => date ( "Y-m-d" ),
  2734. 'status' => 1,
  2735. 'img' => $this->staff [0] ['avatar'],
  2736. 'username' => $this->staff [0] ['username'],
  2737. 'uid' => $this->staff [0] ['sid'],
  2738. 'category' => $this->staff [0] ['category'],
  2739. 'irid' => $detail ['irid']
  2740. );
  2741. $invoiceROLog->setInvoiceROLog ( $item );
  2742. return '/invoiceReceivablesAS';
  2743. }
  2744. function invoiceReceivablesDelete() {
  2745. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2746. if (empty ( $claimKey ))
  2747. die ( 'illegal request' );
  2748. Doo::loadModel ( 'invoiceReceivables' );
  2749. $invoiceReceivables = new invoiceReceivables ();
  2750. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  2751. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2752. if (empty ( $detail ))
  2753. die ( 'illegal request' );
  2754. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  2755. return '/invoiceReceivablesAS';
  2756. }
  2757. /**
  2758. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  2759. */
  2760. function invoiceReceivablesAscription() {
  2761. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2762. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2763. Doo::loadModel ( 'invoiceReceivables' );
  2764. $invoiceReceivables = new invoiceReceivables ();
  2765. Doo::loadModel ( 'invoiceROLog' );
  2766. $invoiceROLog = new invoiceROLog ();
  2767. Doo::loadModel ( 'invoiceStatistics' );
  2768. $invoiceStatistics = new invoiceStatistics ();
  2769. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2770. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  2771. $item = array (
  2772. 'irid' => $detail ['irid'],
  2773. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  2774. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  2775. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2776. 'recepitTitleMark' => $recepitTitleMark,
  2777. 'source' => 1
  2778. );
  2779. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2780. $item = array (
  2781. 'date' => date ( "Y-m-d" ),
  2782. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  2783. 'status' => 2,
  2784. 'img' => $this->staff [0] ['avatar'],
  2785. 'username' => $this->staff [0] ['username'],
  2786. 'uid' => $this->staff [0] ['sid'],
  2787. 'category' => $this->staff [0] ['category'],
  2788. 'irid' => $irid
  2789. );
  2790. $invoiceROLog->setInvoiceROLog ( $item );
  2791. $item = array (
  2792. 'cid' => $this->staff [0] ['cid'],
  2793. 'staff' => $this->staff [0] ['sid']
  2794. );
  2795. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  2796. }
  2797. return "/invoiceReceivablesClaim";
  2798. }
  2799. /**
  2800. */
  2801. function invoiceMyReceivables() {
  2802. Doo::loadModel ( 'invoiceReceivables' );
  2803. $invoiceReceivables = new invoiceReceivables ();
  2804. Doo::loadModel ( 'invoiceStatistics' );
  2805. $invoiceStatistics = new invoiceStatistics ();
  2806. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  2807. $year = date ( "Y" );
  2808. $tmp_date = date ( "Ym" );
  2809. $tmp_year = substr ( $tmp_date, 0, 4 );
  2810. $tmp_mon = substr ( $tmp_date, 4, 2 );
  2811. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  2812. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  2813. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  2814. $htm = $this->showCache ( $path );
  2815. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2816. $this->data ['isMonth'] = $isMonth;
  2817. $this->data ['htm'] = $htm;
  2818. $this->data ['list'] = $list;
  2819. $this->data ['memu'] = "invoice";
  2820. $this->data ['staff'] = $this->staff;
  2821. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  2822. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  2823. }
  2824. /**
  2825. * 收款绑定发票 ,一个收款只能绑定一个发票
  2826. */
  2827. function invoiceBindReceivables() {
  2828. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2829. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2830. Doo::loadModel ( 'invoice' );
  2831. $invoice = new invoice ();
  2832. Doo::loadModel ( 'invoiceReceivables' );
  2833. $invoiceReceivables = new invoiceReceivables ();
  2834. Doo::loadModel ( 'invoiceOperationLog' );
  2835. $invoiceOperationLog = new invoiceOperationLog ();
  2836. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  2837. die ( 'illegal request' );
  2838. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2839. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  2840. if (empty ( $detail ) && empty ( $detailM ))
  2841. die ( 'illegal request' );
  2842. if ($detail ['untreadStatus'] == 3)
  2843. die ( 'illegal request' );
  2844. // 修改 绑定状态改为 金额
  2845. $invoiceReceivables = new invoiceReceivables ();
  2846. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  2847. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  2848. $item = array (
  2849. 'bindPrice' => $invoicePrice
  2850. );
  2851. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  2852. $item = array (
  2853. 'bindPrice' => $invoicePrice,
  2854. 'bindStatus' => 1,
  2855. 'bindDate' => date ( "Y-m-d H:i:s" )
  2856. );
  2857. } else {
  2858. die ( 'illegal request' );
  2859. }
  2860. if ($detailM ['iid'] == 0) {
  2861. $item += array (
  2862. 'iid' => $detail ['iid']
  2863. );
  2864. } else {
  2865. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  2866. array_push ( $iidExtend, $detail ['iid'] );
  2867. $item += array (
  2868. 'iidExtend' => implode ( ',', $iidExtend )
  2869. );
  2870. }
  2871. $item += array (
  2872. 'irid' => $detailM ['irid'],
  2873. 'accountClerk' => $this->staff [0] ['username']
  2874. );
  2875. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2876. $iridString = "";
  2877. if (empty ( $detail ['irid'] ))
  2878. $iridString = $detailM ['irid'];
  2879. else
  2880. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  2881. $item = array (
  2882. 'iid' => $detail ['iid'],
  2883. 'irid' => $iridString
  2884. );
  2885. $invoiceReceivables = new invoiceReceivables ();
  2886. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2887. if ($detail ['invoicePrice'] <= $sum)
  2888. $item += array (
  2889. 'untreadStatus' => 3 ,
  2890. 'bindTime'=>date ( "Y-m-d H:i:s" )
  2891. );
  2892. // print_r($item);
  2893. // echo $sum;die;
  2894. $invoice->setInvoiceByCondition ( $item );
  2895. // 操作日志
  2896. $item = array (
  2897. 'date' => date ( "Y-m-d H:i:s" ),
  2898. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  2899. 'status' => 8,
  2900. 'img' => $this->staff [0] ['avatar'],
  2901. 'username' => $this->staff [0] ['username'],
  2902. 'uid' => $this->staff [0] ['sid'],
  2903. 'category' => $this->staff [0] ['category'],
  2904. 'iid' => $detail ['iid']
  2905. );
  2906. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2907. Doo::loadModel ( 'invoiceStatistics' );
  2908. $invoiceStatistics = new invoiceStatistics ();
  2909. $item = array (
  2910. 'date' => $detailM ['receivablesDate'],
  2911. 'priceClass' => 3,
  2912. 'cid' => $detail ['cid'],
  2913. 'staff' => $detail ['sid'],
  2914. 'accountPrice' => $detailM ['receivablesPrice']
  2915. );
  2916. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2917. return "/invoiceReceivables";
  2918. }
  2919. /**
  2920. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  2921. */
  2922. function invoiceAggregate() {
  2923. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2924. Doo::loadModel ( 'invoiceStatistics' );
  2925. $invoiceStatistics = new invoiceStatistics ();
  2926. Doo::loadModel ( 'L_category' );
  2927. $Lcategory = new L_category ();
  2928. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  2929. $LcategoryList = $Lcategory->getCategory ();
  2930. // print_r($isList);
  2931. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  2932. foreach ( $LcategoryList as $key => $value ) {
  2933. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  2934. $month = 1;
  2935. $invoicePriceYear = 0;
  2936. $receivablesPriceYear = 0;
  2937. $accountPriceYear = 0;
  2938. for(; $month <= 12; $month ++) {
  2939. $flag = true;
  2940. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  2941. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  2942. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  2943. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  2944. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  2945. ';
  2946. $invoicePriceYear += $v ['invoicePrice'];
  2947. $receivablesPriceYear += $v ['receivablesPrice'];
  2948. $accountPriceYear += $v ['accountPrice'];
  2949. $flag = false;
  2950. break;
  2951. }
  2952. }
  2953. if ($flag)
  2954. $html .= '<td class="taR"></td>
  2955. <td class="taR"></td>
  2956. <td class="taR"><b></b></td>
  2957. ';
  2958. }
  2959. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  2960. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  2961. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  2962. ';
  2963. $html .= '</tr>';
  2964. }
  2965. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  2966. $invoicePriceYear = 0;
  2967. $receivablesPriceYear = 0;
  2968. $accountPriceYear = 0;
  2969. for($month = 1; $month <= 12; $month ++) {
  2970. $flag = true;
  2971. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  2972. if ($month == $v ['month']) {
  2973. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  2974. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  2975. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  2976. ';
  2977. $invoicePriceYear += $v ['invoicePrice'];
  2978. $receivablesPriceYear += $v ['receivablesPrice'];
  2979. $accountPriceYear += $v ['accountPrice'];
  2980. $flag = false;
  2981. break;
  2982. }
  2983. }
  2984. if ($flag) {
  2985. $html .= '<td class="taR"></td>
  2986. <td class="taR"></td>
  2987. <td class="taR"><b></b></td>
  2988. ';
  2989. }
  2990. }
  2991. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  2992. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  2993. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  2994. ';
  2995. $html .= '</tr>';
  2996. // print_r($isList);
  2997. $this->data ['html'] = $html;
  2998. $this->data ['LcategoryList'] = $LcategoryList;
  2999. $this->data ['isList'] = $isList;
  3000. $this->data ['year'] = $year;
  3001. $this->data ['memu'] = "invoice";
  3002. $this->data ['staff'] = $this->staff;
  3003. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3004. $this->render ( "/admin/invoiceAggregate", $this->data );
  3005. }
  3006. function invoiceAggregateStaff() {
  3007. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3008. Doo::loadModel ( 'invoiceStatistics' );
  3009. $invoiceStatistics = new invoiceStatistics ();
  3010. Doo::loadModel ( 'L_category' );
  3011. $Lcategory = new L_category ();
  3012. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3013. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3014. $cStaff = $Lcategory->getCategoryStaff ();
  3015. $html = '';
  3016. foreach ( $cStaff as $key => $value ) {
  3017. $categoryFir = true;
  3018. foreach ( $value ['staff'] as $k => $v ) {
  3019. if ($categoryFir) {
  3020. $width = count ( $value ['staff'] ) + 1;
  3021. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3022. $categoryFir = false;
  3023. } else
  3024. $html .= '<tr>';
  3025. $html .= '<th>' . $v ['username'] . '</th>';
  3026. $invoicePriceStaffYear = 0;
  3027. $receivablesPriceStaffYear = 0;
  3028. $accountPriceStaffYear = 0;
  3029. for($month = 1; $month <= 12; $month ++) {
  3030. $flag = true;
  3031. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3032. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3033. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3034. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3035. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3036. ';
  3037. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3038. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3039. $accountPriceStaffYear += $slv ['accountPrice'];
  3040. $flag = false;
  3041. break;
  3042. }
  3043. }
  3044. if ($flag)
  3045. $html .= '<td class="taR"></td>
  3046. <td class="taR"></td>
  3047. <td class="taR"><b></b></td>
  3048. ';
  3049. }
  3050. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3051. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3052. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3053. ';
  3054. }
  3055. $html .= '</tr>';
  3056. // 小计
  3057. if (! empty ( $value ['staff'] )) {
  3058. $html .= '<tr><th class="taR">小计</th>';
  3059. $invoicePriceStaffYear = 0;
  3060. $receivablesPriceStaffYear = 0;
  3061. $accountPriceStaffYear = 0;
  3062. for($month = 1; $month <= 12; $month ++) {
  3063. $flag = true;
  3064. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3065. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3066. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3067. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3068. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3069. ';
  3070. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3071. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3072. $accountPriceStaffYear += $slv ['accountPrice'];
  3073. $flag = false;
  3074. break;
  3075. }
  3076. }
  3077. if ($flag)
  3078. $html .= '<td class="taR"></td>
  3079. <td class="taR"></td>
  3080. <td class="taR"><b></b></td>
  3081. ';
  3082. }
  3083. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3084. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3085. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3086. ';
  3087. $html .= '</tr>';
  3088. }
  3089. }
  3090. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3091. $invoicePriceYear = 0;
  3092. $receivablesPriceYear = 0;
  3093. $accountPriceYear = 0;
  3094. for($month = 1; $month <= 12; $month ++) {
  3095. $flag = true;
  3096. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3097. if ($month == $v ['month']) {
  3098. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3099. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3100. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3101. ';
  3102. $invoicePriceYear += $v ['invoicePrice'];
  3103. $receivablesPriceYear += $v ['receivablesPrice'];
  3104. $accountPriceYear += $v ['accountPrice'];
  3105. $flag = false;
  3106. break;
  3107. }
  3108. }
  3109. if ($flag)
  3110. $html .= '<td class="taR"></td>
  3111. <td class="taR"></td>
  3112. <td class="taR"><b></b></td>
  3113. ';
  3114. }
  3115. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3116. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3117. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3118. ';
  3119. $html .= '</tr>';
  3120. $this->data ['html'] = $html;
  3121. $this->data ['isList'] = $toteList;
  3122. $this->data ['year'] = $year;
  3123. $this->data ['memu'] = "invoice";
  3124. $this->data ['staff'] = $this->staff;
  3125. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3126. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3127. }
  3128. function invoiceAggregateCategory() {
  3129. Doo::loadClass ( 'XDeode' );
  3130. $XDeode = new XDeode ( 5 );
  3131. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3132. $cid = $XDeode->decode ( $cid );
  3133. if (! is_numeric ( $cid ))
  3134. die ( 'illegal request' );
  3135. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3136. Doo::loadModel ( 'invoiceStatistics' );
  3137. $invoiceStatistics = new invoiceStatistics ();
  3138. Doo::loadModel ( 'staff' );
  3139. $staff = new staff ();
  3140. $list = $staff->getStaffByCid ( $cid );
  3141. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3142. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3143. if (empty ( $list ))
  3144. die ( '该办事处没有成员' );
  3145. $htmlA = $htmlB = $htmlC = $html = '';
  3146. foreach ( $list as $key => $value ) {
  3147. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3148. $htmlB = '<tr><th class="taC">收款</th>';
  3149. $htmlC = '<tr><th class="taC">入账</th>';
  3150. $invoicePriceStaffYear = 0;
  3151. $receivablesPriceStaffYear = 0;
  3152. $accountPriceStaffYear = 0;
  3153. for($month = 1; $month <= 12; $month ++) {
  3154. $flag = true;
  3155. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3156. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3157. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3158. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3159. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3160. $invoicePriceStaffYear += $v ['invoicePrice'];
  3161. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3162. $accountPriceStaffYear += $v ['accountPrice'];
  3163. $flag = false;
  3164. break;
  3165. }
  3166. }
  3167. if ($flag) {
  3168. $htmlA .= '<td class="taR">-</td>';
  3169. $htmlB .= '<td class="taR">-</td>';
  3170. $htmlC .= '<td class="taR"><b>-</b></td>';
  3171. }
  3172. }
  3173. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3174. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3175. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3176. $htmlA .= '</tr>';
  3177. $htmlB .= '</tr>';
  3178. $htmlC .= '</tr>';
  3179. $html .= $htmlA . $htmlB . $htmlC;
  3180. }
  3181. $htmlA = $htmlB = $htmlC = "";
  3182. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3183. $htmlB = '<tr><th class="taC">收款</th>';
  3184. $htmlC = '<tr><th class="taC">入账</th>';
  3185. $invoicePriceStaffYear = 0;
  3186. $receivablesPriceStaffYear = 0;
  3187. $accountPriceStaffYear = 0;
  3188. for($month = 1; $month <= 12; $month ++) {
  3189. $flag = true;
  3190. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3191. if ($month == $v ['month']) {
  3192. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3193. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3194. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3195. $invoicePriceStaffYear += $v ['invoicePrice'];
  3196. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3197. $accountPriceStaffYear += $v ['accountPrice'];
  3198. $flag = false;
  3199. break;
  3200. }
  3201. }
  3202. if ($flag) {
  3203. $htmlA .= '<td class="taR">-</td>';
  3204. $htmlB .= '<td class="taR">-</td>';
  3205. $htmlC .= '<td class="taR"><b>-</b></td>';
  3206. }
  3207. }
  3208. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3209. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3210. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3211. $htmlA .= '</tr>';
  3212. $htmlB .= '</tr>';
  3213. $htmlC .= '</tr>';
  3214. $html .= $htmlA . $htmlB . $htmlC;
  3215. $this->data ['html'] = $html;
  3216. $this->data ['cidKey'] = $cidKey;
  3217. $this->data ['slist'] = $list;
  3218. $this->data ['isList'] = $toteList;
  3219. $this->data ['year'] = $year;
  3220. $this->data ['memu'] = "invoice";
  3221. $this->data ['staff'] = $this->staff;
  3222. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3223. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3224. }
  3225. function invoiceAggregateCategoryDetail(){
  3226. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  3227. Doo::loadClass ( 'XDeode' );
  3228. $XDeode = new XDeode ( 5 );
  3229. Doo::loadModel ( 'invoiceStatistics' );
  3230. $invoiceStatistics = new invoiceStatistics ();
  3231. Doo::loadModel('L_category');
  3232. $category=new L_category();
  3233. Doo::loadModel('invoice');
  3234. $invoice=new invoice();
  3235. Doo::loadModel ( 'staff' );
  3236. $staff = new staff ();
  3237. Doo::loadModel ( "invoiceCategoryManage" );
  3238. $invoiceCategoryManage = new invoiceCategoryManage ();
  3239. $imcStaff=$invoiceCategoryManage->getInvoiceCMByStaff($this->staff[0]['sid']);
  3240. $cidList=array();
  3241. foreach ($imcStaff as $key=>$value){
  3242. array_push($cidList, $value['cid']);
  3243. if (empty($cidKey))
  3244. $cidKey=$XDeode->encode ( $value ['cid'] );
  3245. }
  3246. $categoryList =$category->getCategoryInCid(implode(',', $cidList));
  3247. $cid = $XDeode->decode ( $cidKey );
  3248. $redis = new Redis();
  3249. $redis->connect('127.0.0.1', '6379');
  3250. $redisKey=date('Y-m-d').'_iacd_'.$cid;
  3251. $redisValue = $redis->lrange($redisKey, 0, -1);
  3252. if (empty($redisValue)){
  3253. $isMC=$invoiceStatistics->getInvoiceStatistiscsMothByCategory($cid);
  3254. $schedule=$invoice->getInvoiceScheduleByCid($cid);
  3255. //获得办事处人员下的汇总
  3256. $slist=$staff->getStaffByCid($cid);
  3257. $ismsb=$invoiceStatistics->getISMSByCategory($cid);//当月汇总
  3258. $ISAS=$invoiceStatistics->getISASByCategory($cid);//全部汇总
  3259. $scheduleStaff=$invoice->getInvoiceScheduleByCidGroupSid($cid);//完成度
  3260. foreach ($slist as $key=>$value){
  3261. $slist[$key]['invoicePrice']=0;
  3262. $slist[$key]['receivablesPrice']=0;
  3263. $slist[$key]['accountPrice']=0;
  3264. $slist[$key]['invoiceAllPrice']=0;
  3265. $slist[$key]['receivablesAllPrice']=0;
  3266. $slist[$key]['accountAllPrice']=0;
  3267. $slist[$key]['schedule']=0;
  3268. foreach ($ismsb as $k=>$v){
  3269. if ($value['sid']==$v['staff']){
  3270. $slist[$key]['invoicePrice']=$v['invoicePrice'];
  3271. $slist[$key]['receivablesPrice']=$v['receivablesPrice'];
  3272. $slist[$key]['accountPrice']=$v['accountPrice'];
  3273. }
  3274. }
  3275. foreach ($ISAS as $e=>$a){
  3276. if ($value['sid']==$a['staff']){
  3277. $slist[$key]['invoiceAllPrice']=$a['invoicePrice'];
  3278. $slist[$key]['receivablesAllPrice']=$a['receivablesPrice'];
  3279. $slist[$key]['accountAllPrice']=$a['accountPrice'];
  3280. }
  3281. }
  3282. if (isset($scheduleStaff[$value['sid']]))
  3283. $slist[$key]['schedule']=$scheduleStaff[$value['sid']];
  3284. }
  3285. $this->data['cidKey']=$cidKey;
  3286. $schedule=(int)($schedule*100);
  3287. $this->data['slist']=$slist;
  3288. $this->data['isMC']=$isMC;
  3289. $this->data['schedule']=$schedule;
  3290. $slist=json_encode($slist);
  3291. $isMC=json_encode($isMC);
  3292. $schedule=json_encode($schedule);
  3293. $redis->lpush($redisKey, $slist);
  3294. $redis->lpush($redisKey, $isMC);
  3295. $redis->lpush($redisKey, $schedule);
  3296. }else{
  3297. $this->data['cidKey']=$cidKey;
  3298. $this->data['slist']=json_decode($redisValue[2],true);
  3299. $this->data['isMC']=json_decode($redisValue[1],true);
  3300. $this->data['schedule']=json_decode($redisValue[0],true);
  3301. }
  3302. $this->data['categoryList']=$categoryList;
  3303. $this->data ['memu'] = "invoice";
  3304. $this->data ['staff'] = $this->staff;
  3305. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3306. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  3307. }
  3308. function invoiceAchieve() {
  3309. Doo::loadModel ( 'invoice' );
  3310. $invoice = new invoice ();
  3311. Doo::loadClass ( 'XDeode' );
  3312. $XDeode = new XDeode ( 5 );
  3313. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3314. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3315. $page_size = 18;
  3316. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3317. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3318. $get = "/" . $date;
  3319. $con = '';
  3320. if ($date == 'MONTHO')
  3321. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3322. elseif ($date == 'MONTHT')
  3323. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3324. elseif ($date == 'MONTHY')
  3325. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3326. if (! empty ( $MebSea )) {
  3327. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3328. $get .= "/" . $MebSea;
  3329. }
  3330. $pageinfo ['page'] = array (
  3331. 'previous' => ''
  3332. );
  3333. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  3334. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  3335. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3336. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3337. // print_r($pageinfo);
  3338. $this->data ['MebSeaEn'] = $MebSea;
  3339. $this->data ['MebSea'] = urlencode ( $MebSea );
  3340. $this->data ['get'] = $get;
  3341. $this->data ['page'] = $pageinfo;
  3342. $this->data ['list'] = $list;
  3343. $this->data ['date'] = $date;
  3344. $this->data ['memu'] = "invoice";
  3345. $this->data ['staff'] = $this->staff;
  3346. $this->data ['receiptMemu'] = 'invoice';
  3347. $this->render ( "/admin/invoiceAchieve", $this->data );
  3348. }
  3349. function invoiceMyUnAccountAchieve() {
  3350. Doo::loadModel ( 'invoice' );
  3351. $invoice = new invoice ();
  3352. Doo::loadClass ( 'XDeode' );
  3353. $XDeode = new XDeode ( 5 );
  3354. Doo::loadModel ( 'staff' );
  3355. $staff = new staff ();
  3356. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3357. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3358. $page_size = 18;
  3359. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3360. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3361. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3362. $dateArr = explode ( ':', $date );
  3363. $D1 = '';
  3364. $D2 = '';
  3365. if (! empty ( $date )) {
  3366. $D1 = $dateArr [0];
  3367. $D2 = $dateArr [1];
  3368. }
  3369. $con = '';
  3370. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3371. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3372. if (! empty ( $MebSea )) {
  3373. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3374. }
  3375. $pageinfo ['page'] = array (
  3376. 'previous' => ''
  3377. );
  3378. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  3379. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  3380. $action = "invoiceMyUnAccountAchieve";
  3381. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  3382. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3383. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3384. Doo::loadModel ( 'express' );
  3385. $express = new express ();
  3386. $expressList = $express->getExpressByAll ();
  3387. $this->data ['expressList'] = $expressList;
  3388. // print_r($list);
  3389. $this->data ['MebSeaEn'] = $MebSea;
  3390. $this->data ['get'] = $get;
  3391. $this->data ['page'] = $pageinfo;
  3392. $this->data ['date'] = $date;
  3393. $this->data ['list'] = $list;
  3394. $this->data ['memu'] = "invoice";
  3395. $this->data ['staff'] = $this->staff;
  3396. $this->data ['receiptMemu'] = 'invoice';
  3397. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  3398. }
  3399. function invoiceReceivablesAchieve() {
  3400. Doo::loadModel ( 'invoiceReceivables' );
  3401. $invoiceReceivables = new invoiceReceivables ();
  3402. Doo::loadClass ( 'XDeode' );
  3403. $XDeode = new XDeode ( 5 );
  3404. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3405. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3406. $page_size = 12;
  3407. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3408. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3409. $get = "/" . $date;
  3410. $con = '';
  3411. if ($date == 'MONTHO')
  3412. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3413. elseif ($date == 'MONTHT')
  3414. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3415. elseif ($date == 'MONTHY')
  3416. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3417. if (! empty ( $MebSea )) {
  3418. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  3419. $get .= "/" . $MebSea;
  3420. }
  3421. $pageinfo ['page'] = array (
  3422. 'previous' => ''
  3423. );
  3424. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  3425. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  3426. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3427. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  3428. // print_r($pageinfo);
  3429. $this->data ['MebSeaEn'] = $MebSea;
  3430. $this->data ['MebSea'] = urlencode ( $MebSea );
  3431. $this->data ['get'] = $get;
  3432. $this->data ['page'] = $pageinfo;
  3433. $this->data ['list'] = $list;
  3434. $this->data ['date'] = $date;
  3435. $this->data ['memu'] = "invoice";
  3436. $this->data ['staff'] = $this->staff;
  3437. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3438. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  3439. }
  3440. /**
  3441. * 收款解绑
  3442. */
  3443. function invoiceUnBundLing() {
  3444. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  3445. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  3446. Doo::loadModel ( 'invoice' );
  3447. $invoice = new invoice ();
  3448. Doo::loadModel ( 'invoiceReceivables' );
  3449. $invoiceReceivables = new invoiceReceivables ();
  3450. Doo::loadModel ( 'invoiceOperationLog' );
  3451. $invoiceOperationLog = new invoiceOperationLog ();
  3452. Doo::loadModel ( 'invoiceROLog' );
  3453. $invoiceROLog = new invoiceROLog ();
  3454. Doo::loadModel ( 'invoiceStatistics' );
  3455. Doo::loadClass ( 'XDeode' );
  3456. $XDeode = new XDeode ( 5 );
  3457. if (empty ( $iidKey ) )
  3458. die ( 'illegal request' );
  3459. $iid = $XDeode->decode ( $iidKey );
  3460. $irid = $invoice->authcode ( $unBundKey );
  3461. if ((! empty ( $irid ) && ! is_numeric ( $irid ))|| (! empty ( $iid ) && ! is_numeric ( $iid )))
  3462. die ( 'illegal request' );
  3463. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3464. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  3465. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails['iid'] )&& empty ( $irDetails['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  3466. die ( 'illegal request' );
  3467. //收款
  3468. $item = array (
  3469. 'irid' => $irDetails ['irid'],
  3470. 'bindPrice'=>$irDetails['bindPrice']-$invoiceDetails['invoicePrice'],
  3471. 'bindStatus' => 0
  3472. );
  3473. if ($irDetails['iid']==$iid)
  3474. $item += array (
  3475. 'iid' => 0
  3476. );
  3477. else{
  3478. $iidExtend=explode(',', $irDetails['iidExtend']);
  3479. foreach ($iidExtend as $key=>$value){
  3480. if ($value==$iid)
  3481. unset($iidExtend[$key]);
  3482. }
  3483. $iidExtend=implode(',', $iidExtend);
  3484. $item += array (
  3485. 'iidExtend' => $iidExtend
  3486. );
  3487. }
  3488. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3489. // 收款操作日志
  3490. $item = array (
  3491. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  3492. 'date' => date ( "Y-m-d" ),
  3493. 'status' => 3,
  3494. 'img' => $this->staff [0] ['avatar'],
  3495. 'username' => $this->staff [0] ['username'],
  3496. 'uid' => $this->staff [0] ['sid'],
  3497. 'category' => $this->staff [0] ['category'],
  3498. 'irid' => $irid
  3499. );
  3500. $invoiceROLog->setInvoiceROLog ( $item );
  3501. // 扣除入账统计金额
  3502. $invoiceStatistics = new invoiceStatistics ();
  3503. $item = array (
  3504. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3505. 'priceClass' => 3,
  3506. 'cid' => $invoiceDetails ['cid'],
  3507. 'staff' => $invoiceDetails ['sid'],
  3508. 'accountPrice' => - $irDetails ['receivablesPrice']
  3509. );
  3510. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3511. // 扣除收款统计金额
  3512. $invoiceStatistics = new invoiceStatistics ();
  3513. $item = array (
  3514. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3515. 'priceClass' => 2,
  3516. 'cid' => $invoiceDetails ['cid'],
  3517. 'staff' => $invoiceDetails ['sid'],
  3518. 'irid' => $irDetails ['irid'],
  3519. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  3520. );
  3521. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3522. // 发票解绑去收款ID
  3523. $iridString = $invoiceDetails ['irid'];
  3524. if (! empty ( $invoiceDetails ['irid'] )) {
  3525. $list = explode ( ',', $invoiceDetails ['irid'] );
  3526. foreach ( $list as $key => $value ) {
  3527. if ($value == $irDetails ['irid']) {
  3528. unset ( $list [$key] );
  3529. break;
  3530. }
  3531. }
  3532. $iridString = implode ( ",", $list );
  3533. }
  3534. $item = array (
  3535. 'iid' => $invoiceDetails ['iid'],
  3536. 'irid' => $iridString,
  3537. 'updateTime' => date ( "Y-m-d H:i:s" )
  3538. );
  3539. if ($invoiceDetails ['untreadStatus'] == 3)
  3540. $item += array (
  3541. 'untreadStatus' => 0
  3542. );
  3543. $invoice->setInvoiceByCondition ( $item );
  3544. $item = array (
  3545. 'date' => date ( "Y-m-d H:i:s" ),
  3546. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  3547. 'status' => 11,
  3548. 'img' => $this->staff [0] ['avatar'],
  3549. 'username' => $this->staff [0] ['username'],
  3550. 'uid' => $this->staff [0] ['sid'],
  3551. 'category' => $this->staff [0] ['category'],
  3552. 'iid' => $invoiceDetails ['iid']
  3553. );
  3554. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3555. return "/invoiceReceivablesAS";
  3556. }
  3557. /**
  3558. * 或者该收款下的所以发票
  3559. */
  3560. function ajaxGetInvoiceReceivablesByInvoice() {
  3561. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  3562. Doo::loadModel ( 'invoice' );
  3563. $invoice = new invoice ();
  3564. Doo::loadModel ( 'invoiceReceivables' );
  3565. $invoiceReceivables = new invoiceReceivables ();
  3566. $irid = $invoice->authcode ( $irid );
  3567. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  3568. die ( 'illegal request' );
  3569. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3570. $iidString = $irDetails ['iid'];
  3571. $iidExtend=array_filter(explode(',', $irDetails ['iidExtend']));
  3572. if (! empty ( $irDetails ['iidExtend'] ))
  3573. $iidString .= ',' . implode(',', $iidExtend) ;
  3574. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  3575. $html = "";
  3576. foreach ( $invoiceList as $key => $value ) {
  3577. $title=$value['invoiceTitle'];
  3578. if (!empty($value['invoiceCompany']))
  3579. $title=$value['invoiceCompany'];
  3580. $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>';
  3581. }
  3582. echo json_encode ( array (
  3583. 'status' => 1,
  3584. 'html' => $html
  3585. ) );
  3586. }
  3587. /**
  3588. * 发票管理
  3589. */
  3590. function invoiceAS() {
  3591. Doo::loadModel ( 'invoice' );
  3592. $invoice = new invoice ();
  3593. Doo::loadModel ( 'invoiceReceivables' );
  3594. $invoiceReceivables = new invoiceReceivables ();
  3595. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3596. $page_size = 18;
  3597. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3598. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3599. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3600. $dateArr = explode ( ':', $date );
  3601. $D1 = '';
  3602. $D2 = '';
  3603. if (! empty ( $date )) {
  3604. $D1 = $dateArr [0] . " 00:00:00 ";
  3605. if (isset ( $dateArr [1] ))
  3606. $D2 = $dateArr [1] . " 23:59:59 ";
  3607. else
  3608. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3609. // $D2 = $dateArr [1];
  3610. }
  3611. $con = ' status=2 ';
  3612. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3613. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3614. if ($status == 'UNRECORD')
  3615. $con .= ' and printStatus=1 and untreadStatus=0';
  3616. elseif ($status == 'RECORD')
  3617. $con .= ' and printStatus=1 and untreadStatus=3';
  3618. elseif ($status == 'BOUNCED')
  3619. $con .= ' and untreadStatus=2';
  3620. elseif ($status == 'PARTRECORD')
  3621. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  3622. elseif ($status == 'All') {
  3623. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  3624. }
  3625. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3626. if (! empty ( $MebSea )) {
  3627. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  3628. }
  3629. $pageinfo ['page'] = array (
  3630. 'previous' => ''
  3631. );
  3632. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  3633. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3634. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  3635. // foreach ($list as $key=>$value){
  3636. // $list[$key]['rpSum']=0;
  3637. // if (!empty($value['irid']))
  3638. // $list[$key]['rpSum']=$invoiceReceivables->getSumOfReceivablesPrice($value['irid']);
  3639. // }
  3640. $this->data ['MebSeaEn'] = $MebSea;
  3641. $this->data ['MebSea'] = urlencode ( $MebSea );
  3642. $this->data ['date'] = $date;
  3643. $this->data ['page'] = $pageinfo;
  3644. $this->data ['get'] = $get;
  3645. $this->data ['list'] = $list;
  3646. $this->data ['status'] = $status;
  3647. $this->data ['memu'] = "invoice";
  3648. $this->data ['staff'] = $this->staff;
  3649. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3650. $this->render ( "/admin/invoiceAS", $this->data );
  3651. }
  3652. /**
  3653. * 收款管理
  3654. */
  3655. function invoiceReceivablesAS() {
  3656. Doo::loadModel ( 'invoiceReceivables' );
  3657. $invoiceReceivables = new invoiceReceivables ();
  3658. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3659. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  3660. $page_size = 10;
  3661. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3662. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3663. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3664. $dateArr = explode ( ':', $date );
  3665. $D1 = '';
  3666. $D2 = '';
  3667. if (! empty ( $date )) {
  3668. $D1 = $dateArr [0]; // ." 00:00:00 ";
  3669. if (isset ( $dateArr [1] ))
  3670. $D2 = $dateArr [1]; // ." 23:59:59 ";
  3671. else
  3672. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  3673. }
  3674. $descField = 'a.receivablesDate';
  3675. if ($timeType == 'CREATE')
  3676. $descField = 'a.date';
  3677. $con = '1';
  3678. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3679. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3680. // echo $con;
  3681. if ($status == 'Unclaimed')
  3682. $con .= ' and a.bindStatus=0';
  3683. elseif ($status == 'Credited')
  3684. $con .= ' and a.bindStatus=1';
  3685. elseif ($status == 'Claim')
  3686. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  3687. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3688. if (! empty ( $MebSea )) {
  3689. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  3690. }
  3691. $pageinfo ['page'] = array (
  3692. 'previous' => ''
  3693. );
  3694. $sql = 'select count(*) as count
  3695. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  3696. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  3697. where ' . $con . ' group by a.irid
  3698. ';
  3699. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  3700. // print_r($pageinfo);
  3701. // $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  3702. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3703. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  3704. // print_r($list);
  3705. $this->data ['timeType'] = $timeType;
  3706. $this->data ['MebSeaEn'] = $MebSea;
  3707. $this->data ['MebSea'] = urlencode ( $MebSea );
  3708. $this->data ['date'] = $date;
  3709. $this->data ['page'] = $pageinfo;
  3710. $this->data ['get'] = $get;
  3711. $this->data ['list'] = $list;
  3712. $this->data ['status'] = $status;
  3713. $this->data ['memu'] = "invoice";
  3714. $this->data ['staff'] = $this->staff;
  3715. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3716. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  3717. }
  3718. function invoiceApprovalAchieve() {
  3719. Doo::loadModel ( 'invoice' );
  3720. $invoice = new invoice ();
  3721. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3722. $page_size = 12;
  3723. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3724. $date = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  3725. $get = "/" . $date;
  3726. $con = '';
  3727. if ($date == 'ALL')
  3728. $con = ' and isDelete=0 and untreadStatus=0';
  3729. elseif ($date == 'PEND')
  3730. $con = ' and isDelete=0 and untreadStatus=0 ';
  3731. elseif ($date == 'APPROVED')
  3732. $con = ' and isDelete=0 and untreadStatus=0 ';
  3733. if (! empty ( $MebSea )) {
  3734. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3735. $get .= "/" . $MebSea;
  3736. }
  3737. $pageinfo ['page'] = array (
  3738. 'previous' => ''
  3739. );
  3740. $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  3741. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  3742. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3743. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  3744. // print_r($list);
  3745. $this->data ['MebSeaEn'] = $MebSea;
  3746. $this->data ['MebSea'] = urlencode ( $MebSea );
  3747. $this->data ['get'] = $get;
  3748. $this->data ['page'] = $pageinfo;
  3749. $this->data ['list'] = $list;
  3750. $this->data ['date'] = $date;
  3751. $this->data ['memu'] = "invoice";
  3752. $this->data ['staff'] = $this->staff;
  3753. $this->data ['receiptMemu'] = 'invoiceApproval';
  3754. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  3755. }
  3756. function invoiceTAchieve() {
  3757. Doo::loadModel ( 'invoice' );
  3758. $invoice = new invoice ();
  3759. Doo::loadClass ( 'XDeode' );
  3760. $XDeode = new XDeode ( 5 );
  3761. Doo::loadModel ( 'staff' );
  3762. $staff = new staff ();
  3763. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3764. $page_size = 12;
  3765. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3766. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3767. $get = "/" . $date;
  3768. $con = '';
  3769. if ($date == 'MONTHO')
  3770. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3771. elseif ($date == 'MONTHT')
  3772. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3773. elseif ($date == 'MONTHY')
  3774. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3775. if (! empty ( $MebSea )) {
  3776. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3777. $get .= "/" . $MebSea;
  3778. }
  3779. $pageinfo ['page'] = array (
  3780. 'previous' => ''
  3781. );
  3782. $sql = "";
  3783. $action = "";
  3784. if ($this->ACTION == 'invoicePrintAchieve') {
  3785. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  3786. $action = "invoicePrintAchieve";
  3787. } elseif ($this->ACTION == 'invoicePostAchieve') {
  3788. // and untreadStatus=0
  3789. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  3790. $action = "invoicePostAchieve";
  3791. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  3792. $sql = " untreadStatus=2 and status=2 " . $con;
  3793. $action = "invoiceUntreadAchieve";
  3794. }
  3795. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  3796. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3797. $this->data ['MebSeaEn'] = $MebSea;
  3798. $this->data ['MebSea'] = urlencode ( $MebSea );
  3799. $this->data ['get'] = $get;
  3800. $this->data ['page'] = $pageinfo;
  3801. $this->data ['date'] = $date;
  3802. $this->data ['memu'] = "invoice";
  3803. $this->data ['staff'] = $this->staff;
  3804. if ($this->ACTION == 'invoicePrintAchieve') {
  3805. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc',5 );
  3806. $this->data ['receiptMemu'] = 'invoicePrint';
  3807. $this->data ['list'] = $list;
  3808. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  3809. } elseif ($this->ACTION == 'invoicePostAchieve') {
  3810. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3811. Doo::loadModel ( 'express' );
  3812. $express = new express ();
  3813. $expressList = $express->getExpressByAll ();
  3814. $this->data ['expressList'] = $expressList;
  3815. $this->data ['receiptMemu'] = 'invoicePost';
  3816. $this->data ['list'] = $list;
  3817. $this->render ( "/admin/invoicePostAchieve", $this->data );
  3818. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  3819. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3820. $this->data ['receiptMemu'] = 'invoiceUntread';
  3821. $this->data ['list'] = $list;
  3822. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  3823. }
  3824. }
  3825. /**
  3826. *
  3827. * @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 ) ); }
  3828. */
  3829. /**
  3830. * 获取一条收款信息
  3831. */
  3832. function ajaxGetInvoiceReceivables() {
  3833. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3834. Doo::loadModel ( 'invoiceReceivables' );
  3835. $invoiceReceivables = new invoiceReceivables ();
  3836. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3837. echo json_encode ( array (
  3838. 'status' => 1,
  3839. 'detail' => $detail
  3840. ) );
  3841. }
  3842. /**
  3843. * 异步获取办事处用户
  3844. */
  3845. function ajaxGetStaffByCategory() {
  3846. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  3847. Doo::loadModel ( 'staff' );
  3848. $staff = new staff ();
  3849. if ($cid == "PUBLIC") {
  3850. echo json_encode ( array (
  3851. 'status' => 1,
  3852. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  3853. ) );
  3854. die ();
  3855. }
  3856. if (! is_numeric ( $cid )) {
  3857. echo json_encode ( array (
  3858. 'status' => 0,
  3859. 'msg' => 'illegal request'
  3860. ) );
  3861. die ();
  3862. }
  3863. $staffList = $staff->getStaffByCid ( $cid );
  3864. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  3865. foreach ( $staffList as $key => $value ) {
  3866. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  3867. }
  3868. echo json_encode ( array (
  3869. 'status' => 1,
  3870. 'html' => $html
  3871. ) );
  3872. }
  3873. /**
  3874. * 异步获取一条发票的邮寄信息
  3875. */
  3876. function ajaxGetInvoicePostDetail() {
  3877. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3878. Doo::loadModel ( 'invoice' );
  3879. $invoice = new invoice ();
  3880. $iid = $invoice->authcode ( $iid );
  3881. Doo::loadModel ( 'express' );
  3882. $express = new express ();
  3883. $expressList = $express->getExpressByAll ();
  3884. if (! is_numeric ( $iid )) {
  3885. echo json_encode ( array (
  3886. 'status' => 0,
  3887. 'msg' => 'illegal request'
  3888. ) );
  3889. die ();
  3890. }
  3891. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  3892. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  3893. $html = "";
  3894. foreach ( $expressList as $key => $value ) {
  3895. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  3896. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  3897. else
  3898. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  3899. }
  3900. $invoiceDetail ['eaHtml'] = $html;
  3901. echo json_encode ( array (
  3902. 'status' => 1,
  3903. 'invoiceDetail' => $invoiceDetail
  3904. ) );
  3905. }
  3906. /**
  3907. *
  3908. * @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 ) ); }
  3909. */
  3910. /**
  3911. *
  3912. * @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 ) ); }
  3913. */
  3914. /**
  3915. * 我的收款中 选择哪个发票入账,进行金额判断
  3916. */
  3917. function ajaxCompareInvoicePrice() {
  3918. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3919. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3920. Doo::loadModel ( 'invoice' );
  3921. $invoice = new invoice ();
  3922. Doo::loadModel ( 'invoiceReceivables' );
  3923. $invoiceReceivables = new invoiceReceivables ();
  3924. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3925. $keyList = explode ( ';', $claimKey );
  3926. $receivablesPrice = 0;
  3927. foreach ( $keyList as $key => $value ) {
  3928. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  3929. $receivablesPrice += $detailM ['receivablesPrice'];
  3930. }
  3931. if ($receivablesPrice > $detail ['invoicePrice']) {
  3932. $price = $receivablesPrice - $detail ['invoicePrice'];
  3933. echo json_encode ( array (
  3934. 'status' => 1,
  3935. 'price' => $price
  3936. ) );
  3937. } else
  3938. echo json_encode ( array (
  3939. 'status' => 2
  3940. ) );
  3941. }
  3942. /**
  3943. * 获得打印发票
  3944. */
  3945. function ajaxGetInvoiceInfoByPrint() {
  3946. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  3947. if (empty ( $serial )) {
  3948. echo json_encode ( array (
  3949. 'status' => 2,
  3950. 'msg' => 'illegal request'
  3951. ) );
  3952. die ();
  3953. }
  3954. Doo::loadModel ( 'invoice' );
  3955. $invoice = new invoice ();
  3956. Doo::loadModel ( 'invoiceOperationLog' );
  3957. $invoiceOperationLog = new invoiceOperationLog ();
  3958. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  3959. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  3960. if (empty ( $detail ))
  3961. $html = '';
  3962. else {
  3963. $html = '
  3964. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  3965. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  3966. <div class="modal-dialog modal-lg">
  3967. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  3968. <div class="modal-body saeaList">
  3969. <table class="table table-bordered table-condensed"><tbody>
  3970. <tr>
  3971. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  3972. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  3973. </tr>
  3974. <tr>
  3975. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  3976. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  3977. </tr>
  3978. <tr>
  3979. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  3980. </td>
  3981. </tr>
  3982. <tr>
  3983. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  3984. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  3985. </tr>
  3986. <tr>
  3987. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  3988. </tr></tbody></table>';
  3989. if ($detail ['invoiceType'] == 0)
  3990. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3991. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  3992. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  3993. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  3994. </tr>';
  3995. else
  3996. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3997. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  3998. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  3999. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4000. ';
  4001. $html .= '<tr>
  4002. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4003. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4004. </tr>
  4005. <tr>
  4006. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4007. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4008. </tr></tbody></table>';
  4009. if ($detail ['doPost'] == 1)
  4010. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4011. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4012. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4013. </tr><tr>
  4014. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4015. </tr><tr>
  4016. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4017. </tr></tbody></table>';
  4018. if (! empty ( $invoiceOperationLogList )) {
  4019. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  4020. foreach ( $invoiceOperationLogList as $key => $value ) {
  4021. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4022. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4023. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4024. if ($value ['status'] == 2) {
  4025. $html .= '<span class="colGreen">同意</span>';
  4026. } elseif ($value ['status'] == 3) {
  4027. $html .= '<span class="colOrange">退回</span>';
  4028. } elseif ($value ['status'] == 5) {
  4029. $html .= '<span class="colGreen">打印</span>';
  4030. } elseif ($value ['status'] == 4) {
  4031. $html .= '<span class="colRed">终止</span>';
  4032. }
  4033. $html .= $value ['operation'] . '</p></blockquote>';
  4034. }
  4035. }
  4036. $html .= '</td>
  4037. <td><span class="colRed">*</span>No.<input name="invoiceNo" id="invoiceNo" value="" type="text" placeholder="输入发票号" aria-required="true" aria-invalid="true" class="n-invalid">
  4038. <span class="red" id="p-msg"></span>
  4039. </td>
  4040. </tr></tbody></table>';
  4041. }
  4042. $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>
  4043. </div></div></form>
  4044. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  4045. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  4046. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  4047. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  4048. ';
  4049. }
  4050. echo json_encode ( array (
  4051. 'status' => 1,
  4052. 'html' => $html
  4053. ) );
  4054. die ();
  4055. }
  4056. /**
  4057. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  4058. */
  4059. function ajaxGetInvoiceInfoByType() {
  4060. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  4061. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4062. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  4063. if (empty ( $serial )) {
  4064. echo json_encode ( array (
  4065. 'status' => 2,
  4066. 'msg' => 'illegal request'
  4067. ) );
  4068. die ();
  4069. }
  4070. if ($type == 'INVOICE') {
  4071. Doo::loadModel ( 'invoice' );
  4072. $invoice = new invoice ();
  4073. Doo::loadModel ( 'invoiceOperationLog' );
  4074. $invoiceOperationLog = new invoiceOperationLog ();
  4075. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4076. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4077. if (empty ( $detail ))
  4078. $html = '';
  4079. else {
  4080. $html = '
  4081. <div class="modal-dialog modal-lg">
  4082. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  4083. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4084. <tr>
  4085. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4086. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4087. </tr>
  4088. <tr>
  4089. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4090. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4091. </tr>
  4092. <tr>
  4093. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4094. </td>
  4095. </tr>
  4096. <tr>
  4097. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4098. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4099. </tr>
  4100. <tr>
  4101. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4102. </tr></tbody></table>';
  4103. if ($detail ['invoiceType'] == 0)
  4104. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4105. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4106. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4107. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4108. </tr>';
  4109. else
  4110. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4111. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4112. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4113. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4114. ';
  4115. $html .= '<tr>
  4116. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4117. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4118. </tr>
  4119. <tr>
  4120. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4121. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4122. </tr></tbody></table>';
  4123. if ($detail ['doPost'] == 1) {
  4124. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4125. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4126. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4127. </tr><tr>
  4128. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4129. </tr><tr>
  4130. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4131. </tr>
  4132. ';
  4133. if ($detail ['expressCom'] == 'SF')
  4134. $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>';
  4135. else
  4136. $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>';
  4137. $html .= '</tbody></table>';
  4138. }
  4139. if (! empty ( $invoiceOperationLogList )) {
  4140. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4141. foreach ( $invoiceOperationLogList as $key => $value ) {
  4142. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4143. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4144. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4145. if ($value ['status'] == 2) {
  4146. $html .= '<span class="colGreen">同意</span>';
  4147. } elseif ($value ['status'] == 3) {
  4148. $html .= '<span class="colOrange">退回</span>';
  4149. } elseif ($value ['status'] == 5) {
  4150. $html .= '<span class="colGreen">打印</span>';
  4151. } elseif ($value ['status'] == 4) {
  4152. $html .= '<span class="colRed">终止</span>';
  4153. }
  4154. $html .= $value ['operation'] . '</p></blockquote>';
  4155. }
  4156. }
  4157. $html .= '</td></tr></tbody></table>';
  4158. }
  4159. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  4160. }
  4161. echo json_encode ( array (
  4162. 'status' => 1,
  4163. 'html' => $html
  4164. ) );
  4165. die ();
  4166. } elseif ($type == 'RECEIVABLES') {
  4167. Doo::loadModel ( 'invoiceReceivables' );
  4168. $invoiceReceivables = new invoiceReceivables ();
  4169. //
  4170. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  4171. if (empty ( $detail ))
  4172. $html = '';
  4173. else {
  4174. $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">
  4175. <tbody><tr>
  4176. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  4177. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  4178. </tr><tr>
  4179. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  4180. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  4181. </tr>
  4182. <tr>
  4183. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  4184. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  4185. </tr>
  4186. <tr>
  4187. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  4188. </tr>
  4189. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  4190. }
  4191. echo json_encode ( array (
  4192. 'status' => 1,
  4193. 'html' => $html
  4194. ) );
  4195. die ();
  4196. } elseif ($type == 'IRTC') {
  4197. Doo::loadModel ( 'invoice' );
  4198. $invoice = new invoice ();
  4199. Doo::loadModel ( 'invoiceOperationLog' );
  4200. $invoiceOperationLog = new invoiceOperationLog ();
  4201. Doo::loadModel ( 'invoiceReceivables' );
  4202. $invoiceReceivables = new invoiceReceivables ();
  4203. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4204. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4205. if (empty ( $detail ))
  4206. $html = '';
  4207. else {
  4208. $receivablesPriceedHtml = '';
  4209. $receivablesPrice = $detail ['invoicePrice'];
  4210. if (! empty ( $detail ['irid'] )) {
  4211. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  4212. if (empty ( $irList ))
  4213. $irList [0] ['sumPrice'] = 0;
  4214. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  4215. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  4216. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  4217. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  4218. </tr></tbody></table>';
  4219. $receivablesPrice = $balance;
  4220. }
  4221. if ($loss)
  4222. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  4223. $html = $receivablesPriceedHtml . '
  4224. <table class="table table-bordered table-condensed"><tbody>
  4225. <tr>
  4226. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4227. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4228. </tr>
  4229. <tr>
  4230. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4231. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4232. </tr>
  4233. <tr>
  4234. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  4235. </tr>
  4236. <tr>
  4237. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4238. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4239. </tr>
  4240. <tr>
  4241. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4242. </tr></tbody></table>';
  4243. if ($detail ['invoiceType'] == 0) {
  4244. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4245. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4246. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4247. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4248. </tr>';
  4249. $receivablesMessage = $detail ['invoiceTitle'];
  4250. } else {
  4251. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4252. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4253. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4254. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4255. ';
  4256. $receivablesMessage = $detail ['invoiceCompany'];
  4257. }
  4258. $html .= '<tr>
  4259. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4260. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4261. </tr>
  4262. <tr>
  4263. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  4264. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  4265. </tr></tbody></table>';
  4266. if ($detail ['doPost'] == 1)
  4267. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4268. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4269. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4270. </tr><tr>
  4271. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4272. </tr><tr>
  4273. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4274. </tr></tbody></table>';
  4275. if (! empty ( $invoiceOperationLogList )) {
  4276. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4277. foreach ( $invoiceOperationLogList as $key => $value ) {
  4278. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4279. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4280. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4281. if ($value ['status'] == 2) {
  4282. $html .= '<span class="colGreen">同意</span>';
  4283. } elseif ($value ['status'] == 3) {
  4284. $html .= '<span class="colOrange">退回</span>';
  4285. } elseif ($value ['status'] == 5) {
  4286. $html .= '<span class="colGreen">打印</span>';
  4287. }
  4288. $html .= $value ['operation'] . '</p></blockquote>';
  4289. }
  4290. }
  4291. $html .= '</td></tr></tbody></table>';
  4292. }
  4293. }
  4294. echo json_encode ( array (
  4295. 'status' => 1,
  4296. 'html' => $html,
  4297. 'receivablesPrice' => $receivablesPrice,
  4298. 'receivablesMessage' => $receivablesMessage,
  4299. 'receivablesDate' => date ( "Y-m-d" ),
  4300. 'iidKey' => $serial
  4301. ) );
  4302. die ();
  4303. }
  4304. }
  4305. function ajaxGetInvoiceReceivablesByStaff() {
  4306. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  4307. if (empty ( $postData )) {
  4308. echo json_encode ( array (
  4309. 'status' => 2,
  4310. 'msg' => 'illegal request'
  4311. ) );
  4312. die ();
  4313. }
  4314. Doo::loadModel ( 'invoiceReceivables' );
  4315. $invoiceReceivables = new invoiceReceivables ();
  4316. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  4317. if (empty ( $detail )) {
  4318. echo json_encode ( array (
  4319. 'status' => 2,
  4320. 'msg' => 'illegal request'
  4321. ) );
  4322. die ();
  4323. }
  4324. Doo::loadModel ( 'L_category' );
  4325. $lCategory = new L_category ();
  4326. Doo::loadModel ( 'staff' );
  4327. $staff = new staff ();
  4328. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  4329. $category = $lCategory->getCategory ();
  4330. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  4331. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  4332. foreach ( $category as $key => $value ) {
  4333. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  4334. if ($value ['cid'] == $detail ['cid'])
  4335. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  4336. }
  4337. foreach ( $staffList as $key => $value ) {
  4338. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  4339. if ($value ['sid'] == $detail ['sid'])
  4340. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  4341. }
  4342. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  4343. echo json_encode ( array (
  4344. 'status' => 1,
  4345. 'categoryHtml' => $categoryHtml,
  4346. 'staffHtml' => $staffHtml,
  4347. 'rbankHtml' => $rbankHtml,
  4348. 'detail' => $detail
  4349. ) );
  4350. }
  4351. function ajaxGetInvoiceReceivablesByIrid() {
  4352. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  4353. if (empty ( $irid )) {
  4354. echo json_encode ( array (
  4355. 'status' => 2,
  4356. 'msg' => 'illegal request'
  4357. ) );
  4358. die ();
  4359. }
  4360. Doo::loadModel ( 'invoiceReceivables' );
  4361. $invoiceReceivables = new invoiceReceivables ();
  4362. Doo::loadModel ( 'invoice' );
  4363. $invoice = new invoice ();
  4364. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  4365. $flag = true;
  4366. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  4367. $bakDetail = array ();
  4368. if ($flag === false) {
  4369. array_push ( $bakDetail, $invoiceDetail );
  4370. $invoiceDetail = $bakDetail;
  4371. }
  4372. $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>
  4373. <tr>
  4374. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  4375. <td>' . $detail ['receivablesMessage'] . '</td>
  4376. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  4377. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  4378. <td>' . $detail ['recepitTitleMark'] . '</td>
  4379. </tr></tbody></table>';
  4380. $isInvoice = false;
  4381. $invoiceHtml = '';
  4382. if (empty ( $invoiceDetail )) {
  4383. $isInvoice = true;
  4384. } else {
  4385. $invoiceHtml = '<table class="table table-bordered table-condensed">
  4386. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  4387. foreach ( $invoiceDetail as $key => $value ) {
  4388. $invoiceHtml .= '<tr>';
  4389. if (! empty ( $value ['invoiceType'] )) {
  4390. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  4391. } else {
  4392. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  4393. }
  4394. if (! empty ( $value ['invoiceType'] )) {
  4395. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  4396. } else {
  4397. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  4398. }
  4399. $invoiceHtml .= '
  4400. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  4401. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  4402. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  4403. </tr>
  4404. ';
  4405. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  4406. if (empty ( $irList ))
  4407. $irList [0] ['sumPrice'] = 0;
  4408. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  4409. $priceString = '';
  4410. if ($balance < $detail ['receivablesPrice']) {
  4411. $priceString = '收款金额超过开票金额,';
  4412. }
  4413. if ($balance > $detail ['receivablesPrice']) {
  4414. $priceString = '收款金额低于开票金额,';
  4415. }
  4416. }
  4417. $invoiceHtml .= '
  4418. <script>
  4419. $(\'a[bind-receivables^="ir"]\').click(function() {
  4420. var data = $(this).attr("data-ikey");
  4421. $("input[name=\'invoiceKey\']").val(data);
  4422. var invoiceKey=data;
  4423. if(invoiceKey==""){
  4424. alert("入账错误,请重新刷新页面");
  4425. return false;
  4426. }
  4427. if(window.confirm("' . $priceString . '确定入账吗?")){
  4428. $("#IBR").submit();
  4429. }else{
  4430. return false;
  4431. }
  4432. });
  4433. </script>
  4434. ';
  4435. $invoiceHtml .= '</tbody></table>';
  4436. }
  4437. echo json_encode ( array (
  4438. 'status' => 1,
  4439. 'irkey' => $detail ['iridEn'],
  4440. 'receivablesHtml' => $receivablesHtml,
  4441. 'isInvoice' => $isInvoice,
  4442. 'invoiceHtml' => $invoiceHtml
  4443. ) );
  4444. }
  4445. function ajaxGetInvoiceReceivablesByTitle() {
  4446. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  4447. if (empty ( $title )) {
  4448. echo json_encode ( array (
  4449. 'status' => 2,
  4450. 'msg' => 'illegal request'
  4451. ) );
  4452. die ();
  4453. }
  4454. Doo::loadModel ( 'invoice' );
  4455. $invoice = new invoice ();
  4456. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ",true );
  4457. $invoiceHtml = '';
  4458. if (! empty ( $invoiceDetail )) {
  4459. $invoiceHtml = '<table class="table table-bordered table-condensed">
  4460. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  4461. foreach ($invoiceDetail as $key=>$value){
  4462. if (! empty ( $value ['invoiceType'] )) {
  4463. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  4464. } else {
  4465. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  4466. }
  4467. if (! empty ( $value ['invoiceType'] )) {
  4468. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  4469. } else {
  4470. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  4471. }
  4472. $invoiceHtml .= '
  4473. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  4474. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  4475. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  4476. </tr>
  4477. ';
  4478. }
  4479. $invoiceHtml .= '</tbody></table>
  4480. <script>
  4481. $(\'a[bind-receivables^="ir"]\').click(function() {
  4482. var data = $(this).attr("data-ikey");
  4483. $("input[name=\'invoiceKey\']").val(data);
  4484. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  4485. if(invoiceKey==""){
  4486. alert("入账错误,请重新刷新页面");
  4487. return false;
  4488. }
  4489. if(window.confirm("确定入账吗?")){
  4490. $("#IBR").submit();
  4491. }else{
  4492. return false;
  4493. }
  4494. });
  4495. </script>
  4496. ';
  4497. }
  4498. echo json_encode ( array (
  4499. 'status' => 1,
  4500. 'invoiceHtml' => $invoiceHtml
  4501. ) );
  4502. }
  4503. function ajaxInvoicePushNotice() {
  4504. Doo::loadModel ( 'invoice' );
  4505. $invoice = new invoice ();
  4506. $approval = $invoice->getOne ( array (
  4507. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  4508. 'desc' => 'iid',
  4509. 'asArray' => true
  4510. ) );
  4511. $isNotice = false;
  4512. if (! empty ( $approval ))
  4513. $isNotice = true;
  4514. $response = array (
  4515. 'error' => 0,
  4516. 'isNotice' => $isNotice
  4517. );
  4518. echo json_encode ( $response );
  4519. exit ();
  4520. }
  4521. public function ajaxCheckInvoiceNoUniqueness() {
  4522. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  4523. Doo::loadModel ( 'invoice' );
  4524. $invoice = new invoice ();
  4525. if (! empty ( $invoiceNo )) {
  4526. $info = $invoice->getOne ( array (
  4527. 'where' => "invoiceNo = '" . $invoiceNo . "'",
  4528. 'asArray' => TRUE
  4529. ) );
  4530. if (! empty ( $info )) {
  4531. echo json_encode ( array (
  4532. 'error' => '发票号已存在'
  4533. ) );
  4534. die ();
  4535. } else
  4536. echo json_encode ( array (
  4537. 'ok' => '可以使用!'
  4538. ) );
  4539. die ();
  4540. }
  4541. }
  4542. function ajaxCheckInvoicePrice() {
  4543. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  4544. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  4545. Doo::loadModel ( 'invoice' );
  4546. $invoice = new invoice ();
  4547. Doo::loadModel ( 'invoiceReceivables' );
  4548. $invoiceReceivables = new invoiceReceivables ();
  4549. Doo::loadClass ( 'XDeode' );
  4550. $XDeode = new XDeode ( 5 );
  4551. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  4552. $iidKey = $XDeode->decode ( $iidKey );
  4553. $info = $invoice->getInvoiceByIid ( $iidKey );
  4554. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  4555. if (empty ( $irList ))
  4556. $irList [0] ['sumPrice'] = 0;
  4557. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  4558. if ($balance < $receivablesPrice) {
  4559. echo json_encode ( array (
  4560. 'error' => '收款金额超过开票金额。'
  4561. ) );
  4562. die ();
  4563. }
  4564. if ($balance > $receivablesPrice) {
  4565. echo json_encode ( array (
  4566. 'error' => '收款金额低于开票金额。'
  4567. ) );
  4568. die ();
  4569. }
  4570. }
  4571. }
  4572. /**
  4573. * 旧输入导入
  4574. */
  4575. function importInvoice() {
  4576. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  4577. $data ['emsg'] = "";
  4578. if ($emsg != "")
  4579. $data ['emsg'] = "请填写完整的数据";
  4580. $data ['time'] = time ();
  4581. $this->render ( "/admin/invoiceImport", $data );
  4582. }
  4583. function uploadInvoice() {
  4584. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  4585. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  4586. $file = $_FILES ['Filedata'] ['tmp_name'];
  4587. $error = false;
  4588. if (! is_uploaded_file ( $file )) {
  4589. $error = '400 Bad Request';
  4590. }
  4591. if ($error) {
  4592. header ( 'HTTP/1.0 ' . $error );
  4593. die ( 'Error ' . $error );
  4594. } else {
  4595. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  4596. $this->IoHandler = new IoHandler ();
  4597. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  4598. // $filedir=$_POST['time'];
  4599. // 调用定义物理路径
  4600. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  4601. $this->IoHandler->MakeDir ( $t );
  4602. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  4603. if ($filename != 'xlsx')
  4604. return "";
  4605. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  4606. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  4607. $upload_dir = $t . "/" . $upload_file;
  4608. $k = move_uploaded_file ( $file, $upload_dir );
  4609. if ($k) {
  4610. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  4611. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  4612. }
  4613. }
  4614. }
  4615. }
  4616. function importInvoiceDo() {
  4617. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  4618. if ($path != "") {
  4619. Doo::loadModel ( 'invoice' );
  4620. Doo::loadModel ( 'staff' );
  4621. $staff = new staff ();
  4622. Doo::loadModel ( 'invoiceStatistics' );
  4623. Doo::loadModel ( 'invoiceOperationLog' );
  4624. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  4625. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  4626. // print_r ( $exlArray );
  4627. // die ();
  4628. // echo json_encode($exlArray);die;
  4629. foreach ( $exlArray as $key => $value ) {
  4630. // 开票
  4631. $invoice = new invoice ();
  4632. $invoice->invoiceNo = $value ['invoiceNo'];
  4633. $invoice->invoiceType = 0;
  4634. if ($value ['invoiceType'] == '专')
  4635. $invoice->invoiceType = 1;
  4636. $invoice->invoicePrice = $value ['invoicePrice'];
  4637. $invoice->invoiceQuantity = 1;
  4638. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  4639. $invoice->invoiceTitle = $value ['invoiceTitle'];
  4640. if ($value ['invoiceType'] == '专')
  4641. $invoice->invoiceCompany = $value ['invoiceTitle'];
  4642. $invoice->userName = $value ['userName'];
  4643. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  4644. $invoice->sid = $sDetail ['sid'];
  4645. $invoice->cid = $sDetail ['cid'];
  4646. $invoice->categoryName = $sDetail ['category'];
  4647. $invoice->invoiceElement = $value ['invoiceElement'];
  4648. $invoice->remark = $value ['remark'];
  4649. $invoice->date = $value ['date'];
  4650. $invoice->printTime = $value ['date'];
  4651. $invoice->ipSource = 1;
  4652. $invoice->printStatus = 1;
  4653. $invoice->status = 2;
  4654. $invoice->postStatus = 1;
  4655. $invoice->untreadStatus = 0;
  4656. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  4657. $iid = $invoice->insert ();
  4658. // 汇总
  4659. $invoiceStatistics = new invoiceStatistics ();
  4660. //
  4661. $item = array (
  4662. 'date' => $value ['date'],
  4663. 'priceClass' => 1,
  4664. 'cid' => $sDetail ['cid'],
  4665. 'staff' => $sDetail ['sid'],
  4666. 'invoicePrice' => $value ['invoicePrice']
  4667. );
  4668. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4669. $invoiceOperationLog = new invoiceOperationLog ();
  4670. $item = array (
  4671. 'date' => date ( "Y-m-d H:i:s" ),
  4672. 'operation' => date ( "Y-m-d" ) . " 导入",
  4673. 'status' => 1,
  4674. 'img' => $sDetail ['avatar'],
  4675. 'username' => $sDetail ['username'],
  4676. 'uid' => $sDetail ['sid'],
  4677. 'category' => $sDetail ['category'],
  4678. 'iid' => $iid
  4679. );
  4680. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4681. }
  4682. return '/importInvoice?count=' . count ( $exlArray );
  4683. // return "/keyonline";
  4684. }
  4685. echo 'no file';
  4686. }
  4687. function importInvoiceReceivables() {
  4688. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  4689. $data ['emsg'] = "";
  4690. if ($emsg != "")
  4691. $data ['emsg'] = "请填写完整的数据";
  4692. $data ['time'] = time ();
  4693. $this->render ( "/admin/invoiceReceivablesImport", $data );
  4694. }
  4695. // 导入入账数据
  4696. function importInvoiceReceivablesDo() {
  4697. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  4698. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4699. if ($path != "") {
  4700. Doo::loadModel ( 'invoiceReceivables' );
  4701. Doo::loadModel ( 'invoice' );
  4702. Doo::loadModel ( 'staff' );
  4703. $staff = new staff ();
  4704. Doo::loadModel ( 'invoiceStatistics' );
  4705. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  4706. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  4707. // print_r ( $exlArray );
  4708. // die ();
  4709. // echo json_encode($exlArray);die;
  4710. foreach ( $exlArray as $key => $value ) {
  4711. // 收款
  4712. $invoiceReceivables = new invoiceReceivables ();
  4713. $invoice = new invoice ();
  4714. $invoiceReceivables->bindStatus = 1;
  4715. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  4716. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  4717. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  4718. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  4719. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  4720. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  4721. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  4722. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  4723. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  4724. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  4725. $invoiceReceivables->iid = $iDetail ['iid'];
  4726. $irid = $invoiceReceivables->insert ();
  4727. // 发票绑定收款
  4728. $detail = $iDetail;
  4729. $iridString = "";
  4730. if (empty ( $detail ['irid'] ))
  4731. $iridString = $irid;
  4732. else
  4733. $iridString = $detail ['irid'] . ',' . $irid;
  4734. $item = array (
  4735. 'irid' => $iridString,
  4736. 'iid' => $detail ['iid']
  4737. );
  4738. $invoice->setInvoiceByCondition ( $item );
  4739. // 汇总
  4740. $invoiceStatistics = new invoiceStatistics ();
  4741. // 扣除入账统计金额
  4742. $item = array (
  4743. 'date' => $value ['receivablesDate'],
  4744. 'priceClass' => 3,
  4745. 'cid' => $sDetail ['cid'],
  4746. 'staff' => $sDetail ['sid'],
  4747. // 'irid' => $irid,
  4748. 'accountPrice' => $value ['receivablesPrice']
  4749. );
  4750. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4751. }
  4752. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  4753. echo 'data count ' . count ( $exlArray );
  4754. die ();
  4755. // return "/keyonline";
  4756. }
  4757. echo 'no file';
  4758. }
  4759. function formatExcelToArrayTrain($file_url = ""){
  4760. if (! file_exists ( $file_url )) {
  4761. return array ();
  4762. }
  4763. //Doo::loadClass ( 'PHPExcel' );
  4764. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  4765. $PHPExcel = new PHPExcel ();
  4766. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  4767. if (! $PHPReader->canRead ( $file_url )) {
  4768. $PHPReader = new PHPExcel_Reader_Excel5 ();
  4769. if (! $PHPReader->canRead ( $file_url )) {
  4770. echo 'no Excel';
  4771. return;
  4772. }
  4773. }
  4774. $PHPExcel = $PHPReader->load ( $file_url );
  4775. /* * 读取excel文件中的第一个工作表 */
  4776. $currentSheet = $PHPExcel->getSheet ( 0 );
  4777. /* * 取得最大的列号 */
  4778. $allColumn = $currentSheet->getHighestColumn ();
  4779. /* * 取得一共有多少行 */
  4780. $allRow = $currentSheet->getHighestRow ();
  4781. $excel_array = array ();
  4782. //die($file_url);
  4783. $conk = 2;
  4784. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  4785. $excel_column = array ();
  4786. // 后期改进
  4787. if ($allColumn == 'AM')
  4788. $allColumn = 'Z';
  4789. /* * 从第A列开始输出 */
  4790. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  4791. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  4792. if ($val instanceof PHPExcel_RichText)
  4793. $val = $val->__toString ();
  4794. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  4795. // $val = "'" . addslashes ( $val ) . "'";
  4796. if ($currentColumn == 'A'){
  4797. $excel_column ['invoiceTitle'] = $val;
  4798. }elseif ($currentColumn == 'B')
  4799. $excel_column ['invoiceType'] = $val;
  4800. elseif ($currentColumn == 'C') {
  4801. $excel_column ['TIN'] = $val;
  4802. } elseif ($currentColumn == 'D') {
  4803. $excel_column ['address'] = $val;
  4804. } elseif ($currentColumn == 'E') {
  4805. $excel_column ['phone'] = $val;
  4806. } elseif ($currentColumn == 'F') {
  4807. $excel_column ['bank'] = $val;
  4808. } elseif ($currentColumn == 'G') {
  4809. $excel_column ['bankAccount'] = $val;
  4810. } elseif ($currentColumn == 'H') {
  4811. $excel_column ['invoiceElement'] = $val;
  4812. } elseif ($currentColumn == 'I') {
  4813. $excel_column ['invoiceQuantity'] = $val;
  4814. } elseif ($currentColumn == 'J') {
  4815. $excel_column ['invoiceUnitPrice'] = $val;
  4816. } elseif ($currentColumn == 'K') {
  4817. $excel_column ['remark'] = $val;
  4818. } elseif ($currentColumn == 'L') {
  4819. $excel_column ['recipientsAddress'] = $val;
  4820. } elseif ($currentColumn == 'M') {
  4821. $excel_column ['recipients'] = $val;
  4822. } elseif ($currentColumn == 'N') {
  4823. $excel_column ['recipientsPhone'] = $val;
  4824. }
  4825. }
  4826. if (!empty($excel_column ['invoiceTitle'])&&!empty($excel_column ['invoiceQuantity'])&&!empty($excel_column ['invoiceUnitPrice']))
  4827. array_push ( $excel_array, $excel_column );
  4828. }
  4829. return $excel_array;
  4830. }
  4831. /**
  4832. * 格式化excel文件为数组
  4833. * @param unknown_type $file_url
  4834. * @param unknown_type $mcid
  4835. */
  4836. function _format_excel_to_array($file_url = "", $sType = "") {
  4837. if (! file_exists ( $file_url )) {
  4838. return array ();
  4839. }
  4840. Doo::loadClass ( 'PHPExcel' );
  4841. //Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  4842. $PHPExcel = new PHPExcel ();
  4843. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  4844. if (! $PHPReader->canRead ( $file_url )) {
  4845. $PHPReader = new PHPExcel_Reader_Excel5 ();
  4846. if (! $PHPReader->canRead ( $file_url )) {
  4847. echo 'no Excel';
  4848. return;
  4849. }
  4850. }
  4851. $PHPExcel = $PHPReader->load ( $file_url );
  4852. /* * 读取excel文件中的第一个工作表 */
  4853. $currentSheet = $PHPExcel->getSheet ( 0 );
  4854. /* * 取得最大的列号 */
  4855. $allColumn = $currentSheet->getHighestColumn ();
  4856. /* * 取得一共有多少行 */
  4857. $allRow = $currentSheet->getHighestRow ();
  4858. $excel_array = array ();
  4859. //die($file_url);
  4860. $conk = 2;
  4861. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  4862. $excel_column = array ();
  4863. // 后期改进
  4864. if ($allColumn == 'AM')
  4865. $allColumn = 'Z';
  4866. /* * 从第A列开始输出 */
  4867. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  4868. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  4869. if ($val instanceof PHPExcel_RichText)
  4870. $val = $val->__toString ();
  4871. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  4872. // $val = "'" . addslashes ( $val ) . "'";
  4873. if ($sType == 'invoiceReceivables') {
  4874. if ($currentColumn == 'A')
  4875. $excel_column ['invoiceNo'] = $val;
  4876. elseif ($currentColumn == 'B')
  4877. $excel_column ['receivablesPrice'] = $val;
  4878. elseif ($currentColumn == 'C') {
  4879. $excel_column ['receivablesMessage'] = $val;
  4880. } elseif ($currentColumn == 'D') {
  4881. $excel_column ['receivablesBank'] = $val;
  4882. } elseif ($currentColumn == 'E') {
  4883. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  4884. } elseif ($currentColumn == 'F') {
  4885. $excel_column ['receivablesStaff'] = $val;
  4886. } elseif ($currentColumn == 'G') {
  4887. $excel_column ['sourcePrice'] = $val;
  4888. }
  4889. } elseif ($sType == "invoiceTrain") {
  4890. if ($currentColumn == 'A'){
  4891. $excel_column ['invoiceTitle'] = $val;
  4892. }elseif ($currentColumn == 'B')
  4893. $excel_column ['invoiceType'] = $val;
  4894. elseif ($currentColumn == 'C') {
  4895. $excel_column ['TIN'] = $val;
  4896. } elseif ($currentColumn == 'D') {
  4897. $excel_column ['address'] = $val;
  4898. } elseif ($currentColumn == 'E') {
  4899. $excel_column ['phone'] = $val;
  4900. } elseif ($currentColumn == 'F') {
  4901. $excel_column ['bank'] = $val;
  4902. } elseif ($currentColumn == 'G') {
  4903. $excel_column ['bankAccount'] = $val;
  4904. } elseif ($currentColumn == 'H') {
  4905. $excel_column ['invoiceElement'] = $val;
  4906. } elseif ($currentColumn == 'I') {
  4907. $excel_column ['invoiceQuantity'] = $val;
  4908. } elseif ($currentColumn == 'J') {
  4909. $excel_column ['invoiceUnitPrice'] = $val;
  4910. } elseif ($currentColumn == 'K') {
  4911. $excel_column ['remark'] = $val;
  4912. } elseif ($currentColumn == 'L') {
  4913. $excel_column ['recipientsAddress'] = $val;
  4914. } elseif ($currentColumn == 'M') {
  4915. $excel_column ['recipients'] = $val;
  4916. } elseif ($currentColumn == 'N') {
  4917. $excel_column ['recipientsPhone'] = $val;
  4918. }
  4919. } else {
  4920. if ($currentColumn == 'A')
  4921. $excel_column ['invoiceNo'] = $val;
  4922. elseif ($currentColumn == 'B')
  4923. $excel_column ['invoiceType'] = $val;
  4924. elseif ($currentColumn == 'C') {
  4925. $excel_column ['invoicePrice'] = $val;
  4926. } elseif ($currentColumn == 'D') {
  4927. $excel_column ['invoiceTitle'] = $val;
  4928. } elseif ($currentColumn == 'E') {
  4929. $excel_column ['userName'] = $val;
  4930. } elseif ($currentColumn == 'F') {
  4931. $excel_column ['categoryName'] = $val;
  4932. } elseif ($currentColumn == 'G') {
  4933. $excel_column ['invoiceElement'] = $val;
  4934. } elseif ($currentColumn == 'H') {
  4935. $excel_column ['remark'] = $val;
  4936. } elseif ($currentColumn == 'I') {
  4937. $excel_column ['date'] = $this->excelTime ( $val );
  4938. }
  4939. }
  4940. }
  4941. array_push ( $excel_array, $excel_column );
  4942. }
  4943. return $excel_array;
  4944. }
  4945. function excelTime($date, $time = false) {
  4946. if (function_exists ( 'GregorianToJD' )) {
  4947. if (is_numeric ( $date )) {
  4948. $jd = GregorianToJD ( 1, 1, 1970 );
  4949. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  4950. $date = explode ( '/', $gregorian );
  4951. $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" : '');
  4952. return $date_str;
  4953. }
  4954. } else {
  4955. $date = $date > 25568 ? $date + 1 : 25569;
  4956. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  4957. $ofs = (70 * 365 + 17 + 2) * 86400;
  4958. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  4959. }
  4960. return $date;
  4961. }
  4962. /**
  4963. * 旧输入导入
  4964. */
  4965. function _GetFileEXT($filename) {
  4966. $pics = explode ( '.', $filename );
  4967. $num = count ( $pics );
  4968. return $pics [$num - 1];
  4969. }
  4970. function showCache($path = "") {
  4971. // if (file_exists ( $path )) {
  4972. // $htm = file_get_contents ( $path );
  4973. // } else {
  4974. Doo::loadModel ( 'invoiceStatistics' );
  4975. $invoiceStatistics = new invoiceStatistics ();
  4976. $isBriefly = $invoiceStatistics->getBrieflyStatistics ();
  4977. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  4978. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  4979. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  4980. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  4981. /*
  4982. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  4983. */
  4984. file_put_contents ( $path, $htm, FILE_APPEND );
  4985. // }
  4986. return $htm;
  4987. }
  4988. /**
  4989. * 获取get或者POST值
  4990. *
  4991. * @param string $name 属性名称
  4992. * @return fixed 值
  4993. */
  4994. function get_args($name) {
  4995. if (isset ( $_GET [$name] )) {
  4996. if (is_array ( $_GET [$name] ))
  4997. return $_GET [$name];
  4998. else
  4999. return addslashes ( $_GET [$name] );
  5000. } elseif (isset ( $_POST [$name] )) {
  5001. if (is_array ( $_POST [$name] ))
  5002. return $_POST [$name];
  5003. else
  5004. return addslashes ( $_POST [$name] );
  5005. } else
  5006. return false;
  5007. }
  5008. function SafeFilter(&$arr) {
  5009. $ra = Array (
  5010. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  5011. '/script/',
  5012. '/javascript/',
  5013. '/vbscript/',
  5014. '/expression/',
  5015. '/applet/',
  5016. '/meta/',
  5017. '/xml/',
  5018. '/blink/',
  5019. '/link/',
  5020. '/style/',
  5021. '/embed/',
  5022. '/object/',
  5023. '/frame/',
  5024. '/layer/',
  5025. '/title/',
  5026. '/bgsound/',
  5027. '/base/',
  5028. '/onload/',
  5029. '/onunload/',
  5030. '/onchange/',
  5031. '/onsubmit/',
  5032. '/onreset/',
  5033. '/onselect/',
  5034. '/onblur/',
  5035. '/onfocus/',
  5036. '/onabort/',
  5037. '/onkeydown/',
  5038. '/onkeypress/',
  5039. '/onkeyup/',
  5040. '/onclick/',
  5041. '/ondblclick/',
  5042. '/onmousedown/',
  5043. '/onmousemove/',
  5044. '/onmouseout/',
  5045. '/onmouseover/',
  5046. '/onmouseup/',
  5047. '/onunload/'
  5048. );
  5049. if (is_array ( $arr )) {
  5050. foreach ( $arr as $key => $value ) {
  5051. if (! is_array ( $value )) {
  5052. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  5053. {
  5054. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  5055. }
  5056. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  5057. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  5058. } else {
  5059. SafeFilter ( $arr [$key] );
  5060. }
  5061. }
  5062. }
  5063. }
  5064. /**
  5065. * Escape String
  5066. *
  5067. * @access public
  5068. * @param string
  5069. * @param bool whether or not the string will be used in a LIKE condition
  5070. * @return string
  5071. */
  5072. function escape_str($str, $like = FALSE) {
  5073. if (is_array ( $str )) {
  5074. foreach ( $str as $key => $val ) {
  5075. $str [$key] = $this->escape_str ( $val, $like );
  5076. }
  5077. return $str;
  5078. }
  5079. var_dump ( Doo::db ()->getDbObject () );
  5080. die ();
  5081. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  5082. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  5083. } elseif (function_exists ( 'mysql_escape_string' )) {
  5084. $str = mysql_escape_string ( $str );
  5085. } else {
  5086. $str = addslashes ( $str );
  5087. }
  5088. // escape LIKE condition wildcards
  5089. if ($like === TRUE) {
  5090. $str = str_replace ( array (
  5091. '%',
  5092. '_'
  5093. ), array (
  5094. '\\%',
  5095. '\\_'
  5096. ), $str );
  5097. }
  5098. return $str;
  5099. }
  5100. /**
  5101. * 获得分页数据
  5102. * @param unknown_type $table
  5103. * @param unknown_type $condition
  5104. * @param unknown_type $on_page
  5105. * @param unknown_type $page_size
  5106. */
  5107. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  5108. $page_c = "";
  5109. $page ['previous'] = $this->get_previous ( $on_page );
  5110. $page ['on_page'] = $on_page;
  5111. $total_count = $this->get_table_count ( $table, $condition );
  5112. $total = intval ( $total_count / $page_size );
  5113. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  5114. $page ['total_data'] = $total_count;
  5115. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  5116. $i = 1;
  5117. $page_max = 1;
  5118. $page_width = 3;
  5119. if ($on_page >= $page_width) {
  5120. $page_max = intval ( $on_page / $page_width ) + 1;
  5121. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  5122. }
  5123. for(; $i <= $page ['total_page']; $i ++) {
  5124. if ($i == $on_page)
  5125. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  5126. else
  5127. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  5128. if ($i == ($page_width * $page_max))
  5129. break;
  5130. }
  5131. $page ['page'] = $page_c;
  5132. $page ['lower'] = (-- $on_page) * $page_size;
  5133. return $page;
  5134. }
  5135. /**
  5136. * 获取上一页
  5137. * @param unknown_type $on_page
  5138. */
  5139. function get_previous($on_page = 1) {
  5140. return $on_page != 0 ? $on_page - 1 : $on_page;
  5141. }
  5142. /**
  5143. * 获取总页数
  5144. * @param unknown_type $table
  5145. * @param unknown_type $condition
  5146. */
  5147. public function get_table_count($table = "", $condition = "") {
  5148. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  5149. $sql = "select count(*) as count from " . $table . " where " . $condition;
  5150. // echo $sql;die;
  5151. $query = Doo::db ()->query ( $sql );
  5152. $result = $query->fetch ();
  5153. return $result ['count'];
  5154. }
  5155. /**
  5156. * 获得分页数据
  5157. * @param unknown_type $table
  5158. * @param unknown_type $condition
  5159. * @param unknown_type $on_page
  5160. * @param unknown_type $page_size
  5161. */
  5162. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  5163. $page_c = "";
  5164. $page ['previous'] = $this->get_previous ( $on_page );
  5165. $page ['on_page'] = $on_page;
  5166. $total_count = $this->getTableCountBySql ( $sql );
  5167. $total = intval ( $total_count / $page_size );
  5168. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  5169. $page ['total_data'] = $total_count;
  5170. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  5171. $i = 1;
  5172. $page_max = 1;
  5173. $page_width = 3;
  5174. if ($on_page >= $page_width) {
  5175. $page_max = intval ( $on_page / $page_width ) + 1;
  5176. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  5177. }
  5178. for(; $i <= $page ['total_page']; $i ++) {
  5179. if ($i == $on_page)
  5180. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  5181. else
  5182. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  5183. if ($i == ($page_width * $page_max))
  5184. break;
  5185. }
  5186. $page ['page'] = $page_c;
  5187. $page ['lower'] = (-- $on_page) * $page_size;
  5188. return $page;
  5189. }
  5190. /**
  5191. * 获得总页数 sql
  5192. * @param string $type
  5193. * @return boolean[]
  5194. */
  5195. public function getTableCountBySql($sql = "") {
  5196. $query = Doo::db ()->query ( $sql );
  5197. $result = $query->fetch ();
  5198. return $result ['count'];
  5199. }
  5200. function isInvoiceNew($type = "GLOBAL") {
  5201. Doo::loadModel ( 'invoice' );
  5202. $invoice = new invoice ();
  5203. Doo::loadModel ( 'invoiceReceivables' );
  5204. $invoiceReceivables = new invoiceReceivables ();
  5205. Doo::loadModel ( 'staff' );
  5206. $staff = new staff ();
  5207. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  5208. // 我的发票待处理
  5209. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  5210. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  5211. 'desc' => 'iid',
  5212. 'asArray' => TRUE
  5213. ) );
  5214. // 我的收款待入账
  5215. /*
  5216. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  5217. */
  5218. // 发票审批
  5219. $approval = $invoice->getOne ( array (
  5220. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  5221. 'desc' => 'iid',
  5222. 'asArray' => true
  5223. ) );
  5224. // 发票邮寄
  5225. $post = $invoice->getOne ( array (
  5226. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  5227. 'asArray' => TRUE
  5228. ) );
  5229. // 发票打印
  5230. $print = $invoice->getOne ( array (
  5231. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  5232. 'desc' => 'iid',
  5233. 'asArray' => TRUE
  5234. ) );
  5235. // 发票退票 printStatus=1 and
  5236. $untread = $invoice->getOne ( array (
  5237. 'where' => " untreadStatus=1 and status=2 ",
  5238. 'asArray' => TRUE
  5239. ) );
  5240. $new = array (
  5241. 'GLOBAL' => FALSE,
  5242. 'pendingInvoice' => FALSE,
  5243. // 'myClaim' => FALSE,
  5244. 'approval' => FALSE,
  5245. 'post' => FALSE,
  5246. 'print' => FALSE,
  5247. 'untread' => FALSE
  5248. );
  5249. // || ! empty ( $myClaim )
  5250. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  5251. $new ['GLOBAL'] = TRUE;
  5252. if (! empty ( $pendingInvoice ))
  5253. $new ['pendingInvoice'] = TRUE;
  5254. // if (! empty ( $myClaim ))
  5255. // $new ['myClaim'] = TRUE;
  5256. if (! empty ( $approval ))
  5257. $new ['approval'] = TRUE;
  5258. if (! empty ( $post ))
  5259. $new ['post'] = TRUE;
  5260. if (! empty ( $print ))
  5261. $new ['print'] = TRUE;
  5262. if (! empty ( $untread ))
  5263. $new ['untread'] = TRUE;
  5264. return $new;
  5265. }
  5266. function setWXMsg($rid, $typeMsg = '') {
  5267. Doo::loadModel ( 'invoice' );
  5268. $invoice = new invoice ();
  5269. $invoiceDetail = $invoice->getOne ( array (
  5270. 'where' => 'iid=' . $rid,
  5271. 'asArray' => true
  5272. ) );
  5273. if (! empty ( $invoiceDetail )) {
  5274. Doo::loadModel ( 'staff' );
  5275. $staff = new staff ();
  5276. $staffmsg = $staff->getOne ( array (
  5277. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  5278. 'asArray' => TRUE
  5279. ) );
  5280. if (! empty ( $staffmsg ['wxid'] )) {
  5281. require_once (SITE_PATH . '/protected/class/client.php');
  5282. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  5283. $user = $staffmsg ['wxid'];
  5284. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  5285. if (empty ( $expCom ))
  5286. $expCom [0] = '';
  5287. $msg = "";
  5288. if (empty ( $typeMsg ))
  5289. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  5290. elseif ($typeMsg == "PRINT")
  5291. $msg = '太好了,您的发票已打印完成。';
  5292. $result = $client->SendMsg ( $user, $msg, 'text' );
  5293. }
  5294. }
  5295. }
  5296. /**
  5297. * 获取微信部门
  5298. * @param string $category
  5299. * @return number|mixed
  5300. */
  5301. function getToparty($category = '') {
  5302. $token = $this->getAccessToken (); //
  5303. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  5304. $toparty = 0;
  5305. foreach ( $result ['department'] as $key => $value ) {
  5306. if ($value ['name'] == $category)
  5307. $toparty = $value ['id'];
  5308. }
  5309. return $toparty;
  5310. }
  5311. /**
  5312. * 获得某部门下的用户
  5313. * @param string $toparty
  5314. */
  5315. function getUserByToparty($toparty = '') {
  5316. $token = $this->getAccessToken (); //
  5317. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  5318. $userList = array ();
  5319. foreach ( $result ['userlist'] as $key => $value ) {
  5320. array_push ( $userList, "'" . $value ['userid'] . "'" );
  5321. }
  5322. return $userList;
  5323. }
  5324. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  5325. $token = $this->getAccessToken ();
  5326. if ($text == 'text') {
  5327. $data = '{
  5328. "touser": "' . $toparty . '",
  5329. "toparty": "",
  5330. "totag": "",
  5331. "msgtype": "text",
  5332. "agentid": 1000002,
  5333. "text": {
  5334. "content": "' . $msg . '"
  5335. },
  5336. "safe":0
  5337. }';
  5338. }
  5339. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  5340. if ($result->errmsg != 'ok') {
  5341. return 0;
  5342. } else {
  5343. return 1;
  5344. }
  5345. }
  5346. /**
  5347. * 获得可以发送微信用户列表
  5348. * @param string $category
  5349. * @return string
  5350. */
  5351. function getWxidByCategory($category = "") {
  5352. if (empty ( $category ))
  5353. return "";
  5354. Doo::loadModel ( 'staff' );
  5355. $staff = new staff ();
  5356. $toparty = $this->getToparty ( $category );
  5357. $wxList = array ();
  5358. $wxString = "";
  5359. if (! empty ( $toparty )) {
  5360. $userList = $this->getUserByToparty ( $toparty );
  5361. $userCon = implode ( ',', $userList );
  5362. // echo $userCon;
  5363. $sidList = $staff->getStaffByWxid ( $userCon );
  5364. foreach ( $sidList as $key => $value ) {
  5365. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  5366. if ($falg) {
  5367. array_push ( $wxList, $value ['wxid'] );
  5368. }
  5369. }
  5370. $wxString = implode ( '|', $wxList );
  5371. }
  5372. return $wxString;
  5373. }
  5374. /**
  5375. * 读取发送信息规则判断是否需要发送
  5376. * @param number $sid
  5377. * @param string $sendType
  5378. * @return boolean
  5379. */
  5380. function isSendNotification($sid = 0, $sendType = '') {
  5381. Doo::loadModel ( "notificationConf" );
  5382. $notificationConf = new notificationConf ();
  5383. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  5384. $conf = array ();
  5385. $sendFlag = true;
  5386. if (! empty ( $detail )) {
  5387. $conf = json_decode ( $detail ['conf'], true );
  5388. if (! empty ( $sendType )) {
  5389. if (isset ( $conf [$sendType] )) {
  5390. if ($conf [$sendType] == "CLOSE")
  5391. $sendFlag = false;
  5392. elseif ($conf [$sendType] == "Weekend") {
  5393. $day = date ( "w" );
  5394. if (1 <= $day && 5 >= $day)
  5395. $sendFlag = false;
  5396. } elseif ($conf [$sendType] == "OneToFriday") {
  5397. $day = date ( "w" );
  5398. if (0 == $day || 6 == $day)
  5399. $sendFlag = false;
  5400. }
  5401. }
  5402. } else
  5403. $sendFlag = false;
  5404. }
  5405. return $sendFlag;
  5406. }
  5407. /**
  5408. * 根据规则发送信息
  5409. * @param unknown $msg
  5410. * @param unknown $title
  5411. * @param unknown $url
  5412. * @param unknown $user
  5413. * @param string $text
  5414. * @return number
  5415. */
  5416. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  5417. $token = $this->getAccessToken ();
  5418. $falg = $this->isSendNotification ( $sid, $sendType );
  5419. // if ($text == 'text') {
  5420. // $data = '{
  5421. // "touser": "' . $user . '",
  5422. // "toparty": "",
  5423. // "totag": "",
  5424. // "msgtype": "text",
  5425. // "agentid": 1000002,
  5426. // "text": {
  5427. // "content": "' . $msg . '"
  5428. // },
  5429. // "safe":0
  5430. // }';
  5431. // } else {
  5432. $data = '{
  5433. "touser": "' . $user . '",
  5434. "toparty": "",
  5435. "totag": "",
  5436. "msgtype": "news",
  5437. "agentid": 1000002,
  5438. "news": {
  5439. "articles":[
  5440. {
  5441. "title": "' . $title . '",
  5442. "description": "' . $msg . '",
  5443. "url": "' . $url . '",
  5444. "picurl": ""
  5445. }
  5446. ]
  5447. }
  5448. }';
  5449. // }
  5450. if ($falg) {
  5451. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  5452. if ($result->errmsg != 'ok') {
  5453. return 0;
  5454. } else {
  5455. return 1;
  5456. }
  5457. } else
  5458. return 0;
  5459. }
  5460. private function getAccessToken() {
  5461. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  5462. // $file = './access_token.txt';
  5463. // $data = json_decode ( file_get_contents ( $file ) );
  5464. // if ($data->expire_time < time () or ! $data->expire_time) {
  5465. // 如果是企业号用以下URL获取access_token
  5466. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  5467. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  5468. $res = json_decode ( $this->httpGet ( $url ) );
  5469. $access_token = $res->access_token;
  5470. // echo $access_token;
  5471. // if ($access_token) {
  5472. // $data->expire_time = time () + 7000;
  5473. // $data->access_token = $access_token;
  5474. // $fp = fopen ( $file, "w" );
  5475. // fwrite ( $fp, json_encode ( $data ) );
  5476. // fclose ( $fp );
  5477. // }
  5478. // } else {
  5479. // $access_token = $data->access_token;
  5480. // }
  5481. return $access_token;
  5482. }
  5483. private function httpGet($url) {
  5484. $curl = curl_init ();
  5485. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  5486. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  5487. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  5488. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  5489. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  5490. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  5491. curl_setopt ( $curl, CURLOPT_URL, $url );
  5492. $res = curl_exec ( $curl );
  5493. curl_close ( $curl );
  5494. return $res;
  5495. }
  5496. private function httpPost($url, $data) {
  5497. $curl = curl_init ();
  5498. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  5499. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  5500. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  5501. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  5502. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  5503. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  5504. curl_setopt ( $curl, CURLOPT_URL, $url );
  5505. curl_setopt ( $curl, CURLOPT_POST, 1 );
  5506. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  5507. $res = curl_exec ( $curl );
  5508. curl_close ( $curl );
  5509. return $res;
  5510. }
  5511. }
  5512. ?>