InvoiceController.php 328 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040
  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. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request-iacd' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. //echo $routeRs ['1'];
  102. //die('dd');
  103. if (isset ( $_COOKIE ["staff"] )) {
  104. if (! empty ( $_COOKIE ["staff"] )) {
  105. Doo::loadModel ( 'staff' );
  106. $staff = new staff ();
  107. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  108. $this->ACTION = $uriPartsOrig [1];
  109. $this->data ['new'] = $this->isInvoiceNew ();
  110. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  111. $this->data ['isStaffCompleteMsg'] = false;
  112. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  113. if (! empty ( $detail ))
  114. $this->data ['isStaffCompleteMsg'] = true;
  115. return "/";
  116. }
  117. }
  118. Doo::loadCore ( 'uri/DooUriRouter' );
  119. $router = new DooUriRouter ();
  120. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  121. if ($routeRs ['1'] != "login") {
  122. header ( 'Content-Type:text/html;charset=utf-8' );
  123. @header ( "Location: /login" );
  124. }
  125. }
  126. function testSend() {
  127. // 测试根据规则发送信息 普通发送
  128. // $pendingApprovalsSid = 41;
  129. // Doo::loadModel ( 'staff' );
  130. // $staff = new staff ();
  131. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  132. // // 发送微信审批通知
  133. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  134. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  135. // Doo::loadModel ( 'staff' );
  136. // $staff = new staff ();
  137. // $toparty = $this->getToparty ( '广东办' );
  138. // $wxList = array ();
  139. // if (! empty ( $toparty )) {
  140. // $userList = $this->getUserByToparty ( $toparty );
  141. // $userCon = implode ( ',', $userList );
  142. // // echo $userCon;
  143. // $sidList = $staff->getStaffByWxid ( $userCon );
  144. // foreach ( $sidList as $key => $value ) {
  145. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  146. // if ($falg) {
  147. // array_push ( $wxList, $value ['wxid'] );
  148. // }
  149. // }
  150. // $wxString = implode ( '|', $wxList );
  151. // print_r ( $wxList );
  152. // echo $wxString;
  153. // }
  154. // 测试发送
  155. /*
  156. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  157. */
  158. // print_r ( $userList );
  159. // $msTouser='caipin|outaozhen';
  160. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  161. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  162. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  163. // $toparty= $this->getToparty('广东办');
  164. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  165. // $toparty = 26;
  166. // $msg = '';
  167. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  168. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  169. }
  170. function invoice() {
  171. Doo::loadModel ( 'invoice' );
  172. $invoice = new invoice ();
  173. Doo::loadModel ( 'express' );
  174. $express = new express ();
  175. $expressList = $express->getExpressByAll ();
  176. $this->data ['expressList'] = $expressList;
  177. // Doo::loadModel ( 'invoiceReceivables' );
  178. // $invoiceReceivables = new invoiceReceivables ();
  179. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  180. Doo::loadClass ( 'XDeode' );
  181. $XDeode = new XDeode ( 5 );
  182. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  183. Doo::loadModel ( 'invoiceStatistics' );
  184. $invoiceStatistics = new invoiceStatistics ();
  185. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  186. // 缓存统计结果
  187. $year = date ( "Y" );
  188. $tmp_date = date ( "Ym" );
  189. $tmp_year = substr ( $tmp_date, 0, 4 );
  190. $tmp_mon = substr ( $tmp_date, 4, 2 );
  191. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  192. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  193. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  194. if (is_file ( $path ))
  195. $htm = file_get_contents ( $path );
  196. else
  197. $htm = $this->showCache ( $path, $sid );
  198. $invoiceList = $invoice->getMyInvoice ( $sid );
  199. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  200. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  201. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  202. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  203. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  204. // 获得已退票功能
  205. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  206. $this->data ['untreadStatusList'] = $untreadStatusList;
  207. // print_r($untreadStatusList);
  208. $this->data ['isMonth'] = $isMonth;
  209. $this->data ['htm'] = $htm;
  210. $this->data ['invoiceList'] = $invoiceList;
  211. $this->data ['receivablesList'] = $list;
  212. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  213. $this->data ['memu'] = "invoice";
  214. $this->data ['staff'] = $this->staff;
  215. $this->data ['receiptMemu'] = 'invoice';
  216. $this->render ( "/admin/invoice", $this->data );
  217. }
  218. function invoiceExpress() {
  219. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  220. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  221. $this->data ['expressCom'] = $expressCom;
  222. $this->data ['expressNumber'] = $expressNumber;
  223. $this->render ( "/admin/invoiceExpress", $this->data );
  224. }
  225. function invoiceAdd() {
  226. session_start ();
  227. /*Doo::loadModel ( 'invoice' );
  228. $invoice = new invoice ();
  229. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  230. Doo::loadModel ( 'L_category' );
  231. $lCategory = new L_category ();
  232. $category = $lCategory->find ( array (
  233. 'asArray' => true
  234. ) );
  235. $this->data ['category'] = $category;
  236. Doo::loadModel ( 'invoiceTraining' );
  237. $invoiceTraining = new invoiceTraining ();
  238. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  239. Doo::loadModel ( 'receipt' );
  240. $receipt = new receipt ();
  241. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  242. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  243. if (! empty ( $receiptDetail )) {
  244. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  245. unset ( $itList [$key] );
  246. }
  247. }
  248. }
  249. $this->data ['itList'] = $itList;
  250. $token = $this->set_token ();
  251. $tokenTime=time().rand(5, 15);
  252. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  253. $this->data ['token'] = $token;
  254. $this->data['tokenTime']=$tokenTime;
  255. $this->data ['memu'] = "invoice";
  256. $this->data ['staff'] = $this->staff;
  257. $this->data ['receiptMemu'] = 'invoice';
  258. $this->render ( "/admin/invoiceAdd", $this->data );
  259. }
  260. /**
  261. * 自更新发票信息库
  262. * @param unknown $invoicePrintDetail
  263. */
  264. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  265. // 发票信息库
  266. Doo::loadModel ( 'invoiceInfoBase' );
  267. $invoiceInfoBase = new invoiceInfoBase ();
  268. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  269. $TIN = $invoicePrintDetail ['TIN'];
  270. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  271. if (empty ( $invoiceTitle ))
  272. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  273. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  274. // 确认有该条发票信息
  275. $invoiceInfoBase = new invoiceInfoBase ();
  276. if (! empty ( $IIBList )) {
  277. // 发票库里的信息数量
  278. $IIBListCount = count ( $IIBList );
  279. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  280. $item = array (
  281. 'iibID' => $IIBList [0] ['iibID'],
  282. 'invoiceTitle' => $invoiceTitle,
  283. 'TIN' => $TIN
  284. );
  285. if (! empty ( $invoicePrintDetail ['address'] )) {
  286. $item += array (
  287. 'address' => $invoicePrintDetail ['address']
  288. );
  289. }
  290. if (! empty ( $invoicePrintDetail ['phone'] )) {
  291. $item += array (
  292. 'phone' => $invoicePrintDetail ['phone']
  293. );
  294. }
  295. if (! empty ( $invoicePrintDetail ['bank'] )) {
  296. $item += array (
  297. 'bank' => $invoicePrintDetail ['bank']
  298. );
  299. }
  300. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  301. $item += array (
  302. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  303. );
  304. }
  305. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  306. $item += array (
  307. 'updateDate' => $invoicePrintDetail ['date']
  308. );
  309. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  310. }
  311. } else { // 删除多张发票,重新添加发票
  312. $iibIDStr = '';
  313. $iibID = array ();
  314. foreach ( $IIBList as $key => $value ) {
  315. array_push ( $iibID, $value ['iibID'] );
  316. }
  317. $iibIDStr = implode ( ",", $iibID ); // 删除
  318. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  319. $item = array (
  320. 'invoiceTitle' => $invoiceTitle,
  321. 'TIN' => $TIN,
  322. 'address' => $invoicePrintDetail ['address'],
  323. 'phone' => $invoicePrintDetail ['phone'],
  324. 'bank' => $invoicePrintDetail ['bank'],
  325. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  326. 'updateDate' => $invoicePrintDetail ['date']
  327. );
  328. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  329. }
  330. } else { // 没有新增发票信息
  331. $item = array (
  332. 'invoiceTitle' => $invoiceTitle,
  333. 'TIN' => $TIN,
  334. 'address' => $invoicePrintDetail ['address'],
  335. 'phone' => $invoicePrintDetail ['phone'],
  336. 'bank' => $invoicePrintDetail ['bank'],
  337. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  338. 'updateDate' => $invoicePrintDetail ['date']
  339. );
  340. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  341. }
  342. }
  343. function invoiceAddFill() {
  344. session_start ();
  345. Doo::loadModel ( 'L_category' );
  346. $lCategory = new L_category ();
  347. $category = $lCategory->find ( array (
  348. 'asArray' => true
  349. ) );
  350. $this->data ['category'] = $category;
  351. Doo::loadModel ( 'invoiceTraining' );
  352. $invoiceTraining = new invoiceTraining ();
  353. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  354. $this->data ['itList'] = $itList;
  355. Doo::loadModel ( 'invoice' );
  356. $invoice = new invoice ();
  357. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  358. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  359. $token = $this->set_token ();
  360. $tokenTime=time().rand(5, 15);
  361. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  362. $this->data ['token'] = $token;
  363. $this->data['tokenTime']=$tokenTime;
  364. $this->data ['invoiceDetail'] = $detail;
  365. $this->data ['memu'] = "invoice";
  366. $this->data ['staff'] = $this->staff;
  367. $this->data ['receiptMemu'] = 'invoice';
  368. $this->render ( "/admin/invoiceAddFill", $this->data );
  369. }
  370. /**
  371. * 提交一份开票申请,并记录下操作日志
  372. *
  373. * @since 1.0.0
  374. * @var integer cid 办事处ID
  375. * @var integer invoiceType 发票类型
  376. * @var integer doPost 是否邮寄
  377. * @var integer invoicePrice 开票金额
  378. * @var string invoiceElement 开票内容
  379. * @var string invoiceTitle 发票抬头
  380. * @var string invoiceCompany 单位名称
  381. * @var string TIN 纳税人识别码
  382. * @var string address 注册地址
  383. * @var string phone 注册电话
  384. * @var string bank 开户银行
  385. * @var string bankAccount 银行账户
  386. * @var string recipients 收件人
  387. * @var string recipientsPhone 收件人手机/电话
  388. * @var string recipientsAddress 收件地址
  389. * @var string mailItems 邮寄物品
  390. * @var string remark 备注
  391. * @return string 返回跳转开票主页路径
  392. */
  393. function invoiceAddDo() {
  394. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  395. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  396. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  397. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  398. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  399. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  400. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  401. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  402. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  403. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  404. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  405. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  406. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  407. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  408. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  409. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  410. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  411. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  412. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  413. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  414. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  415. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  416. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  417. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  418. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  419. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  420. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  421. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  422. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  423. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  424. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  425. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  426. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  427. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  428. $electronicPhone= $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  429. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  430. /*
  431. * $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;
  432. */
  433. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  434. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  435. if (empty ( $token )) {
  436. die ( 'illegal request-token' );
  437. } else {
  438. session_start ();
  439. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  440. header ( 'Content-Type:text/html;charset=utf-8' );
  441. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  442. die ( '请重新刷新发票申请页面' );
  443. }elseif($_SESSION [$sessionKey]=='repeat'){
  444. die ( '请勿重复申请发票' );
  445. } else {
  446. if ($_SESSION [$sessionKey] != $token){
  447. die ( '请勿重复申请发票' );
  448. }else{
  449. $_SESSION [$sessionKey] = 'repeat';
  450. }
  451. }
  452. }
  453. if($invoiceForm=='electronic'){
  454. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  455. die ( '请至少填写一种联系方式--电子发票' );
  456. }
  457. }
  458. if ($invoiceType == 1) {
  459. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  460. if ($temporary > 100001) {
  461. header ( 'Content-Type:text/html;charset=utf-8' );
  462. die ( '专用发票总金额暂时不能超过100000.00(一万)元。' );
  463. // die ( 'illegal request-Please priceError' );
  464. }
  465. }elseif($invoiceType == 0){
  466. }else{
  467. die ( 'illegal request-invoiceType' );
  468. }
  469. if (empty ( $this->staff [0] ))
  470. die ( 'illegal request-Please login' );
  471. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  472. Doo::loadModel ( 'invoice' );
  473. $invoice = new invoice ();
  474. Doo::loadModel ( 'L_category' );
  475. $lCategory = new L_category ();
  476. Doo::loadModel ( 'invoiceManage' );
  477. $invoiceManage = new invoiceManage ();
  478. Doo::loadModel ( 'invoiceOperationLog' );
  479. $invoiceOperationLog = new invoiceOperationLog ();
  480. Doo::loadClass ( 'XDeode' );
  481. $XDeode = new XDeode ( 5 );
  482. $trainId = $XDeode->decode ( $trainId );
  483. $categoryDetil = $lCategory->getOne ( array (
  484. 'SELECT' => 'title',
  485. 'where' => 'cid=' . $cid,
  486. 'asArray' => true
  487. ) );
  488. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  489. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  490. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  491. // print_r(current($invoiceManageDetail ['staffList']));
  492. // die;
  493. $moldManage = array ();
  494. foreach ( $invoiceManageList as $key => $value ) {
  495. if ($value ['mold'] == '发票打印')
  496. $moldManage [$value ['mold']] = $value ['staffList'];
  497. elseif ($value ['mold'] == '发票邮寄')
  498. $moldManage [$value ['mold']] = $value ['staffList'];
  499. elseif ($value ['mold'] == '发票退票')
  500. $moldManage [$value ['mold']] = $value ['staffList'];
  501. }
  502. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  503. $st = '';
  504. if ($settlementType == 'SOFTWARE') {
  505. $st = 0;
  506. $trainId = 0;
  507. } elseif ($settlementType == 'TRAINING') {
  508. $st = 1;
  509. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  510. die ( 'illegal request-trainingIdError' );
  511. }
  512. } else {
  513. die ( 'illegal request-settlementError' );
  514. }
  515. if($invoiceForm=='electronic'){
  516. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  517. $invoiceForm=1;
  518. $invoiceType=0;
  519. if(!empty($electronicPhone)||!empty($electronicEmail)){
  520. }else{
  521. die ( 'illegal request-electronicContact' );
  522. }
  523. $mailList = array ();
  524. $mailString = '备注:' . $mailItems;
  525. }elseif($invoiceForm=='paper'){
  526. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  527. $invoiceForm=0;
  528. $mailList = array (
  529. 'invoice' => 1,
  530. 'mailItems' => $mailItems
  531. );
  532. $mailString = '发票x1张,备注:' . $mailItems;
  533. }else{
  534. die ( 'illegal request-invoiceForm' );
  535. }
  536. $item = array (
  537. 'cid' => $cid,
  538. 'categoryName' => $categoryDetil ['title'],
  539. 'invoiceElement' => $invoiceElement,
  540. 'invoiceForm'=>$invoiceForm,
  541. 'electronicPhone'=>$electronicPhone,
  542. 'electronicEmail'=>$electronicEmail,
  543. 'invoiceQuantity' => $invoiceQuantity,
  544. 'invoiceUnitPrice' => $invoiceUnitPrice,
  545. 'invoicePrice' => $invoicePrice,
  546. 'invoiceType' => $invoiceType,
  547. 'settlementType' => $st,
  548. 'doPost' => $doPost,
  549. 'status' => 1,
  550. 'invoiceSerial' => $invoiceSerial,
  551. 'date' => date ( "Y-m-d H:i:s" ),
  552. 'updateTime' => date ( "Y-m-d H:i:s" ),
  553. 'sid' => $this->staff [0] ['sid'],
  554. 'userName' => $this->staff [0] ['username'],
  555. 'invoiceManage' => $invoiceManageDetail ['staff'],
  556. 'pendingApprovals' => $pendingApprovalsSid,
  557. 'moldManage' => json_encode ( $moldManage ),
  558. 'remark' => $remark,
  559. 'trainId' => $trainId
  560. );
  561. if ($invoiceType == 0)
  562. $item += array (
  563. 'invoiceTitle' => $invoiceTitle,
  564. 'TIN' => $TINT,
  565. 'address' => $addressT,
  566. 'phone' => $phoneT,
  567. 'bank' => $bankT,
  568. 'bankAccount' => $bankAccountT
  569. );
  570. else {
  571. $item += array (
  572. 'invoiceCompany' => $invoiceCompany,
  573. 'TIN' => $TIN,
  574. 'address' => $address,
  575. 'phone' => $phone,
  576. 'bank' => $bank,
  577. 'bankAccount' => $bankAccount
  578. );
  579. }
  580. if ($doPost == 1) {
  581. if (! empty ( $softLock ))
  582. $mailList += array (
  583. 'softLock' => $softLockNum
  584. );
  585. else
  586. $mailList += array (
  587. 'softLock' => 0
  588. );
  589. if (! empty ( $contract ))
  590. $mailList += array (
  591. 'contract' => $contractNum
  592. );
  593. else
  594. $mailList += array (
  595. 'contract' => 0
  596. );
  597. if (! empty ( $instructions ))
  598. $mailList += array (
  599. 'instructions' => $instructionsNum
  600. );
  601. else
  602. $mailList += array (
  603. 'instructions' => 0
  604. );
  605. if (! empty ( $remittance ))
  606. $mailList += array (
  607. 'remittance' => $remittance
  608. );
  609. else
  610. $mailList += array (
  611. 'remittance' => ''
  612. );
  613. if (! empty ( $softLock ))
  614. $mailString .= ',软件锁x' . $softLockNum . '个';
  615. if (! empty ( $contract ))
  616. $mailString .= ',合同x' . $contractNum . '份';
  617. if (! empty ( $instructions ))
  618. $mailString .= ',说明书x' . $instructionsNum . '本';
  619. if (! empty ( $remittance ))
  620. $mailString .= ',汇款账号单(张)';
  621. $item += array (
  622. 'recipients' => $recipients,
  623. 'recipientsPhone' => $recipientsPhone,
  624. 'recipientsAddress' => $recipientsAddress,
  625. 'mailItems' => $mailString,
  626. 'mailItemsJson' => json_encode ( $mailList )
  627. );
  628. }
  629. $iid = $invoice->addInvoice ( $item );
  630. // 如果是培训班结算 创建培训班发票到培训班备份中
  631. if (! empty ( $st ) && $st == 1) {
  632. Doo::loadModel ( 'invoiceStore' );
  633. $invoiceStore = new invoiceStore ();
  634. Doo::loadModel ( 'invoiceTraining' );
  635. $invoiceTraining = new invoiceTraining ();
  636. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  637. $itemIS = array (
  638. 'isid' => $isid,
  639. 'ipSource' => 1,
  640. 'apStatus' => 1,
  641. 'iid' => $iid
  642. );
  643. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  644. // 更新培训班总数量
  645. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  646. $item = array (
  647. 'itid' => $trainId,
  648. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  649. 'submitStatus' => 1
  650. );
  651. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  652. }
  653. // 操作日志
  654. $item = array (
  655. 'date' => date ( "Y-m-d H:i:s" ),
  656. 'operation' => "创建",
  657. 'status' => 1,
  658. 'img' => $this->staff [0] ['avatar'],
  659. 'username' => $this->staff [0] ['username'],
  660. 'uid' => $this->staff [0] ['sid'],
  661. 'category' => $this->staff [0] ['category'],
  662. 'iid' => $iid
  663. );
  664. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  665. $item = array (
  666. 'date' => date ( "Y-m-d H:i:s" ),
  667. 'operation' => "提交审批",
  668. 'status' => 1,
  669. 'img' => $this->staff [0] ['avatar'],
  670. 'username' => $this->staff [0] ['username'],
  671. 'uid' => $this->staff [0] ['sid'],
  672. 'category' => $this->staff [0] ['category'],
  673. 'iid' => $iid
  674. );
  675. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  676. Doo::loadModel ( 'staff' );
  677. $staff = new staff ();
  678. $username2 = $staff->getOne ( array (
  679. 'select' => 'wxid',
  680. 'where' => 'sid=' . $pendingApprovalsSid,
  681. 'asArray' => TRUE
  682. ) );
  683. // 发送微信审批通知
  684. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  685. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  686. }
  687. return "/invoice";
  688. }
  689. function invoiceEdit() {
  690. Doo::loadClass ( 'XDeode' );
  691. $XDeode = new XDeode ( 5 );
  692. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  693. $iid = $XDeode->decode ( $iid );
  694. if (! is_numeric ( $iid ))
  695. die ( 'illegal request' );
  696. Doo::loadModel ( 'invoice' );
  697. $invoice = new invoice ();
  698. Doo::loadModel ( 'invoiceOperationLog' );
  699. $invoiceOperationLog = new invoiceOperationLog ();
  700. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  701. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  702. $invoiceDetail ['mailItemsJson'] ='';
  703. if(isset($invoiceDetail ['mailItemsJson'])){
  704. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  705. }
  706. $this->data ['operation'] = $operation;
  707. $this->data ['invoiceDetail'] = $invoiceDetail;
  708. $this->data ['memu'] = "invoice";
  709. $this->data ['staff'] = $this->staff;
  710. $this->data ['receiptMemu'] = 'invoice';
  711. $this->render ( "/admin/invoiceEdit", $this->data );
  712. }
  713. /**
  714. * 重新编辑退回的发票
  715. * @return string
  716. */
  717. function invoiceEditDo() {
  718. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  719. Doo::loadModel ( 'invoice' );
  720. $invoice = new invoice ();
  721. $iid = $invoice->authcode ( $iidKey );
  722. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  723. die ( 'illegal request' );
  724. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  725. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  726. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  727. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  728. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  729. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  730. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  731. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  732. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  733. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  734. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  735. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  736. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  737. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  738. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  739. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  740. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  741. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  742. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  743. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  744. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  745. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  746. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  747. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  748. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  749. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  750. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  751. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  752. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  753. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  754. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  755. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  756. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  757. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  758. if ($invoiceType == 1) {
  759. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  760. if ($temporary > 100001)
  761. die ( 'illegal request-Please priceError' );
  762. }
  763. if($invoiceForm=='electronic'){
  764. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  765. die ( '请至少填写一种联系方式--电子发票' );
  766. }
  767. }
  768. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  769. Doo::loadModel ( 'invoiceManage' );
  770. $invoiceManage = new invoiceManage ();
  771. Doo::loadModel ( 'invoiceOperationLog' );
  772. $invoiceOperationLog = new invoiceOperationLog ();
  773. Doo::loadModel ( 'invoiceStore' );
  774. $invoiceStore = new invoiceStore ();
  775. $cid = explode ( ':', $cid );
  776. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  777. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  778. $moldManage = array ();
  779. foreach ( $invoiceManageList as $key => $value ) {
  780. if ($value ['mold'] == '发票打印')
  781. $moldManage [$value ['mold']] = $value ['staffList'];
  782. elseif ($value ['mold'] == '发票邮寄')
  783. $moldManage [$value ['mold']] = $value ['staffList'];
  784. elseif ($value ['mold'] == '发票打印')
  785. $moldManage [$value ['mold']] = $value ['staffList'];
  786. }
  787. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  788. if($invoiceForm=='electronic'){
  789. $invoiceForm=1;
  790. $invoiceType=0;
  791. if(!empty($electronicPhone)||!empty($electronicEmail)){
  792. }else{
  793. die ( 'illegal request-electronicContact' );
  794. }
  795. $mailList = array ();
  796. $mailString = '备注:' . $mailItems;
  797. }elseif($invoiceForm=='paper'){
  798. $invoiceForm=0;
  799. $mailList = array (
  800. 'invoice' => 1,
  801. 'mailItems' => $mailItems
  802. );
  803. $mailString = '发票x1张,备注:' . $mailItems;
  804. }else{
  805. die ( 'illegal request-invoiceForm' );
  806. }
  807. $item = array (
  808. 'iid' => $iid,
  809. 'cid' => $cid [0],
  810. 'categoryName' => $cid [1],
  811. 'invoiceElement' => $invoiceElement,
  812. 'invoiceForm'=>$invoiceForm,
  813. 'electronicPhone'=>$electronicPhone,
  814. 'electronicEmail'=>$electronicEmail,
  815. 'invoiceQuantity' => $invoiceQuantity,
  816. 'invoiceUnitPrice' => $invoiceUnitPrice,
  817. 'invoicePrice' => $invoicePrice,
  818. 'invoiceType' => $invoiceType,
  819. 'doPost' => $doPost,
  820. 'status' => 1,
  821. 'updateTime' => date ( "Y-m-d H:i:s" ),
  822. 'remark' => $remark
  823. );
  824. if ($invoiceType == 0)
  825. $item += array (
  826. 'invoiceTitle' => $invoiceTitle,
  827. 'TIN' => $TINT,
  828. 'address' => $addressT,
  829. 'phone' => $phoneT,
  830. 'bank' => $bankT,
  831. 'bankAccount' => $bankAccountT
  832. );
  833. else {
  834. $item += array (
  835. 'invoiceCompany' => $invoiceCompany,
  836. 'TIN' => $TIN,
  837. 'address' => $address,
  838. 'phone' => $phone,
  839. 'bank' => $bank,
  840. 'bankAccount' => $bankAccount
  841. );
  842. }
  843. if ($doPost == 1) {
  844. if (! empty ( $softLock ))
  845. $mailList += array (
  846. 'softLock' => $softLockNum
  847. );
  848. else
  849. $mailList += array (
  850. 'softLock' => '0'
  851. );
  852. if (! empty ( $contract ))
  853. $mailList += array (
  854. 'contract' => $contractNum
  855. );
  856. else
  857. $mailList += array (
  858. 'contract' => '0'
  859. );
  860. if (! empty ( $instructions ))
  861. $mailList += array (
  862. 'instructions' => $instructionsNum
  863. );
  864. else
  865. $mailList += array (
  866. 'instructions' => '0'
  867. );
  868. if (! empty ( $remittance ))
  869. $mailList += array (
  870. 'remittance' => $remittance
  871. );
  872. else
  873. $mailList += array (
  874. 'remittance' => ''
  875. );
  876. if (! empty ( $softLock ))
  877. $mailString .= ',软件锁x' . $softLockNum;
  878. if (! empty ( $contract ))
  879. $mailString .= ',合同x' . $contractNum;
  880. if (! empty ( $instructions ))
  881. $mailString .= ',说明书x' . $instructionsNum;
  882. if (! empty ( $remittance ))
  883. $mailString .= ',汇款账号单';
  884. $item += array (
  885. 'recipients' => $recipients,
  886. 'recipientsPhone' => $recipientsPhone,
  887. 'recipientsAddress' => $recipientsAddress,
  888. 'mailItems' => $mailString,
  889. 'mailItemsJson' => json_encode ( $mailList )
  890. );
  891. }
  892. $invoice->setInvoiceByCondition ( $item );
  893. // 更新培训班仓库里的发票
  894. $detail = $invoice->getInvoiceByIid ( $iid );
  895. if (! empty ( $detail ['isid'] )) {
  896. $invoiceStore->isid = $detail ['isid'];
  897. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  898. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  899. $invoiceStore->invoicePrice = $invoicePrice;
  900. $invoiceStore->update ();
  901. }
  902. $item = array (
  903. 'date' => date ( "Y-m-d H:i:s" ),
  904. 'operation' => "重新提交审批",
  905. 'status' => 1,
  906. 'img' => $this->staff [0] ['avatar'],
  907. 'username' => $this->staff [0] ['username'],
  908. 'uid' => $this->staff [0] ['sid'],
  909. 'category' => $this->staff [0] ['category'],
  910. 'iid' => $iid
  911. );
  912. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  913. }
  914. return "/invoice";
  915. }
  916. /**
  917. * 培训班
  918. */
  919. function invoiceTraining() {
  920. Doo::loadModel ( 'L_category' );
  921. $lCategory = new L_category ();
  922. Doo::loadModel ( 'invoiceTraining' );
  923. $invoiceTraining = new invoiceTraining ();
  924. Doo::loadModel ( 'invoiceTrainManage' );
  925. $invoiceTrainManage = new invoiceTrainManage ();
  926. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  927. $cidList = array ();
  928. foreach ( $imcStaff as $key => $value ) {
  929. array_push ( $cidList, $value ['cid'] );
  930. }
  931. if (empty ( $cidList )) {
  932. $cidString = $this->staff [0] ['cid'];
  933. } else {
  934. $cidString = implode ( ',', $cidList );
  935. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  936. }
  937. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  938. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  939. $category = $lCategory->getCategory ();
  940. $itid = array ();
  941. foreach ( $itTodoList as $key => $value ) {
  942. array_push ( $itid, $value ['itid'] );
  943. // 如果入账100%更新为已完成
  944. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  945. $invoiceTraining = new invoiceTraining ();
  946. $invoiceTraining->itid = $value ['itid'];
  947. $invoiceTraining->status = 2;
  948. $invoiceTraining->update ();
  949. }
  950. }
  951. foreach ( $itedList as $value ) {
  952. array_push ( $itid, $value ['itid'] );
  953. }
  954. $itid = implode ( ',', $itid );
  955. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  956. // print_r($itTodoList);
  957. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  958. $this->data ['itTodoList'] = $itTodoList;
  959. $this->data ['itedList'] = $itedList;
  960. $this->data ['category'] = $category;
  961. $this->data ['memu'] = "invoice";
  962. $this->data ['staff'] = $this->staff;
  963. $this->data ['receiptMemu'] = 'invoiceTraining';
  964. $this->render ( "/admin/invoiceTraining", $this->data );
  965. }
  966. /**
  967. * 创建培训班
  968. */
  969. function invoiceTrainingAdd() {
  970. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  971. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  972. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  973. if (empty ( $this->staff [0] ))
  974. die ( 'illegal request' );
  975. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  976. Doo::loadModel ( 'invoiceTraining' );
  977. $invoiceTraining = new invoiceTraining ();
  978. Doo::loadModel ( 'invoice' );
  979. $invoice = new invoice ();
  980. Doo::loadModel ( 'L_category' );
  981. $lCategory = new L_category ();
  982. Doo::loadModel ( 'invoiceManage' );
  983. $invoiceManage = new invoiceManage ();
  984. Doo::loadModel ( 'invoiceOperationLog' );
  985. $invoiceOperationLog = new invoiceOperationLog ();
  986. $item = array (
  987. 'cid' => $cid,
  988. 'trainName' => $trainName,
  989. 'trainDate' => $trainDate,
  990. 'creator' => $this->staff [0] ['sid'],
  991. 'creatorDate' => date ( "Y-m-d H:i:s" )
  992. );
  993. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  994. }
  995. return "/invoiceTraining";
  996. }
  997. /**
  998. * 删除培训班
  999. */
  1000. function invoiceTrainingDelDo() {
  1001. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1002. if (! empty ( $itid )) {
  1003. Doo::loadModel ( 'invoiceTraining' );
  1004. $invoiceTraining = new invoiceTraining ();
  1005. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1006. }
  1007. return "/invoiceTraining";
  1008. }
  1009. /**
  1010. * 培训班详情
  1011. */
  1012. function invoiceTrainingDetail() {
  1013. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1014. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1015. Doo::loadModel ( 'invoiceTraining' );
  1016. $invoiceTraining = new invoiceTraining ();
  1017. Doo::loadModel ( 'invoiceStore' );
  1018. $invoiceStore = new invoiceStore ();
  1019. if (empty ( $itid ))
  1020. die ( 'illegal request' );
  1021. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1022. if ($trainStatus == "SUBED")
  1023. $con = ' (b.untreadStatus is null ) and ';
  1024. elseif ($trainStatus == "APPROVAL")
  1025. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1026. elseif ($trainStatus == "TICKET")
  1027. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1028. elseif ($trainStatus == "TICKETING") {
  1029. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1030. }
  1031. $con.=' a.invoiceForm=0 and ';
  1032. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1033. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1034. //print_r($isList);
  1035. $trainlistJson=$this->_trainList($isList);
  1036. if (empty ( $detail ))
  1037. die ( 'illegal request' );
  1038. // 培训班结算是否有和是否已经结算完成
  1039. Doo::loadModel ( 'receipt' );
  1040. $receipt = new receipt ();
  1041. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1042. $this->data ['receiptDetail'] = $receiptDetail;
  1043. $this->data ['trainStatus'] = $trainStatus;
  1044. $this->data ['itid'] = $itid;
  1045. $this->data ['trainlistJson'] = $trainlistJson;
  1046. $this->data ['iTrainDetail'] = $detail;
  1047. $this->data ['memu'] = "invoice";
  1048. $this->data ['staff'] = $this->staff;
  1049. $this->data ['receiptMemu'] = 'invoiceTraining';
  1050. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1051. }
  1052. function invoiceTrainingElectronicDetail(){
  1053. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1054. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1055. Doo::loadModel ( 'invoiceTraining' );
  1056. $invoiceTraining = new invoiceTraining ();
  1057. Doo::loadModel ( 'invoiceStore' );
  1058. $invoiceStore = new invoiceStore ();
  1059. if (empty ( $itid ))
  1060. die ( 'illegal request' );
  1061. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1062. if ($trainStatus == "SUBED")
  1063. $con = ' (b.untreadStatus is null ) and ';
  1064. elseif ($trainStatus == "APPROVAL")
  1065. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1066. elseif ($trainStatus == "TICKET")
  1067. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1068. elseif ($trainStatus == "TICKETING") {
  1069. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1070. }
  1071. $con.=' a.invoiceForm=1 and ';
  1072. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1073. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1074. //print_r($isList);
  1075. if (empty ( $detail )){
  1076. die ( 'illegal request' );
  1077. }
  1078. $trainlistJson=$this->_trainList($isList,1);
  1079. // 培训班结算是否有和是否已经结算完成
  1080. Doo::loadModel ( 'receipt' );
  1081. $receipt = new receipt ();
  1082. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1083. $this->data ['receiptDetail'] = $receiptDetail;
  1084. $this->data ['trainStatus'] = $trainStatus;
  1085. $this->data ['itid'] = $itid;
  1086. $this->data ['trainlistJson'] = $trainlistJson;
  1087. $this->data ['iTrainDetail'] = $detail;
  1088. $this->data ['memu'] = "invoice";
  1089. $this->data ['staff'] = $this->staff;
  1090. $this->data ['receiptMemu'] = 'invoiceTraining';
  1091. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1092. }
  1093. function _trainList($isList,$type=0){
  1094. $trainlist = array ();
  1095. foreach ( $isList as $key => $value ) {
  1096. $irDetail = array ();
  1097. if ($value ['apStatus'] == 1) {
  1098. // array_push ( $irDetail, '' );
  1099. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1100. } else {
  1101. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1102. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1103. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1104. }
  1105. array_push ( $irDetail, $value ['invoiceSerial'] );
  1106. if ($value ['invoiceType'] == 1)
  1107. array_push ( $irDetail, $value ['invoiceCompany'] );
  1108. else
  1109. array_push ( $irDetail, $value ['invoiceTitle'] );
  1110. array_push ( $irDetail, $value ['TIN'] );
  1111. array_push ( $irDetail, $value ['userName'] );
  1112. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1113. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1114. } else
  1115. array_push ( $irDetail, $value ['mailItems'] );
  1116. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1117. if($type==1){
  1118. array_push ( $irDetail, $value ['electronicPhone'] );
  1119. array_push ( $irDetail, $value ['electronicEmail'] );
  1120. }
  1121. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1122. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1123. array_push ( $irDetail, $value ['invoiceElement'] );
  1124. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1125. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1126. if ($value ['invoiceType'] == 1)
  1127. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1128. else
  1129. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1130. array_push ( $irDetail, $value ['remark'] );
  1131. if ($value ['status'] == 1)
  1132. array_push ( $irDetail, '审批中' );
  1133. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1134. array_push ( $irDetail, '已出票' );
  1135. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1136. array_push ( $irDetail, '已入账' );
  1137. else
  1138. array_push ( $irDetail, '' );
  1139. array_push ( $irDetail, $value ['invoiceNo'] );
  1140. array_push ( $irDetail, $value ['printTime'] );
  1141. $html = '';
  1142. foreach ( $value ['invoiceReceivables'] as $v ) {
  1143. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1144. }
  1145. array_push ( $irDetail, $html );
  1146. array_push ( $trainlist, $irDetail );
  1147. }
  1148. $trainlistJson = json_encode ( $trainlist );
  1149. return $trainlistJson;
  1150. }
  1151. /**
  1152. * 上传培训班发票
  1153. * @return string
  1154. */
  1155. function invoiceTrainingUpload() {
  1156. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1157. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1158. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1159. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1160. header ( "HTTP/1.1 500 Internal Server Error" );
  1161. echo "POST exceeded maximum allowed size.";
  1162. exit ( 0 );
  1163. }
  1164. // Settings
  1165. $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)
  1166. $upload_name = "Filedata";
  1167. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1168. $extension_whitelist = array (
  1169. "doc",
  1170. "txt",
  1171. "jpg",
  1172. "gif",
  1173. "png"
  1174. ); // Allowed file extensions
  1175. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1176. // Other variables
  1177. $MAX_FILENAME_LENGTH = 260;
  1178. $file_name = "";
  1179. $file_extension = "";
  1180. $uploadErrors = array (
  1181. 0 => "文件上传成功",
  1182. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1183. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1184. 3 => "上传的文件仅为部分文件",
  1185. 4 => "没有文件上传",
  1186. 6 => "缺少临时文件夹"
  1187. );
  1188. $nk = time ();
  1189. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1190. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1191. echo "文件无法保存.";
  1192. exit ( 0 );
  1193. }
  1194. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1195. echo json_encode ( array (
  1196. 'filename' => $file_name,
  1197. 'id' => $nk
  1198. ) );
  1199. exit ( 0 );
  1200. }
  1201. /**
  1202. * 导入发票临时仓库
  1203. */
  1204. function invoiceStoreImport() {
  1205. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1206. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1207. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1208. if ($path != "" && ! empty ( $trainingKey )) {
  1209. Doo::loadModel ( 'invoiceStore' );
  1210. Doo::loadModel ( 'staff' );
  1211. $staff = new staff ();
  1212. Doo::loadModel ( 'invoiceTraining' );
  1213. $invoiceTraining = new invoiceTraining ();
  1214. Doo::loadClass ( 'XDeode' );
  1215. $XDeode = new XDeode ( 5 );
  1216. $itid = $XDeode->decode ( $trainingKey );
  1217. // 培训班结算是否有和是否已经结算完成
  1218. Doo::loadModel ( 'receipt' );
  1219. $receipt = new receipt ();
  1220. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1221. if (! empty ( $receiptDetail )) {
  1222. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1223. die ( 'illegal request--status' );
  1224. }
  1225. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1226. $userName = $this->staff [0] ['username'];
  1227. $sDetail = $staff->getStaffByName ( $userName );
  1228. //print_r($exlArray);die;
  1229. // die('sdd');
  1230. // 可以优化
  1231. foreach ( $exlArray as $key => $value ) {
  1232. // 开票
  1233. $invoice = new invoiceStore ();
  1234. $invoice->trainId = $itid;
  1235. $invoice->invoiceType = 0;
  1236. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1237. $invoice->invoiceType = 1;
  1238. elseif($value ['invoiceType'] == '电子'){
  1239. $invoice->invoiceType = 0;
  1240. $invoice->invoiceForm=1;
  1241. }
  1242. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1243. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1244. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1245. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1246. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1247. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1248. $invoice->userName = $userName;
  1249. $invoice->sid = $sDetail ['sid'];
  1250. $invoice->cid = $sDetail ['cid'];
  1251. $invoice->categoryName = $sDetail ['category'];
  1252. $invoice->invoiceElement = $value ['invoiceElement'];
  1253. $invoice->remark = $value ['remark'];
  1254. // $invoice->date = $value ['date'];
  1255. // $invoice->printTime = $value ['date'];
  1256. $invoice->ipSource = 1;
  1257. $invoice->printStatus = 0;
  1258. $invoice->status = 0;
  1259. $invoice->postStatus = 1;
  1260. $invoice->untreadStatus = 0;
  1261. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1262. $invoice->TIN = $value ['TIN'];
  1263. $invoice->address = $value ['address'];
  1264. $invoice->phone = $value ['phone'];
  1265. $invoice->bank = $value ['bank'];
  1266. $invoice->bankAccount = $value ['bankAccount'];
  1267. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1268. $invoice->recipients = $value ['recipients'];
  1269. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1270. $invoice->electronicPhone = $value ['electronicPhone'];
  1271. $invoice->electronicEmail = $value ['electronicEmail'];
  1272. $iid = $invoice->insert ();
  1273. }
  1274. // 加入发票总数量
  1275. $item = array (
  1276. 'itid' => $itid,
  1277. 'invoiceTotal' => count ( $exlArray )
  1278. );
  1279. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1280. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1281. }
  1282. echo 'no file';
  1283. }
  1284. /**
  1285. * 编辑仓库里的发票
  1286. */
  1287. function invoiceStoreEdit() {
  1288. Doo::loadClass ( 'XDeode' );
  1289. $XDeode = new XDeode ( 5 );
  1290. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1291. $iid = $XDeode->decode ( $iid );
  1292. if (! is_numeric ( $iid ))
  1293. die ( 'illegal request' );
  1294. Doo::loadModel ( 'invoiceStore' );
  1295. $invoiceStore = new invoiceStore ();
  1296. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1297. // print_r($invoiceDetail);
  1298. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1299. $this->data ['invoiceDetail'] = $invoiceDetail;
  1300. $this->data ['memu'] = "invoice";
  1301. $this->data ['staff'] = $this->staff;
  1302. $this->data ['receiptMemu'] = 'invoiceTraining';
  1303. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1304. }
  1305. function invoiceStoreEditDo() {
  1306. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1307. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1308. Doo::loadModel ( 'invoiceStore' );
  1309. $invoice = new invoiceStore ();
  1310. Doo::loadClass ( 'XDeode' );
  1311. $XDeode = new XDeode ( 5 );
  1312. $iid = $XDeode->decode ( $storeKey );
  1313. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1314. die ( 'illegal request' );
  1315. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1316. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1317. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1318. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1319. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1320. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1321. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1322. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1323. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1324. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1325. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1326. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1327. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1328. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1329. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1330. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1331. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1332. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1333. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1334. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1335. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1336. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1337. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1338. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1339. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1340. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1341. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1342. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1343. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1344. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1345. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1346. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1347. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1348. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1349. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1350. $cid = explode ( ':', $cid );
  1351. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1352. $item = array (
  1353. 'isid' => $iid,
  1354. 'cid' => $cid [0],
  1355. 'categoryName' => $cid [1],
  1356. 'invoiceElement' => $invoiceElement,
  1357. 'invoiceQuantity' => $invoiceQuantity,
  1358. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1359. 'invoicePrice' => $invoicePrice,
  1360. 'invoiceType' => $invoiceType,
  1361. 'doPost' => $doPost,
  1362. 'status' => 1,
  1363. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1364. 'remark' => $remark
  1365. );
  1366. if ($invoiceType == 0)
  1367. $item += array (
  1368. 'invoiceTitle' => $invoiceTitle,
  1369. 'TIN' => $TINT,
  1370. 'address' => $addressT,
  1371. 'phone' => $phoneT,
  1372. 'bank' => $bankT,
  1373. 'bankAccount' => $bankAccountT
  1374. );
  1375. else {
  1376. $item += array (
  1377. 'invoiceCompany' => $invoiceCompany,
  1378. 'TIN' => $TIN,
  1379. 'address' => $address,
  1380. 'phone' => $phone,
  1381. 'bank' => $bank,
  1382. 'bankAccount' => $bankAccount
  1383. );
  1384. }
  1385. if($invoiceForm=='paper'){
  1386. $item += array (
  1387. 'invoiceForm' => 0
  1388. );
  1389. }elseif($invoiceForm=='electronic'){
  1390. $item += array (
  1391. 'invoiceForm' => 1,
  1392. 'electronicPhone' => $electronicPhone,
  1393. 'electronicEmail' => $electronicEmail,
  1394. );
  1395. }
  1396. if ($doPost == 1) {
  1397. $mailList = array (
  1398. 'invoice' => 1,
  1399. 'mailItems' => $mailItems
  1400. );
  1401. if (! empty ( $softLock ))
  1402. $mailList += array (
  1403. 'softLock' => $softLockNum
  1404. );
  1405. else
  1406. $mailList += array (
  1407. 'softLock' => '0'
  1408. );
  1409. if (! empty ( $contract ))
  1410. $mailList += array (
  1411. 'contract' => $contractNum
  1412. );
  1413. else
  1414. $mailList += array (
  1415. 'contract' => '0'
  1416. );
  1417. if (! empty ( $instructions ))
  1418. $mailList += array (
  1419. 'instructions' => $instructionsNum
  1420. );
  1421. else
  1422. $mailList += array (
  1423. 'instructions' => '0'
  1424. );
  1425. if (! empty ( $remittance ))
  1426. $mailList += array (
  1427. 'remittance' => $remittance
  1428. );
  1429. else
  1430. $mailList += array (
  1431. 'remittance' => ''
  1432. );
  1433. $mailString = '发票x1,备注:' . $mailItems;
  1434. if (! empty ( $softLock ))
  1435. $mailString .= ',软件锁x' . $softLockNum;
  1436. if (! empty ( $contract ))
  1437. $mailString .= ',合同x' . $contractNum;
  1438. if (! empty ( $instructions ))
  1439. $mailString .= ',说明书x' . $instructionsNum;
  1440. if (! empty ( $remittance ))
  1441. $mailString .= ',汇款账号单';
  1442. $item += array (
  1443. 'recipients' => $recipients,
  1444. 'recipientsPhone' => $recipientsPhone,
  1445. 'recipientsAddress' => $recipientsAddress,
  1446. 'mailItems' => $mailString,
  1447. 'mailItemsJson' => json_encode ( $mailList )
  1448. );
  1449. }
  1450. $invoice->setInvoiceStoreByCondition ( $item );
  1451. }
  1452. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1453. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1454. }else{
  1455. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1456. }
  1457. }
  1458. /**
  1459. *
  1460. * @return string
  1461. */
  1462. function invoiceStoreDelete() {
  1463. Doo::loadClass ( 'XDeode' );
  1464. $XDeode = new XDeode ( 5 );
  1465. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1466. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1467. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1468. $isid = $XDeode->decode ( $iStoreKey );
  1469. $itid = $XDeode->decode ( $trainKey );
  1470. if (! is_numeric ( $isid ))
  1471. die ( 'illegal request' );
  1472. Doo::loadModel ( 'invoiceStore' );
  1473. $invoiceStore = new invoiceStore ();
  1474. $invoiceStore->delete ( array (
  1475. 'where' => 'isid=' . $isid,
  1476. 'limit' => 1
  1477. ) );
  1478. Doo::loadModel ( 'invoiceTraining' );
  1479. $invoiceTraining = new invoiceTraining ();
  1480. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1481. $item = array (
  1482. 'itid' => $itid,
  1483. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1484. );
  1485. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1486. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1487. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1488. }else{
  1489. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1490. }
  1491. }
  1492. /**
  1493. * 批量删除库里发票
  1494. */
  1495. function invoiceStoreBatchDelete() {
  1496. Doo::loadClass ( 'XDeode' );
  1497. $XDeode = new XDeode ( 5 );
  1498. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1499. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1500. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1501. if (empty ( $trainKey ) || empty ( $storeKey ))
  1502. die ( 'illegal request-IdKey' );
  1503. $tid = $XDeode->decode ( $trainKey );
  1504. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1505. die ( 'illegal request' );
  1506. Doo::loadModel ( 'invoiceStore' );
  1507. $isidKeyList = explode ( ',', $storeKey );
  1508. $isidList = array ();
  1509. foreach ( $isidKeyList as $value ) {
  1510. $isid = $XDeode->decode ( $value );
  1511. if (! empty ( $isid ) && is_numeric ( $isid ))
  1512. array_push ( $isidList, $isid );
  1513. }
  1514. $isidString = implode ( ',', $isidList );
  1515. $invoiceStore = new invoiceStore ();
  1516. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1517. $isidList = array ();
  1518. foreach ( $isList as $key => $value ) {
  1519. if ($value ['apStatus'] == 0)
  1520. array_push ( $isidList, $value ['isid'] );
  1521. }
  1522. $isidString = implode ( ',', $isidList );
  1523. // print_r($isList);
  1524. // echo $isidString;
  1525. $invoiceStore = new invoiceStore ();
  1526. $invoiceStore->delete ( array (
  1527. 'where' => "isid in ( " . $isidString . ")",
  1528. 'asArray' => TRUE
  1529. ) );
  1530. Doo::loadModel ( 'invoiceTraining' );
  1531. $invoiceTraining = new invoiceTraining ();
  1532. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1533. $item = array (
  1534. 'itid' => $tid,
  1535. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1536. );
  1537. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1538. // echo $tid;
  1539. // echo $storeKey;
  1540. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1541. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1542. }else{
  1543. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1544. }
  1545. }
  1546. function invoiceStoreBatchElectronicPhone(){
  1547. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1548. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1549. Doo::loadClass ( 'XDeode' );
  1550. $XDeode = new XDeode ( 5 );
  1551. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1552. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1553. if (empty ( $trainKey ) || empty ( $storeKey ))
  1554. die ( 'illegal request-IdKey' );
  1555. $isidKeyList = explode ( ',', $storeKey );
  1556. $isidList = array ();
  1557. foreach ( $isidKeyList as $value ) {
  1558. $isid = $XDeode->decode ( $value );
  1559. if (! empty ( $isid ) && is_numeric ( $isid ))
  1560. array_push ( $isidList, $isid );
  1561. }
  1562. $isidString = implode ( ',', $isidList );
  1563. $trainId = $XDeode->decode ( $trainKey );
  1564. if (! is_numeric ( $isid ))
  1565. die ( 'illegal request--isid' );
  1566. Doo::loadModel ( 'invoiceStore' );
  1567. $invoiceStore = new invoiceStore ();
  1568. $item = array (
  1569. 'electronicPhone' => $electronicPhone
  1570. );
  1571. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1572. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1573. }
  1574. function invoiceStoreBatchElectronicEmail(){
  1575. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1576. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1577. Doo::loadClass ( 'XDeode' );
  1578. $XDeode = new XDeode ( 5 );
  1579. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1580. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1581. if (empty ( $trainKey ) || empty ( $storeKey ))
  1582. die ( 'illegal request-IdKey' );
  1583. $isidKeyList = explode ( ',', $storeKey );
  1584. $isidList = array ();
  1585. foreach ( $isidKeyList as $value ) {
  1586. $isid = $XDeode->decode ( $value );
  1587. if (! empty ( $isid ) && is_numeric ( $isid ))
  1588. array_push ( $isidList, $isid );
  1589. }
  1590. $isidString = implode ( ',', $isidList );
  1591. $trainId = $XDeode->decode ( $trainKey );
  1592. if (! is_numeric ( $isid ))
  1593. die ( 'illegal request' );
  1594. Doo::loadModel ( 'invoiceStore' );
  1595. $invoiceStore = new invoiceStore ();
  1596. $item = array (
  1597. 'electronicEmail' => $electronicEmail
  1598. );
  1599. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1600. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1601. }
  1602. /**
  1603. * 仓库发票提交审批
  1604. * @return string
  1605. */
  1606. function invoiceStoreApproval() {
  1607. Doo::loadClass ( 'XDeode' );
  1608. $XDeode = new XDeode ( 5 );
  1609. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1610. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1611. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1612. $isid = $XDeode->decode ( $iStoreKey );
  1613. $trainId = $XDeode->decode ( $trainKey );
  1614. if (! is_numeric ( $isid ))
  1615. die ( 'illegal request' );
  1616. Doo::loadModel ( 'invoiceStore' );
  1617. Doo::loadModel ( 'invoice' );
  1618. $invoice = new invoice ();
  1619. // 加入限制必须填写入开票内容和邮寄物品
  1620. $invoiceStore = new invoiceStore ();
  1621. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1622. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1623. header ( 'Content-Type:text/html;charset=utf-8' );
  1624. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1625. }
  1626. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1627. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1628. header ( 'Content-Type:text/html;charset=utf-8' );
  1629. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1630. }
  1631. }
  1632. // 拷贝插入一条发票数据
  1633. $invoiceStore = new invoiceStore ();
  1634. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1635. $invoiceStore = new invoiceStore ();
  1636. $item = array (
  1637. 'isid' => $isid,
  1638. 'iid' => $iid,
  1639. 'apStatus' => 1
  1640. );
  1641. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1642. Doo::loadModel ( 'invoiceManage' );
  1643. $invoiceManage = new invoiceManage ();
  1644. Doo::loadModel ( 'invoiceOperationLog' );
  1645. $invoiceOperationLog = new invoiceOperationLog ();
  1646. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1647. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1648. $moldManage = array ();
  1649. foreach ( $invoiceManageList as $key => $value ) {
  1650. if ($value ['mold'] == '发票打印')
  1651. $moldManage [$value ['mold']] = $value ['staffList'];
  1652. elseif ($value ['mold'] == '发票邮寄')
  1653. $moldManage [$value ['mold']] = $value ['staffList'];
  1654. elseif ($value ['mold'] == '发票退票')
  1655. $moldManage [$value ['mold']] = $value ['staffList'];
  1656. }
  1657. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1658. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1659. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1660. }else{
  1661. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1662. }
  1663. $item = array (
  1664. 'iid' => $iid,
  1665. 'isid' => $isid,
  1666. 'invoiceSerial' => $invoiceSerial,
  1667. 'date' => date ( "Y-m-d H:i:s" ),
  1668. 'status' => 1,
  1669. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1670. 'trainId' => $trainId,
  1671. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1672. 'moldManage' => json_encode ( $moldManage ),
  1673. 'settlementType' => 1,
  1674. 'pendingApprovals' => $pendingApprovalsSid
  1675. );
  1676. $invoice->setInvoiceByCondition ( $item );
  1677. Doo::loadModel ( 'invoiceTraining' );
  1678. $invoiceTraining = new invoiceTraining ();
  1679. $item = array (
  1680. 'itid' => $trainId,
  1681. 'submitStatus' => 1
  1682. );
  1683. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1684. $item = array (
  1685. 'date' => date ( "Y-m-d H:i:s" ),
  1686. 'operation' => "创建",
  1687. 'status' => 1,
  1688. 'img' => $this->staff [0] ['avatar'],
  1689. 'username' => $this->staff [0] ['username'],
  1690. 'uid' => $this->staff [0] ['sid'],
  1691. 'category' => $this->staff [0] ['category'],
  1692. 'iid' => $iid
  1693. );
  1694. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1695. $item = array (
  1696. 'date' => date ( "Y-m-d H:i:s" ),
  1697. 'operation' => "提交审批",
  1698. 'status' => 1,
  1699. 'img' => $this->staff [0] ['avatar'],
  1700. 'username' => $this->staff [0] ['username'],
  1701. 'uid' => $this->staff [0] ['sid'],
  1702. 'category' => $this->staff [0] ['category'],
  1703. 'iid' => $iid
  1704. );
  1705. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1706. Doo::loadModel ( 'staff' );
  1707. $staff = new staff ();
  1708. $username2 = $staff->getOne ( array (
  1709. 'select' => 'wxid',
  1710. 'where' => 'sid=' . $pendingApprovalsSid,
  1711. 'asArray' => TRUE
  1712. ) );
  1713. // 发送微信审批通知
  1714. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1715. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1716. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1717. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1718. }else{
  1719. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1720. }
  1721. }
  1722. /**
  1723. * 批量提交发票
  1724. * @return string
  1725. */
  1726. function invoiceStoreBatchApproval() {
  1727. Doo::loadClass ( 'XDeode' );
  1728. $XDeode = new XDeode ( 5 );
  1729. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1730. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1731. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1732. if (empty ( $trainKey ) || empty ( $storeKey ))
  1733. die ( 'illegal request-IdKey' );
  1734. $trainId = $XDeode->decode ( $trainKey );
  1735. $isidKeyList = explode ( ',', $storeKey );
  1736. $isidList = array ();
  1737. foreach ( $isidKeyList as $value ) {
  1738. $isid = $XDeode->decode ( $value );
  1739. if (! empty ( $isid ) && is_numeric ( $isid ))
  1740. array_push ( $isidList, $isid );
  1741. }
  1742. $isidString = implode ( ',', $isidList );
  1743. if (! is_numeric ( $trainId ))
  1744. die ( 'illegal request' );
  1745. Doo::loadModel ( 'invoiceStore' );
  1746. Doo::loadModel ( 'invoice' );
  1747. // 判断哪些已经加入审批过
  1748. // 加入限制必须填写入开票内容和邮寄物品
  1749. $invoiceStore = new invoiceStore ();
  1750. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1751. foreach ( $isList as $key => $value ) {
  1752. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1753. header ( 'Content-Type:text/html;charset=utf-8' );
  1754. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1755. }
  1756. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1757. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1758. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1759. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1760. header ( 'Content-Type:text/html;charset=utf-8' );
  1761. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1762. }
  1763. }
  1764. }
  1765. // 拷贝插入一条发票数据
  1766. $invoiceStore = new invoiceStore ();
  1767. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1768. $invoiceStore = new invoiceStore ();
  1769. $item = array (
  1770. 'apStatus' => 1
  1771. );
  1772. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1773. // 获得正式发票ID
  1774. $invoice = new invoice ();
  1775. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1776. $sqlList = array ();
  1777. $iidString = '';
  1778. $iida = array ();
  1779. foreach ( $iidList as $key => $value ) {
  1780. $sqlList [$value ['isid']] = $value ['iid'];
  1781. array_push ( $iida, $value ['iid'] );
  1782. }
  1783. $iidString = implode ( ',', $iida );
  1784. $ids = implode ( ',', array_keys ( $sqlList ) );
  1785. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1786. foreach ( $sqlList as $id => $ordinal ) {
  1787. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1788. }
  1789. $sql .= "END WHERE isid IN ($ids)";
  1790. $invoiceStore = new invoiceStore ();
  1791. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1792. Doo::loadModel ( 'invoiceManage' );
  1793. $invoiceManage = new invoiceManage ();
  1794. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1795. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1796. $moldManage = array ();
  1797. foreach ( $invoiceManageList as $key => $value ) {
  1798. if ($value ['mold'] == '发票打印')
  1799. $moldManage [$value ['mold']] = $value ['staffList'];
  1800. elseif ($value ['mold'] == '发票邮寄')
  1801. $moldManage [$value ['mold']] = $value ['staffList'];
  1802. elseif ($value ['mold'] == '发票退票')
  1803. $moldManage [$value ['mold']] = $value ['staffList'];
  1804. }
  1805. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1806. // 批量更新发票信息
  1807. $item = array (
  1808. 'date' => date ( "Y-m-d H:i:s" ),
  1809. 'status' => 1,
  1810. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1811. 'trainId' => $trainId,
  1812. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1813. 'moldManage' => json_encode ( $moldManage ),
  1814. 'settlementType' => 1,
  1815. 'pendingApprovals' => $pendingApprovalsSid
  1816. );
  1817. $invoice = new invoice ();
  1818. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1819. // 批量更新发票中仓库isid
  1820. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1821. foreach ( $sqlList as $isid => $iid ) {
  1822. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1823. }
  1824. $sql .= "END WHERE iid IN ($iidString)";
  1825. $invoice = new invoice ();
  1826. $invoice->UpdateBatchInvoice ( $sql );
  1827. // 批量更新发票序列号
  1828. $sqlList = array ();
  1829. foreach ( $iida as $value ) {
  1830. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1831. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1832. }else{
  1833. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1834. }
  1835. }
  1836. $ids = implode ( ',', array_keys ( $sqlList ) );
  1837. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1838. foreach ( $sqlList as $id => $ordinal ) {
  1839. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1840. }
  1841. $sql .= "END WHERE iid IN ($ids)";
  1842. $invoiceStore = new invoiceStore ();
  1843. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1844. // 批量生产操作日志
  1845. Doo::loadModel ( 'invoiceOperationLog' );
  1846. $sqlList = array ();
  1847. foreach ( $iida as $key => $value ) {
  1848. $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 . '"),
  1849. ("' . 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 . '") ';
  1850. array_push ( $sqlList, $sql );
  1851. }
  1852. $iolSql = implode ( ',', $sqlList );
  1853. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1854. $invoiceOperationLog = new invoiceOperationLog ();
  1855. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1856. Doo::loadModel ( 'invoiceTraining' );
  1857. $invoiceTraining = new invoiceTraining ();
  1858. $item = array (
  1859. 'itid' => $trainId,
  1860. 'submitStatus' => 1
  1861. );
  1862. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1863. Doo::loadModel ( 'staff' );
  1864. $staff = new staff ();
  1865. $username2 = $staff->getOne ( array (
  1866. 'select' => 'wxid',
  1867. 'where' => 'sid=' . $pendingApprovalsSid,
  1868. 'asArray' => TRUE
  1869. ) );
  1870. // 发送微信审批通知
  1871. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1872. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1873. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1874. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1875. }else{
  1876. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1877. }
  1878. }
  1879. /**
  1880. */
  1881. function invoiceStoreMailItemSet() {
  1882. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1883. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1884. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1885. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1886. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1887. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1888. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1889. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1890. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1891. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1892. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1893. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1894. Doo::loadClass ( 'XDeode' );
  1895. $XDeode = new XDeode ( 5 );
  1896. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1897. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1898. $isid = $XDeode->decode ( $storeKey );
  1899. $trainId = $XDeode->decode ( $trainKey );
  1900. if (! is_numeric ( $isid ))
  1901. die ( 'illegal request' );
  1902. Doo::loadModel ( 'invoiceStore' );
  1903. $invoiceStore = new invoiceStore ();
  1904. $mailList = array (
  1905. 'mailItems' => $mailItems
  1906. );
  1907. $mailString = '发票x1,备注:' . $mailItems;
  1908. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1909. $mailString = '备注:' . $mailItems;
  1910. }else{
  1911. $mailList += array (
  1912. 'invoice' => 1,
  1913. );
  1914. }
  1915. if (! empty ( $softLock ))
  1916. $mailList += array (
  1917. 'softLock' => $softLockNum
  1918. );
  1919. else
  1920. $mailList += array (
  1921. 'softLock' => 0
  1922. );
  1923. if (! empty ( $contract ))
  1924. $mailList += array (
  1925. 'contract' => $contractNum
  1926. );
  1927. else
  1928. $mailList += array (
  1929. 'contract' => 0
  1930. );
  1931. if (! empty ( $instructions ))
  1932. $mailList += array (
  1933. 'instructions' => $instructionsNum
  1934. );
  1935. else
  1936. $mailList += array (
  1937. 'instructions' => 0
  1938. );
  1939. if (! empty ( $remittance ))
  1940. $mailList += array (
  1941. 'remittance' => $remittance
  1942. );
  1943. else
  1944. $mailList += array (
  1945. 'remittance' => ''
  1946. );
  1947. if (! empty ( $softLock ))
  1948. $mailString .= ',软件锁x' . $softLockNum;
  1949. if (! empty ( $contract ))
  1950. $mailString .= ',合同x' . $contractNum;
  1951. if (! empty ( $instructions ))
  1952. $mailString .= ',说明书x' . $instructionsNum;
  1953. if (! empty ( $remittance ))
  1954. $mailString .= ',汇款账号单';
  1955. $item = array (
  1956. 'isid' => $isid,
  1957. 'doPost' => 1,
  1958. 'mailItems' => $mailString,
  1959. 'mailItemsJson' => json_encode ( $mailList )
  1960. );
  1961. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1962. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1963. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1964. }else{
  1965. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1966. }
  1967. }
  1968. /**
  1969. * 批量设置邮寄物品
  1970. */
  1971. function invoiceStoreBatchMailItemSet() {
  1972. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1973. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1974. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1975. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1976. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1977. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1978. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1979. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1980. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1981. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1982. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1983. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1984. Doo::loadClass ( 'XDeode' );
  1985. $XDeode = new XDeode ( 5 );
  1986. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1987. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1988. if (empty ( $trainKey ) || empty ( $storeKey ))
  1989. die ( 'illegal request-IdKey' );
  1990. $isidKeyList = explode ( ',', $storeKey );
  1991. $isidList = array ();
  1992. foreach ( $isidKeyList as $value ) {
  1993. $isid = $XDeode->decode ( $value );
  1994. if (! empty ( $isid ) && is_numeric ( $isid ))
  1995. array_push ( $isidList, $isid );
  1996. }
  1997. $isidString = implode ( ',', $isidList );
  1998. $trainId = $XDeode->decode ( $trainKey );
  1999. if (! is_numeric ( $isid ))
  2000. die ( 'illegal request' );
  2001. Doo::loadModel ( 'invoiceStore' );
  2002. $invoiceStore = new invoiceStore ();
  2003. $mailList = array (
  2004. 'mailItems' => $mailItems
  2005. );
  2006. $mailString = '发票x1,备注:' . $mailItems;
  2007. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2008. $mailString = '备注:' . $mailItems;
  2009. }else{
  2010. $mailList += array (
  2011. 'invoice' => 1,
  2012. );
  2013. }
  2014. if (! empty ( $softLock ))
  2015. $mailList += array (
  2016. 'softLock' => $softLockNum
  2017. );
  2018. else
  2019. $mailList += array (
  2020. 'softLock' => 0
  2021. );
  2022. if (! empty ( $contract ))
  2023. $mailList += array (
  2024. 'contract' => $contractNum
  2025. );
  2026. else
  2027. $mailList += array (
  2028. 'contract' => 0
  2029. );
  2030. if (! empty ( $instructions ))
  2031. $mailList += array (
  2032. 'instructions' => $instructionsNum
  2033. );
  2034. else
  2035. $mailList += array (
  2036. 'instructions' => 0
  2037. );
  2038. if (! empty ( $remittance ))
  2039. $mailList += array (
  2040. 'remittance' => $remittance
  2041. );
  2042. else
  2043. $mailList += array (
  2044. 'remittance' => ''
  2045. );
  2046. if (! empty ( $softLock ))
  2047. $mailString .= ',软件锁x' . $softLockNum;
  2048. if (! empty ( $contract ))
  2049. $mailString .= ',合同x' . $contractNum;
  2050. if (! empty ( $instructions ))
  2051. $mailString .= ',说明书x' . $instructionsNum;
  2052. if (! empty ( $remittance ))
  2053. $mailString .= ',汇款账号单';
  2054. $item = array (
  2055. 'doPost' => 1,
  2056. 'mailItems' => $mailString,
  2057. 'mailItemsJson' => json_encode ( $mailList )
  2058. );
  2059. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2060. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2061. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2062. }else{
  2063. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2064. }
  2065. }
  2066. /**
  2067. * 废弃
  2068. */
  2069. function ajaxGetMailItemByIstore() {
  2070. Doo::loadClass ( 'XDeode' );
  2071. $XDeode = new XDeode ( 5 );
  2072. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2073. $isid = $XDeode->decode ( $storeKey );
  2074. if (! is_numeric ( $isid ))
  2075. die ( 'illegal request' );
  2076. Doo::loadModel ( 'invoiceStore' );
  2077. $invoiceStore = new invoiceStore ();
  2078. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2079. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2080. echo json_encode ( $isDetail ['mailItemsJson'] );
  2081. exit ();
  2082. }
  2083. /**
  2084. * 终止开票
  2085. */
  2086. function invoiceDroppedDo() {
  2087. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2088. Doo::loadModel ( 'invoice' );
  2089. $invoice = new invoice ();
  2090. Doo::loadModel ( 'invoiceOperationLog' );
  2091. $invoiceOperationLog = new invoiceOperationLog ();
  2092. $iid = $invoice->authcode ( $droppedIidKey );
  2093. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2094. die ( 'illegal request' );
  2095. $item = array (
  2096. 'iid' => $iid,
  2097. 'status' => 4,
  2098. 'updateTime' => date ( "Y-m-d H:i:s" )
  2099. );
  2100. $invoice->setInvoiceByCondition ( $item );
  2101. $item = array (
  2102. 'date' => date ( "Y-m-d H:i:s" ),
  2103. 'operation' => '终止了开票',
  2104. 'status' => 4,
  2105. 'img' => $this->staff [0] ['avatar'],
  2106. 'username' => $this->staff [0] ['username'],
  2107. 'uid' => $this->staff [0] ['sid'],
  2108. 'category' => $this->staff [0] ['category'],
  2109. 'iid' => $iid
  2110. );
  2111. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2112. return "/invoice";
  2113. }
  2114. /**
  2115. * 更新退票的邮寄信息
  2116. */
  2117. function invoiceUntreadMailDo() {
  2118. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2119. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2120. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2121. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2122. Doo::loadModel ( 'invoice' );
  2123. $invoice = new invoice ();
  2124. $iid = $invoice->authcode ( $untreadIidKey );
  2125. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2126. die ( 'illegal request' );
  2127. $item = array (
  2128. 'iid' => $iid,
  2129. 'untreadCompany' => $untreadCompany,
  2130. 'untreadNumber' => $untreadNumber,
  2131. 'untreadItems' => $untreadItems
  2132. );
  2133. $invoice->setInvoiceByCondition ( $item );
  2134. return "/invoice";
  2135. }
  2136. /**
  2137. * 申请退票 --
  2138. */
  2139. function invoiceUntreadDo() {
  2140. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2141. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2142. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  2143. Doo::loadModel ( 'invoice' );
  2144. $invoice = new invoice ();
  2145. Doo::loadModel ( 'invoiceOperationLog' );
  2146. $invoiceOperationLog = new invoiceOperationLog ();
  2147. Doo::loadModel ( 'invoiceReceivables' );
  2148. $invoiceReceivables = new invoiceReceivables ();
  2149. $iid = $invoice->authcode ( $untreadIidKey );
  2150. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2151. die ( 'illegal request' );
  2152. /*
  2153. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2154. */
  2155. $item = array (
  2156. 'iid' => $iid,
  2157. 'untreadStatus' => 1,
  2158. 'untreadReason' => $untreadReason,
  2159. 'untreadPost' => $untreadPost,
  2160. 'updateTime' => date ( "Y-m-d H:i:s" )
  2161. );
  2162. $invoice->setInvoiceByCondition ( $item );
  2163. $item = array (
  2164. 'date' => date ( "Y-m-d H:i:s" ),
  2165. 'operation' => '申请退票',
  2166. 'status' => 7,
  2167. 'img' => $this->staff [0] ['avatar'],
  2168. 'username' => $this->staff [0] ['username'],
  2169. 'uid' => $this->staff [0] ['sid'],
  2170. 'category' => $this->staff [0] ['category'],
  2171. 'iid' => $iid
  2172. );
  2173. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2174. return "/invoice";
  2175. }
  2176. /**
  2177. * 删除已终止的开票
  2178. */
  2179. function invoiceDelDo() {
  2180. Doo::loadModel ( 'invoice' );
  2181. $invoice = new invoice ();
  2182. Doo::loadModel ( 'invoiceOperationLog' );
  2183. $invoiceOperationLog = new invoiceOperationLog ();
  2184. Doo::loadClass ( 'XDeode' );
  2185. $XDeode = new XDeode ( 5 );
  2186. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2187. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2188. $iid = $XDeode->decode ( $iid );
  2189. Doo::loadModel ( 'invoiceStore' );
  2190. $invoiceStore = new invoiceStore ();
  2191. if (! is_numeric ( $iid ))
  2192. die ( 'illegal request' );
  2193. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2194. if (empty ( $invoiceDetail ))
  2195. die ( 'illegal request' );
  2196. $item = array (
  2197. 'iid' => $iid,
  2198. 'isDelete' => 1,
  2199. 'updateTime' => date ( "Y-m-d H:i:s" )
  2200. );
  2201. $invoice->setInvoiceByCondition ( $item );
  2202. $item = array (
  2203. 'date' => date ( "Y-m-d H:i:s" ),
  2204. 'operation' => '删除了已终止的发票',
  2205. 'status' => 4,
  2206. 'img' => $this->staff [0] ['avatar'],
  2207. 'username' => $this->staff [0] ['username'],
  2208. 'uid' => $this->staff [0] ['sid'],
  2209. 'category' => $this->staff [0] ['category'],
  2210. 'iid' => $iid
  2211. );
  2212. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2213. // 删除培训班发票仓库里的发票
  2214. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2215. return "/invoice";
  2216. }
  2217. /**
  2218. */
  2219. function invoiceApproval() {
  2220. Doo::loadModel ( 'invoice' );
  2221. $invoice = new invoice ();
  2222. Doo::loadClass ( 'XDeode' );
  2223. $XDeode = new XDeode ( 5 );
  2224. Doo::loadModel ( 'staff' );
  2225. $staff = new staff ();
  2226. $invoiceList = $invoice->find ( array (
  2227. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2228. 'desc' => 'iid',
  2229. 'limit' => 10,
  2230. 'asArray' => true
  2231. ) );
  2232. foreach ( $invoiceList as $key => $value ) {
  2233. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2234. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2235. if (! empty ( $lastApprover )) {
  2236. $lastApproverKey = array_keys ( $lastApprover );
  2237. $lastApprover = end ( $lastApprover );
  2238. $staffDetail = $staff->getOne ( array (
  2239. 'where' => 'sid=' . end ( $lastApproverKey ),
  2240. 'asArray' => true
  2241. ) );
  2242. $lastApprover ['username'] = $staffDetail ['username'];
  2243. }
  2244. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2245. }
  2246. $ilist = $invoice->getInvoiceByProcessStatus ();
  2247. foreach ( $ilist as $key => $value ) {
  2248. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2249. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2250. if (! empty ( $lastApprover )) {
  2251. $lastApproverKey = array_keys ( $lastApprover );
  2252. $lastApprover = end ( $lastApprover );
  2253. $staffDetail = $staff->getOne ( array (
  2254. 'where' => 'sid=' . end ( $lastApproverKey ),
  2255. 'asArray' => true
  2256. ) );
  2257. $lastApprover ['username'] = $staffDetail ['username'];
  2258. }
  2259. $ilist [$key] ['lastApprover'] = $lastApprover;
  2260. }
  2261. // print_r($ilist);
  2262. $this->data ['invoiceList'] = $invoiceList;
  2263. $this->data ['ilist'] = $ilist;
  2264. $this->data ['memu'] = "invoice";
  2265. $this->data ['staff'] = $this->staff;
  2266. $this->data ['receiptMemu'] = 'invoiceApproval';
  2267. $this->render ( "/admin/invoiceApproval", $this->data );
  2268. }
  2269. function invoiceDetail() {
  2270. Doo::loadClass ( 'XDeode' );
  2271. $XDeode = new XDeode ( 5 );
  2272. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2273. $iid = $XDeode->decode ( $iid );
  2274. if (! is_numeric ( $iid ))
  2275. die ( 'illegal request' );
  2276. Doo::loadModel ( 'invoice' );
  2277. $invoice = new invoice ();
  2278. Doo::loadModel ( 'invoiceOperationLog' );
  2279. $invoiceOperationLog = new invoiceOperationLog ();
  2280. $invoiceDetail = $invoice->getOne ( array (
  2281. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2282. 'asArray' => true
  2283. ) );
  2284. if (empty ( $invoiceDetail ))
  2285. die ( 'illegal request' );
  2286. if ($invoiceDetail ['settlementType'] == 1) {
  2287. Doo::loadModel ( 'invoiceTraining' );
  2288. $invoiceTraining = new invoiceTraining ();
  2289. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2290. }
  2291. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2292. $this->data ['invoiceDetail'] = $invoiceDetail;
  2293. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2294. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2295. $this->data ['memu'] = "invoice";
  2296. $this->data ['staff'] = $this->staff;
  2297. $this->data ['receiptMemu'] = 'invoiceApproval';
  2298. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2299. }
  2300. /**
  2301. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2302. *
  2303. * @since 1.0.0
  2304. * @var integer iid 开票ID 已加密
  2305. * @var integer status 发票审批状态
  2306. * @var integer opintion 审批发票的意见
  2307. * @return string 如操作成功返回审批首页
  2308. */
  2309. function invoiceApprovalDo() {
  2310. Doo::loadModel ( 'invoice' );
  2311. $invoice = new invoice ();
  2312. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2313. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2314. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2315. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2316. $iid = $invoice->authcode ( $iid );
  2317. if (! is_numeric ( $iid ))
  2318. die ( 'illegal request' );
  2319. // && ! empty ( $opinion )
  2320. if (! empty ( $iid ) && ! empty ( $status )) {
  2321. if (! ($status == 2 || $status == 3 || $status == 4))
  2322. die ( 'illegal request' );
  2323. Doo::loadModel ( 'invoiceOperationLog' );
  2324. $invoiceOperationLog = new invoiceOperationLog ();
  2325. $invoiceDetail = $invoice->getOne ( array (
  2326. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2327. 'asArray' => true
  2328. ) );
  2329. if (empty ( $invoiceDetail ))
  2330. die ( 'illegal request' );
  2331. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2332. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2333. if ($status == 3) {
  2334. $invoice->status = $status;
  2335. $item = array (
  2336. 'operation' => $opinion
  2337. );
  2338. } else {
  2339. if (empty ( $processApprovals )) {
  2340. $processApprovals = array (
  2341. $this->staff [0] ['sid'] => array (
  2342. 'date' => date ( "Y-m-d H:i:s" ),
  2343. 'opinion' => $opinion,
  2344. 'status' => $status
  2345. )
  2346. );
  2347. // var_dump(next($invoiceManage));
  2348. $nextInvoiceManage = next ( $invoiceManage );
  2349. // print_r($nextInvoiceManage);
  2350. if ($status != 4 && $nextInvoiceManage !== false)
  2351. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2352. $invoice->processApprovals = json_encode ( $processApprovals );
  2353. // var_dump($invoice);
  2354. // print_r($invoiceManage);
  2355. } else {
  2356. $processApprovals [$this->staff [0] ['sid']] = array (
  2357. 'date' => date ( "Y-m-d H:i:s" ),
  2358. 'opinion' => $opinion,
  2359. 'status' => $status
  2360. );
  2361. $pendingApprovals = 0;
  2362. foreach ( $invoiceManage as $key => $value ) {
  2363. if ($value [0] == $this->staff [0] ['sid']) {
  2364. if (isset ( $invoiceManage [$key + 1] ))
  2365. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2366. break;
  2367. }
  2368. }
  2369. if ($status != 4 && ! empty ( $pendingApprovals ))
  2370. $invoice->pendingApprovals = $pendingApprovals;
  2371. $invoice->processApprovals = json_encode ( $processApprovals );
  2372. }
  2373. $item = array (
  2374. 'operation' => $opinion
  2375. );
  2376. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2377. $invoice->status = $status;
  2378. $invoice->pendingApprovals = 0;
  2379. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2380. } elseif ($status == 4) {
  2381. $invoice->status = $status;
  2382. $item = array (
  2383. 'operation' => $opinion
  2384. );
  2385. }
  2386. }
  2387. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2388. $invoice->update ( array (
  2389. 'where' => 'iid=' . $iid
  2390. ) );
  2391. $item += array (
  2392. 'date' => date ( "Y-m-d H:i:s" ),
  2393. 'img' => $this->staff [0] ['avatar'],
  2394. 'username' => $this->staff [0] ['username'],
  2395. 'uid' => $this->staff [0] ['sid'],
  2396. 'category' => $this->staff [0] ['category'],
  2397. 'status' => $status,
  2398. 'iid' => $iid
  2399. );
  2400. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2401. if (empty ( $divApproval ))
  2402. return '/invoiceApproval';
  2403. else
  2404. return '/invoiceApprovalAchieve/PEND';
  2405. }
  2406. die ( 'illegal request' );
  2407. }
  2408. /**
  2409. * 展示需要打印的发票数据
  2410. *
  2411. * @since 1.0.0
  2412. */
  2413. function invoicePrint() {
  2414. Doo::loadModel ( 'invoice' );
  2415. $invoice = new invoice ();
  2416. Doo::loadClass ( 'XDeode' );
  2417. $XDeode = new XDeode ( 5 );
  2418. Doo::loadModel ( 'staff' );
  2419. $staff = new staff ();
  2420. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2421. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2422. foreach ( $toPrint as $key => $value ) {
  2423. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2424. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2425. if (! empty ( $lastApprover )) {
  2426. $lastApproverKey = array_keys ( $lastApprover );
  2427. $lastApprover = end ( $lastApprover );
  2428. $staffDetail = $staff->getOne ( array (
  2429. 'where' => 'sid=' . end ( $lastApproverKey ),
  2430. 'asArray' => true
  2431. ) );
  2432. $lastApprover ['username'] = $staffDetail ['username'];
  2433. }
  2434. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2435. }
  2436. foreach ( $printed as $key => $value ) {
  2437. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2438. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2439. if (! empty ( $lastApprover )) {
  2440. $lastApproverKey = array_keys ( $lastApprover );
  2441. $lastApprover = end ( $lastApprover );
  2442. $staffDetail = $staff->getOne ( array (
  2443. 'where' => 'sid=' . end ( $lastApproverKey ),
  2444. 'asArray' => true
  2445. ) );
  2446. $lastApprover ['username'] = $staffDetail ['username'];
  2447. }
  2448. $printed [$key] ['lastApprover'] = $lastApprover;
  2449. }
  2450. $this->data ['printed'] = $printed;
  2451. $this->data ['toPrint'] = $toPrint;
  2452. $this->data ['memu'] = "invoice";
  2453. $this->data ['staff'] = $this->staff;
  2454. $this->data ['receiptMemu'] = 'invoicePrint';
  2455. $this->render ( "/admin/invoicePrint", $this->data );
  2456. }
  2457. /**
  2458. * 展示发票打印的详情页面
  2459. *
  2460. * @since 1.0.0
  2461. */
  2462. function invoicePrintDetail() {
  2463. Doo::loadClass ( 'XDeode' );
  2464. $XDeode = new XDeode ( 5 );
  2465. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2466. $iid = $XDeode->decode ( $iid );
  2467. if (! is_numeric ( $iid ))
  2468. die ( 'illegal request' );
  2469. Doo::loadModel ( 'invoice' );
  2470. $invoice = new invoice ();
  2471. Doo::loadModel ( 'invoiceOperationLog' );
  2472. $invoiceOperationLog = new invoiceOperationLog ();
  2473. Doo::loadModel ( 'invoicePaper' );
  2474. $invoicePaper = new invoicePaper ();
  2475. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2476. if (empty ( $invoiceDetail ))
  2477. die ( 'illegal request' );
  2478. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2479. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2480. if ($invoiceDetail ['settlementType'] == 1) {
  2481. Doo::loadModel ( 'invoiceTraining' );
  2482. $invoiceTraining = new invoiceTraining ();
  2483. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2484. }
  2485. $this->data ['invoicePaperList'] = $invoicePaperList;
  2486. $this->data ['invoiceDetail'] = $invoiceDetail;
  2487. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2488. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2489. $this->data ['memu'] = "invoice";
  2490. $this->data ['staff'] = $this->staff;
  2491. $this->data ['receiptMemu'] = 'invoicePrint';
  2492. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2493. }
  2494. /**
  2495. * 所有待打印 发票
  2496. */
  2497. function invoicePrintStayAchieve() {
  2498. Doo::loadModel ( 'invoice' );
  2499. $invoice = new invoice ();
  2500. Doo::loadClass ( 'XDeode' );
  2501. $XDeode = new XDeode ( 5 );
  2502. Doo::loadModel ( 'staff' );
  2503. $staff = new staff ();
  2504. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2505. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2506. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2507. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2508. Doo::loadModel ( 'invoiceTraining' );
  2509. $invoiceTraining = new invoiceTraining ();
  2510. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2511. $page_size = 12;
  2512. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2513. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2514. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2515. $get = "/" . $status;
  2516. $con = ' and status=2 ';
  2517. if ($status == 'TOPRINT')
  2518. $con = ' and status=2 and printStatus=0 ';
  2519. elseif ($status == 'PRINTED')
  2520. $con = ' and status=2 and printStatus=1';
  2521. if ($invoiceType == 'ORDINARY')
  2522. $con .= ' and invoiceType=0 ';
  2523. elseif ($invoiceType == 'SPECIAL')
  2524. $con .= ' and invoiceType=1 ';
  2525. if ($invoiceTrain == 'ORDINARY')
  2526. $con .= ' and trainId=0 ';
  2527. elseif ($invoiceTrain == 'TRAIN')
  2528. $con .= ' and trainId!=0 ';
  2529. if ($invoiceTrainName != 'ALL') {
  2530. $trainId = $XDeode->decode ( $invoiceTrainName );
  2531. if (is_numeric ( $trainId ))
  2532. $con .= ' and trainId =' . $trainId;
  2533. }
  2534. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2535. $dateArr = explode ( ':', $date );
  2536. $D1 = '';
  2537. $D2 = '';
  2538. if (! empty ( $date )) {
  2539. $D1 = $dateArr [0];
  2540. $D2 = $dateArr [1];
  2541. }
  2542. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2543. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2544. if (! empty ( $MebSea )) {
  2545. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2546. }
  2547. $pageinfo ['page'] = array (
  2548. 'previous' => ''
  2549. );
  2550. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2551. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2552. $action = "invoicePrintStayAchieve";
  2553. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2554. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2555. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2556. $this->data ['trainList'] = $trainList;
  2557. $this->data ['invoiceType'] = $invoiceType;
  2558. $this->data ['invoiceTrain'] = $invoiceTrain;
  2559. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2560. $this->data ['MebSeaEn'] = $MebSea;
  2561. $this->data ['MebSea'] = urlencode ( $MebSea );
  2562. $this->data ['get'] = $get;
  2563. $this->data ['page'] = $pageinfo;
  2564. $this->data ['date'] = $date;
  2565. $this->data ['status'] = $status;
  2566. $this->data ['invoiceType'] = $invoiceType;
  2567. $this->data ['memu'] = "invoice";
  2568. $this->data ['staff'] = $this->staff;
  2569. foreach ( $list as $key => $value ) {
  2570. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2571. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2572. if (! empty ( $lastApprover )) {
  2573. $lastApproverKey = array_keys ( $lastApprover );
  2574. $lastApprover = end ( $lastApprover );
  2575. $staffDetail = $staff->getOne ( array (
  2576. 'where' => 'sid=' . end ( $lastApproverKey ),
  2577. 'asArray' => true
  2578. ) );
  2579. $lastApprover ['username'] = $staffDetail ['username'];
  2580. }
  2581. $list [$key] ['lastApprover'] = $lastApprover;
  2582. }
  2583. $this->data ['receiptMemu'] = 'invoicePrint';
  2584. $this->data ['list'] = $list;
  2585. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2586. }
  2587. /**
  2588. * 填写票号并完成打印
  2589. * @since 1.0.0
  2590. */
  2591. function invoicePrintDo() {
  2592. Doo::loadModel ( 'invoice' );
  2593. $invoice = new invoice ();
  2594. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2595. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2596. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2597. $iid = $invoice->authcode ( $iid );
  2598. if (! is_numeric ( $iid ))
  2599. die ( 'illegal request' );
  2600. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2601. Doo::loadModel ( 'invoiceOperationLog' );
  2602. $invoiceOperationLog = new invoiceOperationLog ();
  2603. Doo::loadModel ( 'invoiceStatistics' );
  2604. $invoiceStatistics = new invoiceStatistics ();
  2605. $XDeode = new XDeode ( 5 );
  2606. Doo::loadModel ( 'invoicePaper' );
  2607. $invoicePaper = new invoicePaper ();
  2608. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2609. if (empty ( $invoicePrintDetail ))
  2610. die ( 'illegal request' );
  2611. //
  2612. $ipid = $XDeode->decode ( $invoiceNo );
  2613. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2614. if (empty ( $paperDetail ))
  2615. die ( 'illegal request' );
  2616. $invoicePaper = new invoicePaper ();
  2617. $item = array (
  2618. 'iid' => $iid,
  2619. 'ipid' => $ipid
  2620. );
  2621. $invoicePaper->setInvoicePaperByCondition ( $item );
  2622. $item = array (
  2623. 'iid' => $iid,
  2624. 'printStatus' => 1,
  2625. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2626. 'printer' => $this->staff [0] ['username'],
  2627. 'printTime' => date ( "Y-m-d H:i:s" ),
  2628. 'invoiceNo' => $paperDetail ['invoiceNo']
  2629. );
  2630. $invoice->setInvoiceByCondition ( $item );
  2631. $item = array (
  2632. 'date' => date ( "Y-m-d H:i:s" ),
  2633. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2634. 'status' => 5,
  2635. 'img' => $this->staff [0] ['avatar'],
  2636. 'username' => $this->staff [0] ['username'],
  2637. 'uid' => $this->staff [0] ['sid'],
  2638. 'category' => $this->staff [0] ['category'],
  2639. 'iid' => $iid
  2640. );
  2641. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2642. // 去统计--负票不汇总
  2643. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2644. $item = array (
  2645. 'date' => date ( "Y-m-d H:i:s" ),
  2646. 'priceClass' => 1,
  2647. 'cid' => $invoicePrintDetail ['cid'],
  2648. 'staff' => $invoicePrintDetail ['sid'],
  2649. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2650. );
  2651. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2652. }
  2653. // 发送通知信息到微信-去除
  2654. // $this->setWXMsg($iid,'PRINT');
  2655. // 发票信息库
  2656. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2657. // 申请人获取微信通知
  2658. Doo::loadModel ( 'staff' );
  2659. $staff = new staff ();
  2660. Doo::loadClass ( 'XDeode' );
  2661. $XDeode = new XDeode ( 5 );
  2662. $username2 = $staff->getOne ( array (
  2663. 'select' => 'wxid',
  2664. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2665. 'asArray' => TRUE
  2666. ) );
  2667. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2668. $msg = '';
  2669. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2670. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2671. if (empty ( $invoicePrintType ))
  2672. return "/invoicePrint";
  2673. else
  2674. return "/invoicePrintStayAchieve";
  2675. }
  2676. }
  2677. /**
  2678. * 需要邮寄的发票
  2679. * @since 1.0.0
  2680. */
  2681. function invoicePost() {
  2682. Doo::loadModel ( 'invoice' );
  2683. $invoice = new invoice ();
  2684. Doo::loadModel ( 'express' );
  2685. $express = new express ();
  2686. $invoicePost = $invoice->getPostByInvoice ();
  2687. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2688. $expressList = $express->getExpressByAll ();
  2689. $invoicePostExpress = "";
  2690. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2691. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2692. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2693. $this->data ['expressList'] = $expressList;
  2694. $this->data ['invoicePost'] = $invoicePost;
  2695. $this->data ['invoicePosted'] = $invoicePosted;
  2696. $this->data ['memu'] = "invoice";
  2697. $this->data ['staff'] = $this->staff;
  2698. $this->data ['receiptMemu'] = 'invoicePost';
  2699. $this->render ( "/admin/invoicePost", $this->data );
  2700. }
  2701. /**
  2702. * 添加发票邮寄信息
  2703. */
  2704. function invoiceExpressAddDo() {
  2705. Doo::loadModel ( 'invoice' );
  2706. $invoice = new invoice ();
  2707. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2708. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2709. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2710. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2711. $iid = $iid = $invoice->authcode ( $iid );
  2712. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2713. die ( 'illegal request' );
  2714. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2715. setcookie ( 'invoicePostExpress', $expressNumber );
  2716. $item = array (
  2717. 'iid' => $iid,
  2718. 'postStatus' => 1,
  2719. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2720. 'postTime' => date ( "Y-m-d H:i:s" ),
  2721. 'expressCompany' => $expressCompany,
  2722. 'expressNumber' => $expressNumber,
  2723. 'actualItems' => $actualItems,
  2724. 'poster' => $this->staff [0] ['username']
  2725. );
  2726. $invoice->setInvoiceByCondition ( $item );
  2727. // 微信通知-去掉
  2728. // $this->setWXMsg ( $iid );
  2729. Doo::loadModel ( 'staff' );
  2730. $staff = new staff ();
  2731. Doo::loadClass ( 'XDeode' );
  2732. $XDeode = new XDeode ( 5 );
  2733. $username2 = $staff->getOne ( array (
  2734. 'select' => 'wxid',
  2735. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2736. 'asArray' => TRUE
  2737. ) );
  2738. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2739. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2740. if (empty ( $expCom ))
  2741. $expCom [0] = '';
  2742. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2743. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2744. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2745. return '/invoicePost';
  2746. }
  2747. function invoiceExpressUpdateDo() {
  2748. Doo::loadModel ( 'invoice' );
  2749. $invoice = new invoice ();
  2750. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2751. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2752. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2753. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2754. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2755. $iid = $invoice->authcode ( $iid );
  2756. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2757. die ( 'illegal request' );
  2758. $item = array (
  2759. 'iid' => $iid,
  2760. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2761. 'expressCompany' => $expressCompany,
  2762. 'expressNumber' => $expressNumber,
  2763. 'actualItems' => $actualItems,
  2764. 'poster' => $this->staff [0] ['username']
  2765. );
  2766. $invoice->setInvoiceByCondition ( $item );
  2767. return $action;
  2768. }
  2769. /**
  2770. * 可退票管理
  2771. */
  2772. function invoiceUntreadIsAchieve() {
  2773. Doo::loadModel ( 'invoice' );
  2774. $invoice = new invoice ();
  2775. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2776. /*
  2777. * Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $page_size = 18; $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1; $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : ""; $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ); $dateArr = explode ( ':', $date ); $D1 = ''; $D2 = ''; if (! empty ( $date )) { $D1 = $dateArr [0]; $D2 = $dateArr [1]; } $con = ''; if (! empty ( $D1 ) && ! empty ( $D2 )) $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" '; // if ($date == 'MONTHO') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'; // elseif ($date == 'MONTHT') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)'; // elseif ($date == 'MONTHY') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)'; if (! empty ( $MebSea )) { $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )'; } $pageinfo ['page'] = array ( 'previous' => '' );
  2778. */
  2779. if (empty ( $MebSea )) {//
  2780. $con = ' and invoiceNo like "NULL" ';
  2781. } else {
  2782. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2783. }
  2784. // printStatus=1 and
  2785. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2786. /*
  2787. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2788. */
  2789. $limit = '0,20';
  2790. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2791. //print_r($list);
  2792. $this->data ['MebSeaEn'] = $MebSea;
  2793. /*
  2794. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2795. */
  2796. $this->data ['list'] = $list;
  2797. $this->data ['memu'] = "invoice";
  2798. $this->data ['staff'] = $this->staff;
  2799. $this->data ['receiptMemu'] = 'invoice';
  2800. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2801. }
  2802. // 已经退票的发票
  2803. function invoiceUntreadED() {
  2804. Doo::loadModel ( 'invoice' );
  2805. $invoice = new invoice ();
  2806. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2807. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2808. Doo::loadClass ( 'XDeode' );
  2809. $XDeode = new XDeode ( 5 );
  2810. $page_size = 18;
  2811. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2812. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2813. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2814. $dateArr = explode ( ':', $date );
  2815. $D1 = '';
  2816. $D2 = '';
  2817. if (! empty ( $date )) {
  2818. $D1 = $dateArr [0];
  2819. $D2 = $dateArr [1];
  2820. }
  2821. $con = '';
  2822. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2823. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2824. }
  2825. // if ($date == 'MONTHO')
  2826. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2827. // elseif ($date == 'MONTHT')
  2828. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2829. // elseif ($date == 'MONTHY')
  2830. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2831. if (! empty ( $MebSea )) {
  2832. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2833. }
  2834. if ($invoiceType == 'ORDINARY') {
  2835. $con .= ' and invoiceType=0 ';
  2836. } elseif ($invoiceType == 'SPECIAL') {
  2837. $con .= ' and invoiceType=1 ';
  2838. }
  2839. $pageinfo ['page'] = array (
  2840. 'previous' => ''
  2841. );
  2842. // printStatus=1 and
  2843. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2844. $action = "invoiceUntreadED";
  2845. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2846. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2847. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2848. // print_r($list);
  2849. $this->data ['MebSeaEn'] = $MebSea;
  2850. $this->data ['get'] = $get;
  2851. $this->data ['page'] = $pageinfo;
  2852. $this->data ['date'] = $date;
  2853. $this->data ['invoiceType'] = $invoiceType;
  2854. $this->data ['list'] = $list;
  2855. $this->data ['memu'] = "invoice";
  2856. $this->data ['staff'] = $this->staff;
  2857. $this->data ['receiptMemu'] = 'invoice';
  2858. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2859. }
  2860. /**
  2861. * 退票处理页面
  2862. */
  2863. function invoiceUntread() {
  2864. Doo::loadModel ( 'invoice' );
  2865. $invoice = new invoice ();
  2866. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2867. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2868. foreach ( $establishedInvoice as $key => $value ) {
  2869. // months
  2870. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2871. $nowDate = strtotime ( 'now' );
  2872. $establishedInvoice [$key] ['lossShow'] = false;
  2873. if ($lossDate < $nowDate)
  2874. $establishedInvoice [$key] ['lossShow'] = true;
  2875. }
  2876. $this->data ['untreadInvoice'] = $untreadInvoice;
  2877. $this->data ['establishedInvoice'] = $establishedInvoice;
  2878. $this->data ['memu'] = "invoice";
  2879. $this->data ['staff'] = $this->staff;
  2880. $this->data ['receiptMemu'] = 'invoiceUntread';
  2881. $this->render ( "/admin/invoiceUntread", $this->data );
  2882. }
  2883. /**
  2884. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2885. */
  2886. function invoiceUntreadEstablishedDo() {
  2887. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2888. Doo::loadModel ( 'invoice' );
  2889. $invoice = new invoice ();
  2890. Doo::loadModel ( 'invoiceOperationLog' );
  2891. $invoiceOperationLog = new invoiceOperationLog ();
  2892. Doo::loadModel ( 'invoiceReceivables' );
  2893. Doo::loadModel ( 'invoiceStatistics' );
  2894. $iid = $invoice->authcode ( $untreadIidKey );
  2895. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2896. die ( 'illegal request' );
  2897. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2898. if ($invoiceDetails ['untreadStatus'] != 1)
  2899. die ( 'illegal request untreadStatus error !=1' );
  2900. $item = array (
  2901. 'iid' => $iid,
  2902. // 'irid'=>'',
  2903. 'untreadStatus' => 2,
  2904. 'updateTime' => date ( "Y-m-d H:i:s" )
  2905. );
  2906. $invoice->setInvoiceByCondition ( $item );
  2907. $item = array (
  2908. 'date' => date ( "Y-m-d H:i:s" ),
  2909. 'operation' => '已确认退票',
  2910. 'status' => 6,
  2911. 'img' => $this->staff [0] ['avatar'],
  2912. 'username' => $this->staff [0] ['username'],
  2913. 'uid' => $this->staff [0] ['sid'],
  2914. 'category' => $this->staff [0] ['category'],
  2915. 'iid' => $iid
  2916. );
  2917. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2918. // 收款解绑以及入账扣除 收款扣除
  2919. if (! empty ( $invoiceDetails ['irid'] )) {
  2920. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2921. foreach ( $iridList as $value ) {
  2922. $invoiceReceivables = new invoiceReceivables ();
  2923. $irDetails = $invoiceReceivables->getOne ( array (
  2924. 'where' => " irid=" . $value . ' and bindStatus=1',
  2925. 'asArray' => TRUE
  2926. ) );
  2927. $item = array (
  2928. 'irid' => $value,
  2929. 'bindStatus' => 0,
  2930. 'untreadStatus' => 1,
  2931. 'untreadStaff' => $invoiceDetails ['userName'],
  2932. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2933. 'iid' => 0
  2934. );
  2935. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2936. if (! empty ( $irDetails )) {
  2937. // 扣除入账
  2938. $invoiceStatistics = new invoiceStatistics ();
  2939. $item = array (
  2940. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2941. 'priceClass' => 3,
  2942. 'cid' => $invoiceDetails ['cid'],
  2943. 'staff' => $invoiceDetails ['sid'],
  2944. 'accountPrice' => - $irDetails ['receivablesPrice']
  2945. );
  2946. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2947. // 扣除收款
  2948. $invoiceStatistics = new invoiceStatistics ();
  2949. $item = array (
  2950. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2951. 'priceClass' => 2,
  2952. 'cid' => $invoiceDetails ['cid'],
  2953. 'staff' => $invoiceDetails ['sid'],
  2954. 'irid' => $irDetails ['irid'],
  2955. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2956. );
  2957. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2958. }
  2959. // 解绑时删除收入流水
  2960. Doo::loadModel ( 'wasteBook' );
  2961. $wasteBook = new wasteBook ();
  2962. $wasteBook->delete ( array (
  2963. 'where' => 'dataID=' . $value . ' and accountType=7',
  2964. 'limit' => 1
  2965. ) );
  2966. }
  2967. }
  2968. return "/invoiceUntread";
  2969. }
  2970. function invoiceUntreadRecallDo() {
  2971. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2972. Doo::loadModel ( 'invoice' );
  2973. $invoice = new invoice ();
  2974. Doo::loadClass ( 'XDeode' );
  2975. $XDeode = new XDeode ( 5 );
  2976. Doo::loadModel ( 'invoiceOperationLog' );
  2977. $invoiceOperationLog = new invoiceOperationLog ();
  2978. $iid = $XDeode->decode ( $iidKey );
  2979. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2980. if (empty ( $invoiceDetail )) {
  2981. die ( 'illegal request-DATANULL' );
  2982. }
  2983. $item = array (
  2984. 'iid' => $iid,
  2985. 'untreadStatus' => 0
  2986. );
  2987. $invoice->setInvoiceByCondition ( $item );
  2988. $item = array (
  2989. 'date' => date ( "Y-m-d H:i:s" ),
  2990. 'operation' => '撤回申请退票',
  2991. 'status' => 13,
  2992. 'img' => $this->staff [0] ['avatar'],
  2993. 'username' => $this->staff [0] ['username'],
  2994. 'uid' => $this->staff [0] ['sid'],
  2995. 'category' => $this->staff [0] ['category'],
  2996. 'iid' => $iid
  2997. );
  2998. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2999. return "/invoiceUntread";
  3000. }
  3001. /**
  3002. * 建立负票,关联原来发票
  3003. */
  3004. function invoiceLossDo() {
  3005. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3006. if (! empty ( $iidKey )) {
  3007. Doo::loadClass ( 'XDeode' );
  3008. $XDeode = new XDeode ( 5 );
  3009. Doo::loadModel ( 'invoice' );
  3010. $invoice = new invoice ();
  3011. Doo::loadModel ( 'invoiceOperationLog' );
  3012. $invoiceOperationLog = new invoiceOperationLog ();
  3013. $iidKey = $XDeode->decode ( $iidKey );
  3014. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3015. // 拷贝插入一条发票数据
  3016. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3017. // 更新负票
  3018. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3019. $invoice = new invoice ();
  3020. $item = array (
  3021. 'iid' => $iid,
  3022. 'sid' => $this->staff [0] ['sid'],
  3023. 'userName' => $this->staff [0] ['username'],
  3024. 'cid' => $this->staff [0] ['cid'],
  3025. 'categoryName' => $this->staff [0] ['category'],
  3026. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3027. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3028. 'invoiceSerial' => $invoiceSerial,
  3029. 'invoiceNo' => '',
  3030. 'printStatus' => 0,
  3031. 'untreadStatus' => 4,
  3032. // 关联发票号
  3033. 'lossIid' => $invoiceDetail ['iid']
  3034. );
  3035. $invoice->setInvoiceByCondition ( $item );
  3036. // 更新原发票
  3037. $invoice = new invoice ();
  3038. $item = array (
  3039. 'iid' => $invoiceDetail ['iid'],
  3040. 'lossIid' => $iid
  3041. );
  3042. $invoice->setInvoiceByCondition ( $item );
  3043. // 操作日志
  3044. $item = array (
  3045. 'date' => date ( "Y-m-d H:i:s" ),
  3046. 'operation' => "创建负票" . $invoiceSerial,
  3047. 'status' => 12,
  3048. 'img' => $this->staff [0] ['avatar'],
  3049. 'username' => $this->staff [0] ['username'],
  3050. 'uid' => $this->staff [0] ['sid'],
  3051. 'category' => $this->staff [0] ['category'],
  3052. 'iid' => $iid
  3053. );
  3054. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3055. // print_r($invoiceDetail);
  3056. // echo $iid;die;
  3057. }
  3058. return '/invoiceUntread';
  3059. }
  3060. /**
  3061. * 上传银行到账 收款文件
  3062. */
  3063. function invoiceReceivablesBankUpload() {
  3064. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3065. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3066. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3067. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3068. header ( "HTTP/1.1 500 Internal Server Error" );
  3069. echo "POST exceeded maximum allowed size.";
  3070. exit ( 0 );
  3071. }
  3072. // Settings
  3073. $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)
  3074. $upload_name = "Filedata";
  3075. $file_name = "";
  3076. $nk = time ();
  3077. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3078. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3079. echo "文件无法保存.";
  3080. exit ( 0 );
  3081. }
  3082. echo json_encode ( array (
  3083. 'filename' => $file_name,
  3084. 'id' => $nk
  3085. ) );
  3086. exit ( 0 );
  3087. }
  3088. /**
  3089. * 解析银行到账收款execl并导入库中
  3090. */
  3091. function invoiceReceivablesImport() {
  3092. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3093. if ($path != "") {
  3094. Doo::loadModel ( 'invoiceReceivables' );
  3095. $invoiceReceivables = new invoiceReceivables ();
  3096. Doo::loadClass ( 'invoice.func' );
  3097. Doo::loadModel ( 'invoiceROLog' );
  3098. $invoiceROLog = new invoiceROLog ();
  3099. Doo::loadModel ( 'invoiceStatistics' );
  3100. $invoiceStatistics = new invoiceStatistics ();
  3101. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3102. $bankBatchNumber = 'BBN_' . time ();
  3103. Doo::db ()->beginTransaction ();
  3104. // 批量存储收款--由于必须获得收款ID,
  3105. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3106. VALUES ';
  3107. $date = date ( "Y-m-d" );
  3108. $receivablesList = array ();
  3109. foreach ( $exlArray as $key => $value ) {
  3110. $receivablesSql = '(' . $value ["receivablesPrice"] . ',' . $value ["receivablesPrice"] . ',"' . $value ["receivablesMessage"] . '",' . '"#SK' . date ( "Ymd" ) . mt_rand ( 1000, 9999 ) . '","' . $value ["receivablesBank"] . '","' . $value ["receivablesDate"] . '","' . $this->staff [0] ['username'] . '","' . $date . '","PUBLIC","PUBLIC","' . $bankBatchNumber . '","' . $value ["receivablesMessage"] . '")';
  3111. array_push ( $receivablesList, $receivablesSql );
  3112. }
  3113. $sql = $sql . implode ( ',', $receivablesList );
  3114. // echo $sql;
  3115. Doo::db ()->query ( $sql );
  3116. // 批量存储收款统计
  3117. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3118. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3119. // 没有irid 回滚所有操作
  3120. if (empty ( $iridList )) {
  3121. Doo::db ()->rollBack ();
  3122. header ( 'Content-Type:text/html;charset=utf-8' );
  3123. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3124. }
  3125. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3126. VALUES ';
  3127. $statisticsList = array ();
  3128. foreach ( $iridList as $value ) {
  3129. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3130. array_push ( $statisticsList, $statisticsSql );
  3131. }
  3132. $sql = $sql . implode ( ',', $statisticsList );
  3133. Doo::db ()->query ( $sql );
  3134. // 批量存储操作日志
  3135. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3136. VALUES ';
  3137. $ROLogList = array ();
  3138. foreach ( $iridList as $value ) {
  3139. $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'] . '")';
  3140. array_push ( $ROLogList, $ROLogSql );
  3141. }
  3142. $sql = $sql . implode ( ',', $ROLogList );
  3143. Doo::db ()->query ( $sql );
  3144. // 批量写入流水
  3145. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3146. VALUES ';
  3147. $wasteBookList = array ();
  3148. foreach ( $iridList as $value ) {
  3149. $accountBank = '';
  3150. if ($value ['receivablesBank'] == '纵横广发') {
  3151. $accountBank = 'CGBDeposit';
  3152. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3153. $accountBank = 'ICBCDeposit';
  3154. } elseif ($value ['receivablesBank'] == '华润银行') {
  3155. $accountBank = 'HUADeposit';
  3156. } elseif ($value ['receivablesBank'] == '个人广发') {
  3157. $accountBank = 'PersonalDeposit';
  3158. }
  3159. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3160. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3161. array_push ( $wasteBookList, $wasteBookSql );
  3162. }
  3163. $sql = $sql . implode ( ',', $wasteBookList );
  3164. Doo::db ()->query ( $sql );
  3165. Doo::db ()->commit ();
  3166. return "/invoiceReceivables";
  3167. }
  3168. echo 'no file';
  3169. }
  3170. function invoiceReceivables() {
  3171. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3172. Doo::loadModel ( 'L_category' );
  3173. $lCategory = new L_category ();
  3174. Doo::loadModel ( 'staff' );
  3175. $staff = new staff ();
  3176. Doo::loadModel ( 'invoiceReceivables' );
  3177. $invoiceReceivables = new invoiceReceivables ();
  3178. Doo::loadModel ( 'invoice' );
  3179. $invoice = new invoice ();
  3180. Doo::loadClass ( 'XDeode' );
  3181. $XDeode = new XDeode ( 5 );
  3182. $category = $lCategory->getCategory ();
  3183. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3184. $sql = 'bindStatus=1 and iid!=0';
  3185. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3186. // 获取未入账发票
  3187. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3188. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3189. foreach ( $invoiceUnAccount as $key => $value ) {
  3190. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3191. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3192. if (! empty ( $lastApprover )) {
  3193. $lastApproverKey = array_keys ( $lastApprover );
  3194. $lastApprover = end ( $lastApprover );
  3195. $staffDetail = $staff->getOne ( array (
  3196. 'where' => 'sid=' . end ( $lastApproverKey ),
  3197. 'asArray' => true
  3198. ) );
  3199. $lastApprover ['username'] = $staffDetail ['username'];
  3200. }
  3201. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3202. }
  3203. foreach ( $invoiceExistAccount as $key => $value ) {
  3204. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3205. // if (empty ( $irList ))
  3206. // $irList [0] ['sumPrice'] = 0;
  3207. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3208. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3209. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3210. }
  3211. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3212. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3213. $this->data ['halfList'] = $halfList;
  3214. $this->data ['halfCount'] = count ( $halfList );
  3215. // print_r($receivablesList);
  3216. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3217. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3218. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3219. $this->data ['receivablesInput'] = $receivablesInput;
  3220. $this->data ['year'] = date ( 'Y' );
  3221. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3222. $this->data ['receivablesList'] = $receivablesList;
  3223. $this->data ['staffList'] = $staffList;
  3224. $this->data ['category'] = $category;
  3225. $this->data ['memu'] = "invoice";
  3226. $this->data ['staff'] = $this->staff;
  3227. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3228. $this->render ( "/admin/invoiceReceivables", $this->data );
  3229. }
  3230. /**
  3231. * 设置收款认领地区
  3232. */
  3233. function setInvoiceReceivablesClaim() {
  3234. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3235. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3236. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3237. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3238. Doo::loadModel ( 'invoiceReceivables' );
  3239. $invoiceReceivables = new invoiceReceivables ();
  3240. Doo::loadClass ( 'XDeode' );
  3241. $XDeode = new XDeode ( 5 );
  3242. Doo::loadModel ( 'invoiceROLog' );
  3243. $invoiceROLog = new invoiceROLog ();
  3244. $irid = $XDeode->decode ( $iridKey );
  3245. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3246. if (empty ( $irDetail ))
  3247. die ( 'illegal request' );
  3248. $item = array (
  3249. 'irid' => $irid,
  3250. 'receivablesCategory' => $receivablesCategory
  3251. );
  3252. if ($receivablesCategory != 'PUBLIC') {
  3253. $item += array (
  3254. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3255. 'inputType' => 1
  3256. );
  3257. }
  3258. $invoiceReceivables = new invoiceReceivables ();
  3259. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3260. // 收款操作日志
  3261. $item = array (
  3262. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3263. 'date' => date ( "Y-m-d" ),
  3264. 'status' => 1,
  3265. 'img' => $this->staff [0] ['avatar'],
  3266. 'username' => $this->staff [0] ['username'],
  3267. 'uid' => $this->staff [0] ['sid'],
  3268. 'category' => $this->staff [0] ['category'],
  3269. 'irid' => $irid
  3270. );
  3271. $invoiceROLog->setInvoiceROLog ( $item );
  3272. if (empty ( $action ))
  3273. return '/invoiceReceivables';
  3274. else
  3275. return "/invoiceReceivablesAS";
  3276. }
  3277. die ( 'illegal request' );
  3278. }
  3279. /**
  3280. * 新添加收款直接入账发票
  3281. */
  3282. function invoiceCompareClaimPrice() {
  3283. // 收款录入
  3284. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3285. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3286. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3287. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3288. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3289. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3290. Doo::loadModel ( 'invoiceReceivables' );
  3291. $invoiceReceivables = new invoiceReceivables ();
  3292. Doo::loadModel ( 'invoiceROLog' );
  3293. $invoiceROLog = new invoiceROLog ();
  3294. Doo::loadModel ( 'invoiceStatistics' );
  3295. Doo::loadModel ( 'invoice' );
  3296. $invoice = new invoice ();
  3297. Doo::loadClass ( 'XDeode' );
  3298. $XDeode = new XDeode ( 5 );
  3299. Doo::loadModel ( 'invoiceOperationLog' );
  3300. $invoiceOperationLog = new invoiceOperationLog ();
  3301. $iidKey = $XDeode->decode ( $iidKey );
  3302. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3303. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3304. die ( 'illegal request' );
  3305. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3306. // 收款录入 并绑定发票
  3307. Doo::db ()->beginTransaction ();
  3308. //获得发票入账余额
  3309. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3310. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3311. $bindStatus = 0;
  3312. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3313. if($invoiceDetail ['invoiceBalance']!=0){
  3314. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3315. }
  3316. if ($receivablesPrice <= $invoiceBalance){
  3317. $bindStatus = 1;
  3318. //$bindPrice=$receivablesPrice;
  3319. }
  3320. $titleMark = $invoiceDetail ['invoiceTitle'];
  3321. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3322. $titleMark = $invoiceDetail ['invoiceCompany'];
  3323. $item = array (
  3324. 'recepitTitleMark' => $titleMark,
  3325. 'bindStatus' => $bindStatus,
  3326. 'iid' => $invoiceDetail ['iid'],
  3327. 'bindPrice' => $receivablesPrice,
  3328. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3329. 'receivablesPrice' => $receivablesPrice,
  3330. 'OriginalPrice' => $receivablesPrice,
  3331. 'receivablesMessage' => $receivablesMessage,
  3332. 'receivablesSerial' => $receivablesSerial,
  3333. 'receivablesBank' => $receivablesBank,
  3334. 'receivablesDate' => $receivablesDate,
  3335. 'inputStaff' => $this->staff [0] ['username'],
  3336. 'accountClerk' => $this->staff [0] ['username'],
  3337. 'date' => date ( "Y-m-d" ),
  3338. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3339. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3340. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3341. );
  3342. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3343. $item = array ();
  3344. // 收款操作日志
  3345. $item = array (
  3346. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3347. );
  3348. $item += array (
  3349. 'date' => date ( "Y-m-d" ),
  3350. 'status' => 1,
  3351. 'img' => $this->staff [0] ['avatar'],
  3352. 'username' => $this->staff [0] ['username'],
  3353. 'uid' => $this->staff [0] ['sid'],
  3354. 'category' => $this->staff [0] ['category'],
  3355. 'irid' => $irid
  3356. );
  3357. $invoiceROLog->setInvoiceROLog ( $item );
  3358. // 收款统计
  3359. $invoiceStatistics = new invoiceStatistics ();
  3360. $item = array (
  3361. 'date' => $receivablesDate,
  3362. 'priceClass' => 2,
  3363. 'irid' => $irid,
  3364. 'cid' => $invoiceDetail ['cid'],
  3365. 'staff' => $invoiceDetail ['sid'],
  3366. 'receivablesPrice' => $receivablesPrice
  3367. );
  3368. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3369. // 收款 入 发票
  3370. $detail = $invoiceDetail;
  3371. $iridString = "";
  3372. if (empty ( $detail ['irid'] ))
  3373. $iridString = $irid;
  3374. else
  3375. $iridString = $detail ['irid'] . ',' . $irid;
  3376. $item = array (
  3377. 'irid' => $iridString,
  3378. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3379. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3380. 'iid' => $detail ['iid']
  3381. );
  3382. // $invoiceReceivables = new invoiceReceivables ();
  3383. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3384. // $sumBind = $bindInvicePrice;
  3385. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3386. // $sum=$sumBind+$sumBalance;
  3387. // ;
  3388. if ($receivablesPrice>=$invoiceBalance){
  3389. $item += array (
  3390. 'invoiceBalance'=>0,
  3391. 'untreadStatus' => 3
  3392. );
  3393. }else{
  3394. $item += array (
  3395. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3396. );
  3397. }
  3398. $invoice->setInvoiceByCondition ( $item );
  3399. // 操作日志
  3400. $item = array (
  3401. 'date' => date ( "Y-m-d H:i:s" ),
  3402. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3403. 'status' => 8,
  3404. 'img' => $this->staff [0] ['avatar'],
  3405. 'username' => $this->staff [0] ['username'],
  3406. 'uid' => $this->staff [0] ['sid'],
  3407. 'category' => $this->staff [0] ['category'],
  3408. 'iid' => $detail ['iid']
  3409. );
  3410. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3411. // 入账汇总
  3412. $invoiceStatistics = new invoiceStatistics ();
  3413. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3414. // $accountPrice = 0;
  3415. // foreach ( $list as $key => $value ) {
  3416. // $accountPrice += $value ['receivablesPrice'];
  3417. // }
  3418. $item = array (
  3419. 'date' => $receivablesDate,
  3420. 'priceClass' => 3,
  3421. 'cid' => $invoiceDetail ['cid'],
  3422. 'staff' => $invoiceDetail ['sid'],
  3423. 'accountPrice' => $receivablesPrice
  3424. );
  3425. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3426. // 公司流水记录
  3427. Doo::loadModel ( 'wasteBook' );
  3428. $wasteBook = new wasteBook ();
  3429. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3430. $accountBank = '';
  3431. if ($receivablesBank == '纵横广发') {
  3432. $accountBank = 'CGBDeposit';
  3433. } elseif ($receivablesBank == '纵横工行') {
  3434. $accountBank = 'ICBCDeposit';
  3435. } elseif ($receivablesBank == '华润银行') {
  3436. $accountBank = 'HUADeposit';
  3437. } elseif ($receivablesBank == '个人广发') {
  3438. $accountBank = 'PersonalDeposit';
  3439. }
  3440. if (empty ( $abDetail )) {
  3441. $item = array (
  3442. 'dataID' => $irid,
  3443. 'expensesType' => 1,
  3444. 'accountType' => 7,
  3445. 'accountPrice' => $receivablesPrice,
  3446. 'accountPriceShow' => $receivablesPrice,
  3447. 'accountBank' => $accountBank,
  3448. 'category' => $this->staff [0] ['category'],
  3449. 'cid' => $this->staff [0] ['cid'],
  3450. 'name' => $this->staff [0] ['username'],
  3451. 'sid' => $this->staff [0] ['sid'],
  3452. 'inputDate' => date ( "Y-m-d H:i:s" )
  3453. );
  3454. $wasteBook->setAccountBookStatistics ( $item );
  3455. }
  3456. Doo::db ()->commit ();
  3457. }
  3458. return '/invoiceReceivables';
  3459. }
  3460. /**
  3461. * 录入收款数据
  3462. * @return string
  3463. */
  3464. function invoiceReceivablesDo() {
  3465. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3466. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3467. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3468. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3469. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3470. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3471. Doo::loadModel ( 'invoiceReceivables' );
  3472. $invoiceReceivables = new invoiceReceivables ();
  3473. Doo::loadModel ( 'invoiceROLog' );
  3474. $invoiceROLog = new invoiceROLog ();
  3475. Doo::loadModel ( 'invoiceStatistics' );
  3476. $invoiceStatistics = new invoiceStatistics ();
  3477. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3478. $item = array (
  3479. 'receivablesPrice' => $receivablesPrice,
  3480. 'OriginalPrice' => $receivablesPrice,
  3481. 'receivablesMessage' => $receivablesMessage,
  3482. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3483. 'receivablesBank' => $receivablesBank,
  3484. 'receivablesDate' => $receivablesDate,
  3485. 'inputStaff' => $this->staff [0] ['username'],
  3486. 'date' => date ( "Y-m-d" ),
  3487. 'receivablesCategory' => $receivablesCategory,
  3488. 'receivablesStaff' => $receivablesStaff
  3489. );
  3490. if ($receivablesCategory != 'PUBLIC') {
  3491. $item += array (
  3492. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3493. 'inputType' => 1
  3494. );
  3495. }
  3496. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3497. $item = array ();
  3498. // 收款操作日志
  3499. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3500. $item = array (
  3501. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3502. );
  3503. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3504. $item = array (
  3505. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3506. );
  3507. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3508. $receivablesStaff = explode ( '-', $receivablesStaff );
  3509. $item = array (
  3510. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3511. );
  3512. }
  3513. $item += array (
  3514. 'date' => date ( "Y-m-d" ),
  3515. 'status' => 1,
  3516. 'img' => $this->staff [0] ['avatar'],
  3517. 'username' => $this->staff [0] ['username'],
  3518. 'uid' => $this->staff [0] ['sid'],
  3519. 'category' => $this->staff [0] ['category'],
  3520. 'irid' => $irid
  3521. );
  3522. $invoiceROLog->setInvoiceROLog ( $item );
  3523. $item = array (
  3524. 'date' => $receivablesDate,
  3525. 'priceClass' => 2,
  3526. 'irid' => $irid,
  3527. 'receivablesPrice' => $receivablesPrice
  3528. );
  3529. if ($receivablesCategory != 'PUBLIC') {
  3530. $receivablesCategory = explode ( ":", $receivablesCategory );
  3531. $item += array (
  3532. 'cid' => $receivablesCategory [0]
  3533. );
  3534. }
  3535. if ($receivablesStaff2 != 'PUBLIC') {
  3536. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3537. $item += array (
  3538. 'staff' => $receivablesStaff [0]
  3539. );
  3540. }
  3541. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3542. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3543. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3544. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3545. if ($toparty != 0)
  3546. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3547. // 公司流水记录
  3548. Doo::loadModel ( 'wasteBook' );
  3549. $wasteBook = new wasteBook ();
  3550. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3551. $accountBank = '';
  3552. if ($receivablesBank == '纵横广发') {
  3553. $accountBank = 'CGBDeposit';
  3554. } elseif ($receivablesBank == '纵横工行') {
  3555. $accountBank = 'ICBCDeposit';
  3556. } elseif ($receivablesBank == '华润银行') {
  3557. $accountBank = 'HUADeposit';
  3558. } elseif ($receivablesBank == '个人广发') {
  3559. $accountBank = 'PersonalDeposit';
  3560. }
  3561. $item = array (
  3562. 'dataID' => $irid,
  3563. 'expensesType' => 1,
  3564. 'accountType' => 7,
  3565. 'accountPriceShow' => $receivablesPrice,
  3566. 'accountPrice' => $receivablesPrice,
  3567. 'accountBank' => $accountBank,
  3568. 'category' => $this->staff [0] ['category'],
  3569. 'cid' => $this->staff [0] ['cid'],
  3570. 'name' => $this->staff [0] ['username'],
  3571. 'sid' => $this->staff [0] ['sid'],
  3572. 'inputDate' => date ( "Y-m-d H:i:s" )
  3573. );
  3574. $wasteBook->setAccountBookStatistics ( $item );
  3575. }
  3576. return "/invoiceReceivables";
  3577. }
  3578. /**
  3579. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3580. */
  3581. function invoiceReceivablesClaim() {
  3582. Doo::loadModel ( 'invoiceReceivables' );
  3583. $invoiceReceivables = new invoiceReceivables ();
  3584. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3585. $this->data ['receivablesList'] = $receivablesList;
  3586. $this->data ['memu'] = "invoice";
  3587. $this->data ['staff'] = $this->staff;
  3588. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3589. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3590. }
  3591. function invoiceReceivablesTitleMarkSet() {
  3592. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3593. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3594. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3595. die ( 'illegal request' );
  3596. Doo::loadModel ( 'invoiceReceivables' );
  3597. $invoiceReceivables = new invoiceReceivables ();
  3598. Doo::loadClass ( 'XDeode' );
  3599. $XDeode = new XDeode ( 5 );
  3600. $irid = $XDeode->decode ( $iridKey );
  3601. if (! is_numeric ( $irid ))
  3602. die ( 'illegal request' );
  3603. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3604. $invoiceReceivables->update ( array (
  3605. 'where' => 'irid = ' . $irid
  3606. ) );
  3607. return '/invoiceReceivablesClaim';
  3608. }
  3609. /**
  3610. * 更新收款相关数据
  3611. */
  3612. function invoiceReceivablesUpdateClaim() {
  3613. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3614. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3615. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3616. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3617. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3618. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3619. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3620. if (empty ( $claimKey ))
  3621. die ( 'illegal request' );
  3622. Doo::loadModel ( 'invoiceReceivables' );
  3623. $invoiceReceivables = new invoiceReceivables ();
  3624. Doo::loadModel ( 'invoiceROLog' );
  3625. $invoiceROLog = new invoiceROLog ();
  3626. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3627. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3628. if (empty ( $detail ))
  3629. die ( 'illegal request' );
  3630. $invoiceReceivables = new invoiceReceivables ();
  3631. $item = array (
  3632. 'irid' => $detail ['irid']
  3633. );
  3634. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3635. $item += array (
  3636. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3637. );
  3638. }
  3639. if (! empty ( $receivablesCategory ))
  3640. $item += array (
  3641. 'receivablesCategory' => $receivablesCategory
  3642. );
  3643. if (! empty ( $receivablesStaff ))
  3644. $item += array (
  3645. 'receivablesStaff' => $receivablesStaff
  3646. );
  3647. if (! empty ( $receivablesPrice ))
  3648. $item += array (
  3649. 'receivablesPrice' => $receivablesPrice
  3650. );
  3651. if (! empty ( $receivablesMessage ))
  3652. $item += array (
  3653. 'receivablesMessage' => $receivablesMessage
  3654. );
  3655. if (! empty ( $receivablesBank ))
  3656. $item += array (
  3657. 'receivablesBank' => $receivablesBank
  3658. );
  3659. if (! empty ( $receivablesDate ))
  3660. $item += array (
  3661. 'receivablesDate' => $receivablesDate
  3662. );
  3663. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3664. // 收款操作日志
  3665. $item = array ();
  3666. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3667. $item = array (
  3668. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3669. );
  3670. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3671. $item = array (
  3672. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3673. );
  3674. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3675. $receivablesStaff = explode ( '-', $receivablesStaff );
  3676. $item = array (
  3677. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3678. );
  3679. }
  3680. $item += array (
  3681. 'date' => date ( "Y-m-d" ),
  3682. 'status' => 1,
  3683. 'img' => $this->staff [0] ['avatar'],
  3684. 'username' => $this->staff [0] ['username'],
  3685. 'uid' => $this->staff [0] ['sid'],
  3686. 'category' => $this->staff [0] ['category'],
  3687. 'irid' => $detail ['irid']
  3688. );
  3689. $invoiceROLog->setInvoiceROLog ( $item );
  3690. return '/invoiceReceivablesAS';
  3691. }
  3692. function invoiceReceivablesDelete() {
  3693. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3694. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3695. if ($skll != '删除到款')
  3696. die ( 'illegal request' );
  3697. if (empty ( $claimKey ))
  3698. die ( 'illegal request' );
  3699. Doo::loadModel ( 'invoiceReceivables' );
  3700. $invoiceReceivables = new invoiceReceivables ();
  3701. $con = ' and bindStatus=0 ';
  3702. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3703. if (empty ( $detail ))
  3704. die ( 'illegal request' );
  3705. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3706. // 扣除收款汇总信息 汇总
  3707. Doo::loadModel ( 'invoiceStatistics' );
  3708. $invoiceStatistics = new invoiceStatistics ();
  3709. $item = array (
  3710. 'date' => $detail ['receivablesDate'],
  3711. 'priceClass' => 2,
  3712. 'irid' => $detail ['irid'],
  3713. 'receivablesPrice' => - $detail ['receivablesPrice']
  3714. );
  3715. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3716. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3717. $item += array (
  3718. 'cid' => $receivablesCategory [0]
  3719. );
  3720. }
  3721. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3722. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3723. $item += array (
  3724. 'staff' => $receivablesStaff [0]
  3725. );
  3726. }
  3727. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3728. // 公司流水-删除时删除流水
  3729. Doo::loadModel ( 'wasteBook' );
  3730. $wasteBook = new wasteBook ();
  3731. $wasteBook->delete ( array (
  3732. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3733. 'limit' => 1
  3734. ) );
  3735. return '/invoiceReceivablesAS';
  3736. }
  3737. /**
  3738. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3739. */
  3740. function invoiceReceivablesAscription() {
  3741. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3742. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3743. Doo::loadModel ( 'invoiceReceivables' );
  3744. $invoiceReceivables = new invoiceReceivables ();
  3745. Doo::loadModel ( 'invoiceROLog' );
  3746. $invoiceROLog = new invoiceROLog ();
  3747. Doo::loadModel ( 'invoiceStatistics' );
  3748. $invoiceStatistics = new invoiceStatistics ();
  3749. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3750. $irid = $invoiceReceivables->authcode ( $irid );
  3751. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3752. $item = array (
  3753. 'irid' => $detail ['irid'],
  3754. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3755. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3756. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3757. 'recepitTitleMark' => $recepitTitleMark,
  3758. 'source' => 1
  3759. );
  3760. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3761. $item = array (
  3762. 'date' => date ( "Y-m-d" ),
  3763. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3764. 'status' => 2,
  3765. 'img' => $this->staff [0] ['avatar'],
  3766. 'username' => $this->staff [0] ['username'],
  3767. 'uid' => $this->staff [0] ['sid'],
  3768. 'category' => $this->staff [0] ['category'],
  3769. 'irid' => $irid
  3770. );
  3771. $invoiceROLog->setInvoiceROLog ( $item );
  3772. $item = array (
  3773. 'cid' => $this->staff [0] ['cid'],
  3774. 'staff' => $this->staff [0] ['sid']
  3775. );
  3776. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3777. }
  3778. return "/invoiceReceivablesClaim";
  3779. }
  3780. /**
  3781. */
  3782. function invoiceMyReceivables() {
  3783. Doo::loadModel ( 'invoiceReceivables' );
  3784. $invoiceReceivables = new invoiceReceivables ();
  3785. Doo::loadModel ( 'invoiceStatistics' );
  3786. $invoiceStatistics = new invoiceStatistics ();
  3787. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3788. $year = date ( "Y" );
  3789. $tmp_date = date ( "Ym" );
  3790. $tmp_year = substr ( $tmp_date, 0, 4 );
  3791. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3792. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3793. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3794. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3795. $htm = $this->showCache ( $path );
  3796. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3797. $this->data ['isMonth'] = $isMonth;
  3798. $this->data ['htm'] = $htm;
  3799. $this->data ['list'] = $list;
  3800. $this->data ['memu'] = "invoice";
  3801. $this->data ['staff'] = $this->staff;
  3802. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3803. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3804. }
  3805. /**
  3806. * 纸票管理
  3807. */
  3808. function invoicePaper() {
  3809. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3810. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3811. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3812. $this->data ['dateString'] = $date;
  3813. $this->data ['status'] = $status;
  3814. $this->data ['invoiceType'] = $invoiceType;
  3815. $this->data ['memu'] = "invoice";
  3816. $this->data ['staff'] = $this->staff;
  3817. $this->data ['receiptMemu'] = 'invoicePaper';
  3818. $this->render ( "/admin/invoicePaper", $this->data );
  3819. }
  3820. /**
  3821. * 电子发票管理
  3822. */
  3823. function invoiceElectronic() {
  3824. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3825. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3826. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3827. $this->data ['dateString'] = $date;
  3828. $this->data ['status'] = $status;
  3829. $this->data ['invoiceType'] = $invoiceType;
  3830. $this->data ['memu'] = "invoice";
  3831. $this->data ['staff'] = $this->staff;
  3832. $this->data ['receiptMemu'] = 'invoicePaper';
  3833. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3834. }
  3835. /**
  3836. * 获得纸票分页数据
  3837. */
  3838. function ajaxGetinvoicePaperAchieve() {
  3839. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3840. Doo::loadModel ( 'invoicePaper' );
  3841. $invoicePaper = new invoicePaper ();
  3842. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3843. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3844. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3845. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3846. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3847. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3848. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3849. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3850. $MebSea = $this->get_args ( 'search' );
  3851. $MebSea = $MebSea ['value'];
  3852. $page_size = $length;
  3853. $con = '';
  3854. if ($status == 'ALL')
  3855. $con = ' where 1 ';
  3856. elseif ($status == 'PRINTED')
  3857. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3858. elseif ($status == 'UNPRINT')
  3859. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3860. elseif ($status == 'TICKET')
  3861. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3862. if ($invoiceType == 'ORDINARY')
  3863. $con .= ' and a.invoiceType=0 ';
  3864. elseif ($invoiceType == 'SPECIAL')
  3865. $con .= ' and a.invoiceType=1 ';
  3866. if($invoiceForm==0){
  3867. $con .= ' and a.invoiceForm=0 ';
  3868. }else{
  3869. $con .= ' and a.invoiceForm=1 ';
  3870. }
  3871. $dateArr = explode ( ':', $date );
  3872. $D1 = $dateString = '';
  3873. $D2 = '';
  3874. if (! empty ( $date )) {
  3875. $D1 = $dateArr [0];
  3876. if (isset ( $dateArr [1] ))
  3877. $D2 = $dateArr [1];
  3878. else
  3879. $D2 = '';
  3880. $dateString = $D1 . " : " . $D2;
  3881. }
  3882. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3883. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3884. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3885. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3886. if (! empty ( $MebSea ))
  3887. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3888. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3889. $sql = ' ' . $con;
  3890. $limit = $page . ',' . $page_size;
  3891. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3892. $paperList = array ();
  3893. foreach ( $list as $key => $value ) {
  3894. $irDetail = array ();
  3895. if ($value ['iid'] == 0)
  3896. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3897. else
  3898. array_push ( $irDetail, '' );
  3899. array_push ( $irDetail, $value ['invoiceCode'] );
  3900. array_push ( $irDetail, $value ['invoiceNo'] );
  3901. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3902. if ($value ['invoiceType'] == 1)
  3903. array_push ( $irDetail, $value ['invoiceCompany'] );
  3904. else
  3905. array_push ( $irDetail, $value ['invoiceTitle'] );
  3906. if ($value ['invoiceType'] == 1)
  3907. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3908. else
  3909. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3910. array_push ( $irDetail, $value ['invoiceElement'] );
  3911. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3912. array_push ( $irDetail, $value ['printTime'] );
  3913. array_push ( $paperList, $irDetail );
  3914. }
  3915. // $approvalListJson = json_encode ( $approvalList );
  3916. $recordsFiltered = $invoiceTotal;
  3917. echo json_encode ( array (
  3918. "draw" => intval ( $draw ),
  3919. "recordsTotal" => intval ( $invoiceTotal ),
  3920. "recordsFiltered" => intval ( $recordsFiltered ),
  3921. "data" => $paperList
  3922. ), JSON_UNESCAPED_UNICODE );
  3923. }
  3924. function invoicePaperDel() {
  3925. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3926. $XDeode = new XDeode ( 5 );
  3927. $ipid = $XDeode->decode ( $ipidKey );
  3928. if (empty ( $ipid ))
  3929. die ( 'illegal request' );
  3930. Doo::loadModel ( 'invoicePaper' );
  3931. $invoicePaper = new invoicePaper ();
  3932. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3933. $invoicePaper->delete ( array (
  3934. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3935. 'limit' => 1
  3936. ) );
  3937. if($ipdetail['invoiceForm']==1){
  3938. return '/invoiceElectronic';
  3939. }else{
  3940. return '/invoicePaper';
  3941. }
  3942. }
  3943. /**
  3944. * 添加纸质发票号
  3945. */
  3946. function invoicePaperAdd() {
  3947. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3948. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3949. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3950. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3951. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  3952. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3953. $sum = $invoiceNoStart + $invoiceNoTotal;
  3954. if (empty ( $sum ))
  3955. die ( 'illegal request' );
  3956. // echo $invoiceNoStart;
  3957. // echo $sum;
  3958. // echo strlen((int)$invoiceNoStart);
  3959. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3960. if($invoiceType==0||$invoiceType==1){
  3961. }else{
  3962. die ( 'illegal request invoiceType' );
  3963. }
  3964. if($invoiceForm==1){
  3965. $invoiceType=0;
  3966. }
  3967. Doo::db ()->beginTransaction ();
  3968. // 批量存储纸质发票
  3969. $date = date ( "Y-m-d H:i:s" );
  3970. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  3971. VALUES ';
  3972. $paperList = array ();
  3973. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3974. // 数字前面自加0
  3975. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3976. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3977. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  3978. array_push ( $paperList, $paperSql );
  3979. }
  3980. if (empty ( $paperList ))
  3981. die ( 'illegal request' );
  3982. $sql = $sql . implode ( ',', $paperList );
  3983. Doo::db ()->query ( $sql );
  3984. Doo::db ()->commit ();
  3985. if($invoiceForm==1){
  3986. return 'invoiceElectronic';
  3987. }else{
  3988. return 'invoicePaper';
  3989. }
  3990. }
  3991. die ( 'illegal request' );
  3992. }
  3993. /**
  3994. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3995. */
  3996. function invoiceBindReceivables() {
  3997. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3998. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3999. Doo::loadModel ( 'invoice' );
  4000. $invoice = new invoice ();
  4001. Doo::loadModel ( 'invoiceReceivables' );
  4002. $invoiceReceivables = new invoiceReceivables ();
  4003. Doo::loadModel ( 'invoiceOperationLog' );
  4004. $invoiceOperationLog = new invoiceOperationLog ();
  4005. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4006. die ( 'illegal request' );
  4007. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4008. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4009. if (empty ( $detail ) && empty ( $detailM ))
  4010. die ( 'illegal request' );
  4011. if ($detail ['untreadStatus'] == 3)
  4012. die ( 'illegal request' );
  4013. // 修改 绑定状态改为 金额
  4014. $invoiceReceivables = new invoiceReceivables ();
  4015. //有BUG-需修改
  4016. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4017. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4018. $item = array (
  4019. 'bindPrice' => $invoicePrice
  4020. );
  4021. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {//发票金额大于收款金额,绑定金额为收款金额
  4022. $item = array (
  4023. 'bindPrice' => $detailM ['receivablesPrice'],
  4024. 'bindStatus' => 1,
  4025. 'bindDate' => date ( "Y-m-d H:i:s" )
  4026. );
  4027. } else {
  4028. die ( 'illegal request' );
  4029. }
  4030. if ($detailM ['iid'] == 0) {
  4031. $item += array (
  4032. 'iid' => $detail ['iid']
  4033. );
  4034. } else {
  4035. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4036. array_push ( $iidExtend, $detail ['iid'] );
  4037. $item += array (
  4038. 'iidExtend' => implode ( ',', $iidExtend )
  4039. );
  4040. }
  4041. $titleMark = $detail ['invoiceTitle'];
  4042. if (! empty ( $detail ['invoiceCompany'] ))
  4043. $titleMark = $detail ['invoiceCompany'];
  4044. $item += array (
  4045. 'irid' => $detailM ['irid'],
  4046. 'recepitTitleMark' => $titleMark,
  4047. 'accountClerk' => $this->staff [0] ['username']
  4048. );
  4049. // 如何没有人收款 则自动绑定收款
  4050. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4051. $item += array (
  4052. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4053. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4054. );
  4055. }
  4056. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4057. $iridString = "";
  4058. if (empty ( $detail ['irid'] ))
  4059. $iridString = $detailM ['irid'];
  4060. else
  4061. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4062. // $invoiceReceivables = new invoiceReceivables ();
  4063. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4064. // //这个收款余额
  4065. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4066. // $sum=$sumBind+$sumBalance;
  4067. //这个收款余额
  4068. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4069. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4070. // die;
  4071. $item = array (
  4072. 'iid' => $detail ['iid'],
  4073. 'irid' => $iridString
  4074. );
  4075. if ($detail ['invoicePrice'] <= $sumBalance){
  4076. $item += array (
  4077. 'invoiceBalance'=>0,
  4078. 'untreadStatus' => 3,
  4079. 'bindTime' => date ( "Y-m-d H:i:s" )
  4080. );
  4081. }else{
  4082. $item += array (
  4083. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4084. );
  4085. }
  4086. // print_r($item);
  4087. // echo $sum;die;
  4088. $invoice->setInvoiceByCondition ( $item );
  4089. // 操作日志
  4090. $item = array (
  4091. 'date' => date ( "Y-m-d H:i:s" ),
  4092. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4093. 'status' => 8,
  4094. 'img' => $this->staff [0] ['avatar'],
  4095. 'username' => $this->staff [0] ['username'],
  4096. 'uid' => $this->staff [0] ['sid'],
  4097. 'category' => $this->staff [0] ['category'],
  4098. 'iid' => $detail ['iid']
  4099. );
  4100. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4101. Doo::loadModel ( 'invoiceStatistics' );
  4102. $invoiceStatistics = new invoiceStatistics ();
  4103. $item = array (
  4104. 'date' => $detailM ['receivablesDate'],
  4105. 'priceClass' => 3,
  4106. 'cid' => $detail ['cid'],
  4107. 'staff' => $detail ['sid'],
  4108. 'accountPrice' => $detailM ['receivablesPrice']
  4109. );
  4110. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4111. // 公司流水记录
  4112. // Doo::loadModel ( 'wasteBook' );
  4113. // $wasteBook = new wasteBook ();
  4114. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4115. // $accountBank='';
  4116. // if ($detailM ['receivablesBank']=='纵横广发'){
  4117. // $accountBank='CGBDeposit';
  4118. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4119. // $accountBank='ICBCDeposit';
  4120. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4121. // $accountBank='HUADeposit';
  4122. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4123. // $accountBank='PersonalDeposit';
  4124. // }
  4125. // if (empty($abDetail)){
  4126. // $item = array (
  4127. // 'dataID' => $detail ['iid'],
  4128. // 'expensesType' => 1,
  4129. // 'accountType' => 8,
  4130. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4131. // 'accountPrice'=>$detail ['invoicePrice'],
  4132. // 'accountBank'=>$accountBank,
  4133. // 'category'=>$this->staff[0]['category'],
  4134. // 'cid'=>$this->staff[0]['cid'],
  4135. // 'name'=>$this->staff[0]['username'],
  4136. // 'sid'=>$this->staff[0]['sid'],
  4137. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4138. // );
  4139. // $wasteBook->setAccountBookStatistics($item);
  4140. // }
  4141. return "/invoiceReceivables";
  4142. }
  4143. /**
  4144. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4145. */
  4146. function invoiceAggregate() {
  4147. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4148. Doo::loadModel ( 'invoiceStatistics' );
  4149. $invoiceStatistics = new invoiceStatistics ();
  4150. Doo::loadModel ( 'L_category' );
  4151. $Lcategory = new L_category ();
  4152. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4153. $LcategoryList = $Lcategory->getCategory ();
  4154. // print_r($isList);
  4155. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4156. foreach ( $LcategoryList as $key => $value ) {
  4157. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4158. $month = 1;
  4159. $invoicePriceYear = 0;
  4160. $receivablesPriceYear = 0;
  4161. $accountPriceYear = 0;
  4162. for(; $month <= 12; $month ++) {
  4163. $flag = true;
  4164. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4165. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4166. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4167. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4168. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4169. ';
  4170. $invoicePriceYear += $v ['invoicePrice'];
  4171. $receivablesPriceYear += $v ['receivablesPrice'];
  4172. $accountPriceYear += $v ['accountPrice'];
  4173. $flag = false;
  4174. break;
  4175. }
  4176. }
  4177. if ($flag)
  4178. $html .= '<td class="taR"></td>
  4179. <td class="taR"></td>
  4180. <td class="taR"><b></b></td>
  4181. ';
  4182. }
  4183. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4184. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4185. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4186. ';
  4187. $html .= '</tr>';
  4188. }
  4189. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4190. $invoicePriceYear = 0;
  4191. $receivablesPriceYear = 0;
  4192. $accountPriceYear = 0;
  4193. for($month = 1; $month <= 12; $month ++) {
  4194. $flag = true;
  4195. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4196. if ($month == $v ['month']) {
  4197. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4198. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4199. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4200. ';
  4201. $invoicePriceYear += $v ['invoicePrice'];
  4202. $receivablesPriceYear += $v ['receivablesPrice'];
  4203. $accountPriceYear += $v ['accountPrice'];
  4204. $flag = false;
  4205. break;
  4206. }
  4207. }
  4208. if ($flag) {
  4209. $html .= '<td class="taR"></td>
  4210. <td class="taR"></td>
  4211. <td class="taR"><b></b></td>
  4212. ';
  4213. }
  4214. }
  4215. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4216. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4217. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4218. ';
  4219. $html .= '</tr>';
  4220. // print_r($isList);
  4221. $this->data ['html'] = $html;
  4222. $this->data ['LcategoryList'] = $LcategoryList;
  4223. $this->data ['isList'] = $isList;
  4224. $this->data ['year'] = $year;
  4225. $this->data ['memu'] = "invoice";
  4226. $this->data ['staff'] = $this->staff;
  4227. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4228. $this->render ( "/admin/invoiceAggregate", $this->data );
  4229. }
  4230. function invoiceAggregateStaff() {
  4231. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4232. Doo::loadModel ( 'invoiceStatistics' );
  4233. $invoiceStatistics = new invoiceStatistics ();
  4234. Doo::loadModel ( 'L_category' );
  4235. $Lcategory = new L_category ();
  4236. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4237. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4238. $cStaff = $Lcategory->getCategoryStaff ();
  4239. $html = '';
  4240. foreach ( $cStaff as $key => $value ) {
  4241. $categoryFir = true;
  4242. foreach ( $value ['staff'] as $k => $v ) {
  4243. if ($categoryFir) {
  4244. $width = count ( $value ['staff'] ) + 1;
  4245. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4246. $categoryFir = false;
  4247. } else
  4248. $html .= '<tr>';
  4249. $html .= '<th>' . $v ['username'] . '</th>';
  4250. $invoicePriceStaffYear = 0;
  4251. $receivablesPriceStaffYear = 0;
  4252. $accountPriceStaffYear = 0;
  4253. for($month = 1; $month <= 12; $month ++) {
  4254. $flag = true;
  4255. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4256. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4257. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4258. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4259. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4260. ';
  4261. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4262. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4263. $accountPriceStaffYear += $slv ['accountPrice'];
  4264. $flag = false;
  4265. break;
  4266. }
  4267. }
  4268. if ($flag)
  4269. $html .= '<td class="taR"></td>
  4270. <td class="taR"></td>
  4271. <td class="taR"><b></b></td>
  4272. ';
  4273. }
  4274. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4275. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4276. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4277. ';
  4278. }
  4279. $html .= '</tr>';
  4280. // 小计
  4281. if (! empty ( $value ['staff'] )) {
  4282. $html .= '<tr><th class="taR">小计</th>';
  4283. $invoicePriceStaffYear = 0;
  4284. $receivablesPriceStaffYear = 0;
  4285. $accountPriceStaffYear = 0;
  4286. for($month = 1; $month <= 12; $month ++) {
  4287. $flag = true;
  4288. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4289. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4290. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4291. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4292. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4293. ';
  4294. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4295. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4296. $accountPriceStaffYear += $slv ['accountPrice'];
  4297. $flag = false;
  4298. break;
  4299. }
  4300. }
  4301. if ($flag)
  4302. $html .= '<td class="taR"></td>
  4303. <td class="taR"></td>
  4304. <td class="taR"><b></b></td>
  4305. ';
  4306. }
  4307. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4308. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4309. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4310. ';
  4311. $html .= '</tr>';
  4312. }
  4313. }
  4314. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4315. $invoicePriceYear = 0;
  4316. $receivablesPriceYear = 0;
  4317. $accountPriceYear = 0;
  4318. for($month = 1; $month <= 12; $month ++) {
  4319. $flag = true;
  4320. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4321. if ($month == $v ['month']) {
  4322. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4323. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4324. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4325. ';
  4326. $invoicePriceYear += $v ['invoicePrice'];
  4327. $receivablesPriceYear += $v ['receivablesPrice'];
  4328. $accountPriceYear += $v ['accountPrice'];
  4329. $flag = false;
  4330. break;
  4331. }
  4332. }
  4333. if ($flag)
  4334. $html .= '<td class="taR"></td>
  4335. <td class="taR"></td>
  4336. <td class="taR"><b></b></td>
  4337. ';
  4338. }
  4339. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4340. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4341. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4342. ';
  4343. $html .= '</tr>';
  4344. $this->data ['html'] = $html;
  4345. $this->data ['isList'] = $toteList;
  4346. $this->data ['year'] = $year;
  4347. $this->data ['memu'] = "invoice";
  4348. $this->data ['staff'] = $this->staff;
  4349. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4350. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4351. }
  4352. function invoiceAggregateCategory() {
  4353. Doo::loadClass ( 'XDeode' );
  4354. $XDeode = new XDeode ( 5 );
  4355. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4356. $cid = $XDeode->decode ( $cid );
  4357. if (! is_numeric ( $cid ))
  4358. die ( 'illegal request' );
  4359. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4360. Doo::loadModel ( 'invoiceStatistics' );
  4361. $invoiceStatistics = new invoiceStatistics ();
  4362. Doo::loadModel ( 'staff' );
  4363. $staff = new staff ();
  4364. $list = $staff->getStaffByCid ( $cid );
  4365. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4366. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4367. if (empty ( $list ))
  4368. die ( '该办事处没有成员' );
  4369. $htmlA = $htmlB = $htmlC = $html = '';
  4370. foreach ( $list as $key => $value ) {
  4371. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4372. $htmlB = '<tr><th class="taC">收款</th>';
  4373. $htmlC = '<tr><th class="taC">入账</th>';
  4374. $invoicePriceStaffYear = 0;
  4375. $receivablesPriceStaffYear = 0;
  4376. $accountPriceStaffYear = 0;
  4377. for($month = 1; $month <= 12; $month ++) {
  4378. $flag = true;
  4379. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4380. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4381. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4382. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4383. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4384. $invoicePriceStaffYear += $v ['invoicePrice'];
  4385. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4386. $accountPriceStaffYear += $v ['accountPrice'];
  4387. $flag = false;
  4388. break;
  4389. }
  4390. }
  4391. if ($flag) {
  4392. $htmlA .= '<td class="taR">-</td>';
  4393. $htmlB .= '<td class="taR">-</td>';
  4394. $htmlC .= '<td class="taR"><b>-</b></td>';
  4395. }
  4396. }
  4397. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4398. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4399. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4400. $htmlA .= '</tr>';
  4401. $htmlB .= '</tr>';
  4402. $htmlC .= '</tr>';
  4403. $html .= $htmlA . $htmlB . $htmlC;
  4404. }
  4405. $htmlA = $htmlB = $htmlC = "";
  4406. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4407. $htmlB = '<tr><th class="taC">收款</th>';
  4408. $htmlC = '<tr><th class="taC">入账</th>';
  4409. $invoicePriceStaffYear = 0;
  4410. $receivablesPriceStaffYear = 0;
  4411. $accountPriceStaffYear = 0;
  4412. for($month = 1; $month <= 12; $month ++) {
  4413. $flag = true;
  4414. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4415. if ($month == $v ['month']) {
  4416. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4417. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4418. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4419. $invoicePriceStaffYear += $v ['invoicePrice'];
  4420. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4421. $accountPriceStaffYear += $v ['accountPrice'];
  4422. $flag = false;
  4423. break;
  4424. }
  4425. }
  4426. if ($flag) {
  4427. $htmlA .= '<td class="taR">-</td>';
  4428. $htmlB .= '<td class="taR">-</td>';
  4429. $htmlC .= '<td class="taR"><b>-</b></td>';
  4430. }
  4431. }
  4432. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4433. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4434. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4435. $htmlA .= '</tr>';
  4436. $htmlB .= '</tr>';
  4437. $htmlC .= '</tr>';
  4438. $html .= $htmlA . $htmlB . $htmlC;
  4439. $this->data ['html'] = $html;
  4440. $this->data ['cidKey'] = $cidKey;
  4441. $this->data ['slist'] = $list;
  4442. $this->data ['isList'] = $toteList;
  4443. $this->data ['year'] = $year;
  4444. $this->data ['memu'] = "invoice";
  4445. $this->data ['staff'] = $this->staff;
  4446. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4447. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4448. }
  4449. /**
  4450. * 办事处汇总信息
  4451. */
  4452. function invoiceAggregateCategoryDetail() {
  4453. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4454. Doo::loadClass ( 'XDeode' );
  4455. $XDeode = new XDeode ( 5 );
  4456. Doo::loadModel ( 'invoiceStatistics' );
  4457. $invoiceStatistics = new invoiceStatistics ();
  4458. Doo::loadModel ( 'L_category' );
  4459. $category = new L_category ();
  4460. Doo::loadModel ( 'invoice' );
  4461. $invoice = new invoice ();
  4462. Doo::loadModel ( 'staff' );
  4463. $staff = new staff ();
  4464. Doo::loadModel ( "invoiceCategoryManage" );
  4465. $invoiceCategoryManage = new invoiceCategoryManage ();
  4466. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4467. $cidList = array ();
  4468. foreach ( $imcStaff as $key => $value ) {
  4469. array_push ( $cidList, $value ['cid'] );
  4470. if (empty ( $cidKey ))
  4471. $cidKey = $XDeode->encode ( $value ['cid'] );
  4472. }
  4473. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4474. $cid = $XDeode->decode ( $cidKey );
  4475. $month = date ( "m", strtotime ( "-1 month" ) );
  4476. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4477. $redis = new Redis ();
  4478. $redis->connect ( '127.0.0.1', '6379' );
  4479. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4480. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4481. if (empty ( $redisValue )) {
  4482. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4483. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4484. // 获得办事处人员下的汇总
  4485. $slist = $staff->getStaffByCid ( $cid );
  4486. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4487. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4488. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4489. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4490. foreach ( $slist as $key => $value ) {
  4491. $slist [$key] ['invoicePrice'] = 0;
  4492. $slist [$key] ['receivablesPrice'] = 0;
  4493. $slist [$key] ['accountPrice'] = 0;
  4494. $slist [$key] ['invoiceAllPrice'] = 0;
  4495. $slist [$key] ['receivablesAllPrice'] = 0;
  4496. $slist [$key] ['accountAllPrice'] = 0;
  4497. $slist [$key] ['schedule'] = 0;
  4498. $slist [$key] ['invoiceMonthPrice'] = 0;
  4499. $slist [$key] ['receivablesMonthPrice'] = 0;
  4500. $slist [$key] ['accountMonthPrice'] = 0;
  4501. foreach ( $ismsbMonth as $y => $l ) {
  4502. if ($value ['sid'] == $l ['staff']) {
  4503. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4504. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4505. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4506. }
  4507. }
  4508. foreach ( $ismsb as $k => $v ) {
  4509. if ($value ['sid'] == $v ['staff']) {
  4510. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4511. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4512. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4513. }
  4514. }
  4515. foreach ( $ISAS as $e => $a ) {
  4516. if ($value ['sid'] == $a ['staff']) {
  4517. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4518. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4519. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4520. }
  4521. }
  4522. if (isset ( $scheduleStaff [$value ['sid']] ))
  4523. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4524. }
  4525. $this->data ['cidKey'] = $cidKey;
  4526. $schedule = ( int ) ($schedule * 100);
  4527. $this->data ['slist'] = $slist;
  4528. $this->data ['isMC'] = $isMC;
  4529. $this->data ['schedule'] = $schedule;
  4530. $slist = json_encode ( $slist );
  4531. $isMC = json_encode ( $isMC );
  4532. $schedule = json_encode ( $schedule );
  4533. $redis->lpush ( $redisKey, $slist );
  4534. $redis->lpush ( $redisKey, $isMC );
  4535. $redis->lpush ( $redisKey, $schedule );
  4536. } else {
  4537. $this->data ['cidKey'] = $cidKey;
  4538. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4539. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4540. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4541. }
  4542. $this->data ['month'] = $month;
  4543. $this->data ['categoryList'] = $categoryList;
  4544. $this->data ['memu'] = "invoice";
  4545. $this->data ['staff'] = $this->staff;
  4546. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4547. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4548. }
  4549. /**
  4550. * 办事处人员汇总详情
  4551. */
  4552. function invoiceAggregateStaffDetail() {
  4553. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4554. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4555. Doo::loadClass ( 'XDeode' );
  4556. $XDeode = new XDeode ( 5 );
  4557. Doo::loadModel ( 'invoice' );
  4558. $invoice = new invoice ();
  4559. Doo::loadModel ( 'staff' );
  4560. $staff = new staff ();
  4561. Doo::loadModel ( "invoiceCategoryManage" );
  4562. $invoiceCategoryManage = new invoiceCategoryManage ();
  4563. $sid = $XDeode->decode ( $sidKey );
  4564. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4565. $cidList = array ();
  4566. foreach ( $imcStaff as $key => $value ) {
  4567. array_push ( $cidList, $value ['cid'] );
  4568. if (empty ( $cidKey ))
  4569. $cidKey = $XDeode->encode ( $value ['cid'] );
  4570. }
  4571. $cidString = implode ( ',', $cidList );
  4572. $staffList = $staff->getStaffInCid ( $cidString );
  4573. $staffDetail = $staff->getStaffBySid ( $sid );
  4574. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4575. $page_size = 18;
  4576. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4577. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4578. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4579. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4580. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4581. $dateArr = explode ( ':', $date );
  4582. $D1 = '';
  4583. $D2 = '';
  4584. if (! empty ( $date )) {
  4585. $D1 = $dateArr [0] . " 00:00:00 ";
  4586. if (isset ( $dateArr [1] ))
  4587. $D2 = $dateArr [1] . " 23:59:59 ";
  4588. else
  4589. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4590. // $D2 = $dateArr [1];
  4591. }
  4592. $con = ' status=2 ';
  4593. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4594. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4595. if ($status == 'UNRECORD')
  4596. $con .= ' and printStatus=1 and untreadStatus=0';
  4597. elseif ($status == 'RECORD')
  4598. $con .= ' and printStatus=1 and untreadStatus=3';
  4599. elseif ($status == 'BOUNCED')
  4600. $con .= ' and untreadStatus=2';
  4601. elseif ($status == 'PARTRECORD')
  4602. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4603. elseif ($status == 'All') {
  4604. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4605. }
  4606. $con .= ' and sid=' . $sid;
  4607. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4608. if (! empty ( $MebSea )) {
  4609. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4610. }
  4611. $pageinfo ['page'] = array (
  4612. 'previous' => ''
  4613. );
  4614. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4615. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4616. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4617. $this->data ['staffDetail'] = $staffDetail;
  4618. $this->data ['staffList'] = $staffList;
  4619. $this->data ['MebSeaEn'] = $MebSea;
  4620. $this->data ['MebSea'] = urlencode ( $MebSea );
  4621. $this->data ['date'] = $date;
  4622. $this->data ['page'] = $pageinfo;
  4623. $this->data ['get'] = $get;
  4624. $this->data ['list'] = $list;
  4625. $this->data ['status'] = $status;
  4626. $this->data ['sidKey'] = $sidKey;
  4627. $this->data ['memu'] = "invoice";
  4628. $this->data ['staff'] = $this->staff;
  4629. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4630. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4631. }
  4632. /**
  4633. * 办事处人员汇总收款情
  4634. */
  4635. function invoiceAggregateStaffReceivablesDetail() {
  4636. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4637. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4638. Doo::loadModel ( 'invoiceReceivables' );
  4639. $invoiceReceivables = new invoiceReceivables ();
  4640. Doo::loadModel ( 'staff' );
  4641. $staff = new staff ();
  4642. Doo::loadModel ( "invoiceCategoryManage" );
  4643. $invoiceCategoryManage = new invoiceCategoryManage ();
  4644. Doo::loadClass ( 'XDeode' );
  4645. $XDeode = new XDeode ( 5 );
  4646. $sid = $XDeode->decode ( $sidKey );
  4647. $staffDetail = $staff->getStaffBySid ( $sid );
  4648. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4649. $cidList = array ();
  4650. foreach ( $imcStaff as $key => $value ) {
  4651. array_push ( $cidList, $value ['cid'] );
  4652. if (empty ( $cidKey ))
  4653. $cidKey = $XDeode->encode ( $value ['cid'] );
  4654. }
  4655. $cidString = implode ( ',', $cidList );
  4656. $staffList = $staff->getStaffInCid ( $cidString );
  4657. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4658. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4659. $page_size = 10;
  4660. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4661. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4662. if ($timeType == "BINDOTP") {
  4663. $status = 'Credited';
  4664. }
  4665. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4666. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4667. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4668. $dateArr = explode ( ':', $date );
  4669. $D1 = '';
  4670. $D2 = '';
  4671. if (! empty ( $date )) {
  4672. $D1 = $dateArr [0] . " 00:00:00 ";
  4673. if (isset ( $dateArr [1] ))
  4674. $D2 = $dateArr [1] . " 23:59:59 ";
  4675. else
  4676. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4677. }
  4678. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4679. $descField = 'a.bindDate';
  4680. if ($timeType == 'CREATE')
  4681. $descField = 'a.date';
  4682. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4683. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4684. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4685. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4686. if ($status == 'Unclaimed')
  4687. $con .= ' and a.bindStatus=0';
  4688. elseif ($status == 'Credited')
  4689. $con .= ' and a.bindStatus=1';
  4690. elseif ($status == 'Claim')
  4691. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4692. elseif ($status == 'BBN')
  4693. $con .= ' and a.bindPrice>a.receivablesPrice';
  4694. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4695. if (! empty ( $MebSea )) {
  4696. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4697. }
  4698. $pageinfo ['page'] = array (
  4699. 'previous' => ''
  4700. );
  4701. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4702. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4703. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4704. // where ' . $con . ' group by a.irid ';
  4705. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4706. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4707. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4708. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4709. foreach ( $list as $key => $value ) {
  4710. $list [$key] ['category'] = '';
  4711. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4712. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4713. $list [$key] ['category'] = $receivablesCategory [1];
  4714. }
  4715. }
  4716. // print_r($list);
  4717. $this->data ['staffDetail'] = $staffDetail;
  4718. $this->data ['sidKey'] = $sidKey;
  4719. $this->data ['staffList'] = $staffList;
  4720. $this->data ['timeType'] = $timeType;
  4721. $this->data ['MebSeaEn'] = $MebSea;
  4722. $this->data ['MebSea'] = urlencode ( $MebSea );
  4723. $this->data ['date'] = $date;
  4724. $this->data ['page'] = $pageinfo;
  4725. $this->data ['get'] = $get;
  4726. $this->data ['list'] = $list;
  4727. $this->data ['status'] = $status;
  4728. $this->data ['memu'] = "invoice";
  4729. $this->data ['staff'] = $this->staff;
  4730. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4731. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4732. }
  4733. function invoiceAchieve() {
  4734. Doo::loadModel ( 'invoice' );
  4735. $invoice = new invoice ();
  4736. Doo::loadClass ( 'XDeode' );
  4737. $XDeode = new XDeode ( 5 );
  4738. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4739. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4740. $page_size = 18;
  4741. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4742. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4743. $get = "/" . $date;
  4744. $con = '';
  4745. if ($date == 'MONTHO')
  4746. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4747. elseif ($date == 'MONTHT')
  4748. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4749. elseif ($date == 'MONTHY')
  4750. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4751. if (! empty ( $MebSea )) {
  4752. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4753. $get .= "/" . $MebSea;
  4754. }
  4755. $pageinfo ['page'] = array (
  4756. 'previous' => ''
  4757. );
  4758. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4759. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4760. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4761. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4762. // print_r($pageinfo);
  4763. $this->data ['MebSeaEn'] = $MebSea;
  4764. $this->data ['MebSea'] = urlencode ( $MebSea );
  4765. $this->data ['get'] = $get;
  4766. $this->data ['page'] = $pageinfo;
  4767. $this->data ['list'] = $list;
  4768. $this->data ['date'] = $date;
  4769. $this->data ['memu'] = "invoice";
  4770. $this->data ['staff'] = $this->staff;
  4771. $this->data ['receiptMemu'] = 'invoice';
  4772. $this->render ( "/admin/invoiceAchieve", $this->data );
  4773. }
  4774. /**
  4775. */
  4776. function invoiceMyUnAccountAchieve() {
  4777. Doo::loadModel ( 'invoice' );
  4778. $invoice = new invoice ();
  4779. Doo::loadClass ( 'XDeode' );
  4780. $XDeode = new XDeode ( 5 );
  4781. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4782. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4783. $page_size = 18;
  4784. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4785. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4786. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4787. $dateArr = explode ( ':', $date );
  4788. $D1 = '';
  4789. $D2 = '';
  4790. if (! empty ( $date )) {
  4791. $D1 = $dateArr [0];
  4792. $D2 = $dateArr [1];
  4793. }
  4794. $con = '';
  4795. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4796. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4797. if (! empty ( $MebSea )) {
  4798. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4799. }
  4800. $pageinfo ['page'] = array (
  4801. 'previous' => ''
  4802. );
  4803. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4804. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4805. $action = "invoiceMyUnAccountAchieve";
  4806. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4807. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4808. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4809. Doo::loadModel ( 'express' );
  4810. $express = new express ();
  4811. $expressList = $express->getExpressByAll ();
  4812. $this->data ['expressList'] = $expressList;
  4813. // print_r($list);
  4814. $this->data ['MebSeaEn'] = $MebSea;
  4815. $this->data ['get'] = $get;
  4816. $this->data ['page'] = $pageinfo;
  4817. $this->data ['date'] = $date;
  4818. $this->data ['list'] = $list;
  4819. $this->data ['memu'] = "invoice";
  4820. $this->data ['staff'] = $this->staff;
  4821. $this->data ['receiptMemu'] = 'invoice';
  4822. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4823. }
  4824. function invoiceReceivablesAchieve() {
  4825. Doo::loadModel ( 'invoiceReceivables' );
  4826. $invoiceReceivables = new invoiceReceivables ();
  4827. Doo::loadClass ( 'XDeode' );
  4828. $XDeode = new XDeode ( 5 );
  4829. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4830. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4831. $page_size = 12;
  4832. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4833. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4834. $get = "/" . $date;
  4835. $con = '';
  4836. if ($date == 'MONTHO')
  4837. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4838. elseif ($date == 'MONTHT')
  4839. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4840. elseif ($date == 'MONTHY')
  4841. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4842. if (! empty ( $MebSea )) {
  4843. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4844. $get .= "/" . $MebSea;
  4845. }
  4846. $pageinfo ['page'] = array (
  4847. 'previous' => ''
  4848. );
  4849. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4850. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4851. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4852. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4853. // print_r($pageinfo);
  4854. $this->data ['MebSeaEn'] = $MebSea;
  4855. $this->data ['MebSea'] = urlencode ( $MebSea );
  4856. $this->data ['get'] = $get;
  4857. $this->data ['page'] = $pageinfo;
  4858. $this->data ['list'] = $list;
  4859. $this->data ['date'] = $date;
  4860. $this->data ['memu'] = "invoice";
  4861. $this->data ['staff'] = $this->staff;
  4862. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4863. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4864. }
  4865. /**
  4866. * 收款解绑
  4867. */
  4868. function invoiceUnBundLing() {
  4869. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4870. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4871. Doo::loadModel ( 'invoice' );
  4872. $invoice = new invoice ();
  4873. Doo::loadModel ( 'invoiceReceivables' );
  4874. $invoiceReceivables = new invoiceReceivables ();
  4875. Doo::loadModel ( 'invoiceOperationLog' );
  4876. $invoiceOperationLog = new invoiceOperationLog ();
  4877. Doo::loadModel ( 'invoiceROLog' );
  4878. $invoiceROLog = new invoiceROLog ();
  4879. Doo::loadModel ( 'invoiceStatistics' );
  4880. Doo::loadClass ( 'XDeode' );
  4881. $XDeode = new XDeode ( 5 );
  4882. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4883. die ( 'illegal request' );
  4884. $iid = $XDeode->decode ( $iidKey );
  4885. $irid = $invoice->authcode ( $unBundKey );
  4886. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4887. die ( 'illegal request' );
  4888. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4889. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4890. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4891. die ( 'illegal request' );
  4892. // 收款
  4893. $item = array (
  4894. 'irid' => $irDetails ['irid'],
  4895. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4896. 'bindStatus' => 0
  4897. );
  4898. if ($irDetails ['iid'] == $iid)
  4899. $item += array (
  4900. 'iid' => 0
  4901. );
  4902. else {
  4903. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4904. foreach ( $iidExtend as $key => $value ) {
  4905. if ($value == $iid)
  4906. unset ( $iidExtend [$key] );
  4907. }
  4908. $iidExtend = implode ( ',', $iidExtend );
  4909. $item += array (
  4910. 'iidExtend' => $iidExtend
  4911. );
  4912. }
  4913. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4914. // 收款操作日志
  4915. $item = array (
  4916. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4917. 'date' => date ( "Y-m-d" ),
  4918. 'status' => 3,
  4919. 'img' => $this->staff [0] ['avatar'],
  4920. 'username' => $this->staff [0] ['username'],
  4921. 'uid' => $this->staff [0] ['sid'],
  4922. 'category' => $this->staff [0] ['category'],
  4923. 'irid' => $irid
  4924. );
  4925. $invoiceROLog->setInvoiceROLog ( $item );
  4926. // 扣除入账统计金额
  4927. $invoiceStatistics = new invoiceStatistics ();
  4928. $item = array (
  4929. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4930. 'priceClass' => 3,
  4931. 'cid' => $invoiceDetails ['cid'],
  4932. 'staff' => $invoiceDetails ['sid'],
  4933. 'accountPrice' => - $irDetails ['receivablesPrice']
  4934. );
  4935. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4936. // 扣除收款统计金额
  4937. $invoiceStatistics = new invoiceStatistics ();
  4938. $item = array (
  4939. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4940. 'priceClass' => 2,
  4941. 'cid' => $invoiceDetails ['cid'],
  4942. 'staff' => $invoiceDetails ['sid'],
  4943. 'irid' => $irDetails ['irid'],
  4944. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4945. );
  4946. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4947. // 发票解绑去收款ID
  4948. $iridString = $invoiceDetails ['irid'];
  4949. if (! empty ( $invoiceDetails ['irid'] )) {
  4950. $list = explode ( ',', $invoiceDetails ['irid'] );
  4951. foreach ( $list as $key => $value ) {
  4952. if ($value == $irDetails ['irid']) {
  4953. unset ( $list [$key] );
  4954. break;
  4955. }
  4956. }
  4957. $iridString = implode ( ",", $list );
  4958. }
  4959. $item = array (
  4960. 'iid' => $invoiceDetails ['iid'],
  4961. 'irid' => $iridString,
  4962. 'updateTime' => date ( "Y-m-d H:i:s" )
  4963. );
  4964. if ($invoiceDetails ['untreadStatus'] == 3)
  4965. $item += array (
  4966. 'untreadStatus' => 0
  4967. );
  4968. $invoice->setInvoiceByCondition ( $item );
  4969. $item = array (
  4970. 'date' => date ( "Y-m-d H:i:s" ),
  4971. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4972. 'status' => 11,
  4973. 'img' => $this->staff [0] ['avatar'],
  4974. 'username' => $this->staff [0] ['username'],
  4975. 'uid' => $this->staff [0] ['sid'],
  4976. 'category' => $this->staff [0] ['category'],
  4977. 'iid' => $invoiceDetails ['iid']
  4978. );
  4979. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4980. // 公司流水-解绑时删除流水
  4981. Doo::loadModel ( 'wasteBook' );
  4982. $wasteBook = new wasteBook ();
  4983. // $wasteBook->delete ( array (
  4984. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4985. // 'limit' => 1
  4986. // ) );
  4987. // 银行
  4988. /*
  4989. * $abDetail = $wasteBook->getAccountBookByAid (2,7,$irDetails ['irid'] ); $accountBank=''; if ($irDetails ['receivablesBank']=='纵横广发'){ $accountBank='CGBDeposit'; }elseif($irDetails ['receivablesBank']=='纵横工行'){ $accountBank='ICBCDeposit'; }elseif($irDetails ['receivablesBank']=='华润银行'){ $accountBank='HUADeposit'; }elseif($irDetails ['receivablesBank']=='个人广发'){ $accountBank='PersonalDeposit'; } if (empty($abDetail)){ $item = array ( 'dataID' => $irDetails ['irid'], 'expensesType' => 2, 'accountType' => 7, 'accountPriceShow'=>$irDetails ['receivablesPrice'], 'accountPrice' => -$irDetails ['receivablesPrice'], 'accountBank'=>$accountBank, 'cid'=>$this->staff[0]['cid'], 'name'=>$this->staff[0]['username'], 'sid'=>$this->staff[0]['sid'], 'inputDate'=>date ( "Y-m-d H:i:s" ) ); $wasteBook->setAccountBookStatistics($item); }
  4990. */
  4991. return "/invoiceReceivablesAS";
  4992. }
  4993. /**
  4994. * 或者该收款下的所以发票
  4995. */
  4996. function ajaxGetInvoiceReceivablesByInvoice() {
  4997. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4998. Doo::loadModel ( 'invoice' );
  4999. $invoice = new invoice ();
  5000. Doo::loadModel ( 'invoiceReceivables' );
  5001. $invoiceReceivables = new invoiceReceivables ();
  5002. $irid = $invoice->authcode ( $irid );
  5003. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5004. die ( 'illegal request' );
  5005. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5006. $iidString = $irDetails ['iid'];
  5007. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5008. if (! empty ( $irDetails ['iidExtend'] ))
  5009. $iidString .= ',' . implode ( ',', $iidExtend );
  5010. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5011. $html = "";
  5012. foreach ( $invoiceList as $key => $value ) {
  5013. $title = $value ['invoiceTitle'];
  5014. if (! empty ( $value ['invoiceCompany'] ))
  5015. $title = $value ['invoiceCompany'];
  5016. $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>';
  5017. }
  5018. echo json_encode ( array (
  5019. 'status' => 1,
  5020. 'html' => $html
  5021. ) );
  5022. }
  5023. /**
  5024. * 发票管理
  5025. */
  5026. function invoiceAS() {
  5027. Doo::loadModel ( 'invoice' );
  5028. $invoice = new invoice ();
  5029. Doo::loadModel ( 'invoiceReceivables' );
  5030. $invoiceReceivables = new invoiceReceivables ();
  5031. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5032. $page_size = 18;
  5033. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5034. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5035. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5036. $dateArr = explode ( ':', $date );
  5037. $D1 = '';
  5038. $D2 = '';
  5039. if (! empty ( $date )) {
  5040. $D1 = $dateArr [0] . " 00:00:00 ";
  5041. if (isset ( $dateArr [1] ))
  5042. $D2 = $dateArr [1] . " 23:59:59 ";
  5043. else
  5044. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5045. // $D2 = $dateArr [1];
  5046. }
  5047. $con = ' status=2 ';
  5048. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5049. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5050. if ($status == 'UNRECORD')
  5051. $con .= ' and printStatus=1 and untreadStatus=0';
  5052. elseif ($status == 'RECORD')
  5053. $con .= ' and printStatus=1 and untreadStatus=3';
  5054. elseif ($status == 'BOUNCED')
  5055. $con .= ' and untreadStatus=2';
  5056. elseif ($status == 'PARTRECORD')
  5057. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5058. elseif ($status == 'All') {
  5059. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5060. }
  5061. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5062. if (! empty ( $MebSea )) {
  5063. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5064. }
  5065. $pageinfo ['page'] = array (
  5066. 'previous' => ''
  5067. );
  5068. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5069. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5070. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5071. $this->data ['MebSeaEn'] = $MebSea;
  5072. $this->data ['MebSea'] = urlencode ( $MebSea );
  5073. $this->data ['date'] = $date;
  5074. $this->data ['page'] = $pageinfo;
  5075. $this->data ['get'] = $get;
  5076. $this->data ['list'] = $list;
  5077. $this->data ['status'] = $status;
  5078. $this->data ['memu'] = "invoice";
  5079. $this->data ['staff'] = $this->staff;
  5080. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5081. $this->render ( "/admin/invoiceAS", $this->data );
  5082. }
  5083. /**
  5084. * 收款管理
  5085. */
  5086. function invoiceReceivablesAS() {
  5087. Doo::loadModel ( 'invoiceReceivables' );
  5088. $invoiceReceivables = new invoiceReceivables ();
  5089. Doo::loadModel ( 'L_category' );
  5090. $lCategory = new L_category ();
  5091. $category = $lCategory->getCategory ();
  5092. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5093. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5094. $page_size = 10;
  5095. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5096. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5097. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5098. $dateArr = explode ( ':', $date );
  5099. $D1 = '';
  5100. $D2 = '';
  5101. if (! empty ( $date )) {
  5102. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5103. if (isset ( $dateArr [1] ))
  5104. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5105. else
  5106. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5107. }
  5108. $descField = 'a.receivablesDate';
  5109. if ($timeType == 'CREATE')
  5110. $descField = 'a.date';
  5111. $con = ' 1 ';
  5112. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5113. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5114. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5115. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5116. if ($status == 'Unclaimed')
  5117. $con .= ' and a.bindStatus=0';
  5118. elseif ($status == 'Credited')
  5119. $con .= ' and a.bindStatus=1';
  5120. elseif ($status == 'Claim')
  5121. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5122. elseif ($status == 'BBN')
  5123. $con .= ' and a.bankBatchNumber!=""';
  5124. elseif ($status == 'REFUND')
  5125. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5126. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5127. if (! empty ( $MebSea )) {
  5128. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5129. }
  5130. $pageinfo ['page'] = array (
  5131. 'previous' => ''
  5132. );
  5133. // if(!empty($con)){
  5134. // $con=' where 1 '.$con;
  5135. // }
  5136. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5137. // ' . $con ;
  5138. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5139. //echo $sql;
  5140. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5141. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5142. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5143. foreach ( $list as $key => $value ) {
  5144. $list [$key] ['category'] = '';
  5145. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5146. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5147. $list [$key] ['category'] = $receivablesCategory [1];
  5148. }
  5149. }
  5150. // print_r($list);
  5151. $this->data ['category'] = $category;
  5152. $this->data ['timeType'] = $timeType;
  5153. $this->data ['MebSeaEn'] = $MebSea;
  5154. $this->data ['MebSea'] = urlencode ( $MebSea );
  5155. $this->data ['date'] = $date;
  5156. $this->data ['page'] = $pageinfo;
  5157. $this->data ['get'] = $get;
  5158. $this->data ['list'] = $list;
  5159. $this->data ['status'] = $status;
  5160. $this->data ['memu'] = "invoice";
  5161. $this->data ['staff'] = $this->staff;
  5162. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5163. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5164. }
  5165. /**
  5166. * 删除一条收款
  5167. */
  5168. function delInvoiceReceivables() {
  5169. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5170. if (empty ( $iridKey ))
  5171. die ( 'illegal request' );
  5172. Doo::loadClass ( 'XDeode' );
  5173. $XDeode = new XDeode ( 5 );
  5174. $irid = $XDeode->decode ( $iridKey );
  5175. Doo::loadModel ( 'invoiceReceivables' );
  5176. $invoiceReceivables = new invoiceReceivables ();
  5177. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5178. if (empty ( $detail ))
  5179. die ( 'illegal request' );
  5180. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5181. // 扣除收款汇总信息 汇总
  5182. Doo::loadModel ( 'invoiceStatistics' );
  5183. $invoiceStatistics = new invoiceStatistics ();
  5184. $item = array (
  5185. 'date' => $detail ['receivablesDate'],
  5186. 'priceClass' => 2,
  5187. 'irid' => $detail ['irid'],
  5188. 'receivablesPrice' => - $detail ['receivablesPrice']
  5189. );
  5190. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5191. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5192. $item += array (
  5193. 'cid' => $receivablesCategory [0]
  5194. );
  5195. }
  5196. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5197. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5198. $item += array (
  5199. 'staff' => $receivablesStaff [0]
  5200. );
  5201. }
  5202. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5203. return '/invoiceReceivablesAS';
  5204. }
  5205. /**
  5206. * 添加退款信息
  5207. */
  5208. function setInvoiceReceivablesRefund() {
  5209. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5210. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5211. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5212. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5213. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5214. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5215. if ($refundPrice < 0)
  5216. die ( 'illegal request' );
  5217. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5218. Doo::loadModel ( 'invoiceReceivables' );
  5219. $invoiceReceivables = new invoiceReceivables ();
  5220. Doo::loadModel ( 'invoiceRefund' );
  5221. $invoiceRefund = new invoiceRefund ();
  5222. $irid = $invoiceReceivables->authcode ( $iridKey );
  5223. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5224. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5225. die ( 'illegal request' );
  5226. $invoiceReceivables = new invoiceReceivables ();
  5227. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5228. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5229. ';
  5230. $item = array (
  5231. 'irid' => $irid,
  5232. 'refundCompany' => $refundCompany,
  5233. 'refundNumber' => $refundNumber,
  5234. 'refundPrice' => $refundPrice,
  5235. 'refundRemarks' => $refundRemarks,
  5236. 'refundLog' => $refundLog
  5237. );
  5238. if ($refundType == 1) {
  5239. $item += array (
  5240. 'refundType' => $refundType,
  5241. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5242. 'bindStatus' => 2
  5243. );
  5244. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5245. $item += array (
  5246. 'refundType' => 1,
  5247. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5248. 'bindStatus' => 2
  5249. );
  5250. } else {
  5251. $item += array (
  5252. 'refundType' => $refundType,
  5253. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5254. );
  5255. }
  5256. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5257. // 添加退款记录
  5258. $item = array (
  5259. 'irid' => $irid,
  5260. 'refundType' => $refundType,
  5261. 'refundCompany' => $refundCompany,
  5262. 'refundNumber' => $refundNumber,
  5263. 'refundPrice' => $refundPrice,
  5264. 'refundLog' => $refundLog,
  5265. 'refundRemarks' => $refundRemarks,
  5266. 'date' => date ( "Y-m-d H:i:s" )
  5267. );
  5268. $invoiceRefund->addInvoiceRefund ( $item );
  5269. // 扣除收款汇总信息 汇总
  5270. Doo::loadModel ( 'invoiceStatistics' );
  5271. $invoiceStatistics = new invoiceStatistics ();
  5272. $item = array (
  5273. 'date' => $irDetail ['receivablesDate'],
  5274. 'priceClass' => 2,
  5275. 'irid' => $irDetail ['irid'],
  5276. 'receivablesPrice' => - $refundPrice
  5277. );
  5278. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5279. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5280. $item += array (
  5281. 'cid' => $receivablesCategory [0]
  5282. );
  5283. }
  5284. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5285. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5286. $item += array (
  5287. 'staff' => $receivablesStaff [0]
  5288. );
  5289. }
  5290. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5291. // 公司日常支出流水
  5292. Doo::loadModel ( 'wasteBook' );
  5293. $wasteBook = new wasteBook ();
  5294. $accountBank = '';
  5295. if ($irDetail ['receivablesBank'] == '纵横广发') {
  5296. $accountBank = 'CGBDeposit';
  5297. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  5298. $accountBank = 'ICBCDeposit';
  5299. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  5300. $accountBank = 'HUADeposit';
  5301. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  5302. $accountBank = 'PersonalDeposit';
  5303. }
  5304. $itemWaste = array (
  5305. 'accountPrice' => - $refundPrice,
  5306. 'expensesType' => 2,
  5307. 'accountType' => 11,
  5308. 'accountPriceShow' => $refundPrice,
  5309. 'dataID' => $irid,
  5310. 'accountBank' => $accountBank,
  5311. 'category' => $this->staff [0] ['category'],
  5312. 'cid' => $this->staff [0] ['cid'],
  5313. 'name' => $this->staff [0] ['username'],
  5314. 'sid' => $this->staff [0] ['sid'],
  5315. 'inputDate' => date ( "Y-m-d H:i:s" )
  5316. );
  5317. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5318. return '/invoiceReceivablesAS';
  5319. }
  5320. die ( 'illegal request' );
  5321. }
  5322. function ajaxCheckInvoiceReceivablesRefund() {
  5323. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5324. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5325. if ($refundPrice < 0) {
  5326. echo json_encode ( array (
  5327. 'error' => '金额不能为负'
  5328. ) );
  5329. die ();
  5330. }
  5331. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5332. Doo::loadModel ( 'invoiceReceivables' );
  5333. $invoiceReceivables = new invoiceReceivables ();
  5334. $irid = $invoiceReceivables->authcode ( $iridKey );
  5335. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5336. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5337. echo json_encode ( array (
  5338. 'error' => '退款金额不能超过收款金额'
  5339. ) );
  5340. die ();
  5341. }
  5342. echo json_encode ( array (
  5343. 'ok' => '可以使用!'
  5344. ) );
  5345. die ();
  5346. }
  5347. }
  5348. /**
  5349. * 获得收款退款信息
  5350. */
  5351. function getRefundByDetail() {
  5352. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5353. Doo::loadModel ( 'invoiceReceivables' );
  5354. $invoiceReceivables = new invoiceReceivables ();
  5355. if (! empty ( $iridKey )) {
  5356. $irid = $invoiceReceivables->authcode ( $iridKey );
  5357. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5358. echo json_encode ( array (
  5359. 'status' => 1,
  5360. 'irDetail' => $irDetail
  5361. ) );
  5362. die ();
  5363. }
  5364. echo json_encode ( array (
  5365. 'status' => 2
  5366. ) );
  5367. }
  5368. /**
  5369. * 根据收款序列号获得收款退款信息
  5370. */
  5371. function ajaxGetInvoiceReceivablesBySerial() {
  5372. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5373. if (! empty ( $receivablesSerial )) {
  5374. Doo::loadModel ( 'invoiceReceivables' );
  5375. $invoiceReceivables = new invoiceReceivables ();
  5376. // , ' and refundLog=""'
  5377. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5378. $html = '';
  5379. if (! empty ( $irDetail ))
  5380. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5381. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5382. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5383. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5384. <td>' . $irDetail ['recepitTitleMark'] . '
  5385. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5386. </td>';
  5387. echo json_encode ( array (
  5388. 'status' => 1,
  5389. 'html' => $html,
  5390. 'irDetail' => $irDetail
  5391. ) );
  5392. die ();
  5393. }
  5394. echo json_encode ( array (
  5395. 'status' => 2
  5396. ) );
  5397. }
  5398. /**
  5399. * 绑定新收款
  5400. */
  5401. function relationNewInvoiceReceivables() {
  5402. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5403. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5404. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5405. Doo::loadModel ( 'invoiceReceivables' );
  5406. $invoiceReceivables = new invoiceReceivables ();
  5407. Doo::loadClass ( 'XDeode' );
  5408. $XDeode = new XDeode ( 5 );
  5409. $irid = $XDeode->decode ( $iridKey );
  5410. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5411. echo $irid . 'bbb' . $iridOld;
  5412. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5413. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5414. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5415. die ( 'illegal request' );
  5416. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5417. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5418. ';
  5419. $invoiceReceivables = new invoiceReceivables ();
  5420. $item = array (
  5421. 'irid' => $iridOld,
  5422. 'relationIrid' => $irid,
  5423. 'relationLog' => $relationLog
  5424. );
  5425. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5426. return '/invoiceReceivablesAS';
  5427. }
  5428. die ( 'illegal request' );
  5429. }
  5430. // function invoiceApprovalAchieve() {
  5431. // Doo::loadModel ( 'invoice' );
  5432. // $invoice = new invoice ();
  5433. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5434. // $page_size = 12;
  5435. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5436. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5437. // $get = "/" . $date;
  5438. // $con = '';
  5439. // if ($date == 'MONTHO')
  5440. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5441. // elseif ($date == 'MONTHT')
  5442. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5443. // elseif ($date == 'MONTHY')
  5444. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5445. // if (! empty ( $MebSea )) {
  5446. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5447. // $get .= "/" . $MebSea;
  5448. // }
  5449. // $pageinfo ['page'] = array (
  5450. // 'previous' => ''
  5451. // );
  5452. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5453. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5454. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5455. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5456. // // print_r($list);
  5457. // $this->data ['MebSeaEn'] = $MebSea;
  5458. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5459. // $this->data ['get'] = $get;
  5460. // $this->data ['page'] = $pageinfo;
  5461. // $this->data ['list'] = $list;
  5462. // $this->data ['date'] = $date;
  5463. // $this->data ['memu'] = "invoice";
  5464. // $this->data ['staff'] = $this->staff;
  5465. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5466. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5467. // }
  5468. /**
  5469. * 获得审批发票的信息以及审批页面
  5470. */
  5471. function ajaxGetInvoiceApprovalDetail() {
  5472. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5473. if (empty ( $serial )) {
  5474. echo json_encode ( array (
  5475. 'status' => 2,
  5476. 'msg' => 'illegal request'
  5477. ) );
  5478. die ();
  5479. }
  5480. Doo::loadModel ( 'invoice' );
  5481. $invoice = new invoice ();
  5482. Doo::loadModel ( 'invoiceOperationLog' );
  5483. $invoiceOperationLog = new invoiceOperationLog ();
  5484. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5485. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5486. if (empty ( $detail ))
  5487. $html = '';
  5488. else {
  5489. $html = '
  5490. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5491. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5492. <input type="hidden" name="status" value="">
  5493. <input type="hidden" name="divApproval" value="divApproval">
  5494. <div class="modal-dialog modal-lg">
  5495. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5496. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5497. <tr>
  5498. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5499. </tr>
  5500. <tr>
  5501. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5502. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5503. </tr>
  5504. <tr>
  5505. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5506. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5507. </tr>
  5508. <tr>
  5509. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5510. </td>
  5511. </tr>
  5512. <tr>
  5513. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5514. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5515. </tr>
  5516. <tr>
  5517. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5518. </tr></tbody></table>';
  5519. if ($detail ['invoiceType'] == 0)
  5520. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5521. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5522. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5523. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5524. </tr>';
  5525. else
  5526. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5527. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5528. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5529. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5530. ';
  5531. $html .= '<tr>
  5532. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5533. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5534. </tr>
  5535. <tr>
  5536. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5537. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5538. </tr></tbody></table>';
  5539. if ($detail ['doPost'] == 1) {
  5540. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5541. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5542. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5543. </tr><tr>
  5544. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5545. </tr><tr>
  5546. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5547. </tr>
  5548. ';
  5549. if ($detail ['expressCom'] == 'SF')
  5550. $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>';
  5551. else
  5552. $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>';
  5553. $html .= '</tbody></table>';
  5554. }
  5555. if (! empty ( $invoiceOperationLogList )) {
  5556. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5557. foreach ( $invoiceOperationLogList as $key => $value ) {
  5558. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5559. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5560. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5561. if ($value ['status'] == 2) {
  5562. $html .= '<span class="colGreen">同意</span>';
  5563. } elseif ($value ['status'] == 3) {
  5564. $html .= '<span class="colOrange">退回</span>';
  5565. } elseif ($value ['status'] == 5) {
  5566. $html .= '<span class="colGreen">打印</span>';
  5567. } elseif ($value ['status'] == 4) {
  5568. $html .= '<span class="colRed">终止</span>';
  5569. }
  5570. $html .= $value ['operation'] . '</p></blockquote>';
  5571. }
  5572. }
  5573. $html .= '</td></tr></tbody></table>';
  5574. }
  5575. $html .= '</div><div class="modal-footer">
  5576. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5577. <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>
  5578. <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>
  5579. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5580. </form>
  5581. <script type="text/javascript">
  5582. $("a[node-approval^=\'approval\']").click(function() {
  5583. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5584. $("form[name=\'invoiceApproval\']").submit();
  5585. });
  5586. </script>
  5587. ';
  5588. }
  5589. echo json_encode ( array (
  5590. 'status' => 1,
  5591. 'html' => $html
  5592. ) );
  5593. die ();
  5594. }
  5595. /**
  5596. * 获得审批发票分页数据
  5597. */
  5598. function ajaxGetinvoiceApprovalAchieve() {
  5599. Doo::loadModel ( 'invoice' );
  5600. $invoice = new invoice ();
  5601. Doo::loadModel ( 'staff' );
  5602. $staff = new staff ();
  5603. Doo::loadClass ( 'XDeode' );
  5604. $XDeode = new XDeode ( 5 );
  5605. Doo::loadModel ( 'invoiceTraining' );
  5606. $invoiceTraining = new invoiceTraining ();
  5607. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5608. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5609. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5610. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5611. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5612. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5613. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5614. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5615. $MebSea = $this->get_args ( 'search' );
  5616. $MebSea = $MebSea ['value'];
  5617. $page_size = $length;
  5618. $con = '';
  5619. if ($status == 'ALL')
  5620. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5621. elseif ($status == 'PEND')
  5622. $con = ' isDelete=0 and status=1';
  5623. elseif ($status == 'APPROVED')
  5624. $con = ' isDelete=0 and status=2';
  5625. if ($invoiceType == 'ORDINARY')
  5626. $con .= ' and invoiceType=0 ';
  5627. elseif ($invoiceType == 'SPECIAL')
  5628. $con .= ' and invoiceType=1 ';
  5629. if ($invoiceTrain == 'ORDINARY')
  5630. $con .= ' and trainId=0 ';
  5631. elseif ($invoiceTrain == 'TRAIN')
  5632. $con .= ' and trainId!=0 ';
  5633. if ($invoiceTrainName != 'ALL') {
  5634. $trainId = $XDeode->decode ( $invoiceTrainName );
  5635. if (is_numeric ( $trainId ))
  5636. $con .= ' and trainId =' . $trainId;
  5637. }
  5638. $dateArr = explode ( ':', $date );
  5639. $D1 = $dateString = '';
  5640. $D2 = '';
  5641. if (! empty ( $date )) {
  5642. $D1 = $dateArr [0];
  5643. if (isset ( $dateArr [1] ))
  5644. $D2 = $dateArr [1];
  5645. else
  5646. $D2 = '';
  5647. $dateString = $D1 . " : " . $D2;
  5648. }
  5649. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5650. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5651. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5652. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5653. if (! empty ( $MebSea ))
  5654. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5655. // /
  5656. $pageinfo ['page'] = array (
  5657. 'previous' => ''
  5658. );
  5659. $sql = ' ' . $con;
  5660. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5661. $limit = $page . ',' . $page_size;
  5662. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5663. $approvalList = array ();
  5664. $html = '<script type="text/javascript">
  5665. </script>';
  5666. // 结算结束不能修改方式
  5667. Doo::loadModel ( 'receipt' );
  5668. $receipt = new receipt ();
  5669. foreach ( $list as $key => $value ) {
  5670. $irDetail = array ();
  5671. // 结算方式
  5672. $receiptDetail = array ();
  5673. if ($value ['trainId'] != 0) {
  5674. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5675. }
  5676. if (! empty ( $receiptDetail )) {
  5677. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5678. array_push ( $irDetail, '' );
  5679. } else {
  5680. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5681. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5682. } elseif ($value ['status'] == 2) {
  5683. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5684. } else
  5685. array_push ( $irDetail, '' );
  5686. }
  5687. } else {
  5688. if ($value ['status'] == 2) {
  5689. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5690. } else
  5691. array_push ( $irDetail, '' );
  5692. }
  5693. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5694. if ($value ['invoiceType'] == 1)
  5695. array_push ( $irDetail, $value ['invoiceCompany'] );
  5696. else
  5697. array_push ( $irDetail, $value ['invoiceTitle'] );
  5698. array_push ( $irDetail, $value ['TIN'] );
  5699. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5700. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5701. array_push ( $irDetail, $value ['remark'] );
  5702. array_push ( $irDetail, $value ['invoiceElement'] );
  5703. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5704. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5705. if ($value ['invoiceType'] == 1) {
  5706. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5707. } else {
  5708. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5709. }
  5710. if ($value ['settlementType'] == 0) {
  5711. array_push ( $irDetail, '软件销售' );
  5712. } else {
  5713. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5714. array_push ( $irDetail, $itDetail ['trainName'] );
  5715. }
  5716. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5717. array_push ( $irDetail, $value ['recipientsAddress'] );
  5718. array_push ( $irDetail, $value ['mailItems'] );
  5719. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5720. $fchtml = $value ['OL'] ['operation'];
  5721. if (count ( $list ) == $page_size)
  5722. $fchtml = $value ['OL'] ['operation'] . $html;
  5723. // 最后的审批意见
  5724. array_push ( $irDetail, $fchtml );
  5725. if ($value ['status'] == 2)
  5726. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5727. elseif ($value ['status'] == 3)
  5728. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5729. elseif ($value ['status'] == 4)
  5730. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5731. else
  5732. array_push ( $irDetail, '' );
  5733. array_push ( $approvalList, $irDetail );
  5734. }
  5735. // $approvalListJson = json_encode ( $approvalList );
  5736. $recordsFiltered = $pageinfo ['total_data'];
  5737. echo json_encode ( array (
  5738. "draw" => intval ( $draw ),
  5739. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5740. "recordsFiltered" => intval ( $recordsFiltered ),
  5741. "data" => $approvalList
  5742. ), JSON_UNESCAPED_UNICODE );
  5743. }
  5744. /**
  5745. * 审批发票查看更多--重构
  5746. */
  5747. function invoiceApprovalAchieve() {
  5748. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5749. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5750. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5751. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5752. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5753. Doo::loadModel ( 'invoiceTraining' );
  5754. $invoiceTraining = new invoiceTraining ();
  5755. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5756. $this->data ['trainList'] = $trainList;
  5757. $this->data ['dateString'] = $date;
  5758. $this->data ['status'] = $status;
  5759. $this->data ['invoiceType'] = $invoiceType;
  5760. $this->data ['invoiceTrain'] = $invoiceTrain;
  5761. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5762. $this->data ['memu'] = "invoice";
  5763. $this->data ['staff'] = $this->staff;
  5764. $this->data ['receiptMemu'] = 'invoiceApproval';
  5765. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5766. }
  5767. function invoiceTAchieve() {
  5768. Doo::loadModel ( 'invoice' );
  5769. $invoice = new invoice ();
  5770. Doo::loadClass ( 'XDeode' );
  5771. $XDeode = new XDeode ( 5 );
  5772. Doo::loadModel ( 'staff' );
  5773. $staff = new staff ();
  5774. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5775. $page_size = 12;
  5776. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5777. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5778. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5779. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5780. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5781. Doo::loadModel ( 'invoiceTraining' );
  5782. $invoiceTraining = new invoiceTraining ();
  5783. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5784. $get = "/" . $date;
  5785. $con = '';
  5786. if ($date == 'MONTHO')
  5787. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5788. elseif ($date == 'MONTHT')
  5789. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5790. elseif ($date == 'MONTHY')
  5791. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5792. if ($invoiceType == 'ORDINARY')
  5793. $con .= ' and invoiceType=0 ';
  5794. elseif ($invoiceType == 'SPECIAL')
  5795. $con .= ' and invoiceType=1 ';
  5796. if ($invoiceTrain == 'ORDINARY')
  5797. $con .= ' and trainId=0 ';
  5798. elseif ($invoiceTrain == 'TRAIN')
  5799. $con .= ' and trainId!=0 ';
  5800. if ($invoiceTrainName != 'ALL') {
  5801. $trainId = $XDeode->decode ( $invoiceTrainName );
  5802. if (is_numeric ( $trainId ))
  5803. $con .= ' and trainId =' . $trainId;
  5804. }
  5805. if (! empty ( $MebSea )) {
  5806. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5807. $get .= "/" . $MebSea;
  5808. }
  5809. $pageinfo ['page'] = array (
  5810. 'previous' => ''
  5811. );
  5812. $sql = "";
  5813. $action = "";
  5814. if ($this->ACTION == 'invoicePrintAchieve') {
  5815. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5816. $action = "invoicePrintAchieve";
  5817. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5818. // and untreadStatus=0
  5819. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5820. $action = "invoicePostAchieve";
  5821. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5822. $sql = " untreadStatus=2 and status=2 " . $con;
  5823. $action = "invoiceUntreadAchieve";
  5824. }
  5825. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5826. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5827. $this->data ['MebSeaEn'] = $MebSea;
  5828. $this->data ['MebSea'] = urlencode ( $MebSea );
  5829. $this->data ['get'] = $get;
  5830. $this->data ['page'] = $pageinfo;
  5831. $this->data ['trainList'] = $trainList;
  5832. $this->data ['invoiceType'] = $invoiceType;
  5833. $this->data ['invoiceTrain'] = $invoiceTrain;
  5834. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5835. $this->data ['date'] = $date;
  5836. $this->data ['memu'] = "invoice";
  5837. $this->data ['staff'] = $this->staff;
  5838. if ($this->ACTION == 'invoicePrintAchieve') {
  5839. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5840. $this->data ['receiptMemu'] = 'invoicePrint';
  5841. $this->data ['list'] = $list;
  5842. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5843. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5844. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5845. Doo::loadModel ( 'express' );
  5846. $express = new express ();
  5847. $expressList = $express->getExpressByAll ();
  5848. $this->data ['expressList'] = $expressList;
  5849. $this->data ['receiptMemu'] = 'invoicePost';
  5850. $this->data ['list'] = $list;
  5851. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5852. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5853. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5854. $this->data ['receiptMemu'] = 'invoiceUntread';
  5855. $this->data ['list'] = $list;
  5856. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5857. }
  5858. }
  5859. /**
  5860. * 公司应收款
  5861. */
  5862. function invoiceAggregateCompanyDetail() {
  5863. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5864. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5865. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5866. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5867. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5868. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5869. Doo::loadClass ( 'XDeode' );
  5870. $XDeode = new XDeode ( 5 );
  5871. Doo::loadModel ( 'invoice' );
  5872. $invoice = new invoice ();
  5873. Doo::loadModel ( 'staff' );
  5874. $staff = new staff ();
  5875. Doo::loadModel ( "invoiceCompanyManage" );
  5876. $invoiceCompanyManage = new invoiceCompanyManage ();
  5877. Doo::loadModel ( 'L_category' );
  5878. $category = new L_category ();
  5879. $sid = '';
  5880. if (! empty ( $sidKey )) {
  5881. $sid = $XDeode->decode ( $sidKey );
  5882. }
  5883. $staffDetail = $staff->getStaffBySid ( $sid );
  5884. $cid = '';
  5885. if (! empty ( $cidKey )) {
  5886. $cid = $XDeode->decode ( $cidKey );
  5887. }
  5888. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5889. $cidList = array ();
  5890. foreach ( $imcStaff as $key => $value ) {
  5891. array_push ( $cidList, $value ['cid'] );
  5892. }
  5893. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5894. $cidString = implode ( ',', $cidList );
  5895. if (empty ( $cid ))
  5896. $staffList = $staff->getStaffInCid ( $cidString );
  5897. else
  5898. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5899. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5900. $page_size = 25;
  5901. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5902. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5903. $con = ' status=2 and untreadStatus!=2 ';
  5904. $statisticsCon = '';
  5905. if (! empty ( $year ) && is_numeric ( $year ))
  5906. $con .= ' and Year(printTime)=' . $year . '';
  5907. if (! empty ( $month ) && is_numeric ( $month ))
  5908. $con .= ' and Month(printTime)="' . $month . '" ';
  5909. if ($status == 'UNRECORD')
  5910. $con .= ' and printStatus=1 and untreadStatus=0';
  5911. elseif ($status == 'RECORD')
  5912. $con .= ' and printStatus=1 and untreadStatus=3';
  5913. elseif ($status == 'BOUNCED')
  5914. $con .= ' and untreadStatus=2';
  5915. elseif ($status == 'PARTRECORD')
  5916. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5917. elseif ($status == 'All') {
  5918. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5919. }
  5920. if (! empty ( $sid ) && is_numeric ( $sid ))
  5921. $con .= ' and sid=' . $sid;
  5922. if (! empty ( $cid ) && is_numeric ( $cid ))
  5923. $con .= ' and cid=' . $cid;
  5924. else
  5925. $con .= ' and cid in (' . $cidString . ')';
  5926. // 开票内容筛选
  5927. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5928. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5929. }
  5930. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5931. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5932. if (! empty ( $titleORno )) {
  5933. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5934. }
  5935. $pageinfo ['page'] = array (
  5936. 'previous' => ''
  5937. );
  5938. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5939. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5940. // 应收款合计
  5941. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5942. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5943. $monthHtml = "";
  5944. if ($year != "ALL") {
  5945. for($i = 1; $i <= 12; $i ++) {
  5946. if ($i == $month)
  5947. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5948. else
  5949. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5950. }
  5951. }
  5952. $this->data ['monthHtml'] = $monthHtml;
  5953. $this->data ['year'] = $year;
  5954. $this->data ['month'] = $month;
  5955. $this->data ['ics'] = $ics;
  5956. $this->data ['cidKey'] = $cidKey;
  5957. $this->data ['sid'] = $sid;
  5958. $this->data ['staffDetail'] = $staffDetail;
  5959. $this->data ['staffList'] = $staffList;
  5960. $this->data ['titleORnoEn'] = $titleORno;
  5961. $this->data ['titleORno'] = urlencode ( $titleORno );
  5962. $this->data ['invoiceDetail'] = array (
  5963. 'invoiceElement' => $invoiceElement
  5964. );
  5965. $this->data ['page'] = $pageinfo;
  5966. $this->data ['get'] = $get;
  5967. $this->data ['list'] = $list;
  5968. $this->data ['status'] = $status;
  5969. $this->data ['categoryList'] = $categoryList;
  5970. $this->data ['memu'] = "invoice";
  5971. $this->data ['staff'] = $this->staff;
  5972. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5973. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5974. }
  5975. /**
  5976. * 获取一条收款信息
  5977. */
  5978. function ajaxGetInvoiceReceivables() {
  5979. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5980. Doo::loadModel ( 'invoiceReceivables' );
  5981. $invoiceReceivables = new invoiceReceivables ();
  5982. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5983. echo json_encode ( array (
  5984. 'status' => 1,
  5985. 'detail' => $detail
  5986. ) );
  5987. }
  5988. /**
  5989. * 异步获取办事处用户
  5990. */
  5991. function ajaxGetStaffByCategory() {
  5992. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5993. Doo::loadModel ( 'staff' );
  5994. $staff = new staff ();
  5995. if ($cid == "PUBLIC") {
  5996. echo json_encode ( array (
  5997. 'status' => 1,
  5998. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5999. ) );
  6000. die ();
  6001. }
  6002. if (! is_numeric ( $cid )) {
  6003. echo json_encode ( array (
  6004. 'status' => 0,
  6005. 'msg' => 'illegal request'
  6006. ) );
  6007. die ();
  6008. }
  6009. $staffList = $staff->getStaffByCid ( $cid );
  6010. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6011. foreach ( $staffList as $key => $value ) {
  6012. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6013. }
  6014. echo json_encode ( array (
  6015. 'status' => 1,
  6016. 'html' => $html
  6017. ) );
  6018. }
  6019. /**
  6020. * 异步获取一条发票的邮寄信息
  6021. */
  6022. function ajaxGetInvoicePostDetail() {
  6023. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6024. Doo::loadModel ( 'invoice' );
  6025. $invoice = new invoice ();
  6026. $iid = $invoice->authcode ( $iid );
  6027. Doo::loadModel ( 'express' );
  6028. $express = new express ();
  6029. $expressList = $express->getExpressByAll ();
  6030. if (! is_numeric ( $iid )) {
  6031. echo json_encode ( array (
  6032. 'status' => 0,
  6033. 'msg' => 'illegal request'
  6034. ) );
  6035. die ();
  6036. }
  6037. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6038. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6039. $html = "";
  6040. foreach ( $expressList as $key => $value ) {
  6041. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6042. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6043. else
  6044. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6045. }
  6046. $invoiceDetail ['eaHtml'] = $html;
  6047. echo json_encode ( array (
  6048. 'status' => 1,
  6049. 'invoiceDetail' => $invoiceDetail
  6050. ) );
  6051. }
  6052. /**
  6053. *
  6054. * @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 ) ); }
  6055. */
  6056. /**
  6057. *
  6058. * @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 ) ); }
  6059. */
  6060. /**
  6061. * 我的收款中 选择哪个发票入账,进行金额判断
  6062. */
  6063. function ajaxCompareInvoicePrice() {
  6064. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6065. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6066. Doo::loadModel ( 'invoice' );
  6067. $invoice = new invoice ();
  6068. Doo::loadModel ( 'invoiceReceivables' );
  6069. $invoiceReceivables = new invoiceReceivables ();
  6070. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6071. $keyList = explode ( ';', $claimKey );
  6072. $receivablesPrice = 0;
  6073. foreach ( $keyList as $key => $value ) {
  6074. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6075. $receivablesPrice += $detailM ['receivablesPrice'];
  6076. }
  6077. if ($receivablesPrice > $detail ['invoicePrice']) {
  6078. $price = $receivablesPrice - $detail ['invoicePrice'];
  6079. echo json_encode ( array (
  6080. 'status' => 1,
  6081. 'price' => $price
  6082. ) );
  6083. } else
  6084. echo json_encode ( array (
  6085. 'status' => 2
  6086. ) );
  6087. }
  6088. /**
  6089. * 获得打印发票
  6090. */
  6091. function ajaxGetInvoiceInfoByPrint() {
  6092. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6093. if (empty ( $serial )) {
  6094. echo json_encode ( array (
  6095. 'status' => 2,
  6096. 'msg' => 'illegal request'
  6097. ) );
  6098. die ();
  6099. }
  6100. Doo::loadModel ( 'invoice' );
  6101. $invoice = new invoice ();
  6102. Doo::loadModel ( 'invoiceOperationLog' );
  6103. $invoiceOperationLog = new invoiceOperationLog ();
  6104. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6105. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6106. Doo::loadModel ( 'invoicePaper' );
  6107. $invoicePaper = new invoicePaper ();
  6108. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6109. if (empty ( $detail ))
  6110. $html = '';
  6111. else {
  6112. $html = '
  6113. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6114. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6115. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6116. <div class="modal-dialog modal-lg">
  6117. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6118. <div class="modal-body saeaList">
  6119. <table class="table table-bordered table-condensed"><tbody>
  6120. <tr>
  6121. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6122. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6123. </tr>
  6124. <tr>
  6125. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6126. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6127. </tr>
  6128. <tr>
  6129. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6130. </td>
  6131. </tr>
  6132. <tr>
  6133. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6134. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6135. </tr>
  6136. <tr>
  6137. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6138. </tr></tbody></table>';
  6139. if ($detail ['invoiceType'] == 0)
  6140. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6141. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6142. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6143. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6144. </tr>';
  6145. else
  6146. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6147. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6148. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6149. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6150. ';
  6151. $html .= '<tr>
  6152. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6153. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6154. </tr>
  6155. <tr>
  6156. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6157. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6158. </tr></tbody></table>';
  6159. if ($detail ['doPost'] == 1)
  6160. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6161. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6162. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6163. </tr><tr>
  6164. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6165. </tr><tr>
  6166. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6167. </tr></tbody></table>';
  6168. if (! empty ( $invoiceOperationLogList )) {
  6169. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6170. foreach ( $invoiceOperationLogList as $key => $value ) {
  6171. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6172. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6173. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6174. if ($value ['status'] == 2) {
  6175. $html .= '<span class="colGreen">同意</span>';
  6176. } elseif ($value ['status'] == 3) {
  6177. $html .= '<span class="colOrange">退回</span>';
  6178. } elseif ($value ['status'] == 5) {
  6179. $html .= '<span class="colGreen">打印</span>';
  6180. } elseif ($value ['status'] == 4) {
  6181. $html .= '<span class="colRed">终止</span>';
  6182. }
  6183. $html .= $value ['operation'] . '</p></blockquote>';
  6184. }
  6185. }
  6186. $html .= '</td>
  6187. <td><span class="colRed">*</span>
  6188. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6189. foreach ( $invoicePaperList as $key => $value ) {
  6190. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6191. }
  6192. $html .= '</select>
  6193. <span class="red" id="p-msg"></span>
  6194. </td>
  6195. </tr></tbody></table>';
  6196. }
  6197. $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>
  6198. </div></div></form>
  6199. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6200. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6201. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6202. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6203. ';
  6204. }
  6205. echo json_encode ( array (
  6206. 'status' => 1,
  6207. 'html' => $html
  6208. ) );
  6209. die ();
  6210. }
  6211. /**
  6212. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6213. */
  6214. function ajaxGetInvoiceInfoByType() {
  6215. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6216. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6217. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6218. if (empty ( $serial )) {
  6219. echo json_encode ( array (
  6220. 'status' => 2,
  6221. 'msg' => 'illegal request'
  6222. ) );
  6223. die ();
  6224. }
  6225. if ($type == 'INVOICE') {
  6226. Doo::loadModel ( 'invoice' );
  6227. $invoice = new invoice ();
  6228. Doo::loadModel ( 'invoiceOperationLog' );
  6229. $invoiceOperationLog = new invoiceOperationLog ();
  6230. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6231. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6232. if (empty ( $detail ))
  6233. $html = '';
  6234. else {
  6235. $html = '
  6236. <div class="modal-dialog modal-lg">
  6237. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6238. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6239. <tr>
  6240. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6241. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6242. </tr>
  6243. <tr>
  6244. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6245. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6246. </tr>
  6247. <tr>
  6248. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6249. </td>
  6250. </tr>
  6251. <tr>
  6252. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6253. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6254. </tr>
  6255. <tr>
  6256. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6257. </tr>';
  6258. if ($detail ['settlementType'] == 1)
  6259. $html .= '<tr>
  6260. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6261. </tr>';
  6262. else
  6263. $html .= '<tr>
  6264. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6265. </tr>';
  6266. $html .= ' </tbody></table>';
  6267. if ($detail ['invoiceType'] == 0){
  6268. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6269. <tr><th colspan="4" class="taC">增值税普通发票';
  6270. if($detail ['invoiceForm']==1){
  6271. $html .= '( <span class="colRed">电子发票</span> )';
  6272. }
  6273. $html .= '</th></tr><tr>
  6274. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6275. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6276. </tr>';
  6277. }else{
  6278. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6279. <tr><th colspan="4" class="taC">增值税专用发票';
  6280. if($detail ['invoiceForm']==1){
  6281. $html .= '( <span class="colRed">电子发票</span> )';
  6282. }
  6283. $html .= '</th></tr><tr>
  6284. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6285. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6286. ';
  6287. }
  6288. $html .= '<tr>
  6289. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6290. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6291. </tr>
  6292. <tr>
  6293. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6294. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6295. </tr></tbody></table>';
  6296. if ($detail ['doPost'] == 1) {
  6297. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6298. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6299. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6300. </tr><tr>
  6301. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6302. </tr><tr>
  6303. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6304. </tr>
  6305. ';
  6306. if ($detail ['expressCom'] == 'SF')
  6307. $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>';
  6308. else
  6309. $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>';
  6310. $html .= '</tbody></table>';
  6311. }
  6312. if ($detail ['invoiceForm'] == 1) {
  6313. $html .= '<table class="table table-bordered table-condensed">
  6314. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6315. <tr>
  6316. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6317. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6318. </tr></tbody></table>';
  6319. if ($detail ['expressCom'] == 'SF')
  6320. $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>';
  6321. else
  6322. $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>';
  6323. $html .= '</tbody></table>';
  6324. }
  6325. if (! empty ( $invoiceOperationLogList )) {
  6326. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6327. foreach ( $invoiceOperationLogList as $key => $value ) {
  6328. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6329. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6330. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6331. if ($value ['status'] == 2) {
  6332. $html .= '<span class="colGreen">同意</span>';
  6333. } elseif ($value ['status'] == 3) {
  6334. $html .= '<span class="colOrange">退回</span>';
  6335. } elseif ($value ['status'] == 5) {
  6336. $html .= '<span class="colGreen">打印</span>';
  6337. } elseif ($value ['status'] == 4) {
  6338. $html .= '<span class="colRed">终止</span>';
  6339. }
  6340. $html .= $value ['operation'] . '</p></blockquote>';
  6341. }
  6342. }
  6343. $html .= '</td></tr></tbody></table>';
  6344. }
  6345. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6346. }
  6347. echo json_encode ( array (
  6348. 'status' => 1,
  6349. 'html' => $html
  6350. ) );
  6351. die ();
  6352. } elseif ($type == 'RECEIVABLES') {
  6353. Doo::loadModel ( 'invoiceReceivables' );
  6354. $invoiceReceivables = new invoiceReceivables ();
  6355. Doo::loadModel ( 'invoiceRefund' );
  6356. $invoiceRefund = new invoiceRefund ();
  6357. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6358. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6359. if (empty ( $detail ))
  6360. $html = '';
  6361. else {
  6362. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6363. <table class="table table-bordered table-condensed">
  6364. <tbody><tr>
  6365. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6366. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6367. </tr><tr>
  6368. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6369. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6370. </tr>
  6371. <tr>
  6372. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6373. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6374. </tr>
  6375. <tr>
  6376. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6377. </tr>
  6378. </tbody></table>';
  6379. if (! empty ( $ireList )) {
  6380. $html .= '
  6381. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6382. <tr>
  6383. <th class="taC">退款单位名称</th>
  6384. <th class="taC">退款的账号</th>
  6385. <th class="taC">退款金额</th>
  6386. <th class="taC">退款</th>
  6387. <th class="taC">备注</th>
  6388. </tr>
  6389. ';
  6390. foreach ( $ireList as $key => $value ) {
  6391. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6392. $html .= '<tr>
  6393. <td>' . $value ['refundCompany'] . '</td>
  6394. <td>' . $value ['refundNumber'] . '</td>
  6395. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6396. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6397. <td>' . $value ['refundRemarks'] . '</td>
  6398. </tr>
  6399. ';
  6400. }
  6401. }
  6402. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6403. }
  6404. echo json_encode ( array (
  6405. 'status' => 1,
  6406. 'html' => $html
  6407. ) );
  6408. die ();
  6409. } elseif ($type == 'IRTC') {
  6410. Doo::loadModel ( 'invoice' );
  6411. $invoice = new invoice ();
  6412. Doo::loadModel ( 'invoiceOperationLog' );
  6413. $invoiceOperationLog = new invoiceOperationLog ();
  6414. // Doo::loadModel ( 'invoiceReceivables' );
  6415. // $invoiceReceivables = new invoiceReceivables ();
  6416. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6417. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6418. if (empty ( $detail ))
  6419. $html = '';
  6420. else {
  6421. $receivablesPriceedHtml = '';
  6422. $receivablesPrice = $detail ['invoicePrice'];
  6423. if (! empty ( $detail ['irid'] )) {
  6424. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6425. // if (empty ( $irList ))
  6426. // $irList [0] ['sumPrice'] = 0;
  6427. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6428. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6429. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6430. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6431. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6432. </tr></tbody></table>';
  6433. $receivablesPrice = $detail ['invoiceBalance'];
  6434. }
  6435. if ($loss)
  6436. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6437. $html = $receivablesPriceedHtml . '
  6438. <table class="table table-bordered table-condensed"><tbody>
  6439. <tr>
  6440. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6441. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6442. </tr>
  6443. <tr>
  6444. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6445. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6446. </tr>
  6447. <tr>
  6448. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6449. </tr>
  6450. <tr>
  6451. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6452. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6453. </tr>
  6454. <tr>
  6455. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6456. </tr></tbody></table>';
  6457. if ($detail ['invoiceType'] == 0) {
  6458. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6459. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6460. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6461. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6462. </tr>';
  6463. $receivablesMessage = $detail ['invoiceTitle'];
  6464. } else {
  6465. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6466. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6467. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6468. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6469. ';
  6470. $receivablesMessage = $detail ['invoiceCompany'];
  6471. }
  6472. $html .= '<tr>
  6473. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6474. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6475. </tr>
  6476. <tr>
  6477. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6478. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6479. </tr></tbody></table>';
  6480. if ($detail ['doPost'] == 1)
  6481. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6482. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6483. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6484. </tr><tr>
  6485. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6486. </tr><tr>
  6487. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6488. </tr></tbody></table>';
  6489. if (! empty ( $invoiceOperationLogList )) {
  6490. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6491. foreach ( $invoiceOperationLogList as $key => $value ) {
  6492. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6493. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6494. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6495. if ($value ['status'] == 2) {
  6496. $html .= '<span class="colGreen">同意</span>';
  6497. } elseif ($value ['status'] == 3) {
  6498. $html .= '<span class="colOrange">退回</span>';
  6499. } elseif ($value ['status'] == 5) {
  6500. $html .= '<span class="colGreen">打印</span>';
  6501. }
  6502. $html .= $value ['operation'] . '</p></blockquote>';
  6503. }
  6504. }
  6505. $html .= '</td></tr></tbody></table>';
  6506. }
  6507. }
  6508. echo json_encode ( array (
  6509. 'status' => 1,
  6510. 'html' => $html,
  6511. 'receivablesPrice' => $receivablesPrice,
  6512. 'receivablesMessage' => $receivablesMessage,
  6513. 'receivablesDate' => date ( "Y-m-d" ),
  6514. 'iidKey' => $serial
  6515. ) );
  6516. die ();
  6517. }
  6518. }
  6519. function ajaxGetInvoiceReceivablesByStaff() {
  6520. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6521. if (empty ( $postData )) {
  6522. echo json_encode ( array (
  6523. 'status' => 2,
  6524. 'msg' => 'illegal request'
  6525. ) );
  6526. die ();
  6527. }
  6528. Doo::loadModel ( 'invoiceReceivables' );
  6529. $invoiceReceivables = new invoiceReceivables ();
  6530. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6531. if (empty ( $detail )) {
  6532. echo json_encode ( array (
  6533. 'status' => 2,
  6534. 'msg' => 'illegal request'
  6535. ) );
  6536. die ();
  6537. }
  6538. Doo::loadModel ( 'L_category' );
  6539. $lCategory = new L_category ();
  6540. Doo::loadModel ( 'staff' );
  6541. $staff = new staff ();
  6542. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6543. $category = $lCategory->getCategory ();
  6544. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6545. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6546. foreach ( $category as $key => $value ) {
  6547. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6548. if ($value ['cid'] == $detail ['cid'])
  6549. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6550. }
  6551. foreach ( $staffList as $key => $value ) {
  6552. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6553. if ($value ['sid'] == $detail ['sid'])
  6554. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6555. }
  6556. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6557. echo json_encode ( array (
  6558. 'status' => 1,
  6559. 'categoryHtml' => $categoryHtml,
  6560. 'staffHtml' => $staffHtml,
  6561. 'rbankHtml' => $rbankHtml,
  6562. 'detail' => $detail
  6563. ) );
  6564. }
  6565. function ajaxGetInvoiceReceivablesByIrid() {
  6566. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6567. if (empty ( $irid )) {
  6568. echo json_encode ( array (
  6569. 'status' => 2,
  6570. 'msg' => 'illegal request'
  6571. ) );
  6572. die ();
  6573. }
  6574. Doo::loadModel ( 'invoiceReceivables' );
  6575. $invoiceReceivables = new invoiceReceivables ();
  6576. Doo::loadModel ( 'invoice' );
  6577. $invoice = new invoice ();
  6578. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6579. $flag = true;
  6580. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6581. $bakDetail = array ();
  6582. if ($flag === false) {
  6583. array_push ( $bakDetail, $invoiceDetail );
  6584. $invoiceDetail = $bakDetail;
  6585. }
  6586. $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>
  6587. <tr>
  6588. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6589. <td>' . $detail ['receivablesMessage'] . '</td>
  6590. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6591. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6592. <td>' . $detail ['recepitTitleMark'] . '</td>
  6593. </tr></tbody></table>';
  6594. $isInvoice = false;
  6595. $invoiceHtml = '';
  6596. if (empty ( $invoiceDetail )) {
  6597. $isInvoice = true;
  6598. } else {
  6599. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6600. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6601. foreach ( $invoiceDetail as $key => $value ) {
  6602. $invoiceHtml .= '<tr>';
  6603. if (! empty ( $value ['invoiceType'] )) {
  6604. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6605. } else {
  6606. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6607. }
  6608. if (! empty ( $value ['invoiceType'] )) {
  6609. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6610. } else {
  6611. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6612. }
  6613. $invoiceHtml .= '
  6614. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6615. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6616. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6617. </tr>
  6618. ';
  6619. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6620. if (empty ( $irList ))
  6621. $irList [0] ['sumPrice'] = 0;
  6622. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6623. $priceString = '';
  6624. if ($balance < $detail ['receivablesPrice']) {
  6625. $priceString = '收款金额超过开票金额,';
  6626. }
  6627. if ($balance > $detail ['receivablesPrice']) {
  6628. $priceString = '收款金额低于开票金额,';
  6629. }
  6630. }
  6631. $invoiceHtml .= '
  6632. <script>
  6633. $(\'a[bind-receivables^="ir"]\').click(function() {
  6634. var data = $(this).attr("data-ikey");
  6635. $("input[name=\'invoiceKey\']").val(data);
  6636. var invoiceKey=data;
  6637. if(invoiceKey==""){
  6638. alert("入账错误,请重新刷新页面");
  6639. return false;
  6640. }
  6641. if(window.confirm("' . $priceString . '确定入账吗?")){
  6642. $("#IBR").submit();
  6643. }else{
  6644. return false;
  6645. }
  6646. });
  6647. </script>
  6648. ';
  6649. $invoiceHtml .= '</tbody></table>';
  6650. }
  6651. echo json_encode ( array (
  6652. 'status' => 1,
  6653. 'irkey' => $detail ['iridEn'],
  6654. 'receivablesHtml' => $receivablesHtml,
  6655. 'isInvoice' => $isInvoice,
  6656. 'invoiceHtml' => $invoiceHtml
  6657. ) );
  6658. }
  6659. function ajaxGetInvoiceReceivablesByTitle() {
  6660. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6661. if (empty ( $title )) {
  6662. echo json_encode ( array (
  6663. 'status' => 2,
  6664. 'msg' => 'illegal request'
  6665. ) );
  6666. die ();
  6667. }
  6668. Doo::loadModel ( 'invoice' );
  6669. $invoice = new invoice ();
  6670. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6671. $invoiceHtml = '';
  6672. if (! empty ( $invoiceDetail )) {
  6673. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6674. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6675. foreach ( $invoiceDetail as $key => $value ) {
  6676. if (! empty ( $value ['invoiceType'] )) {
  6677. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6678. } else {
  6679. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6680. }
  6681. if (! empty ( $value ['invoiceType'] )) {
  6682. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6683. } else {
  6684. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6685. }
  6686. $invoiceHtml .= '
  6687. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6688. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6689. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6690. </tr>
  6691. ';
  6692. }
  6693. $invoiceHtml .= '</tbody></table>
  6694. <script>
  6695. $(\'a[bind-receivables^="ir"]\').click(function() {
  6696. var data = $(this).attr("data-ikey");
  6697. $("input[name=\'invoiceKey\']").val(data);
  6698. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6699. if(invoiceKey==""){
  6700. alert("入账错误,请重新刷新页面");
  6701. return false;
  6702. }
  6703. if(window.confirm("确定入账吗?")){
  6704. $("#IBR").submit();
  6705. }else{
  6706. return false;
  6707. }
  6708. });
  6709. </script>
  6710. ';
  6711. }
  6712. echo json_encode ( array (
  6713. 'status' => 1,
  6714. 'invoiceHtml' => $invoiceHtml
  6715. ) );
  6716. }
  6717. function ajaxInvoicePushNotice() {
  6718. Doo::loadModel ( 'invoice' );
  6719. $invoice = new invoice ();
  6720. $approval = $invoice->getOne ( array (
  6721. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6722. 'desc' => 'iid',
  6723. 'asArray' => true
  6724. ) );
  6725. $isNotice = false;
  6726. if (! empty ( $approval ))
  6727. $isNotice = true;
  6728. $response = array (
  6729. 'error' => 0,
  6730. 'isNotice' => $isNotice
  6731. );
  6732. echo json_encode ( $response );
  6733. exit ();
  6734. }
  6735. public function ajaxCheckInvoiceNoUniqueness() {
  6736. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6737. Doo::loadModel ( 'invoice' );
  6738. $invoice = new invoice ();
  6739. if (! empty ( $invoiceNo )) {
  6740. Doo::loadModel ( 'invoicePaper' );
  6741. $invoicePaper = new invoicePaper ();
  6742. Doo::loadClass ( 'XDeode' );
  6743. $XDeode = new XDeode ( 5 );
  6744. $ipid = $XDeode->decode ( $invoiceNo );
  6745. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6746. $info = $invoice->getOne ( array (
  6747. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6748. 'asArray' => TRUE
  6749. ) );
  6750. if (! empty ( $info )) {
  6751. echo json_encode ( array (
  6752. 'error' => '发票号已存在'
  6753. ) );
  6754. die ();
  6755. } else
  6756. echo json_encode ( array (
  6757. 'ok' => '可以使用!'
  6758. ) );
  6759. die ();
  6760. }
  6761. }
  6762. function ajaxCheckInvoicePrice() {
  6763. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6764. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6765. Doo::loadModel ( 'invoice' );
  6766. $invoice = new invoice ();
  6767. Doo::loadModel ( 'invoiceReceivables' );
  6768. $invoiceReceivables = new invoiceReceivables ();
  6769. Doo::loadClass ( 'XDeode' );
  6770. $XDeode = new XDeode ( 5 );
  6771. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6772. $iidKey = $XDeode->decode ( $iidKey );
  6773. $info = $invoice->getInvoiceByIid ( $iidKey );
  6774. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6775. if (empty ( $irList ))
  6776. $irList [0] ['sumPrice'] = 0;
  6777. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6778. if ($balance < $receivablesPrice) {
  6779. echo json_encode ( array (
  6780. 'error' => '收款金额超过开票金额。'
  6781. ) );
  6782. die ();
  6783. }
  6784. if ($balance > $receivablesPrice) {
  6785. echo json_encode ( array (
  6786. 'error' => '收款金额低于开票金额。'
  6787. ) );
  6788. die ();
  6789. }
  6790. }
  6791. }
  6792. function ajaxGetInvoiceByNew() {
  6793. Doo::loadModel ( 'invoice' );
  6794. $invoice = new invoice ();
  6795. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6796. echo json_encode ( array (
  6797. 'status' => 1,
  6798. 'detail' => $detail
  6799. ) );
  6800. }
  6801. /**
  6802. * 旧输入导入
  6803. */
  6804. function importInvoice() {
  6805. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6806. $data ['emsg'] = "";
  6807. if ($emsg != "")
  6808. $data ['emsg'] = "请填写完整的数据";
  6809. $data ['time'] = time ();
  6810. $this->render ( "/admin/invoiceImport", $data );
  6811. }
  6812. function uploadInvoice() {
  6813. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6814. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6815. $file = $_FILES ['Filedata'] ['tmp_name'];
  6816. $error = false;
  6817. if (! is_uploaded_file ( $file )) {
  6818. $error = '400 Bad Request';
  6819. }
  6820. if ($error) {
  6821. header ( 'HTTP/1.0 ' . $error );
  6822. die ( 'Error ' . $error );
  6823. } else {
  6824. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6825. $this->IoHandler = new IoHandler ();
  6826. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6827. // $filedir=$_POST['time'];
  6828. // 调用定义物理路径
  6829. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6830. $this->IoHandler->MakeDir ( $t );
  6831. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6832. if ($filename != 'xlsx')
  6833. return "";
  6834. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6835. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6836. $upload_dir = $t . "/" . $upload_file;
  6837. $k = move_uploaded_file ( $file, $upload_dir );
  6838. if ($k) {
  6839. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6840. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6841. }
  6842. }
  6843. }
  6844. }
  6845. function importInvoiceDo() {
  6846. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6847. if ($path != "") {
  6848. Doo::loadModel ( 'invoice' );
  6849. Doo::loadModel ( 'staff' );
  6850. $staff = new staff ();
  6851. Doo::loadModel ( 'invoiceStatistics' );
  6852. Doo::loadModel ( 'invoiceOperationLog' );
  6853. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6854. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6855. // print_r ( $exlArray );
  6856. // die ();
  6857. // echo json_encode($exlArray);die;
  6858. foreach ( $exlArray as $key => $value ) {
  6859. // 开票
  6860. $invoice = new invoice ();
  6861. $invoice->invoiceNo = $value ['invoiceNo'];
  6862. $invoice->invoiceType = 0;
  6863. if ($value ['invoiceType'] == '专')
  6864. $invoice->invoiceType = 1;
  6865. $invoice->invoicePrice = $value ['invoicePrice'];
  6866. $invoice->invoiceQuantity = 1;
  6867. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6868. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6869. if ($value ['invoiceType'] == '专')
  6870. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6871. $invoice->userName = $value ['userName'];
  6872. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6873. $invoice->sid = $sDetail ['sid'];
  6874. $invoice->cid = $sDetail ['cid'];
  6875. $invoice->categoryName = $sDetail ['category'];
  6876. $invoice->invoiceElement = $value ['invoiceElement'];
  6877. $invoice->remark = $value ['remark'];
  6878. $invoice->date = $value ['date'];
  6879. $invoice->printTime = $value ['date'];
  6880. $invoice->ipSource = 1;
  6881. $invoice->printStatus = 1;
  6882. $invoice->status = 2;
  6883. $invoice->postStatus = 1;
  6884. $invoice->untreadStatus = 0;
  6885. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6886. $iid = $invoice->insert ();
  6887. // 汇总
  6888. $invoiceStatistics = new invoiceStatistics ();
  6889. //
  6890. $item = array (
  6891. 'date' => $value ['date'],
  6892. 'priceClass' => 1,
  6893. 'cid' => $sDetail ['cid'],
  6894. 'staff' => $sDetail ['sid'],
  6895. 'invoicePrice' => $value ['invoicePrice']
  6896. );
  6897. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6898. $invoiceOperationLog = new invoiceOperationLog ();
  6899. $item = array (
  6900. 'date' => date ( "Y-m-d H:i:s" ),
  6901. 'operation' => date ( "Y-m-d" ) . " 导入",
  6902. 'status' => 1,
  6903. 'img' => $sDetail ['avatar'],
  6904. 'username' => $sDetail ['username'],
  6905. 'uid' => $sDetail ['sid'],
  6906. 'category' => $sDetail ['category'],
  6907. 'iid' => $iid
  6908. );
  6909. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6910. }
  6911. return '/importInvoice?count=' . count ( $exlArray );
  6912. // return "/keyonline";
  6913. }
  6914. echo 'no file';
  6915. }
  6916. function importInvoiceReceivables() {
  6917. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6918. $data ['emsg'] = "";
  6919. if ($emsg != "")
  6920. $data ['emsg'] = "请填写完整的数据";
  6921. $data ['time'] = time ();
  6922. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6923. }
  6924. // 导入入账数据
  6925. function importInvoiceReceivablesDo() {
  6926. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6927. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6928. if ($path != "") {
  6929. Doo::loadModel ( 'invoiceReceivables' );
  6930. Doo::loadModel ( 'invoice' );
  6931. Doo::loadModel ( 'staff' );
  6932. $staff = new staff ();
  6933. Doo::loadModel ( 'invoiceStatistics' );
  6934. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6935. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6936. // print_r ( $exlArray );
  6937. // die ();
  6938. // echo json_encode($exlArray);die;
  6939. foreach ( $exlArray as $key => $value ) {
  6940. // 收款
  6941. $invoiceReceivables = new invoiceReceivables ();
  6942. $invoice = new invoice ();
  6943. $invoiceReceivables->bindStatus = 1;
  6944. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6945. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6946. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6947. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6948. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6949. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6950. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6951. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6952. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6953. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6954. $invoiceReceivables->iid = $iDetail ['iid'];
  6955. $irid = $invoiceReceivables->insert ();
  6956. // 发票绑定收款
  6957. $detail = $iDetail;
  6958. $iridString = "";
  6959. if (empty ( $detail ['irid'] ))
  6960. $iridString = $irid;
  6961. else
  6962. $iridString = $detail ['irid'] . ',' . $irid;
  6963. $item = array (
  6964. 'irid' => $iridString,
  6965. 'iid' => $detail ['iid']
  6966. );
  6967. $invoice->setInvoiceByCondition ( $item );
  6968. // 汇总
  6969. $invoiceStatistics = new invoiceStatistics ();
  6970. // 扣除入账统计金额
  6971. $item = array (
  6972. 'date' => $value ['receivablesDate'],
  6973. 'priceClass' => 3,
  6974. 'cid' => $sDetail ['cid'],
  6975. 'staff' => $sDetail ['sid'],
  6976. // 'irid' => $irid,
  6977. 'accountPrice' => $value ['receivablesPrice']
  6978. );
  6979. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6980. }
  6981. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6982. echo 'data count ' . count ( $exlArray );
  6983. die ();
  6984. // return "/keyonline";
  6985. }
  6986. echo 'no file';
  6987. }
  6988. function formatExcelToArrayTrain($file_url = "") {
  6989. if (! file_exists ( $file_url )) {
  6990. return array ();
  6991. }
  6992. // Doo::loadClass ( 'PHPExcel' );
  6993. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6994. $PHPExcel = new PHPExcel ();
  6995. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6996. if (! $PHPReader->canRead ( $file_url )) {
  6997. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6998. if (! $PHPReader->canRead ( $file_url )) {
  6999. echo 'no Excel';
  7000. return;
  7001. }
  7002. }
  7003. $PHPExcel = $PHPReader->load ( $file_url );
  7004. /* * 读取excel文件中的第一个工作表 */
  7005. $currentSheet = $PHPExcel->getSheet ( 0 );
  7006. /* * 取得最大的列号 */
  7007. $allColumn = $currentSheet->getHighestColumn ();
  7008. /* * 取得一共有多少行 */
  7009. $allRow = $currentSheet->getHighestRow ();
  7010. $excel_array = array ();
  7011. // die($file_url);
  7012. $conk = 2;
  7013. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7014. $excel_column = array ();
  7015. // 后期改进
  7016. if ($allColumn == 'AM')
  7017. $allColumn = 'Z';
  7018. /* * 从第A列开始输出 */
  7019. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7020. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7021. if ($val instanceof PHPExcel_RichText)
  7022. $val = $val->__toString ();
  7023. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7024. // $val = "'" . addslashes ( $val ) . "'";
  7025. if ($currentColumn == 'A') {
  7026. $excel_column ['invoiceTitle'] = $val;
  7027. } elseif ($currentColumn == 'B')
  7028. $excel_column ['invoiceType'] = $val;
  7029. elseif ($currentColumn == 'C') {
  7030. $excel_column ['TIN'] = $val;
  7031. } elseif ($currentColumn == 'D') {
  7032. $excel_column ['address'] = $val;
  7033. } elseif ($currentColumn == 'E') {
  7034. $excel_column ['phone'] = $val;
  7035. } elseif ($currentColumn == 'F') {
  7036. $excel_column ['bank'] = $val;
  7037. } elseif ($currentColumn == 'G') {
  7038. $excel_column ['bankAccount'] = $val;
  7039. } elseif ($currentColumn == 'H') {
  7040. $excel_column ['invoiceElement'] = $val;
  7041. } elseif ($currentColumn == 'I') {
  7042. $excel_column ['invoiceQuantity'] = $val;
  7043. } elseif ($currentColumn == 'J') {
  7044. $excel_column ['invoiceUnitPrice'] = $val;
  7045. } elseif ($currentColumn == 'K') {
  7046. $excel_column ['remark'] = $val;
  7047. } elseif ($currentColumn == 'L') {
  7048. $excel_column ['recipientsAddress'] = $val;
  7049. } elseif ($currentColumn == 'M') {
  7050. $excel_column ['recipients'] = $val;
  7051. } elseif ($currentColumn == 'N') {
  7052. $excel_column ['recipientsPhone'] = $val;
  7053. }elseif ($currentColumn == 'O') {
  7054. $excel_column ['electronicPhone'] = $val;
  7055. } elseif ($currentColumn == 'P') {
  7056. $excel_column ['electronicEmail'] = $val;
  7057. }
  7058. }
  7059. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7060. array_push ( $excel_array, $excel_column );
  7061. }
  7062. return $excel_array;
  7063. }
  7064. /**
  7065. * 格式化excel文件为数组
  7066. * @param unknown_type $file_url
  7067. * @param unknown_type $mcid
  7068. */
  7069. function _format_excel_to_array($file_url = "", $sType = "") {
  7070. if (! file_exists ( $file_url )) {
  7071. return array ();
  7072. }
  7073. Doo::loadClass ( 'PHPExcel' );
  7074. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7075. $PHPExcel = new PHPExcel ();
  7076. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7077. if (! $PHPReader->canRead ( $file_url )) {
  7078. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7079. if (! $PHPReader->canRead ( $file_url )) {
  7080. echo 'no Excel';
  7081. return;
  7082. }
  7083. }
  7084. $PHPExcel = $PHPReader->load ( $file_url );
  7085. /* * 读取excel文件中的第一个工作表 */
  7086. $currentSheet = $PHPExcel->getSheet ( 0 );
  7087. /* * 取得最大的列号 */
  7088. $allColumn = $currentSheet->getHighestColumn ();
  7089. /* * 取得一共有多少行 */
  7090. $allRow = $currentSheet->getHighestRow ();
  7091. $excel_array = array ();
  7092. // die($file_url);
  7093. $conk = 2;
  7094. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7095. $excel_column = array ();
  7096. // 后期改进
  7097. if ($allColumn == 'AM')
  7098. $allColumn = 'Z';
  7099. /* * 从第A列开始输出 */
  7100. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7101. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7102. if ($val instanceof PHPExcel_RichText)
  7103. $val = $val->__toString ();
  7104. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7105. // $val = "'" . addslashes ( $val ) . "'";
  7106. if ($sType == 'invoiceReceivables') {
  7107. if ($currentColumn == 'A')
  7108. $excel_column ['invoiceNo'] = $val;
  7109. elseif ($currentColumn == 'B')
  7110. $excel_column ['receivablesPrice'] = $val;
  7111. elseif ($currentColumn == 'C') {
  7112. $excel_column ['receivablesMessage'] = $val;
  7113. } elseif ($currentColumn == 'D') {
  7114. $excel_column ['receivablesBank'] = $val;
  7115. } elseif ($currentColumn == 'E') {
  7116. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7117. } elseif ($currentColumn == 'F') {
  7118. $excel_column ['receivablesStaff'] = $val;
  7119. } elseif ($currentColumn == 'G') {
  7120. $excel_column ['sourcePrice'] = $val;
  7121. }
  7122. } elseif ($sType == "invoiceTrain") {
  7123. if ($currentColumn == 'A') {
  7124. $excel_column ['invoiceTitle'] = $val;
  7125. } elseif ($currentColumn == 'B')
  7126. $excel_column ['invoiceType'] = $val;
  7127. elseif ($currentColumn == 'C') {
  7128. $excel_column ['TIN'] = $val;
  7129. } elseif ($currentColumn == 'D') {
  7130. $excel_column ['address'] = $val;
  7131. } elseif ($currentColumn == 'E') {
  7132. $excel_column ['phone'] = $val;
  7133. } elseif ($currentColumn == 'F') {
  7134. $excel_column ['bank'] = $val;
  7135. } elseif ($currentColumn == 'G') {
  7136. $excel_column ['bankAccount'] = $val;
  7137. } elseif ($currentColumn == 'H') {
  7138. $excel_column ['invoiceElement'] = $val;
  7139. } elseif ($currentColumn == 'I') {
  7140. $excel_column ['invoiceQuantity'] = $val;
  7141. } elseif ($currentColumn == 'J') {
  7142. $excel_column ['invoiceUnitPrice'] = $val;
  7143. } elseif ($currentColumn == 'K') {
  7144. $excel_column ['remark'] = $val;
  7145. } elseif ($currentColumn == 'L') {
  7146. $excel_column ['recipientsAddress'] = $val;
  7147. } elseif ($currentColumn == 'M') {
  7148. $excel_column ['recipients'] = $val;
  7149. } elseif ($currentColumn == 'N') {
  7150. $excel_column ['recipientsPhone'] = $val;
  7151. }
  7152. } else {
  7153. if ($currentColumn == 'A')
  7154. $excel_column ['invoiceNo'] = $val;
  7155. elseif ($currentColumn == 'B')
  7156. $excel_column ['invoiceType'] = $val;
  7157. elseif ($currentColumn == 'C') {
  7158. $excel_column ['invoicePrice'] = $val;
  7159. } elseif ($currentColumn == 'D') {
  7160. $excel_column ['invoiceTitle'] = $val;
  7161. } elseif ($currentColumn == 'E') {
  7162. $excel_column ['userName'] = $val;
  7163. } elseif ($currentColumn == 'F') {
  7164. $excel_column ['categoryName'] = $val;
  7165. } elseif ($currentColumn == 'G') {
  7166. $excel_column ['invoiceElement'] = $val;
  7167. } elseif ($currentColumn == 'H') {
  7168. $excel_column ['remark'] = $val;
  7169. } elseif ($currentColumn == 'I') {
  7170. $excel_column ['date'] = $this->excelTime ( $val );
  7171. }
  7172. }
  7173. }
  7174. array_push ( $excel_array, $excel_column );
  7175. }
  7176. return $excel_array;
  7177. }
  7178. function excelTime($date, $time = false) {
  7179. if (function_exists ( 'GregorianToJD' )) {
  7180. if (is_numeric ( $date )) {
  7181. $jd = GregorianToJD ( 1, 1, 1970 );
  7182. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7183. $date = explode ( '/', $gregorian );
  7184. $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" : '');
  7185. return $date_str;
  7186. }
  7187. } else {
  7188. $date = $date > 25568 ? $date + 1 : 25569;
  7189. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7190. $ofs = (70 * 365 + 17 + 2) * 86400;
  7191. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7192. }
  7193. return $date;
  7194. }
  7195. /**
  7196. * 旧输入导入
  7197. */
  7198. function _GetFileEXT($filename) {
  7199. $pics = explode ( '.', $filename );
  7200. $num = count ( $pics );
  7201. return $pics [$num - 1];
  7202. }
  7203. function showCache($path = "", $sid = 0) {
  7204. // if (file_exists ( $path )) {
  7205. // $htm = file_get_contents ( $path );
  7206. // } else {
  7207. Doo::loadModel ( 'invoiceStatistics' );
  7208. $invoiceStatistics = new invoiceStatistics ();
  7209. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7210. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7211. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7212. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7213. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7214. /*
  7215. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7216. */
  7217. file_put_contents ( $path, $htm );
  7218. // }
  7219. return $htm;
  7220. }
  7221. /**
  7222. * 生成token
  7223. * @return string
  7224. */
  7225. function set_token() {
  7226. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7227. $str = sha1 ( $str ); // 加密
  7228. return $str;
  7229. }
  7230. /**
  7231. * 获取get或者POST值
  7232. *
  7233. * @param string $name 属性名称
  7234. * @return fixed 值
  7235. */
  7236. function get_args($name) {
  7237. if (isset ( $_GET [$name] )) {
  7238. if (is_array ( $_GET [$name] ))
  7239. return $_GET [$name];
  7240. else
  7241. return addslashes ( $_GET [$name] );
  7242. } elseif (isset ( $_POST [$name] )) {
  7243. if (is_array ( $_POST [$name] ))
  7244. return $_POST [$name];
  7245. else
  7246. return addslashes ( $_POST [$name] );
  7247. } else
  7248. return false;
  7249. }
  7250. function SafeFilter(&$arr) {
  7251. $ra = Array (
  7252. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7253. '/script/',
  7254. '/javascript/',
  7255. '/vbscript/',
  7256. '/expression/',
  7257. '/applet/',
  7258. '/meta/',
  7259. '/xml/',
  7260. '/blink/',
  7261. '/link/',
  7262. '/style/',
  7263. '/embed/',
  7264. '/object/',
  7265. '/frame/',
  7266. '/layer/',
  7267. '/title/',
  7268. '/bgsound/',
  7269. '/base/',
  7270. '/onload/',
  7271. '/onunload/',
  7272. '/onchange/',
  7273. '/onsubmit/',
  7274. '/onreset/',
  7275. '/onselect/',
  7276. '/onblur/',
  7277. '/onfocus/',
  7278. '/onabort/',
  7279. '/onkeydown/',
  7280. '/onkeypress/',
  7281. '/onkeyup/',
  7282. '/onclick/',
  7283. '/ondblclick/',
  7284. '/onmousedown/',
  7285. '/onmousemove/',
  7286. '/onmouseout/',
  7287. '/onmouseover/',
  7288. '/onmouseup/',
  7289. '/onunload/'
  7290. );
  7291. if (is_array ( $arr )) {
  7292. foreach ( $arr as $key => $value ) {
  7293. if (! is_array ( $value )) {
  7294. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7295. {
  7296. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7297. }
  7298. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7299. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7300. } else {
  7301. SafeFilter ( $arr [$key] );
  7302. }
  7303. }
  7304. }
  7305. }
  7306. /**
  7307. * Escape String
  7308. *
  7309. * @access public
  7310. * @param string
  7311. * @param bool whether or not the string will be used in a LIKE condition
  7312. * @return string
  7313. */
  7314. function escape_str($str, $like = FALSE) {
  7315. if (is_array ( $str )) {
  7316. foreach ( $str as $key => $val ) {
  7317. $str [$key] = $this->escape_str ( $val, $like );
  7318. }
  7319. return $str;
  7320. }
  7321. var_dump ( Doo::db ()->getDbObject () );
  7322. die ();
  7323. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7324. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7325. } elseif (function_exists ( 'mysql_escape_string' )) {
  7326. $str = mysql_escape_string ( $str );
  7327. } else {
  7328. $str = addslashes ( $str );
  7329. }
  7330. // escape LIKE condition wildcards
  7331. if ($like === TRUE) {
  7332. $str = str_replace ( array (
  7333. '%',
  7334. '_'
  7335. ), array (
  7336. '\\%',
  7337. '\\_'
  7338. ), $str );
  7339. }
  7340. return $str;
  7341. }
  7342. /**
  7343. * 获得分页数据
  7344. * @param unknown_type $table
  7345. * @param unknown_type $condition
  7346. * @param unknown_type $on_page
  7347. * @param unknown_type $page_size
  7348. */
  7349. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7350. $page_c = "";
  7351. $page ['previous'] = $this->get_previous ( $on_page );
  7352. $page ['on_page'] = $on_page;
  7353. $total_count = $this->get_table_count ( $table, $condition );
  7354. $total = intval ( $total_count / $page_size );
  7355. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7356. $page ['total_data'] = $total_count;
  7357. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7358. $i = 1;
  7359. $page_max = 1;
  7360. $page_width = 3;
  7361. if ($on_page >= $page_width) {
  7362. $page_max = intval ( $on_page / $page_width ) + 1;
  7363. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7364. }
  7365. for(; $i <= $page ['total_page']; $i ++) {
  7366. if ($i == $on_page)
  7367. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7368. else
  7369. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7370. if ($i == ($page_width * $page_max))
  7371. break;
  7372. }
  7373. $page ['page'] = $page_c;
  7374. $page ['lower'] = (-- $on_page) * $page_size;
  7375. return $page;
  7376. }
  7377. /**
  7378. * 获取上一页
  7379. * @param unknown_type $on_page
  7380. */
  7381. function get_previous($on_page = 1) {
  7382. return $on_page != 0 ? $on_page - 1 : $on_page;
  7383. }
  7384. /**
  7385. * 获取总页数
  7386. * @param unknown_type $table
  7387. * @param unknown_type $condition
  7388. */
  7389. public function get_table_count($table = "", $condition = "") {
  7390. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7391. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7392. // echo $sql;die;
  7393. $query = Doo::db ()->query ( $sql );
  7394. $result = $query->fetch ();
  7395. return $result ['count'];
  7396. }
  7397. function isInvoiceNew($type = "GLOBAL") {
  7398. Doo::loadModel ( 'invoice' );
  7399. $invoice = new invoice ();
  7400. Doo::loadModel ( 'invoiceReceivables' );
  7401. $invoiceReceivables = new invoiceReceivables ();
  7402. Doo::loadModel ( 'staff' );
  7403. $staff = new staff ();
  7404. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7405. // 我的发票待处理
  7406. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7407. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7408. 'desc' => 'iid',
  7409. 'asArray' => TRUE
  7410. ) );
  7411. // 我的收款待入账
  7412. /*
  7413. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7414. */
  7415. // 发票审批
  7416. $approval = $invoice->getOne ( array (
  7417. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7418. 'desc' => 'iid',
  7419. 'asArray' => true
  7420. ) );
  7421. // 发票邮寄
  7422. $post = $invoice->getOne ( array (
  7423. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7424. 'asArray' => TRUE
  7425. ) );
  7426. // 发票打印
  7427. $print = $invoice->getOne ( array (
  7428. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7429. 'desc' => 'iid',
  7430. 'asArray' => TRUE
  7431. ) );
  7432. // 发票退票 printStatus=1 and
  7433. $untread = $invoice->getOne ( array (
  7434. 'where' => " untreadStatus=1 and status=2 ",
  7435. 'asArray' => TRUE
  7436. ) );
  7437. $new = array (
  7438. 'GLOBAL' => FALSE,
  7439. 'pendingInvoice' => FALSE,
  7440. // 'myClaim' => FALSE,
  7441. 'approval' => FALSE,
  7442. 'post' => FALSE,
  7443. 'print' => FALSE,
  7444. 'untread' => FALSE
  7445. );
  7446. // || ! empty ( $myClaim )
  7447. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7448. $new ['GLOBAL'] = TRUE;
  7449. if (! empty ( $pendingInvoice ))
  7450. $new ['pendingInvoice'] = TRUE;
  7451. // if (! empty ( $myClaim ))
  7452. // $new ['myClaim'] = TRUE;
  7453. if (! empty ( $approval ))
  7454. $new ['approval'] = TRUE;
  7455. if (! empty ( $post ))
  7456. $new ['post'] = TRUE;
  7457. if (! empty ( $print ))
  7458. $new ['print'] = TRUE;
  7459. if (! empty ( $untread ))
  7460. $new ['untread'] = TRUE;
  7461. return $new;
  7462. }
  7463. function setWXMsg($rid, $typeMsg = '') {
  7464. Doo::loadModel ( 'invoice' );
  7465. $invoice = new invoice ();
  7466. $invoiceDetail = $invoice->getOne ( array (
  7467. 'where' => 'iid=' . $rid,
  7468. 'asArray' => true
  7469. ) );
  7470. if (! empty ( $invoiceDetail )) {
  7471. Doo::loadModel ( 'staff' );
  7472. $staff = new staff ();
  7473. $staffmsg = $staff->getOne ( array (
  7474. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7475. 'asArray' => TRUE
  7476. ) );
  7477. if (! empty ( $staffmsg ['wxid'] )) {
  7478. require_once (SITE_PATH . '/protected/class/client.php');
  7479. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7480. $user = $staffmsg ['wxid'];
  7481. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7482. if (empty ( $expCom ))
  7483. $expCom [0] = '';
  7484. $msg = "";
  7485. if (empty ( $typeMsg ))
  7486. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7487. elseif ($typeMsg == "PRINT")
  7488. $msg = '太好了,您的发票已打印完成。';
  7489. $result = $client->SendMsg ( $user, $msg, 'text' );
  7490. }
  7491. }
  7492. }
  7493. /**
  7494. * 获取微信部门
  7495. * @param string $category
  7496. * @return number|mixed
  7497. */
  7498. function getToparty($category = '') {
  7499. $token = $this->getAccessToken (); //
  7500. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7501. $toparty = 0;
  7502. foreach ( $result ['department'] as $key => $value ) {
  7503. if ($value ['name'] == $category)
  7504. $toparty = $value ['id'];
  7505. }
  7506. return $toparty;
  7507. }
  7508. /**
  7509. * 获得某部门下的用户
  7510. * @param string $toparty
  7511. */
  7512. function getUserByToparty($toparty = '') {
  7513. $token = $this->getAccessToken (); //
  7514. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7515. $userList = array ();
  7516. foreach ( $result ['userlist'] as $key => $value ) {
  7517. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7518. }
  7519. return $userList;
  7520. }
  7521. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7522. $token = $this->getAccessToken ();
  7523. if ($text == 'text') {
  7524. $data = '{
  7525. "touser": "' . $toparty . '",
  7526. "toparty": "",
  7527. "totag": "",
  7528. "msgtype": "text",
  7529. "agentid": 1000002,
  7530. "text": {
  7531. "content": "' . $msg . '"
  7532. },
  7533. "safe":0
  7534. }';
  7535. }
  7536. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7537. if ($result->errmsg != 'ok') {
  7538. return 0;
  7539. } else {
  7540. return 1;
  7541. }
  7542. }
  7543. /**
  7544. * 获得可以发送微信用户列表
  7545. * @param string $category
  7546. * @return string
  7547. */
  7548. function getWxidByCategory($category = "") {
  7549. if (empty ( $category ))
  7550. return "";
  7551. Doo::loadModel ( 'staff' );
  7552. $staff = new staff ();
  7553. $toparty = $this->getToparty ( $category );
  7554. $wxList = array ();
  7555. $wxString = "";
  7556. if (! empty ( $toparty )) {
  7557. $userList = $this->getUserByToparty ( $toparty );
  7558. $userCon = implode ( ',', $userList );
  7559. // echo $userCon;
  7560. $sidList = $staff->getStaffByWxid ( $userCon );
  7561. foreach ( $sidList as $key => $value ) {
  7562. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7563. if ($falg) {
  7564. array_push ( $wxList, $value ['wxid'] );
  7565. }
  7566. }
  7567. $wxString = implode ( '|', $wxList );
  7568. }
  7569. return $wxString;
  7570. }
  7571. /**
  7572. * 读取发送信息规则判断是否需要发送
  7573. * @param number $sid
  7574. * @param string $sendType
  7575. * @return boolean
  7576. */
  7577. function isSendNotification($sid = 0, $sendType = '') {
  7578. Doo::loadModel ( "notificationConf" );
  7579. $notificationConf = new notificationConf ();
  7580. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7581. $conf = array ();
  7582. $sendFlag = true;
  7583. if (! empty ( $detail )) {
  7584. $conf = json_decode ( $detail ['conf'], true );
  7585. if (! empty ( $sendType )) {
  7586. if (isset ( $conf [$sendType] )) {
  7587. if ($conf [$sendType] == "CLOSE")
  7588. $sendFlag = false;
  7589. elseif ($conf [$sendType] == "Weekend") {
  7590. $day = date ( "w" );
  7591. if (1 <= $day && 5 >= $day)
  7592. $sendFlag = false;
  7593. } elseif ($conf [$sendType] == "OneToFriday") {
  7594. $day = date ( "w" );
  7595. if (0 == $day || 6 == $day)
  7596. $sendFlag = false;
  7597. }
  7598. }
  7599. } else
  7600. $sendFlag = false;
  7601. }
  7602. return $sendFlag;
  7603. }
  7604. /**
  7605. * 根据规则发送信息
  7606. * @param unknown $msg
  7607. * @param unknown $title
  7608. * @param unknown $url
  7609. * @param unknown $user
  7610. * @param string $text
  7611. * @return number
  7612. */
  7613. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7614. $token = $this->getAccessToken ();
  7615. $falg = $this->isSendNotification ( $sid, $sendType );
  7616. // if ($text == 'text') {
  7617. // $data = '{
  7618. // "touser": "' . $user . '",
  7619. // "toparty": "",
  7620. // "totag": "",
  7621. // "msgtype": "text",
  7622. // "agentid": 1000002,
  7623. // "text": {
  7624. // "content": "' . $msg . '"
  7625. // },
  7626. // "safe":0
  7627. // }';
  7628. // } else {
  7629. $data = '{
  7630. "touser": "' . $user . '",
  7631. "toparty": "",
  7632. "totag": "",
  7633. "msgtype": "news",
  7634. "agentid": 1000002,
  7635. "news": {
  7636. "articles":[
  7637. {
  7638. "title": "' . $title . '",
  7639. "description": "' . $msg . '",
  7640. "url": "' . $url . '",
  7641. "picurl": ""
  7642. }
  7643. ]
  7644. }
  7645. }';
  7646. // }
  7647. if ($falg) {
  7648. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7649. if ($result->errmsg != 'ok') {
  7650. return 0;
  7651. } else {
  7652. return 1;
  7653. }
  7654. } else
  7655. return 0;
  7656. }
  7657. private function getAccessToken() {
  7658. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7659. // $file = './access_token.txt';
  7660. // $data = json_decode ( file_get_contents ( $file ) );
  7661. // if ($data->expire_time < time () or ! $data->expire_time) {
  7662. // 如果是企业号用以下URL获取access_token
  7663. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7664. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7665. $res = json_decode ( $this->httpGet ( $url ) );
  7666. $access_token = $res->access_token;
  7667. // echo $access_token;
  7668. // if ($access_token) {
  7669. // $data->expire_time = time () + 7000;
  7670. // $data->access_token = $access_token;
  7671. // $fp = fopen ( $file, "w" );
  7672. // fwrite ( $fp, json_encode ( $data ) );
  7673. // fclose ( $fp );
  7674. // }
  7675. // } else {
  7676. // $access_token = $data->access_token;
  7677. // }
  7678. return $access_token;
  7679. }
  7680. private function httpGet($url) {
  7681. $curl = curl_init ();
  7682. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7683. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7684. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7685. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7686. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7687. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7688. curl_setopt ( $curl, CURLOPT_URL, $url );
  7689. $res = curl_exec ( $curl );
  7690. curl_close ( $curl );
  7691. return $res;
  7692. }
  7693. private function httpPost($url, $data) {
  7694. $curl = curl_init ();
  7695. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7696. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7697. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7698. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7699. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7700. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7701. curl_setopt ( $curl, CURLOPT_URL, $url );
  7702. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7703. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7704. $res = curl_exec ( $curl );
  7705. curl_close ( $curl );
  7706. return $res;
  7707. }
  7708. }
  7709. ?>