InvoiceController.php 265 KB

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