InvoiceController.php 314 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. // 获得已退票功能
  203. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  204. $this->data ['untreadStatusList'] = $untreadStatusList;
  205. // print_r($untreadStatusList);
  206. $this->data ['isMonth'] = $isMonth;
  207. $this->data ['htm'] = $htm;
  208. $this->data ['invoiceList'] = $invoiceList;
  209. $this->data ['receivablesList'] = $list;
  210. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  211. $this->data ['memu'] = "invoice";
  212. $this->data ['staff'] = $this->staff;
  213. $this->data ['receiptMemu'] = 'invoice';
  214. $this->render ( "/admin/invoice", $this->data );
  215. }
  216. function invoiceExpress() {
  217. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  218. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  219. $this->data ['expressCom'] = $expressCom;
  220. $this->data ['expressNumber'] = $expressNumber;
  221. $this->render ( "/admin/invoiceExpress", $this->data );
  222. }
  223. function invoiceAdd() {
  224. session_start ();
  225. Doo::loadModel ( 'invoice' );
  226. $invoice = new invoice ();
  227. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  228. Doo::loadModel ( 'L_category' );
  229. $lCategory = new L_category ();
  230. $category = $lCategory->find ( array (
  231. 'asArray' => true
  232. ) );
  233. $this->data ['category'] = $category;
  234. Doo::loadModel ( 'invoiceTraining' );
  235. $invoiceTraining = new invoiceTraining ();
  236. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  237. Doo::loadModel ( 'receipt' );
  238. $receipt = new receipt ();
  239. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  240. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  241. if (! empty ( $receiptDetail )) {
  242. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  243. unset ( $itList [$key] );
  244. }
  245. }
  246. }
  247. $this->data ['itList'] = $itList;
  248. $token = $this->set_token ();
  249. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  250. $this->data ['token'] = $token;
  251. $this->data ['memu'] = "invoice";
  252. $this->data ['staff'] = $this->staff;
  253. $this->data ['receiptMemu'] = 'invoice';
  254. $this->render ( "/admin/invoiceAdd", $this->data );
  255. }
  256. /**
  257. * 自更新发票信息库
  258. * @param unknown $invoicePrintDetail
  259. */
  260. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  261. // 发票信息库
  262. Doo::loadModel ( 'invoiceInfoBase' );
  263. $invoiceInfoBase = new invoiceInfoBase ();
  264. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  265. $TIN = $invoicePrintDetail ['TIN'];
  266. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  267. if (empty ( $invoiceTitle ))
  268. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  269. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  270. // 确认有该条发票信息
  271. $invoiceInfoBase = new invoiceInfoBase ();
  272. if (! empty ( $IIBList )) {
  273. // 发票库里的信息数量
  274. $IIBListCount = count ( $IIBList );
  275. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  276. $item = array (
  277. 'iibID' => $IIBList [0] ['iibID'],
  278. 'invoiceTitle' => $invoiceTitle,
  279. 'TIN' => $TIN
  280. );
  281. if (! empty ( $invoicePrintDetail ['address'] )) {
  282. $item += array (
  283. 'address' => $invoicePrintDetail ['address']
  284. );
  285. }
  286. if (! empty ( $invoicePrintDetail ['phone'] )) {
  287. $item += array (
  288. 'phone' => $invoicePrintDetail ['phone']
  289. );
  290. }
  291. if (! empty ( $invoicePrintDetail ['bank'] )) {
  292. $item += array (
  293. 'bank' => $invoicePrintDetail ['bank']
  294. );
  295. }
  296. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  297. $item += array (
  298. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  299. );
  300. }
  301. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  302. $item += array (
  303. 'updateDate' => $invoicePrintDetail ['date']
  304. );
  305. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  306. }
  307. } else { // 删除多张发票,重新添加发票
  308. $iibIDStr = '';
  309. $iibID = array ();
  310. foreach ( $IIBList as $key => $value ) {
  311. array_push ( $iibID, $value ['iibID'] );
  312. }
  313. $iibIDStr = implode ( ",", $iibID ); // 删除
  314. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  315. $item = array (
  316. 'invoiceTitle' => $invoiceTitle,
  317. 'TIN' => $TIN,
  318. 'address' => $invoicePrintDetail ['address'],
  319. 'phone' => $invoicePrintDetail ['phone'],
  320. 'bank' => $invoicePrintDetail ['bank'],
  321. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  322. 'updateDate' => $invoicePrintDetail ['date']
  323. );
  324. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  325. }
  326. } else { // 没有新增发票信息
  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. }
  339. function invoiceAddFill() {
  340. session_start ();
  341. Doo::loadModel ( 'invoice' );
  342. $invoice = new invoice ();
  343. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  344. Doo::loadModel ( 'L_category' );
  345. $lCategory = new L_category ();
  346. $category = $lCategory->find ( array (
  347. 'asArray' => true
  348. ) );
  349. $this->data ['category'] = $category;
  350. Doo::loadModel ( 'invoiceTraining' );
  351. $invoiceTraining = new invoiceTraining ();
  352. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  353. $this->data ['itList'] = $itList;
  354. Doo::loadModel ( 'invoice' );
  355. $invoice = new invoice ();
  356. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  357. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  358. $token = $this->set_token ();
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data ['invoiceDetail'] = $detail;
  362. $this->data ['memu'] = "invoice";
  363. $this->data ['staff'] = $this->staff;
  364. $this->data ['receiptMemu'] = 'invoice';
  365. $this->render ( "/admin/invoiceAddFill", $this->data );
  366. }
  367. /**
  368. * 提交一份开票申请,并记录下操作日志
  369. *
  370. * @since 1.0.0
  371. * @var integer cid 办事处ID
  372. * @var integer invoiceType 发票类型
  373. * @var integer doPost 是否邮寄
  374. * @var integer invoicePrice 开票金额
  375. * @var string invoiceElement 开票内容
  376. * @var string invoiceTitle 发票抬头
  377. * @var string invoiceCompany 单位名称
  378. * @var string TIN 纳税人识别码
  379. * @var string address 注册地址
  380. * @var string phone 注册电话
  381. * @var string bank 开户银行
  382. * @var string bankAccount 银行账户
  383. * @var string recipients 收件人
  384. * @var string recipientsPhone 收件人手机/电话
  385. * @var string recipientsAddress 收件地址
  386. * @var string mailItems 邮寄物品
  387. * @var string remark 备注
  388. * @return string 返回跳转开票主页路径
  389. */
  390. function invoiceAddDo() {
  391. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  392. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  393. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  394. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  395. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  396. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  397. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  398. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  399. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  400. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  401. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  402. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  403. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  404. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  405. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  406. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  407. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  408. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  409. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  410. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  411. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  412. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  413. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  414. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  415. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  416. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  417. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  418. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  419. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  420. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  421. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  422. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  423. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  424. /*
  425. * $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;
  426. */
  427. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  428. if (empty ( $token )) {
  429. die ( 'illegal request-token' );
  430. } else {
  431. session_start ();
  432. if ($_SESSION ['token_' . $this->staff [0] ['sidKey']] != $token) {
  433. header ( 'Content-Type:text/html;charset=utf-8' );
  434. die ( '请勿重复申请发票' );
  435. } else {
  436. $_SESSION ['token_' . $this->staff [0] ['sidKey']] = '';
  437. }
  438. }
  439. if ($invoiceType == 1) {
  440. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  441. if ($temporary > 10000) {
  442. header ( 'Content-Type:text/html;charset=utf-8' );
  443. die ( '专用发票总金额暂时不能超过10000.00(一万)元。' );
  444. // die ( 'illegal request-Please priceError' );
  445. }
  446. }
  447. if (empty ( $this->staff [0] ))
  448. die ( 'illegal request-Please login' );
  449. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  450. Doo::loadModel ( 'invoice' );
  451. $invoice = new invoice ();
  452. Doo::loadModel ( 'L_category' );
  453. $lCategory = new L_category ();
  454. Doo::loadModel ( 'invoiceManage' );
  455. $invoiceManage = new invoiceManage ();
  456. Doo::loadModel ( 'invoiceOperationLog' );
  457. $invoiceOperationLog = new invoiceOperationLog ();
  458. Doo::loadClass ( 'XDeode' );
  459. $XDeode = new XDeode ( 5 );
  460. $trainId = $XDeode->decode ( $trainId );
  461. $categoryDetil = $lCategory->getOne ( array (
  462. 'SELECT' => 'title',
  463. 'where' => 'cid=' . $cid,
  464. 'asArray' => true
  465. ) );
  466. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  467. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  468. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  469. // print_r(current($invoiceManageDetail ['staffList']));
  470. // die;
  471. $moldManage = array ();
  472. foreach ( $invoiceManageList as $key => $value ) {
  473. if ($value ['mold'] == '发票打印')
  474. $moldManage [$value ['mold']] = $value ['staffList'];
  475. elseif ($value ['mold'] == '发票邮寄')
  476. $moldManage [$value ['mold']] = $value ['staffList'];
  477. elseif ($value ['mold'] == '发票退票')
  478. $moldManage [$value ['mold']] = $value ['staffList'];
  479. }
  480. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  481. $st = '';
  482. if ($settlementType == 'SOFTWARE') {
  483. $st = 0;
  484. $trainId = 0;
  485. } elseif ($settlementType == 'TRAINING') {
  486. $st = 1;
  487. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  488. die ( 'illegal request-trainingIdError' );
  489. }
  490. } else {
  491. die ( 'illegal request-settlementError' );
  492. }
  493. $item = array (
  494. 'cid' => $cid,
  495. 'categoryName' => $categoryDetil ['title'],
  496. 'invoiceElement' => $invoiceElement,
  497. 'invoiceQuantity' => $invoiceQuantity,
  498. 'invoiceUnitPrice' => $invoiceUnitPrice,
  499. 'invoicePrice' => $invoicePrice,
  500. 'invoiceType' => $invoiceType,
  501. 'settlementType' => $st,
  502. 'doPost' => $doPost,
  503. 'status' => 1,
  504. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  505. 'date' => date ( "Y-m-d H:i:s" ),
  506. 'updateTime' => date ( "Y-m-d H:i:s" ),
  507. 'sid' => $this->staff [0] ['sid'],
  508. 'userName' => $this->staff [0] ['username'],
  509. 'invoiceManage' => $invoiceManageDetail ['staff'],
  510. 'pendingApprovals' => $pendingApprovalsSid,
  511. 'moldManage' => json_encode ( $moldManage ),
  512. 'remark' => $remark,
  513. 'trainId' => $trainId
  514. );
  515. if ($invoiceType == 0)
  516. $item += array (
  517. 'invoiceTitle' => $invoiceTitle,
  518. 'TIN' => $TINT,
  519. 'address' => $addressT,
  520. 'phone' => $phoneT,
  521. 'bank' => $bankT,
  522. 'bankAccount' => $bankAccountT
  523. );
  524. else {
  525. $item += array (
  526. 'invoiceCompany' => $invoiceCompany,
  527. 'TIN' => $TIN,
  528. 'address' => $address,
  529. 'phone' => $phone,
  530. 'bank' => $bank,
  531. 'bankAccount' => $bankAccount
  532. );
  533. }
  534. if ($doPost == 1) {
  535. $mailList = array (
  536. 'invoice' => 1,
  537. 'mailItems' => $mailItems
  538. );
  539. if (! empty ( $softLock ))
  540. $mailList += array (
  541. 'softLock' => $softLockNum
  542. );
  543. else
  544. $mailList += array (
  545. 'softLock' => 0
  546. );
  547. if (! empty ( $contract ))
  548. $mailList += array (
  549. 'contract' => $contractNum
  550. );
  551. else
  552. $mailList += array (
  553. 'contract' => 0
  554. );
  555. if (! empty ( $instructions ))
  556. $mailList += array (
  557. 'instructions' => $instructionsNum
  558. );
  559. else
  560. $mailList += array (
  561. 'instructions' => 0
  562. );
  563. if (! empty ( $remittance ))
  564. $mailList += array (
  565. 'remittance' => $remittance
  566. );
  567. else
  568. $mailList += array (
  569. 'remittance' => ''
  570. );
  571. $mailString = '发票x1张,备注:' . $mailItems;
  572. if (! empty ( $softLock ))
  573. $mailString .= ',软件锁x' . $softLockNum . '个';
  574. if (! empty ( $contract ))
  575. $mailString .= ',合同x' . $contractNum . '份';
  576. if (! empty ( $instructions ))
  577. $mailString .= ',说明书x' . $instructionsNum . '本';
  578. if (! empty ( $remittance ))
  579. $mailString .= ',汇款账号单(张)';
  580. $item += array (
  581. 'recipients' => $recipients,
  582. 'recipientsPhone' => $recipientsPhone,
  583. 'recipientsAddress' => $recipientsAddress,
  584. 'mailItems' => $mailString,
  585. 'mailItemsJson' => json_encode ( $mailList )
  586. );
  587. }
  588. $iid = $invoice->addInvoice ( $item );
  589. // 如果是培训班结算 创建培训班发票到培训班备份中
  590. if (! empty ( $st ) && $st == 1) {
  591. Doo::loadModel ( 'invoiceStore' );
  592. $invoiceStore = new invoiceStore ();
  593. Doo::loadModel ( 'invoiceTraining' );
  594. $invoiceTraining = new invoiceTraining ();
  595. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  596. $itemIS = array (
  597. 'isid' => $isid,
  598. 'ipSource' => 1,
  599. 'apStatus' => 1,
  600. 'iid' => $iid
  601. );
  602. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  603. // 更新培训班总数量
  604. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  605. $item = array (
  606. 'itid' => $trainId,
  607. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  608. 'submitStatus' => 1
  609. );
  610. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  611. }
  612. // 操作日志
  613. $item = array (
  614. 'date' => date ( "Y-m-d H:i:s" ),
  615. 'operation' => "创建",
  616. 'status' => 1,
  617. 'img' => $this->staff [0] ['avatar'],
  618. 'username' => $this->staff [0] ['username'],
  619. 'uid' => $this->staff [0] ['sid'],
  620. 'category' => $this->staff [0] ['category'],
  621. 'iid' => $iid
  622. );
  623. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  624. $item = array (
  625. 'date' => date ( "Y-m-d H:i:s" ),
  626. 'operation' => "提交审批",
  627. 'status' => 1,
  628. 'img' => $this->staff [0] ['avatar'],
  629. 'username' => $this->staff [0] ['username'],
  630. 'uid' => $this->staff [0] ['sid'],
  631. 'category' => $this->staff [0] ['category'],
  632. 'iid' => $iid
  633. );
  634. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  635. Doo::loadModel ( 'staff' );
  636. $staff = new staff ();
  637. $username2 = $staff->getOne ( array (
  638. 'select' => 'wxid',
  639. 'where' => 'sid=' . $pendingApprovalsSid,
  640. 'asArray' => TRUE
  641. ) );
  642. // 发送微信审批通知
  643. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  644. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  645. }
  646. return "/invoice";
  647. }
  648. function invoiceEdit() {
  649. Doo::loadClass ( 'XDeode' );
  650. $XDeode = new XDeode ( 5 );
  651. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  652. $iid = $XDeode->decode ( $iid );
  653. if (! is_numeric ( $iid ))
  654. die ( 'illegal request' );
  655. Doo::loadModel ( 'invoice' );
  656. $invoice = new invoice ();
  657. Doo::loadModel ( 'invoiceOperationLog' );
  658. $invoiceOperationLog = new invoiceOperationLog ();
  659. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  660. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  661. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  662. $this->data ['operation'] = $operation;
  663. $this->data ['invoiceDetail'] = $invoiceDetail;
  664. $this->data ['memu'] = "invoice";
  665. $this->data ['staff'] = $this->staff;
  666. $this->data ['receiptMemu'] = 'invoice';
  667. $this->render ( "/admin/invoiceEdit", $this->data );
  668. }
  669. /**
  670. * 重新编辑退回的发票
  671. * @return string
  672. */
  673. function invoiceEditDo() {
  674. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  675. Doo::loadModel ( 'invoice' );
  676. $invoice = new invoice ();
  677. $iid = $invoice->authcode ( $iidKey );
  678. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  679. die ( 'illegal request' );
  680. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  681. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  682. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  683. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  684. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  685. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  686. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  687. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  688. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  689. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  690. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  691. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  692. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  693. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  694. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  695. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  696. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  697. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  698. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  699. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  700. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  701. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  702. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  703. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  704. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  705. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  706. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  707. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  708. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  709. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  710. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  711. if ($invoiceType == 1) {
  712. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  713. if ($temporary > 10000)
  714. die ( 'illegal request-Please priceError' );
  715. }
  716. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  717. Doo::loadModel ( 'invoiceManage' );
  718. $invoiceManage = new invoiceManage ();
  719. Doo::loadModel ( 'invoiceOperationLog' );
  720. $invoiceOperationLog = new invoiceOperationLog ();
  721. Doo::loadModel ( 'invoiceStore' );
  722. $invoiceStore = new invoiceStore ();
  723. $cid = explode ( ':', $cid );
  724. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  725. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  726. $moldManage = array ();
  727. foreach ( $invoiceManageList as $key => $value ) {
  728. if ($value ['mold'] == '发票打印')
  729. $moldManage [$value ['mold']] = $value ['staffList'];
  730. elseif ($value ['mold'] == '发票邮寄')
  731. $moldManage [$value ['mold']] = $value ['staffList'];
  732. elseif ($value ['mold'] == '发票打印')
  733. $moldManage [$value ['mold']] = $value ['staffList'];
  734. }
  735. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  736. $item = array (
  737. 'iid' => $iid,
  738. 'cid' => $cid [0],
  739. 'categoryName' => $cid [1],
  740. 'invoiceElement' => $invoiceElement,
  741. 'invoiceQuantity' => $invoiceQuantity,
  742. 'invoiceUnitPrice' => $invoiceUnitPrice,
  743. 'invoicePrice' => $invoicePrice,
  744. 'invoiceType' => $invoiceType,
  745. 'doPost' => $doPost,
  746. 'status' => 1,
  747. 'updateTime' => date ( "Y-m-d H:i:s" ),
  748. 'remark' => $remark
  749. );
  750. if ($invoiceType == 0)
  751. $item += array (
  752. 'invoiceTitle' => $invoiceTitle,
  753. 'TIN' => $TINT,
  754. 'address' => $addressT,
  755. 'phone' => $phoneT,
  756. 'bank' => $bankT,
  757. 'bankAccount' => $bankAccountT
  758. );
  759. else {
  760. $item += array (
  761. 'invoiceCompany' => $invoiceCompany,
  762. 'TIN' => $TIN,
  763. 'address' => $address,
  764. 'phone' => $phone,
  765. 'bank' => $bank,
  766. 'bankAccount' => $bankAccount
  767. );
  768. }
  769. if ($doPost == 1) {
  770. $mailList = array (
  771. 'invoice' => 1,
  772. 'mailItems' => $mailItems
  773. );
  774. if (! empty ( $softLock ))
  775. $mailList += array (
  776. 'softLock' => $softLockNum
  777. );
  778. else
  779. $mailList += array (
  780. 'softLock' => '0'
  781. );
  782. if (! empty ( $contract ))
  783. $mailList += array (
  784. 'contract' => $contractNum
  785. );
  786. else
  787. $mailList += array (
  788. 'contract' => '0'
  789. );
  790. if (! empty ( $instructions ))
  791. $mailList += array (
  792. 'instructions' => $instructionsNum
  793. );
  794. else
  795. $mailList += array (
  796. 'instructions' => '0'
  797. );
  798. if (! empty ( $remittance ))
  799. $mailList += array (
  800. 'remittance' => $remittance
  801. );
  802. else
  803. $mailList += array (
  804. 'remittance' => ''
  805. );
  806. $mailString = '发票x1,备注:' . $mailItems;
  807. if (! empty ( $softLock ))
  808. $mailString .= ',软件锁x' . $softLockNum;
  809. if (! empty ( $contract ))
  810. $mailString .= ',合同x' . $contractNum;
  811. if (! empty ( $instructions ))
  812. $mailString .= ',说明书x' . $instructionsNum;
  813. if (! empty ( $remittance ))
  814. $mailString .= ',汇款账号单';
  815. $item += array (
  816. 'recipients' => $recipients,
  817. 'recipientsPhone' => $recipientsPhone,
  818. 'recipientsAddress' => $recipientsAddress,
  819. 'mailItems' => $mailString,
  820. 'mailItemsJson' => json_encode ( $mailList )
  821. );
  822. }
  823. $invoice->setInvoiceByCondition ( $item );
  824. // 更新培训班仓库里的发票
  825. $detail = $invoice->getInvoiceByIid ( $iid );
  826. if (! empty ( $detail ['isid'] )) {
  827. $invoiceStore->isid = $detail ['isid'];
  828. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  829. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  830. $invoiceStore->invoicePrice = $invoicePrice;
  831. $invoiceStore->update ();
  832. }
  833. $item = array (
  834. 'date' => date ( "Y-m-d H:i:s" ),
  835. 'operation' => "重新提交审批",
  836. 'status' => 1,
  837. 'img' => $this->staff [0] ['avatar'],
  838. 'username' => $this->staff [0] ['username'],
  839. 'uid' => $this->staff [0] ['sid'],
  840. 'category' => $this->staff [0] ['category'],
  841. 'iid' => $iid
  842. );
  843. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  844. }
  845. return "/invoice";
  846. }
  847. /**
  848. * 培训班
  849. */
  850. function invoiceTraining() {
  851. Doo::loadModel ( 'L_category' );
  852. $lCategory = new L_category ();
  853. Doo::loadModel ( 'invoiceTraining' );
  854. $invoiceTraining = new invoiceTraining ();
  855. Doo::loadModel ( 'invoiceTrainManage' );
  856. $invoiceTrainManage = new invoiceTrainManage ();
  857. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  858. $cidList = array ();
  859. foreach ( $imcStaff as $key => $value ) {
  860. array_push ( $cidList, $value ['cid'] );
  861. }
  862. if (empty ( $cidList )) {
  863. $cidString = $this->staff [0] ['cid'];
  864. } else {
  865. $cidString = implode ( ',', $cidList );
  866. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  867. }
  868. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  869. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  870. $category = $lCategory->getCategory ();
  871. $itid = array ();
  872. foreach ( $itTodoList as $key => $value ) {
  873. array_push ( $itid, $value ['itid'] );
  874. // 如果入账100%更新为已完成
  875. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  876. $invoiceTraining = new invoiceTraining ();
  877. $invoiceTraining->itid = $value ['itid'];
  878. $invoiceTraining->status = 2;
  879. $invoiceTraining->update ();
  880. }
  881. }
  882. foreach ( $itedList as $value ) {
  883. array_push ( $itid, $value ['itid'] );
  884. }
  885. $itid = implode ( ',', $itid );
  886. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  887. // print_r($itTodoList);
  888. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  889. $this->data ['itTodoList'] = $itTodoList;
  890. $this->data ['itedList'] = $itedList;
  891. $this->data ['category'] = $category;
  892. $this->data ['memu'] = "invoice";
  893. $this->data ['staff'] = $this->staff;
  894. $this->data ['receiptMemu'] = 'invoiceTraining';
  895. $this->render ( "/admin/invoiceTraining", $this->data );
  896. }
  897. /**
  898. * 创建培训班
  899. */
  900. function invoiceTrainingAdd() {
  901. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  902. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  903. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  904. if (empty ( $this->staff [0] ))
  905. die ( 'illegal request' );
  906. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  907. Doo::loadModel ( 'invoiceTraining' );
  908. $invoiceTraining = new invoiceTraining ();
  909. Doo::loadModel ( 'invoice' );
  910. $invoice = new invoice ();
  911. Doo::loadModel ( 'L_category' );
  912. $lCategory = new L_category ();
  913. Doo::loadModel ( 'invoiceManage' );
  914. $invoiceManage = new invoiceManage ();
  915. Doo::loadModel ( 'invoiceOperationLog' );
  916. $invoiceOperationLog = new invoiceOperationLog ();
  917. $item = array (
  918. 'cid' => $cid,
  919. 'trainName' => $trainName,
  920. 'trainDate' => $trainDate,
  921. 'creator' => $this->staff [0] ['sid'],
  922. 'creatorDate' => date ( "Y-m-d H:i:s" )
  923. );
  924. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  925. }
  926. return "/invoiceTraining";
  927. }
  928. /**
  929. * 删除培训班
  930. */
  931. function invoiceTrainingDelDo() {
  932. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  933. if (! empty ( $itid )) {
  934. Doo::loadModel ( 'invoiceTraining' );
  935. $invoiceTraining = new invoiceTraining ();
  936. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  937. }
  938. return "/invoiceTraining";
  939. }
  940. /**
  941. * 培训班详情
  942. */
  943. function invoiceTrainingDetail() {
  944. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  945. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  946. Doo::loadModel ( 'invoiceTraining' );
  947. $invoiceTraining = new invoiceTraining ();
  948. Doo::loadModel ( 'invoiceStore' );
  949. $invoiceStore = new invoiceStore ();
  950. if (empty ( $itid ))
  951. die ( 'illegal request' );
  952. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  953. if ($trainStatus == "SUBED")
  954. $con = ' (b.untreadStatus is null ) and ';
  955. elseif ($trainStatus == "APPROVAL")
  956. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  957. elseif ($trainStatus == "TICKET")
  958. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  959. elseif ($trainStatus == "TICKETING") {
  960. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  961. }
  962. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  963. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  964. //print_r($isList);
  965. $trainlist = array ();
  966. foreach ( $isList as $key => $value ) {
  967. $irDetail = array ();
  968. if ($value ['apStatus'] == 1) {
  969. // array_push ( $irDetail, '' );
  970. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  971. } else {
  972. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  973. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  974. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  975. }
  976. array_push ( $irDetail, $value ['invoiceSerial'] );
  977. if ($value ['invoiceType'] == 1)
  978. array_push ( $irDetail, $value ['invoiceCompany'] );
  979. else
  980. array_push ( $irDetail, $value ['invoiceTitle'] );
  981. array_push ( $irDetail, $value ['TIN'] );
  982. array_push ( $irDetail, $value ['userName'] );
  983. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  984. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  985. } else
  986. array_push ( $irDetail, $value ['mailItems'] );
  987. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  988. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  989. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  990. array_push ( $irDetail, $value ['invoiceElement'] );
  991. array_push ( $irDetail, $value ['invoiceQuantity'] );
  992. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  993. if ($value ['invoiceType'] == 1)
  994. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  995. else
  996. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  997. array_push ( $irDetail, $value ['remark'] );
  998. if ($value ['status'] == 1)
  999. array_push ( $irDetail, '审批中' );
  1000. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1001. array_push ( $irDetail, '已出票' );
  1002. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1003. array_push ( $irDetail, '已入账' );
  1004. else
  1005. array_push ( $irDetail, '' );
  1006. array_push ( $irDetail, $value ['invoiceNo'] );
  1007. array_push ( $irDetail, $value ['printTime'] );
  1008. $html = '';
  1009. foreach ( $value ['invoiceReceivables'] as $value ) {
  1010. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1011. }
  1012. array_push ( $irDetail, $html );
  1013. array_push ( $trainlist, $irDetail );
  1014. }
  1015. $trainlistJson = json_encode ( $trainlist );
  1016. if (empty ( $detail ))
  1017. die ( 'illegal request' );
  1018. // 培训班结算是否有和是否已经结算完成
  1019. Doo::loadModel ( 'receipt' );
  1020. $receipt = new receipt ();
  1021. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1022. $this->data ['receiptDetail'] = $receiptDetail;
  1023. $this->data ['trainStatus'] = $trainStatus;
  1024. $this->data ['itid'] = $itid;
  1025. $this->data ['trainlistJson'] = $trainlistJson;
  1026. $this->data ['iTrainDetail'] = $detail;
  1027. $this->data ['memu'] = "invoice";
  1028. $this->data ['staff'] = $this->staff;
  1029. $this->data ['receiptMemu'] = 'invoiceTraining';
  1030. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1031. }
  1032. /**
  1033. * 上传培训班发票
  1034. * @return string
  1035. */
  1036. function invoiceTrainingUpload() {
  1037. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1038. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1039. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1040. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1041. header ( "HTTP/1.1 500 Internal Server Error" );
  1042. echo "POST exceeded maximum allowed size.";
  1043. exit ( 0 );
  1044. }
  1045. // Settings
  1046. $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)
  1047. $upload_name = "Filedata";
  1048. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1049. $extension_whitelist = array (
  1050. "doc",
  1051. "txt",
  1052. "jpg",
  1053. "gif",
  1054. "png"
  1055. ); // Allowed file extensions
  1056. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1057. // Other variables
  1058. $MAX_FILENAME_LENGTH = 260;
  1059. $file_name = "";
  1060. $file_extension = "";
  1061. $uploadErrors = array (
  1062. 0 => "文件上传成功",
  1063. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1064. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1065. 3 => "上传的文件仅为部分文件",
  1066. 4 => "没有文件上传",
  1067. 6 => "缺少临时文件夹"
  1068. );
  1069. $nk = time ();
  1070. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1071. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1072. echo "文件无法保存.";
  1073. exit ( 0 );
  1074. }
  1075. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1076. echo json_encode ( array (
  1077. 'filename' => $file_name,
  1078. 'id' => $nk
  1079. ) );
  1080. exit ( 0 );
  1081. }
  1082. /**
  1083. * 导入发票临时仓库
  1084. */
  1085. function invoiceStoreImport() {
  1086. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1087. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1088. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1089. if ($path != "" && ! empty ( $trainingKey )) {
  1090. Doo::loadModel ( 'invoiceStore' );
  1091. Doo::loadModel ( 'staff' );
  1092. $staff = new staff ();
  1093. Doo::loadModel ( 'invoiceTraining' );
  1094. $invoiceTraining = new invoiceTraining ();
  1095. Doo::loadClass ( 'XDeode' );
  1096. $XDeode = new XDeode ( 5 );
  1097. $itid = $XDeode->decode ( $trainingKey );
  1098. // 培训班结算是否有和是否已经结算完成
  1099. Doo::loadModel ( 'receipt' );
  1100. $receipt = new receipt ();
  1101. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1102. if (! empty ( $receiptDetail )) {
  1103. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1104. die ( 'illegal request--status' );
  1105. }
  1106. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1107. $userName = $this->staff [0] ['username'];
  1108. $sDetail = $staff->getStaffByName ( $userName );
  1109. // die('sdd');
  1110. // 可以优化
  1111. foreach ( $exlArray as $key => $value ) {
  1112. // 开票
  1113. $invoice = new invoiceStore ();
  1114. $invoice->trainId = $itid;
  1115. $invoice->invoiceType = 0;
  1116. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1117. $invoice->invoiceType = 1;
  1118. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1119. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1120. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1121. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1122. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1123. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1124. $invoice->userName = $userName;
  1125. $invoice->sid = $sDetail ['sid'];
  1126. $invoice->cid = $sDetail ['cid'];
  1127. $invoice->categoryName = $sDetail ['category'];
  1128. $invoice->invoiceElement = $value ['invoiceElement'];
  1129. $invoice->remark = $value ['remark'];
  1130. // $invoice->date = $value ['date'];
  1131. // $invoice->printTime = $value ['date'];
  1132. $invoice->ipSource = 1;
  1133. $invoice->printStatus = 0;
  1134. $invoice->status = 0;
  1135. $invoice->postStatus = 1;
  1136. $invoice->untreadStatus = 0;
  1137. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1138. $invoice->TIN = $value ['TIN'];
  1139. $invoice->address = $value ['address'];
  1140. $invoice->phone = $value ['phone'];
  1141. $invoice->bank = $value ['bank'];
  1142. $invoice->bankAccount = $value ['bankAccount'];
  1143. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1144. $invoice->recipients = $value ['recipients'];
  1145. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1146. $iid = $invoice->insert ();
  1147. }
  1148. // 加入发票总数量
  1149. $item = array (
  1150. 'itid' => $itid,
  1151. 'invoiceTotal' => count ( $exlArray )
  1152. );
  1153. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1154. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1155. }
  1156. echo 'no file';
  1157. }
  1158. /**
  1159. * 编辑仓库里的发票
  1160. */
  1161. function invoiceStoreEdit() {
  1162. Doo::loadClass ( 'XDeode' );
  1163. $XDeode = new XDeode ( 5 );
  1164. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1165. $iid = $XDeode->decode ( $iid );
  1166. if (! is_numeric ( $iid ))
  1167. die ( 'illegal request' );
  1168. Doo::loadModel ( 'invoiceStore' );
  1169. $invoiceStore = new invoiceStore ();
  1170. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1171. // print_r($invoiceDetail);
  1172. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1173. $this->data ['invoiceDetail'] = $invoiceDetail;
  1174. $this->data ['memu'] = "invoice";
  1175. $this->data ['staff'] = $this->staff;
  1176. $this->data ['receiptMemu'] = 'invoiceTraining';
  1177. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1178. }
  1179. function invoiceStoreEditDo() {
  1180. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1181. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1182. Doo::loadModel ( 'invoiceStore' );
  1183. $invoice = new invoiceStore ();
  1184. Doo::loadClass ( 'XDeode' );
  1185. $XDeode = new XDeode ( 5 );
  1186. $iid = $XDeode->decode ( $storeKey );
  1187. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1188. die ( 'illegal request' );
  1189. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1190. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1191. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1192. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1193. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1194. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1195. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1196. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1197. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1198. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1199. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1200. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1201. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1202. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1203. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1204. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1205. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1206. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1207. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1208. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1209. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1210. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1211. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1212. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1213. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1214. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1215. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1216. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1217. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1218. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1219. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1220. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1221. $cid = explode ( ':', $cid );
  1222. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1223. $item = array (
  1224. 'isid' => $iid,
  1225. 'cid' => $cid [0],
  1226. 'categoryName' => $cid [1],
  1227. 'invoiceElement' => $invoiceElement,
  1228. 'invoiceQuantity' => $invoiceQuantity,
  1229. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1230. 'invoicePrice' => $invoicePrice,
  1231. 'invoiceType' => $invoiceType,
  1232. 'doPost' => $doPost,
  1233. 'status' => 1,
  1234. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1235. 'remark' => $remark
  1236. );
  1237. if ($invoiceType == 0)
  1238. $item += array (
  1239. 'invoiceTitle' => $invoiceTitle,
  1240. 'TIN' => $TINT,
  1241. 'address' => $addressT,
  1242. 'phone' => $phoneT,
  1243. 'bank' => $bankT,
  1244. 'bankAccount' => $bankAccountT
  1245. );
  1246. else {
  1247. $item += array (
  1248. 'invoiceCompany' => $invoiceCompany,
  1249. 'TIN' => $TIN,
  1250. 'address' => $address,
  1251. 'phone' => $phone,
  1252. 'bank' => $bank,
  1253. 'bankAccount' => $bankAccount
  1254. );
  1255. }
  1256. if ($doPost == 1) {
  1257. $mailList = array (
  1258. 'invoice' => 1,
  1259. 'mailItems' => $mailItems
  1260. );
  1261. if (! empty ( $softLock ))
  1262. $mailList += array (
  1263. 'softLock' => $softLockNum
  1264. );
  1265. else
  1266. $mailList += array (
  1267. 'softLock' => '0'
  1268. );
  1269. if (! empty ( $contract ))
  1270. $mailList += array (
  1271. 'contract' => $contractNum
  1272. );
  1273. else
  1274. $mailList += array (
  1275. 'contract' => '0'
  1276. );
  1277. if (! empty ( $instructions ))
  1278. $mailList += array (
  1279. 'instructions' => $instructionsNum
  1280. );
  1281. else
  1282. $mailList += array (
  1283. 'instructions' => '0'
  1284. );
  1285. if (! empty ( $remittance ))
  1286. $mailList += array (
  1287. 'remittance' => $remittance
  1288. );
  1289. else
  1290. $mailList += array (
  1291. 'remittance' => ''
  1292. );
  1293. $mailString = '发票x1,备注:' . $mailItems;
  1294. if (! empty ( $softLock ))
  1295. $mailString .= ',软件锁x' . $softLockNum;
  1296. if (! empty ( $contract ))
  1297. $mailString .= ',合同x' . $contractNum;
  1298. if (! empty ( $instructions ))
  1299. $mailString .= ',说明书x' . $instructionsNum;
  1300. if (! empty ( $remittance ))
  1301. $mailString .= ',汇款账号单';
  1302. $item += array (
  1303. 'recipients' => $recipients,
  1304. 'recipientsPhone' => $recipientsPhone,
  1305. 'recipientsAddress' => $recipientsAddress,
  1306. 'mailItems' => $mailString,
  1307. 'mailItemsJson' => json_encode ( $mailList )
  1308. );
  1309. }
  1310. $invoice->setInvoiceStoreByCondition ( $item );
  1311. }
  1312. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1313. }
  1314. /**
  1315. *
  1316. * @return string
  1317. */
  1318. function invoiceStoreDelete() {
  1319. Doo::loadClass ( 'XDeode' );
  1320. $XDeode = new XDeode ( 5 );
  1321. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1322. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1323. $isid = $XDeode->decode ( $iStoreKey );
  1324. $itid = $XDeode->decode ( $trainKey );
  1325. if (! is_numeric ( $isid ))
  1326. die ( 'illegal request' );
  1327. Doo::loadModel ( 'invoiceStore' );
  1328. $invoiceStore = new invoiceStore ();
  1329. $invoiceStore->delete ( array (
  1330. 'where' => 'isid=' . $isid,
  1331. 'limit' => 1
  1332. ) );
  1333. Doo::loadModel ( 'invoiceTraining' );
  1334. $invoiceTraining = new invoiceTraining ();
  1335. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1336. $item = array (
  1337. 'itid' => $itid,
  1338. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1339. );
  1340. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1341. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1342. }
  1343. /**
  1344. * 批量删除库里发票
  1345. */
  1346. function invoiceStoreBatchDelete() {
  1347. Doo::loadClass ( 'XDeode' );
  1348. $XDeode = new XDeode ( 5 );
  1349. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1350. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1351. if (empty ( $trainKey ) || empty ( $storeKey ))
  1352. die ( 'illegal request-IdKey' );
  1353. $tid = $XDeode->decode ( $trainKey );
  1354. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1355. die ( 'illegal request' );
  1356. Doo::loadModel ( 'invoiceStore' );
  1357. $isidKeyList = explode ( ',', $storeKey );
  1358. $isidList = array ();
  1359. foreach ( $isidKeyList as $value ) {
  1360. $isid = $XDeode->decode ( $value );
  1361. if (! empty ( $isid ) && is_numeric ( $isid ))
  1362. array_push ( $isidList, $isid );
  1363. }
  1364. $isidString = implode ( ',', $isidList );
  1365. $invoiceStore = new invoiceStore ();
  1366. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1367. $isidList = array ();
  1368. foreach ( $isList as $key => $value ) {
  1369. if ($value ['apStatus'] == 0)
  1370. array_push ( $isidList, $value ['isid'] );
  1371. }
  1372. $isidString = implode ( ',', $isidList );
  1373. // print_r($isList);
  1374. // echo $isidString;
  1375. $invoiceStore = new invoiceStore ();
  1376. $invoiceStore->delete ( array (
  1377. 'where' => "isid in ( " . $isidString . ")",
  1378. 'asArray' => TRUE
  1379. ) );
  1380. Doo::loadModel ( 'invoiceTraining' );
  1381. $invoiceTraining = new invoiceTraining ();
  1382. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1383. $item = array (
  1384. 'itid' => $tid,
  1385. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1386. );
  1387. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1388. // echo $tid;
  1389. // echo $storeKey;
  1390. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1391. }
  1392. /**
  1393. * 仓库发票提交审批
  1394. * @return string
  1395. */
  1396. function invoiceStoreApproval() {
  1397. Doo::loadClass ( 'XDeode' );
  1398. $XDeode = new XDeode ( 5 );
  1399. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1400. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1401. $isid = $XDeode->decode ( $iStoreKey );
  1402. $trainId = $XDeode->decode ( $trainKey );
  1403. if (! is_numeric ( $isid ))
  1404. die ( 'illegal request' );
  1405. Doo::loadModel ( 'invoiceStore' );
  1406. Doo::loadModel ( 'invoice' );
  1407. $invoice = new invoice ();
  1408. // 加入限制必须填写入开票内容和邮寄物品
  1409. $invoiceStore = new invoiceStore ();
  1410. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1411. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1412. header ( 'Content-Type:text/html;charset=utf-8' );
  1413. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1414. }
  1415. // 拷贝插入一条发票数据
  1416. $invoiceStore = new invoiceStore ();
  1417. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1418. $invoiceStore = new invoiceStore ();
  1419. $item = array (
  1420. 'isid' => $isid,
  1421. 'iid' => $iid,
  1422. 'apStatus' => 1
  1423. );
  1424. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1425. Doo::loadModel ( 'invoiceManage' );
  1426. $invoiceManage = new invoiceManage ();
  1427. Doo::loadModel ( 'invoiceOperationLog' );
  1428. $invoiceOperationLog = new invoiceOperationLog ();
  1429. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1430. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1431. $moldManage = array ();
  1432. foreach ( $invoiceManageList as $key => $value ) {
  1433. if ($value ['mold'] == '发票打印')
  1434. $moldManage [$value ['mold']] = $value ['staffList'];
  1435. elseif ($value ['mold'] == '发票邮寄')
  1436. $moldManage [$value ['mold']] = $value ['staffList'];
  1437. elseif ($value ['mold'] == '发票退票')
  1438. $moldManage [$value ['mold']] = $value ['staffList'];
  1439. }
  1440. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1441. $item = array (
  1442. 'iid' => $iid,
  1443. 'isid' => $isid,
  1444. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1445. 'date' => date ( "Y-m-d H:i:s" ),
  1446. 'status' => 1,
  1447. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1448. 'trainId' => $trainId,
  1449. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1450. 'moldManage' => json_encode ( $moldManage ),
  1451. 'settlementType' => 1,
  1452. 'pendingApprovals' => $pendingApprovalsSid
  1453. );
  1454. $invoice->setInvoiceByCondition ( $item );
  1455. Doo::loadModel ( 'invoiceTraining' );
  1456. $invoiceTraining = new invoiceTraining ();
  1457. $item = array (
  1458. 'itid' => $trainId,
  1459. 'submitStatus' => 1
  1460. );
  1461. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1462. $item = array (
  1463. 'date' => date ( "Y-m-d H:i:s" ),
  1464. 'operation' => "创建",
  1465. 'status' => 1,
  1466. 'img' => $this->staff [0] ['avatar'],
  1467. 'username' => $this->staff [0] ['username'],
  1468. 'uid' => $this->staff [0] ['sid'],
  1469. 'category' => $this->staff [0] ['category'],
  1470. 'iid' => $iid
  1471. );
  1472. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1473. $item = array (
  1474. 'date' => date ( "Y-m-d H:i:s" ),
  1475. 'operation' => "提交审批",
  1476. 'status' => 1,
  1477. 'img' => $this->staff [0] ['avatar'],
  1478. 'username' => $this->staff [0] ['username'],
  1479. 'uid' => $this->staff [0] ['sid'],
  1480. 'category' => $this->staff [0] ['category'],
  1481. 'iid' => $iid
  1482. );
  1483. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1484. Doo::loadModel ( 'staff' );
  1485. $staff = new staff ();
  1486. $username2 = $staff->getOne ( array (
  1487. 'select' => 'wxid',
  1488. 'where' => 'sid=' . $pendingApprovalsSid,
  1489. 'asArray' => TRUE
  1490. ) );
  1491. // 发送微信审批通知
  1492. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1493. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1494. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1495. }
  1496. /**
  1497. * 批量提交发票
  1498. * @return string
  1499. */
  1500. function invoiceStoreBatchApproval() {
  1501. Doo::loadClass ( 'XDeode' );
  1502. $XDeode = new XDeode ( 5 );
  1503. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1504. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1505. if (empty ( $trainKey ) || empty ( $storeKey ))
  1506. die ( 'illegal request-IdKey' );
  1507. $trainId = $XDeode->decode ( $trainKey );
  1508. $isidKeyList = explode ( ',', $storeKey );
  1509. $isidList = array ();
  1510. foreach ( $isidKeyList as $value ) {
  1511. $isid = $XDeode->decode ( $value );
  1512. if (! empty ( $isid ) && is_numeric ( $isid ))
  1513. array_push ( $isidList, $isid );
  1514. }
  1515. $isidString = implode ( ',', $isidList );
  1516. if (! is_numeric ( $trainId ))
  1517. die ( 'illegal request' );
  1518. Doo::loadModel ( 'invoiceStore' );
  1519. Doo::loadModel ( 'invoice' );
  1520. // 判断哪些已经加入审批过
  1521. // 加入限制必须填写入开票内容和邮寄物品
  1522. $invoiceStore = new invoiceStore ();
  1523. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1524. foreach ( $isList as $key => $value ) {
  1525. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1526. header ( 'Content-Type:text/html;charset=utf-8' );
  1527. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1528. }
  1529. }
  1530. // 拷贝插入一条发票数据
  1531. $invoiceStore = new invoiceStore ();
  1532. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1533. $invoiceStore = new invoiceStore ();
  1534. $item = array (
  1535. 'apStatus' => 1
  1536. );
  1537. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1538. // 获得正式发票ID
  1539. $invoice = new invoice ();
  1540. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1541. $sqlList = array ();
  1542. $iidString = '';
  1543. $iida = array ();
  1544. foreach ( $iidList as $key => $value ) {
  1545. $sqlList [$value ['isid']] = $value ['iid'];
  1546. array_push ( $iida, $value ['iid'] );
  1547. }
  1548. $iidString = implode ( ',', $iida );
  1549. $ids = implode ( ',', array_keys ( $sqlList ) );
  1550. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1551. foreach ( $sqlList as $id => $ordinal ) {
  1552. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1553. }
  1554. $sql .= "END WHERE isid IN ($ids)";
  1555. $invoiceStore = new invoiceStore ();
  1556. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1557. Doo::loadModel ( 'invoiceManage' );
  1558. $invoiceManage = new invoiceManage ();
  1559. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1560. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1561. $moldManage = array ();
  1562. foreach ( $invoiceManageList as $key => $value ) {
  1563. if ($value ['mold'] == '发票打印')
  1564. $moldManage [$value ['mold']] = $value ['staffList'];
  1565. elseif ($value ['mold'] == '发票邮寄')
  1566. $moldManage [$value ['mold']] = $value ['staffList'];
  1567. elseif ($value ['mold'] == '发票退票')
  1568. $moldManage [$value ['mold']] = $value ['staffList'];
  1569. }
  1570. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1571. // 批量更新发票信息
  1572. $item = array (
  1573. 'date' => date ( "Y-m-d H:i:s" ),
  1574. 'status' => 1,
  1575. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1576. 'trainId' => $trainId,
  1577. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1578. 'moldManage' => json_encode ( $moldManage ),
  1579. 'settlementType' => 1,
  1580. 'pendingApprovals' => $pendingApprovalsSid
  1581. );
  1582. $invoice = new invoice ();
  1583. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1584. // 批量更新发票中仓库isid
  1585. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1586. foreach ( $sqlList as $isid => $iid ) {
  1587. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1588. }
  1589. $sql .= "END WHERE iid IN ($iidString)";
  1590. $invoice = new invoice ();
  1591. $invoice->UpdateBatchInvoice ( $sql );
  1592. // 批量更新发票序列号
  1593. $sqlList = array ();
  1594. foreach ( $iida as $value ) {
  1595. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1596. }
  1597. $ids = implode ( ',', array_keys ( $sqlList ) );
  1598. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1599. foreach ( $sqlList as $id => $ordinal ) {
  1600. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1601. }
  1602. $sql .= "END WHERE iid IN ($ids)";
  1603. $invoiceStore = new invoiceStore ();
  1604. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1605. // 批量生产操作日志
  1606. Doo::loadModel ( 'invoiceOperationLog' );
  1607. $sqlList = array ();
  1608. foreach ( $iida as $key => $value ) {
  1609. $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 . '"),
  1610. ("' . 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 . '") ';
  1611. array_push ( $sqlList, $sql );
  1612. }
  1613. $iolSql = implode ( ',', $sqlList );
  1614. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1615. $invoiceOperationLog = new invoiceOperationLog ();
  1616. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1617. Doo::loadModel ( 'invoiceTraining' );
  1618. $invoiceTraining = new invoiceTraining ();
  1619. $item = array (
  1620. 'itid' => $trainId,
  1621. 'submitStatus' => 1
  1622. );
  1623. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1624. Doo::loadModel ( 'staff' );
  1625. $staff = new staff ();
  1626. $username2 = $staff->getOne ( array (
  1627. 'select' => 'wxid',
  1628. 'where' => 'sid=' . $pendingApprovalsSid,
  1629. 'asArray' => TRUE
  1630. ) );
  1631. // 发送微信审批通知
  1632. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1633. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1634. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1635. }
  1636. /**
  1637. */
  1638. function invoiceStoreMailItemSet() {
  1639. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1640. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1641. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1642. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1643. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1644. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1645. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1646. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1647. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1648. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1649. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1650. Doo::loadClass ( 'XDeode' );
  1651. $XDeode = new XDeode ( 5 );
  1652. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1653. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1654. $isid = $XDeode->decode ( $storeKey );
  1655. $trainId = $XDeode->decode ( $trainKey );
  1656. if (! is_numeric ( $isid ))
  1657. die ( 'illegal request' );
  1658. Doo::loadModel ( 'invoiceStore' );
  1659. $invoiceStore = new invoiceStore ();
  1660. $mailList = array (
  1661. 'invoice' => 1,
  1662. 'mailItems' => $mailItems
  1663. );
  1664. if (! empty ( $softLock ))
  1665. $mailList += array (
  1666. 'softLock' => $softLockNum
  1667. );
  1668. else
  1669. $mailList += array (
  1670. 'softLock' => 0
  1671. );
  1672. if (! empty ( $contract ))
  1673. $mailList += array (
  1674. 'contract' => $contractNum
  1675. );
  1676. else
  1677. $mailList += array (
  1678. 'contract' => 0
  1679. );
  1680. if (! empty ( $instructions ))
  1681. $mailList += array (
  1682. 'instructions' => $instructionsNum
  1683. );
  1684. else
  1685. $mailList += array (
  1686. 'instructions' => 0
  1687. );
  1688. if (! empty ( $remittance ))
  1689. $mailList += array (
  1690. 'remittance' => $remittance
  1691. );
  1692. else
  1693. $mailList += array (
  1694. 'remittance' => ''
  1695. );
  1696. $mailString = '发票x1,备注:' . $mailItems;
  1697. if (! empty ( $softLock ))
  1698. $mailString .= ',软件锁x' . $softLockNum;
  1699. if (! empty ( $contract ))
  1700. $mailString .= ',合同x' . $contractNum;
  1701. if (! empty ( $instructions ))
  1702. $mailString .= ',说明书x' . $instructionsNum;
  1703. if (! empty ( $remittance ))
  1704. $mailString .= ',汇款账号单';
  1705. $item = array (
  1706. 'isid' => $isid,
  1707. 'doPost' => 1,
  1708. 'mailItems' => $mailString,
  1709. 'mailItemsJson' => json_encode ( $mailList )
  1710. );
  1711. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1712. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1713. }
  1714. /**
  1715. * 批量设置邮寄物品
  1716. */
  1717. function invoiceStoreBatchMailItemSet() {
  1718. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1719. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1720. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1721. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1722. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1723. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1724. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1725. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1726. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1727. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1728. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1729. Doo::loadClass ( 'XDeode' );
  1730. $XDeode = new XDeode ( 5 );
  1731. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1732. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1733. if (empty ( $trainKey ) || empty ( $storeKey ))
  1734. die ( 'illegal request-IdKey' );
  1735. $isidKeyList = explode ( ',', $storeKey );
  1736. $isidList = array ();
  1737. foreach ( $isidKeyList as $value ) {
  1738. $isid = $XDeode->decode ( $value );
  1739. if (! empty ( $isid ) && is_numeric ( $isid ))
  1740. array_push ( $isidList, $isid );
  1741. }
  1742. $isidString = implode ( ',', $isidList );
  1743. $trainId = $XDeode->decode ( $trainKey );
  1744. if (! is_numeric ( $isid ))
  1745. die ( 'illegal request' );
  1746. Doo::loadModel ( 'invoiceStore' );
  1747. $invoiceStore = new invoiceStore ();
  1748. $mailList = array (
  1749. 'invoice' => 1,
  1750. 'mailItems' => $mailItems
  1751. );
  1752. if (! empty ( $softLock ))
  1753. $mailList += array (
  1754. 'softLock' => $softLockNum
  1755. );
  1756. else
  1757. $mailList += array (
  1758. 'softLock' => 0
  1759. );
  1760. if (! empty ( $contract ))
  1761. $mailList += array (
  1762. 'contract' => $contractNum
  1763. );
  1764. else
  1765. $mailList += array (
  1766. 'contract' => 0
  1767. );
  1768. if (! empty ( $instructions ))
  1769. $mailList += array (
  1770. 'instructions' => $instructionsNum
  1771. );
  1772. else
  1773. $mailList += array (
  1774. 'instructions' => 0
  1775. );
  1776. if (! empty ( $remittance ))
  1777. $mailList += array (
  1778. 'remittance' => $remittance
  1779. );
  1780. else
  1781. $mailList += array (
  1782. 'remittance' => ''
  1783. );
  1784. $mailString = '发票x1,备注:' . $mailItems;
  1785. if (! empty ( $softLock ))
  1786. $mailString .= ',软件锁x' . $softLockNum;
  1787. if (! empty ( $contract ))
  1788. $mailString .= ',合同x' . $contractNum;
  1789. if (! empty ( $instructions ))
  1790. $mailString .= ',说明书x' . $instructionsNum;
  1791. if (! empty ( $remittance ))
  1792. $mailString .= ',汇款账号单';
  1793. $item = array (
  1794. 'doPost' => 1,
  1795. 'mailItems' => $mailString,
  1796. 'mailItemsJson' => json_encode ( $mailList )
  1797. );
  1798. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1799. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1800. }
  1801. /**
  1802. * 废弃
  1803. */
  1804. function ajaxGetMailItemByIstore() {
  1805. Doo::loadClass ( 'XDeode' );
  1806. $XDeode = new XDeode ( 5 );
  1807. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1808. $isid = $XDeode->decode ( $storeKey );
  1809. if (! is_numeric ( $isid ))
  1810. die ( 'illegal request' );
  1811. Doo::loadModel ( 'invoiceStore' );
  1812. $invoiceStore = new invoiceStore ();
  1813. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1814. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1815. echo json_encode ( $isDetail ['mailItemsJson'] );
  1816. exit ();
  1817. }
  1818. /**
  1819. * 终止开票
  1820. */
  1821. function invoiceDroppedDo() {
  1822. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1823. Doo::loadModel ( 'invoice' );
  1824. $invoice = new invoice ();
  1825. Doo::loadModel ( 'invoiceOperationLog' );
  1826. $invoiceOperationLog = new invoiceOperationLog ();
  1827. $iid = $invoice->authcode ( $droppedIidKey );
  1828. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1829. die ( 'illegal request' );
  1830. $item = array (
  1831. 'iid' => $iid,
  1832. 'status' => 4,
  1833. 'updateTime' => date ( "Y-m-d H:i:s" )
  1834. );
  1835. $invoice->setInvoiceByCondition ( $item );
  1836. $item = array (
  1837. 'date' => date ( "Y-m-d H:i:s" ),
  1838. 'operation' => '终止了开票',
  1839. 'status' => 4,
  1840. 'img' => $this->staff [0] ['avatar'],
  1841. 'username' => $this->staff [0] ['username'],
  1842. 'uid' => $this->staff [0] ['sid'],
  1843. 'category' => $this->staff [0] ['category'],
  1844. 'iid' => $iid
  1845. );
  1846. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1847. return "/invoice";
  1848. }
  1849. /**
  1850. * 更新退票的邮寄信息
  1851. */
  1852. function invoiceUntreadMailDo() {
  1853. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1854. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1855. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1856. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1857. Doo::loadModel ( 'invoice' );
  1858. $invoice = new invoice ();
  1859. $iid = $invoice->authcode ( $untreadIidKey );
  1860. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1861. die ( 'illegal request' );
  1862. $item = array (
  1863. 'iid' => $iid,
  1864. 'untreadCompany' => $untreadCompany,
  1865. 'untreadNumber' => $untreadNumber,
  1866. 'untreadItems' => $untreadItems
  1867. );
  1868. $invoice->setInvoiceByCondition ( $item );
  1869. return "/invoice";
  1870. }
  1871. /**
  1872. * 申请退票 --
  1873. */
  1874. function invoiceUntreadDo() {
  1875. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1876. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1877. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1878. Doo::loadModel ( 'invoice' );
  1879. $invoice = new invoice ();
  1880. Doo::loadModel ( 'invoiceOperationLog' );
  1881. $invoiceOperationLog = new invoiceOperationLog ();
  1882. Doo::loadModel ( 'invoiceReceivables' );
  1883. $invoiceReceivables = new invoiceReceivables ();
  1884. $iid = $invoice->authcode ( $untreadIidKey );
  1885. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1886. die ( 'illegal request' );
  1887. /*
  1888. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1889. */
  1890. $item = array (
  1891. 'iid' => $iid,
  1892. 'untreadStatus' => 1,
  1893. 'untreadReason' => $untreadReason,
  1894. 'untreadPost' => $untreadPost,
  1895. 'updateTime' => date ( "Y-m-d H:i:s" )
  1896. );
  1897. $invoice->setInvoiceByCondition ( $item );
  1898. $item = array (
  1899. 'date' => date ( "Y-m-d H:i:s" ),
  1900. 'operation' => '申请退票',
  1901. 'status' => 7,
  1902. 'img' => $this->staff [0] ['avatar'],
  1903. 'username' => $this->staff [0] ['username'],
  1904. 'uid' => $this->staff [0] ['sid'],
  1905. 'category' => $this->staff [0] ['category'],
  1906. 'iid' => $iid
  1907. );
  1908. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1909. return "/invoice";
  1910. }
  1911. /**
  1912. * 删除已终止的开票
  1913. */
  1914. function invoiceDelDo() {
  1915. Doo::loadModel ( 'invoice' );
  1916. $invoice = new invoice ();
  1917. Doo::loadModel ( 'invoiceOperationLog' );
  1918. $invoiceOperationLog = new invoiceOperationLog ();
  1919. Doo::loadClass ( 'XDeode' );
  1920. $XDeode = new XDeode ( 5 );
  1921. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1922. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1923. $iid = $XDeode->decode ( $iid );
  1924. Doo::loadModel ( 'invoiceStore' );
  1925. $invoiceStore = new invoiceStore ();
  1926. if (! is_numeric ( $iid ))
  1927. die ( 'illegal request' );
  1928. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1929. if (empty ( $invoiceDetail ))
  1930. die ( 'illegal request' );
  1931. $item = array (
  1932. 'iid' => $iid,
  1933. 'isDelete' => 1,
  1934. 'updateTime' => date ( "Y-m-d H:i:s" )
  1935. );
  1936. $invoice->setInvoiceByCondition ( $item );
  1937. $item = array (
  1938. 'date' => date ( "Y-m-d H:i:s" ),
  1939. 'operation' => '删除了已终止的发票',
  1940. 'status' => 4,
  1941. 'img' => $this->staff [0] ['avatar'],
  1942. 'username' => $this->staff [0] ['username'],
  1943. 'uid' => $this->staff [0] ['sid'],
  1944. 'category' => $this->staff [0] ['category'],
  1945. 'iid' => $iid
  1946. );
  1947. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1948. // 删除培训班发票仓库里的发票
  1949. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1950. return "/invoice";
  1951. }
  1952. /**
  1953. */
  1954. function invoiceApproval() {
  1955. Doo::loadModel ( 'invoice' );
  1956. $invoice = new invoice ();
  1957. Doo::loadClass ( 'XDeode' );
  1958. $XDeode = new XDeode ( 5 );
  1959. Doo::loadModel ( 'staff' );
  1960. $staff = new staff ();
  1961. $invoiceList = $invoice->find ( array (
  1962. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1963. 'desc' => 'iid',
  1964. 'limit' => 10,
  1965. 'asArray' => true
  1966. ) );
  1967. foreach ( $invoiceList as $key => $value ) {
  1968. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1969. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1970. if (! empty ( $lastApprover )) {
  1971. $lastApproverKey = array_keys ( $lastApprover );
  1972. $lastApprover = end ( $lastApprover );
  1973. $staffDetail = $staff->getOne ( array (
  1974. 'where' => 'sid=' . end ( $lastApproverKey ),
  1975. 'asArray' => true
  1976. ) );
  1977. $lastApprover ['username'] = $staffDetail ['username'];
  1978. }
  1979. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1980. }
  1981. $ilist = $invoice->getInvoiceByProcessStatus ();
  1982. foreach ( $ilist as $key => $value ) {
  1983. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1984. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1985. if (! empty ( $lastApprover )) {
  1986. $lastApproverKey = array_keys ( $lastApprover );
  1987. $lastApprover = end ( $lastApprover );
  1988. $staffDetail = $staff->getOne ( array (
  1989. 'where' => 'sid=' . end ( $lastApproverKey ),
  1990. 'asArray' => true
  1991. ) );
  1992. $lastApprover ['username'] = $staffDetail ['username'];
  1993. }
  1994. $ilist [$key] ['lastApprover'] = $lastApprover;
  1995. }
  1996. // print_r($ilist);
  1997. $this->data ['invoiceList'] = $invoiceList;
  1998. $this->data ['ilist'] = $ilist;
  1999. $this->data ['memu'] = "invoice";
  2000. $this->data ['staff'] = $this->staff;
  2001. $this->data ['receiptMemu'] = 'invoiceApproval';
  2002. $this->render ( "/admin/invoiceApproval", $this->data );
  2003. }
  2004. function invoiceDetail() {
  2005. Doo::loadClass ( 'XDeode' );
  2006. $XDeode = new XDeode ( 5 );
  2007. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2008. $iid = $XDeode->decode ( $iid );
  2009. if (! is_numeric ( $iid ))
  2010. die ( 'illegal request' );
  2011. Doo::loadModel ( 'invoice' );
  2012. $invoice = new invoice ();
  2013. Doo::loadModel ( 'invoiceOperationLog' );
  2014. $invoiceOperationLog = new invoiceOperationLog ();
  2015. $invoiceDetail = $invoice->getOne ( array (
  2016. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2017. 'asArray' => true
  2018. ) );
  2019. if (empty ( $invoiceDetail ))
  2020. die ( 'illegal request' );
  2021. if ($invoiceDetail ['settlementType'] == 1) {
  2022. Doo::loadModel ( 'invoiceTraining' );
  2023. $invoiceTraining = new invoiceTraining ();
  2024. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2025. }
  2026. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2027. $this->data ['invoiceDetail'] = $invoiceDetail;
  2028. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2029. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2030. $this->data ['memu'] = "invoice";
  2031. $this->data ['staff'] = $this->staff;
  2032. $this->data ['receiptMemu'] = 'invoiceApproval';
  2033. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2034. }
  2035. /**
  2036. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2037. *
  2038. * @since 1.0.0
  2039. * @var integer iid 开票ID 已加密
  2040. * @var integer status 发票审批状态
  2041. * @var integer opintion 审批发票的意见
  2042. * @return string 如操作成功返回审批首页
  2043. */
  2044. function invoiceApprovalDo() {
  2045. Doo::loadModel ( 'invoice' );
  2046. $invoice = new invoice ();
  2047. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2048. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2049. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2050. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2051. $iid = $invoice->authcode ( $iid );
  2052. if (! is_numeric ( $iid ))
  2053. die ( 'illegal request' );
  2054. // && ! empty ( $opinion )
  2055. if (! empty ( $iid ) && ! empty ( $status )) {
  2056. if (! ($status == 2 || $status == 3 || $status == 4))
  2057. die ( 'illegal request' );
  2058. Doo::loadModel ( 'invoiceOperationLog' );
  2059. $invoiceOperationLog = new invoiceOperationLog ();
  2060. $invoiceDetail = $invoice->getOne ( array (
  2061. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2062. 'asArray' => true
  2063. ) );
  2064. if (empty ( $invoiceDetail ))
  2065. die ( 'illegal request' );
  2066. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2067. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2068. if ($status == 3) {
  2069. $invoice->status = $status;
  2070. $item = array (
  2071. 'operation' => $opinion
  2072. );
  2073. } else {
  2074. if (empty ( $processApprovals )) {
  2075. $processApprovals = array (
  2076. $this->staff [0] ['sid'] => array (
  2077. 'date' => date ( "Y-m-d H:i:s" ),
  2078. 'opinion' => $opinion,
  2079. 'status' => $status
  2080. )
  2081. );
  2082. // var_dump(next($invoiceManage));
  2083. $nextInvoiceManage = next ( $invoiceManage );
  2084. // print_r($nextInvoiceManage);
  2085. if ($status != 4 && $nextInvoiceManage !== false)
  2086. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2087. $invoice->processApprovals = json_encode ( $processApprovals );
  2088. // var_dump($invoice);
  2089. // print_r($invoiceManage);
  2090. } else {
  2091. $processApprovals [$this->staff [0] ['sid']] = array (
  2092. 'date' => date ( "Y-m-d H:i:s" ),
  2093. 'opinion' => $opinion,
  2094. 'status' => $status
  2095. );
  2096. $pendingApprovals = 0;
  2097. foreach ( $invoiceManage as $key => $value ) {
  2098. if ($value [0] == $this->staff [0] ['sid']) {
  2099. if (isset ( $invoiceManage [$key + 1] ))
  2100. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2101. break;
  2102. }
  2103. }
  2104. if ($status != 4 && ! empty ( $pendingApprovals ))
  2105. $invoice->pendingApprovals = $pendingApprovals;
  2106. $invoice->processApprovals = json_encode ( $processApprovals );
  2107. }
  2108. $item = array (
  2109. 'operation' => $opinion
  2110. );
  2111. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2112. $invoice->status = $status;
  2113. $invoice->pendingApprovals = 0;
  2114. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2115. } elseif ($status == 4) {
  2116. $invoice->status = $status;
  2117. $item = array (
  2118. 'operation' => $opinion
  2119. );
  2120. }
  2121. }
  2122. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2123. $invoice->update ( array (
  2124. 'where' => 'iid=' . $iid
  2125. ) );
  2126. $item += array (
  2127. 'date' => date ( "Y-m-d H:i:s" ),
  2128. 'img' => $this->staff [0] ['avatar'],
  2129. 'username' => $this->staff [0] ['username'],
  2130. 'uid' => $this->staff [0] ['sid'],
  2131. 'category' => $this->staff [0] ['category'],
  2132. 'status' => $status,
  2133. 'iid' => $iid
  2134. );
  2135. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2136. if (empty ( $divApproval ))
  2137. return '/invoiceApproval';
  2138. else
  2139. return '/invoiceApprovalAchieve/PEND';
  2140. }
  2141. die ( 'illegal request' );
  2142. }
  2143. /**
  2144. * 展示需要打印的发票数据
  2145. *
  2146. * @since 1.0.0
  2147. */
  2148. function invoicePrint() {
  2149. Doo::loadModel ( 'invoice' );
  2150. $invoice = new invoice ();
  2151. Doo::loadClass ( 'XDeode' );
  2152. $XDeode = new XDeode ( 5 );
  2153. Doo::loadModel ( 'staff' );
  2154. $staff = new staff ();
  2155. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2156. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2157. foreach ( $toPrint as $key => $value ) {
  2158. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2159. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2160. if (! empty ( $lastApprover )) {
  2161. $lastApproverKey = array_keys ( $lastApprover );
  2162. $lastApprover = end ( $lastApprover );
  2163. $staffDetail = $staff->getOne ( array (
  2164. 'where' => 'sid=' . end ( $lastApproverKey ),
  2165. 'asArray' => true
  2166. ) );
  2167. $lastApprover ['username'] = $staffDetail ['username'];
  2168. }
  2169. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2170. }
  2171. foreach ( $printed as $key => $value ) {
  2172. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2173. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2174. if (! empty ( $lastApprover )) {
  2175. $lastApproverKey = array_keys ( $lastApprover );
  2176. $lastApprover = end ( $lastApprover );
  2177. $staffDetail = $staff->getOne ( array (
  2178. 'where' => 'sid=' . end ( $lastApproverKey ),
  2179. 'asArray' => true
  2180. ) );
  2181. $lastApprover ['username'] = $staffDetail ['username'];
  2182. }
  2183. $printed [$key] ['lastApprover'] = $lastApprover;
  2184. }
  2185. $this->data ['printed'] = $printed;
  2186. $this->data ['toPrint'] = $toPrint;
  2187. $this->data ['memu'] = "invoice";
  2188. $this->data ['staff'] = $this->staff;
  2189. $this->data ['receiptMemu'] = 'invoicePrint';
  2190. $this->render ( "/admin/invoicePrint", $this->data );
  2191. }
  2192. /**
  2193. * 展示发票打印的详情页面
  2194. *
  2195. * @since 1.0.0
  2196. */
  2197. function invoicePrintDetail() {
  2198. Doo::loadClass ( 'XDeode' );
  2199. $XDeode = new XDeode ( 5 );
  2200. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2201. $iid = $XDeode->decode ( $iid );
  2202. if (! is_numeric ( $iid ))
  2203. die ( 'illegal request' );
  2204. Doo::loadModel ( 'invoice' );
  2205. $invoice = new invoice ();
  2206. Doo::loadModel ( 'invoiceOperationLog' );
  2207. $invoiceOperationLog = new invoiceOperationLog ();
  2208. Doo::loadModel ( 'invoicePaper' );
  2209. $invoicePaper = new invoicePaper ();
  2210. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2211. if (empty ( $invoiceDetail ))
  2212. die ( 'illegal request' );
  2213. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2214. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2215. if ($invoiceDetail ['settlementType'] == 1) {
  2216. Doo::loadModel ( 'invoiceTraining' );
  2217. $invoiceTraining = new invoiceTraining ();
  2218. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2219. }
  2220. $this->data ['invoicePaperList'] = $invoicePaperList;
  2221. $this->data ['invoiceDetail'] = $invoiceDetail;
  2222. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2223. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2224. $this->data ['memu'] = "invoice";
  2225. $this->data ['staff'] = $this->staff;
  2226. $this->data ['receiptMemu'] = 'invoicePrint';
  2227. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2228. }
  2229. /**
  2230. * 所有待打印 发票
  2231. */
  2232. function invoicePrintStayAchieve() {
  2233. Doo::loadModel ( 'invoice' );
  2234. $invoice = new invoice ();
  2235. Doo::loadClass ( 'XDeode' );
  2236. $XDeode = new XDeode ( 5 );
  2237. Doo::loadModel ( 'staff' );
  2238. $staff = new staff ();
  2239. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2240. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2241. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2242. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2243. Doo::loadModel ( 'invoiceTraining' );
  2244. $invoiceTraining = new invoiceTraining ();
  2245. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2246. $page_size = 12;
  2247. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2248. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2249. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2250. $get = "/" . $status;
  2251. $con = ' and status=2 ';
  2252. if ($status == 'TOPRINT')
  2253. $con = ' and status=2 and printStatus=0 ';
  2254. elseif ($status == 'PRINTED')
  2255. $con = ' and status=2 and printStatus=1';
  2256. if ($invoiceType == 'ORDINARY')
  2257. $con .= ' and invoiceType=0 ';
  2258. elseif ($invoiceType == 'SPECIAL')
  2259. $con .= ' and invoiceType=1 ';
  2260. if ($invoiceTrain == 'ORDINARY')
  2261. $con .= ' and trainId=0 ';
  2262. elseif ($invoiceTrain == 'TRAIN')
  2263. $con .= ' and trainId!=0 ';
  2264. if ($invoiceTrainName != 'ALL') {
  2265. $trainId = $XDeode->decode ( $invoiceTrainName );
  2266. if (is_numeric ( $trainId ))
  2267. $con .= ' and trainId =' . $trainId;
  2268. }
  2269. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2270. $dateArr = explode ( ':', $date );
  2271. $D1 = '';
  2272. $D2 = '';
  2273. if (! empty ( $date )) {
  2274. $D1 = $dateArr [0];
  2275. $D2 = $dateArr [1];
  2276. }
  2277. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2278. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2279. if (! empty ( $MebSea )) {
  2280. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2281. }
  2282. $pageinfo ['page'] = array (
  2283. 'previous' => ''
  2284. );
  2285. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2286. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2287. $action = "invoicePrintStayAchieve";
  2288. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2289. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2290. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2291. $this->data ['trainList'] = $trainList;
  2292. $this->data ['invoiceType'] = $invoiceType;
  2293. $this->data ['invoiceTrain'] = $invoiceTrain;
  2294. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2295. $this->data ['MebSeaEn'] = $MebSea;
  2296. $this->data ['MebSea'] = urlencode ( $MebSea );
  2297. $this->data ['get'] = $get;
  2298. $this->data ['page'] = $pageinfo;
  2299. $this->data ['date'] = $date;
  2300. $this->data ['status'] = $status;
  2301. $this->data ['invoiceType'] = $invoiceType;
  2302. $this->data ['memu'] = "invoice";
  2303. $this->data ['staff'] = $this->staff;
  2304. foreach ( $list as $key => $value ) {
  2305. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2306. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2307. if (! empty ( $lastApprover )) {
  2308. $lastApproverKey = array_keys ( $lastApprover );
  2309. $lastApprover = end ( $lastApprover );
  2310. $staffDetail = $staff->getOne ( array (
  2311. 'where' => 'sid=' . end ( $lastApproverKey ),
  2312. 'asArray' => true
  2313. ) );
  2314. $lastApprover ['username'] = $staffDetail ['username'];
  2315. }
  2316. $list [$key] ['lastApprover'] = $lastApprover;
  2317. }
  2318. $this->data ['receiptMemu'] = 'invoicePrint';
  2319. $this->data ['list'] = $list;
  2320. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2321. }
  2322. /**
  2323. * 填写票号并完成打印
  2324. * @since 1.0.0
  2325. */
  2326. function invoicePrintDo() {
  2327. Doo::loadModel ( 'invoice' );
  2328. $invoice = new invoice ();
  2329. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2330. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2331. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2332. $iid = $invoice->authcode ( $iid );
  2333. if (! is_numeric ( $iid ))
  2334. die ( 'illegal request' );
  2335. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2336. Doo::loadModel ( 'invoiceOperationLog' );
  2337. $invoiceOperationLog = new invoiceOperationLog ();
  2338. Doo::loadModel ( 'invoiceStatistics' );
  2339. $invoiceStatistics = new invoiceStatistics ();
  2340. $XDeode = new XDeode ( 5 );
  2341. Doo::loadModel ( 'invoicePaper' );
  2342. $invoicePaper = new invoicePaper ();
  2343. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2344. if (empty ( $invoicePrintDetail ))
  2345. die ( 'illegal request' );
  2346. //
  2347. $ipid = $XDeode->decode ( $invoiceNo );
  2348. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2349. if (empty ( $paperDetail ))
  2350. die ( 'illegal request' );
  2351. $invoicePaper = new invoicePaper ();
  2352. $item = array (
  2353. 'iid' => $iid,
  2354. 'ipid' => $ipid
  2355. );
  2356. $invoicePaper->setInvoicePaperByCondition ( $item );
  2357. $item = array (
  2358. 'iid' => $iid,
  2359. 'printStatus' => 1,
  2360. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2361. 'printer' => $this->staff [0] ['username'],
  2362. 'printTime' => date ( "Y-m-d H:i:s" ),
  2363. 'invoiceNo' => $paperDetail ['invoiceNo']
  2364. );
  2365. $invoice->setInvoiceByCondition ( $item );
  2366. $item = array (
  2367. 'date' => date ( "Y-m-d H:i:s" ),
  2368. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2369. 'status' => 5,
  2370. 'img' => $this->staff [0] ['avatar'],
  2371. 'username' => $this->staff [0] ['username'],
  2372. 'uid' => $this->staff [0] ['sid'],
  2373. 'category' => $this->staff [0] ['category'],
  2374. 'iid' => $iid
  2375. );
  2376. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2377. // 去统计--负票不汇总
  2378. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2379. $item = array (
  2380. 'date' => date ( "Y-m-d H:i:s" ),
  2381. 'priceClass' => 1,
  2382. 'cid' => $invoicePrintDetail ['cid'],
  2383. 'staff' => $invoicePrintDetail ['sid'],
  2384. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2385. );
  2386. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2387. }
  2388. // 发送通知信息到微信-去除
  2389. // $this->setWXMsg($iid,'PRINT');
  2390. // 发票信息库
  2391. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2392. // 申请人获取微信通知
  2393. Doo::loadModel ( 'staff' );
  2394. $staff = new staff ();
  2395. Doo::loadClass ( 'XDeode' );
  2396. $XDeode = new XDeode ( 5 );
  2397. $username2 = $staff->getOne ( array (
  2398. 'select' => 'wxid',
  2399. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2400. 'asArray' => TRUE
  2401. ) );
  2402. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2403. $msg = '';
  2404. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2405. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2406. if (empty ( $invoicePrintType ))
  2407. return "/invoicePrint";
  2408. else
  2409. return "/invoicePrintStayAchieve";
  2410. }
  2411. }
  2412. /**
  2413. * 需要邮寄的发票
  2414. * @since 1.0.0
  2415. */
  2416. function invoicePost() {
  2417. Doo::loadModel ( 'invoice' );
  2418. $invoice = new invoice ();
  2419. Doo::loadModel ( 'express' );
  2420. $express = new express ();
  2421. $invoicePost = $invoice->getPostByInvoice ();
  2422. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2423. $expressList = $express->getExpressByAll ();
  2424. $invoicePostExpress = "";
  2425. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2426. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2427. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2428. $this->data ['expressList'] = $expressList;
  2429. $this->data ['invoicePost'] = $invoicePost;
  2430. $this->data ['invoicePosted'] = $invoicePosted;
  2431. $this->data ['memu'] = "invoice";
  2432. $this->data ['staff'] = $this->staff;
  2433. $this->data ['receiptMemu'] = 'invoicePost';
  2434. $this->render ( "/admin/invoicePost", $this->data );
  2435. }
  2436. /**
  2437. * 添加发票邮寄信息
  2438. */
  2439. function invoiceExpressAddDo() {
  2440. Doo::loadModel ( 'invoice' );
  2441. $invoice = new invoice ();
  2442. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2443. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2444. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2445. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2446. $iid = $iid = $invoice->authcode ( $iid );
  2447. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2448. die ( 'illegal request' );
  2449. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2450. setcookie ( 'invoicePostExpress', $expressNumber );
  2451. $item = array (
  2452. 'iid' => $iid,
  2453. 'postStatus' => 1,
  2454. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2455. 'postTime' => date ( "Y-m-d H:i:s" ),
  2456. 'expressCompany' => $expressCompany,
  2457. 'expressNumber' => $expressNumber,
  2458. 'actualItems' => $actualItems,
  2459. 'poster' => $this->staff [0] ['username']
  2460. );
  2461. $invoice->setInvoiceByCondition ( $item );
  2462. // 微信通知-去掉
  2463. // $this->setWXMsg ( $iid );
  2464. Doo::loadModel ( 'staff' );
  2465. $staff = new staff ();
  2466. Doo::loadClass ( 'XDeode' );
  2467. $XDeode = new XDeode ( 5 );
  2468. $username2 = $staff->getOne ( array (
  2469. 'select' => 'wxid',
  2470. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2471. 'asArray' => TRUE
  2472. ) );
  2473. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2474. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2475. if (empty ( $expCom ))
  2476. $expCom [0] = '';
  2477. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2478. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2479. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2480. return '/invoicePost';
  2481. }
  2482. function invoiceExpressUpdateDo() {
  2483. Doo::loadModel ( 'invoice' );
  2484. $invoice = new invoice ();
  2485. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2486. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2487. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2488. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2489. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2490. $iid = $invoice->authcode ( $iid );
  2491. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2492. die ( 'illegal request' );
  2493. $item = array (
  2494. 'iid' => $iid,
  2495. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2496. 'expressCompany' => $expressCompany,
  2497. 'expressNumber' => $expressNumber,
  2498. 'actualItems' => $actualItems,
  2499. 'poster' => $this->staff [0] ['username']
  2500. );
  2501. $invoice->setInvoiceByCondition ( $item );
  2502. return $action;
  2503. }
  2504. /**
  2505. * 可退票管理
  2506. */
  2507. function invoiceUntreadIsAchieve() {
  2508. Doo::loadModel ( 'invoice' );
  2509. $invoice = new invoice ();
  2510. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2511. /*
  2512. * 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' => '' );
  2513. */
  2514. if (empty ( $MebSea )) {
  2515. $con = ' and invoiceNo like "NULL" ';
  2516. } else {
  2517. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2518. }
  2519. // printStatus=1 and
  2520. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2521. /*
  2522. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2523. */
  2524. $limit = '0,20';
  2525. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2526. // print_r($list);
  2527. $this->data ['MebSeaEn'] = $MebSea;
  2528. /*
  2529. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2530. */
  2531. $this->data ['list'] = $list;
  2532. $this->data ['memu'] = "invoice";
  2533. $this->data ['staff'] = $this->staff;
  2534. $this->data ['receiptMemu'] = 'invoice';
  2535. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2536. }
  2537. // 已经退票的发票
  2538. function invoiceUntreadED() {
  2539. Doo::loadModel ( 'invoice' );
  2540. $invoice = new invoice ();
  2541. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2542. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2543. Doo::loadClass ( 'XDeode' );
  2544. $XDeode = new XDeode ( 5 );
  2545. $page_size = 18;
  2546. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2547. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2548. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2549. $dateArr = explode ( ':', $date );
  2550. $D1 = '';
  2551. $D2 = '';
  2552. if (! empty ( $date )) {
  2553. $D1 = $dateArr [0];
  2554. $D2 = $dateArr [1];
  2555. }
  2556. $con = '';
  2557. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2558. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2559. }
  2560. // if ($date == 'MONTHO')
  2561. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2562. // elseif ($date == 'MONTHT')
  2563. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2564. // elseif ($date == 'MONTHY')
  2565. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2566. if (! empty ( $MebSea )) {
  2567. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2568. }
  2569. if ($invoiceType == 'ORDINARY') {
  2570. $con .= ' and invoiceType=0 ';
  2571. } elseif ($invoiceType == 'SPECIAL') {
  2572. $con .= ' and invoiceType=1 ';
  2573. }
  2574. $pageinfo ['page'] = array (
  2575. 'previous' => ''
  2576. );
  2577. // printStatus=1 and
  2578. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2579. $action = "invoiceUntreadED";
  2580. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2581. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2582. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2583. // print_r($list);
  2584. $this->data ['MebSeaEn'] = $MebSea;
  2585. $this->data ['get'] = $get;
  2586. $this->data ['page'] = $pageinfo;
  2587. $this->data ['date'] = $date;
  2588. $this->data ['invoiceType'] = $invoiceType;
  2589. $this->data ['list'] = $list;
  2590. $this->data ['memu'] = "invoice";
  2591. $this->data ['staff'] = $this->staff;
  2592. $this->data ['receiptMemu'] = 'invoice';
  2593. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2594. }
  2595. /**
  2596. * 退票处理页面
  2597. */
  2598. function invoiceUntread() {
  2599. Doo::loadModel ( 'invoice' );
  2600. $invoice = new invoice ();
  2601. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2602. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2603. foreach ( $establishedInvoice as $key => $value ) {
  2604. // months
  2605. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2606. $nowDate = strtotime ( 'now' );
  2607. $establishedInvoice [$key] ['lossShow'] = false;
  2608. if ($lossDate < $nowDate)
  2609. $establishedInvoice [$key] ['lossShow'] = true;
  2610. }
  2611. $this->data ['untreadInvoice'] = $untreadInvoice;
  2612. $this->data ['establishedInvoice'] = $establishedInvoice;
  2613. $this->data ['memu'] = "invoice";
  2614. $this->data ['staff'] = $this->staff;
  2615. $this->data ['receiptMemu'] = 'invoiceUntread';
  2616. $this->render ( "/admin/invoiceUntread", $this->data );
  2617. }
  2618. /**
  2619. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2620. */
  2621. function invoiceUntreadEstablishedDo() {
  2622. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2623. Doo::loadModel ( 'invoice' );
  2624. $invoice = new invoice ();
  2625. Doo::loadModel ( 'invoiceOperationLog' );
  2626. $invoiceOperationLog = new invoiceOperationLog ();
  2627. Doo::loadModel ( 'invoiceReceivables' );
  2628. Doo::loadModel ( 'invoiceStatistics' );
  2629. $iid = $invoice->authcode ( $untreadIidKey );
  2630. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2631. die ( 'illegal request' );
  2632. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2633. if ($invoiceDetails ['untreadStatus'] != 1)
  2634. die ( 'illegal request' );
  2635. $item = array (
  2636. 'iid' => $iid,
  2637. // 'irid'=>'',
  2638. 'untreadStatus' => 2,
  2639. 'updateTime' => date ( "Y-m-d H:i:s" )
  2640. );
  2641. $invoice->setInvoiceByCondition ( $item );
  2642. $item = array (
  2643. 'date' => date ( "Y-m-d H:i:s" ),
  2644. 'operation' => '已确认退票',
  2645. 'status' => 6,
  2646. 'img' => $this->staff [0] ['avatar'],
  2647. 'username' => $this->staff [0] ['username'],
  2648. 'uid' => $this->staff [0] ['sid'],
  2649. 'category' => $this->staff [0] ['category'],
  2650. 'iid' => $iid
  2651. );
  2652. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2653. // 收款解绑以及入账扣除 收款扣除
  2654. if (! empty ( $invoiceDetails ['irid'] )) {
  2655. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2656. foreach ( $iridList as $value ) {
  2657. $invoiceReceivables = new invoiceReceivables ();
  2658. $irDetails = $invoiceReceivables->getOne ( array (
  2659. 'where' => " irid=" . $value . ' and bindStatus=1',
  2660. 'asArray' => TRUE
  2661. ) );
  2662. $item = array (
  2663. 'irid' => $value,
  2664. 'bindStatus' => 0,
  2665. 'untreadStatus' => 1,
  2666. 'untreadStaff' => $invoiceDetails ['userName'],
  2667. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2668. 'iid' => 0
  2669. );
  2670. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2671. if (! empty ( $irDetails )) {
  2672. // 扣除入账
  2673. $invoiceStatistics = new invoiceStatistics ();
  2674. $item = array (
  2675. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2676. 'priceClass' => 3,
  2677. 'cid' => $invoiceDetails ['cid'],
  2678. 'staff' => $invoiceDetails ['sid'],
  2679. 'accountPrice' => - $irDetails ['receivablesPrice']
  2680. );
  2681. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2682. // 扣除收款
  2683. $invoiceStatistics = new invoiceStatistics ();
  2684. $item = array (
  2685. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2686. 'priceClass' => 2,
  2687. 'cid' => $invoiceDetails ['cid'],
  2688. 'staff' => $invoiceDetails ['sid'],
  2689. 'irid' => $irDetails ['irid'],
  2690. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2691. );
  2692. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2693. }
  2694. // 解绑时删除收入流水
  2695. Doo::loadModel ( 'wasteBook' );
  2696. $wasteBook = new wasteBook ();
  2697. $wasteBook->delete ( array (
  2698. 'where' => 'dataID=' . $value . ' and accountType=7',
  2699. 'limit' => 1
  2700. ) );
  2701. }
  2702. }
  2703. return "/invoiceUntread";
  2704. }
  2705. function invoiceUntreadRecallDo() {
  2706. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2707. Doo::loadModel ( 'invoice' );
  2708. $invoice = new invoice ();
  2709. Doo::loadClass ( 'XDeode' );
  2710. $XDeode = new XDeode ( 5 );
  2711. Doo::loadModel ( 'invoiceOperationLog' );
  2712. $invoiceOperationLog = new invoiceOperationLog ();
  2713. $iid = $XDeode->decode ( $iidKey );
  2714. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2715. if (empty ( $invoiceDetail )) {
  2716. die ( 'illegal request-DATANULL' );
  2717. }
  2718. $item = array (
  2719. 'iid' => $iid,
  2720. 'untreadStatus' => 0
  2721. );
  2722. $invoice->setInvoiceByCondition ( $item );
  2723. $item = array (
  2724. 'date' => date ( "Y-m-d H:i:s" ),
  2725. 'operation' => '撤回申请退票',
  2726. 'status' => 13,
  2727. 'img' => $this->staff [0] ['avatar'],
  2728. 'username' => $this->staff [0] ['username'],
  2729. 'uid' => $this->staff [0] ['sid'],
  2730. 'category' => $this->staff [0] ['category'],
  2731. 'iid' => $iid
  2732. );
  2733. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2734. return "/invoiceUntread";
  2735. }
  2736. /**
  2737. * 建立负票,关联原来发票
  2738. */
  2739. function invoiceLossDo() {
  2740. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2741. if (! empty ( $iidKey )) {
  2742. Doo::loadClass ( 'XDeode' );
  2743. $XDeode = new XDeode ( 5 );
  2744. Doo::loadModel ( 'invoice' );
  2745. $invoice = new invoice ();
  2746. Doo::loadModel ( 'invoiceOperationLog' );
  2747. $invoiceOperationLog = new invoiceOperationLog ();
  2748. $iidKey = $XDeode->decode ( $iidKey );
  2749. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2750. // 拷贝插入一条发票数据
  2751. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2752. // 更新负票
  2753. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2754. $invoice = new invoice ();
  2755. $item = array (
  2756. 'iid' => $iid,
  2757. 'sid' => $this->staff [0] ['sid'],
  2758. 'userName' => $this->staff [0] ['username'],
  2759. 'cid' => $this->staff [0] ['cid'],
  2760. 'categoryName' => $this->staff [0] ['category'],
  2761. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2762. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2763. 'invoiceSerial' => $invoiceSerial,
  2764. 'invoiceNo' => '',
  2765. 'printStatus' => 0,
  2766. 'untreadStatus' => 4,
  2767. // 关联发票号
  2768. 'lossIid' => $invoiceDetail ['iid']
  2769. );
  2770. $invoice->setInvoiceByCondition ( $item );
  2771. // 更新原发票
  2772. $invoice = new invoice ();
  2773. $item = array (
  2774. 'iid' => $invoiceDetail ['iid'],
  2775. 'lossIid' => $iid
  2776. );
  2777. $invoice->setInvoiceByCondition ( $item );
  2778. // 操作日志
  2779. $item = array (
  2780. 'date' => date ( "Y-m-d H:i:s" ),
  2781. 'operation' => "创建负票" . $invoiceSerial,
  2782. 'status' => 12,
  2783. 'img' => $this->staff [0] ['avatar'],
  2784. 'username' => $this->staff [0] ['username'],
  2785. 'uid' => $this->staff [0] ['sid'],
  2786. 'category' => $this->staff [0] ['category'],
  2787. 'iid' => $iid
  2788. );
  2789. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2790. // print_r($invoiceDetail);
  2791. // echo $iid;die;
  2792. }
  2793. return '/invoiceUntread';
  2794. }
  2795. /**
  2796. * 上传银行到账 收款文件
  2797. */
  2798. function invoiceReceivablesBankUpload() {
  2799. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2800. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2801. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2802. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2803. header ( "HTTP/1.1 500 Internal Server Error" );
  2804. echo "POST exceeded maximum allowed size.";
  2805. exit ( 0 );
  2806. }
  2807. // Settings
  2808. $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)
  2809. $upload_name = "Filedata";
  2810. $file_name = "";
  2811. $nk = time ();
  2812. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2813. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2814. echo "文件无法保存.";
  2815. exit ( 0 );
  2816. }
  2817. echo json_encode ( array (
  2818. 'filename' => $file_name,
  2819. 'id' => $nk
  2820. ) );
  2821. exit ( 0 );
  2822. }
  2823. /**
  2824. * 解析银行到账收款execl并导入库中
  2825. */
  2826. function invoiceReceivablesImport() {
  2827. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2828. if ($path != "") {
  2829. Doo::loadModel ( 'invoiceReceivables' );
  2830. $invoiceReceivables = new invoiceReceivables ();
  2831. Doo::loadClass ( 'invoice.func' );
  2832. Doo::loadModel ( 'invoiceROLog' );
  2833. $invoiceROLog = new invoiceROLog ();
  2834. Doo::loadModel ( 'invoiceStatistics' );
  2835. $invoiceStatistics = new invoiceStatistics ();
  2836. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2837. $bankBatchNumber = 'BBN_' . time ();
  2838. Doo::db ()->beginTransaction ();
  2839. // 批量存储收款--由于必须获得收款ID,
  2840. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2841. VALUES ';
  2842. $date = date ( "Y-m-d" );
  2843. $receivablesList = array ();
  2844. foreach ( $exlArray as $key => $value ) {
  2845. $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"] . '")';
  2846. array_push ( $receivablesList, $receivablesSql );
  2847. }
  2848. $sql = $sql . implode ( ',', $receivablesList );
  2849. // echo $sql;
  2850. Doo::db ()->query ( $sql );
  2851. // 批量存储收款统计
  2852. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2853. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2854. // 没有irid 回滚所有操作
  2855. if (empty ( $iridList )) {
  2856. Doo::db ()->rollBack ();
  2857. header ( 'Content-Type:text/html;charset=utf-8' );
  2858. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2859. }
  2860. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2861. VALUES ';
  2862. $statisticsList = array ();
  2863. foreach ( $iridList as $value ) {
  2864. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2865. array_push ( $statisticsList, $statisticsSql );
  2866. }
  2867. $sql = $sql . implode ( ',', $statisticsList );
  2868. Doo::db ()->query ( $sql );
  2869. // 批量存储操作日志
  2870. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2871. VALUES ';
  2872. $ROLogList = array ();
  2873. foreach ( $iridList as $value ) {
  2874. $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'] . '")';
  2875. array_push ( $ROLogList, $ROLogSql );
  2876. }
  2877. $sql = $sql . implode ( ',', $ROLogList );
  2878. Doo::db ()->query ( $sql );
  2879. // 批量写入流水
  2880. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2881. VALUES ';
  2882. $wasteBookList = array ();
  2883. foreach ( $iridList as $value ) {
  2884. $accountBank = '';
  2885. if ($value ['receivablesBank'] == '纵横广发') {
  2886. $accountBank = 'CGBDeposit';
  2887. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2888. $accountBank = 'ICBCDeposit';
  2889. } elseif ($value ['receivablesBank'] == '华润银行') {
  2890. $accountBank = 'HUADeposit';
  2891. } elseif ($value ['receivablesBank'] == '个人广发') {
  2892. $accountBank = 'PersonalDeposit';
  2893. }
  2894. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2895. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2896. array_push ( $wasteBookList, $wasteBookSql );
  2897. }
  2898. $sql = $sql . implode ( ',', $wasteBookList );
  2899. Doo::db ()->query ( $sql );
  2900. Doo::db ()->commit ();
  2901. return "/invoiceReceivables";
  2902. }
  2903. echo 'no file';
  2904. }
  2905. function invoiceReceivables() {
  2906. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2907. Doo::loadModel ( 'L_category' );
  2908. $lCategory = new L_category ();
  2909. Doo::loadModel ( 'staff' );
  2910. $staff = new staff ();
  2911. Doo::loadModel ( 'invoiceReceivables' );
  2912. $invoiceReceivables = new invoiceReceivables ();
  2913. Doo::loadModel ( 'invoice' );
  2914. $invoice = new invoice ();
  2915. Doo::loadClass ( 'XDeode' );
  2916. $XDeode = new XDeode ( 5 );
  2917. $category = $lCategory->getCategory ();
  2918. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2919. $sql = 'bindStatus=1 and iid!=0';
  2920. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2921. // 获取未入账发票
  2922. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2923. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2924. foreach ( $invoiceUnAccount as $key => $value ) {
  2925. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2926. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2927. if (! empty ( $lastApprover )) {
  2928. $lastApproverKey = array_keys ( $lastApprover );
  2929. $lastApprover = end ( $lastApprover );
  2930. $staffDetail = $staff->getOne ( array (
  2931. 'where' => 'sid=' . end ( $lastApproverKey ),
  2932. 'asArray' => true
  2933. ) );
  2934. $lastApprover ['username'] = $staffDetail ['username'];
  2935. }
  2936. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2937. }
  2938. foreach ( $invoiceExistAccount as $key => $value ) {
  2939. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2940. if (empty ( $irList ))
  2941. $irList [0] ['sumPrice'] = 0;
  2942. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2943. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2944. $invoiceExistAccount [$key] ['balance'] = $balance;
  2945. }
  2946. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2947. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2948. $this->data ['halfList'] = $halfList;
  2949. $this->data ['halfCount'] = count ( $halfList );
  2950. // print_r($receivablesList);
  2951. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2952. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2953. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2954. $this->data ['receivablesInput'] = $receivablesInput;
  2955. $this->data ['year'] = date ( 'Y' );
  2956. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2957. $this->data ['receivablesList'] = $receivablesList;
  2958. $this->data ['staffList'] = $staffList;
  2959. $this->data ['category'] = $category;
  2960. $this->data ['memu'] = "invoice";
  2961. $this->data ['staff'] = $this->staff;
  2962. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2963. $this->render ( "/admin/invoiceReceivables", $this->data );
  2964. }
  2965. /**
  2966. * 设置收款认领地区
  2967. */
  2968. function setInvoiceReceivablesClaim() {
  2969. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2970. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2971. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2972. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2973. Doo::loadModel ( 'invoiceReceivables' );
  2974. $invoiceReceivables = new invoiceReceivables ();
  2975. Doo::loadClass ( 'XDeode' );
  2976. $XDeode = new XDeode ( 5 );
  2977. Doo::loadModel ( 'invoiceROLog' );
  2978. $invoiceROLog = new invoiceROLog ();
  2979. $irid = $XDeode->decode ( $iridKey );
  2980. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2981. if (empty ( $irDetail ))
  2982. die ( 'illegal request' );
  2983. $item = array (
  2984. 'irid' => $irid,
  2985. 'receivablesCategory' => $receivablesCategory
  2986. );
  2987. if ($receivablesCategory != 'PUBLIC') {
  2988. $item += array (
  2989. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2990. 'inputType' => 1
  2991. );
  2992. }
  2993. $invoiceReceivables = new invoiceReceivables ();
  2994. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2995. // 收款操作日志
  2996. $item = array (
  2997. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2998. 'date' => date ( "Y-m-d" ),
  2999. 'status' => 1,
  3000. 'img' => $this->staff [0] ['avatar'],
  3001. 'username' => $this->staff [0] ['username'],
  3002. 'uid' => $this->staff [0] ['sid'],
  3003. 'category' => $this->staff [0] ['category'],
  3004. 'irid' => $irid
  3005. );
  3006. $invoiceROLog->setInvoiceROLog ( $item );
  3007. if (empty ( $action ))
  3008. return '/invoiceReceivables';
  3009. else
  3010. return "/invoiceReceivablesAS";
  3011. }
  3012. die ( 'illegal request' );
  3013. }
  3014. /**
  3015. * 新添加收款直接入账发票
  3016. */
  3017. function invoiceCompareClaimPrice() {
  3018. // 收款录入
  3019. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3020. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3021. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3022. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3023. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3024. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3025. Doo::loadModel ( 'invoiceReceivables' );
  3026. $invoiceReceivables = new invoiceReceivables ();
  3027. Doo::loadModel ( 'invoiceROLog' );
  3028. $invoiceROLog = new invoiceROLog ();
  3029. Doo::loadModel ( 'invoiceStatistics' );
  3030. Doo::loadModel ( 'invoice' );
  3031. $invoice = new invoice ();
  3032. Doo::loadClass ( 'XDeode' );
  3033. $XDeode = new XDeode ( 5 );
  3034. Doo::loadModel ( 'invoiceOperationLog' );
  3035. $invoiceOperationLog = new invoiceOperationLog ();
  3036. $iidKey = $XDeode->decode ( $iidKey );
  3037. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3038. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3039. die ( 'illegal request' );
  3040. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3041. // 收款录入 并绑定发票
  3042. Doo::db ()->beginTransaction ();
  3043. $bindStatus = 0;
  3044. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  3045. $bindStatus = 1;
  3046. $titleMark = $invoiceDetail ['invoiceTitle'];
  3047. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3048. $titleMark = $invoiceDetail ['invoiceCompany'];
  3049. $item = array (
  3050. 'recepitTitleMark' => $titleMark,
  3051. 'bindStatus' => $bindStatus,
  3052. 'iid' => $invoiceDetail ['iid'],
  3053. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  3054. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3055. 'receivablesPrice' => $receivablesPrice,
  3056. 'OriginalPrice' => $receivablesPrice,
  3057. 'receivablesMessage' => $receivablesMessage,
  3058. 'receivablesSerial' => $receivablesSerial,
  3059. 'receivablesBank' => $receivablesBank,
  3060. 'receivablesDate' => $receivablesDate,
  3061. 'inputStaff' => $this->staff [0] ['username'],
  3062. 'accountClerk' => $this->staff [0] ['username'],
  3063. 'date' => date ( "Y-m-d" ),
  3064. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3065. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3066. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3067. );
  3068. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3069. $item = array ();
  3070. // 收款操作日志
  3071. $item = array (
  3072. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3073. );
  3074. $item += array (
  3075. 'date' => date ( "Y-m-d" ),
  3076. 'status' => 1,
  3077. 'img' => $this->staff [0] ['avatar'],
  3078. 'username' => $this->staff [0] ['username'],
  3079. 'uid' => $this->staff [0] ['sid'],
  3080. 'category' => $this->staff [0] ['category'],
  3081. 'irid' => $irid
  3082. );
  3083. $invoiceROLog->setInvoiceROLog ( $item );
  3084. // 收款统计
  3085. $invoiceStatistics = new invoiceStatistics ();
  3086. $item = array (
  3087. 'date' => $receivablesDate,
  3088. 'priceClass' => 2,
  3089. 'irid' => $irid,
  3090. 'cid' => $invoiceDetail ['cid'],
  3091. 'staff' => $invoiceDetail ['sid'],
  3092. 'receivablesPrice' => $receivablesPrice
  3093. );
  3094. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3095. // 收款 入 发票
  3096. $detail = $invoiceDetail;
  3097. $iridString = "";
  3098. if (empty ( $detail ['irid'] ))
  3099. $iridString = $irid;
  3100. else
  3101. $iridString = $detail ['irid'] . ',' . $irid;
  3102. $item = array (
  3103. 'irid' => $iridString,
  3104. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3105. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3106. 'iid' => $detail ['iid']
  3107. );
  3108. $invoiceReceivables = new invoiceReceivables ();
  3109. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3110. if ($detail ['invoicePrice'] <= $sum)
  3111. $item += array (
  3112. 'untreadStatus' => 3
  3113. );
  3114. $invoice->setInvoiceByCondition ( $item );
  3115. // 操作日志
  3116. $item = array (
  3117. 'date' => date ( "Y-m-d H:i:s" ),
  3118. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3119. 'status' => 8,
  3120. 'img' => $this->staff [0] ['avatar'],
  3121. 'username' => $this->staff [0] ['username'],
  3122. 'uid' => $this->staff [0] ['sid'],
  3123. 'category' => $this->staff [0] ['category'],
  3124. 'iid' => $detail ['iid']
  3125. );
  3126. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3127. // 入账汇总
  3128. $invoiceStatistics = new invoiceStatistics ();
  3129. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3130. // $accountPrice = 0;
  3131. // foreach ( $list as $key => $value ) {
  3132. // $accountPrice += $value ['receivablesPrice'];
  3133. // }
  3134. $item = array (
  3135. 'date' => $receivablesDate,
  3136. 'priceClass' => 3,
  3137. 'cid' => $invoiceDetail ['cid'],
  3138. 'staff' => $invoiceDetail ['sid'],
  3139. 'accountPrice' => $receivablesPrice
  3140. );
  3141. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3142. // 公司流水记录
  3143. Doo::loadModel ( 'wasteBook' );
  3144. $wasteBook = new wasteBook ();
  3145. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3146. $accountBank = '';
  3147. if ($receivablesBank == '纵横广发') {
  3148. $accountBank = 'CGBDeposit';
  3149. } elseif ($receivablesBank == '纵横工行') {
  3150. $accountBank = 'ICBCDeposit';
  3151. } elseif ($receivablesBank == '华润银行') {
  3152. $accountBank = 'HUADeposit';
  3153. } elseif ($receivablesBank == '个人广发') {
  3154. $accountBank = 'PersonalDeposit';
  3155. }
  3156. if (empty ( $abDetail )) {
  3157. $item = array (
  3158. 'dataID' => $irid,
  3159. 'expensesType' => 1,
  3160. 'accountType' => 7,
  3161. 'accountPrice' => $receivablesPrice,
  3162. 'accountPriceShow' => $receivablesPrice,
  3163. 'accountBank' => $accountBank,
  3164. 'category' => $this->staff [0] ['category'],
  3165. 'cid' => $this->staff [0] ['cid'],
  3166. 'name' => $this->staff [0] ['username'],
  3167. 'sid' => $this->staff [0] ['sid'],
  3168. 'inputDate' => date ( "Y-m-d H:i:s" )
  3169. );
  3170. $wasteBook->setAccountBookStatistics ( $item );
  3171. }
  3172. Doo::db ()->commit ();
  3173. }
  3174. return '/invoiceReceivables';
  3175. }
  3176. /**
  3177. * 录入收款数据
  3178. * @return string
  3179. */
  3180. function invoiceReceivablesDo() {
  3181. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3182. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3183. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3184. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3185. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3186. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3187. Doo::loadModel ( 'invoiceReceivables' );
  3188. $invoiceReceivables = new invoiceReceivables ();
  3189. Doo::loadModel ( 'invoiceROLog' );
  3190. $invoiceROLog = new invoiceROLog ();
  3191. Doo::loadModel ( 'invoiceStatistics' );
  3192. $invoiceStatistics = new invoiceStatistics ();
  3193. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3194. $item = array (
  3195. 'receivablesPrice' => $receivablesPrice,
  3196. 'OriginalPrice' => $receivablesPrice,
  3197. 'receivablesMessage' => $receivablesMessage,
  3198. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3199. 'receivablesBank' => $receivablesBank,
  3200. 'receivablesDate' => $receivablesDate,
  3201. 'inputStaff' => $this->staff [0] ['username'],
  3202. 'date' => date ( "Y-m-d" ),
  3203. 'receivablesCategory' => $receivablesCategory,
  3204. 'receivablesStaff' => $receivablesStaff
  3205. );
  3206. if ($receivablesCategory != 'PUBLIC') {
  3207. $item += array (
  3208. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3209. 'inputType' => 1
  3210. );
  3211. }
  3212. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3213. $item = array ();
  3214. // 收款操作日志
  3215. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3216. $item = array (
  3217. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3218. );
  3219. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3220. $item = array (
  3221. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3222. );
  3223. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3224. $receivablesStaff = explode ( '-', $receivablesStaff );
  3225. $item = array (
  3226. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3227. );
  3228. }
  3229. $item += array (
  3230. 'date' => date ( "Y-m-d" ),
  3231. 'status' => 1,
  3232. 'img' => $this->staff [0] ['avatar'],
  3233. 'username' => $this->staff [0] ['username'],
  3234. 'uid' => $this->staff [0] ['sid'],
  3235. 'category' => $this->staff [0] ['category'],
  3236. 'irid' => $irid
  3237. );
  3238. $invoiceROLog->setInvoiceROLog ( $item );
  3239. $item = array (
  3240. 'date' => $receivablesDate,
  3241. 'priceClass' => 2,
  3242. 'irid' => $irid,
  3243. 'receivablesPrice' => $receivablesPrice
  3244. );
  3245. if ($receivablesCategory != 'PUBLIC') {
  3246. $receivablesCategory = explode ( ":", $receivablesCategory );
  3247. $item += array (
  3248. 'cid' => $receivablesCategory [0]
  3249. );
  3250. }
  3251. if ($receivablesStaff2 != 'PUBLIC') {
  3252. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3253. $item += array (
  3254. 'staff' => $receivablesStaff [0]
  3255. );
  3256. }
  3257. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3258. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3259. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3260. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3261. if ($toparty != 0)
  3262. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3263. // 公司流水记录
  3264. Doo::loadModel ( 'wasteBook' );
  3265. $wasteBook = new wasteBook ();
  3266. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3267. $accountBank = '';
  3268. if ($receivablesBank == '纵横广发') {
  3269. $accountBank = 'CGBDeposit';
  3270. } elseif ($receivablesBank == '纵横工行') {
  3271. $accountBank = 'ICBCDeposit';
  3272. } elseif ($receivablesBank == '华润银行') {
  3273. $accountBank = 'HUADeposit';
  3274. } elseif ($receivablesBank == '个人广发') {
  3275. $accountBank = 'PersonalDeposit';
  3276. }
  3277. $item = array (
  3278. 'dataID' => $irid,
  3279. 'expensesType' => 1,
  3280. 'accountType' => 7,
  3281. 'accountPriceShow' => $receivablesPrice,
  3282. 'accountPrice' => $receivablesPrice,
  3283. 'accountBank' => $accountBank,
  3284. 'category' => $this->staff [0] ['category'],
  3285. 'cid' => $this->staff [0] ['cid'],
  3286. 'name' => $this->staff [0] ['username'],
  3287. 'sid' => $this->staff [0] ['sid'],
  3288. 'inputDate' => date ( "Y-m-d H:i:s" )
  3289. );
  3290. $wasteBook->setAccountBookStatistics ( $item );
  3291. }
  3292. return "/invoiceReceivables";
  3293. }
  3294. /**
  3295. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3296. */
  3297. function invoiceReceivablesClaim() {
  3298. Doo::loadModel ( 'invoiceReceivables' );
  3299. $invoiceReceivables = new invoiceReceivables ();
  3300. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3301. $this->data ['receivablesList'] = $receivablesList;
  3302. $this->data ['memu'] = "invoice";
  3303. $this->data ['staff'] = $this->staff;
  3304. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3305. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3306. }
  3307. function invoiceReceivablesTitleMarkSet() {
  3308. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3309. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3310. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3311. die ( 'illegal request' );
  3312. Doo::loadModel ( 'invoiceReceivables' );
  3313. $invoiceReceivables = new invoiceReceivables ();
  3314. Doo::loadClass ( 'XDeode' );
  3315. $XDeode = new XDeode ( 5 );
  3316. $irid = $XDeode->decode ( $iridKey );
  3317. if (! is_numeric ( $irid ))
  3318. die ( 'illegal request' );
  3319. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3320. $invoiceReceivables->update ( array (
  3321. 'where' => 'irid = ' . $irid
  3322. ) );
  3323. return '/invoiceReceivablesClaim';
  3324. }
  3325. /**
  3326. * 更新收款相关数据
  3327. */
  3328. function invoiceReceivablesUpdateClaim() {
  3329. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3330. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3331. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3332. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3333. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3334. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3335. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3336. if (empty ( $claimKey ))
  3337. die ( 'illegal request' );
  3338. Doo::loadModel ( 'invoiceReceivables' );
  3339. $invoiceReceivables = new invoiceReceivables ();
  3340. Doo::loadModel ( 'invoiceROLog' );
  3341. $invoiceROLog = new invoiceROLog ();
  3342. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3343. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3344. if (empty ( $detail ))
  3345. die ( 'illegal request' );
  3346. $invoiceReceivables = new invoiceReceivables ();
  3347. $item = array (
  3348. 'irid' => $detail ['irid']
  3349. );
  3350. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3351. $item += array (
  3352. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3353. );
  3354. }
  3355. if (! empty ( $receivablesCategory ))
  3356. $item += array (
  3357. 'receivablesCategory' => $receivablesCategory
  3358. );
  3359. if (! empty ( $receivablesStaff ))
  3360. $item += array (
  3361. 'receivablesStaff' => $receivablesStaff
  3362. );
  3363. if (! empty ( $receivablesPrice ))
  3364. $item += array (
  3365. 'receivablesPrice' => $receivablesPrice
  3366. );
  3367. if (! empty ( $receivablesMessage ))
  3368. $item += array (
  3369. 'receivablesMessage' => $receivablesMessage
  3370. );
  3371. if (! empty ( $receivablesBank ))
  3372. $item += array (
  3373. 'receivablesBank' => $receivablesBank
  3374. );
  3375. if (! empty ( $receivablesDate ))
  3376. $item += array (
  3377. 'receivablesDate' => $receivablesDate
  3378. );
  3379. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3380. // 收款操作日志
  3381. $item = array ();
  3382. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3383. $item = array (
  3384. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3385. );
  3386. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3387. $item = array (
  3388. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3389. );
  3390. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3391. $receivablesStaff = explode ( '-', $receivablesStaff );
  3392. $item = array (
  3393. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3394. );
  3395. }
  3396. $item += array (
  3397. 'date' => date ( "Y-m-d" ),
  3398. 'status' => 1,
  3399. 'img' => $this->staff [0] ['avatar'],
  3400. 'username' => $this->staff [0] ['username'],
  3401. 'uid' => $this->staff [0] ['sid'],
  3402. 'category' => $this->staff [0] ['category'],
  3403. 'irid' => $detail ['irid']
  3404. );
  3405. $invoiceROLog->setInvoiceROLog ( $item );
  3406. return '/invoiceReceivablesAS';
  3407. }
  3408. function invoiceReceivablesDelete() {
  3409. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3410. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3411. if ($skll != '删除到款')
  3412. die ( 'illegal request' );
  3413. if (empty ( $claimKey ))
  3414. die ( 'illegal request' );
  3415. Doo::loadModel ( 'invoiceReceivables' );
  3416. $invoiceReceivables = new invoiceReceivables ();
  3417. $con = ' and bindStatus=0 ';
  3418. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3419. if (empty ( $detail ))
  3420. die ( 'illegal request' );
  3421. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3422. // 扣除收款汇总信息 汇总
  3423. Doo::loadModel ( 'invoiceStatistics' );
  3424. $invoiceStatistics = new invoiceStatistics ();
  3425. $item = array (
  3426. 'date' => $detail ['receivablesDate'],
  3427. 'priceClass' => 2,
  3428. 'irid' => $detail ['irid'],
  3429. 'receivablesPrice' => - $detail ['receivablesPrice']
  3430. );
  3431. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3432. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3433. $item += array (
  3434. 'cid' => $receivablesCategory [0]
  3435. );
  3436. }
  3437. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3438. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3439. $item += array (
  3440. 'staff' => $receivablesStaff [0]
  3441. );
  3442. }
  3443. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3444. // 公司流水-删除时删除流水
  3445. Doo::loadModel ( 'wasteBook' );
  3446. $wasteBook = new wasteBook ();
  3447. $wasteBook->delete ( array (
  3448. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3449. 'limit' => 1
  3450. ) );
  3451. return '/invoiceReceivablesAS';
  3452. }
  3453. /**
  3454. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3455. */
  3456. function invoiceReceivablesAscription() {
  3457. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3458. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3459. Doo::loadModel ( 'invoiceReceivables' );
  3460. $invoiceReceivables = new invoiceReceivables ();
  3461. Doo::loadModel ( 'invoiceROLog' );
  3462. $invoiceROLog = new invoiceROLog ();
  3463. Doo::loadModel ( 'invoiceStatistics' );
  3464. $invoiceStatistics = new invoiceStatistics ();
  3465. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3466. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3467. $item = array (
  3468. 'irid' => $detail ['irid'],
  3469. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3470. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3471. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3472. 'recepitTitleMark' => $recepitTitleMark,
  3473. 'source' => 1
  3474. );
  3475. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3476. $item = array (
  3477. 'date' => date ( "Y-m-d" ),
  3478. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3479. 'status' => 2,
  3480. 'img' => $this->staff [0] ['avatar'],
  3481. 'username' => $this->staff [0] ['username'],
  3482. 'uid' => $this->staff [0] ['sid'],
  3483. 'category' => $this->staff [0] ['category'],
  3484. 'irid' => $irid
  3485. );
  3486. $invoiceROLog->setInvoiceROLog ( $item );
  3487. $item = array (
  3488. 'cid' => $this->staff [0] ['cid'],
  3489. 'staff' => $this->staff [0] ['sid']
  3490. );
  3491. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3492. }
  3493. return "/invoiceReceivablesClaim";
  3494. }
  3495. /**
  3496. */
  3497. function invoiceMyReceivables() {
  3498. Doo::loadModel ( 'invoiceReceivables' );
  3499. $invoiceReceivables = new invoiceReceivables ();
  3500. Doo::loadModel ( 'invoiceStatistics' );
  3501. $invoiceStatistics = new invoiceStatistics ();
  3502. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3503. $year = date ( "Y" );
  3504. $tmp_date = date ( "Ym" );
  3505. $tmp_year = substr ( $tmp_date, 0, 4 );
  3506. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3507. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3508. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3509. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3510. $htm = $this->showCache ( $path );
  3511. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3512. $this->data ['isMonth'] = $isMonth;
  3513. $this->data ['htm'] = $htm;
  3514. $this->data ['list'] = $list;
  3515. $this->data ['memu'] = "invoice";
  3516. $this->data ['staff'] = $this->staff;
  3517. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3518. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3519. }
  3520. /**
  3521. * 纸票管理
  3522. */
  3523. function invoicePaper() {
  3524. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3525. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3526. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3527. $this->data ['dateString'] = $date;
  3528. $this->data ['status'] = $status;
  3529. $this->data ['invoiceType'] = $invoiceType;
  3530. $this->data ['memu'] = "invoice";
  3531. $this->data ['staff'] = $this->staff;
  3532. $this->data ['receiptMemu'] = 'invoicePaper';
  3533. $this->render ( "/admin/invoicePaper", $this->data );
  3534. }
  3535. /**
  3536. * 获得纸票分页数据
  3537. */
  3538. function ajaxGetinvoicePaperAchieve() {
  3539. Doo::loadModel ( 'invoicePaper' );
  3540. $invoicePaper = new invoicePaper ();
  3541. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3542. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3543. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3544. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3545. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3546. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3547. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3548. $MebSea = $this->get_args ( 'search' );
  3549. $MebSea = $MebSea ['value'];
  3550. $page_size = $length;
  3551. $con = '';
  3552. if ($status == 'ALL')
  3553. $con = ' where 1 ';
  3554. elseif ($status == 'PRINTED')
  3555. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3556. elseif ($status == 'UNPRINT')
  3557. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3558. elseif ($status == 'TICKET')
  3559. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3560. if ($invoiceType == 'ORDINARY')
  3561. $con .= ' and a.invoiceType=0 ';
  3562. elseif ($invoiceType == 'SPECIAL')
  3563. $con .= ' and a.invoiceType=1 ';
  3564. $dateArr = explode ( ':', $date );
  3565. $D1 = $dateString = '';
  3566. $D2 = '';
  3567. if (! empty ( $date )) {
  3568. $D1 = $dateArr [0];
  3569. if (isset ( $dateArr [1] ))
  3570. $D2 = $dateArr [1];
  3571. else
  3572. $D2 = '';
  3573. $dateString = $D1 . " : " . $D2;
  3574. }
  3575. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3576. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3577. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3578. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3579. if (! empty ( $MebSea ))
  3580. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3581. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3582. $sql = ' ' . $con;
  3583. $limit = $page . ',' . $page_size;
  3584. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3585. $paperList = array ();
  3586. foreach ( $list as $key => $value ) {
  3587. $irDetail = array ();
  3588. if ($value ['iid'] == 0)
  3589. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3590. else
  3591. array_push ( $irDetail, '' );
  3592. array_push ( $irDetail, $value ['invoiceCode'] );
  3593. array_push ( $irDetail, $value ['invoiceNo'] );
  3594. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3595. if ($value ['invoiceType'] == 1)
  3596. array_push ( $irDetail, $value ['invoiceCompany'] );
  3597. else
  3598. array_push ( $irDetail, $value ['invoiceTitle'] );
  3599. if ($value ['invoiceType'] == 1)
  3600. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3601. else
  3602. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3603. array_push ( $irDetail, $value ['invoiceElement'] );
  3604. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3605. array_push ( $irDetail, $value ['printTime'] );
  3606. array_push ( $paperList, $irDetail );
  3607. }
  3608. // $approvalListJson = json_encode ( $approvalList );
  3609. $recordsFiltered = $invoiceTotal;
  3610. echo json_encode ( array (
  3611. "draw" => intval ( $draw ),
  3612. "recordsTotal" => intval ( $invoiceTotal ),
  3613. "recordsFiltered" => intval ( $recordsFiltered ),
  3614. "data" => $paperList
  3615. ), JSON_UNESCAPED_UNICODE );
  3616. }
  3617. function invoicePaperDel() {
  3618. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3619. $XDeode = new XDeode ( 5 );
  3620. $ipid = $XDeode->decode ( $ipidKey );
  3621. if (empty ( $ipid ))
  3622. die ( 'illegal request' );
  3623. Doo::loadModel ( 'invoicePaper' );
  3624. $invoicePaper = new invoicePaper ();
  3625. $invoicePaper->delete ( array (
  3626. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3627. 'limit' => 1
  3628. ) );
  3629. return '/invoicePaper';
  3630. }
  3631. /**
  3632. * 添加纸质发票号
  3633. */
  3634. function invoicePaperAdd() {
  3635. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3636. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3637. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3638. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3639. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3640. $sum = $invoiceNoStart + $invoiceNoTotal;
  3641. if (empty ( $sum ))
  3642. die ( 'illegal request' );
  3643. // echo $invoiceNoStart;
  3644. // echo $sum;
  3645. // echo strlen((int)$invoiceNoStart);
  3646. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3647. Doo::db ()->beginTransaction ();
  3648. // 批量存储纸质发票
  3649. $date = date ( "Y-m-d H:i:s" );
  3650. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3651. VALUES ';
  3652. $paperList = array ();
  3653. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3654. // 数字前面自加0
  3655. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3656. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3657. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3658. array_push ( $paperList, $paperSql );
  3659. }
  3660. if (empty ( $paperList ))
  3661. die ( 'illegal request' );
  3662. $sql = $sql . implode ( ',', $paperList );
  3663. Doo::db ()->query ( $sql );
  3664. Doo::db ()->commit ();
  3665. return 'invoicePaper';
  3666. }
  3667. die ( 'illegal request' );
  3668. }
  3669. /**
  3670. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3671. */
  3672. function invoiceBindReceivables() {
  3673. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3674. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3675. Doo::loadModel ( 'invoice' );
  3676. $invoice = new invoice ();
  3677. Doo::loadModel ( 'invoiceReceivables' );
  3678. $invoiceReceivables = new invoiceReceivables ();
  3679. Doo::loadModel ( 'invoiceOperationLog' );
  3680. $invoiceOperationLog = new invoiceOperationLog ();
  3681. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3682. die ( 'illegal request' );
  3683. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3684. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3685. if (empty ( $detail ) && empty ( $detailM ))
  3686. die ( 'illegal request' );
  3687. if ($detail ['untreadStatus'] == 3)
  3688. die ( 'illegal request' );
  3689. // 修改 绑定状态改为 金额
  3690. $invoiceReceivables = new invoiceReceivables ();
  3691. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3692. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3693. $item = array (
  3694. 'bindPrice' => $invoicePrice
  3695. );
  3696. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3697. $item = array (
  3698. 'bindPrice' => $invoicePrice,
  3699. 'bindStatus' => 1,
  3700. 'bindDate' => date ( "Y-m-d H:i:s" )
  3701. );
  3702. } else {
  3703. die ( 'illegal request' );
  3704. }
  3705. if ($detailM ['iid'] == 0) {
  3706. $item += array (
  3707. 'iid' => $detail ['iid']
  3708. );
  3709. } else {
  3710. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3711. array_push ( $iidExtend, $detail ['iid'] );
  3712. $item += array (
  3713. 'iidExtend' => implode ( ',', $iidExtend )
  3714. );
  3715. }
  3716. $titleMark = $detail ['invoiceTitle'];
  3717. if (! empty ( $detail ['invoiceCompany'] ))
  3718. $titleMark = $detail ['invoiceCompany'];
  3719. $item += array (
  3720. 'irid' => $detailM ['irid'],
  3721. 'recepitTitleMark' => $titleMark,
  3722. 'accountClerk' => $this->staff [0] ['username']
  3723. );
  3724. // 如何没有人收款 则自动绑定收款
  3725. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3726. $item += array (
  3727. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3728. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3729. );
  3730. }
  3731. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3732. $iridString = "";
  3733. if (empty ( $detail ['irid'] ))
  3734. $iridString = $detailM ['irid'];
  3735. else
  3736. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3737. $item = array (
  3738. 'iid' => $detail ['iid'],
  3739. 'irid' => $iridString
  3740. );
  3741. $invoiceReceivables = new invoiceReceivables ();
  3742. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3743. if ($detail ['invoicePrice'] <= $sum)
  3744. $item += array (
  3745. 'untreadStatus' => 3,
  3746. 'bindTime' => date ( "Y-m-d H:i:s" )
  3747. );
  3748. // print_r($item);
  3749. // echo $sum;die;
  3750. $invoice->setInvoiceByCondition ( $item );
  3751. // 操作日志
  3752. $item = array (
  3753. 'date' => date ( "Y-m-d H:i:s" ),
  3754. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3755. 'status' => 8,
  3756. 'img' => $this->staff [0] ['avatar'],
  3757. 'username' => $this->staff [0] ['username'],
  3758. 'uid' => $this->staff [0] ['sid'],
  3759. 'category' => $this->staff [0] ['category'],
  3760. 'iid' => $detail ['iid']
  3761. );
  3762. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3763. Doo::loadModel ( 'invoiceStatistics' );
  3764. $invoiceStatistics = new invoiceStatistics ();
  3765. $item = array (
  3766. 'date' => $detailM ['receivablesDate'],
  3767. 'priceClass' => 3,
  3768. 'cid' => $detail ['cid'],
  3769. 'staff' => $detail ['sid'],
  3770. 'accountPrice' => $detailM ['receivablesPrice']
  3771. );
  3772. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3773. // 公司流水记录
  3774. // Doo::loadModel ( 'wasteBook' );
  3775. // $wasteBook = new wasteBook ();
  3776. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3777. // $accountBank='';
  3778. // if ($detailM ['receivablesBank']=='纵横广发'){
  3779. // $accountBank='CGBDeposit';
  3780. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3781. // $accountBank='ICBCDeposit';
  3782. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3783. // $accountBank='HUADeposit';
  3784. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3785. // $accountBank='PersonalDeposit';
  3786. // }
  3787. // if (empty($abDetail)){
  3788. // $item = array (
  3789. // 'dataID' => $detail ['iid'],
  3790. // 'expensesType' => 1,
  3791. // 'accountType' => 8,
  3792. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3793. // 'accountPrice'=>$detail ['invoicePrice'],
  3794. // 'accountBank'=>$accountBank,
  3795. // 'category'=>$this->staff[0]['category'],
  3796. // 'cid'=>$this->staff[0]['cid'],
  3797. // 'name'=>$this->staff[0]['username'],
  3798. // 'sid'=>$this->staff[0]['sid'],
  3799. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3800. // );
  3801. // $wasteBook->setAccountBookStatistics($item);
  3802. // }
  3803. return "/invoiceReceivables";
  3804. }
  3805. /**
  3806. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3807. */
  3808. function invoiceAggregate() {
  3809. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3810. Doo::loadModel ( 'invoiceStatistics' );
  3811. $invoiceStatistics = new invoiceStatistics ();
  3812. Doo::loadModel ( 'L_category' );
  3813. $Lcategory = new L_category ();
  3814. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3815. $LcategoryList = $Lcategory->getCategory ();
  3816. // print_r($isList);
  3817. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3818. foreach ( $LcategoryList as $key => $value ) {
  3819. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3820. $month = 1;
  3821. $invoicePriceYear = 0;
  3822. $receivablesPriceYear = 0;
  3823. $accountPriceYear = 0;
  3824. for(; $month <= 12; $month ++) {
  3825. $flag = true;
  3826. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3827. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3828. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3829. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3830. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3831. ';
  3832. $invoicePriceYear += $v ['invoicePrice'];
  3833. $receivablesPriceYear += $v ['receivablesPrice'];
  3834. $accountPriceYear += $v ['accountPrice'];
  3835. $flag = false;
  3836. break;
  3837. }
  3838. }
  3839. if ($flag)
  3840. $html .= '<td class="taR"></td>
  3841. <td class="taR"></td>
  3842. <td class="taR"><b></b></td>
  3843. ';
  3844. }
  3845. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3846. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3847. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3848. ';
  3849. $html .= '</tr>';
  3850. }
  3851. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3852. $invoicePriceYear = 0;
  3853. $receivablesPriceYear = 0;
  3854. $accountPriceYear = 0;
  3855. for($month = 1; $month <= 12; $month ++) {
  3856. $flag = true;
  3857. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3858. if ($month == $v ['month']) {
  3859. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3860. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3861. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3862. ';
  3863. $invoicePriceYear += $v ['invoicePrice'];
  3864. $receivablesPriceYear += $v ['receivablesPrice'];
  3865. $accountPriceYear += $v ['accountPrice'];
  3866. $flag = false;
  3867. break;
  3868. }
  3869. }
  3870. if ($flag) {
  3871. $html .= '<td class="taR"></td>
  3872. <td class="taR"></td>
  3873. <td class="taR"><b></b></td>
  3874. ';
  3875. }
  3876. }
  3877. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3878. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3879. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3880. ';
  3881. $html .= '</tr>';
  3882. // print_r($isList);
  3883. $this->data ['html'] = $html;
  3884. $this->data ['LcategoryList'] = $LcategoryList;
  3885. $this->data ['isList'] = $isList;
  3886. $this->data ['year'] = $year;
  3887. $this->data ['memu'] = "invoice";
  3888. $this->data ['staff'] = $this->staff;
  3889. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3890. $this->render ( "/admin/invoiceAggregate", $this->data );
  3891. }
  3892. function invoiceAggregateStaff() {
  3893. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3894. Doo::loadModel ( 'invoiceStatistics' );
  3895. $invoiceStatistics = new invoiceStatistics ();
  3896. Doo::loadModel ( 'L_category' );
  3897. $Lcategory = new L_category ();
  3898. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3899. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3900. $cStaff = $Lcategory->getCategoryStaff ();
  3901. $html = '';
  3902. foreach ( $cStaff as $key => $value ) {
  3903. $categoryFir = true;
  3904. foreach ( $value ['staff'] as $k => $v ) {
  3905. if ($categoryFir) {
  3906. $width = count ( $value ['staff'] ) + 1;
  3907. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3908. $categoryFir = false;
  3909. } else
  3910. $html .= '<tr>';
  3911. $html .= '<th>' . $v ['username'] . '</th>';
  3912. $invoicePriceStaffYear = 0;
  3913. $receivablesPriceStaffYear = 0;
  3914. $accountPriceStaffYear = 0;
  3915. for($month = 1; $month <= 12; $month ++) {
  3916. $flag = true;
  3917. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3918. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3919. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3920. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3921. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3922. ';
  3923. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3924. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3925. $accountPriceStaffYear += $slv ['accountPrice'];
  3926. $flag = false;
  3927. break;
  3928. }
  3929. }
  3930. if ($flag)
  3931. $html .= '<td class="taR"></td>
  3932. <td class="taR"></td>
  3933. <td class="taR"><b></b></td>
  3934. ';
  3935. }
  3936. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3937. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3938. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3939. ';
  3940. }
  3941. $html .= '</tr>';
  3942. // 小计
  3943. if (! empty ( $value ['staff'] )) {
  3944. $html .= '<tr><th class="taR">小计</th>';
  3945. $invoicePriceStaffYear = 0;
  3946. $receivablesPriceStaffYear = 0;
  3947. $accountPriceStaffYear = 0;
  3948. for($month = 1; $month <= 12; $month ++) {
  3949. $flag = true;
  3950. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3951. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3952. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3953. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3954. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3955. ';
  3956. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3957. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3958. $accountPriceStaffYear += $slv ['accountPrice'];
  3959. $flag = false;
  3960. break;
  3961. }
  3962. }
  3963. if ($flag)
  3964. $html .= '<td class="taR"></td>
  3965. <td class="taR"></td>
  3966. <td class="taR"><b></b></td>
  3967. ';
  3968. }
  3969. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3970. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3971. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3972. ';
  3973. $html .= '</tr>';
  3974. }
  3975. }
  3976. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3977. $invoicePriceYear = 0;
  3978. $receivablesPriceYear = 0;
  3979. $accountPriceYear = 0;
  3980. for($month = 1; $month <= 12; $month ++) {
  3981. $flag = true;
  3982. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3983. if ($month == $v ['month']) {
  3984. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3985. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3986. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3987. ';
  3988. $invoicePriceYear += $v ['invoicePrice'];
  3989. $receivablesPriceYear += $v ['receivablesPrice'];
  3990. $accountPriceYear += $v ['accountPrice'];
  3991. $flag = false;
  3992. break;
  3993. }
  3994. }
  3995. if ($flag)
  3996. $html .= '<td class="taR"></td>
  3997. <td class="taR"></td>
  3998. <td class="taR"><b></b></td>
  3999. ';
  4000. }
  4001. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4002. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4003. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4004. ';
  4005. $html .= '</tr>';
  4006. $this->data ['html'] = $html;
  4007. $this->data ['isList'] = $toteList;
  4008. $this->data ['year'] = $year;
  4009. $this->data ['memu'] = "invoice";
  4010. $this->data ['staff'] = $this->staff;
  4011. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4012. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4013. }
  4014. function invoiceAggregateCategory() {
  4015. Doo::loadClass ( 'XDeode' );
  4016. $XDeode = new XDeode ( 5 );
  4017. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4018. $cid = $XDeode->decode ( $cid );
  4019. if (! is_numeric ( $cid ))
  4020. die ( 'illegal request' );
  4021. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4022. Doo::loadModel ( 'invoiceStatistics' );
  4023. $invoiceStatistics = new invoiceStatistics ();
  4024. Doo::loadModel ( 'staff' );
  4025. $staff = new staff ();
  4026. $list = $staff->getStaffByCid ( $cid );
  4027. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4028. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4029. if (empty ( $list ))
  4030. die ( '该办事处没有成员' );
  4031. $htmlA = $htmlB = $htmlC = $html = '';
  4032. foreach ( $list as $key => $value ) {
  4033. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4034. $htmlB = '<tr><th class="taC">收款</th>';
  4035. $htmlC = '<tr><th class="taC">入账</th>';
  4036. $invoicePriceStaffYear = 0;
  4037. $receivablesPriceStaffYear = 0;
  4038. $accountPriceStaffYear = 0;
  4039. for($month = 1; $month <= 12; $month ++) {
  4040. $flag = true;
  4041. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4042. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4043. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4044. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4045. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4046. $invoicePriceStaffYear += $v ['invoicePrice'];
  4047. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4048. $accountPriceStaffYear += $v ['accountPrice'];
  4049. $flag = false;
  4050. break;
  4051. }
  4052. }
  4053. if ($flag) {
  4054. $htmlA .= '<td class="taR">-</td>';
  4055. $htmlB .= '<td class="taR">-</td>';
  4056. $htmlC .= '<td class="taR"><b>-</b></td>';
  4057. }
  4058. }
  4059. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4060. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4061. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4062. $htmlA .= '</tr>';
  4063. $htmlB .= '</tr>';
  4064. $htmlC .= '</tr>';
  4065. $html .= $htmlA . $htmlB . $htmlC;
  4066. }
  4067. $htmlA = $htmlB = $htmlC = "";
  4068. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4069. $htmlB = '<tr><th class="taC">收款</th>';
  4070. $htmlC = '<tr><th class="taC">入账</th>';
  4071. $invoicePriceStaffYear = 0;
  4072. $receivablesPriceStaffYear = 0;
  4073. $accountPriceStaffYear = 0;
  4074. for($month = 1; $month <= 12; $month ++) {
  4075. $flag = true;
  4076. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4077. if ($month == $v ['month']) {
  4078. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4079. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4080. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4081. $invoicePriceStaffYear += $v ['invoicePrice'];
  4082. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4083. $accountPriceStaffYear += $v ['accountPrice'];
  4084. $flag = false;
  4085. break;
  4086. }
  4087. }
  4088. if ($flag) {
  4089. $htmlA .= '<td class="taR">-</td>';
  4090. $htmlB .= '<td class="taR">-</td>';
  4091. $htmlC .= '<td class="taR"><b>-</b></td>';
  4092. }
  4093. }
  4094. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4095. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4096. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4097. $htmlA .= '</tr>';
  4098. $htmlB .= '</tr>';
  4099. $htmlC .= '</tr>';
  4100. $html .= $htmlA . $htmlB . $htmlC;
  4101. $this->data ['html'] = $html;
  4102. $this->data ['cidKey'] = $cidKey;
  4103. $this->data ['slist'] = $list;
  4104. $this->data ['isList'] = $toteList;
  4105. $this->data ['year'] = $year;
  4106. $this->data ['memu'] = "invoice";
  4107. $this->data ['staff'] = $this->staff;
  4108. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4109. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4110. }
  4111. /**
  4112. * 办事处汇总信息
  4113. */
  4114. function invoiceAggregateCategoryDetail() {
  4115. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4116. Doo::loadClass ( 'XDeode' );
  4117. $XDeode = new XDeode ( 5 );
  4118. Doo::loadModel ( 'invoiceStatistics' );
  4119. $invoiceStatistics = new invoiceStatistics ();
  4120. Doo::loadModel ( 'L_category' );
  4121. $category = new L_category ();
  4122. Doo::loadModel ( 'invoice' );
  4123. $invoice = new invoice ();
  4124. Doo::loadModel ( 'staff' );
  4125. $staff = new staff ();
  4126. Doo::loadModel ( "invoiceCategoryManage" );
  4127. $invoiceCategoryManage = new invoiceCategoryManage ();
  4128. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4129. $cidList = array ();
  4130. foreach ( $imcStaff as $key => $value ) {
  4131. array_push ( $cidList, $value ['cid'] );
  4132. if (empty ( $cidKey ))
  4133. $cidKey = $XDeode->encode ( $value ['cid'] );
  4134. }
  4135. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4136. $cid = $XDeode->decode ( $cidKey );
  4137. $month = date ( "m", strtotime ( "-1 month" ) );
  4138. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4139. $redis = new Redis ();
  4140. $redis->connect ( '127.0.0.1', '6379' );
  4141. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4142. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4143. if (empty ( $redisValue )) {
  4144. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4145. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4146. // 获得办事处人员下的汇总
  4147. $slist = $staff->getStaffByCid ( $cid );
  4148. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4149. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4150. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4151. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4152. foreach ( $slist as $key => $value ) {
  4153. $slist [$key] ['invoicePrice'] = 0;
  4154. $slist [$key] ['receivablesPrice'] = 0;
  4155. $slist [$key] ['accountPrice'] = 0;
  4156. $slist [$key] ['invoiceAllPrice'] = 0;
  4157. $slist [$key] ['receivablesAllPrice'] = 0;
  4158. $slist [$key] ['accountAllPrice'] = 0;
  4159. $slist [$key] ['schedule'] = 0;
  4160. $slist [$key] ['invoiceMonthPrice'] = 0;
  4161. $slist [$key] ['receivablesMonthPrice'] = 0;
  4162. $slist [$key] ['accountMonthPrice'] = 0;
  4163. foreach ( $ismsbMonth as $y => $l ) {
  4164. if ($value ['sid'] == $l ['staff']) {
  4165. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4166. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4167. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4168. }
  4169. }
  4170. foreach ( $ismsb as $k => $v ) {
  4171. if ($value ['sid'] == $v ['staff']) {
  4172. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4173. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4174. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4175. }
  4176. }
  4177. foreach ( $ISAS as $e => $a ) {
  4178. if ($value ['sid'] == $a ['staff']) {
  4179. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4180. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4181. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4182. }
  4183. }
  4184. if (isset ( $scheduleStaff [$value ['sid']] ))
  4185. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4186. }
  4187. $this->data ['cidKey'] = $cidKey;
  4188. $schedule = ( int ) ($schedule * 100);
  4189. $this->data ['slist'] = $slist;
  4190. $this->data ['isMC'] = $isMC;
  4191. $this->data ['schedule'] = $schedule;
  4192. $slist = json_encode ( $slist );
  4193. $isMC = json_encode ( $isMC );
  4194. $schedule = json_encode ( $schedule );
  4195. $redis->lpush ( $redisKey, $slist );
  4196. $redis->lpush ( $redisKey, $isMC );
  4197. $redis->lpush ( $redisKey, $schedule );
  4198. } else {
  4199. $this->data ['cidKey'] = $cidKey;
  4200. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4201. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4202. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4203. }
  4204. $this->data ['month'] = $month;
  4205. $this->data ['categoryList'] = $categoryList;
  4206. $this->data ['memu'] = "invoice";
  4207. $this->data ['staff'] = $this->staff;
  4208. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4209. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4210. }
  4211. /**
  4212. * 办事处人员汇总详情
  4213. */
  4214. function invoiceAggregateStaffDetail() {
  4215. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4216. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4217. Doo::loadClass ( 'XDeode' );
  4218. $XDeode = new XDeode ( 5 );
  4219. Doo::loadModel ( 'invoice' );
  4220. $invoice = new invoice ();
  4221. Doo::loadModel ( 'staff' );
  4222. $staff = new staff ();
  4223. Doo::loadModel ( "invoiceCategoryManage" );
  4224. $invoiceCategoryManage = new invoiceCategoryManage ();
  4225. $sid = $XDeode->decode ( $sidKey );
  4226. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4227. $cidList = array ();
  4228. foreach ( $imcStaff as $key => $value ) {
  4229. array_push ( $cidList, $value ['cid'] );
  4230. if (empty ( $cidKey ))
  4231. $cidKey = $XDeode->encode ( $value ['cid'] );
  4232. }
  4233. $cidString = implode ( ',', $cidList );
  4234. $staffList = $staff->getStaffInCid ( $cidString );
  4235. $staffDetail = $staff->getStaffBySid ( $sid );
  4236. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4237. $page_size = 18;
  4238. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4239. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4240. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4241. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4242. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4243. $dateArr = explode ( ':', $date );
  4244. $D1 = '';
  4245. $D2 = '';
  4246. if (! empty ( $date )) {
  4247. $D1 = $dateArr [0] . " 00:00:00 ";
  4248. if (isset ( $dateArr [1] ))
  4249. $D2 = $dateArr [1] . " 23:59:59 ";
  4250. else
  4251. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4252. // $D2 = $dateArr [1];
  4253. }
  4254. $con = ' status=2 ';
  4255. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4256. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4257. if ($status == 'UNRECORD')
  4258. $con .= ' and printStatus=1 and untreadStatus=0';
  4259. elseif ($status == 'RECORD')
  4260. $con .= ' and printStatus=1 and untreadStatus=3';
  4261. elseif ($status == 'BOUNCED')
  4262. $con .= ' and untreadStatus=2';
  4263. elseif ($status == 'PARTRECORD')
  4264. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4265. elseif ($status == 'All') {
  4266. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4267. }
  4268. $con .= ' and sid=' . $sid;
  4269. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4270. if (! empty ( $MebSea )) {
  4271. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4272. }
  4273. $pageinfo ['page'] = array (
  4274. 'previous' => ''
  4275. );
  4276. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4277. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4278. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4279. $this->data ['staffDetail'] = $staffDetail;
  4280. $this->data ['staffList'] = $staffList;
  4281. $this->data ['MebSeaEn'] = $MebSea;
  4282. $this->data ['MebSea'] = urlencode ( $MebSea );
  4283. $this->data ['date'] = $date;
  4284. $this->data ['page'] = $pageinfo;
  4285. $this->data ['get'] = $get;
  4286. $this->data ['list'] = $list;
  4287. $this->data ['status'] = $status;
  4288. $this->data ['sidKey'] = $sidKey;
  4289. $this->data ['memu'] = "invoice";
  4290. $this->data ['staff'] = $this->staff;
  4291. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4292. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4293. }
  4294. /**
  4295. * 办事处人员汇总收款情
  4296. */
  4297. function invoiceAggregateStaffReceivablesDetail() {
  4298. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4299. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4300. Doo::loadModel ( 'invoiceReceivables' );
  4301. $invoiceReceivables = new invoiceReceivables ();
  4302. Doo::loadModel ( 'staff' );
  4303. $staff = new staff ();
  4304. Doo::loadModel ( "invoiceCategoryManage" );
  4305. $invoiceCategoryManage = new invoiceCategoryManage ();
  4306. Doo::loadClass ( 'XDeode' );
  4307. $XDeode = new XDeode ( 5 );
  4308. $sid = $XDeode->decode ( $sidKey );
  4309. $staffDetail = $staff->getStaffBySid ( $sid );
  4310. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4311. $cidList = array ();
  4312. foreach ( $imcStaff as $key => $value ) {
  4313. array_push ( $cidList, $value ['cid'] );
  4314. if (empty ( $cidKey ))
  4315. $cidKey = $XDeode->encode ( $value ['cid'] );
  4316. }
  4317. $cidString = implode ( ',', $cidList );
  4318. $staffList = $staff->getStaffInCid ( $cidString );
  4319. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4320. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4321. $page_size = 10;
  4322. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4323. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4324. if ($timeType == "BINDOTP") {
  4325. $status = 'Credited';
  4326. }
  4327. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4328. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4329. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4330. $dateArr = explode ( ':', $date );
  4331. $D1 = '';
  4332. $D2 = '';
  4333. if (! empty ( $date )) {
  4334. $D1 = $dateArr [0] . " 00:00:00 ";
  4335. if (isset ( $dateArr [1] ))
  4336. $D2 = $dateArr [1] . " 23:59:59 ";
  4337. else
  4338. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4339. }
  4340. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4341. $descField = 'a.bindDate';
  4342. if ($timeType == 'CREATE')
  4343. $descField = 'a.date';
  4344. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4345. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4346. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4347. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4348. if ($status == 'Unclaimed')
  4349. $con .= ' and a.bindStatus=0';
  4350. elseif ($status == 'Credited')
  4351. $con .= ' and a.bindStatus=1';
  4352. elseif ($status == 'Claim')
  4353. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4354. elseif ($status == 'BBN')
  4355. $con .= ' and a.bindPrice>a.receivablesPrice';
  4356. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4357. if (! empty ( $MebSea )) {
  4358. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4359. }
  4360. $pageinfo ['page'] = array (
  4361. 'previous' => ''
  4362. );
  4363. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4364. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4365. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4366. where ' . $con . ' group by a.irid ';
  4367. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4368. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4369. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4370. foreach ( $list as $key => $value ) {
  4371. $list [$key] ['category'] = '';
  4372. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4373. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4374. $list [$key] ['category'] = $receivablesCategory [1];
  4375. }
  4376. }
  4377. // print_r($list);
  4378. $this->data ['staffDetail'] = $staffDetail;
  4379. $this->data ['sidKey'] = $sidKey;
  4380. $this->data ['staffList'] = $staffList;
  4381. $this->data ['timeType'] = $timeType;
  4382. $this->data ['MebSeaEn'] = $MebSea;
  4383. $this->data ['MebSea'] = urlencode ( $MebSea );
  4384. $this->data ['date'] = $date;
  4385. $this->data ['page'] = $pageinfo;
  4386. $this->data ['get'] = $get;
  4387. $this->data ['list'] = $list;
  4388. $this->data ['status'] = $status;
  4389. $this->data ['memu'] = "invoice";
  4390. $this->data ['staff'] = $this->staff;
  4391. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4392. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4393. }
  4394. function invoiceAchieve() {
  4395. Doo::loadModel ( 'invoice' );
  4396. $invoice = new invoice ();
  4397. Doo::loadClass ( 'XDeode' );
  4398. $XDeode = new XDeode ( 5 );
  4399. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4400. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4401. $page_size = 18;
  4402. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4403. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4404. $get = "/" . $date;
  4405. $con = '';
  4406. if ($date == 'MONTHO')
  4407. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4408. elseif ($date == 'MONTHT')
  4409. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4410. elseif ($date == 'MONTHY')
  4411. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4412. if (! empty ( $MebSea )) {
  4413. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4414. $get .= "/" . $MebSea;
  4415. }
  4416. $pageinfo ['page'] = array (
  4417. 'previous' => ''
  4418. );
  4419. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4420. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4421. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4422. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4423. // print_r($pageinfo);
  4424. $this->data ['MebSeaEn'] = $MebSea;
  4425. $this->data ['MebSea'] = urlencode ( $MebSea );
  4426. $this->data ['get'] = $get;
  4427. $this->data ['page'] = $pageinfo;
  4428. $this->data ['list'] = $list;
  4429. $this->data ['date'] = $date;
  4430. $this->data ['memu'] = "invoice";
  4431. $this->data ['staff'] = $this->staff;
  4432. $this->data ['receiptMemu'] = 'invoice';
  4433. $this->render ( "/admin/invoiceAchieve", $this->data );
  4434. }
  4435. /**
  4436. */
  4437. function invoiceMyUnAccountAchieve() {
  4438. Doo::loadModel ( 'invoice' );
  4439. $invoice = new invoice ();
  4440. Doo::loadClass ( 'XDeode' );
  4441. $XDeode = new XDeode ( 5 );
  4442. Doo::loadModel ( 'staff' );
  4443. $staff = new staff ();
  4444. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4445. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4446. $page_size = 18;
  4447. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4448. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4449. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4450. $dateArr = explode ( ':', $date );
  4451. $D1 = '';
  4452. $D2 = '';
  4453. if (! empty ( $date )) {
  4454. $D1 = $dateArr [0];
  4455. $D2 = $dateArr [1];
  4456. }
  4457. $con = '';
  4458. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4459. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4460. if (! empty ( $MebSea )) {
  4461. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4462. }
  4463. $pageinfo ['page'] = array (
  4464. 'previous' => ''
  4465. );
  4466. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4467. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4468. $action = "invoiceMyUnAccountAchieve";
  4469. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4470. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4471. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4472. Doo::loadModel ( 'express' );
  4473. $express = new express ();
  4474. $expressList = $express->getExpressByAll ();
  4475. $this->data ['expressList'] = $expressList;
  4476. // print_r($list);
  4477. $this->data ['MebSeaEn'] = $MebSea;
  4478. $this->data ['get'] = $get;
  4479. $this->data ['page'] = $pageinfo;
  4480. $this->data ['date'] = $date;
  4481. $this->data ['list'] = $list;
  4482. $this->data ['memu'] = "invoice";
  4483. $this->data ['staff'] = $this->staff;
  4484. $this->data ['receiptMemu'] = 'invoice';
  4485. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4486. }
  4487. function invoiceReceivablesAchieve() {
  4488. Doo::loadModel ( 'invoiceReceivables' );
  4489. $invoiceReceivables = new invoiceReceivables ();
  4490. Doo::loadClass ( 'XDeode' );
  4491. $XDeode = new XDeode ( 5 );
  4492. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4493. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4494. $page_size = 12;
  4495. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4496. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4497. $get = "/" . $date;
  4498. $con = '';
  4499. if ($date == 'MONTHO')
  4500. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4501. elseif ($date == 'MONTHT')
  4502. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4503. elseif ($date == 'MONTHY')
  4504. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4505. if (! empty ( $MebSea )) {
  4506. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4507. $get .= "/" . $MebSea;
  4508. }
  4509. $pageinfo ['page'] = array (
  4510. 'previous' => ''
  4511. );
  4512. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4513. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4514. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4515. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4516. // print_r($pageinfo);
  4517. $this->data ['MebSeaEn'] = $MebSea;
  4518. $this->data ['MebSea'] = urlencode ( $MebSea );
  4519. $this->data ['get'] = $get;
  4520. $this->data ['page'] = $pageinfo;
  4521. $this->data ['list'] = $list;
  4522. $this->data ['date'] = $date;
  4523. $this->data ['memu'] = "invoice";
  4524. $this->data ['staff'] = $this->staff;
  4525. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4526. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4527. }
  4528. /**
  4529. * 收款解绑
  4530. */
  4531. function invoiceUnBundLing() {
  4532. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4533. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4534. Doo::loadModel ( 'invoice' );
  4535. $invoice = new invoice ();
  4536. Doo::loadModel ( 'invoiceReceivables' );
  4537. $invoiceReceivables = new invoiceReceivables ();
  4538. Doo::loadModel ( 'invoiceOperationLog' );
  4539. $invoiceOperationLog = new invoiceOperationLog ();
  4540. Doo::loadModel ( 'invoiceROLog' );
  4541. $invoiceROLog = new invoiceROLog ();
  4542. Doo::loadModel ( 'invoiceStatistics' );
  4543. Doo::loadClass ( 'XDeode' );
  4544. $XDeode = new XDeode ( 5 );
  4545. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4546. die ( 'illegal request' );
  4547. $iid = $XDeode->decode ( $iidKey );
  4548. $irid = $invoice->authcode ( $unBundKey );
  4549. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4550. die ( 'illegal request' );
  4551. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4552. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4553. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4554. die ( 'illegal request' );
  4555. // 收款
  4556. $item = array (
  4557. 'irid' => $irDetails ['irid'],
  4558. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4559. 'bindStatus' => 0
  4560. );
  4561. if ($irDetails ['iid'] == $iid)
  4562. $item += array (
  4563. 'iid' => 0
  4564. );
  4565. else {
  4566. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4567. foreach ( $iidExtend as $key => $value ) {
  4568. if ($value == $iid)
  4569. unset ( $iidExtend [$key] );
  4570. }
  4571. $iidExtend = implode ( ',', $iidExtend );
  4572. $item += array (
  4573. 'iidExtend' => $iidExtend
  4574. );
  4575. }
  4576. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4577. // 收款操作日志
  4578. $item = array (
  4579. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4580. 'date' => date ( "Y-m-d" ),
  4581. 'status' => 3,
  4582. 'img' => $this->staff [0] ['avatar'],
  4583. 'username' => $this->staff [0] ['username'],
  4584. 'uid' => $this->staff [0] ['sid'],
  4585. 'category' => $this->staff [0] ['category'],
  4586. 'irid' => $irid
  4587. );
  4588. $invoiceROLog->setInvoiceROLog ( $item );
  4589. // 扣除入账统计金额
  4590. $invoiceStatistics = new invoiceStatistics ();
  4591. $item = array (
  4592. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4593. 'priceClass' => 3,
  4594. 'cid' => $invoiceDetails ['cid'],
  4595. 'staff' => $invoiceDetails ['sid'],
  4596. 'accountPrice' => - $irDetails ['receivablesPrice']
  4597. );
  4598. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4599. // 扣除收款统计金额
  4600. $invoiceStatistics = new invoiceStatistics ();
  4601. $item = array (
  4602. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4603. 'priceClass' => 2,
  4604. 'cid' => $invoiceDetails ['cid'],
  4605. 'staff' => $invoiceDetails ['sid'],
  4606. 'irid' => $irDetails ['irid'],
  4607. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4608. );
  4609. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4610. // 发票解绑去收款ID
  4611. $iridString = $invoiceDetails ['irid'];
  4612. if (! empty ( $invoiceDetails ['irid'] )) {
  4613. $list = explode ( ',', $invoiceDetails ['irid'] );
  4614. foreach ( $list as $key => $value ) {
  4615. if ($value == $irDetails ['irid']) {
  4616. unset ( $list [$key] );
  4617. break;
  4618. }
  4619. }
  4620. $iridString = implode ( ",", $list );
  4621. }
  4622. $item = array (
  4623. 'iid' => $invoiceDetails ['iid'],
  4624. 'irid' => $iridString,
  4625. 'updateTime' => date ( "Y-m-d H:i:s" )
  4626. );
  4627. if ($invoiceDetails ['untreadStatus'] == 3)
  4628. $item += array (
  4629. 'untreadStatus' => 0
  4630. );
  4631. $invoice->setInvoiceByCondition ( $item );
  4632. $item = array (
  4633. 'date' => date ( "Y-m-d H:i:s" ),
  4634. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4635. 'status' => 11,
  4636. 'img' => $this->staff [0] ['avatar'],
  4637. 'username' => $this->staff [0] ['username'],
  4638. 'uid' => $this->staff [0] ['sid'],
  4639. 'category' => $this->staff [0] ['category'],
  4640. 'iid' => $invoiceDetails ['iid']
  4641. );
  4642. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4643. // 公司流水-解绑时删除流水
  4644. Doo::loadModel ( 'wasteBook' );
  4645. $wasteBook = new wasteBook ();
  4646. // $wasteBook->delete ( array (
  4647. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4648. // 'limit' => 1
  4649. // ) );
  4650. // 银行
  4651. /*
  4652. * $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); }
  4653. */
  4654. return "/invoiceReceivablesAS";
  4655. }
  4656. /**
  4657. * 或者该收款下的所以发票
  4658. */
  4659. function ajaxGetInvoiceReceivablesByInvoice() {
  4660. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4661. Doo::loadModel ( 'invoice' );
  4662. $invoice = new invoice ();
  4663. Doo::loadModel ( 'invoiceReceivables' );
  4664. $invoiceReceivables = new invoiceReceivables ();
  4665. $irid = $invoice->authcode ( $irid );
  4666. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4667. die ( 'illegal request' );
  4668. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4669. $iidString = $irDetails ['iid'];
  4670. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4671. if (! empty ( $irDetails ['iidExtend'] ))
  4672. $iidString .= ',' . implode ( ',', $iidExtend );
  4673. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4674. $html = "";
  4675. foreach ( $invoiceList as $key => $value ) {
  4676. $title = $value ['invoiceTitle'];
  4677. if (! empty ( $value ['invoiceCompany'] ))
  4678. $title = $value ['invoiceCompany'];
  4679. $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>';
  4680. }
  4681. echo json_encode ( array (
  4682. 'status' => 1,
  4683. 'html' => $html
  4684. ) );
  4685. }
  4686. /**
  4687. * 发票管理
  4688. */
  4689. function invoiceAS() {
  4690. Doo::loadModel ( 'invoice' );
  4691. $invoice = new invoice ();
  4692. Doo::loadModel ( 'invoiceReceivables' );
  4693. $invoiceReceivables = new invoiceReceivables ();
  4694. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4695. $page_size = 18;
  4696. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4697. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4698. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4699. $dateArr = explode ( ':', $date );
  4700. $D1 = '';
  4701. $D2 = '';
  4702. if (! empty ( $date )) {
  4703. $D1 = $dateArr [0] . " 00:00:00 ";
  4704. if (isset ( $dateArr [1] ))
  4705. $D2 = $dateArr [1] . " 23:59:59 ";
  4706. else
  4707. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4708. // $D2 = $dateArr [1];
  4709. }
  4710. $con = ' status=2 ';
  4711. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4712. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4713. if ($status == 'UNRECORD')
  4714. $con .= ' and printStatus=1 and untreadStatus=0';
  4715. elseif ($status == 'RECORD')
  4716. $con .= ' and printStatus=1 and untreadStatus=3';
  4717. elseif ($status == 'BOUNCED')
  4718. $con .= ' and untreadStatus=2';
  4719. elseif ($status == 'PARTRECORD')
  4720. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4721. elseif ($status == 'All') {
  4722. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4723. }
  4724. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4725. if (! empty ( $MebSea )) {
  4726. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4727. }
  4728. $pageinfo ['page'] = array (
  4729. 'previous' => ''
  4730. );
  4731. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4732. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4733. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4734. $this->data ['MebSeaEn'] = $MebSea;
  4735. $this->data ['MebSea'] = urlencode ( $MebSea );
  4736. $this->data ['date'] = $date;
  4737. $this->data ['page'] = $pageinfo;
  4738. $this->data ['get'] = $get;
  4739. $this->data ['list'] = $list;
  4740. $this->data ['status'] = $status;
  4741. $this->data ['memu'] = "invoice";
  4742. $this->data ['staff'] = $this->staff;
  4743. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4744. $this->render ( "/admin/invoiceAS", $this->data );
  4745. }
  4746. /**
  4747. * 收款管理
  4748. */
  4749. function invoiceReceivablesAS() {
  4750. Doo::loadModel ( 'invoiceReceivables' );
  4751. $invoiceReceivables = new invoiceReceivables ();
  4752. Doo::loadModel ( 'L_category' );
  4753. $lCategory = new L_category ();
  4754. $category = $lCategory->getCategory ();
  4755. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4756. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4757. $page_size = 10;
  4758. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4759. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4760. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4761. $dateArr = explode ( ':', $date );
  4762. $D1 = '';
  4763. $D2 = '';
  4764. if (! empty ( $date )) {
  4765. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4766. if (isset ( $dateArr [1] ))
  4767. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4768. else
  4769. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4770. }
  4771. $descField = 'a.receivablesDate';
  4772. if ($timeType == 'CREATE')
  4773. $descField = 'a.date';
  4774. $con = '1';
  4775. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4776. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4777. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4778. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4779. if ($status == 'Unclaimed')
  4780. $con .= ' and a.bindStatus=0';
  4781. elseif ($status == 'Credited')
  4782. $con .= ' and a.bindStatus=1';
  4783. elseif ($status == 'Claim')
  4784. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4785. elseif ($status == 'BBN')
  4786. $con .= ' and a.bankBatchNumber!=""';
  4787. elseif ($status == 'REFUND')
  4788. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4789. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4790. if (! empty ( $MebSea )) {
  4791. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4792. }
  4793. $pageinfo ['page'] = array (
  4794. 'previous' => ''
  4795. );
  4796. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4797. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4798. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4799. where ' . $con . ' group by a.irid ';
  4800. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4801. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4802. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4803. foreach ( $list as $key => $value ) {
  4804. $list [$key] ['category'] = '';
  4805. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4806. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4807. $list [$key] ['category'] = $receivablesCategory [1];
  4808. }
  4809. }
  4810. // print_r($list);
  4811. $this->data ['category'] = $category;
  4812. $this->data ['timeType'] = $timeType;
  4813. $this->data ['MebSeaEn'] = $MebSea;
  4814. $this->data ['MebSea'] = urlencode ( $MebSea );
  4815. $this->data ['date'] = $date;
  4816. $this->data ['page'] = $pageinfo;
  4817. $this->data ['get'] = $get;
  4818. $this->data ['list'] = $list;
  4819. $this->data ['status'] = $status;
  4820. $this->data ['memu'] = "invoice";
  4821. $this->data ['staff'] = $this->staff;
  4822. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4823. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4824. }
  4825. /**
  4826. * 删除一条收款
  4827. */
  4828. function delInvoiceReceivables() {
  4829. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4830. if (empty ( $iridKey ))
  4831. die ( 'illegal request' );
  4832. Doo::loadClass ( 'XDeode' );
  4833. $XDeode = new XDeode ( 5 );
  4834. $irid = $XDeode->decode ( $iridKey );
  4835. Doo::loadModel ( 'invoiceReceivables' );
  4836. $invoiceReceivables = new invoiceReceivables ();
  4837. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4838. if (empty ( $detail ))
  4839. die ( 'illegal request' );
  4840. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4841. // 扣除收款汇总信息 汇总
  4842. Doo::loadModel ( 'invoiceStatistics' );
  4843. $invoiceStatistics = new invoiceStatistics ();
  4844. $item = array (
  4845. 'date' => $detail ['receivablesDate'],
  4846. 'priceClass' => 2,
  4847. 'irid' => $detail ['irid'],
  4848. 'receivablesPrice' => - $detail ['receivablesPrice']
  4849. );
  4850. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4851. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4852. $item += array (
  4853. 'cid' => $receivablesCategory [0]
  4854. );
  4855. }
  4856. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4857. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4858. $item += array (
  4859. 'staff' => $receivablesStaff [0]
  4860. );
  4861. }
  4862. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4863. return '/invoiceReceivablesAS';
  4864. }
  4865. /**
  4866. * 添加退款信息
  4867. */
  4868. function setInvoiceReceivablesRefund() {
  4869. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4870. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4871. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4872. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4873. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4874. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4875. if ($refundPrice < 0)
  4876. die ( 'illegal request' );
  4877. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4878. Doo::loadModel ( 'invoiceReceivables' );
  4879. $invoiceReceivables = new invoiceReceivables ();
  4880. Doo::loadModel ( 'invoiceRefund' );
  4881. $invoiceRefund = new invoiceRefund ();
  4882. $irid = $invoiceReceivables->authcode ( $iridKey );
  4883. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4884. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4885. die ( 'illegal request' );
  4886. $invoiceReceivables = new invoiceReceivables ();
  4887. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4888. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4889. ';
  4890. $item = array (
  4891. 'irid' => $irid,
  4892. 'refundCompany' => $refundCompany,
  4893. 'refundNumber' => $refundNumber,
  4894. 'refundPrice' => $refundPrice,
  4895. 'refundRemarks' => $refundRemarks,
  4896. 'refundLog' => $refundLog
  4897. );
  4898. if ($refundType == 1) {
  4899. $item += array (
  4900. 'refundType' => $refundType,
  4901. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4902. 'bindStatus' => 2
  4903. );
  4904. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4905. $item += array (
  4906. 'refundType' => 1,
  4907. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4908. 'bindStatus' => 2
  4909. );
  4910. } else {
  4911. $item += array (
  4912. 'refundType' => $refundType,
  4913. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4914. );
  4915. }
  4916. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4917. // 添加退款记录
  4918. $item = array (
  4919. 'irid' => $irid,
  4920. 'refundType' => $refundType,
  4921. 'refundCompany' => $refundCompany,
  4922. 'refundNumber' => $refundNumber,
  4923. 'refundPrice' => $refundPrice,
  4924. 'refundLog' => $refundLog,
  4925. 'refundRemarks' => $refundRemarks,
  4926. 'date' => date ( "Y-m-d H:i:s" )
  4927. );
  4928. $invoiceRefund->addInvoiceRefund ( $item );
  4929. // 扣除收款汇总信息 汇总
  4930. Doo::loadModel ( 'invoiceStatistics' );
  4931. $invoiceStatistics = new invoiceStatistics ();
  4932. $item = array (
  4933. 'date' => $irDetail ['receivablesDate'],
  4934. 'priceClass' => 2,
  4935. 'irid' => $irDetail ['irid'],
  4936. 'receivablesPrice' => - $refundPrice
  4937. );
  4938. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4939. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4940. $item += array (
  4941. 'cid' => $receivablesCategory [0]
  4942. );
  4943. }
  4944. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4945. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4946. $item += array (
  4947. 'staff' => $receivablesStaff [0]
  4948. );
  4949. }
  4950. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4951. // 公司日常支出流水
  4952. Doo::loadModel ( 'wasteBook' );
  4953. $wasteBook = new wasteBook ();
  4954. $accountBank = '';
  4955. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4956. $accountBank = 'CGBDeposit';
  4957. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4958. $accountBank = 'ICBCDeposit';
  4959. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4960. $accountBank = 'HUADeposit';
  4961. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4962. $accountBank = 'PersonalDeposit';
  4963. }
  4964. $itemWaste = array (
  4965. 'accountPrice' => - $refundPrice,
  4966. 'expensesType' => 2,
  4967. 'accountType' => 11,
  4968. 'accountPriceShow' => $refundPrice,
  4969. 'dataID' => $irid,
  4970. 'accountBank' => $accountBank,
  4971. 'category' => $this->staff [0] ['category'],
  4972. 'cid' => $this->staff [0] ['cid'],
  4973. 'name' => $this->staff [0] ['username'],
  4974. 'sid' => $this->staff [0] ['sid'],
  4975. 'inputDate' => date ( "Y-m-d H:i:s" )
  4976. );
  4977. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4978. return '/invoiceReceivablesAS';
  4979. }
  4980. die ( 'illegal request' );
  4981. }
  4982. function ajaxCheckInvoiceReceivablesRefund() {
  4983. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4984. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4985. if ($refundPrice < 0) {
  4986. echo json_encode ( array (
  4987. 'error' => '金额不能为负'
  4988. ) );
  4989. die ();
  4990. }
  4991. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4992. Doo::loadModel ( 'invoiceReceivables' );
  4993. $invoiceReceivables = new invoiceReceivables ();
  4994. $irid = $invoiceReceivables->authcode ( $iridKey );
  4995. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4996. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4997. echo json_encode ( array (
  4998. 'error' => '退款金额不能超过收款金额'
  4999. ) );
  5000. die ();
  5001. }
  5002. echo json_encode ( array (
  5003. 'ok' => '可以使用!'
  5004. ) );
  5005. die ();
  5006. }
  5007. }
  5008. /**
  5009. * 获得收款退款信息
  5010. */
  5011. function getRefundByDetail() {
  5012. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5013. Doo::loadModel ( 'invoiceReceivables' );
  5014. $invoiceReceivables = new invoiceReceivables ();
  5015. if (! empty ( $iridKey )) {
  5016. $irid = $invoiceReceivables->authcode ( $iridKey );
  5017. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5018. echo json_encode ( array (
  5019. 'status' => 1,
  5020. 'irDetail' => $irDetail
  5021. ) );
  5022. die ();
  5023. }
  5024. echo json_encode ( array (
  5025. 'status' => 2
  5026. ) );
  5027. }
  5028. /**
  5029. * 根据收款序列号获得收款退款信息
  5030. */
  5031. function ajaxGetInvoiceReceivablesBySerial() {
  5032. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5033. if (! empty ( $receivablesSerial )) {
  5034. Doo::loadModel ( 'invoiceReceivables' );
  5035. $invoiceReceivables = new invoiceReceivables ();
  5036. // , ' and refundLog=""'
  5037. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5038. $html = '';
  5039. if (! empty ( $irDetail ))
  5040. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5041. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5042. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5043. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5044. <td>' . $irDetail ['recepitTitleMark'] . '
  5045. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5046. </td>';
  5047. echo json_encode ( array (
  5048. 'status' => 1,
  5049. 'html' => $html,
  5050. 'irDetail' => $irDetail
  5051. ) );
  5052. die ();
  5053. }
  5054. echo json_encode ( array (
  5055. 'status' => 2
  5056. ) );
  5057. }
  5058. /**
  5059. * 绑定新收款
  5060. */
  5061. function relationNewInvoiceReceivables() {
  5062. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5063. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5064. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5065. Doo::loadModel ( 'invoiceReceivables' );
  5066. $invoiceReceivables = new invoiceReceivables ();
  5067. Doo::loadClass ( 'XDeode' );
  5068. $XDeode = new XDeode ( 5 );
  5069. $irid = $XDeode->decode ( $iridKey );
  5070. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5071. echo $irid . 'bbb' . $iridOld;
  5072. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5073. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5074. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5075. die ( 'illegal request' );
  5076. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5077. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5078. ';
  5079. $invoiceReceivables = new invoiceReceivables ();
  5080. $item = array (
  5081. 'irid' => $iridOld,
  5082. 'relationIrid' => $irid,
  5083. 'relationLog' => $relationLog
  5084. );
  5085. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5086. return '/invoiceReceivablesAS';
  5087. }
  5088. die ( 'illegal request' );
  5089. }
  5090. // function invoiceApprovalAchieve() {
  5091. // Doo::loadModel ( 'invoice' );
  5092. // $invoice = new invoice ();
  5093. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5094. // $page_size = 12;
  5095. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5096. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5097. // $get = "/" . $date;
  5098. // $con = '';
  5099. // if ($date == 'MONTHO')
  5100. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5101. // elseif ($date == 'MONTHT')
  5102. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5103. // elseif ($date == 'MONTHY')
  5104. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5105. // if (! empty ( $MebSea )) {
  5106. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5107. // $get .= "/" . $MebSea;
  5108. // }
  5109. // $pageinfo ['page'] = array (
  5110. // 'previous' => ''
  5111. // );
  5112. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5113. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5114. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5115. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5116. // // print_r($list);
  5117. // $this->data ['MebSeaEn'] = $MebSea;
  5118. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5119. // $this->data ['get'] = $get;
  5120. // $this->data ['page'] = $pageinfo;
  5121. // $this->data ['list'] = $list;
  5122. // $this->data ['date'] = $date;
  5123. // $this->data ['memu'] = "invoice";
  5124. // $this->data ['staff'] = $this->staff;
  5125. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5126. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5127. // }
  5128. /**
  5129. * 获得审批发票的信息以及审批页面
  5130. */
  5131. function ajaxGetInvoiceApprovalDetail() {
  5132. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5133. if (empty ( $serial )) {
  5134. echo json_encode ( array (
  5135. 'status' => 2,
  5136. 'msg' => 'illegal request'
  5137. ) );
  5138. die ();
  5139. }
  5140. Doo::loadModel ( 'invoice' );
  5141. $invoice = new invoice ();
  5142. Doo::loadModel ( 'invoiceOperationLog' );
  5143. $invoiceOperationLog = new invoiceOperationLog ();
  5144. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5145. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5146. if (empty ( $detail ))
  5147. $html = '';
  5148. else {
  5149. $html = '
  5150. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5151. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5152. <input type="hidden" name="status" value="">
  5153. <input type="hidden" name="divApproval" value="divApproval">
  5154. <div class="modal-dialog modal-lg">
  5155. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5156. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5157. <tr>
  5158. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5159. </tr>
  5160. <tr>
  5161. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5162. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5163. </tr>
  5164. <tr>
  5165. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5166. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5167. </tr>
  5168. <tr>
  5169. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5170. </td>
  5171. </tr>
  5172. <tr>
  5173. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5174. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5175. </tr>
  5176. <tr>
  5177. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5178. </tr></tbody></table>';
  5179. if ($detail ['invoiceType'] == 0)
  5180. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5181. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5182. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5183. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5184. </tr>';
  5185. else
  5186. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5187. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5188. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5189. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5190. ';
  5191. $html .= '<tr>
  5192. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5193. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5194. </tr>
  5195. <tr>
  5196. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5197. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5198. </tr></tbody></table>';
  5199. if ($detail ['doPost'] == 1) {
  5200. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5201. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5202. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5203. </tr><tr>
  5204. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5205. </tr><tr>
  5206. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5207. </tr>
  5208. ';
  5209. if ($detail ['expressCom'] == 'SF')
  5210. $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>';
  5211. else
  5212. $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>';
  5213. $html .= '</tbody></table>';
  5214. }
  5215. if (! empty ( $invoiceOperationLogList )) {
  5216. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5217. foreach ( $invoiceOperationLogList as $key => $value ) {
  5218. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5219. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5220. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5221. if ($value ['status'] == 2) {
  5222. $html .= '<span class="colGreen">同意</span>';
  5223. } elseif ($value ['status'] == 3) {
  5224. $html .= '<span class="colOrange">退回</span>';
  5225. } elseif ($value ['status'] == 5) {
  5226. $html .= '<span class="colGreen">打印</span>';
  5227. } elseif ($value ['status'] == 4) {
  5228. $html .= '<span class="colRed">终止</span>';
  5229. }
  5230. $html .= $value ['operation'] . '</p></blockquote>';
  5231. }
  5232. }
  5233. $html .= '</td></tr></tbody></table>';
  5234. }
  5235. $html .= '</div><div class="modal-footer">
  5236. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5237. <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>
  5238. <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>
  5239. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5240. </form>
  5241. <script type="text/javascript">
  5242. $("a[node-approval^=\'approval\']").click(function() {
  5243. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5244. $("form[name=\'invoiceApproval\']").submit();
  5245. });
  5246. </script>
  5247. ';
  5248. }
  5249. echo json_encode ( array (
  5250. 'status' => 1,
  5251. 'html' => $html
  5252. ) );
  5253. die ();
  5254. }
  5255. /**
  5256. * 获得审批发票分页数据
  5257. */
  5258. function ajaxGetinvoiceApprovalAchieve() {
  5259. Doo::loadModel ( 'invoice' );
  5260. $invoice = new invoice ();
  5261. Doo::loadModel ( 'staff' );
  5262. $staff = new staff ();
  5263. Doo::loadClass ( 'XDeode' );
  5264. $XDeode = new XDeode ( 5 );
  5265. Doo::loadModel ( 'invoiceTraining' );
  5266. $invoiceTraining = new invoiceTraining ();
  5267. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5268. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5269. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5270. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5271. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5272. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5273. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5274. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5275. $MebSea = $this->get_args ( 'search' );
  5276. $MebSea = $MebSea ['value'];
  5277. $page_size = $length;
  5278. $con = '';
  5279. if ($status == 'ALL')
  5280. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5281. elseif ($status == 'PEND')
  5282. $con = ' isDelete=0 and status=1';
  5283. elseif ($status == 'APPROVED')
  5284. $con = ' isDelete=0 and status=2';
  5285. if ($invoiceType == 'ORDINARY')
  5286. $con .= ' and invoiceType=0 ';
  5287. elseif ($invoiceType == 'SPECIAL')
  5288. $con .= ' and invoiceType=1 ';
  5289. if ($invoiceTrain == 'ORDINARY')
  5290. $con .= ' and trainId=0 ';
  5291. elseif ($invoiceTrain == 'TRAIN')
  5292. $con .= ' and trainId!=0 ';
  5293. if ($invoiceTrainName != 'ALL') {
  5294. $trainId = $XDeode->decode ( $invoiceTrainName );
  5295. if (is_numeric ( $trainId ))
  5296. $con .= ' and trainId =' . $trainId;
  5297. }
  5298. $dateArr = explode ( ':', $date );
  5299. $D1 = $dateString = '';
  5300. $D2 = '';
  5301. if (! empty ( $date )) {
  5302. $D1 = $dateArr [0];
  5303. if (isset ( $dateArr [1] ))
  5304. $D2 = $dateArr [1];
  5305. else
  5306. $D2 = '';
  5307. $dateString = $D1 . " : " . $D2;
  5308. }
  5309. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5310. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5311. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5312. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5313. if (! empty ( $MebSea ))
  5314. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5315. // /
  5316. $pageinfo ['page'] = array (
  5317. 'previous' => ''
  5318. );
  5319. $sql = ' ' . $con;
  5320. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5321. $limit = $page . ',' . $page_size;
  5322. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5323. $approvalList = array ();
  5324. $html = '<script type="text/javascript">
  5325. </script>';
  5326. // 结算结束不能修改方式
  5327. Doo::loadModel ( 'receipt' );
  5328. $receipt = new receipt ();
  5329. foreach ( $list as $key => $value ) {
  5330. $irDetail = array ();
  5331. // 结算方式
  5332. $receiptDetail = array ();
  5333. if ($value ['trainId'] != 0) {
  5334. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5335. }
  5336. if (! empty ( $receiptDetail )) {
  5337. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5338. array_push ( $irDetail, '' );
  5339. } else {
  5340. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5341. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5342. } elseif ($value ['status'] == 2) {
  5343. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5344. } else
  5345. array_push ( $irDetail, '' );
  5346. }
  5347. } else {
  5348. if ($value ['status'] == 2) {
  5349. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5350. } else
  5351. array_push ( $irDetail, '' );
  5352. }
  5353. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5354. if ($value ['invoiceType'] == 1)
  5355. array_push ( $irDetail, $value ['invoiceCompany'] );
  5356. else
  5357. array_push ( $irDetail, $value ['invoiceTitle'] );
  5358. array_push ( $irDetail, $value ['TIN'] );
  5359. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5360. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5361. array_push ( $irDetail, $value ['remark'] );
  5362. array_push ( $irDetail, $value ['invoiceElement'] );
  5363. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5364. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5365. if ($value ['invoiceType'] == 1) {
  5366. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5367. } else {
  5368. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5369. }
  5370. if ($value ['settlementType'] == 0) {
  5371. array_push ( $irDetail, '软件销售' );
  5372. } else {
  5373. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5374. array_push ( $irDetail, $itDetail ['trainName'] );
  5375. }
  5376. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5377. array_push ( $irDetail, $value ['recipientsAddress'] );
  5378. array_push ( $irDetail, $value ['mailItems'] );
  5379. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5380. $fchtml = $value ['OL'] ['operation'];
  5381. if (count ( $list ) == $page_size)
  5382. $fchtml = $value ['OL'] ['operation'] . $html;
  5383. // 最后的审批意见
  5384. array_push ( $irDetail, $fchtml );
  5385. if ($value ['status'] == 2)
  5386. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5387. elseif ($value ['status'] == 3)
  5388. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5389. elseif ($value ['status'] == 4)
  5390. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5391. else
  5392. array_push ( $irDetail, '' );
  5393. array_push ( $approvalList, $irDetail );
  5394. }
  5395. // $approvalListJson = json_encode ( $approvalList );
  5396. $recordsFiltered = $pageinfo ['total_data'];
  5397. echo json_encode ( array (
  5398. "draw" => intval ( $draw ),
  5399. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5400. "recordsFiltered" => intval ( $recordsFiltered ),
  5401. "data" => $approvalList
  5402. ), JSON_UNESCAPED_UNICODE );
  5403. }
  5404. /**
  5405. * 审批发票查看更多--重构
  5406. */
  5407. function invoiceApprovalAchieve() {
  5408. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5409. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5410. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5411. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5412. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5413. Doo::loadModel ( 'invoiceTraining' );
  5414. $invoiceTraining = new invoiceTraining ();
  5415. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5416. $this->data ['trainList'] = $trainList;
  5417. $this->data ['dateString'] = $date;
  5418. $this->data ['status'] = $status;
  5419. $this->data ['invoiceType'] = $invoiceType;
  5420. $this->data ['invoiceTrain'] = $invoiceTrain;
  5421. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5422. $this->data ['memu'] = "invoice";
  5423. $this->data ['staff'] = $this->staff;
  5424. $this->data ['receiptMemu'] = 'invoiceApproval';
  5425. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5426. }
  5427. function invoiceTAchieve() {
  5428. Doo::loadModel ( 'invoice' );
  5429. $invoice = new invoice ();
  5430. Doo::loadClass ( 'XDeode' );
  5431. $XDeode = new XDeode ( 5 );
  5432. Doo::loadModel ( 'staff' );
  5433. $staff = new staff ();
  5434. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5435. $page_size = 12;
  5436. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5437. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5438. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5439. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5440. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5441. Doo::loadModel ( 'invoiceTraining' );
  5442. $invoiceTraining = new invoiceTraining ();
  5443. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5444. $get = "/" . $date;
  5445. $con = '';
  5446. if ($date == 'MONTHO')
  5447. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5448. elseif ($date == 'MONTHT')
  5449. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5450. elseif ($date == 'MONTHY')
  5451. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5452. if ($invoiceType == 'ORDINARY')
  5453. $con .= ' and invoiceType=0 ';
  5454. elseif ($invoiceType == 'SPECIAL')
  5455. $con .= ' and invoiceType=1 ';
  5456. if ($invoiceTrain == 'ORDINARY')
  5457. $con .= ' and trainId=0 ';
  5458. elseif ($invoiceTrain == 'TRAIN')
  5459. $con .= ' and trainId!=0 ';
  5460. if ($invoiceTrainName != 'ALL') {
  5461. $trainId = $XDeode->decode ( $invoiceTrainName );
  5462. if (is_numeric ( $trainId ))
  5463. $con .= ' and trainId =' . $trainId;
  5464. }
  5465. if (! empty ( $MebSea )) {
  5466. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5467. $get .= "/" . $MebSea;
  5468. }
  5469. $pageinfo ['page'] = array (
  5470. 'previous' => ''
  5471. );
  5472. $sql = "";
  5473. $action = "";
  5474. if ($this->ACTION == 'invoicePrintAchieve') {
  5475. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5476. $action = "invoicePrintAchieve";
  5477. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5478. // and untreadStatus=0
  5479. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5480. $action = "invoicePostAchieve";
  5481. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5482. $sql = " untreadStatus=2 and status=2 " . $con;
  5483. $action = "invoiceUntreadAchieve";
  5484. }
  5485. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5486. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5487. $this->data ['MebSeaEn'] = $MebSea;
  5488. $this->data ['MebSea'] = urlencode ( $MebSea );
  5489. $this->data ['get'] = $get;
  5490. $this->data ['page'] = $pageinfo;
  5491. $this->data ['trainList'] = $trainList;
  5492. $this->data ['invoiceType'] = $invoiceType;
  5493. $this->data ['invoiceTrain'] = $invoiceTrain;
  5494. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5495. $this->data ['date'] = $date;
  5496. $this->data ['memu'] = "invoice";
  5497. $this->data ['staff'] = $this->staff;
  5498. if ($this->ACTION == 'invoicePrintAchieve') {
  5499. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5500. $this->data ['receiptMemu'] = 'invoicePrint';
  5501. $this->data ['list'] = $list;
  5502. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5503. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5504. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5505. Doo::loadModel ( 'express' );
  5506. $express = new express ();
  5507. $expressList = $express->getExpressByAll ();
  5508. $this->data ['expressList'] = $expressList;
  5509. $this->data ['receiptMemu'] = 'invoicePost';
  5510. $this->data ['list'] = $list;
  5511. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5512. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5513. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5514. $this->data ['receiptMemu'] = 'invoiceUntread';
  5515. $this->data ['list'] = $list;
  5516. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5517. }
  5518. }
  5519. /**
  5520. * 公司应收款
  5521. */
  5522. function invoiceAggregateCompanyDetail() {
  5523. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5524. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5525. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5526. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5527. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5528. Doo::loadClass ( 'XDeode' );
  5529. $XDeode = new XDeode ( 5 );
  5530. Doo::loadModel ( 'invoice' );
  5531. $invoice = new invoice ();
  5532. Doo::loadModel ( 'staff' );
  5533. $staff = new staff ();
  5534. Doo::loadModel ( "invoiceCompanyManage" );
  5535. $invoiceCompanyManage = new invoiceCompanyManage ();
  5536. Doo::loadModel ( 'L_category' );
  5537. $category = new L_category ();
  5538. $sid = '';
  5539. if (! empty ( $sidKey )) {
  5540. $sid = $XDeode->decode ( $sidKey );
  5541. }
  5542. $staffDetail = $staff->getStaffBySid ( $sid );
  5543. $cid = '';
  5544. if (! empty ( $cidKey )) {
  5545. $cid = $XDeode->decode ( $cidKey );
  5546. }
  5547. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5548. $cidList = array ();
  5549. foreach ( $imcStaff as $key => $value ) {
  5550. array_push ( $cidList, $value ['cid'] );
  5551. }
  5552. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5553. $cidString = implode ( ',', $cidList );
  5554. if (empty ( $cid ))
  5555. $staffList = $staff->getStaffInCid ( $cidString );
  5556. else
  5557. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5558. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5559. $page_size = 25;
  5560. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5561. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5562. $con = ' status=2 and untreadStatus!=2 ';
  5563. $statisticsCon = '';
  5564. if (! empty ( $year ) && is_numeric ( $year ))
  5565. $con .= ' and Year(printTime)=' . $year . '';
  5566. if (! empty ( $month ) && is_numeric ( $month ))
  5567. $con .= ' and Month(printTime)="' . $month . '" ';
  5568. if ($status == 'UNRECORD')
  5569. $con .= ' and printStatus=1 and untreadStatus=0';
  5570. elseif ($status == 'RECORD')
  5571. $con .= ' and printStatus=1 and untreadStatus=3';
  5572. elseif ($status == 'BOUNCED')
  5573. $con .= ' and untreadStatus=2';
  5574. elseif ($status == 'PARTRECORD')
  5575. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5576. elseif ($status == 'All') {
  5577. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5578. }
  5579. if (! empty ( $sid ) && is_numeric ( $sid ))
  5580. $con .= ' and sid=' . $sid;
  5581. if (! empty ( $cid ) && is_numeric ( $cid ))
  5582. $con .= ' and cid=' . $cid;
  5583. else
  5584. $con .= ' and cid in (' . $cidString . ')';
  5585. // 开票内容筛选
  5586. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5587. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5588. }
  5589. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5590. if (! empty ( $MebSea )) {
  5591. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5592. }
  5593. $pageinfo ['page'] = array (
  5594. 'previous' => ''
  5595. );
  5596. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5597. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5598. // 应收款合计
  5599. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5600. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5601. $monthHtml = "";
  5602. if ($year != "ALL") {
  5603. for($i = 1; $i <= 12; $i ++) {
  5604. if ($i == $month)
  5605. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5606. else
  5607. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5608. }
  5609. }
  5610. $this->data ['monthHtml'] = $monthHtml;
  5611. $this->data ['year'] = $year;
  5612. $this->data ['month'] = $month;
  5613. $this->data ['ics'] = $ics;
  5614. $this->data ['cidKey'] = $cidKey;
  5615. $this->data ['sid'] = $sid;
  5616. $this->data ['staffDetail'] = $staffDetail;
  5617. $this->data ['staffList'] = $staffList;
  5618. $this->data ['MebSeaEn'] = $MebSea;
  5619. $this->data ['MebSea'] = urlencode ( $MebSea );
  5620. $this->data ['invoiceDetail'] = array (
  5621. 'invoiceElement' => $invoiceElement
  5622. );
  5623. $this->data ['page'] = $pageinfo;
  5624. $this->data ['get'] = $get;
  5625. $this->data ['list'] = $list;
  5626. $this->data ['status'] = $status;
  5627. $this->data ['categoryList'] = $categoryList;
  5628. $this->data ['memu'] = "invoice";
  5629. $this->data ['staff'] = $this->staff;
  5630. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5631. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5632. }
  5633. /**
  5634. * 获取一条收款信息
  5635. */
  5636. function ajaxGetInvoiceReceivables() {
  5637. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5638. Doo::loadModel ( 'invoiceReceivables' );
  5639. $invoiceReceivables = new invoiceReceivables ();
  5640. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5641. echo json_encode ( array (
  5642. 'status' => 1,
  5643. 'detail' => $detail
  5644. ) );
  5645. }
  5646. /**
  5647. * 异步获取办事处用户
  5648. */
  5649. function ajaxGetStaffByCategory() {
  5650. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5651. Doo::loadModel ( 'staff' );
  5652. $staff = new staff ();
  5653. if ($cid == "PUBLIC") {
  5654. echo json_encode ( array (
  5655. 'status' => 1,
  5656. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5657. ) );
  5658. die ();
  5659. }
  5660. if (! is_numeric ( $cid )) {
  5661. echo json_encode ( array (
  5662. 'status' => 0,
  5663. 'msg' => 'illegal request'
  5664. ) );
  5665. die ();
  5666. }
  5667. $staffList = $staff->getStaffByCid ( $cid );
  5668. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5669. foreach ( $staffList as $key => $value ) {
  5670. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5671. }
  5672. echo json_encode ( array (
  5673. 'status' => 1,
  5674. 'html' => $html
  5675. ) );
  5676. }
  5677. /**
  5678. * 异步获取一条发票的邮寄信息
  5679. */
  5680. function ajaxGetInvoicePostDetail() {
  5681. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5682. Doo::loadModel ( 'invoice' );
  5683. $invoice = new invoice ();
  5684. $iid = $invoice->authcode ( $iid );
  5685. Doo::loadModel ( 'express' );
  5686. $express = new express ();
  5687. $expressList = $express->getExpressByAll ();
  5688. if (! is_numeric ( $iid )) {
  5689. echo json_encode ( array (
  5690. 'status' => 0,
  5691. 'msg' => 'illegal request'
  5692. ) );
  5693. die ();
  5694. }
  5695. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5696. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5697. $html = "";
  5698. foreach ( $expressList as $key => $value ) {
  5699. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5700. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5701. else
  5702. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5703. }
  5704. $invoiceDetail ['eaHtml'] = $html;
  5705. echo json_encode ( array (
  5706. 'status' => 1,
  5707. 'invoiceDetail' => $invoiceDetail
  5708. ) );
  5709. }
  5710. /**
  5711. *
  5712. * @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 ) ); }
  5713. */
  5714. /**
  5715. *
  5716. * @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 ) ); }
  5717. */
  5718. /**
  5719. * 我的收款中 选择哪个发票入账,进行金额判断
  5720. */
  5721. function ajaxCompareInvoicePrice() {
  5722. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5723. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5724. Doo::loadModel ( 'invoice' );
  5725. $invoice = new invoice ();
  5726. Doo::loadModel ( 'invoiceReceivables' );
  5727. $invoiceReceivables = new invoiceReceivables ();
  5728. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5729. $keyList = explode ( ';', $claimKey );
  5730. $receivablesPrice = 0;
  5731. foreach ( $keyList as $key => $value ) {
  5732. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5733. $receivablesPrice += $detailM ['receivablesPrice'];
  5734. }
  5735. if ($receivablesPrice > $detail ['invoicePrice']) {
  5736. $price = $receivablesPrice - $detail ['invoicePrice'];
  5737. echo json_encode ( array (
  5738. 'status' => 1,
  5739. 'price' => $price
  5740. ) );
  5741. } else
  5742. echo json_encode ( array (
  5743. 'status' => 2
  5744. ) );
  5745. }
  5746. /**
  5747. * 获得打印发票
  5748. */
  5749. function ajaxGetInvoiceInfoByPrint() {
  5750. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5751. if (empty ( $serial )) {
  5752. echo json_encode ( array (
  5753. 'status' => 2,
  5754. 'msg' => 'illegal request'
  5755. ) );
  5756. die ();
  5757. }
  5758. Doo::loadModel ( 'invoice' );
  5759. $invoice = new invoice ();
  5760. Doo::loadModel ( 'invoiceOperationLog' );
  5761. $invoiceOperationLog = new invoiceOperationLog ();
  5762. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5763. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5764. Doo::loadModel ( 'invoicePaper' );
  5765. $invoicePaper = new invoicePaper ();
  5766. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5767. if (empty ( $detail ))
  5768. $html = '';
  5769. else {
  5770. $html = '
  5771. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5772. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5773. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5774. <div class="modal-dialog modal-lg">
  5775. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5776. <div class="modal-body saeaList">
  5777. <table class="table table-bordered table-condensed"><tbody>
  5778. <tr>
  5779. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5780. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5781. </tr>
  5782. <tr>
  5783. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5784. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5785. </tr>
  5786. <tr>
  5787. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5788. </td>
  5789. </tr>
  5790. <tr>
  5791. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5792. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5793. </tr>
  5794. <tr>
  5795. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5796. </tr></tbody></table>';
  5797. if ($detail ['invoiceType'] == 0)
  5798. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5799. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5800. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5801. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5802. </tr>';
  5803. else
  5804. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5805. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5806. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5807. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5808. ';
  5809. $html .= '<tr>
  5810. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5811. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5812. </tr>
  5813. <tr>
  5814. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5815. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5816. </tr></tbody></table>';
  5817. if ($detail ['doPost'] == 1)
  5818. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5819. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5820. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5821. </tr><tr>
  5822. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5823. </tr><tr>
  5824. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5825. </tr></tbody></table>';
  5826. if (! empty ( $invoiceOperationLogList )) {
  5827. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5828. foreach ( $invoiceOperationLogList as $key => $value ) {
  5829. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5830. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5831. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5832. if ($value ['status'] == 2) {
  5833. $html .= '<span class="colGreen">同意</span>';
  5834. } elseif ($value ['status'] == 3) {
  5835. $html .= '<span class="colOrange">退回</span>';
  5836. } elseif ($value ['status'] == 5) {
  5837. $html .= '<span class="colGreen">打印</span>';
  5838. } elseif ($value ['status'] == 4) {
  5839. $html .= '<span class="colRed">终止</span>';
  5840. }
  5841. $html .= $value ['operation'] . '</p></blockquote>';
  5842. }
  5843. }
  5844. $html .= '</td>
  5845. <td><span class="colRed">*</span>
  5846. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5847. foreach ( $invoicePaperList as $key => $value ) {
  5848. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5849. }
  5850. $html .= '</select>
  5851. <span class="red" id="p-msg"></span>
  5852. </td>
  5853. </tr></tbody></table>';
  5854. }
  5855. $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>
  5856. </div></div></form>
  5857. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5858. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5859. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5860. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5861. ';
  5862. }
  5863. echo json_encode ( array (
  5864. 'status' => 1,
  5865. 'html' => $html
  5866. ) );
  5867. die ();
  5868. }
  5869. /**
  5870. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5871. */
  5872. function ajaxGetInvoiceInfoByType() {
  5873. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5874. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5875. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5876. if (empty ( $serial )) {
  5877. echo json_encode ( array (
  5878. 'status' => 2,
  5879. 'msg' => 'illegal request'
  5880. ) );
  5881. die ();
  5882. }
  5883. if ($type == 'INVOICE') {
  5884. Doo::loadModel ( 'invoice' );
  5885. $invoice = new invoice ();
  5886. Doo::loadModel ( 'invoiceOperationLog' );
  5887. $invoiceOperationLog = new invoiceOperationLog ();
  5888. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5889. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5890. if (empty ( $detail ))
  5891. $html = '';
  5892. else {
  5893. $html = '
  5894. <div class="modal-dialog modal-lg">
  5895. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5896. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5897. <tr>
  5898. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5899. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5900. </tr>
  5901. <tr>
  5902. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5903. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5904. </tr>
  5905. <tr>
  5906. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5907. </td>
  5908. </tr>
  5909. <tr>
  5910. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5911. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5912. </tr>
  5913. <tr>
  5914. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5915. </tr>';
  5916. if ($detail ['settlementType'] == 1)
  5917. $html .= '<tr>
  5918. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5919. </tr>';
  5920. else
  5921. $html .= '<tr>
  5922. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5923. </tr>';
  5924. $html .= ' </tbody></table>';
  5925. if ($detail ['invoiceType'] == 0)
  5926. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5927. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5928. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5929. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5930. </tr>';
  5931. else
  5932. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5933. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5934. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5935. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5936. ';
  5937. $html .= '<tr>
  5938. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5939. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5940. </tr>
  5941. <tr>
  5942. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5943. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5944. </tr></tbody></table>';
  5945. if ($detail ['doPost'] == 1) {
  5946. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5947. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5948. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5949. </tr><tr>
  5950. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5951. </tr><tr>
  5952. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5953. </tr>
  5954. ';
  5955. if ($detail ['expressCom'] == 'SF')
  5956. $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>';
  5957. else
  5958. $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>';
  5959. $html .= '</tbody></table>';
  5960. }
  5961. if (! empty ( $invoiceOperationLogList )) {
  5962. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5963. foreach ( $invoiceOperationLogList as $key => $value ) {
  5964. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5965. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5966. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5967. if ($value ['status'] == 2) {
  5968. $html .= '<span class="colGreen">同意</span>';
  5969. } elseif ($value ['status'] == 3) {
  5970. $html .= '<span class="colOrange">退回</span>';
  5971. } elseif ($value ['status'] == 5) {
  5972. $html .= '<span class="colGreen">打印</span>';
  5973. } elseif ($value ['status'] == 4) {
  5974. $html .= '<span class="colRed">终止</span>';
  5975. }
  5976. $html .= $value ['operation'] . '</p></blockquote>';
  5977. }
  5978. }
  5979. $html .= '</td></tr></tbody></table>';
  5980. }
  5981. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5982. }
  5983. echo json_encode ( array (
  5984. 'status' => 1,
  5985. 'html' => $html
  5986. ) );
  5987. die ();
  5988. } elseif ($type == 'RECEIVABLES') {
  5989. Doo::loadModel ( 'invoiceReceivables' );
  5990. $invoiceReceivables = new invoiceReceivables ();
  5991. Doo::loadModel ( 'invoiceRefund' );
  5992. $invoiceRefund = new invoiceRefund ();
  5993. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5994. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5995. if (empty ( $detail ))
  5996. $html = '';
  5997. else {
  5998. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5999. <table class="table table-bordered table-condensed">
  6000. <tbody><tr>
  6001. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6002. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6003. </tr><tr>
  6004. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6005. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6006. </tr>
  6007. <tr>
  6008. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6009. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6010. </tr>
  6011. <tr>
  6012. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6013. </tr>
  6014. </tbody></table>';
  6015. if (! empty ( $ireList )) {
  6016. $html .= '
  6017. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6018. <tr>
  6019. <th class="taC">退款单位名称</th>
  6020. <th class="taC">退款的账号</th>
  6021. <th class="taC">退款金额</th>
  6022. <th class="taC">退款</th>
  6023. <th class="taC">备注</th>
  6024. </tr>
  6025. ';
  6026. foreach ( $ireList as $key => $value ) {
  6027. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6028. $html .= '<tr>
  6029. <td>' . $value ['refundCompany'] . '</td>
  6030. <td>' . $value ['refundNumber'] . '</td>
  6031. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6032. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6033. <td>' . $value ['refundRemarks'] . '</td>
  6034. </tr>
  6035. ';
  6036. }
  6037. }
  6038. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6039. }
  6040. echo json_encode ( array (
  6041. 'status' => 1,
  6042. 'html' => $html
  6043. ) );
  6044. die ();
  6045. } elseif ($type == 'IRTC') {
  6046. Doo::loadModel ( 'invoice' );
  6047. $invoice = new invoice ();
  6048. Doo::loadModel ( 'invoiceOperationLog' );
  6049. $invoiceOperationLog = new invoiceOperationLog ();
  6050. Doo::loadModel ( 'invoiceReceivables' );
  6051. $invoiceReceivables = new invoiceReceivables ();
  6052. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6053. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6054. if (empty ( $detail ))
  6055. $html = '';
  6056. else {
  6057. $receivablesPriceedHtml = '';
  6058. $receivablesPrice = $detail ['invoicePrice'];
  6059. if (! empty ( $detail ['irid'] )) {
  6060. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6061. if (empty ( $irList ))
  6062. $irList [0] ['sumPrice'] = 0;
  6063. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6064. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6065. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  6066. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  6067. </tr></tbody></table>';
  6068. $receivablesPrice = $balance;
  6069. }
  6070. if ($loss)
  6071. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6072. $html = $receivablesPriceedHtml . '
  6073. <table class="table table-bordered table-condensed"><tbody>
  6074. <tr>
  6075. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6076. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6077. </tr>
  6078. <tr>
  6079. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6080. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6081. </tr>
  6082. <tr>
  6083. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6084. </tr>
  6085. <tr>
  6086. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6087. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6088. </tr>
  6089. <tr>
  6090. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6091. </tr></tbody></table>';
  6092. if ($detail ['invoiceType'] == 0) {
  6093. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6094. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6095. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6096. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6097. </tr>';
  6098. $receivablesMessage = $detail ['invoiceTitle'];
  6099. } else {
  6100. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6101. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6102. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6103. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6104. ';
  6105. $receivablesMessage = $detail ['invoiceCompany'];
  6106. }
  6107. $html .= '<tr>
  6108. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6109. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6110. </tr>
  6111. <tr>
  6112. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6113. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6114. </tr></tbody></table>';
  6115. if ($detail ['doPost'] == 1)
  6116. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6117. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6118. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6119. </tr><tr>
  6120. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6121. </tr><tr>
  6122. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6123. </tr></tbody></table>';
  6124. if (! empty ( $invoiceOperationLogList )) {
  6125. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6126. foreach ( $invoiceOperationLogList as $key => $value ) {
  6127. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6128. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6129. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6130. if ($value ['status'] == 2) {
  6131. $html .= '<span class="colGreen">同意</span>';
  6132. } elseif ($value ['status'] == 3) {
  6133. $html .= '<span class="colOrange">退回</span>';
  6134. } elseif ($value ['status'] == 5) {
  6135. $html .= '<span class="colGreen">打印</span>';
  6136. }
  6137. $html .= $value ['operation'] . '</p></blockquote>';
  6138. }
  6139. }
  6140. $html .= '</td></tr></tbody></table>';
  6141. }
  6142. }
  6143. echo json_encode ( array (
  6144. 'status' => 1,
  6145. 'html' => $html,
  6146. 'receivablesPrice' => $receivablesPrice,
  6147. 'receivablesMessage' => $receivablesMessage,
  6148. 'receivablesDate' => date ( "Y-m-d" ),
  6149. 'iidKey' => $serial
  6150. ) );
  6151. die ();
  6152. }
  6153. }
  6154. function ajaxGetInvoiceReceivablesByStaff() {
  6155. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6156. if (empty ( $postData )) {
  6157. echo json_encode ( array (
  6158. 'status' => 2,
  6159. 'msg' => 'illegal request'
  6160. ) );
  6161. die ();
  6162. }
  6163. Doo::loadModel ( 'invoiceReceivables' );
  6164. $invoiceReceivables = new invoiceReceivables ();
  6165. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6166. if (empty ( $detail )) {
  6167. echo json_encode ( array (
  6168. 'status' => 2,
  6169. 'msg' => 'illegal request'
  6170. ) );
  6171. die ();
  6172. }
  6173. Doo::loadModel ( 'L_category' );
  6174. $lCategory = new L_category ();
  6175. Doo::loadModel ( 'staff' );
  6176. $staff = new staff ();
  6177. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6178. $category = $lCategory->getCategory ();
  6179. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6180. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6181. foreach ( $category as $key => $value ) {
  6182. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6183. if ($value ['cid'] == $detail ['cid'])
  6184. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6185. }
  6186. foreach ( $staffList as $key => $value ) {
  6187. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6188. if ($value ['sid'] == $detail ['sid'])
  6189. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6190. }
  6191. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6192. echo json_encode ( array (
  6193. 'status' => 1,
  6194. 'categoryHtml' => $categoryHtml,
  6195. 'staffHtml' => $staffHtml,
  6196. 'rbankHtml' => $rbankHtml,
  6197. 'detail' => $detail
  6198. ) );
  6199. }
  6200. function ajaxGetInvoiceReceivablesByIrid() {
  6201. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6202. if (empty ( $irid )) {
  6203. echo json_encode ( array (
  6204. 'status' => 2,
  6205. 'msg' => 'illegal request'
  6206. ) );
  6207. die ();
  6208. }
  6209. Doo::loadModel ( 'invoiceReceivables' );
  6210. $invoiceReceivables = new invoiceReceivables ();
  6211. Doo::loadModel ( 'invoice' );
  6212. $invoice = new invoice ();
  6213. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6214. $flag = true;
  6215. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6216. $bakDetail = array ();
  6217. if ($flag === false) {
  6218. array_push ( $bakDetail, $invoiceDetail );
  6219. $invoiceDetail = $bakDetail;
  6220. }
  6221. $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>
  6222. <tr>
  6223. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6224. <td>' . $detail ['receivablesMessage'] . '</td>
  6225. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6226. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6227. <td>' . $detail ['recepitTitleMark'] . '</td>
  6228. </tr></tbody></table>';
  6229. $isInvoice = false;
  6230. $invoiceHtml = '';
  6231. if (empty ( $invoiceDetail )) {
  6232. $isInvoice = true;
  6233. } else {
  6234. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6235. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6236. foreach ( $invoiceDetail as $key => $value ) {
  6237. $invoiceHtml .= '<tr>';
  6238. if (! empty ( $value ['invoiceType'] )) {
  6239. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6240. } else {
  6241. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6242. }
  6243. if (! empty ( $value ['invoiceType'] )) {
  6244. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6245. } else {
  6246. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6247. }
  6248. $invoiceHtml .= '
  6249. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6250. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6251. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6252. </tr>
  6253. ';
  6254. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6255. if (empty ( $irList ))
  6256. $irList [0] ['sumPrice'] = 0;
  6257. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6258. $priceString = '';
  6259. if ($balance < $detail ['receivablesPrice']) {
  6260. $priceString = '收款金额超过开票金额,';
  6261. }
  6262. if ($balance > $detail ['receivablesPrice']) {
  6263. $priceString = '收款金额低于开票金额,';
  6264. }
  6265. }
  6266. $invoiceHtml .= '
  6267. <script>
  6268. $(\'a[bind-receivables^="ir"]\').click(function() {
  6269. var data = $(this).attr("data-ikey");
  6270. $("input[name=\'invoiceKey\']").val(data);
  6271. var invoiceKey=data;
  6272. if(invoiceKey==""){
  6273. alert("入账错误,请重新刷新页面");
  6274. return false;
  6275. }
  6276. if(window.confirm("' . $priceString . '确定入账吗?")){
  6277. $("#IBR").submit();
  6278. }else{
  6279. return false;
  6280. }
  6281. });
  6282. </script>
  6283. ';
  6284. $invoiceHtml .= '</tbody></table>';
  6285. }
  6286. echo json_encode ( array (
  6287. 'status' => 1,
  6288. 'irkey' => $detail ['iridEn'],
  6289. 'receivablesHtml' => $receivablesHtml,
  6290. 'isInvoice' => $isInvoice,
  6291. 'invoiceHtml' => $invoiceHtml
  6292. ) );
  6293. }
  6294. function ajaxGetInvoiceReceivablesByTitle() {
  6295. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6296. if (empty ( $title )) {
  6297. echo json_encode ( array (
  6298. 'status' => 2,
  6299. 'msg' => 'illegal request'
  6300. ) );
  6301. die ();
  6302. }
  6303. Doo::loadModel ( 'invoice' );
  6304. $invoice = new invoice ();
  6305. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6306. $invoiceHtml = '';
  6307. if (! empty ( $invoiceDetail )) {
  6308. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6309. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6310. foreach ( $invoiceDetail as $key => $value ) {
  6311. if (! empty ( $value ['invoiceType'] )) {
  6312. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6313. } else {
  6314. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6315. }
  6316. if (! empty ( $value ['invoiceType'] )) {
  6317. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6318. } else {
  6319. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6320. }
  6321. $invoiceHtml .= '
  6322. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6323. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6324. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6325. </tr>
  6326. ';
  6327. }
  6328. $invoiceHtml .= '</tbody></table>
  6329. <script>
  6330. $(\'a[bind-receivables^="ir"]\').click(function() {
  6331. var data = $(this).attr("data-ikey");
  6332. $("input[name=\'invoiceKey\']").val(data);
  6333. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6334. if(invoiceKey==""){
  6335. alert("入账错误,请重新刷新页面");
  6336. return false;
  6337. }
  6338. if(window.confirm("确定入账吗?")){
  6339. $("#IBR").submit();
  6340. }else{
  6341. return false;
  6342. }
  6343. });
  6344. </script>
  6345. ';
  6346. }
  6347. echo json_encode ( array (
  6348. 'status' => 1,
  6349. 'invoiceHtml' => $invoiceHtml
  6350. ) );
  6351. }
  6352. function ajaxInvoicePushNotice() {
  6353. Doo::loadModel ( 'invoice' );
  6354. $invoice = new invoice ();
  6355. $approval = $invoice->getOne ( array (
  6356. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6357. 'desc' => 'iid',
  6358. 'asArray' => true
  6359. ) );
  6360. $isNotice = false;
  6361. if (! empty ( $approval ))
  6362. $isNotice = true;
  6363. $response = array (
  6364. 'error' => 0,
  6365. 'isNotice' => $isNotice
  6366. );
  6367. echo json_encode ( $response );
  6368. exit ();
  6369. }
  6370. public function ajaxCheckInvoiceNoUniqueness() {
  6371. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6372. Doo::loadModel ( 'invoice' );
  6373. $invoice = new invoice ();
  6374. if (! empty ( $invoiceNo )) {
  6375. Doo::loadModel ( 'invoicePaper' );
  6376. $invoicePaper = new invoicePaper ();
  6377. Doo::loadClass ( 'XDeode' );
  6378. $XDeode = new XDeode ( 5 );
  6379. $ipid = $XDeode->decode ( $invoiceNo );
  6380. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6381. $info = $invoice->getOne ( array (
  6382. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6383. 'asArray' => TRUE
  6384. ) );
  6385. if (! empty ( $info )) {
  6386. echo json_encode ( array (
  6387. 'error' => '发票号已存在'
  6388. ) );
  6389. die ();
  6390. } else
  6391. echo json_encode ( array (
  6392. 'ok' => '可以使用!'
  6393. ) );
  6394. die ();
  6395. }
  6396. }
  6397. function ajaxCheckInvoicePrice() {
  6398. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6399. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6400. Doo::loadModel ( 'invoice' );
  6401. $invoice = new invoice ();
  6402. Doo::loadModel ( 'invoiceReceivables' );
  6403. $invoiceReceivables = new invoiceReceivables ();
  6404. Doo::loadClass ( 'XDeode' );
  6405. $XDeode = new XDeode ( 5 );
  6406. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6407. $iidKey = $XDeode->decode ( $iidKey );
  6408. $info = $invoice->getInvoiceByIid ( $iidKey );
  6409. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6410. if (empty ( $irList ))
  6411. $irList [0] ['sumPrice'] = 0;
  6412. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6413. if ($balance < $receivablesPrice) {
  6414. echo json_encode ( array (
  6415. 'error' => '收款金额超过开票金额。'
  6416. ) );
  6417. die ();
  6418. }
  6419. if ($balance > $receivablesPrice) {
  6420. echo json_encode ( array (
  6421. 'error' => '收款金额低于开票金额。'
  6422. ) );
  6423. die ();
  6424. }
  6425. }
  6426. }
  6427. function ajaxGetInvoiceByNew() {
  6428. Doo::loadModel ( 'invoice' );
  6429. $invoice = new invoice ();
  6430. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6431. echo json_encode ( array (
  6432. 'status' => 1,
  6433. 'detail' => $detail
  6434. ) );
  6435. }
  6436. /**
  6437. * 旧输入导入
  6438. */
  6439. function importInvoice() {
  6440. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6441. $data ['emsg'] = "";
  6442. if ($emsg != "")
  6443. $data ['emsg'] = "请填写完整的数据";
  6444. $data ['time'] = time ();
  6445. $this->render ( "/admin/invoiceImport", $data );
  6446. }
  6447. function uploadInvoice() {
  6448. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6449. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6450. $file = $_FILES ['Filedata'] ['tmp_name'];
  6451. $error = false;
  6452. if (! is_uploaded_file ( $file )) {
  6453. $error = '400 Bad Request';
  6454. }
  6455. if ($error) {
  6456. header ( 'HTTP/1.0 ' . $error );
  6457. die ( 'Error ' . $error );
  6458. } else {
  6459. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6460. $this->IoHandler = new IoHandler ();
  6461. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6462. // $filedir=$_POST['time'];
  6463. // 调用定义物理路径
  6464. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6465. $this->IoHandler->MakeDir ( $t );
  6466. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6467. if ($filename != 'xlsx')
  6468. return "";
  6469. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6470. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6471. $upload_dir = $t . "/" . $upload_file;
  6472. $k = move_uploaded_file ( $file, $upload_dir );
  6473. if ($k) {
  6474. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6475. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6476. }
  6477. }
  6478. }
  6479. }
  6480. function importInvoiceDo() {
  6481. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6482. if ($path != "") {
  6483. Doo::loadModel ( 'invoice' );
  6484. Doo::loadModel ( 'staff' );
  6485. $staff = new staff ();
  6486. Doo::loadModel ( 'invoiceStatistics' );
  6487. Doo::loadModel ( 'invoiceOperationLog' );
  6488. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6489. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6490. // print_r ( $exlArray );
  6491. // die ();
  6492. // echo json_encode($exlArray);die;
  6493. foreach ( $exlArray as $key => $value ) {
  6494. // 开票
  6495. $invoice = new invoice ();
  6496. $invoice->invoiceNo = $value ['invoiceNo'];
  6497. $invoice->invoiceType = 0;
  6498. if ($value ['invoiceType'] == '专')
  6499. $invoice->invoiceType = 1;
  6500. $invoice->invoicePrice = $value ['invoicePrice'];
  6501. $invoice->invoiceQuantity = 1;
  6502. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6503. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6504. if ($value ['invoiceType'] == '专')
  6505. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6506. $invoice->userName = $value ['userName'];
  6507. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6508. $invoice->sid = $sDetail ['sid'];
  6509. $invoice->cid = $sDetail ['cid'];
  6510. $invoice->categoryName = $sDetail ['category'];
  6511. $invoice->invoiceElement = $value ['invoiceElement'];
  6512. $invoice->remark = $value ['remark'];
  6513. $invoice->date = $value ['date'];
  6514. $invoice->printTime = $value ['date'];
  6515. $invoice->ipSource = 1;
  6516. $invoice->printStatus = 1;
  6517. $invoice->status = 2;
  6518. $invoice->postStatus = 1;
  6519. $invoice->untreadStatus = 0;
  6520. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6521. $iid = $invoice->insert ();
  6522. // 汇总
  6523. $invoiceStatistics = new invoiceStatistics ();
  6524. //
  6525. $item = array (
  6526. 'date' => $value ['date'],
  6527. 'priceClass' => 1,
  6528. 'cid' => $sDetail ['cid'],
  6529. 'staff' => $sDetail ['sid'],
  6530. 'invoicePrice' => $value ['invoicePrice']
  6531. );
  6532. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6533. $invoiceOperationLog = new invoiceOperationLog ();
  6534. $item = array (
  6535. 'date' => date ( "Y-m-d H:i:s" ),
  6536. 'operation' => date ( "Y-m-d" ) . " 导入",
  6537. 'status' => 1,
  6538. 'img' => $sDetail ['avatar'],
  6539. 'username' => $sDetail ['username'],
  6540. 'uid' => $sDetail ['sid'],
  6541. 'category' => $sDetail ['category'],
  6542. 'iid' => $iid
  6543. );
  6544. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6545. }
  6546. return '/importInvoice?count=' . count ( $exlArray );
  6547. // return "/keyonline";
  6548. }
  6549. echo 'no file';
  6550. }
  6551. function importInvoiceReceivables() {
  6552. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6553. $data ['emsg'] = "";
  6554. if ($emsg != "")
  6555. $data ['emsg'] = "请填写完整的数据";
  6556. $data ['time'] = time ();
  6557. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6558. }
  6559. // 导入入账数据
  6560. function importInvoiceReceivablesDo() {
  6561. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6562. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6563. if ($path != "") {
  6564. Doo::loadModel ( 'invoiceReceivables' );
  6565. Doo::loadModel ( 'invoice' );
  6566. Doo::loadModel ( 'staff' );
  6567. $staff = new staff ();
  6568. Doo::loadModel ( 'invoiceStatistics' );
  6569. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6570. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6571. // print_r ( $exlArray );
  6572. // die ();
  6573. // echo json_encode($exlArray);die;
  6574. foreach ( $exlArray as $key => $value ) {
  6575. // 收款
  6576. $invoiceReceivables = new invoiceReceivables ();
  6577. $invoice = new invoice ();
  6578. $invoiceReceivables->bindStatus = 1;
  6579. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6580. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6581. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6582. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6583. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6584. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6585. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6586. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6587. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6588. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6589. $invoiceReceivables->iid = $iDetail ['iid'];
  6590. $irid = $invoiceReceivables->insert ();
  6591. // 发票绑定收款
  6592. $detail = $iDetail;
  6593. $iridString = "";
  6594. if (empty ( $detail ['irid'] ))
  6595. $iridString = $irid;
  6596. else
  6597. $iridString = $detail ['irid'] . ',' . $irid;
  6598. $item = array (
  6599. 'irid' => $iridString,
  6600. 'iid' => $detail ['iid']
  6601. );
  6602. $invoice->setInvoiceByCondition ( $item );
  6603. // 汇总
  6604. $invoiceStatistics = new invoiceStatistics ();
  6605. // 扣除入账统计金额
  6606. $item = array (
  6607. 'date' => $value ['receivablesDate'],
  6608. 'priceClass' => 3,
  6609. 'cid' => $sDetail ['cid'],
  6610. 'staff' => $sDetail ['sid'],
  6611. // 'irid' => $irid,
  6612. 'accountPrice' => $value ['receivablesPrice']
  6613. );
  6614. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6615. }
  6616. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6617. echo 'data count ' . count ( $exlArray );
  6618. die ();
  6619. // return "/keyonline";
  6620. }
  6621. echo 'no file';
  6622. }
  6623. function formatExcelToArrayTrain($file_url = "") {
  6624. if (! file_exists ( $file_url )) {
  6625. return array ();
  6626. }
  6627. // Doo::loadClass ( 'PHPExcel' );
  6628. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6629. $PHPExcel = new PHPExcel ();
  6630. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6631. if (! $PHPReader->canRead ( $file_url )) {
  6632. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6633. if (! $PHPReader->canRead ( $file_url )) {
  6634. echo 'no Excel';
  6635. return;
  6636. }
  6637. }
  6638. $PHPExcel = $PHPReader->load ( $file_url );
  6639. /* * 读取excel文件中的第一个工作表 */
  6640. $currentSheet = $PHPExcel->getSheet ( 0 );
  6641. /* * 取得最大的列号 */
  6642. $allColumn = $currentSheet->getHighestColumn ();
  6643. /* * 取得一共有多少行 */
  6644. $allRow = $currentSheet->getHighestRow ();
  6645. $excel_array = array ();
  6646. // die($file_url);
  6647. $conk = 2;
  6648. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6649. $excel_column = array ();
  6650. // 后期改进
  6651. if ($allColumn == 'AM')
  6652. $allColumn = 'Z';
  6653. /* * 从第A列开始输出 */
  6654. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6655. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6656. if ($val instanceof PHPExcel_RichText)
  6657. $val = $val->__toString ();
  6658. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6659. // $val = "'" . addslashes ( $val ) . "'";
  6660. if ($currentColumn == 'A') {
  6661. $excel_column ['invoiceTitle'] = $val;
  6662. } elseif ($currentColumn == 'B')
  6663. $excel_column ['invoiceType'] = $val;
  6664. elseif ($currentColumn == 'C') {
  6665. $excel_column ['TIN'] = $val;
  6666. } elseif ($currentColumn == 'D') {
  6667. $excel_column ['address'] = $val;
  6668. } elseif ($currentColumn == 'E') {
  6669. $excel_column ['phone'] = $val;
  6670. } elseif ($currentColumn == 'F') {
  6671. $excel_column ['bank'] = $val;
  6672. } elseif ($currentColumn == 'G') {
  6673. $excel_column ['bankAccount'] = $val;
  6674. } elseif ($currentColumn == 'H') {
  6675. $excel_column ['invoiceElement'] = $val;
  6676. } elseif ($currentColumn == 'I') {
  6677. $excel_column ['invoiceQuantity'] = $val;
  6678. } elseif ($currentColumn == 'J') {
  6679. $excel_column ['invoiceUnitPrice'] = $val;
  6680. } elseif ($currentColumn == 'K') {
  6681. $excel_column ['remark'] = $val;
  6682. } elseif ($currentColumn == 'L') {
  6683. $excel_column ['recipientsAddress'] = $val;
  6684. } elseif ($currentColumn == 'M') {
  6685. $excel_column ['recipients'] = $val;
  6686. } elseif ($currentColumn == 'N') {
  6687. $excel_column ['recipientsPhone'] = $val;
  6688. }
  6689. }
  6690. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6691. array_push ( $excel_array, $excel_column );
  6692. }
  6693. return $excel_array;
  6694. }
  6695. /**
  6696. * 格式化excel文件为数组
  6697. * @param unknown_type $file_url
  6698. * @param unknown_type $mcid
  6699. */
  6700. function _format_excel_to_array($file_url = "", $sType = "") {
  6701. if (! file_exists ( $file_url )) {
  6702. return array ();
  6703. }
  6704. Doo::loadClass ( 'PHPExcel' );
  6705. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6706. $PHPExcel = new PHPExcel ();
  6707. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6708. if (! $PHPReader->canRead ( $file_url )) {
  6709. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6710. if (! $PHPReader->canRead ( $file_url )) {
  6711. echo 'no Excel';
  6712. return;
  6713. }
  6714. }
  6715. $PHPExcel = $PHPReader->load ( $file_url );
  6716. /* * 读取excel文件中的第一个工作表 */
  6717. $currentSheet = $PHPExcel->getSheet ( 0 );
  6718. /* * 取得最大的列号 */
  6719. $allColumn = $currentSheet->getHighestColumn ();
  6720. /* * 取得一共有多少行 */
  6721. $allRow = $currentSheet->getHighestRow ();
  6722. $excel_array = array ();
  6723. // die($file_url);
  6724. $conk = 2;
  6725. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6726. $excel_column = array ();
  6727. // 后期改进
  6728. if ($allColumn == 'AM')
  6729. $allColumn = 'Z';
  6730. /* * 从第A列开始输出 */
  6731. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6732. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6733. if ($val instanceof PHPExcel_RichText)
  6734. $val = $val->__toString ();
  6735. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6736. // $val = "'" . addslashes ( $val ) . "'";
  6737. if ($sType == 'invoiceReceivables') {
  6738. if ($currentColumn == 'A')
  6739. $excel_column ['invoiceNo'] = $val;
  6740. elseif ($currentColumn == 'B')
  6741. $excel_column ['receivablesPrice'] = $val;
  6742. elseif ($currentColumn == 'C') {
  6743. $excel_column ['receivablesMessage'] = $val;
  6744. } elseif ($currentColumn == 'D') {
  6745. $excel_column ['receivablesBank'] = $val;
  6746. } elseif ($currentColumn == 'E') {
  6747. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6748. } elseif ($currentColumn == 'F') {
  6749. $excel_column ['receivablesStaff'] = $val;
  6750. } elseif ($currentColumn == 'G') {
  6751. $excel_column ['sourcePrice'] = $val;
  6752. }
  6753. } elseif ($sType == "invoiceTrain") {
  6754. if ($currentColumn == 'A') {
  6755. $excel_column ['invoiceTitle'] = $val;
  6756. } elseif ($currentColumn == 'B')
  6757. $excel_column ['invoiceType'] = $val;
  6758. elseif ($currentColumn == 'C') {
  6759. $excel_column ['TIN'] = $val;
  6760. } elseif ($currentColumn == 'D') {
  6761. $excel_column ['address'] = $val;
  6762. } elseif ($currentColumn == 'E') {
  6763. $excel_column ['phone'] = $val;
  6764. } elseif ($currentColumn == 'F') {
  6765. $excel_column ['bank'] = $val;
  6766. } elseif ($currentColumn == 'G') {
  6767. $excel_column ['bankAccount'] = $val;
  6768. } elseif ($currentColumn == 'H') {
  6769. $excel_column ['invoiceElement'] = $val;
  6770. } elseif ($currentColumn == 'I') {
  6771. $excel_column ['invoiceQuantity'] = $val;
  6772. } elseif ($currentColumn == 'J') {
  6773. $excel_column ['invoiceUnitPrice'] = $val;
  6774. } elseif ($currentColumn == 'K') {
  6775. $excel_column ['remark'] = $val;
  6776. } elseif ($currentColumn == 'L') {
  6777. $excel_column ['recipientsAddress'] = $val;
  6778. } elseif ($currentColumn == 'M') {
  6779. $excel_column ['recipients'] = $val;
  6780. } elseif ($currentColumn == 'N') {
  6781. $excel_column ['recipientsPhone'] = $val;
  6782. }
  6783. } else {
  6784. if ($currentColumn == 'A')
  6785. $excel_column ['invoiceNo'] = $val;
  6786. elseif ($currentColumn == 'B')
  6787. $excel_column ['invoiceType'] = $val;
  6788. elseif ($currentColumn == 'C') {
  6789. $excel_column ['invoicePrice'] = $val;
  6790. } elseif ($currentColumn == 'D') {
  6791. $excel_column ['invoiceTitle'] = $val;
  6792. } elseif ($currentColumn == 'E') {
  6793. $excel_column ['userName'] = $val;
  6794. } elseif ($currentColumn == 'F') {
  6795. $excel_column ['categoryName'] = $val;
  6796. } elseif ($currentColumn == 'G') {
  6797. $excel_column ['invoiceElement'] = $val;
  6798. } elseif ($currentColumn == 'H') {
  6799. $excel_column ['remark'] = $val;
  6800. } elseif ($currentColumn == 'I') {
  6801. $excel_column ['date'] = $this->excelTime ( $val );
  6802. }
  6803. }
  6804. }
  6805. array_push ( $excel_array, $excel_column );
  6806. }
  6807. return $excel_array;
  6808. }
  6809. function excelTime($date, $time = false) {
  6810. if (function_exists ( 'GregorianToJD' )) {
  6811. if (is_numeric ( $date )) {
  6812. $jd = GregorianToJD ( 1, 1, 1970 );
  6813. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6814. $date = explode ( '/', $gregorian );
  6815. $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" : '');
  6816. return $date_str;
  6817. }
  6818. } else {
  6819. $date = $date > 25568 ? $date + 1 : 25569;
  6820. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6821. $ofs = (70 * 365 + 17 + 2) * 86400;
  6822. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6823. }
  6824. return $date;
  6825. }
  6826. /**
  6827. * 旧输入导入
  6828. */
  6829. function _GetFileEXT($filename) {
  6830. $pics = explode ( '.', $filename );
  6831. $num = count ( $pics );
  6832. return $pics [$num - 1];
  6833. }
  6834. function showCache($path = "", $sid = 0) {
  6835. // if (file_exists ( $path )) {
  6836. // $htm = file_get_contents ( $path );
  6837. // } else {
  6838. Doo::loadModel ( 'invoiceStatistics' );
  6839. $invoiceStatistics = new invoiceStatistics ();
  6840. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6841. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6842. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6843. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6844. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6845. /*
  6846. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6847. */
  6848. file_put_contents ( $path, $htm );
  6849. // }
  6850. return $htm;
  6851. }
  6852. /**
  6853. * 生成token
  6854. * @return string
  6855. */
  6856. function set_token() {
  6857. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6858. $str = sha1 ( $str ); // 加密
  6859. return $str;
  6860. }
  6861. /**
  6862. * 获取get或者POST值
  6863. *
  6864. * @param string $name 属性名称
  6865. * @return fixed 值
  6866. */
  6867. function get_args($name) {
  6868. if (isset ( $_GET [$name] )) {
  6869. if (is_array ( $_GET [$name] ))
  6870. return $_GET [$name];
  6871. else
  6872. return addslashes ( $_GET [$name] );
  6873. } elseif (isset ( $_POST [$name] )) {
  6874. if (is_array ( $_POST [$name] ))
  6875. return $_POST [$name];
  6876. else
  6877. return addslashes ( $_POST [$name] );
  6878. } else
  6879. return false;
  6880. }
  6881. function SafeFilter(&$arr) {
  6882. $ra = Array (
  6883. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6884. '/script/',
  6885. '/javascript/',
  6886. '/vbscript/',
  6887. '/expression/',
  6888. '/applet/',
  6889. '/meta/',
  6890. '/xml/',
  6891. '/blink/',
  6892. '/link/',
  6893. '/style/',
  6894. '/embed/',
  6895. '/object/',
  6896. '/frame/',
  6897. '/layer/',
  6898. '/title/',
  6899. '/bgsound/',
  6900. '/base/',
  6901. '/onload/',
  6902. '/onunload/',
  6903. '/onchange/',
  6904. '/onsubmit/',
  6905. '/onreset/',
  6906. '/onselect/',
  6907. '/onblur/',
  6908. '/onfocus/',
  6909. '/onabort/',
  6910. '/onkeydown/',
  6911. '/onkeypress/',
  6912. '/onkeyup/',
  6913. '/onclick/',
  6914. '/ondblclick/',
  6915. '/onmousedown/',
  6916. '/onmousemove/',
  6917. '/onmouseout/',
  6918. '/onmouseover/',
  6919. '/onmouseup/',
  6920. '/onunload/'
  6921. );
  6922. if (is_array ( $arr )) {
  6923. foreach ( $arr as $key => $value ) {
  6924. if (! is_array ( $value )) {
  6925. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6926. {
  6927. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6928. }
  6929. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6930. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6931. } else {
  6932. SafeFilter ( $arr [$key] );
  6933. }
  6934. }
  6935. }
  6936. }
  6937. /**
  6938. * Escape String
  6939. *
  6940. * @access public
  6941. * @param string
  6942. * @param bool whether or not the string will be used in a LIKE condition
  6943. * @return string
  6944. */
  6945. function escape_str($str, $like = FALSE) {
  6946. if (is_array ( $str )) {
  6947. foreach ( $str as $key => $val ) {
  6948. $str [$key] = $this->escape_str ( $val, $like );
  6949. }
  6950. return $str;
  6951. }
  6952. var_dump ( Doo::db ()->getDbObject () );
  6953. die ();
  6954. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6955. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6956. } elseif (function_exists ( 'mysql_escape_string' )) {
  6957. $str = mysql_escape_string ( $str );
  6958. } else {
  6959. $str = addslashes ( $str );
  6960. }
  6961. // escape LIKE condition wildcards
  6962. if ($like === TRUE) {
  6963. $str = str_replace ( array (
  6964. '%',
  6965. '_'
  6966. ), array (
  6967. '\\%',
  6968. '\\_'
  6969. ), $str );
  6970. }
  6971. return $str;
  6972. }
  6973. /**
  6974. * 获得分页数据
  6975. * @param unknown_type $table
  6976. * @param unknown_type $condition
  6977. * @param unknown_type $on_page
  6978. * @param unknown_type $page_size
  6979. */
  6980. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6981. $page_c = "";
  6982. $page ['previous'] = $this->get_previous ( $on_page );
  6983. $page ['on_page'] = $on_page;
  6984. $total_count = $this->get_table_count ( $table, $condition );
  6985. $total = intval ( $total_count / $page_size );
  6986. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6987. $page ['total_data'] = $total_count;
  6988. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6989. $i = 1;
  6990. $page_max = 1;
  6991. $page_width = 3;
  6992. if ($on_page >= $page_width) {
  6993. $page_max = intval ( $on_page / $page_width ) + 1;
  6994. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6995. }
  6996. for(; $i <= $page ['total_page']; $i ++) {
  6997. if ($i == $on_page)
  6998. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6999. else
  7000. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7001. if ($i == ($page_width * $page_max))
  7002. break;
  7003. }
  7004. $page ['page'] = $page_c;
  7005. $page ['lower'] = (-- $on_page) * $page_size;
  7006. return $page;
  7007. }
  7008. /**
  7009. * 获取上一页
  7010. * @param unknown_type $on_page
  7011. */
  7012. function get_previous($on_page = 1) {
  7013. return $on_page != 0 ? $on_page - 1 : $on_page;
  7014. }
  7015. /**
  7016. * 获取总页数
  7017. * @param unknown_type $table
  7018. * @param unknown_type $condition
  7019. */
  7020. public function get_table_count($table = "", $condition = "") {
  7021. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7022. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7023. // echo $sql;die;
  7024. $query = Doo::db ()->query ( $sql );
  7025. $result = $query->fetch ();
  7026. return $result ['count'];
  7027. }
  7028. /**
  7029. * 获得分页数据
  7030. * @param unknown_type $table
  7031. * @param unknown_type $condition
  7032. * @param unknown_type $on_page
  7033. * @param unknown_type $page_size
  7034. */
  7035. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7036. $page_c = "";
  7037. $page ['previous'] = $this->get_previous ( $on_page );
  7038. $page ['on_page'] = $on_page;
  7039. $total_count = $this->getTableCountBySql ( $sql );
  7040. $total = intval ( $total_count / $page_size );
  7041. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7042. $page ['total_data'] = $total_count;
  7043. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7044. $i = 1;
  7045. $page_max = 1;
  7046. $page_width = 3;
  7047. if ($on_page >= $page_width) {
  7048. $page_max = intval ( $on_page / $page_width ) + 1;
  7049. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7050. }
  7051. for(; $i <= $page ['total_page']; $i ++) {
  7052. if ($i == $on_page)
  7053. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7054. else
  7055. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7056. if ($i == ($page_width * $page_max))
  7057. break;
  7058. }
  7059. $page ['page'] = $page_c;
  7060. $page ['lower'] = (-- $on_page) * $page_size;
  7061. return $page;
  7062. }
  7063. /**
  7064. * 获得总页数 sql
  7065. * @param string $type
  7066. * @return boolean[]
  7067. */
  7068. public function getTableCountBySql($sql = "") {
  7069. $query = Doo::db ()->query ( $sql );
  7070. $result = $query->fetchAll ();
  7071. return count ( $result );
  7072. }
  7073. function isInvoiceNew($type = "GLOBAL") {
  7074. Doo::loadModel ( 'invoice' );
  7075. $invoice = new invoice ();
  7076. Doo::loadModel ( 'invoiceReceivables' );
  7077. $invoiceReceivables = new invoiceReceivables ();
  7078. Doo::loadModel ( 'staff' );
  7079. $staff = new staff ();
  7080. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7081. // 我的发票待处理
  7082. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7083. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7084. 'desc' => 'iid',
  7085. 'asArray' => TRUE
  7086. ) );
  7087. // 我的收款待入账
  7088. /*
  7089. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7090. */
  7091. // 发票审批
  7092. $approval = $invoice->getOne ( array (
  7093. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7094. 'desc' => 'iid',
  7095. 'asArray' => true
  7096. ) );
  7097. // 发票邮寄
  7098. $post = $invoice->getOne ( array (
  7099. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7100. 'asArray' => TRUE
  7101. ) );
  7102. // 发票打印
  7103. $print = $invoice->getOne ( array (
  7104. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7105. 'desc' => 'iid',
  7106. 'asArray' => TRUE
  7107. ) );
  7108. // 发票退票 printStatus=1 and
  7109. $untread = $invoice->getOne ( array (
  7110. 'where' => " untreadStatus=1 and status=2 ",
  7111. 'asArray' => TRUE
  7112. ) );
  7113. $new = array (
  7114. 'GLOBAL' => FALSE,
  7115. 'pendingInvoice' => FALSE,
  7116. // 'myClaim' => FALSE,
  7117. 'approval' => FALSE,
  7118. 'post' => FALSE,
  7119. 'print' => FALSE,
  7120. 'untread' => FALSE
  7121. );
  7122. // || ! empty ( $myClaim )
  7123. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7124. $new ['GLOBAL'] = TRUE;
  7125. if (! empty ( $pendingInvoice ))
  7126. $new ['pendingInvoice'] = TRUE;
  7127. // if (! empty ( $myClaim ))
  7128. // $new ['myClaim'] = TRUE;
  7129. if (! empty ( $approval ))
  7130. $new ['approval'] = TRUE;
  7131. if (! empty ( $post ))
  7132. $new ['post'] = TRUE;
  7133. if (! empty ( $print ))
  7134. $new ['print'] = TRUE;
  7135. if (! empty ( $untread ))
  7136. $new ['untread'] = TRUE;
  7137. return $new;
  7138. }
  7139. function setWXMsg($rid, $typeMsg = '') {
  7140. Doo::loadModel ( 'invoice' );
  7141. $invoice = new invoice ();
  7142. $invoiceDetail = $invoice->getOne ( array (
  7143. 'where' => 'iid=' . $rid,
  7144. 'asArray' => true
  7145. ) );
  7146. if (! empty ( $invoiceDetail )) {
  7147. Doo::loadModel ( 'staff' );
  7148. $staff = new staff ();
  7149. $staffmsg = $staff->getOne ( array (
  7150. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7151. 'asArray' => TRUE
  7152. ) );
  7153. if (! empty ( $staffmsg ['wxid'] )) {
  7154. require_once (SITE_PATH . '/protected/class/client.php');
  7155. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7156. $user = $staffmsg ['wxid'];
  7157. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7158. if (empty ( $expCom ))
  7159. $expCom [0] = '';
  7160. $msg = "";
  7161. if (empty ( $typeMsg ))
  7162. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7163. elseif ($typeMsg == "PRINT")
  7164. $msg = '太好了,您的发票已打印完成。';
  7165. $result = $client->SendMsg ( $user, $msg, 'text' );
  7166. }
  7167. }
  7168. }
  7169. /**
  7170. * 获取微信部门
  7171. * @param string $category
  7172. * @return number|mixed
  7173. */
  7174. function getToparty($category = '') {
  7175. $token = $this->getAccessToken (); //
  7176. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7177. $toparty = 0;
  7178. foreach ( $result ['department'] as $key => $value ) {
  7179. if ($value ['name'] == $category)
  7180. $toparty = $value ['id'];
  7181. }
  7182. return $toparty;
  7183. }
  7184. /**
  7185. * 获得某部门下的用户
  7186. * @param string $toparty
  7187. */
  7188. function getUserByToparty($toparty = '') {
  7189. $token = $this->getAccessToken (); //
  7190. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7191. $userList = array ();
  7192. foreach ( $result ['userlist'] as $key => $value ) {
  7193. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7194. }
  7195. return $userList;
  7196. }
  7197. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7198. $token = $this->getAccessToken ();
  7199. if ($text == 'text') {
  7200. $data = '{
  7201. "touser": "' . $toparty . '",
  7202. "toparty": "",
  7203. "totag": "",
  7204. "msgtype": "text",
  7205. "agentid": 1000002,
  7206. "text": {
  7207. "content": "' . $msg . '"
  7208. },
  7209. "safe":0
  7210. }';
  7211. }
  7212. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7213. if ($result->errmsg != 'ok') {
  7214. return 0;
  7215. } else {
  7216. return 1;
  7217. }
  7218. }
  7219. /**
  7220. * 获得可以发送微信用户列表
  7221. * @param string $category
  7222. * @return string
  7223. */
  7224. function getWxidByCategory($category = "") {
  7225. if (empty ( $category ))
  7226. return "";
  7227. Doo::loadModel ( 'staff' );
  7228. $staff = new staff ();
  7229. $toparty = $this->getToparty ( $category );
  7230. $wxList = array ();
  7231. $wxString = "";
  7232. if (! empty ( $toparty )) {
  7233. $userList = $this->getUserByToparty ( $toparty );
  7234. $userCon = implode ( ',', $userList );
  7235. // echo $userCon;
  7236. $sidList = $staff->getStaffByWxid ( $userCon );
  7237. foreach ( $sidList as $key => $value ) {
  7238. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7239. if ($falg) {
  7240. array_push ( $wxList, $value ['wxid'] );
  7241. }
  7242. }
  7243. $wxString = implode ( '|', $wxList );
  7244. }
  7245. return $wxString;
  7246. }
  7247. /**
  7248. * 读取发送信息规则判断是否需要发送
  7249. * @param number $sid
  7250. * @param string $sendType
  7251. * @return boolean
  7252. */
  7253. function isSendNotification($sid = 0, $sendType = '') {
  7254. Doo::loadModel ( "notificationConf" );
  7255. $notificationConf = new notificationConf ();
  7256. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7257. $conf = array ();
  7258. $sendFlag = true;
  7259. if (! empty ( $detail )) {
  7260. $conf = json_decode ( $detail ['conf'], true );
  7261. if (! empty ( $sendType )) {
  7262. if (isset ( $conf [$sendType] )) {
  7263. if ($conf [$sendType] == "CLOSE")
  7264. $sendFlag = false;
  7265. elseif ($conf [$sendType] == "Weekend") {
  7266. $day = date ( "w" );
  7267. if (1 <= $day && 5 >= $day)
  7268. $sendFlag = false;
  7269. } elseif ($conf [$sendType] == "OneToFriday") {
  7270. $day = date ( "w" );
  7271. if (0 == $day || 6 == $day)
  7272. $sendFlag = false;
  7273. }
  7274. }
  7275. } else
  7276. $sendFlag = false;
  7277. }
  7278. return $sendFlag;
  7279. }
  7280. /**
  7281. * 根据规则发送信息
  7282. * @param unknown $msg
  7283. * @param unknown $title
  7284. * @param unknown $url
  7285. * @param unknown $user
  7286. * @param string $text
  7287. * @return number
  7288. */
  7289. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7290. $token = $this->getAccessToken ();
  7291. $falg = $this->isSendNotification ( $sid, $sendType );
  7292. // if ($text == 'text') {
  7293. // $data = '{
  7294. // "touser": "' . $user . '",
  7295. // "toparty": "",
  7296. // "totag": "",
  7297. // "msgtype": "text",
  7298. // "agentid": 1000002,
  7299. // "text": {
  7300. // "content": "' . $msg . '"
  7301. // },
  7302. // "safe":0
  7303. // }';
  7304. // } else {
  7305. $data = '{
  7306. "touser": "' . $user . '",
  7307. "toparty": "",
  7308. "totag": "",
  7309. "msgtype": "news",
  7310. "agentid": 1000002,
  7311. "news": {
  7312. "articles":[
  7313. {
  7314. "title": "' . $title . '",
  7315. "description": "' . $msg . '",
  7316. "url": "' . $url . '",
  7317. "picurl": ""
  7318. }
  7319. ]
  7320. }
  7321. }';
  7322. // }
  7323. if ($falg) {
  7324. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7325. if ($result->errmsg != 'ok') {
  7326. return 0;
  7327. } else {
  7328. return 1;
  7329. }
  7330. } else
  7331. return 0;
  7332. }
  7333. private function getAccessToken() {
  7334. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7335. // $file = './access_token.txt';
  7336. // $data = json_decode ( file_get_contents ( $file ) );
  7337. // if ($data->expire_time < time () or ! $data->expire_time) {
  7338. // 如果是企业号用以下URL获取access_token
  7339. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7340. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7341. $res = json_decode ( $this->httpGet ( $url ) );
  7342. $access_token = $res->access_token;
  7343. // echo $access_token;
  7344. // if ($access_token) {
  7345. // $data->expire_time = time () + 7000;
  7346. // $data->access_token = $access_token;
  7347. // $fp = fopen ( $file, "w" );
  7348. // fwrite ( $fp, json_encode ( $data ) );
  7349. // fclose ( $fp );
  7350. // }
  7351. // } else {
  7352. // $access_token = $data->access_token;
  7353. // }
  7354. return $access_token;
  7355. }
  7356. private function httpGet($url) {
  7357. $curl = curl_init ();
  7358. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7359. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7360. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7361. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7362. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7363. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7364. curl_setopt ( $curl, CURLOPT_URL, $url );
  7365. $res = curl_exec ( $curl );
  7366. curl_close ( $curl );
  7367. return $res;
  7368. }
  7369. private function httpPost($url, $data) {
  7370. $curl = curl_init ();
  7371. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7372. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7373. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7374. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7375. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7376. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7377. curl_setopt ( $curl, CURLOPT_URL, $url );
  7378. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7379. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7380. $res = curl_exec ( $curl );
  7381. curl_close ( $curl );
  7382. return $res;
  7383. }
  7384. }
  7385. ?>