InvoiceController.php 315 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request-iacd' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. 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. $tokenTime=time().rand(5, 15);
  250. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  251. $this->data ['token'] = $token;
  252. $this->data['tokenTime']=$tokenTime;
  253. $this->data ['memu'] = "invoice";
  254. $this->data ['staff'] = $this->staff;
  255. $this->data ['receiptMemu'] = 'invoice';
  256. $this->render ( "/admin/invoiceAdd", $this->data );
  257. }
  258. /**
  259. * 自更新发票信息库
  260. * @param unknown $invoicePrintDetail
  261. */
  262. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  263. // 发票信息库
  264. Doo::loadModel ( 'invoiceInfoBase' );
  265. $invoiceInfoBase = new invoiceInfoBase ();
  266. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  267. $TIN = $invoicePrintDetail ['TIN'];
  268. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  269. if (empty ( $invoiceTitle ))
  270. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  271. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  272. // 确认有该条发票信息
  273. $invoiceInfoBase = new invoiceInfoBase ();
  274. if (! empty ( $IIBList )) {
  275. // 发票库里的信息数量
  276. $IIBListCount = count ( $IIBList );
  277. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  278. $item = array (
  279. 'iibID' => $IIBList [0] ['iibID'],
  280. 'invoiceTitle' => $invoiceTitle,
  281. 'TIN' => $TIN
  282. );
  283. if (! empty ( $invoicePrintDetail ['address'] )) {
  284. $item += array (
  285. 'address' => $invoicePrintDetail ['address']
  286. );
  287. }
  288. if (! empty ( $invoicePrintDetail ['phone'] )) {
  289. $item += array (
  290. 'phone' => $invoicePrintDetail ['phone']
  291. );
  292. }
  293. if (! empty ( $invoicePrintDetail ['bank'] )) {
  294. $item += array (
  295. 'bank' => $invoicePrintDetail ['bank']
  296. );
  297. }
  298. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  299. $item += array (
  300. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  301. );
  302. }
  303. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  304. $item += array (
  305. 'updateDate' => $invoicePrintDetail ['date']
  306. );
  307. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  308. }
  309. } else { // 删除多张发票,重新添加发票
  310. $iibIDStr = '';
  311. $iibID = array ();
  312. foreach ( $IIBList as $key => $value ) {
  313. array_push ( $iibID, $value ['iibID'] );
  314. }
  315. $iibIDStr = implode ( ",", $iibID ); // 删除
  316. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  317. $item = array (
  318. 'invoiceTitle' => $invoiceTitle,
  319. 'TIN' => $TIN,
  320. 'address' => $invoicePrintDetail ['address'],
  321. 'phone' => $invoicePrintDetail ['phone'],
  322. 'bank' => $invoicePrintDetail ['bank'],
  323. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  324. 'updateDate' => $invoicePrintDetail ['date']
  325. );
  326. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  327. }
  328. } else { // 没有新增发票信息
  329. $item = array (
  330. 'invoiceTitle' => $invoiceTitle,
  331. 'TIN' => $TIN,
  332. 'address' => $invoicePrintDetail ['address'],
  333. 'phone' => $invoicePrintDetail ['phone'],
  334. 'bank' => $invoicePrintDetail ['bank'],
  335. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  336. 'updateDate' => $invoicePrintDetail ['date']
  337. );
  338. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  339. }
  340. }
  341. function invoiceAddFill() {
  342. session_start ();
  343. Doo::loadModel ( 'L_category' );
  344. $lCategory = new L_category ();
  345. $category = $lCategory->find ( array (
  346. 'asArray' => true
  347. ) );
  348. $this->data ['category'] = $category;
  349. Doo::loadModel ( 'invoiceTraining' );
  350. $invoiceTraining = new invoiceTraining ();
  351. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  352. $this->data ['itList'] = $itList;
  353. Doo::loadModel ( 'invoice' );
  354. $invoice = new invoice ();
  355. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  356. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  357. $token = $this->set_token ();
  358. $tokenTime=time().rand(5, 15);
  359. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  360. $this->data ['token'] = $token;
  361. $this->data['tokenTime']=$tokenTime;
  362. $this->data ['invoiceDetail'] = $detail;
  363. $this->data ['memu'] = "invoice";
  364. $this->data ['staff'] = $this->staff;
  365. $this->data ['receiptMemu'] = 'invoice';
  366. $this->render ( "/admin/invoiceAddFill", $this->data );
  367. }
  368. /**
  369. * 提交一份开票申请,并记录下操作日志
  370. *
  371. * @since 1.0.0
  372. * @var integer cid 办事处ID
  373. * @var integer invoiceType 发票类型
  374. * @var integer doPost 是否邮寄
  375. * @var integer invoicePrice 开票金额
  376. * @var string invoiceElement 开票内容
  377. * @var string invoiceTitle 发票抬头
  378. * @var string invoiceCompany 单位名称
  379. * @var string TIN 纳税人识别码
  380. * @var string address 注册地址
  381. * @var string phone 注册电话
  382. * @var string bank 开户银行
  383. * @var string bankAccount 银行账户
  384. * @var string recipients 收件人
  385. * @var string recipientsPhone 收件人手机/电话
  386. * @var string recipientsAddress 收件地址
  387. * @var string mailItems 邮寄物品
  388. * @var string remark 备注
  389. * @return string 返回跳转开票主页路径
  390. */
  391. function invoiceAddDo() {
  392. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  393. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  394. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  395. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  396. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  397. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  398. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  399. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  400. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  401. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  402. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  403. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  404. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  405. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  406. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  407. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  408. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  409. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  410. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  411. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  412. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  413. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  414. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  415. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  416. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  417. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  418. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  419. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  420. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  421. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  422. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  423. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  424. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  425. /*
  426. * $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;
  427. */
  428. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  429. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  430. if (empty ( $token )) {
  431. die ( 'illegal request-token' );
  432. } else {
  433. session_start ();
  434. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  435. header ( 'Content-Type:text/html;charset=utf-8' );
  436. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  437. die ( '请重新刷新发票申请页面' );
  438. }elseif($_SESSION [$sessionKey]=='repeat'){
  439. die ( '请勿重复申请发票' );
  440. } else {
  441. if ($_SESSION [$sessionKey] != $token){
  442. die ( '请勿重复申请发票' );
  443. }else{
  444. $_SESSION [$sessionKey] = 'repeat';
  445. }
  446. }
  447. }
  448. if ($invoiceType == 1) {
  449. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  450. if ($temporary > 100001) {
  451. header ( 'Content-Type:text/html;charset=utf-8' );
  452. die ( '专用发票总金额暂时不能超过100000.00(一万)元。' );
  453. // die ( 'illegal request-Please priceError' );
  454. }
  455. }
  456. if (empty ( $this->staff [0] ))
  457. die ( 'illegal request-Please login' );
  458. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  459. Doo::loadModel ( 'invoice' );
  460. $invoice = new invoice ();
  461. Doo::loadModel ( 'L_category' );
  462. $lCategory = new L_category ();
  463. Doo::loadModel ( 'invoiceManage' );
  464. $invoiceManage = new invoiceManage ();
  465. Doo::loadModel ( 'invoiceOperationLog' );
  466. $invoiceOperationLog = new invoiceOperationLog ();
  467. Doo::loadClass ( 'XDeode' );
  468. $XDeode = new XDeode ( 5 );
  469. $trainId = $XDeode->decode ( $trainId );
  470. $categoryDetil = $lCategory->getOne ( array (
  471. 'SELECT' => 'title',
  472. 'where' => 'cid=' . $cid,
  473. 'asArray' => true
  474. ) );
  475. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  476. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  477. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  478. // print_r(current($invoiceManageDetail ['staffList']));
  479. // die;
  480. $moldManage = array ();
  481. foreach ( $invoiceManageList as $key => $value ) {
  482. if ($value ['mold'] == '发票打印')
  483. $moldManage [$value ['mold']] = $value ['staffList'];
  484. elseif ($value ['mold'] == '发票邮寄')
  485. $moldManage [$value ['mold']] = $value ['staffList'];
  486. elseif ($value ['mold'] == '发票退票')
  487. $moldManage [$value ['mold']] = $value ['staffList'];
  488. }
  489. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  490. $st = '';
  491. if ($settlementType == 'SOFTWARE') {
  492. $st = 0;
  493. $trainId = 0;
  494. } elseif ($settlementType == 'TRAINING') {
  495. $st = 1;
  496. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  497. die ( 'illegal request-trainingIdError' );
  498. }
  499. } else {
  500. die ( 'illegal request-settlementError' );
  501. }
  502. $item = array (
  503. 'cid' => $cid,
  504. 'categoryName' => $categoryDetil ['title'],
  505. 'invoiceElement' => $invoiceElement,
  506. 'invoiceQuantity' => $invoiceQuantity,
  507. 'invoiceUnitPrice' => $invoiceUnitPrice,
  508. 'invoicePrice' => $invoicePrice,
  509. 'invoiceType' => $invoiceType,
  510. 'settlementType' => $st,
  511. 'doPost' => $doPost,
  512. 'status' => 1,
  513. 'invoiceSerial' => "#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT),
  514. 'date' => date ( "Y-m-d H:i:s" ),
  515. 'updateTime' => date ( "Y-m-d H:i:s" ),
  516. 'sid' => $this->staff [0] ['sid'],
  517. 'userName' => $this->staff [0] ['username'],
  518. 'invoiceManage' => $invoiceManageDetail ['staff'],
  519. 'pendingApprovals' => $pendingApprovalsSid,
  520. 'moldManage' => json_encode ( $moldManage ),
  521. 'remark' => $remark,
  522. 'trainId' => $trainId
  523. );
  524. if ($invoiceType == 0)
  525. $item += array (
  526. 'invoiceTitle' => $invoiceTitle,
  527. 'TIN' => $TINT,
  528. 'address' => $addressT,
  529. 'phone' => $phoneT,
  530. 'bank' => $bankT,
  531. 'bankAccount' => $bankAccountT
  532. );
  533. else {
  534. $item += array (
  535. 'invoiceCompany' => $invoiceCompany,
  536. 'TIN' => $TIN,
  537. 'address' => $address,
  538. 'phone' => $phone,
  539. 'bank' => $bank,
  540. 'bankAccount' => $bankAccount
  541. );
  542. }
  543. if ($doPost == 1) {
  544. $mailList = array (
  545. 'invoice' => 1,
  546. 'mailItems' => $mailItems
  547. );
  548. if (! empty ( $softLock ))
  549. $mailList += array (
  550. 'softLock' => $softLockNum
  551. );
  552. else
  553. $mailList += array (
  554. 'softLock' => 0
  555. );
  556. if (! empty ( $contract ))
  557. $mailList += array (
  558. 'contract' => $contractNum
  559. );
  560. else
  561. $mailList += array (
  562. 'contract' => 0
  563. );
  564. if (! empty ( $instructions ))
  565. $mailList += array (
  566. 'instructions' => $instructionsNum
  567. );
  568. else
  569. $mailList += array (
  570. 'instructions' => 0
  571. );
  572. if (! empty ( $remittance ))
  573. $mailList += array (
  574. 'remittance' => $remittance
  575. );
  576. else
  577. $mailList += array (
  578. 'remittance' => ''
  579. );
  580. $mailString = '发票x1张,备注:' . $mailItems;
  581. if (! empty ( $softLock ))
  582. $mailString .= ',软件锁x' . $softLockNum . '个';
  583. if (! empty ( $contract ))
  584. $mailString .= ',合同x' . $contractNum . '份';
  585. if (! empty ( $instructions ))
  586. $mailString .= ',说明书x' . $instructionsNum . '本';
  587. if (! empty ( $remittance ))
  588. $mailString .= ',汇款账号单(张)';
  589. $item += array (
  590. 'recipients' => $recipients,
  591. 'recipientsPhone' => $recipientsPhone,
  592. 'recipientsAddress' => $recipientsAddress,
  593. 'mailItems' => $mailString,
  594. 'mailItemsJson' => json_encode ( $mailList )
  595. );
  596. }
  597. $iid = $invoice->addInvoice ( $item );
  598. // 如果是培训班结算 创建培训班发票到培训班备份中
  599. if (! empty ( $st ) && $st == 1) {
  600. Doo::loadModel ( 'invoiceStore' );
  601. $invoiceStore = new invoiceStore ();
  602. Doo::loadModel ( 'invoiceTraining' );
  603. $invoiceTraining = new invoiceTraining ();
  604. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  605. $itemIS = array (
  606. 'isid' => $isid,
  607. 'ipSource' => 1,
  608. 'apStatus' => 1,
  609. 'iid' => $iid
  610. );
  611. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  612. // 更新培训班总数量
  613. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  614. $item = array (
  615. 'itid' => $trainId,
  616. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  617. 'submitStatus' => 1
  618. );
  619. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  620. }
  621. // 操作日志
  622. $item = array (
  623. 'date' => date ( "Y-m-d H:i:s" ),
  624. 'operation' => "创建",
  625. 'status' => 1,
  626. 'img' => $this->staff [0] ['avatar'],
  627. 'username' => $this->staff [0] ['username'],
  628. 'uid' => $this->staff [0] ['sid'],
  629. 'category' => $this->staff [0] ['category'],
  630. 'iid' => $iid
  631. );
  632. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  633. $item = array (
  634. 'date' => date ( "Y-m-d H:i:s" ),
  635. 'operation' => "提交审批",
  636. 'status' => 1,
  637. 'img' => $this->staff [0] ['avatar'],
  638. 'username' => $this->staff [0] ['username'],
  639. 'uid' => $this->staff [0] ['sid'],
  640. 'category' => $this->staff [0] ['category'],
  641. 'iid' => $iid
  642. );
  643. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  644. Doo::loadModel ( 'staff' );
  645. $staff = new staff ();
  646. $username2 = $staff->getOne ( array (
  647. 'select' => 'wxid',
  648. 'where' => 'sid=' . $pendingApprovalsSid,
  649. 'asArray' => TRUE
  650. ) );
  651. // 发送微信审批通知
  652. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  653. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  654. }
  655. return "/invoice";
  656. }
  657. function invoiceEdit() {
  658. Doo::loadClass ( 'XDeode' );
  659. $XDeode = new XDeode ( 5 );
  660. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  661. $iid = $XDeode->decode ( $iid );
  662. if (! is_numeric ( $iid ))
  663. die ( 'illegal request' );
  664. Doo::loadModel ( 'invoice' );
  665. $invoice = new invoice ();
  666. Doo::loadModel ( 'invoiceOperationLog' );
  667. $invoiceOperationLog = new invoiceOperationLog ();
  668. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  669. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  670. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  671. $this->data ['operation'] = $operation;
  672. $this->data ['invoiceDetail'] = $invoiceDetail;
  673. $this->data ['memu'] = "invoice";
  674. $this->data ['staff'] = $this->staff;
  675. $this->data ['receiptMemu'] = 'invoice';
  676. $this->render ( "/admin/invoiceEdit", $this->data );
  677. }
  678. /**
  679. * 重新编辑退回的发票
  680. * @return string
  681. */
  682. function invoiceEditDo() {
  683. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  684. Doo::loadModel ( 'invoice' );
  685. $invoice = new invoice ();
  686. $iid = $invoice->authcode ( $iidKey );
  687. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  688. die ( 'illegal request' );
  689. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  690. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  691. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  692. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  693. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  694. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  695. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  696. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  697. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  698. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  699. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  700. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  701. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  702. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  703. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  704. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  705. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  706. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  707. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  708. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  709. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  710. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  711. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  712. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  713. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  714. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  715. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  716. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  717. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  718. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  719. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  720. if ($invoiceType == 1) {
  721. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  722. if ($temporary > 100001)
  723. die ( 'illegal request-Please priceError' );
  724. }
  725. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  726. Doo::loadModel ( 'invoiceManage' );
  727. $invoiceManage = new invoiceManage ();
  728. Doo::loadModel ( 'invoiceOperationLog' );
  729. $invoiceOperationLog = new invoiceOperationLog ();
  730. Doo::loadModel ( 'invoiceStore' );
  731. $invoiceStore = new invoiceStore ();
  732. $cid = explode ( ':', $cid );
  733. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  734. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  735. $moldManage = array ();
  736. foreach ( $invoiceManageList as $key => $value ) {
  737. if ($value ['mold'] == '发票打印')
  738. $moldManage [$value ['mold']] = $value ['staffList'];
  739. elseif ($value ['mold'] == '发票邮寄')
  740. $moldManage [$value ['mold']] = $value ['staffList'];
  741. elseif ($value ['mold'] == '发票打印')
  742. $moldManage [$value ['mold']] = $value ['staffList'];
  743. }
  744. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  745. $item = array (
  746. 'iid' => $iid,
  747. 'cid' => $cid [0],
  748. 'categoryName' => $cid [1],
  749. 'invoiceElement' => $invoiceElement,
  750. 'invoiceQuantity' => $invoiceQuantity,
  751. 'invoiceUnitPrice' => $invoiceUnitPrice,
  752. 'invoicePrice' => $invoicePrice,
  753. 'invoiceType' => $invoiceType,
  754. 'doPost' => $doPost,
  755. 'status' => 1,
  756. 'updateTime' => date ( "Y-m-d H:i:s" ),
  757. 'remark' => $remark
  758. );
  759. if ($invoiceType == 0)
  760. $item += array (
  761. 'invoiceTitle' => $invoiceTitle,
  762. 'TIN' => $TINT,
  763. 'address' => $addressT,
  764. 'phone' => $phoneT,
  765. 'bank' => $bankT,
  766. 'bankAccount' => $bankAccountT
  767. );
  768. else {
  769. $item += array (
  770. 'invoiceCompany' => $invoiceCompany,
  771. 'TIN' => $TIN,
  772. 'address' => $address,
  773. 'phone' => $phone,
  774. 'bank' => $bank,
  775. 'bankAccount' => $bankAccount
  776. );
  777. }
  778. if ($doPost == 1) {
  779. $mailList = array (
  780. 'invoice' => 1,
  781. 'mailItems' => $mailItems
  782. );
  783. if (! empty ( $softLock ))
  784. $mailList += array (
  785. 'softLock' => $softLockNum
  786. );
  787. else
  788. $mailList += array (
  789. 'softLock' => '0'
  790. );
  791. if (! empty ( $contract ))
  792. $mailList += array (
  793. 'contract' => $contractNum
  794. );
  795. else
  796. $mailList += array (
  797. 'contract' => '0'
  798. );
  799. if (! empty ( $instructions ))
  800. $mailList += array (
  801. 'instructions' => $instructionsNum
  802. );
  803. else
  804. $mailList += array (
  805. 'instructions' => '0'
  806. );
  807. if (! empty ( $remittance ))
  808. $mailList += array (
  809. 'remittance' => $remittance
  810. );
  811. else
  812. $mailList += array (
  813. 'remittance' => ''
  814. );
  815. $mailString = '发票x1,备注:' . $mailItems;
  816. if (! empty ( $softLock ))
  817. $mailString .= ',软件锁x' . $softLockNum;
  818. if (! empty ( $contract ))
  819. $mailString .= ',合同x' . $contractNum;
  820. if (! empty ( $instructions ))
  821. $mailString .= ',说明书x' . $instructionsNum;
  822. if (! empty ( $remittance ))
  823. $mailString .= ',汇款账号单';
  824. $item += array (
  825. 'recipients' => $recipients,
  826. 'recipientsPhone' => $recipientsPhone,
  827. 'recipientsAddress' => $recipientsAddress,
  828. 'mailItems' => $mailString,
  829. 'mailItemsJson' => json_encode ( $mailList )
  830. );
  831. }
  832. $invoice->setInvoiceByCondition ( $item );
  833. // 更新培训班仓库里的发票
  834. $detail = $invoice->getInvoiceByIid ( $iid );
  835. if (! empty ( $detail ['isid'] )) {
  836. $invoiceStore->isid = $detail ['isid'];
  837. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  838. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  839. $invoiceStore->invoicePrice = $invoicePrice;
  840. $invoiceStore->update ();
  841. }
  842. $item = array (
  843. 'date' => date ( "Y-m-d H:i:s" ),
  844. 'operation' => "重新提交审批",
  845. 'status' => 1,
  846. 'img' => $this->staff [0] ['avatar'],
  847. 'username' => $this->staff [0] ['username'],
  848. 'uid' => $this->staff [0] ['sid'],
  849. 'category' => $this->staff [0] ['category'],
  850. 'iid' => $iid
  851. );
  852. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  853. }
  854. return "/invoice";
  855. }
  856. /**
  857. * 培训班
  858. */
  859. function invoiceTraining() {
  860. Doo::loadModel ( 'L_category' );
  861. $lCategory = new L_category ();
  862. Doo::loadModel ( 'invoiceTraining' );
  863. $invoiceTraining = new invoiceTraining ();
  864. Doo::loadModel ( 'invoiceTrainManage' );
  865. $invoiceTrainManage = new invoiceTrainManage ();
  866. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  867. $cidList = array ();
  868. foreach ( $imcStaff as $key => $value ) {
  869. array_push ( $cidList, $value ['cid'] );
  870. }
  871. if (empty ( $cidList )) {
  872. $cidString = $this->staff [0] ['cid'];
  873. } else {
  874. $cidString = implode ( ',', $cidList );
  875. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  876. }
  877. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  878. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  879. $category = $lCategory->getCategory ();
  880. $itid = array ();
  881. foreach ( $itTodoList as $key => $value ) {
  882. array_push ( $itid, $value ['itid'] );
  883. // 如果入账100%更新为已完成
  884. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  885. $invoiceTraining = new invoiceTraining ();
  886. $invoiceTraining->itid = $value ['itid'];
  887. $invoiceTraining->status = 2;
  888. $invoiceTraining->update ();
  889. }
  890. }
  891. foreach ( $itedList as $value ) {
  892. array_push ( $itid, $value ['itid'] );
  893. }
  894. $itid = implode ( ',', $itid );
  895. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  896. // print_r($itTodoList);
  897. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  898. $this->data ['itTodoList'] = $itTodoList;
  899. $this->data ['itedList'] = $itedList;
  900. $this->data ['category'] = $category;
  901. $this->data ['memu'] = "invoice";
  902. $this->data ['staff'] = $this->staff;
  903. $this->data ['receiptMemu'] = 'invoiceTraining';
  904. $this->render ( "/admin/invoiceTraining", $this->data );
  905. }
  906. /**
  907. * 创建培训班
  908. */
  909. function invoiceTrainingAdd() {
  910. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  911. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  912. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  913. if (empty ( $this->staff [0] ))
  914. die ( 'illegal request' );
  915. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  916. Doo::loadModel ( 'invoiceTraining' );
  917. $invoiceTraining = new invoiceTraining ();
  918. Doo::loadModel ( 'invoice' );
  919. $invoice = new invoice ();
  920. Doo::loadModel ( 'L_category' );
  921. $lCategory = new L_category ();
  922. Doo::loadModel ( 'invoiceManage' );
  923. $invoiceManage = new invoiceManage ();
  924. Doo::loadModel ( 'invoiceOperationLog' );
  925. $invoiceOperationLog = new invoiceOperationLog ();
  926. $item = array (
  927. 'cid' => $cid,
  928. 'trainName' => $trainName,
  929. 'trainDate' => $trainDate,
  930. 'creator' => $this->staff [0] ['sid'],
  931. 'creatorDate' => date ( "Y-m-d H:i:s" )
  932. );
  933. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  934. }
  935. return "/invoiceTraining";
  936. }
  937. /**
  938. * 删除培训班
  939. */
  940. function invoiceTrainingDelDo() {
  941. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  942. if (! empty ( $itid )) {
  943. Doo::loadModel ( 'invoiceTraining' );
  944. $invoiceTraining = new invoiceTraining ();
  945. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  946. }
  947. return "/invoiceTraining";
  948. }
  949. /**
  950. * 培训班详情
  951. */
  952. function invoiceTrainingDetail() {
  953. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  954. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  955. Doo::loadModel ( 'invoiceTraining' );
  956. $invoiceTraining = new invoiceTraining ();
  957. Doo::loadModel ( 'invoiceStore' );
  958. $invoiceStore = new invoiceStore ();
  959. if (empty ( $itid ))
  960. die ( 'illegal request' );
  961. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  962. if ($trainStatus == "SUBED")
  963. $con = ' (b.untreadStatus is null ) and ';
  964. elseif ($trainStatus == "APPROVAL")
  965. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  966. elseif ($trainStatus == "TICKET")
  967. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  968. elseif ($trainStatus == "TICKETING") {
  969. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  970. }
  971. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  972. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  973. //print_r($isList);
  974. $trainlist = array ();
  975. foreach ( $isList as $key => $value ) {
  976. $irDetail = array ();
  977. if ($value ['apStatus'] == 1) {
  978. // array_push ( $irDetail, '' );
  979. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  980. } else {
  981. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  982. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  983. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  984. }
  985. array_push ( $irDetail, $value ['invoiceSerial'] );
  986. if ($value ['invoiceType'] == 1)
  987. array_push ( $irDetail, $value ['invoiceCompany'] );
  988. else
  989. array_push ( $irDetail, $value ['invoiceTitle'] );
  990. array_push ( $irDetail, $value ['TIN'] );
  991. array_push ( $irDetail, $value ['userName'] );
  992. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  993. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  994. } else
  995. array_push ( $irDetail, $value ['mailItems'] );
  996. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  997. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  998. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  999. array_push ( $irDetail, $value ['invoiceElement'] );
  1000. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1001. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1002. if ($value ['invoiceType'] == 1)
  1003. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1004. else
  1005. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1006. array_push ( $irDetail, $value ['remark'] );
  1007. if ($value ['status'] == 1)
  1008. array_push ( $irDetail, '审批中' );
  1009. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1010. array_push ( $irDetail, '已出票' );
  1011. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1012. array_push ( $irDetail, '已入账' );
  1013. else
  1014. array_push ( $irDetail, '' );
  1015. array_push ( $irDetail, $value ['invoiceNo'] );
  1016. array_push ( $irDetail, $value ['printTime'] );
  1017. $html = '';
  1018. foreach ( $value ['invoiceReceivables'] as $value ) {
  1019. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  1020. }
  1021. array_push ( $irDetail, $html );
  1022. array_push ( $trainlist, $irDetail );
  1023. }
  1024. $trainlistJson = json_encode ( $trainlist );
  1025. if (empty ( $detail ))
  1026. die ( 'illegal request' );
  1027. // 培训班结算是否有和是否已经结算完成
  1028. Doo::loadModel ( 'receipt' );
  1029. $receipt = new receipt ();
  1030. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1031. $this->data ['receiptDetail'] = $receiptDetail;
  1032. $this->data ['trainStatus'] = $trainStatus;
  1033. $this->data ['itid'] = $itid;
  1034. $this->data ['trainlistJson'] = $trainlistJson;
  1035. $this->data ['iTrainDetail'] = $detail;
  1036. $this->data ['memu'] = "invoice";
  1037. $this->data ['staff'] = $this->staff;
  1038. $this->data ['receiptMemu'] = 'invoiceTraining';
  1039. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1040. }
  1041. /**
  1042. * 上传培训班发票
  1043. * @return string
  1044. */
  1045. function invoiceTrainingUpload() {
  1046. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1047. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1048. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1049. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1050. header ( "HTTP/1.1 500 Internal Server Error" );
  1051. echo "POST exceeded maximum allowed size.";
  1052. exit ( 0 );
  1053. }
  1054. // Settings
  1055. $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)
  1056. $upload_name = "Filedata";
  1057. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1058. $extension_whitelist = array (
  1059. "doc",
  1060. "txt",
  1061. "jpg",
  1062. "gif",
  1063. "png"
  1064. ); // Allowed file extensions
  1065. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1066. // Other variables
  1067. $MAX_FILENAME_LENGTH = 260;
  1068. $file_name = "";
  1069. $file_extension = "";
  1070. $uploadErrors = array (
  1071. 0 => "文件上传成功",
  1072. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1073. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1074. 3 => "上传的文件仅为部分文件",
  1075. 4 => "没有文件上传",
  1076. 6 => "缺少临时文件夹"
  1077. );
  1078. $nk = time ();
  1079. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1080. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1081. echo "文件无法保存.";
  1082. exit ( 0 );
  1083. }
  1084. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1085. echo json_encode ( array (
  1086. 'filename' => $file_name,
  1087. 'id' => $nk
  1088. ) );
  1089. exit ( 0 );
  1090. }
  1091. /**
  1092. * 导入发票临时仓库
  1093. */
  1094. function invoiceStoreImport() {
  1095. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1096. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1097. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1098. if ($path != "" && ! empty ( $trainingKey )) {
  1099. Doo::loadModel ( 'invoiceStore' );
  1100. Doo::loadModel ( 'staff' );
  1101. $staff = new staff ();
  1102. Doo::loadModel ( 'invoiceTraining' );
  1103. $invoiceTraining = new invoiceTraining ();
  1104. Doo::loadClass ( 'XDeode' );
  1105. $XDeode = new XDeode ( 5 );
  1106. $itid = $XDeode->decode ( $trainingKey );
  1107. // 培训班结算是否有和是否已经结算完成
  1108. Doo::loadModel ( 'receipt' );
  1109. $receipt = new receipt ();
  1110. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1111. if (! empty ( $receiptDetail )) {
  1112. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1113. die ( 'illegal request--status' );
  1114. }
  1115. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1116. $userName = $this->staff [0] ['username'];
  1117. $sDetail = $staff->getStaffByName ( $userName );
  1118. // die('sdd');
  1119. // 可以优化
  1120. foreach ( $exlArray as $key => $value ) {
  1121. // 开票
  1122. $invoice = new invoiceStore ();
  1123. $invoice->trainId = $itid;
  1124. $invoice->invoiceType = 0;
  1125. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1126. $invoice->invoiceType = 1;
  1127. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1128. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1129. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1130. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1131. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1132. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1133. $invoice->userName = $userName;
  1134. $invoice->sid = $sDetail ['sid'];
  1135. $invoice->cid = $sDetail ['cid'];
  1136. $invoice->categoryName = $sDetail ['category'];
  1137. $invoice->invoiceElement = $value ['invoiceElement'];
  1138. $invoice->remark = $value ['remark'];
  1139. // $invoice->date = $value ['date'];
  1140. // $invoice->printTime = $value ['date'];
  1141. $invoice->ipSource = 1;
  1142. $invoice->printStatus = 0;
  1143. $invoice->status = 0;
  1144. $invoice->postStatus = 1;
  1145. $invoice->untreadStatus = 0;
  1146. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1147. $invoice->TIN = $value ['TIN'];
  1148. $invoice->address = $value ['address'];
  1149. $invoice->phone = $value ['phone'];
  1150. $invoice->bank = $value ['bank'];
  1151. $invoice->bankAccount = $value ['bankAccount'];
  1152. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1153. $invoice->recipients = $value ['recipients'];
  1154. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1155. $iid = $invoice->insert ();
  1156. }
  1157. // 加入发票总数量
  1158. $item = array (
  1159. 'itid' => $itid,
  1160. 'invoiceTotal' => count ( $exlArray )
  1161. );
  1162. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1163. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1164. }
  1165. echo 'no file';
  1166. }
  1167. /**
  1168. * 编辑仓库里的发票
  1169. */
  1170. function invoiceStoreEdit() {
  1171. Doo::loadClass ( 'XDeode' );
  1172. $XDeode = new XDeode ( 5 );
  1173. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1174. $iid = $XDeode->decode ( $iid );
  1175. if (! is_numeric ( $iid ))
  1176. die ( 'illegal request' );
  1177. Doo::loadModel ( 'invoiceStore' );
  1178. $invoiceStore = new invoiceStore ();
  1179. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1180. // print_r($invoiceDetail);
  1181. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1182. $this->data ['invoiceDetail'] = $invoiceDetail;
  1183. $this->data ['memu'] = "invoice";
  1184. $this->data ['staff'] = $this->staff;
  1185. $this->data ['receiptMemu'] = 'invoiceTraining';
  1186. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1187. }
  1188. function invoiceStoreEditDo() {
  1189. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1190. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1191. Doo::loadModel ( 'invoiceStore' );
  1192. $invoice = new invoiceStore ();
  1193. Doo::loadClass ( 'XDeode' );
  1194. $XDeode = new XDeode ( 5 );
  1195. $iid = $XDeode->decode ( $storeKey );
  1196. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1197. die ( 'illegal request' );
  1198. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1199. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1200. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1201. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1202. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1203. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1204. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1205. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1206. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1207. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1208. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1209. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1210. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1211. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1212. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1213. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1214. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1215. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1216. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1217. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1218. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1219. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1220. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1221. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1222. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1223. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1224. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1225. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1226. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1227. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1228. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1229. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1230. $cid = explode ( ':', $cid );
  1231. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1232. $item = array (
  1233. 'isid' => $iid,
  1234. 'cid' => $cid [0],
  1235. 'categoryName' => $cid [1],
  1236. 'invoiceElement' => $invoiceElement,
  1237. 'invoiceQuantity' => $invoiceQuantity,
  1238. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1239. 'invoicePrice' => $invoicePrice,
  1240. 'invoiceType' => $invoiceType,
  1241. 'doPost' => $doPost,
  1242. 'status' => 1,
  1243. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1244. 'remark' => $remark
  1245. );
  1246. if ($invoiceType == 0)
  1247. $item += array (
  1248. 'invoiceTitle' => $invoiceTitle,
  1249. 'TIN' => $TINT,
  1250. 'address' => $addressT,
  1251. 'phone' => $phoneT,
  1252. 'bank' => $bankT,
  1253. 'bankAccount' => $bankAccountT
  1254. );
  1255. else {
  1256. $item += array (
  1257. 'invoiceCompany' => $invoiceCompany,
  1258. 'TIN' => $TIN,
  1259. 'address' => $address,
  1260. 'phone' => $phone,
  1261. 'bank' => $bank,
  1262. 'bankAccount' => $bankAccount
  1263. );
  1264. }
  1265. if ($doPost == 1) {
  1266. $mailList = array (
  1267. 'invoice' => 1,
  1268. 'mailItems' => $mailItems
  1269. );
  1270. if (! empty ( $softLock ))
  1271. $mailList += array (
  1272. 'softLock' => $softLockNum
  1273. );
  1274. else
  1275. $mailList += array (
  1276. 'softLock' => '0'
  1277. );
  1278. if (! empty ( $contract ))
  1279. $mailList += array (
  1280. 'contract' => $contractNum
  1281. );
  1282. else
  1283. $mailList += array (
  1284. 'contract' => '0'
  1285. );
  1286. if (! empty ( $instructions ))
  1287. $mailList += array (
  1288. 'instructions' => $instructionsNum
  1289. );
  1290. else
  1291. $mailList += array (
  1292. 'instructions' => '0'
  1293. );
  1294. if (! empty ( $remittance ))
  1295. $mailList += array (
  1296. 'remittance' => $remittance
  1297. );
  1298. else
  1299. $mailList += array (
  1300. 'remittance' => ''
  1301. );
  1302. $mailString = '发票x1,备注:' . $mailItems;
  1303. if (! empty ( $softLock ))
  1304. $mailString .= ',软件锁x' . $softLockNum;
  1305. if (! empty ( $contract ))
  1306. $mailString .= ',合同x' . $contractNum;
  1307. if (! empty ( $instructions ))
  1308. $mailString .= ',说明书x' . $instructionsNum;
  1309. if (! empty ( $remittance ))
  1310. $mailString .= ',汇款账号单';
  1311. $item += array (
  1312. 'recipients' => $recipients,
  1313. 'recipientsPhone' => $recipientsPhone,
  1314. 'recipientsAddress' => $recipientsAddress,
  1315. 'mailItems' => $mailString,
  1316. 'mailItemsJson' => json_encode ( $mailList )
  1317. );
  1318. }
  1319. $invoice->setInvoiceStoreByCondition ( $item );
  1320. }
  1321. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1322. }
  1323. /**
  1324. *
  1325. * @return string
  1326. */
  1327. function invoiceStoreDelete() {
  1328. Doo::loadClass ( 'XDeode' );
  1329. $XDeode = new XDeode ( 5 );
  1330. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1331. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1332. $isid = $XDeode->decode ( $iStoreKey );
  1333. $itid = $XDeode->decode ( $trainKey );
  1334. if (! is_numeric ( $isid ))
  1335. die ( 'illegal request' );
  1336. Doo::loadModel ( 'invoiceStore' );
  1337. $invoiceStore = new invoiceStore ();
  1338. $invoiceStore->delete ( array (
  1339. 'where' => 'isid=' . $isid,
  1340. 'limit' => 1
  1341. ) );
  1342. Doo::loadModel ( 'invoiceTraining' );
  1343. $invoiceTraining = new invoiceTraining ();
  1344. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1345. $item = array (
  1346. 'itid' => $itid,
  1347. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1348. );
  1349. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1350. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1351. }
  1352. /**
  1353. * 批量删除库里发票
  1354. */
  1355. function invoiceStoreBatchDelete() {
  1356. Doo::loadClass ( 'XDeode' );
  1357. $XDeode = new XDeode ( 5 );
  1358. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1359. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1360. if (empty ( $trainKey ) || empty ( $storeKey ))
  1361. die ( 'illegal request-IdKey' );
  1362. $tid = $XDeode->decode ( $trainKey );
  1363. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1364. die ( 'illegal request' );
  1365. Doo::loadModel ( 'invoiceStore' );
  1366. $isidKeyList = explode ( ',', $storeKey );
  1367. $isidList = array ();
  1368. foreach ( $isidKeyList as $value ) {
  1369. $isid = $XDeode->decode ( $value );
  1370. if (! empty ( $isid ) && is_numeric ( $isid ))
  1371. array_push ( $isidList, $isid );
  1372. }
  1373. $isidString = implode ( ',', $isidList );
  1374. $invoiceStore = new invoiceStore ();
  1375. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1376. $isidList = array ();
  1377. foreach ( $isList as $key => $value ) {
  1378. if ($value ['apStatus'] == 0)
  1379. array_push ( $isidList, $value ['isid'] );
  1380. }
  1381. $isidString = implode ( ',', $isidList );
  1382. // print_r($isList);
  1383. // echo $isidString;
  1384. $invoiceStore = new invoiceStore ();
  1385. $invoiceStore->delete ( array (
  1386. 'where' => "isid in ( " . $isidString . ")",
  1387. 'asArray' => TRUE
  1388. ) );
  1389. Doo::loadModel ( 'invoiceTraining' );
  1390. $invoiceTraining = new invoiceTraining ();
  1391. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1392. $item = array (
  1393. 'itid' => $tid,
  1394. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1395. );
  1396. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1397. // echo $tid;
  1398. // echo $storeKey;
  1399. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1400. }
  1401. /**
  1402. * 仓库发票提交审批
  1403. * @return string
  1404. */
  1405. function invoiceStoreApproval() {
  1406. Doo::loadClass ( 'XDeode' );
  1407. $XDeode = new XDeode ( 5 );
  1408. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1409. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1410. $isid = $XDeode->decode ( $iStoreKey );
  1411. $trainId = $XDeode->decode ( $trainKey );
  1412. if (! is_numeric ( $isid ))
  1413. die ( 'illegal request' );
  1414. Doo::loadModel ( 'invoiceStore' );
  1415. Doo::loadModel ( 'invoice' );
  1416. $invoice = new invoice ();
  1417. // 加入限制必须填写入开票内容和邮寄物品
  1418. $invoiceStore = new invoiceStore ();
  1419. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1420. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1421. header ( 'Content-Type:text/html;charset=utf-8' );
  1422. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1423. }
  1424. // 拷贝插入一条发票数据
  1425. $invoiceStore = new invoiceStore ();
  1426. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1427. $invoiceStore = new invoiceStore ();
  1428. $item = array (
  1429. 'isid' => $isid,
  1430. 'iid' => $iid,
  1431. 'apStatus' => 1
  1432. );
  1433. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1434. Doo::loadModel ( 'invoiceManage' );
  1435. $invoiceManage = new invoiceManage ();
  1436. Doo::loadModel ( 'invoiceOperationLog' );
  1437. $invoiceOperationLog = new invoiceOperationLog ();
  1438. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1439. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1440. $moldManage = array ();
  1441. foreach ( $invoiceManageList as $key => $value ) {
  1442. if ($value ['mold'] == '发票打印')
  1443. $moldManage [$value ['mold']] = $value ['staffList'];
  1444. elseif ($value ['mold'] == '发票邮寄')
  1445. $moldManage [$value ['mold']] = $value ['staffList'];
  1446. elseif ($value ['mold'] == '发票退票')
  1447. $moldManage [$value ['mold']] = $value ['staffList'];
  1448. }
  1449. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1450. $item = array (
  1451. 'iid' => $iid,
  1452. 'isid' => $isid,
  1453. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1454. 'date' => date ( "Y-m-d H:i:s" ),
  1455. 'status' => 1,
  1456. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1457. 'trainId' => $trainId,
  1458. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1459. 'moldManage' => json_encode ( $moldManage ),
  1460. 'settlementType' => 1,
  1461. 'pendingApprovals' => $pendingApprovalsSid
  1462. );
  1463. $invoice->setInvoiceByCondition ( $item );
  1464. Doo::loadModel ( 'invoiceTraining' );
  1465. $invoiceTraining = new invoiceTraining ();
  1466. $item = array (
  1467. 'itid' => $trainId,
  1468. 'submitStatus' => 1
  1469. );
  1470. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1471. $item = array (
  1472. 'date' => date ( "Y-m-d H:i:s" ),
  1473. 'operation' => "创建",
  1474. 'status' => 1,
  1475. 'img' => $this->staff [0] ['avatar'],
  1476. 'username' => $this->staff [0] ['username'],
  1477. 'uid' => $this->staff [0] ['sid'],
  1478. 'category' => $this->staff [0] ['category'],
  1479. 'iid' => $iid
  1480. );
  1481. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1482. $item = array (
  1483. 'date' => date ( "Y-m-d H:i:s" ),
  1484. 'operation' => "提交审批",
  1485. 'status' => 1,
  1486. 'img' => $this->staff [0] ['avatar'],
  1487. 'username' => $this->staff [0] ['username'],
  1488. 'uid' => $this->staff [0] ['sid'],
  1489. 'category' => $this->staff [0] ['category'],
  1490. 'iid' => $iid
  1491. );
  1492. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1493. Doo::loadModel ( 'staff' );
  1494. $staff = new staff ();
  1495. $username2 = $staff->getOne ( array (
  1496. 'select' => 'wxid',
  1497. 'where' => 'sid=' . $pendingApprovalsSid,
  1498. 'asArray' => TRUE
  1499. ) );
  1500. // 发送微信审批通知
  1501. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1502. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1503. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1504. }
  1505. /**
  1506. * 批量提交发票
  1507. * @return string
  1508. */
  1509. function invoiceStoreBatchApproval() {
  1510. Doo::loadClass ( 'XDeode' );
  1511. $XDeode = new XDeode ( 5 );
  1512. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1513. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1514. if (empty ( $trainKey ) || empty ( $storeKey ))
  1515. die ( 'illegal request-IdKey' );
  1516. $trainId = $XDeode->decode ( $trainKey );
  1517. $isidKeyList = explode ( ',', $storeKey );
  1518. $isidList = array ();
  1519. foreach ( $isidKeyList as $value ) {
  1520. $isid = $XDeode->decode ( $value );
  1521. if (! empty ( $isid ) && is_numeric ( $isid ))
  1522. array_push ( $isidList, $isid );
  1523. }
  1524. $isidString = implode ( ',', $isidList );
  1525. if (! is_numeric ( $trainId ))
  1526. die ( 'illegal request' );
  1527. Doo::loadModel ( 'invoiceStore' );
  1528. Doo::loadModel ( 'invoice' );
  1529. // 判断哪些已经加入审批过
  1530. // 加入限制必须填写入开票内容和邮寄物品
  1531. $invoiceStore = new invoiceStore ();
  1532. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1533. foreach ( $isList as $key => $value ) {
  1534. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1535. header ( 'Content-Type:text/html;charset=utf-8' );
  1536. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1537. }
  1538. }
  1539. // 拷贝插入一条发票数据
  1540. $invoiceStore = new invoiceStore ();
  1541. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1542. $invoiceStore = new invoiceStore ();
  1543. $item = array (
  1544. 'apStatus' => 1
  1545. );
  1546. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1547. // 获得正式发票ID
  1548. $invoice = new invoice ();
  1549. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1550. $sqlList = array ();
  1551. $iidString = '';
  1552. $iida = array ();
  1553. foreach ( $iidList as $key => $value ) {
  1554. $sqlList [$value ['isid']] = $value ['iid'];
  1555. array_push ( $iida, $value ['iid'] );
  1556. }
  1557. $iidString = implode ( ',', $iida );
  1558. $ids = implode ( ',', array_keys ( $sqlList ) );
  1559. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1560. foreach ( $sqlList as $id => $ordinal ) {
  1561. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1562. }
  1563. $sql .= "END WHERE isid IN ($ids)";
  1564. $invoiceStore = new invoiceStore ();
  1565. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1566. Doo::loadModel ( 'invoiceManage' );
  1567. $invoiceManage = new invoiceManage ();
  1568. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1569. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1570. $moldManage = array ();
  1571. foreach ( $invoiceManageList as $key => $value ) {
  1572. if ($value ['mold'] == '发票打印')
  1573. $moldManage [$value ['mold']] = $value ['staffList'];
  1574. elseif ($value ['mold'] == '发票邮寄')
  1575. $moldManage [$value ['mold']] = $value ['staffList'];
  1576. elseif ($value ['mold'] == '发票退票')
  1577. $moldManage [$value ['mold']] = $value ['staffList'];
  1578. }
  1579. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1580. // 批量更新发票信息
  1581. $item = array (
  1582. 'date' => date ( "Y-m-d H:i:s" ),
  1583. 'status' => 1,
  1584. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1585. 'trainId' => $trainId,
  1586. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1587. 'moldManage' => json_encode ( $moldManage ),
  1588. 'settlementType' => 1,
  1589. 'pendingApprovals' => $pendingApprovalsSid
  1590. );
  1591. $invoice = new invoice ();
  1592. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1593. // 批量更新发票中仓库isid
  1594. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1595. foreach ( $sqlList as $isid => $iid ) {
  1596. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1597. }
  1598. $sql .= "END WHERE iid IN ($iidString)";
  1599. $invoice = new invoice ();
  1600. $invoice->UpdateBatchInvoice ( $sql );
  1601. // 批量更新发票序列号
  1602. $sqlList = array ();
  1603. foreach ( $iida as $value ) {
  1604. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1605. }
  1606. $ids = implode ( ',', array_keys ( $sqlList ) );
  1607. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1608. foreach ( $sqlList as $id => $ordinal ) {
  1609. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1610. }
  1611. $sql .= "END WHERE iid IN ($ids)";
  1612. $invoiceStore = new invoiceStore ();
  1613. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1614. // 批量生产操作日志
  1615. Doo::loadModel ( 'invoiceOperationLog' );
  1616. $sqlList = array ();
  1617. foreach ( $iida as $key => $value ) {
  1618. $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 . '"),
  1619. ("' . 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 . '") ';
  1620. array_push ( $sqlList, $sql );
  1621. }
  1622. $iolSql = implode ( ',', $sqlList );
  1623. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1624. $invoiceOperationLog = new invoiceOperationLog ();
  1625. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1626. Doo::loadModel ( 'invoiceTraining' );
  1627. $invoiceTraining = new invoiceTraining ();
  1628. $item = array (
  1629. 'itid' => $trainId,
  1630. 'submitStatus' => 1
  1631. );
  1632. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1633. Doo::loadModel ( 'staff' );
  1634. $staff = new staff ();
  1635. $username2 = $staff->getOne ( array (
  1636. 'select' => 'wxid',
  1637. 'where' => 'sid=' . $pendingApprovalsSid,
  1638. 'asArray' => TRUE
  1639. ) );
  1640. // 发送微信审批通知
  1641. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1642. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1643. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1644. }
  1645. /**
  1646. */
  1647. function invoiceStoreMailItemSet() {
  1648. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1649. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1650. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1651. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1652. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1653. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1654. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1655. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1656. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1657. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1658. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1659. Doo::loadClass ( 'XDeode' );
  1660. $XDeode = new XDeode ( 5 );
  1661. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1662. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1663. $isid = $XDeode->decode ( $storeKey );
  1664. $trainId = $XDeode->decode ( $trainKey );
  1665. if (! is_numeric ( $isid ))
  1666. die ( 'illegal request' );
  1667. Doo::loadModel ( 'invoiceStore' );
  1668. $invoiceStore = new invoiceStore ();
  1669. $mailList = array (
  1670. 'invoice' => 1,
  1671. 'mailItems' => $mailItems
  1672. );
  1673. if (! empty ( $softLock ))
  1674. $mailList += array (
  1675. 'softLock' => $softLockNum
  1676. );
  1677. else
  1678. $mailList += array (
  1679. 'softLock' => 0
  1680. );
  1681. if (! empty ( $contract ))
  1682. $mailList += array (
  1683. 'contract' => $contractNum
  1684. );
  1685. else
  1686. $mailList += array (
  1687. 'contract' => 0
  1688. );
  1689. if (! empty ( $instructions ))
  1690. $mailList += array (
  1691. 'instructions' => $instructionsNum
  1692. );
  1693. else
  1694. $mailList += array (
  1695. 'instructions' => 0
  1696. );
  1697. if (! empty ( $remittance ))
  1698. $mailList += array (
  1699. 'remittance' => $remittance
  1700. );
  1701. else
  1702. $mailList += array (
  1703. 'remittance' => ''
  1704. );
  1705. $mailString = '发票x1,备注:' . $mailItems;
  1706. if (! empty ( $softLock ))
  1707. $mailString .= ',软件锁x' . $softLockNum;
  1708. if (! empty ( $contract ))
  1709. $mailString .= ',合同x' . $contractNum;
  1710. if (! empty ( $instructions ))
  1711. $mailString .= ',说明书x' . $instructionsNum;
  1712. if (! empty ( $remittance ))
  1713. $mailString .= ',汇款账号单';
  1714. $item = array (
  1715. 'isid' => $isid,
  1716. 'doPost' => 1,
  1717. 'mailItems' => $mailString,
  1718. 'mailItemsJson' => json_encode ( $mailList )
  1719. );
  1720. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1721. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1722. }
  1723. /**
  1724. * 批量设置邮寄物品
  1725. */
  1726. function invoiceStoreBatchMailItemSet() {
  1727. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1728. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1729. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1730. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1731. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1732. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1733. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1734. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1735. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1736. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1737. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1738. Doo::loadClass ( 'XDeode' );
  1739. $XDeode = new XDeode ( 5 );
  1740. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1741. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1742. if (empty ( $trainKey ) || empty ( $storeKey ))
  1743. die ( 'illegal request-IdKey' );
  1744. $isidKeyList = explode ( ',', $storeKey );
  1745. $isidList = array ();
  1746. foreach ( $isidKeyList as $value ) {
  1747. $isid = $XDeode->decode ( $value );
  1748. if (! empty ( $isid ) && is_numeric ( $isid ))
  1749. array_push ( $isidList, $isid );
  1750. }
  1751. $isidString = implode ( ',', $isidList );
  1752. $trainId = $XDeode->decode ( $trainKey );
  1753. if (! is_numeric ( $isid ))
  1754. die ( 'illegal request' );
  1755. Doo::loadModel ( 'invoiceStore' );
  1756. $invoiceStore = new invoiceStore ();
  1757. $mailList = array (
  1758. 'invoice' => 1,
  1759. 'mailItems' => $mailItems
  1760. );
  1761. if (! empty ( $softLock ))
  1762. $mailList += array (
  1763. 'softLock' => $softLockNum
  1764. );
  1765. else
  1766. $mailList += array (
  1767. 'softLock' => 0
  1768. );
  1769. if (! empty ( $contract ))
  1770. $mailList += array (
  1771. 'contract' => $contractNum
  1772. );
  1773. else
  1774. $mailList += array (
  1775. 'contract' => 0
  1776. );
  1777. if (! empty ( $instructions ))
  1778. $mailList += array (
  1779. 'instructions' => $instructionsNum
  1780. );
  1781. else
  1782. $mailList += array (
  1783. 'instructions' => 0
  1784. );
  1785. if (! empty ( $remittance ))
  1786. $mailList += array (
  1787. 'remittance' => $remittance
  1788. );
  1789. else
  1790. $mailList += array (
  1791. 'remittance' => ''
  1792. );
  1793. $mailString = '发票x1,备注:' . $mailItems;
  1794. if (! empty ( $softLock ))
  1795. $mailString .= ',软件锁x' . $softLockNum;
  1796. if (! empty ( $contract ))
  1797. $mailString .= ',合同x' . $contractNum;
  1798. if (! empty ( $instructions ))
  1799. $mailString .= ',说明书x' . $instructionsNum;
  1800. if (! empty ( $remittance ))
  1801. $mailString .= ',汇款账号单';
  1802. $item = array (
  1803. 'doPost' => 1,
  1804. 'mailItems' => $mailString,
  1805. 'mailItemsJson' => json_encode ( $mailList )
  1806. );
  1807. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1808. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1809. }
  1810. /**
  1811. * 废弃
  1812. */
  1813. function ajaxGetMailItemByIstore() {
  1814. Doo::loadClass ( 'XDeode' );
  1815. $XDeode = new XDeode ( 5 );
  1816. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1817. $isid = $XDeode->decode ( $storeKey );
  1818. if (! is_numeric ( $isid ))
  1819. die ( 'illegal request' );
  1820. Doo::loadModel ( 'invoiceStore' );
  1821. $invoiceStore = new invoiceStore ();
  1822. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1823. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1824. echo json_encode ( $isDetail ['mailItemsJson'] );
  1825. exit ();
  1826. }
  1827. /**
  1828. * 终止开票
  1829. */
  1830. function invoiceDroppedDo() {
  1831. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1832. Doo::loadModel ( 'invoice' );
  1833. $invoice = new invoice ();
  1834. Doo::loadModel ( 'invoiceOperationLog' );
  1835. $invoiceOperationLog = new invoiceOperationLog ();
  1836. $iid = $invoice->authcode ( $droppedIidKey );
  1837. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1838. die ( 'illegal request' );
  1839. $item = array (
  1840. 'iid' => $iid,
  1841. 'status' => 4,
  1842. 'updateTime' => date ( "Y-m-d H:i:s" )
  1843. );
  1844. $invoice->setInvoiceByCondition ( $item );
  1845. $item = array (
  1846. 'date' => date ( "Y-m-d H:i:s" ),
  1847. 'operation' => '终止了开票',
  1848. 'status' => 4,
  1849. 'img' => $this->staff [0] ['avatar'],
  1850. 'username' => $this->staff [0] ['username'],
  1851. 'uid' => $this->staff [0] ['sid'],
  1852. 'category' => $this->staff [0] ['category'],
  1853. 'iid' => $iid
  1854. );
  1855. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1856. return "/invoice";
  1857. }
  1858. /**
  1859. * 更新退票的邮寄信息
  1860. */
  1861. function invoiceUntreadMailDo() {
  1862. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1863. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1864. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1865. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1866. Doo::loadModel ( 'invoice' );
  1867. $invoice = new invoice ();
  1868. $iid = $invoice->authcode ( $untreadIidKey );
  1869. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1870. die ( 'illegal request' );
  1871. $item = array (
  1872. 'iid' => $iid,
  1873. 'untreadCompany' => $untreadCompany,
  1874. 'untreadNumber' => $untreadNumber,
  1875. 'untreadItems' => $untreadItems
  1876. );
  1877. $invoice->setInvoiceByCondition ( $item );
  1878. return "/invoice";
  1879. }
  1880. /**
  1881. * 申请退票 --
  1882. */
  1883. function invoiceUntreadDo() {
  1884. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1885. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1886. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1887. Doo::loadModel ( 'invoice' );
  1888. $invoice = new invoice ();
  1889. Doo::loadModel ( 'invoiceOperationLog' );
  1890. $invoiceOperationLog = new invoiceOperationLog ();
  1891. Doo::loadModel ( 'invoiceReceivables' );
  1892. $invoiceReceivables = new invoiceReceivables ();
  1893. $iid = $invoice->authcode ( $untreadIidKey );
  1894. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1895. die ( 'illegal request' );
  1896. /*
  1897. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1898. */
  1899. $item = array (
  1900. 'iid' => $iid,
  1901. 'untreadStatus' => 1,
  1902. 'untreadReason' => $untreadReason,
  1903. 'untreadPost' => $untreadPost,
  1904. 'updateTime' => date ( "Y-m-d H:i:s" )
  1905. );
  1906. $invoice->setInvoiceByCondition ( $item );
  1907. $item = array (
  1908. 'date' => date ( "Y-m-d H:i:s" ),
  1909. 'operation' => '申请退票',
  1910. 'status' => 7,
  1911. 'img' => $this->staff [0] ['avatar'],
  1912. 'username' => $this->staff [0] ['username'],
  1913. 'uid' => $this->staff [0] ['sid'],
  1914. 'category' => $this->staff [0] ['category'],
  1915. 'iid' => $iid
  1916. );
  1917. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1918. return "/invoice";
  1919. }
  1920. /**
  1921. * 删除已终止的开票
  1922. */
  1923. function invoiceDelDo() {
  1924. Doo::loadModel ( 'invoice' );
  1925. $invoice = new invoice ();
  1926. Doo::loadModel ( 'invoiceOperationLog' );
  1927. $invoiceOperationLog = new invoiceOperationLog ();
  1928. Doo::loadClass ( 'XDeode' );
  1929. $XDeode = new XDeode ( 5 );
  1930. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1931. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1932. $iid = $XDeode->decode ( $iid );
  1933. Doo::loadModel ( 'invoiceStore' );
  1934. $invoiceStore = new invoiceStore ();
  1935. if (! is_numeric ( $iid ))
  1936. die ( 'illegal request' );
  1937. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1938. if (empty ( $invoiceDetail ))
  1939. die ( 'illegal request' );
  1940. $item = array (
  1941. 'iid' => $iid,
  1942. 'isDelete' => 1,
  1943. 'updateTime' => date ( "Y-m-d H:i:s" )
  1944. );
  1945. $invoice->setInvoiceByCondition ( $item );
  1946. $item = array (
  1947. 'date' => date ( "Y-m-d H:i:s" ),
  1948. 'operation' => '删除了已终止的发票',
  1949. 'status' => 4,
  1950. 'img' => $this->staff [0] ['avatar'],
  1951. 'username' => $this->staff [0] ['username'],
  1952. 'uid' => $this->staff [0] ['sid'],
  1953. 'category' => $this->staff [0] ['category'],
  1954. 'iid' => $iid
  1955. );
  1956. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1957. // 删除培训班发票仓库里的发票
  1958. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1959. return "/invoice";
  1960. }
  1961. /**
  1962. */
  1963. function invoiceApproval() {
  1964. Doo::loadModel ( 'invoice' );
  1965. $invoice = new invoice ();
  1966. Doo::loadClass ( 'XDeode' );
  1967. $XDeode = new XDeode ( 5 );
  1968. Doo::loadModel ( 'staff' );
  1969. $staff = new staff ();
  1970. $invoiceList = $invoice->find ( array (
  1971. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1972. 'desc' => 'iid',
  1973. 'limit' => 10,
  1974. 'asArray' => true
  1975. ) );
  1976. foreach ( $invoiceList as $key => $value ) {
  1977. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1978. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1979. if (! empty ( $lastApprover )) {
  1980. $lastApproverKey = array_keys ( $lastApprover );
  1981. $lastApprover = end ( $lastApprover );
  1982. $staffDetail = $staff->getOne ( array (
  1983. 'where' => 'sid=' . end ( $lastApproverKey ),
  1984. 'asArray' => true
  1985. ) );
  1986. $lastApprover ['username'] = $staffDetail ['username'];
  1987. }
  1988. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1989. }
  1990. $ilist = $invoice->getInvoiceByProcessStatus ();
  1991. foreach ( $ilist as $key => $value ) {
  1992. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1993. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1994. if (! empty ( $lastApprover )) {
  1995. $lastApproverKey = array_keys ( $lastApprover );
  1996. $lastApprover = end ( $lastApprover );
  1997. $staffDetail = $staff->getOne ( array (
  1998. 'where' => 'sid=' . end ( $lastApproverKey ),
  1999. 'asArray' => true
  2000. ) );
  2001. $lastApprover ['username'] = $staffDetail ['username'];
  2002. }
  2003. $ilist [$key] ['lastApprover'] = $lastApprover;
  2004. }
  2005. // print_r($ilist);
  2006. $this->data ['invoiceList'] = $invoiceList;
  2007. $this->data ['ilist'] = $ilist;
  2008. $this->data ['memu'] = "invoice";
  2009. $this->data ['staff'] = $this->staff;
  2010. $this->data ['receiptMemu'] = 'invoiceApproval';
  2011. $this->render ( "/admin/invoiceApproval", $this->data );
  2012. }
  2013. function invoiceDetail() {
  2014. Doo::loadClass ( 'XDeode' );
  2015. $XDeode = new XDeode ( 5 );
  2016. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2017. $iid = $XDeode->decode ( $iid );
  2018. if (! is_numeric ( $iid ))
  2019. die ( 'illegal request' );
  2020. Doo::loadModel ( 'invoice' );
  2021. $invoice = new invoice ();
  2022. Doo::loadModel ( 'invoiceOperationLog' );
  2023. $invoiceOperationLog = new invoiceOperationLog ();
  2024. $invoiceDetail = $invoice->getOne ( array (
  2025. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2026. 'asArray' => true
  2027. ) );
  2028. if (empty ( $invoiceDetail ))
  2029. die ( 'illegal request' );
  2030. if ($invoiceDetail ['settlementType'] == 1) {
  2031. Doo::loadModel ( 'invoiceTraining' );
  2032. $invoiceTraining = new invoiceTraining ();
  2033. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2034. }
  2035. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2036. $this->data ['invoiceDetail'] = $invoiceDetail;
  2037. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2038. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2039. $this->data ['memu'] = "invoice";
  2040. $this->data ['staff'] = $this->staff;
  2041. $this->data ['receiptMemu'] = 'invoiceApproval';
  2042. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2043. }
  2044. /**
  2045. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2046. *
  2047. * @since 1.0.0
  2048. * @var integer iid 开票ID 已加密
  2049. * @var integer status 发票审批状态
  2050. * @var integer opintion 审批发票的意见
  2051. * @return string 如操作成功返回审批首页
  2052. */
  2053. function invoiceApprovalDo() {
  2054. Doo::loadModel ( 'invoice' );
  2055. $invoice = new invoice ();
  2056. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2057. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2058. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2059. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2060. $iid = $invoice->authcode ( $iid );
  2061. if (! is_numeric ( $iid ))
  2062. die ( 'illegal request' );
  2063. // && ! empty ( $opinion )
  2064. if (! empty ( $iid ) && ! empty ( $status )) {
  2065. if (! ($status == 2 || $status == 3 || $status == 4))
  2066. die ( 'illegal request' );
  2067. Doo::loadModel ( 'invoiceOperationLog' );
  2068. $invoiceOperationLog = new invoiceOperationLog ();
  2069. $invoiceDetail = $invoice->getOne ( array (
  2070. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2071. 'asArray' => true
  2072. ) );
  2073. if (empty ( $invoiceDetail ))
  2074. die ( 'illegal request' );
  2075. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2076. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2077. if ($status == 3) {
  2078. $invoice->status = $status;
  2079. $item = array (
  2080. 'operation' => $opinion
  2081. );
  2082. } else {
  2083. if (empty ( $processApprovals )) {
  2084. $processApprovals = array (
  2085. $this->staff [0] ['sid'] => array (
  2086. 'date' => date ( "Y-m-d H:i:s" ),
  2087. 'opinion' => $opinion,
  2088. 'status' => $status
  2089. )
  2090. );
  2091. // var_dump(next($invoiceManage));
  2092. $nextInvoiceManage = next ( $invoiceManage );
  2093. // print_r($nextInvoiceManage);
  2094. if ($status != 4 && $nextInvoiceManage !== false)
  2095. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2096. $invoice->processApprovals = json_encode ( $processApprovals );
  2097. // var_dump($invoice);
  2098. // print_r($invoiceManage);
  2099. } else {
  2100. $processApprovals [$this->staff [0] ['sid']] = array (
  2101. 'date' => date ( "Y-m-d H:i:s" ),
  2102. 'opinion' => $opinion,
  2103. 'status' => $status
  2104. );
  2105. $pendingApprovals = 0;
  2106. foreach ( $invoiceManage as $key => $value ) {
  2107. if ($value [0] == $this->staff [0] ['sid']) {
  2108. if (isset ( $invoiceManage [$key + 1] ))
  2109. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2110. break;
  2111. }
  2112. }
  2113. if ($status != 4 && ! empty ( $pendingApprovals ))
  2114. $invoice->pendingApprovals = $pendingApprovals;
  2115. $invoice->processApprovals = json_encode ( $processApprovals );
  2116. }
  2117. $item = array (
  2118. 'operation' => $opinion
  2119. );
  2120. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2121. $invoice->status = $status;
  2122. $invoice->pendingApprovals = 0;
  2123. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2124. } elseif ($status == 4) {
  2125. $invoice->status = $status;
  2126. $item = array (
  2127. 'operation' => $opinion
  2128. );
  2129. }
  2130. }
  2131. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2132. $invoice->update ( array (
  2133. 'where' => 'iid=' . $iid
  2134. ) );
  2135. $item += array (
  2136. 'date' => date ( "Y-m-d H:i:s" ),
  2137. 'img' => $this->staff [0] ['avatar'],
  2138. 'username' => $this->staff [0] ['username'],
  2139. 'uid' => $this->staff [0] ['sid'],
  2140. 'category' => $this->staff [0] ['category'],
  2141. 'status' => $status,
  2142. 'iid' => $iid
  2143. );
  2144. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2145. if (empty ( $divApproval ))
  2146. return '/invoiceApproval';
  2147. else
  2148. return '/invoiceApprovalAchieve/PEND';
  2149. }
  2150. die ( 'illegal request' );
  2151. }
  2152. /**
  2153. * 展示需要打印的发票数据
  2154. *
  2155. * @since 1.0.0
  2156. */
  2157. function invoicePrint() {
  2158. Doo::loadModel ( 'invoice' );
  2159. $invoice = new invoice ();
  2160. Doo::loadClass ( 'XDeode' );
  2161. $XDeode = new XDeode ( 5 );
  2162. Doo::loadModel ( 'staff' );
  2163. $staff = new staff ();
  2164. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2165. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2166. foreach ( $toPrint as $key => $value ) {
  2167. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2168. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2169. if (! empty ( $lastApprover )) {
  2170. $lastApproverKey = array_keys ( $lastApprover );
  2171. $lastApprover = end ( $lastApprover );
  2172. $staffDetail = $staff->getOne ( array (
  2173. 'where' => 'sid=' . end ( $lastApproverKey ),
  2174. 'asArray' => true
  2175. ) );
  2176. $lastApprover ['username'] = $staffDetail ['username'];
  2177. }
  2178. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2179. }
  2180. foreach ( $printed as $key => $value ) {
  2181. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2182. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2183. if (! empty ( $lastApprover )) {
  2184. $lastApproverKey = array_keys ( $lastApprover );
  2185. $lastApprover = end ( $lastApprover );
  2186. $staffDetail = $staff->getOne ( array (
  2187. 'where' => 'sid=' . end ( $lastApproverKey ),
  2188. 'asArray' => true
  2189. ) );
  2190. $lastApprover ['username'] = $staffDetail ['username'];
  2191. }
  2192. $printed [$key] ['lastApprover'] = $lastApprover;
  2193. }
  2194. $this->data ['printed'] = $printed;
  2195. $this->data ['toPrint'] = $toPrint;
  2196. $this->data ['memu'] = "invoice";
  2197. $this->data ['staff'] = $this->staff;
  2198. $this->data ['receiptMemu'] = 'invoicePrint';
  2199. $this->render ( "/admin/invoicePrint", $this->data );
  2200. }
  2201. /**
  2202. * 展示发票打印的详情页面
  2203. *
  2204. * @since 1.0.0
  2205. */
  2206. function invoicePrintDetail() {
  2207. Doo::loadClass ( 'XDeode' );
  2208. $XDeode = new XDeode ( 5 );
  2209. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2210. $iid = $XDeode->decode ( $iid );
  2211. if (! is_numeric ( $iid ))
  2212. die ( 'illegal request' );
  2213. Doo::loadModel ( 'invoice' );
  2214. $invoice = new invoice ();
  2215. Doo::loadModel ( 'invoiceOperationLog' );
  2216. $invoiceOperationLog = new invoiceOperationLog ();
  2217. Doo::loadModel ( 'invoicePaper' );
  2218. $invoicePaper = new invoicePaper ();
  2219. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2220. if (empty ( $invoiceDetail ))
  2221. die ( 'illegal request' );
  2222. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2223. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2224. if ($invoiceDetail ['settlementType'] == 1) {
  2225. Doo::loadModel ( 'invoiceTraining' );
  2226. $invoiceTraining = new invoiceTraining ();
  2227. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2228. }
  2229. $this->data ['invoicePaperList'] = $invoicePaperList;
  2230. $this->data ['invoiceDetail'] = $invoiceDetail;
  2231. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2232. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2233. $this->data ['memu'] = "invoice";
  2234. $this->data ['staff'] = $this->staff;
  2235. $this->data ['receiptMemu'] = 'invoicePrint';
  2236. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2237. }
  2238. /**
  2239. * 所有待打印 发票
  2240. */
  2241. function invoicePrintStayAchieve() {
  2242. Doo::loadModel ( 'invoice' );
  2243. $invoice = new invoice ();
  2244. Doo::loadClass ( 'XDeode' );
  2245. $XDeode = new XDeode ( 5 );
  2246. Doo::loadModel ( 'staff' );
  2247. $staff = new staff ();
  2248. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2249. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2250. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2251. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2252. Doo::loadModel ( 'invoiceTraining' );
  2253. $invoiceTraining = new invoiceTraining ();
  2254. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2255. $page_size = 12;
  2256. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2257. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2258. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2259. $get = "/" . $status;
  2260. $con = ' and status=2 ';
  2261. if ($status == 'TOPRINT')
  2262. $con = ' and status=2 and printStatus=0 ';
  2263. elseif ($status == 'PRINTED')
  2264. $con = ' and status=2 and printStatus=1';
  2265. if ($invoiceType == 'ORDINARY')
  2266. $con .= ' and invoiceType=0 ';
  2267. elseif ($invoiceType == 'SPECIAL')
  2268. $con .= ' and invoiceType=1 ';
  2269. if ($invoiceTrain == 'ORDINARY')
  2270. $con .= ' and trainId=0 ';
  2271. elseif ($invoiceTrain == 'TRAIN')
  2272. $con .= ' and trainId!=0 ';
  2273. if ($invoiceTrainName != 'ALL') {
  2274. $trainId = $XDeode->decode ( $invoiceTrainName );
  2275. if (is_numeric ( $trainId ))
  2276. $con .= ' and trainId =' . $trainId;
  2277. }
  2278. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2279. $dateArr = explode ( ':', $date );
  2280. $D1 = '';
  2281. $D2 = '';
  2282. if (! empty ( $date )) {
  2283. $D1 = $dateArr [0];
  2284. $D2 = $dateArr [1];
  2285. }
  2286. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2287. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2288. if (! empty ( $MebSea )) {
  2289. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2290. }
  2291. $pageinfo ['page'] = array (
  2292. 'previous' => ''
  2293. );
  2294. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2295. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2296. $action = "invoicePrintStayAchieve";
  2297. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2298. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2299. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2300. $this->data ['trainList'] = $trainList;
  2301. $this->data ['invoiceType'] = $invoiceType;
  2302. $this->data ['invoiceTrain'] = $invoiceTrain;
  2303. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2304. $this->data ['MebSeaEn'] = $MebSea;
  2305. $this->data ['MebSea'] = urlencode ( $MebSea );
  2306. $this->data ['get'] = $get;
  2307. $this->data ['page'] = $pageinfo;
  2308. $this->data ['date'] = $date;
  2309. $this->data ['status'] = $status;
  2310. $this->data ['invoiceType'] = $invoiceType;
  2311. $this->data ['memu'] = "invoice";
  2312. $this->data ['staff'] = $this->staff;
  2313. foreach ( $list as $key => $value ) {
  2314. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2315. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2316. if (! empty ( $lastApprover )) {
  2317. $lastApproverKey = array_keys ( $lastApprover );
  2318. $lastApprover = end ( $lastApprover );
  2319. $staffDetail = $staff->getOne ( array (
  2320. 'where' => 'sid=' . end ( $lastApproverKey ),
  2321. 'asArray' => true
  2322. ) );
  2323. $lastApprover ['username'] = $staffDetail ['username'];
  2324. }
  2325. $list [$key] ['lastApprover'] = $lastApprover;
  2326. }
  2327. $this->data ['receiptMemu'] = 'invoicePrint';
  2328. $this->data ['list'] = $list;
  2329. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2330. }
  2331. /**
  2332. * 填写票号并完成打印
  2333. * @since 1.0.0
  2334. */
  2335. function invoicePrintDo() {
  2336. Doo::loadModel ( 'invoice' );
  2337. $invoice = new invoice ();
  2338. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2339. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2340. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2341. $iid = $invoice->authcode ( $iid );
  2342. if (! is_numeric ( $iid ))
  2343. die ( 'illegal request' );
  2344. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2345. Doo::loadModel ( 'invoiceOperationLog' );
  2346. $invoiceOperationLog = new invoiceOperationLog ();
  2347. Doo::loadModel ( 'invoiceStatistics' );
  2348. $invoiceStatistics = new invoiceStatistics ();
  2349. $XDeode = new XDeode ( 5 );
  2350. Doo::loadModel ( 'invoicePaper' );
  2351. $invoicePaper = new invoicePaper ();
  2352. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2353. if (empty ( $invoicePrintDetail ))
  2354. die ( 'illegal request' );
  2355. //
  2356. $ipid = $XDeode->decode ( $invoiceNo );
  2357. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2358. if (empty ( $paperDetail ))
  2359. die ( 'illegal request' );
  2360. $invoicePaper = new invoicePaper ();
  2361. $item = array (
  2362. 'iid' => $iid,
  2363. 'ipid' => $ipid
  2364. );
  2365. $invoicePaper->setInvoicePaperByCondition ( $item );
  2366. $item = array (
  2367. 'iid' => $iid,
  2368. 'printStatus' => 1,
  2369. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2370. 'printer' => $this->staff [0] ['username'],
  2371. 'printTime' => date ( "Y-m-d H:i:s" ),
  2372. 'invoiceNo' => $paperDetail ['invoiceNo']
  2373. );
  2374. $invoice->setInvoiceByCondition ( $item );
  2375. $item = array (
  2376. 'date' => date ( "Y-m-d H:i:s" ),
  2377. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2378. 'status' => 5,
  2379. 'img' => $this->staff [0] ['avatar'],
  2380. 'username' => $this->staff [0] ['username'],
  2381. 'uid' => $this->staff [0] ['sid'],
  2382. 'category' => $this->staff [0] ['category'],
  2383. 'iid' => $iid
  2384. );
  2385. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2386. // 去统计--负票不汇总
  2387. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2388. $item = array (
  2389. 'date' => date ( "Y-m-d H:i:s" ),
  2390. 'priceClass' => 1,
  2391. 'cid' => $invoicePrintDetail ['cid'],
  2392. 'staff' => $invoicePrintDetail ['sid'],
  2393. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2394. );
  2395. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2396. }
  2397. // 发送通知信息到微信-去除
  2398. // $this->setWXMsg($iid,'PRINT');
  2399. // 发票信息库
  2400. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2401. // 申请人获取微信通知
  2402. Doo::loadModel ( 'staff' );
  2403. $staff = new staff ();
  2404. Doo::loadClass ( 'XDeode' );
  2405. $XDeode = new XDeode ( 5 );
  2406. $username2 = $staff->getOne ( array (
  2407. 'select' => 'wxid',
  2408. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2409. 'asArray' => TRUE
  2410. ) );
  2411. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2412. $msg = '';
  2413. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2414. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2415. if (empty ( $invoicePrintType ))
  2416. return "/invoicePrint";
  2417. else
  2418. return "/invoicePrintStayAchieve";
  2419. }
  2420. }
  2421. /**
  2422. * 需要邮寄的发票
  2423. * @since 1.0.0
  2424. */
  2425. function invoicePost() {
  2426. Doo::loadModel ( 'invoice' );
  2427. $invoice = new invoice ();
  2428. Doo::loadModel ( 'express' );
  2429. $express = new express ();
  2430. $invoicePost = $invoice->getPostByInvoice ();
  2431. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2432. $expressList = $express->getExpressByAll ();
  2433. $invoicePostExpress = "";
  2434. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2435. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2436. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2437. $this->data ['expressList'] = $expressList;
  2438. $this->data ['invoicePost'] = $invoicePost;
  2439. $this->data ['invoicePosted'] = $invoicePosted;
  2440. $this->data ['memu'] = "invoice";
  2441. $this->data ['staff'] = $this->staff;
  2442. $this->data ['receiptMemu'] = 'invoicePost';
  2443. $this->render ( "/admin/invoicePost", $this->data );
  2444. }
  2445. /**
  2446. * 添加发票邮寄信息
  2447. */
  2448. function invoiceExpressAddDo() {
  2449. Doo::loadModel ( 'invoice' );
  2450. $invoice = new invoice ();
  2451. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2452. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2453. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2454. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2455. $iid = $iid = $invoice->authcode ( $iid );
  2456. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2457. die ( 'illegal request' );
  2458. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2459. setcookie ( 'invoicePostExpress', $expressNumber );
  2460. $item = array (
  2461. 'iid' => $iid,
  2462. 'postStatus' => 1,
  2463. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2464. 'postTime' => date ( "Y-m-d H:i:s" ),
  2465. 'expressCompany' => $expressCompany,
  2466. 'expressNumber' => $expressNumber,
  2467. 'actualItems' => $actualItems,
  2468. 'poster' => $this->staff [0] ['username']
  2469. );
  2470. $invoice->setInvoiceByCondition ( $item );
  2471. // 微信通知-去掉
  2472. // $this->setWXMsg ( $iid );
  2473. Doo::loadModel ( 'staff' );
  2474. $staff = new staff ();
  2475. Doo::loadClass ( 'XDeode' );
  2476. $XDeode = new XDeode ( 5 );
  2477. $username2 = $staff->getOne ( array (
  2478. 'select' => 'wxid',
  2479. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2480. 'asArray' => TRUE
  2481. ) );
  2482. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2483. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2484. if (empty ( $expCom ))
  2485. $expCom [0] = '';
  2486. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2487. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2488. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2489. return '/invoicePost';
  2490. }
  2491. function invoiceExpressUpdateDo() {
  2492. Doo::loadModel ( 'invoice' );
  2493. $invoice = new invoice ();
  2494. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2495. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2496. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2497. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2498. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2499. $iid = $invoice->authcode ( $iid );
  2500. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2501. die ( 'illegal request' );
  2502. $item = array (
  2503. 'iid' => $iid,
  2504. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2505. 'expressCompany' => $expressCompany,
  2506. 'expressNumber' => $expressNumber,
  2507. 'actualItems' => $actualItems,
  2508. 'poster' => $this->staff [0] ['username']
  2509. );
  2510. $invoice->setInvoiceByCondition ( $item );
  2511. return $action;
  2512. }
  2513. /**
  2514. * 可退票管理
  2515. */
  2516. function invoiceUntreadIsAchieve() {
  2517. Doo::loadModel ( 'invoice' );
  2518. $invoice = new invoice ();
  2519. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2520. /*
  2521. * 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' => '' );
  2522. */
  2523. if (empty ( $MebSea )) {//
  2524. $con = ' and invoiceNo like "NULL" ';
  2525. } else {
  2526. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2527. }
  2528. // printStatus=1 and
  2529. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2530. /*
  2531. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2532. */
  2533. $limit = '0,20';
  2534. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2535. // print_r($list);
  2536. $this->data ['MebSeaEn'] = $MebSea;
  2537. /*
  2538. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2539. */
  2540. $this->data ['list'] = $list;
  2541. $this->data ['memu'] = "invoice";
  2542. $this->data ['staff'] = $this->staff;
  2543. $this->data ['receiptMemu'] = 'invoice';
  2544. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2545. }
  2546. // 已经退票的发票
  2547. function invoiceUntreadED() {
  2548. Doo::loadModel ( 'invoice' );
  2549. $invoice = new invoice ();
  2550. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2551. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2552. Doo::loadClass ( 'XDeode' );
  2553. $XDeode = new XDeode ( 5 );
  2554. $page_size = 18;
  2555. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2556. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2557. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2558. $dateArr = explode ( ':', $date );
  2559. $D1 = '';
  2560. $D2 = '';
  2561. if (! empty ( $date )) {
  2562. $D1 = $dateArr [0];
  2563. $D2 = $dateArr [1];
  2564. }
  2565. $con = '';
  2566. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2567. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2568. }
  2569. // if ($date == 'MONTHO')
  2570. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2571. // elseif ($date == 'MONTHT')
  2572. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2573. // elseif ($date == 'MONTHY')
  2574. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2575. if (! empty ( $MebSea )) {
  2576. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2577. }
  2578. if ($invoiceType == 'ORDINARY') {
  2579. $con .= ' and invoiceType=0 ';
  2580. } elseif ($invoiceType == 'SPECIAL') {
  2581. $con .= ' and invoiceType=1 ';
  2582. }
  2583. $pageinfo ['page'] = array (
  2584. 'previous' => ''
  2585. );
  2586. // printStatus=1 and
  2587. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2588. $action = "invoiceUntreadED";
  2589. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2590. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2591. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2592. // print_r($list);
  2593. $this->data ['MebSeaEn'] = $MebSea;
  2594. $this->data ['get'] = $get;
  2595. $this->data ['page'] = $pageinfo;
  2596. $this->data ['date'] = $date;
  2597. $this->data ['invoiceType'] = $invoiceType;
  2598. $this->data ['list'] = $list;
  2599. $this->data ['memu'] = "invoice";
  2600. $this->data ['staff'] = $this->staff;
  2601. $this->data ['receiptMemu'] = 'invoice';
  2602. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2603. }
  2604. /**
  2605. * 退票处理页面
  2606. */
  2607. function invoiceUntread() {
  2608. Doo::loadModel ( 'invoice' );
  2609. $invoice = new invoice ();
  2610. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2611. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2612. foreach ( $establishedInvoice as $key => $value ) {
  2613. // months
  2614. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2615. $nowDate = strtotime ( 'now' );
  2616. $establishedInvoice [$key] ['lossShow'] = false;
  2617. if ($lossDate < $nowDate)
  2618. $establishedInvoice [$key] ['lossShow'] = true;
  2619. }
  2620. $this->data ['untreadInvoice'] = $untreadInvoice;
  2621. $this->data ['establishedInvoice'] = $establishedInvoice;
  2622. $this->data ['memu'] = "invoice";
  2623. $this->data ['staff'] = $this->staff;
  2624. $this->data ['receiptMemu'] = 'invoiceUntread';
  2625. $this->render ( "/admin/invoiceUntread", $this->data );
  2626. }
  2627. /**
  2628. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2629. */
  2630. function invoiceUntreadEstablishedDo() {
  2631. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2632. Doo::loadModel ( 'invoice' );
  2633. $invoice = new invoice ();
  2634. Doo::loadModel ( 'invoiceOperationLog' );
  2635. $invoiceOperationLog = new invoiceOperationLog ();
  2636. Doo::loadModel ( 'invoiceReceivables' );
  2637. Doo::loadModel ( 'invoiceStatistics' );
  2638. $iid = $invoice->authcode ( $untreadIidKey );
  2639. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2640. die ( 'illegal request' );
  2641. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2642. if ($invoiceDetails ['untreadStatus'] != 1)
  2643. die ( 'illegal request untreadStatus error !=1' );
  2644. $item = array (
  2645. 'iid' => $iid,
  2646. // 'irid'=>'',
  2647. 'untreadStatus' => 2,
  2648. 'updateTime' => date ( "Y-m-d H:i:s" )
  2649. );
  2650. $invoice->setInvoiceByCondition ( $item );
  2651. $item = array (
  2652. 'date' => date ( "Y-m-d H:i:s" ),
  2653. 'operation' => '已确认退票',
  2654. 'status' => 6,
  2655. 'img' => $this->staff [0] ['avatar'],
  2656. 'username' => $this->staff [0] ['username'],
  2657. 'uid' => $this->staff [0] ['sid'],
  2658. 'category' => $this->staff [0] ['category'],
  2659. 'iid' => $iid
  2660. );
  2661. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2662. // 收款解绑以及入账扣除 收款扣除
  2663. if (! empty ( $invoiceDetails ['irid'] )) {
  2664. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2665. foreach ( $iridList as $value ) {
  2666. $invoiceReceivables = new invoiceReceivables ();
  2667. $irDetails = $invoiceReceivables->getOne ( array (
  2668. 'where' => " irid=" . $value . ' and bindStatus=1',
  2669. 'asArray' => TRUE
  2670. ) );
  2671. $item = array (
  2672. 'irid' => $value,
  2673. 'bindStatus' => 0,
  2674. 'untreadStatus' => 1,
  2675. 'untreadStaff' => $invoiceDetails ['userName'],
  2676. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2677. 'iid' => 0
  2678. );
  2679. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2680. if (! empty ( $irDetails )) {
  2681. // 扣除入账
  2682. $invoiceStatistics = new invoiceStatistics ();
  2683. $item = array (
  2684. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2685. 'priceClass' => 3,
  2686. 'cid' => $invoiceDetails ['cid'],
  2687. 'staff' => $invoiceDetails ['sid'],
  2688. 'accountPrice' => - $irDetails ['receivablesPrice']
  2689. );
  2690. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2691. // 扣除收款
  2692. $invoiceStatistics = new invoiceStatistics ();
  2693. $item = array (
  2694. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2695. 'priceClass' => 2,
  2696. 'cid' => $invoiceDetails ['cid'],
  2697. 'staff' => $invoiceDetails ['sid'],
  2698. 'irid' => $irDetails ['irid'],
  2699. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2700. );
  2701. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2702. }
  2703. // 解绑时删除收入流水
  2704. Doo::loadModel ( 'wasteBook' );
  2705. $wasteBook = new wasteBook ();
  2706. $wasteBook->delete ( array (
  2707. 'where' => 'dataID=' . $value . ' and accountType=7',
  2708. 'limit' => 1
  2709. ) );
  2710. }
  2711. }
  2712. return "/invoiceUntread";
  2713. }
  2714. function invoiceUntreadRecallDo() {
  2715. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2716. Doo::loadModel ( 'invoice' );
  2717. $invoice = new invoice ();
  2718. Doo::loadClass ( 'XDeode' );
  2719. $XDeode = new XDeode ( 5 );
  2720. Doo::loadModel ( 'invoiceOperationLog' );
  2721. $invoiceOperationLog = new invoiceOperationLog ();
  2722. $iid = $XDeode->decode ( $iidKey );
  2723. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2724. if (empty ( $invoiceDetail )) {
  2725. die ( 'illegal request-DATANULL' );
  2726. }
  2727. $item = array (
  2728. 'iid' => $iid,
  2729. 'untreadStatus' => 0
  2730. );
  2731. $invoice->setInvoiceByCondition ( $item );
  2732. $item = array (
  2733. 'date' => date ( "Y-m-d H:i:s" ),
  2734. 'operation' => '撤回申请退票',
  2735. 'status' => 13,
  2736. 'img' => $this->staff [0] ['avatar'],
  2737. 'username' => $this->staff [0] ['username'],
  2738. 'uid' => $this->staff [0] ['sid'],
  2739. 'category' => $this->staff [0] ['category'],
  2740. 'iid' => $iid
  2741. );
  2742. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2743. return "/invoiceUntread";
  2744. }
  2745. /**
  2746. * 建立负票,关联原来发票
  2747. */
  2748. function invoiceLossDo() {
  2749. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2750. if (! empty ( $iidKey )) {
  2751. Doo::loadClass ( 'XDeode' );
  2752. $XDeode = new XDeode ( 5 );
  2753. Doo::loadModel ( 'invoice' );
  2754. $invoice = new invoice ();
  2755. Doo::loadModel ( 'invoiceOperationLog' );
  2756. $invoiceOperationLog = new invoiceOperationLog ();
  2757. $iidKey = $XDeode->decode ( $iidKey );
  2758. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2759. // 拷贝插入一条发票数据
  2760. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2761. // 更新负票
  2762. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2763. $invoice = new invoice ();
  2764. $item = array (
  2765. 'iid' => $iid,
  2766. 'sid' => $this->staff [0] ['sid'],
  2767. 'userName' => $this->staff [0] ['username'],
  2768. 'cid' => $this->staff [0] ['cid'],
  2769. 'categoryName' => $this->staff [0] ['category'],
  2770. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2771. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2772. 'invoiceSerial' => $invoiceSerial,
  2773. 'invoiceNo' => '',
  2774. 'printStatus' => 0,
  2775. 'untreadStatus' => 4,
  2776. // 关联发票号
  2777. 'lossIid' => $invoiceDetail ['iid']
  2778. );
  2779. $invoice->setInvoiceByCondition ( $item );
  2780. // 更新原发票
  2781. $invoice = new invoice ();
  2782. $item = array (
  2783. 'iid' => $invoiceDetail ['iid'],
  2784. 'lossIid' => $iid
  2785. );
  2786. $invoice->setInvoiceByCondition ( $item );
  2787. // 操作日志
  2788. $item = array (
  2789. 'date' => date ( "Y-m-d H:i:s" ),
  2790. 'operation' => "创建负票" . $invoiceSerial,
  2791. 'status' => 12,
  2792. 'img' => $this->staff [0] ['avatar'],
  2793. 'username' => $this->staff [0] ['username'],
  2794. 'uid' => $this->staff [0] ['sid'],
  2795. 'category' => $this->staff [0] ['category'],
  2796. 'iid' => $iid
  2797. );
  2798. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2799. // print_r($invoiceDetail);
  2800. // echo $iid;die;
  2801. }
  2802. return '/invoiceUntread';
  2803. }
  2804. /**
  2805. * 上传银行到账 收款文件
  2806. */
  2807. function invoiceReceivablesBankUpload() {
  2808. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2809. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2810. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2811. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2812. header ( "HTTP/1.1 500 Internal Server Error" );
  2813. echo "POST exceeded maximum allowed size.";
  2814. exit ( 0 );
  2815. }
  2816. // Settings
  2817. $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)
  2818. $upload_name = "Filedata";
  2819. $file_name = "";
  2820. $nk = time ();
  2821. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2822. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2823. echo "文件无法保存.";
  2824. exit ( 0 );
  2825. }
  2826. echo json_encode ( array (
  2827. 'filename' => $file_name,
  2828. 'id' => $nk
  2829. ) );
  2830. exit ( 0 );
  2831. }
  2832. /**
  2833. * 解析银行到账收款execl并导入库中
  2834. */
  2835. function invoiceReceivablesImport() {
  2836. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2837. if ($path != "") {
  2838. Doo::loadModel ( 'invoiceReceivables' );
  2839. $invoiceReceivables = new invoiceReceivables ();
  2840. Doo::loadClass ( 'invoice.func' );
  2841. Doo::loadModel ( 'invoiceROLog' );
  2842. $invoiceROLog = new invoiceROLog ();
  2843. Doo::loadModel ( 'invoiceStatistics' );
  2844. $invoiceStatistics = new invoiceStatistics ();
  2845. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2846. $bankBatchNumber = 'BBN_' . time ();
  2847. Doo::db ()->beginTransaction ();
  2848. // 批量存储收款--由于必须获得收款ID,
  2849. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2850. VALUES ';
  2851. $date = date ( "Y-m-d" );
  2852. $receivablesList = array ();
  2853. foreach ( $exlArray as $key => $value ) {
  2854. $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"] . '")';
  2855. array_push ( $receivablesList, $receivablesSql );
  2856. }
  2857. $sql = $sql . implode ( ',', $receivablesList );
  2858. // echo $sql;
  2859. Doo::db ()->query ( $sql );
  2860. // 批量存储收款统计
  2861. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2862. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2863. // 没有irid 回滚所有操作
  2864. if (empty ( $iridList )) {
  2865. Doo::db ()->rollBack ();
  2866. header ( 'Content-Type:text/html;charset=utf-8' );
  2867. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2868. }
  2869. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2870. VALUES ';
  2871. $statisticsList = array ();
  2872. foreach ( $iridList as $value ) {
  2873. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2874. array_push ( $statisticsList, $statisticsSql );
  2875. }
  2876. $sql = $sql . implode ( ',', $statisticsList );
  2877. Doo::db ()->query ( $sql );
  2878. // 批量存储操作日志
  2879. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2880. VALUES ';
  2881. $ROLogList = array ();
  2882. foreach ( $iridList as $value ) {
  2883. $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'] . '")';
  2884. array_push ( $ROLogList, $ROLogSql );
  2885. }
  2886. $sql = $sql . implode ( ',', $ROLogList );
  2887. Doo::db ()->query ( $sql );
  2888. // 批量写入流水
  2889. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2890. VALUES ';
  2891. $wasteBookList = array ();
  2892. foreach ( $iridList as $value ) {
  2893. $accountBank = '';
  2894. if ($value ['receivablesBank'] == '纵横广发') {
  2895. $accountBank = 'CGBDeposit';
  2896. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2897. $accountBank = 'ICBCDeposit';
  2898. } elseif ($value ['receivablesBank'] == '华润银行') {
  2899. $accountBank = 'HUADeposit';
  2900. } elseif ($value ['receivablesBank'] == '个人广发') {
  2901. $accountBank = 'PersonalDeposit';
  2902. }
  2903. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2904. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2905. array_push ( $wasteBookList, $wasteBookSql );
  2906. }
  2907. $sql = $sql . implode ( ',', $wasteBookList );
  2908. Doo::db ()->query ( $sql );
  2909. Doo::db ()->commit ();
  2910. return "/invoiceReceivables";
  2911. }
  2912. echo 'no file';
  2913. }
  2914. function invoiceReceivables() {
  2915. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2916. Doo::loadModel ( 'L_category' );
  2917. $lCategory = new L_category ();
  2918. Doo::loadModel ( 'staff' );
  2919. $staff = new staff ();
  2920. Doo::loadModel ( 'invoiceReceivables' );
  2921. $invoiceReceivables = new invoiceReceivables ();
  2922. Doo::loadModel ( 'invoice' );
  2923. $invoice = new invoice ();
  2924. Doo::loadClass ( 'XDeode' );
  2925. $XDeode = new XDeode ( 5 );
  2926. $category = $lCategory->getCategory ();
  2927. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2928. $sql = 'bindStatus=1 and iid!=0';
  2929. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2930. // 获取未入账发票
  2931. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2932. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2933. foreach ( $invoiceUnAccount as $key => $value ) {
  2934. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2935. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2936. if (! empty ( $lastApprover )) {
  2937. $lastApproverKey = array_keys ( $lastApprover );
  2938. $lastApprover = end ( $lastApprover );
  2939. $staffDetail = $staff->getOne ( array (
  2940. 'where' => 'sid=' . end ( $lastApproverKey ),
  2941. 'asArray' => true
  2942. ) );
  2943. $lastApprover ['username'] = $staffDetail ['username'];
  2944. }
  2945. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2946. }
  2947. foreach ( $invoiceExistAccount as $key => $value ) {
  2948. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2949. if (empty ( $irList ))
  2950. $irList [0] ['sumPrice'] = 0;
  2951. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2952. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2953. $invoiceExistAccount [$key] ['balance'] = $balance;
  2954. }
  2955. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2956. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2957. $this->data ['halfList'] = $halfList;
  2958. $this->data ['halfCount'] = count ( $halfList );
  2959. // print_r($receivablesList);
  2960. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2961. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2962. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2963. $this->data ['receivablesInput'] = $receivablesInput;
  2964. $this->data ['year'] = date ( 'Y' );
  2965. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2966. $this->data ['receivablesList'] = $receivablesList;
  2967. $this->data ['staffList'] = $staffList;
  2968. $this->data ['category'] = $category;
  2969. $this->data ['memu'] = "invoice";
  2970. $this->data ['staff'] = $this->staff;
  2971. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2972. $this->render ( "/admin/invoiceReceivables", $this->data );
  2973. }
  2974. /**
  2975. * 设置收款认领地区
  2976. */
  2977. function setInvoiceReceivablesClaim() {
  2978. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2979. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2980. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2981. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2982. Doo::loadModel ( 'invoiceReceivables' );
  2983. $invoiceReceivables = new invoiceReceivables ();
  2984. Doo::loadClass ( 'XDeode' );
  2985. $XDeode = new XDeode ( 5 );
  2986. Doo::loadModel ( 'invoiceROLog' );
  2987. $invoiceROLog = new invoiceROLog ();
  2988. $irid = $XDeode->decode ( $iridKey );
  2989. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2990. if (empty ( $irDetail ))
  2991. die ( 'illegal request' );
  2992. $item = array (
  2993. 'irid' => $irid,
  2994. 'receivablesCategory' => $receivablesCategory
  2995. );
  2996. if ($receivablesCategory != 'PUBLIC') {
  2997. $item += array (
  2998. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2999. 'inputType' => 1
  3000. );
  3001. }
  3002. $invoiceReceivables = new invoiceReceivables ();
  3003. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3004. // 收款操作日志
  3005. $item = array (
  3006. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3007. 'date' => date ( "Y-m-d" ),
  3008. 'status' => 1,
  3009. 'img' => $this->staff [0] ['avatar'],
  3010. 'username' => $this->staff [0] ['username'],
  3011. 'uid' => $this->staff [0] ['sid'],
  3012. 'category' => $this->staff [0] ['category'],
  3013. 'irid' => $irid
  3014. );
  3015. $invoiceROLog->setInvoiceROLog ( $item );
  3016. if (empty ( $action ))
  3017. return '/invoiceReceivables';
  3018. else
  3019. return "/invoiceReceivablesAS";
  3020. }
  3021. die ( 'illegal request' );
  3022. }
  3023. /**
  3024. * 新添加收款直接入账发票
  3025. */
  3026. function invoiceCompareClaimPrice() {
  3027. // 收款录入
  3028. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3029. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3030. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3031. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3032. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3033. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3034. Doo::loadModel ( 'invoiceReceivables' );
  3035. $invoiceReceivables = new invoiceReceivables ();
  3036. Doo::loadModel ( 'invoiceROLog' );
  3037. $invoiceROLog = new invoiceROLog ();
  3038. Doo::loadModel ( 'invoiceStatistics' );
  3039. Doo::loadModel ( 'invoice' );
  3040. $invoice = new invoice ();
  3041. Doo::loadClass ( 'XDeode' );
  3042. $XDeode = new XDeode ( 5 );
  3043. Doo::loadModel ( 'invoiceOperationLog' );
  3044. $invoiceOperationLog = new invoiceOperationLog ();
  3045. $iidKey = $XDeode->decode ( $iidKey );
  3046. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3047. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3048. die ( 'illegal request' );
  3049. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3050. // 收款录入 并绑定发票
  3051. Doo::db ()->beginTransaction ();
  3052. $bindStatus = 0;
  3053. if ($receivablesPrice <= $invoiceDetail ['invoicePrice']){
  3054. $bindStatus = 1;
  3055. }
  3056. $titleMark = $invoiceDetail ['invoiceTitle'];
  3057. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3058. $titleMark = $invoiceDetail ['invoiceCompany'];
  3059. $item = array (
  3060. 'recepitTitleMark' => $titleMark,
  3061. 'bindStatus' => $bindStatus,
  3062. 'iid' => $invoiceDetail ['iid'],
  3063. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  3064. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3065. 'receivablesPrice' => $receivablesPrice,
  3066. 'OriginalPrice' => $receivablesPrice,
  3067. 'receivablesMessage' => $receivablesMessage,
  3068. 'receivablesSerial' => $receivablesSerial,
  3069. 'receivablesBank' => $receivablesBank,
  3070. 'receivablesDate' => $receivablesDate,
  3071. 'inputStaff' => $this->staff [0] ['username'],
  3072. 'accountClerk' => $this->staff [0] ['username'],
  3073. 'date' => date ( "Y-m-d" ),
  3074. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3075. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3076. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3077. );
  3078. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3079. $item = array ();
  3080. // 收款操作日志
  3081. $item = array (
  3082. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3083. );
  3084. $item += array (
  3085. 'date' => date ( "Y-m-d" ),
  3086. 'status' => 1,
  3087. 'img' => $this->staff [0] ['avatar'],
  3088. 'username' => $this->staff [0] ['username'],
  3089. 'uid' => $this->staff [0] ['sid'],
  3090. 'category' => $this->staff [0] ['category'],
  3091. 'irid' => $irid
  3092. );
  3093. $invoiceROLog->setInvoiceROLog ( $item );
  3094. // 收款统计
  3095. $invoiceStatistics = new invoiceStatistics ();
  3096. $item = array (
  3097. 'date' => $receivablesDate,
  3098. 'priceClass' => 2,
  3099. 'irid' => $irid,
  3100. 'cid' => $invoiceDetail ['cid'],
  3101. 'staff' => $invoiceDetail ['sid'],
  3102. 'receivablesPrice' => $receivablesPrice
  3103. );
  3104. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3105. // 收款 入 发票
  3106. $detail = $invoiceDetail;
  3107. $iridString = "";
  3108. if (empty ( $detail ['irid'] ))
  3109. $iridString = $irid;
  3110. else
  3111. $iridString = $detail ['irid'] . ',' . $irid;
  3112. $item = array (
  3113. 'irid' => $iridString,
  3114. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3115. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3116. 'iid' => $detail ['iid']
  3117. );
  3118. $invoiceReceivables = new invoiceReceivables ();
  3119. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3120. if ($detail ['invoicePrice'] <= $sum)
  3121. $item += array (
  3122. 'untreadStatus' => 3
  3123. );
  3124. $invoice->setInvoiceByCondition ( $item );
  3125. // 操作日志
  3126. $item = array (
  3127. 'date' => date ( "Y-m-d H:i:s" ),
  3128. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3129. 'status' => 8,
  3130. 'img' => $this->staff [0] ['avatar'],
  3131. 'username' => $this->staff [0] ['username'],
  3132. 'uid' => $this->staff [0] ['sid'],
  3133. 'category' => $this->staff [0] ['category'],
  3134. 'iid' => $detail ['iid']
  3135. );
  3136. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3137. // 入账汇总
  3138. $invoiceStatistics = new invoiceStatistics ();
  3139. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3140. // $accountPrice = 0;
  3141. // foreach ( $list as $key => $value ) {
  3142. // $accountPrice += $value ['receivablesPrice'];
  3143. // }
  3144. $item = array (
  3145. 'date' => $receivablesDate,
  3146. 'priceClass' => 3,
  3147. 'cid' => $invoiceDetail ['cid'],
  3148. 'staff' => $invoiceDetail ['sid'],
  3149. 'accountPrice' => $receivablesPrice
  3150. );
  3151. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3152. // 公司流水记录
  3153. Doo::loadModel ( 'wasteBook' );
  3154. $wasteBook = new wasteBook ();
  3155. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3156. $accountBank = '';
  3157. if ($receivablesBank == '纵横广发') {
  3158. $accountBank = 'CGBDeposit';
  3159. } elseif ($receivablesBank == '纵横工行') {
  3160. $accountBank = 'ICBCDeposit';
  3161. } elseif ($receivablesBank == '华润银行') {
  3162. $accountBank = 'HUADeposit';
  3163. } elseif ($receivablesBank == '个人广发') {
  3164. $accountBank = 'PersonalDeposit';
  3165. }
  3166. if (empty ( $abDetail )) {
  3167. $item = array (
  3168. 'dataID' => $irid,
  3169. 'expensesType' => 1,
  3170. 'accountType' => 7,
  3171. 'accountPrice' => $receivablesPrice,
  3172. 'accountPriceShow' => $receivablesPrice,
  3173. 'accountBank' => $accountBank,
  3174. 'category' => $this->staff [0] ['category'],
  3175. 'cid' => $this->staff [0] ['cid'],
  3176. 'name' => $this->staff [0] ['username'],
  3177. 'sid' => $this->staff [0] ['sid'],
  3178. 'inputDate' => date ( "Y-m-d H:i:s" )
  3179. );
  3180. $wasteBook->setAccountBookStatistics ( $item );
  3181. }
  3182. Doo::db ()->commit ();
  3183. }
  3184. return '/invoiceReceivables';
  3185. }
  3186. /**
  3187. * 录入收款数据
  3188. * @return string
  3189. */
  3190. function invoiceReceivablesDo() {
  3191. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3192. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3193. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3194. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3195. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3196. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3197. Doo::loadModel ( 'invoiceReceivables' );
  3198. $invoiceReceivables = new invoiceReceivables ();
  3199. Doo::loadModel ( 'invoiceROLog' );
  3200. $invoiceROLog = new invoiceROLog ();
  3201. Doo::loadModel ( 'invoiceStatistics' );
  3202. $invoiceStatistics = new invoiceStatistics ();
  3203. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3204. $item = array (
  3205. 'receivablesPrice' => $receivablesPrice,
  3206. 'OriginalPrice' => $receivablesPrice,
  3207. 'receivablesMessage' => $receivablesMessage,
  3208. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3209. 'receivablesBank' => $receivablesBank,
  3210. 'receivablesDate' => $receivablesDate,
  3211. 'inputStaff' => $this->staff [0] ['username'],
  3212. 'date' => date ( "Y-m-d" ),
  3213. 'receivablesCategory' => $receivablesCategory,
  3214. 'receivablesStaff' => $receivablesStaff
  3215. );
  3216. if ($receivablesCategory != 'PUBLIC') {
  3217. $item += array (
  3218. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3219. 'inputType' => 1
  3220. );
  3221. }
  3222. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3223. $item = array ();
  3224. // 收款操作日志
  3225. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3226. $item = array (
  3227. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3228. );
  3229. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3230. $item = array (
  3231. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3232. );
  3233. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3234. $receivablesStaff = explode ( '-', $receivablesStaff );
  3235. $item = array (
  3236. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3237. );
  3238. }
  3239. $item += array (
  3240. 'date' => date ( "Y-m-d" ),
  3241. 'status' => 1,
  3242. 'img' => $this->staff [0] ['avatar'],
  3243. 'username' => $this->staff [0] ['username'],
  3244. 'uid' => $this->staff [0] ['sid'],
  3245. 'category' => $this->staff [0] ['category'],
  3246. 'irid' => $irid
  3247. );
  3248. $invoiceROLog->setInvoiceROLog ( $item );
  3249. $item = array (
  3250. 'date' => $receivablesDate,
  3251. 'priceClass' => 2,
  3252. 'irid' => $irid,
  3253. 'receivablesPrice' => $receivablesPrice
  3254. );
  3255. if ($receivablesCategory != 'PUBLIC') {
  3256. $receivablesCategory = explode ( ":", $receivablesCategory );
  3257. $item += array (
  3258. 'cid' => $receivablesCategory [0]
  3259. );
  3260. }
  3261. if ($receivablesStaff2 != 'PUBLIC') {
  3262. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3263. $item += array (
  3264. 'staff' => $receivablesStaff [0]
  3265. );
  3266. }
  3267. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3268. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3269. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3270. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3271. if ($toparty != 0)
  3272. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3273. // 公司流水记录
  3274. Doo::loadModel ( 'wasteBook' );
  3275. $wasteBook = new wasteBook ();
  3276. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3277. $accountBank = '';
  3278. if ($receivablesBank == '纵横广发') {
  3279. $accountBank = 'CGBDeposit';
  3280. } elseif ($receivablesBank == '纵横工行') {
  3281. $accountBank = 'ICBCDeposit';
  3282. } elseif ($receivablesBank == '华润银行') {
  3283. $accountBank = 'HUADeposit';
  3284. } elseif ($receivablesBank == '个人广发') {
  3285. $accountBank = 'PersonalDeposit';
  3286. }
  3287. $item = array (
  3288. 'dataID' => $irid,
  3289. 'expensesType' => 1,
  3290. 'accountType' => 7,
  3291. 'accountPriceShow' => $receivablesPrice,
  3292. 'accountPrice' => $receivablesPrice,
  3293. 'accountBank' => $accountBank,
  3294. 'category' => $this->staff [0] ['category'],
  3295. 'cid' => $this->staff [0] ['cid'],
  3296. 'name' => $this->staff [0] ['username'],
  3297. 'sid' => $this->staff [0] ['sid'],
  3298. 'inputDate' => date ( "Y-m-d H:i:s" )
  3299. );
  3300. $wasteBook->setAccountBookStatistics ( $item );
  3301. }
  3302. return "/invoiceReceivables";
  3303. }
  3304. /**
  3305. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3306. */
  3307. function invoiceReceivablesClaim() {
  3308. Doo::loadModel ( 'invoiceReceivables' );
  3309. $invoiceReceivables = new invoiceReceivables ();
  3310. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3311. $this->data ['receivablesList'] = $receivablesList;
  3312. $this->data ['memu'] = "invoice";
  3313. $this->data ['staff'] = $this->staff;
  3314. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3315. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3316. }
  3317. function invoiceReceivablesTitleMarkSet() {
  3318. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3319. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3320. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3321. die ( 'illegal request' );
  3322. Doo::loadModel ( 'invoiceReceivables' );
  3323. $invoiceReceivables = new invoiceReceivables ();
  3324. Doo::loadClass ( 'XDeode' );
  3325. $XDeode = new XDeode ( 5 );
  3326. $irid = $XDeode->decode ( $iridKey );
  3327. if (! is_numeric ( $irid ))
  3328. die ( 'illegal request' );
  3329. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3330. $invoiceReceivables->update ( array (
  3331. 'where' => 'irid = ' . $irid
  3332. ) );
  3333. return '/invoiceReceivablesClaim';
  3334. }
  3335. /**
  3336. * 更新收款相关数据
  3337. */
  3338. function invoiceReceivablesUpdateClaim() {
  3339. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3340. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3341. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3342. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3343. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3344. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3345. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3346. if (empty ( $claimKey ))
  3347. die ( 'illegal request' );
  3348. Doo::loadModel ( 'invoiceReceivables' );
  3349. $invoiceReceivables = new invoiceReceivables ();
  3350. Doo::loadModel ( 'invoiceROLog' );
  3351. $invoiceROLog = new invoiceROLog ();
  3352. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3353. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3354. if (empty ( $detail ))
  3355. die ( 'illegal request' );
  3356. $invoiceReceivables = new invoiceReceivables ();
  3357. $item = array (
  3358. 'irid' => $detail ['irid']
  3359. );
  3360. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3361. $item += array (
  3362. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3363. );
  3364. }
  3365. if (! empty ( $receivablesCategory ))
  3366. $item += array (
  3367. 'receivablesCategory' => $receivablesCategory
  3368. );
  3369. if (! empty ( $receivablesStaff ))
  3370. $item += array (
  3371. 'receivablesStaff' => $receivablesStaff
  3372. );
  3373. if (! empty ( $receivablesPrice ))
  3374. $item += array (
  3375. 'receivablesPrice' => $receivablesPrice
  3376. );
  3377. if (! empty ( $receivablesMessage ))
  3378. $item += array (
  3379. 'receivablesMessage' => $receivablesMessage
  3380. );
  3381. if (! empty ( $receivablesBank ))
  3382. $item += array (
  3383. 'receivablesBank' => $receivablesBank
  3384. );
  3385. if (! empty ( $receivablesDate ))
  3386. $item += array (
  3387. 'receivablesDate' => $receivablesDate
  3388. );
  3389. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3390. // 收款操作日志
  3391. $item = array ();
  3392. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3393. $item = array (
  3394. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3395. );
  3396. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3397. $item = array (
  3398. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3399. );
  3400. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3401. $receivablesStaff = explode ( '-', $receivablesStaff );
  3402. $item = array (
  3403. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3404. );
  3405. }
  3406. $item += array (
  3407. 'date' => date ( "Y-m-d" ),
  3408. 'status' => 1,
  3409. 'img' => $this->staff [0] ['avatar'],
  3410. 'username' => $this->staff [0] ['username'],
  3411. 'uid' => $this->staff [0] ['sid'],
  3412. 'category' => $this->staff [0] ['category'],
  3413. 'irid' => $detail ['irid']
  3414. );
  3415. $invoiceROLog->setInvoiceROLog ( $item );
  3416. return '/invoiceReceivablesAS';
  3417. }
  3418. function invoiceReceivablesDelete() {
  3419. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3420. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3421. if ($skll != '删除到款')
  3422. die ( 'illegal request' );
  3423. if (empty ( $claimKey ))
  3424. die ( 'illegal request' );
  3425. Doo::loadModel ( 'invoiceReceivables' );
  3426. $invoiceReceivables = new invoiceReceivables ();
  3427. $con = ' and bindStatus=0 ';
  3428. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3429. if (empty ( $detail ))
  3430. die ( 'illegal request' );
  3431. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3432. // 扣除收款汇总信息 汇总
  3433. Doo::loadModel ( 'invoiceStatistics' );
  3434. $invoiceStatistics = new invoiceStatistics ();
  3435. $item = array (
  3436. 'date' => $detail ['receivablesDate'],
  3437. 'priceClass' => 2,
  3438. 'irid' => $detail ['irid'],
  3439. 'receivablesPrice' => - $detail ['receivablesPrice']
  3440. );
  3441. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3442. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3443. $item += array (
  3444. 'cid' => $receivablesCategory [0]
  3445. );
  3446. }
  3447. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3448. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3449. $item += array (
  3450. 'staff' => $receivablesStaff [0]
  3451. );
  3452. }
  3453. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3454. // 公司流水-删除时删除流水
  3455. Doo::loadModel ( 'wasteBook' );
  3456. $wasteBook = new wasteBook ();
  3457. $wasteBook->delete ( array (
  3458. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3459. 'limit' => 1
  3460. ) );
  3461. return '/invoiceReceivablesAS';
  3462. }
  3463. /**
  3464. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3465. */
  3466. function invoiceReceivablesAscription() {
  3467. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3468. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3469. Doo::loadModel ( 'invoiceReceivables' );
  3470. $invoiceReceivables = new invoiceReceivables ();
  3471. Doo::loadModel ( 'invoiceROLog' );
  3472. $invoiceROLog = new invoiceROLog ();
  3473. Doo::loadModel ( 'invoiceStatistics' );
  3474. $invoiceStatistics = new invoiceStatistics ();
  3475. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3476. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3477. $item = array (
  3478. 'irid' => $detail ['irid'],
  3479. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3480. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3481. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3482. 'recepitTitleMark' => $recepitTitleMark,
  3483. 'source' => 1
  3484. );
  3485. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3486. $item = array (
  3487. 'date' => date ( "Y-m-d" ),
  3488. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3489. 'status' => 2,
  3490. 'img' => $this->staff [0] ['avatar'],
  3491. 'username' => $this->staff [0] ['username'],
  3492. 'uid' => $this->staff [0] ['sid'],
  3493. 'category' => $this->staff [0] ['category'],
  3494. 'irid' => $irid
  3495. );
  3496. $invoiceROLog->setInvoiceROLog ( $item );
  3497. $item = array (
  3498. 'cid' => $this->staff [0] ['cid'],
  3499. 'staff' => $this->staff [0] ['sid']
  3500. );
  3501. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3502. }
  3503. return "/invoiceReceivablesClaim";
  3504. }
  3505. /**
  3506. */
  3507. function invoiceMyReceivables() {
  3508. Doo::loadModel ( 'invoiceReceivables' );
  3509. $invoiceReceivables = new invoiceReceivables ();
  3510. Doo::loadModel ( 'invoiceStatistics' );
  3511. $invoiceStatistics = new invoiceStatistics ();
  3512. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3513. $year = date ( "Y" );
  3514. $tmp_date = date ( "Ym" );
  3515. $tmp_year = substr ( $tmp_date, 0, 4 );
  3516. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3517. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3518. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3519. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3520. $htm = $this->showCache ( $path );
  3521. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3522. $this->data ['isMonth'] = $isMonth;
  3523. $this->data ['htm'] = $htm;
  3524. $this->data ['list'] = $list;
  3525. $this->data ['memu'] = "invoice";
  3526. $this->data ['staff'] = $this->staff;
  3527. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3528. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3529. }
  3530. /**
  3531. * 纸票管理
  3532. */
  3533. function invoicePaper() {
  3534. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3535. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3536. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3537. $this->data ['dateString'] = $date;
  3538. $this->data ['status'] = $status;
  3539. $this->data ['invoiceType'] = $invoiceType;
  3540. $this->data ['memu'] = "invoice";
  3541. $this->data ['staff'] = $this->staff;
  3542. $this->data ['receiptMemu'] = 'invoicePaper';
  3543. $this->render ( "/admin/invoicePaper", $this->data );
  3544. }
  3545. /**
  3546. * 获得纸票分页数据
  3547. */
  3548. function ajaxGetinvoicePaperAchieve() {
  3549. Doo::loadModel ( 'invoicePaper' );
  3550. $invoicePaper = new invoicePaper ();
  3551. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3552. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3553. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3554. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3555. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3556. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3557. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3558. $MebSea = $this->get_args ( 'search' );
  3559. $MebSea = $MebSea ['value'];
  3560. $page_size = $length;
  3561. $con = '';
  3562. if ($status == 'ALL')
  3563. $con = ' where 1 ';
  3564. elseif ($status == 'PRINTED')
  3565. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3566. elseif ($status == 'UNPRINT')
  3567. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3568. elseif ($status == 'TICKET')
  3569. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3570. if ($invoiceType == 'ORDINARY')
  3571. $con .= ' and a.invoiceType=0 ';
  3572. elseif ($invoiceType == 'SPECIAL')
  3573. $con .= ' and a.invoiceType=1 ';
  3574. $dateArr = explode ( ':', $date );
  3575. $D1 = $dateString = '';
  3576. $D2 = '';
  3577. if (! empty ( $date )) {
  3578. $D1 = $dateArr [0];
  3579. if (isset ( $dateArr [1] ))
  3580. $D2 = $dateArr [1];
  3581. else
  3582. $D2 = '';
  3583. $dateString = $D1 . " : " . $D2;
  3584. }
  3585. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3586. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3587. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3588. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3589. if (! empty ( $MebSea ))
  3590. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3591. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3592. $sql = ' ' . $con;
  3593. $limit = $page . ',' . $page_size;
  3594. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3595. $paperList = array ();
  3596. foreach ( $list as $key => $value ) {
  3597. $irDetail = array ();
  3598. if ($value ['iid'] == 0)
  3599. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3600. else
  3601. array_push ( $irDetail, '' );
  3602. array_push ( $irDetail, $value ['invoiceCode'] );
  3603. array_push ( $irDetail, $value ['invoiceNo'] );
  3604. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3605. if ($value ['invoiceType'] == 1)
  3606. array_push ( $irDetail, $value ['invoiceCompany'] );
  3607. else
  3608. array_push ( $irDetail, $value ['invoiceTitle'] );
  3609. if ($value ['invoiceType'] == 1)
  3610. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3611. else
  3612. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3613. array_push ( $irDetail, $value ['invoiceElement'] );
  3614. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3615. array_push ( $irDetail, $value ['printTime'] );
  3616. array_push ( $paperList, $irDetail );
  3617. }
  3618. // $approvalListJson = json_encode ( $approvalList );
  3619. $recordsFiltered = $invoiceTotal;
  3620. echo json_encode ( array (
  3621. "draw" => intval ( $draw ),
  3622. "recordsTotal" => intval ( $invoiceTotal ),
  3623. "recordsFiltered" => intval ( $recordsFiltered ),
  3624. "data" => $paperList
  3625. ), JSON_UNESCAPED_UNICODE );
  3626. }
  3627. function invoicePaperDel() {
  3628. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3629. $XDeode = new XDeode ( 5 );
  3630. $ipid = $XDeode->decode ( $ipidKey );
  3631. if (empty ( $ipid ))
  3632. die ( 'illegal request' );
  3633. Doo::loadModel ( 'invoicePaper' );
  3634. $invoicePaper = new invoicePaper ();
  3635. $invoicePaper->delete ( array (
  3636. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3637. 'limit' => 1
  3638. ) );
  3639. return '/invoicePaper';
  3640. }
  3641. /**
  3642. * 添加纸质发票号
  3643. */
  3644. function invoicePaperAdd() {
  3645. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3646. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3647. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3648. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3649. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3650. $sum = $invoiceNoStart + $invoiceNoTotal;
  3651. if (empty ( $sum ))
  3652. die ( 'illegal request' );
  3653. // echo $invoiceNoStart;
  3654. // echo $sum;
  3655. // echo strlen((int)$invoiceNoStart);
  3656. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3657. Doo::db ()->beginTransaction ();
  3658. // 批量存储纸质发票
  3659. $date = date ( "Y-m-d H:i:s" );
  3660. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3661. VALUES ';
  3662. $paperList = array ();
  3663. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3664. // 数字前面自加0
  3665. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3666. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3667. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3668. array_push ( $paperList, $paperSql );
  3669. }
  3670. if (empty ( $paperList ))
  3671. die ( 'illegal request' );
  3672. $sql = $sql . implode ( ',', $paperList );
  3673. Doo::db ()->query ( $sql );
  3674. Doo::db ()->commit ();
  3675. return 'invoicePaper';
  3676. }
  3677. die ( 'illegal request' );
  3678. }
  3679. /**
  3680. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3681. */
  3682. function invoiceBindReceivables() {
  3683. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3684. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3685. Doo::loadModel ( 'invoice' );
  3686. $invoice = new invoice ();
  3687. Doo::loadModel ( 'invoiceReceivables' );
  3688. $invoiceReceivables = new invoiceReceivables ();
  3689. Doo::loadModel ( 'invoiceOperationLog' );
  3690. $invoiceOperationLog = new invoiceOperationLog ();
  3691. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3692. die ( 'illegal request' );
  3693. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3694. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3695. if (empty ( $detail ) && empty ( $detailM ))
  3696. die ( 'illegal request' );
  3697. if ($detail ['untreadStatus'] == 3)
  3698. die ( 'illegal request' );
  3699. // 修改 绑定状态改为 金额
  3700. $invoiceReceivables = new invoiceReceivables ();
  3701. //有BUG-需修改
  3702. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3703. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3704. $item = array (
  3705. 'bindPrice' => $invoicePrice
  3706. );
  3707. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3708. $item = array (
  3709. 'bindPrice' => $invoicePrice,
  3710. 'bindStatus' => 1,
  3711. 'bindDate' => date ( "Y-m-d H:i:s" )
  3712. );
  3713. } else {
  3714. die ( 'illegal request' );
  3715. }
  3716. if ($detailM ['iid'] == 0) {
  3717. $item += array (
  3718. 'iid' => $detail ['iid']
  3719. );
  3720. } else {
  3721. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3722. array_push ( $iidExtend, $detail ['iid'] );
  3723. $item += array (
  3724. 'iidExtend' => implode ( ',', $iidExtend )
  3725. );
  3726. }
  3727. $titleMark = $detail ['invoiceTitle'];
  3728. if (! empty ( $detail ['invoiceCompany'] ))
  3729. $titleMark = $detail ['invoiceCompany'];
  3730. $item += array (
  3731. 'irid' => $detailM ['irid'],
  3732. 'recepitTitleMark' => $titleMark,
  3733. 'accountClerk' => $this->staff [0] ['username']
  3734. );
  3735. // 如何没有人收款 则自动绑定收款
  3736. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3737. $item += array (
  3738. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3739. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3740. );
  3741. }
  3742. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3743. $iridString = "";
  3744. if (empty ( $detail ['irid'] ))
  3745. $iridString = $detailM ['irid'];
  3746. else
  3747. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3748. $item = array (
  3749. 'iid' => $detail ['iid'],
  3750. 'irid' => $iridString
  3751. );
  3752. $invoiceReceivables = new invoiceReceivables ();
  3753. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3754. if ($detail ['invoicePrice'] <= $sum)
  3755. $item += array (
  3756. 'untreadStatus' => 3,
  3757. 'bindTime' => date ( "Y-m-d H:i:s" )
  3758. );
  3759. // print_r($item);
  3760. // echo $sum;die;
  3761. $invoice->setInvoiceByCondition ( $item );
  3762. // 操作日志
  3763. $item = array (
  3764. 'date' => date ( "Y-m-d H:i:s" ),
  3765. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3766. 'status' => 8,
  3767. 'img' => $this->staff [0] ['avatar'],
  3768. 'username' => $this->staff [0] ['username'],
  3769. 'uid' => $this->staff [0] ['sid'],
  3770. 'category' => $this->staff [0] ['category'],
  3771. 'iid' => $detail ['iid']
  3772. );
  3773. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3774. Doo::loadModel ( 'invoiceStatistics' );
  3775. $invoiceStatistics = new invoiceStatistics ();
  3776. $item = array (
  3777. 'date' => $detailM ['receivablesDate'],
  3778. 'priceClass' => 3,
  3779. 'cid' => $detail ['cid'],
  3780. 'staff' => $detail ['sid'],
  3781. 'accountPrice' => $detailM ['receivablesPrice']
  3782. );
  3783. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3784. // 公司流水记录
  3785. // Doo::loadModel ( 'wasteBook' );
  3786. // $wasteBook = new wasteBook ();
  3787. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3788. // $accountBank='';
  3789. // if ($detailM ['receivablesBank']=='纵横广发'){
  3790. // $accountBank='CGBDeposit';
  3791. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3792. // $accountBank='ICBCDeposit';
  3793. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3794. // $accountBank='HUADeposit';
  3795. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3796. // $accountBank='PersonalDeposit';
  3797. // }
  3798. // if (empty($abDetail)){
  3799. // $item = array (
  3800. // 'dataID' => $detail ['iid'],
  3801. // 'expensesType' => 1,
  3802. // 'accountType' => 8,
  3803. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3804. // 'accountPrice'=>$detail ['invoicePrice'],
  3805. // 'accountBank'=>$accountBank,
  3806. // 'category'=>$this->staff[0]['category'],
  3807. // 'cid'=>$this->staff[0]['cid'],
  3808. // 'name'=>$this->staff[0]['username'],
  3809. // 'sid'=>$this->staff[0]['sid'],
  3810. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3811. // );
  3812. // $wasteBook->setAccountBookStatistics($item);
  3813. // }
  3814. return "/invoiceReceivables";
  3815. }
  3816. /**
  3817. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3818. */
  3819. function invoiceAggregate() {
  3820. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3821. Doo::loadModel ( 'invoiceStatistics' );
  3822. $invoiceStatistics = new invoiceStatistics ();
  3823. Doo::loadModel ( 'L_category' );
  3824. $Lcategory = new L_category ();
  3825. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3826. $LcategoryList = $Lcategory->getCategory ();
  3827. // print_r($isList);
  3828. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3829. foreach ( $LcategoryList as $key => $value ) {
  3830. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3831. $month = 1;
  3832. $invoicePriceYear = 0;
  3833. $receivablesPriceYear = 0;
  3834. $accountPriceYear = 0;
  3835. for(; $month <= 12; $month ++) {
  3836. $flag = true;
  3837. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3838. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3839. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3840. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3841. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3842. ';
  3843. $invoicePriceYear += $v ['invoicePrice'];
  3844. $receivablesPriceYear += $v ['receivablesPrice'];
  3845. $accountPriceYear += $v ['accountPrice'];
  3846. $flag = false;
  3847. break;
  3848. }
  3849. }
  3850. if ($flag)
  3851. $html .= '<td class="taR"></td>
  3852. <td class="taR"></td>
  3853. <td class="taR"><b></b></td>
  3854. ';
  3855. }
  3856. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3857. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3858. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3859. ';
  3860. $html .= '</tr>';
  3861. }
  3862. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3863. $invoicePriceYear = 0;
  3864. $receivablesPriceYear = 0;
  3865. $accountPriceYear = 0;
  3866. for($month = 1; $month <= 12; $month ++) {
  3867. $flag = true;
  3868. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3869. if ($month == $v ['month']) {
  3870. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3871. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3872. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3873. ';
  3874. $invoicePriceYear += $v ['invoicePrice'];
  3875. $receivablesPriceYear += $v ['receivablesPrice'];
  3876. $accountPriceYear += $v ['accountPrice'];
  3877. $flag = false;
  3878. break;
  3879. }
  3880. }
  3881. if ($flag) {
  3882. $html .= '<td class="taR"></td>
  3883. <td class="taR"></td>
  3884. <td class="taR"><b></b></td>
  3885. ';
  3886. }
  3887. }
  3888. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3889. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3890. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3891. ';
  3892. $html .= '</tr>';
  3893. // print_r($isList);
  3894. $this->data ['html'] = $html;
  3895. $this->data ['LcategoryList'] = $LcategoryList;
  3896. $this->data ['isList'] = $isList;
  3897. $this->data ['year'] = $year;
  3898. $this->data ['memu'] = "invoice";
  3899. $this->data ['staff'] = $this->staff;
  3900. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3901. $this->render ( "/admin/invoiceAggregate", $this->data );
  3902. }
  3903. function invoiceAggregateStaff() {
  3904. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3905. Doo::loadModel ( 'invoiceStatistics' );
  3906. $invoiceStatistics = new invoiceStatistics ();
  3907. Doo::loadModel ( 'L_category' );
  3908. $Lcategory = new L_category ();
  3909. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3910. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3911. $cStaff = $Lcategory->getCategoryStaff ();
  3912. $html = '';
  3913. foreach ( $cStaff as $key => $value ) {
  3914. $categoryFir = true;
  3915. foreach ( $value ['staff'] as $k => $v ) {
  3916. if ($categoryFir) {
  3917. $width = count ( $value ['staff'] ) + 1;
  3918. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3919. $categoryFir = false;
  3920. } else
  3921. $html .= '<tr>';
  3922. $html .= '<th>' . $v ['username'] . '</th>';
  3923. $invoicePriceStaffYear = 0;
  3924. $receivablesPriceStaffYear = 0;
  3925. $accountPriceStaffYear = 0;
  3926. for($month = 1; $month <= 12; $month ++) {
  3927. $flag = true;
  3928. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3929. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3930. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3931. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3932. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3933. ';
  3934. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3935. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3936. $accountPriceStaffYear += $slv ['accountPrice'];
  3937. $flag = false;
  3938. break;
  3939. }
  3940. }
  3941. if ($flag)
  3942. $html .= '<td class="taR"></td>
  3943. <td class="taR"></td>
  3944. <td class="taR"><b></b></td>
  3945. ';
  3946. }
  3947. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3948. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3949. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3950. ';
  3951. }
  3952. $html .= '</tr>';
  3953. // 小计
  3954. if (! empty ( $value ['staff'] )) {
  3955. $html .= '<tr><th class="taR">小计</th>';
  3956. $invoicePriceStaffYear = 0;
  3957. $receivablesPriceStaffYear = 0;
  3958. $accountPriceStaffYear = 0;
  3959. for($month = 1; $month <= 12; $month ++) {
  3960. $flag = true;
  3961. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3962. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3963. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3964. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3965. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3966. ';
  3967. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3968. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3969. $accountPriceStaffYear += $slv ['accountPrice'];
  3970. $flag = false;
  3971. break;
  3972. }
  3973. }
  3974. if ($flag)
  3975. $html .= '<td class="taR"></td>
  3976. <td class="taR"></td>
  3977. <td class="taR"><b></b></td>
  3978. ';
  3979. }
  3980. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3981. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3982. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3983. ';
  3984. $html .= '</tr>';
  3985. }
  3986. }
  3987. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3988. $invoicePriceYear = 0;
  3989. $receivablesPriceYear = 0;
  3990. $accountPriceYear = 0;
  3991. for($month = 1; $month <= 12; $month ++) {
  3992. $flag = true;
  3993. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3994. if ($month == $v ['month']) {
  3995. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3996. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3997. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3998. ';
  3999. $invoicePriceYear += $v ['invoicePrice'];
  4000. $receivablesPriceYear += $v ['receivablesPrice'];
  4001. $accountPriceYear += $v ['accountPrice'];
  4002. $flag = false;
  4003. break;
  4004. }
  4005. }
  4006. if ($flag)
  4007. $html .= '<td class="taR"></td>
  4008. <td class="taR"></td>
  4009. <td class="taR"><b></b></td>
  4010. ';
  4011. }
  4012. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4013. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4014. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4015. ';
  4016. $html .= '</tr>';
  4017. $this->data ['html'] = $html;
  4018. $this->data ['isList'] = $toteList;
  4019. $this->data ['year'] = $year;
  4020. $this->data ['memu'] = "invoice";
  4021. $this->data ['staff'] = $this->staff;
  4022. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4023. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4024. }
  4025. function invoiceAggregateCategory() {
  4026. Doo::loadClass ( 'XDeode' );
  4027. $XDeode = new XDeode ( 5 );
  4028. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4029. $cid = $XDeode->decode ( $cid );
  4030. if (! is_numeric ( $cid ))
  4031. die ( 'illegal request' );
  4032. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4033. Doo::loadModel ( 'invoiceStatistics' );
  4034. $invoiceStatistics = new invoiceStatistics ();
  4035. Doo::loadModel ( 'staff' );
  4036. $staff = new staff ();
  4037. $list = $staff->getStaffByCid ( $cid );
  4038. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4039. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4040. if (empty ( $list ))
  4041. die ( '该办事处没有成员' );
  4042. $htmlA = $htmlB = $htmlC = $html = '';
  4043. foreach ( $list as $key => $value ) {
  4044. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4045. $htmlB = '<tr><th class="taC">收款</th>';
  4046. $htmlC = '<tr><th class="taC">入账</th>';
  4047. $invoicePriceStaffYear = 0;
  4048. $receivablesPriceStaffYear = 0;
  4049. $accountPriceStaffYear = 0;
  4050. for($month = 1; $month <= 12; $month ++) {
  4051. $flag = true;
  4052. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4053. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4054. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4055. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4056. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4057. $invoicePriceStaffYear += $v ['invoicePrice'];
  4058. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4059. $accountPriceStaffYear += $v ['accountPrice'];
  4060. $flag = false;
  4061. break;
  4062. }
  4063. }
  4064. if ($flag) {
  4065. $htmlA .= '<td class="taR">-</td>';
  4066. $htmlB .= '<td class="taR">-</td>';
  4067. $htmlC .= '<td class="taR"><b>-</b></td>';
  4068. }
  4069. }
  4070. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4071. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4072. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4073. $htmlA .= '</tr>';
  4074. $htmlB .= '</tr>';
  4075. $htmlC .= '</tr>';
  4076. $html .= $htmlA . $htmlB . $htmlC;
  4077. }
  4078. $htmlA = $htmlB = $htmlC = "";
  4079. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4080. $htmlB = '<tr><th class="taC">收款</th>';
  4081. $htmlC = '<tr><th class="taC">入账</th>';
  4082. $invoicePriceStaffYear = 0;
  4083. $receivablesPriceStaffYear = 0;
  4084. $accountPriceStaffYear = 0;
  4085. for($month = 1; $month <= 12; $month ++) {
  4086. $flag = true;
  4087. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4088. if ($month == $v ['month']) {
  4089. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4090. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4091. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4092. $invoicePriceStaffYear += $v ['invoicePrice'];
  4093. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4094. $accountPriceStaffYear += $v ['accountPrice'];
  4095. $flag = false;
  4096. break;
  4097. }
  4098. }
  4099. if ($flag) {
  4100. $htmlA .= '<td class="taR">-</td>';
  4101. $htmlB .= '<td class="taR">-</td>';
  4102. $htmlC .= '<td class="taR"><b>-</b></td>';
  4103. }
  4104. }
  4105. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4106. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4107. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4108. $htmlA .= '</tr>';
  4109. $htmlB .= '</tr>';
  4110. $htmlC .= '</tr>';
  4111. $html .= $htmlA . $htmlB . $htmlC;
  4112. $this->data ['html'] = $html;
  4113. $this->data ['cidKey'] = $cidKey;
  4114. $this->data ['slist'] = $list;
  4115. $this->data ['isList'] = $toteList;
  4116. $this->data ['year'] = $year;
  4117. $this->data ['memu'] = "invoice";
  4118. $this->data ['staff'] = $this->staff;
  4119. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4120. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4121. }
  4122. /**
  4123. * 办事处汇总信息
  4124. */
  4125. function invoiceAggregateCategoryDetail() {
  4126. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4127. Doo::loadClass ( 'XDeode' );
  4128. $XDeode = new XDeode ( 5 );
  4129. Doo::loadModel ( 'invoiceStatistics' );
  4130. $invoiceStatistics = new invoiceStatistics ();
  4131. Doo::loadModel ( 'L_category' );
  4132. $category = new L_category ();
  4133. Doo::loadModel ( 'invoice' );
  4134. $invoice = new invoice ();
  4135. Doo::loadModel ( 'staff' );
  4136. $staff = new staff ();
  4137. Doo::loadModel ( "invoiceCategoryManage" );
  4138. $invoiceCategoryManage = new invoiceCategoryManage ();
  4139. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4140. $cidList = array ();
  4141. foreach ( $imcStaff as $key => $value ) {
  4142. array_push ( $cidList, $value ['cid'] );
  4143. if (empty ( $cidKey ))
  4144. $cidKey = $XDeode->encode ( $value ['cid'] );
  4145. }
  4146. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4147. $cid = $XDeode->decode ( $cidKey );
  4148. $month = date ( "m", strtotime ( "-1 month" ) );
  4149. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4150. $redis = new Redis ();
  4151. $redis->connect ( '127.0.0.1', '6379' );
  4152. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4153. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4154. if (empty ( $redisValue )) {
  4155. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4156. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4157. // 获得办事处人员下的汇总
  4158. $slist = $staff->getStaffByCid ( $cid );
  4159. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4160. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4161. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4162. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4163. foreach ( $slist as $key => $value ) {
  4164. $slist [$key] ['invoicePrice'] = 0;
  4165. $slist [$key] ['receivablesPrice'] = 0;
  4166. $slist [$key] ['accountPrice'] = 0;
  4167. $slist [$key] ['invoiceAllPrice'] = 0;
  4168. $slist [$key] ['receivablesAllPrice'] = 0;
  4169. $slist [$key] ['accountAllPrice'] = 0;
  4170. $slist [$key] ['schedule'] = 0;
  4171. $slist [$key] ['invoiceMonthPrice'] = 0;
  4172. $slist [$key] ['receivablesMonthPrice'] = 0;
  4173. $slist [$key] ['accountMonthPrice'] = 0;
  4174. foreach ( $ismsbMonth as $y => $l ) {
  4175. if ($value ['sid'] == $l ['staff']) {
  4176. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4177. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4178. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4179. }
  4180. }
  4181. foreach ( $ismsb as $k => $v ) {
  4182. if ($value ['sid'] == $v ['staff']) {
  4183. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4184. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4185. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4186. }
  4187. }
  4188. foreach ( $ISAS as $e => $a ) {
  4189. if ($value ['sid'] == $a ['staff']) {
  4190. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4191. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4192. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4193. }
  4194. }
  4195. if (isset ( $scheduleStaff [$value ['sid']] ))
  4196. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4197. }
  4198. $this->data ['cidKey'] = $cidKey;
  4199. $schedule = ( int ) ($schedule * 100);
  4200. $this->data ['slist'] = $slist;
  4201. $this->data ['isMC'] = $isMC;
  4202. $this->data ['schedule'] = $schedule;
  4203. $slist = json_encode ( $slist );
  4204. $isMC = json_encode ( $isMC );
  4205. $schedule = json_encode ( $schedule );
  4206. $redis->lpush ( $redisKey, $slist );
  4207. $redis->lpush ( $redisKey, $isMC );
  4208. $redis->lpush ( $redisKey, $schedule );
  4209. } else {
  4210. $this->data ['cidKey'] = $cidKey;
  4211. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4212. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4213. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4214. }
  4215. $this->data ['month'] = $month;
  4216. $this->data ['categoryList'] = $categoryList;
  4217. $this->data ['memu'] = "invoice";
  4218. $this->data ['staff'] = $this->staff;
  4219. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4220. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4221. }
  4222. /**
  4223. * 办事处人员汇总详情
  4224. */
  4225. function invoiceAggregateStaffDetail() {
  4226. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4227. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4228. Doo::loadClass ( 'XDeode' );
  4229. $XDeode = new XDeode ( 5 );
  4230. Doo::loadModel ( 'invoice' );
  4231. $invoice = new invoice ();
  4232. Doo::loadModel ( 'staff' );
  4233. $staff = new staff ();
  4234. Doo::loadModel ( "invoiceCategoryManage" );
  4235. $invoiceCategoryManage = new invoiceCategoryManage ();
  4236. $sid = $XDeode->decode ( $sidKey );
  4237. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4238. $cidList = array ();
  4239. foreach ( $imcStaff as $key => $value ) {
  4240. array_push ( $cidList, $value ['cid'] );
  4241. if (empty ( $cidKey ))
  4242. $cidKey = $XDeode->encode ( $value ['cid'] );
  4243. }
  4244. $cidString = implode ( ',', $cidList );
  4245. $staffList = $staff->getStaffInCid ( $cidString );
  4246. $staffDetail = $staff->getStaffBySid ( $sid );
  4247. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4248. $page_size = 18;
  4249. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4250. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4251. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4252. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4253. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4254. $dateArr = explode ( ':', $date );
  4255. $D1 = '';
  4256. $D2 = '';
  4257. if (! empty ( $date )) {
  4258. $D1 = $dateArr [0] . " 00:00:00 ";
  4259. if (isset ( $dateArr [1] ))
  4260. $D2 = $dateArr [1] . " 23:59:59 ";
  4261. else
  4262. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4263. // $D2 = $dateArr [1];
  4264. }
  4265. $con = ' status=2 ';
  4266. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4267. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4268. if ($status == 'UNRECORD')
  4269. $con .= ' and printStatus=1 and untreadStatus=0';
  4270. elseif ($status == 'RECORD')
  4271. $con .= ' and printStatus=1 and untreadStatus=3';
  4272. elseif ($status == 'BOUNCED')
  4273. $con .= ' and untreadStatus=2';
  4274. elseif ($status == 'PARTRECORD')
  4275. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4276. elseif ($status == 'All') {
  4277. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4278. }
  4279. $con .= ' and sid=' . $sid;
  4280. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4281. if (! empty ( $MebSea )) {
  4282. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4283. }
  4284. $pageinfo ['page'] = array (
  4285. 'previous' => ''
  4286. );
  4287. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4288. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4289. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4290. $this->data ['staffDetail'] = $staffDetail;
  4291. $this->data ['staffList'] = $staffList;
  4292. $this->data ['MebSeaEn'] = $MebSea;
  4293. $this->data ['MebSea'] = urlencode ( $MebSea );
  4294. $this->data ['date'] = $date;
  4295. $this->data ['page'] = $pageinfo;
  4296. $this->data ['get'] = $get;
  4297. $this->data ['list'] = $list;
  4298. $this->data ['status'] = $status;
  4299. $this->data ['sidKey'] = $sidKey;
  4300. $this->data ['memu'] = "invoice";
  4301. $this->data ['staff'] = $this->staff;
  4302. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4303. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4304. }
  4305. /**
  4306. * 办事处人员汇总收款情
  4307. */
  4308. function invoiceAggregateStaffReceivablesDetail() {
  4309. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4310. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4311. Doo::loadModel ( 'invoiceReceivables' );
  4312. $invoiceReceivables = new invoiceReceivables ();
  4313. Doo::loadModel ( 'staff' );
  4314. $staff = new staff ();
  4315. Doo::loadModel ( "invoiceCategoryManage" );
  4316. $invoiceCategoryManage = new invoiceCategoryManage ();
  4317. Doo::loadClass ( 'XDeode' );
  4318. $XDeode = new XDeode ( 5 );
  4319. $sid = $XDeode->decode ( $sidKey );
  4320. $staffDetail = $staff->getStaffBySid ( $sid );
  4321. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4322. $cidList = array ();
  4323. foreach ( $imcStaff as $key => $value ) {
  4324. array_push ( $cidList, $value ['cid'] );
  4325. if (empty ( $cidKey ))
  4326. $cidKey = $XDeode->encode ( $value ['cid'] );
  4327. }
  4328. $cidString = implode ( ',', $cidList );
  4329. $staffList = $staff->getStaffInCid ( $cidString );
  4330. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4331. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4332. $page_size = 10;
  4333. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4334. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4335. if ($timeType == "BINDOTP") {
  4336. $status = 'Credited';
  4337. }
  4338. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4339. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4340. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4341. $dateArr = explode ( ':', $date );
  4342. $D1 = '';
  4343. $D2 = '';
  4344. if (! empty ( $date )) {
  4345. $D1 = $dateArr [0] . " 00:00:00 ";
  4346. if (isset ( $dateArr [1] ))
  4347. $D2 = $dateArr [1] . " 23:59:59 ";
  4348. else
  4349. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4350. }
  4351. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4352. $descField = 'a.bindDate';
  4353. if ($timeType == 'CREATE')
  4354. $descField = 'a.date';
  4355. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4356. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4357. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4358. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4359. if ($status == 'Unclaimed')
  4360. $con .= ' and a.bindStatus=0';
  4361. elseif ($status == 'Credited')
  4362. $con .= ' and a.bindStatus=1';
  4363. elseif ($status == 'Claim')
  4364. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4365. elseif ($status == 'BBN')
  4366. $con .= ' and a.bindPrice>a.receivablesPrice';
  4367. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4368. if (! empty ( $MebSea )) {
  4369. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4370. }
  4371. $pageinfo ['page'] = array (
  4372. 'previous' => ''
  4373. );
  4374. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4375. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4376. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4377. // where ' . $con . ' group by a.irid ';
  4378. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4379. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4380. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4381. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'a.bindTime' );
  4382. foreach ( $list as $key => $value ) {
  4383. $list [$key] ['category'] = '';
  4384. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4385. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4386. $list [$key] ['category'] = $receivablesCategory [1];
  4387. }
  4388. }
  4389. // print_r($list);
  4390. $this->data ['staffDetail'] = $staffDetail;
  4391. $this->data ['sidKey'] = $sidKey;
  4392. $this->data ['staffList'] = $staffList;
  4393. $this->data ['timeType'] = $timeType;
  4394. $this->data ['MebSeaEn'] = $MebSea;
  4395. $this->data ['MebSea'] = urlencode ( $MebSea );
  4396. $this->data ['date'] = $date;
  4397. $this->data ['page'] = $pageinfo;
  4398. $this->data ['get'] = $get;
  4399. $this->data ['list'] = $list;
  4400. $this->data ['status'] = $status;
  4401. $this->data ['memu'] = "invoice";
  4402. $this->data ['staff'] = $this->staff;
  4403. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4404. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4405. }
  4406. function invoiceAchieve() {
  4407. Doo::loadModel ( 'invoice' );
  4408. $invoice = new invoice ();
  4409. Doo::loadClass ( 'XDeode' );
  4410. $XDeode = new XDeode ( 5 );
  4411. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4412. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4413. $page_size = 18;
  4414. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4415. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4416. $get = "/" . $date;
  4417. $con = '';
  4418. if ($date == 'MONTHO')
  4419. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4420. elseif ($date == 'MONTHT')
  4421. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4422. elseif ($date == 'MONTHY')
  4423. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4424. if (! empty ( $MebSea )) {
  4425. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4426. $get .= "/" . $MebSea;
  4427. }
  4428. $pageinfo ['page'] = array (
  4429. 'previous' => ''
  4430. );
  4431. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4432. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4433. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4434. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4435. // print_r($pageinfo);
  4436. $this->data ['MebSeaEn'] = $MebSea;
  4437. $this->data ['MebSea'] = urlencode ( $MebSea );
  4438. $this->data ['get'] = $get;
  4439. $this->data ['page'] = $pageinfo;
  4440. $this->data ['list'] = $list;
  4441. $this->data ['date'] = $date;
  4442. $this->data ['memu'] = "invoice";
  4443. $this->data ['staff'] = $this->staff;
  4444. $this->data ['receiptMemu'] = 'invoice';
  4445. $this->render ( "/admin/invoiceAchieve", $this->data );
  4446. }
  4447. /**
  4448. */
  4449. function invoiceMyUnAccountAchieve() {
  4450. Doo::loadModel ( 'invoice' );
  4451. $invoice = new invoice ();
  4452. Doo::loadClass ( 'XDeode' );
  4453. $XDeode = new XDeode ( 5 );
  4454. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4455. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4456. $page_size = 18;
  4457. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4458. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4459. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4460. $dateArr = explode ( ':', $date );
  4461. $D1 = '';
  4462. $D2 = '';
  4463. if (! empty ( $date )) {
  4464. $D1 = $dateArr [0];
  4465. $D2 = $dateArr [1];
  4466. }
  4467. $con = '';
  4468. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4469. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4470. if (! empty ( $MebSea )) {
  4471. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4472. }
  4473. $pageinfo ['page'] = array (
  4474. 'previous' => ''
  4475. );
  4476. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4477. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4478. $action = "invoiceMyUnAccountAchieve";
  4479. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4480. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4481. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4482. Doo::loadModel ( 'express' );
  4483. $express = new express ();
  4484. $expressList = $express->getExpressByAll ();
  4485. $this->data ['expressList'] = $expressList;
  4486. // print_r($list);
  4487. $this->data ['MebSeaEn'] = $MebSea;
  4488. $this->data ['get'] = $get;
  4489. $this->data ['page'] = $pageinfo;
  4490. $this->data ['date'] = $date;
  4491. $this->data ['list'] = $list;
  4492. $this->data ['memu'] = "invoice";
  4493. $this->data ['staff'] = $this->staff;
  4494. $this->data ['receiptMemu'] = 'invoice';
  4495. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4496. }
  4497. function invoiceReceivablesAchieve() {
  4498. Doo::loadModel ( 'invoiceReceivables' );
  4499. $invoiceReceivables = new invoiceReceivables ();
  4500. Doo::loadClass ( 'XDeode' );
  4501. $XDeode = new XDeode ( 5 );
  4502. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4503. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4504. $page_size = 12;
  4505. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4506. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4507. $get = "/" . $date;
  4508. $con = '';
  4509. if ($date == 'MONTHO')
  4510. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4511. elseif ($date == 'MONTHT')
  4512. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4513. elseif ($date == 'MONTHY')
  4514. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4515. if (! empty ( $MebSea )) {
  4516. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4517. $get .= "/" . $MebSea;
  4518. }
  4519. $pageinfo ['page'] = array (
  4520. 'previous' => ''
  4521. );
  4522. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4523. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4524. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4525. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4526. // print_r($pageinfo);
  4527. $this->data ['MebSeaEn'] = $MebSea;
  4528. $this->data ['MebSea'] = urlencode ( $MebSea );
  4529. $this->data ['get'] = $get;
  4530. $this->data ['page'] = $pageinfo;
  4531. $this->data ['list'] = $list;
  4532. $this->data ['date'] = $date;
  4533. $this->data ['memu'] = "invoice";
  4534. $this->data ['staff'] = $this->staff;
  4535. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4536. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4537. }
  4538. /**
  4539. * 收款解绑
  4540. */
  4541. function invoiceUnBundLing() {
  4542. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4543. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4544. Doo::loadModel ( 'invoice' );
  4545. $invoice = new invoice ();
  4546. Doo::loadModel ( 'invoiceReceivables' );
  4547. $invoiceReceivables = new invoiceReceivables ();
  4548. Doo::loadModel ( 'invoiceOperationLog' );
  4549. $invoiceOperationLog = new invoiceOperationLog ();
  4550. Doo::loadModel ( 'invoiceROLog' );
  4551. $invoiceROLog = new invoiceROLog ();
  4552. Doo::loadModel ( 'invoiceStatistics' );
  4553. Doo::loadClass ( 'XDeode' );
  4554. $XDeode = new XDeode ( 5 );
  4555. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4556. die ( 'illegal request' );
  4557. $iid = $XDeode->decode ( $iidKey );
  4558. $irid = $invoice->authcode ( $unBundKey );
  4559. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4560. die ( 'illegal request' );
  4561. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4562. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4563. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4564. die ( 'illegal request' );
  4565. // 收款
  4566. $item = array (
  4567. 'irid' => $irDetails ['irid'],
  4568. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4569. 'bindStatus' => 0
  4570. );
  4571. if ($irDetails ['iid'] == $iid)
  4572. $item += array (
  4573. 'iid' => 0
  4574. );
  4575. else {
  4576. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4577. foreach ( $iidExtend as $key => $value ) {
  4578. if ($value == $iid)
  4579. unset ( $iidExtend [$key] );
  4580. }
  4581. $iidExtend = implode ( ',', $iidExtend );
  4582. $item += array (
  4583. 'iidExtend' => $iidExtend
  4584. );
  4585. }
  4586. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4587. // 收款操作日志
  4588. $item = array (
  4589. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4590. 'date' => date ( "Y-m-d" ),
  4591. 'status' => 3,
  4592. 'img' => $this->staff [0] ['avatar'],
  4593. 'username' => $this->staff [0] ['username'],
  4594. 'uid' => $this->staff [0] ['sid'],
  4595. 'category' => $this->staff [0] ['category'],
  4596. 'irid' => $irid
  4597. );
  4598. $invoiceROLog->setInvoiceROLog ( $item );
  4599. // 扣除入账统计金额
  4600. $invoiceStatistics = new invoiceStatistics ();
  4601. $item = array (
  4602. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4603. 'priceClass' => 3,
  4604. 'cid' => $invoiceDetails ['cid'],
  4605. 'staff' => $invoiceDetails ['sid'],
  4606. 'accountPrice' => - $irDetails ['receivablesPrice']
  4607. );
  4608. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4609. // 扣除收款统计金额
  4610. $invoiceStatistics = new invoiceStatistics ();
  4611. $item = array (
  4612. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4613. 'priceClass' => 2,
  4614. 'cid' => $invoiceDetails ['cid'],
  4615. 'staff' => $invoiceDetails ['sid'],
  4616. 'irid' => $irDetails ['irid'],
  4617. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4618. );
  4619. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4620. // 发票解绑去收款ID
  4621. $iridString = $invoiceDetails ['irid'];
  4622. if (! empty ( $invoiceDetails ['irid'] )) {
  4623. $list = explode ( ',', $invoiceDetails ['irid'] );
  4624. foreach ( $list as $key => $value ) {
  4625. if ($value == $irDetails ['irid']) {
  4626. unset ( $list [$key] );
  4627. break;
  4628. }
  4629. }
  4630. $iridString = implode ( ",", $list );
  4631. }
  4632. $item = array (
  4633. 'iid' => $invoiceDetails ['iid'],
  4634. 'irid' => $iridString,
  4635. 'updateTime' => date ( "Y-m-d H:i:s" )
  4636. );
  4637. if ($invoiceDetails ['untreadStatus'] == 3)
  4638. $item += array (
  4639. 'untreadStatus' => 0
  4640. );
  4641. $invoice->setInvoiceByCondition ( $item );
  4642. $item = array (
  4643. 'date' => date ( "Y-m-d H:i:s" ),
  4644. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4645. 'status' => 11,
  4646. 'img' => $this->staff [0] ['avatar'],
  4647. 'username' => $this->staff [0] ['username'],
  4648. 'uid' => $this->staff [0] ['sid'],
  4649. 'category' => $this->staff [0] ['category'],
  4650. 'iid' => $invoiceDetails ['iid']
  4651. );
  4652. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4653. // 公司流水-解绑时删除流水
  4654. Doo::loadModel ( 'wasteBook' );
  4655. $wasteBook = new wasteBook ();
  4656. // $wasteBook->delete ( array (
  4657. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4658. // 'limit' => 1
  4659. // ) );
  4660. // 银行
  4661. /*
  4662. * $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); }
  4663. */
  4664. return "/invoiceReceivablesAS";
  4665. }
  4666. /**
  4667. * 或者该收款下的所以发票
  4668. */
  4669. function ajaxGetInvoiceReceivablesByInvoice() {
  4670. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4671. Doo::loadModel ( 'invoice' );
  4672. $invoice = new invoice ();
  4673. Doo::loadModel ( 'invoiceReceivables' );
  4674. $invoiceReceivables = new invoiceReceivables ();
  4675. $irid = $invoice->authcode ( $irid );
  4676. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4677. die ( 'illegal request' );
  4678. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4679. $iidString = $irDetails ['iid'];
  4680. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4681. if (! empty ( $irDetails ['iidExtend'] ))
  4682. $iidString .= ',' . implode ( ',', $iidExtend );
  4683. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4684. $html = "";
  4685. foreach ( $invoiceList as $key => $value ) {
  4686. $title = $value ['invoiceTitle'];
  4687. if (! empty ( $value ['invoiceCompany'] ))
  4688. $title = $value ['invoiceCompany'];
  4689. $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>';
  4690. }
  4691. echo json_encode ( array (
  4692. 'status' => 1,
  4693. 'html' => $html
  4694. ) );
  4695. }
  4696. /**
  4697. * 发票管理
  4698. */
  4699. function invoiceAS() {
  4700. Doo::loadModel ( 'invoice' );
  4701. $invoice = new invoice ();
  4702. Doo::loadModel ( 'invoiceReceivables' );
  4703. $invoiceReceivables = new invoiceReceivables ();
  4704. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4705. $page_size = 18;
  4706. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4707. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4708. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4709. $dateArr = explode ( ':', $date );
  4710. $D1 = '';
  4711. $D2 = '';
  4712. if (! empty ( $date )) {
  4713. $D1 = $dateArr [0] . " 00:00:00 ";
  4714. if (isset ( $dateArr [1] ))
  4715. $D2 = $dateArr [1] . " 23:59:59 ";
  4716. else
  4717. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4718. // $D2 = $dateArr [1];
  4719. }
  4720. $con = ' status=2 ';
  4721. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4722. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4723. if ($status == 'UNRECORD')
  4724. $con .= ' and printStatus=1 and untreadStatus=0';
  4725. elseif ($status == 'RECORD')
  4726. $con .= ' and printStatus=1 and untreadStatus=3';
  4727. elseif ($status == 'BOUNCED')
  4728. $con .= ' and untreadStatus=2';
  4729. elseif ($status == 'PARTRECORD')
  4730. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4731. elseif ($status == 'All') {
  4732. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4733. }
  4734. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4735. if (! empty ( $MebSea )) {
  4736. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4737. }
  4738. $pageinfo ['page'] = array (
  4739. 'previous' => ''
  4740. );
  4741. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4742. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4743. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4744. $this->data ['MebSeaEn'] = $MebSea;
  4745. $this->data ['MebSea'] = urlencode ( $MebSea );
  4746. $this->data ['date'] = $date;
  4747. $this->data ['page'] = $pageinfo;
  4748. $this->data ['get'] = $get;
  4749. $this->data ['list'] = $list;
  4750. $this->data ['status'] = $status;
  4751. $this->data ['memu'] = "invoice";
  4752. $this->data ['staff'] = $this->staff;
  4753. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4754. $this->render ( "/admin/invoiceAS", $this->data );
  4755. }
  4756. /**
  4757. * 收款管理
  4758. */
  4759. function invoiceReceivablesAS() {
  4760. Doo::loadModel ( 'invoiceReceivables' );
  4761. $invoiceReceivables = new invoiceReceivables ();
  4762. Doo::loadModel ( 'L_category' );
  4763. $lCategory = new L_category ();
  4764. $category = $lCategory->getCategory ();
  4765. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4766. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4767. $page_size = 10;
  4768. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4769. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4770. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4771. $dateArr = explode ( ':', $date );
  4772. $D1 = '';
  4773. $D2 = '';
  4774. if (! empty ( $date )) {
  4775. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4776. if (isset ( $dateArr [1] ))
  4777. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4778. else
  4779. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4780. }
  4781. $descField = 'a.receivablesDate';
  4782. if ($timeType == 'CREATE')
  4783. $descField = 'a.date';
  4784. $con = ' 1 ';
  4785. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4786. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4787. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4788. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4789. if ($status == 'Unclaimed')
  4790. $con .= ' and a.bindStatus=0';
  4791. elseif ($status == 'Credited')
  4792. $con .= ' and a.bindStatus=1';
  4793. elseif ($status == 'Claim')
  4794. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4795. elseif ($status == 'BBN')
  4796. $con .= ' and a.bankBatchNumber!=""';
  4797. elseif ($status == 'REFUND')
  4798. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4799. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4800. if (! empty ( $MebSea )) {
  4801. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4802. }
  4803. $pageinfo ['page'] = array (
  4804. 'previous' => ''
  4805. );
  4806. // if(!empty($con)){
  4807. // $con=' where 1 '.$con;
  4808. // }
  4809. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  4810. // ' . $con ;
  4811. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4812. //echo $sql;
  4813. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4814. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4815. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4816. foreach ( $list as $key => $value ) {
  4817. $list [$key] ['category'] = '';
  4818. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4819. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4820. $list [$key] ['category'] = $receivablesCategory [1];
  4821. }
  4822. }
  4823. // print_r($list);
  4824. $this->data ['category'] = $category;
  4825. $this->data ['timeType'] = $timeType;
  4826. $this->data ['MebSeaEn'] = $MebSea;
  4827. $this->data ['MebSea'] = urlencode ( $MebSea );
  4828. $this->data ['date'] = $date;
  4829. $this->data ['page'] = $pageinfo;
  4830. $this->data ['get'] = $get;
  4831. $this->data ['list'] = $list;
  4832. $this->data ['status'] = $status;
  4833. $this->data ['memu'] = "invoice";
  4834. $this->data ['staff'] = $this->staff;
  4835. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4836. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4837. }
  4838. /**
  4839. * 删除一条收款
  4840. */
  4841. function delInvoiceReceivables() {
  4842. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4843. if (empty ( $iridKey ))
  4844. die ( 'illegal request' );
  4845. Doo::loadClass ( 'XDeode' );
  4846. $XDeode = new XDeode ( 5 );
  4847. $irid = $XDeode->decode ( $iridKey );
  4848. Doo::loadModel ( 'invoiceReceivables' );
  4849. $invoiceReceivables = new invoiceReceivables ();
  4850. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4851. if (empty ( $detail ))
  4852. die ( 'illegal request' );
  4853. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4854. // 扣除收款汇总信息 汇总
  4855. Doo::loadModel ( 'invoiceStatistics' );
  4856. $invoiceStatistics = new invoiceStatistics ();
  4857. $item = array (
  4858. 'date' => $detail ['receivablesDate'],
  4859. 'priceClass' => 2,
  4860. 'irid' => $detail ['irid'],
  4861. 'receivablesPrice' => - $detail ['receivablesPrice']
  4862. );
  4863. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4864. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4865. $item += array (
  4866. 'cid' => $receivablesCategory [0]
  4867. );
  4868. }
  4869. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4870. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4871. $item += array (
  4872. 'staff' => $receivablesStaff [0]
  4873. );
  4874. }
  4875. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4876. return '/invoiceReceivablesAS';
  4877. }
  4878. /**
  4879. * 添加退款信息
  4880. */
  4881. function setInvoiceReceivablesRefund() {
  4882. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4883. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4884. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4885. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4886. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4887. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4888. if ($refundPrice < 0)
  4889. die ( 'illegal request' );
  4890. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4891. Doo::loadModel ( 'invoiceReceivables' );
  4892. $invoiceReceivables = new invoiceReceivables ();
  4893. Doo::loadModel ( 'invoiceRefund' );
  4894. $invoiceRefund = new invoiceRefund ();
  4895. $irid = $invoiceReceivables->authcode ( $iridKey );
  4896. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4897. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4898. die ( 'illegal request' );
  4899. $invoiceReceivables = new invoiceReceivables ();
  4900. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4901. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4902. ';
  4903. $item = array (
  4904. 'irid' => $irid,
  4905. 'refundCompany' => $refundCompany,
  4906. 'refundNumber' => $refundNumber,
  4907. 'refundPrice' => $refundPrice,
  4908. 'refundRemarks' => $refundRemarks,
  4909. 'refundLog' => $refundLog
  4910. );
  4911. if ($refundType == 1) {
  4912. $item += array (
  4913. 'refundType' => $refundType,
  4914. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4915. 'bindStatus' => 2
  4916. );
  4917. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4918. $item += array (
  4919. 'refundType' => 1,
  4920. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4921. 'bindStatus' => 2
  4922. );
  4923. } else {
  4924. $item += array (
  4925. 'refundType' => $refundType,
  4926. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4927. );
  4928. }
  4929. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4930. // 添加退款记录
  4931. $item = array (
  4932. 'irid' => $irid,
  4933. 'refundType' => $refundType,
  4934. 'refundCompany' => $refundCompany,
  4935. 'refundNumber' => $refundNumber,
  4936. 'refundPrice' => $refundPrice,
  4937. 'refundLog' => $refundLog,
  4938. 'refundRemarks' => $refundRemarks,
  4939. 'date' => date ( "Y-m-d H:i:s" )
  4940. );
  4941. $invoiceRefund->addInvoiceRefund ( $item );
  4942. // 扣除收款汇总信息 汇总
  4943. Doo::loadModel ( 'invoiceStatistics' );
  4944. $invoiceStatistics = new invoiceStatistics ();
  4945. $item = array (
  4946. 'date' => $irDetail ['receivablesDate'],
  4947. 'priceClass' => 2,
  4948. 'irid' => $irDetail ['irid'],
  4949. 'receivablesPrice' => - $refundPrice
  4950. );
  4951. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4952. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4953. $item += array (
  4954. 'cid' => $receivablesCategory [0]
  4955. );
  4956. }
  4957. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4958. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4959. $item += array (
  4960. 'staff' => $receivablesStaff [0]
  4961. );
  4962. }
  4963. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4964. // 公司日常支出流水
  4965. Doo::loadModel ( 'wasteBook' );
  4966. $wasteBook = new wasteBook ();
  4967. $accountBank = '';
  4968. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4969. $accountBank = 'CGBDeposit';
  4970. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4971. $accountBank = 'ICBCDeposit';
  4972. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4973. $accountBank = 'HUADeposit';
  4974. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4975. $accountBank = 'PersonalDeposit';
  4976. }
  4977. $itemWaste = array (
  4978. 'accountPrice' => - $refundPrice,
  4979. 'expensesType' => 2,
  4980. 'accountType' => 11,
  4981. 'accountPriceShow' => $refundPrice,
  4982. 'dataID' => $irid,
  4983. 'accountBank' => $accountBank,
  4984. 'category' => $this->staff [0] ['category'],
  4985. 'cid' => $this->staff [0] ['cid'],
  4986. 'name' => $this->staff [0] ['username'],
  4987. 'sid' => $this->staff [0] ['sid'],
  4988. 'inputDate' => date ( "Y-m-d H:i:s" )
  4989. );
  4990. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4991. return '/invoiceReceivablesAS';
  4992. }
  4993. die ( 'illegal request' );
  4994. }
  4995. function ajaxCheckInvoiceReceivablesRefund() {
  4996. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4997. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4998. if ($refundPrice < 0) {
  4999. echo json_encode ( array (
  5000. 'error' => '金额不能为负'
  5001. ) );
  5002. die ();
  5003. }
  5004. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5005. Doo::loadModel ( 'invoiceReceivables' );
  5006. $invoiceReceivables = new invoiceReceivables ();
  5007. $irid = $invoiceReceivables->authcode ( $iridKey );
  5008. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5009. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5010. echo json_encode ( array (
  5011. 'error' => '退款金额不能超过收款金额'
  5012. ) );
  5013. die ();
  5014. }
  5015. echo json_encode ( array (
  5016. 'ok' => '可以使用!'
  5017. ) );
  5018. die ();
  5019. }
  5020. }
  5021. /**
  5022. * 获得收款退款信息
  5023. */
  5024. function getRefundByDetail() {
  5025. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5026. Doo::loadModel ( 'invoiceReceivables' );
  5027. $invoiceReceivables = new invoiceReceivables ();
  5028. if (! empty ( $iridKey )) {
  5029. $irid = $invoiceReceivables->authcode ( $iridKey );
  5030. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5031. echo json_encode ( array (
  5032. 'status' => 1,
  5033. 'irDetail' => $irDetail
  5034. ) );
  5035. die ();
  5036. }
  5037. echo json_encode ( array (
  5038. 'status' => 2
  5039. ) );
  5040. }
  5041. /**
  5042. * 根据收款序列号获得收款退款信息
  5043. */
  5044. function ajaxGetInvoiceReceivablesBySerial() {
  5045. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5046. if (! empty ( $receivablesSerial )) {
  5047. Doo::loadModel ( 'invoiceReceivables' );
  5048. $invoiceReceivables = new invoiceReceivables ();
  5049. // , ' and refundLog=""'
  5050. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5051. $html = '';
  5052. if (! empty ( $irDetail ))
  5053. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5054. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5055. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5056. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5057. <td>' . $irDetail ['recepitTitleMark'] . '
  5058. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5059. </td>';
  5060. echo json_encode ( array (
  5061. 'status' => 1,
  5062. 'html' => $html,
  5063. 'irDetail' => $irDetail
  5064. ) );
  5065. die ();
  5066. }
  5067. echo json_encode ( array (
  5068. 'status' => 2
  5069. ) );
  5070. }
  5071. /**
  5072. * 绑定新收款
  5073. */
  5074. function relationNewInvoiceReceivables() {
  5075. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5076. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5077. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5078. Doo::loadModel ( 'invoiceReceivables' );
  5079. $invoiceReceivables = new invoiceReceivables ();
  5080. Doo::loadClass ( 'XDeode' );
  5081. $XDeode = new XDeode ( 5 );
  5082. $irid = $XDeode->decode ( $iridKey );
  5083. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5084. echo $irid . 'bbb' . $iridOld;
  5085. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5086. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5087. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5088. die ( 'illegal request' );
  5089. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5090. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5091. ';
  5092. $invoiceReceivables = new invoiceReceivables ();
  5093. $item = array (
  5094. 'irid' => $iridOld,
  5095. 'relationIrid' => $irid,
  5096. 'relationLog' => $relationLog
  5097. );
  5098. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5099. return '/invoiceReceivablesAS';
  5100. }
  5101. die ( 'illegal request' );
  5102. }
  5103. // function invoiceApprovalAchieve() {
  5104. // Doo::loadModel ( 'invoice' );
  5105. // $invoice = new invoice ();
  5106. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5107. // $page_size = 12;
  5108. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5109. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5110. // $get = "/" . $date;
  5111. // $con = '';
  5112. // if ($date == 'MONTHO')
  5113. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5114. // elseif ($date == 'MONTHT')
  5115. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5116. // elseif ($date == 'MONTHY')
  5117. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5118. // if (! empty ( $MebSea )) {
  5119. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5120. // $get .= "/" . $MebSea;
  5121. // }
  5122. // $pageinfo ['page'] = array (
  5123. // 'previous' => ''
  5124. // );
  5125. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5126. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5127. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5128. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5129. // // print_r($list);
  5130. // $this->data ['MebSeaEn'] = $MebSea;
  5131. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5132. // $this->data ['get'] = $get;
  5133. // $this->data ['page'] = $pageinfo;
  5134. // $this->data ['list'] = $list;
  5135. // $this->data ['date'] = $date;
  5136. // $this->data ['memu'] = "invoice";
  5137. // $this->data ['staff'] = $this->staff;
  5138. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5139. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5140. // }
  5141. /**
  5142. * 获得审批发票的信息以及审批页面
  5143. */
  5144. function ajaxGetInvoiceApprovalDetail() {
  5145. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5146. if (empty ( $serial )) {
  5147. echo json_encode ( array (
  5148. 'status' => 2,
  5149. 'msg' => 'illegal request'
  5150. ) );
  5151. die ();
  5152. }
  5153. Doo::loadModel ( 'invoice' );
  5154. $invoice = new invoice ();
  5155. Doo::loadModel ( 'invoiceOperationLog' );
  5156. $invoiceOperationLog = new invoiceOperationLog ();
  5157. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5158. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5159. if (empty ( $detail ))
  5160. $html = '';
  5161. else {
  5162. $html = '
  5163. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5164. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5165. <input type="hidden" name="status" value="">
  5166. <input type="hidden" name="divApproval" value="divApproval">
  5167. <div class="modal-dialog modal-lg">
  5168. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5169. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5170. <tr>
  5171. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5172. </tr>
  5173. <tr>
  5174. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5175. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5176. </tr>
  5177. <tr>
  5178. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5179. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5180. </tr>
  5181. <tr>
  5182. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5183. </td>
  5184. </tr>
  5185. <tr>
  5186. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5187. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5188. </tr>
  5189. <tr>
  5190. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5191. </tr></tbody></table>';
  5192. if ($detail ['invoiceType'] == 0)
  5193. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5194. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5195. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5196. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5197. </tr>';
  5198. else
  5199. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5200. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5201. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5202. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5203. ';
  5204. $html .= '<tr>
  5205. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5206. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5207. </tr>
  5208. <tr>
  5209. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5210. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5211. </tr></tbody></table>';
  5212. if ($detail ['doPost'] == 1) {
  5213. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5214. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5215. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5216. </tr><tr>
  5217. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5218. </tr><tr>
  5219. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5220. </tr>
  5221. ';
  5222. if ($detail ['expressCom'] == 'SF')
  5223. $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>';
  5224. else
  5225. $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>';
  5226. $html .= '</tbody></table>';
  5227. }
  5228. if (! empty ( $invoiceOperationLogList )) {
  5229. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5230. foreach ( $invoiceOperationLogList as $key => $value ) {
  5231. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5232. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5233. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5234. if ($value ['status'] == 2) {
  5235. $html .= '<span class="colGreen">同意</span>';
  5236. } elseif ($value ['status'] == 3) {
  5237. $html .= '<span class="colOrange">退回</span>';
  5238. } elseif ($value ['status'] == 5) {
  5239. $html .= '<span class="colGreen">打印</span>';
  5240. } elseif ($value ['status'] == 4) {
  5241. $html .= '<span class="colRed">终止</span>';
  5242. }
  5243. $html .= $value ['operation'] . '</p></blockquote>';
  5244. }
  5245. }
  5246. $html .= '</td></tr></tbody></table>';
  5247. }
  5248. $html .= '</div><div class="modal-footer">
  5249. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5250. <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>
  5251. <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>
  5252. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5253. </form>
  5254. <script type="text/javascript">
  5255. $("a[node-approval^=\'approval\']").click(function() {
  5256. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5257. $("form[name=\'invoiceApproval\']").submit();
  5258. });
  5259. </script>
  5260. ';
  5261. }
  5262. echo json_encode ( array (
  5263. 'status' => 1,
  5264. 'html' => $html
  5265. ) );
  5266. die ();
  5267. }
  5268. /**
  5269. * 获得审批发票分页数据
  5270. */
  5271. function ajaxGetinvoiceApprovalAchieve() {
  5272. Doo::loadModel ( 'invoice' );
  5273. $invoice = new invoice ();
  5274. Doo::loadModel ( 'staff' );
  5275. $staff = new staff ();
  5276. Doo::loadClass ( 'XDeode' );
  5277. $XDeode = new XDeode ( 5 );
  5278. Doo::loadModel ( 'invoiceTraining' );
  5279. $invoiceTraining = new invoiceTraining ();
  5280. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5281. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5282. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5283. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5284. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5285. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5286. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5287. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5288. $MebSea = $this->get_args ( 'search' );
  5289. $MebSea = $MebSea ['value'];
  5290. $page_size = $length;
  5291. $con = '';
  5292. if ($status == 'ALL')
  5293. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5294. elseif ($status == 'PEND')
  5295. $con = ' isDelete=0 and status=1';
  5296. elseif ($status == 'APPROVED')
  5297. $con = ' isDelete=0 and status=2';
  5298. if ($invoiceType == 'ORDINARY')
  5299. $con .= ' and invoiceType=0 ';
  5300. elseif ($invoiceType == 'SPECIAL')
  5301. $con .= ' and invoiceType=1 ';
  5302. if ($invoiceTrain == 'ORDINARY')
  5303. $con .= ' and trainId=0 ';
  5304. elseif ($invoiceTrain == 'TRAIN')
  5305. $con .= ' and trainId!=0 ';
  5306. if ($invoiceTrainName != 'ALL') {
  5307. $trainId = $XDeode->decode ( $invoiceTrainName );
  5308. if (is_numeric ( $trainId ))
  5309. $con .= ' and trainId =' . $trainId;
  5310. }
  5311. $dateArr = explode ( ':', $date );
  5312. $D1 = $dateString = '';
  5313. $D2 = '';
  5314. if (! empty ( $date )) {
  5315. $D1 = $dateArr [0];
  5316. if (isset ( $dateArr [1] ))
  5317. $D2 = $dateArr [1];
  5318. else
  5319. $D2 = '';
  5320. $dateString = $D1 . " : " . $D2;
  5321. }
  5322. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5323. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5324. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5325. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5326. if (! empty ( $MebSea ))
  5327. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5328. // /
  5329. $pageinfo ['page'] = array (
  5330. 'previous' => ''
  5331. );
  5332. $sql = ' ' . $con;
  5333. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5334. $limit = $page . ',' . $page_size;
  5335. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5336. $approvalList = array ();
  5337. $html = '<script type="text/javascript">
  5338. </script>';
  5339. // 结算结束不能修改方式
  5340. Doo::loadModel ( 'receipt' );
  5341. $receipt = new receipt ();
  5342. foreach ( $list as $key => $value ) {
  5343. $irDetail = array ();
  5344. // 结算方式
  5345. $receiptDetail = array ();
  5346. if ($value ['trainId'] != 0) {
  5347. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5348. }
  5349. if (! empty ( $receiptDetail )) {
  5350. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5351. array_push ( $irDetail, '' );
  5352. } else {
  5353. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5354. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5355. } elseif ($value ['status'] == 2) {
  5356. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5357. } else
  5358. array_push ( $irDetail, '' );
  5359. }
  5360. } else {
  5361. if ($value ['status'] == 2) {
  5362. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5363. } else
  5364. array_push ( $irDetail, '' );
  5365. }
  5366. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5367. if ($value ['invoiceType'] == 1)
  5368. array_push ( $irDetail, $value ['invoiceCompany'] );
  5369. else
  5370. array_push ( $irDetail, $value ['invoiceTitle'] );
  5371. array_push ( $irDetail, $value ['TIN'] );
  5372. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5373. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5374. array_push ( $irDetail, $value ['remark'] );
  5375. array_push ( $irDetail, $value ['invoiceElement'] );
  5376. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5377. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5378. if ($value ['invoiceType'] == 1) {
  5379. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5380. } else {
  5381. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5382. }
  5383. if ($value ['settlementType'] == 0) {
  5384. array_push ( $irDetail, '软件销售' );
  5385. } else {
  5386. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5387. array_push ( $irDetail, $itDetail ['trainName'] );
  5388. }
  5389. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5390. array_push ( $irDetail, $value ['recipientsAddress'] );
  5391. array_push ( $irDetail, $value ['mailItems'] );
  5392. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5393. $fchtml = $value ['OL'] ['operation'];
  5394. if (count ( $list ) == $page_size)
  5395. $fchtml = $value ['OL'] ['operation'] . $html;
  5396. // 最后的审批意见
  5397. array_push ( $irDetail, $fchtml );
  5398. if ($value ['status'] == 2)
  5399. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5400. elseif ($value ['status'] == 3)
  5401. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5402. elseif ($value ['status'] == 4)
  5403. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5404. else
  5405. array_push ( $irDetail, '' );
  5406. array_push ( $approvalList, $irDetail );
  5407. }
  5408. // $approvalListJson = json_encode ( $approvalList );
  5409. $recordsFiltered = $pageinfo ['total_data'];
  5410. echo json_encode ( array (
  5411. "draw" => intval ( $draw ),
  5412. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5413. "recordsFiltered" => intval ( $recordsFiltered ),
  5414. "data" => $approvalList
  5415. ), JSON_UNESCAPED_UNICODE );
  5416. }
  5417. /**
  5418. * 审批发票查看更多--重构
  5419. */
  5420. function invoiceApprovalAchieve() {
  5421. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5422. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5423. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5424. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5425. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5426. Doo::loadModel ( 'invoiceTraining' );
  5427. $invoiceTraining = new invoiceTraining ();
  5428. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5429. $this->data ['trainList'] = $trainList;
  5430. $this->data ['dateString'] = $date;
  5431. $this->data ['status'] = $status;
  5432. $this->data ['invoiceType'] = $invoiceType;
  5433. $this->data ['invoiceTrain'] = $invoiceTrain;
  5434. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5435. $this->data ['memu'] = "invoice";
  5436. $this->data ['staff'] = $this->staff;
  5437. $this->data ['receiptMemu'] = 'invoiceApproval';
  5438. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5439. }
  5440. function invoiceTAchieve() {
  5441. Doo::loadModel ( 'invoice' );
  5442. $invoice = new invoice ();
  5443. Doo::loadClass ( 'XDeode' );
  5444. $XDeode = new XDeode ( 5 );
  5445. Doo::loadModel ( 'staff' );
  5446. $staff = new staff ();
  5447. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5448. $page_size = 12;
  5449. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5450. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5451. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5452. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5453. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5454. Doo::loadModel ( 'invoiceTraining' );
  5455. $invoiceTraining = new invoiceTraining ();
  5456. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5457. $get = "/" . $date;
  5458. $con = '';
  5459. if ($date == 'MONTHO')
  5460. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5461. elseif ($date == 'MONTHT')
  5462. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5463. elseif ($date == 'MONTHY')
  5464. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5465. if ($invoiceType == 'ORDINARY')
  5466. $con .= ' and invoiceType=0 ';
  5467. elseif ($invoiceType == 'SPECIAL')
  5468. $con .= ' and invoiceType=1 ';
  5469. if ($invoiceTrain == 'ORDINARY')
  5470. $con .= ' and trainId=0 ';
  5471. elseif ($invoiceTrain == 'TRAIN')
  5472. $con .= ' and trainId!=0 ';
  5473. if ($invoiceTrainName != 'ALL') {
  5474. $trainId = $XDeode->decode ( $invoiceTrainName );
  5475. if (is_numeric ( $trainId ))
  5476. $con .= ' and trainId =' . $trainId;
  5477. }
  5478. if (! empty ( $MebSea )) {
  5479. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5480. $get .= "/" . $MebSea;
  5481. }
  5482. $pageinfo ['page'] = array (
  5483. 'previous' => ''
  5484. );
  5485. $sql = "";
  5486. $action = "";
  5487. if ($this->ACTION == 'invoicePrintAchieve') {
  5488. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5489. $action = "invoicePrintAchieve";
  5490. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5491. // and untreadStatus=0
  5492. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5493. $action = "invoicePostAchieve";
  5494. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5495. $sql = " untreadStatus=2 and status=2 " . $con;
  5496. $action = "invoiceUntreadAchieve";
  5497. }
  5498. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5499. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5500. $this->data ['MebSeaEn'] = $MebSea;
  5501. $this->data ['MebSea'] = urlencode ( $MebSea );
  5502. $this->data ['get'] = $get;
  5503. $this->data ['page'] = $pageinfo;
  5504. $this->data ['trainList'] = $trainList;
  5505. $this->data ['invoiceType'] = $invoiceType;
  5506. $this->data ['invoiceTrain'] = $invoiceTrain;
  5507. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5508. $this->data ['date'] = $date;
  5509. $this->data ['memu'] = "invoice";
  5510. $this->data ['staff'] = $this->staff;
  5511. if ($this->ACTION == 'invoicePrintAchieve') {
  5512. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5513. $this->data ['receiptMemu'] = 'invoicePrint';
  5514. $this->data ['list'] = $list;
  5515. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5516. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5517. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5518. Doo::loadModel ( 'express' );
  5519. $express = new express ();
  5520. $expressList = $express->getExpressByAll ();
  5521. $this->data ['expressList'] = $expressList;
  5522. $this->data ['receiptMemu'] = 'invoicePost';
  5523. $this->data ['list'] = $list;
  5524. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5525. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5526. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5527. $this->data ['receiptMemu'] = 'invoiceUntread';
  5528. $this->data ['list'] = $list;
  5529. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5530. }
  5531. }
  5532. /**
  5533. * 公司应收款
  5534. */
  5535. function invoiceAggregateCompanyDetail() {
  5536. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5537. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5538. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5539. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5540. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5541. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5542. Doo::loadClass ( 'XDeode' );
  5543. $XDeode = new XDeode ( 5 );
  5544. Doo::loadModel ( 'invoice' );
  5545. $invoice = new invoice ();
  5546. Doo::loadModel ( 'staff' );
  5547. $staff = new staff ();
  5548. Doo::loadModel ( "invoiceCompanyManage" );
  5549. $invoiceCompanyManage = new invoiceCompanyManage ();
  5550. Doo::loadModel ( 'L_category' );
  5551. $category = new L_category ();
  5552. $sid = '';
  5553. if (! empty ( $sidKey )) {
  5554. $sid = $XDeode->decode ( $sidKey );
  5555. }
  5556. $staffDetail = $staff->getStaffBySid ( $sid );
  5557. $cid = '';
  5558. if (! empty ( $cidKey )) {
  5559. $cid = $XDeode->decode ( $cidKey );
  5560. }
  5561. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5562. $cidList = array ();
  5563. foreach ( $imcStaff as $key => $value ) {
  5564. array_push ( $cidList, $value ['cid'] );
  5565. }
  5566. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5567. $cidString = implode ( ',', $cidList );
  5568. if (empty ( $cid ))
  5569. $staffList = $staff->getStaffInCid ( $cidString );
  5570. else
  5571. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5572. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5573. $page_size = 25;
  5574. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5575. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5576. $con = ' status=2 and untreadStatus!=2 ';
  5577. $statisticsCon = '';
  5578. if (! empty ( $year ) && is_numeric ( $year ))
  5579. $con .= ' and Year(printTime)=' . $year . '';
  5580. if (! empty ( $month ) && is_numeric ( $month ))
  5581. $con .= ' and Month(printTime)="' . $month . '" ';
  5582. if ($status == 'UNRECORD')
  5583. $con .= ' and printStatus=1 and untreadStatus=0';
  5584. elseif ($status == 'RECORD')
  5585. $con .= ' and printStatus=1 and untreadStatus=3';
  5586. elseif ($status == 'BOUNCED')
  5587. $con .= ' and untreadStatus=2';
  5588. elseif ($status == 'PARTRECORD')
  5589. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5590. elseif ($status == 'All') {
  5591. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5592. }
  5593. if (! empty ( $sid ) && is_numeric ( $sid ))
  5594. $con .= ' and sid=' . $sid;
  5595. if (! empty ( $cid ) && is_numeric ( $cid ))
  5596. $con .= ' and cid=' . $cid;
  5597. else
  5598. $con .= ' and cid in (' . $cidString . ')';
  5599. // 开票内容筛选
  5600. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5601. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5602. }
  5603. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5604. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5605. if (! empty ( $titleORno )) {
  5606. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5607. }
  5608. $pageinfo ['page'] = array (
  5609. 'previous' => ''
  5610. );
  5611. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5612. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5613. // 应收款合计
  5614. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5615. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5616. $monthHtml = "";
  5617. if ($year != "ALL") {
  5618. for($i = 1; $i <= 12; $i ++) {
  5619. if ($i == $month)
  5620. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5621. else
  5622. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5623. }
  5624. }
  5625. $this->data ['monthHtml'] = $monthHtml;
  5626. $this->data ['year'] = $year;
  5627. $this->data ['month'] = $month;
  5628. $this->data ['ics'] = $ics;
  5629. $this->data ['cidKey'] = $cidKey;
  5630. $this->data ['sid'] = $sid;
  5631. $this->data ['staffDetail'] = $staffDetail;
  5632. $this->data ['staffList'] = $staffList;
  5633. $this->data ['titleORnoEn'] = $titleORno;
  5634. $this->data ['titleORno'] = urlencode ( $titleORno );
  5635. $this->data ['invoiceDetail'] = array (
  5636. 'invoiceElement' => $invoiceElement
  5637. );
  5638. $this->data ['page'] = $pageinfo;
  5639. $this->data ['get'] = $get;
  5640. $this->data ['list'] = $list;
  5641. $this->data ['status'] = $status;
  5642. $this->data ['categoryList'] = $categoryList;
  5643. $this->data ['memu'] = "invoice";
  5644. $this->data ['staff'] = $this->staff;
  5645. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5646. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5647. }
  5648. /**
  5649. * 获取一条收款信息
  5650. */
  5651. function ajaxGetInvoiceReceivables() {
  5652. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5653. Doo::loadModel ( 'invoiceReceivables' );
  5654. $invoiceReceivables = new invoiceReceivables ();
  5655. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5656. echo json_encode ( array (
  5657. 'status' => 1,
  5658. 'detail' => $detail
  5659. ) );
  5660. }
  5661. /**
  5662. * 异步获取办事处用户
  5663. */
  5664. function ajaxGetStaffByCategory() {
  5665. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5666. Doo::loadModel ( 'staff' );
  5667. $staff = new staff ();
  5668. if ($cid == "PUBLIC") {
  5669. echo json_encode ( array (
  5670. 'status' => 1,
  5671. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5672. ) );
  5673. die ();
  5674. }
  5675. if (! is_numeric ( $cid )) {
  5676. echo json_encode ( array (
  5677. 'status' => 0,
  5678. 'msg' => 'illegal request'
  5679. ) );
  5680. die ();
  5681. }
  5682. $staffList = $staff->getStaffByCid ( $cid );
  5683. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5684. foreach ( $staffList as $key => $value ) {
  5685. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5686. }
  5687. echo json_encode ( array (
  5688. 'status' => 1,
  5689. 'html' => $html
  5690. ) );
  5691. }
  5692. /**
  5693. * 异步获取一条发票的邮寄信息
  5694. */
  5695. function ajaxGetInvoicePostDetail() {
  5696. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5697. Doo::loadModel ( 'invoice' );
  5698. $invoice = new invoice ();
  5699. $iid = $invoice->authcode ( $iid );
  5700. Doo::loadModel ( 'express' );
  5701. $express = new express ();
  5702. $expressList = $express->getExpressByAll ();
  5703. if (! is_numeric ( $iid )) {
  5704. echo json_encode ( array (
  5705. 'status' => 0,
  5706. 'msg' => 'illegal request'
  5707. ) );
  5708. die ();
  5709. }
  5710. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5711. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5712. $html = "";
  5713. foreach ( $expressList as $key => $value ) {
  5714. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5715. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5716. else
  5717. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5718. }
  5719. $invoiceDetail ['eaHtml'] = $html;
  5720. echo json_encode ( array (
  5721. 'status' => 1,
  5722. 'invoiceDetail' => $invoiceDetail
  5723. ) );
  5724. }
  5725. /**
  5726. *
  5727. * @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 ) ); }
  5728. */
  5729. /**
  5730. *
  5731. * @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 ) ); }
  5732. */
  5733. /**
  5734. * 我的收款中 选择哪个发票入账,进行金额判断
  5735. */
  5736. function ajaxCompareInvoicePrice() {
  5737. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5738. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5739. Doo::loadModel ( 'invoice' );
  5740. $invoice = new invoice ();
  5741. Doo::loadModel ( 'invoiceReceivables' );
  5742. $invoiceReceivables = new invoiceReceivables ();
  5743. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5744. $keyList = explode ( ';', $claimKey );
  5745. $receivablesPrice = 0;
  5746. foreach ( $keyList as $key => $value ) {
  5747. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5748. $receivablesPrice += $detailM ['receivablesPrice'];
  5749. }
  5750. if ($receivablesPrice > $detail ['invoicePrice']) {
  5751. $price = $receivablesPrice - $detail ['invoicePrice'];
  5752. echo json_encode ( array (
  5753. 'status' => 1,
  5754. 'price' => $price
  5755. ) );
  5756. } else
  5757. echo json_encode ( array (
  5758. 'status' => 2
  5759. ) );
  5760. }
  5761. /**
  5762. * 获得打印发票
  5763. */
  5764. function ajaxGetInvoiceInfoByPrint() {
  5765. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5766. if (empty ( $serial )) {
  5767. echo json_encode ( array (
  5768. 'status' => 2,
  5769. 'msg' => 'illegal request'
  5770. ) );
  5771. die ();
  5772. }
  5773. Doo::loadModel ( 'invoice' );
  5774. $invoice = new invoice ();
  5775. Doo::loadModel ( 'invoiceOperationLog' );
  5776. $invoiceOperationLog = new invoiceOperationLog ();
  5777. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5778. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5779. Doo::loadModel ( 'invoicePaper' );
  5780. $invoicePaper = new invoicePaper ();
  5781. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5782. if (empty ( $detail ))
  5783. $html = '';
  5784. else {
  5785. $html = '
  5786. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5787. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5788. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5789. <div class="modal-dialog modal-lg">
  5790. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5791. <div class="modal-body saeaList">
  5792. <table class="table table-bordered table-condensed"><tbody>
  5793. <tr>
  5794. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5795. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5796. </tr>
  5797. <tr>
  5798. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5799. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5800. </tr>
  5801. <tr>
  5802. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5803. </td>
  5804. </tr>
  5805. <tr>
  5806. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5807. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5808. </tr>
  5809. <tr>
  5810. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5811. </tr></tbody></table>';
  5812. if ($detail ['invoiceType'] == 0)
  5813. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5814. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5815. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5816. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5817. </tr>';
  5818. else
  5819. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5820. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5821. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5822. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5823. ';
  5824. $html .= '<tr>
  5825. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5826. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5827. </tr>
  5828. <tr>
  5829. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5830. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5831. </tr></tbody></table>';
  5832. if ($detail ['doPost'] == 1)
  5833. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5834. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5835. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5836. </tr><tr>
  5837. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5838. </tr><tr>
  5839. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5840. </tr></tbody></table>';
  5841. if (! empty ( $invoiceOperationLogList )) {
  5842. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5843. foreach ( $invoiceOperationLogList as $key => $value ) {
  5844. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5845. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5846. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5847. if ($value ['status'] == 2) {
  5848. $html .= '<span class="colGreen">同意</span>';
  5849. } elseif ($value ['status'] == 3) {
  5850. $html .= '<span class="colOrange">退回</span>';
  5851. } elseif ($value ['status'] == 5) {
  5852. $html .= '<span class="colGreen">打印</span>';
  5853. } elseif ($value ['status'] == 4) {
  5854. $html .= '<span class="colRed">终止</span>';
  5855. }
  5856. $html .= $value ['operation'] . '</p></blockquote>';
  5857. }
  5858. }
  5859. $html .= '</td>
  5860. <td><span class="colRed">*</span>
  5861. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5862. foreach ( $invoicePaperList as $key => $value ) {
  5863. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5864. }
  5865. $html .= '</select>
  5866. <span class="red" id="p-msg"></span>
  5867. </td>
  5868. </tr></tbody></table>';
  5869. }
  5870. $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>
  5871. </div></div></form>
  5872. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5873. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5874. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5875. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5876. ';
  5877. }
  5878. echo json_encode ( array (
  5879. 'status' => 1,
  5880. 'html' => $html
  5881. ) );
  5882. die ();
  5883. }
  5884. /**
  5885. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5886. */
  5887. function ajaxGetInvoiceInfoByType() {
  5888. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5889. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5890. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5891. if (empty ( $serial )) {
  5892. echo json_encode ( array (
  5893. 'status' => 2,
  5894. 'msg' => 'illegal request'
  5895. ) );
  5896. die ();
  5897. }
  5898. if ($type == 'INVOICE') {
  5899. Doo::loadModel ( 'invoice' );
  5900. $invoice = new invoice ();
  5901. Doo::loadModel ( 'invoiceOperationLog' );
  5902. $invoiceOperationLog = new invoiceOperationLog ();
  5903. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5904. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5905. if (empty ( $detail ))
  5906. $html = '';
  5907. else {
  5908. $html = '
  5909. <div class="modal-dialog modal-lg">
  5910. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5911. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5912. <tr>
  5913. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5914. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5915. </tr>
  5916. <tr>
  5917. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5918. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5919. </tr>
  5920. <tr>
  5921. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5922. </td>
  5923. </tr>
  5924. <tr>
  5925. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5926. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5927. </tr>
  5928. <tr>
  5929. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5930. </tr>';
  5931. if ($detail ['settlementType'] == 1)
  5932. $html .= '<tr>
  5933. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5934. </tr>';
  5935. else
  5936. $html .= '<tr>
  5937. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5938. </tr>';
  5939. $html .= ' </tbody></table>';
  5940. if ($detail ['invoiceType'] == 0)
  5941. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5942. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5943. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5944. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5945. </tr>';
  5946. else
  5947. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5948. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5949. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5950. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5951. ';
  5952. $html .= '<tr>
  5953. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5954. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5955. </tr>
  5956. <tr>
  5957. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5958. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5959. </tr></tbody></table>';
  5960. if ($detail ['doPost'] == 1) {
  5961. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5962. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5963. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5964. </tr><tr>
  5965. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5966. </tr><tr>
  5967. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5968. </tr>
  5969. ';
  5970. if ($detail ['expressCom'] == 'SF')
  5971. $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>';
  5972. else
  5973. $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>';
  5974. $html .= '</tbody></table>';
  5975. }
  5976. if (! empty ( $invoiceOperationLogList )) {
  5977. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5978. foreach ( $invoiceOperationLogList as $key => $value ) {
  5979. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5980. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5981. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5982. if ($value ['status'] == 2) {
  5983. $html .= '<span class="colGreen">同意</span>';
  5984. } elseif ($value ['status'] == 3) {
  5985. $html .= '<span class="colOrange">退回</span>';
  5986. } elseif ($value ['status'] == 5) {
  5987. $html .= '<span class="colGreen">打印</span>';
  5988. } elseif ($value ['status'] == 4) {
  5989. $html .= '<span class="colRed">终止</span>';
  5990. }
  5991. $html .= $value ['operation'] . '</p></blockquote>';
  5992. }
  5993. }
  5994. $html .= '</td></tr></tbody></table>';
  5995. }
  5996. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5997. }
  5998. echo json_encode ( array (
  5999. 'status' => 1,
  6000. 'html' => $html
  6001. ) );
  6002. die ();
  6003. } elseif ($type == 'RECEIVABLES') {
  6004. Doo::loadModel ( 'invoiceReceivables' );
  6005. $invoiceReceivables = new invoiceReceivables ();
  6006. Doo::loadModel ( 'invoiceRefund' );
  6007. $invoiceRefund = new invoiceRefund ();
  6008. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6009. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6010. if (empty ( $detail ))
  6011. $html = '';
  6012. else {
  6013. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6014. <table class="table table-bordered table-condensed">
  6015. <tbody><tr>
  6016. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6017. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6018. </tr><tr>
  6019. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6020. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6021. </tr>
  6022. <tr>
  6023. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6024. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6025. </tr>
  6026. <tr>
  6027. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6028. </tr>
  6029. </tbody></table>';
  6030. if (! empty ( $ireList )) {
  6031. $html .= '
  6032. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6033. <tr>
  6034. <th class="taC">退款单位名称</th>
  6035. <th class="taC">退款的账号</th>
  6036. <th class="taC">退款金额</th>
  6037. <th class="taC">退款</th>
  6038. <th class="taC">备注</th>
  6039. </tr>
  6040. ';
  6041. foreach ( $ireList as $key => $value ) {
  6042. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6043. $html .= '<tr>
  6044. <td>' . $value ['refundCompany'] . '</td>
  6045. <td>' . $value ['refundNumber'] . '</td>
  6046. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6047. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6048. <td>' . $value ['refundRemarks'] . '</td>
  6049. </tr>
  6050. ';
  6051. }
  6052. }
  6053. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6054. }
  6055. echo json_encode ( array (
  6056. 'status' => 1,
  6057. 'html' => $html
  6058. ) );
  6059. die ();
  6060. } elseif ($type == 'IRTC') {
  6061. Doo::loadModel ( 'invoice' );
  6062. $invoice = new invoice ();
  6063. Doo::loadModel ( 'invoiceOperationLog' );
  6064. $invoiceOperationLog = new invoiceOperationLog ();
  6065. Doo::loadModel ( 'invoiceReceivables' );
  6066. $invoiceReceivables = new invoiceReceivables ();
  6067. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6068. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6069. if (empty ( $detail ))
  6070. $html = '';
  6071. else {
  6072. $receivablesPriceedHtml = '';
  6073. $receivablesPrice = $detail ['invoicePrice'];
  6074. if (! empty ( $detail ['irid'] )) {
  6075. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6076. if (empty ( $irList ))
  6077. $irList [0] ['sumPrice'] = 0;
  6078. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6079. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6080. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  6081. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  6082. </tr></tbody></table>';
  6083. $receivablesPrice = $balance;
  6084. }
  6085. if ($loss)
  6086. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6087. $html = $receivablesPriceedHtml . '
  6088. <table class="table table-bordered table-condensed"><tbody>
  6089. <tr>
  6090. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6091. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6092. </tr>
  6093. <tr>
  6094. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6095. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6096. </tr>
  6097. <tr>
  6098. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6099. </tr>
  6100. <tr>
  6101. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6102. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6103. </tr>
  6104. <tr>
  6105. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6106. </tr></tbody></table>';
  6107. if ($detail ['invoiceType'] == 0) {
  6108. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6109. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6110. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6111. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6112. </tr>';
  6113. $receivablesMessage = $detail ['invoiceTitle'];
  6114. } else {
  6115. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6116. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6117. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6118. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6119. ';
  6120. $receivablesMessage = $detail ['invoiceCompany'];
  6121. }
  6122. $html .= '<tr>
  6123. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6124. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6125. </tr>
  6126. <tr>
  6127. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6128. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6129. </tr></tbody></table>';
  6130. if ($detail ['doPost'] == 1)
  6131. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6132. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6133. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6134. </tr><tr>
  6135. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6136. </tr><tr>
  6137. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6138. </tr></tbody></table>';
  6139. if (! empty ( $invoiceOperationLogList )) {
  6140. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6141. foreach ( $invoiceOperationLogList as $key => $value ) {
  6142. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6143. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6144. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6145. if ($value ['status'] == 2) {
  6146. $html .= '<span class="colGreen">同意</span>';
  6147. } elseif ($value ['status'] == 3) {
  6148. $html .= '<span class="colOrange">退回</span>';
  6149. } elseif ($value ['status'] == 5) {
  6150. $html .= '<span class="colGreen">打印</span>';
  6151. }
  6152. $html .= $value ['operation'] . '</p></blockquote>';
  6153. }
  6154. }
  6155. $html .= '</td></tr></tbody></table>';
  6156. }
  6157. }
  6158. echo json_encode ( array (
  6159. 'status' => 1,
  6160. 'html' => $html,
  6161. 'receivablesPrice' => $receivablesPrice,
  6162. 'receivablesMessage' => $receivablesMessage,
  6163. 'receivablesDate' => date ( "Y-m-d" ),
  6164. 'iidKey' => $serial
  6165. ) );
  6166. die ();
  6167. }
  6168. }
  6169. function ajaxGetInvoiceReceivablesByStaff() {
  6170. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6171. if (empty ( $postData )) {
  6172. echo json_encode ( array (
  6173. 'status' => 2,
  6174. 'msg' => 'illegal request'
  6175. ) );
  6176. die ();
  6177. }
  6178. Doo::loadModel ( 'invoiceReceivables' );
  6179. $invoiceReceivables = new invoiceReceivables ();
  6180. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6181. if (empty ( $detail )) {
  6182. echo json_encode ( array (
  6183. 'status' => 2,
  6184. 'msg' => 'illegal request'
  6185. ) );
  6186. die ();
  6187. }
  6188. Doo::loadModel ( 'L_category' );
  6189. $lCategory = new L_category ();
  6190. Doo::loadModel ( 'staff' );
  6191. $staff = new staff ();
  6192. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6193. $category = $lCategory->getCategory ();
  6194. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6195. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6196. foreach ( $category as $key => $value ) {
  6197. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6198. if ($value ['cid'] == $detail ['cid'])
  6199. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6200. }
  6201. foreach ( $staffList as $key => $value ) {
  6202. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6203. if ($value ['sid'] == $detail ['sid'])
  6204. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6205. }
  6206. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6207. echo json_encode ( array (
  6208. 'status' => 1,
  6209. 'categoryHtml' => $categoryHtml,
  6210. 'staffHtml' => $staffHtml,
  6211. 'rbankHtml' => $rbankHtml,
  6212. 'detail' => $detail
  6213. ) );
  6214. }
  6215. function ajaxGetInvoiceReceivablesByIrid() {
  6216. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6217. if (empty ( $irid )) {
  6218. echo json_encode ( array (
  6219. 'status' => 2,
  6220. 'msg' => 'illegal request'
  6221. ) );
  6222. die ();
  6223. }
  6224. Doo::loadModel ( 'invoiceReceivables' );
  6225. $invoiceReceivables = new invoiceReceivables ();
  6226. Doo::loadModel ( 'invoice' );
  6227. $invoice = new invoice ();
  6228. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6229. $flag = true;
  6230. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6231. $bakDetail = array ();
  6232. if ($flag === false) {
  6233. array_push ( $bakDetail, $invoiceDetail );
  6234. $invoiceDetail = $bakDetail;
  6235. }
  6236. $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>
  6237. <tr>
  6238. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6239. <td>' . $detail ['receivablesMessage'] . '</td>
  6240. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6241. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6242. <td>' . $detail ['recepitTitleMark'] . '</td>
  6243. </tr></tbody></table>';
  6244. $isInvoice = false;
  6245. $invoiceHtml = '';
  6246. if (empty ( $invoiceDetail )) {
  6247. $isInvoice = true;
  6248. } else {
  6249. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6250. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6251. foreach ( $invoiceDetail as $key => $value ) {
  6252. $invoiceHtml .= '<tr>';
  6253. if (! empty ( $value ['invoiceType'] )) {
  6254. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6255. } else {
  6256. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6257. }
  6258. if (! empty ( $value ['invoiceType'] )) {
  6259. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6260. } else {
  6261. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6262. }
  6263. $invoiceHtml .= '
  6264. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6265. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6266. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6267. </tr>
  6268. ';
  6269. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6270. if (empty ( $irList ))
  6271. $irList [0] ['sumPrice'] = 0;
  6272. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6273. $priceString = '';
  6274. if ($balance < $detail ['receivablesPrice']) {
  6275. $priceString = '收款金额超过开票金额,';
  6276. }
  6277. if ($balance > $detail ['receivablesPrice']) {
  6278. $priceString = '收款金额低于开票金额,';
  6279. }
  6280. }
  6281. $invoiceHtml .= '
  6282. <script>
  6283. $(\'a[bind-receivables^="ir"]\').click(function() {
  6284. var data = $(this).attr("data-ikey");
  6285. $("input[name=\'invoiceKey\']").val(data);
  6286. var invoiceKey=data;
  6287. if(invoiceKey==""){
  6288. alert("入账错误,请重新刷新页面");
  6289. return false;
  6290. }
  6291. if(window.confirm("' . $priceString . '确定入账吗?")){
  6292. $("#IBR").submit();
  6293. }else{
  6294. return false;
  6295. }
  6296. });
  6297. </script>
  6298. ';
  6299. $invoiceHtml .= '</tbody></table>';
  6300. }
  6301. echo json_encode ( array (
  6302. 'status' => 1,
  6303. 'irkey' => $detail ['iridEn'],
  6304. 'receivablesHtml' => $receivablesHtml,
  6305. 'isInvoice' => $isInvoice,
  6306. 'invoiceHtml' => $invoiceHtml
  6307. ) );
  6308. }
  6309. function ajaxGetInvoiceReceivablesByTitle() {
  6310. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6311. if (empty ( $title )) {
  6312. echo json_encode ( array (
  6313. 'status' => 2,
  6314. 'msg' => 'illegal request'
  6315. ) );
  6316. die ();
  6317. }
  6318. Doo::loadModel ( 'invoice' );
  6319. $invoice = new invoice ();
  6320. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6321. $invoiceHtml = '';
  6322. if (! empty ( $invoiceDetail )) {
  6323. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6324. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6325. foreach ( $invoiceDetail as $key => $value ) {
  6326. if (! empty ( $value ['invoiceType'] )) {
  6327. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6328. } else {
  6329. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6330. }
  6331. if (! empty ( $value ['invoiceType'] )) {
  6332. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6333. } else {
  6334. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6335. }
  6336. $invoiceHtml .= '
  6337. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6338. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6339. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6340. </tr>
  6341. ';
  6342. }
  6343. $invoiceHtml .= '</tbody></table>
  6344. <script>
  6345. $(\'a[bind-receivables^="ir"]\').click(function() {
  6346. var data = $(this).attr("data-ikey");
  6347. $("input[name=\'invoiceKey\']").val(data);
  6348. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6349. if(invoiceKey==""){
  6350. alert("入账错误,请重新刷新页面");
  6351. return false;
  6352. }
  6353. if(window.confirm("确定入账吗?")){
  6354. $("#IBR").submit();
  6355. }else{
  6356. return false;
  6357. }
  6358. });
  6359. </script>
  6360. ';
  6361. }
  6362. echo json_encode ( array (
  6363. 'status' => 1,
  6364. 'invoiceHtml' => $invoiceHtml
  6365. ) );
  6366. }
  6367. function ajaxInvoicePushNotice() {
  6368. Doo::loadModel ( 'invoice' );
  6369. $invoice = new invoice ();
  6370. $approval = $invoice->getOne ( array (
  6371. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6372. 'desc' => 'iid',
  6373. 'asArray' => true
  6374. ) );
  6375. $isNotice = false;
  6376. if (! empty ( $approval ))
  6377. $isNotice = true;
  6378. $response = array (
  6379. 'error' => 0,
  6380. 'isNotice' => $isNotice
  6381. );
  6382. echo json_encode ( $response );
  6383. exit ();
  6384. }
  6385. public function ajaxCheckInvoiceNoUniqueness() {
  6386. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6387. Doo::loadModel ( 'invoice' );
  6388. $invoice = new invoice ();
  6389. if (! empty ( $invoiceNo )) {
  6390. Doo::loadModel ( 'invoicePaper' );
  6391. $invoicePaper = new invoicePaper ();
  6392. Doo::loadClass ( 'XDeode' );
  6393. $XDeode = new XDeode ( 5 );
  6394. $ipid = $XDeode->decode ( $invoiceNo );
  6395. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6396. $info = $invoice->getOne ( array (
  6397. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6398. 'asArray' => TRUE
  6399. ) );
  6400. if (! empty ( $info )) {
  6401. echo json_encode ( array (
  6402. 'error' => '发票号已存在'
  6403. ) );
  6404. die ();
  6405. } else
  6406. echo json_encode ( array (
  6407. 'ok' => '可以使用!'
  6408. ) );
  6409. die ();
  6410. }
  6411. }
  6412. function ajaxCheckInvoicePrice() {
  6413. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6414. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6415. Doo::loadModel ( 'invoice' );
  6416. $invoice = new invoice ();
  6417. Doo::loadModel ( 'invoiceReceivables' );
  6418. $invoiceReceivables = new invoiceReceivables ();
  6419. Doo::loadClass ( 'XDeode' );
  6420. $XDeode = new XDeode ( 5 );
  6421. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6422. $iidKey = $XDeode->decode ( $iidKey );
  6423. $info = $invoice->getInvoiceByIid ( $iidKey );
  6424. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6425. if (empty ( $irList ))
  6426. $irList [0] ['sumPrice'] = 0;
  6427. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6428. if ($balance < $receivablesPrice) {
  6429. echo json_encode ( array (
  6430. 'error' => '收款金额超过开票金额。'
  6431. ) );
  6432. die ();
  6433. }
  6434. if ($balance > $receivablesPrice) {
  6435. echo json_encode ( array (
  6436. 'error' => '收款金额低于开票金额。'
  6437. ) );
  6438. die ();
  6439. }
  6440. }
  6441. }
  6442. function ajaxGetInvoiceByNew() {
  6443. Doo::loadModel ( 'invoice' );
  6444. $invoice = new invoice ();
  6445. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6446. echo json_encode ( array (
  6447. 'status' => 1,
  6448. 'detail' => $detail
  6449. ) );
  6450. }
  6451. /**
  6452. * 旧输入导入
  6453. */
  6454. function importInvoice() {
  6455. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6456. $data ['emsg'] = "";
  6457. if ($emsg != "")
  6458. $data ['emsg'] = "请填写完整的数据";
  6459. $data ['time'] = time ();
  6460. $this->render ( "/admin/invoiceImport", $data );
  6461. }
  6462. function uploadInvoice() {
  6463. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6464. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6465. $file = $_FILES ['Filedata'] ['tmp_name'];
  6466. $error = false;
  6467. if (! is_uploaded_file ( $file )) {
  6468. $error = '400 Bad Request';
  6469. }
  6470. if ($error) {
  6471. header ( 'HTTP/1.0 ' . $error );
  6472. die ( 'Error ' . $error );
  6473. } else {
  6474. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6475. $this->IoHandler = new IoHandler ();
  6476. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6477. // $filedir=$_POST['time'];
  6478. // 调用定义物理路径
  6479. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6480. $this->IoHandler->MakeDir ( $t );
  6481. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6482. if ($filename != 'xlsx')
  6483. return "";
  6484. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6485. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6486. $upload_dir = $t . "/" . $upload_file;
  6487. $k = move_uploaded_file ( $file, $upload_dir );
  6488. if ($k) {
  6489. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6490. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6491. }
  6492. }
  6493. }
  6494. }
  6495. function importInvoiceDo() {
  6496. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6497. if ($path != "") {
  6498. Doo::loadModel ( 'invoice' );
  6499. Doo::loadModel ( 'staff' );
  6500. $staff = new staff ();
  6501. Doo::loadModel ( 'invoiceStatistics' );
  6502. Doo::loadModel ( 'invoiceOperationLog' );
  6503. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6504. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6505. // print_r ( $exlArray );
  6506. // die ();
  6507. // echo json_encode($exlArray);die;
  6508. foreach ( $exlArray as $key => $value ) {
  6509. // 开票
  6510. $invoice = new invoice ();
  6511. $invoice->invoiceNo = $value ['invoiceNo'];
  6512. $invoice->invoiceType = 0;
  6513. if ($value ['invoiceType'] == '专')
  6514. $invoice->invoiceType = 1;
  6515. $invoice->invoicePrice = $value ['invoicePrice'];
  6516. $invoice->invoiceQuantity = 1;
  6517. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6518. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6519. if ($value ['invoiceType'] == '专')
  6520. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6521. $invoice->userName = $value ['userName'];
  6522. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6523. $invoice->sid = $sDetail ['sid'];
  6524. $invoice->cid = $sDetail ['cid'];
  6525. $invoice->categoryName = $sDetail ['category'];
  6526. $invoice->invoiceElement = $value ['invoiceElement'];
  6527. $invoice->remark = $value ['remark'];
  6528. $invoice->date = $value ['date'];
  6529. $invoice->printTime = $value ['date'];
  6530. $invoice->ipSource = 1;
  6531. $invoice->printStatus = 1;
  6532. $invoice->status = 2;
  6533. $invoice->postStatus = 1;
  6534. $invoice->untreadStatus = 0;
  6535. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6536. $iid = $invoice->insert ();
  6537. // 汇总
  6538. $invoiceStatistics = new invoiceStatistics ();
  6539. //
  6540. $item = array (
  6541. 'date' => $value ['date'],
  6542. 'priceClass' => 1,
  6543. 'cid' => $sDetail ['cid'],
  6544. 'staff' => $sDetail ['sid'],
  6545. 'invoicePrice' => $value ['invoicePrice']
  6546. );
  6547. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6548. $invoiceOperationLog = new invoiceOperationLog ();
  6549. $item = array (
  6550. 'date' => date ( "Y-m-d H:i:s" ),
  6551. 'operation' => date ( "Y-m-d" ) . " 导入",
  6552. 'status' => 1,
  6553. 'img' => $sDetail ['avatar'],
  6554. 'username' => $sDetail ['username'],
  6555. 'uid' => $sDetail ['sid'],
  6556. 'category' => $sDetail ['category'],
  6557. 'iid' => $iid
  6558. );
  6559. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6560. }
  6561. return '/importInvoice?count=' . count ( $exlArray );
  6562. // return "/keyonline";
  6563. }
  6564. echo 'no file';
  6565. }
  6566. function importInvoiceReceivables() {
  6567. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6568. $data ['emsg'] = "";
  6569. if ($emsg != "")
  6570. $data ['emsg'] = "请填写完整的数据";
  6571. $data ['time'] = time ();
  6572. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6573. }
  6574. // 导入入账数据
  6575. function importInvoiceReceivablesDo() {
  6576. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6577. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6578. if ($path != "") {
  6579. Doo::loadModel ( 'invoiceReceivables' );
  6580. Doo::loadModel ( 'invoice' );
  6581. Doo::loadModel ( 'staff' );
  6582. $staff = new staff ();
  6583. Doo::loadModel ( 'invoiceStatistics' );
  6584. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6585. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6586. // print_r ( $exlArray );
  6587. // die ();
  6588. // echo json_encode($exlArray);die;
  6589. foreach ( $exlArray as $key => $value ) {
  6590. // 收款
  6591. $invoiceReceivables = new invoiceReceivables ();
  6592. $invoice = new invoice ();
  6593. $invoiceReceivables->bindStatus = 1;
  6594. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6595. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6596. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6597. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6598. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6599. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6600. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6601. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6602. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6603. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6604. $invoiceReceivables->iid = $iDetail ['iid'];
  6605. $irid = $invoiceReceivables->insert ();
  6606. // 发票绑定收款
  6607. $detail = $iDetail;
  6608. $iridString = "";
  6609. if (empty ( $detail ['irid'] ))
  6610. $iridString = $irid;
  6611. else
  6612. $iridString = $detail ['irid'] . ',' . $irid;
  6613. $item = array (
  6614. 'irid' => $iridString,
  6615. 'iid' => $detail ['iid']
  6616. );
  6617. $invoice->setInvoiceByCondition ( $item );
  6618. // 汇总
  6619. $invoiceStatistics = new invoiceStatistics ();
  6620. // 扣除入账统计金额
  6621. $item = array (
  6622. 'date' => $value ['receivablesDate'],
  6623. 'priceClass' => 3,
  6624. 'cid' => $sDetail ['cid'],
  6625. 'staff' => $sDetail ['sid'],
  6626. // 'irid' => $irid,
  6627. 'accountPrice' => $value ['receivablesPrice']
  6628. );
  6629. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6630. }
  6631. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6632. echo 'data count ' . count ( $exlArray );
  6633. die ();
  6634. // return "/keyonline";
  6635. }
  6636. echo 'no file';
  6637. }
  6638. function formatExcelToArrayTrain($file_url = "") {
  6639. if (! file_exists ( $file_url )) {
  6640. return array ();
  6641. }
  6642. // Doo::loadClass ( 'PHPExcel' );
  6643. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6644. $PHPExcel = new PHPExcel ();
  6645. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6646. if (! $PHPReader->canRead ( $file_url )) {
  6647. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6648. if (! $PHPReader->canRead ( $file_url )) {
  6649. echo 'no Excel';
  6650. return;
  6651. }
  6652. }
  6653. $PHPExcel = $PHPReader->load ( $file_url );
  6654. /* * 读取excel文件中的第一个工作表 */
  6655. $currentSheet = $PHPExcel->getSheet ( 0 );
  6656. /* * 取得最大的列号 */
  6657. $allColumn = $currentSheet->getHighestColumn ();
  6658. /* * 取得一共有多少行 */
  6659. $allRow = $currentSheet->getHighestRow ();
  6660. $excel_array = array ();
  6661. // die($file_url);
  6662. $conk = 2;
  6663. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6664. $excel_column = array ();
  6665. // 后期改进
  6666. if ($allColumn == 'AM')
  6667. $allColumn = 'Z';
  6668. /* * 从第A列开始输出 */
  6669. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6670. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6671. if ($val instanceof PHPExcel_RichText)
  6672. $val = $val->__toString ();
  6673. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6674. // $val = "'" . addslashes ( $val ) . "'";
  6675. if ($currentColumn == 'A') {
  6676. $excel_column ['invoiceTitle'] = $val;
  6677. } elseif ($currentColumn == 'B')
  6678. $excel_column ['invoiceType'] = $val;
  6679. elseif ($currentColumn == 'C') {
  6680. $excel_column ['TIN'] = $val;
  6681. } elseif ($currentColumn == 'D') {
  6682. $excel_column ['address'] = $val;
  6683. } elseif ($currentColumn == 'E') {
  6684. $excel_column ['phone'] = $val;
  6685. } elseif ($currentColumn == 'F') {
  6686. $excel_column ['bank'] = $val;
  6687. } elseif ($currentColumn == 'G') {
  6688. $excel_column ['bankAccount'] = $val;
  6689. } elseif ($currentColumn == 'H') {
  6690. $excel_column ['invoiceElement'] = $val;
  6691. } elseif ($currentColumn == 'I') {
  6692. $excel_column ['invoiceQuantity'] = $val;
  6693. } elseif ($currentColumn == 'J') {
  6694. $excel_column ['invoiceUnitPrice'] = $val;
  6695. } elseif ($currentColumn == 'K') {
  6696. $excel_column ['remark'] = $val;
  6697. } elseif ($currentColumn == 'L') {
  6698. $excel_column ['recipientsAddress'] = $val;
  6699. } elseif ($currentColumn == 'M') {
  6700. $excel_column ['recipients'] = $val;
  6701. } elseif ($currentColumn == 'N') {
  6702. $excel_column ['recipientsPhone'] = $val;
  6703. }
  6704. }
  6705. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6706. array_push ( $excel_array, $excel_column );
  6707. }
  6708. return $excel_array;
  6709. }
  6710. /**
  6711. * 格式化excel文件为数组
  6712. * @param unknown_type $file_url
  6713. * @param unknown_type $mcid
  6714. */
  6715. function _format_excel_to_array($file_url = "", $sType = "") {
  6716. if (! file_exists ( $file_url )) {
  6717. return array ();
  6718. }
  6719. Doo::loadClass ( 'PHPExcel' );
  6720. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6721. $PHPExcel = new PHPExcel ();
  6722. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6723. if (! $PHPReader->canRead ( $file_url )) {
  6724. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6725. if (! $PHPReader->canRead ( $file_url )) {
  6726. echo 'no Excel';
  6727. return;
  6728. }
  6729. }
  6730. $PHPExcel = $PHPReader->load ( $file_url );
  6731. /* * 读取excel文件中的第一个工作表 */
  6732. $currentSheet = $PHPExcel->getSheet ( 0 );
  6733. /* * 取得最大的列号 */
  6734. $allColumn = $currentSheet->getHighestColumn ();
  6735. /* * 取得一共有多少行 */
  6736. $allRow = $currentSheet->getHighestRow ();
  6737. $excel_array = array ();
  6738. // die($file_url);
  6739. $conk = 2;
  6740. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6741. $excel_column = array ();
  6742. // 后期改进
  6743. if ($allColumn == 'AM')
  6744. $allColumn = 'Z';
  6745. /* * 从第A列开始输出 */
  6746. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6747. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6748. if ($val instanceof PHPExcel_RichText)
  6749. $val = $val->__toString ();
  6750. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6751. // $val = "'" . addslashes ( $val ) . "'";
  6752. if ($sType == 'invoiceReceivables') {
  6753. if ($currentColumn == 'A')
  6754. $excel_column ['invoiceNo'] = $val;
  6755. elseif ($currentColumn == 'B')
  6756. $excel_column ['receivablesPrice'] = $val;
  6757. elseif ($currentColumn == 'C') {
  6758. $excel_column ['receivablesMessage'] = $val;
  6759. } elseif ($currentColumn == 'D') {
  6760. $excel_column ['receivablesBank'] = $val;
  6761. } elseif ($currentColumn == 'E') {
  6762. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6763. } elseif ($currentColumn == 'F') {
  6764. $excel_column ['receivablesStaff'] = $val;
  6765. } elseif ($currentColumn == 'G') {
  6766. $excel_column ['sourcePrice'] = $val;
  6767. }
  6768. } elseif ($sType == "invoiceTrain") {
  6769. if ($currentColumn == 'A') {
  6770. $excel_column ['invoiceTitle'] = $val;
  6771. } elseif ($currentColumn == 'B')
  6772. $excel_column ['invoiceType'] = $val;
  6773. elseif ($currentColumn == 'C') {
  6774. $excel_column ['TIN'] = $val;
  6775. } elseif ($currentColumn == 'D') {
  6776. $excel_column ['address'] = $val;
  6777. } elseif ($currentColumn == 'E') {
  6778. $excel_column ['phone'] = $val;
  6779. } elseif ($currentColumn == 'F') {
  6780. $excel_column ['bank'] = $val;
  6781. } elseif ($currentColumn == 'G') {
  6782. $excel_column ['bankAccount'] = $val;
  6783. } elseif ($currentColumn == 'H') {
  6784. $excel_column ['invoiceElement'] = $val;
  6785. } elseif ($currentColumn == 'I') {
  6786. $excel_column ['invoiceQuantity'] = $val;
  6787. } elseif ($currentColumn == 'J') {
  6788. $excel_column ['invoiceUnitPrice'] = $val;
  6789. } elseif ($currentColumn == 'K') {
  6790. $excel_column ['remark'] = $val;
  6791. } elseif ($currentColumn == 'L') {
  6792. $excel_column ['recipientsAddress'] = $val;
  6793. } elseif ($currentColumn == 'M') {
  6794. $excel_column ['recipients'] = $val;
  6795. } elseif ($currentColumn == 'N') {
  6796. $excel_column ['recipientsPhone'] = $val;
  6797. }
  6798. } else {
  6799. if ($currentColumn == 'A')
  6800. $excel_column ['invoiceNo'] = $val;
  6801. elseif ($currentColumn == 'B')
  6802. $excel_column ['invoiceType'] = $val;
  6803. elseif ($currentColumn == 'C') {
  6804. $excel_column ['invoicePrice'] = $val;
  6805. } elseif ($currentColumn == 'D') {
  6806. $excel_column ['invoiceTitle'] = $val;
  6807. } elseif ($currentColumn == 'E') {
  6808. $excel_column ['userName'] = $val;
  6809. } elseif ($currentColumn == 'F') {
  6810. $excel_column ['categoryName'] = $val;
  6811. } elseif ($currentColumn == 'G') {
  6812. $excel_column ['invoiceElement'] = $val;
  6813. } elseif ($currentColumn == 'H') {
  6814. $excel_column ['remark'] = $val;
  6815. } elseif ($currentColumn == 'I') {
  6816. $excel_column ['date'] = $this->excelTime ( $val );
  6817. }
  6818. }
  6819. }
  6820. array_push ( $excel_array, $excel_column );
  6821. }
  6822. return $excel_array;
  6823. }
  6824. function excelTime($date, $time = false) {
  6825. if (function_exists ( 'GregorianToJD' )) {
  6826. if (is_numeric ( $date )) {
  6827. $jd = GregorianToJD ( 1, 1, 1970 );
  6828. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6829. $date = explode ( '/', $gregorian );
  6830. $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" : '');
  6831. return $date_str;
  6832. }
  6833. } else {
  6834. $date = $date > 25568 ? $date + 1 : 25569;
  6835. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6836. $ofs = (70 * 365 + 17 + 2) * 86400;
  6837. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6838. }
  6839. return $date;
  6840. }
  6841. /**
  6842. * 旧输入导入
  6843. */
  6844. function _GetFileEXT($filename) {
  6845. $pics = explode ( '.', $filename );
  6846. $num = count ( $pics );
  6847. return $pics [$num - 1];
  6848. }
  6849. function showCache($path = "", $sid = 0) {
  6850. // if (file_exists ( $path )) {
  6851. // $htm = file_get_contents ( $path );
  6852. // } else {
  6853. Doo::loadModel ( 'invoiceStatistics' );
  6854. $invoiceStatistics = new invoiceStatistics ();
  6855. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6856. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6857. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6858. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6859. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6860. /*
  6861. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6862. */
  6863. file_put_contents ( $path, $htm );
  6864. // }
  6865. return $htm;
  6866. }
  6867. /**
  6868. * 生成token
  6869. * @return string
  6870. */
  6871. function set_token() {
  6872. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  6873. $str = sha1 ( $str ); // 加密
  6874. return $str;
  6875. }
  6876. /**
  6877. * 获取get或者POST值
  6878. *
  6879. * @param string $name 属性名称
  6880. * @return fixed 值
  6881. */
  6882. function get_args($name) {
  6883. if (isset ( $_GET [$name] )) {
  6884. if (is_array ( $_GET [$name] ))
  6885. return $_GET [$name];
  6886. else
  6887. return addslashes ( $_GET [$name] );
  6888. } elseif (isset ( $_POST [$name] )) {
  6889. if (is_array ( $_POST [$name] ))
  6890. return $_POST [$name];
  6891. else
  6892. return addslashes ( $_POST [$name] );
  6893. } else
  6894. return false;
  6895. }
  6896. function SafeFilter(&$arr) {
  6897. $ra = Array (
  6898. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6899. '/script/',
  6900. '/javascript/',
  6901. '/vbscript/',
  6902. '/expression/',
  6903. '/applet/',
  6904. '/meta/',
  6905. '/xml/',
  6906. '/blink/',
  6907. '/link/',
  6908. '/style/',
  6909. '/embed/',
  6910. '/object/',
  6911. '/frame/',
  6912. '/layer/',
  6913. '/title/',
  6914. '/bgsound/',
  6915. '/base/',
  6916. '/onload/',
  6917. '/onunload/',
  6918. '/onchange/',
  6919. '/onsubmit/',
  6920. '/onreset/',
  6921. '/onselect/',
  6922. '/onblur/',
  6923. '/onfocus/',
  6924. '/onabort/',
  6925. '/onkeydown/',
  6926. '/onkeypress/',
  6927. '/onkeyup/',
  6928. '/onclick/',
  6929. '/ondblclick/',
  6930. '/onmousedown/',
  6931. '/onmousemove/',
  6932. '/onmouseout/',
  6933. '/onmouseover/',
  6934. '/onmouseup/',
  6935. '/onunload/'
  6936. );
  6937. if (is_array ( $arr )) {
  6938. foreach ( $arr as $key => $value ) {
  6939. if (! is_array ( $value )) {
  6940. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6941. {
  6942. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6943. }
  6944. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6945. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6946. } else {
  6947. SafeFilter ( $arr [$key] );
  6948. }
  6949. }
  6950. }
  6951. }
  6952. /**
  6953. * Escape String
  6954. *
  6955. * @access public
  6956. * @param string
  6957. * @param bool whether or not the string will be used in a LIKE condition
  6958. * @return string
  6959. */
  6960. function escape_str($str, $like = FALSE) {
  6961. if (is_array ( $str )) {
  6962. foreach ( $str as $key => $val ) {
  6963. $str [$key] = $this->escape_str ( $val, $like );
  6964. }
  6965. return $str;
  6966. }
  6967. var_dump ( Doo::db ()->getDbObject () );
  6968. die ();
  6969. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6970. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6971. } elseif (function_exists ( 'mysql_escape_string' )) {
  6972. $str = mysql_escape_string ( $str );
  6973. } else {
  6974. $str = addslashes ( $str );
  6975. }
  6976. // escape LIKE condition wildcards
  6977. if ($like === TRUE) {
  6978. $str = str_replace ( array (
  6979. '%',
  6980. '_'
  6981. ), array (
  6982. '\\%',
  6983. '\\_'
  6984. ), $str );
  6985. }
  6986. return $str;
  6987. }
  6988. /**
  6989. * 获得分页数据
  6990. * @param unknown_type $table
  6991. * @param unknown_type $condition
  6992. * @param unknown_type $on_page
  6993. * @param unknown_type $page_size
  6994. */
  6995. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6996. $page_c = "";
  6997. $page ['previous'] = $this->get_previous ( $on_page );
  6998. $page ['on_page'] = $on_page;
  6999. $total_count = $this->get_table_count ( $table, $condition );
  7000. $total = intval ( $total_count / $page_size );
  7001. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7002. $page ['total_data'] = $total_count;
  7003. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7004. $i = 1;
  7005. $page_max = 1;
  7006. $page_width = 3;
  7007. if ($on_page >= $page_width) {
  7008. $page_max = intval ( $on_page / $page_width ) + 1;
  7009. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7010. }
  7011. for(; $i <= $page ['total_page']; $i ++) {
  7012. if ($i == $on_page)
  7013. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7014. else
  7015. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7016. if ($i == ($page_width * $page_max))
  7017. break;
  7018. }
  7019. $page ['page'] = $page_c;
  7020. $page ['lower'] = (-- $on_page) * $page_size;
  7021. return $page;
  7022. }
  7023. /**
  7024. * 获取上一页
  7025. * @param unknown_type $on_page
  7026. */
  7027. function get_previous($on_page = 1) {
  7028. return $on_page != 0 ? $on_page - 1 : $on_page;
  7029. }
  7030. /**
  7031. * 获取总页数
  7032. * @param unknown_type $table
  7033. * @param unknown_type $condition
  7034. */
  7035. public function get_table_count($table = "", $condition = "") {
  7036. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7037. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7038. // echo $sql;die;
  7039. $query = Doo::db ()->query ( $sql );
  7040. $result = $query->fetch ();
  7041. return $result ['count'];
  7042. }
  7043. /**
  7044. * 获得分页数据
  7045. * @param unknown_type $table
  7046. * @param unknown_type $condition
  7047. * @param unknown_type $on_page
  7048. * @param unknown_type $page_size
  7049. */
  7050. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7051. $page_c = "";
  7052. $page ['previous'] = $this->get_previous ( $on_page );
  7053. $page ['on_page'] = $on_page;
  7054. $total_count = $this->getTableCountBySql ( $sql );
  7055. $total = intval ( $total_count / $page_size );
  7056. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7057. $page ['total_data'] = $total_count;
  7058. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7059. $i = 1;
  7060. $page_max = 1;
  7061. $page_width = 3;
  7062. if ($on_page >= $page_width) {
  7063. $page_max = intval ( $on_page / $page_width ) + 1;
  7064. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7065. }
  7066. for(; $i <= $page ['total_page']; $i ++) {
  7067. if ($i == $on_page)
  7068. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7069. else
  7070. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7071. if ($i == ($page_width * $page_max))
  7072. break;
  7073. }
  7074. $page ['page'] = $page_c;
  7075. $page ['lower'] = (-- $on_page) * $page_size;
  7076. return $page;
  7077. }
  7078. /**
  7079. * 获得总页数 sql
  7080. * @param string $type
  7081. * @return boolean[]
  7082. */
  7083. public function getTableCountBySql($sql = "") {
  7084. $query = Doo::db ()->query ( $sql );
  7085. $result = $query->fetchAll ();
  7086. return count ( $result );
  7087. }
  7088. function isInvoiceNew($type = "GLOBAL") {
  7089. Doo::loadModel ( 'invoice' );
  7090. $invoice = new invoice ();
  7091. Doo::loadModel ( 'invoiceReceivables' );
  7092. $invoiceReceivables = new invoiceReceivables ();
  7093. Doo::loadModel ( 'staff' );
  7094. $staff = new staff ();
  7095. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7096. // 我的发票待处理
  7097. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7098. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7099. 'desc' => 'iid',
  7100. 'asArray' => TRUE
  7101. ) );
  7102. // 我的收款待入账
  7103. /*
  7104. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7105. */
  7106. // 发票审批
  7107. $approval = $invoice->getOne ( array (
  7108. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7109. 'desc' => 'iid',
  7110. 'asArray' => true
  7111. ) );
  7112. // 发票邮寄
  7113. $post = $invoice->getOne ( array (
  7114. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7115. 'asArray' => TRUE
  7116. ) );
  7117. // 发票打印
  7118. $print = $invoice->getOne ( array (
  7119. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7120. 'desc' => 'iid',
  7121. 'asArray' => TRUE
  7122. ) );
  7123. // 发票退票 printStatus=1 and
  7124. $untread = $invoice->getOne ( array (
  7125. 'where' => " untreadStatus=1 and status=2 ",
  7126. 'asArray' => TRUE
  7127. ) );
  7128. $new = array (
  7129. 'GLOBAL' => FALSE,
  7130. 'pendingInvoice' => FALSE,
  7131. // 'myClaim' => FALSE,
  7132. 'approval' => FALSE,
  7133. 'post' => FALSE,
  7134. 'print' => FALSE,
  7135. 'untread' => FALSE
  7136. );
  7137. // || ! empty ( $myClaim )
  7138. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7139. $new ['GLOBAL'] = TRUE;
  7140. if (! empty ( $pendingInvoice ))
  7141. $new ['pendingInvoice'] = TRUE;
  7142. // if (! empty ( $myClaim ))
  7143. // $new ['myClaim'] = TRUE;
  7144. if (! empty ( $approval ))
  7145. $new ['approval'] = TRUE;
  7146. if (! empty ( $post ))
  7147. $new ['post'] = TRUE;
  7148. if (! empty ( $print ))
  7149. $new ['print'] = TRUE;
  7150. if (! empty ( $untread ))
  7151. $new ['untread'] = TRUE;
  7152. return $new;
  7153. }
  7154. function setWXMsg($rid, $typeMsg = '') {
  7155. Doo::loadModel ( 'invoice' );
  7156. $invoice = new invoice ();
  7157. $invoiceDetail = $invoice->getOne ( array (
  7158. 'where' => 'iid=' . $rid,
  7159. 'asArray' => true
  7160. ) );
  7161. if (! empty ( $invoiceDetail )) {
  7162. Doo::loadModel ( 'staff' );
  7163. $staff = new staff ();
  7164. $staffmsg = $staff->getOne ( array (
  7165. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7166. 'asArray' => TRUE
  7167. ) );
  7168. if (! empty ( $staffmsg ['wxid'] )) {
  7169. require_once (SITE_PATH . '/protected/class/client.php');
  7170. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7171. $user = $staffmsg ['wxid'];
  7172. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7173. if (empty ( $expCom ))
  7174. $expCom [0] = '';
  7175. $msg = "";
  7176. if (empty ( $typeMsg ))
  7177. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7178. elseif ($typeMsg == "PRINT")
  7179. $msg = '太好了,您的发票已打印完成。';
  7180. $result = $client->SendMsg ( $user, $msg, 'text' );
  7181. }
  7182. }
  7183. }
  7184. /**
  7185. * 获取微信部门
  7186. * @param string $category
  7187. * @return number|mixed
  7188. */
  7189. function getToparty($category = '') {
  7190. $token = $this->getAccessToken (); //
  7191. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7192. $toparty = 0;
  7193. foreach ( $result ['department'] as $key => $value ) {
  7194. if ($value ['name'] == $category)
  7195. $toparty = $value ['id'];
  7196. }
  7197. return $toparty;
  7198. }
  7199. /**
  7200. * 获得某部门下的用户
  7201. * @param string $toparty
  7202. */
  7203. function getUserByToparty($toparty = '') {
  7204. $token = $this->getAccessToken (); //
  7205. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7206. $userList = array ();
  7207. foreach ( $result ['userlist'] as $key => $value ) {
  7208. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7209. }
  7210. return $userList;
  7211. }
  7212. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7213. $token = $this->getAccessToken ();
  7214. if ($text == 'text') {
  7215. $data = '{
  7216. "touser": "' . $toparty . '",
  7217. "toparty": "",
  7218. "totag": "",
  7219. "msgtype": "text",
  7220. "agentid": 1000002,
  7221. "text": {
  7222. "content": "' . $msg . '"
  7223. },
  7224. "safe":0
  7225. }';
  7226. }
  7227. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7228. if ($result->errmsg != 'ok') {
  7229. return 0;
  7230. } else {
  7231. return 1;
  7232. }
  7233. }
  7234. /**
  7235. * 获得可以发送微信用户列表
  7236. * @param string $category
  7237. * @return string
  7238. */
  7239. function getWxidByCategory($category = "") {
  7240. if (empty ( $category ))
  7241. return "";
  7242. Doo::loadModel ( 'staff' );
  7243. $staff = new staff ();
  7244. $toparty = $this->getToparty ( $category );
  7245. $wxList = array ();
  7246. $wxString = "";
  7247. if (! empty ( $toparty )) {
  7248. $userList = $this->getUserByToparty ( $toparty );
  7249. $userCon = implode ( ',', $userList );
  7250. // echo $userCon;
  7251. $sidList = $staff->getStaffByWxid ( $userCon );
  7252. foreach ( $sidList as $key => $value ) {
  7253. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7254. if ($falg) {
  7255. array_push ( $wxList, $value ['wxid'] );
  7256. }
  7257. }
  7258. $wxString = implode ( '|', $wxList );
  7259. }
  7260. return $wxString;
  7261. }
  7262. /**
  7263. * 读取发送信息规则判断是否需要发送
  7264. * @param number $sid
  7265. * @param string $sendType
  7266. * @return boolean
  7267. */
  7268. function isSendNotification($sid = 0, $sendType = '') {
  7269. Doo::loadModel ( "notificationConf" );
  7270. $notificationConf = new notificationConf ();
  7271. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7272. $conf = array ();
  7273. $sendFlag = true;
  7274. if (! empty ( $detail )) {
  7275. $conf = json_decode ( $detail ['conf'], true );
  7276. if (! empty ( $sendType )) {
  7277. if (isset ( $conf [$sendType] )) {
  7278. if ($conf [$sendType] == "CLOSE")
  7279. $sendFlag = false;
  7280. elseif ($conf [$sendType] == "Weekend") {
  7281. $day = date ( "w" );
  7282. if (1 <= $day && 5 >= $day)
  7283. $sendFlag = false;
  7284. } elseif ($conf [$sendType] == "OneToFriday") {
  7285. $day = date ( "w" );
  7286. if (0 == $day || 6 == $day)
  7287. $sendFlag = false;
  7288. }
  7289. }
  7290. } else
  7291. $sendFlag = false;
  7292. }
  7293. return $sendFlag;
  7294. }
  7295. /**
  7296. * 根据规则发送信息
  7297. * @param unknown $msg
  7298. * @param unknown $title
  7299. * @param unknown $url
  7300. * @param unknown $user
  7301. * @param string $text
  7302. * @return number
  7303. */
  7304. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7305. $token = $this->getAccessToken ();
  7306. $falg = $this->isSendNotification ( $sid, $sendType );
  7307. // if ($text == 'text') {
  7308. // $data = '{
  7309. // "touser": "' . $user . '",
  7310. // "toparty": "",
  7311. // "totag": "",
  7312. // "msgtype": "text",
  7313. // "agentid": 1000002,
  7314. // "text": {
  7315. // "content": "' . $msg . '"
  7316. // },
  7317. // "safe":0
  7318. // }';
  7319. // } else {
  7320. $data = '{
  7321. "touser": "' . $user . '",
  7322. "toparty": "",
  7323. "totag": "",
  7324. "msgtype": "news",
  7325. "agentid": 1000002,
  7326. "news": {
  7327. "articles":[
  7328. {
  7329. "title": "' . $title . '",
  7330. "description": "' . $msg . '",
  7331. "url": "' . $url . '",
  7332. "picurl": ""
  7333. }
  7334. ]
  7335. }
  7336. }';
  7337. // }
  7338. if ($falg) {
  7339. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7340. if ($result->errmsg != 'ok') {
  7341. return 0;
  7342. } else {
  7343. return 1;
  7344. }
  7345. } else
  7346. return 0;
  7347. }
  7348. private function getAccessToken() {
  7349. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7350. // $file = './access_token.txt';
  7351. // $data = json_decode ( file_get_contents ( $file ) );
  7352. // if ($data->expire_time < time () or ! $data->expire_time) {
  7353. // 如果是企业号用以下URL获取access_token
  7354. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7355. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7356. $res = json_decode ( $this->httpGet ( $url ) );
  7357. $access_token = $res->access_token;
  7358. // echo $access_token;
  7359. // if ($access_token) {
  7360. // $data->expire_time = time () + 7000;
  7361. // $data->access_token = $access_token;
  7362. // $fp = fopen ( $file, "w" );
  7363. // fwrite ( $fp, json_encode ( $data ) );
  7364. // fclose ( $fp );
  7365. // }
  7366. // } else {
  7367. // $access_token = $data->access_token;
  7368. // }
  7369. return $access_token;
  7370. }
  7371. private function httpGet($url) {
  7372. $curl = curl_init ();
  7373. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7374. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7375. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7376. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7377. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7378. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7379. curl_setopt ( $curl, CURLOPT_URL, $url );
  7380. $res = curl_exec ( $curl );
  7381. curl_close ( $curl );
  7382. return $res;
  7383. }
  7384. private function httpPost($url, $data) {
  7385. $curl = curl_init ();
  7386. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7387. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7388. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7389. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7390. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7391. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7392. curl_setopt ( $curl, CURLOPT_URL, $url );
  7393. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7394. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7395. $res = curl_exec ( $curl );
  7396. curl_close ( $curl );
  7397. return $res;
  7398. }
  7399. }
  7400. ?>