InvoiceController.php 333 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. require "protected/services/invoice_service.php";
  10. class InvoiceController extends DooController {
  11. public $staff;
  12. public $NEW;
  13. public $data;
  14. public $invoiceService;
  15. private $INVOICEKEY = "APPROVAL";
  16. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  17. private $ACTION = '';
  18. private $appId = 'wx3ee46531947a1384';
  19. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  20. public function beforeRun($resource, $action) {
  21. Doo::loadModel ( "invoiceManage" );
  22. $invoiceManage = new invoiceManage ();
  23. Doo::loadClass ( 'XDeode' );
  24. $XDeode = new XDeode ( 5 );
  25. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  26. header ( 'Content-Type:text/html;charset=utf-8' );
  27. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  28. if (empty ( $moldList )) {
  29. $flag = false;
  30. $uGroups = 'ordinary';
  31. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  32. $flag = true;
  33. }
  34. } else {
  35. $flag = false;
  36. array_push ( $moldList, array (
  37. 'mold' => 'ordinary'
  38. ) );
  39. // 删除审批人后-加入权限问题-暂时关闭
  40. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  41. $fiML = json_decode ( $fileInvoice, true );
  42. if (empty ( $fiML ))
  43. $fiML = array ();
  44. foreach ( $fiML as $key => $value ) {
  45. $sidList = explode ( ',', $value );
  46. foreach ( $sidList as $k => $v ) {
  47. if ($v == $sid) {
  48. array_push ( $moldList, array (
  49. 'mold' => $key
  50. ) );
  51. break;
  52. }
  53. }
  54. }
  55. foreach ( $moldList as $value ) {
  56. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  57. $flag = true;
  58. break;
  59. }
  60. }
  61. }
  62. /*
  63. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  64. */
  65. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  66. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  67. Doo::loadModel ( "invoiceCategoryManage" );
  68. $invoiceCategoryManage = new invoiceCategoryManage ();
  69. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  70. if (empty ( $icm ))
  71. die ( 'illegal request-iacd' );
  72. }
  73. // 单独判断应收款访问权限
  74. if ($action == 'invoiceAggregateCompanyDetail') {
  75. Doo::loadModel ( "invoiceCompanyManage" );
  76. $invoiceCompanyManage = new invoiceCompanyManage ();
  77. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  78. if (empty ( $icm ))
  79. die ( 'illegal request' );
  80. }
  81. // 主权限获得与判断
  82. Doo::loadModel ( 'staff' );
  83. $staff = new staff ();
  84. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  85. $accessModular = 'INVOICE';
  86. if (empty ( $detail ['cldAccessArray'] ))
  87. die ( 'illegal request' );
  88. else {
  89. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  90. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  91. $flag = true;
  92. } else {
  93. $flag = false;
  94. }
  95. } else {
  96. die ( 'illegal request' );
  97. }
  98. }
  99. if (! $flag)
  100. die ( 'illegal request' );
  101. }
  102. function __construct() {
  103. $this->invoiceService = new invoice_service ();
  104. //echo $routeRs ['1'];
  105. //die('dd');
  106. if (isset ( $_COOKIE ["staff"] )) {
  107. if (! empty ( $_COOKIE ["staff"] )) {
  108. Doo::loadModel ( 'staff' );
  109. $staff = new staff ();
  110. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  111. $this->ACTION = $uriPartsOrig [1];
  112. $this->data ['new'] = $this->isInvoiceNew ();
  113. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  114. $this->data ['isStaffCompleteMsg'] = false;
  115. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  116. if (! empty ( $detail ))
  117. $this->data ['isStaffCompleteMsg'] = true;
  118. return "/";
  119. }
  120. }
  121. Doo::loadCore ( 'uri/DooUriRouter' );
  122. $router = new DooUriRouter ();
  123. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  124. if ($routeRs ['1'] != "login") {
  125. header ( 'Content-Type:text/html;charset=utf-8' );
  126. @header ( "Location: /login" );
  127. }
  128. }
  129. function testSend() {
  130. // 测试根据规则发送信息 普通发送
  131. // $pendingApprovalsSid = 41;
  132. // Doo::loadModel ( 'staff' );
  133. // $staff = new staff ();
  134. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  135. // // 发送微信审批通知
  136. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  137. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  138. // Doo::loadModel ( 'staff' );
  139. // $staff = new staff ();
  140. // $toparty = $this->getToparty ( '广东办' );
  141. // $wxList = array ();
  142. // if (! empty ( $toparty )) {
  143. // $userList = $this->getUserByToparty ( $toparty );
  144. // $userCon = implode ( ',', $userList );
  145. // // echo $userCon;
  146. // $sidList = $staff->getStaffByWxid ( $userCon );
  147. // foreach ( $sidList as $key => $value ) {
  148. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  149. // if ($falg) {
  150. // array_push ( $wxList, $value ['wxid'] );
  151. // }
  152. // }
  153. // $wxString = implode ( '|', $wxList );
  154. // print_r ( $wxList );
  155. // echo $wxString;
  156. // }
  157. // 测试发送
  158. /*
  159. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  160. */
  161. // print_r ( $userList );
  162. // $msTouser='caipin|outaozhen';
  163. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  164. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  165. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  166. // $toparty= $this->getToparty('广东办');
  167. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  168. // $toparty = 26;
  169. // $msg = '';
  170. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  171. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  172. }
  173. function invoice() {
  174. Doo::loadModel ( 'invoice' );
  175. $invoice = new invoice ();
  176. Doo::loadModel ( 'express' );
  177. $express = new express ();
  178. $expressList = $express->getExpressByAll ();
  179. $this->data ['expressList'] = $expressList;
  180. // Doo::loadModel ( 'invoiceReceivables' );
  181. // $invoiceReceivables = new invoiceReceivables ();
  182. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  183. Doo::loadClass ( 'XDeode' );
  184. $XDeode = new XDeode ( 5 );
  185. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  186. Doo::loadModel ( 'invoiceStatistics' );
  187. $invoiceStatistics = new invoiceStatistics ();
  188. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  189. // 缓存统计结果
  190. $year = date ( "Y" );
  191. $tmp_date = date ( "Ym" );
  192. $tmp_year = substr ( $tmp_date, 0, 4 );
  193. $tmp_mon = substr ( $tmp_date, 4, 2 );
  194. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  195. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  196. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  197. if (is_file ( $path ))
  198. $htm = file_get_contents ( $path );
  199. else
  200. $htm = $this->showCache ( $path, $sid );
  201. $invoiceList = $invoice->getMyInvoice ( $sid );
  202. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  203. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  204. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  205. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  206. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  207. // 获得已退票功能
  208. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  209. $this->data ['untreadStatusList'] = $untreadStatusList;
  210. // print_r($untreadStatusList);
  211. $this->data ['isMonth'] = $isMonth;
  212. $this->data ['htm'] = $htm;
  213. $this->data ['invoiceList'] = $invoiceList;
  214. $this->data ['receivablesList'] = $list;
  215. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  216. $this->data ['memu'] = "invoice";
  217. $this->data ['staff'] = $this->staff;
  218. $this->data ['receiptMemu'] = 'invoice';
  219. $this->render ( "/admin/invoice", $this->data );
  220. }
  221. function invoiceExpress() {
  222. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  223. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  224. $this->data ['expressCom'] = $expressCom;
  225. $this->data ['expressNumber'] = $expressNumber;
  226. $this->render ( "/admin/invoiceExpress", $this->data );
  227. }
  228. function invoiceAdd() {
  229. session_start ();
  230. /*Doo::loadModel ( 'invoice' );
  231. $invoice = new invoice ();
  232. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  233. Doo::loadModel ( 'L_category' );
  234. $lCategory = new L_category ();
  235. $category = $lCategory->find ( array (
  236. 'asArray' => true
  237. ) );
  238. $this->data ['category'] = $category;
  239. Doo::loadModel ( 'invoiceTraining' );
  240. $invoiceTraining = new invoiceTraining ();
  241. $itList = $invoiceTraining->findAll( array (
  242. 'where' => " cid=" . $this->staff [0] ['cid'].' or creator ='.$this->staff [0]['sid'],
  243. 'desc'=>'itid',
  244. 'asArray' => TRUE
  245. ) );
  246. //$itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  247. Doo::loadModel ( 'receipt' );
  248. $receipt = new receipt ();
  249. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  250. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  251. if (! empty ( $receiptDetail )) {
  252. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  253. unset ( $itList [$key] );
  254. }
  255. }
  256. }
  257. $this->data ['itList'] = $itList;
  258. $token = $this->set_token ();
  259. $tokenTime=time().rand(5, 15);
  260. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  261. $this->data ['token'] = $token;
  262. $this->data['tokenTime']=$tokenTime;
  263. $this->data ['memu'] = "invoice";
  264. $this->data ['staff'] = $this->staff;
  265. $this->data ['receiptMemu'] = 'invoice';
  266. $this->render ( "/admin/invoiceAdd", $this->data );
  267. }
  268. /**
  269. * 自更新发票信息库
  270. * @param unknown $invoicePrintDetail
  271. */
  272. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  273. // 发票信息库
  274. Doo::loadModel ( 'invoiceInfoBase' );
  275. $invoiceInfoBase = new invoiceInfoBase ();
  276. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  277. $TIN = $invoicePrintDetail ['TIN'];
  278. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  279. if (empty ( $invoiceTitle ))
  280. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  281. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  282. // 确认有该条发票信息
  283. $invoiceInfoBase = new invoiceInfoBase ();
  284. if (! empty ( $IIBList )) {
  285. // 发票库里的信息数量
  286. $IIBListCount = count ( $IIBList );
  287. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  288. $item = array (
  289. 'iibID' => $IIBList [0] ['iibID'],
  290. 'invoiceTitle' => $invoiceTitle,
  291. 'TIN' => $TIN
  292. );
  293. if (! empty ( $invoicePrintDetail ['address'] )) {
  294. $item += array (
  295. 'address' => $invoicePrintDetail ['address']
  296. );
  297. }
  298. if (! empty ( $invoicePrintDetail ['phone'] )) {
  299. $item += array (
  300. 'phone' => $invoicePrintDetail ['phone']
  301. );
  302. }
  303. if (! empty ( $invoicePrintDetail ['bank'] )) {
  304. $item += array (
  305. 'bank' => $invoicePrintDetail ['bank']
  306. );
  307. }
  308. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  309. $item += array (
  310. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  311. );
  312. }
  313. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  314. $item += array (
  315. 'updateDate' => $invoicePrintDetail ['date']
  316. );
  317. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  318. }
  319. } else { // 删除多张发票,重新添加发票
  320. $iibIDStr = '';
  321. $iibID = array ();
  322. foreach ( $IIBList as $key => $value ) {
  323. array_push ( $iibID, $value ['iibID'] );
  324. }
  325. $iibIDStr = implode ( ",", $iibID ); // 删除
  326. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  327. $item = array (
  328. 'invoiceTitle' => $invoiceTitle,
  329. 'TIN' => $TIN,
  330. 'address' => $invoicePrintDetail ['address'],
  331. 'phone' => $invoicePrintDetail ['phone'],
  332. 'bank' => $invoicePrintDetail ['bank'],
  333. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  334. 'updateDate' => $invoicePrintDetail ['date']
  335. );
  336. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  337. }
  338. } else { // 没有新增发票信息
  339. $item = array (
  340. 'invoiceTitle' => $invoiceTitle,
  341. 'TIN' => $TIN,
  342. 'address' => $invoicePrintDetail ['address'],
  343. 'phone' => $invoicePrintDetail ['phone'],
  344. 'bank' => $invoicePrintDetail ['bank'],
  345. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  346. 'updateDate' => $invoicePrintDetail ['date']
  347. );
  348. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  349. }
  350. }
  351. function invoiceAddFill() {
  352. session_start ();
  353. Doo::loadModel ( 'L_category' );
  354. $lCategory = new L_category ();
  355. $category = $lCategory->find ( array (
  356. 'asArray' => true
  357. ) );
  358. $this->data ['category'] = $category;
  359. Doo::loadModel ( 'invoiceTraining' );
  360. $invoiceTraining = new invoiceTraining ();
  361. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  362. $this->data ['itList'] = $itList;
  363. Doo::loadModel ( 'invoice' );
  364. $invoice = new invoice ();
  365. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  366. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  367. $token = $this->set_token ();
  368. $tokenTime=time().rand(5, 15);
  369. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  370. $this->data ['token'] = $token;
  371. $this->data['tokenTime']=$tokenTime;
  372. $this->data ['invoiceDetail'] = $detail;
  373. $this->data ['memu'] = "invoice";
  374. $this->data ['staff'] = $this->staff;
  375. $this->data ['receiptMemu'] = 'invoice';
  376. $this->render ( "/admin/invoiceAddFill", $this->data );
  377. }
  378. /**
  379. * 提交一份开票申请,并记录下操作日志
  380. *
  381. * @since 1.0.0
  382. * @var integer cid 办事处ID
  383. * @var integer invoiceType 发票类型
  384. * @var integer doPost 是否邮寄
  385. * @var integer invoicePrice 开票金额
  386. * @var string invoiceElement 开票内容
  387. * @var string invoiceTitle 发票抬头
  388. * @var string invoiceCompany 单位名称
  389. * @var string TIN 纳税人识别码
  390. * @var string address 注册地址
  391. * @var string phone 注册电话
  392. * @var string bank 开户银行
  393. * @var string bankAccount 银行账户
  394. * @var string recipients 收件人
  395. * @var string recipientsPhone 收件人手机/电话
  396. * @var string recipientsAddress 收件地址
  397. * @var string mailItems 邮寄物品
  398. * @var string remark 备注
  399. * @return string 返回跳转开票主页路径
  400. */
  401. function invoiceAddDo() {
  402. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  403. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  404. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  405. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  406. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  407. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  408. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  409. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  410. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  411. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  412. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  413. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  414. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  415. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  416. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  417. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  418. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  419. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  420. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  421. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  422. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  423. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  424. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  425. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  426. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  427. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  428. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  429. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  430. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  431. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  432. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  433. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  434. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  435. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  436. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  437. $electronicPhone= $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  438. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  439. /*
  440. * $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;
  441. */
  442. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  443. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  444. if (empty ( $token )) {
  445. die ( 'illegal request-token' );
  446. } else {
  447. session_start ();
  448. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  449. header ( 'Content-Type:text/html;charset=utf-8' );
  450. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  451. die ( '请重新刷新发票申请页面' );
  452. }elseif($_SESSION [$sessionKey]=='repeat'){
  453. die ( '请勿重复申请发票' );
  454. } else {
  455. if ($_SESSION [$sessionKey] != $token){
  456. die ( '请勿重复申请发票' );
  457. }else{
  458. $_SESSION [$sessionKey] = 'repeat';
  459. }
  460. }
  461. }
  462. if($invoiceForm=='electronic'){
  463. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  464. die ( '请至少填写一种联系方式--电子发票' );
  465. }
  466. }
  467. if ($invoiceType == 1) {
  468. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  469. if ($temporary > 100001) {
  470. header ( 'Content-Type:text/html;charset=utf-8' );
  471. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  472. }
  473. }elseif($invoiceType == 0){
  474. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  475. if ($temporary > 100001) {
  476. header ( 'Content-Type:text/html;charset=utf-8' );
  477. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  478. }
  479. }else{
  480. die ( 'illegal request-invoiceType' );
  481. }
  482. if (empty ( $this->staff [0] ))
  483. die ( 'illegal request-Please login' );
  484. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  485. Doo::loadModel ( 'invoice' );
  486. $invoice = new invoice ();
  487. Doo::loadModel ( 'L_category' );
  488. $lCategory = new L_category ();
  489. Doo::loadModel ( 'invoiceManage' );
  490. $invoiceManage = new invoiceManage ();
  491. Doo::loadModel ( 'invoiceOperationLog' );
  492. $invoiceOperationLog = new invoiceOperationLog ();
  493. Doo::loadClass ( 'XDeode' );
  494. $XDeode = new XDeode ( 5 );
  495. $trainId = $XDeode->decode ( $trainId );
  496. $categoryDetil = $lCategory->getOne ( array (
  497. 'SELECT' => 'title',
  498. 'where' => 'cid=' . $cid,
  499. 'asArray' => true
  500. ) );
  501. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  502. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  503. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  504. // print_r(current($invoiceManageDetail ['staffList']));
  505. // die;
  506. $moldManage = array ();
  507. foreach ( $invoiceManageList as $key => $value ) {
  508. if ($value ['mold'] == '发票打印')
  509. $moldManage [$value ['mold']] = $value ['staffList'];
  510. elseif ($value ['mold'] == '发票邮寄')
  511. $moldManage [$value ['mold']] = $value ['staffList'];
  512. elseif ($value ['mold'] == '发票退票')
  513. $moldManage [$value ['mold']] = $value ['staffList'];
  514. }
  515. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  516. $st = '';
  517. if ($settlementType == 'SOFTWARE') {
  518. $st = 0;
  519. $trainId = 0;
  520. } elseif ($settlementType == 'TRAINING') {
  521. $st = 1;
  522. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  523. die ( 'illegal request-trainingIdError' );
  524. }
  525. } else {
  526. die ( 'illegal request-settlementError' );
  527. }
  528. if($invoiceForm=='electronic'){
  529. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  530. $invoiceForm=1;
  531. $invoiceType=0;
  532. if(!empty($electronicPhone)||!empty($electronicEmail)){
  533. }else{
  534. die ( 'illegal request-electronicContact' );
  535. }
  536. $mailList = array ();
  537. $mailString = '备注:' . $mailItems;
  538. }elseif($invoiceForm=='paper'){
  539. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  540. $invoiceForm=0;
  541. $mailList = array (
  542. 'invoice' => 1,
  543. 'mailItems' => $mailItems
  544. );
  545. $mailString = '发票x1张,备注:' . $mailItems;
  546. }else{
  547. die ( 'illegal request-invoiceForm' );
  548. }
  549. $item = array (
  550. 'cid' => $cid,
  551. 'categoryName' => $categoryDetil ['title'],
  552. 'invoiceElement' => $invoiceElement,
  553. 'invoiceForm'=>$invoiceForm,
  554. 'electronicPhone'=>$electronicPhone,
  555. 'electronicEmail'=>$electronicEmail,
  556. 'invoiceQuantity' => $invoiceQuantity,
  557. 'invoiceUnitPrice' => $invoiceUnitPrice,
  558. 'invoicePrice' => $invoicePrice,
  559. 'invoiceType' => $invoiceType,
  560. 'settlementType' => $st,
  561. 'doPost' => $doPost,
  562. 'status' => 1,
  563. 'invoiceSerial' => $invoiceSerial,
  564. 'date' => date ( "Y-m-d H:i:s" ),
  565. 'updateTime' => date ( "Y-m-d H:i:s" ),
  566. 'sid' => $this->staff [0] ['sid'],
  567. 'userName' => $this->staff [0] ['username'],
  568. 'invoiceManage' => $invoiceManageDetail ['staff'],
  569. 'pendingApprovals' => $pendingApprovalsSid,
  570. 'moldManage' => json_encode ( $moldManage ),
  571. 'remark' => $remark,
  572. 'trainId' => $trainId
  573. );
  574. if ($invoiceType == 0)
  575. $item += array (
  576. 'invoiceTitle' => $invoiceTitle,
  577. 'TIN' => $TINT,
  578. 'address' => $addressT,
  579. 'phone' => $phoneT,
  580. 'bank' => $bankT,
  581. 'bankAccount' => $bankAccountT
  582. );
  583. else {
  584. $item += array (
  585. 'invoiceCompany' => $invoiceCompany,
  586. 'TIN' => $TIN,
  587. 'address' => $address,
  588. 'phone' => $phone,
  589. 'bank' => $bank,
  590. 'bankAccount' => $bankAccount
  591. );
  592. }
  593. if ($doPost == 1) {
  594. if (! empty ( $softLock ))
  595. $mailList += array (
  596. 'softLock' => $softLockNum
  597. );
  598. else
  599. $mailList += array (
  600. 'softLock' => 0
  601. );
  602. if (! empty ( $contract ))
  603. $mailList += array (
  604. 'contract' => $contractNum
  605. );
  606. else
  607. $mailList += array (
  608. 'contract' => 0
  609. );
  610. if (! empty ( $instructions ))
  611. $mailList += array (
  612. 'instructions' => $instructionsNum
  613. );
  614. else
  615. $mailList += array (
  616. 'instructions' => 0
  617. );
  618. if (! empty ( $remittance ))
  619. $mailList += array (
  620. 'remittance' => $remittance
  621. );
  622. else
  623. $mailList += array (
  624. 'remittance' => ''
  625. );
  626. if (! empty ( $softLock ))
  627. $mailString .= ',软件锁x' . $softLockNum . '个';
  628. if (! empty ( $contract ))
  629. $mailString .= ',合同x' . $contractNum . '份';
  630. if (! empty ( $instructions ))
  631. $mailString .= ',说明书x' . $instructionsNum . '本';
  632. if (! empty ( $remittance ))
  633. $mailString .= ',汇款账号单(张)';
  634. $item += array (
  635. 'recipients' => $recipients,
  636. 'recipientsPhone' => $recipientsPhone,
  637. 'recipientsAddress' => $recipientsAddress,
  638. 'mailItems' => $mailString,
  639. 'mailItemsJson' => json_encode ( $mailList )
  640. );
  641. }
  642. $iid = $invoice->addInvoice ( $item );
  643. // 如果是培训班结算 创建培训班发票到培训班备份中
  644. if (! empty ( $st ) && $st == 1) {
  645. Doo::loadModel ( 'invoiceStore' );
  646. $invoiceStore = new invoiceStore ();
  647. Doo::loadModel ( 'invoiceTraining' );
  648. $invoiceTraining = new invoiceTraining ();
  649. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  650. $itemIS = array (
  651. 'isid' => $isid,
  652. 'ipSource' => 1,
  653. 'apStatus' => 1,
  654. 'iid' => $iid
  655. );
  656. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  657. // 更新培训班总数量
  658. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  659. $item = array (
  660. 'itid' => $trainId,
  661. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  662. 'submitStatus' => 1
  663. );
  664. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  665. }
  666. // 操作日志
  667. $item = array (
  668. 'date' => date ( "Y-m-d H:i:s" ),
  669. 'operation' => "创建",
  670. 'status' => 1,
  671. 'img' => $this->staff [0] ['avatar'],
  672. 'username' => $this->staff [0] ['username'],
  673. 'uid' => $this->staff [0] ['sid'],
  674. 'category' => $this->staff [0] ['category'],
  675. 'iid' => $iid
  676. );
  677. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  678. $item = array (
  679. 'date' => date ( "Y-m-d H:i:s" ),
  680. 'operation' => "提交审批",
  681. 'status' => 1,
  682. 'img' => $this->staff [0] ['avatar'],
  683. 'username' => $this->staff [0] ['username'],
  684. 'uid' => $this->staff [0] ['sid'],
  685. 'category' => $this->staff [0] ['category'],
  686. 'iid' => $iid
  687. );
  688. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  689. Doo::loadModel ( 'staff' );
  690. $staff = new staff ();
  691. $username2 = $staff->getOne ( array (
  692. 'select' => 'wxid',
  693. 'where' => 'sid=' . $pendingApprovalsSid,
  694. 'asArray' => TRUE
  695. ) );
  696. // 发送微信审批通知
  697. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  698. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  699. }
  700. return "/invoice";
  701. }
  702. function invoiceEdit() {
  703. Doo::loadClass ( 'XDeode' );
  704. $XDeode = new XDeode ( 5 );
  705. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  706. $iid = $XDeode->decode ( $iid );
  707. if (! is_numeric ( $iid ))
  708. die ( 'illegal request' );
  709. Doo::loadModel ( 'invoice' );
  710. $invoice = new invoice ();
  711. Doo::loadModel ( 'invoiceOperationLog' );
  712. $invoiceOperationLog = new invoiceOperationLog ();
  713. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  714. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  715. $invoiceDetail ['mailItemsJson'] ='';
  716. if(isset($invoiceDetail ['mailItemsJson'])){
  717. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  718. }
  719. $this->data ['operation'] = $operation;
  720. $this->data ['invoiceDetail'] = $invoiceDetail;
  721. $this->data ['memu'] = "invoice";
  722. $this->data ['staff'] = $this->staff;
  723. $this->data ['receiptMemu'] = 'invoice';
  724. $this->render ( "/admin/invoiceEdit", $this->data );
  725. }
  726. /**
  727. * 重新编辑退回的发票
  728. * @return string
  729. */
  730. function invoiceEditDo() {
  731. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  732. Doo::loadModel ( 'invoice' );
  733. $invoice = new invoice ();
  734. $iid = $invoice->authcode ( $iidKey );
  735. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  736. die ( 'illegal request' );
  737. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  738. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  739. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  740. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  741. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  742. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  743. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  744. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  745. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  746. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  747. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  748. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  749. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  750. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  751. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  752. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  753. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  754. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  755. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  756. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  757. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  758. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  759. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  760. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  761. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  762. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  763. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  764. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  765. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  766. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  767. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  768. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  769. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  770. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  771. if ($invoiceType == 1) {
  772. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  773. if ($temporary > 100001)
  774. die ( 'illegal request-Please priceError' );
  775. }
  776. if($invoiceForm=='electronic'){
  777. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  778. die ( '请至少填写一种联系方式--电子发票' );
  779. }
  780. }
  781. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  782. Doo::loadModel ( 'invoiceManage' );
  783. $invoiceManage = new invoiceManage ();
  784. Doo::loadModel ( 'invoiceOperationLog' );
  785. $invoiceOperationLog = new invoiceOperationLog ();
  786. Doo::loadModel ( 'invoiceStore' );
  787. $invoiceStore = new invoiceStore ();
  788. $cid = explode ( ':', $cid );
  789. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  790. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  791. $moldManage = array ();
  792. foreach ( $invoiceManageList as $key => $value ) {
  793. if ($value ['mold'] == '发票打印')
  794. $moldManage [$value ['mold']] = $value ['staffList'];
  795. elseif ($value ['mold'] == '发票邮寄')
  796. $moldManage [$value ['mold']] = $value ['staffList'];
  797. elseif ($value ['mold'] == '发票打印')
  798. $moldManage [$value ['mold']] = $value ['staffList'];
  799. }
  800. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  801. if($invoiceForm=='electronic'){
  802. $invoiceForm=1;
  803. $invoiceType=0;
  804. if(!empty($electronicPhone)||!empty($electronicEmail)){
  805. }else{
  806. die ( 'illegal request-electronicContact' );
  807. }
  808. $mailList = array ();
  809. $mailString = '备注:' . $mailItems;
  810. }elseif($invoiceForm=='paper'){
  811. $invoiceForm=0;
  812. $mailList = array (
  813. 'invoice' => 1,
  814. 'mailItems' => $mailItems
  815. );
  816. $mailString = '发票x1张,备注:' . $mailItems;
  817. }else{
  818. die ( 'illegal request-invoiceForm' );
  819. }
  820. $item = array (
  821. 'iid' => $iid,
  822. 'cid' => $cid [0],
  823. 'categoryName' => $cid [1],
  824. 'invoiceElement' => $invoiceElement,
  825. 'invoiceForm'=>$invoiceForm,
  826. 'electronicPhone'=>$electronicPhone,
  827. 'electronicEmail'=>$electronicEmail,
  828. 'invoiceQuantity' => $invoiceQuantity,
  829. 'invoiceUnitPrice' => $invoiceUnitPrice,
  830. 'invoicePrice' => $invoicePrice,
  831. 'invoiceType' => $invoiceType,
  832. 'doPost' => $doPost,
  833. 'status' => 1,
  834. 'updateTime' => date ( "Y-m-d H:i:s" ),
  835. 'remark' => $remark
  836. );
  837. if ($invoiceType == 0)
  838. $item += array (
  839. 'invoiceTitle' => $invoiceTitle,
  840. 'TIN' => $TINT,
  841. 'address' => $addressT,
  842. 'phone' => $phoneT,
  843. 'bank' => $bankT,
  844. 'bankAccount' => $bankAccountT
  845. );
  846. else {
  847. $item += array (
  848. 'invoiceCompany' => $invoiceCompany,
  849. 'TIN' => $TIN,
  850. 'address' => $address,
  851. 'phone' => $phone,
  852. 'bank' => $bank,
  853. 'bankAccount' => $bankAccount
  854. );
  855. }
  856. if ($doPost == 1) {
  857. if (! empty ( $softLock ))
  858. $mailList += array (
  859. 'softLock' => $softLockNum
  860. );
  861. else
  862. $mailList += array (
  863. 'softLock' => '0'
  864. );
  865. if (! empty ( $contract ))
  866. $mailList += array (
  867. 'contract' => $contractNum
  868. );
  869. else
  870. $mailList += array (
  871. 'contract' => '0'
  872. );
  873. if (! empty ( $instructions ))
  874. $mailList += array (
  875. 'instructions' => $instructionsNum
  876. );
  877. else
  878. $mailList += array (
  879. 'instructions' => '0'
  880. );
  881. if (! empty ( $remittance ))
  882. $mailList += array (
  883. 'remittance' => $remittance
  884. );
  885. else
  886. $mailList += array (
  887. 'remittance' => ''
  888. );
  889. if (! empty ( $softLock ))
  890. $mailString .= ',软件锁x' . $softLockNum;
  891. if (! empty ( $contract ))
  892. $mailString .= ',合同x' . $contractNum;
  893. if (! empty ( $instructions ))
  894. $mailString .= ',说明书x' . $instructionsNum;
  895. if (! empty ( $remittance ))
  896. $mailString .= ',汇款账号单';
  897. $item += array (
  898. 'recipients' => $recipients,
  899. 'recipientsPhone' => $recipientsPhone,
  900. 'recipientsAddress' => $recipientsAddress,
  901. 'mailItems' => $mailString,
  902. 'mailItemsJson' => json_encode ( $mailList )
  903. );
  904. }
  905. $invoice->setInvoiceByCondition ( $item );
  906. // 更新培训班仓库里的发票
  907. $detail = $invoice->getInvoiceByIid ( $iid );
  908. if (! empty ( $detail ['isid'] )) {
  909. $invoiceStore->isid = $detail ['isid'];
  910. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  911. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  912. $invoiceStore->invoicePrice = $invoicePrice;
  913. $invoiceStore->update ();
  914. }
  915. $item = array (
  916. 'date' => date ( "Y-m-d H:i:s" ),
  917. 'operation' => "重新提交审批",
  918. 'status' => 1,
  919. 'img' => $this->staff [0] ['avatar'],
  920. 'username' => $this->staff [0] ['username'],
  921. 'uid' => $this->staff [0] ['sid'],
  922. 'category' => $this->staff [0] ['category'],
  923. 'iid' => $iid
  924. );
  925. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  926. }
  927. return "/invoice";
  928. }
  929. /**
  930. * 培训班
  931. */
  932. function invoiceTraining() {
  933. Doo::loadModel ( 'L_category' );
  934. $lCategory = new L_category ();
  935. Doo::loadModel ( 'invoiceTraining' );
  936. $invoiceTraining = new invoiceTraining ();
  937. Doo::loadModel ( 'invoiceTrainManage' );
  938. $invoiceTrainManage = new invoiceTrainManage ();
  939. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  940. $cidList = array ();
  941. foreach ( $imcStaff as $key => $value ) {
  942. array_push ( $cidList, $value ['cid'] );
  943. }
  944. if (empty ( $cidList )) {
  945. $cidString = $this->staff [0] ['cid'];
  946. } else {
  947. $cidString = implode ( ',', $cidList );
  948. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  949. }
  950. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  951. // $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  952. //TODO 待完成入账培训班
  953. $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  954. // if($this->staff [0] ['sid']==94){
  955. // $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  956. // }else{
  957. // $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  958. // }
  959. // $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  960. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  961. $category = $lCategory->getCategory ();
  962. $itid = array ();
  963. foreach ( $itTodoList as $key => $value ) {
  964. array_push ( $itid, $value ['itid'] );
  965. // 如果入账100%更新为已完成
  966. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  967. $invoiceTraining = new invoiceTraining ();
  968. $invoiceTraining->itid = $value ['itid'];
  969. $invoiceTraining->status = 2;
  970. $invoiceTraining->update ();
  971. }
  972. }
  973. foreach ( $itedList as $value ) {
  974. array_push ( $itid, $value ['itid'] );
  975. }
  976. $itid = implode ( ',', $itid );
  977. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  978. // print_r($itTodoList);
  979. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  980. $this->data ['itTodoList'] = $itTodoList;
  981. $this->data ['itedList'] = $itedList;
  982. $this->data ['category'] = $category;
  983. $this->data ['memu'] = "invoice";
  984. $this->data ['staff'] = $this->staff;
  985. $this->data ['receiptMemu'] = 'invoiceTraining';
  986. $this->render ( "/admin/invoiceTraining", $this->data );
  987. }
  988. /**
  989. * 创建培训班
  990. */
  991. function invoiceTrainingAdd() {
  992. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  993. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  994. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  995. if (empty ( $this->staff [0] ))
  996. die ( 'illegal request' );
  997. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  998. Doo::loadModel ( 'invoiceTraining' );
  999. $invoiceTraining = new invoiceTraining ();
  1000. Doo::loadModel ( 'invoice' );
  1001. $invoice = new invoice ();
  1002. Doo::loadModel ( 'L_category' );
  1003. $lCategory = new L_category ();
  1004. Doo::loadModel ( 'invoiceManage' );
  1005. $invoiceManage = new invoiceManage ();
  1006. Doo::loadModel ( 'invoiceOperationLog' );
  1007. $invoiceOperationLog = new invoiceOperationLog ();
  1008. $item = array (
  1009. 'cid' => $cid,
  1010. 'trainName' => $trainName,
  1011. 'trainDate' => $trainDate,
  1012. 'creator' => $this->staff [0] ['sid'],
  1013. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1014. );
  1015. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  1016. }
  1017. return "/invoiceTraining";
  1018. }
  1019. /**
  1020. * 删除培训班
  1021. */
  1022. function invoiceTrainingDelDo() {
  1023. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1024. if (! empty ( $itid )) {
  1025. Doo::loadModel ( 'invoiceTraining' );
  1026. $invoiceTraining = new invoiceTraining ();
  1027. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1028. }
  1029. return "/invoiceTraining";
  1030. }
  1031. /**
  1032. * 培训班详情
  1033. */
  1034. function invoiceTrainingDetail() {
  1035. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1036. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1037. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1038. Doo::loadModel ( 'invoiceTraining' );
  1039. $invoiceTraining = new invoiceTraining ();
  1040. Doo::loadModel ( 'invoiceStore' );
  1041. $invoiceStore = new invoiceStore ();
  1042. if (empty ( $itid ))
  1043. die ( 'illegal request' );
  1044. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1045. if ($trainStatus == "SUBED")
  1046. $con = ' (b.untreadStatus is null ) and ';
  1047. elseif ($trainStatus == "APPROVAL")
  1048. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1049. elseif ($trainStatus == "TICKET")
  1050. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1051. elseif ($trainStatus == "TICKETING") {
  1052. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1053. }
  1054. $con.=' a.invoiceForm=0 and ';
  1055. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1056. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1057. //print_r($isList);
  1058. $trainlistJson=$this->_trainList($isList);
  1059. if (empty ( $detail ))
  1060. die ( 'illegal request' );
  1061. // 培训班结算是否有和是否已经结算完成
  1062. Doo::loadModel ( 'receipt' );
  1063. $receipt = new receipt ();
  1064. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1065. $this->data ['receiptDetail'] = $receiptDetail;
  1066. $this->data ['trainStatus'] = $trainStatus;
  1067. $this->data ['itid'] = $itid;
  1068. $this->data ['trainlistJson'] = $trainlistJson;
  1069. $this->data ['iTrainDetail'] = $detail;
  1070. $this->data ['memu'] = "invoice";
  1071. $this->data ['staff'] = $this->staff;
  1072. $this->data ['receiptMemu'] = 'invoiceTraining';
  1073. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1074. }
  1075. function invoiceTrainingElectronicDetail(){
  1076. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1077. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1078. Doo::loadModel ( 'invoiceTraining' );
  1079. $invoiceTraining = new invoiceTraining ();
  1080. Doo::loadModel ( 'invoiceStore' );
  1081. $invoiceStore = new invoiceStore ();
  1082. if (empty ( $itid ))
  1083. die ( 'illegal request' );
  1084. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1085. if ($trainStatus == "SUBED")
  1086. $con = ' (b.untreadStatus is null ) and ';
  1087. elseif ($trainStatus == "APPROVAL")
  1088. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1089. elseif ($trainStatus == "TICKET")
  1090. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1091. elseif ($trainStatus == "TICKETING") {
  1092. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1093. }
  1094. $con.=' a.invoiceForm=1 and ';
  1095. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1096. // TODO 获得电子票
  1097. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1098. //print_r($isList);
  1099. if (empty ( $detail )){
  1100. die ( 'illegal request' );
  1101. }
  1102. $trainlistJson=$this->_trainList($isList,1);
  1103. // 培训班结算是否有和是否已经结算完成
  1104. Doo::loadModel ( 'receipt' );
  1105. $receipt = new receipt ();
  1106. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1107. $this->data ['receiptDetail'] = $receiptDetail;
  1108. $this->data ['trainStatus'] = $trainStatus;
  1109. $this->data ['itid'] = $itid;
  1110. $this->data ['trainlistJson'] = $trainlistJson;
  1111. $this->data ['iTrainDetail'] = $detail;
  1112. $this->data ['memu'] = "invoice";
  1113. $this->data ['staff'] = $this->staff;
  1114. $this->data ['receiptMemu'] = 'invoiceTraining';
  1115. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1116. }
  1117. function _trainList($isList,$type=0){
  1118. $trainlist = array ();
  1119. foreach ( $isList as $key => $value ) {
  1120. $irDetail = array ();
  1121. if ($value ['apStatus'] == 1) {
  1122. // array_push ( $irDetail, '' );
  1123. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1124. } else {
  1125. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1126. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1127. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1128. }
  1129. array_push ( $irDetail, $value ['invoiceSerial'] );
  1130. if ($value ['invoiceType'] == 1)
  1131. array_push ( $irDetail, $value ['invoiceCompany'] );
  1132. else
  1133. array_push ( $irDetail, $value ['invoiceTitle'] );
  1134. array_push ( $irDetail, $value ['TIN'] );
  1135. array_push ( $irDetail, $value ['userName'] );
  1136. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1137. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1138. } else
  1139. array_push ( $irDetail, $value ['mailItems'] );
  1140. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1141. if($type==1){
  1142. array_push ( $irDetail, $value ['electronicPhone'] );
  1143. array_push ( $irDetail, $value ['electronicEmail'] );
  1144. }
  1145. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1146. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1147. array_push ( $irDetail, $value ['invoiceElement'] );
  1148. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1149. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1150. if ($value ['invoiceType'] == 1)
  1151. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1152. else
  1153. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1154. array_push ( $irDetail, $value ['remark'] );
  1155. if ($value ['status'] == 1)
  1156. array_push ( $irDetail, '审批中' );
  1157. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1158. array_push ( $irDetail, '已出票' );
  1159. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1160. array_push ( $irDetail, '已入账' );
  1161. else
  1162. array_push ( $irDetail, '' );
  1163. array_push ( $irDetail, $value ['invoiceNo'] );
  1164. array_push ( $irDetail, $value ['printTime'] );
  1165. $html = '';
  1166. foreach ( $value ['invoiceReceivables'] as $v ) {
  1167. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1168. }
  1169. array_push ( $irDetail, $html );
  1170. array_push ( $trainlist, $irDetail );
  1171. }
  1172. $trainlistJson = json_encode ( $trainlist );
  1173. return $trainlistJson;
  1174. }
  1175. /**
  1176. * 上传培训班发票
  1177. * @return string
  1178. */
  1179. function invoiceTrainingUpload() {
  1180. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1181. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1182. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1183. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1184. header ( "HTTP/1.1 500 Internal Server Error" );
  1185. echo "POST exceeded maximum allowed size.";
  1186. exit ( 0 );
  1187. }
  1188. // Settings
  1189. $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)
  1190. $upload_name = "Filedata";
  1191. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1192. $extension_whitelist = array (
  1193. "doc",
  1194. "txt",
  1195. "jpg",
  1196. "gif",
  1197. "png"
  1198. ); // Allowed file extensions
  1199. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1200. // Other variables
  1201. $MAX_FILENAME_LENGTH = 260;
  1202. $file_name = "";
  1203. $file_extension = "";
  1204. $uploadErrors = array (
  1205. 0 => "文件上传成功",
  1206. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1207. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1208. 3 => "上传的文件仅为部分文件",
  1209. 4 => "没有文件上传",
  1210. 6 => "缺少临时文件夹"
  1211. );
  1212. $nk = time ();
  1213. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1214. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1215. echo "文件无法保存.";
  1216. exit ( 0 );
  1217. }
  1218. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1219. echo json_encode ( array (
  1220. 'filename' => $file_name,
  1221. 'id' => $nk
  1222. ) );
  1223. exit ( 0 );
  1224. }
  1225. /**
  1226. * 导入发票临时仓库
  1227. */
  1228. function invoiceStoreImport() {
  1229. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1230. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1231. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1232. if ($path != "" && ! empty ( $trainingKey )) {
  1233. Doo::loadModel ( 'invoiceStore' );
  1234. Doo::loadModel ( 'staff' );
  1235. $staff = new staff ();
  1236. Doo::loadModel ( 'invoiceTraining' );
  1237. $invoiceTraining = new invoiceTraining ();
  1238. Doo::loadClass ( 'XDeode' );
  1239. $XDeode = new XDeode ( 5 );
  1240. $itid = $XDeode->decode ( $trainingKey );
  1241. // 培训班结算是否有和是否已经结算完成
  1242. Doo::loadModel ( 'receipt' );
  1243. $receipt = new receipt ();
  1244. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1245. if (! empty ( $receiptDetail )) {
  1246. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1247. die ( 'illegal request--status' );
  1248. }
  1249. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1250. $userName = $this->staff [0] ['username'];
  1251. $sDetail = $staff->getStaffByName ( $userName );
  1252. //print_r($exlArray);die;
  1253. // die('sdd');
  1254. // 可以优化
  1255. foreach ( $exlArray as $key => $value ) {
  1256. // 开票
  1257. $invoice = new invoiceStore ();
  1258. $invoice->trainId = $itid;
  1259. $invoice->invoiceType = 0;
  1260. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1261. $invoice->invoiceType = 1;
  1262. elseif($value ['invoiceType'] == '电子'){
  1263. $invoice->invoiceType = 0;
  1264. $invoice->invoiceForm=1;
  1265. }
  1266. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1267. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1268. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1269. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1270. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1271. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1272. $invoice->userName = $userName;
  1273. $invoice->sid = $sDetail ['sid'];
  1274. $invoice->cid = $sDetail ['cid'];
  1275. $invoice->categoryName = $sDetail ['category'];
  1276. $invoice->invoiceElement = $value ['invoiceElement'];
  1277. $invoice->remark = $value ['remark'];
  1278. // $invoice->date = $value ['date'];
  1279. // $invoice->printTime = $value ['date'];
  1280. $invoice->ipSource = 1;
  1281. $invoice->printStatus = 0;
  1282. $invoice->status = 0;
  1283. $invoice->postStatus = 1;
  1284. $invoice->untreadStatus = 0;
  1285. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1286. $invoice->TIN = $value ['TIN'];
  1287. $invoice->address = $value ['address'];
  1288. $invoice->phone = $value ['phone'];
  1289. $invoice->bank = $value ['bank'];
  1290. $invoice->bankAccount = $value ['bankAccount'];
  1291. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1292. $invoice->recipients = $value ['recipients'];
  1293. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1294. $invoice->electronicPhone = $value ['electronicPhone'];
  1295. $invoice->electronicEmail = $value ['electronicEmail'];
  1296. $iid = $invoice->insert ();
  1297. }
  1298. // 加入发票总数量
  1299. $item = array (
  1300. 'itid' => $itid,
  1301. 'invoiceTotal' => count ( $exlArray )
  1302. );
  1303. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1304. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1305. }
  1306. echo 'no file';
  1307. }
  1308. /**
  1309. * 编辑仓库里的发票
  1310. */
  1311. function invoiceStoreEdit() {
  1312. Doo::loadClass ( 'XDeode' );
  1313. $XDeode = new XDeode ( 5 );
  1314. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1315. $iid = $XDeode->decode ( $iid );
  1316. if (! is_numeric ( $iid ))
  1317. die ( 'illegal request' );
  1318. Doo::loadModel ( 'invoiceStore' );
  1319. $invoiceStore = new invoiceStore ();
  1320. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1321. // print_r($invoiceDetail);
  1322. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1323. $this->data ['invoiceDetail'] = $invoiceDetail;
  1324. $this->data ['memu'] = "invoice";
  1325. $this->data ['staff'] = $this->staff;
  1326. $this->data ['receiptMemu'] = 'invoiceTraining';
  1327. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1328. }
  1329. function invoiceStoreEditDo() {
  1330. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1331. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1332. Doo::loadModel ( 'invoiceStore' );
  1333. $invoice = new invoiceStore ();
  1334. Doo::loadClass ( 'XDeode' );
  1335. $XDeode = new XDeode ( 5 );
  1336. $iid = $XDeode->decode ( $storeKey );
  1337. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1338. die ( 'illegal request' );
  1339. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1340. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1341. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1342. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1343. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1344. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1345. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1346. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1347. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1348. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1349. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1350. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1351. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1352. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1353. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1354. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1355. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1356. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1357. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1358. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1359. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1360. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1361. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1362. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1363. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1364. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1365. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1366. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1367. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1368. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1369. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1370. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1371. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1372. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1373. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1374. $cid = explode ( ':', $cid );
  1375. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1376. $item = array (
  1377. 'isid' => $iid,
  1378. 'cid' => $cid [0],
  1379. 'categoryName' => $cid [1],
  1380. 'invoiceElement' => $invoiceElement,
  1381. 'invoiceQuantity' => $invoiceQuantity,
  1382. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1383. 'invoicePrice' => $invoicePrice,
  1384. 'invoiceType' => $invoiceType,
  1385. 'doPost' => $doPost,
  1386. 'status' => 1,
  1387. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1388. 'remark' => $remark
  1389. );
  1390. if ($invoiceType == 0)
  1391. $item += array (
  1392. 'invoiceTitle' => $invoiceTitle,
  1393. 'TIN' => $TINT,
  1394. 'address' => $addressT,
  1395. 'phone' => $phoneT,
  1396. 'bank' => $bankT,
  1397. 'bankAccount' => $bankAccountT
  1398. );
  1399. else {
  1400. $item += array (
  1401. 'invoiceCompany' => $invoiceCompany,
  1402. 'TIN' => $TIN,
  1403. 'address' => $address,
  1404. 'phone' => $phone,
  1405. 'bank' => $bank,
  1406. 'bankAccount' => $bankAccount
  1407. );
  1408. }
  1409. if($invoiceForm=='paper'){
  1410. $item += array (
  1411. 'invoiceForm' => 0
  1412. );
  1413. }elseif($invoiceForm=='electronic'){
  1414. $item += array (
  1415. 'invoiceForm' => 1,
  1416. 'electronicPhone' => $electronicPhone,
  1417. 'electronicEmail' => $electronicEmail,
  1418. );
  1419. }
  1420. if ($doPost == 1) {
  1421. $mailList = array (
  1422. 'invoice' => 1,
  1423. 'mailItems' => $mailItems
  1424. );
  1425. if (! empty ( $softLock ))
  1426. $mailList += array (
  1427. 'softLock' => $softLockNum
  1428. );
  1429. else
  1430. $mailList += array (
  1431. 'softLock' => '0'
  1432. );
  1433. if (! empty ( $contract ))
  1434. $mailList += array (
  1435. 'contract' => $contractNum
  1436. );
  1437. else
  1438. $mailList += array (
  1439. 'contract' => '0'
  1440. );
  1441. if (! empty ( $instructions ))
  1442. $mailList += array (
  1443. 'instructions' => $instructionsNum
  1444. );
  1445. else
  1446. $mailList += array (
  1447. 'instructions' => '0'
  1448. );
  1449. if (! empty ( $remittance ))
  1450. $mailList += array (
  1451. 'remittance' => $remittance
  1452. );
  1453. else
  1454. $mailList += array (
  1455. 'remittance' => ''
  1456. );
  1457. $mailString = '发票x1,备注:' . $mailItems;
  1458. if (! empty ( $softLock ))
  1459. $mailString .= ',软件锁x' . $softLockNum;
  1460. if (! empty ( $contract ))
  1461. $mailString .= ',合同x' . $contractNum;
  1462. if (! empty ( $instructions ))
  1463. $mailString .= ',说明书x' . $instructionsNum;
  1464. if (! empty ( $remittance ))
  1465. $mailString .= ',汇款账号单';
  1466. $item += array (
  1467. 'recipients' => $recipients,
  1468. 'recipientsPhone' => $recipientsPhone,
  1469. 'recipientsAddress' => $recipientsAddress,
  1470. 'mailItems' => $mailString,
  1471. 'mailItemsJson' => json_encode ( $mailList )
  1472. );
  1473. }
  1474. $invoice->setInvoiceStoreByCondition ( $item );
  1475. }
  1476. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1477. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1478. }else{
  1479. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1480. }
  1481. }
  1482. /**
  1483. *
  1484. * @return string
  1485. */
  1486. function invoiceStoreDelete() {
  1487. Doo::loadClass ( 'XDeode' );
  1488. $XDeode = new XDeode ( 5 );
  1489. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1490. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1491. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1492. $isid = $XDeode->decode ( $iStoreKey );
  1493. $itid = $XDeode->decode ( $trainKey );
  1494. if (! is_numeric ( $isid ))
  1495. die ( 'illegal request' );
  1496. Doo::loadModel ( 'invoiceStore' );
  1497. $invoiceStore = new invoiceStore ();
  1498. $invoiceStore->delete ( array (
  1499. 'where' => 'isid=' . $isid,
  1500. 'limit' => 1
  1501. ) );
  1502. Doo::loadModel ( 'invoiceTraining' );
  1503. $invoiceTraining = new invoiceTraining ();
  1504. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1505. $item = array (
  1506. 'itid' => $itid,
  1507. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1508. );
  1509. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1510. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1511. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1512. }else{
  1513. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1514. }
  1515. }
  1516. /**
  1517. * 批量删除库里发票
  1518. */
  1519. function invoiceStoreBatchDelete() {
  1520. Doo::loadClass ( 'XDeode' );
  1521. $XDeode = new XDeode ( 5 );
  1522. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1523. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1524. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1525. if (empty ( $trainKey ) || empty ( $storeKey ))
  1526. die ( 'illegal request-IdKey' );
  1527. $tid = $XDeode->decode ( $trainKey );
  1528. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1529. die ( 'illegal request' );
  1530. Doo::loadModel ( 'invoiceStore' );
  1531. $isidKeyList = explode ( ',', $storeKey );
  1532. $isidList = array ();
  1533. foreach ( $isidKeyList as $value ) {
  1534. $isid = $XDeode->decode ( $value );
  1535. if (! empty ( $isid ) && is_numeric ( $isid ))
  1536. array_push ( $isidList, $isid );
  1537. }
  1538. $isidString = implode ( ',', $isidList );
  1539. $invoiceStore = new invoiceStore ();
  1540. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1541. $isidList = array ();
  1542. foreach ( $isList as $key => $value ) {
  1543. if ($value ['apStatus'] == 0)
  1544. array_push ( $isidList, $value ['isid'] );
  1545. }
  1546. $isidString = implode ( ',', $isidList );
  1547. // print_r($isList);
  1548. // echo $isidString;
  1549. $invoiceStore = new invoiceStore ();
  1550. $invoiceStore->delete ( array (
  1551. 'where' => "isid in ( " . $isidString . ")",
  1552. 'asArray' => TRUE
  1553. ) );
  1554. Doo::loadModel ( 'invoiceTraining' );
  1555. $invoiceTraining = new invoiceTraining ();
  1556. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1557. $item = array (
  1558. 'itid' => $tid,
  1559. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1560. );
  1561. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1562. // echo $tid;
  1563. // echo $storeKey;
  1564. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1565. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1566. }else{
  1567. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1568. }
  1569. }
  1570. function invoiceStoreBatchElectronicPhone(){
  1571. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1572. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1573. Doo::loadClass ( 'XDeode' );
  1574. $XDeode = new XDeode ( 5 );
  1575. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1576. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1577. if (empty ( $trainKey ) || empty ( $storeKey ))
  1578. die ( 'illegal request-IdKey' );
  1579. $isidKeyList = explode ( ',', $storeKey );
  1580. $isidList = array ();
  1581. foreach ( $isidKeyList as $value ) {
  1582. $isid = $XDeode->decode ( $value );
  1583. if (! empty ( $isid ) && is_numeric ( $isid ))
  1584. array_push ( $isidList, $isid );
  1585. }
  1586. $isidString = implode ( ',', $isidList );
  1587. $trainId = $XDeode->decode ( $trainKey );
  1588. if (! is_numeric ( $isid ))
  1589. die ( 'illegal request--isid' );
  1590. Doo::loadModel ( 'invoiceStore' );
  1591. $invoiceStore = new invoiceStore ();
  1592. $item = array (
  1593. 'electronicPhone' => $electronicPhone
  1594. );
  1595. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1596. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1597. }
  1598. function invoiceStoreBatchElectronicEmail(){
  1599. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1600. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1601. Doo::loadClass ( 'XDeode' );
  1602. $XDeode = new XDeode ( 5 );
  1603. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1604. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1605. if (empty ( $trainKey ) || empty ( $storeKey ))
  1606. die ( 'illegal request-IdKey' );
  1607. $isidKeyList = explode ( ',', $storeKey );
  1608. $isidList = array ();
  1609. foreach ( $isidKeyList as $value ) {
  1610. $isid = $XDeode->decode ( $value );
  1611. if (! empty ( $isid ) && is_numeric ( $isid ))
  1612. array_push ( $isidList, $isid );
  1613. }
  1614. $isidString = implode ( ',', $isidList );
  1615. $trainId = $XDeode->decode ( $trainKey );
  1616. if (! is_numeric ( $isid ))
  1617. die ( 'illegal request' );
  1618. Doo::loadModel ( 'invoiceStore' );
  1619. $invoiceStore = new invoiceStore ();
  1620. $item = array (
  1621. 'electronicEmail' => $electronicEmail
  1622. );
  1623. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1624. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1625. }
  1626. /**
  1627. * 仓库发票提交审批
  1628. * @return string
  1629. */
  1630. function invoiceStoreApproval() {
  1631. Doo::loadClass ( 'XDeode' );
  1632. $XDeode = new XDeode ( 5 );
  1633. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1634. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1635. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1636. $isid = $XDeode->decode ( $iStoreKey );
  1637. $trainId = $XDeode->decode ( $trainKey );
  1638. if (! is_numeric ( $isid ))
  1639. die ( 'illegal request' );
  1640. Doo::loadModel ( 'invoiceStore' );
  1641. Doo::loadModel ( 'invoice' );
  1642. $invoice = new invoice ();
  1643. // 加入限制必须填写入开票内容和邮寄物品
  1644. $invoiceStore = new invoiceStore ();
  1645. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1646. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1647. header ( 'Content-Type:text/html;charset=utf-8' );
  1648. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1649. }
  1650. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1651. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1652. header ( 'Content-Type:text/html;charset=utf-8' );
  1653. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1654. }
  1655. }
  1656. // 拷贝插入一条发票数据
  1657. $invoiceStore = new invoiceStore ();
  1658. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1659. $invoiceStore = new invoiceStore ();
  1660. $item = array (
  1661. 'isid' => $isid,
  1662. 'iid' => $iid,
  1663. 'apStatus' => 1
  1664. );
  1665. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1666. Doo::loadModel ( 'invoiceManage' );
  1667. $invoiceManage = new invoiceManage ();
  1668. Doo::loadModel ( 'invoiceOperationLog' );
  1669. $invoiceOperationLog = new invoiceOperationLog ();
  1670. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1671. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1672. $moldManage = array ();
  1673. foreach ( $invoiceManageList as $key => $value ) {
  1674. if ($value ['mold'] == '发票打印')
  1675. $moldManage [$value ['mold']] = $value ['staffList'];
  1676. elseif ($value ['mold'] == '发票邮寄')
  1677. $moldManage [$value ['mold']] = $value ['staffList'];
  1678. elseif ($value ['mold'] == '发票退票')
  1679. $moldManage [$value ['mold']] = $value ['staffList'];
  1680. }
  1681. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1682. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1683. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1684. }else{
  1685. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1686. }
  1687. $item = array (
  1688. 'iid' => $iid,
  1689. 'isid' => $isid,
  1690. 'invoiceSerial' => $invoiceSerial,
  1691. 'date' => date ( "Y-m-d H:i:s" ),
  1692. 'status' => 1,
  1693. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1694. 'trainId' => $trainId,
  1695. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1696. 'moldManage' => json_encode ( $moldManage ),
  1697. 'settlementType' => 1,
  1698. 'pendingApprovals' => $pendingApprovalsSid
  1699. );
  1700. $invoice->setInvoiceByCondition ( $item );
  1701. Doo::loadModel ( 'invoiceTraining' );
  1702. $invoiceTraining = new invoiceTraining ();
  1703. $item = array (
  1704. 'itid' => $trainId,
  1705. 'submitStatus' => 1
  1706. );
  1707. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1708. $item = array (
  1709. 'date' => date ( "Y-m-d H:i:s" ),
  1710. 'operation' => "创建",
  1711. 'status' => 1,
  1712. 'img' => $this->staff [0] ['avatar'],
  1713. 'username' => $this->staff [0] ['username'],
  1714. 'uid' => $this->staff [0] ['sid'],
  1715. 'category' => $this->staff [0] ['category'],
  1716. 'iid' => $iid
  1717. );
  1718. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1719. $item = array (
  1720. 'date' => date ( "Y-m-d H:i:s" ),
  1721. 'operation' => "提交审批",
  1722. 'status' => 1,
  1723. 'img' => $this->staff [0] ['avatar'],
  1724. 'username' => $this->staff [0] ['username'],
  1725. 'uid' => $this->staff [0] ['sid'],
  1726. 'category' => $this->staff [0] ['category'],
  1727. 'iid' => $iid
  1728. );
  1729. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1730. Doo::loadModel ( 'staff' );
  1731. $staff = new staff ();
  1732. $username2 = $staff->getOne ( array (
  1733. 'select' => 'wxid',
  1734. 'where' => 'sid=' . $pendingApprovalsSid,
  1735. 'asArray' => TRUE
  1736. ) );
  1737. // 发送微信审批通知
  1738. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1739. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1740. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1741. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1742. }else{
  1743. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1744. }
  1745. }
  1746. /**
  1747. * 批量提交发票
  1748. * @return string
  1749. */
  1750. function invoiceStoreBatchApproval() {
  1751. Doo::loadClass ( 'XDeode' );
  1752. $XDeode = new XDeode ( 5 );
  1753. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1754. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1755. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1756. if (empty ( $trainKey ) || empty ( $storeKey ))
  1757. die ( 'illegal request-IdKey' );
  1758. $trainId = $XDeode->decode ( $trainKey );
  1759. $isidKeyList = explode ( ',', $storeKey );
  1760. $isidList = array ();
  1761. foreach ( $isidKeyList as $value ) {
  1762. $isid = $XDeode->decode ( $value );
  1763. if (! empty ( $isid ) && is_numeric ( $isid ))
  1764. array_push ( $isidList, $isid );
  1765. }
  1766. $isidString = implode ( ',', $isidList );
  1767. if (! is_numeric ( $trainId ))
  1768. die ( 'illegal request' );
  1769. Doo::loadModel ( 'invoiceStore' );
  1770. Doo::loadModel ( 'invoice' );
  1771. // 判断哪些已经加入审批过
  1772. // 加入限制必须填写入开票内容和邮寄物品
  1773. $invoiceStore = new invoiceStore ();
  1774. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1775. foreach ( $isList as $key => $value ) {
  1776. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1777. header ( 'Content-Type:text/html;charset=utf-8' );
  1778. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1779. }
  1780. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1781. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1782. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1783. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1784. header ( 'Content-Type:text/html;charset=utf-8' );
  1785. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1786. }
  1787. }
  1788. }
  1789. // 拷贝插入一条发票数据
  1790. $invoiceStore = new invoiceStore ();
  1791. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1792. $invoiceStore = new invoiceStore ();
  1793. $item = array (
  1794. 'apStatus' => 1
  1795. );
  1796. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1797. // 获得正式发票ID
  1798. $invoice = new invoice ();
  1799. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1800. $sqlList = array ();
  1801. $iidString = '';
  1802. $iida = array ();
  1803. foreach ( $iidList as $key => $value ) {
  1804. $sqlList [$value ['isid']] = $value ['iid'];
  1805. array_push ( $iida, $value ['iid'] );
  1806. }
  1807. $iidString = implode ( ',', $iida );
  1808. $ids = implode ( ',', array_keys ( $sqlList ) );
  1809. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1810. foreach ( $sqlList as $id => $ordinal ) {
  1811. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1812. }
  1813. $sql .= "END WHERE isid IN ($ids)";
  1814. $invoiceStore = new invoiceStore ();
  1815. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1816. Doo::loadModel ( 'invoiceManage' );
  1817. $invoiceManage = new invoiceManage ();
  1818. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1819. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1820. $moldManage = array ();
  1821. foreach ( $invoiceManageList as $key => $value ) {
  1822. if ($value ['mold'] == '发票打印')
  1823. $moldManage [$value ['mold']] = $value ['staffList'];
  1824. elseif ($value ['mold'] == '发票邮寄')
  1825. $moldManage [$value ['mold']] = $value ['staffList'];
  1826. elseif ($value ['mold'] == '发票退票')
  1827. $moldManage [$value ['mold']] = $value ['staffList'];
  1828. }
  1829. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1830. // 批量更新发票信息
  1831. $item = array (
  1832. 'date' => date ( "Y-m-d H:i:s" ),
  1833. 'status' => 1,
  1834. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1835. 'trainId' => $trainId,
  1836. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1837. 'moldManage' => json_encode ( $moldManage ),
  1838. 'settlementType' => 1,
  1839. 'pendingApprovals' => $pendingApprovalsSid
  1840. );
  1841. $invoice = new invoice ();
  1842. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1843. // 批量更新发票中仓库isid
  1844. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1845. foreach ( $sqlList as $isid => $iid ) {
  1846. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1847. }
  1848. $sql .= "END WHERE iid IN ($iidString)";
  1849. $invoice = new invoice ();
  1850. $invoice->UpdateBatchInvoice ( $sql );
  1851. // 批量更新发票序列号
  1852. $sqlList = array ();
  1853. foreach ( $iida as $value ) {
  1854. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1855. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1856. }else{
  1857. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1858. }
  1859. }
  1860. $ids = implode ( ',', array_keys ( $sqlList ) );
  1861. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1862. foreach ( $sqlList as $id => $ordinal ) {
  1863. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1864. }
  1865. $sql .= "END WHERE iid IN ($ids)";
  1866. $invoiceStore = new invoiceStore ();
  1867. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1868. // 批量生产操作日志
  1869. Doo::loadModel ( 'invoiceOperationLog' );
  1870. $sqlList = array ();
  1871. foreach ( $iida as $key => $value ) {
  1872. $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 . '"),
  1873. ("' . 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 . '") ';
  1874. array_push ( $sqlList, $sql );
  1875. }
  1876. $iolSql = implode ( ',', $sqlList );
  1877. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1878. $invoiceOperationLog = new invoiceOperationLog ();
  1879. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1880. Doo::loadModel ( 'invoiceTraining' );
  1881. $invoiceTraining = new invoiceTraining ();
  1882. $item = array (
  1883. 'itid' => $trainId,
  1884. 'submitStatus' => 1
  1885. );
  1886. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1887. Doo::loadModel ( 'staff' );
  1888. $staff = new staff ();
  1889. $username2 = $staff->getOne ( array (
  1890. 'select' => 'wxid',
  1891. 'where' => 'sid=' . $pendingApprovalsSid,
  1892. 'asArray' => TRUE
  1893. ) );
  1894. // 发送微信审批通知
  1895. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1896. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1897. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1898. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1899. }else{
  1900. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1901. }
  1902. }
  1903. /**
  1904. */
  1905. function invoiceStoreMailItemSet() {
  1906. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1907. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1908. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1909. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1910. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1911. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1912. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1913. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1914. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1915. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1916. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1917. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1918. Doo::loadClass ( 'XDeode' );
  1919. $XDeode = new XDeode ( 5 );
  1920. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1921. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1922. $isid = $XDeode->decode ( $storeKey );
  1923. $trainId = $XDeode->decode ( $trainKey );
  1924. if (! is_numeric ( $isid ))
  1925. die ( 'illegal request' );
  1926. Doo::loadModel ( 'invoiceStore' );
  1927. $invoiceStore = new invoiceStore ();
  1928. $mailList = array (
  1929. 'mailItems' => $mailItems
  1930. );
  1931. $mailString = '发票x1,备注:' . $mailItems;
  1932. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1933. $mailString = '备注:' . $mailItems;
  1934. }else{
  1935. $mailList += array (
  1936. 'invoice' => 1,
  1937. );
  1938. }
  1939. if (! empty ( $softLock ))
  1940. $mailList += array (
  1941. 'softLock' => $softLockNum
  1942. );
  1943. else
  1944. $mailList += array (
  1945. 'softLock' => 0
  1946. );
  1947. if (! empty ( $contract ))
  1948. $mailList += array (
  1949. 'contract' => $contractNum
  1950. );
  1951. else
  1952. $mailList += array (
  1953. 'contract' => 0
  1954. );
  1955. if (! empty ( $instructions ))
  1956. $mailList += array (
  1957. 'instructions' => $instructionsNum
  1958. );
  1959. else
  1960. $mailList += array (
  1961. 'instructions' => 0
  1962. );
  1963. if (! empty ( $remittance ))
  1964. $mailList += array (
  1965. 'remittance' => $remittance
  1966. );
  1967. else
  1968. $mailList += array (
  1969. 'remittance' => ''
  1970. );
  1971. if (! empty ( $softLock ))
  1972. $mailString .= ',软件锁x' . $softLockNum;
  1973. if (! empty ( $contract ))
  1974. $mailString .= ',合同x' . $contractNum;
  1975. if (! empty ( $instructions ))
  1976. $mailString .= ',说明书x' . $instructionsNum;
  1977. if (! empty ( $remittance ))
  1978. $mailString .= ',汇款账号单';
  1979. $item = array (
  1980. 'isid' => $isid,
  1981. 'doPost' => 1,
  1982. 'mailItems' => $mailString,
  1983. 'mailItemsJson' => json_encode ( $mailList )
  1984. );
  1985. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1986. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1987. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1988. }else{
  1989. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1990. }
  1991. }
  1992. /**
  1993. * 批量设置邮寄物品
  1994. */
  1995. function invoiceStoreBatchMailItemSet() {
  1996. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1997. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1998. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1999. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  2000. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  2001. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  2002. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  2003. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  2004. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  2005. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  2006. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  2007. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  2008. Doo::loadClass ( 'XDeode' );
  2009. $XDeode = new XDeode ( 5 );
  2010. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  2011. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2012. if (empty ( $trainKey ) || empty ( $storeKey ))
  2013. die ( 'illegal request-IdKey' );
  2014. $isidKeyList = explode ( ',', $storeKey );
  2015. $isidList = array ();
  2016. foreach ( $isidKeyList as $value ) {
  2017. $isid = $XDeode->decode ( $value );
  2018. if (! empty ( $isid ) && is_numeric ( $isid ))
  2019. array_push ( $isidList, $isid );
  2020. }
  2021. $isidString = implode ( ',', $isidList );
  2022. $trainId = $XDeode->decode ( $trainKey );
  2023. if (! is_numeric ( $isid ))
  2024. die ( 'illegal request' );
  2025. Doo::loadModel ( 'invoiceStore' );
  2026. $invoiceStore = new invoiceStore ();
  2027. $mailList = array (
  2028. 'mailItems' => $mailItems
  2029. );
  2030. $mailString = '发票x1,备注:' . $mailItems;
  2031. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2032. $mailString = '备注:' . $mailItems;
  2033. }else{
  2034. $mailList += array (
  2035. 'invoice' => 1,
  2036. );
  2037. }
  2038. if (! empty ( $softLock ))
  2039. $mailList += array (
  2040. 'softLock' => $softLockNum
  2041. );
  2042. else
  2043. $mailList += array (
  2044. 'softLock' => 0
  2045. );
  2046. if (! empty ( $contract ))
  2047. $mailList += array (
  2048. 'contract' => $contractNum
  2049. );
  2050. else
  2051. $mailList += array (
  2052. 'contract' => 0
  2053. );
  2054. if (! empty ( $instructions ))
  2055. $mailList += array (
  2056. 'instructions' => $instructionsNum
  2057. );
  2058. else
  2059. $mailList += array (
  2060. 'instructions' => 0
  2061. );
  2062. if (! empty ( $remittance ))
  2063. $mailList += array (
  2064. 'remittance' => $remittance
  2065. );
  2066. else
  2067. $mailList += array (
  2068. 'remittance' => ''
  2069. );
  2070. if (! empty ( $softLock ))
  2071. $mailString .= ',软件锁x' . $softLockNum;
  2072. if (! empty ( $contract ))
  2073. $mailString .= ',合同x' . $contractNum;
  2074. if (! empty ( $instructions ))
  2075. $mailString .= ',说明书x' . $instructionsNum;
  2076. if (! empty ( $remittance ))
  2077. $mailString .= ',汇款账号单';
  2078. $item = array (
  2079. 'doPost' => 1,
  2080. 'mailItems' => $mailString,
  2081. 'mailItemsJson' => json_encode ( $mailList )
  2082. );
  2083. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2084. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2085. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2086. }else{
  2087. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2088. }
  2089. }
  2090. /**
  2091. * 废弃
  2092. */
  2093. function ajaxGetMailItemByIstore() {
  2094. Doo::loadClass ( 'XDeode' );
  2095. $XDeode = new XDeode ( 5 );
  2096. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2097. $isid = $XDeode->decode ( $storeKey );
  2098. if (! is_numeric ( $isid ))
  2099. die ( 'illegal request' );
  2100. Doo::loadModel ( 'invoiceStore' );
  2101. $invoiceStore = new invoiceStore ();
  2102. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2103. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2104. echo json_encode ( $isDetail ['mailItemsJson'] );
  2105. exit ();
  2106. }
  2107. /**
  2108. * 终止开票
  2109. */
  2110. function invoiceDroppedDo() {
  2111. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2112. Doo::loadModel ( 'invoice' );
  2113. $invoice = new invoice ();
  2114. Doo::loadModel ( 'invoiceOperationLog' );
  2115. $invoiceOperationLog = new invoiceOperationLog ();
  2116. $iid = $invoice->authcode ( $droppedIidKey );
  2117. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2118. die ( 'illegal request' );
  2119. $item = array (
  2120. 'iid' => $iid,
  2121. 'status' => 4,
  2122. 'updateTime' => date ( "Y-m-d H:i:s" )
  2123. );
  2124. $invoice->setInvoiceByCondition ( $item );
  2125. $item = array (
  2126. 'date' => date ( "Y-m-d H:i:s" ),
  2127. 'operation' => '终止了开票',
  2128. 'status' => 4,
  2129. 'img' => $this->staff [0] ['avatar'],
  2130. 'username' => $this->staff [0] ['username'],
  2131. 'uid' => $this->staff [0] ['sid'],
  2132. 'category' => $this->staff [0] ['category'],
  2133. 'iid' => $iid
  2134. );
  2135. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2136. return "/invoice";
  2137. }
  2138. /**
  2139. * 更新退票的邮寄信息
  2140. */
  2141. function invoiceUntreadMailDo() {
  2142. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2143. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2144. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2145. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2146. Doo::loadModel ( 'invoice' );
  2147. $invoice = new invoice ();
  2148. $iid = $invoice->authcode ( $untreadIidKey );
  2149. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2150. die ( 'illegal request' );
  2151. $item = array (
  2152. 'iid' => $iid,
  2153. 'untreadCompany' => $untreadCompany,
  2154. 'untreadNumber' => $untreadNumber,
  2155. 'untreadItems' => $untreadItems
  2156. );
  2157. $invoice->setInvoiceByCondition ( $item );
  2158. return "/invoice";
  2159. }
  2160. /**
  2161. * 申请退票 --
  2162. */
  2163. function invoiceUntreadDo() {
  2164. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2165. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2166. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : 0;
  2167. Doo::loadModel ( 'invoice' );
  2168. $invoice = new invoice ();
  2169. Doo::loadModel ( 'invoiceOperationLog' );
  2170. $invoiceOperationLog = new invoiceOperationLog ();
  2171. Doo::loadModel ( 'invoiceReceivables' );
  2172. $invoiceReceivables = new invoiceReceivables ();
  2173. $iid = $invoice->authcode ( $untreadIidKey );
  2174. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2175. die ( 'illegal request' );
  2176. /*
  2177. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2178. */
  2179. $item = array (
  2180. 'iid' => $iid,
  2181. 'untreadStatus' => 1,
  2182. 'untreadReason' => $untreadReason,
  2183. 'untreadPost' => $untreadPost,
  2184. 'updateTime' => date ( "Y-m-d H:i:s" )
  2185. );
  2186. $invoice->setInvoiceByCondition ( $item );
  2187. $item = array (
  2188. 'date' => date ( "Y-m-d H:i:s" ),
  2189. 'operation' => '申请退票',
  2190. 'status' => 7,
  2191. 'img' => $this->staff [0] ['avatar'],
  2192. 'username' => $this->staff [0] ['username'],
  2193. 'uid' => $this->staff [0] ['sid'],
  2194. 'category' => $this->staff [0] ['category'],
  2195. 'iid' => $iid
  2196. );
  2197. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2198. return "/invoice";
  2199. }
  2200. /**
  2201. * 删除已终止的开票
  2202. */
  2203. function invoiceDelDo() {
  2204. Doo::loadModel ( 'invoice' );
  2205. $invoice = new invoice ();
  2206. Doo::loadModel ( 'invoiceOperationLog' );
  2207. $invoiceOperationLog = new invoiceOperationLog ();
  2208. Doo::loadClass ( 'XDeode' );
  2209. $XDeode = new XDeode ( 5 );
  2210. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2211. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2212. $iid = $XDeode->decode ( $iid );
  2213. Doo::loadModel ( 'invoiceStore' );
  2214. $invoiceStore = new invoiceStore ();
  2215. if (! is_numeric ( $iid ))
  2216. die ( 'illegal request' );
  2217. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2218. if (empty ( $invoiceDetail ))
  2219. die ( 'illegal request' );
  2220. $item = array (
  2221. 'iid' => $iid,
  2222. 'isDelete' => 1,
  2223. 'updateTime' => date ( "Y-m-d H:i:s" )
  2224. );
  2225. $invoice->setInvoiceByCondition ( $item );
  2226. $item = array (
  2227. 'date' => date ( "Y-m-d H:i:s" ),
  2228. 'operation' => '删除了已终止的发票',
  2229. 'status' => 4,
  2230. 'img' => $this->staff [0] ['avatar'],
  2231. 'username' => $this->staff [0] ['username'],
  2232. 'uid' => $this->staff [0] ['sid'],
  2233. 'category' => $this->staff [0] ['category'],
  2234. 'iid' => $iid
  2235. );
  2236. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2237. // 删除培训班发票仓库里的发票
  2238. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2239. return "/invoice";
  2240. }
  2241. /**
  2242. */
  2243. function invoiceApproval() {
  2244. Doo::loadModel ( 'invoice' );
  2245. $invoice = new invoice ();
  2246. Doo::loadClass ( 'XDeode' );
  2247. $XDeode = new XDeode ( 5 );
  2248. Doo::loadModel ( 'staff' );
  2249. $staff = new staff ();
  2250. $invoiceList = $invoice->find ( array (
  2251. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2252. 'desc' => 'iid',
  2253. 'limit' => 10,
  2254. 'asArray' => true
  2255. ) );
  2256. foreach ( $invoiceList as $key => $value ) {
  2257. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2258. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2259. if (! empty ( $lastApprover )) {
  2260. $lastApproverKey = array_keys ( $lastApprover );
  2261. $lastApprover = end ( $lastApprover );
  2262. $staffDetail = $staff->getOne ( array (
  2263. 'where' => 'sid=' . end ( $lastApproverKey ),
  2264. 'asArray' => true
  2265. ) );
  2266. $lastApprover ['username'] = $staffDetail ['username'];
  2267. }
  2268. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2269. }
  2270. $ilist = $invoice->getInvoiceByProcessStatus ();
  2271. foreach ( $ilist as $key => $value ) {
  2272. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2273. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2274. if (! empty ( $lastApprover )) {
  2275. $lastApproverKey = array_keys ( $lastApprover );
  2276. $lastApprover = end ( $lastApprover );
  2277. $staffDetail = $staff->getOne ( array (
  2278. 'where' => 'sid=' . end ( $lastApproverKey ),
  2279. 'asArray' => true
  2280. ) );
  2281. $lastApprover ['username'] = $staffDetail ['username'];
  2282. }
  2283. $ilist [$key] ['lastApprover'] = $lastApprover;
  2284. }
  2285. // print_r($ilist);
  2286. $this->data ['invoiceList'] = $invoiceList;
  2287. $this->data ['ilist'] = $ilist;
  2288. $this->data ['memu'] = "invoice";
  2289. $this->data ['staff'] = $this->staff;
  2290. $this->data ['receiptMemu'] = 'invoiceApproval';
  2291. $this->render ( "/admin/invoiceApproval", $this->data );
  2292. }
  2293. function invoiceDetail() {
  2294. Doo::loadClass ( 'XDeode' );
  2295. $XDeode = new XDeode ( 5 );
  2296. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2297. $iid = $XDeode->decode ( $iid );
  2298. if (! is_numeric ( $iid ))
  2299. die ( 'illegal request' );
  2300. Doo::loadModel ( 'invoice' );
  2301. $invoice = new invoice ();
  2302. Doo::loadModel ( 'invoiceOperationLog' );
  2303. $invoiceOperationLog = new invoiceOperationLog ();
  2304. $invoiceDetail = $invoice->getOne ( array (
  2305. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2306. 'asArray' => true
  2307. ) );
  2308. if (empty ( $invoiceDetail ))
  2309. die ( 'illegal request' );
  2310. if ($invoiceDetail ['settlementType'] == 1) {
  2311. Doo::loadModel ( 'invoiceTraining' );
  2312. $invoiceTraining = new invoiceTraining ();
  2313. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2314. }
  2315. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2316. $this->data ['invoiceDetail'] = $invoiceDetail;
  2317. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2318. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2319. $this->data ['memu'] = "invoice";
  2320. $this->data ['staff'] = $this->staff;
  2321. $this->data ['receiptMemu'] = 'invoiceApproval';
  2322. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2323. }
  2324. /**
  2325. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2326. *
  2327. * @since 1.0.0
  2328. * @var integer iid 开票ID 已加密
  2329. * @var integer status 发票审批状态
  2330. * @var integer opintion 审批发票的意见
  2331. * @return string 如操作成功返回审批首页
  2332. */
  2333. function invoiceApprovalDo() {
  2334. Doo::loadModel ( 'invoice' );
  2335. $invoice = new invoice ();
  2336. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2337. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2338. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2339. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2340. $iid = $invoice->authcode ( $iid );
  2341. if (! is_numeric ( $iid ))
  2342. die ( 'illegal request' );
  2343. // && ! empty ( $opinion )
  2344. if (! empty ( $iid ) && ! empty ( $status )) {
  2345. if (! ($status == 2 || $status == 3 || $status == 4))
  2346. die ( 'illegal request' );
  2347. Doo::loadModel ( 'invoiceOperationLog' );
  2348. $invoiceOperationLog = new invoiceOperationLog ();
  2349. $invoiceDetail = $invoice->getOne ( array (
  2350. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2351. 'asArray' => true
  2352. ) );
  2353. if (empty ( $invoiceDetail ))
  2354. die ( 'illegal request' );
  2355. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2356. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2357. if ($status == 3) {
  2358. $invoice->status = $status;
  2359. $item = array (
  2360. 'operation' => $opinion
  2361. );
  2362. } else {
  2363. if (empty ( $processApprovals )) {
  2364. $processApprovals = array (
  2365. $this->staff [0] ['sid'] => array (
  2366. 'date' => date ( "Y-m-d H:i:s" ),
  2367. 'opinion' => $opinion,
  2368. 'status' => $status
  2369. )
  2370. );
  2371. // var_dump(next($invoiceManage));
  2372. $nextInvoiceManage = next ( $invoiceManage );
  2373. // print_r($nextInvoiceManage);
  2374. if ($status != 4 && $nextInvoiceManage !== false)
  2375. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2376. $invoice->processApprovals = json_encode ( $processApprovals );
  2377. // var_dump($invoice);
  2378. // print_r($invoiceManage);
  2379. } else {
  2380. $processApprovals [$this->staff [0] ['sid']] = array (
  2381. 'date' => date ( "Y-m-d H:i:s" ),
  2382. 'opinion' => $opinion,
  2383. 'status' => $status
  2384. );
  2385. $pendingApprovals = 0;
  2386. foreach ( $invoiceManage as $key => $value ) {
  2387. if ($value [0] == $this->staff [0] ['sid']) {
  2388. if (isset ( $invoiceManage [$key + 1] ))
  2389. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2390. break;
  2391. }
  2392. }
  2393. if ($status != 4 && ! empty ( $pendingApprovals ))
  2394. $invoice->pendingApprovals = $pendingApprovals;
  2395. $invoice->processApprovals = json_encode ( $processApprovals );
  2396. }
  2397. $item = array (
  2398. 'operation' => $opinion
  2399. );
  2400. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2401. $invoice->status = $status;
  2402. $invoice->pendingApprovals = 0;
  2403. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2404. } elseif ($status == 4) {
  2405. $invoice->status = $status;
  2406. $item = array (
  2407. 'operation' => $opinion
  2408. );
  2409. }
  2410. }
  2411. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2412. $invoice->update ( array (
  2413. 'where' => 'iid=' . $iid
  2414. ) );
  2415. $item += array (
  2416. 'date' => date ( "Y-m-d H:i:s" ),
  2417. 'img' => $this->staff [0] ['avatar'],
  2418. 'username' => $this->staff [0] ['username'],
  2419. 'uid' => $this->staff [0] ['sid'],
  2420. 'category' => $this->staff [0] ['category'],
  2421. 'status' => $status,
  2422. 'iid' => $iid
  2423. );
  2424. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2425. if (empty ( $divApproval ))
  2426. return '/invoiceApproval';
  2427. else
  2428. return '/invoiceApprovalAchieve/PEND';
  2429. }
  2430. die ( 'illegal request' );
  2431. }
  2432. /**
  2433. * 展示需要打印的发票数据
  2434. *
  2435. * @since 1.0.0
  2436. */
  2437. function invoicePrint() {
  2438. Doo::loadModel ( 'invoice' );
  2439. $invoice = new invoice ();
  2440. Doo::loadClass ( 'XDeode' );
  2441. $XDeode = new XDeode ( 5 );
  2442. Doo::loadModel ( 'staff' );
  2443. $staff = new staff ();
  2444. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2445. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2446. foreach ( $toPrint as $key => $value ) {
  2447. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2448. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2449. if (! empty ( $lastApprover )) {
  2450. $lastApproverKey = array_keys ( $lastApprover );
  2451. $lastApprover = end ( $lastApprover );
  2452. $staffDetail = $staff->getOne ( array (
  2453. 'where' => 'sid=' . end ( $lastApproverKey ),
  2454. 'asArray' => true
  2455. ) );
  2456. $lastApprover ['username'] = $staffDetail ['username'];
  2457. }
  2458. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2459. }
  2460. foreach ( $printed as $key => $value ) {
  2461. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2462. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2463. if (! empty ( $lastApprover )) {
  2464. $lastApproverKey = array_keys ( $lastApprover );
  2465. $lastApprover = end ( $lastApprover );
  2466. $staffDetail = $staff->getOne ( array (
  2467. 'where' => 'sid=' . end ( $lastApproverKey ),
  2468. 'asArray' => true
  2469. ) );
  2470. $lastApprover ['username'] = $staffDetail ['username'];
  2471. }
  2472. $printed [$key] ['lastApprover'] = $lastApprover;
  2473. }
  2474. $this->data ['printed'] = $printed;
  2475. $this->data ['toPrint'] = $toPrint;
  2476. $this->data ['memu'] = "invoice";
  2477. $this->data ['staff'] = $this->staff;
  2478. $this->data ['receiptMemu'] = 'invoicePrint';
  2479. $this->render ( "/admin/invoicePrint", $this->data );
  2480. }
  2481. /**
  2482. * 展示发票打印的详情页面
  2483. *
  2484. * @since 1.0.0
  2485. */
  2486. function invoicePrintDetail() {
  2487. Doo::loadClass ( 'XDeode' );
  2488. $XDeode = new XDeode ( 5 );
  2489. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2490. $iid = $XDeode->decode ( $iid );
  2491. if (! is_numeric ( $iid ))
  2492. die ( 'illegal request' );
  2493. Doo::loadModel ( 'invoice' );
  2494. $invoice = new invoice ();
  2495. Doo::loadModel ( 'invoiceOperationLog' );
  2496. $invoiceOperationLog = new invoiceOperationLog ();
  2497. Doo::loadModel ( 'invoicePaper' );
  2498. $invoicePaper = new invoicePaper ();
  2499. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2500. if (empty ( $invoiceDetail ))
  2501. die ( 'illegal request' );
  2502. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2503. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2504. if ($invoiceDetail ['settlementType'] == 1) {
  2505. Doo::loadModel ( 'invoiceTraining' );
  2506. $invoiceTraining = new invoiceTraining ();
  2507. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2508. }
  2509. $this->data ['invoicePaperList'] = $invoicePaperList;
  2510. $this->data ['invoiceDetail'] = $invoiceDetail;
  2511. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2512. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2513. $this->data ['memu'] = "invoice";
  2514. $this->data ['staff'] = $this->staff;
  2515. $this->data ['receiptMemu'] = 'invoicePrint';
  2516. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2517. }
  2518. /**
  2519. * 所有待打印 发票
  2520. */
  2521. function invoicePrintStayAchieve() {
  2522. Doo::loadModel ( 'invoice' );
  2523. $invoice = new invoice ();
  2524. Doo::loadClass ( 'XDeode' );
  2525. $XDeode = new XDeode ( 5 );
  2526. Doo::loadModel ( 'staff' );
  2527. $staff = new staff ();
  2528. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2529. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2530. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2531. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2532. Doo::loadModel ( 'invoiceTraining' );
  2533. $invoiceTraining = new invoiceTraining ();
  2534. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2535. $page_size = 12;
  2536. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2537. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2538. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2539. $get = "/" . $status;
  2540. $con = ' and status=2 ';
  2541. if ($status == 'TOPRINT')
  2542. $con = ' and status=2 and printStatus=0 ';
  2543. elseif ($status == 'PRINTED')
  2544. $con = ' and status=2 and printStatus=1';
  2545. if ($invoiceType == 'ORDINARY')
  2546. $con .= ' and invoiceType=0 and invoiceForm=0 ';
  2547. elseif ($invoiceType == 'SPECIAL'){
  2548. $con .= ' and invoiceType=1 ';
  2549. }elseif($invoiceType == 'ELECTRON'){
  2550. $con .= ' and invoiceType=0 and invoiceForm=1 ';
  2551. }
  2552. if ($invoiceTrain == 'ORDINARY')
  2553. $con .= ' and trainId=0 ';
  2554. elseif ($invoiceTrain == 'TRAIN')
  2555. $con .= ' and trainId!=0 ';
  2556. if ($invoiceTrainName != 'ALL') {
  2557. $trainId = $XDeode->decode ( $invoiceTrainName );
  2558. if (is_numeric ( $trainId ))
  2559. $con .= ' and trainId =' . $trainId;
  2560. }
  2561. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2562. $dateArr = explode ( ':', $date );
  2563. $D1 = '';
  2564. $D2 = '';
  2565. if (! empty ( $date )) {
  2566. $D1 = $dateArr [0];
  2567. $D2 = $dateArr [1];
  2568. }
  2569. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date )){
  2570. $D1= $D1.":00.00.00";
  2571. $D2= $D2.":23.59.59";
  2572. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2573. }
  2574. if (! empty ( $MebSea )) {
  2575. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2576. }
  2577. $pageinfo ['page'] = array (
  2578. 'previous' => ''
  2579. );
  2580. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2581. $sql = " (untreadStatus=0 or untreadStatus=3 or untreadStatus=4) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2582. $action = "invoicePrintStayAchieve";
  2583. //echo $sql;
  2584. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2585. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2586. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2587. $this->data ['trainList'] = $trainList;
  2588. $this->data ['invoiceType'] = $invoiceType;
  2589. $this->data ['invoiceTrain'] = $invoiceTrain;
  2590. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2591. $this->data ['MebSeaEn'] = $MebSea;
  2592. $this->data ['MebSea'] = urlencode ( $MebSea );
  2593. $this->data ['get'] = $get;
  2594. $this->data ['page'] = $pageinfo;
  2595. $this->data ['date'] = $date;
  2596. $this->data ['status'] = $status;
  2597. $this->data ['invoiceType'] = $invoiceType;
  2598. $this->data ['memu'] = "invoice";
  2599. $this->data ['staff'] = $this->staff;
  2600. foreach ( $list as $key => $value ) {
  2601. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2602. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2603. if (! empty ( $lastApprover )) {
  2604. $lastApproverKey = array_keys ( $lastApprover );
  2605. $lastApprover = end ( $lastApprover );
  2606. $staffDetail = $staff->getOne ( array (
  2607. 'where' => 'sid=' . end ( $lastApproverKey ),
  2608. 'asArray' => true
  2609. ) );
  2610. $lastApprover ['username'] = $staffDetail ['username'];
  2611. }
  2612. $list [$key] ['lastApprover'] = $lastApprover;
  2613. }
  2614. $this->data ['receiptMemu'] = 'invoicePrint';
  2615. $this->data ['list'] = $list;
  2616. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2617. }
  2618. /**
  2619. * 填写票号并完成打印
  2620. * @since 1.0.0
  2621. */
  2622. function invoicePrintDo() {
  2623. Doo::loadModel ( 'invoice' );
  2624. $invoice = new invoice ();
  2625. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2626. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2627. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2628. $iid = $invoice->authcode ( $iid );
  2629. if (! is_numeric ( $iid ))
  2630. die ( 'illegal request-iid' );
  2631. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2632. Doo::loadModel ( 'invoiceOperationLog' );
  2633. $invoiceOperationLog = new invoiceOperationLog ();
  2634. Doo::loadModel ( 'invoiceStatistics' );
  2635. $invoiceStatistics = new invoiceStatistics ();
  2636. $XDeode = new XDeode ( 5 );
  2637. Doo::loadModel ( 'invoicePaper' );
  2638. $invoicePaper = new invoicePaper ();
  2639. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2640. if (empty ( $invoicePrintDetail ))
  2641. die ( 'illegal request-data_empty' );
  2642. //
  2643. $ipid = $XDeode->decode ( $invoiceNo );
  2644. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2645. if (empty ( $paperDetail ))
  2646. die ( 'illegal request-paper_empty' );
  2647. $invoicePaper = new invoicePaper ();
  2648. $item = array (
  2649. 'iid' => $iid,
  2650. 'ipid' => $ipid
  2651. );
  2652. $invoicePaper->setInvoicePaperByCondition ( $item );
  2653. $item = array (
  2654. 'iid' => $iid,
  2655. 'printStatus' => 1,
  2656. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2657. 'printer' => $this->staff [0] ['username'],
  2658. 'printTime' => date ( "Y-m-d H:i:s" ),
  2659. 'invoiceNo' => $paperDetail ['invoiceNo']
  2660. );
  2661. $invoice->setInvoiceByCondition ( $item );
  2662. $item = array (
  2663. 'date' => date ( "Y-m-d H:i:s" ),
  2664. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2665. 'status' => 5,
  2666. 'img' => $this->staff [0] ['avatar'],
  2667. 'username' => $this->staff [0] ['username'],
  2668. 'uid' => $this->staff [0] ['sid'],
  2669. 'category' => $this->staff [0] ['category'],
  2670. 'iid' => $iid
  2671. );
  2672. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2673. // 去统计--负票不汇总
  2674. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2675. $item = array (
  2676. 'date' => date ( "Y-m-d H:i:s" ),
  2677. 'priceClass' => 1,
  2678. 'cid' => $invoicePrintDetail ['cid'],
  2679. 'staff' => $invoicePrintDetail ['sid'],
  2680. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2681. );
  2682. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2683. }
  2684. // 发送通知信息到微信-去除
  2685. // $this->setWXMsg($iid,'PRINT');
  2686. // 发票信息库
  2687. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2688. // 申请人获取微信通知
  2689. Doo::loadModel ( 'staff' );
  2690. $staff = new staff ();
  2691. Doo::loadClass ( 'XDeode' );
  2692. $XDeode = new XDeode ( 5 );
  2693. $username2 = $staff->getOne ( array (
  2694. 'select' => 'wxid',
  2695. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2696. 'asArray' => TRUE
  2697. ) );
  2698. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2699. $msg = '';
  2700. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2701. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2702. if (empty ( $invoicePrintType ))
  2703. return "/invoicePrint";
  2704. else
  2705. return "/invoicePrintStayAchieve";
  2706. }
  2707. }
  2708. /**
  2709. * 需要邮寄的发票
  2710. * @since 1.0.0
  2711. */
  2712. function invoicePost() {
  2713. Doo::loadModel ( 'invoice' );
  2714. $invoice = new invoice ();
  2715. Doo::loadModel ( 'express' );
  2716. $express = new express ();
  2717. $invoicePost = $invoice->getPostByInvoice ();
  2718. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2719. $expressList = $express->getExpressByAll ();
  2720. $invoicePostExpress = "";
  2721. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2722. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2723. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2724. $this->data ['expressList'] = $expressList;
  2725. $this->data ['invoicePost'] = $invoicePost;
  2726. $this->data ['invoicePosted'] = $invoicePosted;
  2727. $this->data ['memu'] = "invoice";
  2728. $this->data ['staff'] = $this->staff;
  2729. $this->data ['receiptMemu'] = 'invoicePost';
  2730. $this->render ( "/admin/invoicePost", $this->data );
  2731. }
  2732. /**
  2733. * 添加发票邮寄信息
  2734. */
  2735. function invoiceExpressAddDo() {
  2736. Doo::loadModel ( 'invoice' );
  2737. $invoice = new invoice ();
  2738. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2739. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2740. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2741. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2742. $iid = $iid = $invoice->authcode ( $iid );
  2743. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2744. die ( 'illegal request' );
  2745. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2746. setcookie ( 'invoicePostExpress', $expressNumber );
  2747. $item = array (
  2748. 'iid' => $iid,
  2749. 'postStatus' => 1,
  2750. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2751. 'postTime' => date ( "Y-m-d H:i:s" ),
  2752. 'expressCompany' => $expressCompany,
  2753. 'expressNumber' => $expressNumber,
  2754. 'actualItems' => $actualItems,
  2755. 'poster' => $this->staff [0] ['username']
  2756. );
  2757. $invoice->setInvoiceByCondition ( $item );
  2758. // 微信通知-去掉
  2759. // $this->setWXMsg ( $iid );
  2760. Doo::loadModel ( 'staff' );
  2761. $staff = new staff ();
  2762. Doo::loadClass ( 'XDeode' );
  2763. $XDeode = new XDeode ( 5 );
  2764. $username2 = $staff->getOne ( array (
  2765. 'select' => 'wxid',
  2766. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2767. 'asArray' => TRUE
  2768. ) );
  2769. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2770. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2771. if (empty ( $expCom ))
  2772. $expCom [0] = '';
  2773. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2774. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2775. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2776. return '/invoicePost';
  2777. }
  2778. function invoiceExpressUpdateDo() {
  2779. Doo::loadModel ( 'invoice' );
  2780. $invoice = new invoice ();
  2781. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2782. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2783. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2784. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2785. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2786. $iid = $invoice->authcode ( $iid );
  2787. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2788. die ( 'illegal request' );
  2789. $item = array (
  2790. 'iid' => $iid,
  2791. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2792. 'expressCompany' => $expressCompany,
  2793. 'expressNumber' => $expressNumber,
  2794. 'actualItems' => $actualItems,
  2795. 'poster' => $this->staff [0] ['username']
  2796. );
  2797. $invoice->setInvoiceByCondition ( $item );
  2798. return $action;
  2799. }
  2800. /**
  2801. * 可退票管理
  2802. */
  2803. function invoiceUntreadIsAchieve() {
  2804. Doo::loadModel ( 'invoice' );
  2805. $invoice = new invoice ();
  2806. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2807. /*
  2808. * 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' => '' );
  2809. */
  2810. if (empty ( $MebSea )) {//
  2811. $con = ' and invoiceNo like "NULL" ';
  2812. } else {
  2813. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2814. }
  2815. // printStatus=1 and
  2816. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2817. /*
  2818. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2819. */
  2820. $limit = '0,50';
  2821. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2822. //print_r($list);
  2823. $this->data ['MebSeaEn'] = $MebSea;
  2824. /*
  2825. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2826. */
  2827. $this->data ['list'] = $list;
  2828. $this->data ['memu'] = "invoice";
  2829. $this->data ['staff'] = $this->staff;
  2830. $this->data ['receiptMemu'] = 'invoice';
  2831. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2832. }
  2833. // 已经退票的发票
  2834. function invoiceUntreadED() {
  2835. Doo::loadModel ( 'invoice' );
  2836. $invoice = new invoice ();
  2837. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2838. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2839. Doo::loadClass ( 'XDeode' );
  2840. $XDeode = new XDeode ( 5 );
  2841. $page_size = 18;
  2842. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2843. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2844. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2845. $dateArr = explode ( ':', $date );
  2846. $D1 = '';
  2847. $D2 = '';
  2848. if (! empty ( $date )) {
  2849. $D1 = $dateArr [0];
  2850. $D2 = $dateArr [1];
  2851. }
  2852. $con = '';
  2853. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2854. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2855. }
  2856. // if ($date == 'MONTHO')
  2857. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2858. // elseif ($date == 'MONTHT')
  2859. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2860. // elseif ($date == 'MONTHY')
  2861. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2862. if (! empty ( $MebSea )) {
  2863. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2864. }
  2865. if ($invoiceType == 'ORDINARY') {
  2866. $con .= ' and invoiceType=0 ';
  2867. } elseif ($invoiceType == 'SPECIAL') {
  2868. $con .= ' and invoiceType=1 ';
  2869. }
  2870. $pageinfo ['page'] = array (
  2871. 'previous' => ''
  2872. );
  2873. // printStatus=1 and
  2874. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2875. $action = "invoiceUntreadED";
  2876. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2877. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2878. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2879. // print_r($list);
  2880. $this->data ['MebSeaEn'] = $MebSea;
  2881. $this->data ['get'] = $get;
  2882. $this->data ['page'] = $pageinfo;
  2883. $this->data ['date'] = $date;
  2884. $this->data ['invoiceType'] = $invoiceType;
  2885. $this->data ['list'] = $list;
  2886. $this->data ['memu'] = "invoice";
  2887. $this->data ['staff'] = $this->staff;
  2888. $this->data ['receiptMemu'] = 'invoice';
  2889. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2890. }
  2891. /**
  2892. * 退票处理页面
  2893. */
  2894. function invoiceUntread() {
  2895. Doo::loadModel ( 'invoice' );
  2896. $invoice = new invoice ();
  2897. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2898. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2899. //print_r($establishedInvoice);
  2900. // foreach ( $establishedInvoice as $key => $value ) {
  2901. // // months
  2902. // $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2903. // $nowDate = strtotime ( 'now' );
  2904. // $establishedInvoice [$key] ['lossShow'] = false;
  2905. // if ($lossDate < $nowDate)
  2906. // $establishedInvoice [$key] ['lossShow'] = true;
  2907. // }
  2908. $this->data ['untreadInvoice'] = $untreadInvoice;
  2909. $this->data ['establishedInvoice'] = $establishedInvoice;
  2910. $this->data ['memu'] = "invoice";
  2911. $this->data ['staff'] = $this->staff;
  2912. $this->data ['receiptMemu'] = 'invoiceUntread';
  2913. $this->render ( "/admin/invoiceUntread", $this->data );
  2914. }
  2915. /**
  2916. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2917. */
  2918. function invoiceUntreadEstablishedDo() {
  2919. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2920. Doo::loadModel ( 'invoice' );
  2921. $invoice = new invoice ();
  2922. Doo::loadModel ( 'invoiceOperationLog' );
  2923. $invoiceOperationLog = new invoiceOperationLog ();
  2924. Doo::loadModel ( 'invoiceReceivables' );
  2925. Doo::loadModel ( 'invoiceStatistics' );
  2926. $iid = $invoice->authcode ( $untreadIidKey );
  2927. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2928. die ( 'illegal request' );
  2929. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2930. if ($invoiceDetails ['untreadStatus'] != 1)
  2931. die ( 'illegal request untreadStatus error !=1' );
  2932. $item = array (
  2933. 'iid' => $iid,
  2934. // 'irid'=>'',
  2935. 'untreadStatus' => 2,
  2936. 'untreadTime'=>date ( "Y-m-d H:i:s" ) ,
  2937. 'updateTime' => date ( "Y-m-d H:i:s" )
  2938. );
  2939. $invoice->setInvoiceByCondition ( $item );
  2940. $item = array (
  2941. 'date' => date ( "Y-m-d H:i:s" ),
  2942. 'operation' => '已确认退票',
  2943. 'status' => 6,
  2944. 'img' => $this->staff [0] ['avatar'],
  2945. 'username' => $this->staff [0] ['username'],
  2946. 'uid' => $this->staff [0] ['sid'],
  2947. 'category' => $this->staff [0] ['category'],
  2948. 'iid' => $iid
  2949. );
  2950. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2951. // 收款解绑以及入账扣除 收款扣除
  2952. if (! empty ( $invoiceDetails ['irid'] )) {
  2953. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2954. foreach ( $iridList as $value ) {
  2955. $invoiceReceivables = new invoiceReceivables ();
  2956. $irDetails = $invoiceReceivables->getOne ( array (
  2957. 'where' => " irid=" . $value . ' ',
  2958. 'asArray' => TRUE
  2959. ) );
  2960. $bindPrice=$irDetails['bindPrice']-$invoiceDetails['invoicePrice'];
  2961. if($bindPrice<0){
  2962. $bindPrice=0;
  2963. }
  2964. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  2965. $item = array (
  2966. 'irid' => $value,
  2967. 'bindStatus' => 0,
  2968. 'untreadStatus' => 1,
  2969. 'bindPrice'=>$bindPrice,
  2970. 'untreadStaff' => $invoiceDetails ['userName'],
  2971. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2972. );
  2973. if($irDetails['iid']==$iid){
  2974. $item+=array(
  2975. 'iid' => 0
  2976. );
  2977. }else{
  2978. foreach ($iidExtend as $iek=>$iev){
  2979. if($iev==$iid){
  2980. unset($iidExtend[$iek]);
  2981. break;
  2982. }
  2983. }
  2984. if(empty($iidExtend)){
  2985. $item+=array(
  2986. 'iidExtend' => ''
  2987. );
  2988. }else{
  2989. $iidExtend=implode(",", $iidExtend);
  2990. $item+=array(
  2991. 'iidExtend' => $iidExtend
  2992. );
  2993. }
  2994. }
  2995. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2996. if (! empty ( $irDetails )) {
  2997. // 扣除入账
  2998. $invoiceStatistics = new invoiceStatistics ();
  2999. $item = array (
  3000. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3001. 'priceClass' => 3,
  3002. 'cid' => $invoiceDetails ['cid'],
  3003. 'staff' => $invoiceDetails ['sid'],
  3004. 'accountPrice' => - $irDetails ['receivablesPrice']
  3005. );
  3006. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3007. // 扣除收款
  3008. $invoiceStatistics = new invoiceStatistics ();
  3009. $item = array (
  3010. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3011. 'priceClass' => 2,
  3012. 'cid' => $invoiceDetails ['cid'],
  3013. 'staff' => $invoiceDetails ['sid'],
  3014. 'irid' => $irDetails ['irid'],
  3015. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  3016. );
  3017. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3018. }
  3019. // 解绑时删除收入流水--退票不删除流水
  3020. // Doo::loadModel ( 'wasteBook' );
  3021. // $wasteBook = new wasteBook ();
  3022. // $wasteBook->delete ( array (
  3023. // 'where' => 'dataID=' . $value . ' and accountType=7',
  3024. // 'limit' => 1
  3025. // ) );
  3026. }
  3027. }
  3028. return "/invoiceUntread";
  3029. }
  3030. function invoiceUntreadRecallDo() {
  3031. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  3032. Doo::loadModel ( 'invoice' );
  3033. $invoice = new invoice ();
  3034. Doo::loadClass ( 'XDeode' );
  3035. $XDeode = new XDeode ( 5 );
  3036. Doo::loadModel ( 'invoiceOperationLog' );
  3037. $invoiceOperationLog = new invoiceOperationLog ();
  3038. $iid = $XDeode->decode ( $iidKey );
  3039. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  3040. if (empty ( $invoiceDetail )) {
  3041. die ( 'illegal request-DATANULL' );
  3042. }
  3043. $item = array (
  3044. 'iid' => $iid,
  3045. 'untreadStatus' => 0
  3046. );
  3047. $invoice->setInvoiceByCondition ( $item );
  3048. $item = array (
  3049. 'date' => date ( "Y-m-d H:i:s" ),
  3050. 'operation' => '撤回申请退票',
  3051. 'status' => 13,
  3052. 'img' => $this->staff [0] ['avatar'],
  3053. 'username' => $this->staff [0] ['username'],
  3054. 'uid' => $this->staff [0] ['sid'],
  3055. 'category' => $this->staff [0] ['category'],
  3056. 'iid' => $iid
  3057. );
  3058. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3059. return "/invoiceUntread";
  3060. }
  3061. /**
  3062. * 建立负票,关联原来发票
  3063. */
  3064. function invoiceLossDo() {
  3065. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3066. if (! empty ( $iidKey )) {
  3067. Doo::loadClass ( 'XDeode' );
  3068. $XDeode = new XDeode ( 5 );
  3069. Doo::loadModel ( 'invoice' );
  3070. $invoice = new invoice ();
  3071. Doo::loadModel ( 'invoiceOperationLog' );
  3072. $invoiceOperationLog = new invoiceOperationLog ();
  3073. $iidKey = $XDeode->decode ( $iidKey );
  3074. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3075. // 拷贝插入一条发票数据
  3076. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3077. // 更新负票
  3078. if($invoiceDetail['invoiceForm']==1){
  3079. $invoiceSerial = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3080. }else{
  3081. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3082. }
  3083. $invoice = new invoice ();
  3084. $item = array (
  3085. 'iid' => $iid,
  3086. 'sid' => $this->staff [0] ['sid'],
  3087. 'userName' => $this->staff [0] ['username'],
  3088. 'cid' => $this->staff [0] ['cid'],
  3089. 'categoryName' => $this->staff [0] ['category'],
  3090. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3091. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3092. 'invoiceSerial' => $invoiceSerial,
  3093. 'invoiceNo' => '',
  3094. 'printStatus' => 0,
  3095. 'untreadStatus' => 4,
  3096. // 关联发票号
  3097. 'lossIid' => $invoiceDetail ['iid']
  3098. );
  3099. $invoice->setInvoiceByCondition ( $item );
  3100. // 更新原发票
  3101. $invoice = new invoice ();
  3102. $item = array (
  3103. 'iid' => $invoiceDetail ['iid'],
  3104. 'lossIid' => $iid
  3105. );
  3106. $invoice->setInvoiceByCondition ( $item );
  3107. // 操作日志
  3108. $item = array (
  3109. 'date' => date ( "Y-m-d H:i:s" ),
  3110. 'operation' => "创建负票" . $invoiceSerial,
  3111. 'status' => 12,
  3112. 'img' => $this->staff [0] ['avatar'],
  3113. 'username' => $this->staff [0] ['username'],
  3114. 'uid' => $this->staff [0] ['sid'],
  3115. 'category' => $this->staff [0] ['category'],
  3116. 'iid' => $iid
  3117. );
  3118. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3119. // print_r($invoiceDetail);
  3120. // echo $iid;die;
  3121. }
  3122. return '/invoiceUntread';
  3123. }
  3124. /**
  3125. * 上传银行到账 收款文件
  3126. */
  3127. function invoiceReceivablesBankUpload() {
  3128. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3129. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3130. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3131. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3132. header ( "HTTP/1.1 500 Internal Server Error" );
  3133. echo "POST exceeded maximum allowed size.";
  3134. exit ( 0 );
  3135. }
  3136. // Settings
  3137. $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)
  3138. $upload_name = "Filedata";
  3139. $file_name = "";
  3140. $nk = time ();
  3141. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3142. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3143. echo "文件无法保存.";
  3144. exit ( 0 );
  3145. }
  3146. echo json_encode ( array (
  3147. 'filename' => $file_name,
  3148. 'id' => $nk
  3149. ) );
  3150. exit ( 0 );
  3151. }
  3152. /**
  3153. * 解析银行到账收款execl并导入库中
  3154. */
  3155. function invoiceReceivablesImport() {
  3156. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3157. if ($path != "") {
  3158. Doo::loadModel ( 'invoiceReceivables' );
  3159. $invoiceReceivables = new invoiceReceivables ();
  3160. Doo::loadClass ( 'invoice.func' );
  3161. Doo::loadModel ( 'invoiceROLog' );
  3162. $invoiceROLog = new invoiceROLog ();
  3163. Doo::loadModel ( 'invoiceStatistics' );
  3164. $invoiceStatistics = new invoiceStatistics ();
  3165. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3166. $bankBatchNumber = 'BBN_' . time ();
  3167. Doo::db ()->beginTransaction ();
  3168. // 批量存储收款--由于必须获得收款ID,
  3169. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3170. VALUES ';
  3171. $date = date ( "Y-m-d" );
  3172. $receivablesList = array ();
  3173. foreach ( $exlArray as $key => $value ) {
  3174. $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"] . '")';
  3175. array_push ( $receivablesList, $receivablesSql );
  3176. }
  3177. $sql = $sql . implode ( ',', $receivablesList );
  3178. // echo $sql;
  3179. Doo::db ()->query ( $sql );
  3180. // 批量存储收款统计
  3181. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3182. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3183. // 没有irid 回滚所有操作
  3184. if (empty ( $iridList )) {
  3185. Doo::db ()->rollBack ();
  3186. header ( 'Content-Type:text/html;charset=utf-8' );
  3187. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3188. }
  3189. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3190. VALUES ';
  3191. $statisticsList = array ();
  3192. foreach ( $iridList as $value ) {
  3193. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3194. array_push ( $statisticsList, $statisticsSql );
  3195. }
  3196. $sql = $sql . implode ( ',', $statisticsList );
  3197. Doo::db ()->query ( $sql );
  3198. // 批量存储操作日志
  3199. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3200. VALUES ';
  3201. $ROLogList = array ();
  3202. foreach ( $iridList as $value ) {
  3203. $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'] . '")';
  3204. array_push ( $ROLogList, $ROLogSql );
  3205. }
  3206. $sql = $sql . implode ( ',', $ROLogList );
  3207. Doo::db ()->query ( $sql );
  3208. // 批量写入流水
  3209. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3210. VALUES ';
  3211. $wasteBookList = array ();
  3212. foreach ( $iridList as $value ) {
  3213. $accountBank = '';
  3214. if ($value ['receivablesBank'] == '纵横广发') {
  3215. $accountBank = 'CGBDeposit';
  3216. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3217. $accountBank = 'ICBCDeposit';
  3218. } elseif ($value ['receivablesBank'] == '华润银行') {
  3219. $accountBank = 'HUADeposit';
  3220. } elseif ($value ['receivablesBank'] == '个人广发') {
  3221. $accountBank = 'PersonalDeposit';
  3222. }
  3223. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3224. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3225. array_push ( $wasteBookList, $wasteBookSql );
  3226. }
  3227. $sql = $sql . implode ( ',', $wasteBookList );
  3228. Doo::db ()->query ( $sql );
  3229. Doo::db ()->commit ();
  3230. return "/invoiceReceivables";
  3231. }
  3232. echo 'no file';
  3233. }
  3234. function invoiceReceivables() {
  3235. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3236. Doo::loadModel ( 'L_category' );
  3237. $lCategory = new L_category ();
  3238. Doo::loadModel ( 'staff' );
  3239. $staff = new staff ();
  3240. Doo::loadModel ( 'invoiceReceivables' );
  3241. $invoiceReceivables = new invoiceReceivables ();
  3242. Doo::loadModel ( 'invoice' );
  3243. $invoice = new invoice ();
  3244. Doo::loadClass ( 'XDeode' );
  3245. $XDeode = new XDeode ( 5 );
  3246. $category = $lCategory->getCategory ();
  3247. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3248. $sql = 'bindStatus=1 and iid!=0';
  3249. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3250. // 获取未入账发票
  3251. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3252. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3253. foreach ( $invoiceUnAccount as $key => $value ) {
  3254. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3255. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3256. if (! empty ( $lastApprover )) {
  3257. $lastApproverKey = array_keys ( $lastApprover );
  3258. $lastApprover = end ( $lastApprover );
  3259. $staffDetail = $staff->getOne ( array (
  3260. 'where' => 'sid=' . end ( $lastApproverKey ),
  3261. 'asArray' => true
  3262. ) );
  3263. $lastApprover ['username'] = $staffDetail ['username'];
  3264. }
  3265. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3266. }
  3267. foreach ( $invoiceExistAccount as $key => $value ) {
  3268. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3269. // if (empty ( $irList ))
  3270. // $irList [0] ['sumPrice'] = 0;
  3271. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3272. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3273. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3274. }
  3275. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3276. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3277. $this->data ['halfList'] = $halfList;
  3278. $this->data ['halfCount'] = count ( $halfList );
  3279. // print_r($receivablesList);
  3280. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3281. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3282. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3283. $this->data ['receivablesInput'] = $receivablesInput;
  3284. $this->data ['year'] = date ( 'Y' );
  3285. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3286. $this->data ['receivablesList'] = $receivablesList;
  3287. $this->data ['staffList'] = $staffList;
  3288. $this->data ['category'] = $category;
  3289. $this->data ['memu'] = "invoice";
  3290. $this->data ['staff'] = $this->staff;
  3291. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3292. $this->render ( "/admin/invoiceReceivables", $this->data );
  3293. }
  3294. /**
  3295. * 设置收款认领地区
  3296. */
  3297. function setInvoiceReceivablesClaim() {
  3298. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3299. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3300. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3301. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3302. Doo::loadModel ( 'invoiceReceivables' );
  3303. $invoiceReceivables = new invoiceReceivables ();
  3304. Doo::loadClass ( 'XDeode' );
  3305. $XDeode = new XDeode ( 5 );
  3306. Doo::loadModel ( 'invoiceROLog' );
  3307. $invoiceROLog = new invoiceROLog ();
  3308. $irid = $XDeode->decode ( $iridKey );
  3309. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3310. if (empty ( $irDetail ))
  3311. die ( 'illegal request' );
  3312. $item = array (
  3313. 'irid' => $irid,
  3314. 'receivablesCategory' => $receivablesCategory
  3315. );
  3316. if ($receivablesCategory != 'PUBLIC') {
  3317. $item += array (
  3318. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3319. 'inputType' => 1
  3320. );
  3321. }
  3322. $invoiceReceivables = new invoiceReceivables ();
  3323. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3324. // 收款操作日志
  3325. $item = array (
  3326. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3327. 'date' => date ( "Y-m-d" ),
  3328. 'status' => 1,
  3329. 'img' => $this->staff [0] ['avatar'],
  3330. 'username' => $this->staff [0] ['username'],
  3331. 'uid' => $this->staff [0] ['sid'],
  3332. 'category' => $this->staff [0] ['category'],
  3333. 'irid' => $irid
  3334. );
  3335. $invoiceROLog->setInvoiceROLog ( $item );
  3336. if (empty ( $action ))
  3337. return '/invoiceReceivables';
  3338. else
  3339. return "/invoiceReceivablesAS";
  3340. }
  3341. die ( 'illegal request' );
  3342. }
  3343. /**
  3344. * 新添加收款直接入账发票
  3345. */
  3346. function invoiceCompareClaimPrice() {
  3347. // 收款录入
  3348. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3349. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3350. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3351. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3352. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3353. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3354. Doo::loadModel ( 'invoiceReceivables' );
  3355. $invoiceReceivables = new invoiceReceivables ();
  3356. Doo::loadModel ( 'invoiceROLog' );
  3357. $invoiceROLog = new invoiceROLog ();
  3358. Doo::loadModel ( 'invoiceStatistics' );
  3359. Doo::loadModel ( 'invoice' );
  3360. $invoice = new invoice ();
  3361. Doo::loadModel ( 'bill' );
  3362. $bill = new bill ();
  3363. Doo::loadClass ( 'XDeode' );
  3364. $XDeode = new XDeode ( 5 );
  3365. Doo::loadModel ( 'invoiceOperationLog' );
  3366. $invoiceOperationLog = new invoiceOperationLog ();
  3367. $iidKey = $XDeode->decode ( $iidKey );
  3368. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3369. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3370. die ( 'illegal request' );
  3371. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3372. // 收款录入 并绑定发票
  3373. Doo::db ()->beginTransaction ();
  3374. //获得发票入账余额
  3375. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3376. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3377. $bindStatus = 0;
  3378. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3379. if($invoiceDetail ['invoiceBalance']!=0){
  3380. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3381. }
  3382. if ($receivablesPrice <= $invoiceBalance){
  3383. $bindStatus = 1;
  3384. //$bindPrice=$receivablesPrice;
  3385. }
  3386. $titleMark = $invoiceDetail ['invoiceTitle'];
  3387. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3388. $titleMark = $invoiceDetail ['invoiceCompany'];
  3389. $item = array (
  3390. 'recepitTitleMark' => $titleMark,
  3391. 'bindStatus' => $bindStatus,
  3392. 'iid' => $invoiceDetail ['iid'],
  3393. 'bindPrice' => $receivablesPrice,
  3394. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3395. 'receivablesPrice' => $receivablesPrice,
  3396. 'OriginalPrice' => $receivablesPrice,
  3397. 'receivablesMessage' => $receivablesMessage,
  3398. 'receivablesSerial' => $receivablesSerial,
  3399. 'receivablesBank' => $receivablesBank,
  3400. 'receivablesDate' => $receivablesDate,
  3401. 'inputStaff' => $this->staff [0] ['username'],
  3402. 'accountClerk' => $this->staff [0] ['username'],
  3403. 'date' => date ( "Y-m-d" ),
  3404. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3405. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3406. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3407. );
  3408. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3409. $item = array ();
  3410. // 收款操作日志
  3411. $item = array (
  3412. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3413. );
  3414. $item += array (
  3415. 'date' => date ( "Y-m-d" ),
  3416. 'status' => 1,
  3417. 'img' => $this->staff [0] ['avatar'],
  3418. 'username' => $this->staff [0] ['username'],
  3419. 'uid' => $this->staff [0] ['sid'],
  3420. 'category' => $this->staff [0] ['category'],
  3421. 'irid' => $irid
  3422. );
  3423. $invoiceROLog->setInvoiceROLog ( $item );
  3424. // 收款统计
  3425. $invoiceStatistics = new invoiceStatistics ();
  3426. $item = array (
  3427. 'date' => $receivablesDate,
  3428. 'priceClass' => 2,
  3429. 'irid' => $irid,
  3430. 'cid' => $invoiceDetail ['cid'],
  3431. 'staff' => $invoiceDetail ['sid'],
  3432. 'receivablesPrice' => $receivablesPrice
  3433. );
  3434. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3435. // 收款 入 发票
  3436. $detail = $invoiceDetail;
  3437. $iridString = "";
  3438. if (empty ( $detail ['irid'] ))
  3439. $iridString = $irid;
  3440. else
  3441. $iridString = $detail ['irid'] . ',' . $irid;
  3442. $item = array (
  3443. 'irid' => $iridString,
  3444. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3445. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3446. 'iid' => $detail ['iid']
  3447. );
  3448. // $invoiceReceivables = new invoiceReceivables ();
  3449. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3450. // $sumBind = $bindInvicePrice;
  3451. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3452. // $sum=$sumBind+$sumBalance;
  3453. // ;
  3454. if ($receivablesPrice>=$invoiceBalance){
  3455. $item += array (
  3456. 'invoiceBalance'=>0,
  3457. 'untreadStatus' => 3
  3458. );
  3459. }else{
  3460. $item += array (
  3461. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3462. );
  3463. }
  3464. $invoice->setInvoiceByCondition ( $item );
  3465. // 操作日志
  3466. $item = array (
  3467. 'date' => date ( "Y-m-d H:i:s" ),
  3468. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3469. 'status' => 8,
  3470. 'img' => $this->staff [0] ['avatar'],
  3471. 'username' => $this->staff [0] ['username'],
  3472. 'uid' => $this->staff [0] ['sid'],
  3473. 'category' => $this->staff [0] ['category'],
  3474. 'iid' => $detail ['iid']
  3475. );
  3476. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3477. // 入账汇总
  3478. $invoiceStatistics = new invoiceStatistics ();
  3479. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3480. // $accountPrice = 0;
  3481. // foreach ( $list as $key => $value ) {
  3482. // $accountPrice += $value ['receivablesPrice'];
  3483. // }
  3484. $item = array (
  3485. 'date' => $receivablesDate,
  3486. 'priceClass' => 3,
  3487. 'cid' => $invoiceDetail ['cid'],
  3488. 'staff' => $invoiceDetail ['sid'],
  3489. 'accountPrice' => $receivablesPrice
  3490. );
  3491. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3492. //发票入账记录
  3493. $bill->iid=$invoiceDetail['iid'];
  3494. $bill->trainId=$invoiceDetail['trainId'];
  3495. $bill->irid=$irid;
  3496. $bill->create_time=date ( "Y-m-d H:i:s" );
  3497. $bill->price=$invoiceBalance;
  3498. $bill->insert ();
  3499. // 公司流水记录
  3500. Doo::loadModel ( 'wasteBook' );
  3501. $wasteBook = new wasteBook ();
  3502. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3503. $accountBank=$wasteBook->_getAccountBankEN($receivablesBank);
  3504. if (empty ( $abDetail )) {
  3505. $item = array (
  3506. 'dataID' => $irid,
  3507. 'expensesType' => 1,
  3508. 'accountType' => 7,
  3509. 'accountPrice' => $receivablesPrice,
  3510. 'accountPriceShow' => $receivablesPrice,
  3511. 'accountBank' => $accountBank,
  3512. 'cid'=>$invoiceDetail['cid'],
  3513. 'category' => $invoiceDetail ['categoryName'],
  3514. 'name' => $this->staff [0] ['username'],
  3515. 'sid' => $this->staff [0] ['sid'],
  3516. 'inputDate' => $receivablesDate//date ( "Y-m-d H:i:s" )
  3517. );
  3518. $wasteBook->setAccountBookStatistics ( $item );
  3519. }
  3520. Doo::db ()->commit ();
  3521. }
  3522. return '/invoiceReceivables';
  3523. }
  3524. /**
  3525. * 录入收款数据
  3526. * @return string
  3527. */
  3528. function invoiceReceivablesDo() {
  3529. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3530. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3531. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3532. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3533. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3534. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3535. Doo::loadModel ( 'invoiceReceivables' );
  3536. $invoiceReceivables = new invoiceReceivables ();
  3537. Doo::loadModel ( 'invoiceROLog' );
  3538. $invoiceROLog = new invoiceROLog ();
  3539. Doo::loadModel ( 'invoiceStatistics' );
  3540. $invoiceStatistics = new invoiceStatistics ();
  3541. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3542. $item = array (
  3543. 'receivablesPrice' => $receivablesPrice,
  3544. 'OriginalPrice' => $receivablesPrice,
  3545. 'receivablesMessage' => $receivablesMessage,
  3546. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3547. 'receivablesBank' => $receivablesBank,
  3548. 'receivablesDate' => $receivablesDate,
  3549. 'inputStaff' => $this->staff [0] ['username'],
  3550. 'date' => date ( "Y-m-d" ),
  3551. 'receivablesCategory' => $receivablesCategory,
  3552. 'receivablesStaff' => $receivablesStaff
  3553. );
  3554. if ($receivablesCategory != 'PUBLIC') {
  3555. $item += array (
  3556. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3557. 'inputType' => 1
  3558. );
  3559. }
  3560. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3561. $item = array ();
  3562. // 收款操作日志
  3563. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3564. $item = array (
  3565. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3566. );
  3567. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3568. $item = array (
  3569. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3570. );
  3571. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3572. $receivablesStaff = explode ( '-', $receivablesStaff );
  3573. $item = array (
  3574. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3575. );
  3576. }
  3577. $item += array (
  3578. 'date' => date ( "Y-m-d" ),
  3579. 'status' => 1,
  3580. 'img' => $this->staff [0] ['avatar'],
  3581. 'username' => $this->staff [0] ['username'],
  3582. 'uid' => $this->staff [0] ['sid'],
  3583. 'category' => $this->staff [0] ['category'],
  3584. 'irid' => $irid
  3585. );
  3586. $invoiceROLog->setInvoiceROLog ( $item );
  3587. $item = array (
  3588. 'date' => $receivablesDate,
  3589. 'priceClass' => 2,
  3590. 'irid' => $irid,
  3591. 'receivablesPrice' => $receivablesPrice
  3592. );
  3593. if ($receivablesCategory != 'PUBLIC') {
  3594. $receivablesCategory = explode ( ":", $receivablesCategory );
  3595. $item += array (
  3596. 'cid' => $receivablesCategory [0]
  3597. );
  3598. }
  3599. if ($receivablesStaff2 != 'PUBLIC') {
  3600. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3601. $item += array (
  3602. 'staff' => $receivablesStaff [0]
  3603. );
  3604. }
  3605. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3606. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3607. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3608. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3609. if ($toparty != 0)
  3610. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3611. // 公司流水记录
  3612. Doo::loadModel ( 'wasteBook' );
  3613. $wasteBook = new wasteBook ();
  3614. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3615. $accountBank=$wasteBook->_getAccountBankEN($receivablesBank);
  3616. $item = array (
  3617. 'dataID' => $irid,
  3618. 'expensesType' => 1,
  3619. 'accountType' => 7,
  3620. 'accountPriceShow' => $receivablesPrice,
  3621. 'accountPrice' => $receivablesPrice,
  3622. 'accountBank' => $accountBank,
  3623. 'category' => $this->staff [0] ['category'],
  3624. 'cid' => $this->staff [0] ['cid'],
  3625. 'name' => $this->staff [0] ['username'],
  3626. 'sid' => $this->staff [0] ['sid'],
  3627. 'inputDate' => $receivablesDate ,
  3628. //'createAt'=>date ( "Y-m-d H:i:s" ) ,
  3629. 'synPaymentDate'=>1
  3630. );
  3631. $wasteBook->setAccountBookStatistics ( $item );
  3632. }
  3633. return "/invoiceReceivables";
  3634. }
  3635. /**
  3636. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3637. */
  3638. function invoiceReceivablesClaim() {
  3639. Doo::loadModel ( 'invoiceReceivables' );
  3640. $invoiceReceivables = new invoiceReceivables ();
  3641. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3642. $this->data ['receivablesList'] = $receivablesList;
  3643. $this->data ['memu'] = "invoice";
  3644. $this->data ['staff'] = $this->staff;
  3645. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3646. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3647. }
  3648. function invoiceReceivablesTitleMarkSet() {
  3649. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3650. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3651. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3652. die ( 'illegal request' );
  3653. Doo::loadModel ( 'invoiceReceivables' );
  3654. $invoiceReceivables = new invoiceReceivables ();
  3655. Doo::loadClass ( 'XDeode' );
  3656. $XDeode = new XDeode ( 5 );
  3657. $irid = $XDeode->decode ( $iridKey );
  3658. if (! is_numeric ( $irid ))
  3659. die ( 'illegal request' );
  3660. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3661. $invoiceReceivables->update ( array (
  3662. 'where' => 'irid = ' . $irid
  3663. ) );
  3664. return '/invoiceReceivablesClaim';
  3665. }
  3666. /**
  3667. * 更新收款相关数据
  3668. */
  3669. function invoiceReceivablesUpdateClaim() {
  3670. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3671. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3672. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3673. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3674. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3675. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3676. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3677. if (empty ( $claimKey ))
  3678. die ( 'illegal request' );
  3679. Doo::loadModel ( 'invoiceReceivables' );
  3680. $invoiceReceivables = new invoiceReceivables ();
  3681. Doo::loadModel ( 'invoiceROLog' );
  3682. $invoiceROLog = new invoiceROLog ();
  3683. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3684. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3685. if (empty ( $detail ))
  3686. die ( 'illegal request' );
  3687. $invoiceReceivables = new invoiceReceivables ();
  3688. $item = array (
  3689. 'irid' => $detail ['irid']
  3690. );
  3691. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3692. $item += array (
  3693. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3694. );
  3695. }
  3696. if (! empty ( $receivablesCategory ))
  3697. $item += array (
  3698. 'receivablesCategory' => $receivablesCategory
  3699. );
  3700. if (! empty ( $receivablesStaff ))
  3701. $item += array (
  3702. 'receivablesStaff' => $receivablesStaff
  3703. );
  3704. if (! empty ( $receivablesPrice ))
  3705. $item += array (
  3706. 'receivablesPrice' => $receivablesPrice
  3707. );
  3708. if (! empty ( $receivablesMessage ))
  3709. $item += array (
  3710. 'receivablesMessage' => $receivablesMessage
  3711. );
  3712. if (! empty ( $receivablesBank ))
  3713. $item += array (
  3714. 'receivablesBank' => $receivablesBank
  3715. );
  3716. if (! empty ( $receivablesDate ))
  3717. $item += array (
  3718. 'receivablesDate' => $receivablesDate
  3719. );
  3720. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3721. // 收款操作日志
  3722. $item = array ();
  3723. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3724. $item = array (
  3725. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3726. );
  3727. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3728. $item = array (
  3729. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3730. );
  3731. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3732. $receivablesStaff = explode ( '-', $receivablesStaff );
  3733. $item = array (
  3734. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3735. );
  3736. }
  3737. $item += array (
  3738. 'date' => date ( "Y-m-d" ),
  3739. 'status' => 1,
  3740. 'img' => $this->staff [0] ['avatar'],
  3741. 'username' => $this->staff [0] ['username'],
  3742. 'uid' => $this->staff [0] ['sid'],
  3743. 'category' => $this->staff [0] ['category'],
  3744. 'irid' => $detail ['irid']
  3745. );
  3746. $invoiceROLog->setInvoiceROLog ( $item );
  3747. return '/invoiceReceivablesAS';
  3748. }
  3749. function invoiceReceivablesDelete() {
  3750. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3751. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3752. if ($skll != '删除到款')
  3753. die ( 'illegal request-未填写 删除到款' );
  3754. if (empty ( $claimKey ))
  3755. die ( 'illegal request-收款key不正确' );
  3756. Doo::loadModel ( 'invoiceReceivables' );
  3757. $invoiceReceivables = new invoiceReceivables ();
  3758. $con = ' and bindStatus=0 ';
  3759. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3760. if (empty ( $detail ))
  3761. die ( 'illegal request-未找到该收款或者未解绑' );
  3762. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3763. // 扣除收款汇总信息 汇总
  3764. Doo::loadModel ( 'invoiceStatistics' );
  3765. $invoiceStatistics = new invoiceStatistics ();
  3766. $item = array (
  3767. 'date' => $detail ['receivablesDate'],
  3768. 'priceClass' => 2,
  3769. 'irid' => $detail ['irid'],
  3770. 'receivablesPrice' => - $detail ['receivablesPrice']
  3771. );
  3772. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3773. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3774. $item += array (
  3775. 'cid' => $receivablesCategory [0]
  3776. );
  3777. }
  3778. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3779. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3780. $item += array (
  3781. 'staff' => $receivablesStaff [0]
  3782. );
  3783. }
  3784. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3785. // 公司流水-删除时删除流水
  3786. Doo::loadModel ( 'wasteBook' );
  3787. $wasteBook = new wasteBook ();
  3788. $wasteBook->delete ( array (
  3789. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3790. 'limit' => 1
  3791. ) );
  3792. return '/invoiceReceivablesAS';
  3793. }
  3794. /**
  3795. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3796. */
  3797. function invoiceReceivablesAscription() {
  3798. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3799. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3800. Doo::loadModel ( 'invoiceReceivables' );
  3801. $invoiceReceivables = new invoiceReceivables ();
  3802. Doo::loadModel ( 'invoiceROLog' );
  3803. $invoiceROLog = new invoiceROLog ();
  3804. Doo::loadModel ( 'invoiceStatistics' );
  3805. $invoiceStatistics = new invoiceStatistics ();
  3806. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3807. $irid = $invoiceReceivables->authcode ( $irid );
  3808. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3809. $item = array (
  3810. 'irid' => $detail ['irid'],
  3811. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3812. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3813. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3814. 'recepitTitleMark' => $recepitTitleMark,
  3815. 'source' => 1
  3816. );
  3817. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3818. $item = array (
  3819. 'date' => date ( "Y-m-d" ),
  3820. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3821. 'status' => 2,
  3822. 'img' => $this->staff [0] ['avatar'],
  3823. 'username' => $this->staff [0] ['username'],
  3824. 'uid' => $this->staff [0] ['sid'],
  3825. 'category' => $this->staff [0] ['category'],
  3826. 'irid' => $irid
  3827. );
  3828. $invoiceROLog->setInvoiceROLog ( $item );
  3829. $item = array (
  3830. 'cid' => $this->staff [0] ['cid'],
  3831. 'staff' => $this->staff [0] ['sid']
  3832. );
  3833. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3834. //更新流水的办事处
  3835. Doo::loadModel ( 'wasteBook' );
  3836. $wasteBook = new wasteBook ();
  3837. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $detail ['irid'] );
  3838. $wasteBook->wid = $abDetail ['wid'];
  3839. $wasteBook->category = $this->staff [0] ['category'];
  3840. $wasteBook->cid = $this->staff [0] ['cid'];
  3841. $wasteBook->update ();
  3842. }
  3843. return "/invoiceReceivablesClaim";
  3844. }
  3845. /**
  3846. */
  3847. function invoiceMyReceivables() {
  3848. Doo::loadModel ( 'invoiceReceivables' );
  3849. $invoiceReceivables = new invoiceReceivables ();
  3850. Doo::loadModel ( 'invoiceStatistics' );
  3851. $invoiceStatistics = new invoiceStatistics ();
  3852. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3853. $year = date ( "Y" );
  3854. $tmp_date = date ( "Ym" );
  3855. $tmp_year = substr ( $tmp_date, 0, 4 );
  3856. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3857. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3858. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3859. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3860. $htm = $this->showCache ( $path );
  3861. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3862. $this->data ['isMonth'] = $isMonth;
  3863. $this->data ['htm'] = $htm;
  3864. $this->data ['list'] = $list;
  3865. $this->data ['memu'] = "invoice";
  3866. $this->data ['staff'] = $this->staff;
  3867. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3868. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3869. }
  3870. /**
  3871. * 纸票管理
  3872. */
  3873. function invoicePaper() {
  3874. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3875. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3876. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3877. $this->data ['dateString'] = $date;
  3878. $this->data ['status'] = $status;
  3879. $this->data ['invoiceType'] = $invoiceType;
  3880. $this->data ['memu'] = "invoice";
  3881. $this->data ['staff'] = $this->staff;
  3882. $this->data ['receiptMemu'] = 'invoicePaper';
  3883. $this->render ( "/admin/invoicePaper", $this->data );
  3884. }
  3885. /**
  3886. * 电子发票管理
  3887. */
  3888. function invoiceElectronic() {
  3889. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3890. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3891. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3892. $this->data ['dateString'] = $date;
  3893. $this->data ['status'] = $status;
  3894. $this->data ['invoiceType'] = $invoiceType;
  3895. $this->data ['memu'] = "invoice";
  3896. $this->data ['staff'] = $this->staff;
  3897. $this->data ['receiptMemu'] = 'invoicePaper';
  3898. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3899. }
  3900. /**
  3901. * 获得纸票分页数据
  3902. */
  3903. function ajaxGetinvoicePaperAchieve() {
  3904. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3905. Doo::loadModel ( 'invoicePaper' );
  3906. $invoicePaper = new invoicePaper ();
  3907. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3908. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3909. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3910. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3911. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3912. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3913. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3914. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3915. $MebSea = $this->get_args ( 'search' );
  3916. $MebSea = $MebSea ['value'];
  3917. $page_size = $length;
  3918. $con = '';
  3919. if ($status == 'ALL')
  3920. $con = ' where 1 ';
  3921. elseif ($status == 'PRINTED')
  3922. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3923. elseif ($status == 'UNPRINT')
  3924. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3925. elseif ($status == 'TICKET')
  3926. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3927. if ($invoiceType == 'ORDINARY')
  3928. $con .= ' and a.invoiceType=0 ';
  3929. elseif ($invoiceType == 'SPECIAL')
  3930. $con .= ' and a.invoiceType=1 ';
  3931. if($invoiceForm==0){
  3932. $con .= ' and a.invoiceForm=0 ';
  3933. }else{
  3934. $con .= ' and a.invoiceForm=1 ';
  3935. }
  3936. $dateArr = explode ( ':', $date );
  3937. $D1 = $dateString = '';
  3938. $D2 = '';
  3939. if (! empty ( $date )) {
  3940. $D1 = $dateArr [0];
  3941. if (isset ( $dateArr [1] ))
  3942. $D2 = $dateArr [1];
  3943. else
  3944. $D2 = '';
  3945. $dateString = $D1 . " : " . $D2;
  3946. }
  3947. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3948. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3949. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3950. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3951. if (! empty ( $MebSea ))
  3952. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3953. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3954. $sql = ' ' . $con;
  3955. $limit = $page . ',' . $page_size;
  3956. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3957. $paperList = array ();
  3958. foreach ( $list as $key => $value ) {
  3959. $irDetail = array ();
  3960. if ($value ['iid'] == 0)
  3961. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3962. else
  3963. array_push ( $irDetail, '' );
  3964. array_push ( $irDetail, $value ['invoiceCode'] );
  3965. array_push ( $irDetail, $value ['invoiceNo'] );
  3966. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3967. if ($value ['invoiceType'] == 1)
  3968. array_push ( $irDetail, $value ['invoiceCompany'] );
  3969. else
  3970. array_push ( $irDetail, $value ['invoiceTitle'] );
  3971. if ($value ['invoiceType'] == 1)
  3972. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3973. else
  3974. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3975. array_push ( $irDetail, $value ['invoiceElement'] );
  3976. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3977. array_push ( $irDetail, $value ['printTime'] );
  3978. array_push ( $paperList, $irDetail );
  3979. }
  3980. // $approvalListJson = json_encode ( $approvalList );
  3981. $recordsFiltered = $invoiceTotal;
  3982. echo json_encode ( array (
  3983. "draw" => intval ( $draw ),
  3984. "recordsTotal" => intval ( $invoiceTotal ),
  3985. "recordsFiltered" => intval ( $recordsFiltered ),
  3986. "data" => $paperList
  3987. ), JSON_UNESCAPED_UNICODE );
  3988. }
  3989. function invoicePaperDel() {
  3990. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3991. $XDeode = new XDeode ( 5 );
  3992. $ipid = $XDeode->decode ( $ipidKey );
  3993. if (empty ( $ipid ))
  3994. die ( 'illegal request' );
  3995. Doo::loadModel ( 'invoicePaper' );
  3996. $invoicePaper = new invoicePaper ();
  3997. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3998. $invoicePaper->delete ( array (
  3999. 'where' => 'ipid=' . $ipid . ' and iid=0',
  4000. 'limit' => 1
  4001. ) );
  4002. if($ipdetail['invoiceForm']==1){
  4003. return '/invoiceElectronic';
  4004. }else{
  4005. return '/invoicePaper';
  4006. }
  4007. }
  4008. /**
  4009. * 添加纸质发票号
  4010. */
  4011. function invoicePaperAdd() {
  4012. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  4013. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  4014. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  4015. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  4016. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  4017. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  4018. $sum = $invoiceNoStart + $invoiceNoTotal;
  4019. if (empty ( $sum ))
  4020. die ( 'illegal request' );
  4021. // echo $invoiceNoStart;
  4022. // echo $sum;
  4023. // echo strlen((int)$invoiceNoStart);
  4024. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  4025. if($invoiceType==0||$invoiceType==1){
  4026. }else{
  4027. die ( 'illegal request invoiceType' );
  4028. }
  4029. if($invoiceForm==1){
  4030. $invoiceType=0;
  4031. }
  4032. Doo::db ()->beginTransaction ();
  4033. // 批量存储纸质发票
  4034. $date = date ( "Y-m-d H:i:s" );
  4035. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  4036. VALUES ';
  4037. $paperList = array ();
  4038. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  4039. // 数字前面自加0
  4040. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  4041. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  4042. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  4043. array_push ( $paperList, $paperSql );
  4044. }
  4045. if (empty ( $paperList ))
  4046. die ( 'illegal request' );
  4047. $sql = $sql . implode ( ',', $paperList );
  4048. Doo::db ()->query ( $sql );
  4049. Doo::db ()->commit ();
  4050. if($invoiceForm==1){
  4051. return 'invoiceElectronic';
  4052. }else{
  4053. return 'invoicePaper';
  4054. }
  4055. }
  4056. die ( 'illegal request' );
  4057. }
  4058. /**
  4059. * 收款绑定发票 ,//一个收款只能绑定一个发票
  4060. */
  4061. function invoiceBindReceivables() {
  4062. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4063. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4064. Doo::loadModel ( 'invoice' );
  4065. $invoice = new invoice ();
  4066. Doo::loadModel ( 'invoiceReceivables' );
  4067. $invoiceReceivables = new invoiceReceivables ();
  4068. Doo::loadModel ( 'invoiceOperationLog' );
  4069. $invoiceOperationLog = new invoiceOperationLog ();
  4070. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4071. die ( 'illegal request' );
  4072. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4073. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4074. if (empty ( $detail ) && empty ( $detailM ))
  4075. die ( 'illegal request' );
  4076. if ($detail ['untreadStatus'] == 3)
  4077. die ( 'illegal request' );
  4078. // 修改 绑定状态改为 金额
  4079. $invoiceReceivables = new invoiceReceivables ();
  4080. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4081. $billPrice=0;
  4082. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4083. $item = array (
  4084. 'bindPrice' => $invoicePrice
  4085. );
  4086. $billPrice=$invoicePrice;
  4087. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) { //发票金额大于收款金额,绑定金额为收款金额
  4088. $item = array (
  4089. 'bindPrice' => $detailM ['receivablesPrice'],
  4090. 'bindStatus' => 1,
  4091. 'bindDate' => date ( "Y-m-d H:i:s" )
  4092. );
  4093. $billPrice=$detailM ['receivablesPrice'];
  4094. } else {
  4095. die ( 'illegal request' );
  4096. }
  4097. if ($detailM ['iid'] == 0) {
  4098. $item += array (
  4099. 'iid' => $detail ['iid']
  4100. );
  4101. } else {
  4102. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4103. array_push ( $iidExtend, $detail ['iid'] );
  4104. $item += array (
  4105. 'iidExtend' => implode ( ',', $iidExtend )
  4106. );
  4107. }
  4108. $titleMark = $detail ['invoiceTitle'];
  4109. if (! empty ( $detail ['invoiceCompany'] ))
  4110. $titleMark = $detail ['invoiceCompany'];
  4111. $item += array (
  4112. 'irid' => $detailM ['irid'],
  4113. 'recepitTitleMark' => $titleMark,
  4114. 'accountClerk' => $this->staff [0] ['username']
  4115. );
  4116. // 如何没有人收款 则自动绑定收款
  4117. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4118. $item += array (
  4119. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4120. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4121. );
  4122. }
  4123. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4124. $iridString = "";
  4125. if (empty ( $detail ['irid'] ))
  4126. $iridString = $detailM ['irid'];
  4127. else
  4128. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4129. // $invoiceReceivables = new invoiceReceivables ();
  4130. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4131. // //这个收款余额
  4132. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4133. // $sum=$sumBind+$sumBalance;
  4134. //这个收款余额
  4135. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4136. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4137. // die;
  4138. $invoice = new invoice ();
  4139. $item = array (
  4140. 'iid' => $detail ['iid'],
  4141. 'irid' => $iridString
  4142. );
  4143. if ($detail ['invoicePrice'] <= $sumBalance){
  4144. $item += array (
  4145. 'invoiceBalance'=>0,
  4146. 'untreadStatus' => 3,
  4147. 'bindTime' => date ( "Y-m-d H:i:s" )
  4148. );
  4149. }else{
  4150. $item += array (
  4151. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4152. );
  4153. }
  4154. // print_r($item);
  4155. // echo $sum;die;
  4156. $invoice->setInvoiceByCondition ( $item );
  4157. //发票入账记录
  4158. Doo::loadModel ( 'bill' );
  4159. $bill = new bill ();
  4160. $bill->iid=$detail ['iid'];
  4161. $bill->trainId=$detail['trainId'];
  4162. $bill->irid=$detailM ['irid'];
  4163. $bill->create_time=date ( "Y-m-d H:i:s" );
  4164. $bill->price=$billPrice;
  4165. $bill->insert ();
  4166. // 操作日志
  4167. $item = array (
  4168. 'date' => date ( "Y-m-d H:i:s" ),
  4169. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4170. 'status' => 8,
  4171. 'img' => $this->staff [0] ['avatar'],
  4172. 'username' => $this->staff [0] ['username'],
  4173. 'uid' => $this->staff [0] ['sid'],
  4174. 'category' => $this->staff [0] ['category'],
  4175. 'iid' => $detail ['iid']
  4176. );
  4177. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4178. Doo::loadModel ( 'invoiceStatistics' );
  4179. $invoiceStatistics = new invoiceStatistics ();
  4180. $item = array (
  4181. 'date' => $detailM ['receivablesDate'],
  4182. 'priceClass' => 3,
  4183. 'cid' => $detail ['cid'],
  4184. 'staff' => $detail ['sid'],
  4185. 'accountPrice' => $detailM ['receivablesPrice']
  4186. );
  4187. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4188. //TODO
  4189. // 公司流水记录
  4190. // Doo::loadModel ( 'wasteBook' );
  4191. // $wasteBook = new wasteBook ();
  4192. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4193. // $accountBank='';
  4194. // if ($detailM ['receivablesBank']=='纵横广发'){
  4195. // $accountBank='CGBDeposit';
  4196. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4197. // $accountBank='ICBCDeposit';
  4198. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4199. // $accountBank='HUADeposit';
  4200. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4201. // $accountBank='PersonalDeposit';
  4202. // }
  4203. // if (empty($abDetail)){
  4204. // $item = array (
  4205. // 'dataID' => $detail ['iid'],
  4206. // 'expensesType' => 1,
  4207. // 'accountType' => 8,
  4208. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4209. // 'accountPrice'=>$detail ['invoicePrice'],
  4210. // 'accountBank'=>$accountBank,
  4211. // 'category'=>$this->staff[0]['category'],
  4212. // 'cid'=>$this->staff[0]['cid'],
  4213. // 'name'=>$this->staff[0]['username'],
  4214. // 'sid'=>$this->staff[0]['sid'],
  4215. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4216. // );
  4217. // $wasteBook->setAccountBookStatistics($item);
  4218. // }
  4219. return "/invoiceReceivables";
  4220. }
  4221. /**
  4222. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4223. */
  4224. function invoiceAggregate() {
  4225. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4226. Doo::loadModel ( 'invoiceStatistics' );
  4227. $invoiceStatistics = new invoiceStatistics ();
  4228. Doo::loadModel ( 'L_category' );
  4229. $Lcategory = new L_category ();
  4230. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4231. $LcategoryList = $Lcategory->getCategory ();
  4232. // print_r($isList);
  4233. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4234. foreach ( $LcategoryList as $key => $value ) {
  4235. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4236. $month = 1;
  4237. $invoicePriceYear = 0;
  4238. $receivablesPriceYear = 0;
  4239. $accountPriceYear = 0;
  4240. for(; $month <= 12; $month ++) {
  4241. $flag = true;
  4242. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4243. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4244. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4245. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4246. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4247. ';
  4248. $invoicePriceYear += $v ['invoicePrice'];
  4249. $receivablesPriceYear += $v ['receivablesPrice'];
  4250. $accountPriceYear += $v ['accountPrice'];
  4251. $flag = false;
  4252. break;
  4253. }
  4254. }
  4255. if ($flag)
  4256. $html .= '<td class="taR"></td>
  4257. <td class="taR"></td>
  4258. <td class="taR"><b></b></td>
  4259. ';
  4260. }
  4261. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4262. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4263. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4264. ';
  4265. $html .= '</tr>';
  4266. }
  4267. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4268. $invoicePriceYear = 0;
  4269. $receivablesPriceYear = 0;
  4270. $accountPriceYear = 0;
  4271. for($month = 1; $month <= 12; $month ++) {
  4272. $flag = true;
  4273. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4274. if ($month == $v ['month']) {
  4275. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4276. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4277. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4278. ';
  4279. $invoicePriceYear += $v ['invoicePrice'];
  4280. $receivablesPriceYear += $v ['receivablesPrice'];
  4281. $accountPriceYear += $v ['accountPrice'];
  4282. $flag = false;
  4283. break;
  4284. }
  4285. }
  4286. if ($flag) {
  4287. $html .= '<td class="taR"></td>
  4288. <td class="taR"></td>
  4289. <td class="taR"><b></b></td>
  4290. ';
  4291. }
  4292. }
  4293. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4294. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4295. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4296. ';
  4297. $html .= '</tr>';
  4298. // print_r($isList);
  4299. $this->data ['html'] = $html;
  4300. $this->data ['LcategoryList'] = $LcategoryList;
  4301. $this->data ['isList'] = $isList;
  4302. $this->data ['year'] = $year;
  4303. $this->data ['memu'] = "invoice";
  4304. $this->data ['staff'] = $this->staff;
  4305. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4306. $this->render ( "/admin/invoiceAggregate", $this->data );
  4307. }
  4308. function invoiceAggregateStaff() {
  4309. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4310. Doo::loadModel ( 'invoiceStatistics' );
  4311. $invoiceStatistics = new invoiceStatistics ();
  4312. Doo::loadModel ( 'L_category' );
  4313. $Lcategory = new L_category ();
  4314. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4315. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4316. $cStaff = $Lcategory->getCategoryStaff ();
  4317. $html = '';
  4318. foreach ( $cStaff as $key => $value ) {
  4319. $categoryFir = true;
  4320. foreach ( $value ['staff'] as $k => $v ) {
  4321. if ($categoryFir) {
  4322. $width = count ( $value ['staff'] ) + 1;
  4323. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4324. $categoryFir = false;
  4325. } else
  4326. $html .= '<tr>';
  4327. $html .= '<th>' . $v ['username'] . '</th>';
  4328. $invoicePriceStaffYear = 0;
  4329. $receivablesPriceStaffYear = 0;
  4330. $accountPriceStaffYear = 0;
  4331. for($month = 1; $month <= 12; $month ++) {
  4332. $flag = true;
  4333. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4334. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4335. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4336. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4337. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4338. ';
  4339. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4340. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4341. $accountPriceStaffYear += $slv ['accountPrice'];
  4342. $flag = false;
  4343. break;
  4344. }
  4345. }
  4346. if ($flag)
  4347. $html .= '<td class="taR"></td>
  4348. <td class="taR"></td>
  4349. <td class="taR"><b></b></td>
  4350. ';
  4351. }
  4352. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4353. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4354. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4355. ';
  4356. }
  4357. $html .= '</tr>';
  4358. // 小计
  4359. if (! empty ( $value ['staff'] )) {
  4360. $html .= '<tr><th class="taR">小计</th>';
  4361. $invoicePriceStaffYear = 0;
  4362. $receivablesPriceStaffYear = 0;
  4363. $accountPriceStaffYear = 0;
  4364. for($month = 1; $month <= 12; $month ++) {
  4365. $flag = true;
  4366. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4367. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4368. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4369. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4370. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4371. ';
  4372. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4373. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4374. $accountPriceStaffYear += $slv ['accountPrice'];
  4375. $flag = false;
  4376. break;
  4377. }
  4378. }
  4379. if ($flag)
  4380. $html .= '<td class="taR"></td>
  4381. <td class="taR"></td>
  4382. <td class="taR"><b></b></td>
  4383. ';
  4384. }
  4385. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4386. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4387. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4388. ';
  4389. $html .= '</tr>';
  4390. }
  4391. }
  4392. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4393. $invoicePriceYear = 0;
  4394. $receivablesPriceYear = 0;
  4395. $accountPriceYear = 0;
  4396. for($month = 1; $month <= 12; $month ++) {
  4397. $flag = true;
  4398. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4399. if ($month == $v ['month']) {
  4400. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4401. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4402. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4403. ';
  4404. $invoicePriceYear += $v ['invoicePrice'];
  4405. $receivablesPriceYear += $v ['receivablesPrice'];
  4406. $accountPriceYear += $v ['accountPrice'];
  4407. $flag = false;
  4408. break;
  4409. }
  4410. }
  4411. if ($flag)
  4412. $html .= '<td class="taR"></td>
  4413. <td class="taR"></td>
  4414. <td class="taR"><b></b></td>
  4415. ';
  4416. }
  4417. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4418. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4419. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4420. ';
  4421. $html .= '</tr>';
  4422. $this->data ['html'] = $html;
  4423. $this->data ['isList'] = $toteList;
  4424. $this->data ['year'] = $year;
  4425. $this->data ['memu'] = "invoice";
  4426. $this->data ['staff'] = $this->staff;
  4427. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4428. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4429. }
  4430. function invoiceAggregateCategory() {
  4431. Doo::loadClass ( 'XDeode' );
  4432. $XDeode = new XDeode ( 5 );
  4433. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4434. $cid = $XDeode->decode ( $cid );
  4435. if (! is_numeric ( $cid ))
  4436. die ( 'illegal request' );
  4437. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4438. Doo::loadModel ( 'invoiceStatistics' );
  4439. $invoiceStatistics = new invoiceStatistics ();
  4440. Doo::loadModel ( 'staff' );
  4441. $staff = new staff ();
  4442. $list = $staff->getStaffByCid ( $cid );
  4443. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4444. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4445. if (empty ( $list ))
  4446. die ( '该办事处没有成员' );
  4447. $htmlA = $htmlB = $htmlC = $html = '';
  4448. foreach ( $list as $key => $value ) {
  4449. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4450. $htmlB = '<tr><th class="taC">收款</th>';
  4451. $htmlC = '<tr><th class="taC">入账</th>';
  4452. $invoicePriceStaffYear = 0;
  4453. $receivablesPriceStaffYear = 0;
  4454. $accountPriceStaffYear = 0;
  4455. for($month = 1; $month <= 12; $month ++) {
  4456. $flag = true;
  4457. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4458. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4459. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4460. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4461. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4462. $invoicePriceStaffYear += $v ['invoicePrice'];
  4463. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4464. $accountPriceStaffYear += $v ['accountPrice'];
  4465. $flag = false;
  4466. break;
  4467. }
  4468. }
  4469. if ($flag) {
  4470. $htmlA .= '<td class="taR">-</td>';
  4471. $htmlB .= '<td class="taR">-</td>';
  4472. $htmlC .= '<td class="taR"><b>-</b></td>';
  4473. }
  4474. }
  4475. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4476. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4477. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4478. $htmlA .= '</tr>';
  4479. $htmlB .= '</tr>';
  4480. $htmlC .= '</tr>';
  4481. $html .= $htmlA . $htmlB . $htmlC;
  4482. }
  4483. $htmlA = $htmlB = $htmlC = "";
  4484. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4485. $htmlB = '<tr><th class="taC">收款</th>';
  4486. $htmlC = '<tr><th class="taC">入账</th>';
  4487. $invoicePriceStaffYear = 0;
  4488. $receivablesPriceStaffYear = 0;
  4489. $accountPriceStaffYear = 0;
  4490. for($month = 1; $month <= 12; $month ++) {
  4491. $flag = true;
  4492. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4493. if ($month == $v ['month']) {
  4494. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4495. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4496. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4497. $invoicePriceStaffYear += $v ['invoicePrice'];
  4498. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4499. $accountPriceStaffYear += $v ['accountPrice'];
  4500. $flag = false;
  4501. break;
  4502. }
  4503. }
  4504. if ($flag) {
  4505. $htmlA .= '<td class="taR">-</td>';
  4506. $htmlB .= '<td class="taR">-</td>';
  4507. $htmlC .= '<td class="taR"><b>-</b></td>';
  4508. }
  4509. }
  4510. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4511. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4512. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4513. $htmlA .= '</tr>';
  4514. $htmlB .= '</tr>';
  4515. $htmlC .= '</tr>';
  4516. $html .= $htmlA . $htmlB . $htmlC;
  4517. $this->data ['html'] = $html;
  4518. $this->data ['cidKey'] = $cidKey;
  4519. $this->data ['slist'] = $list;
  4520. $this->data ['isList'] = $toteList;
  4521. $this->data ['year'] = $year;
  4522. $this->data ['memu'] = "invoice";
  4523. $this->data ['staff'] = $this->staff;
  4524. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4525. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4526. }
  4527. /**
  4528. * 办事处汇总信息
  4529. */
  4530. function invoiceAggregateCategoryDetail() {
  4531. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4532. Doo::loadClass ( 'XDeode' );
  4533. $XDeode = new XDeode ( 5 );
  4534. Doo::loadModel ( 'invoiceStatistics' );
  4535. $invoiceStatistics = new invoiceStatistics ();
  4536. Doo::loadModel ( 'L_category' );
  4537. $category = new L_category ();
  4538. Doo::loadModel ( 'invoice' );
  4539. $invoice = new invoice ();
  4540. Doo::loadModel ( 'staff' );
  4541. $staff = new staff ();
  4542. Doo::loadModel ( "invoiceCategoryManage" );
  4543. $invoiceCategoryManage = new invoiceCategoryManage ();
  4544. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4545. $cidList = array ();
  4546. foreach ( $imcStaff as $key => $value ) {
  4547. array_push ( $cidList, $value ['cid'] );
  4548. if (empty ( $cidKey ))
  4549. $cidKey = $XDeode->encode ( $value ['cid'] );
  4550. }
  4551. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4552. $cid = $XDeode->decode ( $cidKey );
  4553. $month = date ( "m", strtotime ( "-1 month" ) );
  4554. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4555. $redis = new Redis ();
  4556. $redis->connect ( '127.0.0.1', '6379' );
  4557. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4558. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4559. if (empty ( $redisValue )) {
  4560. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4561. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4562. // 获得办事处人员下的汇总
  4563. $slist = $staff->getStaffByCid ( $cid );
  4564. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4565. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4566. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4567. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4568. foreach ( $slist as $key => $value ) {
  4569. $slist [$key] ['invoicePrice'] = 0;
  4570. $slist [$key] ['receivablesPrice'] = 0;
  4571. $slist [$key] ['accountPrice'] = 0;
  4572. $slist [$key] ['invoiceAllPrice'] = 0;
  4573. $slist [$key] ['receivablesAllPrice'] = 0;
  4574. $slist [$key] ['accountAllPrice'] = 0;
  4575. $slist [$key] ['schedule'] = 0;
  4576. $slist [$key] ['invoiceMonthPrice'] = 0;
  4577. $slist [$key] ['receivablesMonthPrice'] = 0;
  4578. $slist [$key] ['accountMonthPrice'] = 0;
  4579. foreach ( $ismsbMonth as $y => $l ) {
  4580. if ($value ['sid'] == $l ['staff']) {
  4581. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4582. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4583. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4584. }
  4585. }
  4586. foreach ( $ismsb as $k => $v ) {
  4587. if ($value ['sid'] == $v ['staff']) {
  4588. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4589. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4590. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4591. }
  4592. }
  4593. foreach ( $ISAS as $e => $a ) {
  4594. if ($value ['sid'] == $a ['staff']) {
  4595. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4596. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4597. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4598. }
  4599. }
  4600. if (isset ( $scheduleStaff [$value ['sid']] ))
  4601. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4602. }
  4603. $this->data ['cidKey'] = $cidKey;
  4604. $schedule = ( int ) ($schedule * 100);
  4605. $this->data ['slist'] = $slist;
  4606. $this->data ['isMC'] = $isMC;
  4607. $this->data ['schedule'] = $schedule;
  4608. $slist = json_encode ( $slist );
  4609. $isMC = json_encode ( $isMC );
  4610. $schedule = json_encode ( $schedule );
  4611. $redis->lpush ( $redisKey, $slist );
  4612. $redis->lpush ( $redisKey, $isMC );
  4613. $redis->lpush ( $redisKey, $schedule );
  4614. } else {
  4615. $this->data ['cidKey'] = $cidKey;
  4616. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4617. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4618. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4619. }
  4620. $this->data ['month'] = $month;
  4621. $this->data ['categoryList'] = $categoryList;
  4622. $this->data ['memu'] = "invoice";
  4623. $this->data ['staff'] = $this->staff;
  4624. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4625. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4626. }
  4627. /**
  4628. * 办事处人员汇总详情
  4629. */
  4630. function invoiceAggregateStaffDetail() {
  4631. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4632. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4633. Doo::loadClass ( 'XDeode' );
  4634. $XDeode = new XDeode ( 5 );
  4635. Doo::loadModel ( 'invoice' );
  4636. $invoice = new invoice ();
  4637. Doo::loadModel ( 'staff' );
  4638. $staff = new staff ();
  4639. Doo::loadModel ( "invoiceCategoryManage" );
  4640. $invoiceCategoryManage = new invoiceCategoryManage ();
  4641. $sid = $XDeode->decode ( $sidKey );
  4642. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4643. $cidList = array ();
  4644. foreach ( $imcStaff as $key => $value ) {
  4645. array_push ( $cidList, $value ['cid'] );
  4646. if (empty ( $cidKey ))
  4647. $cidKey = $XDeode->encode ( $value ['cid'] );
  4648. }
  4649. $cidString = implode ( ',', $cidList );
  4650. $staffList = $staff->getStaffInCid ( $cidString );
  4651. $staffDetail = $staff->getStaffBySid ( $sid );
  4652. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4653. $page_size = 18;
  4654. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4655. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4656. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4657. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4658. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4659. $dateArr = explode ( ':', $date );
  4660. $D1 = '';
  4661. $D2 = '';
  4662. if (! empty ( $date )) {
  4663. $D1 = $dateArr [0] . " 00:00:00 ";
  4664. if (isset ( $dateArr [1] ))
  4665. $D2 = $dateArr [1] . " 23:59:59 ";
  4666. else
  4667. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4668. // $D2 = $dateArr [1];
  4669. }
  4670. $con = ' status=2 ';
  4671. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4672. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4673. if ($status == 'UNRECORD')
  4674. $con .= ' and printStatus=1 and untreadStatus=0';
  4675. elseif ($status == 'RECORD')
  4676. $con .= ' and printStatus=1 and untreadStatus=3';
  4677. elseif ($status == 'BOUNCED')
  4678. $con .= ' and untreadStatus=2';
  4679. elseif ($status == 'PARTRECORD')
  4680. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4681. elseif ($status == 'All') {
  4682. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4683. }
  4684. $con .= ' and sid=' . $sid;
  4685. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4686. if (! empty ( $MebSea )) {
  4687. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4688. }
  4689. $pageinfo ['page'] = array (
  4690. 'previous' => ''
  4691. );
  4692. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4693. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4694. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4695. $this->data ['staffDetail'] = $staffDetail;
  4696. $this->data ['staffList'] = $staffList;
  4697. $this->data ['MebSeaEn'] = $MebSea;
  4698. $this->data ['MebSea'] = urlencode ( $MebSea );
  4699. $this->data ['date'] = $date;
  4700. $this->data ['page'] = $pageinfo;
  4701. $this->data ['get'] = $get;
  4702. $this->data ['list'] = $list;
  4703. $this->data ['status'] = $status;
  4704. $this->data ['sidKey'] = $sidKey;
  4705. $this->data ['memu'] = "invoice";
  4706. $this->data ['staff'] = $this->staff;
  4707. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4708. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4709. }
  4710. /**
  4711. * 办事处人员汇总收款情
  4712. */
  4713. function invoiceAggregateStaffReceivablesDetail() {
  4714. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4715. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4716. Doo::loadModel ( 'invoiceReceivables' );
  4717. $invoiceReceivables = new invoiceReceivables ();
  4718. Doo::loadModel ( 'staff' );
  4719. $staff = new staff ();
  4720. Doo::loadModel ( "invoiceCategoryManage" );
  4721. $invoiceCategoryManage = new invoiceCategoryManage ();
  4722. Doo::loadClass ( 'XDeode' );
  4723. $XDeode = new XDeode ( 5 );
  4724. $sid = $XDeode->decode ( $sidKey );
  4725. $staffDetail = $staff->getStaffBySid ( $sid );
  4726. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4727. $cidList = array ();
  4728. foreach ( $imcStaff as $key => $value ) {
  4729. array_push ( $cidList, $value ['cid'] );
  4730. if (empty ( $cidKey ))
  4731. $cidKey = $XDeode->encode ( $value ['cid'] );
  4732. }
  4733. $cidString = implode ( ',', $cidList );
  4734. $staffList = $staff->getStaffInCid ( $cidString );
  4735. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4736. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4737. $page_size = 10;
  4738. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4739. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4740. if ($timeType == "BINDOTP") {
  4741. $status = 'Credited';
  4742. }
  4743. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4744. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4745. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4746. $dateArr = explode ( ':', $date );
  4747. $D1 = '';
  4748. $D2 = '';
  4749. if (! empty ( $date )) {
  4750. $D1 = $dateArr [0] . " 00:00:00 ";
  4751. if (isset ( $dateArr [1] ))
  4752. $D2 = $dateArr [1] . " 23:59:59 ";
  4753. else
  4754. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4755. }
  4756. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4757. $descField = 'a.bindDate';
  4758. if ($timeType == 'CREATE')
  4759. $descField = 'a.date';
  4760. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4761. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4762. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4763. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4764. if ($status == 'Unclaimed')
  4765. $con .= ' and a.bindStatus=0';
  4766. elseif ($status == 'Credited')
  4767. $con .= ' and a.bindStatus=1';
  4768. elseif ($status == 'Claim')
  4769. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4770. elseif ($status == 'BBN')
  4771. $con .= ' and a.bindPrice>a.receivablesPrice';
  4772. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4773. if (! empty ( $MebSea )) {
  4774. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4775. }
  4776. $pageinfo ['page'] = array (
  4777. 'previous' => ''
  4778. );
  4779. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4780. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4781. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4782. // where ' . $con . ' group by a.irid ';
  4783. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4784. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4785. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4786. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4787. foreach ( $list as $key => $value ) {
  4788. $list [$key] ['category'] = '';
  4789. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4790. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4791. $list [$key] ['category'] = $receivablesCategory [1];
  4792. }
  4793. }
  4794. // print_r($list);
  4795. $this->data ['staffDetail'] = $staffDetail;
  4796. $this->data ['sidKey'] = $sidKey;
  4797. $this->data ['staffList'] = $staffList;
  4798. $this->data ['timeType'] = $timeType;
  4799. $this->data ['MebSeaEn'] = $MebSea;
  4800. $this->data ['MebSea'] = urlencode ( $MebSea );
  4801. $this->data ['date'] = $date;
  4802. $this->data ['page'] = $pageinfo;
  4803. $this->data ['get'] = $get;
  4804. $this->data ['list'] = $list;
  4805. $this->data ['status'] = $status;
  4806. $this->data ['memu'] = "invoice";
  4807. $this->data ['staff'] = $this->staff;
  4808. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4809. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4810. }
  4811. function invoiceAchieve() {
  4812. Doo::loadModel ( 'invoice' );
  4813. $invoice = new invoice ();
  4814. Doo::loadClass ( 'XDeode' );
  4815. $XDeode = new XDeode ( 5 );
  4816. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4817. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4818. $page_size = 18;
  4819. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4820. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4821. $get = "/" . $date;
  4822. $con = '';
  4823. if ($date == 'MONTHO')
  4824. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4825. elseif ($date == 'MONTHT')
  4826. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4827. elseif ($date == 'MONTHY')
  4828. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4829. if (! empty ( $MebSea )) {
  4830. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4831. $get .= "/" . $MebSea;
  4832. }
  4833. $pageinfo ['page'] = array (
  4834. 'previous' => ''
  4835. );
  4836. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4837. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4838. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4839. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4840. // print_r($pageinfo);
  4841. $this->data ['MebSeaEn'] = $MebSea;
  4842. $this->data ['MebSea'] = urlencode ( $MebSea );
  4843. $this->data ['get'] = $get;
  4844. $this->data ['page'] = $pageinfo;
  4845. $this->data ['list'] = $list;
  4846. $this->data ['date'] = $date;
  4847. $this->data ['memu'] = "invoice";
  4848. $this->data ['staff'] = $this->staff;
  4849. $this->data ['receiptMemu'] = 'invoice';
  4850. $this->render ( "/admin/invoiceAchieve", $this->data );
  4851. }
  4852. /**
  4853. */
  4854. function invoiceMyUnAccountAchieve() {
  4855. Doo::loadModel ( 'invoice' );
  4856. $invoice = new invoice ();
  4857. Doo::loadClass ( 'XDeode' );
  4858. $XDeode = new XDeode ( 5 );
  4859. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4860. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4861. $page_size = 18;
  4862. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4863. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4864. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4865. $dateArr = explode ( ':', $date );
  4866. $D1 = '';
  4867. $D2 = '';
  4868. if (! empty ( $date )) {
  4869. $D1 = $dateArr [0];
  4870. $D2 = $dateArr [1];
  4871. }
  4872. $con = '';
  4873. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4874. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4875. if (! empty ( $MebSea )) {
  4876. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4877. }
  4878. $pageinfo ['page'] = array (
  4879. 'previous' => ''
  4880. );
  4881. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4882. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4883. $action = "invoiceMyUnAccountAchieve";
  4884. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4885. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4886. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4887. Doo::loadModel ( 'express' );
  4888. $express = new express ();
  4889. $expressList = $express->getExpressByAll ();
  4890. $this->data ['expressList'] = $expressList;
  4891. // print_r($list);
  4892. $this->data ['MebSeaEn'] = $MebSea;
  4893. $this->data ['get'] = $get;
  4894. $this->data ['page'] = $pageinfo;
  4895. $this->data ['date'] = $date;
  4896. $this->data ['list'] = $list;
  4897. $this->data ['memu'] = "invoice";
  4898. $this->data ['staff'] = $this->staff;
  4899. $this->data ['receiptMemu'] = 'invoice';
  4900. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4901. }
  4902. function invoiceReceivablesAchieve() {
  4903. Doo::loadModel ( 'invoiceReceivables' );
  4904. $invoiceReceivables = new invoiceReceivables ();
  4905. Doo::loadClass ( 'XDeode' );
  4906. $XDeode = new XDeode ( 5 );
  4907. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4908. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4909. $page_size = 12;
  4910. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4911. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4912. $get = "/" . $date;
  4913. $con = '';
  4914. if ($date == 'MONTHO')
  4915. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4916. elseif ($date == 'MONTHT')
  4917. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4918. elseif ($date == 'MONTHY')
  4919. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4920. if (! empty ( $MebSea )) {
  4921. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4922. $get .= "/" . $MebSea;
  4923. }
  4924. $pageinfo ['page'] = array (
  4925. 'previous' => ''
  4926. );
  4927. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4928. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4929. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4930. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4931. // print_r($pageinfo);
  4932. $this->data ['MebSeaEn'] = $MebSea;
  4933. $this->data ['MebSea'] = urlencode ( $MebSea );
  4934. $this->data ['get'] = $get;
  4935. $this->data ['page'] = $pageinfo;
  4936. $this->data ['list'] = $list;
  4937. $this->data ['date'] = $date;
  4938. $this->data ['memu'] = "invoice";
  4939. $this->data ['staff'] = $this->staff;
  4940. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4941. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4942. }
  4943. /**
  4944. * 收款解绑
  4945. */
  4946. function invoiceUnBundLing() {
  4947. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4948. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4949. Doo::loadModel ( 'invoice' );
  4950. $invoice = new invoice ();
  4951. Doo::loadModel ( 'invoiceReceivables' );
  4952. $invoiceReceivables = new invoiceReceivables ();
  4953. Doo::loadModel ( 'invoiceOperationLog' );
  4954. $invoiceOperationLog = new invoiceOperationLog ();
  4955. Doo::loadModel ( 'invoiceROLog' );
  4956. $invoiceROLog = new invoiceROLog ();
  4957. Doo::loadModel ( 'invoiceStatistics' );
  4958. Doo::loadClass ( 'XDeode' );
  4959. $XDeode = new XDeode ( 5 );
  4960. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4961. die ( 'illegal request' );
  4962. $iid = $XDeode->decode ( $iidKey );
  4963. $irid = $invoice->authcode ( $unBundKey );
  4964. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4965. die ( 'illegal request' );
  4966. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4967. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4968. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4969. die ( 'illegal request' );
  4970. // 收款
  4971. $item = array (
  4972. 'irid' => $irDetails ['irid'],
  4973. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4974. 'bindStatus' => 0
  4975. );
  4976. if ($irDetails ['iid'] == $iid)
  4977. $item += array (
  4978. 'iid' => 0
  4979. );
  4980. else {
  4981. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4982. foreach ( $iidExtend as $key => $value ) {
  4983. if ($value == $iid)
  4984. unset ( $iidExtend [$key] );
  4985. }
  4986. $iidExtend = implode ( ',', $iidExtend );
  4987. $item += array (
  4988. 'iidExtend' => $iidExtend
  4989. );
  4990. }
  4991. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4992. // 收款操作日志
  4993. $item = array (
  4994. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4995. 'date' => date ( "Y-m-d" ),
  4996. 'status' => 3,
  4997. 'img' => $this->staff [0] ['avatar'],
  4998. 'username' => $this->staff [0] ['username'],
  4999. 'uid' => $this->staff [0] ['sid'],
  5000. 'category' => $this->staff [0] ['category'],
  5001. 'irid' => $irid
  5002. );
  5003. $invoiceROLog->setInvoiceROLog ( $item );
  5004. // 扣除入账统计金额
  5005. $invoiceStatistics = new invoiceStatistics ();
  5006. $item = array (
  5007. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  5008. 'priceClass' => 3,
  5009. 'cid' => $invoiceDetails ['cid'],
  5010. 'staff' => $invoiceDetails ['sid'],
  5011. 'accountPrice' => - $invoiceDetails ['invoicePrice']
  5012. );
  5013. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5014. // 扣除收款统计金额
  5015. $invoiceStatistics = new invoiceStatistics ();
  5016. $item = array (
  5017. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  5018. 'priceClass' => 2,
  5019. 'cid' => $invoiceDetails ['cid'],
  5020. 'staff' => $invoiceDetails ['sid'],
  5021. 'irid' => $irDetails ['irid'],
  5022. 'receivablesPrice' => - $invoiceDetails ['invoicePrice']
  5023. );
  5024. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5025. // 发票解绑去收款ID
  5026. $iridString = $invoiceDetails ['irid'];
  5027. if (! empty ( $invoiceDetails ['irid'] )) {
  5028. $list = explode ( ',', $invoiceDetails ['irid'] );
  5029. foreach ( $list as $key => $value ) {
  5030. if ($value == $irDetails ['irid']) {
  5031. unset ( $list [$key] );
  5032. break;
  5033. }
  5034. }
  5035. $iridString = implode ( ",", $list );
  5036. }
  5037. //解绑后余额 加回去
  5038. $invoiceBalance=$invoiceDetails['invoiceBalance']+$irDetails['receivablesPrice'];
  5039. if ($invoiceBalance<0){
  5040. $invoiceBalance=0;
  5041. }
  5042. if($invoiceBalance>$invoiceDetails['invoicePrice']){
  5043. $invoiceBalance=$invoiceDetails['invoicePrice'];
  5044. }
  5045. $item = array (
  5046. 'iid' => $invoiceDetails ['iid'],
  5047. 'irid' => $iridString,
  5048. 'invoiceBalance'=>$invoiceBalance,
  5049. 'updateTime' => date ( "Y-m-d H:i:s" )
  5050. );
  5051. if ($invoiceDetails ['untreadStatus'] == 3)
  5052. $item += array (
  5053. 'untreadStatus' => 0
  5054. );
  5055. $invoice->setInvoiceByCondition ( $item );
  5056. Doo::loadModel ( 'bill' );
  5057. $bill = new bill ();
  5058. $bill->iid=$invoiceDetails ['iid'];
  5059. $bill->trainId=$invoiceDetails['trainId'];
  5060. $bill->irid=$irDetails ['irid'];
  5061. $bill->create_time=date ( "Y-m-d H:i:s" );
  5062. $bill->price=-$invoiceDetails ['invoicePrice'];
  5063. $bill->remark='解绑-扣除入账';
  5064. $bill->insert ();
  5065. $item = array (
  5066. 'date' => date ( "Y-m-d H:i:s" ),
  5067. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  5068. 'status' => 11,
  5069. 'img' => $this->staff [0] ['avatar'],
  5070. 'username' => $this->staff [0] ['username'],
  5071. 'uid' => $this->staff [0] ['sid'],
  5072. 'category' => $this->staff [0] ['category'],
  5073. 'iid' => $invoiceDetails ['iid']
  5074. );
  5075. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5076. // 公司流水-解绑时删除流水
  5077. // Doo::loadModel ( 'wasteBook' );
  5078. // $wasteBook = new wasteBook ();
  5079. // $wasteBook->delete ( array (
  5080. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  5081. // 'limit' => 1
  5082. // ) );
  5083. // 银行
  5084. /*
  5085. * $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); }
  5086. */
  5087. return "/invoiceReceivablesAS";
  5088. }
  5089. /**
  5090. * 或者该收款下的所以发票
  5091. */
  5092. function ajaxGetInvoiceReceivablesByInvoice() {
  5093. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  5094. Doo::loadModel ( 'invoice' );
  5095. $invoice = new invoice ();
  5096. Doo::loadModel ( 'invoiceReceivables' );
  5097. $invoiceReceivables = new invoiceReceivables ();
  5098. $irid = $invoice->authcode ( $irid );
  5099. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5100. die ( 'illegal request' );
  5101. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5102. $iidString = $irDetails ['iid'];
  5103. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5104. if (! empty ( $irDetails ['iidExtend'] ))
  5105. $iidString .= ',' . implode ( ',', $iidExtend );
  5106. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5107. $html = "";
  5108. foreach ( $invoiceList as $key => $value ) {
  5109. $title = $value ['invoiceTitle'];
  5110. if (! empty ( $value ['invoiceCompany'] ))
  5111. $title = $value ['invoiceCompany'];
  5112. $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>';
  5113. }
  5114. echo json_encode ( array (
  5115. 'status' => 1,
  5116. 'html' => $html
  5117. ) );
  5118. }
  5119. /**
  5120. * 发票管理
  5121. */
  5122. function invoiceAS() {
  5123. Doo::loadModel ( 'invoice' );
  5124. $invoice = new invoice ();
  5125. Doo::loadModel ( 'invoiceReceivables' );
  5126. $invoiceReceivables = new invoiceReceivables ();
  5127. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5128. $page_size = 18;
  5129. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5130. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5131. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5132. $dateArr = explode ( ':', $date );
  5133. $D1 = '';
  5134. $D2 = '';
  5135. if (! empty ( $date )) {
  5136. $D1 = $dateArr [0] . " 00:00:00 ";
  5137. if (isset ( $dateArr [1] ))
  5138. $D2 = $dateArr [1] . " 23:59:59 ";
  5139. else
  5140. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5141. // $D2 = $dateArr [1];
  5142. }
  5143. $con = ' status=2 ';
  5144. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5145. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5146. if ($status == 'UNRECORD')
  5147. $con .= ' and printStatus=1 and untreadStatus=0';
  5148. elseif ($status == 'RECORD')
  5149. $con .= ' and printStatus=1 and untreadStatus=3';
  5150. elseif ($status == 'BOUNCED')
  5151. $con .= ' and untreadStatus=2';
  5152. elseif ($status == 'PARTRECORD')
  5153. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5154. elseif ($status == 'All') {
  5155. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5156. }
  5157. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5158. if (! empty ( $MebSea )) {
  5159. $con .= ' and ( invoiceSerial like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5160. }
  5161. $pageinfo ['page'] = array (
  5162. 'previous' => ''
  5163. );
  5164. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5165. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5166. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5167. $this->data ['MebSeaEn'] = $MebSea;
  5168. $this->data ['MebSea'] = urlencode ( $MebSea );
  5169. $this->data ['date'] = $date;
  5170. $this->data ['page'] = $pageinfo;
  5171. $this->data ['get'] = $get;
  5172. $this->data ['list'] = $list;
  5173. $this->data ['status'] = $status;
  5174. $this->data ['memu'] = "invoice";
  5175. $this->data ['staff'] = $this->staff;
  5176. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5177. $this->render ( "/admin/invoiceAS", $this->data );
  5178. }
  5179. /**
  5180. * 收款管理
  5181. */
  5182. function invoiceReceivablesAS() {
  5183. Doo::loadModel ( 'invoiceReceivables' );
  5184. $invoiceReceivables = new invoiceReceivables ();
  5185. Doo::loadModel ( 'L_category' );
  5186. $lCategory = new L_category ();
  5187. $category = $lCategory->getCategory ();
  5188. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5189. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5190. $page_size = 10;
  5191. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5192. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5193. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5194. $dateArr = explode ( ':', $date );
  5195. $D1 = '';
  5196. $D2 = '';
  5197. if (! empty ( $date )) {
  5198. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5199. if (isset ( $dateArr [1] ))
  5200. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5201. else
  5202. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5203. }
  5204. $descField = 'a.receivablesDate';
  5205. if ($timeType == 'CREATE')
  5206. $descField = 'a.date';
  5207. $con = ' 1 ';
  5208. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5209. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5210. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5211. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5212. if ($status == 'Unclaimed')
  5213. $con .= ' and a.bindStatus=0';
  5214. elseif ($status == 'Credited')
  5215. $con .= ' and a.bindStatus=1';
  5216. elseif ($status == 'Claim')
  5217. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5218. elseif ($status == 'BBN')
  5219. $con .= ' and a.bankBatchNumber!=""';
  5220. elseif ($status == 'REFUND')
  5221. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5222. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5223. if (! empty ( $MebSea )) {
  5224. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5225. }
  5226. $pageinfo ['page'] = array (
  5227. 'previous' => ''
  5228. );
  5229. // if(!empty($con)){
  5230. // $con=' where 1 '.$con;
  5231. // }
  5232. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5233. // ' . $con ;
  5234. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5235. //echo $sql;
  5236. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5237. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5238. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5239. foreach ( $list as $key => $value ) {
  5240. $list [$key] ['category'] = '';
  5241. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5242. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5243. $list [$key] ['category'] = $receivablesCategory [1];
  5244. }
  5245. }
  5246. // print_r($list);
  5247. $this->data ['category'] = $category;
  5248. $this->data ['timeType'] = $timeType;
  5249. $this->data ['MebSeaEn'] = $MebSea;
  5250. $this->data ['MebSea'] = urlencode ( $MebSea );
  5251. $this->data ['date'] = $date;
  5252. $this->data ['page'] = $pageinfo;
  5253. $this->data ['get'] = $get;
  5254. $this->data ['list'] = $list;
  5255. $this->data ['status'] = $status;
  5256. $this->data ['memu'] = "invoice";
  5257. $this->data ['staff'] = $this->staff;
  5258. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5259. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5260. }
  5261. /**
  5262. * 删除一条收款
  5263. */
  5264. function delInvoiceReceivables() {
  5265. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5266. if (empty ( $iridKey ))
  5267. die ( 'illegal request' );
  5268. Doo::loadClass ( 'XDeode' );
  5269. $XDeode = new XDeode ( 5 );
  5270. $irid = $XDeode->decode ( $iridKey );
  5271. Doo::loadModel ( 'invoiceReceivables' );
  5272. $invoiceReceivables = new invoiceReceivables ();
  5273. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5274. if (empty ( $detail ))
  5275. die ( 'illegal request' );
  5276. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5277. // 扣除收款汇总信息 汇总
  5278. Doo::loadModel ( 'invoiceStatistics' );
  5279. $invoiceStatistics = new invoiceStatistics ();
  5280. $item = array (
  5281. 'date' => $detail ['receivablesDate'],
  5282. 'priceClass' => 2,
  5283. 'irid' => $detail ['irid'],
  5284. 'receivablesPrice' => - $detail ['receivablesPrice']
  5285. );
  5286. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5287. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5288. $item += array (
  5289. 'cid' => $receivablesCategory [0]
  5290. );
  5291. }
  5292. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5293. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5294. $item += array (
  5295. 'staff' => $receivablesStaff [0]
  5296. );
  5297. }
  5298. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5299. return '/invoiceReceivablesAS';
  5300. }
  5301. /**
  5302. * 添加退款信息
  5303. */
  5304. function setInvoiceReceivablesRefund() {
  5305. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5306. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5307. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5308. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5309. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5310. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5311. if ($refundPrice < 0)
  5312. die ( 'illegal request' );
  5313. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5314. Doo::loadModel ( 'invoiceReceivables' );
  5315. $invoiceReceivables = new invoiceReceivables ();
  5316. Doo::loadModel ( 'invoiceRefund' );
  5317. $invoiceRefund = new invoiceRefund ();
  5318. $irid = $invoiceReceivables->authcode ( $iridKey );
  5319. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5320. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5321. die ( 'illegal request' );
  5322. $invoiceReceivables = new invoiceReceivables ();
  5323. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5324. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5325. ';
  5326. $item = array (
  5327. 'irid' => $irid,
  5328. 'refundCompany' => $refundCompany,
  5329. 'refundNumber' => $refundNumber,
  5330. 'refundPrice' => $refundPrice,
  5331. 'refundRemarks' => $refundRemarks,
  5332. 'refundLog' => $refundLog
  5333. );
  5334. if ($refundType == 1) {
  5335. $item += array (
  5336. 'refundType' => $refundType,
  5337. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5338. 'bindStatus' => 2
  5339. );
  5340. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5341. $item += array (
  5342. 'refundType' => 1,
  5343. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5344. 'bindStatus' => 2
  5345. );
  5346. } else {
  5347. $item += array (
  5348. 'refundType' => $refundType,
  5349. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5350. );
  5351. }
  5352. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5353. // 添加退款记录
  5354. $item = array (
  5355. 'irid' => $irid,
  5356. 'refundType' => $refundType,
  5357. 'refundCompany' => $refundCompany,
  5358. 'refundNumber' => $refundNumber,
  5359. 'refundPrice' => $refundPrice,
  5360. 'refundLog' => $refundLog,
  5361. 'refundRemarks' => $refundRemarks,
  5362. 'date' => date ( "Y-m-d H:i:s" )
  5363. );
  5364. $invoiceRefund->addInvoiceRefund ( $item );
  5365. // 扣除收款汇总信息 汇总
  5366. Doo::loadModel ( 'invoiceStatistics' );
  5367. $invoiceStatistics = new invoiceStatistics ();
  5368. $item = array (
  5369. 'date' => $irDetail ['receivablesDate'],
  5370. 'priceClass' => 2,
  5371. 'irid' => $irDetail ['irid'],
  5372. 'receivablesPrice' => - $refundPrice
  5373. );
  5374. $receivablesCategory=array(0=>'',1=>'');
  5375. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5376. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5377. $item += array (
  5378. 'cid' => $receivablesCategory [0]
  5379. );
  5380. }
  5381. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5382. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5383. $item += array (
  5384. 'staff' => $receivablesStaff [0]
  5385. );
  5386. }
  5387. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5388. // 公司日常支出流水
  5389. Doo::loadModel ( 'wasteBook' );
  5390. $wasteBook = new wasteBook ();
  5391. $accountBank=$wasteBook->_getAccountBankEN($irDetail ['receivablesBank']);
  5392. $itemWaste = array (
  5393. 'accountPrice' => - $refundPrice,
  5394. 'expensesType' => 2,
  5395. 'accountType' => 11,
  5396. 'accountPriceShow' => $refundPrice,
  5397. 'dataID' => $irid,
  5398. 'accountBank' => $accountBank,
  5399. 'category' => $receivablesCategory[1],
  5400. 'cid' => $receivablesCategory[0],
  5401. 'name' => $this->staff [0] ['username'],
  5402. 'sid' => $this->staff [0] ['sid'],
  5403. 'inputDate' => date ( "Y-m-d H:i:s" )
  5404. );
  5405. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5406. return '/invoiceReceivablesAS';
  5407. }
  5408. die ( 'illegal request' );
  5409. }
  5410. function ajaxCheckInvoiceReceivablesRefund() {
  5411. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5412. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5413. if ($refundPrice < 0) {
  5414. echo json_encode ( array (
  5415. 'error' => '金额不能为负'
  5416. ) );
  5417. die ();
  5418. }
  5419. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5420. Doo::loadModel ( 'invoiceReceivables' );
  5421. $invoiceReceivables = new invoiceReceivables ();
  5422. $irid = $invoiceReceivables->authcode ( $iridKey );
  5423. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5424. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5425. echo json_encode ( array (
  5426. 'error' => '退款金额不能超过收款金额'
  5427. ) );
  5428. die ();
  5429. }
  5430. echo json_encode ( array (
  5431. 'ok' => '可以使用!'
  5432. ) );
  5433. die ();
  5434. }
  5435. }
  5436. /**
  5437. * 获得收款退款信息
  5438. */
  5439. function getRefundByDetail() {
  5440. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5441. Doo::loadModel ( 'invoiceReceivables' );
  5442. $invoiceReceivables = new invoiceReceivables ();
  5443. if (! empty ( $iridKey )) {
  5444. $irid = $invoiceReceivables->authcode ( $iridKey );
  5445. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5446. echo json_encode ( array (
  5447. 'status' => 1,
  5448. 'irDetail' => $irDetail
  5449. ) );
  5450. die ();
  5451. }
  5452. echo json_encode ( array (
  5453. 'status' => 2
  5454. ) );
  5455. }
  5456. /**
  5457. * 根据收款序列号获得收款退款信息
  5458. */
  5459. function ajaxGetInvoiceReceivablesBySerial() {
  5460. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5461. if (! empty ( $receivablesSerial )) {
  5462. Doo::loadModel ( 'invoiceReceivables' );
  5463. $invoiceReceivables = new invoiceReceivables ();
  5464. // , ' and refundLog=""'
  5465. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5466. $html = '';
  5467. if (! empty ( $irDetail ))
  5468. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5469. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5470. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5471. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5472. <td>' . $irDetail ['recepitTitleMark'] . '
  5473. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5474. </td>';
  5475. echo json_encode ( array (
  5476. 'status' => 1,
  5477. 'html' => $html,
  5478. 'irDetail' => $irDetail
  5479. ) );
  5480. die ();
  5481. }
  5482. echo json_encode ( array (
  5483. 'status' => 2
  5484. ) );
  5485. }
  5486. /**
  5487. * 绑定新收款
  5488. */
  5489. function relationNewInvoiceReceivables() {
  5490. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5491. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5492. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5493. Doo::loadModel ( 'invoiceReceivables' );
  5494. $invoiceReceivables = new invoiceReceivables ();
  5495. Doo::loadClass ( 'XDeode' );
  5496. $XDeode = new XDeode ( 5 );
  5497. $irid = $XDeode->decode ( $iridKey );
  5498. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5499. echo $irid . 'bbb' . $iridOld;
  5500. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5501. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5502. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5503. die ( 'illegal request' );
  5504. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5505. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5506. ';
  5507. $invoiceReceivables = new invoiceReceivables ();
  5508. $item = array (
  5509. 'irid' => $iridOld,
  5510. 'relationIrid' => $irid,
  5511. 'relationLog' => $relationLog
  5512. );
  5513. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5514. return '/invoiceReceivablesAS';
  5515. }
  5516. die ( 'illegal request' );
  5517. }
  5518. // function invoiceApprovalAchieve() {
  5519. // Doo::loadModel ( 'invoice' );
  5520. // $invoice = new invoice ();
  5521. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5522. // $page_size = 12;
  5523. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5524. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5525. // $get = "/" . $date;
  5526. // $con = '';
  5527. // if ($date == 'MONTHO')
  5528. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5529. // elseif ($date == 'MONTHT')
  5530. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5531. // elseif ($date == 'MONTHY')
  5532. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5533. // if (! empty ( $MebSea )) {
  5534. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5535. // $get .= "/" . $MebSea;
  5536. // }
  5537. // $pageinfo ['page'] = array (
  5538. // 'previous' => ''
  5539. // );
  5540. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5541. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5542. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5543. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5544. // // print_r($list);
  5545. // $this->data ['MebSeaEn'] = $MebSea;
  5546. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5547. // $this->data ['get'] = $get;
  5548. // $this->data ['page'] = $pageinfo;
  5549. // $this->data ['list'] = $list;
  5550. // $this->data ['date'] = $date;
  5551. // $this->data ['memu'] = "invoice";
  5552. // $this->data ['staff'] = $this->staff;
  5553. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5554. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5555. // }
  5556. /**
  5557. * 获得审批发票的信息以及审批页面
  5558. */
  5559. function ajaxGetInvoiceApprovalDetail() {
  5560. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5561. if (empty ( $serial )) {
  5562. echo json_encode ( array (
  5563. 'status' => 2,
  5564. 'msg' => 'illegal request'
  5565. ) );
  5566. die ();
  5567. }
  5568. Doo::loadModel ( 'invoice' );
  5569. $invoice = new invoice ();
  5570. Doo::loadModel ( 'invoiceOperationLog' );
  5571. $invoiceOperationLog = new invoiceOperationLog ();
  5572. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5573. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5574. if (empty ( $detail ))
  5575. $html = '';
  5576. else {
  5577. $html = '
  5578. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5579. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5580. <input type="hidden" name="status" value="">
  5581. <input type="hidden" name="divApproval" value="divApproval">
  5582. <div class="modal-dialog modal-lg">
  5583. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5584. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5585. <tr>
  5586. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5587. </tr>
  5588. <tr>
  5589. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5590. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5591. </tr>
  5592. <tr>
  5593. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5594. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5595. </tr>
  5596. <tr>
  5597. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5598. </td>
  5599. </tr>
  5600. <tr>
  5601. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5602. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5603. </tr>
  5604. <tr>
  5605. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5606. </tr></tbody></table>';
  5607. if ($detail ['invoiceType'] == 0)
  5608. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5609. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5610. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5611. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5612. </tr>';
  5613. else
  5614. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5615. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5616. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5617. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5618. ';
  5619. $html .= '<tr>
  5620. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5621. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5622. </tr>
  5623. <tr>
  5624. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5625. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5626. </tr></tbody></table>';
  5627. if ($detail ['doPost'] == 1) {
  5628. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5629. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5630. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5631. </tr><tr>
  5632. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5633. </tr><tr>
  5634. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5635. </tr>
  5636. ';
  5637. if ($detail ['expressCom'] == 'SF')
  5638. $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>';
  5639. else
  5640. $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>';
  5641. $html .= '</tbody></table>';
  5642. }
  5643. if (! empty ( $invoiceOperationLogList )) {
  5644. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5645. foreach ( $invoiceOperationLogList as $key => $value ) {
  5646. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5647. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5648. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5649. if ($value ['status'] == 2) {
  5650. $html .= '<span class="colGreen">同意</span>';
  5651. } elseif ($value ['status'] == 3) {
  5652. $html .= '<span class="colOrange">退回</span>';
  5653. } elseif ($value ['status'] == 5) {
  5654. $html .= '<span class="colGreen">打印</span>';
  5655. } elseif ($value ['status'] == 4) {
  5656. $html .= '<span class="colRed">终止</span>';
  5657. }
  5658. $html .= $value ['operation'] . '</p></blockquote>';
  5659. }
  5660. }
  5661. $html .= '</td></tr></tbody></table>';
  5662. }
  5663. $html .= '</div><div class="modal-footer">
  5664. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5665. <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>
  5666. <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>
  5667. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5668. </form>
  5669. <script type="text/javascript">
  5670. $("a[node-approval^=\'approval\']").click(function() {
  5671. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5672. $("form[name=\'invoiceApproval\']").submit();
  5673. });
  5674. </script>
  5675. ';
  5676. }
  5677. echo json_encode ( array (
  5678. 'status' => 1,
  5679. 'html' => $html
  5680. ) );
  5681. die ();
  5682. }
  5683. /**
  5684. * 获得审批发票分页数据
  5685. */
  5686. function ajaxGetinvoiceApprovalAchieve() {
  5687. Doo::loadModel ( 'invoice' );
  5688. $invoice = new invoice ();
  5689. Doo::loadModel ( 'staff' );
  5690. $staff = new staff ();
  5691. Doo::loadClass ( 'XDeode' );
  5692. $XDeode = new XDeode ( 5 );
  5693. Doo::loadModel ( 'invoiceTraining' );
  5694. $invoiceTraining = new invoiceTraining ();
  5695. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5696. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5697. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5698. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5699. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5700. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5701. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5702. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5703. $MebSea = $this->get_args ( 'search' );
  5704. $MebSea = $MebSea ['value'];
  5705. $page_size = $length;
  5706. $con = '';
  5707. if ($status == 'ALL')
  5708. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5709. elseif ($status == 'PEND')
  5710. $con = ' isDelete=0 and status=1';
  5711. elseif ($status == 'APPROVED')
  5712. $con = ' isDelete=0 and status=2';
  5713. if ($invoiceType == 'ORDINARY')
  5714. $con .= ' and invoiceType=0 ';
  5715. elseif ($invoiceType == 'SPECIAL')
  5716. $con .= ' and invoiceType=1 ';
  5717. if ($invoiceTrain == 'ORDINARY')
  5718. $con .= ' and trainId=0 ';
  5719. elseif ($invoiceTrain == 'TRAIN')
  5720. $con .= ' and trainId!=0 ';
  5721. if ($invoiceTrainName != 'ALL') {
  5722. $trainId = $XDeode->decode ( $invoiceTrainName );
  5723. if (is_numeric ( $trainId ))
  5724. $con .= ' and trainId =' . $trainId;
  5725. }
  5726. $dateArr = explode ( ':', $date );
  5727. $D1 = $dateString = '';
  5728. $D2 = '';
  5729. if (! empty ( $date )) {
  5730. $D1 = $dateArr [0];
  5731. if (isset ( $dateArr [1] ))
  5732. $D2 = $dateArr [1];
  5733. else
  5734. $D2 = '';
  5735. $dateString = $D1 . " : " . $D2;
  5736. }
  5737. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5738. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5739. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5740. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5741. if (! empty ( $MebSea ))
  5742. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5743. // /
  5744. $pageinfo ['page'] = array (
  5745. 'previous' => ''
  5746. );
  5747. $sql = ' ' . $con;
  5748. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5749. $limit = $page . ',' . $page_size;
  5750. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5751. $approvalList = array ();
  5752. $html = '<script type="text/javascript">
  5753. </script>';
  5754. // 结算结束不能修改方式
  5755. Doo::loadModel ( 'receipt' );
  5756. $receipt = new receipt ();
  5757. foreach ( $list as $key => $value ) {
  5758. $irDetail = array ();
  5759. // 结算方式
  5760. $receiptDetail = array ();
  5761. if ($value ['trainId'] != 0) {
  5762. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5763. }
  5764. if (! empty ( $receiptDetail )) {
  5765. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5766. array_push ( $irDetail, '' );
  5767. } else {
  5768. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5769. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5770. } elseif ($value ['status'] == 2) {
  5771. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5772. } else
  5773. array_push ( $irDetail, '' );
  5774. }
  5775. } else {
  5776. if ($value ['status'] == 2) {
  5777. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5778. } else{
  5779. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5780. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5781. }else{
  5782. array_push ( $irDetail, '' );
  5783. }
  5784. }
  5785. }
  5786. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5787. if ($value ['invoiceType'] == 1)
  5788. array_push ( $irDetail, $value ['invoiceCompany'] );
  5789. else
  5790. array_push ( $irDetail, $value ['invoiceTitle'] );
  5791. array_push ( $irDetail, $value ['TIN'] );
  5792. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5793. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5794. array_push ( $irDetail, $value ['remark'] );
  5795. array_push ( $irDetail, $value ['invoiceElement'] );
  5796. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5797. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5798. if ($value ['invoiceType'] == 1) {
  5799. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5800. } else {
  5801. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5802. }
  5803. if ($value ['settlementType'] == 0) {
  5804. array_push ( $irDetail, '软件销售' );
  5805. } else {
  5806. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5807. array_push ( $irDetail, $itDetail ['trainName'] );
  5808. }
  5809. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5810. array_push ( $irDetail, $value ['recipientsAddress'] );
  5811. array_push ( $irDetail, $value ['mailItems'] );
  5812. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5813. $fchtml = $value ['OL'] ['operation'];
  5814. if (count ( $list ) == $page_size)
  5815. $fchtml = $value ['OL'] ['operation'] . $html;
  5816. // 最后的审批意见
  5817. array_push ( $irDetail, $fchtml );
  5818. if ($value ['status'] == 2)
  5819. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5820. elseif ($value ['status'] == 3)
  5821. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5822. elseif ($value ['status'] == 4)
  5823. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5824. else
  5825. array_push ( $irDetail, '' );
  5826. array_push ( $approvalList, $irDetail );
  5827. }
  5828. // $approvalListJson = json_encode ( $approvalList );
  5829. $recordsFiltered = $pageinfo ['total_data'];
  5830. echo json_encode ( array (
  5831. "draw" => intval ( $draw ),
  5832. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5833. "recordsFiltered" => intval ( $recordsFiltered ),
  5834. "data" => $approvalList
  5835. ), JSON_UNESCAPED_UNICODE );
  5836. }
  5837. /**
  5838. * 审批发票查看更多--重构
  5839. */
  5840. function invoiceApprovalAchieve() {
  5841. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5842. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5843. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5844. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5845. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5846. Doo::loadModel ( 'invoiceTraining' );
  5847. $invoiceTraining = new invoiceTraining ();
  5848. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5849. $this->data ['trainList'] = $trainList;
  5850. $this->data ['dateString'] = $date;
  5851. $this->data ['status'] = $status;
  5852. $this->data ['invoiceType'] = $invoiceType;
  5853. $this->data ['invoiceTrain'] = $invoiceTrain;
  5854. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5855. $this->data ['memu'] = "invoice";
  5856. $this->data ['staff'] = $this->staff;
  5857. $this->data ['receiptMemu'] = 'invoiceApproval';
  5858. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5859. }
  5860. function invoiceTAchieve() {
  5861. Doo::loadModel ( 'invoice' );
  5862. $invoice = new invoice ();
  5863. Doo::loadClass ( 'XDeode' );
  5864. $XDeode = new XDeode ( 5 );
  5865. Doo::loadModel ( 'staff' );
  5866. $staff = new staff ();
  5867. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5868. $page_size = 12;
  5869. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5870. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5871. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5872. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5873. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5874. Doo::loadModel ( 'invoiceTraining' );
  5875. $invoiceTraining = new invoiceTraining ();
  5876. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5877. $get = "/" . $date;
  5878. $con = '';
  5879. if ($date == 'MONTHO')
  5880. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5881. elseif ($date == 'MONTHT')
  5882. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5883. elseif ($date == 'MONTHY')
  5884. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5885. if ($invoiceType == 'ORDINARY')
  5886. $con .= ' and invoiceType=0 ';
  5887. elseif ($invoiceType == 'SPECIAL')
  5888. $con .= ' and invoiceType=1 ';
  5889. if ($invoiceTrain == 'ORDINARY')
  5890. $con .= ' and trainId=0 ';
  5891. elseif ($invoiceTrain == 'TRAIN')
  5892. $con .= ' and trainId!=0 ';
  5893. if ($invoiceTrainName != 'ALL') {
  5894. $trainId = $XDeode->decode ( $invoiceTrainName );
  5895. if (is_numeric ( $trainId ))
  5896. $con .= ' and trainId =' . $trainId;
  5897. }
  5898. if (! empty ( $MebSea )) {
  5899. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5900. $get .= "/" . $MebSea;
  5901. }
  5902. $pageinfo ['page'] = array (
  5903. 'previous' => ''
  5904. );
  5905. $sql = "";
  5906. $action = "";
  5907. if ($this->ACTION == 'invoicePrintAchieve') {
  5908. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5909. $action = "invoicePrintAchieve";
  5910. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5911. // and untreadStatus=0
  5912. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5913. $action = "invoicePostAchieve";
  5914. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5915. $sql = " untreadStatus=2 and status=2 " . $con;
  5916. $action = "invoiceUntreadAchieve";
  5917. }
  5918. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5919. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5920. $this->data ['MebSeaEn'] = $MebSea;
  5921. $this->data ['MebSea'] = urlencode ( $MebSea );
  5922. $this->data ['get'] = $get;
  5923. $this->data ['page'] = $pageinfo;
  5924. $this->data ['trainList'] = $trainList;
  5925. $this->data ['invoiceType'] = $invoiceType;
  5926. $this->data ['invoiceTrain'] = $invoiceTrain;
  5927. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5928. $this->data ['date'] = $date;
  5929. $this->data ['memu'] = "invoice";
  5930. $this->data ['staff'] = $this->staff;
  5931. if ($this->ACTION == 'invoicePrintAchieve') {
  5932. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5933. $this->data ['receiptMemu'] = 'invoicePrint';
  5934. $this->data ['list'] = $list;
  5935. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5936. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5937. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5938. Doo::loadModel ( 'express' );
  5939. $express = new express ();
  5940. $expressList = $express->getExpressByAll ();
  5941. $this->data ['expressList'] = $expressList;
  5942. $this->data ['receiptMemu'] = 'invoicePost';
  5943. $this->data ['list'] = $list;
  5944. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5945. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5946. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc','desc','untreadTime' );
  5947. $this->data ['receiptMemu'] = 'invoiceUntread';
  5948. $this->data ['list'] = $list;
  5949. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5950. }
  5951. }
  5952. /**
  5953. * 公司应收款
  5954. */
  5955. function invoiceAggregateCompanyDetail() {
  5956. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5957. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5958. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5959. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5960. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5961. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5962. Doo::loadClass ( 'XDeode' );
  5963. $XDeode = new XDeode ( 5 );
  5964. Doo::loadModel ( 'invoice' );
  5965. $invoice = new invoice ();
  5966. Doo::loadModel ( 'staff' );
  5967. $staff = new staff ();
  5968. Doo::loadModel ( "invoiceCompanyManage" );
  5969. $invoiceCompanyManage = new invoiceCompanyManage ();
  5970. Doo::loadModel ( 'L_category' );
  5971. $category = new L_category ();
  5972. $sid = '';
  5973. if (! empty ( $sidKey )) {
  5974. $sid = $XDeode->decode ( $sidKey );
  5975. }
  5976. $staffDetail = $staff->getStaffBySid ( $sid );
  5977. $cid = '';
  5978. if (! empty ( $cidKey )) {
  5979. $cid = $XDeode->decode ( $cidKey );
  5980. }
  5981. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5982. $cidList = array ();
  5983. foreach ( $imcStaff as $key => $value ) {
  5984. array_push ( $cidList, $value ['cid'] );
  5985. }
  5986. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5987. $cidString = implode ( ',', $cidList );
  5988. if (empty ( $cid ))
  5989. $staffList = $staff->getStaffInCid ( $cidString );
  5990. else
  5991. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5992. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5993. $page_size = 25;
  5994. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5995. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5996. $con = ' status=2 and untreadStatus!=2 and invalid=0 and isDelete=0 and badDebt=0 ';
  5997. $statisticsCon = '';
  5998. if (! empty ( $year ) && is_numeric ( $year ))
  5999. $con .= ' and Year(printTime)=' . $year . '';
  6000. if (! empty ( $month ) && is_numeric ( $month ))
  6001. $con .= ' and Month(printTime)="' . $month . '" ';
  6002. if ($status == 'UNRECORD')
  6003. $con .= ' and printStatus=1 and untreadStatus=0';
  6004. elseif ($status == 'RECORD')
  6005. $con .= ' and printStatus=1 and untreadStatus=3';
  6006. elseif ($status == 'BOUNCED')
  6007. $con .= ' and untreadStatus=2';
  6008. elseif ($status == 'PARTRECORD')
  6009. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  6010. elseif ($status == 'All') {
  6011. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  6012. }
  6013. if (! empty ( $sid ) && is_numeric ( $sid ))
  6014. $con .= ' and sid=' . $sid;
  6015. if (! empty ( $cid ) && is_numeric ( $cid ))
  6016. $con .= ' and cid=' . $cid;
  6017. else
  6018. $con .= ' and cid in (' . $cidString . ')';
  6019. // 开票内容筛选
  6020. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  6021. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  6022. }
  6023. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  6024. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  6025. if (! empty ( $titleORno )) {
  6026. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  6027. }
  6028. $pageinfo ['page'] = array (
  6029. 'previous' => ''
  6030. );
  6031. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  6032. $limit = $pageinfo ['lower'] . ',' . $page_size;
  6033. // 应收款合计
  6034. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  6035. //,'desc','desc','printTime'
  6036. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  6037. $totalPrice=array('invoicePrice'=>0.00,'receivePrice'=>0.00,'receivablesPrice'=>0.00);
  6038. foreach ($list as $key=>$value){
  6039. $totalPrice['invoicePrice']=bcadd($totalPrice['invoicePrice'], $value['invoicePrice'],2);
  6040. if($value['sumPrice']!=0){
  6041. $totalPrice['receivePrice']=bcadd($totalPrice['receivePrice'], $value['sumPrice'],2);
  6042. }
  6043. if($value['diffPrice']!=0){
  6044. $totalPrice['receivablesPrice']=bcadd($totalPrice['receivablesPrice'], $value['diffPrice'],2);
  6045. }
  6046. }
  6047. $this->data ['totalPrice'] = $totalPrice;
  6048. $monthHtml = "";
  6049. if ($year != "ALL") {
  6050. for($i = 1; $i <= 12; $i ++) {
  6051. if ($i == $month)
  6052. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  6053. else
  6054. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  6055. }
  6056. }
  6057. $this->data ['monthHtml'] = $monthHtml;
  6058. $this->data ['year'] = $year;
  6059. $this->data ['month'] = $month;
  6060. $this->data ['ics'] = $ics;
  6061. $this->data ['cidKey'] = $cidKey;
  6062. $this->data ['sid'] = $sid;
  6063. $this->data ['staffDetail'] = $staffDetail;
  6064. $this->data ['staffList'] = $staffList;
  6065. $this->data ['titleORnoEn'] = $titleORno;
  6066. $this->data ['titleORno'] = urlencode ( $titleORno );
  6067. $this->data ['invoiceDetail'] = array (
  6068. 'invoiceElement' => $invoiceElement
  6069. );
  6070. $this->data ['page'] = $pageinfo;
  6071. $this->data ['get'] = $get;
  6072. $this->data ['list'] = $list;
  6073. $this->data ['status'] = $status;
  6074. $this->data ['categoryList'] = $categoryList;
  6075. $this->data ['memu'] = "invoice";
  6076. $this->data ['staff'] = $this->staff;
  6077. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  6078. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  6079. }
  6080. /**
  6081. * 获取一条收款信息
  6082. */
  6083. function ajaxGetInvoiceReceivables() {
  6084. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  6085. Doo::loadModel ( 'invoiceReceivables' );
  6086. $invoiceReceivables = new invoiceReceivables ();
  6087. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  6088. echo json_encode ( array (
  6089. 'status' => 1,
  6090. 'detail' => $detail
  6091. ) );
  6092. }
  6093. /**
  6094. * 异步获取办事处用户
  6095. */
  6096. function ajaxGetStaffByCategory() {
  6097. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  6098. Doo::loadModel ( 'staff' );
  6099. $staff = new staff ();
  6100. if ($cid == "PUBLIC") {
  6101. echo json_encode ( array (
  6102. 'status' => 1,
  6103. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  6104. ) );
  6105. die ();
  6106. }
  6107. if (! is_numeric ( $cid )) {
  6108. echo json_encode ( array (
  6109. 'status' => 0,
  6110. 'msg' => 'illegal request'
  6111. ) );
  6112. die ();
  6113. }
  6114. $staffList = $staff->getStaffByCid ( $cid );
  6115. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6116. foreach ( $staffList as $key => $value ) {
  6117. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6118. }
  6119. echo json_encode ( array (
  6120. 'status' => 1,
  6121. 'html' => $html
  6122. ) );
  6123. }
  6124. /**
  6125. * 异步获取一条发票的邮寄信息
  6126. */
  6127. function ajaxGetInvoicePostDetail() {
  6128. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6129. Doo::loadModel ( 'invoice' );
  6130. $invoice = new invoice ();
  6131. $iid = $invoice->authcode ( $iid );
  6132. Doo::loadModel ( 'express' );
  6133. $express = new express ();
  6134. $expressList = $express->getExpressByAll ();
  6135. if (! is_numeric ( $iid )) {
  6136. echo json_encode ( array (
  6137. 'status' => 0,
  6138. 'msg' => 'illegal request'
  6139. ) );
  6140. die ();
  6141. }
  6142. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6143. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6144. $html = "";
  6145. foreach ( $expressList as $key => $value ) {
  6146. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6147. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6148. else
  6149. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6150. }
  6151. $invoiceDetail ['eaHtml'] = $html;
  6152. echo json_encode ( array (
  6153. 'status' => 1,
  6154. 'invoiceDetail' => $invoiceDetail
  6155. ) );
  6156. }
  6157. /**
  6158. *
  6159. * @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 ) ); }
  6160. */
  6161. /**
  6162. *
  6163. * @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 ) ); }
  6164. */
  6165. /**
  6166. * 我的收款中 选择哪个发票入账,进行金额判断
  6167. */
  6168. function ajaxCompareInvoicePrice() {
  6169. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6170. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6171. Doo::loadModel ( 'invoice' );
  6172. $invoice = new invoice ();
  6173. Doo::loadModel ( 'invoiceReceivables' );
  6174. $invoiceReceivables = new invoiceReceivables ();
  6175. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6176. $keyList = explode ( ';', $claimKey );
  6177. $receivablesPrice = 0;
  6178. foreach ( $keyList as $key => $value ) {
  6179. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6180. $receivablesPrice += $detailM ['receivablesPrice'];
  6181. }
  6182. if ($receivablesPrice > $detail ['invoicePrice']) {
  6183. $price = $receivablesPrice - $detail ['invoicePrice'];
  6184. echo json_encode ( array (
  6185. 'status' => 1,
  6186. 'price' => $price
  6187. ) );
  6188. } else
  6189. echo json_encode ( array (
  6190. 'status' => 2
  6191. ) );
  6192. }
  6193. /**
  6194. * 获得打印发票
  6195. */
  6196. function ajaxGetInvoiceInfoByPrint() {
  6197. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6198. if (empty ( $serial )) {
  6199. echo json_encode ( array (
  6200. 'status' => 2,
  6201. 'msg' => 'illegal request'
  6202. ) );
  6203. die ();
  6204. }
  6205. Doo::loadModel ( 'invoice' );
  6206. $invoice = new invoice ();
  6207. Doo::loadModel ( 'invoiceOperationLog' );
  6208. $invoiceOperationLog = new invoiceOperationLog ();
  6209. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6210. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6211. Doo::loadModel ( 'invoicePaper' );
  6212. $invoicePaper = new invoicePaper ();
  6213. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6214. if (empty ( $detail ))
  6215. $html = '';
  6216. else {
  6217. $html = '
  6218. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6219. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6220. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6221. <div class="modal-dialog modal-lg">
  6222. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6223. <div class="modal-body saeaList">
  6224. <table class="table table-bordered table-condensed"><tbody>
  6225. <tr>
  6226. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6227. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6228. </tr>
  6229. <tr>
  6230. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6231. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6232. </tr>
  6233. <tr>
  6234. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6235. </td>
  6236. </tr>
  6237. <tr>
  6238. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6239. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6240. </tr>
  6241. <tr>
  6242. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6243. </tr></tbody></table>';
  6244. if ($detail ['invoiceType'] == 0)
  6245. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6246. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6247. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6248. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6249. </tr>';
  6250. else
  6251. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6252. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6253. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6254. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6255. ';
  6256. $html .= '<tr>
  6257. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6258. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6259. </tr>
  6260. <tr>
  6261. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6262. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6263. </tr></tbody></table>';
  6264. if ($detail ['doPost'] == 1)
  6265. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6266. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6267. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6268. </tr><tr>
  6269. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6270. </tr><tr>
  6271. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6272. </tr></tbody></table>';
  6273. if (! empty ( $invoiceOperationLogList )) {
  6274. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6275. foreach ( $invoiceOperationLogList as $key => $value ) {
  6276. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6277. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6278. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6279. if ($value ['status'] == 2) {
  6280. $html .= '<span class="colGreen">同意</span>';
  6281. } elseif ($value ['status'] == 3) {
  6282. $html .= '<span class="colOrange">退回</span>';
  6283. } elseif ($value ['status'] == 5) {
  6284. $html .= '<span class="colGreen">打印</span>';
  6285. } elseif ($value ['status'] == 4) {
  6286. $html .= '<span class="colRed">终止</span>';
  6287. }
  6288. $html .= $value ['operation'] . '</p></blockquote>';
  6289. }
  6290. }
  6291. $html .= '</td>
  6292. <td><span class="colRed">*</span>
  6293. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6294. foreach ( $invoicePaperList as $key => $value ) {
  6295. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6296. }
  6297. $html .= '</select>
  6298. <span class="red" id="p-msg"></span>
  6299. </td>
  6300. </tr></tbody></table>';
  6301. }
  6302. $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>
  6303. </div></div></form>
  6304. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6305. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6306. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6307. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6308. ';
  6309. }
  6310. echo json_encode ( array (
  6311. 'status' => 1,
  6312. 'html' => $html
  6313. ) );
  6314. die ();
  6315. }
  6316. /**
  6317. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6318. */
  6319. function ajaxGetInvoiceInfoByType() {
  6320. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6321. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6322. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6323. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6324. if (empty ( $serial )) {
  6325. echo json_encode ( array (
  6326. 'status' => 2,
  6327. 'msg' => 'illegal request'
  6328. ) );
  6329. die ();
  6330. }
  6331. if ($type == 'INVOICE') {
  6332. Doo::loadModel ( 'invoice' );
  6333. $invoice = new invoice ();
  6334. Doo::loadModel ( 'invoiceOperationLog' );
  6335. $invoiceOperationLog = new invoiceOperationLog ();
  6336. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6337. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6338. if (empty ( $detail ))
  6339. $html = '';
  6340. else {
  6341. $html = '
  6342. <div class="modal-dialog modal-lg">
  6343. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6344. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6345. <tr>
  6346. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6347. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6348. </tr>
  6349. <tr>
  6350. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6351. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6352. </tr>
  6353. <tr>
  6354. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6355. </td>
  6356. </tr>
  6357. <tr>
  6358. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6359. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6360. </tr>
  6361. <tr>
  6362. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6363. </tr>';
  6364. if ($detail ['settlementType'] == 1)
  6365. $html .= '<tr>
  6366. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6367. </tr>';
  6368. else
  6369. $html .= '<tr>
  6370. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6371. </tr>';
  6372. $html .= ' </tbody></table>';
  6373. if ($detail ['invoiceType'] == 0){
  6374. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6375. <tr><th colspan="4" class="taC">增值税普通发票';
  6376. if($detail ['invoiceForm']==1){
  6377. $html .= '( <span class="colRed">电子发票</span> )';
  6378. }
  6379. $html .= '</th></tr><tr>
  6380. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6381. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6382. </tr>';
  6383. }else{
  6384. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6385. <tr><th colspan="4" class="taC">增值税专用发票';
  6386. if($detail ['invoiceForm']==1){
  6387. $html .= '( <span class="colRed">电子发票</span> )';
  6388. }
  6389. $html .= '</th></tr><tr>
  6390. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6391. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6392. ';
  6393. }
  6394. $html .= '<tr>
  6395. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6396. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6397. </tr>
  6398. <tr>
  6399. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6400. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6401. </tr>
  6402. <tr>
  6403. <th class="taC">发票号</th><td>' . $detail ['invoiceNo'] . '</td>
  6404. <th class="taC"></th><td></td>
  6405. </tr>
  6406. </tbody></table>';
  6407. if ($detail ['doPost'] == 1) {
  6408. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6409. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6410. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6411. </tr><tr>
  6412. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6413. </tr><tr>
  6414. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6415. </tr>
  6416. ';
  6417. if ($detail ['expressCom'] == 'SF')
  6418. $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>';
  6419. else
  6420. $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>';
  6421. $html .= '</tbody></table>';
  6422. }
  6423. if ($detail ['invoiceForm'] == 1) {
  6424. $html .= '<table class="table table-bordered table-condensed">
  6425. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6426. <tr>
  6427. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6428. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6429. </tr></tbody></table>';
  6430. }
  6431. if (! empty ( $invoiceOperationLogList )) {
  6432. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6433. foreach ( $invoiceOperationLogList as $key => $value ) {
  6434. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6435. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6436. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6437. if ($value ['status'] == 2) {
  6438. $html .= '<span class="colGreen">同意</span>';
  6439. } elseif ($value ['status'] == 3) {
  6440. $html .= '<span class="colOrange">退回</span>';
  6441. } elseif ($value ['status'] == 5) {
  6442. $html .= '<span class="colGreen">打印</span>';
  6443. } elseif ($value ['status'] == 4) {
  6444. $html .= '<span class="colRed">终止</span>';
  6445. }
  6446. $html .= $value ['operation'] . '</p></blockquote>';
  6447. }
  6448. }
  6449. $html .= '</td></tr></tbody></table>';
  6450. }
  6451. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6452. }
  6453. echo json_encode ( array (
  6454. 'status' => 1,
  6455. 'html' => $html
  6456. ) );
  6457. die ();
  6458. } elseif ($type == 'RECEIVABLES') {
  6459. Doo::loadModel ( 'invoiceReceivables' );
  6460. $invoiceReceivables = new invoiceReceivables ();
  6461. Doo::loadModel ( 'invoiceRefund' );
  6462. $invoiceRefund = new invoiceRefund ();
  6463. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6464. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6465. if (empty ( $detail ))
  6466. $html = '';
  6467. else {
  6468. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6469. <table class="table table-bordered table-condensed">
  6470. <tbody><tr>
  6471. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6472. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6473. </tr><tr>
  6474. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6475. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6476. </tr>
  6477. <tr>
  6478. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6479. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6480. </tr>
  6481. <tr>
  6482. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6483. </tr>
  6484. </tbody></table>';
  6485. if (! empty ( $ireList )) {
  6486. $html .= '
  6487. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6488. <tr>
  6489. <th class="taC">退款单位名称</th>
  6490. <th class="taC">退款的账号</th>
  6491. <th class="taC">退款金额</th>
  6492. <th class="taC">退款</th>
  6493. <th class="taC">备注</th>
  6494. </tr>
  6495. ';
  6496. foreach ( $ireList as $key => $value ) {
  6497. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6498. $html .= '<tr>
  6499. <td>' . $value ['refundCompany'] . '</td>
  6500. <td>' . $value ['refundNumber'] . '</td>
  6501. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6502. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6503. <td>' . $value ['refundRemarks'] . '</td>
  6504. </tr>
  6505. ';
  6506. }
  6507. }
  6508. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6509. }
  6510. echo json_encode ( array (
  6511. 'status' => 1,
  6512. 'html' => $html
  6513. ) );
  6514. die ();
  6515. } elseif ($type == 'IRTC') {
  6516. Doo::loadModel ( 'invoice' );
  6517. $invoice = new invoice ();
  6518. Doo::loadModel ( 'invoiceOperationLog' );
  6519. $invoiceOperationLog = new invoiceOperationLog ();
  6520. // Doo::loadModel ( 'invoiceReceivables' );
  6521. // $invoiceReceivables = new invoiceReceivables ();
  6522. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6523. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6524. if (empty ( $detail ))
  6525. $html = '';
  6526. else {
  6527. $receivablesPriceedHtml = '';
  6528. $receivablesPrice = $detail ['invoicePrice'];
  6529. if (! empty ( $detail ['irid'] )) {
  6530. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6531. // if (empty ( $irList ))
  6532. // $irList [0] ['sumPrice'] = 0;
  6533. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6534. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6535. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6536. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6537. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6538. </tr></tbody></table>';
  6539. $receivablesPrice = $detail ['invoiceBalance'];
  6540. }
  6541. if ($loss)
  6542. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6543. $html = $receivablesPriceedHtml . '
  6544. <table class="table table-bordered table-condensed"><tbody>
  6545. <tr>
  6546. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6547. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6548. </tr>
  6549. <tr>
  6550. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6551. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6552. </tr>
  6553. <tr>
  6554. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6555. </tr>
  6556. <tr>
  6557. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6558. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6559. </tr>
  6560. <tr>
  6561. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6562. </tr></tbody></table>';
  6563. if ($detail ['invoiceType'] == 0) {
  6564. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6565. <tr><th colspan="4" class="taC">增值税普通发票';
  6566. if($detail ['invoiceForm']==1){
  6567. $html .= '( <span class="colRed">电子发票</span> )';
  6568. }
  6569. $html.='</th></tr><tr>
  6570. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6571. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6572. </tr>';
  6573. $receivablesMessage = $detail ['invoiceTitle'];
  6574. } else {
  6575. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6576. <tr><th colspan="4" class="taC">增值税专用发票';
  6577. if($detail ['invoiceForm']==1){
  6578. $html .= '( <span class="colRed">电子发票</span> )';
  6579. }
  6580. $html .= '</th></tr><tr>
  6581. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6582. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6583. ';
  6584. $receivablesMessage = $detail ['invoiceCompany'];
  6585. }
  6586. $html .= '<tr>
  6587. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6588. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6589. </tr>
  6590. <tr>
  6591. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6592. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6593. </tr></tbody></table>';
  6594. if ($detail ['doPost'] == 1)
  6595. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6596. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6597. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6598. </tr><tr>
  6599. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6600. </tr><tr>
  6601. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6602. </tr></tbody></table>';
  6603. if (! empty ( $invoiceOperationLogList )) {
  6604. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6605. foreach ( $invoiceOperationLogList as $key => $value ) {
  6606. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6607. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6608. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6609. if ($value ['status'] == 2) {
  6610. $html .= '<span class="colGreen">同意</span>';
  6611. } elseif ($value ['status'] == 3) {
  6612. $html .= '<span class="colOrange">退回</span>';
  6613. } elseif ($value ['status'] == 5) {
  6614. $html .= '<span class="colGreen">打印</span>';
  6615. }
  6616. $html .= $value ['operation'] . '</p></blockquote>';
  6617. }
  6618. }
  6619. $html .= '</td></tr></tbody></table>';
  6620. }
  6621. }
  6622. echo json_encode ( array (
  6623. 'status' => 1,
  6624. 'html' => $html,
  6625. 'receivablesPrice' => $receivablesPrice,
  6626. 'receivablesMessage' => $receivablesMessage,
  6627. 'receivablesDate' => date ( "Y-m-d" ),
  6628. 'iidKey' => $serial
  6629. ) );
  6630. die ();
  6631. }
  6632. }
  6633. function ajaxGetInvoiceReceivablesByStaff() {
  6634. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6635. if (empty ( $postData )) {
  6636. echo json_encode ( array (
  6637. 'status' => 2,
  6638. 'msg' => 'illegal request'
  6639. ) );
  6640. die ();
  6641. }
  6642. Doo::loadModel ( 'invoiceReceivables' );
  6643. $invoiceReceivables = new invoiceReceivables ();
  6644. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6645. if (empty ( $detail )) {
  6646. echo json_encode ( array (
  6647. 'status' => 2,
  6648. 'msg' => 'illegal request'
  6649. ) );
  6650. die ();
  6651. }
  6652. Doo::loadModel ( 'L_category' );
  6653. $lCategory = new L_category ();
  6654. Doo::loadModel ( 'staff' );
  6655. $staff = new staff ();
  6656. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6657. $category = $lCategory->getCategory ();
  6658. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6659. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6660. foreach ( $category as $key => $value ) {
  6661. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6662. if ($value ['cid'] == $detail ['cid'])
  6663. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6664. }
  6665. foreach ( $staffList as $key => $value ) {
  6666. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6667. if ($value ['sid'] == $detail ['sid'])
  6668. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6669. }
  6670. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6671. echo json_encode ( array (
  6672. 'status' => 1,
  6673. 'categoryHtml' => $categoryHtml,
  6674. 'staffHtml' => $staffHtml,
  6675. 'rbankHtml' => $rbankHtml,
  6676. 'detail' => $detail
  6677. ) );
  6678. }
  6679. function ajaxGetInvoiceReceivablesByIrid() {
  6680. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6681. if (empty ( $irid )) {
  6682. echo json_encode ( array (
  6683. 'status' => 2,
  6684. 'msg' => 'illegal request'
  6685. ) );
  6686. die ();
  6687. }
  6688. Doo::loadModel ( 'invoiceReceivables' );
  6689. $invoiceReceivables = new invoiceReceivables ();
  6690. Doo::loadModel ( 'invoice' );
  6691. $invoice = new invoice ();
  6692. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6693. $flag = true;
  6694. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6695. $bakDetail = array ();
  6696. if ($flag === false) {
  6697. array_push ( $bakDetail, $invoiceDetail );
  6698. $invoiceDetail = $bakDetail;
  6699. }
  6700. $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>
  6701. <tr>
  6702. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6703. <td>' . $detail ['receivablesMessage'] . '</td>
  6704. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6705. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6706. <td>' . $detail ['recepitTitleMark'] . '</td>
  6707. </tr></tbody></table>';
  6708. $isInvoice = false;
  6709. $invoiceHtml = '';
  6710. if (empty ( $invoiceDetail )) {
  6711. $isInvoice = true;
  6712. } else {
  6713. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6714. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6715. foreach ( $invoiceDetail as $key => $value ) {
  6716. $invoiceHtml .= '<tr>';
  6717. if (! empty ( $value ['invoiceType'] )) {
  6718. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6719. } else {
  6720. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6721. }
  6722. if (! empty ( $value ['invoiceType'] )) {
  6723. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6724. } else {
  6725. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6726. }
  6727. $invoiceHtml .= '
  6728. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6729. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6730. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6731. </tr>
  6732. ';
  6733. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6734. if (empty ( $irList ))
  6735. $irList [0] ['sumPrice'] = 0;
  6736. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6737. $priceString = '';
  6738. if ($balance < $detail ['receivablesPrice']) {
  6739. $priceString = '收款金额超过开票金额,';
  6740. }
  6741. if ($balance > $detail ['receivablesPrice']) {
  6742. $priceString = '收款金额低于开票金额,';
  6743. }
  6744. }
  6745. $invoiceHtml .= '
  6746. <script>
  6747. $(\'a[bind-receivables^="ir"]\').click(function() {
  6748. var data = $(this).attr("data-ikey");
  6749. $("input[name=\'invoiceKey\']").val(data);
  6750. var invoiceKey=data;
  6751. if(invoiceKey==""){
  6752. alert("入账错误,请重新刷新页面");
  6753. return false;
  6754. }
  6755. if(window.confirm("' . $priceString . '确定入账吗?")){
  6756. $("#IBR").submit();
  6757. }else{
  6758. return false;
  6759. }
  6760. });
  6761. </script>
  6762. ';
  6763. $invoiceHtml .= '</tbody></table>';
  6764. }
  6765. echo json_encode ( array (
  6766. 'status' => 1,
  6767. 'irkey' => $detail ['iridEn'],
  6768. 'receivablesHtml' => $receivablesHtml,
  6769. 'isInvoice' => $isInvoice,
  6770. 'invoiceHtml' => $invoiceHtml
  6771. ) );
  6772. }
  6773. function ajaxGetInvoiceReceivablesByTitle() {
  6774. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6775. if (empty ( $title )) {
  6776. echo json_encode ( array (
  6777. 'status' => 2,
  6778. 'msg' => 'illegal request'
  6779. ) );
  6780. die ();
  6781. }
  6782. Doo::loadModel ( 'invoice' );
  6783. $invoice = new invoice ();
  6784. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6785. $invoiceHtml = '';
  6786. if (! empty ( $invoiceDetail )) {
  6787. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6788. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6789. foreach ( $invoiceDetail as $key => $value ) {
  6790. if (! empty ( $value ['invoiceType'] )) {
  6791. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6792. } else {
  6793. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6794. }
  6795. if (! empty ( $value ['invoiceType'] )) {
  6796. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6797. } else {
  6798. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6799. }
  6800. $invoiceHtml .= '
  6801. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6802. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6803. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6804. </tr>
  6805. ';
  6806. }
  6807. $invoiceHtml .= '</tbody></table>
  6808. <script>
  6809. $(\'a[bind-receivables^="ir"]\').click(function() {
  6810. var data = $(this).attr("data-ikey");
  6811. $("input[name=\'invoiceKey\']").val(data);
  6812. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6813. if(invoiceKey==""){
  6814. alert("入账错误,请重新刷新页面");
  6815. return false;
  6816. }
  6817. if(window.confirm("确定入账吗?")){
  6818. $("#IBR").submit();
  6819. }else{
  6820. return false;
  6821. }
  6822. });
  6823. </script>
  6824. ';
  6825. }
  6826. echo json_encode ( array (
  6827. 'status' => 1,
  6828. 'invoiceHtml' => $invoiceHtml
  6829. ) );
  6830. }
  6831. function ajaxInvoicePushNotice() {
  6832. Doo::loadModel ( 'invoice' );
  6833. $invoice = new invoice ();
  6834. $approval = $invoice->getOne ( array (
  6835. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6836. 'desc' => 'iid',
  6837. 'asArray' => true
  6838. ) );
  6839. $isNotice = false;
  6840. if (! empty ( $approval ))
  6841. $isNotice = true;
  6842. $response = array (
  6843. 'error' => 0,
  6844. 'isNotice' => $isNotice
  6845. );
  6846. echo json_encode ( $response );
  6847. exit ();
  6848. }
  6849. public function ajaxCheckInvoiceNoUniqueness() {
  6850. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6851. Doo::loadModel ( 'invoice' );
  6852. $invoice = new invoice ();
  6853. if (! empty ( $invoiceNo )) {
  6854. Doo::loadModel ( 'invoicePaper' );
  6855. $invoicePaper = new invoicePaper ();
  6856. Doo::loadClass ( 'XDeode' );
  6857. $XDeode = new XDeode ( 5 );
  6858. $ipid = $XDeode->decode ( $invoiceNo );
  6859. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6860. $info = $invoice->getOne ( array (
  6861. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6862. 'asArray' => TRUE
  6863. ) );
  6864. if (! empty ( $info )) {
  6865. echo json_encode ( array (
  6866. 'error' => '发票号已存在'
  6867. ) );
  6868. die ();
  6869. } else
  6870. echo json_encode ( array (
  6871. 'ok' => '可以使用!'
  6872. ) );
  6873. die ();
  6874. }
  6875. }
  6876. function ajaxCheckInvoicePrice() {
  6877. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6878. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6879. Doo::loadModel ( 'invoice' );
  6880. $invoice = new invoice ();
  6881. Doo::loadModel ( 'invoiceReceivables' );
  6882. $invoiceReceivables = new invoiceReceivables ();
  6883. Doo::loadClass ( 'XDeode' );
  6884. $XDeode = new XDeode ( 5 );
  6885. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6886. $iidKey = $XDeode->decode ( $iidKey );
  6887. $info = $invoice->getInvoiceByIid ( $iidKey );
  6888. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6889. if (empty ( $irList ))
  6890. $irList [0] ['sumPrice'] = 0;
  6891. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6892. if ($balance < $receivablesPrice) {
  6893. echo json_encode ( array (
  6894. 'error' => '收款金额超过开票金额。'
  6895. ) );
  6896. die ();
  6897. }
  6898. if ($balance > $receivablesPrice) {
  6899. echo json_encode ( array (
  6900. 'error' => '收款金额低于开票金额。'
  6901. ) );
  6902. die ();
  6903. }
  6904. }
  6905. }
  6906. function ajaxGetInvoiceByNew() {
  6907. Doo::loadModel ( 'invoice' );
  6908. $invoice = new invoice ();
  6909. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6910. echo json_encode ( array (
  6911. 'status' => 1,
  6912. 'detail' => $detail
  6913. ) );
  6914. }
  6915. /**
  6916. * 旧输入导入
  6917. */
  6918. function importInvoice() {
  6919. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6920. $data ['emsg'] = "";
  6921. if ($emsg != "")
  6922. $data ['emsg'] = "请填写完整的数据";
  6923. $data ['time'] = time ();
  6924. $this->render ( "/admin/invoiceImport", $data );
  6925. }
  6926. function uploadInvoice() {
  6927. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6928. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6929. $file = $_FILES ['Filedata'] ['tmp_name'];
  6930. $error = false;
  6931. if (! is_uploaded_file ( $file )) {
  6932. $error = '400 Bad Request';
  6933. }
  6934. if ($error) {
  6935. header ( 'HTTP/1.0 ' . $error );
  6936. die ( 'Error ' . $error );
  6937. } else {
  6938. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6939. $this->IoHandler = new IoHandler ();
  6940. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6941. // $filedir=$_POST['time'];
  6942. // 调用定义物理路径
  6943. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6944. $this->IoHandler->MakeDir ( $t );
  6945. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6946. if ($filename != 'xlsx')
  6947. return "";
  6948. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6949. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6950. $upload_dir = $t . "/" . $upload_file;
  6951. $k = move_uploaded_file ( $file, $upload_dir );
  6952. if ($k) {
  6953. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6954. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6955. }
  6956. }
  6957. }
  6958. }
  6959. function importInvoiceDo() {
  6960. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6961. if ($path != "") {
  6962. Doo::loadModel ( 'invoice' );
  6963. Doo::loadModel ( 'staff' );
  6964. $staff = new staff ();
  6965. Doo::loadModel ( 'invoiceStatistics' );
  6966. Doo::loadModel ( 'invoiceOperationLog' );
  6967. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6968. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6969. // print_r ( $exlArray );
  6970. // die ();
  6971. // echo json_encode($exlArray);die;
  6972. foreach ( $exlArray as $key => $value ) {
  6973. // 开票
  6974. $invoice = new invoice ();
  6975. $invoice->invoiceNo = $value ['invoiceNo'];
  6976. $invoice->invoiceType = 0;
  6977. if ($value ['invoiceType'] == '专')
  6978. $invoice->invoiceType = 1;
  6979. $invoice->invoicePrice = $value ['invoicePrice'];
  6980. $invoice->invoiceQuantity = 1;
  6981. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6982. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6983. if ($value ['invoiceType'] == '专')
  6984. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6985. $invoice->userName = $value ['userName'];
  6986. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6987. $invoice->sid = $sDetail ['sid'];
  6988. $invoice->cid = $sDetail ['cid'];
  6989. $invoice->categoryName = $sDetail ['category'];
  6990. $invoice->invoiceElement = $value ['invoiceElement'];
  6991. $invoice->remark = $value ['remark'];
  6992. $invoice->date = $value ['date'];
  6993. $invoice->printTime = $value ['date'];
  6994. $invoice->ipSource = 1;
  6995. $invoice->printStatus = 1;
  6996. $invoice->status = 2;
  6997. $invoice->postStatus = 1;
  6998. $invoice->untreadStatus = 0;
  6999. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  7000. $iid = $invoice->insert ();
  7001. // 汇总
  7002. $invoiceStatistics = new invoiceStatistics ();
  7003. //
  7004. $item = array (
  7005. 'date' => $value ['date'],
  7006. 'priceClass' => 1,
  7007. 'cid' => $sDetail ['cid'],
  7008. 'staff' => $sDetail ['sid'],
  7009. 'invoicePrice' => $value ['invoicePrice']
  7010. );
  7011. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7012. $invoiceOperationLog = new invoiceOperationLog ();
  7013. $item = array (
  7014. 'date' => date ( "Y-m-d H:i:s" ),
  7015. 'operation' => date ( "Y-m-d" ) . " 导入",
  7016. 'status' => 1,
  7017. 'img' => $sDetail ['avatar'],
  7018. 'username' => $sDetail ['username'],
  7019. 'uid' => $sDetail ['sid'],
  7020. 'category' => $sDetail ['category'],
  7021. 'iid' => $iid
  7022. );
  7023. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  7024. }
  7025. return '/importInvoice?count=' . count ( $exlArray );
  7026. // return "/keyonline";
  7027. }
  7028. echo 'no file';
  7029. }
  7030. function importInvoiceReceivables() {
  7031. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  7032. $data ['emsg'] = "";
  7033. if ($emsg != "")
  7034. $data ['emsg'] = "请填写完整的数据";
  7035. $data ['time'] = time ();
  7036. $this->render ( "/admin/invoiceReceivablesImport", $data );
  7037. }
  7038. // 导入入账数据
  7039. function importInvoiceReceivablesDo() {
  7040. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  7041. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  7042. if ($path != "") {
  7043. Doo::loadModel ( 'invoiceReceivables' );
  7044. Doo::loadModel ( 'invoice' );
  7045. Doo::loadModel ( 'staff' );
  7046. $staff = new staff ();
  7047. Doo::loadModel ( 'invoiceStatistics' );
  7048. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  7049. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  7050. // print_r ( $exlArray );
  7051. // die ();
  7052. // echo json_encode($exlArray);die;
  7053. foreach ( $exlArray as $key => $value ) {
  7054. // 收款
  7055. $invoiceReceivables = new invoiceReceivables ();
  7056. $invoice = new invoice ();
  7057. $invoiceReceivables->bindStatus = 1;
  7058. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  7059. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  7060. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  7061. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  7062. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  7063. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  7064. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  7065. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  7066. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  7067. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  7068. $invoiceReceivables->iid = $iDetail ['iid'];
  7069. $irid = $invoiceReceivables->insert ();
  7070. // 发票绑定收款
  7071. $detail = $iDetail;
  7072. $iridString = "";
  7073. if (empty ( $detail ['irid'] ))
  7074. $iridString = $irid;
  7075. else
  7076. $iridString = $detail ['irid'] . ',' . $irid;
  7077. $item = array (
  7078. 'irid' => $iridString,
  7079. 'iid' => $detail ['iid']
  7080. );
  7081. $invoice->setInvoiceByCondition ( $item );
  7082. // 汇总
  7083. $invoiceStatistics = new invoiceStatistics ();
  7084. // 扣除入账统计金额
  7085. $item = array (
  7086. 'date' => $value ['receivablesDate'],
  7087. 'priceClass' => 3,
  7088. 'cid' => $sDetail ['cid'],
  7089. 'staff' => $sDetail ['sid'],
  7090. // 'irid' => $irid,
  7091. 'accountPrice' => $value ['receivablesPrice']
  7092. );
  7093. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7094. }
  7095. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  7096. echo 'data count ' . count ( $exlArray );
  7097. die ();
  7098. // return "/keyonline";
  7099. }
  7100. echo 'no file';
  7101. }
  7102. function formatExcelToArrayTrain($file_url = "") {
  7103. if (! file_exists ( $file_url )) {
  7104. return array ();
  7105. }
  7106. // Doo::loadClass ( 'PHPExcel' );
  7107. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7108. $PHPExcel = new PHPExcel ();
  7109. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7110. if (! $PHPReader->canRead ( $file_url )) {
  7111. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7112. if (! $PHPReader->canRead ( $file_url )) {
  7113. echo 'no Excel';
  7114. return;
  7115. }
  7116. }
  7117. $PHPExcel = $PHPReader->load ( $file_url );
  7118. /* * 读取excel文件中的第一个工作表 */
  7119. $currentSheet = $PHPExcel->getSheet ( 0 );
  7120. /* * 取得最大的列号 */
  7121. $allColumn = $currentSheet->getHighestColumn ();
  7122. /* * 取得一共有多少行 */
  7123. $allRow = $currentSheet->getHighestRow ();
  7124. $excel_array = array ();
  7125. // die($file_url);
  7126. $conk = 2;
  7127. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7128. $excel_column = array ();
  7129. // 后期改进
  7130. if ($allColumn == 'AM')
  7131. $allColumn = 'Z';
  7132. /* * 从第A列开始输出 */
  7133. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7134. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7135. if ($val instanceof PHPExcel_RichText)
  7136. $val = $val->__toString ();
  7137. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7138. // $val = "'" . addslashes ( $val ) . "'";
  7139. if ($currentColumn == 'A') {
  7140. $excel_column ['invoiceTitle'] = $val;
  7141. } elseif ($currentColumn == 'B')
  7142. $excel_column ['invoiceType'] = $val;
  7143. elseif ($currentColumn == 'C') {
  7144. $excel_column ['TIN'] = $val;
  7145. } elseif ($currentColumn == 'D') {
  7146. $excel_column ['address'] = $val;
  7147. } elseif ($currentColumn == 'E') {
  7148. $excel_column ['phone'] = $val;
  7149. } elseif ($currentColumn == 'F') {
  7150. $excel_column ['bank'] = $val;
  7151. } elseif ($currentColumn == 'G') {
  7152. $excel_column ['bankAccount'] = $val;
  7153. } elseif ($currentColumn == 'H') {
  7154. $excel_column ['invoiceElement'] = $val;
  7155. } elseif ($currentColumn == 'I') {
  7156. $excel_column ['invoiceQuantity'] = $val;
  7157. } elseif ($currentColumn == 'J') {
  7158. $excel_column ['invoiceUnitPrice'] = $val;
  7159. } elseif ($currentColumn == 'K') {
  7160. $excel_column ['remark'] = $val;
  7161. } elseif ($currentColumn == 'L') {
  7162. $excel_column ['recipientsAddress'] = $val;
  7163. } elseif ($currentColumn == 'M') {
  7164. $excel_column ['recipients'] = $val;
  7165. } elseif ($currentColumn == 'N') {
  7166. $excel_column ['recipientsPhone'] = $val;
  7167. }elseif ($currentColumn == 'O') {
  7168. $excel_column ['electronicPhone'] = $val;
  7169. } elseif ($currentColumn == 'P') {
  7170. $excel_column ['electronicEmail'] = $val;
  7171. }
  7172. }
  7173. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7174. array_push ( $excel_array, $excel_column );
  7175. }
  7176. return $excel_array;
  7177. }
  7178. /**
  7179. * 格式化excel文件为数组
  7180. * @param unknown_type $file_url
  7181. * @param unknown_type $mcid
  7182. */
  7183. function _format_excel_to_array($file_url = "", $sType = "") {
  7184. if (! file_exists ( $file_url )) {
  7185. return array ();
  7186. }
  7187. Doo::loadClass ( 'PHPExcel' );
  7188. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7189. $PHPExcel = new PHPExcel ();
  7190. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7191. if (! $PHPReader->canRead ( $file_url )) {
  7192. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7193. if (! $PHPReader->canRead ( $file_url )) {
  7194. echo 'no Excel';
  7195. return;
  7196. }
  7197. }
  7198. $PHPExcel = $PHPReader->load ( $file_url );
  7199. /* * 读取excel文件中的第一个工作表 */
  7200. $currentSheet = $PHPExcel->getSheet ( 0 );
  7201. /* * 取得最大的列号 */
  7202. $allColumn = $currentSheet->getHighestColumn ();
  7203. /* * 取得一共有多少行 */
  7204. $allRow = $currentSheet->getHighestRow ();
  7205. $excel_array = array ();
  7206. // die($file_url);
  7207. $conk = 2;
  7208. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7209. $excel_column = array ();
  7210. // 后期改进
  7211. if ($allColumn == 'AM')
  7212. $allColumn = 'Z';
  7213. /* * 从第A列开始输出 */
  7214. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7215. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7216. if ($val instanceof PHPExcel_RichText)
  7217. $val = $val->__toString ();
  7218. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7219. // $val = "'" . addslashes ( $val ) . "'";
  7220. if ($sType == 'invoiceReceivables') {
  7221. if ($currentColumn == 'A')
  7222. $excel_column ['invoiceNo'] = $val;
  7223. elseif ($currentColumn == 'B')
  7224. $excel_column ['receivablesPrice'] = $val;
  7225. elseif ($currentColumn == 'C') {
  7226. $excel_column ['receivablesMessage'] = $val;
  7227. } elseif ($currentColumn == 'D') {
  7228. $excel_column ['receivablesBank'] = $val;
  7229. } elseif ($currentColumn == 'E') {
  7230. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7231. } elseif ($currentColumn == 'F') {
  7232. $excel_column ['receivablesStaff'] = $val;
  7233. } elseif ($currentColumn == 'G') {
  7234. $excel_column ['sourcePrice'] = $val;
  7235. }
  7236. } elseif ($sType == "invoiceTrain") {
  7237. if ($currentColumn == 'A') {
  7238. $excel_column ['invoiceTitle'] = $val;
  7239. } elseif ($currentColumn == 'B')
  7240. $excel_column ['invoiceType'] = $val;
  7241. elseif ($currentColumn == 'C') {
  7242. $excel_column ['TIN'] = $val;
  7243. } elseif ($currentColumn == 'D') {
  7244. $excel_column ['address'] = $val;
  7245. } elseif ($currentColumn == 'E') {
  7246. $excel_column ['phone'] = $val;
  7247. } elseif ($currentColumn == 'F') {
  7248. $excel_column ['bank'] = $val;
  7249. } elseif ($currentColumn == 'G') {
  7250. $excel_column ['bankAccount'] = $val;
  7251. } elseif ($currentColumn == 'H') {
  7252. $excel_column ['invoiceElement'] = $val;
  7253. } elseif ($currentColumn == 'I') {
  7254. $excel_column ['invoiceQuantity'] = $val;
  7255. } elseif ($currentColumn == 'J') {
  7256. $excel_column ['invoiceUnitPrice'] = $val;
  7257. } elseif ($currentColumn == 'K') {
  7258. $excel_column ['remark'] = $val;
  7259. } elseif ($currentColumn == 'L') {
  7260. $excel_column ['recipientsAddress'] = $val;
  7261. } elseif ($currentColumn == 'M') {
  7262. $excel_column ['recipients'] = $val;
  7263. } elseif ($currentColumn == 'N') {
  7264. $excel_column ['recipientsPhone'] = $val;
  7265. }
  7266. } else {
  7267. if ($currentColumn == 'A')
  7268. $excel_column ['invoiceNo'] = $val;
  7269. elseif ($currentColumn == 'B')
  7270. $excel_column ['invoiceType'] = $val;
  7271. elseif ($currentColumn == 'C') {
  7272. $excel_column ['invoicePrice'] = $val;
  7273. } elseif ($currentColumn == 'D') {
  7274. $excel_column ['invoiceTitle'] = $val;
  7275. } elseif ($currentColumn == 'E') {
  7276. $excel_column ['userName'] = $val;
  7277. } elseif ($currentColumn == 'F') {
  7278. $excel_column ['categoryName'] = $val;
  7279. } elseif ($currentColumn == 'G') {
  7280. $excel_column ['invoiceElement'] = $val;
  7281. } elseif ($currentColumn == 'H') {
  7282. $excel_column ['remark'] = $val;
  7283. } elseif ($currentColumn == 'I') {
  7284. $excel_column ['date'] = $this->excelTime ( $val );
  7285. }
  7286. }
  7287. }
  7288. array_push ( $excel_array, $excel_column );
  7289. }
  7290. return $excel_array;
  7291. }
  7292. function excelTime($date, $time = false) {
  7293. if (function_exists ( 'GregorianToJD' )) {
  7294. if (is_numeric ( $date )) {
  7295. $jd = GregorianToJD ( 1, 1, 1970 );
  7296. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7297. $date = explode ( '/', $gregorian );
  7298. $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" : '');
  7299. return $date_str;
  7300. }
  7301. } else {
  7302. $date = $date > 25568 ? $date + 1 : 25569;
  7303. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7304. $ofs = (70 * 365 + 17 + 2) * 86400;
  7305. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7306. }
  7307. return $date;
  7308. }
  7309. /**
  7310. * 旧输入导入
  7311. */
  7312. function _GetFileEXT($filename) {
  7313. $pics = explode ( '.', $filename );
  7314. $num = count ( $pics );
  7315. return $pics [$num - 1];
  7316. }
  7317. function showCache($path = "", $sid = 0) {
  7318. // if (file_exists ( $path )) {
  7319. // $htm = file_get_contents ( $path );
  7320. // } else {
  7321. Doo::loadModel ( 'invoiceStatistics' );
  7322. $invoiceStatistics = new invoiceStatistics ();
  7323. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7324. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7325. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7326. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7327. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7328. /*
  7329. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7330. */
  7331. file_put_contents ( $path, $htm );
  7332. // }
  7333. return $htm;
  7334. }
  7335. /**
  7336. * 生成token
  7337. * @return string
  7338. */
  7339. function set_token() {
  7340. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7341. $str = sha1 ( $str ); // 加密
  7342. return $str;
  7343. }
  7344. /**
  7345. * 获取get或者POST值
  7346. *
  7347. * @param string $name 属性名称
  7348. * @return fixed 值
  7349. */
  7350. function get_args($name) {
  7351. if (isset ( $_GET [$name] )) {
  7352. if (is_array ( $_GET [$name] ))
  7353. return $_GET [$name];
  7354. else
  7355. return addslashes ( $_GET [$name] );
  7356. } elseif (isset ( $_POST [$name] )) {
  7357. if (is_array ( $_POST [$name] ))
  7358. return $_POST [$name];
  7359. else
  7360. return addslashes ( $_POST [$name] );
  7361. } else
  7362. return false;
  7363. }
  7364. function SafeFilter(&$arr) {
  7365. $ra = Array (
  7366. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7367. '/script/',
  7368. '/javascript/',
  7369. '/vbscript/',
  7370. '/expression/',
  7371. '/applet/',
  7372. '/meta/',
  7373. '/xml/',
  7374. '/blink/',
  7375. '/link/',
  7376. '/style/',
  7377. '/embed/',
  7378. '/object/',
  7379. '/frame/',
  7380. '/layer/',
  7381. '/title/',
  7382. '/bgsound/',
  7383. '/base/',
  7384. '/onload/',
  7385. '/onunload/',
  7386. '/onchange/',
  7387. '/onsubmit/',
  7388. '/onreset/',
  7389. '/onselect/',
  7390. '/onblur/',
  7391. '/onfocus/',
  7392. '/onabort/',
  7393. '/onkeydown/',
  7394. '/onkeypress/',
  7395. '/onkeyup/',
  7396. '/onclick/',
  7397. '/ondblclick/',
  7398. '/onmousedown/',
  7399. '/onmousemove/',
  7400. '/onmouseout/',
  7401. '/onmouseover/',
  7402. '/onmouseup/',
  7403. '/onunload/'
  7404. );
  7405. if (is_array ( $arr )) {
  7406. foreach ( $arr as $key => $value ) {
  7407. if (! is_array ( $value )) {
  7408. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7409. {
  7410. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7411. }
  7412. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7413. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7414. } else {
  7415. SafeFilter ( $arr [$key] );
  7416. }
  7417. }
  7418. }
  7419. }
  7420. /**
  7421. * Escape String
  7422. *
  7423. * @access public
  7424. * @param string
  7425. * @param bool whether or not the string will be used in a LIKE condition
  7426. * @return string
  7427. */
  7428. function escape_str($str, $like = FALSE) {
  7429. if (is_array ( $str )) {
  7430. foreach ( $str as $key => $val ) {
  7431. $str [$key] = $this->escape_str ( $val, $like );
  7432. }
  7433. return $str;
  7434. }
  7435. var_dump ( Doo::db ()->getDbObject () );
  7436. die ();
  7437. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7438. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7439. } elseif (function_exists ( 'mysql_escape_string' )) {
  7440. $str = mysql_escape_string ( $str );
  7441. } else {
  7442. $str = addslashes ( $str );
  7443. }
  7444. // escape LIKE condition wildcards
  7445. if ($like === TRUE) {
  7446. $str = str_replace ( array (
  7447. '%',
  7448. '_'
  7449. ), array (
  7450. '\\%',
  7451. '\\_'
  7452. ), $str );
  7453. }
  7454. return $str;
  7455. }
  7456. /**
  7457. * 获得分页数据
  7458. * @param unknown_type $table
  7459. * @param unknown_type $condition
  7460. * @param unknown_type $on_page
  7461. * @param unknown_type $page_size
  7462. */
  7463. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7464. $page_c = "";
  7465. $page ['previous'] = $this->get_previous ( $on_page );
  7466. $page ['on_page'] = $on_page;
  7467. $total_count = $this->get_table_count ( $table, $condition );
  7468. $total = intval ( $total_count / $page_size );
  7469. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7470. $page ['total_data'] = $total_count;
  7471. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7472. $i = 1;
  7473. $page_max = 1;
  7474. $page_width = 3;
  7475. if ($on_page >= $page_width) {
  7476. $page_max = intval ( $on_page / $page_width ) + 1;
  7477. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7478. }
  7479. for(; $i <= $page ['total_page']; $i ++) {
  7480. if ($i == $on_page)
  7481. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7482. else
  7483. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7484. if ($i == ($page_width * $page_max))
  7485. break;
  7486. }
  7487. $page ['page'] = $page_c;
  7488. $page ['lower'] = (-- $on_page) * $page_size;
  7489. return $page;
  7490. }
  7491. /**
  7492. * 获取上一页
  7493. * @param unknown_type $on_page
  7494. */
  7495. function get_previous($on_page = 1) {
  7496. return $on_page != 0 ? $on_page - 1 : $on_page;
  7497. }
  7498. /**
  7499. * 获取总页数
  7500. * @param unknown_type $table
  7501. * @param unknown_type $condition
  7502. */
  7503. public function get_table_count($table = "", $condition = "") {
  7504. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7505. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7506. // echo $sql;die;
  7507. $query = Doo::db ()->query ( $sql );
  7508. $result = $query->fetch ();
  7509. return $result ['count'];
  7510. }
  7511. function isInvoiceNew($type = "GLOBAL") {
  7512. Doo::loadModel ( 'invoice' );
  7513. $invoice = new invoice ();
  7514. Doo::loadModel ( 'invoiceReceivables' );
  7515. $invoiceReceivables = new invoiceReceivables ();
  7516. Doo::loadModel ( 'staff' );
  7517. $staff = new staff ();
  7518. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7519. // 我的发票待处理
  7520. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7521. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7522. 'desc' => 'iid',
  7523. 'asArray' => TRUE
  7524. ) );
  7525. // 我的收款待入账
  7526. /*
  7527. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7528. */
  7529. // 发票审批
  7530. $approval = $invoice->getOne ( array (
  7531. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7532. 'desc' => 'iid',
  7533. 'asArray' => true
  7534. ) );
  7535. // 发票邮寄
  7536. $post = $invoice->getOne ( array (
  7537. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7538. 'asArray' => TRUE
  7539. ) );
  7540. // 发票打印
  7541. $print = $invoice->getOne ( array (
  7542. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7543. 'desc' => 'iid',
  7544. 'asArray' => TRUE
  7545. ) );
  7546. // 发票退票 printStatus=1 and
  7547. $untread = $invoice->getOne ( array (
  7548. 'where' => " untreadStatus=1 and status=2 ",
  7549. 'asArray' => TRUE
  7550. ) );
  7551. $new = array (
  7552. 'GLOBAL' => FALSE,
  7553. 'pendingInvoice' => FALSE,
  7554. // 'myClaim' => FALSE,
  7555. 'approval' => FALSE,
  7556. 'post' => FALSE,
  7557. 'print' => FALSE,
  7558. 'untread' => FALSE
  7559. );
  7560. // || ! empty ( $myClaim )
  7561. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7562. $new ['GLOBAL'] = TRUE;
  7563. if (! empty ( $pendingInvoice ))
  7564. $new ['pendingInvoice'] = TRUE;
  7565. // if (! empty ( $myClaim ))
  7566. // $new ['myClaim'] = TRUE;
  7567. if (! empty ( $approval ))
  7568. $new ['approval'] = TRUE;
  7569. if (! empty ( $post ))
  7570. $new ['post'] = TRUE;
  7571. if (! empty ( $print ))
  7572. $new ['print'] = TRUE;
  7573. if (! empty ( $untread ))
  7574. $new ['untread'] = TRUE;
  7575. return $new;
  7576. }
  7577. function setWXMsg($rid, $typeMsg = '') {
  7578. Doo::loadModel ( 'invoice' );
  7579. $invoice = new invoice ();
  7580. $invoiceDetail = $invoice->getOne ( array (
  7581. 'where' => 'iid=' . $rid,
  7582. 'asArray' => true
  7583. ) );
  7584. if (! empty ( $invoiceDetail )) {
  7585. Doo::loadModel ( 'staff' );
  7586. $staff = new staff ();
  7587. $staffmsg = $staff->getOne ( array (
  7588. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7589. 'asArray' => TRUE
  7590. ) );
  7591. if (! empty ( $staffmsg ['wxid'] )) {
  7592. require_once (SITE_PATH . '/protected/class/client.php');
  7593. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7594. $user = $staffmsg ['wxid'];
  7595. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7596. if (empty ( $expCom ))
  7597. $expCom [0] = '';
  7598. $msg = "";
  7599. if (empty ( $typeMsg ))
  7600. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7601. elseif ($typeMsg == "PRINT")
  7602. $msg = '太好了,您的发票已打印完成。';
  7603. $result = $client->SendMsg ( $user, $msg, 'text' );
  7604. }
  7605. }
  7606. }
  7607. /**
  7608. * 获取微信部门
  7609. * @param string $category
  7610. * @return number|mixed
  7611. */
  7612. function getToparty($category = '') {
  7613. $token = $this->getAccessToken (); //
  7614. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7615. $toparty = 0;
  7616. foreach ( $result ['department'] as $key => $value ) {
  7617. if ($value ['name'] == $category)
  7618. $toparty = $value ['id'];
  7619. }
  7620. return $toparty;
  7621. }
  7622. /**
  7623. * 获得某部门下的用户
  7624. * @param string $toparty
  7625. */
  7626. function getUserByToparty($toparty = '') {
  7627. $token = $this->getAccessToken (); //
  7628. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7629. $userList = array ();
  7630. foreach ( $result ['userlist'] as $key => $value ) {
  7631. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7632. }
  7633. return $userList;
  7634. }
  7635. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7636. $token = $this->getAccessToken ();
  7637. if ($text == 'text') {
  7638. $data = '{
  7639. "touser": "' . $toparty . '",
  7640. "toparty": "",
  7641. "totag": "",
  7642. "msgtype": "text",
  7643. "agentid": 1000002,
  7644. "text": {
  7645. "content": "' . $msg . '"
  7646. },
  7647. "safe":0
  7648. }';
  7649. }
  7650. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7651. if ($result->errmsg != 'ok') {
  7652. return 0;
  7653. } else {
  7654. return 1;
  7655. }
  7656. }
  7657. /**
  7658. * 获得可以发送微信用户列表
  7659. * @param string $category
  7660. * @return string
  7661. */
  7662. function getWxidByCategory($category = "") {
  7663. if (empty ( $category ))
  7664. return "";
  7665. Doo::loadModel ( 'staff' );
  7666. $staff = new staff ();
  7667. $toparty = $this->getToparty ( $category );
  7668. $wxList = array ();
  7669. $wxString = "";
  7670. if (! empty ( $toparty )) {
  7671. $userList = $this->getUserByToparty ( $toparty );
  7672. $userCon = implode ( ',', $userList );
  7673. // echo $userCon;
  7674. $sidList = $staff->getStaffByWxid ( $userCon );
  7675. foreach ( $sidList as $key => $value ) {
  7676. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7677. if ($falg) {
  7678. array_push ( $wxList, $value ['wxid'] );
  7679. }
  7680. }
  7681. $wxString = implode ( '|', $wxList );
  7682. }
  7683. return $wxString;
  7684. }
  7685. /**
  7686. * 读取发送信息规则判断是否需要发送
  7687. * @param number $sid
  7688. * @param string $sendType
  7689. * @return boolean
  7690. */
  7691. function isSendNotification($sid = 0, $sendType = '') {
  7692. Doo::loadModel ( "notificationConf" );
  7693. $notificationConf = new notificationConf ();
  7694. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7695. $conf = array ();
  7696. $sendFlag = true;
  7697. if (! empty ( $detail )) {
  7698. $conf = json_decode ( $detail ['conf'], true );
  7699. if (! empty ( $sendType )) {
  7700. if (isset ( $conf [$sendType] )) {
  7701. if ($conf [$sendType] == "CLOSE")
  7702. $sendFlag = false;
  7703. elseif ($conf [$sendType] == "Weekend") {
  7704. $day = date ( "w" );
  7705. if (1 <= $day && 5 >= $day)
  7706. $sendFlag = false;
  7707. } elseif ($conf [$sendType] == "OneToFriday") {
  7708. $day = date ( "w" );
  7709. if (0 == $day || 6 == $day)
  7710. $sendFlag = false;
  7711. }
  7712. }
  7713. } else
  7714. $sendFlag = false;
  7715. }
  7716. return $sendFlag;
  7717. }
  7718. /**
  7719. * 根据规则发送信息
  7720. * @param unknown $msg
  7721. * @param unknown $title
  7722. * @param unknown $url
  7723. * @param unknown $user
  7724. * @param string $text
  7725. * @return number
  7726. */
  7727. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7728. $token = $this->getAccessToken ();
  7729. $falg = $this->isSendNotification ( $sid, $sendType );
  7730. // if ($text == 'text') {
  7731. // $data = '{
  7732. // "touser": "' . $user . '",
  7733. // "toparty": "",
  7734. // "totag": "",
  7735. // "msgtype": "text",
  7736. // "agentid": 1000002,
  7737. // "text": {
  7738. // "content": "' . $msg . '"
  7739. // },
  7740. // "safe":0
  7741. // }';
  7742. // } else {
  7743. $data = '{
  7744. "touser": "' . $user . '",
  7745. "toparty": "",
  7746. "totag": "",
  7747. "msgtype": "news",
  7748. "agentid": 1000002,
  7749. "news": {
  7750. "articles":[
  7751. {
  7752. "title": "' . $title . '",
  7753. "description": "' . $msg . '",
  7754. "url": "' . $url . '",
  7755. "picurl": ""
  7756. }
  7757. ]
  7758. }
  7759. }';
  7760. // }
  7761. if ($falg) {
  7762. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7763. if ($result->errmsg != 'ok') {
  7764. return 0;
  7765. } else {
  7766. return 1;
  7767. }
  7768. } else
  7769. return 0;
  7770. }
  7771. private function getAccessToken() {
  7772. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7773. // $file = './access_token.txt';
  7774. // $data = json_decode ( file_get_contents ( $file ) );
  7775. // if ($data->expire_time < time () or ! $data->expire_time) {
  7776. // 如果是企业号用以下URL获取access_token
  7777. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7778. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7779. $res = json_decode ( $this->httpGet ( $url ) );
  7780. $access_token = $res->access_token;
  7781. // echo $access_token;
  7782. // if ($access_token) {
  7783. // $data->expire_time = time () + 7000;
  7784. // $data->access_token = $access_token;
  7785. // $fp = fopen ( $file, "w" );
  7786. // fwrite ( $fp, json_encode ( $data ) );
  7787. // fclose ( $fp );
  7788. // }
  7789. // } else {
  7790. // $access_token = $data->access_token;
  7791. // }
  7792. return $access_token;
  7793. }
  7794. private function httpGet($url) {
  7795. $curl = curl_init ();
  7796. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7797. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7798. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7799. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7800. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7801. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7802. curl_setopt ( $curl, CURLOPT_URL, $url );
  7803. $res = curl_exec ( $curl );
  7804. curl_close ( $curl );
  7805. return $res;
  7806. }
  7807. private function httpPost($url, $data) {
  7808. $curl = curl_init ();
  7809. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7810. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7811. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7812. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7813. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7814. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7815. curl_setopt ( $curl, CURLOPT_URL, $url );
  7816. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7817. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7818. $res = curl_exec ( $curl );
  7819. curl_close ( $curl );
  7820. return $res;
  7821. }
  7822. }
  7823. ?>