InvoiceController.php 330 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112
  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. }
  464. }elseif($invoiceType == 0){
  465. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  466. if ($temporary > 100001) {
  467. header ( 'Content-Type:text/html;charset=utf-8' );
  468. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  469. }
  470. }else{
  471. die ( 'illegal request-invoiceType' );
  472. }
  473. if (empty ( $this->staff [0] ))
  474. die ( 'illegal request-Please login' );
  475. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  476. Doo::loadModel ( 'invoice' );
  477. $invoice = new invoice ();
  478. Doo::loadModel ( 'L_category' );
  479. $lCategory = new L_category ();
  480. Doo::loadModel ( 'invoiceManage' );
  481. $invoiceManage = new invoiceManage ();
  482. Doo::loadModel ( 'invoiceOperationLog' );
  483. $invoiceOperationLog = new invoiceOperationLog ();
  484. Doo::loadClass ( 'XDeode' );
  485. $XDeode = new XDeode ( 5 );
  486. $trainId = $XDeode->decode ( $trainId );
  487. $categoryDetil = $lCategory->getOne ( array (
  488. 'SELECT' => 'title',
  489. 'where' => 'cid=' . $cid,
  490. 'asArray' => true
  491. ) );
  492. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  493. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  494. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  495. // print_r(current($invoiceManageDetail ['staffList']));
  496. // die;
  497. $moldManage = array ();
  498. foreach ( $invoiceManageList as $key => $value ) {
  499. if ($value ['mold'] == '发票打印')
  500. $moldManage [$value ['mold']] = $value ['staffList'];
  501. elseif ($value ['mold'] == '发票邮寄')
  502. $moldManage [$value ['mold']] = $value ['staffList'];
  503. elseif ($value ['mold'] == '发票退票')
  504. $moldManage [$value ['mold']] = $value ['staffList'];
  505. }
  506. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  507. $st = '';
  508. if ($settlementType == 'SOFTWARE') {
  509. $st = 0;
  510. $trainId = 0;
  511. } elseif ($settlementType == 'TRAINING') {
  512. $st = 1;
  513. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  514. die ( 'illegal request-trainingIdError' );
  515. }
  516. } else {
  517. die ( 'illegal request-settlementError' );
  518. }
  519. if($invoiceForm=='electronic'){
  520. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  521. $invoiceForm=1;
  522. $invoiceType=0;
  523. if(!empty($electronicPhone)||!empty($electronicEmail)){
  524. }else{
  525. die ( 'illegal request-electronicContact' );
  526. }
  527. $mailList = array ();
  528. $mailString = '备注:' . $mailItems;
  529. }elseif($invoiceForm=='paper'){
  530. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  531. $invoiceForm=0;
  532. $mailList = array (
  533. 'invoice' => 1,
  534. 'mailItems' => $mailItems
  535. );
  536. $mailString = '发票x1张,备注:' . $mailItems;
  537. }else{
  538. die ( 'illegal request-invoiceForm' );
  539. }
  540. $item = array (
  541. 'cid' => $cid,
  542. 'categoryName' => $categoryDetil ['title'],
  543. 'invoiceElement' => $invoiceElement,
  544. 'invoiceForm'=>$invoiceForm,
  545. 'electronicPhone'=>$electronicPhone,
  546. 'electronicEmail'=>$electronicEmail,
  547. 'invoiceQuantity' => $invoiceQuantity,
  548. 'invoiceUnitPrice' => $invoiceUnitPrice,
  549. 'invoicePrice' => $invoicePrice,
  550. 'invoiceType' => $invoiceType,
  551. 'settlementType' => $st,
  552. 'doPost' => $doPost,
  553. 'status' => 1,
  554. 'invoiceSerial' => $invoiceSerial,
  555. 'date' => date ( "Y-m-d H:i:s" ),
  556. 'updateTime' => date ( "Y-m-d H:i:s" ),
  557. 'sid' => $this->staff [0] ['sid'],
  558. 'userName' => $this->staff [0] ['username'],
  559. 'invoiceManage' => $invoiceManageDetail ['staff'],
  560. 'pendingApprovals' => $pendingApprovalsSid,
  561. 'moldManage' => json_encode ( $moldManage ),
  562. 'remark' => $remark,
  563. 'trainId' => $trainId
  564. );
  565. if ($invoiceType == 0)
  566. $item += array (
  567. 'invoiceTitle' => $invoiceTitle,
  568. 'TIN' => $TINT,
  569. 'address' => $addressT,
  570. 'phone' => $phoneT,
  571. 'bank' => $bankT,
  572. 'bankAccount' => $bankAccountT
  573. );
  574. else {
  575. $item += array (
  576. 'invoiceCompany' => $invoiceCompany,
  577. 'TIN' => $TIN,
  578. 'address' => $address,
  579. 'phone' => $phone,
  580. 'bank' => $bank,
  581. 'bankAccount' => $bankAccount
  582. );
  583. }
  584. if ($doPost == 1) {
  585. if (! empty ( $softLock ))
  586. $mailList += array (
  587. 'softLock' => $softLockNum
  588. );
  589. else
  590. $mailList += array (
  591. 'softLock' => 0
  592. );
  593. if (! empty ( $contract ))
  594. $mailList += array (
  595. 'contract' => $contractNum
  596. );
  597. else
  598. $mailList += array (
  599. 'contract' => 0
  600. );
  601. if (! empty ( $instructions ))
  602. $mailList += array (
  603. 'instructions' => $instructionsNum
  604. );
  605. else
  606. $mailList += array (
  607. 'instructions' => 0
  608. );
  609. if (! empty ( $remittance ))
  610. $mailList += array (
  611. 'remittance' => $remittance
  612. );
  613. else
  614. $mailList += array (
  615. 'remittance' => ''
  616. );
  617. if (! empty ( $softLock ))
  618. $mailString .= ',软件锁x' . $softLockNum . '个';
  619. if (! empty ( $contract ))
  620. $mailString .= ',合同x' . $contractNum . '份';
  621. if (! empty ( $instructions ))
  622. $mailString .= ',说明书x' . $instructionsNum . '本';
  623. if (! empty ( $remittance ))
  624. $mailString .= ',汇款账号单(张)';
  625. $item += array (
  626. 'recipients' => $recipients,
  627. 'recipientsPhone' => $recipientsPhone,
  628. 'recipientsAddress' => $recipientsAddress,
  629. 'mailItems' => $mailString,
  630. 'mailItemsJson' => json_encode ( $mailList )
  631. );
  632. }
  633. $iid = $invoice->addInvoice ( $item );
  634. // 如果是培训班结算 创建培训班发票到培训班备份中
  635. if (! empty ( $st ) && $st == 1) {
  636. Doo::loadModel ( 'invoiceStore' );
  637. $invoiceStore = new invoiceStore ();
  638. Doo::loadModel ( 'invoiceTraining' );
  639. $invoiceTraining = new invoiceTraining ();
  640. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  641. $itemIS = array (
  642. 'isid' => $isid,
  643. 'ipSource' => 1,
  644. 'apStatus' => 1,
  645. 'iid' => $iid
  646. );
  647. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  648. // 更新培训班总数量
  649. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  650. $item = array (
  651. 'itid' => $trainId,
  652. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  653. 'submitStatus' => 1
  654. );
  655. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  656. }
  657. // 操作日志
  658. $item = array (
  659. 'date' => date ( "Y-m-d H:i:s" ),
  660. 'operation' => "创建",
  661. 'status' => 1,
  662. 'img' => $this->staff [0] ['avatar'],
  663. 'username' => $this->staff [0] ['username'],
  664. 'uid' => $this->staff [0] ['sid'],
  665. 'category' => $this->staff [0] ['category'],
  666. 'iid' => $iid
  667. );
  668. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  669. $item = array (
  670. 'date' => date ( "Y-m-d H:i:s" ),
  671. 'operation' => "提交审批",
  672. 'status' => 1,
  673. 'img' => $this->staff [0] ['avatar'],
  674. 'username' => $this->staff [0] ['username'],
  675. 'uid' => $this->staff [0] ['sid'],
  676. 'category' => $this->staff [0] ['category'],
  677. 'iid' => $iid
  678. );
  679. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  680. Doo::loadModel ( 'staff' );
  681. $staff = new staff ();
  682. $username2 = $staff->getOne ( array (
  683. 'select' => 'wxid',
  684. 'where' => 'sid=' . $pendingApprovalsSid,
  685. 'asArray' => TRUE
  686. ) );
  687. // 发送微信审批通知
  688. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  689. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  690. }
  691. return "/invoice";
  692. }
  693. function invoiceEdit() {
  694. Doo::loadClass ( 'XDeode' );
  695. $XDeode = new XDeode ( 5 );
  696. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  697. $iid = $XDeode->decode ( $iid );
  698. if (! is_numeric ( $iid ))
  699. die ( 'illegal request' );
  700. Doo::loadModel ( 'invoice' );
  701. $invoice = new invoice ();
  702. Doo::loadModel ( 'invoiceOperationLog' );
  703. $invoiceOperationLog = new invoiceOperationLog ();
  704. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  705. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  706. $invoiceDetail ['mailItemsJson'] ='';
  707. if(isset($invoiceDetail ['mailItemsJson'])){
  708. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  709. }
  710. $this->data ['operation'] = $operation;
  711. $this->data ['invoiceDetail'] = $invoiceDetail;
  712. $this->data ['memu'] = "invoice";
  713. $this->data ['staff'] = $this->staff;
  714. $this->data ['receiptMemu'] = 'invoice';
  715. $this->render ( "/admin/invoiceEdit", $this->data );
  716. }
  717. /**
  718. * 重新编辑退回的发票
  719. * @return string
  720. */
  721. function invoiceEditDo() {
  722. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  723. Doo::loadModel ( 'invoice' );
  724. $invoice = new invoice ();
  725. $iid = $invoice->authcode ( $iidKey );
  726. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  727. die ( 'illegal request' );
  728. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  729. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  730. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  731. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  732. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  733. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  734. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  735. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  736. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  737. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  738. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  739. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  740. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  741. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  742. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  743. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  744. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  745. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  746. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  747. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  748. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  749. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  750. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  751. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  752. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  753. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  754. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  755. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  756. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  757. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  758. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  759. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  760. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  761. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  762. if ($invoiceType == 1) {
  763. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  764. if ($temporary > 100001)
  765. die ( 'illegal request-Please priceError' );
  766. }
  767. if($invoiceForm=='electronic'){
  768. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  769. die ( '请至少填写一种联系方式--电子发票' );
  770. }
  771. }
  772. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  773. Doo::loadModel ( 'invoiceManage' );
  774. $invoiceManage = new invoiceManage ();
  775. Doo::loadModel ( 'invoiceOperationLog' );
  776. $invoiceOperationLog = new invoiceOperationLog ();
  777. Doo::loadModel ( 'invoiceStore' );
  778. $invoiceStore = new invoiceStore ();
  779. $cid = explode ( ':', $cid );
  780. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  781. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  782. $moldManage = array ();
  783. foreach ( $invoiceManageList as $key => $value ) {
  784. if ($value ['mold'] == '发票打印')
  785. $moldManage [$value ['mold']] = $value ['staffList'];
  786. elseif ($value ['mold'] == '发票邮寄')
  787. $moldManage [$value ['mold']] = $value ['staffList'];
  788. elseif ($value ['mold'] == '发票打印')
  789. $moldManage [$value ['mold']] = $value ['staffList'];
  790. }
  791. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  792. if($invoiceForm=='electronic'){
  793. $invoiceForm=1;
  794. $invoiceType=0;
  795. if(!empty($electronicPhone)||!empty($electronicEmail)){
  796. }else{
  797. die ( 'illegal request-electronicContact' );
  798. }
  799. $mailList = array ();
  800. $mailString = '备注:' . $mailItems;
  801. }elseif($invoiceForm=='paper'){
  802. $invoiceForm=0;
  803. $mailList = array (
  804. 'invoice' => 1,
  805. 'mailItems' => $mailItems
  806. );
  807. $mailString = '发票x1张,备注:' . $mailItems;
  808. }else{
  809. die ( 'illegal request-invoiceForm' );
  810. }
  811. $item = array (
  812. 'iid' => $iid,
  813. 'cid' => $cid [0],
  814. 'categoryName' => $cid [1],
  815. 'invoiceElement' => $invoiceElement,
  816. 'invoiceForm'=>$invoiceForm,
  817. 'electronicPhone'=>$electronicPhone,
  818. 'electronicEmail'=>$electronicEmail,
  819. 'invoiceQuantity' => $invoiceQuantity,
  820. 'invoiceUnitPrice' => $invoiceUnitPrice,
  821. 'invoicePrice' => $invoicePrice,
  822. 'invoiceType' => $invoiceType,
  823. 'doPost' => $doPost,
  824. 'status' => 1,
  825. 'updateTime' => date ( "Y-m-d H:i:s" ),
  826. 'remark' => $remark
  827. );
  828. if ($invoiceType == 0)
  829. $item += array (
  830. 'invoiceTitle' => $invoiceTitle,
  831. 'TIN' => $TINT,
  832. 'address' => $addressT,
  833. 'phone' => $phoneT,
  834. 'bank' => $bankT,
  835. 'bankAccount' => $bankAccountT
  836. );
  837. else {
  838. $item += array (
  839. 'invoiceCompany' => $invoiceCompany,
  840. 'TIN' => $TIN,
  841. 'address' => $address,
  842. 'phone' => $phone,
  843. 'bank' => $bank,
  844. 'bankAccount' => $bankAccount
  845. );
  846. }
  847. if ($doPost == 1) {
  848. if (! empty ( $softLock ))
  849. $mailList += array (
  850. 'softLock' => $softLockNum
  851. );
  852. else
  853. $mailList += array (
  854. 'softLock' => '0'
  855. );
  856. if (! empty ( $contract ))
  857. $mailList += array (
  858. 'contract' => $contractNum
  859. );
  860. else
  861. $mailList += array (
  862. 'contract' => '0'
  863. );
  864. if (! empty ( $instructions ))
  865. $mailList += array (
  866. 'instructions' => $instructionsNum
  867. );
  868. else
  869. $mailList += array (
  870. 'instructions' => '0'
  871. );
  872. if (! empty ( $remittance ))
  873. $mailList += array (
  874. 'remittance' => $remittance
  875. );
  876. else
  877. $mailList += array (
  878. 'remittance' => ''
  879. );
  880. if (! empty ( $softLock ))
  881. $mailString .= ',软件锁x' . $softLockNum;
  882. if (! empty ( $contract ))
  883. $mailString .= ',合同x' . $contractNum;
  884. if (! empty ( $instructions ))
  885. $mailString .= ',说明书x' . $instructionsNum;
  886. if (! empty ( $remittance ))
  887. $mailString .= ',汇款账号单';
  888. $item += array (
  889. 'recipients' => $recipients,
  890. 'recipientsPhone' => $recipientsPhone,
  891. 'recipientsAddress' => $recipientsAddress,
  892. 'mailItems' => $mailString,
  893. 'mailItemsJson' => json_encode ( $mailList )
  894. );
  895. }
  896. $invoice->setInvoiceByCondition ( $item );
  897. // 更新培训班仓库里的发票
  898. $detail = $invoice->getInvoiceByIid ( $iid );
  899. if (! empty ( $detail ['isid'] )) {
  900. $invoiceStore->isid = $detail ['isid'];
  901. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  902. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  903. $invoiceStore->invoicePrice = $invoicePrice;
  904. $invoiceStore->update ();
  905. }
  906. $item = array (
  907. 'date' => date ( "Y-m-d H:i:s" ),
  908. 'operation' => "重新提交审批",
  909. 'status' => 1,
  910. 'img' => $this->staff [0] ['avatar'],
  911. 'username' => $this->staff [0] ['username'],
  912. 'uid' => $this->staff [0] ['sid'],
  913. 'category' => $this->staff [0] ['category'],
  914. 'iid' => $iid
  915. );
  916. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  917. }
  918. return "/invoice";
  919. }
  920. /**
  921. * 培训班
  922. */
  923. function invoiceTraining() {
  924. Doo::loadModel ( 'L_category' );
  925. $lCategory = new L_category ();
  926. Doo::loadModel ( 'invoiceTraining' );
  927. $invoiceTraining = new invoiceTraining ();
  928. Doo::loadModel ( 'invoiceTrainManage' );
  929. $invoiceTrainManage = new invoiceTrainManage ();
  930. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  931. $cidList = array ();
  932. foreach ( $imcStaff as $key => $value ) {
  933. array_push ( $cidList, $value ['cid'] );
  934. }
  935. if (empty ( $cidList )) {
  936. $cidString = $this->staff [0] ['cid'];
  937. } else {
  938. $cidString = implode ( ',', $cidList );
  939. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  940. }
  941. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  942. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  943. $category = $lCategory->getCategory ();
  944. $itid = array ();
  945. foreach ( $itTodoList as $key => $value ) {
  946. array_push ( $itid, $value ['itid'] );
  947. // 如果入账100%更新为已完成
  948. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  949. $invoiceTraining = new invoiceTraining ();
  950. $invoiceTraining->itid = $value ['itid'];
  951. $invoiceTraining->status = 2;
  952. $invoiceTraining->update ();
  953. }
  954. }
  955. foreach ( $itedList as $value ) {
  956. array_push ( $itid, $value ['itid'] );
  957. }
  958. $itid = implode ( ',', $itid );
  959. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  960. // print_r($itTodoList);
  961. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  962. $this->data ['itTodoList'] = $itTodoList;
  963. $this->data ['itedList'] = $itedList;
  964. $this->data ['category'] = $category;
  965. $this->data ['memu'] = "invoice";
  966. $this->data ['staff'] = $this->staff;
  967. $this->data ['receiptMemu'] = 'invoiceTraining';
  968. $this->render ( "/admin/invoiceTraining", $this->data );
  969. }
  970. /**
  971. * 创建培训班
  972. */
  973. function invoiceTrainingAdd() {
  974. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  975. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  976. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  977. if (empty ( $this->staff [0] ))
  978. die ( 'illegal request' );
  979. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  980. Doo::loadModel ( 'invoiceTraining' );
  981. $invoiceTraining = new invoiceTraining ();
  982. Doo::loadModel ( 'invoice' );
  983. $invoice = new invoice ();
  984. Doo::loadModel ( 'L_category' );
  985. $lCategory = new L_category ();
  986. Doo::loadModel ( 'invoiceManage' );
  987. $invoiceManage = new invoiceManage ();
  988. Doo::loadModel ( 'invoiceOperationLog' );
  989. $invoiceOperationLog = new invoiceOperationLog ();
  990. $item = array (
  991. 'cid' => $cid,
  992. 'trainName' => $trainName,
  993. 'trainDate' => $trainDate,
  994. 'creator' => $this->staff [0] ['sid'],
  995. 'creatorDate' => date ( "Y-m-d H:i:s" )
  996. );
  997. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  998. }
  999. return "/invoiceTraining";
  1000. }
  1001. /**
  1002. * 删除培训班
  1003. */
  1004. function invoiceTrainingDelDo() {
  1005. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1006. if (! empty ( $itid )) {
  1007. Doo::loadModel ( 'invoiceTraining' );
  1008. $invoiceTraining = new invoiceTraining ();
  1009. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1010. }
  1011. return "/invoiceTraining";
  1012. }
  1013. /**
  1014. * 培训班详情
  1015. */
  1016. function invoiceTrainingDetail() {
  1017. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1018. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1019. Doo::loadModel ( 'invoiceTraining' );
  1020. $invoiceTraining = new invoiceTraining ();
  1021. Doo::loadModel ( 'invoiceStore' );
  1022. $invoiceStore = new invoiceStore ();
  1023. if (empty ( $itid ))
  1024. die ( 'illegal request' );
  1025. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1026. if ($trainStatus == "SUBED")
  1027. $con = ' (b.untreadStatus is null ) and ';
  1028. elseif ($trainStatus == "APPROVAL")
  1029. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1030. elseif ($trainStatus == "TICKET")
  1031. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1032. elseif ($trainStatus == "TICKETING") {
  1033. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1034. }
  1035. $con.=' a.invoiceForm=0 and ';
  1036. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1037. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1038. //print_r($isList);
  1039. $trainlistJson=$this->_trainList($isList);
  1040. if (empty ( $detail ))
  1041. die ( 'illegal request' );
  1042. // 培训班结算是否有和是否已经结算完成
  1043. Doo::loadModel ( 'receipt' );
  1044. $receipt = new receipt ();
  1045. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1046. $this->data ['receiptDetail'] = $receiptDetail;
  1047. $this->data ['trainStatus'] = $trainStatus;
  1048. $this->data ['itid'] = $itid;
  1049. $this->data ['trainlistJson'] = $trainlistJson;
  1050. $this->data ['iTrainDetail'] = $detail;
  1051. $this->data ['memu'] = "invoice";
  1052. $this->data ['staff'] = $this->staff;
  1053. $this->data ['receiptMemu'] = 'invoiceTraining';
  1054. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1055. }
  1056. function invoiceTrainingElectronicDetail(){
  1057. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1058. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1059. Doo::loadModel ( 'invoiceTraining' );
  1060. $invoiceTraining = new invoiceTraining ();
  1061. Doo::loadModel ( 'invoiceStore' );
  1062. $invoiceStore = new invoiceStore ();
  1063. if (empty ( $itid ))
  1064. die ( 'illegal request' );
  1065. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1066. if ($trainStatus == "SUBED")
  1067. $con = ' (b.untreadStatus is null ) and ';
  1068. elseif ($trainStatus == "APPROVAL")
  1069. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1070. elseif ($trainStatus == "TICKET")
  1071. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1072. elseif ($trainStatus == "TICKETING") {
  1073. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1074. }
  1075. $con.=' a.invoiceForm=1 and ';
  1076. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1077. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1078. //print_r($isList);
  1079. if (empty ( $detail )){
  1080. die ( 'illegal request' );
  1081. }
  1082. $trainlistJson=$this->_trainList($isList,1);
  1083. // 培训班结算是否有和是否已经结算完成
  1084. Doo::loadModel ( 'receipt' );
  1085. $receipt = new receipt ();
  1086. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1087. $this->data ['receiptDetail'] = $receiptDetail;
  1088. $this->data ['trainStatus'] = $trainStatus;
  1089. $this->data ['itid'] = $itid;
  1090. $this->data ['trainlistJson'] = $trainlistJson;
  1091. $this->data ['iTrainDetail'] = $detail;
  1092. $this->data ['memu'] = "invoice";
  1093. $this->data ['staff'] = $this->staff;
  1094. $this->data ['receiptMemu'] = 'invoiceTraining';
  1095. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1096. }
  1097. function _trainList($isList,$type=0){
  1098. $trainlist = array ();
  1099. foreach ( $isList as $key => $value ) {
  1100. $irDetail = array ();
  1101. if ($value ['apStatus'] == 1) {
  1102. // array_push ( $irDetail, '' );
  1103. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1104. } else {
  1105. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1106. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1107. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1108. }
  1109. array_push ( $irDetail, $value ['invoiceSerial'] );
  1110. if ($value ['invoiceType'] == 1)
  1111. array_push ( $irDetail, $value ['invoiceCompany'] );
  1112. else
  1113. array_push ( $irDetail, $value ['invoiceTitle'] );
  1114. array_push ( $irDetail, $value ['TIN'] );
  1115. array_push ( $irDetail, $value ['userName'] );
  1116. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1117. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1118. } else
  1119. array_push ( $irDetail, $value ['mailItems'] );
  1120. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1121. if($type==1){
  1122. array_push ( $irDetail, $value ['electronicPhone'] );
  1123. array_push ( $irDetail, $value ['electronicEmail'] );
  1124. }
  1125. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1126. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1127. array_push ( $irDetail, $value ['invoiceElement'] );
  1128. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1129. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1130. if ($value ['invoiceType'] == 1)
  1131. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1132. else
  1133. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1134. array_push ( $irDetail, $value ['remark'] );
  1135. if ($value ['status'] == 1)
  1136. array_push ( $irDetail, '审批中' );
  1137. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1138. array_push ( $irDetail, '已出票' );
  1139. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1140. array_push ( $irDetail, '已入账' );
  1141. else
  1142. array_push ( $irDetail, '' );
  1143. array_push ( $irDetail, $value ['invoiceNo'] );
  1144. array_push ( $irDetail, $value ['printTime'] );
  1145. $html = '';
  1146. foreach ( $value ['invoiceReceivables'] as $v ) {
  1147. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1148. }
  1149. array_push ( $irDetail, $html );
  1150. array_push ( $trainlist, $irDetail );
  1151. }
  1152. $trainlistJson = json_encode ( $trainlist );
  1153. return $trainlistJson;
  1154. }
  1155. /**
  1156. * 上传培训班发票
  1157. * @return string
  1158. */
  1159. function invoiceTrainingUpload() {
  1160. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1161. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1162. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1163. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1164. header ( "HTTP/1.1 500 Internal Server Error" );
  1165. echo "POST exceeded maximum allowed size.";
  1166. exit ( 0 );
  1167. }
  1168. // Settings
  1169. $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)
  1170. $upload_name = "Filedata";
  1171. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1172. $extension_whitelist = array (
  1173. "doc",
  1174. "txt",
  1175. "jpg",
  1176. "gif",
  1177. "png"
  1178. ); // Allowed file extensions
  1179. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1180. // Other variables
  1181. $MAX_FILENAME_LENGTH = 260;
  1182. $file_name = "";
  1183. $file_extension = "";
  1184. $uploadErrors = array (
  1185. 0 => "文件上传成功",
  1186. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1187. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1188. 3 => "上传的文件仅为部分文件",
  1189. 4 => "没有文件上传",
  1190. 6 => "缺少临时文件夹"
  1191. );
  1192. $nk = time ();
  1193. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1194. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1195. echo "文件无法保存.";
  1196. exit ( 0 );
  1197. }
  1198. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1199. echo json_encode ( array (
  1200. 'filename' => $file_name,
  1201. 'id' => $nk
  1202. ) );
  1203. exit ( 0 );
  1204. }
  1205. /**
  1206. * 导入发票临时仓库
  1207. */
  1208. function invoiceStoreImport() {
  1209. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1210. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1211. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1212. if ($path != "" && ! empty ( $trainingKey )) {
  1213. Doo::loadModel ( 'invoiceStore' );
  1214. Doo::loadModel ( 'staff' );
  1215. $staff = new staff ();
  1216. Doo::loadModel ( 'invoiceTraining' );
  1217. $invoiceTraining = new invoiceTraining ();
  1218. Doo::loadClass ( 'XDeode' );
  1219. $XDeode = new XDeode ( 5 );
  1220. $itid = $XDeode->decode ( $trainingKey );
  1221. // 培训班结算是否有和是否已经结算完成
  1222. Doo::loadModel ( 'receipt' );
  1223. $receipt = new receipt ();
  1224. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1225. if (! empty ( $receiptDetail )) {
  1226. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1227. die ( 'illegal request--status' );
  1228. }
  1229. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1230. $userName = $this->staff [0] ['username'];
  1231. $sDetail = $staff->getStaffByName ( $userName );
  1232. //print_r($exlArray);die;
  1233. // die('sdd');
  1234. // 可以优化
  1235. foreach ( $exlArray as $key => $value ) {
  1236. // 开票
  1237. $invoice = new invoiceStore ();
  1238. $invoice->trainId = $itid;
  1239. $invoice->invoiceType = 0;
  1240. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1241. $invoice->invoiceType = 1;
  1242. elseif($value ['invoiceType'] == '电子'){
  1243. $invoice->invoiceType = 0;
  1244. $invoice->invoiceForm=1;
  1245. }
  1246. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1247. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1248. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1249. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1250. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1251. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1252. $invoice->userName = $userName;
  1253. $invoice->sid = $sDetail ['sid'];
  1254. $invoice->cid = $sDetail ['cid'];
  1255. $invoice->categoryName = $sDetail ['category'];
  1256. $invoice->invoiceElement = $value ['invoiceElement'];
  1257. $invoice->remark = $value ['remark'];
  1258. // $invoice->date = $value ['date'];
  1259. // $invoice->printTime = $value ['date'];
  1260. $invoice->ipSource = 1;
  1261. $invoice->printStatus = 0;
  1262. $invoice->status = 0;
  1263. $invoice->postStatus = 1;
  1264. $invoice->untreadStatus = 0;
  1265. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1266. $invoice->TIN = $value ['TIN'];
  1267. $invoice->address = $value ['address'];
  1268. $invoice->phone = $value ['phone'];
  1269. $invoice->bank = $value ['bank'];
  1270. $invoice->bankAccount = $value ['bankAccount'];
  1271. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1272. $invoice->recipients = $value ['recipients'];
  1273. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1274. $invoice->electronicPhone = $value ['electronicPhone'];
  1275. $invoice->electronicEmail = $value ['electronicEmail'];
  1276. $iid = $invoice->insert ();
  1277. }
  1278. // 加入发票总数量
  1279. $item = array (
  1280. 'itid' => $itid,
  1281. 'invoiceTotal' => count ( $exlArray )
  1282. );
  1283. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1284. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1285. }
  1286. echo 'no file';
  1287. }
  1288. /**
  1289. * 编辑仓库里的发票
  1290. */
  1291. function invoiceStoreEdit() {
  1292. Doo::loadClass ( 'XDeode' );
  1293. $XDeode = new XDeode ( 5 );
  1294. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1295. $iid = $XDeode->decode ( $iid );
  1296. if (! is_numeric ( $iid ))
  1297. die ( 'illegal request' );
  1298. Doo::loadModel ( 'invoiceStore' );
  1299. $invoiceStore = new invoiceStore ();
  1300. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1301. // print_r($invoiceDetail);
  1302. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1303. $this->data ['invoiceDetail'] = $invoiceDetail;
  1304. $this->data ['memu'] = "invoice";
  1305. $this->data ['staff'] = $this->staff;
  1306. $this->data ['receiptMemu'] = 'invoiceTraining';
  1307. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1308. }
  1309. function invoiceStoreEditDo() {
  1310. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1311. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1312. Doo::loadModel ( 'invoiceStore' );
  1313. $invoice = new invoiceStore ();
  1314. Doo::loadClass ( 'XDeode' );
  1315. $XDeode = new XDeode ( 5 );
  1316. $iid = $XDeode->decode ( $storeKey );
  1317. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1318. die ( 'illegal request' );
  1319. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1320. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1321. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1322. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1323. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1324. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1325. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1326. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1327. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1328. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1329. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1330. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1331. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1332. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1333. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1334. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1335. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1336. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1337. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1338. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1339. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1340. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1341. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1342. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1343. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1344. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1345. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1346. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1347. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1348. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1349. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1350. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1351. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1352. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1353. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1354. $cid = explode ( ':', $cid );
  1355. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1356. $item = array (
  1357. 'isid' => $iid,
  1358. 'cid' => $cid [0],
  1359. 'categoryName' => $cid [1],
  1360. 'invoiceElement' => $invoiceElement,
  1361. 'invoiceQuantity' => $invoiceQuantity,
  1362. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1363. 'invoicePrice' => $invoicePrice,
  1364. 'invoiceType' => $invoiceType,
  1365. 'doPost' => $doPost,
  1366. 'status' => 1,
  1367. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1368. 'remark' => $remark
  1369. );
  1370. if ($invoiceType == 0)
  1371. $item += array (
  1372. 'invoiceTitle' => $invoiceTitle,
  1373. 'TIN' => $TINT,
  1374. 'address' => $addressT,
  1375. 'phone' => $phoneT,
  1376. 'bank' => $bankT,
  1377. 'bankAccount' => $bankAccountT
  1378. );
  1379. else {
  1380. $item += array (
  1381. 'invoiceCompany' => $invoiceCompany,
  1382. 'TIN' => $TIN,
  1383. 'address' => $address,
  1384. 'phone' => $phone,
  1385. 'bank' => $bank,
  1386. 'bankAccount' => $bankAccount
  1387. );
  1388. }
  1389. if($invoiceForm=='paper'){
  1390. $item += array (
  1391. 'invoiceForm' => 0
  1392. );
  1393. }elseif($invoiceForm=='electronic'){
  1394. $item += array (
  1395. 'invoiceForm' => 1,
  1396. 'electronicPhone' => $electronicPhone,
  1397. 'electronicEmail' => $electronicEmail,
  1398. );
  1399. }
  1400. if ($doPost == 1) {
  1401. $mailList = array (
  1402. 'invoice' => 1,
  1403. 'mailItems' => $mailItems
  1404. );
  1405. if (! empty ( $softLock ))
  1406. $mailList += array (
  1407. 'softLock' => $softLockNum
  1408. );
  1409. else
  1410. $mailList += array (
  1411. 'softLock' => '0'
  1412. );
  1413. if (! empty ( $contract ))
  1414. $mailList += array (
  1415. 'contract' => $contractNum
  1416. );
  1417. else
  1418. $mailList += array (
  1419. 'contract' => '0'
  1420. );
  1421. if (! empty ( $instructions ))
  1422. $mailList += array (
  1423. 'instructions' => $instructionsNum
  1424. );
  1425. else
  1426. $mailList += array (
  1427. 'instructions' => '0'
  1428. );
  1429. if (! empty ( $remittance ))
  1430. $mailList += array (
  1431. 'remittance' => $remittance
  1432. );
  1433. else
  1434. $mailList += array (
  1435. 'remittance' => ''
  1436. );
  1437. $mailString = '发票x1,备注:' . $mailItems;
  1438. if (! empty ( $softLock ))
  1439. $mailString .= ',软件锁x' . $softLockNum;
  1440. if (! empty ( $contract ))
  1441. $mailString .= ',合同x' . $contractNum;
  1442. if (! empty ( $instructions ))
  1443. $mailString .= ',说明书x' . $instructionsNum;
  1444. if (! empty ( $remittance ))
  1445. $mailString .= ',汇款账号单';
  1446. $item += array (
  1447. 'recipients' => $recipients,
  1448. 'recipientsPhone' => $recipientsPhone,
  1449. 'recipientsAddress' => $recipientsAddress,
  1450. 'mailItems' => $mailString,
  1451. 'mailItemsJson' => json_encode ( $mailList )
  1452. );
  1453. }
  1454. $invoice->setInvoiceStoreByCondition ( $item );
  1455. }
  1456. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1457. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1458. }else{
  1459. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1460. }
  1461. }
  1462. /**
  1463. *
  1464. * @return string
  1465. */
  1466. function invoiceStoreDelete() {
  1467. Doo::loadClass ( 'XDeode' );
  1468. $XDeode = new XDeode ( 5 );
  1469. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1470. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1471. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1472. $isid = $XDeode->decode ( $iStoreKey );
  1473. $itid = $XDeode->decode ( $trainKey );
  1474. if (! is_numeric ( $isid ))
  1475. die ( 'illegal request' );
  1476. Doo::loadModel ( 'invoiceStore' );
  1477. $invoiceStore = new invoiceStore ();
  1478. $invoiceStore->delete ( array (
  1479. 'where' => 'isid=' . $isid,
  1480. 'limit' => 1
  1481. ) );
  1482. Doo::loadModel ( 'invoiceTraining' );
  1483. $invoiceTraining = new invoiceTraining ();
  1484. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1485. $item = array (
  1486. 'itid' => $itid,
  1487. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1488. );
  1489. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1490. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1491. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1492. }else{
  1493. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1494. }
  1495. }
  1496. /**
  1497. * 批量删除库里发票
  1498. */
  1499. function invoiceStoreBatchDelete() {
  1500. Doo::loadClass ( 'XDeode' );
  1501. $XDeode = new XDeode ( 5 );
  1502. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1503. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1504. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1505. if (empty ( $trainKey ) || empty ( $storeKey ))
  1506. die ( 'illegal request-IdKey' );
  1507. $tid = $XDeode->decode ( $trainKey );
  1508. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1509. die ( 'illegal request' );
  1510. Doo::loadModel ( 'invoiceStore' );
  1511. $isidKeyList = explode ( ',', $storeKey );
  1512. $isidList = array ();
  1513. foreach ( $isidKeyList as $value ) {
  1514. $isid = $XDeode->decode ( $value );
  1515. if (! empty ( $isid ) && is_numeric ( $isid ))
  1516. array_push ( $isidList, $isid );
  1517. }
  1518. $isidString = implode ( ',', $isidList );
  1519. $invoiceStore = new invoiceStore ();
  1520. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1521. $isidList = array ();
  1522. foreach ( $isList as $key => $value ) {
  1523. if ($value ['apStatus'] == 0)
  1524. array_push ( $isidList, $value ['isid'] );
  1525. }
  1526. $isidString = implode ( ',', $isidList );
  1527. // print_r($isList);
  1528. // echo $isidString;
  1529. $invoiceStore = new invoiceStore ();
  1530. $invoiceStore->delete ( array (
  1531. 'where' => "isid in ( " . $isidString . ")",
  1532. 'asArray' => TRUE
  1533. ) );
  1534. Doo::loadModel ( 'invoiceTraining' );
  1535. $invoiceTraining = new invoiceTraining ();
  1536. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1537. $item = array (
  1538. 'itid' => $tid,
  1539. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1540. );
  1541. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1542. // echo $tid;
  1543. // echo $storeKey;
  1544. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1545. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1546. }else{
  1547. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1548. }
  1549. }
  1550. function invoiceStoreBatchElectronicPhone(){
  1551. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1552. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1553. Doo::loadClass ( 'XDeode' );
  1554. $XDeode = new XDeode ( 5 );
  1555. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1556. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1557. if (empty ( $trainKey ) || empty ( $storeKey ))
  1558. die ( 'illegal request-IdKey' );
  1559. $isidKeyList = explode ( ',', $storeKey );
  1560. $isidList = array ();
  1561. foreach ( $isidKeyList as $value ) {
  1562. $isid = $XDeode->decode ( $value );
  1563. if (! empty ( $isid ) && is_numeric ( $isid ))
  1564. array_push ( $isidList, $isid );
  1565. }
  1566. $isidString = implode ( ',', $isidList );
  1567. $trainId = $XDeode->decode ( $trainKey );
  1568. if (! is_numeric ( $isid ))
  1569. die ( 'illegal request--isid' );
  1570. Doo::loadModel ( 'invoiceStore' );
  1571. $invoiceStore = new invoiceStore ();
  1572. $item = array (
  1573. 'electronicPhone' => $electronicPhone
  1574. );
  1575. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1576. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1577. }
  1578. function invoiceStoreBatchElectronicEmail(){
  1579. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1580. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1581. Doo::loadClass ( 'XDeode' );
  1582. $XDeode = new XDeode ( 5 );
  1583. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1584. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1585. if (empty ( $trainKey ) || empty ( $storeKey ))
  1586. die ( 'illegal request-IdKey' );
  1587. $isidKeyList = explode ( ',', $storeKey );
  1588. $isidList = array ();
  1589. foreach ( $isidKeyList as $value ) {
  1590. $isid = $XDeode->decode ( $value );
  1591. if (! empty ( $isid ) && is_numeric ( $isid ))
  1592. array_push ( $isidList, $isid );
  1593. }
  1594. $isidString = implode ( ',', $isidList );
  1595. $trainId = $XDeode->decode ( $trainKey );
  1596. if (! is_numeric ( $isid ))
  1597. die ( 'illegal request' );
  1598. Doo::loadModel ( 'invoiceStore' );
  1599. $invoiceStore = new invoiceStore ();
  1600. $item = array (
  1601. 'electronicEmail' => $electronicEmail
  1602. );
  1603. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1604. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1605. }
  1606. /**
  1607. * 仓库发票提交审批
  1608. * @return string
  1609. */
  1610. function invoiceStoreApproval() {
  1611. Doo::loadClass ( 'XDeode' );
  1612. $XDeode = new XDeode ( 5 );
  1613. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1614. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1615. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1616. $isid = $XDeode->decode ( $iStoreKey );
  1617. $trainId = $XDeode->decode ( $trainKey );
  1618. if (! is_numeric ( $isid ))
  1619. die ( 'illegal request' );
  1620. Doo::loadModel ( 'invoiceStore' );
  1621. Doo::loadModel ( 'invoice' );
  1622. $invoice = new invoice ();
  1623. // 加入限制必须填写入开票内容和邮寄物品
  1624. $invoiceStore = new invoiceStore ();
  1625. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1626. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1627. header ( 'Content-Type:text/html;charset=utf-8' );
  1628. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1629. }
  1630. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1631. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1632. header ( 'Content-Type:text/html;charset=utf-8' );
  1633. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1634. }
  1635. }
  1636. // 拷贝插入一条发票数据
  1637. $invoiceStore = new invoiceStore ();
  1638. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1639. $invoiceStore = new invoiceStore ();
  1640. $item = array (
  1641. 'isid' => $isid,
  1642. 'iid' => $iid,
  1643. 'apStatus' => 1
  1644. );
  1645. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1646. Doo::loadModel ( 'invoiceManage' );
  1647. $invoiceManage = new invoiceManage ();
  1648. Doo::loadModel ( 'invoiceOperationLog' );
  1649. $invoiceOperationLog = new invoiceOperationLog ();
  1650. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1651. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1652. $moldManage = array ();
  1653. foreach ( $invoiceManageList as $key => $value ) {
  1654. if ($value ['mold'] == '发票打印')
  1655. $moldManage [$value ['mold']] = $value ['staffList'];
  1656. elseif ($value ['mold'] == '发票邮寄')
  1657. $moldManage [$value ['mold']] = $value ['staffList'];
  1658. elseif ($value ['mold'] == '发票退票')
  1659. $moldManage [$value ['mold']] = $value ['staffList'];
  1660. }
  1661. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1662. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1663. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1664. }else{
  1665. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1666. }
  1667. $item = array (
  1668. 'iid' => $iid,
  1669. 'isid' => $isid,
  1670. 'invoiceSerial' => $invoiceSerial,
  1671. 'date' => date ( "Y-m-d H:i:s" ),
  1672. 'status' => 1,
  1673. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1674. 'trainId' => $trainId,
  1675. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1676. 'moldManage' => json_encode ( $moldManage ),
  1677. 'settlementType' => 1,
  1678. 'pendingApprovals' => $pendingApprovalsSid
  1679. );
  1680. $invoice->setInvoiceByCondition ( $item );
  1681. Doo::loadModel ( 'invoiceTraining' );
  1682. $invoiceTraining = new invoiceTraining ();
  1683. $item = array (
  1684. 'itid' => $trainId,
  1685. 'submitStatus' => 1
  1686. );
  1687. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1688. $item = array (
  1689. 'date' => date ( "Y-m-d H:i:s" ),
  1690. 'operation' => "创建",
  1691. 'status' => 1,
  1692. 'img' => $this->staff [0] ['avatar'],
  1693. 'username' => $this->staff [0] ['username'],
  1694. 'uid' => $this->staff [0] ['sid'],
  1695. 'category' => $this->staff [0] ['category'],
  1696. 'iid' => $iid
  1697. );
  1698. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1699. $item = array (
  1700. 'date' => date ( "Y-m-d H:i:s" ),
  1701. 'operation' => "提交审批",
  1702. 'status' => 1,
  1703. 'img' => $this->staff [0] ['avatar'],
  1704. 'username' => $this->staff [0] ['username'],
  1705. 'uid' => $this->staff [0] ['sid'],
  1706. 'category' => $this->staff [0] ['category'],
  1707. 'iid' => $iid
  1708. );
  1709. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1710. Doo::loadModel ( 'staff' );
  1711. $staff = new staff ();
  1712. $username2 = $staff->getOne ( array (
  1713. 'select' => 'wxid',
  1714. 'where' => 'sid=' . $pendingApprovalsSid,
  1715. 'asArray' => TRUE
  1716. ) );
  1717. // 发送微信审批通知
  1718. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1719. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1720. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1721. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1722. }else{
  1723. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1724. }
  1725. }
  1726. /**
  1727. * 批量提交发票
  1728. * @return string
  1729. */
  1730. function invoiceStoreBatchApproval() {
  1731. Doo::loadClass ( 'XDeode' );
  1732. $XDeode = new XDeode ( 5 );
  1733. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1734. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1735. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1736. if (empty ( $trainKey ) || empty ( $storeKey ))
  1737. die ( 'illegal request-IdKey' );
  1738. $trainId = $XDeode->decode ( $trainKey );
  1739. $isidKeyList = explode ( ',', $storeKey );
  1740. $isidList = array ();
  1741. foreach ( $isidKeyList as $value ) {
  1742. $isid = $XDeode->decode ( $value );
  1743. if (! empty ( $isid ) && is_numeric ( $isid ))
  1744. array_push ( $isidList, $isid );
  1745. }
  1746. $isidString = implode ( ',', $isidList );
  1747. if (! is_numeric ( $trainId ))
  1748. die ( 'illegal request' );
  1749. Doo::loadModel ( 'invoiceStore' );
  1750. Doo::loadModel ( 'invoice' );
  1751. // 判断哪些已经加入审批过
  1752. // 加入限制必须填写入开票内容和邮寄物品
  1753. $invoiceStore = new invoiceStore ();
  1754. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1755. foreach ( $isList as $key => $value ) {
  1756. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1757. header ( 'Content-Type:text/html;charset=utf-8' );
  1758. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1759. }
  1760. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1761. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1762. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1763. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1764. header ( 'Content-Type:text/html;charset=utf-8' );
  1765. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1766. }
  1767. }
  1768. }
  1769. // 拷贝插入一条发票数据
  1770. $invoiceStore = new invoiceStore ();
  1771. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1772. $invoiceStore = new invoiceStore ();
  1773. $item = array (
  1774. 'apStatus' => 1
  1775. );
  1776. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1777. // 获得正式发票ID
  1778. $invoice = new invoice ();
  1779. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1780. $sqlList = array ();
  1781. $iidString = '';
  1782. $iida = array ();
  1783. foreach ( $iidList as $key => $value ) {
  1784. $sqlList [$value ['isid']] = $value ['iid'];
  1785. array_push ( $iida, $value ['iid'] );
  1786. }
  1787. $iidString = implode ( ',', $iida );
  1788. $ids = implode ( ',', array_keys ( $sqlList ) );
  1789. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1790. foreach ( $sqlList as $id => $ordinal ) {
  1791. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1792. }
  1793. $sql .= "END WHERE isid IN ($ids)";
  1794. $invoiceStore = new invoiceStore ();
  1795. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1796. Doo::loadModel ( 'invoiceManage' );
  1797. $invoiceManage = new invoiceManage ();
  1798. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1799. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1800. $moldManage = array ();
  1801. foreach ( $invoiceManageList as $key => $value ) {
  1802. if ($value ['mold'] == '发票打印')
  1803. $moldManage [$value ['mold']] = $value ['staffList'];
  1804. elseif ($value ['mold'] == '发票邮寄')
  1805. $moldManage [$value ['mold']] = $value ['staffList'];
  1806. elseif ($value ['mold'] == '发票退票')
  1807. $moldManage [$value ['mold']] = $value ['staffList'];
  1808. }
  1809. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1810. // 批量更新发票信息
  1811. $item = array (
  1812. 'date' => date ( "Y-m-d H:i:s" ),
  1813. 'status' => 1,
  1814. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1815. 'trainId' => $trainId,
  1816. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1817. 'moldManage' => json_encode ( $moldManage ),
  1818. 'settlementType' => 1,
  1819. 'pendingApprovals' => $pendingApprovalsSid
  1820. );
  1821. $invoice = new invoice ();
  1822. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1823. // 批量更新发票中仓库isid
  1824. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1825. foreach ( $sqlList as $isid => $iid ) {
  1826. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1827. }
  1828. $sql .= "END WHERE iid IN ($iidString)";
  1829. $invoice = new invoice ();
  1830. $invoice->UpdateBatchInvoice ( $sql );
  1831. // 批量更新发票序列号
  1832. $sqlList = array ();
  1833. foreach ( $iida as $value ) {
  1834. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1835. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1836. }else{
  1837. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1838. }
  1839. }
  1840. $ids = implode ( ',', array_keys ( $sqlList ) );
  1841. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1842. foreach ( $sqlList as $id => $ordinal ) {
  1843. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1844. }
  1845. $sql .= "END WHERE iid IN ($ids)";
  1846. $invoiceStore = new invoiceStore ();
  1847. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1848. // 批量生产操作日志
  1849. Doo::loadModel ( 'invoiceOperationLog' );
  1850. $sqlList = array ();
  1851. foreach ( $iida as $key => $value ) {
  1852. $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 . '"),
  1853. ("' . 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 . '") ';
  1854. array_push ( $sqlList, $sql );
  1855. }
  1856. $iolSql = implode ( ',', $sqlList );
  1857. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1858. $invoiceOperationLog = new invoiceOperationLog ();
  1859. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1860. Doo::loadModel ( 'invoiceTraining' );
  1861. $invoiceTraining = new invoiceTraining ();
  1862. $item = array (
  1863. 'itid' => $trainId,
  1864. 'submitStatus' => 1
  1865. );
  1866. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1867. Doo::loadModel ( 'staff' );
  1868. $staff = new staff ();
  1869. $username2 = $staff->getOne ( array (
  1870. 'select' => 'wxid',
  1871. 'where' => 'sid=' . $pendingApprovalsSid,
  1872. 'asArray' => TRUE
  1873. ) );
  1874. // 发送微信审批通知
  1875. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1876. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1877. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1878. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1879. }else{
  1880. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1881. }
  1882. }
  1883. /**
  1884. */
  1885. function invoiceStoreMailItemSet() {
  1886. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1887. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1888. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1889. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1890. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1891. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1892. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1893. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1894. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1895. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1896. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1897. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1898. Doo::loadClass ( 'XDeode' );
  1899. $XDeode = new XDeode ( 5 );
  1900. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1901. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1902. $isid = $XDeode->decode ( $storeKey );
  1903. $trainId = $XDeode->decode ( $trainKey );
  1904. if (! is_numeric ( $isid ))
  1905. die ( 'illegal request' );
  1906. Doo::loadModel ( 'invoiceStore' );
  1907. $invoiceStore = new invoiceStore ();
  1908. $mailList = array (
  1909. 'mailItems' => $mailItems
  1910. );
  1911. $mailString = '发票x1,备注:' . $mailItems;
  1912. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1913. $mailString = '备注:' . $mailItems;
  1914. }else{
  1915. $mailList += array (
  1916. 'invoice' => 1,
  1917. );
  1918. }
  1919. if (! empty ( $softLock ))
  1920. $mailList += array (
  1921. 'softLock' => $softLockNum
  1922. );
  1923. else
  1924. $mailList += array (
  1925. 'softLock' => 0
  1926. );
  1927. if (! empty ( $contract ))
  1928. $mailList += array (
  1929. 'contract' => $contractNum
  1930. );
  1931. else
  1932. $mailList += array (
  1933. 'contract' => 0
  1934. );
  1935. if (! empty ( $instructions ))
  1936. $mailList += array (
  1937. 'instructions' => $instructionsNum
  1938. );
  1939. else
  1940. $mailList += array (
  1941. 'instructions' => 0
  1942. );
  1943. if (! empty ( $remittance ))
  1944. $mailList += array (
  1945. 'remittance' => $remittance
  1946. );
  1947. else
  1948. $mailList += array (
  1949. 'remittance' => ''
  1950. );
  1951. if (! empty ( $softLock ))
  1952. $mailString .= ',软件锁x' . $softLockNum;
  1953. if (! empty ( $contract ))
  1954. $mailString .= ',合同x' . $contractNum;
  1955. if (! empty ( $instructions ))
  1956. $mailString .= ',说明书x' . $instructionsNum;
  1957. if (! empty ( $remittance ))
  1958. $mailString .= ',汇款账号单';
  1959. $item = array (
  1960. 'isid' => $isid,
  1961. 'doPost' => 1,
  1962. 'mailItems' => $mailString,
  1963. 'mailItemsJson' => json_encode ( $mailList )
  1964. );
  1965. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1966. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1967. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1968. }else{
  1969. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1970. }
  1971. }
  1972. /**
  1973. * 批量设置邮寄物品
  1974. */
  1975. function invoiceStoreBatchMailItemSet() {
  1976. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1977. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1978. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1979. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1980. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1981. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1982. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1983. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1984. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1985. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1986. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1987. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1988. Doo::loadClass ( 'XDeode' );
  1989. $XDeode = new XDeode ( 5 );
  1990. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1991. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1992. if (empty ( $trainKey ) || empty ( $storeKey ))
  1993. die ( 'illegal request-IdKey' );
  1994. $isidKeyList = explode ( ',', $storeKey );
  1995. $isidList = array ();
  1996. foreach ( $isidKeyList as $value ) {
  1997. $isid = $XDeode->decode ( $value );
  1998. if (! empty ( $isid ) && is_numeric ( $isid ))
  1999. array_push ( $isidList, $isid );
  2000. }
  2001. $isidString = implode ( ',', $isidList );
  2002. $trainId = $XDeode->decode ( $trainKey );
  2003. if (! is_numeric ( $isid ))
  2004. die ( 'illegal request' );
  2005. Doo::loadModel ( 'invoiceStore' );
  2006. $invoiceStore = new invoiceStore ();
  2007. $mailList = array (
  2008. 'mailItems' => $mailItems
  2009. );
  2010. $mailString = '发票x1,备注:' . $mailItems;
  2011. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2012. $mailString = '备注:' . $mailItems;
  2013. }else{
  2014. $mailList += array (
  2015. 'invoice' => 1,
  2016. );
  2017. }
  2018. if (! empty ( $softLock ))
  2019. $mailList += array (
  2020. 'softLock' => $softLockNum
  2021. );
  2022. else
  2023. $mailList += array (
  2024. 'softLock' => 0
  2025. );
  2026. if (! empty ( $contract ))
  2027. $mailList += array (
  2028. 'contract' => $contractNum
  2029. );
  2030. else
  2031. $mailList += array (
  2032. 'contract' => 0
  2033. );
  2034. if (! empty ( $instructions ))
  2035. $mailList += array (
  2036. 'instructions' => $instructionsNum
  2037. );
  2038. else
  2039. $mailList += array (
  2040. 'instructions' => 0
  2041. );
  2042. if (! empty ( $remittance ))
  2043. $mailList += array (
  2044. 'remittance' => $remittance
  2045. );
  2046. else
  2047. $mailList += array (
  2048. 'remittance' => ''
  2049. );
  2050. if (! empty ( $softLock ))
  2051. $mailString .= ',软件锁x' . $softLockNum;
  2052. if (! empty ( $contract ))
  2053. $mailString .= ',合同x' . $contractNum;
  2054. if (! empty ( $instructions ))
  2055. $mailString .= ',说明书x' . $instructionsNum;
  2056. if (! empty ( $remittance ))
  2057. $mailString .= ',汇款账号单';
  2058. $item = array (
  2059. 'doPost' => 1,
  2060. 'mailItems' => $mailString,
  2061. 'mailItemsJson' => json_encode ( $mailList )
  2062. );
  2063. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2064. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2065. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2066. }else{
  2067. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2068. }
  2069. }
  2070. /**
  2071. * 废弃
  2072. */
  2073. function ajaxGetMailItemByIstore() {
  2074. Doo::loadClass ( 'XDeode' );
  2075. $XDeode = new XDeode ( 5 );
  2076. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2077. $isid = $XDeode->decode ( $storeKey );
  2078. if (! is_numeric ( $isid ))
  2079. die ( 'illegal request' );
  2080. Doo::loadModel ( 'invoiceStore' );
  2081. $invoiceStore = new invoiceStore ();
  2082. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2083. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2084. echo json_encode ( $isDetail ['mailItemsJson'] );
  2085. exit ();
  2086. }
  2087. /**
  2088. * 终止开票
  2089. */
  2090. function invoiceDroppedDo() {
  2091. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2092. Doo::loadModel ( 'invoice' );
  2093. $invoice = new invoice ();
  2094. Doo::loadModel ( 'invoiceOperationLog' );
  2095. $invoiceOperationLog = new invoiceOperationLog ();
  2096. $iid = $invoice->authcode ( $droppedIidKey );
  2097. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2098. die ( 'illegal request' );
  2099. $item = array (
  2100. 'iid' => $iid,
  2101. 'status' => 4,
  2102. 'updateTime' => date ( "Y-m-d H:i:s" )
  2103. );
  2104. $invoice->setInvoiceByCondition ( $item );
  2105. $item = array (
  2106. 'date' => date ( "Y-m-d H:i:s" ),
  2107. 'operation' => '终止了开票',
  2108. 'status' => 4,
  2109. 'img' => $this->staff [0] ['avatar'],
  2110. 'username' => $this->staff [0] ['username'],
  2111. 'uid' => $this->staff [0] ['sid'],
  2112. 'category' => $this->staff [0] ['category'],
  2113. 'iid' => $iid
  2114. );
  2115. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2116. return "/invoice";
  2117. }
  2118. /**
  2119. * 更新退票的邮寄信息
  2120. */
  2121. function invoiceUntreadMailDo() {
  2122. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2123. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2124. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2125. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2126. Doo::loadModel ( 'invoice' );
  2127. $invoice = new invoice ();
  2128. $iid = $invoice->authcode ( $untreadIidKey );
  2129. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2130. die ( 'illegal request' );
  2131. $item = array (
  2132. 'iid' => $iid,
  2133. 'untreadCompany' => $untreadCompany,
  2134. 'untreadNumber' => $untreadNumber,
  2135. 'untreadItems' => $untreadItems
  2136. );
  2137. $invoice->setInvoiceByCondition ( $item );
  2138. return "/invoice";
  2139. }
  2140. /**
  2141. * 申请退票 --
  2142. */
  2143. function invoiceUntreadDo() {
  2144. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2145. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2146. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : 0;
  2147. Doo::loadModel ( 'invoice' );
  2148. $invoice = new invoice ();
  2149. Doo::loadModel ( 'invoiceOperationLog' );
  2150. $invoiceOperationLog = new invoiceOperationLog ();
  2151. Doo::loadModel ( 'invoiceReceivables' );
  2152. $invoiceReceivables = new invoiceReceivables ();
  2153. $iid = $invoice->authcode ( $untreadIidKey );
  2154. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2155. die ( 'illegal request' );
  2156. /*
  2157. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2158. */
  2159. $item = array (
  2160. 'iid' => $iid,
  2161. 'untreadStatus' => 1,
  2162. 'untreadReason' => $untreadReason,
  2163. 'untreadPost' => $untreadPost,
  2164. 'updateTime' => date ( "Y-m-d H:i:s" )
  2165. );
  2166. $invoice->setInvoiceByCondition ( $item );
  2167. $item = array (
  2168. 'date' => date ( "Y-m-d H:i:s" ),
  2169. 'operation' => '申请退票',
  2170. 'status' => 7,
  2171. 'img' => $this->staff [0] ['avatar'],
  2172. 'username' => $this->staff [0] ['username'],
  2173. 'uid' => $this->staff [0] ['sid'],
  2174. 'category' => $this->staff [0] ['category'],
  2175. 'iid' => $iid
  2176. );
  2177. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2178. return "/invoice";
  2179. }
  2180. /**
  2181. * 删除已终止的开票
  2182. */
  2183. function invoiceDelDo() {
  2184. Doo::loadModel ( 'invoice' );
  2185. $invoice = new invoice ();
  2186. Doo::loadModel ( 'invoiceOperationLog' );
  2187. $invoiceOperationLog = new invoiceOperationLog ();
  2188. Doo::loadClass ( 'XDeode' );
  2189. $XDeode = new XDeode ( 5 );
  2190. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2191. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2192. $iid = $XDeode->decode ( $iid );
  2193. Doo::loadModel ( 'invoiceStore' );
  2194. $invoiceStore = new invoiceStore ();
  2195. if (! is_numeric ( $iid ))
  2196. die ( 'illegal request' );
  2197. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2198. if (empty ( $invoiceDetail ))
  2199. die ( 'illegal request' );
  2200. $item = array (
  2201. 'iid' => $iid,
  2202. 'isDelete' => 1,
  2203. 'updateTime' => date ( "Y-m-d H:i:s" )
  2204. );
  2205. $invoice->setInvoiceByCondition ( $item );
  2206. $item = array (
  2207. 'date' => date ( "Y-m-d H:i:s" ),
  2208. 'operation' => '删除了已终止的发票',
  2209. 'status' => 4,
  2210. 'img' => $this->staff [0] ['avatar'],
  2211. 'username' => $this->staff [0] ['username'],
  2212. 'uid' => $this->staff [0] ['sid'],
  2213. 'category' => $this->staff [0] ['category'],
  2214. 'iid' => $iid
  2215. );
  2216. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2217. // 删除培训班发票仓库里的发票
  2218. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2219. return "/invoice";
  2220. }
  2221. /**
  2222. */
  2223. function invoiceApproval() {
  2224. Doo::loadModel ( 'invoice' );
  2225. $invoice = new invoice ();
  2226. Doo::loadClass ( 'XDeode' );
  2227. $XDeode = new XDeode ( 5 );
  2228. Doo::loadModel ( 'staff' );
  2229. $staff = new staff ();
  2230. $invoiceList = $invoice->find ( array (
  2231. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2232. 'desc' => 'iid',
  2233. 'limit' => 10,
  2234. 'asArray' => true
  2235. ) );
  2236. foreach ( $invoiceList as $key => $value ) {
  2237. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2238. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2239. if (! empty ( $lastApprover )) {
  2240. $lastApproverKey = array_keys ( $lastApprover );
  2241. $lastApprover = end ( $lastApprover );
  2242. $staffDetail = $staff->getOne ( array (
  2243. 'where' => 'sid=' . end ( $lastApproverKey ),
  2244. 'asArray' => true
  2245. ) );
  2246. $lastApprover ['username'] = $staffDetail ['username'];
  2247. }
  2248. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2249. }
  2250. $ilist = $invoice->getInvoiceByProcessStatus ();
  2251. foreach ( $ilist as $key => $value ) {
  2252. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2253. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2254. if (! empty ( $lastApprover )) {
  2255. $lastApproverKey = array_keys ( $lastApprover );
  2256. $lastApprover = end ( $lastApprover );
  2257. $staffDetail = $staff->getOne ( array (
  2258. 'where' => 'sid=' . end ( $lastApproverKey ),
  2259. 'asArray' => true
  2260. ) );
  2261. $lastApprover ['username'] = $staffDetail ['username'];
  2262. }
  2263. $ilist [$key] ['lastApprover'] = $lastApprover;
  2264. }
  2265. // print_r($ilist);
  2266. $this->data ['invoiceList'] = $invoiceList;
  2267. $this->data ['ilist'] = $ilist;
  2268. $this->data ['memu'] = "invoice";
  2269. $this->data ['staff'] = $this->staff;
  2270. $this->data ['receiptMemu'] = 'invoiceApproval';
  2271. $this->render ( "/admin/invoiceApproval", $this->data );
  2272. }
  2273. function invoiceDetail() {
  2274. Doo::loadClass ( 'XDeode' );
  2275. $XDeode = new XDeode ( 5 );
  2276. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2277. $iid = $XDeode->decode ( $iid );
  2278. if (! is_numeric ( $iid ))
  2279. die ( 'illegal request' );
  2280. Doo::loadModel ( 'invoice' );
  2281. $invoice = new invoice ();
  2282. Doo::loadModel ( 'invoiceOperationLog' );
  2283. $invoiceOperationLog = new invoiceOperationLog ();
  2284. $invoiceDetail = $invoice->getOne ( array (
  2285. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2286. 'asArray' => true
  2287. ) );
  2288. if (empty ( $invoiceDetail ))
  2289. die ( 'illegal request' );
  2290. if ($invoiceDetail ['settlementType'] == 1) {
  2291. Doo::loadModel ( 'invoiceTraining' );
  2292. $invoiceTraining = new invoiceTraining ();
  2293. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2294. }
  2295. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2296. $this->data ['invoiceDetail'] = $invoiceDetail;
  2297. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2298. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2299. $this->data ['memu'] = "invoice";
  2300. $this->data ['staff'] = $this->staff;
  2301. $this->data ['receiptMemu'] = 'invoiceApproval';
  2302. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2303. }
  2304. /**
  2305. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2306. *
  2307. * @since 1.0.0
  2308. * @var integer iid 开票ID 已加密
  2309. * @var integer status 发票审批状态
  2310. * @var integer opintion 审批发票的意见
  2311. * @return string 如操作成功返回审批首页
  2312. */
  2313. function invoiceApprovalDo() {
  2314. Doo::loadModel ( 'invoice' );
  2315. $invoice = new invoice ();
  2316. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2317. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2318. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2319. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2320. $iid = $invoice->authcode ( $iid );
  2321. if (! is_numeric ( $iid ))
  2322. die ( 'illegal request' );
  2323. // && ! empty ( $opinion )
  2324. if (! empty ( $iid ) && ! empty ( $status )) {
  2325. if (! ($status == 2 || $status == 3 || $status == 4))
  2326. die ( 'illegal request' );
  2327. Doo::loadModel ( 'invoiceOperationLog' );
  2328. $invoiceOperationLog = new invoiceOperationLog ();
  2329. $invoiceDetail = $invoice->getOne ( array (
  2330. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2331. 'asArray' => true
  2332. ) );
  2333. if (empty ( $invoiceDetail ))
  2334. die ( 'illegal request' );
  2335. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2336. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2337. if ($status == 3) {
  2338. $invoice->status = $status;
  2339. $item = array (
  2340. 'operation' => $opinion
  2341. );
  2342. } else {
  2343. if (empty ( $processApprovals )) {
  2344. $processApprovals = array (
  2345. $this->staff [0] ['sid'] => array (
  2346. 'date' => date ( "Y-m-d H:i:s" ),
  2347. 'opinion' => $opinion,
  2348. 'status' => $status
  2349. )
  2350. );
  2351. // var_dump(next($invoiceManage));
  2352. $nextInvoiceManage = next ( $invoiceManage );
  2353. // print_r($nextInvoiceManage);
  2354. if ($status != 4 && $nextInvoiceManage !== false)
  2355. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2356. $invoice->processApprovals = json_encode ( $processApprovals );
  2357. // var_dump($invoice);
  2358. // print_r($invoiceManage);
  2359. } else {
  2360. $processApprovals [$this->staff [0] ['sid']] = array (
  2361. 'date' => date ( "Y-m-d H:i:s" ),
  2362. 'opinion' => $opinion,
  2363. 'status' => $status
  2364. );
  2365. $pendingApprovals = 0;
  2366. foreach ( $invoiceManage as $key => $value ) {
  2367. if ($value [0] == $this->staff [0] ['sid']) {
  2368. if (isset ( $invoiceManage [$key + 1] ))
  2369. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2370. break;
  2371. }
  2372. }
  2373. if ($status != 4 && ! empty ( $pendingApprovals ))
  2374. $invoice->pendingApprovals = $pendingApprovals;
  2375. $invoice->processApprovals = json_encode ( $processApprovals );
  2376. }
  2377. $item = array (
  2378. 'operation' => $opinion
  2379. );
  2380. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2381. $invoice->status = $status;
  2382. $invoice->pendingApprovals = 0;
  2383. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2384. } elseif ($status == 4) {
  2385. $invoice->status = $status;
  2386. $item = array (
  2387. 'operation' => $opinion
  2388. );
  2389. }
  2390. }
  2391. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2392. $invoice->update ( array (
  2393. 'where' => 'iid=' . $iid
  2394. ) );
  2395. $item += array (
  2396. 'date' => date ( "Y-m-d H:i:s" ),
  2397. 'img' => $this->staff [0] ['avatar'],
  2398. 'username' => $this->staff [0] ['username'],
  2399. 'uid' => $this->staff [0] ['sid'],
  2400. 'category' => $this->staff [0] ['category'],
  2401. 'status' => $status,
  2402. 'iid' => $iid
  2403. );
  2404. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2405. if (empty ( $divApproval ))
  2406. return '/invoiceApproval';
  2407. else
  2408. return '/invoiceApprovalAchieve/PEND';
  2409. }
  2410. die ( 'illegal request' );
  2411. }
  2412. /**
  2413. * 展示需要打印的发票数据
  2414. *
  2415. * @since 1.0.0
  2416. */
  2417. function invoicePrint() {
  2418. Doo::loadModel ( 'invoice' );
  2419. $invoice = new invoice ();
  2420. Doo::loadClass ( 'XDeode' );
  2421. $XDeode = new XDeode ( 5 );
  2422. Doo::loadModel ( 'staff' );
  2423. $staff = new staff ();
  2424. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2425. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2426. foreach ( $toPrint as $key => $value ) {
  2427. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2428. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2429. if (! empty ( $lastApprover )) {
  2430. $lastApproverKey = array_keys ( $lastApprover );
  2431. $lastApprover = end ( $lastApprover );
  2432. $staffDetail = $staff->getOne ( array (
  2433. 'where' => 'sid=' . end ( $lastApproverKey ),
  2434. 'asArray' => true
  2435. ) );
  2436. $lastApprover ['username'] = $staffDetail ['username'];
  2437. }
  2438. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2439. }
  2440. foreach ( $printed as $key => $value ) {
  2441. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2442. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2443. if (! empty ( $lastApprover )) {
  2444. $lastApproverKey = array_keys ( $lastApprover );
  2445. $lastApprover = end ( $lastApprover );
  2446. $staffDetail = $staff->getOne ( array (
  2447. 'where' => 'sid=' . end ( $lastApproverKey ),
  2448. 'asArray' => true
  2449. ) );
  2450. $lastApprover ['username'] = $staffDetail ['username'];
  2451. }
  2452. $printed [$key] ['lastApprover'] = $lastApprover;
  2453. }
  2454. $this->data ['printed'] = $printed;
  2455. $this->data ['toPrint'] = $toPrint;
  2456. $this->data ['memu'] = "invoice";
  2457. $this->data ['staff'] = $this->staff;
  2458. $this->data ['receiptMemu'] = 'invoicePrint';
  2459. $this->render ( "/admin/invoicePrint", $this->data );
  2460. }
  2461. /**
  2462. * 展示发票打印的详情页面
  2463. *
  2464. * @since 1.0.0
  2465. */
  2466. function invoicePrintDetail() {
  2467. Doo::loadClass ( 'XDeode' );
  2468. $XDeode = new XDeode ( 5 );
  2469. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2470. $iid = $XDeode->decode ( $iid );
  2471. if (! is_numeric ( $iid ))
  2472. die ( 'illegal request' );
  2473. Doo::loadModel ( 'invoice' );
  2474. $invoice = new invoice ();
  2475. Doo::loadModel ( 'invoiceOperationLog' );
  2476. $invoiceOperationLog = new invoiceOperationLog ();
  2477. Doo::loadModel ( 'invoicePaper' );
  2478. $invoicePaper = new invoicePaper ();
  2479. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2480. if (empty ( $invoiceDetail ))
  2481. die ( 'illegal request' );
  2482. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2483. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2484. if ($invoiceDetail ['settlementType'] == 1) {
  2485. Doo::loadModel ( 'invoiceTraining' );
  2486. $invoiceTraining = new invoiceTraining ();
  2487. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2488. }
  2489. $this->data ['invoicePaperList'] = $invoicePaperList;
  2490. $this->data ['invoiceDetail'] = $invoiceDetail;
  2491. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2492. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2493. $this->data ['memu'] = "invoice";
  2494. $this->data ['staff'] = $this->staff;
  2495. $this->data ['receiptMemu'] = 'invoicePrint';
  2496. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2497. }
  2498. /**
  2499. * 所有待打印 发票
  2500. */
  2501. function invoicePrintStayAchieve() {
  2502. Doo::loadModel ( 'invoice' );
  2503. $invoice = new invoice ();
  2504. Doo::loadClass ( 'XDeode' );
  2505. $XDeode = new XDeode ( 5 );
  2506. Doo::loadModel ( 'staff' );
  2507. $staff = new staff ();
  2508. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2509. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2510. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2511. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2512. Doo::loadModel ( 'invoiceTraining' );
  2513. $invoiceTraining = new invoiceTraining ();
  2514. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2515. $page_size = 12;
  2516. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2517. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2518. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2519. $get = "/" . $status;
  2520. $con = ' and status=2 ';
  2521. if ($status == 'TOPRINT')
  2522. $con = ' and status=2 and printStatus=0 ';
  2523. elseif ($status == 'PRINTED')
  2524. $con = ' and status=2 and printStatus=1';
  2525. if ($invoiceType == 'ORDINARY')
  2526. $con .= ' and invoiceType=0 ';
  2527. elseif ($invoiceType == 'SPECIAL')
  2528. $con .= ' and invoiceType=1 ';
  2529. if ($invoiceTrain == 'ORDINARY')
  2530. $con .= ' and trainId=0 ';
  2531. elseif ($invoiceTrain == 'TRAIN')
  2532. $con .= ' and trainId!=0 ';
  2533. if ($invoiceTrainName != 'ALL') {
  2534. $trainId = $XDeode->decode ( $invoiceTrainName );
  2535. if (is_numeric ( $trainId ))
  2536. $con .= ' and trainId =' . $trainId;
  2537. }
  2538. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2539. $dateArr = explode ( ':', $date );
  2540. $D1 = '';
  2541. $D2 = '';
  2542. if (! empty ( $date )) {
  2543. $D1 = $dateArr [0];
  2544. $D2 = $dateArr [1];
  2545. }
  2546. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2547. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2548. if (! empty ( $MebSea )) {
  2549. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2550. }
  2551. $pageinfo ['page'] = array (
  2552. 'previous' => ''
  2553. );
  2554. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2555. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2556. $action = "invoicePrintStayAchieve";
  2557. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2558. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2559. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2560. $this->data ['trainList'] = $trainList;
  2561. $this->data ['invoiceType'] = $invoiceType;
  2562. $this->data ['invoiceTrain'] = $invoiceTrain;
  2563. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2564. $this->data ['MebSeaEn'] = $MebSea;
  2565. $this->data ['MebSea'] = urlencode ( $MebSea );
  2566. $this->data ['get'] = $get;
  2567. $this->data ['page'] = $pageinfo;
  2568. $this->data ['date'] = $date;
  2569. $this->data ['status'] = $status;
  2570. $this->data ['invoiceType'] = $invoiceType;
  2571. $this->data ['memu'] = "invoice";
  2572. $this->data ['staff'] = $this->staff;
  2573. foreach ( $list as $key => $value ) {
  2574. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2575. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2576. if (! empty ( $lastApprover )) {
  2577. $lastApproverKey = array_keys ( $lastApprover );
  2578. $lastApprover = end ( $lastApprover );
  2579. $staffDetail = $staff->getOne ( array (
  2580. 'where' => 'sid=' . end ( $lastApproverKey ),
  2581. 'asArray' => true
  2582. ) );
  2583. $lastApprover ['username'] = $staffDetail ['username'];
  2584. }
  2585. $list [$key] ['lastApprover'] = $lastApprover;
  2586. }
  2587. $this->data ['receiptMemu'] = 'invoicePrint';
  2588. $this->data ['list'] = $list;
  2589. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2590. }
  2591. /**
  2592. * 填写票号并完成打印
  2593. * @since 1.0.0
  2594. */
  2595. function invoicePrintDo() {
  2596. Doo::loadModel ( 'invoice' );
  2597. $invoice = new invoice ();
  2598. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2599. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2600. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2601. $iid = $invoice->authcode ( $iid );
  2602. if (! is_numeric ( $iid ))
  2603. die ( 'illegal request-iid' );
  2604. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2605. Doo::loadModel ( 'invoiceOperationLog' );
  2606. $invoiceOperationLog = new invoiceOperationLog ();
  2607. Doo::loadModel ( 'invoiceStatistics' );
  2608. $invoiceStatistics = new invoiceStatistics ();
  2609. $XDeode = new XDeode ( 5 );
  2610. Doo::loadModel ( 'invoicePaper' );
  2611. $invoicePaper = new invoicePaper ();
  2612. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2613. if (empty ( $invoicePrintDetail ))
  2614. die ( 'illegal request-data_empty' );
  2615. //
  2616. $ipid = $XDeode->decode ( $invoiceNo );
  2617. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2618. if (empty ( $paperDetail ))
  2619. die ( 'illegal request-paper_empty' );
  2620. $invoicePaper = new invoicePaper ();
  2621. $item = array (
  2622. 'iid' => $iid,
  2623. 'ipid' => $ipid
  2624. );
  2625. $invoicePaper->setInvoicePaperByCondition ( $item );
  2626. $item = array (
  2627. 'iid' => $iid,
  2628. 'printStatus' => 1,
  2629. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2630. 'printer' => $this->staff [0] ['username'],
  2631. 'printTime' => date ( "Y-m-d H:i:s" ),
  2632. 'invoiceNo' => $paperDetail ['invoiceNo']
  2633. );
  2634. $invoice->setInvoiceByCondition ( $item );
  2635. $item = array (
  2636. 'date' => date ( "Y-m-d H:i:s" ),
  2637. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2638. 'status' => 5,
  2639. 'img' => $this->staff [0] ['avatar'],
  2640. 'username' => $this->staff [0] ['username'],
  2641. 'uid' => $this->staff [0] ['sid'],
  2642. 'category' => $this->staff [0] ['category'],
  2643. 'iid' => $iid
  2644. );
  2645. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2646. // 去统计--负票不汇总
  2647. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2648. $item = array (
  2649. 'date' => date ( "Y-m-d H:i:s" ),
  2650. 'priceClass' => 1,
  2651. 'cid' => $invoicePrintDetail ['cid'],
  2652. 'staff' => $invoicePrintDetail ['sid'],
  2653. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2654. );
  2655. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2656. }
  2657. // 发送通知信息到微信-去除
  2658. // $this->setWXMsg($iid,'PRINT');
  2659. // 发票信息库
  2660. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2661. // 申请人获取微信通知
  2662. Doo::loadModel ( 'staff' );
  2663. $staff = new staff ();
  2664. Doo::loadClass ( 'XDeode' );
  2665. $XDeode = new XDeode ( 5 );
  2666. $username2 = $staff->getOne ( array (
  2667. 'select' => 'wxid',
  2668. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2669. 'asArray' => TRUE
  2670. ) );
  2671. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2672. $msg = '';
  2673. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2674. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2675. if (empty ( $invoicePrintType ))
  2676. return "/invoicePrint";
  2677. else
  2678. return "/invoicePrintStayAchieve";
  2679. }
  2680. }
  2681. /**
  2682. * 需要邮寄的发票
  2683. * @since 1.0.0
  2684. */
  2685. function invoicePost() {
  2686. Doo::loadModel ( 'invoice' );
  2687. $invoice = new invoice ();
  2688. Doo::loadModel ( 'express' );
  2689. $express = new express ();
  2690. $invoicePost = $invoice->getPostByInvoice ();
  2691. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2692. $expressList = $express->getExpressByAll ();
  2693. $invoicePostExpress = "";
  2694. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2695. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2696. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2697. $this->data ['expressList'] = $expressList;
  2698. $this->data ['invoicePost'] = $invoicePost;
  2699. $this->data ['invoicePosted'] = $invoicePosted;
  2700. $this->data ['memu'] = "invoice";
  2701. $this->data ['staff'] = $this->staff;
  2702. $this->data ['receiptMemu'] = 'invoicePost';
  2703. $this->render ( "/admin/invoicePost", $this->data );
  2704. }
  2705. /**
  2706. * 添加发票邮寄信息
  2707. */
  2708. function invoiceExpressAddDo() {
  2709. Doo::loadModel ( 'invoice' );
  2710. $invoice = new invoice ();
  2711. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2712. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2713. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2714. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2715. $iid = $iid = $invoice->authcode ( $iid );
  2716. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2717. die ( 'illegal request' );
  2718. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2719. setcookie ( 'invoicePostExpress', $expressNumber );
  2720. $item = array (
  2721. 'iid' => $iid,
  2722. 'postStatus' => 1,
  2723. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2724. 'postTime' => date ( "Y-m-d H:i:s" ),
  2725. 'expressCompany' => $expressCompany,
  2726. 'expressNumber' => $expressNumber,
  2727. 'actualItems' => $actualItems,
  2728. 'poster' => $this->staff [0] ['username']
  2729. );
  2730. $invoice->setInvoiceByCondition ( $item );
  2731. // 微信通知-去掉
  2732. // $this->setWXMsg ( $iid );
  2733. Doo::loadModel ( 'staff' );
  2734. $staff = new staff ();
  2735. Doo::loadClass ( 'XDeode' );
  2736. $XDeode = new XDeode ( 5 );
  2737. $username2 = $staff->getOne ( array (
  2738. 'select' => 'wxid',
  2739. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2740. 'asArray' => TRUE
  2741. ) );
  2742. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2743. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2744. if (empty ( $expCom ))
  2745. $expCom [0] = '';
  2746. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2747. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2748. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2749. return '/invoicePost';
  2750. }
  2751. function invoiceExpressUpdateDo() {
  2752. Doo::loadModel ( 'invoice' );
  2753. $invoice = new invoice ();
  2754. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2755. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2756. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2757. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2758. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2759. $iid = $invoice->authcode ( $iid );
  2760. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2761. die ( 'illegal request' );
  2762. $item = array (
  2763. 'iid' => $iid,
  2764. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2765. 'expressCompany' => $expressCompany,
  2766. 'expressNumber' => $expressNumber,
  2767. 'actualItems' => $actualItems,
  2768. 'poster' => $this->staff [0] ['username']
  2769. );
  2770. $invoice->setInvoiceByCondition ( $item );
  2771. return $action;
  2772. }
  2773. /**
  2774. * 可退票管理
  2775. */
  2776. function invoiceUntreadIsAchieve() {
  2777. Doo::loadModel ( 'invoice' );
  2778. $invoice = new invoice ();
  2779. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2780. /*
  2781. * 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' => '' );
  2782. */
  2783. if (empty ( $MebSea )) {//
  2784. $con = ' and invoiceNo like "NULL" ';
  2785. } else {
  2786. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2787. }
  2788. // printStatus=1 and
  2789. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2790. /*
  2791. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2792. */
  2793. $limit = '0,20';
  2794. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2795. //print_r($list);
  2796. $this->data ['MebSeaEn'] = $MebSea;
  2797. /*
  2798. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2799. */
  2800. $this->data ['list'] = $list;
  2801. $this->data ['memu'] = "invoice";
  2802. $this->data ['staff'] = $this->staff;
  2803. $this->data ['receiptMemu'] = 'invoice';
  2804. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2805. }
  2806. // 已经退票的发票
  2807. function invoiceUntreadED() {
  2808. Doo::loadModel ( 'invoice' );
  2809. $invoice = new invoice ();
  2810. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2811. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2812. Doo::loadClass ( 'XDeode' );
  2813. $XDeode = new XDeode ( 5 );
  2814. $page_size = 18;
  2815. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2816. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2817. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2818. $dateArr = explode ( ':', $date );
  2819. $D1 = '';
  2820. $D2 = '';
  2821. if (! empty ( $date )) {
  2822. $D1 = $dateArr [0];
  2823. $D2 = $dateArr [1];
  2824. }
  2825. $con = '';
  2826. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2827. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2828. }
  2829. // if ($date == 'MONTHO')
  2830. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2831. // elseif ($date == 'MONTHT')
  2832. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2833. // elseif ($date == 'MONTHY')
  2834. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2835. if (! empty ( $MebSea )) {
  2836. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2837. }
  2838. if ($invoiceType == 'ORDINARY') {
  2839. $con .= ' and invoiceType=0 ';
  2840. } elseif ($invoiceType == 'SPECIAL') {
  2841. $con .= ' and invoiceType=1 ';
  2842. }
  2843. $pageinfo ['page'] = array (
  2844. 'previous' => ''
  2845. );
  2846. // printStatus=1 and
  2847. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2848. $action = "invoiceUntreadED";
  2849. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2850. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2851. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2852. // print_r($list);
  2853. $this->data ['MebSeaEn'] = $MebSea;
  2854. $this->data ['get'] = $get;
  2855. $this->data ['page'] = $pageinfo;
  2856. $this->data ['date'] = $date;
  2857. $this->data ['invoiceType'] = $invoiceType;
  2858. $this->data ['list'] = $list;
  2859. $this->data ['memu'] = "invoice";
  2860. $this->data ['staff'] = $this->staff;
  2861. $this->data ['receiptMemu'] = 'invoice';
  2862. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2863. }
  2864. /**
  2865. * 退票处理页面
  2866. */
  2867. function invoiceUntread() {
  2868. Doo::loadModel ( 'invoice' );
  2869. $invoice = new invoice ();
  2870. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2871. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2872. //print_r($establishedInvoice);
  2873. // foreach ( $establishedInvoice as $key => $value ) {
  2874. // // months
  2875. // $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2876. // $nowDate = strtotime ( 'now' );
  2877. // $establishedInvoice [$key] ['lossShow'] = false;
  2878. // if ($lossDate < $nowDate)
  2879. // $establishedInvoice [$key] ['lossShow'] = true;
  2880. // }
  2881. $this->data ['untreadInvoice'] = $untreadInvoice;
  2882. $this->data ['establishedInvoice'] = $establishedInvoice;
  2883. $this->data ['memu'] = "invoice";
  2884. $this->data ['staff'] = $this->staff;
  2885. $this->data ['receiptMemu'] = 'invoiceUntread';
  2886. $this->render ( "/admin/invoiceUntread", $this->data );
  2887. }
  2888. /**
  2889. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2890. */
  2891. function invoiceUntreadEstablishedDo() {
  2892. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2893. Doo::loadModel ( 'invoice' );
  2894. $invoice = new invoice ();
  2895. Doo::loadModel ( 'invoiceOperationLog' );
  2896. $invoiceOperationLog = new invoiceOperationLog ();
  2897. Doo::loadModel ( 'invoiceReceivables' );
  2898. Doo::loadModel ( 'invoiceStatistics' );
  2899. $iid = $invoice->authcode ( $untreadIidKey );
  2900. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2901. die ( 'illegal request' );
  2902. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2903. if ($invoiceDetails ['untreadStatus'] != 1)
  2904. die ( 'illegal request untreadStatus error !=1' );
  2905. $item = array (
  2906. 'iid' => $iid,
  2907. // 'irid'=>'',
  2908. 'untreadStatus' => 2,
  2909. 'untreadTime'=>date ( "Y-m-d H:i:s" ) ,
  2910. 'updateTime' => date ( "Y-m-d H:i:s" )
  2911. );
  2912. $invoice->setInvoiceByCondition ( $item );
  2913. $item = array (
  2914. 'date' => date ( "Y-m-d H:i:s" ),
  2915. 'operation' => '已确认退票',
  2916. 'status' => 6,
  2917. 'img' => $this->staff [0] ['avatar'],
  2918. 'username' => $this->staff [0] ['username'],
  2919. 'uid' => $this->staff [0] ['sid'],
  2920. 'category' => $this->staff [0] ['category'],
  2921. 'iid' => $iid
  2922. );
  2923. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2924. // 收款解绑以及入账扣除 收款扣除
  2925. if (! empty ( $invoiceDetails ['irid'] )) {
  2926. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2927. foreach ( $iridList as $value ) {
  2928. $invoiceReceivables = new invoiceReceivables ();
  2929. $irDetails = $invoiceReceivables->getOne ( array (
  2930. 'where' => " irid=" . $value . ' ',
  2931. 'asArray' => TRUE
  2932. ) );
  2933. $bindPrice=$irDetails['bindPrice']-$invoiceDetails['invoicePrice'];
  2934. if($bindPrice<0){
  2935. $bindPrice=0;
  2936. }
  2937. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  2938. $item = array (
  2939. 'irid' => $value,
  2940. 'bindStatus' => 0,
  2941. 'untreadStatus' => 1,
  2942. 'bindPrice'=>$bindPrice,
  2943. 'untreadStaff' => $invoiceDetails ['userName'],
  2944. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2945. );
  2946. if($irDetails['iid']==$iid){
  2947. $item+=array(
  2948. 'iid' => 0
  2949. );
  2950. }else{
  2951. foreach ($iidExtend as $iek=>$iev){
  2952. if($iev==$iid){
  2953. unset($iidExtend[$iek]);
  2954. break;
  2955. }
  2956. }
  2957. if(empty($iidExtend)){
  2958. $item+=array(
  2959. 'iidExtend' => ''
  2960. );
  2961. }else{
  2962. $iidExtend=implode(",", $iidExtend);
  2963. $item+=array(
  2964. 'iidExtend' => $iidExtend
  2965. );
  2966. }
  2967. }
  2968. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2969. if (! empty ( $irDetails )) {
  2970. // 扣除入账
  2971. $invoiceStatistics = new invoiceStatistics ();
  2972. $item = array (
  2973. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2974. 'priceClass' => 3,
  2975. 'cid' => $invoiceDetails ['cid'],
  2976. 'staff' => $invoiceDetails ['sid'],
  2977. 'accountPrice' => - $irDetails ['receivablesPrice']
  2978. );
  2979. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2980. // 扣除收款
  2981. $invoiceStatistics = new invoiceStatistics ();
  2982. $item = array (
  2983. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2984. 'priceClass' => 2,
  2985. 'cid' => $invoiceDetails ['cid'],
  2986. 'staff' => $invoiceDetails ['sid'],
  2987. 'irid' => $irDetails ['irid'],
  2988. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2989. );
  2990. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2991. }
  2992. // 解绑时删除收入流水--退票不删除流水
  2993. // Doo::loadModel ( 'wasteBook' );
  2994. // $wasteBook = new wasteBook ();
  2995. // $wasteBook->delete ( array (
  2996. // 'where' => 'dataID=' . $value . ' and accountType=7',
  2997. // 'limit' => 1
  2998. // ) );
  2999. }
  3000. }
  3001. return "/invoiceUntread";
  3002. }
  3003. function invoiceUntreadRecallDo() {
  3004. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  3005. Doo::loadModel ( 'invoice' );
  3006. $invoice = new invoice ();
  3007. Doo::loadClass ( 'XDeode' );
  3008. $XDeode = new XDeode ( 5 );
  3009. Doo::loadModel ( 'invoiceOperationLog' );
  3010. $invoiceOperationLog = new invoiceOperationLog ();
  3011. $iid = $XDeode->decode ( $iidKey );
  3012. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  3013. if (empty ( $invoiceDetail )) {
  3014. die ( 'illegal request-DATANULL' );
  3015. }
  3016. $item = array (
  3017. 'iid' => $iid,
  3018. 'untreadStatus' => 0
  3019. );
  3020. $invoice->setInvoiceByCondition ( $item );
  3021. $item = array (
  3022. 'date' => date ( "Y-m-d H:i:s" ),
  3023. 'operation' => '撤回申请退票',
  3024. 'status' => 13,
  3025. 'img' => $this->staff [0] ['avatar'],
  3026. 'username' => $this->staff [0] ['username'],
  3027. 'uid' => $this->staff [0] ['sid'],
  3028. 'category' => $this->staff [0] ['category'],
  3029. 'iid' => $iid
  3030. );
  3031. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3032. return "/invoiceUntread";
  3033. }
  3034. /**
  3035. * 建立负票,关联原来发票
  3036. */
  3037. function invoiceLossDo() {
  3038. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3039. if (! empty ( $iidKey )) {
  3040. Doo::loadClass ( 'XDeode' );
  3041. $XDeode = new XDeode ( 5 );
  3042. Doo::loadModel ( 'invoice' );
  3043. $invoice = new invoice ();
  3044. Doo::loadModel ( 'invoiceOperationLog' );
  3045. $invoiceOperationLog = new invoiceOperationLog ();
  3046. $iidKey = $XDeode->decode ( $iidKey );
  3047. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3048. // 拷贝插入一条发票数据
  3049. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3050. // 更新负票
  3051. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3052. $invoice = new invoice ();
  3053. $item = array (
  3054. 'iid' => $iid,
  3055. 'sid' => $this->staff [0] ['sid'],
  3056. 'userName' => $this->staff [0] ['username'],
  3057. 'cid' => $this->staff [0] ['cid'],
  3058. 'categoryName' => $this->staff [0] ['category'],
  3059. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3060. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3061. 'invoiceSerial' => $invoiceSerial,
  3062. 'invoiceNo' => '',
  3063. 'printStatus' => 0,
  3064. 'untreadStatus' => 4,
  3065. // 关联发票号
  3066. 'lossIid' => $invoiceDetail ['iid']
  3067. );
  3068. $invoice->setInvoiceByCondition ( $item );
  3069. // 更新原发票
  3070. $invoice = new invoice ();
  3071. $item = array (
  3072. 'iid' => $invoiceDetail ['iid'],
  3073. 'lossIid' => $iid
  3074. );
  3075. $invoice->setInvoiceByCondition ( $item );
  3076. // 操作日志
  3077. $item = array (
  3078. 'date' => date ( "Y-m-d H:i:s" ),
  3079. 'operation' => "创建负票" . $invoiceSerial,
  3080. 'status' => 12,
  3081. 'img' => $this->staff [0] ['avatar'],
  3082. 'username' => $this->staff [0] ['username'],
  3083. 'uid' => $this->staff [0] ['sid'],
  3084. 'category' => $this->staff [0] ['category'],
  3085. 'iid' => $iid
  3086. );
  3087. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3088. // print_r($invoiceDetail);
  3089. // echo $iid;die;
  3090. }
  3091. return '/invoiceUntread';
  3092. }
  3093. /**
  3094. * 上传银行到账 收款文件
  3095. */
  3096. function invoiceReceivablesBankUpload() {
  3097. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3098. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3099. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3100. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3101. header ( "HTTP/1.1 500 Internal Server Error" );
  3102. echo "POST exceeded maximum allowed size.";
  3103. exit ( 0 );
  3104. }
  3105. // Settings
  3106. $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)
  3107. $upload_name = "Filedata";
  3108. $file_name = "";
  3109. $nk = time ();
  3110. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3111. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3112. echo "文件无法保存.";
  3113. exit ( 0 );
  3114. }
  3115. echo json_encode ( array (
  3116. 'filename' => $file_name,
  3117. 'id' => $nk
  3118. ) );
  3119. exit ( 0 );
  3120. }
  3121. /**
  3122. * 解析银行到账收款execl并导入库中
  3123. */
  3124. function invoiceReceivablesImport() {
  3125. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3126. if ($path != "") {
  3127. Doo::loadModel ( 'invoiceReceivables' );
  3128. $invoiceReceivables = new invoiceReceivables ();
  3129. Doo::loadClass ( 'invoice.func' );
  3130. Doo::loadModel ( 'invoiceROLog' );
  3131. $invoiceROLog = new invoiceROLog ();
  3132. Doo::loadModel ( 'invoiceStatistics' );
  3133. $invoiceStatistics = new invoiceStatistics ();
  3134. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3135. $bankBatchNumber = 'BBN_' . time ();
  3136. Doo::db ()->beginTransaction ();
  3137. // 批量存储收款--由于必须获得收款ID,
  3138. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3139. VALUES ';
  3140. $date = date ( "Y-m-d" );
  3141. $receivablesList = array ();
  3142. foreach ( $exlArray as $key => $value ) {
  3143. $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"] . '")';
  3144. array_push ( $receivablesList, $receivablesSql );
  3145. }
  3146. $sql = $sql . implode ( ',', $receivablesList );
  3147. // echo $sql;
  3148. Doo::db ()->query ( $sql );
  3149. // 批量存储收款统计
  3150. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3151. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3152. // 没有irid 回滚所有操作
  3153. if (empty ( $iridList )) {
  3154. Doo::db ()->rollBack ();
  3155. header ( 'Content-Type:text/html;charset=utf-8' );
  3156. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3157. }
  3158. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3159. VALUES ';
  3160. $statisticsList = array ();
  3161. foreach ( $iridList as $value ) {
  3162. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3163. array_push ( $statisticsList, $statisticsSql );
  3164. }
  3165. $sql = $sql . implode ( ',', $statisticsList );
  3166. Doo::db ()->query ( $sql );
  3167. // 批量存储操作日志
  3168. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3169. VALUES ';
  3170. $ROLogList = array ();
  3171. foreach ( $iridList as $value ) {
  3172. $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'] . '")';
  3173. array_push ( $ROLogList, $ROLogSql );
  3174. }
  3175. $sql = $sql . implode ( ',', $ROLogList );
  3176. Doo::db ()->query ( $sql );
  3177. // 批量写入流水
  3178. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3179. VALUES ';
  3180. $wasteBookList = array ();
  3181. foreach ( $iridList as $value ) {
  3182. $accountBank = '';
  3183. if ($value ['receivablesBank'] == '纵横广发') {
  3184. $accountBank = 'CGBDeposit';
  3185. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3186. $accountBank = 'ICBCDeposit';
  3187. } elseif ($value ['receivablesBank'] == '华润银行') {
  3188. $accountBank = 'HUADeposit';
  3189. } elseif ($value ['receivablesBank'] == '个人广发') {
  3190. $accountBank = 'PersonalDeposit';
  3191. }
  3192. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3193. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3194. array_push ( $wasteBookList, $wasteBookSql );
  3195. }
  3196. $sql = $sql . implode ( ',', $wasteBookList );
  3197. Doo::db ()->query ( $sql );
  3198. Doo::db ()->commit ();
  3199. return "/invoiceReceivables";
  3200. }
  3201. echo 'no file';
  3202. }
  3203. function invoiceReceivables() {
  3204. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3205. Doo::loadModel ( 'L_category' );
  3206. $lCategory = new L_category ();
  3207. Doo::loadModel ( 'staff' );
  3208. $staff = new staff ();
  3209. Doo::loadModel ( 'invoiceReceivables' );
  3210. $invoiceReceivables = new invoiceReceivables ();
  3211. Doo::loadModel ( 'invoice' );
  3212. $invoice = new invoice ();
  3213. Doo::loadClass ( 'XDeode' );
  3214. $XDeode = new XDeode ( 5 );
  3215. $category = $lCategory->getCategory ();
  3216. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3217. $sql = 'bindStatus=1 and iid!=0';
  3218. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3219. // 获取未入账发票
  3220. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3221. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3222. foreach ( $invoiceUnAccount as $key => $value ) {
  3223. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3224. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3225. if (! empty ( $lastApprover )) {
  3226. $lastApproverKey = array_keys ( $lastApprover );
  3227. $lastApprover = end ( $lastApprover );
  3228. $staffDetail = $staff->getOne ( array (
  3229. 'where' => 'sid=' . end ( $lastApproverKey ),
  3230. 'asArray' => true
  3231. ) );
  3232. $lastApprover ['username'] = $staffDetail ['username'];
  3233. }
  3234. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3235. }
  3236. foreach ( $invoiceExistAccount as $key => $value ) {
  3237. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3238. // if (empty ( $irList ))
  3239. // $irList [0] ['sumPrice'] = 0;
  3240. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3241. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3242. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3243. }
  3244. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3245. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3246. $this->data ['halfList'] = $halfList;
  3247. $this->data ['halfCount'] = count ( $halfList );
  3248. // print_r($receivablesList);
  3249. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3250. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3251. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3252. $this->data ['receivablesInput'] = $receivablesInput;
  3253. $this->data ['year'] = date ( 'Y' );
  3254. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3255. $this->data ['receivablesList'] = $receivablesList;
  3256. $this->data ['staffList'] = $staffList;
  3257. $this->data ['category'] = $category;
  3258. $this->data ['memu'] = "invoice";
  3259. $this->data ['staff'] = $this->staff;
  3260. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3261. $this->render ( "/admin/invoiceReceivables", $this->data );
  3262. }
  3263. /**
  3264. * 设置收款认领地区
  3265. */
  3266. function setInvoiceReceivablesClaim() {
  3267. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3268. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3269. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3270. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3271. Doo::loadModel ( 'invoiceReceivables' );
  3272. $invoiceReceivables = new invoiceReceivables ();
  3273. Doo::loadClass ( 'XDeode' );
  3274. $XDeode = new XDeode ( 5 );
  3275. Doo::loadModel ( 'invoiceROLog' );
  3276. $invoiceROLog = new invoiceROLog ();
  3277. $irid = $XDeode->decode ( $iridKey );
  3278. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3279. if (empty ( $irDetail ))
  3280. die ( 'illegal request' );
  3281. $item = array (
  3282. 'irid' => $irid,
  3283. 'receivablesCategory' => $receivablesCategory
  3284. );
  3285. if ($receivablesCategory != 'PUBLIC') {
  3286. $item += array (
  3287. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3288. 'inputType' => 1
  3289. );
  3290. }
  3291. $invoiceReceivables = new invoiceReceivables ();
  3292. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3293. // 收款操作日志
  3294. $item = array (
  3295. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3296. 'date' => date ( "Y-m-d" ),
  3297. 'status' => 1,
  3298. 'img' => $this->staff [0] ['avatar'],
  3299. 'username' => $this->staff [0] ['username'],
  3300. 'uid' => $this->staff [0] ['sid'],
  3301. 'category' => $this->staff [0] ['category'],
  3302. 'irid' => $irid
  3303. );
  3304. $invoiceROLog->setInvoiceROLog ( $item );
  3305. if (empty ( $action ))
  3306. return '/invoiceReceivables';
  3307. else
  3308. return "/invoiceReceivablesAS";
  3309. }
  3310. die ( 'illegal request' );
  3311. }
  3312. /**
  3313. * 新添加收款直接入账发票
  3314. */
  3315. function invoiceCompareClaimPrice() {
  3316. // 收款录入
  3317. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3318. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3319. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3320. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3321. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3322. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3323. Doo::loadModel ( 'invoiceReceivables' );
  3324. $invoiceReceivables = new invoiceReceivables ();
  3325. Doo::loadModel ( 'invoiceROLog' );
  3326. $invoiceROLog = new invoiceROLog ();
  3327. Doo::loadModel ( 'invoiceStatistics' );
  3328. Doo::loadModel ( 'invoice' );
  3329. $invoice = new invoice ();
  3330. Doo::loadModel ( 'bill' );
  3331. $bill = new bill ();
  3332. Doo::loadClass ( 'XDeode' );
  3333. $XDeode = new XDeode ( 5 );
  3334. Doo::loadModel ( 'invoiceOperationLog' );
  3335. $invoiceOperationLog = new invoiceOperationLog ();
  3336. $iidKey = $XDeode->decode ( $iidKey );
  3337. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3338. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3339. die ( 'illegal request' );
  3340. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3341. // 收款录入 并绑定发票
  3342. Doo::db ()->beginTransaction ();
  3343. //获得发票入账余额
  3344. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3345. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3346. $bindStatus = 0;
  3347. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3348. if($invoiceDetail ['invoiceBalance']!=0){
  3349. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3350. }
  3351. if ($receivablesPrice <= $invoiceBalance){
  3352. $bindStatus = 1;
  3353. //$bindPrice=$receivablesPrice;
  3354. }
  3355. $titleMark = $invoiceDetail ['invoiceTitle'];
  3356. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3357. $titleMark = $invoiceDetail ['invoiceCompany'];
  3358. $item = array (
  3359. 'recepitTitleMark' => $titleMark,
  3360. 'bindStatus' => $bindStatus,
  3361. 'iid' => $invoiceDetail ['iid'],
  3362. 'bindPrice' => $receivablesPrice,
  3363. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3364. 'receivablesPrice' => $receivablesPrice,
  3365. 'OriginalPrice' => $receivablesPrice,
  3366. 'receivablesMessage' => $receivablesMessage,
  3367. 'receivablesSerial' => $receivablesSerial,
  3368. 'receivablesBank' => $receivablesBank,
  3369. 'receivablesDate' => $receivablesDate,
  3370. 'inputStaff' => $this->staff [0] ['username'],
  3371. 'accountClerk' => $this->staff [0] ['username'],
  3372. 'date' => date ( "Y-m-d" ),
  3373. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3374. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3375. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3376. );
  3377. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3378. $item = array ();
  3379. // 收款操作日志
  3380. $item = array (
  3381. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3382. );
  3383. $item += array (
  3384. 'date' => date ( "Y-m-d" ),
  3385. 'status' => 1,
  3386. 'img' => $this->staff [0] ['avatar'],
  3387. 'username' => $this->staff [0] ['username'],
  3388. 'uid' => $this->staff [0] ['sid'],
  3389. 'category' => $this->staff [0] ['category'],
  3390. 'irid' => $irid
  3391. );
  3392. $invoiceROLog->setInvoiceROLog ( $item );
  3393. // 收款统计
  3394. $invoiceStatistics = new invoiceStatistics ();
  3395. $item = array (
  3396. 'date' => $receivablesDate,
  3397. 'priceClass' => 2,
  3398. 'irid' => $irid,
  3399. 'cid' => $invoiceDetail ['cid'],
  3400. 'staff' => $invoiceDetail ['sid'],
  3401. 'receivablesPrice' => $receivablesPrice
  3402. );
  3403. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3404. // 收款 入 发票
  3405. $detail = $invoiceDetail;
  3406. $iridString = "";
  3407. if (empty ( $detail ['irid'] ))
  3408. $iridString = $irid;
  3409. else
  3410. $iridString = $detail ['irid'] . ',' . $irid;
  3411. $item = array (
  3412. 'irid' => $iridString,
  3413. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3414. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3415. 'iid' => $detail ['iid']
  3416. );
  3417. // $invoiceReceivables = new invoiceReceivables ();
  3418. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3419. // $sumBind = $bindInvicePrice;
  3420. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3421. // $sum=$sumBind+$sumBalance;
  3422. // ;
  3423. if ($receivablesPrice>=$invoiceBalance){
  3424. $item += array (
  3425. 'invoiceBalance'=>0,
  3426. 'untreadStatus' => 3
  3427. );
  3428. }else{
  3429. $item += array (
  3430. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3431. );
  3432. }
  3433. $invoice->setInvoiceByCondition ( $item );
  3434. // 操作日志
  3435. $item = array (
  3436. 'date' => date ( "Y-m-d H:i:s" ),
  3437. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3438. 'status' => 8,
  3439. 'img' => $this->staff [0] ['avatar'],
  3440. 'username' => $this->staff [0] ['username'],
  3441. 'uid' => $this->staff [0] ['sid'],
  3442. 'category' => $this->staff [0] ['category'],
  3443. 'iid' => $detail ['iid']
  3444. );
  3445. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3446. // 入账汇总
  3447. $invoiceStatistics = new invoiceStatistics ();
  3448. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3449. // $accountPrice = 0;
  3450. // foreach ( $list as $key => $value ) {
  3451. // $accountPrice += $value ['receivablesPrice'];
  3452. // }
  3453. $item = array (
  3454. 'date' => $receivablesDate,
  3455. 'priceClass' => 3,
  3456. 'cid' => $invoiceDetail ['cid'],
  3457. 'staff' => $invoiceDetail ['sid'],
  3458. 'accountPrice' => $receivablesPrice
  3459. );
  3460. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3461. //发票入账记录
  3462. $bill->iid=$invoiceDetail['iid'];
  3463. $bill->trainId=$invoiceDetail['trainId'];
  3464. $bill->irid=$irid;
  3465. $bill->create_time=date ( "Y-m-d H:i:s" );
  3466. $bill->price=$receivablesPrice;
  3467. $bill->insert ();
  3468. // 公司流水记录
  3469. Doo::loadModel ( 'wasteBook' );
  3470. $wasteBook = new wasteBook ();
  3471. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3472. $accountBank = '';
  3473. if ($receivablesBank == '纵横广发') {
  3474. $accountBank = 'CGBDeposit';
  3475. } elseif ($receivablesBank == '纵横工行') {
  3476. $accountBank = 'ICBCDeposit';
  3477. } elseif ($receivablesBank == '华润银行') {
  3478. $accountBank = 'HUADeposit';
  3479. } elseif ($receivablesBank == '个人广发') {
  3480. $accountBank = 'PersonalDeposit';
  3481. }
  3482. if (empty ( $abDetail )) {
  3483. $item = array (
  3484. 'dataID' => $irid,
  3485. 'expensesType' => 1,
  3486. 'accountType' => 7,
  3487. 'accountPrice' => $receivablesPrice,
  3488. 'accountPriceShow' => $receivablesPrice,
  3489. 'accountBank' => $accountBank,
  3490. 'category' => $this->staff [0] ['category'],
  3491. 'cid' => $this->staff [0] ['cid'],
  3492. 'name' => $this->staff [0] ['username'],
  3493. 'sid' => $this->staff [0] ['sid'],
  3494. 'inputDate' => date ( "Y-m-d H:i:s" )
  3495. );
  3496. $wasteBook->setAccountBookStatistics ( $item );
  3497. }
  3498. Doo::db ()->commit ();
  3499. }
  3500. return '/invoiceReceivables';
  3501. }
  3502. /**
  3503. * 录入收款数据
  3504. * @return string
  3505. */
  3506. function invoiceReceivablesDo() {
  3507. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3508. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3509. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3510. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3511. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3512. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3513. Doo::loadModel ( 'invoiceReceivables' );
  3514. $invoiceReceivables = new invoiceReceivables ();
  3515. Doo::loadModel ( 'invoiceROLog' );
  3516. $invoiceROLog = new invoiceROLog ();
  3517. Doo::loadModel ( 'invoiceStatistics' );
  3518. $invoiceStatistics = new invoiceStatistics ();
  3519. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3520. $item = array (
  3521. 'receivablesPrice' => $receivablesPrice,
  3522. 'OriginalPrice' => $receivablesPrice,
  3523. 'receivablesMessage' => $receivablesMessage,
  3524. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3525. 'receivablesBank' => $receivablesBank,
  3526. 'receivablesDate' => $receivablesDate,
  3527. 'inputStaff' => $this->staff [0] ['username'],
  3528. 'date' => date ( "Y-m-d" ),
  3529. 'receivablesCategory' => $receivablesCategory,
  3530. 'receivablesStaff' => $receivablesStaff
  3531. );
  3532. if ($receivablesCategory != 'PUBLIC') {
  3533. $item += array (
  3534. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3535. 'inputType' => 1
  3536. );
  3537. }
  3538. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3539. $item = array ();
  3540. // 收款操作日志
  3541. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3542. $item = array (
  3543. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3544. );
  3545. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3546. $item = array (
  3547. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3548. );
  3549. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3550. $receivablesStaff = explode ( '-', $receivablesStaff );
  3551. $item = array (
  3552. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3553. );
  3554. }
  3555. $item += array (
  3556. 'date' => date ( "Y-m-d" ),
  3557. 'status' => 1,
  3558. 'img' => $this->staff [0] ['avatar'],
  3559. 'username' => $this->staff [0] ['username'],
  3560. 'uid' => $this->staff [0] ['sid'],
  3561. 'category' => $this->staff [0] ['category'],
  3562. 'irid' => $irid
  3563. );
  3564. $invoiceROLog->setInvoiceROLog ( $item );
  3565. $item = array (
  3566. 'date' => $receivablesDate,
  3567. 'priceClass' => 2,
  3568. 'irid' => $irid,
  3569. 'receivablesPrice' => $receivablesPrice
  3570. );
  3571. if ($receivablesCategory != 'PUBLIC') {
  3572. $receivablesCategory = explode ( ":", $receivablesCategory );
  3573. $item += array (
  3574. 'cid' => $receivablesCategory [0]
  3575. );
  3576. }
  3577. if ($receivablesStaff2 != 'PUBLIC') {
  3578. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3579. $item += array (
  3580. 'staff' => $receivablesStaff [0]
  3581. );
  3582. }
  3583. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3584. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3585. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3586. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3587. if ($toparty != 0)
  3588. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3589. // 公司流水记录
  3590. Doo::loadModel ( 'wasteBook' );
  3591. $wasteBook = new wasteBook ();
  3592. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3593. $accountBank = '';
  3594. if ($receivablesBank == '纵横广发') {
  3595. $accountBank = 'CGBDeposit';
  3596. } elseif ($receivablesBank == '纵横工行') {
  3597. $accountBank = 'ICBCDeposit';
  3598. } elseif ($receivablesBank == '华润银行') {
  3599. $accountBank = 'HUADeposit';
  3600. } elseif ($receivablesBank == '个人广发') {
  3601. $accountBank = 'PersonalDeposit';
  3602. }
  3603. $item = array (
  3604. 'dataID' => $irid,
  3605. 'expensesType' => 1,
  3606. 'accountType' => 7,
  3607. 'accountPriceShow' => $receivablesPrice,
  3608. 'accountPrice' => $receivablesPrice,
  3609. 'accountBank' => $accountBank,
  3610. 'category' => $this->staff [0] ['category'],
  3611. 'cid' => $this->staff [0] ['cid'],
  3612. 'name' => $this->staff [0] ['username'],
  3613. 'sid' => $this->staff [0] ['sid'],
  3614. 'inputDate' => $receivablesDate ,
  3615. //'createAt'=>date ( "Y-m-d H:i:s" ) ,
  3616. 'synPaymentDate'=>1
  3617. );
  3618. $wasteBook->setAccountBookStatistics ( $item );
  3619. }
  3620. return "/invoiceReceivables";
  3621. }
  3622. /**
  3623. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3624. */
  3625. function invoiceReceivablesClaim() {
  3626. Doo::loadModel ( 'invoiceReceivables' );
  3627. $invoiceReceivables = new invoiceReceivables ();
  3628. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3629. $this->data ['receivablesList'] = $receivablesList;
  3630. $this->data ['memu'] = "invoice";
  3631. $this->data ['staff'] = $this->staff;
  3632. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3633. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3634. }
  3635. function invoiceReceivablesTitleMarkSet() {
  3636. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3637. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3638. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3639. die ( 'illegal request' );
  3640. Doo::loadModel ( 'invoiceReceivables' );
  3641. $invoiceReceivables = new invoiceReceivables ();
  3642. Doo::loadClass ( 'XDeode' );
  3643. $XDeode = new XDeode ( 5 );
  3644. $irid = $XDeode->decode ( $iridKey );
  3645. if (! is_numeric ( $irid ))
  3646. die ( 'illegal request' );
  3647. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3648. $invoiceReceivables->update ( array (
  3649. 'where' => 'irid = ' . $irid
  3650. ) );
  3651. return '/invoiceReceivablesClaim';
  3652. }
  3653. /**
  3654. * 更新收款相关数据
  3655. */
  3656. function invoiceReceivablesUpdateClaim() {
  3657. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3658. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3659. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3660. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3661. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3662. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3663. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3664. if (empty ( $claimKey ))
  3665. die ( 'illegal request' );
  3666. Doo::loadModel ( 'invoiceReceivables' );
  3667. $invoiceReceivables = new invoiceReceivables ();
  3668. Doo::loadModel ( 'invoiceROLog' );
  3669. $invoiceROLog = new invoiceROLog ();
  3670. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3671. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3672. if (empty ( $detail ))
  3673. die ( 'illegal request' );
  3674. $invoiceReceivables = new invoiceReceivables ();
  3675. $item = array (
  3676. 'irid' => $detail ['irid']
  3677. );
  3678. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3679. $item += array (
  3680. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3681. );
  3682. }
  3683. if (! empty ( $receivablesCategory ))
  3684. $item += array (
  3685. 'receivablesCategory' => $receivablesCategory
  3686. );
  3687. if (! empty ( $receivablesStaff ))
  3688. $item += array (
  3689. 'receivablesStaff' => $receivablesStaff
  3690. );
  3691. if (! empty ( $receivablesPrice ))
  3692. $item += array (
  3693. 'receivablesPrice' => $receivablesPrice
  3694. );
  3695. if (! empty ( $receivablesMessage ))
  3696. $item += array (
  3697. 'receivablesMessage' => $receivablesMessage
  3698. );
  3699. if (! empty ( $receivablesBank ))
  3700. $item += array (
  3701. 'receivablesBank' => $receivablesBank
  3702. );
  3703. if (! empty ( $receivablesDate ))
  3704. $item += array (
  3705. 'receivablesDate' => $receivablesDate
  3706. );
  3707. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3708. // 收款操作日志
  3709. $item = array ();
  3710. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3711. $item = array (
  3712. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3713. );
  3714. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3715. $item = array (
  3716. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3717. );
  3718. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3719. $receivablesStaff = explode ( '-', $receivablesStaff );
  3720. $item = array (
  3721. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3722. );
  3723. }
  3724. $item += array (
  3725. 'date' => date ( "Y-m-d" ),
  3726. 'status' => 1,
  3727. 'img' => $this->staff [0] ['avatar'],
  3728. 'username' => $this->staff [0] ['username'],
  3729. 'uid' => $this->staff [0] ['sid'],
  3730. 'category' => $this->staff [0] ['category'],
  3731. 'irid' => $detail ['irid']
  3732. );
  3733. $invoiceROLog->setInvoiceROLog ( $item );
  3734. return '/invoiceReceivablesAS';
  3735. }
  3736. function invoiceReceivablesDelete() {
  3737. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3738. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3739. if ($skll != '删除到款')
  3740. die ( 'illegal request' );
  3741. if (empty ( $claimKey ))
  3742. die ( 'illegal request' );
  3743. Doo::loadModel ( 'invoiceReceivables' );
  3744. $invoiceReceivables = new invoiceReceivables ();
  3745. $con = ' and bindStatus=0 ';
  3746. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3747. if (empty ( $detail ))
  3748. die ( 'illegal request' );
  3749. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3750. // 扣除收款汇总信息 汇总
  3751. Doo::loadModel ( 'invoiceStatistics' );
  3752. $invoiceStatistics = new invoiceStatistics ();
  3753. $item = array (
  3754. 'date' => $detail ['receivablesDate'],
  3755. 'priceClass' => 2,
  3756. 'irid' => $detail ['irid'],
  3757. 'receivablesPrice' => - $detail ['receivablesPrice']
  3758. );
  3759. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3760. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3761. $item += array (
  3762. 'cid' => $receivablesCategory [0]
  3763. );
  3764. }
  3765. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3766. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3767. $item += array (
  3768. 'staff' => $receivablesStaff [0]
  3769. );
  3770. }
  3771. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3772. // 公司流水-删除时删除流水
  3773. Doo::loadModel ( 'wasteBook' );
  3774. $wasteBook = new wasteBook ();
  3775. $wasteBook->delete ( array (
  3776. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3777. 'limit' => 1
  3778. ) );
  3779. return '/invoiceReceivablesAS';
  3780. }
  3781. /**
  3782. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3783. */
  3784. function invoiceReceivablesAscription() {
  3785. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3786. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3787. Doo::loadModel ( 'invoiceReceivables' );
  3788. $invoiceReceivables = new invoiceReceivables ();
  3789. Doo::loadModel ( 'invoiceROLog' );
  3790. $invoiceROLog = new invoiceROLog ();
  3791. Doo::loadModel ( 'invoiceStatistics' );
  3792. $invoiceStatistics = new invoiceStatistics ();
  3793. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3794. $irid = $invoiceReceivables->authcode ( $irid );
  3795. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3796. $item = array (
  3797. 'irid' => $detail ['irid'],
  3798. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3799. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3800. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3801. 'recepitTitleMark' => $recepitTitleMark,
  3802. 'source' => 1
  3803. );
  3804. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3805. $item = array (
  3806. 'date' => date ( "Y-m-d" ),
  3807. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3808. 'status' => 2,
  3809. 'img' => $this->staff [0] ['avatar'],
  3810. 'username' => $this->staff [0] ['username'],
  3811. 'uid' => $this->staff [0] ['sid'],
  3812. 'category' => $this->staff [0] ['category'],
  3813. 'irid' => $irid
  3814. );
  3815. $invoiceROLog->setInvoiceROLog ( $item );
  3816. $item = array (
  3817. 'cid' => $this->staff [0] ['cid'],
  3818. 'staff' => $this->staff [0] ['sid']
  3819. );
  3820. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3821. }
  3822. return "/invoiceReceivablesClaim";
  3823. }
  3824. /**
  3825. */
  3826. function invoiceMyReceivables() {
  3827. Doo::loadModel ( 'invoiceReceivables' );
  3828. $invoiceReceivables = new invoiceReceivables ();
  3829. Doo::loadModel ( 'invoiceStatistics' );
  3830. $invoiceStatistics = new invoiceStatistics ();
  3831. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3832. $year = date ( "Y" );
  3833. $tmp_date = date ( "Ym" );
  3834. $tmp_year = substr ( $tmp_date, 0, 4 );
  3835. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3836. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3837. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3838. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3839. $htm = $this->showCache ( $path );
  3840. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3841. $this->data ['isMonth'] = $isMonth;
  3842. $this->data ['htm'] = $htm;
  3843. $this->data ['list'] = $list;
  3844. $this->data ['memu'] = "invoice";
  3845. $this->data ['staff'] = $this->staff;
  3846. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3847. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3848. }
  3849. /**
  3850. * 纸票管理
  3851. */
  3852. function invoicePaper() {
  3853. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3854. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3855. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3856. $this->data ['dateString'] = $date;
  3857. $this->data ['status'] = $status;
  3858. $this->data ['invoiceType'] = $invoiceType;
  3859. $this->data ['memu'] = "invoice";
  3860. $this->data ['staff'] = $this->staff;
  3861. $this->data ['receiptMemu'] = 'invoicePaper';
  3862. $this->render ( "/admin/invoicePaper", $this->data );
  3863. }
  3864. /**
  3865. * 电子发票管理
  3866. */
  3867. function invoiceElectronic() {
  3868. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3869. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3870. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3871. $this->data ['dateString'] = $date;
  3872. $this->data ['status'] = $status;
  3873. $this->data ['invoiceType'] = $invoiceType;
  3874. $this->data ['memu'] = "invoice";
  3875. $this->data ['staff'] = $this->staff;
  3876. $this->data ['receiptMemu'] = 'invoicePaper';
  3877. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3878. }
  3879. /**
  3880. * 获得纸票分页数据
  3881. */
  3882. function ajaxGetinvoicePaperAchieve() {
  3883. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3884. Doo::loadModel ( 'invoicePaper' );
  3885. $invoicePaper = new invoicePaper ();
  3886. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3887. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3888. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3889. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3890. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3891. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3892. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3893. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3894. $MebSea = $this->get_args ( 'search' );
  3895. $MebSea = $MebSea ['value'];
  3896. $page_size = $length;
  3897. $con = '';
  3898. if ($status == 'ALL')
  3899. $con = ' where 1 ';
  3900. elseif ($status == 'PRINTED')
  3901. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3902. elseif ($status == 'UNPRINT')
  3903. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3904. elseif ($status == 'TICKET')
  3905. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3906. if ($invoiceType == 'ORDINARY')
  3907. $con .= ' and a.invoiceType=0 ';
  3908. elseif ($invoiceType == 'SPECIAL')
  3909. $con .= ' and a.invoiceType=1 ';
  3910. if($invoiceForm==0){
  3911. $con .= ' and a.invoiceForm=0 ';
  3912. }else{
  3913. $con .= ' and a.invoiceForm=1 ';
  3914. }
  3915. $dateArr = explode ( ':', $date );
  3916. $D1 = $dateString = '';
  3917. $D2 = '';
  3918. if (! empty ( $date )) {
  3919. $D1 = $dateArr [0];
  3920. if (isset ( $dateArr [1] ))
  3921. $D2 = $dateArr [1];
  3922. else
  3923. $D2 = '';
  3924. $dateString = $D1 . " : " . $D2;
  3925. }
  3926. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3927. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3928. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3929. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3930. if (! empty ( $MebSea ))
  3931. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3932. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3933. $sql = ' ' . $con;
  3934. $limit = $page . ',' . $page_size;
  3935. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3936. $paperList = array ();
  3937. foreach ( $list as $key => $value ) {
  3938. $irDetail = array ();
  3939. if ($value ['iid'] == 0)
  3940. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3941. else
  3942. array_push ( $irDetail, '' );
  3943. array_push ( $irDetail, $value ['invoiceCode'] );
  3944. array_push ( $irDetail, $value ['invoiceNo'] );
  3945. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3946. if ($value ['invoiceType'] == 1)
  3947. array_push ( $irDetail, $value ['invoiceCompany'] );
  3948. else
  3949. array_push ( $irDetail, $value ['invoiceTitle'] );
  3950. if ($value ['invoiceType'] == 1)
  3951. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3952. else
  3953. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3954. array_push ( $irDetail, $value ['invoiceElement'] );
  3955. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3956. array_push ( $irDetail, $value ['printTime'] );
  3957. array_push ( $paperList, $irDetail );
  3958. }
  3959. // $approvalListJson = json_encode ( $approvalList );
  3960. $recordsFiltered = $invoiceTotal;
  3961. echo json_encode ( array (
  3962. "draw" => intval ( $draw ),
  3963. "recordsTotal" => intval ( $invoiceTotal ),
  3964. "recordsFiltered" => intval ( $recordsFiltered ),
  3965. "data" => $paperList
  3966. ), JSON_UNESCAPED_UNICODE );
  3967. }
  3968. function invoicePaperDel() {
  3969. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3970. $XDeode = new XDeode ( 5 );
  3971. $ipid = $XDeode->decode ( $ipidKey );
  3972. if (empty ( $ipid ))
  3973. die ( 'illegal request' );
  3974. Doo::loadModel ( 'invoicePaper' );
  3975. $invoicePaper = new invoicePaper ();
  3976. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3977. $invoicePaper->delete ( array (
  3978. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3979. 'limit' => 1
  3980. ) );
  3981. if($ipdetail['invoiceForm']==1){
  3982. return '/invoiceElectronic';
  3983. }else{
  3984. return '/invoicePaper';
  3985. }
  3986. }
  3987. /**
  3988. * 添加纸质发票号
  3989. */
  3990. function invoicePaperAdd() {
  3991. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3992. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3993. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3994. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3995. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  3996. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3997. $sum = $invoiceNoStart + $invoiceNoTotal;
  3998. if (empty ( $sum ))
  3999. die ( 'illegal request' );
  4000. // echo $invoiceNoStart;
  4001. // echo $sum;
  4002. // echo strlen((int)$invoiceNoStart);
  4003. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  4004. if($invoiceType==0||$invoiceType==1){
  4005. }else{
  4006. die ( 'illegal request invoiceType' );
  4007. }
  4008. if($invoiceForm==1){
  4009. $invoiceType=0;
  4010. }
  4011. Doo::db ()->beginTransaction ();
  4012. // 批量存储纸质发票
  4013. $date = date ( "Y-m-d H:i:s" );
  4014. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  4015. VALUES ';
  4016. $paperList = array ();
  4017. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  4018. // 数字前面自加0
  4019. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  4020. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  4021. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  4022. array_push ( $paperList, $paperSql );
  4023. }
  4024. if (empty ( $paperList ))
  4025. die ( 'illegal request' );
  4026. $sql = $sql . implode ( ',', $paperList );
  4027. Doo::db ()->query ( $sql );
  4028. Doo::db ()->commit ();
  4029. if($invoiceForm==1){
  4030. return 'invoiceElectronic';
  4031. }else{
  4032. return 'invoicePaper';
  4033. }
  4034. }
  4035. die ( 'illegal request' );
  4036. }
  4037. /**
  4038. * 收款绑定发票 ,//一个收款只能绑定一个发票
  4039. */
  4040. function invoiceBindReceivables() {
  4041. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4042. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4043. Doo::loadModel ( 'invoice' );
  4044. $invoice = new invoice ();
  4045. Doo::loadModel ( 'invoiceReceivables' );
  4046. $invoiceReceivables = new invoiceReceivables ();
  4047. Doo::loadModel ( 'invoiceOperationLog' );
  4048. $invoiceOperationLog = new invoiceOperationLog ();
  4049. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4050. die ( 'illegal request' );
  4051. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4052. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4053. if (empty ( $detail ) && empty ( $detailM ))
  4054. die ( 'illegal request' );
  4055. if ($detail ['untreadStatus'] == 3)
  4056. die ( 'illegal request' );
  4057. // 修改 绑定状态改为 金额
  4058. $invoiceReceivables = new invoiceReceivables ();
  4059. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4060. $billPrice=0;
  4061. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4062. $item = array (
  4063. 'bindPrice' => $invoicePrice
  4064. );
  4065. $billPrice=$invoicePrice;
  4066. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) { //发票金额大于收款金额,绑定金额为收款金额
  4067. $item = array (
  4068. 'bindPrice' => $detailM ['receivablesPrice'],
  4069. 'bindStatus' => 1,
  4070. 'bindDate' => date ( "Y-m-d H:i:s" )
  4071. );
  4072. $billPrice=$detailM ['receivablesPrice'];
  4073. } else {
  4074. die ( 'illegal request' );
  4075. }
  4076. if ($detailM ['iid'] == 0) {
  4077. $item += array (
  4078. 'iid' => $detail ['iid']
  4079. );
  4080. } else {
  4081. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4082. array_push ( $iidExtend, $detail ['iid'] );
  4083. $item += array (
  4084. 'iidExtend' => implode ( ',', $iidExtend )
  4085. );
  4086. }
  4087. $titleMark = $detail ['invoiceTitle'];
  4088. if (! empty ( $detail ['invoiceCompany'] ))
  4089. $titleMark = $detail ['invoiceCompany'];
  4090. $item += array (
  4091. 'irid' => $detailM ['irid'],
  4092. 'recepitTitleMark' => $titleMark,
  4093. 'accountClerk' => $this->staff [0] ['username']
  4094. );
  4095. // 如何没有人收款 则自动绑定收款
  4096. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4097. $item += array (
  4098. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4099. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4100. );
  4101. }
  4102. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4103. $iridString = "";
  4104. if (empty ( $detail ['irid'] ))
  4105. $iridString = $detailM ['irid'];
  4106. else
  4107. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4108. // $invoiceReceivables = new invoiceReceivables ();
  4109. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4110. // //这个收款余额
  4111. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4112. // $sum=$sumBind+$sumBalance;
  4113. //这个收款余额
  4114. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4115. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4116. // die;
  4117. $invoice = new invoice ();
  4118. $item = array (
  4119. 'iid' => $detail ['iid'],
  4120. 'irid' => $iridString
  4121. );
  4122. if ($detail ['invoicePrice'] <= $sumBalance){
  4123. $item += array (
  4124. 'invoiceBalance'=>0,
  4125. 'untreadStatus' => 3,
  4126. 'bindTime' => date ( "Y-m-d H:i:s" )
  4127. );
  4128. }else{
  4129. $item += array (
  4130. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4131. );
  4132. }
  4133. // print_r($item);
  4134. // echo $sum;die;
  4135. $invoice->setInvoiceByCondition ( $item );
  4136. //发票入账记录
  4137. Doo::loadModel ( 'bill' );
  4138. $bill = new bill ();
  4139. $bill->iid=$detail ['iid'];
  4140. $bill->trainId=$detail['trainId'];
  4141. $bill->irid=$detailM ['irid'];
  4142. $bill->create_time=date ( "Y-m-d H:i:s" );
  4143. $bill->price=$billPrice;
  4144. $bill->insert ();
  4145. // 操作日志
  4146. $item = array (
  4147. 'date' => date ( "Y-m-d H:i:s" ),
  4148. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4149. 'status' => 8,
  4150. 'img' => $this->staff [0] ['avatar'],
  4151. 'username' => $this->staff [0] ['username'],
  4152. 'uid' => $this->staff [0] ['sid'],
  4153. 'category' => $this->staff [0] ['category'],
  4154. 'iid' => $detail ['iid']
  4155. );
  4156. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4157. Doo::loadModel ( 'invoiceStatistics' );
  4158. $invoiceStatistics = new invoiceStatistics ();
  4159. $item = array (
  4160. 'date' => $detailM ['receivablesDate'],
  4161. 'priceClass' => 3,
  4162. 'cid' => $detail ['cid'],
  4163. 'staff' => $detail ['sid'],
  4164. 'accountPrice' => $detailM ['receivablesPrice']
  4165. );
  4166. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4167. //TODO
  4168. // 公司流水记录
  4169. // Doo::loadModel ( 'wasteBook' );
  4170. // $wasteBook = new wasteBook ();
  4171. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4172. // $accountBank='';
  4173. // if ($detailM ['receivablesBank']=='纵横广发'){
  4174. // $accountBank='CGBDeposit';
  4175. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4176. // $accountBank='ICBCDeposit';
  4177. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4178. // $accountBank='HUADeposit';
  4179. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4180. // $accountBank='PersonalDeposit';
  4181. // }
  4182. // if (empty($abDetail)){
  4183. // $item = array (
  4184. // 'dataID' => $detail ['iid'],
  4185. // 'expensesType' => 1,
  4186. // 'accountType' => 8,
  4187. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4188. // 'accountPrice'=>$detail ['invoicePrice'],
  4189. // 'accountBank'=>$accountBank,
  4190. // 'category'=>$this->staff[0]['category'],
  4191. // 'cid'=>$this->staff[0]['cid'],
  4192. // 'name'=>$this->staff[0]['username'],
  4193. // 'sid'=>$this->staff[0]['sid'],
  4194. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4195. // );
  4196. // $wasteBook->setAccountBookStatistics($item);
  4197. // }
  4198. return "/invoiceReceivables";
  4199. }
  4200. /**
  4201. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4202. */
  4203. function invoiceAggregate() {
  4204. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4205. Doo::loadModel ( 'invoiceStatistics' );
  4206. $invoiceStatistics = new invoiceStatistics ();
  4207. Doo::loadModel ( 'L_category' );
  4208. $Lcategory = new L_category ();
  4209. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4210. $LcategoryList = $Lcategory->getCategory ();
  4211. // print_r($isList);
  4212. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4213. foreach ( $LcategoryList as $key => $value ) {
  4214. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4215. $month = 1;
  4216. $invoicePriceYear = 0;
  4217. $receivablesPriceYear = 0;
  4218. $accountPriceYear = 0;
  4219. for(; $month <= 12; $month ++) {
  4220. $flag = true;
  4221. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4222. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4223. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4224. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4225. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4226. ';
  4227. $invoicePriceYear += $v ['invoicePrice'];
  4228. $receivablesPriceYear += $v ['receivablesPrice'];
  4229. $accountPriceYear += $v ['accountPrice'];
  4230. $flag = false;
  4231. break;
  4232. }
  4233. }
  4234. if ($flag)
  4235. $html .= '<td class="taR"></td>
  4236. <td class="taR"></td>
  4237. <td class="taR"><b></b></td>
  4238. ';
  4239. }
  4240. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4241. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4242. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4243. ';
  4244. $html .= '</tr>';
  4245. }
  4246. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4247. $invoicePriceYear = 0;
  4248. $receivablesPriceYear = 0;
  4249. $accountPriceYear = 0;
  4250. for($month = 1; $month <= 12; $month ++) {
  4251. $flag = true;
  4252. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4253. if ($month == $v ['month']) {
  4254. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4255. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4256. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4257. ';
  4258. $invoicePriceYear += $v ['invoicePrice'];
  4259. $receivablesPriceYear += $v ['receivablesPrice'];
  4260. $accountPriceYear += $v ['accountPrice'];
  4261. $flag = false;
  4262. break;
  4263. }
  4264. }
  4265. if ($flag) {
  4266. $html .= '<td class="taR"></td>
  4267. <td class="taR"></td>
  4268. <td class="taR"><b></b></td>
  4269. ';
  4270. }
  4271. }
  4272. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4273. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4274. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4275. ';
  4276. $html .= '</tr>';
  4277. // print_r($isList);
  4278. $this->data ['html'] = $html;
  4279. $this->data ['LcategoryList'] = $LcategoryList;
  4280. $this->data ['isList'] = $isList;
  4281. $this->data ['year'] = $year;
  4282. $this->data ['memu'] = "invoice";
  4283. $this->data ['staff'] = $this->staff;
  4284. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4285. $this->render ( "/admin/invoiceAggregate", $this->data );
  4286. }
  4287. function invoiceAggregateStaff() {
  4288. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4289. Doo::loadModel ( 'invoiceStatistics' );
  4290. $invoiceStatistics = new invoiceStatistics ();
  4291. Doo::loadModel ( 'L_category' );
  4292. $Lcategory = new L_category ();
  4293. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4294. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4295. $cStaff = $Lcategory->getCategoryStaff ();
  4296. $html = '';
  4297. foreach ( $cStaff as $key => $value ) {
  4298. $categoryFir = true;
  4299. foreach ( $value ['staff'] as $k => $v ) {
  4300. if ($categoryFir) {
  4301. $width = count ( $value ['staff'] ) + 1;
  4302. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4303. $categoryFir = false;
  4304. } else
  4305. $html .= '<tr>';
  4306. $html .= '<th>' . $v ['username'] . '</th>';
  4307. $invoicePriceStaffYear = 0;
  4308. $receivablesPriceStaffYear = 0;
  4309. $accountPriceStaffYear = 0;
  4310. for($month = 1; $month <= 12; $month ++) {
  4311. $flag = true;
  4312. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4313. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4314. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4315. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4316. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4317. ';
  4318. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4319. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4320. $accountPriceStaffYear += $slv ['accountPrice'];
  4321. $flag = false;
  4322. break;
  4323. }
  4324. }
  4325. if ($flag)
  4326. $html .= '<td class="taR"></td>
  4327. <td class="taR"></td>
  4328. <td class="taR"><b></b></td>
  4329. ';
  4330. }
  4331. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4332. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4333. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4334. ';
  4335. }
  4336. $html .= '</tr>';
  4337. // 小计
  4338. if (! empty ( $value ['staff'] )) {
  4339. $html .= '<tr><th class="taR">小计</th>';
  4340. $invoicePriceStaffYear = 0;
  4341. $receivablesPriceStaffYear = 0;
  4342. $accountPriceStaffYear = 0;
  4343. for($month = 1; $month <= 12; $month ++) {
  4344. $flag = true;
  4345. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4346. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4347. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4348. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4349. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4350. ';
  4351. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4352. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4353. $accountPriceStaffYear += $slv ['accountPrice'];
  4354. $flag = false;
  4355. break;
  4356. }
  4357. }
  4358. if ($flag)
  4359. $html .= '<td class="taR"></td>
  4360. <td class="taR"></td>
  4361. <td class="taR"><b></b></td>
  4362. ';
  4363. }
  4364. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4365. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4366. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4367. ';
  4368. $html .= '</tr>';
  4369. }
  4370. }
  4371. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4372. $invoicePriceYear = 0;
  4373. $receivablesPriceYear = 0;
  4374. $accountPriceYear = 0;
  4375. for($month = 1; $month <= 12; $month ++) {
  4376. $flag = true;
  4377. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4378. if ($month == $v ['month']) {
  4379. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4380. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4381. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4382. ';
  4383. $invoicePriceYear += $v ['invoicePrice'];
  4384. $receivablesPriceYear += $v ['receivablesPrice'];
  4385. $accountPriceYear += $v ['accountPrice'];
  4386. $flag = false;
  4387. break;
  4388. }
  4389. }
  4390. if ($flag)
  4391. $html .= '<td class="taR"></td>
  4392. <td class="taR"></td>
  4393. <td class="taR"><b></b></td>
  4394. ';
  4395. }
  4396. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4397. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4398. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4399. ';
  4400. $html .= '</tr>';
  4401. $this->data ['html'] = $html;
  4402. $this->data ['isList'] = $toteList;
  4403. $this->data ['year'] = $year;
  4404. $this->data ['memu'] = "invoice";
  4405. $this->data ['staff'] = $this->staff;
  4406. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4407. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4408. }
  4409. function invoiceAggregateCategory() {
  4410. Doo::loadClass ( 'XDeode' );
  4411. $XDeode = new XDeode ( 5 );
  4412. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4413. $cid = $XDeode->decode ( $cid );
  4414. if (! is_numeric ( $cid ))
  4415. die ( 'illegal request' );
  4416. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4417. Doo::loadModel ( 'invoiceStatistics' );
  4418. $invoiceStatistics = new invoiceStatistics ();
  4419. Doo::loadModel ( 'staff' );
  4420. $staff = new staff ();
  4421. $list = $staff->getStaffByCid ( $cid );
  4422. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4423. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4424. if (empty ( $list ))
  4425. die ( '该办事处没有成员' );
  4426. $htmlA = $htmlB = $htmlC = $html = '';
  4427. foreach ( $list as $key => $value ) {
  4428. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4429. $htmlB = '<tr><th class="taC">收款</th>';
  4430. $htmlC = '<tr><th class="taC">入账</th>';
  4431. $invoicePriceStaffYear = 0;
  4432. $receivablesPriceStaffYear = 0;
  4433. $accountPriceStaffYear = 0;
  4434. for($month = 1; $month <= 12; $month ++) {
  4435. $flag = true;
  4436. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4437. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4438. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4439. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4440. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4441. $invoicePriceStaffYear += $v ['invoicePrice'];
  4442. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4443. $accountPriceStaffYear += $v ['accountPrice'];
  4444. $flag = false;
  4445. break;
  4446. }
  4447. }
  4448. if ($flag) {
  4449. $htmlA .= '<td class="taR">-</td>';
  4450. $htmlB .= '<td class="taR">-</td>';
  4451. $htmlC .= '<td class="taR"><b>-</b></td>';
  4452. }
  4453. }
  4454. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4455. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4456. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4457. $htmlA .= '</tr>';
  4458. $htmlB .= '</tr>';
  4459. $htmlC .= '</tr>';
  4460. $html .= $htmlA . $htmlB . $htmlC;
  4461. }
  4462. $htmlA = $htmlB = $htmlC = "";
  4463. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4464. $htmlB = '<tr><th class="taC">收款</th>';
  4465. $htmlC = '<tr><th class="taC">入账</th>';
  4466. $invoicePriceStaffYear = 0;
  4467. $receivablesPriceStaffYear = 0;
  4468. $accountPriceStaffYear = 0;
  4469. for($month = 1; $month <= 12; $month ++) {
  4470. $flag = true;
  4471. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4472. if ($month == $v ['month']) {
  4473. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4474. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4475. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4476. $invoicePriceStaffYear += $v ['invoicePrice'];
  4477. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4478. $accountPriceStaffYear += $v ['accountPrice'];
  4479. $flag = false;
  4480. break;
  4481. }
  4482. }
  4483. if ($flag) {
  4484. $htmlA .= '<td class="taR">-</td>';
  4485. $htmlB .= '<td class="taR">-</td>';
  4486. $htmlC .= '<td class="taR"><b>-</b></td>';
  4487. }
  4488. }
  4489. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4490. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4491. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4492. $htmlA .= '</tr>';
  4493. $htmlB .= '</tr>';
  4494. $htmlC .= '</tr>';
  4495. $html .= $htmlA . $htmlB . $htmlC;
  4496. $this->data ['html'] = $html;
  4497. $this->data ['cidKey'] = $cidKey;
  4498. $this->data ['slist'] = $list;
  4499. $this->data ['isList'] = $toteList;
  4500. $this->data ['year'] = $year;
  4501. $this->data ['memu'] = "invoice";
  4502. $this->data ['staff'] = $this->staff;
  4503. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4504. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4505. }
  4506. /**
  4507. * 办事处汇总信息
  4508. */
  4509. function invoiceAggregateCategoryDetail() {
  4510. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4511. Doo::loadClass ( 'XDeode' );
  4512. $XDeode = new XDeode ( 5 );
  4513. Doo::loadModel ( 'invoiceStatistics' );
  4514. $invoiceStatistics = new invoiceStatistics ();
  4515. Doo::loadModel ( 'L_category' );
  4516. $category = new L_category ();
  4517. Doo::loadModel ( 'invoice' );
  4518. $invoice = new invoice ();
  4519. Doo::loadModel ( 'staff' );
  4520. $staff = new staff ();
  4521. Doo::loadModel ( "invoiceCategoryManage" );
  4522. $invoiceCategoryManage = new invoiceCategoryManage ();
  4523. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4524. $cidList = array ();
  4525. foreach ( $imcStaff as $key => $value ) {
  4526. array_push ( $cidList, $value ['cid'] );
  4527. if (empty ( $cidKey ))
  4528. $cidKey = $XDeode->encode ( $value ['cid'] );
  4529. }
  4530. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4531. $cid = $XDeode->decode ( $cidKey );
  4532. $month = date ( "m", strtotime ( "-1 month" ) );
  4533. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4534. $redis = new Redis ();
  4535. $redis->connect ( '127.0.0.1', '6379' );
  4536. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4537. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4538. if (empty ( $redisValue )) {
  4539. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4540. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4541. // 获得办事处人员下的汇总
  4542. $slist = $staff->getStaffByCid ( $cid );
  4543. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4544. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4545. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4546. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4547. foreach ( $slist as $key => $value ) {
  4548. $slist [$key] ['invoicePrice'] = 0;
  4549. $slist [$key] ['receivablesPrice'] = 0;
  4550. $slist [$key] ['accountPrice'] = 0;
  4551. $slist [$key] ['invoiceAllPrice'] = 0;
  4552. $slist [$key] ['receivablesAllPrice'] = 0;
  4553. $slist [$key] ['accountAllPrice'] = 0;
  4554. $slist [$key] ['schedule'] = 0;
  4555. $slist [$key] ['invoiceMonthPrice'] = 0;
  4556. $slist [$key] ['receivablesMonthPrice'] = 0;
  4557. $slist [$key] ['accountMonthPrice'] = 0;
  4558. foreach ( $ismsbMonth as $y => $l ) {
  4559. if ($value ['sid'] == $l ['staff']) {
  4560. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4561. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4562. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4563. }
  4564. }
  4565. foreach ( $ismsb as $k => $v ) {
  4566. if ($value ['sid'] == $v ['staff']) {
  4567. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4568. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4569. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4570. }
  4571. }
  4572. foreach ( $ISAS as $e => $a ) {
  4573. if ($value ['sid'] == $a ['staff']) {
  4574. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4575. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4576. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4577. }
  4578. }
  4579. if (isset ( $scheduleStaff [$value ['sid']] ))
  4580. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4581. }
  4582. $this->data ['cidKey'] = $cidKey;
  4583. $schedule = ( int ) ($schedule * 100);
  4584. $this->data ['slist'] = $slist;
  4585. $this->data ['isMC'] = $isMC;
  4586. $this->data ['schedule'] = $schedule;
  4587. $slist = json_encode ( $slist );
  4588. $isMC = json_encode ( $isMC );
  4589. $schedule = json_encode ( $schedule );
  4590. $redis->lpush ( $redisKey, $slist );
  4591. $redis->lpush ( $redisKey, $isMC );
  4592. $redis->lpush ( $redisKey, $schedule );
  4593. } else {
  4594. $this->data ['cidKey'] = $cidKey;
  4595. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4596. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4597. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4598. }
  4599. $this->data ['month'] = $month;
  4600. $this->data ['categoryList'] = $categoryList;
  4601. $this->data ['memu'] = "invoice";
  4602. $this->data ['staff'] = $this->staff;
  4603. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4604. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4605. }
  4606. /**
  4607. * 办事处人员汇总详情
  4608. */
  4609. function invoiceAggregateStaffDetail() {
  4610. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4611. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4612. Doo::loadClass ( 'XDeode' );
  4613. $XDeode = new XDeode ( 5 );
  4614. Doo::loadModel ( 'invoice' );
  4615. $invoice = new invoice ();
  4616. Doo::loadModel ( 'staff' );
  4617. $staff = new staff ();
  4618. Doo::loadModel ( "invoiceCategoryManage" );
  4619. $invoiceCategoryManage = new invoiceCategoryManage ();
  4620. $sid = $XDeode->decode ( $sidKey );
  4621. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4622. $cidList = array ();
  4623. foreach ( $imcStaff as $key => $value ) {
  4624. array_push ( $cidList, $value ['cid'] );
  4625. if (empty ( $cidKey ))
  4626. $cidKey = $XDeode->encode ( $value ['cid'] );
  4627. }
  4628. $cidString = implode ( ',', $cidList );
  4629. $staffList = $staff->getStaffInCid ( $cidString );
  4630. $staffDetail = $staff->getStaffBySid ( $sid );
  4631. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4632. $page_size = 18;
  4633. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4634. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4635. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4636. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4637. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4638. $dateArr = explode ( ':', $date );
  4639. $D1 = '';
  4640. $D2 = '';
  4641. if (! empty ( $date )) {
  4642. $D1 = $dateArr [0] . " 00:00:00 ";
  4643. if (isset ( $dateArr [1] ))
  4644. $D2 = $dateArr [1] . " 23:59:59 ";
  4645. else
  4646. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4647. // $D2 = $dateArr [1];
  4648. }
  4649. $con = ' status=2 ';
  4650. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4651. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4652. if ($status == 'UNRECORD')
  4653. $con .= ' and printStatus=1 and untreadStatus=0';
  4654. elseif ($status == 'RECORD')
  4655. $con .= ' and printStatus=1 and untreadStatus=3';
  4656. elseif ($status == 'BOUNCED')
  4657. $con .= ' and untreadStatus=2';
  4658. elseif ($status == 'PARTRECORD')
  4659. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4660. elseif ($status == 'All') {
  4661. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4662. }
  4663. $con .= ' and sid=' . $sid;
  4664. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4665. if (! empty ( $MebSea )) {
  4666. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4667. }
  4668. $pageinfo ['page'] = array (
  4669. 'previous' => ''
  4670. );
  4671. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4672. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4673. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4674. $this->data ['staffDetail'] = $staffDetail;
  4675. $this->data ['staffList'] = $staffList;
  4676. $this->data ['MebSeaEn'] = $MebSea;
  4677. $this->data ['MebSea'] = urlencode ( $MebSea );
  4678. $this->data ['date'] = $date;
  4679. $this->data ['page'] = $pageinfo;
  4680. $this->data ['get'] = $get;
  4681. $this->data ['list'] = $list;
  4682. $this->data ['status'] = $status;
  4683. $this->data ['sidKey'] = $sidKey;
  4684. $this->data ['memu'] = "invoice";
  4685. $this->data ['staff'] = $this->staff;
  4686. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4687. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4688. }
  4689. /**
  4690. * 办事处人员汇总收款情
  4691. */
  4692. function invoiceAggregateStaffReceivablesDetail() {
  4693. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4694. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4695. Doo::loadModel ( 'invoiceReceivables' );
  4696. $invoiceReceivables = new invoiceReceivables ();
  4697. Doo::loadModel ( 'staff' );
  4698. $staff = new staff ();
  4699. Doo::loadModel ( "invoiceCategoryManage" );
  4700. $invoiceCategoryManage = new invoiceCategoryManage ();
  4701. Doo::loadClass ( 'XDeode' );
  4702. $XDeode = new XDeode ( 5 );
  4703. $sid = $XDeode->decode ( $sidKey );
  4704. $staffDetail = $staff->getStaffBySid ( $sid );
  4705. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4706. $cidList = array ();
  4707. foreach ( $imcStaff as $key => $value ) {
  4708. array_push ( $cidList, $value ['cid'] );
  4709. if (empty ( $cidKey ))
  4710. $cidKey = $XDeode->encode ( $value ['cid'] );
  4711. }
  4712. $cidString = implode ( ',', $cidList );
  4713. $staffList = $staff->getStaffInCid ( $cidString );
  4714. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4715. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4716. $page_size = 10;
  4717. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4718. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4719. if ($timeType == "BINDOTP") {
  4720. $status = 'Credited';
  4721. }
  4722. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4723. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4724. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4725. $dateArr = explode ( ':', $date );
  4726. $D1 = '';
  4727. $D2 = '';
  4728. if (! empty ( $date )) {
  4729. $D1 = $dateArr [0] . " 00:00:00 ";
  4730. if (isset ( $dateArr [1] ))
  4731. $D2 = $dateArr [1] . " 23:59:59 ";
  4732. else
  4733. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4734. }
  4735. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4736. $descField = 'a.bindDate';
  4737. if ($timeType == 'CREATE')
  4738. $descField = 'a.date';
  4739. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4740. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4741. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4742. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4743. if ($status == 'Unclaimed')
  4744. $con .= ' and a.bindStatus=0';
  4745. elseif ($status == 'Credited')
  4746. $con .= ' and a.bindStatus=1';
  4747. elseif ($status == 'Claim')
  4748. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4749. elseif ($status == 'BBN')
  4750. $con .= ' and a.bindPrice>a.receivablesPrice';
  4751. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4752. if (! empty ( $MebSea )) {
  4753. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4754. }
  4755. $pageinfo ['page'] = array (
  4756. 'previous' => ''
  4757. );
  4758. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4759. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4760. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4761. // where ' . $con . ' group by a.irid ';
  4762. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4763. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4764. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4765. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4766. foreach ( $list as $key => $value ) {
  4767. $list [$key] ['category'] = '';
  4768. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4769. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4770. $list [$key] ['category'] = $receivablesCategory [1];
  4771. }
  4772. }
  4773. // print_r($list);
  4774. $this->data ['staffDetail'] = $staffDetail;
  4775. $this->data ['sidKey'] = $sidKey;
  4776. $this->data ['staffList'] = $staffList;
  4777. $this->data ['timeType'] = $timeType;
  4778. $this->data ['MebSeaEn'] = $MebSea;
  4779. $this->data ['MebSea'] = urlencode ( $MebSea );
  4780. $this->data ['date'] = $date;
  4781. $this->data ['page'] = $pageinfo;
  4782. $this->data ['get'] = $get;
  4783. $this->data ['list'] = $list;
  4784. $this->data ['status'] = $status;
  4785. $this->data ['memu'] = "invoice";
  4786. $this->data ['staff'] = $this->staff;
  4787. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4788. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4789. }
  4790. function invoiceAchieve() {
  4791. Doo::loadModel ( 'invoice' );
  4792. $invoice = new invoice ();
  4793. Doo::loadClass ( 'XDeode' );
  4794. $XDeode = new XDeode ( 5 );
  4795. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4796. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4797. $page_size = 18;
  4798. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4799. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4800. $get = "/" . $date;
  4801. $con = '';
  4802. if ($date == 'MONTHO')
  4803. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4804. elseif ($date == 'MONTHT')
  4805. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4806. elseif ($date == 'MONTHY')
  4807. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4808. if (! empty ( $MebSea )) {
  4809. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4810. $get .= "/" . $MebSea;
  4811. }
  4812. $pageinfo ['page'] = array (
  4813. 'previous' => ''
  4814. );
  4815. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4816. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4817. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4818. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4819. // print_r($pageinfo);
  4820. $this->data ['MebSeaEn'] = $MebSea;
  4821. $this->data ['MebSea'] = urlencode ( $MebSea );
  4822. $this->data ['get'] = $get;
  4823. $this->data ['page'] = $pageinfo;
  4824. $this->data ['list'] = $list;
  4825. $this->data ['date'] = $date;
  4826. $this->data ['memu'] = "invoice";
  4827. $this->data ['staff'] = $this->staff;
  4828. $this->data ['receiptMemu'] = 'invoice';
  4829. $this->render ( "/admin/invoiceAchieve", $this->data );
  4830. }
  4831. /**
  4832. */
  4833. function invoiceMyUnAccountAchieve() {
  4834. Doo::loadModel ( 'invoice' );
  4835. $invoice = new invoice ();
  4836. Doo::loadClass ( 'XDeode' );
  4837. $XDeode = new XDeode ( 5 );
  4838. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4839. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4840. $page_size = 18;
  4841. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4842. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4843. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4844. $dateArr = explode ( ':', $date );
  4845. $D1 = '';
  4846. $D2 = '';
  4847. if (! empty ( $date )) {
  4848. $D1 = $dateArr [0];
  4849. $D2 = $dateArr [1];
  4850. }
  4851. $con = '';
  4852. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4853. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4854. if (! empty ( $MebSea )) {
  4855. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4856. }
  4857. $pageinfo ['page'] = array (
  4858. 'previous' => ''
  4859. );
  4860. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4861. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4862. $action = "invoiceMyUnAccountAchieve";
  4863. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4864. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4865. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4866. Doo::loadModel ( 'express' );
  4867. $express = new express ();
  4868. $expressList = $express->getExpressByAll ();
  4869. $this->data ['expressList'] = $expressList;
  4870. // print_r($list);
  4871. $this->data ['MebSeaEn'] = $MebSea;
  4872. $this->data ['get'] = $get;
  4873. $this->data ['page'] = $pageinfo;
  4874. $this->data ['date'] = $date;
  4875. $this->data ['list'] = $list;
  4876. $this->data ['memu'] = "invoice";
  4877. $this->data ['staff'] = $this->staff;
  4878. $this->data ['receiptMemu'] = 'invoice';
  4879. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4880. }
  4881. function invoiceReceivablesAchieve() {
  4882. Doo::loadModel ( 'invoiceReceivables' );
  4883. $invoiceReceivables = new invoiceReceivables ();
  4884. Doo::loadClass ( 'XDeode' );
  4885. $XDeode = new XDeode ( 5 );
  4886. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4887. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4888. $page_size = 12;
  4889. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4890. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4891. $get = "/" . $date;
  4892. $con = '';
  4893. if ($date == 'MONTHO')
  4894. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4895. elseif ($date == 'MONTHT')
  4896. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4897. elseif ($date == 'MONTHY')
  4898. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4899. if (! empty ( $MebSea )) {
  4900. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4901. $get .= "/" . $MebSea;
  4902. }
  4903. $pageinfo ['page'] = array (
  4904. 'previous' => ''
  4905. );
  4906. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4907. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4908. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4909. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4910. // print_r($pageinfo);
  4911. $this->data ['MebSeaEn'] = $MebSea;
  4912. $this->data ['MebSea'] = urlencode ( $MebSea );
  4913. $this->data ['get'] = $get;
  4914. $this->data ['page'] = $pageinfo;
  4915. $this->data ['list'] = $list;
  4916. $this->data ['date'] = $date;
  4917. $this->data ['memu'] = "invoice";
  4918. $this->data ['staff'] = $this->staff;
  4919. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4920. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4921. }
  4922. /**
  4923. * 收款解绑
  4924. */
  4925. function invoiceUnBundLing() {
  4926. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4927. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4928. Doo::loadModel ( 'invoice' );
  4929. $invoice = new invoice ();
  4930. Doo::loadModel ( 'invoiceReceivables' );
  4931. $invoiceReceivables = new invoiceReceivables ();
  4932. Doo::loadModel ( 'invoiceOperationLog' );
  4933. $invoiceOperationLog = new invoiceOperationLog ();
  4934. Doo::loadModel ( 'invoiceROLog' );
  4935. $invoiceROLog = new invoiceROLog ();
  4936. Doo::loadModel ( 'invoiceStatistics' );
  4937. Doo::loadClass ( 'XDeode' );
  4938. $XDeode = new XDeode ( 5 );
  4939. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4940. die ( 'illegal request' );
  4941. $iid = $XDeode->decode ( $iidKey );
  4942. $irid = $invoice->authcode ( $unBundKey );
  4943. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4944. die ( 'illegal request' );
  4945. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4946. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4947. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4948. die ( 'illegal request' );
  4949. // 收款
  4950. $item = array (
  4951. 'irid' => $irDetails ['irid'],
  4952. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4953. 'bindStatus' => 0
  4954. );
  4955. if ($irDetails ['iid'] == $iid)
  4956. $item += array (
  4957. 'iid' => 0
  4958. );
  4959. else {
  4960. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4961. foreach ( $iidExtend as $key => $value ) {
  4962. if ($value == $iid)
  4963. unset ( $iidExtend [$key] );
  4964. }
  4965. $iidExtend = implode ( ',', $iidExtend );
  4966. $item += array (
  4967. 'iidExtend' => $iidExtend
  4968. );
  4969. }
  4970. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4971. // 收款操作日志
  4972. $item = array (
  4973. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4974. 'date' => date ( "Y-m-d" ),
  4975. 'status' => 3,
  4976. 'img' => $this->staff [0] ['avatar'],
  4977. 'username' => $this->staff [0] ['username'],
  4978. 'uid' => $this->staff [0] ['sid'],
  4979. 'category' => $this->staff [0] ['category'],
  4980. 'irid' => $irid
  4981. );
  4982. $invoiceROLog->setInvoiceROLog ( $item );
  4983. // 扣除入账统计金额
  4984. $invoiceStatistics = new invoiceStatistics ();
  4985. $item = array (
  4986. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4987. 'priceClass' => 3,
  4988. 'cid' => $invoiceDetails ['cid'],
  4989. 'staff' => $invoiceDetails ['sid'],
  4990. 'accountPrice' => - $invoiceDetails ['invoicePrice']
  4991. );
  4992. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4993. // 扣除收款统计金额
  4994. $invoiceStatistics = new invoiceStatistics ();
  4995. $item = array (
  4996. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4997. 'priceClass' => 2,
  4998. 'cid' => $invoiceDetails ['cid'],
  4999. 'staff' => $invoiceDetails ['sid'],
  5000. 'irid' => $irDetails ['irid'],
  5001. 'receivablesPrice' => - $invoiceDetails ['invoicePrice']
  5002. );
  5003. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5004. // 发票解绑去收款ID
  5005. $iridString = $invoiceDetails ['irid'];
  5006. if (! empty ( $invoiceDetails ['irid'] )) {
  5007. $list = explode ( ',', $invoiceDetails ['irid'] );
  5008. foreach ( $list as $key => $value ) {
  5009. if ($value == $irDetails ['irid']) {
  5010. unset ( $list [$key] );
  5011. break;
  5012. }
  5013. }
  5014. $iridString = implode ( ",", $list );
  5015. }
  5016. $item = array (
  5017. 'iid' => $invoiceDetails ['iid'],
  5018. 'irid' => $iridString,
  5019. 'updateTime' => date ( "Y-m-d H:i:s" )
  5020. );
  5021. if ($invoiceDetails ['untreadStatus'] == 3)
  5022. $item += array (
  5023. 'untreadStatus' => 0
  5024. );
  5025. $invoice->setInvoiceByCondition ( $item );
  5026. Doo::loadModel ( 'bill' );
  5027. $bill = new bill ();
  5028. $bill->iid=$invoiceDetails ['iid'];
  5029. $bill->trainId=$invoiceDetails['trainId'];
  5030. $bill->irid=$irDetails ['irid'];
  5031. $bill->create_time=date ( "Y-m-d H:i:s" );
  5032. $bill->price=-$invoiceDetails ['invoicePrice'];
  5033. $bill->remark='解绑-扣除入账';
  5034. $bill->insert ();
  5035. $item = array (
  5036. 'date' => date ( "Y-m-d H:i:s" ),
  5037. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  5038. 'status' => 11,
  5039. 'img' => $this->staff [0] ['avatar'],
  5040. 'username' => $this->staff [0] ['username'],
  5041. 'uid' => $this->staff [0] ['sid'],
  5042. 'category' => $this->staff [0] ['category'],
  5043. 'iid' => $invoiceDetails ['iid']
  5044. );
  5045. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5046. // 公司流水-解绑时删除流水
  5047. // Doo::loadModel ( 'wasteBook' );
  5048. // $wasteBook = new wasteBook ();
  5049. // $wasteBook->delete ( array (
  5050. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  5051. // 'limit' => 1
  5052. // ) );
  5053. // 银行
  5054. /*
  5055. * $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); }
  5056. */
  5057. return "/invoiceReceivablesAS";
  5058. }
  5059. /**
  5060. * 或者该收款下的所以发票
  5061. */
  5062. function ajaxGetInvoiceReceivablesByInvoice() {
  5063. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  5064. Doo::loadModel ( 'invoice' );
  5065. $invoice = new invoice ();
  5066. Doo::loadModel ( 'invoiceReceivables' );
  5067. $invoiceReceivables = new invoiceReceivables ();
  5068. $irid = $invoice->authcode ( $irid );
  5069. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5070. die ( 'illegal request' );
  5071. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5072. $iidString = $irDetails ['iid'];
  5073. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5074. if (! empty ( $irDetails ['iidExtend'] ))
  5075. $iidString .= ',' . implode ( ',', $iidExtend );
  5076. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5077. $html = "";
  5078. foreach ( $invoiceList as $key => $value ) {
  5079. $title = $value ['invoiceTitle'];
  5080. if (! empty ( $value ['invoiceCompany'] ))
  5081. $title = $value ['invoiceCompany'];
  5082. $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>';
  5083. }
  5084. echo json_encode ( array (
  5085. 'status' => 1,
  5086. 'html' => $html
  5087. ) );
  5088. }
  5089. /**
  5090. * 发票管理
  5091. */
  5092. function invoiceAS() {
  5093. Doo::loadModel ( 'invoice' );
  5094. $invoice = new invoice ();
  5095. Doo::loadModel ( 'invoiceReceivables' );
  5096. $invoiceReceivables = new invoiceReceivables ();
  5097. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5098. $page_size = 18;
  5099. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5100. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5101. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5102. $dateArr = explode ( ':', $date );
  5103. $D1 = '';
  5104. $D2 = '';
  5105. if (! empty ( $date )) {
  5106. $D1 = $dateArr [0] . " 00:00:00 ";
  5107. if (isset ( $dateArr [1] ))
  5108. $D2 = $dateArr [1] . " 23:59:59 ";
  5109. else
  5110. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5111. // $D2 = $dateArr [1];
  5112. }
  5113. $con = ' status=2 ';
  5114. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5115. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5116. if ($status == 'UNRECORD')
  5117. $con .= ' and printStatus=1 and untreadStatus=0';
  5118. elseif ($status == 'RECORD')
  5119. $con .= ' and printStatus=1 and untreadStatus=3';
  5120. elseif ($status == 'BOUNCED')
  5121. $con .= ' and untreadStatus=2';
  5122. elseif ($status == 'PARTRECORD')
  5123. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5124. elseif ($status == 'All') {
  5125. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5126. }
  5127. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5128. if (! empty ( $MebSea )) {
  5129. $con .= ' and ( invoiceSerial like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5130. }
  5131. $pageinfo ['page'] = array (
  5132. 'previous' => ''
  5133. );
  5134. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5135. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5136. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5137. $this->data ['MebSeaEn'] = $MebSea;
  5138. $this->data ['MebSea'] = urlencode ( $MebSea );
  5139. $this->data ['date'] = $date;
  5140. $this->data ['page'] = $pageinfo;
  5141. $this->data ['get'] = $get;
  5142. $this->data ['list'] = $list;
  5143. $this->data ['status'] = $status;
  5144. $this->data ['memu'] = "invoice";
  5145. $this->data ['staff'] = $this->staff;
  5146. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5147. $this->render ( "/admin/invoiceAS", $this->data );
  5148. }
  5149. /**
  5150. * 收款管理
  5151. */
  5152. function invoiceReceivablesAS() {
  5153. Doo::loadModel ( 'invoiceReceivables' );
  5154. $invoiceReceivables = new invoiceReceivables ();
  5155. Doo::loadModel ( 'L_category' );
  5156. $lCategory = new L_category ();
  5157. $category = $lCategory->getCategory ();
  5158. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5159. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5160. $page_size = 10;
  5161. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5162. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5163. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5164. $dateArr = explode ( ':', $date );
  5165. $D1 = '';
  5166. $D2 = '';
  5167. if (! empty ( $date )) {
  5168. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5169. if (isset ( $dateArr [1] ))
  5170. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5171. else
  5172. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5173. }
  5174. $descField = 'a.receivablesDate';
  5175. if ($timeType == 'CREATE')
  5176. $descField = 'a.date';
  5177. $con = ' 1 ';
  5178. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5179. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5180. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5181. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5182. if ($status == 'Unclaimed')
  5183. $con .= ' and a.bindStatus=0';
  5184. elseif ($status == 'Credited')
  5185. $con .= ' and a.bindStatus=1';
  5186. elseif ($status == 'Claim')
  5187. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5188. elseif ($status == 'BBN')
  5189. $con .= ' and a.bankBatchNumber!=""';
  5190. elseif ($status == 'REFUND')
  5191. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5192. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5193. if (! empty ( $MebSea )) {
  5194. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5195. }
  5196. $pageinfo ['page'] = array (
  5197. 'previous' => ''
  5198. );
  5199. // if(!empty($con)){
  5200. // $con=' where 1 '.$con;
  5201. // }
  5202. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5203. // ' . $con ;
  5204. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5205. //echo $sql;
  5206. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5207. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5208. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5209. foreach ( $list as $key => $value ) {
  5210. $list [$key] ['category'] = '';
  5211. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5212. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5213. $list [$key] ['category'] = $receivablesCategory [1];
  5214. }
  5215. }
  5216. // print_r($list);
  5217. $this->data ['category'] = $category;
  5218. $this->data ['timeType'] = $timeType;
  5219. $this->data ['MebSeaEn'] = $MebSea;
  5220. $this->data ['MebSea'] = urlencode ( $MebSea );
  5221. $this->data ['date'] = $date;
  5222. $this->data ['page'] = $pageinfo;
  5223. $this->data ['get'] = $get;
  5224. $this->data ['list'] = $list;
  5225. $this->data ['status'] = $status;
  5226. $this->data ['memu'] = "invoice";
  5227. $this->data ['staff'] = $this->staff;
  5228. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5229. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5230. }
  5231. /**
  5232. * 删除一条收款
  5233. */
  5234. function delInvoiceReceivables() {
  5235. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5236. if (empty ( $iridKey ))
  5237. die ( 'illegal request' );
  5238. Doo::loadClass ( 'XDeode' );
  5239. $XDeode = new XDeode ( 5 );
  5240. $irid = $XDeode->decode ( $iridKey );
  5241. Doo::loadModel ( 'invoiceReceivables' );
  5242. $invoiceReceivables = new invoiceReceivables ();
  5243. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5244. if (empty ( $detail ))
  5245. die ( 'illegal request' );
  5246. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5247. // 扣除收款汇总信息 汇总
  5248. Doo::loadModel ( 'invoiceStatistics' );
  5249. $invoiceStatistics = new invoiceStatistics ();
  5250. $item = array (
  5251. 'date' => $detail ['receivablesDate'],
  5252. 'priceClass' => 2,
  5253. 'irid' => $detail ['irid'],
  5254. 'receivablesPrice' => - $detail ['receivablesPrice']
  5255. );
  5256. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5257. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5258. $item += array (
  5259. 'cid' => $receivablesCategory [0]
  5260. );
  5261. }
  5262. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5263. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5264. $item += array (
  5265. 'staff' => $receivablesStaff [0]
  5266. );
  5267. }
  5268. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5269. return '/invoiceReceivablesAS';
  5270. }
  5271. /**
  5272. * 添加退款信息
  5273. */
  5274. function setInvoiceReceivablesRefund() {
  5275. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5276. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5277. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5278. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5279. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5280. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5281. if ($refundPrice < 0)
  5282. die ( 'illegal request' );
  5283. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5284. Doo::loadModel ( 'invoiceReceivables' );
  5285. $invoiceReceivables = new invoiceReceivables ();
  5286. Doo::loadModel ( 'invoiceRefund' );
  5287. $invoiceRefund = new invoiceRefund ();
  5288. $irid = $invoiceReceivables->authcode ( $iridKey );
  5289. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5290. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5291. die ( 'illegal request' );
  5292. $invoiceReceivables = new invoiceReceivables ();
  5293. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5294. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5295. ';
  5296. $item = array (
  5297. 'irid' => $irid,
  5298. 'refundCompany' => $refundCompany,
  5299. 'refundNumber' => $refundNumber,
  5300. 'refundPrice' => $refundPrice,
  5301. 'refundRemarks' => $refundRemarks,
  5302. 'refundLog' => $refundLog
  5303. );
  5304. if ($refundType == 1) {
  5305. $item += array (
  5306. 'refundType' => $refundType,
  5307. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5308. 'bindStatus' => 2
  5309. );
  5310. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5311. $item += array (
  5312. 'refundType' => 1,
  5313. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5314. 'bindStatus' => 2
  5315. );
  5316. } else {
  5317. $item += array (
  5318. 'refundType' => $refundType,
  5319. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5320. );
  5321. }
  5322. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5323. // 添加退款记录
  5324. $item = array (
  5325. 'irid' => $irid,
  5326. 'refundType' => $refundType,
  5327. 'refundCompany' => $refundCompany,
  5328. 'refundNumber' => $refundNumber,
  5329. 'refundPrice' => $refundPrice,
  5330. 'refundLog' => $refundLog,
  5331. 'refundRemarks' => $refundRemarks,
  5332. 'date' => date ( "Y-m-d H:i:s" )
  5333. );
  5334. $invoiceRefund->addInvoiceRefund ( $item );
  5335. // 扣除收款汇总信息 汇总
  5336. Doo::loadModel ( 'invoiceStatistics' );
  5337. $invoiceStatistics = new invoiceStatistics ();
  5338. $item = array (
  5339. 'date' => $irDetail ['receivablesDate'],
  5340. 'priceClass' => 2,
  5341. 'irid' => $irDetail ['irid'],
  5342. 'receivablesPrice' => - $refundPrice
  5343. );
  5344. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5345. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5346. $item += array (
  5347. 'cid' => $receivablesCategory [0]
  5348. );
  5349. }
  5350. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5351. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5352. $item += array (
  5353. 'staff' => $receivablesStaff [0]
  5354. );
  5355. }
  5356. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5357. // 公司日常支出流水
  5358. Doo::loadModel ( 'wasteBook' );
  5359. $wasteBook = new wasteBook ();
  5360. $accountBank = '';
  5361. if ($irDetail ['receivablesBank'] == '纵横广发') {
  5362. $accountBank = 'CGBDeposit';
  5363. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  5364. $accountBank = 'ICBCDeposit';
  5365. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  5366. $accountBank = 'HUADeposit';
  5367. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  5368. $accountBank = 'PersonalDeposit';
  5369. }
  5370. $itemWaste = array (
  5371. 'accountPrice' => - $refundPrice,
  5372. 'expensesType' => 2,
  5373. 'accountType' => 11,
  5374. 'accountPriceShow' => $refundPrice,
  5375. 'dataID' => $irid,
  5376. 'accountBank' => $accountBank,
  5377. 'category' => $this->staff [0] ['category'],
  5378. 'cid' => $this->staff [0] ['cid'],
  5379. 'name' => $this->staff [0] ['username'],
  5380. 'sid' => $this->staff [0] ['sid'],
  5381. 'inputDate' => date ( "Y-m-d H:i:s" )
  5382. );
  5383. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5384. return '/invoiceReceivablesAS';
  5385. }
  5386. die ( 'illegal request' );
  5387. }
  5388. function ajaxCheckInvoiceReceivablesRefund() {
  5389. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5390. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5391. if ($refundPrice < 0) {
  5392. echo json_encode ( array (
  5393. 'error' => '金额不能为负'
  5394. ) );
  5395. die ();
  5396. }
  5397. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5398. Doo::loadModel ( 'invoiceReceivables' );
  5399. $invoiceReceivables = new invoiceReceivables ();
  5400. $irid = $invoiceReceivables->authcode ( $iridKey );
  5401. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5402. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5403. echo json_encode ( array (
  5404. 'error' => '退款金额不能超过收款金额'
  5405. ) );
  5406. die ();
  5407. }
  5408. echo json_encode ( array (
  5409. 'ok' => '可以使用!'
  5410. ) );
  5411. die ();
  5412. }
  5413. }
  5414. /**
  5415. * 获得收款退款信息
  5416. */
  5417. function getRefundByDetail() {
  5418. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5419. Doo::loadModel ( 'invoiceReceivables' );
  5420. $invoiceReceivables = new invoiceReceivables ();
  5421. if (! empty ( $iridKey )) {
  5422. $irid = $invoiceReceivables->authcode ( $iridKey );
  5423. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5424. echo json_encode ( array (
  5425. 'status' => 1,
  5426. 'irDetail' => $irDetail
  5427. ) );
  5428. die ();
  5429. }
  5430. echo json_encode ( array (
  5431. 'status' => 2
  5432. ) );
  5433. }
  5434. /**
  5435. * 根据收款序列号获得收款退款信息
  5436. */
  5437. function ajaxGetInvoiceReceivablesBySerial() {
  5438. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5439. if (! empty ( $receivablesSerial )) {
  5440. Doo::loadModel ( 'invoiceReceivables' );
  5441. $invoiceReceivables = new invoiceReceivables ();
  5442. // , ' and refundLog=""'
  5443. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5444. $html = '';
  5445. if (! empty ( $irDetail ))
  5446. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5447. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5448. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5449. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5450. <td>' . $irDetail ['recepitTitleMark'] . '
  5451. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5452. </td>';
  5453. echo json_encode ( array (
  5454. 'status' => 1,
  5455. 'html' => $html,
  5456. 'irDetail' => $irDetail
  5457. ) );
  5458. die ();
  5459. }
  5460. echo json_encode ( array (
  5461. 'status' => 2
  5462. ) );
  5463. }
  5464. /**
  5465. * 绑定新收款
  5466. */
  5467. function relationNewInvoiceReceivables() {
  5468. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5469. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5470. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5471. Doo::loadModel ( 'invoiceReceivables' );
  5472. $invoiceReceivables = new invoiceReceivables ();
  5473. Doo::loadClass ( 'XDeode' );
  5474. $XDeode = new XDeode ( 5 );
  5475. $irid = $XDeode->decode ( $iridKey );
  5476. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5477. echo $irid . 'bbb' . $iridOld;
  5478. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5479. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5480. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5481. die ( 'illegal request' );
  5482. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5483. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5484. ';
  5485. $invoiceReceivables = new invoiceReceivables ();
  5486. $item = array (
  5487. 'irid' => $iridOld,
  5488. 'relationIrid' => $irid,
  5489. 'relationLog' => $relationLog
  5490. );
  5491. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5492. return '/invoiceReceivablesAS';
  5493. }
  5494. die ( 'illegal request' );
  5495. }
  5496. // function invoiceApprovalAchieve() {
  5497. // Doo::loadModel ( 'invoice' );
  5498. // $invoice = new invoice ();
  5499. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5500. // $page_size = 12;
  5501. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5502. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5503. // $get = "/" . $date;
  5504. // $con = '';
  5505. // if ($date == 'MONTHO')
  5506. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5507. // elseif ($date == 'MONTHT')
  5508. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5509. // elseif ($date == 'MONTHY')
  5510. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5511. // if (! empty ( $MebSea )) {
  5512. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5513. // $get .= "/" . $MebSea;
  5514. // }
  5515. // $pageinfo ['page'] = array (
  5516. // 'previous' => ''
  5517. // );
  5518. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5519. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5520. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5521. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5522. // // print_r($list);
  5523. // $this->data ['MebSeaEn'] = $MebSea;
  5524. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5525. // $this->data ['get'] = $get;
  5526. // $this->data ['page'] = $pageinfo;
  5527. // $this->data ['list'] = $list;
  5528. // $this->data ['date'] = $date;
  5529. // $this->data ['memu'] = "invoice";
  5530. // $this->data ['staff'] = $this->staff;
  5531. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5532. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5533. // }
  5534. /**
  5535. * 获得审批发票的信息以及审批页面
  5536. */
  5537. function ajaxGetInvoiceApprovalDetail() {
  5538. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5539. if (empty ( $serial )) {
  5540. echo json_encode ( array (
  5541. 'status' => 2,
  5542. 'msg' => 'illegal request'
  5543. ) );
  5544. die ();
  5545. }
  5546. Doo::loadModel ( 'invoice' );
  5547. $invoice = new invoice ();
  5548. Doo::loadModel ( 'invoiceOperationLog' );
  5549. $invoiceOperationLog = new invoiceOperationLog ();
  5550. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5551. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5552. if (empty ( $detail ))
  5553. $html = '';
  5554. else {
  5555. $html = '
  5556. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5557. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5558. <input type="hidden" name="status" value="">
  5559. <input type="hidden" name="divApproval" value="divApproval">
  5560. <div class="modal-dialog modal-lg">
  5561. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5562. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5563. <tr>
  5564. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5565. </tr>
  5566. <tr>
  5567. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5568. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5569. </tr>
  5570. <tr>
  5571. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5572. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5573. </tr>
  5574. <tr>
  5575. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5576. </td>
  5577. </tr>
  5578. <tr>
  5579. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5580. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5581. </tr>
  5582. <tr>
  5583. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5584. </tr></tbody></table>';
  5585. if ($detail ['invoiceType'] == 0)
  5586. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5587. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5588. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5589. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5590. </tr>';
  5591. else
  5592. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5593. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5594. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5595. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5596. ';
  5597. $html .= '<tr>
  5598. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5599. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5600. </tr>
  5601. <tr>
  5602. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5603. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5604. </tr></tbody></table>';
  5605. if ($detail ['doPost'] == 1) {
  5606. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5607. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5608. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5609. </tr><tr>
  5610. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5611. </tr><tr>
  5612. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5613. </tr>
  5614. ';
  5615. if ($detail ['expressCom'] == 'SF')
  5616. $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>';
  5617. else
  5618. $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>';
  5619. $html .= '</tbody></table>';
  5620. }
  5621. if (! empty ( $invoiceOperationLogList )) {
  5622. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5623. foreach ( $invoiceOperationLogList as $key => $value ) {
  5624. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5625. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5626. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5627. if ($value ['status'] == 2) {
  5628. $html .= '<span class="colGreen">同意</span>';
  5629. } elseif ($value ['status'] == 3) {
  5630. $html .= '<span class="colOrange">退回</span>';
  5631. } elseif ($value ['status'] == 5) {
  5632. $html .= '<span class="colGreen">打印</span>';
  5633. } elseif ($value ['status'] == 4) {
  5634. $html .= '<span class="colRed">终止</span>';
  5635. }
  5636. $html .= $value ['operation'] . '</p></blockquote>';
  5637. }
  5638. }
  5639. $html .= '</td></tr></tbody></table>';
  5640. }
  5641. $html .= '</div><div class="modal-footer">
  5642. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5643. <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>
  5644. <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>
  5645. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5646. </form>
  5647. <script type="text/javascript">
  5648. $("a[node-approval^=\'approval\']").click(function() {
  5649. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5650. $("form[name=\'invoiceApproval\']").submit();
  5651. });
  5652. </script>
  5653. ';
  5654. }
  5655. echo json_encode ( array (
  5656. 'status' => 1,
  5657. 'html' => $html
  5658. ) );
  5659. die ();
  5660. }
  5661. /**
  5662. * 获得审批发票分页数据
  5663. */
  5664. function ajaxGetinvoiceApprovalAchieve() {
  5665. Doo::loadModel ( 'invoice' );
  5666. $invoice = new invoice ();
  5667. Doo::loadModel ( 'staff' );
  5668. $staff = new staff ();
  5669. Doo::loadClass ( 'XDeode' );
  5670. $XDeode = new XDeode ( 5 );
  5671. Doo::loadModel ( 'invoiceTraining' );
  5672. $invoiceTraining = new invoiceTraining ();
  5673. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5674. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5675. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5676. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5677. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5678. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5679. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5680. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5681. $MebSea = $this->get_args ( 'search' );
  5682. $MebSea = $MebSea ['value'];
  5683. $page_size = $length;
  5684. $con = '';
  5685. if ($status == 'ALL')
  5686. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5687. elseif ($status == 'PEND')
  5688. $con = ' isDelete=0 and status=1';
  5689. elseif ($status == 'APPROVED')
  5690. $con = ' isDelete=0 and status=2';
  5691. if ($invoiceType == 'ORDINARY')
  5692. $con .= ' and invoiceType=0 ';
  5693. elseif ($invoiceType == 'SPECIAL')
  5694. $con .= ' and invoiceType=1 ';
  5695. if ($invoiceTrain == 'ORDINARY')
  5696. $con .= ' and trainId=0 ';
  5697. elseif ($invoiceTrain == 'TRAIN')
  5698. $con .= ' and trainId!=0 ';
  5699. if ($invoiceTrainName != 'ALL') {
  5700. $trainId = $XDeode->decode ( $invoiceTrainName );
  5701. if (is_numeric ( $trainId ))
  5702. $con .= ' and trainId =' . $trainId;
  5703. }
  5704. $dateArr = explode ( ':', $date );
  5705. $D1 = $dateString = '';
  5706. $D2 = '';
  5707. if (! empty ( $date )) {
  5708. $D1 = $dateArr [0];
  5709. if (isset ( $dateArr [1] ))
  5710. $D2 = $dateArr [1];
  5711. else
  5712. $D2 = '';
  5713. $dateString = $D1 . " : " . $D2;
  5714. }
  5715. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5716. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5717. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5718. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5719. if (! empty ( $MebSea ))
  5720. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5721. // /
  5722. $pageinfo ['page'] = array (
  5723. 'previous' => ''
  5724. );
  5725. $sql = ' ' . $con;
  5726. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5727. $limit = $page . ',' . $page_size;
  5728. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5729. $approvalList = array ();
  5730. $html = '<script type="text/javascript">
  5731. </script>';
  5732. // 结算结束不能修改方式
  5733. Doo::loadModel ( 'receipt' );
  5734. $receipt = new receipt ();
  5735. foreach ( $list as $key => $value ) {
  5736. $irDetail = array ();
  5737. // 结算方式
  5738. $receiptDetail = array ();
  5739. if ($value ['trainId'] != 0) {
  5740. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5741. }
  5742. if (! empty ( $receiptDetail )) {
  5743. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5744. array_push ( $irDetail, '' );
  5745. } else {
  5746. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5747. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5748. } elseif ($value ['status'] == 2) {
  5749. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5750. } else
  5751. array_push ( $irDetail, '' );
  5752. }
  5753. } else {
  5754. if ($value ['status'] == 2) {
  5755. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5756. } else
  5757. array_push ( $irDetail, '' );
  5758. }
  5759. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5760. if ($value ['invoiceType'] == 1)
  5761. array_push ( $irDetail, $value ['invoiceCompany'] );
  5762. else
  5763. array_push ( $irDetail, $value ['invoiceTitle'] );
  5764. array_push ( $irDetail, $value ['TIN'] );
  5765. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5766. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5767. array_push ( $irDetail, $value ['remark'] );
  5768. array_push ( $irDetail, $value ['invoiceElement'] );
  5769. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5770. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5771. if ($value ['invoiceType'] == 1) {
  5772. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5773. } else {
  5774. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5775. }
  5776. if ($value ['settlementType'] == 0) {
  5777. array_push ( $irDetail, '软件销售' );
  5778. } else {
  5779. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5780. array_push ( $irDetail, $itDetail ['trainName'] );
  5781. }
  5782. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5783. array_push ( $irDetail, $value ['recipientsAddress'] );
  5784. array_push ( $irDetail, $value ['mailItems'] );
  5785. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5786. $fchtml = $value ['OL'] ['operation'];
  5787. if (count ( $list ) == $page_size)
  5788. $fchtml = $value ['OL'] ['operation'] . $html;
  5789. // 最后的审批意见
  5790. array_push ( $irDetail, $fchtml );
  5791. if ($value ['status'] == 2)
  5792. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5793. elseif ($value ['status'] == 3)
  5794. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5795. elseif ($value ['status'] == 4)
  5796. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5797. else
  5798. array_push ( $irDetail, '' );
  5799. array_push ( $approvalList, $irDetail );
  5800. }
  5801. // $approvalListJson = json_encode ( $approvalList );
  5802. $recordsFiltered = $pageinfo ['total_data'];
  5803. echo json_encode ( array (
  5804. "draw" => intval ( $draw ),
  5805. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5806. "recordsFiltered" => intval ( $recordsFiltered ),
  5807. "data" => $approvalList
  5808. ), JSON_UNESCAPED_UNICODE );
  5809. }
  5810. /**
  5811. * 审批发票查看更多--重构
  5812. */
  5813. function invoiceApprovalAchieve() {
  5814. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5815. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5816. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5817. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5818. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5819. Doo::loadModel ( 'invoiceTraining' );
  5820. $invoiceTraining = new invoiceTraining ();
  5821. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5822. $this->data ['trainList'] = $trainList;
  5823. $this->data ['dateString'] = $date;
  5824. $this->data ['status'] = $status;
  5825. $this->data ['invoiceType'] = $invoiceType;
  5826. $this->data ['invoiceTrain'] = $invoiceTrain;
  5827. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5828. $this->data ['memu'] = "invoice";
  5829. $this->data ['staff'] = $this->staff;
  5830. $this->data ['receiptMemu'] = 'invoiceApproval';
  5831. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5832. }
  5833. function invoiceTAchieve() {
  5834. Doo::loadModel ( 'invoice' );
  5835. $invoice = new invoice ();
  5836. Doo::loadClass ( 'XDeode' );
  5837. $XDeode = new XDeode ( 5 );
  5838. Doo::loadModel ( 'staff' );
  5839. $staff = new staff ();
  5840. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5841. $page_size = 12;
  5842. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5843. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5844. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5845. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5846. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5847. Doo::loadModel ( 'invoiceTraining' );
  5848. $invoiceTraining = new invoiceTraining ();
  5849. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5850. $get = "/" . $date;
  5851. $con = '';
  5852. if ($date == 'MONTHO')
  5853. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5854. elseif ($date == 'MONTHT')
  5855. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5856. elseif ($date == 'MONTHY')
  5857. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5858. if ($invoiceType == 'ORDINARY')
  5859. $con .= ' and invoiceType=0 ';
  5860. elseif ($invoiceType == 'SPECIAL')
  5861. $con .= ' and invoiceType=1 ';
  5862. if ($invoiceTrain == 'ORDINARY')
  5863. $con .= ' and trainId=0 ';
  5864. elseif ($invoiceTrain == 'TRAIN')
  5865. $con .= ' and trainId!=0 ';
  5866. if ($invoiceTrainName != 'ALL') {
  5867. $trainId = $XDeode->decode ( $invoiceTrainName );
  5868. if (is_numeric ( $trainId ))
  5869. $con .= ' and trainId =' . $trainId;
  5870. }
  5871. if (! empty ( $MebSea )) {
  5872. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5873. $get .= "/" . $MebSea;
  5874. }
  5875. $pageinfo ['page'] = array (
  5876. 'previous' => ''
  5877. );
  5878. $sql = "";
  5879. $action = "";
  5880. if ($this->ACTION == 'invoicePrintAchieve') {
  5881. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5882. $action = "invoicePrintAchieve";
  5883. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5884. // and untreadStatus=0
  5885. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5886. $action = "invoicePostAchieve";
  5887. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5888. $sql = " untreadStatus=2 and status=2 " . $con;
  5889. $action = "invoiceUntreadAchieve";
  5890. }
  5891. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5892. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5893. $this->data ['MebSeaEn'] = $MebSea;
  5894. $this->data ['MebSea'] = urlencode ( $MebSea );
  5895. $this->data ['get'] = $get;
  5896. $this->data ['page'] = $pageinfo;
  5897. $this->data ['trainList'] = $trainList;
  5898. $this->data ['invoiceType'] = $invoiceType;
  5899. $this->data ['invoiceTrain'] = $invoiceTrain;
  5900. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5901. $this->data ['date'] = $date;
  5902. $this->data ['memu'] = "invoice";
  5903. $this->data ['staff'] = $this->staff;
  5904. if ($this->ACTION == 'invoicePrintAchieve') {
  5905. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5906. $this->data ['receiptMemu'] = 'invoicePrint';
  5907. $this->data ['list'] = $list;
  5908. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5909. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5910. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5911. Doo::loadModel ( 'express' );
  5912. $express = new express ();
  5913. $expressList = $express->getExpressByAll ();
  5914. $this->data ['expressList'] = $expressList;
  5915. $this->data ['receiptMemu'] = 'invoicePost';
  5916. $this->data ['list'] = $list;
  5917. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5918. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5919. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc','desc','untreadTime' );
  5920. $this->data ['receiptMemu'] = 'invoiceUntread';
  5921. $this->data ['list'] = $list;
  5922. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5923. }
  5924. }
  5925. /**
  5926. * 公司应收款
  5927. */
  5928. function invoiceAggregateCompanyDetail() {
  5929. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5930. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5931. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5932. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5933. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5934. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5935. Doo::loadClass ( 'XDeode' );
  5936. $XDeode = new XDeode ( 5 );
  5937. Doo::loadModel ( 'invoice' );
  5938. $invoice = new invoice ();
  5939. Doo::loadModel ( 'staff' );
  5940. $staff = new staff ();
  5941. Doo::loadModel ( "invoiceCompanyManage" );
  5942. $invoiceCompanyManage = new invoiceCompanyManage ();
  5943. Doo::loadModel ( 'L_category' );
  5944. $category = new L_category ();
  5945. $sid = '';
  5946. if (! empty ( $sidKey )) {
  5947. $sid = $XDeode->decode ( $sidKey );
  5948. }
  5949. $staffDetail = $staff->getStaffBySid ( $sid );
  5950. $cid = '';
  5951. if (! empty ( $cidKey )) {
  5952. $cid = $XDeode->decode ( $cidKey );
  5953. }
  5954. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5955. $cidList = array ();
  5956. foreach ( $imcStaff as $key => $value ) {
  5957. array_push ( $cidList, $value ['cid'] );
  5958. }
  5959. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5960. $cidString = implode ( ',', $cidList );
  5961. if (empty ( $cid ))
  5962. $staffList = $staff->getStaffInCid ( $cidString );
  5963. else
  5964. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5965. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5966. $page_size = 25;
  5967. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5968. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5969. $con = ' status=2 and untreadStatus!=2 and invalid=0 and isDelete=0 and badDebt=0 ';
  5970. $statisticsCon = '';
  5971. if (! empty ( $year ) && is_numeric ( $year ))
  5972. $con .= ' and Year(printTime)=' . $year . '';
  5973. if (! empty ( $month ) && is_numeric ( $month ))
  5974. $con .= ' and Month(printTime)="' . $month . '" ';
  5975. if ($status == 'UNRECORD')
  5976. $con .= ' and printStatus=1 and untreadStatus=0';
  5977. elseif ($status == 'RECORD')
  5978. $con .= ' and printStatus=1 and untreadStatus=3';
  5979. elseif ($status == 'BOUNCED')
  5980. $con .= ' and untreadStatus=2';
  5981. elseif ($status == 'PARTRECORD')
  5982. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5983. elseif ($status == 'All') {
  5984. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5985. }
  5986. if (! empty ( $sid ) && is_numeric ( $sid ))
  5987. $con .= ' and sid=' . $sid;
  5988. if (! empty ( $cid ) && is_numeric ( $cid ))
  5989. $con .= ' and cid=' . $cid;
  5990. else
  5991. $con .= ' and cid in (' . $cidString . ')';
  5992. // 开票内容筛选
  5993. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5994. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5995. }
  5996. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5997. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5998. if (! empty ( $titleORno )) {
  5999. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  6000. }
  6001. $pageinfo ['page'] = array (
  6002. 'previous' => ''
  6003. );
  6004. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  6005. $limit = $pageinfo ['lower'] . ',' . $page_size;
  6006. // 应收款合计
  6007. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  6008. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  6009. $monthHtml = "";
  6010. if ($year != "ALL") {
  6011. for($i = 1; $i <= 12; $i ++) {
  6012. if ($i == $month)
  6013. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  6014. else
  6015. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  6016. }
  6017. }
  6018. $this->data ['monthHtml'] = $monthHtml;
  6019. $this->data ['year'] = $year;
  6020. $this->data ['month'] = $month;
  6021. $this->data ['ics'] = $ics;
  6022. $this->data ['cidKey'] = $cidKey;
  6023. $this->data ['sid'] = $sid;
  6024. $this->data ['staffDetail'] = $staffDetail;
  6025. $this->data ['staffList'] = $staffList;
  6026. $this->data ['titleORnoEn'] = $titleORno;
  6027. $this->data ['titleORno'] = urlencode ( $titleORno );
  6028. $this->data ['invoiceDetail'] = array (
  6029. 'invoiceElement' => $invoiceElement
  6030. );
  6031. $this->data ['page'] = $pageinfo;
  6032. $this->data ['get'] = $get;
  6033. $this->data ['list'] = $list;
  6034. $this->data ['status'] = $status;
  6035. $this->data ['categoryList'] = $categoryList;
  6036. $this->data ['memu'] = "invoice";
  6037. $this->data ['staff'] = $this->staff;
  6038. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  6039. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  6040. }
  6041. /**
  6042. * 获取一条收款信息
  6043. */
  6044. function ajaxGetInvoiceReceivables() {
  6045. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  6046. Doo::loadModel ( 'invoiceReceivables' );
  6047. $invoiceReceivables = new invoiceReceivables ();
  6048. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  6049. echo json_encode ( array (
  6050. 'status' => 1,
  6051. 'detail' => $detail
  6052. ) );
  6053. }
  6054. /**
  6055. * 异步获取办事处用户
  6056. */
  6057. function ajaxGetStaffByCategory() {
  6058. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  6059. Doo::loadModel ( 'staff' );
  6060. $staff = new staff ();
  6061. if ($cid == "PUBLIC") {
  6062. echo json_encode ( array (
  6063. 'status' => 1,
  6064. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  6065. ) );
  6066. die ();
  6067. }
  6068. if (! is_numeric ( $cid )) {
  6069. echo json_encode ( array (
  6070. 'status' => 0,
  6071. 'msg' => 'illegal request'
  6072. ) );
  6073. die ();
  6074. }
  6075. $staffList = $staff->getStaffByCid ( $cid );
  6076. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6077. foreach ( $staffList as $key => $value ) {
  6078. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6079. }
  6080. echo json_encode ( array (
  6081. 'status' => 1,
  6082. 'html' => $html
  6083. ) );
  6084. }
  6085. /**
  6086. * 异步获取一条发票的邮寄信息
  6087. */
  6088. function ajaxGetInvoicePostDetail() {
  6089. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6090. Doo::loadModel ( 'invoice' );
  6091. $invoice = new invoice ();
  6092. $iid = $invoice->authcode ( $iid );
  6093. Doo::loadModel ( 'express' );
  6094. $express = new express ();
  6095. $expressList = $express->getExpressByAll ();
  6096. if (! is_numeric ( $iid )) {
  6097. echo json_encode ( array (
  6098. 'status' => 0,
  6099. 'msg' => 'illegal request'
  6100. ) );
  6101. die ();
  6102. }
  6103. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6104. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6105. $html = "";
  6106. foreach ( $expressList as $key => $value ) {
  6107. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6108. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6109. else
  6110. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6111. }
  6112. $invoiceDetail ['eaHtml'] = $html;
  6113. echo json_encode ( array (
  6114. 'status' => 1,
  6115. 'invoiceDetail' => $invoiceDetail
  6116. ) );
  6117. }
  6118. /**
  6119. *
  6120. * @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 ) ); }
  6121. */
  6122. /**
  6123. *
  6124. * @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 ) ); }
  6125. */
  6126. /**
  6127. * 我的收款中 选择哪个发票入账,进行金额判断
  6128. */
  6129. function ajaxCompareInvoicePrice() {
  6130. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6131. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6132. Doo::loadModel ( 'invoice' );
  6133. $invoice = new invoice ();
  6134. Doo::loadModel ( 'invoiceReceivables' );
  6135. $invoiceReceivables = new invoiceReceivables ();
  6136. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6137. $keyList = explode ( ';', $claimKey );
  6138. $receivablesPrice = 0;
  6139. foreach ( $keyList as $key => $value ) {
  6140. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6141. $receivablesPrice += $detailM ['receivablesPrice'];
  6142. }
  6143. if ($receivablesPrice > $detail ['invoicePrice']) {
  6144. $price = $receivablesPrice - $detail ['invoicePrice'];
  6145. echo json_encode ( array (
  6146. 'status' => 1,
  6147. 'price' => $price
  6148. ) );
  6149. } else
  6150. echo json_encode ( array (
  6151. 'status' => 2
  6152. ) );
  6153. }
  6154. /**
  6155. * 获得打印发票
  6156. */
  6157. function ajaxGetInvoiceInfoByPrint() {
  6158. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6159. if (empty ( $serial )) {
  6160. echo json_encode ( array (
  6161. 'status' => 2,
  6162. 'msg' => 'illegal request'
  6163. ) );
  6164. die ();
  6165. }
  6166. Doo::loadModel ( 'invoice' );
  6167. $invoice = new invoice ();
  6168. Doo::loadModel ( 'invoiceOperationLog' );
  6169. $invoiceOperationLog = new invoiceOperationLog ();
  6170. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6171. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6172. Doo::loadModel ( 'invoicePaper' );
  6173. $invoicePaper = new invoicePaper ();
  6174. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6175. if (empty ( $detail ))
  6176. $html = '';
  6177. else {
  6178. $html = '
  6179. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6180. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6181. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6182. <div class="modal-dialog modal-lg">
  6183. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6184. <div class="modal-body saeaList">
  6185. <table class="table table-bordered table-condensed"><tbody>
  6186. <tr>
  6187. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6188. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6189. </tr>
  6190. <tr>
  6191. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6192. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6193. </tr>
  6194. <tr>
  6195. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6196. </td>
  6197. </tr>
  6198. <tr>
  6199. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6200. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6201. </tr>
  6202. <tr>
  6203. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6204. </tr></tbody></table>';
  6205. if ($detail ['invoiceType'] == 0)
  6206. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6207. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6208. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6209. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6210. </tr>';
  6211. else
  6212. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6213. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6214. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6215. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6216. ';
  6217. $html .= '<tr>
  6218. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6219. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6220. </tr>
  6221. <tr>
  6222. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6223. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6224. </tr></tbody></table>';
  6225. if ($detail ['doPost'] == 1)
  6226. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6227. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6228. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6229. </tr><tr>
  6230. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6231. </tr><tr>
  6232. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6233. </tr></tbody></table>';
  6234. if (! empty ( $invoiceOperationLogList )) {
  6235. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6236. foreach ( $invoiceOperationLogList as $key => $value ) {
  6237. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6238. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6239. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6240. if ($value ['status'] == 2) {
  6241. $html .= '<span class="colGreen">同意</span>';
  6242. } elseif ($value ['status'] == 3) {
  6243. $html .= '<span class="colOrange">退回</span>';
  6244. } elseif ($value ['status'] == 5) {
  6245. $html .= '<span class="colGreen">打印</span>';
  6246. } elseif ($value ['status'] == 4) {
  6247. $html .= '<span class="colRed">终止</span>';
  6248. }
  6249. $html .= $value ['operation'] . '</p></blockquote>';
  6250. }
  6251. }
  6252. $html .= '</td>
  6253. <td><span class="colRed">*</span>
  6254. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6255. foreach ( $invoicePaperList as $key => $value ) {
  6256. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6257. }
  6258. $html .= '</select>
  6259. <span class="red" id="p-msg"></span>
  6260. </td>
  6261. </tr></tbody></table>';
  6262. }
  6263. $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>
  6264. </div></div></form>
  6265. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6266. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6267. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6268. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6269. ';
  6270. }
  6271. echo json_encode ( array (
  6272. 'status' => 1,
  6273. 'html' => $html
  6274. ) );
  6275. die ();
  6276. }
  6277. /**
  6278. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6279. */
  6280. function ajaxGetInvoiceInfoByType() {
  6281. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6282. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6283. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6284. if (empty ( $serial )) {
  6285. echo json_encode ( array (
  6286. 'status' => 2,
  6287. 'msg' => 'illegal request'
  6288. ) );
  6289. die ();
  6290. }
  6291. if ($type == 'INVOICE') {
  6292. Doo::loadModel ( 'invoice' );
  6293. $invoice = new invoice ();
  6294. Doo::loadModel ( 'invoiceOperationLog' );
  6295. $invoiceOperationLog = new invoiceOperationLog ();
  6296. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6297. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6298. if (empty ( $detail ))
  6299. $html = '';
  6300. else {
  6301. $html = '
  6302. <div class="modal-dialog modal-lg">
  6303. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6304. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6305. <tr>
  6306. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6307. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6308. </tr>
  6309. <tr>
  6310. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6311. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6312. </tr>
  6313. <tr>
  6314. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6315. </td>
  6316. </tr>
  6317. <tr>
  6318. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6319. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6320. </tr>
  6321. <tr>
  6322. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6323. </tr>';
  6324. if ($detail ['settlementType'] == 1)
  6325. $html .= '<tr>
  6326. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6327. </tr>';
  6328. else
  6329. $html .= '<tr>
  6330. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6331. </tr>';
  6332. $html .= ' </tbody></table>';
  6333. if ($detail ['invoiceType'] == 0){
  6334. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6335. <tr><th colspan="4" class="taC">增值税普通发票';
  6336. if($detail ['invoiceForm']==1){
  6337. $html .= '( <span class="colRed">电子发票</span> )';
  6338. }
  6339. $html .= '</th></tr><tr>
  6340. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6341. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6342. </tr>';
  6343. }else{
  6344. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6345. <tr><th colspan="4" class="taC">增值税专用发票';
  6346. if($detail ['invoiceForm']==1){
  6347. $html .= '( <span class="colRed">电子发票</span> )';
  6348. }
  6349. $html .= '</th></tr><tr>
  6350. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6351. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6352. ';
  6353. }
  6354. $html .= '<tr>
  6355. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6356. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6357. </tr>
  6358. <tr>
  6359. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6360. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6361. </tr></tbody></table>';
  6362. if ($detail ['doPost'] == 1) {
  6363. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6364. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6365. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6366. </tr><tr>
  6367. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6368. </tr><tr>
  6369. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6370. </tr>
  6371. ';
  6372. if ($detail ['expressCom'] == 'SF')
  6373. $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>';
  6374. else
  6375. $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>';
  6376. $html .= '</tbody></table>';
  6377. }
  6378. if ($detail ['invoiceForm'] == 1) {
  6379. $html .= '<table class="table table-bordered table-condensed">
  6380. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6381. <tr>
  6382. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6383. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6384. </tr></tbody></table>';
  6385. }
  6386. if (! empty ( $invoiceOperationLogList )) {
  6387. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6388. foreach ( $invoiceOperationLogList as $key => $value ) {
  6389. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6390. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6391. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6392. if ($value ['status'] == 2) {
  6393. $html .= '<span class="colGreen">同意</span>';
  6394. } elseif ($value ['status'] == 3) {
  6395. $html .= '<span class="colOrange">退回</span>';
  6396. } elseif ($value ['status'] == 5) {
  6397. $html .= '<span class="colGreen">打印</span>';
  6398. } elseif ($value ['status'] == 4) {
  6399. $html .= '<span class="colRed">终止</span>';
  6400. }
  6401. $html .= $value ['operation'] . '</p></blockquote>';
  6402. }
  6403. }
  6404. $html .= '</td></tr></tbody></table>';
  6405. }
  6406. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6407. }
  6408. echo json_encode ( array (
  6409. 'status' => 1,
  6410. 'html' => $html
  6411. ) );
  6412. die ();
  6413. } elseif ($type == 'RECEIVABLES') {
  6414. Doo::loadModel ( 'invoiceReceivables' );
  6415. $invoiceReceivables = new invoiceReceivables ();
  6416. Doo::loadModel ( 'invoiceRefund' );
  6417. $invoiceRefund = new invoiceRefund ();
  6418. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6419. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6420. if (empty ( $detail ))
  6421. $html = '';
  6422. else {
  6423. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6424. <table class="table table-bordered table-condensed">
  6425. <tbody><tr>
  6426. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6427. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6428. </tr><tr>
  6429. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6430. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6431. </tr>
  6432. <tr>
  6433. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6434. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6435. </tr>
  6436. <tr>
  6437. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6438. </tr>
  6439. </tbody></table>';
  6440. if (! empty ( $ireList )) {
  6441. $html .= '
  6442. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6443. <tr>
  6444. <th class="taC">退款单位名称</th>
  6445. <th class="taC">退款的账号</th>
  6446. <th class="taC">退款金额</th>
  6447. <th class="taC">退款</th>
  6448. <th class="taC">备注</th>
  6449. </tr>
  6450. ';
  6451. foreach ( $ireList as $key => $value ) {
  6452. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6453. $html .= '<tr>
  6454. <td>' . $value ['refundCompany'] . '</td>
  6455. <td>' . $value ['refundNumber'] . '</td>
  6456. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6457. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6458. <td>' . $value ['refundRemarks'] . '</td>
  6459. </tr>
  6460. ';
  6461. }
  6462. }
  6463. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6464. }
  6465. echo json_encode ( array (
  6466. 'status' => 1,
  6467. 'html' => $html
  6468. ) );
  6469. die ();
  6470. } elseif ($type == 'IRTC') {
  6471. Doo::loadModel ( 'invoice' );
  6472. $invoice = new invoice ();
  6473. Doo::loadModel ( 'invoiceOperationLog' );
  6474. $invoiceOperationLog = new invoiceOperationLog ();
  6475. // Doo::loadModel ( 'invoiceReceivables' );
  6476. // $invoiceReceivables = new invoiceReceivables ();
  6477. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6478. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6479. if (empty ( $detail ))
  6480. $html = '';
  6481. else {
  6482. $receivablesPriceedHtml = '';
  6483. $receivablesPrice = $detail ['invoicePrice'];
  6484. if (! empty ( $detail ['irid'] )) {
  6485. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6486. // if (empty ( $irList ))
  6487. // $irList [0] ['sumPrice'] = 0;
  6488. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6489. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6490. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6491. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6492. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6493. </tr></tbody></table>';
  6494. $receivablesPrice = $detail ['invoiceBalance'];
  6495. }
  6496. if ($loss)
  6497. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6498. $html = $receivablesPriceedHtml . '
  6499. <table class="table table-bordered table-condensed"><tbody>
  6500. <tr>
  6501. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6502. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6503. </tr>
  6504. <tr>
  6505. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6506. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6507. </tr>
  6508. <tr>
  6509. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6510. </tr>
  6511. <tr>
  6512. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6513. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6514. </tr>
  6515. <tr>
  6516. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6517. </tr></tbody></table>';
  6518. if ($detail ['invoiceType'] == 0) {
  6519. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6520. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6521. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6522. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6523. </tr>';
  6524. $receivablesMessage = $detail ['invoiceTitle'];
  6525. } else {
  6526. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6527. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6528. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6529. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6530. ';
  6531. $receivablesMessage = $detail ['invoiceCompany'];
  6532. }
  6533. $html .= '<tr>
  6534. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6535. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6536. </tr>
  6537. <tr>
  6538. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6539. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6540. </tr></tbody></table>';
  6541. if ($detail ['doPost'] == 1)
  6542. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6543. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6544. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6545. </tr><tr>
  6546. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6547. </tr><tr>
  6548. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6549. </tr></tbody></table>';
  6550. if (! empty ( $invoiceOperationLogList )) {
  6551. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6552. foreach ( $invoiceOperationLogList as $key => $value ) {
  6553. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6554. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6555. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6556. if ($value ['status'] == 2) {
  6557. $html .= '<span class="colGreen">同意</span>';
  6558. } elseif ($value ['status'] == 3) {
  6559. $html .= '<span class="colOrange">退回</span>';
  6560. } elseif ($value ['status'] == 5) {
  6561. $html .= '<span class="colGreen">打印</span>';
  6562. }
  6563. $html .= $value ['operation'] . '</p></blockquote>';
  6564. }
  6565. }
  6566. $html .= '</td></tr></tbody></table>';
  6567. }
  6568. }
  6569. echo json_encode ( array (
  6570. 'status' => 1,
  6571. 'html' => $html,
  6572. 'receivablesPrice' => $receivablesPrice,
  6573. 'receivablesMessage' => $receivablesMessage,
  6574. 'receivablesDate' => date ( "Y-m-d" ),
  6575. 'iidKey' => $serial
  6576. ) );
  6577. die ();
  6578. }
  6579. }
  6580. function ajaxGetInvoiceReceivablesByStaff() {
  6581. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6582. if (empty ( $postData )) {
  6583. echo json_encode ( array (
  6584. 'status' => 2,
  6585. 'msg' => 'illegal request'
  6586. ) );
  6587. die ();
  6588. }
  6589. Doo::loadModel ( 'invoiceReceivables' );
  6590. $invoiceReceivables = new invoiceReceivables ();
  6591. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6592. if (empty ( $detail )) {
  6593. echo json_encode ( array (
  6594. 'status' => 2,
  6595. 'msg' => 'illegal request'
  6596. ) );
  6597. die ();
  6598. }
  6599. Doo::loadModel ( 'L_category' );
  6600. $lCategory = new L_category ();
  6601. Doo::loadModel ( 'staff' );
  6602. $staff = new staff ();
  6603. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6604. $category = $lCategory->getCategory ();
  6605. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6606. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6607. foreach ( $category as $key => $value ) {
  6608. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6609. if ($value ['cid'] == $detail ['cid'])
  6610. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6611. }
  6612. foreach ( $staffList as $key => $value ) {
  6613. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6614. if ($value ['sid'] == $detail ['sid'])
  6615. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6616. }
  6617. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6618. echo json_encode ( array (
  6619. 'status' => 1,
  6620. 'categoryHtml' => $categoryHtml,
  6621. 'staffHtml' => $staffHtml,
  6622. 'rbankHtml' => $rbankHtml,
  6623. 'detail' => $detail
  6624. ) );
  6625. }
  6626. function ajaxGetInvoiceReceivablesByIrid() {
  6627. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6628. if (empty ( $irid )) {
  6629. echo json_encode ( array (
  6630. 'status' => 2,
  6631. 'msg' => 'illegal request'
  6632. ) );
  6633. die ();
  6634. }
  6635. Doo::loadModel ( 'invoiceReceivables' );
  6636. $invoiceReceivables = new invoiceReceivables ();
  6637. Doo::loadModel ( 'invoice' );
  6638. $invoice = new invoice ();
  6639. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6640. $flag = true;
  6641. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6642. $bakDetail = array ();
  6643. if ($flag === false) {
  6644. array_push ( $bakDetail, $invoiceDetail );
  6645. $invoiceDetail = $bakDetail;
  6646. }
  6647. $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>
  6648. <tr>
  6649. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6650. <td>' . $detail ['receivablesMessage'] . '</td>
  6651. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6652. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6653. <td>' . $detail ['recepitTitleMark'] . '</td>
  6654. </tr></tbody></table>';
  6655. $isInvoice = false;
  6656. $invoiceHtml = '';
  6657. if (empty ( $invoiceDetail )) {
  6658. $isInvoice = true;
  6659. } else {
  6660. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6661. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6662. foreach ( $invoiceDetail as $key => $value ) {
  6663. $invoiceHtml .= '<tr>';
  6664. if (! empty ( $value ['invoiceType'] )) {
  6665. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6666. } else {
  6667. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6668. }
  6669. if (! empty ( $value ['invoiceType'] )) {
  6670. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6671. } else {
  6672. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6673. }
  6674. $invoiceHtml .= '
  6675. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6676. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6677. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6678. </tr>
  6679. ';
  6680. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6681. if (empty ( $irList ))
  6682. $irList [0] ['sumPrice'] = 0;
  6683. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6684. $priceString = '';
  6685. if ($balance < $detail ['receivablesPrice']) {
  6686. $priceString = '收款金额超过开票金额,';
  6687. }
  6688. if ($balance > $detail ['receivablesPrice']) {
  6689. $priceString = '收款金额低于开票金额,';
  6690. }
  6691. }
  6692. $invoiceHtml .= '
  6693. <script>
  6694. $(\'a[bind-receivables^="ir"]\').click(function() {
  6695. var data = $(this).attr("data-ikey");
  6696. $("input[name=\'invoiceKey\']").val(data);
  6697. var invoiceKey=data;
  6698. if(invoiceKey==""){
  6699. alert("入账错误,请重新刷新页面");
  6700. return false;
  6701. }
  6702. if(window.confirm("' . $priceString . '确定入账吗?")){
  6703. $("#IBR").submit();
  6704. }else{
  6705. return false;
  6706. }
  6707. });
  6708. </script>
  6709. ';
  6710. $invoiceHtml .= '</tbody></table>';
  6711. }
  6712. echo json_encode ( array (
  6713. 'status' => 1,
  6714. 'irkey' => $detail ['iridEn'],
  6715. 'receivablesHtml' => $receivablesHtml,
  6716. 'isInvoice' => $isInvoice,
  6717. 'invoiceHtml' => $invoiceHtml
  6718. ) );
  6719. }
  6720. function ajaxGetInvoiceReceivablesByTitle() {
  6721. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6722. if (empty ( $title )) {
  6723. echo json_encode ( array (
  6724. 'status' => 2,
  6725. 'msg' => 'illegal request'
  6726. ) );
  6727. die ();
  6728. }
  6729. Doo::loadModel ( 'invoice' );
  6730. $invoice = new invoice ();
  6731. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6732. $invoiceHtml = '';
  6733. if (! empty ( $invoiceDetail )) {
  6734. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6735. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6736. foreach ( $invoiceDetail as $key => $value ) {
  6737. if (! empty ( $value ['invoiceType'] )) {
  6738. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6739. } else {
  6740. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6741. }
  6742. if (! empty ( $value ['invoiceType'] )) {
  6743. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6744. } else {
  6745. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6746. }
  6747. $invoiceHtml .= '
  6748. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6749. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6750. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6751. </tr>
  6752. ';
  6753. }
  6754. $invoiceHtml .= '</tbody></table>
  6755. <script>
  6756. $(\'a[bind-receivables^="ir"]\').click(function() {
  6757. var data = $(this).attr("data-ikey");
  6758. $("input[name=\'invoiceKey\']").val(data);
  6759. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6760. if(invoiceKey==""){
  6761. alert("入账错误,请重新刷新页面");
  6762. return false;
  6763. }
  6764. if(window.confirm("确定入账吗?")){
  6765. $("#IBR").submit();
  6766. }else{
  6767. return false;
  6768. }
  6769. });
  6770. </script>
  6771. ';
  6772. }
  6773. echo json_encode ( array (
  6774. 'status' => 1,
  6775. 'invoiceHtml' => $invoiceHtml
  6776. ) );
  6777. }
  6778. function ajaxInvoicePushNotice() {
  6779. Doo::loadModel ( 'invoice' );
  6780. $invoice = new invoice ();
  6781. $approval = $invoice->getOne ( array (
  6782. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6783. 'desc' => 'iid',
  6784. 'asArray' => true
  6785. ) );
  6786. $isNotice = false;
  6787. if (! empty ( $approval ))
  6788. $isNotice = true;
  6789. $response = array (
  6790. 'error' => 0,
  6791. 'isNotice' => $isNotice
  6792. );
  6793. echo json_encode ( $response );
  6794. exit ();
  6795. }
  6796. public function ajaxCheckInvoiceNoUniqueness() {
  6797. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6798. Doo::loadModel ( 'invoice' );
  6799. $invoice = new invoice ();
  6800. if (! empty ( $invoiceNo )) {
  6801. Doo::loadModel ( 'invoicePaper' );
  6802. $invoicePaper = new invoicePaper ();
  6803. Doo::loadClass ( 'XDeode' );
  6804. $XDeode = new XDeode ( 5 );
  6805. $ipid = $XDeode->decode ( $invoiceNo );
  6806. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6807. $info = $invoice->getOne ( array (
  6808. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6809. 'asArray' => TRUE
  6810. ) );
  6811. if (! empty ( $info )) {
  6812. echo json_encode ( array (
  6813. 'error' => '发票号已存在'
  6814. ) );
  6815. die ();
  6816. } else
  6817. echo json_encode ( array (
  6818. 'ok' => '可以使用!'
  6819. ) );
  6820. die ();
  6821. }
  6822. }
  6823. function ajaxCheckInvoicePrice() {
  6824. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6825. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6826. Doo::loadModel ( 'invoice' );
  6827. $invoice = new invoice ();
  6828. Doo::loadModel ( 'invoiceReceivables' );
  6829. $invoiceReceivables = new invoiceReceivables ();
  6830. Doo::loadClass ( 'XDeode' );
  6831. $XDeode = new XDeode ( 5 );
  6832. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6833. $iidKey = $XDeode->decode ( $iidKey );
  6834. $info = $invoice->getInvoiceByIid ( $iidKey );
  6835. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6836. if (empty ( $irList ))
  6837. $irList [0] ['sumPrice'] = 0;
  6838. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6839. if ($balance < $receivablesPrice) {
  6840. echo json_encode ( array (
  6841. 'error' => '收款金额超过开票金额。'
  6842. ) );
  6843. die ();
  6844. }
  6845. if ($balance > $receivablesPrice) {
  6846. echo json_encode ( array (
  6847. 'error' => '收款金额低于开票金额。'
  6848. ) );
  6849. die ();
  6850. }
  6851. }
  6852. }
  6853. function ajaxGetInvoiceByNew() {
  6854. Doo::loadModel ( 'invoice' );
  6855. $invoice = new invoice ();
  6856. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6857. echo json_encode ( array (
  6858. 'status' => 1,
  6859. 'detail' => $detail
  6860. ) );
  6861. }
  6862. /**
  6863. * 旧输入导入
  6864. */
  6865. function importInvoice() {
  6866. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6867. $data ['emsg'] = "";
  6868. if ($emsg != "")
  6869. $data ['emsg'] = "请填写完整的数据";
  6870. $data ['time'] = time ();
  6871. $this->render ( "/admin/invoiceImport", $data );
  6872. }
  6873. function uploadInvoice() {
  6874. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6875. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6876. $file = $_FILES ['Filedata'] ['tmp_name'];
  6877. $error = false;
  6878. if (! is_uploaded_file ( $file )) {
  6879. $error = '400 Bad Request';
  6880. }
  6881. if ($error) {
  6882. header ( 'HTTP/1.0 ' . $error );
  6883. die ( 'Error ' . $error );
  6884. } else {
  6885. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6886. $this->IoHandler = new IoHandler ();
  6887. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6888. // $filedir=$_POST['time'];
  6889. // 调用定义物理路径
  6890. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6891. $this->IoHandler->MakeDir ( $t );
  6892. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6893. if ($filename != 'xlsx')
  6894. return "";
  6895. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6896. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6897. $upload_dir = $t . "/" . $upload_file;
  6898. $k = move_uploaded_file ( $file, $upload_dir );
  6899. if ($k) {
  6900. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6901. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6902. }
  6903. }
  6904. }
  6905. }
  6906. function importInvoiceDo() {
  6907. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6908. if ($path != "") {
  6909. Doo::loadModel ( 'invoice' );
  6910. Doo::loadModel ( 'staff' );
  6911. $staff = new staff ();
  6912. Doo::loadModel ( 'invoiceStatistics' );
  6913. Doo::loadModel ( 'invoiceOperationLog' );
  6914. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6915. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6916. // print_r ( $exlArray );
  6917. // die ();
  6918. // echo json_encode($exlArray);die;
  6919. foreach ( $exlArray as $key => $value ) {
  6920. // 开票
  6921. $invoice = new invoice ();
  6922. $invoice->invoiceNo = $value ['invoiceNo'];
  6923. $invoice->invoiceType = 0;
  6924. if ($value ['invoiceType'] == '专')
  6925. $invoice->invoiceType = 1;
  6926. $invoice->invoicePrice = $value ['invoicePrice'];
  6927. $invoice->invoiceQuantity = 1;
  6928. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6929. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6930. if ($value ['invoiceType'] == '专')
  6931. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6932. $invoice->userName = $value ['userName'];
  6933. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6934. $invoice->sid = $sDetail ['sid'];
  6935. $invoice->cid = $sDetail ['cid'];
  6936. $invoice->categoryName = $sDetail ['category'];
  6937. $invoice->invoiceElement = $value ['invoiceElement'];
  6938. $invoice->remark = $value ['remark'];
  6939. $invoice->date = $value ['date'];
  6940. $invoice->printTime = $value ['date'];
  6941. $invoice->ipSource = 1;
  6942. $invoice->printStatus = 1;
  6943. $invoice->status = 2;
  6944. $invoice->postStatus = 1;
  6945. $invoice->untreadStatus = 0;
  6946. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6947. $iid = $invoice->insert ();
  6948. // 汇总
  6949. $invoiceStatistics = new invoiceStatistics ();
  6950. //
  6951. $item = array (
  6952. 'date' => $value ['date'],
  6953. 'priceClass' => 1,
  6954. 'cid' => $sDetail ['cid'],
  6955. 'staff' => $sDetail ['sid'],
  6956. 'invoicePrice' => $value ['invoicePrice']
  6957. );
  6958. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6959. $invoiceOperationLog = new invoiceOperationLog ();
  6960. $item = array (
  6961. 'date' => date ( "Y-m-d H:i:s" ),
  6962. 'operation' => date ( "Y-m-d" ) . " 导入",
  6963. 'status' => 1,
  6964. 'img' => $sDetail ['avatar'],
  6965. 'username' => $sDetail ['username'],
  6966. 'uid' => $sDetail ['sid'],
  6967. 'category' => $sDetail ['category'],
  6968. 'iid' => $iid
  6969. );
  6970. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6971. }
  6972. return '/importInvoice?count=' . count ( $exlArray );
  6973. // return "/keyonline";
  6974. }
  6975. echo 'no file';
  6976. }
  6977. function importInvoiceReceivables() {
  6978. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6979. $data ['emsg'] = "";
  6980. if ($emsg != "")
  6981. $data ['emsg'] = "请填写完整的数据";
  6982. $data ['time'] = time ();
  6983. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6984. }
  6985. // 导入入账数据
  6986. function importInvoiceReceivablesDo() {
  6987. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6988. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6989. if ($path != "") {
  6990. Doo::loadModel ( 'invoiceReceivables' );
  6991. Doo::loadModel ( 'invoice' );
  6992. Doo::loadModel ( 'staff' );
  6993. $staff = new staff ();
  6994. Doo::loadModel ( 'invoiceStatistics' );
  6995. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6996. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6997. // print_r ( $exlArray );
  6998. // die ();
  6999. // echo json_encode($exlArray);die;
  7000. foreach ( $exlArray as $key => $value ) {
  7001. // 收款
  7002. $invoiceReceivables = new invoiceReceivables ();
  7003. $invoice = new invoice ();
  7004. $invoiceReceivables->bindStatus = 1;
  7005. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  7006. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  7007. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  7008. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  7009. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  7010. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  7011. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  7012. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  7013. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  7014. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  7015. $invoiceReceivables->iid = $iDetail ['iid'];
  7016. $irid = $invoiceReceivables->insert ();
  7017. // 发票绑定收款
  7018. $detail = $iDetail;
  7019. $iridString = "";
  7020. if (empty ( $detail ['irid'] ))
  7021. $iridString = $irid;
  7022. else
  7023. $iridString = $detail ['irid'] . ',' . $irid;
  7024. $item = array (
  7025. 'irid' => $iridString,
  7026. 'iid' => $detail ['iid']
  7027. );
  7028. $invoice->setInvoiceByCondition ( $item );
  7029. // 汇总
  7030. $invoiceStatistics = new invoiceStatistics ();
  7031. // 扣除入账统计金额
  7032. $item = array (
  7033. 'date' => $value ['receivablesDate'],
  7034. 'priceClass' => 3,
  7035. 'cid' => $sDetail ['cid'],
  7036. 'staff' => $sDetail ['sid'],
  7037. // 'irid' => $irid,
  7038. 'accountPrice' => $value ['receivablesPrice']
  7039. );
  7040. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7041. }
  7042. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  7043. echo 'data count ' . count ( $exlArray );
  7044. die ();
  7045. // return "/keyonline";
  7046. }
  7047. echo 'no file';
  7048. }
  7049. function formatExcelToArrayTrain($file_url = "") {
  7050. if (! file_exists ( $file_url )) {
  7051. return array ();
  7052. }
  7053. // Doo::loadClass ( 'PHPExcel' );
  7054. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7055. $PHPExcel = new PHPExcel ();
  7056. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7057. if (! $PHPReader->canRead ( $file_url )) {
  7058. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7059. if (! $PHPReader->canRead ( $file_url )) {
  7060. echo 'no Excel';
  7061. return;
  7062. }
  7063. }
  7064. $PHPExcel = $PHPReader->load ( $file_url );
  7065. /* * 读取excel文件中的第一个工作表 */
  7066. $currentSheet = $PHPExcel->getSheet ( 0 );
  7067. /* * 取得最大的列号 */
  7068. $allColumn = $currentSheet->getHighestColumn ();
  7069. /* * 取得一共有多少行 */
  7070. $allRow = $currentSheet->getHighestRow ();
  7071. $excel_array = array ();
  7072. // die($file_url);
  7073. $conk = 2;
  7074. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7075. $excel_column = array ();
  7076. // 后期改进
  7077. if ($allColumn == 'AM')
  7078. $allColumn = 'Z';
  7079. /* * 从第A列开始输出 */
  7080. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7081. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7082. if ($val instanceof PHPExcel_RichText)
  7083. $val = $val->__toString ();
  7084. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7085. // $val = "'" . addslashes ( $val ) . "'";
  7086. if ($currentColumn == 'A') {
  7087. $excel_column ['invoiceTitle'] = $val;
  7088. } elseif ($currentColumn == 'B')
  7089. $excel_column ['invoiceType'] = $val;
  7090. elseif ($currentColumn == 'C') {
  7091. $excel_column ['TIN'] = $val;
  7092. } elseif ($currentColumn == 'D') {
  7093. $excel_column ['address'] = $val;
  7094. } elseif ($currentColumn == 'E') {
  7095. $excel_column ['phone'] = $val;
  7096. } elseif ($currentColumn == 'F') {
  7097. $excel_column ['bank'] = $val;
  7098. } elseif ($currentColumn == 'G') {
  7099. $excel_column ['bankAccount'] = $val;
  7100. } elseif ($currentColumn == 'H') {
  7101. $excel_column ['invoiceElement'] = $val;
  7102. } elseif ($currentColumn == 'I') {
  7103. $excel_column ['invoiceQuantity'] = $val;
  7104. } elseif ($currentColumn == 'J') {
  7105. $excel_column ['invoiceUnitPrice'] = $val;
  7106. } elseif ($currentColumn == 'K') {
  7107. $excel_column ['remark'] = $val;
  7108. } elseif ($currentColumn == 'L') {
  7109. $excel_column ['recipientsAddress'] = $val;
  7110. } elseif ($currentColumn == 'M') {
  7111. $excel_column ['recipients'] = $val;
  7112. } elseif ($currentColumn == 'N') {
  7113. $excel_column ['recipientsPhone'] = $val;
  7114. }elseif ($currentColumn == 'O') {
  7115. $excel_column ['electronicPhone'] = $val;
  7116. } elseif ($currentColumn == 'P') {
  7117. $excel_column ['electronicEmail'] = $val;
  7118. }
  7119. }
  7120. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7121. array_push ( $excel_array, $excel_column );
  7122. }
  7123. return $excel_array;
  7124. }
  7125. /**
  7126. * 格式化excel文件为数组
  7127. * @param unknown_type $file_url
  7128. * @param unknown_type $mcid
  7129. */
  7130. function _format_excel_to_array($file_url = "", $sType = "") {
  7131. if (! file_exists ( $file_url )) {
  7132. return array ();
  7133. }
  7134. Doo::loadClass ( 'PHPExcel' );
  7135. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7136. $PHPExcel = new PHPExcel ();
  7137. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7138. if (! $PHPReader->canRead ( $file_url )) {
  7139. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7140. if (! $PHPReader->canRead ( $file_url )) {
  7141. echo 'no Excel';
  7142. return;
  7143. }
  7144. }
  7145. $PHPExcel = $PHPReader->load ( $file_url );
  7146. /* * 读取excel文件中的第一个工作表 */
  7147. $currentSheet = $PHPExcel->getSheet ( 0 );
  7148. /* * 取得最大的列号 */
  7149. $allColumn = $currentSheet->getHighestColumn ();
  7150. /* * 取得一共有多少行 */
  7151. $allRow = $currentSheet->getHighestRow ();
  7152. $excel_array = array ();
  7153. // die($file_url);
  7154. $conk = 2;
  7155. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7156. $excel_column = array ();
  7157. // 后期改进
  7158. if ($allColumn == 'AM')
  7159. $allColumn = 'Z';
  7160. /* * 从第A列开始输出 */
  7161. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7162. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7163. if ($val instanceof PHPExcel_RichText)
  7164. $val = $val->__toString ();
  7165. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7166. // $val = "'" . addslashes ( $val ) . "'";
  7167. if ($sType == 'invoiceReceivables') {
  7168. if ($currentColumn == 'A')
  7169. $excel_column ['invoiceNo'] = $val;
  7170. elseif ($currentColumn == 'B')
  7171. $excel_column ['receivablesPrice'] = $val;
  7172. elseif ($currentColumn == 'C') {
  7173. $excel_column ['receivablesMessage'] = $val;
  7174. } elseif ($currentColumn == 'D') {
  7175. $excel_column ['receivablesBank'] = $val;
  7176. } elseif ($currentColumn == 'E') {
  7177. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7178. } elseif ($currentColumn == 'F') {
  7179. $excel_column ['receivablesStaff'] = $val;
  7180. } elseif ($currentColumn == 'G') {
  7181. $excel_column ['sourcePrice'] = $val;
  7182. }
  7183. } elseif ($sType == "invoiceTrain") {
  7184. if ($currentColumn == 'A') {
  7185. $excel_column ['invoiceTitle'] = $val;
  7186. } elseif ($currentColumn == 'B')
  7187. $excel_column ['invoiceType'] = $val;
  7188. elseif ($currentColumn == 'C') {
  7189. $excel_column ['TIN'] = $val;
  7190. } elseif ($currentColumn == 'D') {
  7191. $excel_column ['address'] = $val;
  7192. } elseif ($currentColumn == 'E') {
  7193. $excel_column ['phone'] = $val;
  7194. } elseif ($currentColumn == 'F') {
  7195. $excel_column ['bank'] = $val;
  7196. } elseif ($currentColumn == 'G') {
  7197. $excel_column ['bankAccount'] = $val;
  7198. } elseif ($currentColumn == 'H') {
  7199. $excel_column ['invoiceElement'] = $val;
  7200. } elseif ($currentColumn == 'I') {
  7201. $excel_column ['invoiceQuantity'] = $val;
  7202. } elseif ($currentColumn == 'J') {
  7203. $excel_column ['invoiceUnitPrice'] = $val;
  7204. } elseif ($currentColumn == 'K') {
  7205. $excel_column ['remark'] = $val;
  7206. } elseif ($currentColumn == 'L') {
  7207. $excel_column ['recipientsAddress'] = $val;
  7208. } elseif ($currentColumn == 'M') {
  7209. $excel_column ['recipients'] = $val;
  7210. } elseif ($currentColumn == 'N') {
  7211. $excel_column ['recipientsPhone'] = $val;
  7212. }
  7213. } else {
  7214. if ($currentColumn == 'A')
  7215. $excel_column ['invoiceNo'] = $val;
  7216. elseif ($currentColumn == 'B')
  7217. $excel_column ['invoiceType'] = $val;
  7218. elseif ($currentColumn == 'C') {
  7219. $excel_column ['invoicePrice'] = $val;
  7220. } elseif ($currentColumn == 'D') {
  7221. $excel_column ['invoiceTitle'] = $val;
  7222. } elseif ($currentColumn == 'E') {
  7223. $excel_column ['userName'] = $val;
  7224. } elseif ($currentColumn == 'F') {
  7225. $excel_column ['categoryName'] = $val;
  7226. } elseif ($currentColumn == 'G') {
  7227. $excel_column ['invoiceElement'] = $val;
  7228. } elseif ($currentColumn == 'H') {
  7229. $excel_column ['remark'] = $val;
  7230. } elseif ($currentColumn == 'I') {
  7231. $excel_column ['date'] = $this->excelTime ( $val );
  7232. }
  7233. }
  7234. }
  7235. array_push ( $excel_array, $excel_column );
  7236. }
  7237. return $excel_array;
  7238. }
  7239. function excelTime($date, $time = false) {
  7240. if (function_exists ( 'GregorianToJD' )) {
  7241. if (is_numeric ( $date )) {
  7242. $jd = GregorianToJD ( 1, 1, 1970 );
  7243. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7244. $date = explode ( '/', $gregorian );
  7245. $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" : '');
  7246. return $date_str;
  7247. }
  7248. } else {
  7249. $date = $date > 25568 ? $date + 1 : 25569;
  7250. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7251. $ofs = (70 * 365 + 17 + 2) * 86400;
  7252. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7253. }
  7254. return $date;
  7255. }
  7256. /**
  7257. * 旧输入导入
  7258. */
  7259. function _GetFileEXT($filename) {
  7260. $pics = explode ( '.', $filename );
  7261. $num = count ( $pics );
  7262. return $pics [$num - 1];
  7263. }
  7264. function showCache($path = "", $sid = 0) {
  7265. // if (file_exists ( $path )) {
  7266. // $htm = file_get_contents ( $path );
  7267. // } else {
  7268. Doo::loadModel ( 'invoiceStatistics' );
  7269. $invoiceStatistics = new invoiceStatistics ();
  7270. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7271. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7272. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7273. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7274. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7275. /*
  7276. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7277. */
  7278. file_put_contents ( $path, $htm );
  7279. // }
  7280. return $htm;
  7281. }
  7282. /**
  7283. * 生成token
  7284. * @return string
  7285. */
  7286. function set_token() {
  7287. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7288. $str = sha1 ( $str ); // 加密
  7289. return $str;
  7290. }
  7291. /**
  7292. * 获取get或者POST值
  7293. *
  7294. * @param string $name 属性名称
  7295. * @return fixed 值
  7296. */
  7297. function get_args($name) {
  7298. if (isset ( $_GET [$name] )) {
  7299. if (is_array ( $_GET [$name] ))
  7300. return $_GET [$name];
  7301. else
  7302. return addslashes ( $_GET [$name] );
  7303. } elseif (isset ( $_POST [$name] )) {
  7304. if (is_array ( $_POST [$name] ))
  7305. return $_POST [$name];
  7306. else
  7307. return addslashes ( $_POST [$name] );
  7308. } else
  7309. return false;
  7310. }
  7311. function SafeFilter(&$arr) {
  7312. $ra = Array (
  7313. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7314. '/script/',
  7315. '/javascript/',
  7316. '/vbscript/',
  7317. '/expression/',
  7318. '/applet/',
  7319. '/meta/',
  7320. '/xml/',
  7321. '/blink/',
  7322. '/link/',
  7323. '/style/',
  7324. '/embed/',
  7325. '/object/',
  7326. '/frame/',
  7327. '/layer/',
  7328. '/title/',
  7329. '/bgsound/',
  7330. '/base/',
  7331. '/onload/',
  7332. '/onunload/',
  7333. '/onchange/',
  7334. '/onsubmit/',
  7335. '/onreset/',
  7336. '/onselect/',
  7337. '/onblur/',
  7338. '/onfocus/',
  7339. '/onabort/',
  7340. '/onkeydown/',
  7341. '/onkeypress/',
  7342. '/onkeyup/',
  7343. '/onclick/',
  7344. '/ondblclick/',
  7345. '/onmousedown/',
  7346. '/onmousemove/',
  7347. '/onmouseout/',
  7348. '/onmouseover/',
  7349. '/onmouseup/',
  7350. '/onunload/'
  7351. );
  7352. if (is_array ( $arr )) {
  7353. foreach ( $arr as $key => $value ) {
  7354. if (! is_array ( $value )) {
  7355. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7356. {
  7357. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7358. }
  7359. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7360. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7361. } else {
  7362. SafeFilter ( $arr [$key] );
  7363. }
  7364. }
  7365. }
  7366. }
  7367. /**
  7368. * Escape String
  7369. *
  7370. * @access public
  7371. * @param string
  7372. * @param bool whether or not the string will be used in a LIKE condition
  7373. * @return string
  7374. */
  7375. function escape_str($str, $like = FALSE) {
  7376. if (is_array ( $str )) {
  7377. foreach ( $str as $key => $val ) {
  7378. $str [$key] = $this->escape_str ( $val, $like );
  7379. }
  7380. return $str;
  7381. }
  7382. var_dump ( Doo::db ()->getDbObject () );
  7383. die ();
  7384. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7385. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7386. } elseif (function_exists ( 'mysql_escape_string' )) {
  7387. $str = mysql_escape_string ( $str );
  7388. } else {
  7389. $str = addslashes ( $str );
  7390. }
  7391. // escape LIKE condition wildcards
  7392. if ($like === TRUE) {
  7393. $str = str_replace ( array (
  7394. '%',
  7395. '_'
  7396. ), array (
  7397. '\\%',
  7398. '\\_'
  7399. ), $str );
  7400. }
  7401. return $str;
  7402. }
  7403. /**
  7404. * 获得分页数据
  7405. * @param unknown_type $table
  7406. * @param unknown_type $condition
  7407. * @param unknown_type $on_page
  7408. * @param unknown_type $page_size
  7409. */
  7410. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7411. $page_c = "";
  7412. $page ['previous'] = $this->get_previous ( $on_page );
  7413. $page ['on_page'] = $on_page;
  7414. $total_count = $this->get_table_count ( $table, $condition );
  7415. $total = intval ( $total_count / $page_size );
  7416. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7417. $page ['total_data'] = $total_count;
  7418. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7419. $i = 1;
  7420. $page_max = 1;
  7421. $page_width = 3;
  7422. if ($on_page >= $page_width) {
  7423. $page_max = intval ( $on_page / $page_width ) + 1;
  7424. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7425. }
  7426. for(; $i <= $page ['total_page']; $i ++) {
  7427. if ($i == $on_page)
  7428. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7429. else
  7430. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7431. if ($i == ($page_width * $page_max))
  7432. break;
  7433. }
  7434. $page ['page'] = $page_c;
  7435. $page ['lower'] = (-- $on_page) * $page_size;
  7436. return $page;
  7437. }
  7438. /**
  7439. * 获取上一页
  7440. * @param unknown_type $on_page
  7441. */
  7442. function get_previous($on_page = 1) {
  7443. return $on_page != 0 ? $on_page - 1 : $on_page;
  7444. }
  7445. /**
  7446. * 获取总页数
  7447. * @param unknown_type $table
  7448. * @param unknown_type $condition
  7449. */
  7450. public function get_table_count($table = "", $condition = "") {
  7451. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7452. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7453. // echo $sql;die;
  7454. $query = Doo::db ()->query ( $sql );
  7455. $result = $query->fetch ();
  7456. return $result ['count'];
  7457. }
  7458. function isInvoiceNew($type = "GLOBAL") {
  7459. Doo::loadModel ( 'invoice' );
  7460. $invoice = new invoice ();
  7461. Doo::loadModel ( 'invoiceReceivables' );
  7462. $invoiceReceivables = new invoiceReceivables ();
  7463. Doo::loadModel ( 'staff' );
  7464. $staff = new staff ();
  7465. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7466. // 我的发票待处理
  7467. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7468. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7469. 'desc' => 'iid',
  7470. 'asArray' => TRUE
  7471. ) );
  7472. // 我的收款待入账
  7473. /*
  7474. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7475. */
  7476. // 发票审批
  7477. $approval = $invoice->getOne ( array (
  7478. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7479. 'desc' => 'iid',
  7480. 'asArray' => true
  7481. ) );
  7482. // 发票邮寄
  7483. $post = $invoice->getOne ( array (
  7484. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7485. 'asArray' => TRUE
  7486. ) );
  7487. // 发票打印
  7488. $print = $invoice->getOne ( array (
  7489. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7490. 'desc' => 'iid',
  7491. 'asArray' => TRUE
  7492. ) );
  7493. // 发票退票 printStatus=1 and
  7494. $untread = $invoice->getOne ( array (
  7495. 'where' => " untreadStatus=1 and status=2 ",
  7496. 'asArray' => TRUE
  7497. ) );
  7498. $new = array (
  7499. 'GLOBAL' => FALSE,
  7500. 'pendingInvoice' => FALSE,
  7501. // 'myClaim' => FALSE,
  7502. 'approval' => FALSE,
  7503. 'post' => FALSE,
  7504. 'print' => FALSE,
  7505. 'untread' => FALSE
  7506. );
  7507. // || ! empty ( $myClaim )
  7508. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7509. $new ['GLOBAL'] = TRUE;
  7510. if (! empty ( $pendingInvoice ))
  7511. $new ['pendingInvoice'] = TRUE;
  7512. // if (! empty ( $myClaim ))
  7513. // $new ['myClaim'] = TRUE;
  7514. if (! empty ( $approval ))
  7515. $new ['approval'] = TRUE;
  7516. if (! empty ( $post ))
  7517. $new ['post'] = TRUE;
  7518. if (! empty ( $print ))
  7519. $new ['print'] = TRUE;
  7520. if (! empty ( $untread ))
  7521. $new ['untread'] = TRUE;
  7522. return $new;
  7523. }
  7524. function setWXMsg($rid, $typeMsg = '') {
  7525. Doo::loadModel ( 'invoice' );
  7526. $invoice = new invoice ();
  7527. $invoiceDetail = $invoice->getOne ( array (
  7528. 'where' => 'iid=' . $rid,
  7529. 'asArray' => true
  7530. ) );
  7531. if (! empty ( $invoiceDetail )) {
  7532. Doo::loadModel ( 'staff' );
  7533. $staff = new staff ();
  7534. $staffmsg = $staff->getOne ( array (
  7535. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7536. 'asArray' => TRUE
  7537. ) );
  7538. if (! empty ( $staffmsg ['wxid'] )) {
  7539. require_once (SITE_PATH . '/protected/class/client.php');
  7540. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7541. $user = $staffmsg ['wxid'];
  7542. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7543. if (empty ( $expCom ))
  7544. $expCom [0] = '';
  7545. $msg = "";
  7546. if (empty ( $typeMsg ))
  7547. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7548. elseif ($typeMsg == "PRINT")
  7549. $msg = '太好了,您的发票已打印完成。';
  7550. $result = $client->SendMsg ( $user, $msg, 'text' );
  7551. }
  7552. }
  7553. }
  7554. /**
  7555. * 获取微信部门
  7556. * @param string $category
  7557. * @return number|mixed
  7558. */
  7559. function getToparty($category = '') {
  7560. $token = $this->getAccessToken (); //
  7561. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7562. $toparty = 0;
  7563. foreach ( $result ['department'] as $key => $value ) {
  7564. if ($value ['name'] == $category)
  7565. $toparty = $value ['id'];
  7566. }
  7567. return $toparty;
  7568. }
  7569. /**
  7570. * 获得某部门下的用户
  7571. * @param string $toparty
  7572. */
  7573. function getUserByToparty($toparty = '') {
  7574. $token = $this->getAccessToken (); //
  7575. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7576. $userList = array ();
  7577. foreach ( $result ['userlist'] as $key => $value ) {
  7578. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7579. }
  7580. return $userList;
  7581. }
  7582. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7583. $token = $this->getAccessToken ();
  7584. if ($text == 'text') {
  7585. $data = '{
  7586. "touser": "' . $toparty . '",
  7587. "toparty": "",
  7588. "totag": "",
  7589. "msgtype": "text",
  7590. "agentid": 1000002,
  7591. "text": {
  7592. "content": "' . $msg . '"
  7593. },
  7594. "safe":0
  7595. }';
  7596. }
  7597. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7598. if ($result->errmsg != 'ok') {
  7599. return 0;
  7600. } else {
  7601. return 1;
  7602. }
  7603. }
  7604. /**
  7605. * 获得可以发送微信用户列表
  7606. * @param string $category
  7607. * @return string
  7608. */
  7609. function getWxidByCategory($category = "") {
  7610. if (empty ( $category ))
  7611. return "";
  7612. Doo::loadModel ( 'staff' );
  7613. $staff = new staff ();
  7614. $toparty = $this->getToparty ( $category );
  7615. $wxList = array ();
  7616. $wxString = "";
  7617. if (! empty ( $toparty )) {
  7618. $userList = $this->getUserByToparty ( $toparty );
  7619. $userCon = implode ( ',', $userList );
  7620. // echo $userCon;
  7621. $sidList = $staff->getStaffByWxid ( $userCon );
  7622. foreach ( $sidList as $key => $value ) {
  7623. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7624. if ($falg) {
  7625. array_push ( $wxList, $value ['wxid'] );
  7626. }
  7627. }
  7628. $wxString = implode ( '|', $wxList );
  7629. }
  7630. return $wxString;
  7631. }
  7632. /**
  7633. * 读取发送信息规则判断是否需要发送
  7634. * @param number $sid
  7635. * @param string $sendType
  7636. * @return boolean
  7637. */
  7638. function isSendNotification($sid = 0, $sendType = '') {
  7639. Doo::loadModel ( "notificationConf" );
  7640. $notificationConf = new notificationConf ();
  7641. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7642. $conf = array ();
  7643. $sendFlag = true;
  7644. if (! empty ( $detail )) {
  7645. $conf = json_decode ( $detail ['conf'], true );
  7646. if (! empty ( $sendType )) {
  7647. if (isset ( $conf [$sendType] )) {
  7648. if ($conf [$sendType] == "CLOSE")
  7649. $sendFlag = false;
  7650. elseif ($conf [$sendType] == "Weekend") {
  7651. $day = date ( "w" );
  7652. if (1 <= $day && 5 >= $day)
  7653. $sendFlag = false;
  7654. } elseif ($conf [$sendType] == "OneToFriday") {
  7655. $day = date ( "w" );
  7656. if (0 == $day || 6 == $day)
  7657. $sendFlag = false;
  7658. }
  7659. }
  7660. } else
  7661. $sendFlag = false;
  7662. }
  7663. return $sendFlag;
  7664. }
  7665. /**
  7666. * 根据规则发送信息
  7667. * @param unknown $msg
  7668. * @param unknown $title
  7669. * @param unknown $url
  7670. * @param unknown $user
  7671. * @param string $text
  7672. * @return number
  7673. */
  7674. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7675. $token = $this->getAccessToken ();
  7676. $falg = $this->isSendNotification ( $sid, $sendType );
  7677. // if ($text == 'text') {
  7678. // $data = '{
  7679. // "touser": "' . $user . '",
  7680. // "toparty": "",
  7681. // "totag": "",
  7682. // "msgtype": "text",
  7683. // "agentid": 1000002,
  7684. // "text": {
  7685. // "content": "' . $msg . '"
  7686. // },
  7687. // "safe":0
  7688. // }';
  7689. // } else {
  7690. $data = '{
  7691. "touser": "' . $user . '",
  7692. "toparty": "",
  7693. "totag": "",
  7694. "msgtype": "news",
  7695. "agentid": 1000002,
  7696. "news": {
  7697. "articles":[
  7698. {
  7699. "title": "' . $title . '",
  7700. "description": "' . $msg . '",
  7701. "url": "' . $url . '",
  7702. "picurl": ""
  7703. }
  7704. ]
  7705. }
  7706. }';
  7707. // }
  7708. if ($falg) {
  7709. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7710. if ($result->errmsg != 'ok') {
  7711. return 0;
  7712. } else {
  7713. return 1;
  7714. }
  7715. } else
  7716. return 0;
  7717. }
  7718. private function getAccessToken() {
  7719. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7720. // $file = './access_token.txt';
  7721. // $data = json_decode ( file_get_contents ( $file ) );
  7722. // if ($data->expire_time < time () or ! $data->expire_time) {
  7723. // 如果是企业号用以下URL获取access_token
  7724. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7725. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7726. $res = json_decode ( $this->httpGet ( $url ) );
  7727. $access_token = $res->access_token;
  7728. // echo $access_token;
  7729. // if ($access_token) {
  7730. // $data->expire_time = time () + 7000;
  7731. // $data->access_token = $access_token;
  7732. // $fp = fopen ( $file, "w" );
  7733. // fwrite ( $fp, json_encode ( $data ) );
  7734. // fclose ( $fp );
  7735. // }
  7736. // } else {
  7737. // $access_token = $data->access_token;
  7738. // }
  7739. return $access_token;
  7740. }
  7741. private function httpGet($url) {
  7742. $curl = curl_init ();
  7743. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7744. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7745. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7746. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7747. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7748. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7749. curl_setopt ( $curl, CURLOPT_URL, $url );
  7750. $res = curl_exec ( $curl );
  7751. curl_close ( $curl );
  7752. return $res;
  7753. }
  7754. private function httpPost($url, $data) {
  7755. $curl = curl_init ();
  7756. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7757. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7758. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7759. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7760. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7761. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7762. curl_setopt ( $curl, CURLOPT_URL, $url );
  7763. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7764. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7765. $res = curl_exec ( $curl );
  7766. curl_close ( $curl );
  7767. return $res;
  7768. }
  7769. }
  7770. ?>