InvoiceController.php 329 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request-iacd' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. //echo $routeRs ['1'];
  102. //die('dd');
  103. if (isset ( $_COOKIE ["staff"] )) {
  104. if (! empty ( $_COOKIE ["staff"] )) {
  105. Doo::loadModel ( 'staff' );
  106. $staff = new staff ();
  107. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  108. $this->ACTION = $uriPartsOrig [1];
  109. $this->data ['new'] = $this->isInvoiceNew ();
  110. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  111. $this->data ['isStaffCompleteMsg'] = false;
  112. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  113. if (! empty ( $detail ))
  114. $this->data ['isStaffCompleteMsg'] = true;
  115. return "/";
  116. }
  117. }
  118. Doo::loadCore ( 'uri/DooUriRouter' );
  119. $router = new DooUriRouter ();
  120. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  121. if ($routeRs ['1'] != "login") {
  122. header ( 'Content-Type:text/html;charset=utf-8' );
  123. @header ( "Location: /login" );
  124. }
  125. }
  126. function testSend() {
  127. // 测试根据规则发送信息 普通发送
  128. // $pendingApprovalsSid = 41;
  129. // Doo::loadModel ( 'staff' );
  130. // $staff = new staff ();
  131. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  132. // // 发送微信审批通知
  133. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  134. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  135. // Doo::loadModel ( 'staff' );
  136. // $staff = new staff ();
  137. // $toparty = $this->getToparty ( '广东办' );
  138. // $wxList = array ();
  139. // if (! empty ( $toparty )) {
  140. // $userList = $this->getUserByToparty ( $toparty );
  141. // $userCon = implode ( ',', $userList );
  142. // // echo $userCon;
  143. // $sidList = $staff->getStaffByWxid ( $userCon );
  144. // foreach ( $sidList as $key => $value ) {
  145. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  146. // if ($falg) {
  147. // array_push ( $wxList, $value ['wxid'] );
  148. // }
  149. // }
  150. // $wxString = implode ( '|', $wxList );
  151. // print_r ( $wxList );
  152. // echo $wxString;
  153. // }
  154. // 测试发送
  155. /*
  156. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  157. */
  158. // print_r ( $userList );
  159. // $msTouser='caipin|outaozhen';
  160. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  161. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  162. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  163. // $toparty= $this->getToparty('广东办');
  164. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  165. // $toparty = 26;
  166. // $msg = '';
  167. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  168. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  169. }
  170. function invoice() {
  171. Doo::loadModel ( 'invoice' );
  172. $invoice = new invoice ();
  173. Doo::loadModel ( 'express' );
  174. $express = new express ();
  175. $expressList = $express->getExpressByAll ();
  176. $this->data ['expressList'] = $expressList;
  177. // Doo::loadModel ( 'invoiceReceivables' );
  178. // $invoiceReceivables = new invoiceReceivables ();
  179. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  180. Doo::loadClass ( 'XDeode' );
  181. $XDeode = new XDeode ( 5 );
  182. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  183. Doo::loadModel ( 'invoiceStatistics' );
  184. $invoiceStatistics = new invoiceStatistics ();
  185. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  186. // 缓存统计结果
  187. $year = date ( "Y" );
  188. $tmp_date = date ( "Ym" );
  189. $tmp_year = substr ( $tmp_date, 0, 4 );
  190. $tmp_mon = substr ( $tmp_date, 4, 2 );
  191. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  192. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  193. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  194. if (is_file ( $path ))
  195. $htm = file_get_contents ( $path );
  196. else
  197. $htm = $this->showCache ( $path, $sid );
  198. $invoiceList = $invoice->getMyInvoice ( $sid );
  199. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  200. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  201. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  202. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  203. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  204. // 获得已退票功能
  205. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  206. $this->data ['untreadStatusList'] = $untreadStatusList;
  207. // print_r($untreadStatusList);
  208. $this->data ['isMonth'] = $isMonth;
  209. $this->data ['htm'] = $htm;
  210. $this->data ['invoiceList'] = $invoiceList;
  211. $this->data ['receivablesList'] = $list;
  212. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  213. $this->data ['memu'] = "invoice";
  214. $this->data ['staff'] = $this->staff;
  215. $this->data ['receiptMemu'] = 'invoice';
  216. $this->render ( "/admin/invoice", $this->data );
  217. }
  218. function invoiceExpress() {
  219. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  220. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  221. $this->data ['expressCom'] = $expressCom;
  222. $this->data ['expressNumber'] = $expressNumber;
  223. $this->render ( "/admin/invoiceExpress", $this->data );
  224. }
  225. function invoiceAdd() {
  226. session_start ();
  227. /*Doo::loadModel ( 'invoice' );
  228. $invoice = new invoice ();
  229. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  230. Doo::loadModel ( 'L_category' );
  231. $lCategory = new L_category ();
  232. $category = $lCategory->find ( array (
  233. 'asArray' => true
  234. ) );
  235. $this->data ['category'] = $category;
  236. Doo::loadModel ( 'invoiceTraining' );
  237. $invoiceTraining = new invoiceTraining ();
  238. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  239. Doo::loadModel ( 'receipt' );
  240. $receipt = new receipt ();
  241. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  242. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  243. if (! empty ( $receiptDetail )) {
  244. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  245. unset ( $itList [$key] );
  246. }
  247. }
  248. }
  249. $this->data ['itList'] = $itList;
  250. $token = $this->set_token ();
  251. $tokenTime=time().rand(5, 15);
  252. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  253. $this->data ['token'] = $token;
  254. $this->data['tokenTime']=$tokenTime;
  255. $this->data ['memu'] = "invoice";
  256. $this->data ['staff'] = $this->staff;
  257. $this->data ['receiptMemu'] = 'invoice';
  258. $this->render ( "/admin/invoiceAdd", $this->data );
  259. }
  260. /**
  261. * 自更新发票信息库
  262. * @param unknown $invoicePrintDetail
  263. */
  264. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  265. // 发票信息库
  266. Doo::loadModel ( 'invoiceInfoBase' );
  267. $invoiceInfoBase = new invoiceInfoBase ();
  268. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  269. $TIN = $invoicePrintDetail ['TIN'];
  270. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  271. if (empty ( $invoiceTitle ))
  272. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  273. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  274. // 确认有该条发票信息
  275. $invoiceInfoBase = new invoiceInfoBase ();
  276. if (! empty ( $IIBList )) {
  277. // 发票库里的信息数量
  278. $IIBListCount = count ( $IIBList );
  279. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  280. $item = array (
  281. 'iibID' => $IIBList [0] ['iibID'],
  282. 'invoiceTitle' => $invoiceTitle,
  283. 'TIN' => $TIN
  284. );
  285. if (! empty ( $invoicePrintDetail ['address'] )) {
  286. $item += array (
  287. 'address' => $invoicePrintDetail ['address']
  288. );
  289. }
  290. if (! empty ( $invoicePrintDetail ['phone'] )) {
  291. $item += array (
  292. 'phone' => $invoicePrintDetail ['phone']
  293. );
  294. }
  295. if (! empty ( $invoicePrintDetail ['bank'] )) {
  296. $item += array (
  297. 'bank' => $invoicePrintDetail ['bank']
  298. );
  299. }
  300. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  301. $item += array (
  302. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  303. );
  304. }
  305. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  306. $item += array (
  307. 'updateDate' => $invoicePrintDetail ['date']
  308. );
  309. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  310. }
  311. } else { // 删除多张发票,重新添加发票
  312. $iibIDStr = '';
  313. $iibID = array ();
  314. foreach ( $IIBList as $key => $value ) {
  315. array_push ( $iibID, $value ['iibID'] );
  316. }
  317. $iibIDStr = implode ( ",", $iibID ); // 删除
  318. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  319. $item = array (
  320. 'invoiceTitle' => $invoiceTitle,
  321. 'TIN' => $TIN,
  322. 'address' => $invoicePrintDetail ['address'],
  323. 'phone' => $invoicePrintDetail ['phone'],
  324. 'bank' => $invoicePrintDetail ['bank'],
  325. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  326. 'updateDate' => $invoicePrintDetail ['date']
  327. );
  328. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  329. }
  330. } else { // 没有新增发票信息
  331. $item = array (
  332. 'invoiceTitle' => $invoiceTitle,
  333. 'TIN' => $TIN,
  334. 'address' => $invoicePrintDetail ['address'],
  335. 'phone' => $invoicePrintDetail ['phone'],
  336. 'bank' => $invoicePrintDetail ['bank'],
  337. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  338. 'updateDate' => $invoicePrintDetail ['date']
  339. );
  340. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  341. }
  342. }
  343. function invoiceAddFill() {
  344. session_start ();
  345. Doo::loadModel ( 'L_category' );
  346. $lCategory = new L_category ();
  347. $category = $lCategory->find ( array (
  348. 'asArray' => true
  349. ) );
  350. $this->data ['category'] = $category;
  351. Doo::loadModel ( 'invoiceTraining' );
  352. $invoiceTraining = new invoiceTraining ();
  353. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  354. $this->data ['itList'] = $itList;
  355. Doo::loadModel ( 'invoice' );
  356. $invoice = new invoice ();
  357. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  358. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  359. $token = $this->set_token ();
  360. $tokenTime=time().rand(5, 15);
  361. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  362. $this->data ['token'] = $token;
  363. $this->data['tokenTime']=$tokenTime;
  364. $this->data ['invoiceDetail'] = $detail;
  365. $this->data ['memu'] = "invoice";
  366. $this->data ['staff'] = $this->staff;
  367. $this->data ['receiptMemu'] = 'invoice';
  368. $this->render ( "/admin/invoiceAddFill", $this->data );
  369. }
  370. /**
  371. * 提交一份开票申请,并记录下操作日志
  372. *
  373. * @since 1.0.0
  374. * @var integer cid 办事处ID
  375. * @var integer invoiceType 发票类型
  376. * @var integer doPost 是否邮寄
  377. * @var integer invoicePrice 开票金额
  378. * @var string invoiceElement 开票内容
  379. * @var string invoiceTitle 发票抬头
  380. * @var string invoiceCompany 单位名称
  381. * @var string TIN 纳税人识别码
  382. * @var string address 注册地址
  383. * @var string phone 注册电话
  384. * @var string bank 开户银行
  385. * @var string bankAccount 银行账户
  386. * @var string recipients 收件人
  387. * @var string recipientsPhone 收件人手机/电话
  388. * @var string recipientsAddress 收件地址
  389. * @var string mailItems 邮寄物品
  390. * @var string remark 备注
  391. * @return string 返回跳转开票主页路径
  392. */
  393. function invoiceAddDo() {
  394. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  395. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  396. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  397. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  398. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  399. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  400. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  401. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  402. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  403. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  404. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  405. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  406. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  407. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  408. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  409. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  410. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  411. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  412. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  413. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  414. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  415. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  416. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  417. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  418. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  419. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  420. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  421. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  422. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  423. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  424. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  425. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  426. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  427. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  428. $electronicPhone= $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  429. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  430. /*
  431. * $mailList=array(); array_push($mailList, array('invoice'=>1)); array_push($mailList, array('mailItems'=>$mailItems)); if (!empty($softLock)) array_push($mailList, array('softLock'=>$softLockNum)); if (!empty($contract)) array_push($mailList, array('contract'=>$contractNum)); if (!empty($instructions)) array_push($mailList, array('instructions'=>$instructionsNum)); if (!empty($remittance)) array_push($mailList, array('remittance'=>$remittance)); echo json_encode($mailList) ; print_r($mailList); die;
  432. */
  433. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  434. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  435. if (empty ( $token )) {
  436. die ( 'illegal request-token' );
  437. } else {
  438. session_start ();
  439. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  440. header ( 'Content-Type:text/html;charset=utf-8' );
  441. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  442. die ( '请重新刷新发票申请页面' );
  443. }elseif($_SESSION [$sessionKey]=='repeat'){
  444. die ( '请勿重复申请发票' );
  445. } else {
  446. if ($_SESSION [$sessionKey] != $token){
  447. die ( '请勿重复申请发票' );
  448. }else{
  449. $_SESSION [$sessionKey] = 'repeat';
  450. }
  451. }
  452. }
  453. if($invoiceForm=='electronic'){
  454. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  455. die ( '请至少填写一种联系方式--电子发票' );
  456. }
  457. }
  458. if ($invoiceType == 1) {
  459. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  460. if ($temporary > 100001) {
  461. header ( 'Content-Type:text/html;charset=utf-8' );
  462. die ( '专用发票总金额暂时不能超过100000.00(一万)元。' );
  463. // die ( 'illegal request-Please priceError' );
  464. }
  465. }elseif($invoiceType == 0){
  466. }else{
  467. die ( 'illegal request-invoiceType' );
  468. }
  469. if (empty ( $this->staff [0] ))
  470. die ( 'illegal request-Please login' );
  471. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  472. Doo::loadModel ( 'invoice' );
  473. $invoice = new invoice ();
  474. Doo::loadModel ( 'L_category' );
  475. $lCategory = new L_category ();
  476. Doo::loadModel ( 'invoiceManage' );
  477. $invoiceManage = new invoiceManage ();
  478. Doo::loadModel ( 'invoiceOperationLog' );
  479. $invoiceOperationLog = new invoiceOperationLog ();
  480. Doo::loadClass ( 'XDeode' );
  481. $XDeode = new XDeode ( 5 );
  482. $trainId = $XDeode->decode ( $trainId );
  483. $categoryDetil = $lCategory->getOne ( array (
  484. 'SELECT' => 'title',
  485. 'where' => 'cid=' . $cid,
  486. 'asArray' => true
  487. ) );
  488. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  489. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  490. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  491. // print_r(current($invoiceManageDetail ['staffList']));
  492. // die;
  493. $moldManage = array ();
  494. foreach ( $invoiceManageList as $key => $value ) {
  495. if ($value ['mold'] == '发票打印')
  496. $moldManage [$value ['mold']] = $value ['staffList'];
  497. elseif ($value ['mold'] == '发票邮寄')
  498. $moldManage [$value ['mold']] = $value ['staffList'];
  499. elseif ($value ['mold'] == '发票退票')
  500. $moldManage [$value ['mold']] = $value ['staffList'];
  501. }
  502. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  503. $st = '';
  504. if ($settlementType == 'SOFTWARE') {
  505. $st = 0;
  506. $trainId = 0;
  507. } elseif ($settlementType == 'TRAINING') {
  508. $st = 1;
  509. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  510. die ( 'illegal request-trainingIdError' );
  511. }
  512. } else {
  513. die ( 'illegal request-settlementError' );
  514. }
  515. if($invoiceForm=='electronic'){
  516. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  517. $invoiceForm=1;
  518. $invoiceType=0;
  519. if(!empty($electronicPhone)||!empty($electronicEmail)){
  520. }else{
  521. die ( 'illegal request-electronicContact' );
  522. }
  523. $mailList = array ();
  524. $mailString = '备注:' . $mailItems;
  525. }elseif($invoiceForm=='paper'){
  526. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  527. $invoiceForm=0;
  528. $mailList = array (
  529. 'invoice' => 1,
  530. 'mailItems' => $mailItems
  531. );
  532. $mailString = '发票x1张,备注:' . $mailItems;
  533. }else{
  534. die ( 'illegal request-invoiceForm' );
  535. }
  536. $item = array (
  537. 'cid' => $cid,
  538. 'categoryName' => $categoryDetil ['title'],
  539. 'invoiceElement' => $invoiceElement,
  540. 'invoiceForm'=>$invoiceForm,
  541. 'electronicPhone'=>$electronicPhone,
  542. 'electronicEmail'=>$electronicEmail,
  543. 'invoiceQuantity' => $invoiceQuantity,
  544. 'invoiceUnitPrice' => $invoiceUnitPrice,
  545. 'invoicePrice' => $invoicePrice,
  546. 'invoiceType' => $invoiceType,
  547. 'settlementType' => $st,
  548. 'doPost' => $doPost,
  549. 'status' => 1,
  550. 'invoiceSerial' => $invoiceSerial,
  551. 'date' => date ( "Y-m-d H:i:s" ),
  552. 'updateTime' => date ( "Y-m-d H:i:s" ),
  553. 'sid' => $this->staff [0] ['sid'],
  554. 'userName' => $this->staff [0] ['username'],
  555. 'invoiceManage' => $invoiceManageDetail ['staff'],
  556. 'pendingApprovals' => $pendingApprovalsSid,
  557. 'moldManage' => json_encode ( $moldManage ),
  558. 'remark' => $remark,
  559. 'trainId' => $trainId
  560. );
  561. if ($invoiceType == 0)
  562. $item += array (
  563. 'invoiceTitle' => $invoiceTitle,
  564. 'TIN' => $TINT,
  565. 'address' => $addressT,
  566. 'phone' => $phoneT,
  567. 'bank' => $bankT,
  568. 'bankAccount' => $bankAccountT
  569. );
  570. else {
  571. $item += array (
  572. 'invoiceCompany' => $invoiceCompany,
  573. 'TIN' => $TIN,
  574. 'address' => $address,
  575. 'phone' => $phone,
  576. 'bank' => $bank,
  577. 'bankAccount' => $bankAccount
  578. );
  579. }
  580. if ($doPost == 1) {
  581. if (! empty ( $softLock ))
  582. $mailList += array (
  583. 'softLock' => $softLockNum
  584. );
  585. else
  586. $mailList += array (
  587. 'softLock' => 0
  588. );
  589. if (! empty ( $contract ))
  590. $mailList += array (
  591. 'contract' => $contractNum
  592. );
  593. else
  594. $mailList += array (
  595. 'contract' => 0
  596. );
  597. if (! empty ( $instructions ))
  598. $mailList += array (
  599. 'instructions' => $instructionsNum
  600. );
  601. else
  602. $mailList += array (
  603. 'instructions' => 0
  604. );
  605. if (! empty ( $remittance ))
  606. $mailList += array (
  607. 'remittance' => $remittance
  608. );
  609. else
  610. $mailList += array (
  611. 'remittance' => ''
  612. );
  613. if (! empty ( $softLock ))
  614. $mailString .= ',软件锁x' . $softLockNum . '个';
  615. if (! empty ( $contract ))
  616. $mailString .= ',合同x' . $contractNum . '份';
  617. if (! empty ( $instructions ))
  618. $mailString .= ',说明书x' . $instructionsNum . '本';
  619. if (! empty ( $remittance ))
  620. $mailString .= ',汇款账号单(张)';
  621. $item += array (
  622. 'recipients' => $recipients,
  623. 'recipientsPhone' => $recipientsPhone,
  624. 'recipientsAddress' => $recipientsAddress,
  625. 'mailItems' => $mailString,
  626. 'mailItemsJson' => json_encode ( $mailList )
  627. );
  628. }
  629. $iid = $invoice->addInvoice ( $item );
  630. // 如果是培训班结算 创建培训班发票到培训班备份中
  631. if (! empty ( $st ) && $st == 1) {
  632. Doo::loadModel ( 'invoiceStore' );
  633. $invoiceStore = new invoiceStore ();
  634. Doo::loadModel ( 'invoiceTraining' );
  635. $invoiceTraining = new invoiceTraining ();
  636. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  637. $itemIS = array (
  638. 'isid' => $isid,
  639. 'ipSource' => 1,
  640. 'apStatus' => 1,
  641. 'iid' => $iid
  642. );
  643. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  644. // 更新培训班总数量
  645. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  646. $item = array (
  647. 'itid' => $trainId,
  648. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  649. 'submitStatus' => 1
  650. );
  651. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  652. }
  653. // 操作日志
  654. $item = array (
  655. 'date' => date ( "Y-m-d H:i:s" ),
  656. 'operation' => "创建",
  657. 'status' => 1,
  658. 'img' => $this->staff [0] ['avatar'],
  659. 'username' => $this->staff [0] ['username'],
  660. 'uid' => $this->staff [0] ['sid'],
  661. 'category' => $this->staff [0] ['category'],
  662. 'iid' => $iid
  663. );
  664. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  665. $item = array (
  666. 'date' => date ( "Y-m-d H:i:s" ),
  667. 'operation' => "提交审批",
  668. 'status' => 1,
  669. 'img' => $this->staff [0] ['avatar'],
  670. 'username' => $this->staff [0] ['username'],
  671. 'uid' => $this->staff [0] ['sid'],
  672. 'category' => $this->staff [0] ['category'],
  673. 'iid' => $iid
  674. );
  675. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  676. Doo::loadModel ( 'staff' );
  677. $staff = new staff ();
  678. $username2 = $staff->getOne ( array (
  679. 'select' => 'wxid',
  680. 'where' => 'sid=' . $pendingApprovalsSid,
  681. 'asArray' => TRUE
  682. ) );
  683. // 发送微信审批通知
  684. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  685. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  686. }
  687. return "/invoice";
  688. }
  689. function invoiceEdit() {
  690. Doo::loadClass ( 'XDeode' );
  691. $XDeode = new XDeode ( 5 );
  692. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  693. $iid = $XDeode->decode ( $iid );
  694. if (! is_numeric ( $iid ))
  695. die ( 'illegal request' );
  696. Doo::loadModel ( 'invoice' );
  697. $invoice = new invoice ();
  698. Doo::loadModel ( 'invoiceOperationLog' );
  699. $invoiceOperationLog = new invoiceOperationLog ();
  700. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  701. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  702. $invoiceDetail ['mailItemsJson'] ='';
  703. if(isset($invoiceDetail ['mailItemsJson'])){
  704. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  705. }
  706. $this->data ['operation'] = $operation;
  707. $this->data ['invoiceDetail'] = $invoiceDetail;
  708. $this->data ['memu'] = "invoice";
  709. $this->data ['staff'] = $this->staff;
  710. $this->data ['receiptMemu'] = 'invoice';
  711. $this->render ( "/admin/invoiceEdit", $this->data );
  712. }
  713. /**
  714. * 重新编辑退回的发票
  715. * @return string
  716. */
  717. function invoiceEditDo() {
  718. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  719. Doo::loadModel ( 'invoice' );
  720. $invoice = new invoice ();
  721. $iid = $invoice->authcode ( $iidKey );
  722. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  723. die ( 'illegal request' );
  724. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  725. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  726. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  727. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  728. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  729. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  730. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  731. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  732. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  733. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  734. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  735. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  736. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  737. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  738. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  739. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  740. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  741. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  742. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  743. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  744. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  745. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  746. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  747. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  748. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  749. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  750. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  751. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  752. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  753. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  754. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  755. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  756. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  757. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  758. if ($invoiceType == 1) {
  759. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  760. if ($temporary > 100001)
  761. die ( 'illegal request-Please priceError' );
  762. }
  763. if($invoiceForm=='electronic'){
  764. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  765. die ( '请至少填写一种联系方式--电子发票' );
  766. }
  767. }
  768. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  769. Doo::loadModel ( 'invoiceManage' );
  770. $invoiceManage = new invoiceManage ();
  771. Doo::loadModel ( 'invoiceOperationLog' );
  772. $invoiceOperationLog = new invoiceOperationLog ();
  773. Doo::loadModel ( 'invoiceStore' );
  774. $invoiceStore = new invoiceStore ();
  775. $cid = explode ( ':', $cid );
  776. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  777. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  778. $moldManage = array ();
  779. foreach ( $invoiceManageList as $key => $value ) {
  780. if ($value ['mold'] == '发票打印')
  781. $moldManage [$value ['mold']] = $value ['staffList'];
  782. elseif ($value ['mold'] == '发票邮寄')
  783. $moldManage [$value ['mold']] = $value ['staffList'];
  784. elseif ($value ['mold'] == '发票打印')
  785. $moldManage [$value ['mold']] = $value ['staffList'];
  786. }
  787. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  788. if($invoiceForm=='electronic'){
  789. $invoiceForm=1;
  790. $invoiceType=0;
  791. if(!empty($electronicPhone)||!empty($electronicEmail)){
  792. }else{
  793. die ( 'illegal request-electronicContact' );
  794. }
  795. $mailList = array ();
  796. $mailString = '备注:' . $mailItems;
  797. }elseif($invoiceForm=='paper'){
  798. $invoiceForm=0;
  799. $mailList = array (
  800. 'invoice' => 1,
  801. 'mailItems' => $mailItems
  802. );
  803. $mailString = '发票x1张,备注:' . $mailItems;
  804. }else{
  805. die ( 'illegal request-invoiceForm' );
  806. }
  807. $item = array (
  808. 'iid' => $iid,
  809. 'cid' => $cid [0],
  810. 'categoryName' => $cid [1],
  811. 'invoiceElement' => $invoiceElement,
  812. 'invoiceForm'=>$invoiceForm,
  813. 'electronicPhone'=>$electronicPhone,
  814. 'electronicEmail'=>$electronicEmail,
  815. 'invoiceQuantity' => $invoiceQuantity,
  816. 'invoiceUnitPrice' => $invoiceUnitPrice,
  817. 'invoicePrice' => $invoicePrice,
  818. 'invoiceType' => $invoiceType,
  819. 'doPost' => $doPost,
  820. 'status' => 1,
  821. 'updateTime' => date ( "Y-m-d H:i:s" ),
  822. 'remark' => $remark
  823. );
  824. if ($invoiceType == 0)
  825. $item += array (
  826. 'invoiceTitle' => $invoiceTitle,
  827. 'TIN' => $TINT,
  828. 'address' => $addressT,
  829. 'phone' => $phoneT,
  830. 'bank' => $bankT,
  831. 'bankAccount' => $bankAccountT
  832. );
  833. else {
  834. $item += array (
  835. 'invoiceCompany' => $invoiceCompany,
  836. 'TIN' => $TIN,
  837. 'address' => $address,
  838. 'phone' => $phone,
  839. 'bank' => $bank,
  840. 'bankAccount' => $bankAccount
  841. );
  842. }
  843. if ($doPost == 1) {
  844. if (! empty ( $softLock ))
  845. $mailList += array (
  846. 'softLock' => $softLockNum
  847. );
  848. else
  849. $mailList += array (
  850. 'softLock' => '0'
  851. );
  852. if (! empty ( $contract ))
  853. $mailList += array (
  854. 'contract' => $contractNum
  855. );
  856. else
  857. $mailList += array (
  858. 'contract' => '0'
  859. );
  860. if (! empty ( $instructions ))
  861. $mailList += array (
  862. 'instructions' => $instructionsNum
  863. );
  864. else
  865. $mailList += array (
  866. 'instructions' => '0'
  867. );
  868. if (! empty ( $remittance ))
  869. $mailList += array (
  870. 'remittance' => $remittance
  871. );
  872. else
  873. $mailList += array (
  874. 'remittance' => ''
  875. );
  876. if (! empty ( $softLock ))
  877. $mailString .= ',软件锁x' . $softLockNum;
  878. if (! empty ( $contract ))
  879. $mailString .= ',合同x' . $contractNum;
  880. if (! empty ( $instructions ))
  881. $mailString .= ',说明书x' . $instructionsNum;
  882. if (! empty ( $remittance ))
  883. $mailString .= ',汇款账号单';
  884. $item += array (
  885. 'recipients' => $recipients,
  886. 'recipientsPhone' => $recipientsPhone,
  887. 'recipientsAddress' => $recipientsAddress,
  888. 'mailItems' => $mailString,
  889. 'mailItemsJson' => json_encode ( $mailList )
  890. );
  891. }
  892. $invoice->setInvoiceByCondition ( $item );
  893. // 更新培训班仓库里的发票
  894. $detail = $invoice->getInvoiceByIid ( $iid );
  895. if (! empty ( $detail ['isid'] )) {
  896. $invoiceStore->isid = $detail ['isid'];
  897. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  898. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  899. $invoiceStore->invoicePrice = $invoicePrice;
  900. $invoiceStore->update ();
  901. }
  902. $item = array (
  903. 'date' => date ( "Y-m-d H:i:s" ),
  904. 'operation' => "重新提交审批",
  905. 'status' => 1,
  906. 'img' => $this->staff [0] ['avatar'],
  907. 'username' => $this->staff [0] ['username'],
  908. 'uid' => $this->staff [0] ['sid'],
  909. 'category' => $this->staff [0] ['category'],
  910. 'iid' => $iid
  911. );
  912. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  913. }
  914. return "/invoice";
  915. }
  916. /**
  917. * 培训班
  918. */
  919. function invoiceTraining() {
  920. Doo::loadModel ( 'L_category' );
  921. $lCategory = new L_category ();
  922. Doo::loadModel ( 'invoiceTraining' );
  923. $invoiceTraining = new invoiceTraining ();
  924. Doo::loadModel ( 'invoiceTrainManage' );
  925. $invoiceTrainManage = new invoiceTrainManage ();
  926. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  927. $cidList = array ();
  928. foreach ( $imcStaff as $key => $value ) {
  929. array_push ( $cidList, $value ['cid'] );
  930. }
  931. if (empty ( $cidList )) {
  932. $cidString = $this->staff [0] ['cid'];
  933. } else {
  934. $cidString = implode ( ',', $cidList );
  935. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  936. }
  937. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  938. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  939. $category = $lCategory->getCategory ();
  940. $itid = array ();
  941. foreach ( $itTodoList as $key => $value ) {
  942. array_push ( $itid, $value ['itid'] );
  943. // 如果入账100%更新为已完成
  944. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  945. $invoiceTraining = new invoiceTraining ();
  946. $invoiceTraining->itid = $value ['itid'];
  947. $invoiceTraining->status = 2;
  948. $invoiceTraining->update ();
  949. }
  950. }
  951. foreach ( $itedList as $value ) {
  952. array_push ( $itid, $value ['itid'] );
  953. }
  954. $itid = implode ( ',', $itid );
  955. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  956. // print_r($itTodoList);
  957. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  958. $this->data ['itTodoList'] = $itTodoList;
  959. $this->data ['itedList'] = $itedList;
  960. $this->data ['category'] = $category;
  961. $this->data ['memu'] = "invoice";
  962. $this->data ['staff'] = $this->staff;
  963. $this->data ['receiptMemu'] = 'invoiceTraining';
  964. $this->render ( "/admin/invoiceTraining", $this->data );
  965. }
  966. /**
  967. * 创建培训班
  968. */
  969. function invoiceTrainingAdd() {
  970. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  971. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  972. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  973. if (empty ( $this->staff [0] ))
  974. die ( 'illegal request' );
  975. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  976. Doo::loadModel ( 'invoiceTraining' );
  977. $invoiceTraining = new invoiceTraining ();
  978. Doo::loadModel ( 'invoice' );
  979. $invoice = new invoice ();
  980. Doo::loadModel ( 'L_category' );
  981. $lCategory = new L_category ();
  982. Doo::loadModel ( 'invoiceManage' );
  983. $invoiceManage = new invoiceManage ();
  984. Doo::loadModel ( 'invoiceOperationLog' );
  985. $invoiceOperationLog = new invoiceOperationLog ();
  986. $item = array (
  987. 'cid' => $cid,
  988. 'trainName' => $trainName,
  989. 'trainDate' => $trainDate,
  990. 'creator' => $this->staff [0] ['sid'],
  991. 'creatorDate' => date ( "Y-m-d H:i:s" )
  992. );
  993. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  994. }
  995. return "/invoiceTraining";
  996. }
  997. /**
  998. * 删除培训班
  999. */
  1000. function invoiceTrainingDelDo() {
  1001. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1002. if (! empty ( $itid )) {
  1003. Doo::loadModel ( 'invoiceTraining' );
  1004. $invoiceTraining = new invoiceTraining ();
  1005. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1006. }
  1007. return "/invoiceTraining";
  1008. }
  1009. /**
  1010. * 培训班详情
  1011. */
  1012. function invoiceTrainingDetail() {
  1013. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1014. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1015. Doo::loadModel ( 'invoiceTraining' );
  1016. $invoiceTraining = new invoiceTraining ();
  1017. Doo::loadModel ( 'invoiceStore' );
  1018. $invoiceStore = new invoiceStore ();
  1019. if (empty ( $itid ))
  1020. die ( 'illegal request' );
  1021. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1022. if ($trainStatus == "SUBED")
  1023. $con = ' (b.untreadStatus is null ) and ';
  1024. elseif ($trainStatus == "APPROVAL")
  1025. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1026. elseif ($trainStatus == "TICKET")
  1027. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1028. elseif ($trainStatus == "TICKETING") {
  1029. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1030. }
  1031. $con.=' a.invoiceForm=0 and ';
  1032. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1033. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1034. //print_r($isList);
  1035. $trainlistJson=$this->_trainList($isList);
  1036. if (empty ( $detail ))
  1037. die ( 'illegal request' );
  1038. // 培训班结算是否有和是否已经结算完成
  1039. Doo::loadModel ( 'receipt' );
  1040. $receipt = new receipt ();
  1041. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1042. $this->data ['receiptDetail'] = $receiptDetail;
  1043. $this->data ['trainStatus'] = $trainStatus;
  1044. $this->data ['itid'] = $itid;
  1045. $this->data ['trainlistJson'] = $trainlistJson;
  1046. $this->data ['iTrainDetail'] = $detail;
  1047. $this->data ['memu'] = "invoice";
  1048. $this->data ['staff'] = $this->staff;
  1049. $this->data ['receiptMemu'] = 'invoiceTraining';
  1050. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1051. }
  1052. function invoiceTrainingElectronicDetail(){
  1053. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1054. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1055. Doo::loadModel ( 'invoiceTraining' );
  1056. $invoiceTraining = new invoiceTraining ();
  1057. Doo::loadModel ( 'invoiceStore' );
  1058. $invoiceStore = new invoiceStore ();
  1059. if (empty ( $itid ))
  1060. die ( 'illegal request' );
  1061. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1062. if ($trainStatus == "SUBED")
  1063. $con = ' (b.untreadStatus is null ) and ';
  1064. elseif ($trainStatus == "APPROVAL")
  1065. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1066. elseif ($trainStatus == "TICKET")
  1067. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1068. elseif ($trainStatus == "TICKETING") {
  1069. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1070. }
  1071. $con.=' a.invoiceForm=1 and ';
  1072. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1073. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1074. //print_r($isList);
  1075. if (empty ( $detail )){
  1076. die ( 'illegal request' );
  1077. }
  1078. $trainlistJson=$this->_trainList($isList,1);
  1079. // 培训班结算是否有和是否已经结算完成
  1080. Doo::loadModel ( 'receipt' );
  1081. $receipt = new receipt ();
  1082. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1083. $this->data ['receiptDetail'] = $receiptDetail;
  1084. $this->data ['trainStatus'] = $trainStatus;
  1085. $this->data ['itid'] = $itid;
  1086. $this->data ['trainlistJson'] = $trainlistJson;
  1087. $this->data ['iTrainDetail'] = $detail;
  1088. $this->data ['memu'] = "invoice";
  1089. $this->data ['staff'] = $this->staff;
  1090. $this->data ['receiptMemu'] = 'invoiceTraining';
  1091. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1092. }
  1093. function _trainList($isList,$type=0){
  1094. $trainlist = array ();
  1095. foreach ( $isList as $key => $value ) {
  1096. $irDetail = array ();
  1097. if ($value ['apStatus'] == 1) {
  1098. // array_push ( $irDetail, '' );
  1099. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1100. } else {
  1101. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1102. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1103. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1104. }
  1105. array_push ( $irDetail, $value ['invoiceSerial'] );
  1106. if ($value ['invoiceType'] == 1)
  1107. array_push ( $irDetail, $value ['invoiceCompany'] );
  1108. else
  1109. array_push ( $irDetail, $value ['invoiceTitle'] );
  1110. array_push ( $irDetail, $value ['TIN'] );
  1111. array_push ( $irDetail, $value ['userName'] );
  1112. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1113. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1114. } else
  1115. array_push ( $irDetail, $value ['mailItems'] );
  1116. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1117. if($type==1){
  1118. array_push ( $irDetail, $value ['electronicPhone'] );
  1119. array_push ( $irDetail, $value ['electronicEmail'] );
  1120. }
  1121. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1122. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1123. array_push ( $irDetail, $value ['invoiceElement'] );
  1124. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1125. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1126. if ($value ['invoiceType'] == 1)
  1127. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1128. else
  1129. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1130. array_push ( $irDetail, $value ['remark'] );
  1131. if ($value ['status'] == 1)
  1132. array_push ( $irDetail, '审批中' );
  1133. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1134. array_push ( $irDetail, '已出票' );
  1135. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1136. array_push ( $irDetail, '已入账' );
  1137. else
  1138. array_push ( $irDetail, '' );
  1139. array_push ( $irDetail, $value ['invoiceNo'] );
  1140. array_push ( $irDetail, $value ['printTime'] );
  1141. $html = '';
  1142. foreach ( $value ['invoiceReceivables'] as $v ) {
  1143. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1144. }
  1145. array_push ( $irDetail, $html );
  1146. array_push ( $trainlist, $irDetail );
  1147. }
  1148. $trainlistJson = json_encode ( $trainlist );
  1149. return $trainlistJson;
  1150. }
  1151. /**
  1152. * 上传培训班发票
  1153. * @return string
  1154. */
  1155. function invoiceTrainingUpload() {
  1156. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1157. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1158. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1159. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1160. header ( "HTTP/1.1 500 Internal Server Error" );
  1161. echo "POST exceeded maximum allowed size.";
  1162. exit ( 0 );
  1163. }
  1164. // Settings
  1165. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceTraining/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  1166. $upload_name = "Filedata";
  1167. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1168. $extension_whitelist = array (
  1169. "doc",
  1170. "txt",
  1171. "jpg",
  1172. "gif",
  1173. "png"
  1174. ); // Allowed file extensions
  1175. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1176. // Other variables
  1177. $MAX_FILENAME_LENGTH = 260;
  1178. $file_name = "";
  1179. $file_extension = "";
  1180. $uploadErrors = array (
  1181. 0 => "文件上传成功",
  1182. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1183. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1184. 3 => "上传的文件仅为部分文件",
  1185. 4 => "没有文件上传",
  1186. 6 => "缺少临时文件夹"
  1187. );
  1188. $nk = time ();
  1189. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1190. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1191. echo "文件无法保存.";
  1192. exit ( 0 );
  1193. }
  1194. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1195. echo json_encode ( array (
  1196. 'filename' => $file_name,
  1197. 'id' => $nk
  1198. ) );
  1199. exit ( 0 );
  1200. }
  1201. /**
  1202. * 导入发票临时仓库
  1203. */
  1204. function invoiceStoreImport() {
  1205. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1206. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1207. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1208. if ($path != "" && ! empty ( $trainingKey )) {
  1209. Doo::loadModel ( 'invoiceStore' );
  1210. Doo::loadModel ( 'staff' );
  1211. $staff = new staff ();
  1212. Doo::loadModel ( 'invoiceTraining' );
  1213. $invoiceTraining = new invoiceTraining ();
  1214. Doo::loadClass ( 'XDeode' );
  1215. $XDeode = new XDeode ( 5 );
  1216. $itid = $XDeode->decode ( $trainingKey );
  1217. // 培训班结算是否有和是否已经结算完成
  1218. Doo::loadModel ( 'receipt' );
  1219. $receipt = new receipt ();
  1220. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1221. if (! empty ( $receiptDetail )) {
  1222. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1223. die ( 'illegal request--status' );
  1224. }
  1225. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1226. $userName = $this->staff [0] ['username'];
  1227. $sDetail = $staff->getStaffByName ( $userName );
  1228. //print_r($exlArray);die;
  1229. // die('sdd');
  1230. // 可以优化
  1231. foreach ( $exlArray as $key => $value ) {
  1232. // 开票
  1233. $invoice = new invoiceStore ();
  1234. $invoice->trainId = $itid;
  1235. $invoice->invoiceType = 0;
  1236. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1237. $invoice->invoiceType = 1;
  1238. elseif($value ['invoiceType'] == '电子'){
  1239. $invoice->invoiceType = 0;
  1240. $invoice->invoiceForm=1;
  1241. }
  1242. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1243. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1244. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1245. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1246. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1247. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1248. $invoice->userName = $userName;
  1249. $invoice->sid = $sDetail ['sid'];
  1250. $invoice->cid = $sDetail ['cid'];
  1251. $invoice->categoryName = $sDetail ['category'];
  1252. $invoice->invoiceElement = $value ['invoiceElement'];
  1253. $invoice->remark = $value ['remark'];
  1254. // $invoice->date = $value ['date'];
  1255. // $invoice->printTime = $value ['date'];
  1256. $invoice->ipSource = 1;
  1257. $invoice->printStatus = 0;
  1258. $invoice->status = 0;
  1259. $invoice->postStatus = 1;
  1260. $invoice->untreadStatus = 0;
  1261. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1262. $invoice->TIN = $value ['TIN'];
  1263. $invoice->address = $value ['address'];
  1264. $invoice->phone = $value ['phone'];
  1265. $invoice->bank = $value ['bank'];
  1266. $invoice->bankAccount = $value ['bankAccount'];
  1267. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1268. $invoice->recipients = $value ['recipients'];
  1269. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1270. $invoice->electronicPhone = $value ['electronicPhone'];
  1271. $invoice->electronicEmail = $value ['electronicEmail'];
  1272. $iid = $invoice->insert ();
  1273. }
  1274. // 加入发票总数量
  1275. $item = array (
  1276. 'itid' => $itid,
  1277. 'invoiceTotal' => count ( $exlArray )
  1278. );
  1279. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1280. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1281. }
  1282. echo 'no file';
  1283. }
  1284. /**
  1285. * 编辑仓库里的发票
  1286. */
  1287. function invoiceStoreEdit() {
  1288. Doo::loadClass ( 'XDeode' );
  1289. $XDeode = new XDeode ( 5 );
  1290. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1291. $iid = $XDeode->decode ( $iid );
  1292. if (! is_numeric ( $iid ))
  1293. die ( 'illegal request' );
  1294. Doo::loadModel ( 'invoiceStore' );
  1295. $invoiceStore = new invoiceStore ();
  1296. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1297. // print_r($invoiceDetail);
  1298. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1299. $this->data ['invoiceDetail'] = $invoiceDetail;
  1300. $this->data ['memu'] = "invoice";
  1301. $this->data ['staff'] = $this->staff;
  1302. $this->data ['receiptMemu'] = 'invoiceTraining';
  1303. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1304. }
  1305. function invoiceStoreEditDo() {
  1306. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1307. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1308. Doo::loadModel ( 'invoiceStore' );
  1309. $invoice = new invoiceStore ();
  1310. Doo::loadClass ( 'XDeode' );
  1311. $XDeode = new XDeode ( 5 );
  1312. $iid = $XDeode->decode ( $storeKey );
  1313. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1314. die ( 'illegal request' );
  1315. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1316. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1317. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1318. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1319. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1320. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1321. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1322. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1323. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1324. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1325. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1326. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1327. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1328. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1329. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1330. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1331. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1332. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1333. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1334. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1335. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1336. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1337. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1338. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1339. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1340. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1341. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1342. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1343. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1344. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1345. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1346. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1347. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1348. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1349. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1350. $cid = explode ( ':', $cid );
  1351. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1352. $item = array (
  1353. 'isid' => $iid,
  1354. 'cid' => $cid [0],
  1355. 'categoryName' => $cid [1],
  1356. 'invoiceElement' => $invoiceElement,
  1357. 'invoiceQuantity' => $invoiceQuantity,
  1358. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1359. 'invoicePrice' => $invoicePrice,
  1360. 'invoiceType' => $invoiceType,
  1361. 'doPost' => $doPost,
  1362. 'status' => 1,
  1363. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1364. 'remark' => $remark
  1365. );
  1366. if ($invoiceType == 0)
  1367. $item += array (
  1368. 'invoiceTitle' => $invoiceTitle,
  1369. 'TIN' => $TINT,
  1370. 'address' => $addressT,
  1371. 'phone' => $phoneT,
  1372. 'bank' => $bankT,
  1373. 'bankAccount' => $bankAccountT
  1374. );
  1375. else {
  1376. $item += array (
  1377. 'invoiceCompany' => $invoiceCompany,
  1378. 'TIN' => $TIN,
  1379. 'address' => $address,
  1380. 'phone' => $phone,
  1381. 'bank' => $bank,
  1382. 'bankAccount' => $bankAccount
  1383. );
  1384. }
  1385. if($invoiceForm=='paper'){
  1386. $item += array (
  1387. 'invoiceForm' => 0
  1388. );
  1389. }elseif($invoiceForm=='electronic'){
  1390. $item += array (
  1391. 'invoiceForm' => 1,
  1392. 'electronicPhone' => $electronicPhone,
  1393. 'electronicEmail' => $electronicEmail,
  1394. );
  1395. }
  1396. if ($doPost == 1) {
  1397. $mailList = array (
  1398. 'invoice' => 1,
  1399. 'mailItems' => $mailItems
  1400. );
  1401. if (! empty ( $softLock ))
  1402. $mailList += array (
  1403. 'softLock' => $softLockNum
  1404. );
  1405. else
  1406. $mailList += array (
  1407. 'softLock' => '0'
  1408. );
  1409. if (! empty ( $contract ))
  1410. $mailList += array (
  1411. 'contract' => $contractNum
  1412. );
  1413. else
  1414. $mailList += array (
  1415. 'contract' => '0'
  1416. );
  1417. if (! empty ( $instructions ))
  1418. $mailList += array (
  1419. 'instructions' => $instructionsNum
  1420. );
  1421. else
  1422. $mailList += array (
  1423. 'instructions' => '0'
  1424. );
  1425. if (! empty ( $remittance ))
  1426. $mailList += array (
  1427. 'remittance' => $remittance
  1428. );
  1429. else
  1430. $mailList += array (
  1431. 'remittance' => ''
  1432. );
  1433. $mailString = '发票x1,备注:' . $mailItems;
  1434. if (! empty ( $softLock ))
  1435. $mailString .= ',软件锁x' . $softLockNum;
  1436. if (! empty ( $contract ))
  1437. $mailString .= ',合同x' . $contractNum;
  1438. if (! empty ( $instructions ))
  1439. $mailString .= ',说明书x' . $instructionsNum;
  1440. if (! empty ( $remittance ))
  1441. $mailString .= ',汇款账号单';
  1442. $item += array (
  1443. 'recipients' => $recipients,
  1444. 'recipientsPhone' => $recipientsPhone,
  1445. 'recipientsAddress' => $recipientsAddress,
  1446. 'mailItems' => $mailString,
  1447. 'mailItemsJson' => json_encode ( $mailList )
  1448. );
  1449. }
  1450. $invoice->setInvoiceStoreByCondition ( $item );
  1451. }
  1452. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1453. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1454. }else{
  1455. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1456. }
  1457. }
  1458. /**
  1459. *
  1460. * @return string
  1461. */
  1462. function invoiceStoreDelete() {
  1463. Doo::loadClass ( 'XDeode' );
  1464. $XDeode = new XDeode ( 5 );
  1465. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1466. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1467. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1468. $isid = $XDeode->decode ( $iStoreKey );
  1469. $itid = $XDeode->decode ( $trainKey );
  1470. if (! is_numeric ( $isid ))
  1471. die ( 'illegal request' );
  1472. Doo::loadModel ( 'invoiceStore' );
  1473. $invoiceStore = new invoiceStore ();
  1474. $invoiceStore->delete ( array (
  1475. 'where' => 'isid=' . $isid,
  1476. 'limit' => 1
  1477. ) );
  1478. Doo::loadModel ( 'invoiceTraining' );
  1479. $invoiceTraining = new invoiceTraining ();
  1480. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1481. $item = array (
  1482. 'itid' => $itid,
  1483. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1484. );
  1485. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1486. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1487. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1488. }else{
  1489. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1490. }
  1491. }
  1492. /**
  1493. * 批量删除库里发票
  1494. */
  1495. function invoiceStoreBatchDelete() {
  1496. Doo::loadClass ( 'XDeode' );
  1497. $XDeode = new XDeode ( 5 );
  1498. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1499. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1500. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1501. if (empty ( $trainKey ) || empty ( $storeKey ))
  1502. die ( 'illegal request-IdKey' );
  1503. $tid = $XDeode->decode ( $trainKey );
  1504. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1505. die ( 'illegal request' );
  1506. Doo::loadModel ( 'invoiceStore' );
  1507. $isidKeyList = explode ( ',', $storeKey );
  1508. $isidList = array ();
  1509. foreach ( $isidKeyList as $value ) {
  1510. $isid = $XDeode->decode ( $value );
  1511. if (! empty ( $isid ) && is_numeric ( $isid ))
  1512. array_push ( $isidList, $isid );
  1513. }
  1514. $isidString = implode ( ',', $isidList );
  1515. $invoiceStore = new invoiceStore ();
  1516. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1517. $isidList = array ();
  1518. foreach ( $isList as $key => $value ) {
  1519. if ($value ['apStatus'] == 0)
  1520. array_push ( $isidList, $value ['isid'] );
  1521. }
  1522. $isidString = implode ( ',', $isidList );
  1523. // print_r($isList);
  1524. // echo $isidString;
  1525. $invoiceStore = new invoiceStore ();
  1526. $invoiceStore->delete ( array (
  1527. 'where' => "isid in ( " . $isidString . ")",
  1528. 'asArray' => TRUE
  1529. ) );
  1530. Doo::loadModel ( 'invoiceTraining' );
  1531. $invoiceTraining = new invoiceTraining ();
  1532. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1533. $item = array (
  1534. 'itid' => $tid,
  1535. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1536. );
  1537. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1538. // echo $tid;
  1539. // echo $storeKey;
  1540. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1541. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1542. }else{
  1543. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1544. }
  1545. }
  1546. function invoiceStoreBatchElectronicPhone(){
  1547. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1548. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1549. Doo::loadClass ( 'XDeode' );
  1550. $XDeode = new XDeode ( 5 );
  1551. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1552. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1553. if (empty ( $trainKey ) || empty ( $storeKey ))
  1554. die ( 'illegal request-IdKey' );
  1555. $isidKeyList = explode ( ',', $storeKey );
  1556. $isidList = array ();
  1557. foreach ( $isidKeyList as $value ) {
  1558. $isid = $XDeode->decode ( $value );
  1559. if (! empty ( $isid ) && is_numeric ( $isid ))
  1560. array_push ( $isidList, $isid );
  1561. }
  1562. $isidString = implode ( ',', $isidList );
  1563. $trainId = $XDeode->decode ( $trainKey );
  1564. if (! is_numeric ( $isid ))
  1565. die ( 'illegal request--isid' );
  1566. Doo::loadModel ( 'invoiceStore' );
  1567. $invoiceStore = new invoiceStore ();
  1568. $item = array (
  1569. 'electronicPhone' => $electronicPhone
  1570. );
  1571. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1572. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1573. }
  1574. function invoiceStoreBatchElectronicEmail(){
  1575. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1576. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1577. Doo::loadClass ( 'XDeode' );
  1578. $XDeode = new XDeode ( 5 );
  1579. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1580. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1581. if (empty ( $trainKey ) || empty ( $storeKey ))
  1582. die ( 'illegal request-IdKey' );
  1583. $isidKeyList = explode ( ',', $storeKey );
  1584. $isidList = array ();
  1585. foreach ( $isidKeyList as $value ) {
  1586. $isid = $XDeode->decode ( $value );
  1587. if (! empty ( $isid ) && is_numeric ( $isid ))
  1588. array_push ( $isidList, $isid );
  1589. }
  1590. $isidString = implode ( ',', $isidList );
  1591. $trainId = $XDeode->decode ( $trainKey );
  1592. if (! is_numeric ( $isid ))
  1593. die ( 'illegal request' );
  1594. Doo::loadModel ( 'invoiceStore' );
  1595. $invoiceStore = new invoiceStore ();
  1596. $item = array (
  1597. 'electronicEmail' => $electronicEmail
  1598. );
  1599. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1600. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1601. }
  1602. /**
  1603. * 仓库发票提交审批
  1604. * @return string
  1605. */
  1606. function invoiceStoreApproval() {
  1607. Doo::loadClass ( 'XDeode' );
  1608. $XDeode = new XDeode ( 5 );
  1609. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1610. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1611. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1612. $isid = $XDeode->decode ( $iStoreKey );
  1613. $trainId = $XDeode->decode ( $trainKey );
  1614. if (! is_numeric ( $isid ))
  1615. die ( 'illegal request' );
  1616. Doo::loadModel ( 'invoiceStore' );
  1617. Doo::loadModel ( 'invoice' );
  1618. $invoice = new invoice ();
  1619. // 加入限制必须填写入开票内容和邮寄物品
  1620. $invoiceStore = new invoiceStore ();
  1621. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1622. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1623. header ( 'Content-Type:text/html;charset=utf-8' );
  1624. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1625. }
  1626. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1627. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1628. header ( 'Content-Type:text/html;charset=utf-8' );
  1629. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1630. }
  1631. }
  1632. // 拷贝插入一条发票数据
  1633. $invoiceStore = new invoiceStore ();
  1634. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1635. $invoiceStore = new invoiceStore ();
  1636. $item = array (
  1637. 'isid' => $isid,
  1638. 'iid' => $iid,
  1639. 'apStatus' => 1
  1640. );
  1641. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1642. Doo::loadModel ( 'invoiceManage' );
  1643. $invoiceManage = new invoiceManage ();
  1644. Doo::loadModel ( 'invoiceOperationLog' );
  1645. $invoiceOperationLog = new invoiceOperationLog ();
  1646. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1647. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1648. $moldManage = array ();
  1649. foreach ( $invoiceManageList as $key => $value ) {
  1650. if ($value ['mold'] == '发票打印')
  1651. $moldManage [$value ['mold']] = $value ['staffList'];
  1652. elseif ($value ['mold'] == '发票邮寄')
  1653. $moldManage [$value ['mold']] = $value ['staffList'];
  1654. elseif ($value ['mold'] == '发票退票')
  1655. $moldManage [$value ['mold']] = $value ['staffList'];
  1656. }
  1657. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1658. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1659. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1660. }else{
  1661. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1662. }
  1663. $item = array (
  1664. 'iid' => $iid,
  1665. 'isid' => $isid,
  1666. 'invoiceSerial' => $invoiceSerial,
  1667. 'date' => date ( "Y-m-d H:i:s" ),
  1668. 'status' => 1,
  1669. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1670. 'trainId' => $trainId,
  1671. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1672. 'moldManage' => json_encode ( $moldManage ),
  1673. 'settlementType' => 1,
  1674. 'pendingApprovals' => $pendingApprovalsSid
  1675. );
  1676. $invoice->setInvoiceByCondition ( $item );
  1677. Doo::loadModel ( 'invoiceTraining' );
  1678. $invoiceTraining = new invoiceTraining ();
  1679. $item = array (
  1680. 'itid' => $trainId,
  1681. 'submitStatus' => 1
  1682. );
  1683. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1684. $item = array (
  1685. 'date' => date ( "Y-m-d H:i:s" ),
  1686. 'operation' => "创建",
  1687. 'status' => 1,
  1688. 'img' => $this->staff [0] ['avatar'],
  1689. 'username' => $this->staff [0] ['username'],
  1690. 'uid' => $this->staff [0] ['sid'],
  1691. 'category' => $this->staff [0] ['category'],
  1692. 'iid' => $iid
  1693. );
  1694. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1695. $item = array (
  1696. 'date' => date ( "Y-m-d H:i:s" ),
  1697. 'operation' => "提交审批",
  1698. 'status' => 1,
  1699. 'img' => $this->staff [0] ['avatar'],
  1700. 'username' => $this->staff [0] ['username'],
  1701. 'uid' => $this->staff [0] ['sid'],
  1702. 'category' => $this->staff [0] ['category'],
  1703. 'iid' => $iid
  1704. );
  1705. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1706. Doo::loadModel ( 'staff' );
  1707. $staff = new staff ();
  1708. $username2 = $staff->getOne ( array (
  1709. 'select' => 'wxid',
  1710. 'where' => 'sid=' . $pendingApprovalsSid,
  1711. 'asArray' => TRUE
  1712. ) );
  1713. // 发送微信审批通知
  1714. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1715. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1716. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1717. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1718. }else{
  1719. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1720. }
  1721. }
  1722. /**
  1723. * 批量提交发票
  1724. * @return string
  1725. */
  1726. function invoiceStoreBatchApproval() {
  1727. Doo::loadClass ( 'XDeode' );
  1728. $XDeode = new XDeode ( 5 );
  1729. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1730. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1731. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1732. if (empty ( $trainKey ) || empty ( $storeKey ))
  1733. die ( 'illegal request-IdKey' );
  1734. $trainId = $XDeode->decode ( $trainKey );
  1735. $isidKeyList = explode ( ',', $storeKey );
  1736. $isidList = array ();
  1737. foreach ( $isidKeyList as $value ) {
  1738. $isid = $XDeode->decode ( $value );
  1739. if (! empty ( $isid ) && is_numeric ( $isid ))
  1740. array_push ( $isidList, $isid );
  1741. }
  1742. $isidString = implode ( ',', $isidList );
  1743. if (! is_numeric ( $trainId ))
  1744. die ( 'illegal request' );
  1745. Doo::loadModel ( 'invoiceStore' );
  1746. Doo::loadModel ( 'invoice' );
  1747. // 判断哪些已经加入审批过
  1748. // 加入限制必须填写入开票内容和邮寄物品
  1749. $invoiceStore = new invoiceStore ();
  1750. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1751. foreach ( $isList as $key => $value ) {
  1752. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1753. header ( 'Content-Type:text/html;charset=utf-8' );
  1754. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1755. }
  1756. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1757. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1758. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1759. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1760. header ( 'Content-Type:text/html;charset=utf-8' );
  1761. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1762. }
  1763. }
  1764. }
  1765. // 拷贝插入一条发票数据
  1766. $invoiceStore = new invoiceStore ();
  1767. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1768. $invoiceStore = new invoiceStore ();
  1769. $item = array (
  1770. 'apStatus' => 1
  1771. );
  1772. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1773. // 获得正式发票ID
  1774. $invoice = new invoice ();
  1775. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1776. $sqlList = array ();
  1777. $iidString = '';
  1778. $iida = array ();
  1779. foreach ( $iidList as $key => $value ) {
  1780. $sqlList [$value ['isid']] = $value ['iid'];
  1781. array_push ( $iida, $value ['iid'] );
  1782. }
  1783. $iidString = implode ( ',', $iida );
  1784. $ids = implode ( ',', array_keys ( $sqlList ) );
  1785. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1786. foreach ( $sqlList as $id => $ordinal ) {
  1787. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1788. }
  1789. $sql .= "END WHERE isid IN ($ids)";
  1790. $invoiceStore = new invoiceStore ();
  1791. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1792. Doo::loadModel ( 'invoiceManage' );
  1793. $invoiceManage = new invoiceManage ();
  1794. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1795. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1796. $moldManage = array ();
  1797. foreach ( $invoiceManageList as $key => $value ) {
  1798. if ($value ['mold'] == '发票打印')
  1799. $moldManage [$value ['mold']] = $value ['staffList'];
  1800. elseif ($value ['mold'] == '发票邮寄')
  1801. $moldManage [$value ['mold']] = $value ['staffList'];
  1802. elseif ($value ['mold'] == '发票退票')
  1803. $moldManage [$value ['mold']] = $value ['staffList'];
  1804. }
  1805. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1806. // 批量更新发票信息
  1807. $item = array (
  1808. 'date' => date ( "Y-m-d H:i:s" ),
  1809. 'status' => 1,
  1810. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1811. 'trainId' => $trainId,
  1812. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1813. 'moldManage' => json_encode ( $moldManage ),
  1814. 'settlementType' => 1,
  1815. 'pendingApprovals' => $pendingApprovalsSid
  1816. );
  1817. $invoice = new invoice ();
  1818. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1819. // 批量更新发票中仓库isid
  1820. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1821. foreach ( $sqlList as $isid => $iid ) {
  1822. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1823. }
  1824. $sql .= "END WHERE iid IN ($iidString)";
  1825. $invoice = new invoice ();
  1826. $invoice->UpdateBatchInvoice ( $sql );
  1827. // 批量更新发票序列号
  1828. $sqlList = array ();
  1829. foreach ( $iida as $value ) {
  1830. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1831. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1832. }else{
  1833. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1834. }
  1835. }
  1836. $ids = implode ( ',', array_keys ( $sqlList ) );
  1837. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1838. foreach ( $sqlList as $id => $ordinal ) {
  1839. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1840. }
  1841. $sql .= "END WHERE iid IN ($ids)";
  1842. $invoiceStore = new invoiceStore ();
  1843. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1844. // 批量生产操作日志
  1845. Doo::loadModel ( 'invoiceOperationLog' );
  1846. $sqlList = array ();
  1847. foreach ( $iida as $key => $value ) {
  1848. $sql = '("' . date ( "Y-m-d H:i:s" ) . '","创建","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '"),
  1849. ("' . date ( "Y-m-d H:i:s" ) . '","提交审批","1","' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value . '") ';
  1850. array_push ( $sqlList, $sql );
  1851. }
  1852. $iolSql = implode ( ',', $sqlList );
  1853. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1854. $invoiceOperationLog = new invoiceOperationLog ();
  1855. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1856. Doo::loadModel ( 'invoiceTraining' );
  1857. $invoiceTraining = new invoiceTraining ();
  1858. $item = array (
  1859. 'itid' => $trainId,
  1860. 'submitStatus' => 1
  1861. );
  1862. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1863. Doo::loadModel ( 'staff' );
  1864. $staff = new staff ();
  1865. $username2 = $staff->getOne ( array (
  1866. 'select' => 'wxid',
  1867. 'where' => 'sid=' . $pendingApprovalsSid,
  1868. 'asArray' => TRUE
  1869. ) );
  1870. // 发送微信审批通知
  1871. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1872. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1873. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1874. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1875. }else{
  1876. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1877. }
  1878. }
  1879. /**
  1880. */
  1881. function invoiceStoreMailItemSet() {
  1882. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1883. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1884. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1885. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1886. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1887. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1888. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1889. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1890. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1891. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1892. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1893. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1894. Doo::loadClass ( 'XDeode' );
  1895. $XDeode = new XDeode ( 5 );
  1896. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1897. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1898. $isid = $XDeode->decode ( $storeKey );
  1899. $trainId = $XDeode->decode ( $trainKey );
  1900. if (! is_numeric ( $isid ))
  1901. die ( 'illegal request' );
  1902. Doo::loadModel ( 'invoiceStore' );
  1903. $invoiceStore = new invoiceStore ();
  1904. $mailList = array (
  1905. 'mailItems' => $mailItems
  1906. );
  1907. $mailString = '发票x1,备注:' . $mailItems;
  1908. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1909. $mailString = '备注:' . $mailItems;
  1910. }else{
  1911. $mailList += array (
  1912. 'invoice' => 1,
  1913. );
  1914. }
  1915. if (! empty ( $softLock ))
  1916. $mailList += array (
  1917. 'softLock' => $softLockNum
  1918. );
  1919. else
  1920. $mailList += array (
  1921. 'softLock' => 0
  1922. );
  1923. if (! empty ( $contract ))
  1924. $mailList += array (
  1925. 'contract' => $contractNum
  1926. );
  1927. else
  1928. $mailList += array (
  1929. 'contract' => 0
  1930. );
  1931. if (! empty ( $instructions ))
  1932. $mailList += array (
  1933. 'instructions' => $instructionsNum
  1934. );
  1935. else
  1936. $mailList += array (
  1937. 'instructions' => 0
  1938. );
  1939. if (! empty ( $remittance ))
  1940. $mailList += array (
  1941. 'remittance' => $remittance
  1942. );
  1943. else
  1944. $mailList += array (
  1945. 'remittance' => ''
  1946. );
  1947. if (! empty ( $softLock ))
  1948. $mailString .= ',软件锁x' . $softLockNum;
  1949. if (! empty ( $contract ))
  1950. $mailString .= ',合同x' . $contractNum;
  1951. if (! empty ( $instructions ))
  1952. $mailString .= ',说明书x' . $instructionsNum;
  1953. if (! empty ( $remittance ))
  1954. $mailString .= ',汇款账号单';
  1955. $item = array (
  1956. 'isid' => $isid,
  1957. 'doPost' => 1,
  1958. 'mailItems' => $mailString,
  1959. 'mailItemsJson' => json_encode ( $mailList )
  1960. );
  1961. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1962. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1963. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1964. }else{
  1965. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1966. }
  1967. }
  1968. /**
  1969. * 批量设置邮寄物品
  1970. */
  1971. function invoiceStoreBatchMailItemSet() {
  1972. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1973. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1974. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1975. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1976. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1977. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1978. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1979. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1980. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1981. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1982. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1983. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1984. Doo::loadClass ( 'XDeode' );
  1985. $XDeode = new XDeode ( 5 );
  1986. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1987. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1988. if (empty ( $trainKey ) || empty ( $storeKey ))
  1989. die ( 'illegal request-IdKey' );
  1990. $isidKeyList = explode ( ',', $storeKey );
  1991. $isidList = array ();
  1992. foreach ( $isidKeyList as $value ) {
  1993. $isid = $XDeode->decode ( $value );
  1994. if (! empty ( $isid ) && is_numeric ( $isid ))
  1995. array_push ( $isidList, $isid );
  1996. }
  1997. $isidString = implode ( ',', $isidList );
  1998. $trainId = $XDeode->decode ( $trainKey );
  1999. if (! is_numeric ( $isid ))
  2000. die ( 'illegal request' );
  2001. Doo::loadModel ( 'invoiceStore' );
  2002. $invoiceStore = new invoiceStore ();
  2003. $mailList = array (
  2004. 'mailItems' => $mailItems
  2005. );
  2006. $mailString = '发票x1,备注:' . $mailItems;
  2007. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2008. $mailString = '备注:' . $mailItems;
  2009. }else{
  2010. $mailList += array (
  2011. 'invoice' => 1,
  2012. );
  2013. }
  2014. if (! empty ( $softLock ))
  2015. $mailList += array (
  2016. 'softLock' => $softLockNum
  2017. );
  2018. else
  2019. $mailList += array (
  2020. 'softLock' => 0
  2021. );
  2022. if (! empty ( $contract ))
  2023. $mailList += array (
  2024. 'contract' => $contractNum
  2025. );
  2026. else
  2027. $mailList += array (
  2028. 'contract' => 0
  2029. );
  2030. if (! empty ( $instructions ))
  2031. $mailList += array (
  2032. 'instructions' => $instructionsNum
  2033. );
  2034. else
  2035. $mailList += array (
  2036. 'instructions' => 0
  2037. );
  2038. if (! empty ( $remittance ))
  2039. $mailList += array (
  2040. 'remittance' => $remittance
  2041. );
  2042. else
  2043. $mailList += array (
  2044. 'remittance' => ''
  2045. );
  2046. if (! empty ( $softLock ))
  2047. $mailString .= ',软件锁x' . $softLockNum;
  2048. if (! empty ( $contract ))
  2049. $mailString .= ',合同x' . $contractNum;
  2050. if (! empty ( $instructions ))
  2051. $mailString .= ',说明书x' . $instructionsNum;
  2052. if (! empty ( $remittance ))
  2053. $mailString .= ',汇款账号单';
  2054. $item = array (
  2055. 'doPost' => 1,
  2056. 'mailItems' => $mailString,
  2057. 'mailItemsJson' => json_encode ( $mailList )
  2058. );
  2059. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2060. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2061. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2062. }else{
  2063. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2064. }
  2065. }
  2066. /**
  2067. * 废弃
  2068. */
  2069. function ajaxGetMailItemByIstore() {
  2070. Doo::loadClass ( 'XDeode' );
  2071. $XDeode = new XDeode ( 5 );
  2072. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2073. $isid = $XDeode->decode ( $storeKey );
  2074. if (! is_numeric ( $isid ))
  2075. die ( 'illegal request' );
  2076. Doo::loadModel ( 'invoiceStore' );
  2077. $invoiceStore = new invoiceStore ();
  2078. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2079. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2080. echo json_encode ( $isDetail ['mailItemsJson'] );
  2081. exit ();
  2082. }
  2083. /**
  2084. * 终止开票
  2085. */
  2086. function invoiceDroppedDo() {
  2087. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2088. Doo::loadModel ( 'invoice' );
  2089. $invoice = new invoice ();
  2090. Doo::loadModel ( 'invoiceOperationLog' );
  2091. $invoiceOperationLog = new invoiceOperationLog ();
  2092. $iid = $invoice->authcode ( $droppedIidKey );
  2093. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2094. die ( 'illegal request' );
  2095. $item = array (
  2096. 'iid' => $iid,
  2097. 'status' => 4,
  2098. 'updateTime' => date ( "Y-m-d H:i:s" )
  2099. );
  2100. $invoice->setInvoiceByCondition ( $item );
  2101. $item = array (
  2102. 'date' => date ( "Y-m-d H:i:s" ),
  2103. 'operation' => '终止了开票',
  2104. 'status' => 4,
  2105. 'img' => $this->staff [0] ['avatar'],
  2106. 'username' => $this->staff [0] ['username'],
  2107. 'uid' => $this->staff [0] ['sid'],
  2108. 'category' => $this->staff [0] ['category'],
  2109. 'iid' => $iid
  2110. );
  2111. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2112. return "/invoice";
  2113. }
  2114. /**
  2115. * 更新退票的邮寄信息
  2116. */
  2117. function invoiceUntreadMailDo() {
  2118. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2119. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2120. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2121. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2122. Doo::loadModel ( 'invoice' );
  2123. $invoice = new invoice ();
  2124. $iid = $invoice->authcode ( $untreadIidKey );
  2125. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2126. die ( 'illegal request' );
  2127. $item = array (
  2128. 'iid' => $iid,
  2129. 'untreadCompany' => $untreadCompany,
  2130. 'untreadNumber' => $untreadNumber,
  2131. 'untreadItems' => $untreadItems
  2132. );
  2133. $invoice->setInvoiceByCondition ( $item );
  2134. return "/invoice";
  2135. }
  2136. /**
  2137. * 申请退票 --
  2138. */
  2139. function invoiceUntreadDo() {
  2140. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2141. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2142. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  2143. Doo::loadModel ( 'invoice' );
  2144. $invoice = new invoice ();
  2145. Doo::loadModel ( 'invoiceOperationLog' );
  2146. $invoiceOperationLog = new invoiceOperationLog ();
  2147. Doo::loadModel ( 'invoiceReceivables' );
  2148. $invoiceReceivables = new invoiceReceivables ();
  2149. $iid = $invoice->authcode ( $untreadIidKey );
  2150. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2151. die ( 'illegal request' );
  2152. /*
  2153. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2154. */
  2155. $item = array (
  2156. 'iid' => $iid,
  2157. 'untreadStatus' => 1,
  2158. 'untreadReason' => $untreadReason,
  2159. 'untreadPost' => $untreadPost,
  2160. 'updateTime' => date ( "Y-m-d H:i:s" )
  2161. );
  2162. $invoice->setInvoiceByCondition ( $item );
  2163. $item = array (
  2164. 'date' => date ( "Y-m-d H:i:s" ),
  2165. 'operation' => '申请退票',
  2166. 'status' => 7,
  2167. 'img' => $this->staff [0] ['avatar'],
  2168. 'username' => $this->staff [0] ['username'],
  2169. 'uid' => $this->staff [0] ['sid'],
  2170. 'category' => $this->staff [0] ['category'],
  2171. 'iid' => $iid
  2172. );
  2173. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2174. return "/invoice";
  2175. }
  2176. /**
  2177. * 删除已终止的开票
  2178. */
  2179. function invoiceDelDo() {
  2180. Doo::loadModel ( 'invoice' );
  2181. $invoice = new invoice ();
  2182. Doo::loadModel ( 'invoiceOperationLog' );
  2183. $invoiceOperationLog = new invoiceOperationLog ();
  2184. Doo::loadClass ( 'XDeode' );
  2185. $XDeode = new XDeode ( 5 );
  2186. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2187. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2188. $iid = $XDeode->decode ( $iid );
  2189. Doo::loadModel ( 'invoiceStore' );
  2190. $invoiceStore = new invoiceStore ();
  2191. if (! is_numeric ( $iid ))
  2192. die ( 'illegal request' );
  2193. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2194. if (empty ( $invoiceDetail ))
  2195. die ( 'illegal request' );
  2196. $item = array (
  2197. 'iid' => $iid,
  2198. 'isDelete' => 1,
  2199. 'updateTime' => date ( "Y-m-d H:i:s" )
  2200. );
  2201. $invoice->setInvoiceByCondition ( $item );
  2202. $item = array (
  2203. 'date' => date ( "Y-m-d H:i:s" ),
  2204. 'operation' => '删除了已终止的发票',
  2205. 'status' => 4,
  2206. 'img' => $this->staff [0] ['avatar'],
  2207. 'username' => $this->staff [0] ['username'],
  2208. 'uid' => $this->staff [0] ['sid'],
  2209. 'category' => $this->staff [0] ['category'],
  2210. 'iid' => $iid
  2211. );
  2212. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2213. // 删除培训班发票仓库里的发票
  2214. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2215. return "/invoice";
  2216. }
  2217. /**
  2218. */
  2219. function invoiceApproval() {
  2220. Doo::loadModel ( 'invoice' );
  2221. $invoice = new invoice ();
  2222. Doo::loadClass ( 'XDeode' );
  2223. $XDeode = new XDeode ( 5 );
  2224. Doo::loadModel ( 'staff' );
  2225. $staff = new staff ();
  2226. $invoiceList = $invoice->find ( array (
  2227. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2228. 'desc' => 'iid',
  2229. 'limit' => 10,
  2230. 'asArray' => true
  2231. ) );
  2232. foreach ( $invoiceList as $key => $value ) {
  2233. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2234. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2235. if (! empty ( $lastApprover )) {
  2236. $lastApproverKey = array_keys ( $lastApprover );
  2237. $lastApprover = end ( $lastApprover );
  2238. $staffDetail = $staff->getOne ( array (
  2239. 'where' => 'sid=' . end ( $lastApproverKey ),
  2240. 'asArray' => true
  2241. ) );
  2242. $lastApprover ['username'] = $staffDetail ['username'];
  2243. }
  2244. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2245. }
  2246. $ilist = $invoice->getInvoiceByProcessStatus ();
  2247. foreach ( $ilist as $key => $value ) {
  2248. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2249. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2250. if (! empty ( $lastApprover )) {
  2251. $lastApproverKey = array_keys ( $lastApprover );
  2252. $lastApprover = end ( $lastApprover );
  2253. $staffDetail = $staff->getOne ( array (
  2254. 'where' => 'sid=' . end ( $lastApproverKey ),
  2255. 'asArray' => true
  2256. ) );
  2257. $lastApprover ['username'] = $staffDetail ['username'];
  2258. }
  2259. $ilist [$key] ['lastApprover'] = $lastApprover;
  2260. }
  2261. // print_r($ilist);
  2262. $this->data ['invoiceList'] = $invoiceList;
  2263. $this->data ['ilist'] = $ilist;
  2264. $this->data ['memu'] = "invoice";
  2265. $this->data ['staff'] = $this->staff;
  2266. $this->data ['receiptMemu'] = 'invoiceApproval';
  2267. $this->render ( "/admin/invoiceApproval", $this->data );
  2268. }
  2269. function invoiceDetail() {
  2270. Doo::loadClass ( 'XDeode' );
  2271. $XDeode = new XDeode ( 5 );
  2272. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2273. $iid = $XDeode->decode ( $iid );
  2274. if (! is_numeric ( $iid ))
  2275. die ( 'illegal request' );
  2276. Doo::loadModel ( 'invoice' );
  2277. $invoice = new invoice ();
  2278. Doo::loadModel ( 'invoiceOperationLog' );
  2279. $invoiceOperationLog = new invoiceOperationLog ();
  2280. $invoiceDetail = $invoice->getOne ( array (
  2281. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2282. 'asArray' => true
  2283. ) );
  2284. if (empty ( $invoiceDetail ))
  2285. die ( 'illegal request' );
  2286. if ($invoiceDetail ['settlementType'] == 1) {
  2287. Doo::loadModel ( 'invoiceTraining' );
  2288. $invoiceTraining = new invoiceTraining ();
  2289. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2290. }
  2291. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2292. $this->data ['invoiceDetail'] = $invoiceDetail;
  2293. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2294. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2295. $this->data ['memu'] = "invoice";
  2296. $this->data ['staff'] = $this->staff;
  2297. $this->data ['receiptMemu'] = 'invoiceApproval';
  2298. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2299. }
  2300. /**
  2301. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2302. *
  2303. * @since 1.0.0
  2304. * @var integer iid 开票ID 已加密
  2305. * @var integer status 发票审批状态
  2306. * @var integer opintion 审批发票的意见
  2307. * @return string 如操作成功返回审批首页
  2308. */
  2309. function invoiceApprovalDo() {
  2310. Doo::loadModel ( 'invoice' );
  2311. $invoice = new invoice ();
  2312. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2313. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2314. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2315. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2316. $iid = $invoice->authcode ( $iid );
  2317. if (! is_numeric ( $iid ))
  2318. die ( 'illegal request' );
  2319. // && ! empty ( $opinion )
  2320. if (! empty ( $iid ) && ! empty ( $status )) {
  2321. if (! ($status == 2 || $status == 3 || $status == 4))
  2322. die ( 'illegal request' );
  2323. Doo::loadModel ( 'invoiceOperationLog' );
  2324. $invoiceOperationLog = new invoiceOperationLog ();
  2325. $invoiceDetail = $invoice->getOne ( array (
  2326. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2327. 'asArray' => true
  2328. ) );
  2329. if (empty ( $invoiceDetail ))
  2330. die ( 'illegal request' );
  2331. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2332. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2333. if ($status == 3) {
  2334. $invoice->status = $status;
  2335. $item = array (
  2336. 'operation' => $opinion
  2337. );
  2338. } else {
  2339. if (empty ( $processApprovals )) {
  2340. $processApprovals = array (
  2341. $this->staff [0] ['sid'] => array (
  2342. 'date' => date ( "Y-m-d H:i:s" ),
  2343. 'opinion' => $opinion,
  2344. 'status' => $status
  2345. )
  2346. );
  2347. // var_dump(next($invoiceManage));
  2348. $nextInvoiceManage = next ( $invoiceManage );
  2349. // print_r($nextInvoiceManage);
  2350. if ($status != 4 && $nextInvoiceManage !== false)
  2351. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2352. $invoice->processApprovals = json_encode ( $processApprovals );
  2353. // var_dump($invoice);
  2354. // print_r($invoiceManage);
  2355. } else {
  2356. $processApprovals [$this->staff [0] ['sid']] = array (
  2357. 'date' => date ( "Y-m-d H:i:s" ),
  2358. 'opinion' => $opinion,
  2359. 'status' => $status
  2360. );
  2361. $pendingApprovals = 0;
  2362. foreach ( $invoiceManage as $key => $value ) {
  2363. if ($value [0] == $this->staff [0] ['sid']) {
  2364. if (isset ( $invoiceManage [$key + 1] ))
  2365. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2366. break;
  2367. }
  2368. }
  2369. if ($status != 4 && ! empty ( $pendingApprovals ))
  2370. $invoice->pendingApprovals = $pendingApprovals;
  2371. $invoice->processApprovals = json_encode ( $processApprovals );
  2372. }
  2373. $item = array (
  2374. 'operation' => $opinion
  2375. );
  2376. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2377. $invoice->status = $status;
  2378. $invoice->pendingApprovals = 0;
  2379. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2380. } elseif ($status == 4) {
  2381. $invoice->status = $status;
  2382. $item = array (
  2383. 'operation' => $opinion
  2384. );
  2385. }
  2386. }
  2387. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2388. $invoice->update ( array (
  2389. 'where' => 'iid=' . $iid
  2390. ) );
  2391. $item += array (
  2392. 'date' => date ( "Y-m-d H:i:s" ),
  2393. 'img' => $this->staff [0] ['avatar'],
  2394. 'username' => $this->staff [0] ['username'],
  2395. 'uid' => $this->staff [0] ['sid'],
  2396. 'category' => $this->staff [0] ['category'],
  2397. 'status' => $status,
  2398. 'iid' => $iid
  2399. );
  2400. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2401. if (empty ( $divApproval ))
  2402. return '/invoiceApproval';
  2403. else
  2404. return '/invoiceApprovalAchieve/PEND';
  2405. }
  2406. die ( 'illegal request' );
  2407. }
  2408. /**
  2409. * 展示需要打印的发票数据
  2410. *
  2411. * @since 1.0.0
  2412. */
  2413. function invoicePrint() {
  2414. Doo::loadModel ( 'invoice' );
  2415. $invoice = new invoice ();
  2416. Doo::loadClass ( 'XDeode' );
  2417. $XDeode = new XDeode ( 5 );
  2418. Doo::loadModel ( 'staff' );
  2419. $staff = new staff ();
  2420. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2421. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2422. foreach ( $toPrint as $key => $value ) {
  2423. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2424. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2425. if (! empty ( $lastApprover )) {
  2426. $lastApproverKey = array_keys ( $lastApprover );
  2427. $lastApprover = end ( $lastApprover );
  2428. $staffDetail = $staff->getOne ( array (
  2429. 'where' => 'sid=' . end ( $lastApproverKey ),
  2430. 'asArray' => true
  2431. ) );
  2432. $lastApprover ['username'] = $staffDetail ['username'];
  2433. }
  2434. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2435. }
  2436. foreach ( $printed as $key => $value ) {
  2437. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2438. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2439. if (! empty ( $lastApprover )) {
  2440. $lastApproverKey = array_keys ( $lastApprover );
  2441. $lastApprover = end ( $lastApprover );
  2442. $staffDetail = $staff->getOne ( array (
  2443. 'where' => 'sid=' . end ( $lastApproverKey ),
  2444. 'asArray' => true
  2445. ) );
  2446. $lastApprover ['username'] = $staffDetail ['username'];
  2447. }
  2448. $printed [$key] ['lastApprover'] = $lastApprover;
  2449. }
  2450. $this->data ['printed'] = $printed;
  2451. $this->data ['toPrint'] = $toPrint;
  2452. $this->data ['memu'] = "invoice";
  2453. $this->data ['staff'] = $this->staff;
  2454. $this->data ['receiptMemu'] = 'invoicePrint';
  2455. $this->render ( "/admin/invoicePrint", $this->data );
  2456. }
  2457. /**
  2458. * 展示发票打印的详情页面
  2459. *
  2460. * @since 1.0.0
  2461. */
  2462. function invoicePrintDetail() {
  2463. Doo::loadClass ( 'XDeode' );
  2464. $XDeode = new XDeode ( 5 );
  2465. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2466. $iid = $XDeode->decode ( $iid );
  2467. if (! is_numeric ( $iid ))
  2468. die ( 'illegal request' );
  2469. Doo::loadModel ( 'invoice' );
  2470. $invoice = new invoice ();
  2471. Doo::loadModel ( 'invoiceOperationLog' );
  2472. $invoiceOperationLog = new invoiceOperationLog ();
  2473. Doo::loadModel ( 'invoicePaper' );
  2474. $invoicePaper = new invoicePaper ();
  2475. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2476. if (empty ( $invoiceDetail ))
  2477. die ( 'illegal request' );
  2478. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2479. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2480. if ($invoiceDetail ['settlementType'] == 1) {
  2481. Doo::loadModel ( 'invoiceTraining' );
  2482. $invoiceTraining = new invoiceTraining ();
  2483. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2484. }
  2485. $this->data ['invoicePaperList'] = $invoicePaperList;
  2486. $this->data ['invoiceDetail'] = $invoiceDetail;
  2487. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2488. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2489. $this->data ['memu'] = "invoice";
  2490. $this->data ['staff'] = $this->staff;
  2491. $this->data ['receiptMemu'] = 'invoicePrint';
  2492. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2493. }
  2494. /**
  2495. * 所有待打印 发票
  2496. */
  2497. function invoicePrintStayAchieve() {
  2498. Doo::loadModel ( 'invoice' );
  2499. $invoice = new invoice ();
  2500. Doo::loadClass ( 'XDeode' );
  2501. $XDeode = new XDeode ( 5 );
  2502. Doo::loadModel ( 'staff' );
  2503. $staff = new staff ();
  2504. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2505. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2506. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2507. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2508. Doo::loadModel ( 'invoiceTraining' );
  2509. $invoiceTraining = new invoiceTraining ();
  2510. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2511. $page_size = 12;
  2512. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2513. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2514. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2515. $get = "/" . $status;
  2516. $con = ' and status=2 ';
  2517. if ($status == 'TOPRINT')
  2518. $con = ' and status=2 and printStatus=0 ';
  2519. elseif ($status == 'PRINTED')
  2520. $con = ' and status=2 and printStatus=1';
  2521. if ($invoiceType == 'ORDINARY')
  2522. $con .= ' and invoiceType=0 ';
  2523. elseif ($invoiceType == 'SPECIAL')
  2524. $con .= ' and invoiceType=1 ';
  2525. if ($invoiceTrain == 'ORDINARY')
  2526. $con .= ' and trainId=0 ';
  2527. elseif ($invoiceTrain == 'TRAIN')
  2528. $con .= ' and trainId!=0 ';
  2529. if ($invoiceTrainName != 'ALL') {
  2530. $trainId = $XDeode->decode ( $invoiceTrainName );
  2531. if (is_numeric ( $trainId ))
  2532. $con .= ' and trainId =' . $trainId;
  2533. }
  2534. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2535. $dateArr = explode ( ':', $date );
  2536. $D1 = '';
  2537. $D2 = '';
  2538. if (! empty ( $date )) {
  2539. $D1 = $dateArr [0];
  2540. $D2 = $dateArr [1];
  2541. }
  2542. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2543. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2544. if (! empty ( $MebSea )) {
  2545. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2546. }
  2547. $pageinfo ['page'] = array (
  2548. 'previous' => ''
  2549. );
  2550. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2551. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2552. $action = "invoicePrintStayAchieve";
  2553. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2554. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2555. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2556. $this->data ['trainList'] = $trainList;
  2557. $this->data ['invoiceType'] = $invoiceType;
  2558. $this->data ['invoiceTrain'] = $invoiceTrain;
  2559. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2560. $this->data ['MebSeaEn'] = $MebSea;
  2561. $this->data ['MebSea'] = urlencode ( $MebSea );
  2562. $this->data ['get'] = $get;
  2563. $this->data ['page'] = $pageinfo;
  2564. $this->data ['date'] = $date;
  2565. $this->data ['status'] = $status;
  2566. $this->data ['invoiceType'] = $invoiceType;
  2567. $this->data ['memu'] = "invoice";
  2568. $this->data ['staff'] = $this->staff;
  2569. foreach ( $list as $key => $value ) {
  2570. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2571. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2572. if (! empty ( $lastApprover )) {
  2573. $lastApproverKey = array_keys ( $lastApprover );
  2574. $lastApprover = end ( $lastApprover );
  2575. $staffDetail = $staff->getOne ( array (
  2576. 'where' => 'sid=' . end ( $lastApproverKey ),
  2577. 'asArray' => true
  2578. ) );
  2579. $lastApprover ['username'] = $staffDetail ['username'];
  2580. }
  2581. $list [$key] ['lastApprover'] = $lastApprover;
  2582. }
  2583. $this->data ['receiptMemu'] = 'invoicePrint';
  2584. $this->data ['list'] = $list;
  2585. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2586. }
  2587. /**
  2588. * 填写票号并完成打印
  2589. * @since 1.0.0
  2590. */
  2591. function invoicePrintDo() {
  2592. Doo::loadModel ( 'invoice' );
  2593. $invoice = new invoice ();
  2594. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2595. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2596. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2597. $iid = $invoice->authcode ( $iid );
  2598. if (! is_numeric ( $iid ))
  2599. die ( 'illegal request' );
  2600. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2601. Doo::loadModel ( 'invoiceOperationLog' );
  2602. $invoiceOperationLog = new invoiceOperationLog ();
  2603. Doo::loadModel ( 'invoiceStatistics' );
  2604. $invoiceStatistics = new invoiceStatistics ();
  2605. $XDeode = new XDeode ( 5 );
  2606. Doo::loadModel ( 'invoicePaper' );
  2607. $invoicePaper = new invoicePaper ();
  2608. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2609. if (empty ( $invoicePrintDetail ))
  2610. die ( 'illegal request' );
  2611. //
  2612. $ipid = $XDeode->decode ( $invoiceNo );
  2613. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2614. if (empty ( $paperDetail ))
  2615. die ( 'illegal request' );
  2616. $invoicePaper = new invoicePaper ();
  2617. $item = array (
  2618. 'iid' => $iid,
  2619. 'ipid' => $ipid
  2620. );
  2621. $invoicePaper->setInvoicePaperByCondition ( $item );
  2622. $item = array (
  2623. 'iid' => $iid,
  2624. 'printStatus' => 1,
  2625. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2626. 'printer' => $this->staff [0] ['username'],
  2627. 'printTime' => date ( "Y-m-d H:i:s" ),
  2628. 'invoiceNo' => $paperDetail ['invoiceNo']
  2629. );
  2630. $invoice->setInvoiceByCondition ( $item );
  2631. $item = array (
  2632. 'date' => date ( "Y-m-d H:i:s" ),
  2633. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2634. 'status' => 5,
  2635. 'img' => $this->staff [0] ['avatar'],
  2636. 'username' => $this->staff [0] ['username'],
  2637. 'uid' => $this->staff [0] ['sid'],
  2638. 'category' => $this->staff [0] ['category'],
  2639. 'iid' => $iid
  2640. );
  2641. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2642. // 去统计--负票不汇总
  2643. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2644. $item = array (
  2645. 'date' => date ( "Y-m-d H:i:s" ),
  2646. 'priceClass' => 1,
  2647. 'cid' => $invoicePrintDetail ['cid'],
  2648. 'staff' => $invoicePrintDetail ['sid'],
  2649. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2650. );
  2651. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2652. }
  2653. // 发送通知信息到微信-去除
  2654. // $this->setWXMsg($iid,'PRINT');
  2655. // 发票信息库
  2656. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2657. // 申请人获取微信通知
  2658. Doo::loadModel ( 'staff' );
  2659. $staff = new staff ();
  2660. Doo::loadClass ( 'XDeode' );
  2661. $XDeode = new XDeode ( 5 );
  2662. $username2 = $staff->getOne ( array (
  2663. 'select' => 'wxid',
  2664. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2665. 'asArray' => TRUE
  2666. ) );
  2667. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2668. $msg = '';
  2669. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2670. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2671. if (empty ( $invoicePrintType ))
  2672. return "/invoicePrint";
  2673. else
  2674. return "/invoicePrintStayAchieve";
  2675. }
  2676. }
  2677. /**
  2678. * 需要邮寄的发票
  2679. * @since 1.0.0
  2680. */
  2681. function invoicePost() {
  2682. Doo::loadModel ( 'invoice' );
  2683. $invoice = new invoice ();
  2684. Doo::loadModel ( 'express' );
  2685. $express = new express ();
  2686. $invoicePost = $invoice->getPostByInvoice ();
  2687. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2688. $expressList = $express->getExpressByAll ();
  2689. $invoicePostExpress = "";
  2690. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2691. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2692. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2693. $this->data ['expressList'] = $expressList;
  2694. $this->data ['invoicePost'] = $invoicePost;
  2695. $this->data ['invoicePosted'] = $invoicePosted;
  2696. $this->data ['memu'] = "invoice";
  2697. $this->data ['staff'] = $this->staff;
  2698. $this->data ['receiptMemu'] = 'invoicePost';
  2699. $this->render ( "/admin/invoicePost", $this->data );
  2700. }
  2701. /**
  2702. * 添加发票邮寄信息
  2703. */
  2704. function invoiceExpressAddDo() {
  2705. Doo::loadModel ( 'invoice' );
  2706. $invoice = new invoice ();
  2707. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2708. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2709. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2710. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2711. $iid = $iid = $invoice->authcode ( $iid );
  2712. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2713. die ( 'illegal request' );
  2714. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2715. setcookie ( 'invoicePostExpress', $expressNumber );
  2716. $item = array (
  2717. 'iid' => $iid,
  2718. 'postStatus' => 1,
  2719. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2720. 'postTime' => date ( "Y-m-d H:i:s" ),
  2721. 'expressCompany' => $expressCompany,
  2722. 'expressNumber' => $expressNumber,
  2723. 'actualItems' => $actualItems,
  2724. 'poster' => $this->staff [0] ['username']
  2725. );
  2726. $invoice->setInvoiceByCondition ( $item );
  2727. // 微信通知-去掉
  2728. // $this->setWXMsg ( $iid );
  2729. Doo::loadModel ( 'staff' );
  2730. $staff = new staff ();
  2731. Doo::loadClass ( 'XDeode' );
  2732. $XDeode = new XDeode ( 5 );
  2733. $username2 = $staff->getOne ( array (
  2734. 'select' => 'wxid',
  2735. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2736. 'asArray' => TRUE
  2737. ) );
  2738. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2739. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2740. if (empty ( $expCom ))
  2741. $expCom [0] = '';
  2742. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2743. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2744. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2745. return '/invoicePost';
  2746. }
  2747. function invoiceExpressUpdateDo() {
  2748. Doo::loadModel ( 'invoice' );
  2749. $invoice = new invoice ();
  2750. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2751. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2752. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2753. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2754. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2755. $iid = $invoice->authcode ( $iid );
  2756. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2757. die ( 'illegal request' );
  2758. $item = array (
  2759. 'iid' => $iid,
  2760. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2761. 'expressCompany' => $expressCompany,
  2762. 'expressNumber' => $expressNumber,
  2763. 'actualItems' => $actualItems,
  2764. 'poster' => $this->staff [0] ['username']
  2765. );
  2766. $invoice->setInvoiceByCondition ( $item );
  2767. return $action;
  2768. }
  2769. /**
  2770. * 可退票管理
  2771. */
  2772. function invoiceUntreadIsAchieve() {
  2773. Doo::loadModel ( 'invoice' );
  2774. $invoice = new invoice ();
  2775. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2776. /*
  2777. * Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $page_size = 18; $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1; $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : ""; $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ); $dateArr = explode ( ':', $date ); $D1 = ''; $D2 = ''; if (! empty ( $date )) { $D1 = $dateArr [0]; $D2 = $dateArr [1]; } $con = ''; if (! empty ( $D1 ) && ! empty ( $D2 )) $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" '; // if ($date == 'MONTHO') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)'; // elseif ($date == 'MONTHT') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)'; // elseif ($date == 'MONTHY') // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)'; if (! empty ( $MebSea )) { $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )'; } $pageinfo ['page'] = array ( 'previous' => '' );
  2778. */
  2779. if (empty ( $MebSea )) {//
  2780. $con = ' and invoiceNo like "NULL" ';
  2781. } else {
  2782. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2783. }
  2784. // printStatus=1 and
  2785. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2786. /*
  2787. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2788. */
  2789. $limit = '0,20';
  2790. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2791. //print_r($list);
  2792. $this->data ['MebSeaEn'] = $MebSea;
  2793. /*
  2794. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2795. */
  2796. $this->data ['list'] = $list;
  2797. $this->data ['memu'] = "invoice";
  2798. $this->data ['staff'] = $this->staff;
  2799. $this->data ['receiptMemu'] = 'invoice';
  2800. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2801. }
  2802. // 已经退票的发票
  2803. function invoiceUntreadED() {
  2804. Doo::loadModel ( 'invoice' );
  2805. $invoice = new invoice ();
  2806. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2807. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2808. Doo::loadClass ( 'XDeode' );
  2809. $XDeode = new XDeode ( 5 );
  2810. $page_size = 18;
  2811. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2812. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2813. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2814. $dateArr = explode ( ':', $date );
  2815. $D1 = '';
  2816. $D2 = '';
  2817. if (! empty ( $date )) {
  2818. $D1 = $dateArr [0];
  2819. $D2 = $dateArr [1];
  2820. }
  2821. $con = '';
  2822. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2823. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2824. }
  2825. // if ($date == 'MONTHO')
  2826. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2827. // elseif ($date == 'MONTHT')
  2828. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2829. // elseif ($date == 'MONTHY')
  2830. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2831. if (! empty ( $MebSea )) {
  2832. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2833. }
  2834. if ($invoiceType == 'ORDINARY') {
  2835. $con .= ' and invoiceType=0 ';
  2836. } elseif ($invoiceType == 'SPECIAL') {
  2837. $con .= ' and invoiceType=1 ';
  2838. }
  2839. $pageinfo ['page'] = array (
  2840. 'previous' => ''
  2841. );
  2842. // printStatus=1 and
  2843. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2844. $action = "invoiceUntreadED";
  2845. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2846. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2847. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2848. // print_r($list);
  2849. $this->data ['MebSeaEn'] = $MebSea;
  2850. $this->data ['get'] = $get;
  2851. $this->data ['page'] = $pageinfo;
  2852. $this->data ['date'] = $date;
  2853. $this->data ['invoiceType'] = $invoiceType;
  2854. $this->data ['list'] = $list;
  2855. $this->data ['memu'] = "invoice";
  2856. $this->data ['staff'] = $this->staff;
  2857. $this->data ['receiptMemu'] = 'invoice';
  2858. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2859. }
  2860. /**
  2861. * 退票处理页面
  2862. */
  2863. function invoiceUntread() {
  2864. Doo::loadModel ( 'invoice' );
  2865. $invoice = new invoice ();
  2866. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2867. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2868. foreach ( $establishedInvoice as $key => $value ) {
  2869. // months
  2870. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2871. $nowDate = strtotime ( 'now' );
  2872. $establishedInvoice [$key] ['lossShow'] = false;
  2873. if ($lossDate < $nowDate)
  2874. $establishedInvoice [$key] ['lossShow'] = true;
  2875. }
  2876. $this->data ['untreadInvoice'] = $untreadInvoice;
  2877. $this->data ['establishedInvoice'] = $establishedInvoice;
  2878. $this->data ['memu'] = "invoice";
  2879. $this->data ['staff'] = $this->staff;
  2880. $this->data ['receiptMemu'] = 'invoiceUntread';
  2881. $this->render ( "/admin/invoiceUntread", $this->data );
  2882. }
  2883. /**
  2884. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2885. */
  2886. function invoiceUntreadEstablishedDo() {
  2887. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2888. Doo::loadModel ( 'invoice' );
  2889. $invoice = new invoice ();
  2890. Doo::loadModel ( 'invoiceOperationLog' );
  2891. $invoiceOperationLog = new invoiceOperationLog ();
  2892. Doo::loadModel ( 'invoiceReceivables' );
  2893. Doo::loadModel ( 'invoiceStatistics' );
  2894. $iid = $invoice->authcode ( $untreadIidKey );
  2895. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2896. die ( 'illegal request' );
  2897. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2898. if ($invoiceDetails ['untreadStatus'] != 1)
  2899. die ( 'illegal request untreadStatus error !=1' );
  2900. $item = array (
  2901. 'iid' => $iid,
  2902. // 'irid'=>'',
  2903. 'untreadStatus' => 2,
  2904. 'updateTime' => date ( "Y-m-d H:i:s" )
  2905. );
  2906. $invoice->setInvoiceByCondition ( $item );
  2907. $item = array (
  2908. 'date' => date ( "Y-m-d H:i:s" ),
  2909. 'operation' => '已确认退票',
  2910. 'status' => 6,
  2911. 'img' => $this->staff [0] ['avatar'],
  2912. 'username' => $this->staff [0] ['username'],
  2913. 'uid' => $this->staff [0] ['sid'],
  2914. 'category' => $this->staff [0] ['category'],
  2915. 'iid' => $iid
  2916. );
  2917. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2918. // 收款解绑以及入账扣除 收款扣除
  2919. if (! empty ( $invoiceDetails ['irid'] )) {
  2920. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2921. foreach ( $iridList as $value ) {
  2922. $invoiceReceivables = new invoiceReceivables ();
  2923. $irDetails = $invoiceReceivables->getOne ( array (
  2924. 'where' => " irid=" . $value . ' and bindStatus=1',
  2925. 'asArray' => TRUE
  2926. ) );
  2927. $item = array (
  2928. 'irid' => $value,
  2929. 'bindStatus' => 0,
  2930. 'untreadStatus' => 1,
  2931. 'untreadStaff' => $invoiceDetails ['userName'],
  2932. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2933. 'iid' => 0
  2934. );
  2935. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2936. if (! empty ( $irDetails )) {
  2937. // 扣除入账
  2938. $invoiceStatistics = new invoiceStatistics ();
  2939. $item = array (
  2940. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2941. 'priceClass' => 3,
  2942. 'cid' => $invoiceDetails ['cid'],
  2943. 'staff' => $invoiceDetails ['sid'],
  2944. 'accountPrice' => - $irDetails ['receivablesPrice']
  2945. );
  2946. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2947. // 扣除收款
  2948. $invoiceStatistics = new invoiceStatistics ();
  2949. $item = array (
  2950. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2951. 'priceClass' => 2,
  2952. 'cid' => $invoiceDetails ['cid'],
  2953. 'staff' => $invoiceDetails ['sid'],
  2954. 'irid' => $irDetails ['irid'],
  2955. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2956. );
  2957. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2958. }
  2959. // 解绑时删除收入流水
  2960. Doo::loadModel ( 'wasteBook' );
  2961. $wasteBook = new wasteBook ();
  2962. $wasteBook->delete ( array (
  2963. 'where' => 'dataID=' . $value . ' and accountType=7',
  2964. 'limit' => 1
  2965. ) );
  2966. }
  2967. }
  2968. return "/invoiceUntread";
  2969. }
  2970. function invoiceUntreadRecallDo() {
  2971. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  2972. Doo::loadModel ( 'invoice' );
  2973. $invoice = new invoice ();
  2974. Doo::loadClass ( 'XDeode' );
  2975. $XDeode = new XDeode ( 5 );
  2976. Doo::loadModel ( 'invoiceOperationLog' );
  2977. $invoiceOperationLog = new invoiceOperationLog ();
  2978. $iid = $XDeode->decode ( $iidKey );
  2979. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  2980. if (empty ( $invoiceDetail )) {
  2981. die ( 'illegal request-DATANULL' );
  2982. }
  2983. $item = array (
  2984. 'iid' => $iid,
  2985. 'untreadStatus' => 0
  2986. );
  2987. $invoice->setInvoiceByCondition ( $item );
  2988. $item = array (
  2989. 'date' => date ( "Y-m-d H:i:s" ),
  2990. 'operation' => '撤回申请退票',
  2991. 'status' => 13,
  2992. 'img' => $this->staff [0] ['avatar'],
  2993. 'username' => $this->staff [0] ['username'],
  2994. 'uid' => $this->staff [0] ['sid'],
  2995. 'category' => $this->staff [0] ['category'],
  2996. 'iid' => $iid
  2997. );
  2998. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2999. return "/invoiceUntread";
  3000. }
  3001. /**
  3002. * 建立负票,关联原来发票
  3003. */
  3004. function invoiceLossDo() {
  3005. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3006. if (! empty ( $iidKey )) {
  3007. Doo::loadClass ( 'XDeode' );
  3008. $XDeode = new XDeode ( 5 );
  3009. Doo::loadModel ( 'invoice' );
  3010. $invoice = new invoice ();
  3011. Doo::loadModel ( 'invoiceOperationLog' );
  3012. $invoiceOperationLog = new invoiceOperationLog ();
  3013. $iidKey = $XDeode->decode ( $iidKey );
  3014. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3015. // 拷贝插入一条发票数据
  3016. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3017. // 更新负票
  3018. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3019. $invoice = new invoice ();
  3020. $item = array (
  3021. 'iid' => $iid,
  3022. 'sid' => $this->staff [0] ['sid'],
  3023. 'userName' => $this->staff [0] ['username'],
  3024. 'cid' => $this->staff [0] ['cid'],
  3025. 'categoryName' => $this->staff [0] ['category'],
  3026. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3027. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3028. 'invoiceSerial' => $invoiceSerial,
  3029. 'invoiceNo' => '',
  3030. 'printStatus' => 0,
  3031. 'untreadStatus' => 4,
  3032. // 关联发票号
  3033. 'lossIid' => $invoiceDetail ['iid']
  3034. );
  3035. $invoice->setInvoiceByCondition ( $item );
  3036. // 更新原发票
  3037. $invoice = new invoice ();
  3038. $item = array (
  3039. 'iid' => $invoiceDetail ['iid'],
  3040. 'lossIid' => $iid
  3041. );
  3042. $invoice->setInvoiceByCondition ( $item );
  3043. // 操作日志
  3044. $item = array (
  3045. 'date' => date ( "Y-m-d H:i:s" ),
  3046. 'operation' => "创建负票" . $invoiceSerial,
  3047. 'status' => 12,
  3048. 'img' => $this->staff [0] ['avatar'],
  3049. 'username' => $this->staff [0] ['username'],
  3050. 'uid' => $this->staff [0] ['sid'],
  3051. 'category' => $this->staff [0] ['category'],
  3052. 'iid' => $iid
  3053. );
  3054. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3055. // print_r($invoiceDetail);
  3056. // echo $iid;die;
  3057. }
  3058. return '/invoiceUntread';
  3059. }
  3060. /**
  3061. * 上传银行到账 收款文件
  3062. */
  3063. function invoiceReceivablesBankUpload() {
  3064. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3065. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3066. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3067. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3068. header ( "HTTP/1.1 500 Internal Server Error" );
  3069. echo "POST exceeded maximum allowed size.";
  3070. exit ( 0 );
  3071. }
  3072. // Settings
  3073. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  3074. $upload_name = "Filedata";
  3075. $file_name = "";
  3076. $nk = time ();
  3077. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3078. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3079. echo "文件无法保存.";
  3080. exit ( 0 );
  3081. }
  3082. echo json_encode ( array (
  3083. 'filename' => $file_name,
  3084. 'id' => $nk
  3085. ) );
  3086. exit ( 0 );
  3087. }
  3088. /**
  3089. * 解析银行到账收款execl并导入库中
  3090. */
  3091. function invoiceReceivablesImport() {
  3092. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3093. if ($path != "") {
  3094. Doo::loadModel ( 'invoiceReceivables' );
  3095. $invoiceReceivables = new invoiceReceivables ();
  3096. Doo::loadClass ( 'invoice.func' );
  3097. Doo::loadModel ( 'invoiceROLog' );
  3098. $invoiceROLog = new invoiceROLog ();
  3099. Doo::loadModel ( 'invoiceStatistics' );
  3100. $invoiceStatistics = new invoiceStatistics ();
  3101. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3102. $bankBatchNumber = 'BBN_' . time ();
  3103. Doo::db ()->beginTransaction ();
  3104. // 批量存储收款--由于必须获得收款ID,
  3105. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3106. VALUES ';
  3107. $date = date ( "Y-m-d" );
  3108. $receivablesList = array ();
  3109. foreach ( $exlArray as $key => $value ) {
  3110. $receivablesSql = '(' . $value ["receivablesPrice"] . ',' . $value ["receivablesPrice"] . ',"' . $value ["receivablesMessage"] . '",' . '"#SK' . date ( "Ymd" ) . mt_rand ( 1000, 9999 ) . '","' . $value ["receivablesBank"] . '","' . $value ["receivablesDate"] . '","' . $this->staff [0] ['username'] . '","' . $date . '","PUBLIC","PUBLIC","' . $bankBatchNumber . '","' . $value ["receivablesMessage"] . '")';
  3111. array_push ( $receivablesList, $receivablesSql );
  3112. }
  3113. $sql = $sql . implode ( ',', $receivablesList );
  3114. // echo $sql;
  3115. Doo::db ()->query ( $sql );
  3116. // 批量存储收款统计
  3117. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3118. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3119. // 没有irid 回滚所有操作
  3120. if (empty ( $iridList )) {
  3121. Doo::db ()->rollBack ();
  3122. header ( 'Content-Type:text/html;charset=utf-8' );
  3123. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3124. }
  3125. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3126. VALUES ';
  3127. $statisticsList = array ();
  3128. foreach ( $iridList as $value ) {
  3129. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3130. array_push ( $statisticsList, $statisticsSql );
  3131. }
  3132. $sql = $sql . implode ( ',', $statisticsList );
  3133. Doo::db ()->query ( $sql );
  3134. // 批量存储操作日志
  3135. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3136. VALUES ';
  3137. $ROLogList = array ();
  3138. foreach ( $iridList as $value ) {
  3139. $ROLogSql = '("' . $this->staff [0] ['username'] . ' 转入 公共待认领款项","' . $date . '",1,"' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value ['irid'] . '")';
  3140. array_push ( $ROLogList, $ROLogSql );
  3141. }
  3142. $sql = $sql . implode ( ',', $ROLogList );
  3143. Doo::db ()->query ( $sql );
  3144. // 批量写入流水
  3145. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3146. VALUES ';
  3147. $wasteBookList = array ();
  3148. foreach ( $iridList as $value ) {
  3149. $accountBank = '';
  3150. if ($value ['receivablesBank'] == '纵横广发') {
  3151. $accountBank = 'CGBDeposit';
  3152. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3153. $accountBank = 'ICBCDeposit';
  3154. } elseif ($value ['receivablesBank'] == '华润银行') {
  3155. $accountBank = 'HUADeposit';
  3156. } elseif ($value ['receivablesBank'] == '个人广发') {
  3157. $accountBank = 'PersonalDeposit';
  3158. }
  3159. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3160. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3161. array_push ( $wasteBookList, $wasteBookSql );
  3162. }
  3163. $sql = $sql . implode ( ',', $wasteBookList );
  3164. Doo::db ()->query ( $sql );
  3165. Doo::db ()->commit ();
  3166. return "/invoiceReceivables";
  3167. }
  3168. echo 'no file';
  3169. }
  3170. function invoiceReceivables() {
  3171. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3172. Doo::loadModel ( 'L_category' );
  3173. $lCategory = new L_category ();
  3174. Doo::loadModel ( 'staff' );
  3175. $staff = new staff ();
  3176. Doo::loadModel ( 'invoiceReceivables' );
  3177. $invoiceReceivables = new invoiceReceivables ();
  3178. Doo::loadModel ( 'invoice' );
  3179. $invoice = new invoice ();
  3180. Doo::loadClass ( 'XDeode' );
  3181. $XDeode = new XDeode ( 5 );
  3182. $category = $lCategory->getCategory ();
  3183. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3184. $sql = 'bindStatus=1 and iid!=0';
  3185. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3186. // 获取未入账发票
  3187. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3188. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3189. foreach ( $invoiceUnAccount as $key => $value ) {
  3190. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3191. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3192. if (! empty ( $lastApprover )) {
  3193. $lastApproverKey = array_keys ( $lastApprover );
  3194. $lastApprover = end ( $lastApprover );
  3195. $staffDetail = $staff->getOne ( array (
  3196. 'where' => 'sid=' . end ( $lastApproverKey ),
  3197. 'asArray' => true
  3198. ) );
  3199. $lastApprover ['username'] = $staffDetail ['username'];
  3200. }
  3201. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3202. }
  3203. foreach ( $invoiceExistAccount as $key => $value ) {
  3204. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3205. // if (empty ( $irList ))
  3206. // $irList [0] ['sumPrice'] = 0;
  3207. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3208. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3209. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3210. }
  3211. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3212. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3213. $this->data ['halfList'] = $halfList;
  3214. $this->data ['halfCount'] = count ( $halfList );
  3215. // print_r($receivablesList);
  3216. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3217. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3218. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3219. $this->data ['receivablesInput'] = $receivablesInput;
  3220. $this->data ['year'] = date ( 'Y' );
  3221. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3222. $this->data ['receivablesList'] = $receivablesList;
  3223. $this->data ['staffList'] = $staffList;
  3224. $this->data ['category'] = $category;
  3225. $this->data ['memu'] = "invoice";
  3226. $this->data ['staff'] = $this->staff;
  3227. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3228. $this->render ( "/admin/invoiceReceivables", $this->data );
  3229. }
  3230. /**
  3231. * 设置收款认领地区
  3232. */
  3233. function setInvoiceReceivablesClaim() {
  3234. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3235. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3236. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3237. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3238. Doo::loadModel ( 'invoiceReceivables' );
  3239. $invoiceReceivables = new invoiceReceivables ();
  3240. Doo::loadClass ( 'XDeode' );
  3241. $XDeode = new XDeode ( 5 );
  3242. Doo::loadModel ( 'invoiceROLog' );
  3243. $invoiceROLog = new invoiceROLog ();
  3244. $irid = $XDeode->decode ( $iridKey );
  3245. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3246. if (empty ( $irDetail ))
  3247. die ( 'illegal request' );
  3248. $item = array (
  3249. 'irid' => $irid,
  3250. 'receivablesCategory' => $receivablesCategory
  3251. );
  3252. if ($receivablesCategory != 'PUBLIC') {
  3253. $item += array (
  3254. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3255. 'inputType' => 1
  3256. );
  3257. }
  3258. $invoiceReceivables = new invoiceReceivables ();
  3259. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3260. // 收款操作日志
  3261. $item = array (
  3262. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3263. 'date' => date ( "Y-m-d" ),
  3264. 'status' => 1,
  3265. 'img' => $this->staff [0] ['avatar'],
  3266. 'username' => $this->staff [0] ['username'],
  3267. 'uid' => $this->staff [0] ['sid'],
  3268. 'category' => $this->staff [0] ['category'],
  3269. 'irid' => $irid
  3270. );
  3271. $invoiceROLog->setInvoiceROLog ( $item );
  3272. if (empty ( $action ))
  3273. return '/invoiceReceivables';
  3274. else
  3275. return "/invoiceReceivablesAS";
  3276. }
  3277. die ( 'illegal request' );
  3278. }
  3279. /**
  3280. * 新添加收款直接入账发票
  3281. */
  3282. function invoiceCompareClaimPrice() {
  3283. // 收款录入
  3284. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3285. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3286. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3287. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3288. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3289. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3290. Doo::loadModel ( 'invoiceReceivables' );
  3291. $invoiceReceivables = new invoiceReceivables ();
  3292. Doo::loadModel ( 'invoiceROLog' );
  3293. $invoiceROLog = new invoiceROLog ();
  3294. Doo::loadModel ( 'invoiceStatistics' );
  3295. Doo::loadModel ( 'invoice' );
  3296. $invoice = new invoice ();
  3297. Doo::loadModel ( 'bill' );
  3298. $bill = new bill ();
  3299. Doo::loadClass ( 'XDeode' );
  3300. $XDeode = new XDeode ( 5 );
  3301. Doo::loadModel ( 'invoiceOperationLog' );
  3302. $invoiceOperationLog = new invoiceOperationLog ();
  3303. $iidKey = $XDeode->decode ( $iidKey );
  3304. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3305. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3306. die ( 'illegal request' );
  3307. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3308. // 收款录入 并绑定发票
  3309. Doo::db ()->beginTransaction ();
  3310. //获得发票入账余额
  3311. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3312. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3313. $bindStatus = 0;
  3314. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3315. if($invoiceDetail ['invoiceBalance']!=0){
  3316. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3317. }
  3318. if ($receivablesPrice <= $invoiceBalance){
  3319. $bindStatus = 1;
  3320. //$bindPrice=$receivablesPrice;
  3321. }
  3322. $titleMark = $invoiceDetail ['invoiceTitle'];
  3323. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3324. $titleMark = $invoiceDetail ['invoiceCompany'];
  3325. $item = array (
  3326. 'recepitTitleMark' => $titleMark,
  3327. 'bindStatus' => $bindStatus,
  3328. 'iid' => $invoiceDetail ['iid'],
  3329. 'bindPrice' => $receivablesPrice,
  3330. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3331. 'receivablesPrice' => $receivablesPrice,
  3332. 'OriginalPrice' => $receivablesPrice,
  3333. 'receivablesMessage' => $receivablesMessage,
  3334. 'receivablesSerial' => $receivablesSerial,
  3335. 'receivablesBank' => $receivablesBank,
  3336. 'receivablesDate' => $receivablesDate,
  3337. 'inputStaff' => $this->staff [0] ['username'],
  3338. 'accountClerk' => $this->staff [0] ['username'],
  3339. 'date' => date ( "Y-m-d" ),
  3340. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3341. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3342. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3343. );
  3344. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3345. $item = array ();
  3346. // 收款操作日志
  3347. $item = array (
  3348. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3349. );
  3350. $item += array (
  3351. 'date' => date ( "Y-m-d" ),
  3352. 'status' => 1,
  3353. 'img' => $this->staff [0] ['avatar'],
  3354. 'username' => $this->staff [0] ['username'],
  3355. 'uid' => $this->staff [0] ['sid'],
  3356. 'category' => $this->staff [0] ['category'],
  3357. 'irid' => $irid
  3358. );
  3359. $invoiceROLog->setInvoiceROLog ( $item );
  3360. // 收款统计
  3361. $invoiceStatistics = new invoiceStatistics ();
  3362. $item = array (
  3363. 'date' => $receivablesDate,
  3364. 'priceClass' => 2,
  3365. 'irid' => $irid,
  3366. 'cid' => $invoiceDetail ['cid'],
  3367. 'staff' => $invoiceDetail ['sid'],
  3368. 'receivablesPrice' => $receivablesPrice
  3369. );
  3370. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3371. // 收款 入 发票
  3372. $detail = $invoiceDetail;
  3373. $iridString = "";
  3374. if (empty ( $detail ['irid'] ))
  3375. $iridString = $irid;
  3376. else
  3377. $iridString = $detail ['irid'] . ',' . $irid;
  3378. $item = array (
  3379. 'irid' => $iridString,
  3380. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3381. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3382. 'iid' => $detail ['iid']
  3383. );
  3384. // $invoiceReceivables = new invoiceReceivables ();
  3385. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3386. // $sumBind = $bindInvicePrice;
  3387. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3388. // $sum=$sumBind+$sumBalance;
  3389. // ;
  3390. if ($receivablesPrice>=$invoiceBalance){
  3391. $item += array (
  3392. 'invoiceBalance'=>0,
  3393. 'untreadStatus' => 3
  3394. );
  3395. }else{
  3396. $item += array (
  3397. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3398. );
  3399. }
  3400. $invoice->setInvoiceByCondition ( $item );
  3401. // 操作日志
  3402. $item = array (
  3403. 'date' => date ( "Y-m-d H:i:s" ),
  3404. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3405. 'status' => 8,
  3406. 'img' => $this->staff [0] ['avatar'],
  3407. 'username' => $this->staff [0] ['username'],
  3408. 'uid' => $this->staff [0] ['sid'],
  3409. 'category' => $this->staff [0] ['category'],
  3410. 'iid' => $detail ['iid']
  3411. );
  3412. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3413. // 入账汇总
  3414. $invoiceStatistics = new invoiceStatistics ();
  3415. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3416. // $accountPrice = 0;
  3417. // foreach ( $list as $key => $value ) {
  3418. // $accountPrice += $value ['receivablesPrice'];
  3419. // }
  3420. $item = array (
  3421. 'date' => $receivablesDate,
  3422. 'priceClass' => 3,
  3423. 'cid' => $invoiceDetail ['cid'],
  3424. 'staff' => $invoiceDetail ['sid'],
  3425. 'accountPrice' => $receivablesPrice
  3426. );
  3427. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3428. //发票入账记录
  3429. $bill->iid=$invoiceDetail['iid'];
  3430. $bill->trainId=$invoiceDetail['trainId'];
  3431. $bill->irid=$irid;
  3432. $bill->create_time=date ( "Y-m-d H:i:s" );
  3433. $bill->price=$receivablesPrice;
  3434. $bill->insert ();
  3435. // 公司流水记录
  3436. Doo::loadModel ( 'wasteBook' );
  3437. $wasteBook = new wasteBook ();
  3438. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3439. $accountBank = '';
  3440. if ($receivablesBank == '纵横广发') {
  3441. $accountBank = 'CGBDeposit';
  3442. } elseif ($receivablesBank == '纵横工行') {
  3443. $accountBank = 'ICBCDeposit';
  3444. } elseif ($receivablesBank == '华润银行') {
  3445. $accountBank = 'HUADeposit';
  3446. } elseif ($receivablesBank == '个人广发') {
  3447. $accountBank = 'PersonalDeposit';
  3448. }
  3449. if (empty ( $abDetail )) {
  3450. $item = array (
  3451. 'dataID' => $irid,
  3452. 'expensesType' => 1,
  3453. 'accountType' => 7,
  3454. 'accountPrice' => $receivablesPrice,
  3455. 'accountPriceShow' => $receivablesPrice,
  3456. 'accountBank' => $accountBank,
  3457. 'category' => $this->staff [0] ['category'],
  3458. 'cid' => $this->staff [0] ['cid'],
  3459. 'name' => $this->staff [0] ['username'],
  3460. 'sid' => $this->staff [0] ['sid'],
  3461. 'inputDate' => date ( "Y-m-d H:i:s" )
  3462. );
  3463. $wasteBook->setAccountBookStatistics ( $item );
  3464. }
  3465. Doo::db ()->commit ();
  3466. }
  3467. return '/invoiceReceivables';
  3468. }
  3469. /**
  3470. * 录入收款数据
  3471. * @return string
  3472. */
  3473. function invoiceReceivablesDo() {
  3474. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3475. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3476. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3477. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3478. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3479. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3480. Doo::loadModel ( 'invoiceReceivables' );
  3481. $invoiceReceivables = new invoiceReceivables ();
  3482. Doo::loadModel ( 'invoiceROLog' );
  3483. $invoiceROLog = new invoiceROLog ();
  3484. Doo::loadModel ( 'invoiceStatistics' );
  3485. $invoiceStatistics = new invoiceStatistics ();
  3486. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3487. $item = array (
  3488. 'receivablesPrice' => $receivablesPrice,
  3489. 'OriginalPrice' => $receivablesPrice,
  3490. 'receivablesMessage' => $receivablesMessage,
  3491. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3492. 'receivablesBank' => $receivablesBank,
  3493. 'receivablesDate' => $receivablesDate,
  3494. 'inputStaff' => $this->staff [0] ['username'],
  3495. 'date' => date ( "Y-m-d" ),
  3496. 'receivablesCategory' => $receivablesCategory,
  3497. 'receivablesStaff' => $receivablesStaff
  3498. );
  3499. if ($receivablesCategory != 'PUBLIC') {
  3500. $item += array (
  3501. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3502. 'inputType' => 1
  3503. );
  3504. }
  3505. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3506. $item = array ();
  3507. // 收款操作日志
  3508. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3509. $item = array (
  3510. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3511. );
  3512. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3513. $item = array (
  3514. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3515. );
  3516. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3517. $receivablesStaff = explode ( '-', $receivablesStaff );
  3518. $item = array (
  3519. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3520. );
  3521. }
  3522. $item += array (
  3523. 'date' => date ( "Y-m-d" ),
  3524. 'status' => 1,
  3525. 'img' => $this->staff [0] ['avatar'],
  3526. 'username' => $this->staff [0] ['username'],
  3527. 'uid' => $this->staff [0] ['sid'],
  3528. 'category' => $this->staff [0] ['category'],
  3529. 'irid' => $irid
  3530. );
  3531. $invoiceROLog->setInvoiceROLog ( $item );
  3532. $item = array (
  3533. 'date' => $receivablesDate,
  3534. 'priceClass' => 2,
  3535. 'irid' => $irid,
  3536. 'receivablesPrice' => $receivablesPrice
  3537. );
  3538. if ($receivablesCategory != 'PUBLIC') {
  3539. $receivablesCategory = explode ( ":", $receivablesCategory );
  3540. $item += array (
  3541. 'cid' => $receivablesCategory [0]
  3542. );
  3543. }
  3544. if ($receivablesStaff2 != 'PUBLIC') {
  3545. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3546. $item += array (
  3547. 'staff' => $receivablesStaff [0]
  3548. );
  3549. }
  3550. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3551. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3552. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3553. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3554. if ($toparty != 0)
  3555. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3556. // 公司流水记录
  3557. Doo::loadModel ( 'wasteBook' );
  3558. $wasteBook = new wasteBook ();
  3559. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3560. $accountBank = '';
  3561. if ($receivablesBank == '纵横广发') {
  3562. $accountBank = 'CGBDeposit';
  3563. } elseif ($receivablesBank == '纵横工行') {
  3564. $accountBank = 'ICBCDeposit';
  3565. } elseif ($receivablesBank == '华润银行') {
  3566. $accountBank = 'HUADeposit';
  3567. } elseif ($receivablesBank == '个人广发') {
  3568. $accountBank = 'PersonalDeposit';
  3569. }
  3570. $item = array (
  3571. 'dataID' => $irid,
  3572. 'expensesType' => 1,
  3573. 'accountType' => 7,
  3574. 'accountPriceShow' => $receivablesPrice,
  3575. 'accountPrice' => $receivablesPrice,
  3576. 'accountBank' => $accountBank,
  3577. 'category' => $this->staff [0] ['category'],
  3578. 'cid' => $this->staff [0] ['cid'],
  3579. 'name' => $this->staff [0] ['username'],
  3580. 'sid' => $this->staff [0] ['sid'],
  3581. 'inputDate' => date ( "Y-m-d H:i:s" )
  3582. );
  3583. $wasteBook->setAccountBookStatistics ( $item );
  3584. }
  3585. return "/invoiceReceivables";
  3586. }
  3587. /**
  3588. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3589. */
  3590. function invoiceReceivablesClaim() {
  3591. Doo::loadModel ( 'invoiceReceivables' );
  3592. $invoiceReceivables = new invoiceReceivables ();
  3593. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3594. $this->data ['receivablesList'] = $receivablesList;
  3595. $this->data ['memu'] = "invoice";
  3596. $this->data ['staff'] = $this->staff;
  3597. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3598. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3599. }
  3600. function invoiceReceivablesTitleMarkSet() {
  3601. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3602. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3603. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3604. die ( 'illegal request' );
  3605. Doo::loadModel ( 'invoiceReceivables' );
  3606. $invoiceReceivables = new invoiceReceivables ();
  3607. Doo::loadClass ( 'XDeode' );
  3608. $XDeode = new XDeode ( 5 );
  3609. $irid = $XDeode->decode ( $iridKey );
  3610. if (! is_numeric ( $irid ))
  3611. die ( 'illegal request' );
  3612. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3613. $invoiceReceivables->update ( array (
  3614. 'where' => 'irid = ' . $irid
  3615. ) );
  3616. return '/invoiceReceivablesClaim';
  3617. }
  3618. /**
  3619. * 更新收款相关数据
  3620. */
  3621. function invoiceReceivablesUpdateClaim() {
  3622. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3623. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3624. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3625. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3626. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3627. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3628. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3629. if (empty ( $claimKey ))
  3630. die ( 'illegal request' );
  3631. Doo::loadModel ( 'invoiceReceivables' );
  3632. $invoiceReceivables = new invoiceReceivables ();
  3633. Doo::loadModel ( 'invoiceROLog' );
  3634. $invoiceROLog = new invoiceROLog ();
  3635. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3636. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3637. if (empty ( $detail ))
  3638. die ( 'illegal request' );
  3639. $invoiceReceivables = new invoiceReceivables ();
  3640. $item = array (
  3641. 'irid' => $detail ['irid']
  3642. );
  3643. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3644. $item += array (
  3645. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3646. );
  3647. }
  3648. if (! empty ( $receivablesCategory ))
  3649. $item += array (
  3650. 'receivablesCategory' => $receivablesCategory
  3651. );
  3652. if (! empty ( $receivablesStaff ))
  3653. $item += array (
  3654. 'receivablesStaff' => $receivablesStaff
  3655. );
  3656. if (! empty ( $receivablesPrice ))
  3657. $item += array (
  3658. 'receivablesPrice' => $receivablesPrice
  3659. );
  3660. if (! empty ( $receivablesMessage ))
  3661. $item += array (
  3662. 'receivablesMessage' => $receivablesMessage
  3663. );
  3664. if (! empty ( $receivablesBank ))
  3665. $item += array (
  3666. 'receivablesBank' => $receivablesBank
  3667. );
  3668. if (! empty ( $receivablesDate ))
  3669. $item += array (
  3670. 'receivablesDate' => $receivablesDate
  3671. );
  3672. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3673. // 收款操作日志
  3674. $item = array ();
  3675. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3676. $item = array (
  3677. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3678. );
  3679. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3680. $item = array (
  3681. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3682. );
  3683. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3684. $receivablesStaff = explode ( '-', $receivablesStaff );
  3685. $item = array (
  3686. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3687. );
  3688. }
  3689. $item += array (
  3690. 'date' => date ( "Y-m-d" ),
  3691. 'status' => 1,
  3692. 'img' => $this->staff [0] ['avatar'],
  3693. 'username' => $this->staff [0] ['username'],
  3694. 'uid' => $this->staff [0] ['sid'],
  3695. 'category' => $this->staff [0] ['category'],
  3696. 'irid' => $detail ['irid']
  3697. );
  3698. $invoiceROLog->setInvoiceROLog ( $item );
  3699. return '/invoiceReceivablesAS';
  3700. }
  3701. function invoiceReceivablesDelete() {
  3702. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3703. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3704. if ($skll != '删除到款')
  3705. die ( 'illegal request' );
  3706. if (empty ( $claimKey ))
  3707. die ( 'illegal request' );
  3708. Doo::loadModel ( 'invoiceReceivables' );
  3709. $invoiceReceivables = new invoiceReceivables ();
  3710. $con = ' and bindStatus=0 ';
  3711. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3712. if (empty ( $detail ))
  3713. die ( 'illegal request' );
  3714. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3715. // 扣除收款汇总信息 汇总
  3716. Doo::loadModel ( 'invoiceStatistics' );
  3717. $invoiceStatistics = new invoiceStatistics ();
  3718. $item = array (
  3719. 'date' => $detail ['receivablesDate'],
  3720. 'priceClass' => 2,
  3721. 'irid' => $detail ['irid'],
  3722. 'receivablesPrice' => - $detail ['receivablesPrice']
  3723. );
  3724. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3725. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3726. $item += array (
  3727. 'cid' => $receivablesCategory [0]
  3728. );
  3729. }
  3730. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3731. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3732. $item += array (
  3733. 'staff' => $receivablesStaff [0]
  3734. );
  3735. }
  3736. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3737. // 公司流水-删除时删除流水
  3738. Doo::loadModel ( 'wasteBook' );
  3739. $wasteBook = new wasteBook ();
  3740. $wasteBook->delete ( array (
  3741. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3742. 'limit' => 1
  3743. ) );
  3744. return '/invoiceReceivablesAS';
  3745. }
  3746. /**
  3747. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3748. */
  3749. function invoiceReceivablesAscription() {
  3750. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3751. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3752. Doo::loadModel ( 'invoiceReceivables' );
  3753. $invoiceReceivables = new invoiceReceivables ();
  3754. Doo::loadModel ( 'invoiceROLog' );
  3755. $invoiceROLog = new invoiceROLog ();
  3756. Doo::loadModel ( 'invoiceStatistics' );
  3757. $invoiceStatistics = new invoiceStatistics ();
  3758. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3759. $irid = $invoiceReceivables->authcode ( $irid );
  3760. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3761. $item = array (
  3762. 'irid' => $detail ['irid'],
  3763. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3764. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3765. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3766. 'recepitTitleMark' => $recepitTitleMark,
  3767. 'source' => 1
  3768. );
  3769. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3770. $item = array (
  3771. 'date' => date ( "Y-m-d" ),
  3772. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3773. 'status' => 2,
  3774. 'img' => $this->staff [0] ['avatar'],
  3775. 'username' => $this->staff [0] ['username'],
  3776. 'uid' => $this->staff [0] ['sid'],
  3777. 'category' => $this->staff [0] ['category'],
  3778. 'irid' => $irid
  3779. );
  3780. $invoiceROLog->setInvoiceROLog ( $item );
  3781. $item = array (
  3782. 'cid' => $this->staff [0] ['cid'],
  3783. 'staff' => $this->staff [0] ['sid']
  3784. );
  3785. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3786. }
  3787. return "/invoiceReceivablesClaim";
  3788. }
  3789. /**
  3790. */
  3791. function invoiceMyReceivables() {
  3792. Doo::loadModel ( 'invoiceReceivables' );
  3793. $invoiceReceivables = new invoiceReceivables ();
  3794. Doo::loadModel ( 'invoiceStatistics' );
  3795. $invoiceStatistics = new invoiceStatistics ();
  3796. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3797. $year = date ( "Y" );
  3798. $tmp_date = date ( "Ym" );
  3799. $tmp_year = substr ( $tmp_date, 0, 4 );
  3800. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3801. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3802. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3803. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3804. $htm = $this->showCache ( $path );
  3805. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3806. $this->data ['isMonth'] = $isMonth;
  3807. $this->data ['htm'] = $htm;
  3808. $this->data ['list'] = $list;
  3809. $this->data ['memu'] = "invoice";
  3810. $this->data ['staff'] = $this->staff;
  3811. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3812. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3813. }
  3814. /**
  3815. * 纸票管理
  3816. */
  3817. function invoicePaper() {
  3818. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3819. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3820. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3821. $this->data ['dateString'] = $date;
  3822. $this->data ['status'] = $status;
  3823. $this->data ['invoiceType'] = $invoiceType;
  3824. $this->data ['memu'] = "invoice";
  3825. $this->data ['staff'] = $this->staff;
  3826. $this->data ['receiptMemu'] = 'invoicePaper';
  3827. $this->render ( "/admin/invoicePaper", $this->data );
  3828. }
  3829. /**
  3830. * 电子发票管理
  3831. */
  3832. function invoiceElectronic() {
  3833. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3834. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3835. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3836. $this->data ['dateString'] = $date;
  3837. $this->data ['status'] = $status;
  3838. $this->data ['invoiceType'] = $invoiceType;
  3839. $this->data ['memu'] = "invoice";
  3840. $this->data ['staff'] = $this->staff;
  3841. $this->data ['receiptMemu'] = 'invoicePaper';
  3842. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3843. }
  3844. /**
  3845. * 获得纸票分页数据
  3846. */
  3847. function ajaxGetinvoicePaperAchieve() {
  3848. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3849. Doo::loadModel ( 'invoicePaper' );
  3850. $invoicePaper = new invoicePaper ();
  3851. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3852. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3853. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3854. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3855. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3856. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3857. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3858. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3859. $MebSea = $this->get_args ( 'search' );
  3860. $MebSea = $MebSea ['value'];
  3861. $page_size = $length;
  3862. $con = '';
  3863. if ($status == 'ALL')
  3864. $con = ' where 1 ';
  3865. elseif ($status == 'PRINTED')
  3866. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3867. elseif ($status == 'UNPRINT')
  3868. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3869. elseif ($status == 'TICKET')
  3870. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3871. if ($invoiceType == 'ORDINARY')
  3872. $con .= ' and a.invoiceType=0 ';
  3873. elseif ($invoiceType == 'SPECIAL')
  3874. $con .= ' and a.invoiceType=1 ';
  3875. if($invoiceForm==0){
  3876. $con .= ' and a.invoiceForm=0 ';
  3877. }else{
  3878. $con .= ' and a.invoiceForm=1 ';
  3879. }
  3880. $dateArr = explode ( ':', $date );
  3881. $D1 = $dateString = '';
  3882. $D2 = '';
  3883. if (! empty ( $date )) {
  3884. $D1 = $dateArr [0];
  3885. if (isset ( $dateArr [1] ))
  3886. $D2 = $dateArr [1];
  3887. else
  3888. $D2 = '';
  3889. $dateString = $D1 . " : " . $D2;
  3890. }
  3891. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3892. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3893. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3894. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3895. if (! empty ( $MebSea ))
  3896. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3897. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3898. $sql = ' ' . $con;
  3899. $limit = $page . ',' . $page_size;
  3900. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3901. $paperList = array ();
  3902. foreach ( $list as $key => $value ) {
  3903. $irDetail = array ();
  3904. if ($value ['iid'] == 0)
  3905. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3906. else
  3907. array_push ( $irDetail, '' );
  3908. array_push ( $irDetail, $value ['invoiceCode'] );
  3909. array_push ( $irDetail, $value ['invoiceNo'] );
  3910. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3911. if ($value ['invoiceType'] == 1)
  3912. array_push ( $irDetail, $value ['invoiceCompany'] );
  3913. else
  3914. array_push ( $irDetail, $value ['invoiceTitle'] );
  3915. if ($value ['invoiceType'] == 1)
  3916. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3917. else
  3918. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3919. array_push ( $irDetail, $value ['invoiceElement'] );
  3920. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3921. array_push ( $irDetail, $value ['printTime'] );
  3922. array_push ( $paperList, $irDetail );
  3923. }
  3924. // $approvalListJson = json_encode ( $approvalList );
  3925. $recordsFiltered = $invoiceTotal;
  3926. echo json_encode ( array (
  3927. "draw" => intval ( $draw ),
  3928. "recordsTotal" => intval ( $invoiceTotal ),
  3929. "recordsFiltered" => intval ( $recordsFiltered ),
  3930. "data" => $paperList
  3931. ), JSON_UNESCAPED_UNICODE );
  3932. }
  3933. function invoicePaperDel() {
  3934. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3935. $XDeode = new XDeode ( 5 );
  3936. $ipid = $XDeode->decode ( $ipidKey );
  3937. if (empty ( $ipid ))
  3938. die ( 'illegal request' );
  3939. Doo::loadModel ( 'invoicePaper' );
  3940. $invoicePaper = new invoicePaper ();
  3941. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3942. $invoicePaper->delete ( array (
  3943. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3944. 'limit' => 1
  3945. ) );
  3946. if($ipdetail['invoiceForm']==1){
  3947. return '/invoiceElectronic';
  3948. }else{
  3949. return '/invoicePaper';
  3950. }
  3951. }
  3952. /**
  3953. * 添加纸质发票号
  3954. */
  3955. function invoicePaperAdd() {
  3956. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3957. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3958. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3959. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3960. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  3961. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3962. $sum = $invoiceNoStart + $invoiceNoTotal;
  3963. if (empty ( $sum ))
  3964. die ( 'illegal request' );
  3965. // echo $invoiceNoStart;
  3966. // echo $sum;
  3967. // echo strlen((int)$invoiceNoStart);
  3968. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3969. if($invoiceType==0||$invoiceType==1){
  3970. }else{
  3971. die ( 'illegal request invoiceType' );
  3972. }
  3973. if($invoiceForm==1){
  3974. $invoiceType=0;
  3975. }
  3976. Doo::db ()->beginTransaction ();
  3977. // 批量存储纸质发票
  3978. $date = date ( "Y-m-d H:i:s" );
  3979. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  3980. VALUES ';
  3981. $paperList = array ();
  3982. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3983. // 数字前面自加0
  3984. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3985. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3986. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  3987. array_push ( $paperList, $paperSql );
  3988. }
  3989. if (empty ( $paperList ))
  3990. die ( 'illegal request' );
  3991. $sql = $sql . implode ( ',', $paperList );
  3992. Doo::db ()->query ( $sql );
  3993. Doo::db ()->commit ();
  3994. if($invoiceForm==1){
  3995. return 'invoiceElectronic';
  3996. }else{
  3997. return 'invoicePaper';
  3998. }
  3999. }
  4000. die ( 'illegal request' );
  4001. }
  4002. /**
  4003. * 收款绑定发票 ,//一个收款只能绑定一个发票
  4004. */
  4005. function invoiceBindReceivables() {
  4006. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4007. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4008. Doo::loadModel ( 'invoice' );
  4009. $invoice = new invoice ();
  4010. Doo::loadModel ( 'invoiceReceivables' );
  4011. $invoiceReceivables = new invoiceReceivables ();
  4012. Doo::loadModel ( 'invoiceOperationLog' );
  4013. $invoiceOperationLog = new invoiceOperationLog ();
  4014. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4015. die ( 'illegal request' );
  4016. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4017. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4018. if (empty ( $detail ) && empty ( $detailM ))
  4019. die ( 'illegal request' );
  4020. if ($detail ['untreadStatus'] == 3)
  4021. die ( 'illegal request' );
  4022. // 修改 绑定状态改为 金额
  4023. $invoiceReceivables = new invoiceReceivables ();
  4024. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4025. $billPrice=0;
  4026. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4027. $item = array (
  4028. 'bindPrice' => $invoicePrice
  4029. );
  4030. $billPrice=$invoicePrice;
  4031. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) { //发票金额大于收款金额,绑定金额为收款金额
  4032. $item = array (
  4033. 'bindPrice' => $detailM ['receivablesPrice'],
  4034. 'bindStatus' => 1,
  4035. 'bindDate' => date ( "Y-m-d H:i:s" )
  4036. );
  4037. $billPrice=$detailM ['receivablesPrice'];
  4038. } else {
  4039. die ( 'illegal request' );
  4040. }
  4041. if ($detailM ['iid'] == 0) {
  4042. $item += array (
  4043. 'iid' => $detail ['iid']
  4044. );
  4045. } else {
  4046. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4047. array_push ( $iidExtend, $detail ['iid'] );
  4048. $item += array (
  4049. 'iidExtend' => implode ( ',', $iidExtend )
  4050. );
  4051. }
  4052. $titleMark = $detail ['invoiceTitle'];
  4053. if (! empty ( $detail ['invoiceCompany'] ))
  4054. $titleMark = $detail ['invoiceCompany'];
  4055. $item += array (
  4056. 'irid' => $detailM ['irid'],
  4057. 'recepitTitleMark' => $titleMark,
  4058. 'accountClerk' => $this->staff [0] ['username']
  4059. );
  4060. // 如何没有人收款 则自动绑定收款
  4061. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4062. $item += array (
  4063. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4064. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4065. );
  4066. }
  4067. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4068. $iridString = "";
  4069. if (empty ( $detail ['irid'] ))
  4070. $iridString = $detailM ['irid'];
  4071. else
  4072. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4073. // $invoiceReceivables = new invoiceReceivables ();
  4074. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4075. // //这个收款余额
  4076. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4077. // $sum=$sumBind+$sumBalance;
  4078. //这个收款余额
  4079. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4080. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4081. // die;
  4082. $item = array (
  4083. 'iid' => $detail ['iid'],
  4084. 'irid' => $iridString
  4085. );
  4086. if ($detail ['invoicePrice'] <= $sumBalance){
  4087. $item += array (
  4088. 'invoiceBalance'=>0,
  4089. 'untreadStatus' => 3,
  4090. 'bindTime' => date ( "Y-m-d H:i:s" )
  4091. );
  4092. }else{
  4093. $item += array (
  4094. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4095. );
  4096. }
  4097. // print_r($item);
  4098. // echo $sum;die;
  4099. $invoice->setInvoiceByCondition ( $item );
  4100. //发票入账记录
  4101. Doo::loadModel ( 'bill' );
  4102. $bill = new bill ();
  4103. $bill->iid=$detail ['iid'];
  4104. $bill->trainId=$detail['trainId'];
  4105. $bill->irid=$detailM ['irid'];
  4106. $bill->create_time=date ( "Y-m-d H:i:s" );
  4107. $bill->price=$billPrice;
  4108. $bill->insert ();
  4109. // 操作日志
  4110. $item = array (
  4111. 'date' => date ( "Y-m-d H:i:s" ),
  4112. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4113. 'status' => 8,
  4114. 'img' => $this->staff [0] ['avatar'],
  4115. 'username' => $this->staff [0] ['username'],
  4116. 'uid' => $this->staff [0] ['sid'],
  4117. 'category' => $this->staff [0] ['category'],
  4118. 'iid' => $detail ['iid']
  4119. );
  4120. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4121. Doo::loadModel ( 'invoiceStatistics' );
  4122. $invoiceStatistics = new invoiceStatistics ();
  4123. $item = array (
  4124. 'date' => $detailM ['receivablesDate'],
  4125. 'priceClass' => 3,
  4126. 'cid' => $detail ['cid'],
  4127. 'staff' => $detail ['sid'],
  4128. 'accountPrice' => $detailM ['receivablesPrice']
  4129. );
  4130. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4131. // 公司流水记录
  4132. // Doo::loadModel ( 'wasteBook' );
  4133. // $wasteBook = new wasteBook ();
  4134. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4135. // $accountBank='';
  4136. // if ($detailM ['receivablesBank']=='纵横广发'){
  4137. // $accountBank='CGBDeposit';
  4138. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4139. // $accountBank='ICBCDeposit';
  4140. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4141. // $accountBank='HUADeposit';
  4142. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4143. // $accountBank='PersonalDeposit';
  4144. // }
  4145. // if (empty($abDetail)){
  4146. // $item = array (
  4147. // 'dataID' => $detail ['iid'],
  4148. // 'expensesType' => 1,
  4149. // 'accountType' => 8,
  4150. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4151. // 'accountPrice'=>$detail ['invoicePrice'],
  4152. // 'accountBank'=>$accountBank,
  4153. // 'category'=>$this->staff[0]['category'],
  4154. // 'cid'=>$this->staff[0]['cid'],
  4155. // 'name'=>$this->staff[0]['username'],
  4156. // 'sid'=>$this->staff[0]['sid'],
  4157. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4158. // );
  4159. // $wasteBook->setAccountBookStatistics($item);
  4160. // }
  4161. return "/invoiceReceivables";
  4162. }
  4163. /**
  4164. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4165. */
  4166. function invoiceAggregate() {
  4167. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4168. Doo::loadModel ( 'invoiceStatistics' );
  4169. $invoiceStatistics = new invoiceStatistics ();
  4170. Doo::loadModel ( 'L_category' );
  4171. $Lcategory = new L_category ();
  4172. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4173. $LcategoryList = $Lcategory->getCategory ();
  4174. // print_r($isList);
  4175. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4176. foreach ( $LcategoryList as $key => $value ) {
  4177. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4178. $month = 1;
  4179. $invoicePriceYear = 0;
  4180. $receivablesPriceYear = 0;
  4181. $accountPriceYear = 0;
  4182. for(; $month <= 12; $month ++) {
  4183. $flag = true;
  4184. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4185. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4186. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4187. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4188. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4189. ';
  4190. $invoicePriceYear += $v ['invoicePrice'];
  4191. $receivablesPriceYear += $v ['receivablesPrice'];
  4192. $accountPriceYear += $v ['accountPrice'];
  4193. $flag = false;
  4194. break;
  4195. }
  4196. }
  4197. if ($flag)
  4198. $html .= '<td class="taR"></td>
  4199. <td class="taR"></td>
  4200. <td class="taR"><b></b></td>
  4201. ';
  4202. }
  4203. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4204. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4205. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4206. ';
  4207. $html .= '</tr>';
  4208. }
  4209. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4210. $invoicePriceYear = 0;
  4211. $receivablesPriceYear = 0;
  4212. $accountPriceYear = 0;
  4213. for($month = 1; $month <= 12; $month ++) {
  4214. $flag = true;
  4215. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4216. if ($month == $v ['month']) {
  4217. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4218. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4219. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4220. ';
  4221. $invoicePriceYear += $v ['invoicePrice'];
  4222. $receivablesPriceYear += $v ['receivablesPrice'];
  4223. $accountPriceYear += $v ['accountPrice'];
  4224. $flag = false;
  4225. break;
  4226. }
  4227. }
  4228. if ($flag) {
  4229. $html .= '<td class="taR"></td>
  4230. <td class="taR"></td>
  4231. <td class="taR"><b></b></td>
  4232. ';
  4233. }
  4234. }
  4235. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4236. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4237. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4238. ';
  4239. $html .= '</tr>';
  4240. // print_r($isList);
  4241. $this->data ['html'] = $html;
  4242. $this->data ['LcategoryList'] = $LcategoryList;
  4243. $this->data ['isList'] = $isList;
  4244. $this->data ['year'] = $year;
  4245. $this->data ['memu'] = "invoice";
  4246. $this->data ['staff'] = $this->staff;
  4247. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4248. $this->render ( "/admin/invoiceAggregate", $this->data );
  4249. }
  4250. function invoiceAggregateStaff() {
  4251. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4252. Doo::loadModel ( 'invoiceStatistics' );
  4253. $invoiceStatistics = new invoiceStatistics ();
  4254. Doo::loadModel ( 'L_category' );
  4255. $Lcategory = new L_category ();
  4256. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4257. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4258. $cStaff = $Lcategory->getCategoryStaff ();
  4259. $html = '';
  4260. foreach ( $cStaff as $key => $value ) {
  4261. $categoryFir = true;
  4262. foreach ( $value ['staff'] as $k => $v ) {
  4263. if ($categoryFir) {
  4264. $width = count ( $value ['staff'] ) + 1;
  4265. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4266. $categoryFir = false;
  4267. } else
  4268. $html .= '<tr>';
  4269. $html .= '<th>' . $v ['username'] . '</th>';
  4270. $invoicePriceStaffYear = 0;
  4271. $receivablesPriceStaffYear = 0;
  4272. $accountPriceStaffYear = 0;
  4273. for($month = 1; $month <= 12; $month ++) {
  4274. $flag = true;
  4275. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4276. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4277. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4278. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4279. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4280. ';
  4281. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4282. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4283. $accountPriceStaffYear += $slv ['accountPrice'];
  4284. $flag = false;
  4285. break;
  4286. }
  4287. }
  4288. if ($flag)
  4289. $html .= '<td class="taR"></td>
  4290. <td class="taR"></td>
  4291. <td class="taR"><b></b></td>
  4292. ';
  4293. }
  4294. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4295. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4296. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4297. ';
  4298. }
  4299. $html .= '</tr>';
  4300. // 小计
  4301. if (! empty ( $value ['staff'] )) {
  4302. $html .= '<tr><th class="taR">小计</th>';
  4303. $invoicePriceStaffYear = 0;
  4304. $receivablesPriceStaffYear = 0;
  4305. $accountPriceStaffYear = 0;
  4306. for($month = 1; $month <= 12; $month ++) {
  4307. $flag = true;
  4308. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4309. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4310. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4311. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4312. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4313. ';
  4314. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4315. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4316. $accountPriceStaffYear += $slv ['accountPrice'];
  4317. $flag = false;
  4318. break;
  4319. }
  4320. }
  4321. if ($flag)
  4322. $html .= '<td class="taR"></td>
  4323. <td class="taR"></td>
  4324. <td class="taR"><b></b></td>
  4325. ';
  4326. }
  4327. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4328. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4329. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4330. ';
  4331. $html .= '</tr>';
  4332. }
  4333. }
  4334. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4335. $invoicePriceYear = 0;
  4336. $receivablesPriceYear = 0;
  4337. $accountPriceYear = 0;
  4338. for($month = 1; $month <= 12; $month ++) {
  4339. $flag = true;
  4340. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4341. if ($month == $v ['month']) {
  4342. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4343. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4344. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4345. ';
  4346. $invoicePriceYear += $v ['invoicePrice'];
  4347. $receivablesPriceYear += $v ['receivablesPrice'];
  4348. $accountPriceYear += $v ['accountPrice'];
  4349. $flag = false;
  4350. break;
  4351. }
  4352. }
  4353. if ($flag)
  4354. $html .= '<td class="taR"></td>
  4355. <td class="taR"></td>
  4356. <td class="taR"><b></b></td>
  4357. ';
  4358. }
  4359. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4360. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4361. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4362. ';
  4363. $html .= '</tr>';
  4364. $this->data ['html'] = $html;
  4365. $this->data ['isList'] = $toteList;
  4366. $this->data ['year'] = $year;
  4367. $this->data ['memu'] = "invoice";
  4368. $this->data ['staff'] = $this->staff;
  4369. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4370. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4371. }
  4372. function invoiceAggregateCategory() {
  4373. Doo::loadClass ( 'XDeode' );
  4374. $XDeode = new XDeode ( 5 );
  4375. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4376. $cid = $XDeode->decode ( $cid );
  4377. if (! is_numeric ( $cid ))
  4378. die ( 'illegal request' );
  4379. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4380. Doo::loadModel ( 'invoiceStatistics' );
  4381. $invoiceStatistics = new invoiceStatistics ();
  4382. Doo::loadModel ( 'staff' );
  4383. $staff = new staff ();
  4384. $list = $staff->getStaffByCid ( $cid );
  4385. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4386. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4387. if (empty ( $list ))
  4388. die ( '该办事处没有成员' );
  4389. $htmlA = $htmlB = $htmlC = $html = '';
  4390. foreach ( $list as $key => $value ) {
  4391. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4392. $htmlB = '<tr><th class="taC">收款</th>';
  4393. $htmlC = '<tr><th class="taC">入账</th>';
  4394. $invoicePriceStaffYear = 0;
  4395. $receivablesPriceStaffYear = 0;
  4396. $accountPriceStaffYear = 0;
  4397. for($month = 1; $month <= 12; $month ++) {
  4398. $flag = true;
  4399. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4400. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4401. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4402. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4403. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4404. $invoicePriceStaffYear += $v ['invoicePrice'];
  4405. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4406. $accountPriceStaffYear += $v ['accountPrice'];
  4407. $flag = false;
  4408. break;
  4409. }
  4410. }
  4411. if ($flag) {
  4412. $htmlA .= '<td class="taR">-</td>';
  4413. $htmlB .= '<td class="taR">-</td>';
  4414. $htmlC .= '<td class="taR"><b>-</b></td>';
  4415. }
  4416. }
  4417. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4418. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4419. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4420. $htmlA .= '</tr>';
  4421. $htmlB .= '</tr>';
  4422. $htmlC .= '</tr>';
  4423. $html .= $htmlA . $htmlB . $htmlC;
  4424. }
  4425. $htmlA = $htmlB = $htmlC = "";
  4426. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4427. $htmlB = '<tr><th class="taC">收款</th>';
  4428. $htmlC = '<tr><th class="taC">入账</th>';
  4429. $invoicePriceStaffYear = 0;
  4430. $receivablesPriceStaffYear = 0;
  4431. $accountPriceStaffYear = 0;
  4432. for($month = 1; $month <= 12; $month ++) {
  4433. $flag = true;
  4434. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4435. if ($month == $v ['month']) {
  4436. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4437. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4438. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4439. $invoicePriceStaffYear += $v ['invoicePrice'];
  4440. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4441. $accountPriceStaffYear += $v ['accountPrice'];
  4442. $flag = false;
  4443. break;
  4444. }
  4445. }
  4446. if ($flag) {
  4447. $htmlA .= '<td class="taR">-</td>';
  4448. $htmlB .= '<td class="taR">-</td>';
  4449. $htmlC .= '<td class="taR"><b>-</b></td>';
  4450. }
  4451. }
  4452. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4453. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4454. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4455. $htmlA .= '</tr>';
  4456. $htmlB .= '</tr>';
  4457. $htmlC .= '</tr>';
  4458. $html .= $htmlA . $htmlB . $htmlC;
  4459. $this->data ['html'] = $html;
  4460. $this->data ['cidKey'] = $cidKey;
  4461. $this->data ['slist'] = $list;
  4462. $this->data ['isList'] = $toteList;
  4463. $this->data ['year'] = $year;
  4464. $this->data ['memu'] = "invoice";
  4465. $this->data ['staff'] = $this->staff;
  4466. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4467. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4468. }
  4469. /**
  4470. * 办事处汇总信息
  4471. */
  4472. function invoiceAggregateCategoryDetail() {
  4473. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4474. Doo::loadClass ( 'XDeode' );
  4475. $XDeode = new XDeode ( 5 );
  4476. Doo::loadModel ( 'invoiceStatistics' );
  4477. $invoiceStatistics = new invoiceStatistics ();
  4478. Doo::loadModel ( 'L_category' );
  4479. $category = new L_category ();
  4480. Doo::loadModel ( 'invoice' );
  4481. $invoice = new invoice ();
  4482. Doo::loadModel ( 'staff' );
  4483. $staff = new staff ();
  4484. Doo::loadModel ( "invoiceCategoryManage" );
  4485. $invoiceCategoryManage = new invoiceCategoryManage ();
  4486. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4487. $cidList = array ();
  4488. foreach ( $imcStaff as $key => $value ) {
  4489. array_push ( $cidList, $value ['cid'] );
  4490. if (empty ( $cidKey ))
  4491. $cidKey = $XDeode->encode ( $value ['cid'] );
  4492. }
  4493. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4494. $cid = $XDeode->decode ( $cidKey );
  4495. $month = date ( "m", strtotime ( "-1 month" ) );
  4496. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4497. $redis = new Redis ();
  4498. $redis->connect ( '127.0.0.1', '6379' );
  4499. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4500. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4501. if (empty ( $redisValue )) {
  4502. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4503. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4504. // 获得办事处人员下的汇总
  4505. $slist = $staff->getStaffByCid ( $cid );
  4506. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4507. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4508. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4509. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4510. foreach ( $slist as $key => $value ) {
  4511. $slist [$key] ['invoicePrice'] = 0;
  4512. $slist [$key] ['receivablesPrice'] = 0;
  4513. $slist [$key] ['accountPrice'] = 0;
  4514. $slist [$key] ['invoiceAllPrice'] = 0;
  4515. $slist [$key] ['receivablesAllPrice'] = 0;
  4516. $slist [$key] ['accountAllPrice'] = 0;
  4517. $slist [$key] ['schedule'] = 0;
  4518. $slist [$key] ['invoiceMonthPrice'] = 0;
  4519. $slist [$key] ['receivablesMonthPrice'] = 0;
  4520. $slist [$key] ['accountMonthPrice'] = 0;
  4521. foreach ( $ismsbMonth as $y => $l ) {
  4522. if ($value ['sid'] == $l ['staff']) {
  4523. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4524. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4525. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4526. }
  4527. }
  4528. foreach ( $ismsb as $k => $v ) {
  4529. if ($value ['sid'] == $v ['staff']) {
  4530. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4531. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4532. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4533. }
  4534. }
  4535. foreach ( $ISAS as $e => $a ) {
  4536. if ($value ['sid'] == $a ['staff']) {
  4537. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4538. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4539. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4540. }
  4541. }
  4542. if (isset ( $scheduleStaff [$value ['sid']] ))
  4543. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4544. }
  4545. $this->data ['cidKey'] = $cidKey;
  4546. $schedule = ( int ) ($schedule * 100);
  4547. $this->data ['slist'] = $slist;
  4548. $this->data ['isMC'] = $isMC;
  4549. $this->data ['schedule'] = $schedule;
  4550. $slist = json_encode ( $slist );
  4551. $isMC = json_encode ( $isMC );
  4552. $schedule = json_encode ( $schedule );
  4553. $redis->lpush ( $redisKey, $slist );
  4554. $redis->lpush ( $redisKey, $isMC );
  4555. $redis->lpush ( $redisKey, $schedule );
  4556. } else {
  4557. $this->data ['cidKey'] = $cidKey;
  4558. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4559. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4560. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4561. }
  4562. $this->data ['month'] = $month;
  4563. $this->data ['categoryList'] = $categoryList;
  4564. $this->data ['memu'] = "invoice";
  4565. $this->data ['staff'] = $this->staff;
  4566. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4567. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4568. }
  4569. /**
  4570. * 办事处人员汇总详情
  4571. */
  4572. function invoiceAggregateStaffDetail() {
  4573. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4574. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4575. Doo::loadClass ( 'XDeode' );
  4576. $XDeode = new XDeode ( 5 );
  4577. Doo::loadModel ( 'invoice' );
  4578. $invoice = new invoice ();
  4579. Doo::loadModel ( 'staff' );
  4580. $staff = new staff ();
  4581. Doo::loadModel ( "invoiceCategoryManage" );
  4582. $invoiceCategoryManage = new invoiceCategoryManage ();
  4583. $sid = $XDeode->decode ( $sidKey );
  4584. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4585. $cidList = array ();
  4586. foreach ( $imcStaff as $key => $value ) {
  4587. array_push ( $cidList, $value ['cid'] );
  4588. if (empty ( $cidKey ))
  4589. $cidKey = $XDeode->encode ( $value ['cid'] );
  4590. }
  4591. $cidString = implode ( ',', $cidList );
  4592. $staffList = $staff->getStaffInCid ( $cidString );
  4593. $staffDetail = $staff->getStaffBySid ( $sid );
  4594. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4595. $page_size = 18;
  4596. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4597. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4598. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4599. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4600. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4601. $dateArr = explode ( ':', $date );
  4602. $D1 = '';
  4603. $D2 = '';
  4604. if (! empty ( $date )) {
  4605. $D1 = $dateArr [0] . " 00:00:00 ";
  4606. if (isset ( $dateArr [1] ))
  4607. $D2 = $dateArr [1] . " 23:59:59 ";
  4608. else
  4609. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4610. // $D2 = $dateArr [1];
  4611. }
  4612. $con = ' status=2 ';
  4613. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4614. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4615. if ($status == 'UNRECORD')
  4616. $con .= ' and printStatus=1 and untreadStatus=0';
  4617. elseif ($status == 'RECORD')
  4618. $con .= ' and printStatus=1 and untreadStatus=3';
  4619. elseif ($status == 'BOUNCED')
  4620. $con .= ' and untreadStatus=2';
  4621. elseif ($status == 'PARTRECORD')
  4622. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4623. elseif ($status == 'All') {
  4624. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4625. }
  4626. $con .= ' and sid=' . $sid;
  4627. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4628. if (! empty ( $MebSea )) {
  4629. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4630. }
  4631. $pageinfo ['page'] = array (
  4632. 'previous' => ''
  4633. );
  4634. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4635. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4636. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4637. $this->data ['staffDetail'] = $staffDetail;
  4638. $this->data ['staffList'] = $staffList;
  4639. $this->data ['MebSeaEn'] = $MebSea;
  4640. $this->data ['MebSea'] = urlencode ( $MebSea );
  4641. $this->data ['date'] = $date;
  4642. $this->data ['page'] = $pageinfo;
  4643. $this->data ['get'] = $get;
  4644. $this->data ['list'] = $list;
  4645. $this->data ['status'] = $status;
  4646. $this->data ['sidKey'] = $sidKey;
  4647. $this->data ['memu'] = "invoice";
  4648. $this->data ['staff'] = $this->staff;
  4649. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4650. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4651. }
  4652. /**
  4653. * 办事处人员汇总收款情
  4654. */
  4655. function invoiceAggregateStaffReceivablesDetail() {
  4656. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4657. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4658. Doo::loadModel ( 'invoiceReceivables' );
  4659. $invoiceReceivables = new invoiceReceivables ();
  4660. Doo::loadModel ( 'staff' );
  4661. $staff = new staff ();
  4662. Doo::loadModel ( "invoiceCategoryManage" );
  4663. $invoiceCategoryManage = new invoiceCategoryManage ();
  4664. Doo::loadClass ( 'XDeode' );
  4665. $XDeode = new XDeode ( 5 );
  4666. $sid = $XDeode->decode ( $sidKey );
  4667. $staffDetail = $staff->getStaffBySid ( $sid );
  4668. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4669. $cidList = array ();
  4670. foreach ( $imcStaff as $key => $value ) {
  4671. array_push ( $cidList, $value ['cid'] );
  4672. if (empty ( $cidKey ))
  4673. $cidKey = $XDeode->encode ( $value ['cid'] );
  4674. }
  4675. $cidString = implode ( ',', $cidList );
  4676. $staffList = $staff->getStaffInCid ( $cidString );
  4677. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4678. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4679. $page_size = 10;
  4680. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4681. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4682. if ($timeType == "BINDOTP") {
  4683. $status = 'Credited';
  4684. }
  4685. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4686. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4687. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4688. $dateArr = explode ( ':', $date );
  4689. $D1 = '';
  4690. $D2 = '';
  4691. if (! empty ( $date )) {
  4692. $D1 = $dateArr [0] . " 00:00:00 ";
  4693. if (isset ( $dateArr [1] ))
  4694. $D2 = $dateArr [1] . " 23:59:59 ";
  4695. else
  4696. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4697. }
  4698. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4699. $descField = 'a.bindDate';
  4700. if ($timeType == 'CREATE')
  4701. $descField = 'a.date';
  4702. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4703. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4704. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4705. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4706. if ($status == 'Unclaimed')
  4707. $con .= ' and a.bindStatus=0';
  4708. elseif ($status == 'Credited')
  4709. $con .= ' and a.bindStatus=1';
  4710. elseif ($status == 'Claim')
  4711. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4712. elseif ($status == 'BBN')
  4713. $con .= ' and a.bindPrice>a.receivablesPrice';
  4714. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4715. if (! empty ( $MebSea )) {
  4716. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4717. }
  4718. $pageinfo ['page'] = array (
  4719. 'previous' => ''
  4720. );
  4721. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4722. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4723. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4724. // where ' . $con . ' group by a.irid ';
  4725. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4726. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4727. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4728. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4729. foreach ( $list as $key => $value ) {
  4730. $list [$key] ['category'] = '';
  4731. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4732. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4733. $list [$key] ['category'] = $receivablesCategory [1];
  4734. }
  4735. }
  4736. // print_r($list);
  4737. $this->data ['staffDetail'] = $staffDetail;
  4738. $this->data ['sidKey'] = $sidKey;
  4739. $this->data ['staffList'] = $staffList;
  4740. $this->data ['timeType'] = $timeType;
  4741. $this->data ['MebSeaEn'] = $MebSea;
  4742. $this->data ['MebSea'] = urlencode ( $MebSea );
  4743. $this->data ['date'] = $date;
  4744. $this->data ['page'] = $pageinfo;
  4745. $this->data ['get'] = $get;
  4746. $this->data ['list'] = $list;
  4747. $this->data ['status'] = $status;
  4748. $this->data ['memu'] = "invoice";
  4749. $this->data ['staff'] = $this->staff;
  4750. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4751. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4752. }
  4753. function invoiceAchieve() {
  4754. Doo::loadModel ( 'invoice' );
  4755. $invoice = new invoice ();
  4756. Doo::loadClass ( 'XDeode' );
  4757. $XDeode = new XDeode ( 5 );
  4758. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4759. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4760. $page_size = 18;
  4761. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4762. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4763. $get = "/" . $date;
  4764. $con = '';
  4765. if ($date == 'MONTHO')
  4766. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4767. elseif ($date == 'MONTHT')
  4768. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4769. elseif ($date == 'MONTHY')
  4770. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4771. if (! empty ( $MebSea )) {
  4772. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4773. $get .= "/" . $MebSea;
  4774. }
  4775. $pageinfo ['page'] = array (
  4776. 'previous' => ''
  4777. );
  4778. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4779. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4780. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4781. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4782. // print_r($pageinfo);
  4783. $this->data ['MebSeaEn'] = $MebSea;
  4784. $this->data ['MebSea'] = urlencode ( $MebSea );
  4785. $this->data ['get'] = $get;
  4786. $this->data ['page'] = $pageinfo;
  4787. $this->data ['list'] = $list;
  4788. $this->data ['date'] = $date;
  4789. $this->data ['memu'] = "invoice";
  4790. $this->data ['staff'] = $this->staff;
  4791. $this->data ['receiptMemu'] = 'invoice';
  4792. $this->render ( "/admin/invoiceAchieve", $this->data );
  4793. }
  4794. /**
  4795. */
  4796. function invoiceMyUnAccountAchieve() {
  4797. Doo::loadModel ( 'invoice' );
  4798. $invoice = new invoice ();
  4799. Doo::loadClass ( 'XDeode' );
  4800. $XDeode = new XDeode ( 5 );
  4801. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4802. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4803. $page_size = 18;
  4804. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4805. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4806. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4807. $dateArr = explode ( ':', $date );
  4808. $D1 = '';
  4809. $D2 = '';
  4810. if (! empty ( $date )) {
  4811. $D1 = $dateArr [0];
  4812. $D2 = $dateArr [1];
  4813. }
  4814. $con = '';
  4815. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4816. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4817. if (! empty ( $MebSea )) {
  4818. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4819. }
  4820. $pageinfo ['page'] = array (
  4821. 'previous' => ''
  4822. );
  4823. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4824. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4825. $action = "invoiceMyUnAccountAchieve";
  4826. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4827. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4828. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4829. Doo::loadModel ( 'express' );
  4830. $express = new express ();
  4831. $expressList = $express->getExpressByAll ();
  4832. $this->data ['expressList'] = $expressList;
  4833. // print_r($list);
  4834. $this->data ['MebSeaEn'] = $MebSea;
  4835. $this->data ['get'] = $get;
  4836. $this->data ['page'] = $pageinfo;
  4837. $this->data ['date'] = $date;
  4838. $this->data ['list'] = $list;
  4839. $this->data ['memu'] = "invoice";
  4840. $this->data ['staff'] = $this->staff;
  4841. $this->data ['receiptMemu'] = 'invoice';
  4842. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4843. }
  4844. function invoiceReceivablesAchieve() {
  4845. Doo::loadModel ( 'invoiceReceivables' );
  4846. $invoiceReceivables = new invoiceReceivables ();
  4847. Doo::loadClass ( 'XDeode' );
  4848. $XDeode = new XDeode ( 5 );
  4849. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4850. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4851. $page_size = 12;
  4852. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4853. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4854. $get = "/" . $date;
  4855. $con = '';
  4856. if ($date == 'MONTHO')
  4857. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4858. elseif ($date == 'MONTHT')
  4859. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4860. elseif ($date == 'MONTHY')
  4861. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4862. if (! empty ( $MebSea )) {
  4863. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4864. $get .= "/" . $MebSea;
  4865. }
  4866. $pageinfo ['page'] = array (
  4867. 'previous' => ''
  4868. );
  4869. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4870. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4871. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4872. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4873. // print_r($pageinfo);
  4874. $this->data ['MebSeaEn'] = $MebSea;
  4875. $this->data ['MebSea'] = urlencode ( $MebSea );
  4876. $this->data ['get'] = $get;
  4877. $this->data ['page'] = $pageinfo;
  4878. $this->data ['list'] = $list;
  4879. $this->data ['date'] = $date;
  4880. $this->data ['memu'] = "invoice";
  4881. $this->data ['staff'] = $this->staff;
  4882. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4883. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4884. }
  4885. /**
  4886. * 收款解绑
  4887. */
  4888. function invoiceUnBundLing() {
  4889. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4890. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4891. Doo::loadModel ( 'invoice' );
  4892. $invoice = new invoice ();
  4893. Doo::loadModel ( 'invoiceReceivables' );
  4894. $invoiceReceivables = new invoiceReceivables ();
  4895. Doo::loadModel ( 'invoiceOperationLog' );
  4896. $invoiceOperationLog = new invoiceOperationLog ();
  4897. Doo::loadModel ( 'invoiceROLog' );
  4898. $invoiceROLog = new invoiceROLog ();
  4899. Doo::loadModel ( 'invoiceStatistics' );
  4900. Doo::loadClass ( 'XDeode' );
  4901. $XDeode = new XDeode ( 5 );
  4902. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4903. die ( 'illegal request' );
  4904. $iid = $XDeode->decode ( $iidKey );
  4905. $irid = $invoice->authcode ( $unBundKey );
  4906. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4907. die ( 'illegal request' );
  4908. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4909. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4910. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4911. die ( 'illegal request' );
  4912. // 收款
  4913. $item = array (
  4914. 'irid' => $irDetails ['irid'],
  4915. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4916. 'bindStatus' => 0
  4917. );
  4918. if ($irDetails ['iid'] == $iid)
  4919. $item += array (
  4920. 'iid' => 0
  4921. );
  4922. else {
  4923. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4924. foreach ( $iidExtend as $key => $value ) {
  4925. if ($value == $iid)
  4926. unset ( $iidExtend [$key] );
  4927. }
  4928. $iidExtend = implode ( ',', $iidExtend );
  4929. $item += array (
  4930. 'iidExtend' => $iidExtend
  4931. );
  4932. }
  4933. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4934. // 收款操作日志
  4935. $item = array (
  4936. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4937. 'date' => date ( "Y-m-d" ),
  4938. 'status' => 3,
  4939. 'img' => $this->staff [0] ['avatar'],
  4940. 'username' => $this->staff [0] ['username'],
  4941. 'uid' => $this->staff [0] ['sid'],
  4942. 'category' => $this->staff [0] ['category'],
  4943. 'irid' => $irid
  4944. );
  4945. $invoiceROLog->setInvoiceROLog ( $item );
  4946. // 扣除入账统计金额
  4947. $invoiceStatistics = new invoiceStatistics ();
  4948. $item = array (
  4949. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4950. 'priceClass' => 3,
  4951. 'cid' => $invoiceDetails ['cid'],
  4952. 'staff' => $invoiceDetails ['sid'],
  4953. 'accountPrice' => - $invoiceDetails ['invoicePrice']
  4954. );
  4955. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4956. // 扣除收款统计金额
  4957. $invoiceStatistics = new invoiceStatistics ();
  4958. $item = array (
  4959. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4960. 'priceClass' => 2,
  4961. 'cid' => $invoiceDetails ['cid'],
  4962. 'staff' => $invoiceDetails ['sid'],
  4963. 'irid' => $irDetails ['irid'],
  4964. 'receivablesPrice' => - $invoiceDetails ['invoicePrice']
  4965. );
  4966. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4967. // 发票解绑去收款ID
  4968. $iridString = $invoiceDetails ['irid'];
  4969. if (! empty ( $invoiceDetails ['irid'] )) {
  4970. $list = explode ( ',', $invoiceDetails ['irid'] );
  4971. foreach ( $list as $key => $value ) {
  4972. if ($value == $irDetails ['irid']) {
  4973. unset ( $list [$key] );
  4974. break;
  4975. }
  4976. }
  4977. $iridString = implode ( ",", $list );
  4978. }
  4979. $item = array (
  4980. 'iid' => $invoiceDetails ['iid'],
  4981. 'irid' => $iridString,
  4982. 'updateTime' => date ( "Y-m-d H:i:s" )
  4983. );
  4984. if ($invoiceDetails ['untreadStatus'] == 3)
  4985. $item += array (
  4986. 'untreadStatus' => 0
  4987. );
  4988. $invoice->setInvoiceByCondition ( $item );
  4989. Doo::loadModel ( 'bill' );
  4990. $bill = new bill ();
  4991. $bill->iid=$invoiceDetails ['iid'];
  4992. $bill->trainId=$invoiceDetails['trainId'];
  4993. $bill->irid=$irDetails ['irid'];
  4994. $bill->create_time=date ( "Y-m-d H:i:s" );
  4995. $bill->price=-$invoiceDetails ['invoicePrice'];
  4996. $bill->remark='解绑-扣除入账';
  4997. $bill->insert ();
  4998. $item = array (
  4999. 'date' => date ( "Y-m-d H:i:s" ),
  5000. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  5001. 'status' => 11,
  5002. 'img' => $this->staff [0] ['avatar'],
  5003. 'username' => $this->staff [0] ['username'],
  5004. 'uid' => $this->staff [0] ['sid'],
  5005. 'category' => $this->staff [0] ['category'],
  5006. 'iid' => $invoiceDetails ['iid']
  5007. );
  5008. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5009. // 公司流水-解绑时删除流水
  5010. // Doo::loadModel ( 'wasteBook' );
  5011. // $wasteBook = new wasteBook ();
  5012. // $wasteBook->delete ( array (
  5013. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  5014. // 'limit' => 1
  5015. // ) );
  5016. // 银行
  5017. /*
  5018. * $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); }
  5019. */
  5020. return "/invoiceReceivablesAS";
  5021. }
  5022. /**
  5023. * 或者该收款下的所以发票
  5024. */
  5025. function ajaxGetInvoiceReceivablesByInvoice() {
  5026. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  5027. Doo::loadModel ( 'invoice' );
  5028. $invoice = new invoice ();
  5029. Doo::loadModel ( 'invoiceReceivables' );
  5030. $invoiceReceivables = new invoiceReceivables ();
  5031. $irid = $invoice->authcode ( $irid );
  5032. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5033. die ( 'illegal request' );
  5034. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5035. $iidString = $irDetails ['iid'];
  5036. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5037. if (! empty ( $irDetails ['iidExtend'] ))
  5038. $iidString .= ',' . implode ( ',', $iidExtend );
  5039. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5040. $html = "";
  5041. foreach ( $invoiceList as $key => $value ) {
  5042. $title = $value ['invoiceTitle'];
  5043. if (! empty ( $value ['invoiceCompany'] ))
  5044. $title = $value ['invoiceCompany'];
  5045. $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>';
  5046. }
  5047. echo json_encode ( array (
  5048. 'status' => 1,
  5049. 'html' => $html
  5050. ) );
  5051. }
  5052. /**
  5053. * 发票管理
  5054. */
  5055. function invoiceAS() {
  5056. Doo::loadModel ( 'invoice' );
  5057. $invoice = new invoice ();
  5058. Doo::loadModel ( 'invoiceReceivables' );
  5059. $invoiceReceivables = new invoiceReceivables ();
  5060. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5061. $page_size = 18;
  5062. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5063. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5064. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5065. $dateArr = explode ( ':', $date );
  5066. $D1 = '';
  5067. $D2 = '';
  5068. if (! empty ( $date )) {
  5069. $D1 = $dateArr [0] . " 00:00:00 ";
  5070. if (isset ( $dateArr [1] ))
  5071. $D2 = $dateArr [1] . " 23:59:59 ";
  5072. else
  5073. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5074. // $D2 = $dateArr [1];
  5075. }
  5076. $con = ' status=2 ';
  5077. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5078. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5079. if ($status == 'UNRECORD')
  5080. $con .= ' and printStatus=1 and untreadStatus=0';
  5081. elseif ($status == 'RECORD')
  5082. $con .= ' and printStatus=1 and untreadStatus=3';
  5083. elseif ($status == 'BOUNCED')
  5084. $con .= ' and untreadStatus=2';
  5085. elseif ($status == 'PARTRECORD')
  5086. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5087. elseif ($status == 'All') {
  5088. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5089. }
  5090. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5091. if (! empty ( $MebSea )) {
  5092. $con .= ' and ( invoiceSerial like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5093. }
  5094. $pageinfo ['page'] = array (
  5095. 'previous' => ''
  5096. );
  5097. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5098. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5099. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5100. $this->data ['MebSeaEn'] = $MebSea;
  5101. $this->data ['MebSea'] = urlencode ( $MebSea );
  5102. $this->data ['date'] = $date;
  5103. $this->data ['page'] = $pageinfo;
  5104. $this->data ['get'] = $get;
  5105. $this->data ['list'] = $list;
  5106. $this->data ['status'] = $status;
  5107. $this->data ['memu'] = "invoice";
  5108. $this->data ['staff'] = $this->staff;
  5109. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5110. $this->render ( "/admin/invoiceAS", $this->data );
  5111. }
  5112. /**
  5113. * 收款管理
  5114. */
  5115. function invoiceReceivablesAS() {
  5116. Doo::loadModel ( 'invoiceReceivables' );
  5117. $invoiceReceivables = new invoiceReceivables ();
  5118. Doo::loadModel ( 'L_category' );
  5119. $lCategory = new L_category ();
  5120. $category = $lCategory->getCategory ();
  5121. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5122. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5123. $page_size = 10;
  5124. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5125. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5126. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5127. $dateArr = explode ( ':', $date );
  5128. $D1 = '';
  5129. $D2 = '';
  5130. if (! empty ( $date )) {
  5131. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5132. if (isset ( $dateArr [1] ))
  5133. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5134. else
  5135. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5136. }
  5137. $descField = 'a.receivablesDate';
  5138. if ($timeType == 'CREATE')
  5139. $descField = 'a.date';
  5140. $con = ' 1 ';
  5141. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5142. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5143. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5144. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5145. if ($status == 'Unclaimed')
  5146. $con .= ' and a.bindStatus=0';
  5147. elseif ($status == 'Credited')
  5148. $con .= ' and a.bindStatus=1';
  5149. elseif ($status == 'Claim')
  5150. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5151. elseif ($status == 'BBN')
  5152. $con .= ' and a.bankBatchNumber!=""';
  5153. elseif ($status == 'REFUND')
  5154. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5155. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5156. if (! empty ( $MebSea )) {
  5157. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5158. }
  5159. $pageinfo ['page'] = array (
  5160. 'previous' => ''
  5161. );
  5162. // if(!empty($con)){
  5163. // $con=' where 1 '.$con;
  5164. // }
  5165. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5166. // ' . $con ;
  5167. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5168. //echo $sql;
  5169. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5170. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5171. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5172. foreach ( $list as $key => $value ) {
  5173. $list [$key] ['category'] = '';
  5174. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5175. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5176. $list [$key] ['category'] = $receivablesCategory [1];
  5177. }
  5178. }
  5179. // print_r($list);
  5180. $this->data ['category'] = $category;
  5181. $this->data ['timeType'] = $timeType;
  5182. $this->data ['MebSeaEn'] = $MebSea;
  5183. $this->data ['MebSea'] = urlencode ( $MebSea );
  5184. $this->data ['date'] = $date;
  5185. $this->data ['page'] = $pageinfo;
  5186. $this->data ['get'] = $get;
  5187. $this->data ['list'] = $list;
  5188. $this->data ['status'] = $status;
  5189. $this->data ['memu'] = "invoice";
  5190. $this->data ['staff'] = $this->staff;
  5191. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5192. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5193. }
  5194. /**
  5195. * 删除一条收款
  5196. */
  5197. function delInvoiceReceivables() {
  5198. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5199. if (empty ( $iridKey ))
  5200. die ( 'illegal request' );
  5201. Doo::loadClass ( 'XDeode' );
  5202. $XDeode = new XDeode ( 5 );
  5203. $irid = $XDeode->decode ( $iridKey );
  5204. Doo::loadModel ( 'invoiceReceivables' );
  5205. $invoiceReceivables = new invoiceReceivables ();
  5206. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5207. if (empty ( $detail ))
  5208. die ( 'illegal request' );
  5209. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5210. // 扣除收款汇总信息 汇总
  5211. Doo::loadModel ( 'invoiceStatistics' );
  5212. $invoiceStatistics = new invoiceStatistics ();
  5213. $item = array (
  5214. 'date' => $detail ['receivablesDate'],
  5215. 'priceClass' => 2,
  5216. 'irid' => $detail ['irid'],
  5217. 'receivablesPrice' => - $detail ['receivablesPrice']
  5218. );
  5219. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5220. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5221. $item += array (
  5222. 'cid' => $receivablesCategory [0]
  5223. );
  5224. }
  5225. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5226. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5227. $item += array (
  5228. 'staff' => $receivablesStaff [0]
  5229. );
  5230. }
  5231. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5232. return '/invoiceReceivablesAS';
  5233. }
  5234. /**
  5235. * 添加退款信息
  5236. */
  5237. function setInvoiceReceivablesRefund() {
  5238. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5239. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5240. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5241. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5242. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5243. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5244. if ($refundPrice < 0)
  5245. die ( 'illegal request' );
  5246. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5247. Doo::loadModel ( 'invoiceReceivables' );
  5248. $invoiceReceivables = new invoiceReceivables ();
  5249. Doo::loadModel ( 'invoiceRefund' );
  5250. $invoiceRefund = new invoiceRefund ();
  5251. $irid = $invoiceReceivables->authcode ( $iridKey );
  5252. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5253. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5254. die ( 'illegal request' );
  5255. $invoiceReceivables = new invoiceReceivables ();
  5256. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5257. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5258. ';
  5259. $item = array (
  5260. 'irid' => $irid,
  5261. 'refundCompany' => $refundCompany,
  5262. 'refundNumber' => $refundNumber,
  5263. 'refundPrice' => $refundPrice,
  5264. 'refundRemarks' => $refundRemarks,
  5265. 'refundLog' => $refundLog
  5266. );
  5267. if ($refundType == 1) {
  5268. $item += array (
  5269. 'refundType' => $refundType,
  5270. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5271. 'bindStatus' => 2
  5272. );
  5273. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5274. $item += array (
  5275. 'refundType' => 1,
  5276. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5277. 'bindStatus' => 2
  5278. );
  5279. } else {
  5280. $item += array (
  5281. 'refundType' => $refundType,
  5282. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5283. );
  5284. }
  5285. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5286. // 添加退款记录
  5287. $item = array (
  5288. 'irid' => $irid,
  5289. 'refundType' => $refundType,
  5290. 'refundCompany' => $refundCompany,
  5291. 'refundNumber' => $refundNumber,
  5292. 'refundPrice' => $refundPrice,
  5293. 'refundLog' => $refundLog,
  5294. 'refundRemarks' => $refundRemarks,
  5295. 'date' => date ( "Y-m-d H:i:s" )
  5296. );
  5297. $invoiceRefund->addInvoiceRefund ( $item );
  5298. // 扣除收款汇总信息 汇总
  5299. Doo::loadModel ( 'invoiceStatistics' );
  5300. $invoiceStatistics = new invoiceStatistics ();
  5301. $item = array (
  5302. 'date' => $irDetail ['receivablesDate'],
  5303. 'priceClass' => 2,
  5304. 'irid' => $irDetail ['irid'],
  5305. 'receivablesPrice' => - $refundPrice
  5306. );
  5307. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5308. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5309. $item += array (
  5310. 'cid' => $receivablesCategory [0]
  5311. );
  5312. }
  5313. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5314. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5315. $item += array (
  5316. 'staff' => $receivablesStaff [0]
  5317. );
  5318. }
  5319. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5320. // 公司日常支出流水
  5321. Doo::loadModel ( 'wasteBook' );
  5322. $wasteBook = new wasteBook ();
  5323. $accountBank = '';
  5324. if ($irDetail ['receivablesBank'] == '纵横广发') {
  5325. $accountBank = 'CGBDeposit';
  5326. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  5327. $accountBank = 'ICBCDeposit';
  5328. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  5329. $accountBank = 'HUADeposit';
  5330. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  5331. $accountBank = 'PersonalDeposit';
  5332. }
  5333. $itemWaste = array (
  5334. 'accountPrice' => - $refundPrice,
  5335. 'expensesType' => 2,
  5336. 'accountType' => 11,
  5337. 'accountPriceShow' => $refundPrice,
  5338. 'dataID' => $irid,
  5339. 'accountBank' => $accountBank,
  5340. 'category' => $this->staff [0] ['category'],
  5341. 'cid' => $this->staff [0] ['cid'],
  5342. 'name' => $this->staff [0] ['username'],
  5343. 'sid' => $this->staff [0] ['sid'],
  5344. 'inputDate' => date ( "Y-m-d H:i:s" )
  5345. );
  5346. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5347. return '/invoiceReceivablesAS';
  5348. }
  5349. die ( 'illegal request' );
  5350. }
  5351. function ajaxCheckInvoiceReceivablesRefund() {
  5352. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5353. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5354. if ($refundPrice < 0) {
  5355. echo json_encode ( array (
  5356. 'error' => '金额不能为负'
  5357. ) );
  5358. die ();
  5359. }
  5360. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5361. Doo::loadModel ( 'invoiceReceivables' );
  5362. $invoiceReceivables = new invoiceReceivables ();
  5363. $irid = $invoiceReceivables->authcode ( $iridKey );
  5364. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5365. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5366. echo json_encode ( array (
  5367. 'error' => '退款金额不能超过收款金额'
  5368. ) );
  5369. die ();
  5370. }
  5371. echo json_encode ( array (
  5372. 'ok' => '可以使用!'
  5373. ) );
  5374. die ();
  5375. }
  5376. }
  5377. /**
  5378. * 获得收款退款信息
  5379. */
  5380. function getRefundByDetail() {
  5381. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5382. Doo::loadModel ( 'invoiceReceivables' );
  5383. $invoiceReceivables = new invoiceReceivables ();
  5384. if (! empty ( $iridKey )) {
  5385. $irid = $invoiceReceivables->authcode ( $iridKey );
  5386. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5387. echo json_encode ( array (
  5388. 'status' => 1,
  5389. 'irDetail' => $irDetail
  5390. ) );
  5391. die ();
  5392. }
  5393. echo json_encode ( array (
  5394. 'status' => 2
  5395. ) );
  5396. }
  5397. /**
  5398. * 根据收款序列号获得收款退款信息
  5399. */
  5400. function ajaxGetInvoiceReceivablesBySerial() {
  5401. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5402. if (! empty ( $receivablesSerial )) {
  5403. Doo::loadModel ( 'invoiceReceivables' );
  5404. $invoiceReceivables = new invoiceReceivables ();
  5405. // , ' and refundLog=""'
  5406. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5407. $html = '';
  5408. if (! empty ( $irDetail ))
  5409. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5410. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5411. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5412. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5413. <td>' . $irDetail ['recepitTitleMark'] . '
  5414. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5415. </td>';
  5416. echo json_encode ( array (
  5417. 'status' => 1,
  5418. 'html' => $html,
  5419. 'irDetail' => $irDetail
  5420. ) );
  5421. die ();
  5422. }
  5423. echo json_encode ( array (
  5424. 'status' => 2
  5425. ) );
  5426. }
  5427. /**
  5428. * 绑定新收款
  5429. */
  5430. function relationNewInvoiceReceivables() {
  5431. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5432. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5433. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5434. Doo::loadModel ( 'invoiceReceivables' );
  5435. $invoiceReceivables = new invoiceReceivables ();
  5436. Doo::loadClass ( 'XDeode' );
  5437. $XDeode = new XDeode ( 5 );
  5438. $irid = $XDeode->decode ( $iridKey );
  5439. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5440. echo $irid . 'bbb' . $iridOld;
  5441. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5442. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5443. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5444. die ( 'illegal request' );
  5445. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5446. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5447. ';
  5448. $invoiceReceivables = new invoiceReceivables ();
  5449. $item = array (
  5450. 'irid' => $iridOld,
  5451. 'relationIrid' => $irid,
  5452. 'relationLog' => $relationLog
  5453. );
  5454. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5455. return '/invoiceReceivablesAS';
  5456. }
  5457. die ( 'illegal request' );
  5458. }
  5459. // function invoiceApprovalAchieve() {
  5460. // Doo::loadModel ( 'invoice' );
  5461. // $invoice = new invoice ();
  5462. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5463. // $page_size = 12;
  5464. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5465. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5466. // $get = "/" . $date;
  5467. // $con = '';
  5468. // if ($date == 'MONTHO')
  5469. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5470. // elseif ($date == 'MONTHT')
  5471. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5472. // elseif ($date == 'MONTHY')
  5473. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5474. // if (! empty ( $MebSea )) {
  5475. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5476. // $get .= "/" . $MebSea;
  5477. // }
  5478. // $pageinfo ['page'] = array (
  5479. // 'previous' => ''
  5480. // );
  5481. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5482. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5483. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5484. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5485. // // print_r($list);
  5486. // $this->data ['MebSeaEn'] = $MebSea;
  5487. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5488. // $this->data ['get'] = $get;
  5489. // $this->data ['page'] = $pageinfo;
  5490. // $this->data ['list'] = $list;
  5491. // $this->data ['date'] = $date;
  5492. // $this->data ['memu'] = "invoice";
  5493. // $this->data ['staff'] = $this->staff;
  5494. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5495. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5496. // }
  5497. /**
  5498. * 获得审批发票的信息以及审批页面
  5499. */
  5500. function ajaxGetInvoiceApprovalDetail() {
  5501. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5502. if (empty ( $serial )) {
  5503. echo json_encode ( array (
  5504. 'status' => 2,
  5505. 'msg' => 'illegal request'
  5506. ) );
  5507. die ();
  5508. }
  5509. Doo::loadModel ( 'invoice' );
  5510. $invoice = new invoice ();
  5511. Doo::loadModel ( 'invoiceOperationLog' );
  5512. $invoiceOperationLog = new invoiceOperationLog ();
  5513. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5514. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5515. if (empty ( $detail ))
  5516. $html = '';
  5517. else {
  5518. $html = '
  5519. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5520. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5521. <input type="hidden" name="status" value="">
  5522. <input type="hidden" name="divApproval" value="divApproval">
  5523. <div class="modal-dialog modal-lg">
  5524. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5525. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5526. <tr>
  5527. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5528. </tr>
  5529. <tr>
  5530. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5531. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5532. </tr>
  5533. <tr>
  5534. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5535. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5536. </tr>
  5537. <tr>
  5538. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5539. </td>
  5540. </tr>
  5541. <tr>
  5542. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5543. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5544. </tr>
  5545. <tr>
  5546. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5547. </tr></tbody></table>';
  5548. if ($detail ['invoiceType'] == 0)
  5549. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5550. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5551. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5552. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5553. </tr>';
  5554. else
  5555. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5556. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5557. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5558. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5559. ';
  5560. $html .= '<tr>
  5561. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5562. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5563. </tr>
  5564. <tr>
  5565. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5566. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5567. </tr></tbody></table>';
  5568. if ($detail ['doPost'] == 1) {
  5569. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5570. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5571. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5572. </tr><tr>
  5573. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5574. </tr><tr>
  5575. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5576. </tr>
  5577. ';
  5578. if ($detail ['expressCom'] == 'SF')
  5579. $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>';
  5580. else
  5581. $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>';
  5582. $html .= '</tbody></table>';
  5583. }
  5584. if (! empty ( $invoiceOperationLogList )) {
  5585. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5586. foreach ( $invoiceOperationLogList as $key => $value ) {
  5587. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5588. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5589. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5590. if ($value ['status'] == 2) {
  5591. $html .= '<span class="colGreen">同意</span>';
  5592. } elseif ($value ['status'] == 3) {
  5593. $html .= '<span class="colOrange">退回</span>';
  5594. } elseif ($value ['status'] == 5) {
  5595. $html .= '<span class="colGreen">打印</span>';
  5596. } elseif ($value ['status'] == 4) {
  5597. $html .= '<span class="colRed">终止</span>';
  5598. }
  5599. $html .= $value ['operation'] . '</p></blockquote>';
  5600. }
  5601. }
  5602. $html .= '</td></tr></tbody></table>';
  5603. }
  5604. $html .= '</div><div class="modal-footer">
  5605. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5606. <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>
  5607. <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>
  5608. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5609. </form>
  5610. <script type="text/javascript">
  5611. $("a[node-approval^=\'approval\']").click(function() {
  5612. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5613. $("form[name=\'invoiceApproval\']").submit();
  5614. });
  5615. </script>
  5616. ';
  5617. }
  5618. echo json_encode ( array (
  5619. 'status' => 1,
  5620. 'html' => $html
  5621. ) );
  5622. die ();
  5623. }
  5624. /**
  5625. * 获得审批发票分页数据
  5626. */
  5627. function ajaxGetinvoiceApprovalAchieve() {
  5628. Doo::loadModel ( 'invoice' );
  5629. $invoice = new invoice ();
  5630. Doo::loadModel ( 'staff' );
  5631. $staff = new staff ();
  5632. Doo::loadClass ( 'XDeode' );
  5633. $XDeode = new XDeode ( 5 );
  5634. Doo::loadModel ( 'invoiceTraining' );
  5635. $invoiceTraining = new invoiceTraining ();
  5636. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5637. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5638. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5639. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5640. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5641. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5642. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5643. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5644. $MebSea = $this->get_args ( 'search' );
  5645. $MebSea = $MebSea ['value'];
  5646. $page_size = $length;
  5647. $con = '';
  5648. if ($status == 'ALL')
  5649. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5650. elseif ($status == 'PEND')
  5651. $con = ' isDelete=0 and status=1';
  5652. elseif ($status == 'APPROVED')
  5653. $con = ' isDelete=0 and status=2';
  5654. if ($invoiceType == 'ORDINARY')
  5655. $con .= ' and invoiceType=0 ';
  5656. elseif ($invoiceType == 'SPECIAL')
  5657. $con .= ' and invoiceType=1 ';
  5658. if ($invoiceTrain == 'ORDINARY')
  5659. $con .= ' and trainId=0 ';
  5660. elseif ($invoiceTrain == 'TRAIN')
  5661. $con .= ' and trainId!=0 ';
  5662. if ($invoiceTrainName != 'ALL') {
  5663. $trainId = $XDeode->decode ( $invoiceTrainName );
  5664. if (is_numeric ( $trainId ))
  5665. $con .= ' and trainId =' . $trainId;
  5666. }
  5667. $dateArr = explode ( ':', $date );
  5668. $D1 = $dateString = '';
  5669. $D2 = '';
  5670. if (! empty ( $date )) {
  5671. $D1 = $dateArr [0];
  5672. if (isset ( $dateArr [1] ))
  5673. $D2 = $dateArr [1];
  5674. else
  5675. $D2 = '';
  5676. $dateString = $D1 . " : " . $D2;
  5677. }
  5678. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5679. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5680. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5681. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5682. if (! empty ( $MebSea ))
  5683. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5684. // /
  5685. $pageinfo ['page'] = array (
  5686. 'previous' => ''
  5687. );
  5688. $sql = ' ' . $con;
  5689. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5690. $limit = $page . ',' . $page_size;
  5691. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5692. $approvalList = array ();
  5693. $html = '<script type="text/javascript">
  5694. </script>';
  5695. // 结算结束不能修改方式
  5696. Doo::loadModel ( 'receipt' );
  5697. $receipt = new receipt ();
  5698. foreach ( $list as $key => $value ) {
  5699. $irDetail = array ();
  5700. // 结算方式
  5701. $receiptDetail = array ();
  5702. if ($value ['trainId'] != 0) {
  5703. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5704. }
  5705. if (! empty ( $receiptDetail )) {
  5706. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5707. array_push ( $irDetail, '' );
  5708. } else {
  5709. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5710. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5711. } elseif ($value ['status'] == 2) {
  5712. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5713. } else
  5714. array_push ( $irDetail, '' );
  5715. }
  5716. } else {
  5717. if ($value ['status'] == 2) {
  5718. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5719. } else
  5720. array_push ( $irDetail, '' );
  5721. }
  5722. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5723. if ($value ['invoiceType'] == 1)
  5724. array_push ( $irDetail, $value ['invoiceCompany'] );
  5725. else
  5726. array_push ( $irDetail, $value ['invoiceTitle'] );
  5727. array_push ( $irDetail, $value ['TIN'] );
  5728. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5729. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5730. array_push ( $irDetail, $value ['remark'] );
  5731. array_push ( $irDetail, $value ['invoiceElement'] );
  5732. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5733. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5734. if ($value ['invoiceType'] == 1) {
  5735. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5736. } else {
  5737. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5738. }
  5739. if ($value ['settlementType'] == 0) {
  5740. array_push ( $irDetail, '软件销售' );
  5741. } else {
  5742. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5743. array_push ( $irDetail, $itDetail ['trainName'] );
  5744. }
  5745. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5746. array_push ( $irDetail, $value ['recipientsAddress'] );
  5747. array_push ( $irDetail, $value ['mailItems'] );
  5748. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5749. $fchtml = $value ['OL'] ['operation'];
  5750. if (count ( $list ) == $page_size)
  5751. $fchtml = $value ['OL'] ['operation'] . $html;
  5752. // 最后的审批意见
  5753. array_push ( $irDetail, $fchtml );
  5754. if ($value ['status'] == 2)
  5755. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5756. elseif ($value ['status'] == 3)
  5757. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5758. elseif ($value ['status'] == 4)
  5759. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5760. else
  5761. array_push ( $irDetail, '' );
  5762. array_push ( $approvalList, $irDetail );
  5763. }
  5764. // $approvalListJson = json_encode ( $approvalList );
  5765. $recordsFiltered = $pageinfo ['total_data'];
  5766. echo json_encode ( array (
  5767. "draw" => intval ( $draw ),
  5768. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5769. "recordsFiltered" => intval ( $recordsFiltered ),
  5770. "data" => $approvalList
  5771. ), JSON_UNESCAPED_UNICODE );
  5772. }
  5773. /**
  5774. * 审批发票查看更多--重构
  5775. */
  5776. function invoiceApprovalAchieve() {
  5777. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5778. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5779. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5780. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5781. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5782. Doo::loadModel ( 'invoiceTraining' );
  5783. $invoiceTraining = new invoiceTraining ();
  5784. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5785. $this->data ['trainList'] = $trainList;
  5786. $this->data ['dateString'] = $date;
  5787. $this->data ['status'] = $status;
  5788. $this->data ['invoiceType'] = $invoiceType;
  5789. $this->data ['invoiceTrain'] = $invoiceTrain;
  5790. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5791. $this->data ['memu'] = "invoice";
  5792. $this->data ['staff'] = $this->staff;
  5793. $this->data ['receiptMemu'] = 'invoiceApproval';
  5794. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5795. }
  5796. function invoiceTAchieve() {
  5797. Doo::loadModel ( 'invoice' );
  5798. $invoice = new invoice ();
  5799. Doo::loadClass ( 'XDeode' );
  5800. $XDeode = new XDeode ( 5 );
  5801. Doo::loadModel ( 'staff' );
  5802. $staff = new staff ();
  5803. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5804. $page_size = 12;
  5805. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5806. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5807. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5808. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5809. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5810. Doo::loadModel ( 'invoiceTraining' );
  5811. $invoiceTraining = new invoiceTraining ();
  5812. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5813. $get = "/" . $date;
  5814. $con = '';
  5815. if ($date == 'MONTHO')
  5816. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5817. elseif ($date == 'MONTHT')
  5818. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5819. elseif ($date == 'MONTHY')
  5820. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5821. if ($invoiceType == 'ORDINARY')
  5822. $con .= ' and invoiceType=0 ';
  5823. elseif ($invoiceType == 'SPECIAL')
  5824. $con .= ' and invoiceType=1 ';
  5825. if ($invoiceTrain == 'ORDINARY')
  5826. $con .= ' and trainId=0 ';
  5827. elseif ($invoiceTrain == 'TRAIN')
  5828. $con .= ' and trainId!=0 ';
  5829. if ($invoiceTrainName != 'ALL') {
  5830. $trainId = $XDeode->decode ( $invoiceTrainName );
  5831. if (is_numeric ( $trainId ))
  5832. $con .= ' and trainId =' . $trainId;
  5833. }
  5834. if (! empty ( $MebSea )) {
  5835. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5836. $get .= "/" . $MebSea;
  5837. }
  5838. $pageinfo ['page'] = array (
  5839. 'previous' => ''
  5840. );
  5841. $sql = "";
  5842. $action = "";
  5843. if ($this->ACTION == 'invoicePrintAchieve') {
  5844. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5845. $action = "invoicePrintAchieve";
  5846. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5847. // and untreadStatus=0
  5848. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5849. $action = "invoicePostAchieve";
  5850. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5851. $sql = " untreadStatus=2 and status=2 " . $con;
  5852. $action = "invoiceUntreadAchieve";
  5853. }
  5854. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5855. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5856. $this->data ['MebSeaEn'] = $MebSea;
  5857. $this->data ['MebSea'] = urlencode ( $MebSea );
  5858. $this->data ['get'] = $get;
  5859. $this->data ['page'] = $pageinfo;
  5860. $this->data ['trainList'] = $trainList;
  5861. $this->data ['invoiceType'] = $invoiceType;
  5862. $this->data ['invoiceTrain'] = $invoiceTrain;
  5863. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5864. $this->data ['date'] = $date;
  5865. $this->data ['memu'] = "invoice";
  5866. $this->data ['staff'] = $this->staff;
  5867. if ($this->ACTION == 'invoicePrintAchieve') {
  5868. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5869. $this->data ['receiptMemu'] = 'invoicePrint';
  5870. $this->data ['list'] = $list;
  5871. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5872. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5873. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5874. Doo::loadModel ( 'express' );
  5875. $express = new express ();
  5876. $expressList = $express->getExpressByAll ();
  5877. $this->data ['expressList'] = $expressList;
  5878. $this->data ['receiptMemu'] = 'invoicePost';
  5879. $this->data ['list'] = $list;
  5880. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5881. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5882. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5883. $this->data ['receiptMemu'] = 'invoiceUntread';
  5884. $this->data ['list'] = $list;
  5885. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5886. }
  5887. }
  5888. /**
  5889. * 公司应收款
  5890. */
  5891. function invoiceAggregateCompanyDetail() {
  5892. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5893. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5894. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5895. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5896. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5897. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5898. Doo::loadClass ( 'XDeode' );
  5899. $XDeode = new XDeode ( 5 );
  5900. Doo::loadModel ( 'invoice' );
  5901. $invoice = new invoice ();
  5902. Doo::loadModel ( 'staff' );
  5903. $staff = new staff ();
  5904. Doo::loadModel ( "invoiceCompanyManage" );
  5905. $invoiceCompanyManage = new invoiceCompanyManage ();
  5906. Doo::loadModel ( 'L_category' );
  5907. $category = new L_category ();
  5908. $sid = '';
  5909. if (! empty ( $sidKey )) {
  5910. $sid = $XDeode->decode ( $sidKey );
  5911. }
  5912. $staffDetail = $staff->getStaffBySid ( $sid );
  5913. $cid = '';
  5914. if (! empty ( $cidKey )) {
  5915. $cid = $XDeode->decode ( $cidKey );
  5916. }
  5917. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5918. $cidList = array ();
  5919. foreach ( $imcStaff as $key => $value ) {
  5920. array_push ( $cidList, $value ['cid'] );
  5921. }
  5922. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5923. $cidString = implode ( ',', $cidList );
  5924. if (empty ( $cid ))
  5925. $staffList = $staff->getStaffInCid ( $cidString );
  5926. else
  5927. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5928. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5929. $page_size = 25;
  5930. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5931. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5932. $con = ' status=2 and untreadStatus!=2 ';
  5933. $statisticsCon = '';
  5934. if (! empty ( $year ) && is_numeric ( $year ))
  5935. $con .= ' and Year(printTime)=' . $year . '';
  5936. if (! empty ( $month ) && is_numeric ( $month ))
  5937. $con .= ' and Month(printTime)="' . $month . '" ';
  5938. if ($status == 'UNRECORD')
  5939. $con .= ' and printStatus=1 and untreadStatus=0';
  5940. elseif ($status == 'RECORD')
  5941. $con .= ' and printStatus=1 and untreadStatus=3';
  5942. elseif ($status == 'BOUNCED')
  5943. $con .= ' and untreadStatus=2';
  5944. elseif ($status == 'PARTRECORD')
  5945. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5946. elseif ($status == 'All') {
  5947. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5948. }
  5949. if (! empty ( $sid ) && is_numeric ( $sid ))
  5950. $con .= ' and sid=' . $sid;
  5951. if (! empty ( $cid ) && is_numeric ( $cid ))
  5952. $con .= ' and cid=' . $cid;
  5953. else
  5954. $con .= ' and cid in (' . $cidString . ')';
  5955. // 开票内容筛选
  5956. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5957. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5958. }
  5959. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5960. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5961. if (! empty ( $titleORno )) {
  5962. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5963. }
  5964. $pageinfo ['page'] = array (
  5965. 'previous' => ''
  5966. );
  5967. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5968. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5969. // 应收款合计
  5970. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5971. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5972. $monthHtml = "";
  5973. if ($year != "ALL") {
  5974. for($i = 1; $i <= 12; $i ++) {
  5975. if ($i == $month)
  5976. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5977. else
  5978. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5979. }
  5980. }
  5981. $this->data ['monthHtml'] = $monthHtml;
  5982. $this->data ['year'] = $year;
  5983. $this->data ['month'] = $month;
  5984. $this->data ['ics'] = $ics;
  5985. $this->data ['cidKey'] = $cidKey;
  5986. $this->data ['sid'] = $sid;
  5987. $this->data ['staffDetail'] = $staffDetail;
  5988. $this->data ['staffList'] = $staffList;
  5989. $this->data ['titleORnoEn'] = $titleORno;
  5990. $this->data ['titleORno'] = urlencode ( $titleORno );
  5991. $this->data ['invoiceDetail'] = array (
  5992. 'invoiceElement' => $invoiceElement
  5993. );
  5994. $this->data ['page'] = $pageinfo;
  5995. $this->data ['get'] = $get;
  5996. $this->data ['list'] = $list;
  5997. $this->data ['status'] = $status;
  5998. $this->data ['categoryList'] = $categoryList;
  5999. $this->data ['memu'] = "invoice";
  6000. $this->data ['staff'] = $this->staff;
  6001. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  6002. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  6003. }
  6004. /**
  6005. * 获取一条收款信息
  6006. */
  6007. function ajaxGetInvoiceReceivables() {
  6008. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  6009. Doo::loadModel ( 'invoiceReceivables' );
  6010. $invoiceReceivables = new invoiceReceivables ();
  6011. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  6012. echo json_encode ( array (
  6013. 'status' => 1,
  6014. 'detail' => $detail
  6015. ) );
  6016. }
  6017. /**
  6018. * 异步获取办事处用户
  6019. */
  6020. function ajaxGetStaffByCategory() {
  6021. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  6022. Doo::loadModel ( 'staff' );
  6023. $staff = new staff ();
  6024. if ($cid == "PUBLIC") {
  6025. echo json_encode ( array (
  6026. 'status' => 1,
  6027. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  6028. ) );
  6029. die ();
  6030. }
  6031. if (! is_numeric ( $cid )) {
  6032. echo json_encode ( array (
  6033. 'status' => 0,
  6034. 'msg' => 'illegal request'
  6035. ) );
  6036. die ();
  6037. }
  6038. $staffList = $staff->getStaffByCid ( $cid );
  6039. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6040. foreach ( $staffList as $key => $value ) {
  6041. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6042. }
  6043. echo json_encode ( array (
  6044. 'status' => 1,
  6045. 'html' => $html
  6046. ) );
  6047. }
  6048. /**
  6049. * 异步获取一条发票的邮寄信息
  6050. */
  6051. function ajaxGetInvoicePostDetail() {
  6052. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6053. Doo::loadModel ( 'invoice' );
  6054. $invoice = new invoice ();
  6055. $iid = $invoice->authcode ( $iid );
  6056. Doo::loadModel ( 'express' );
  6057. $express = new express ();
  6058. $expressList = $express->getExpressByAll ();
  6059. if (! is_numeric ( $iid )) {
  6060. echo json_encode ( array (
  6061. 'status' => 0,
  6062. 'msg' => 'illegal request'
  6063. ) );
  6064. die ();
  6065. }
  6066. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6067. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6068. $html = "";
  6069. foreach ( $expressList as $key => $value ) {
  6070. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6071. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6072. else
  6073. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6074. }
  6075. $invoiceDetail ['eaHtml'] = $html;
  6076. echo json_encode ( array (
  6077. 'status' => 1,
  6078. 'invoiceDetail' => $invoiceDetail
  6079. ) );
  6080. }
  6081. /**
  6082. *
  6083. * @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 ) ); }
  6084. */
  6085. /**
  6086. *
  6087. * @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 ) ); }
  6088. */
  6089. /**
  6090. * 我的收款中 选择哪个发票入账,进行金额判断
  6091. */
  6092. function ajaxCompareInvoicePrice() {
  6093. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6094. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6095. Doo::loadModel ( 'invoice' );
  6096. $invoice = new invoice ();
  6097. Doo::loadModel ( 'invoiceReceivables' );
  6098. $invoiceReceivables = new invoiceReceivables ();
  6099. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6100. $keyList = explode ( ';', $claimKey );
  6101. $receivablesPrice = 0;
  6102. foreach ( $keyList as $key => $value ) {
  6103. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6104. $receivablesPrice += $detailM ['receivablesPrice'];
  6105. }
  6106. if ($receivablesPrice > $detail ['invoicePrice']) {
  6107. $price = $receivablesPrice - $detail ['invoicePrice'];
  6108. echo json_encode ( array (
  6109. 'status' => 1,
  6110. 'price' => $price
  6111. ) );
  6112. } else
  6113. echo json_encode ( array (
  6114. 'status' => 2
  6115. ) );
  6116. }
  6117. /**
  6118. * 获得打印发票
  6119. */
  6120. function ajaxGetInvoiceInfoByPrint() {
  6121. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6122. if (empty ( $serial )) {
  6123. echo json_encode ( array (
  6124. 'status' => 2,
  6125. 'msg' => 'illegal request'
  6126. ) );
  6127. die ();
  6128. }
  6129. Doo::loadModel ( 'invoice' );
  6130. $invoice = new invoice ();
  6131. Doo::loadModel ( 'invoiceOperationLog' );
  6132. $invoiceOperationLog = new invoiceOperationLog ();
  6133. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6134. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6135. Doo::loadModel ( 'invoicePaper' );
  6136. $invoicePaper = new invoicePaper ();
  6137. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6138. if (empty ( $detail ))
  6139. $html = '';
  6140. else {
  6141. $html = '
  6142. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6143. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6144. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6145. <div class="modal-dialog modal-lg">
  6146. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6147. <div class="modal-body saeaList">
  6148. <table class="table table-bordered table-condensed"><tbody>
  6149. <tr>
  6150. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6151. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6152. </tr>
  6153. <tr>
  6154. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6155. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6156. </tr>
  6157. <tr>
  6158. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6159. </td>
  6160. </tr>
  6161. <tr>
  6162. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6163. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6164. </tr>
  6165. <tr>
  6166. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6167. </tr></tbody></table>';
  6168. if ($detail ['invoiceType'] == 0)
  6169. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6170. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6171. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6172. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6173. </tr>';
  6174. else
  6175. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6176. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6177. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6178. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6179. ';
  6180. $html .= '<tr>
  6181. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6182. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6183. </tr>
  6184. <tr>
  6185. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6186. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6187. </tr></tbody></table>';
  6188. if ($detail ['doPost'] == 1)
  6189. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6190. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6191. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6192. </tr><tr>
  6193. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6194. </tr><tr>
  6195. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6196. </tr></tbody></table>';
  6197. if (! empty ( $invoiceOperationLogList )) {
  6198. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6199. foreach ( $invoiceOperationLogList as $key => $value ) {
  6200. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6201. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6202. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6203. if ($value ['status'] == 2) {
  6204. $html .= '<span class="colGreen">同意</span>';
  6205. } elseif ($value ['status'] == 3) {
  6206. $html .= '<span class="colOrange">退回</span>';
  6207. } elseif ($value ['status'] == 5) {
  6208. $html .= '<span class="colGreen">打印</span>';
  6209. } elseif ($value ['status'] == 4) {
  6210. $html .= '<span class="colRed">终止</span>';
  6211. }
  6212. $html .= $value ['operation'] . '</p></blockquote>';
  6213. }
  6214. }
  6215. $html .= '</td>
  6216. <td><span class="colRed">*</span>
  6217. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6218. foreach ( $invoicePaperList as $key => $value ) {
  6219. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6220. }
  6221. $html .= '</select>
  6222. <span class="red" id="p-msg"></span>
  6223. </td>
  6224. </tr></tbody></table>';
  6225. }
  6226. $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>
  6227. </div></div></form>
  6228. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6229. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6230. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6231. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6232. ';
  6233. }
  6234. echo json_encode ( array (
  6235. 'status' => 1,
  6236. 'html' => $html
  6237. ) );
  6238. die ();
  6239. }
  6240. /**
  6241. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6242. */
  6243. function ajaxGetInvoiceInfoByType() {
  6244. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6245. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6246. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6247. if (empty ( $serial )) {
  6248. echo json_encode ( array (
  6249. 'status' => 2,
  6250. 'msg' => 'illegal request'
  6251. ) );
  6252. die ();
  6253. }
  6254. if ($type == 'INVOICE') {
  6255. Doo::loadModel ( 'invoice' );
  6256. $invoice = new invoice ();
  6257. Doo::loadModel ( 'invoiceOperationLog' );
  6258. $invoiceOperationLog = new invoiceOperationLog ();
  6259. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6260. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6261. if (empty ( $detail ))
  6262. $html = '';
  6263. else {
  6264. $html = '
  6265. <div class="modal-dialog modal-lg">
  6266. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6267. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6268. <tr>
  6269. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6270. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6271. </tr>
  6272. <tr>
  6273. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6274. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6275. </tr>
  6276. <tr>
  6277. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6278. </td>
  6279. </tr>
  6280. <tr>
  6281. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6282. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6283. </tr>
  6284. <tr>
  6285. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6286. </tr>';
  6287. if ($detail ['settlementType'] == 1)
  6288. $html .= '<tr>
  6289. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6290. </tr>';
  6291. else
  6292. $html .= '<tr>
  6293. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6294. </tr>';
  6295. $html .= ' </tbody></table>';
  6296. if ($detail ['invoiceType'] == 0){
  6297. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6298. <tr><th colspan="4" class="taC">增值税普通发票';
  6299. if($detail ['invoiceForm']==1){
  6300. $html .= '( <span class="colRed">电子发票</span> )';
  6301. }
  6302. $html .= '</th></tr><tr>
  6303. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6304. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6305. </tr>';
  6306. }else{
  6307. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6308. <tr><th colspan="4" class="taC">增值税专用发票';
  6309. if($detail ['invoiceForm']==1){
  6310. $html .= '( <span class="colRed">电子发票</span> )';
  6311. }
  6312. $html .= '</th></tr><tr>
  6313. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6314. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6315. ';
  6316. }
  6317. $html .= '<tr>
  6318. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6319. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6320. </tr>
  6321. <tr>
  6322. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6323. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6324. </tr></tbody></table>';
  6325. if ($detail ['doPost'] == 1) {
  6326. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6327. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6328. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6329. </tr><tr>
  6330. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6331. </tr><tr>
  6332. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6333. </tr>
  6334. ';
  6335. if ($detail ['expressCom'] == 'SF')
  6336. $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>';
  6337. else
  6338. $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>';
  6339. $html .= '</tbody></table>';
  6340. }
  6341. if ($detail ['invoiceForm'] == 1) {
  6342. $html .= '<table class="table table-bordered table-condensed">
  6343. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6344. <tr>
  6345. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6346. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6347. </tr></tbody></table>';
  6348. }
  6349. if (! empty ( $invoiceOperationLogList )) {
  6350. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6351. foreach ( $invoiceOperationLogList as $key => $value ) {
  6352. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6353. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6354. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6355. if ($value ['status'] == 2) {
  6356. $html .= '<span class="colGreen">同意</span>';
  6357. } elseif ($value ['status'] == 3) {
  6358. $html .= '<span class="colOrange">退回</span>';
  6359. } elseif ($value ['status'] == 5) {
  6360. $html .= '<span class="colGreen">打印</span>';
  6361. } elseif ($value ['status'] == 4) {
  6362. $html .= '<span class="colRed">终止</span>';
  6363. }
  6364. $html .= $value ['operation'] . '</p></blockquote>';
  6365. }
  6366. }
  6367. $html .= '</td></tr></tbody></table>';
  6368. }
  6369. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6370. }
  6371. echo json_encode ( array (
  6372. 'status' => 1,
  6373. 'html' => $html
  6374. ) );
  6375. die ();
  6376. } elseif ($type == 'RECEIVABLES') {
  6377. Doo::loadModel ( 'invoiceReceivables' );
  6378. $invoiceReceivables = new invoiceReceivables ();
  6379. Doo::loadModel ( 'invoiceRefund' );
  6380. $invoiceRefund = new invoiceRefund ();
  6381. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6382. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6383. if (empty ( $detail ))
  6384. $html = '';
  6385. else {
  6386. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6387. <table class="table table-bordered table-condensed">
  6388. <tbody><tr>
  6389. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6390. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6391. </tr><tr>
  6392. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6393. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6394. </tr>
  6395. <tr>
  6396. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6397. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6398. </tr>
  6399. <tr>
  6400. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6401. </tr>
  6402. </tbody></table>';
  6403. if (! empty ( $ireList )) {
  6404. $html .= '
  6405. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6406. <tr>
  6407. <th class="taC">退款单位名称</th>
  6408. <th class="taC">退款的账号</th>
  6409. <th class="taC">退款金额</th>
  6410. <th class="taC">退款</th>
  6411. <th class="taC">备注</th>
  6412. </tr>
  6413. ';
  6414. foreach ( $ireList as $key => $value ) {
  6415. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6416. $html .= '<tr>
  6417. <td>' . $value ['refundCompany'] . '</td>
  6418. <td>' . $value ['refundNumber'] . '</td>
  6419. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6420. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6421. <td>' . $value ['refundRemarks'] . '</td>
  6422. </tr>
  6423. ';
  6424. }
  6425. }
  6426. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6427. }
  6428. echo json_encode ( array (
  6429. 'status' => 1,
  6430. 'html' => $html
  6431. ) );
  6432. die ();
  6433. } elseif ($type == 'IRTC') {
  6434. Doo::loadModel ( 'invoice' );
  6435. $invoice = new invoice ();
  6436. Doo::loadModel ( 'invoiceOperationLog' );
  6437. $invoiceOperationLog = new invoiceOperationLog ();
  6438. // Doo::loadModel ( 'invoiceReceivables' );
  6439. // $invoiceReceivables = new invoiceReceivables ();
  6440. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6441. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6442. if (empty ( $detail ))
  6443. $html = '';
  6444. else {
  6445. $receivablesPriceedHtml = '';
  6446. $receivablesPrice = $detail ['invoicePrice'];
  6447. if (! empty ( $detail ['irid'] )) {
  6448. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6449. // if (empty ( $irList ))
  6450. // $irList [0] ['sumPrice'] = 0;
  6451. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6452. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6453. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6454. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6455. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6456. </tr></tbody></table>';
  6457. $receivablesPrice = $detail ['invoiceBalance'];
  6458. }
  6459. if ($loss)
  6460. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6461. $html = $receivablesPriceedHtml . '
  6462. <table class="table table-bordered table-condensed"><tbody>
  6463. <tr>
  6464. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6465. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6466. </tr>
  6467. <tr>
  6468. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6469. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6470. </tr>
  6471. <tr>
  6472. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6473. </tr>
  6474. <tr>
  6475. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6476. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6477. </tr>
  6478. <tr>
  6479. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6480. </tr></tbody></table>';
  6481. if ($detail ['invoiceType'] == 0) {
  6482. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6483. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6484. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6485. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6486. </tr>';
  6487. $receivablesMessage = $detail ['invoiceTitle'];
  6488. } else {
  6489. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6490. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6491. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6492. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6493. ';
  6494. $receivablesMessage = $detail ['invoiceCompany'];
  6495. }
  6496. $html .= '<tr>
  6497. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6498. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6499. </tr>
  6500. <tr>
  6501. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6502. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6503. </tr></tbody></table>';
  6504. if ($detail ['doPost'] == 1)
  6505. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6506. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6507. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6508. </tr><tr>
  6509. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6510. </tr><tr>
  6511. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6512. </tr></tbody></table>';
  6513. if (! empty ( $invoiceOperationLogList )) {
  6514. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6515. foreach ( $invoiceOperationLogList as $key => $value ) {
  6516. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6517. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6518. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6519. if ($value ['status'] == 2) {
  6520. $html .= '<span class="colGreen">同意</span>';
  6521. } elseif ($value ['status'] == 3) {
  6522. $html .= '<span class="colOrange">退回</span>';
  6523. } elseif ($value ['status'] == 5) {
  6524. $html .= '<span class="colGreen">打印</span>';
  6525. }
  6526. $html .= $value ['operation'] . '</p></blockquote>';
  6527. }
  6528. }
  6529. $html .= '</td></tr></tbody></table>';
  6530. }
  6531. }
  6532. echo json_encode ( array (
  6533. 'status' => 1,
  6534. 'html' => $html,
  6535. 'receivablesPrice' => $receivablesPrice,
  6536. 'receivablesMessage' => $receivablesMessage,
  6537. 'receivablesDate' => date ( "Y-m-d" ),
  6538. 'iidKey' => $serial
  6539. ) );
  6540. die ();
  6541. }
  6542. }
  6543. function ajaxGetInvoiceReceivablesByStaff() {
  6544. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6545. if (empty ( $postData )) {
  6546. echo json_encode ( array (
  6547. 'status' => 2,
  6548. 'msg' => 'illegal request'
  6549. ) );
  6550. die ();
  6551. }
  6552. Doo::loadModel ( 'invoiceReceivables' );
  6553. $invoiceReceivables = new invoiceReceivables ();
  6554. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6555. if (empty ( $detail )) {
  6556. echo json_encode ( array (
  6557. 'status' => 2,
  6558. 'msg' => 'illegal request'
  6559. ) );
  6560. die ();
  6561. }
  6562. Doo::loadModel ( 'L_category' );
  6563. $lCategory = new L_category ();
  6564. Doo::loadModel ( 'staff' );
  6565. $staff = new staff ();
  6566. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6567. $category = $lCategory->getCategory ();
  6568. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6569. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6570. foreach ( $category as $key => $value ) {
  6571. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6572. if ($value ['cid'] == $detail ['cid'])
  6573. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6574. }
  6575. foreach ( $staffList as $key => $value ) {
  6576. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6577. if ($value ['sid'] == $detail ['sid'])
  6578. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6579. }
  6580. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6581. echo json_encode ( array (
  6582. 'status' => 1,
  6583. 'categoryHtml' => $categoryHtml,
  6584. 'staffHtml' => $staffHtml,
  6585. 'rbankHtml' => $rbankHtml,
  6586. 'detail' => $detail
  6587. ) );
  6588. }
  6589. function ajaxGetInvoiceReceivablesByIrid() {
  6590. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6591. if (empty ( $irid )) {
  6592. echo json_encode ( array (
  6593. 'status' => 2,
  6594. 'msg' => 'illegal request'
  6595. ) );
  6596. die ();
  6597. }
  6598. Doo::loadModel ( 'invoiceReceivables' );
  6599. $invoiceReceivables = new invoiceReceivables ();
  6600. Doo::loadModel ( 'invoice' );
  6601. $invoice = new invoice ();
  6602. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6603. $flag = true;
  6604. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6605. $bakDetail = array ();
  6606. if ($flag === false) {
  6607. array_push ( $bakDetail, $invoiceDetail );
  6608. $invoiceDetail = $bakDetail;
  6609. }
  6610. $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>
  6611. <tr>
  6612. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6613. <td>' . $detail ['receivablesMessage'] . '</td>
  6614. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6615. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6616. <td>' . $detail ['recepitTitleMark'] . '</td>
  6617. </tr></tbody></table>';
  6618. $isInvoice = false;
  6619. $invoiceHtml = '';
  6620. if (empty ( $invoiceDetail )) {
  6621. $isInvoice = true;
  6622. } else {
  6623. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6624. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6625. foreach ( $invoiceDetail as $key => $value ) {
  6626. $invoiceHtml .= '<tr>';
  6627. if (! empty ( $value ['invoiceType'] )) {
  6628. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6629. } else {
  6630. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6631. }
  6632. if (! empty ( $value ['invoiceType'] )) {
  6633. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6634. } else {
  6635. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6636. }
  6637. $invoiceHtml .= '
  6638. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6639. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6640. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6641. </tr>
  6642. ';
  6643. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6644. if (empty ( $irList ))
  6645. $irList [0] ['sumPrice'] = 0;
  6646. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6647. $priceString = '';
  6648. if ($balance < $detail ['receivablesPrice']) {
  6649. $priceString = '收款金额超过开票金额,';
  6650. }
  6651. if ($balance > $detail ['receivablesPrice']) {
  6652. $priceString = '收款金额低于开票金额,';
  6653. }
  6654. }
  6655. $invoiceHtml .= '
  6656. <script>
  6657. $(\'a[bind-receivables^="ir"]\').click(function() {
  6658. var data = $(this).attr("data-ikey");
  6659. $("input[name=\'invoiceKey\']").val(data);
  6660. var invoiceKey=data;
  6661. if(invoiceKey==""){
  6662. alert("入账错误,请重新刷新页面");
  6663. return false;
  6664. }
  6665. if(window.confirm("' . $priceString . '确定入账吗?")){
  6666. $("#IBR").submit();
  6667. }else{
  6668. return false;
  6669. }
  6670. });
  6671. </script>
  6672. ';
  6673. $invoiceHtml .= '</tbody></table>';
  6674. }
  6675. echo json_encode ( array (
  6676. 'status' => 1,
  6677. 'irkey' => $detail ['iridEn'],
  6678. 'receivablesHtml' => $receivablesHtml,
  6679. 'isInvoice' => $isInvoice,
  6680. 'invoiceHtml' => $invoiceHtml
  6681. ) );
  6682. }
  6683. function ajaxGetInvoiceReceivablesByTitle() {
  6684. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6685. if (empty ( $title )) {
  6686. echo json_encode ( array (
  6687. 'status' => 2,
  6688. 'msg' => 'illegal request'
  6689. ) );
  6690. die ();
  6691. }
  6692. Doo::loadModel ( 'invoice' );
  6693. $invoice = new invoice ();
  6694. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6695. $invoiceHtml = '';
  6696. if (! empty ( $invoiceDetail )) {
  6697. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6698. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6699. foreach ( $invoiceDetail as $key => $value ) {
  6700. if (! empty ( $value ['invoiceType'] )) {
  6701. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6702. } else {
  6703. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6704. }
  6705. if (! empty ( $value ['invoiceType'] )) {
  6706. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6707. } else {
  6708. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6709. }
  6710. $invoiceHtml .= '
  6711. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6712. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6713. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6714. </tr>
  6715. ';
  6716. }
  6717. $invoiceHtml .= '</tbody></table>
  6718. <script>
  6719. $(\'a[bind-receivables^="ir"]\').click(function() {
  6720. var data = $(this).attr("data-ikey");
  6721. $("input[name=\'invoiceKey\']").val(data);
  6722. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6723. if(invoiceKey==""){
  6724. alert("入账错误,请重新刷新页面");
  6725. return false;
  6726. }
  6727. if(window.confirm("确定入账吗?")){
  6728. $("#IBR").submit();
  6729. }else{
  6730. return false;
  6731. }
  6732. });
  6733. </script>
  6734. ';
  6735. }
  6736. echo json_encode ( array (
  6737. 'status' => 1,
  6738. 'invoiceHtml' => $invoiceHtml
  6739. ) );
  6740. }
  6741. function ajaxInvoicePushNotice() {
  6742. Doo::loadModel ( 'invoice' );
  6743. $invoice = new invoice ();
  6744. $approval = $invoice->getOne ( array (
  6745. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6746. 'desc' => 'iid',
  6747. 'asArray' => true
  6748. ) );
  6749. $isNotice = false;
  6750. if (! empty ( $approval ))
  6751. $isNotice = true;
  6752. $response = array (
  6753. 'error' => 0,
  6754. 'isNotice' => $isNotice
  6755. );
  6756. echo json_encode ( $response );
  6757. exit ();
  6758. }
  6759. public function ajaxCheckInvoiceNoUniqueness() {
  6760. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6761. Doo::loadModel ( 'invoice' );
  6762. $invoice = new invoice ();
  6763. if (! empty ( $invoiceNo )) {
  6764. Doo::loadModel ( 'invoicePaper' );
  6765. $invoicePaper = new invoicePaper ();
  6766. Doo::loadClass ( 'XDeode' );
  6767. $XDeode = new XDeode ( 5 );
  6768. $ipid = $XDeode->decode ( $invoiceNo );
  6769. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6770. $info = $invoice->getOne ( array (
  6771. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6772. 'asArray' => TRUE
  6773. ) );
  6774. if (! empty ( $info )) {
  6775. echo json_encode ( array (
  6776. 'error' => '发票号已存在'
  6777. ) );
  6778. die ();
  6779. } else
  6780. echo json_encode ( array (
  6781. 'ok' => '可以使用!'
  6782. ) );
  6783. die ();
  6784. }
  6785. }
  6786. function ajaxCheckInvoicePrice() {
  6787. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6788. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6789. Doo::loadModel ( 'invoice' );
  6790. $invoice = new invoice ();
  6791. Doo::loadModel ( 'invoiceReceivables' );
  6792. $invoiceReceivables = new invoiceReceivables ();
  6793. Doo::loadClass ( 'XDeode' );
  6794. $XDeode = new XDeode ( 5 );
  6795. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6796. $iidKey = $XDeode->decode ( $iidKey );
  6797. $info = $invoice->getInvoiceByIid ( $iidKey );
  6798. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6799. if (empty ( $irList ))
  6800. $irList [0] ['sumPrice'] = 0;
  6801. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6802. if ($balance < $receivablesPrice) {
  6803. echo json_encode ( array (
  6804. 'error' => '收款金额超过开票金额。'
  6805. ) );
  6806. die ();
  6807. }
  6808. if ($balance > $receivablesPrice) {
  6809. echo json_encode ( array (
  6810. 'error' => '收款金额低于开票金额。'
  6811. ) );
  6812. die ();
  6813. }
  6814. }
  6815. }
  6816. function ajaxGetInvoiceByNew() {
  6817. Doo::loadModel ( 'invoice' );
  6818. $invoice = new invoice ();
  6819. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6820. echo json_encode ( array (
  6821. 'status' => 1,
  6822. 'detail' => $detail
  6823. ) );
  6824. }
  6825. /**
  6826. * 旧输入导入
  6827. */
  6828. function importInvoice() {
  6829. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6830. $data ['emsg'] = "";
  6831. if ($emsg != "")
  6832. $data ['emsg'] = "请填写完整的数据";
  6833. $data ['time'] = time ();
  6834. $this->render ( "/admin/invoiceImport", $data );
  6835. }
  6836. function uploadInvoice() {
  6837. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6838. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6839. $file = $_FILES ['Filedata'] ['tmp_name'];
  6840. $error = false;
  6841. if (! is_uploaded_file ( $file )) {
  6842. $error = '400 Bad Request';
  6843. }
  6844. if ($error) {
  6845. header ( 'HTTP/1.0 ' . $error );
  6846. die ( 'Error ' . $error );
  6847. } else {
  6848. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6849. $this->IoHandler = new IoHandler ();
  6850. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6851. // $filedir=$_POST['time'];
  6852. // 调用定义物理路径
  6853. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6854. $this->IoHandler->MakeDir ( $t );
  6855. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6856. if ($filename != 'xlsx')
  6857. return "";
  6858. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6859. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6860. $upload_dir = $t . "/" . $upload_file;
  6861. $k = move_uploaded_file ( $file, $upload_dir );
  6862. if ($k) {
  6863. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6864. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6865. }
  6866. }
  6867. }
  6868. }
  6869. function importInvoiceDo() {
  6870. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6871. if ($path != "") {
  6872. Doo::loadModel ( 'invoice' );
  6873. Doo::loadModel ( 'staff' );
  6874. $staff = new staff ();
  6875. Doo::loadModel ( 'invoiceStatistics' );
  6876. Doo::loadModel ( 'invoiceOperationLog' );
  6877. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6878. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6879. // print_r ( $exlArray );
  6880. // die ();
  6881. // echo json_encode($exlArray);die;
  6882. foreach ( $exlArray as $key => $value ) {
  6883. // 开票
  6884. $invoice = new invoice ();
  6885. $invoice->invoiceNo = $value ['invoiceNo'];
  6886. $invoice->invoiceType = 0;
  6887. if ($value ['invoiceType'] == '专')
  6888. $invoice->invoiceType = 1;
  6889. $invoice->invoicePrice = $value ['invoicePrice'];
  6890. $invoice->invoiceQuantity = 1;
  6891. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6892. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6893. if ($value ['invoiceType'] == '专')
  6894. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6895. $invoice->userName = $value ['userName'];
  6896. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6897. $invoice->sid = $sDetail ['sid'];
  6898. $invoice->cid = $sDetail ['cid'];
  6899. $invoice->categoryName = $sDetail ['category'];
  6900. $invoice->invoiceElement = $value ['invoiceElement'];
  6901. $invoice->remark = $value ['remark'];
  6902. $invoice->date = $value ['date'];
  6903. $invoice->printTime = $value ['date'];
  6904. $invoice->ipSource = 1;
  6905. $invoice->printStatus = 1;
  6906. $invoice->status = 2;
  6907. $invoice->postStatus = 1;
  6908. $invoice->untreadStatus = 0;
  6909. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6910. $iid = $invoice->insert ();
  6911. // 汇总
  6912. $invoiceStatistics = new invoiceStatistics ();
  6913. //
  6914. $item = array (
  6915. 'date' => $value ['date'],
  6916. 'priceClass' => 1,
  6917. 'cid' => $sDetail ['cid'],
  6918. 'staff' => $sDetail ['sid'],
  6919. 'invoicePrice' => $value ['invoicePrice']
  6920. );
  6921. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6922. $invoiceOperationLog = new invoiceOperationLog ();
  6923. $item = array (
  6924. 'date' => date ( "Y-m-d H:i:s" ),
  6925. 'operation' => date ( "Y-m-d" ) . " 导入",
  6926. 'status' => 1,
  6927. 'img' => $sDetail ['avatar'],
  6928. 'username' => $sDetail ['username'],
  6929. 'uid' => $sDetail ['sid'],
  6930. 'category' => $sDetail ['category'],
  6931. 'iid' => $iid
  6932. );
  6933. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6934. }
  6935. return '/importInvoice?count=' . count ( $exlArray );
  6936. // return "/keyonline";
  6937. }
  6938. echo 'no file';
  6939. }
  6940. function importInvoiceReceivables() {
  6941. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6942. $data ['emsg'] = "";
  6943. if ($emsg != "")
  6944. $data ['emsg'] = "请填写完整的数据";
  6945. $data ['time'] = time ();
  6946. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6947. }
  6948. // 导入入账数据
  6949. function importInvoiceReceivablesDo() {
  6950. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6951. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6952. if ($path != "") {
  6953. Doo::loadModel ( 'invoiceReceivables' );
  6954. Doo::loadModel ( 'invoice' );
  6955. Doo::loadModel ( 'staff' );
  6956. $staff = new staff ();
  6957. Doo::loadModel ( 'invoiceStatistics' );
  6958. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6959. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6960. // print_r ( $exlArray );
  6961. // die ();
  6962. // echo json_encode($exlArray);die;
  6963. foreach ( $exlArray as $key => $value ) {
  6964. // 收款
  6965. $invoiceReceivables = new invoiceReceivables ();
  6966. $invoice = new invoice ();
  6967. $invoiceReceivables->bindStatus = 1;
  6968. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6969. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6970. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6971. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6972. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6973. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6974. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6975. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6976. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6977. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6978. $invoiceReceivables->iid = $iDetail ['iid'];
  6979. $irid = $invoiceReceivables->insert ();
  6980. // 发票绑定收款
  6981. $detail = $iDetail;
  6982. $iridString = "";
  6983. if (empty ( $detail ['irid'] ))
  6984. $iridString = $irid;
  6985. else
  6986. $iridString = $detail ['irid'] . ',' . $irid;
  6987. $item = array (
  6988. 'irid' => $iridString,
  6989. 'iid' => $detail ['iid']
  6990. );
  6991. $invoice->setInvoiceByCondition ( $item );
  6992. // 汇总
  6993. $invoiceStatistics = new invoiceStatistics ();
  6994. // 扣除入账统计金额
  6995. $item = array (
  6996. 'date' => $value ['receivablesDate'],
  6997. 'priceClass' => 3,
  6998. 'cid' => $sDetail ['cid'],
  6999. 'staff' => $sDetail ['sid'],
  7000. // 'irid' => $irid,
  7001. 'accountPrice' => $value ['receivablesPrice']
  7002. );
  7003. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7004. }
  7005. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  7006. echo 'data count ' . count ( $exlArray );
  7007. die ();
  7008. // return "/keyonline";
  7009. }
  7010. echo 'no file';
  7011. }
  7012. function formatExcelToArrayTrain($file_url = "") {
  7013. if (! file_exists ( $file_url )) {
  7014. return array ();
  7015. }
  7016. // Doo::loadClass ( 'PHPExcel' );
  7017. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7018. $PHPExcel = new PHPExcel ();
  7019. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7020. if (! $PHPReader->canRead ( $file_url )) {
  7021. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7022. if (! $PHPReader->canRead ( $file_url )) {
  7023. echo 'no Excel';
  7024. return;
  7025. }
  7026. }
  7027. $PHPExcel = $PHPReader->load ( $file_url );
  7028. /* * 读取excel文件中的第一个工作表 */
  7029. $currentSheet = $PHPExcel->getSheet ( 0 );
  7030. /* * 取得最大的列号 */
  7031. $allColumn = $currentSheet->getHighestColumn ();
  7032. /* * 取得一共有多少行 */
  7033. $allRow = $currentSheet->getHighestRow ();
  7034. $excel_array = array ();
  7035. // die($file_url);
  7036. $conk = 2;
  7037. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7038. $excel_column = array ();
  7039. // 后期改进
  7040. if ($allColumn == 'AM')
  7041. $allColumn = 'Z';
  7042. /* * 从第A列开始输出 */
  7043. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7044. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7045. if ($val instanceof PHPExcel_RichText)
  7046. $val = $val->__toString ();
  7047. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7048. // $val = "'" . addslashes ( $val ) . "'";
  7049. if ($currentColumn == 'A') {
  7050. $excel_column ['invoiceTitle'] = $val;
  7051. } elseif ($currentColumn == 'B')
  7052. $excel_column ['invoiceType'] = $val;
  7053. elseif ($currentColumn == 'C') {
  7054. $excel_column ['TIN'] = $val;
  7055. } elseif ($currentColumn == 'D') {
  7056. $excel_column ['address'] = $val;
  7057. } elseif ($currentColumn == 'E') {
  7058. $excel_column ['phone'] = $val;
  7059. } elseif ($currentColumn == 'F') {
  7060. $excel_column ['bank'] = $val;
  7061. } elseif ($currentColumn == 'G') {
  7062. $excel_column ['bankAccount'] = $val;
  7063. } elseif ($currentColumn == 'H') {
  7064. $excel_column ['invoiceElement'] = $val;
  7065. } elseif ($currentColumn == 'I') {
  7066. $excel_column ['invoiceQuantity'] = $val;
  7067. } elseif ($currentColumn == 'J') {
  7068. $excel_column ['invoiceUnitPrice'] = $val;
  7069. } elseif ($currentColumn == 'K') {
  7070. $excel_column ['remark'] = $val;
  7071. } elseif ($currentColumn == 'L') {
  7072. $excel_column ['recipientsAddress'] = $val;
  7073. } elseif ($currentColumn == 'M') {
  7074. $excel_column ['recipients'] = $val;
  7075. } elseif ($currentColumn == 'N') {
  7076. $excel_column ['recipientsPhone'] = $val;
  7077. }elseif ($currentColumn == 'O') {
  7078. $excel_column ['electronicPhone'] = $val;
  7079. } elseif ($currentColumn == 'P') {
  7080. $excel_column ['electronicEmail'] = $val;
  7081. }
  7082. }
  7083. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7084. array_push ( $excel_array, $excel_column );
  7085. }
  7086. return $excel_array;
  7087. }
  7088. /**
  7089. * 格式化excel文件为数组
  7090. * @param unknown_type $file_url
  7091. * @param unknown_type $mcid
  7092. */
  7093. function _format_excel_to_array($file_url = "", $sType = "") {
  7094. if (! file_exists ( $file_url )) {
  7095. return array ();
  7096. }
  7097. Doo::loadClass ( 'PHPExcel' );
  7098. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7099. $PHPExcel = new PHPExcel ();
  7100. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7101. if (! $PHPReader->canRead ( $file_url )) {
  7102. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7103. if (! $PHPReader->canRead ( $file_url )) {
  7104. echo 'no Excel';
  7105. return;
  7106. }
  7107. }
  7108. $PHPExcel = $PHPReader->load ( $file_url );
  7109. /* * 读取excel文件中的第一个工作表 */
  7110. $currentSheet = $PHPExcel->getSheet ( 0 );
  7111. /* * 取得最大的列号 */
  7112. $allColumn = $currentSheet->getHighestColumn ();
  7113. /* * 取得一共有多少行 */
  7114. $allRow = $currentSheet->getHighestRow ();
  7115. $excel_array = array ();
  7116. // die($file_url);
  7117. $conk = 2;
  7118. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7119. $excel_column = array ();
  7120. // 后期改进
  7121. if ($allColumn == 'AM')
  7122. $allColumn = 'Z';
  7123. /* * 从第A列开始输出 */
  7124. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7125. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7126. if ($val instanceof PHPExcel_RichText)
  7127. $val = $val->__toString ();
  7128. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7129. // $val = "'" . addslashes ( $val ) . "'";
  7130. if ($sType == 'invoiceReceivables') {
  7131. if ($currentColumn == 'A')
  7132. $excel_column ['invoiceNo'] = $val;
  7133. elseif ($currentColumn == 'B')
  7134. $excel_column ['receivablesPrice'] = $val;
  7135. elseif ($currentColumn == 'C') {
  7136. $excel_column ['receivablesMessage'] = $val;
  7137. } elseif ($currentColumn == 'D') {
  7138. $excel_column ['receivablesBank'] = $val;
  7139. } elseif ($currentColumn == 'E') {
  7140. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7141. } elseif ($currentColumn == 'F') {
  7142. $excel_column ['receivablesStaff'] = $val;
  7143. } elseif ($currentColumn == 'G') {
  7144. $excel_column ['sourcePrice'] = $val;
  7145. }
  7146. } elseif ($sType == "invoiceTrain") {
  7147. if ($currentColumn == 'A') {
  7148. $excel_column ['invoiceTitle'] = $val;
  7149. } elseif ($currentColumn == 'B')
  7150. $excel_column ['invoiceType'] = $val;
  7151. elseif ($currentColumn == 'C') {
  7152. $excel_column ['TIN'] = $val;
  7153. } elseif ($currentColumn == 'D') {
  7154. $excel_column ['address'] = $val;
  7155. } elseif ($currentColumn == 'E') {
  7156. $excel_column ['phone'] = $val;
  7157. } elseif ($currentColumn == 'F') {
  7158. $excel_column ['bank'] = $val;
  7159. } elseif ($currentColumn == 'G') {
  7160. $excel_column ['bankAccount'] = $val;
  7161. } elseif ($currentColumn == 'H') {
  7162. $excel_column ['invoiceElement'] = $val;
  7163. } elseif ($currentColumn == 'I') {
  7164. $excel_column ['invoiceQuantity'] = $val;
  7165. } elseif ($currentColumn == 'J') {
  7166. $excel_column ['invoiceUnitPrice'] = $val;
  7167. } elseif ($currentColumn == 'K') {
  7168. $excel_column ['remark'] = $val;
  7169. } elseif ($currentColumn == 'L') {
  7170. $excel_column ['recipientsAddress'] = $val;
  7171. } elseif ($currentColumn == 'M') {
  7172. $excel_column ['recipients'] = $val;
  7173. } elseif ($currentColumn == 'N') {
  7174. $excel_column ['recipientsPhone'] = $val;
  7175. }
  7176. } else {
  7177. if ($currentColumn == 'A')
  7178. $excel_column ['invoiceNo'] = $val;
  7179. elseif ($currentColumn == 'B')
  7180. $excel_column ['invoiceType'] = $val;
  7181. elseif ($currentColumn == 'C') {
  7182. $excel_column ['invoicePrice'] = $val;
  7183. } elseif ($currentColumn == 'D') {
  7184. $excel_column ['invoiceTitle'] = $val;
  7185. } elseif ($currentColumn == 'E') {
  7186. $excel_column ['userName'] = $val;
  7187. } elseif ($currentColumn == 'F') {
  7188. $excel_column ['categoryName'] = $val;
  7189. } elseif ($currentColumn == 'G') {
  7190. $excel_column ['invoiceElement'] = $val;
  7191. } elseif ($currentColumn == 'H') {
  7192. $excel_column ['remark'] = $val;
  7193. } elseif ($currentColumn == 'I') {
  7194. $excel_column ['date'] = $this->excelTime ( $val );
  7195. }
  7196. }
  7197. }
  7198. array_push ( $excel_array, $excel_column );
  7199. }
  7200. return $excel_array;
  7201. }
  7202. function excelTime($date, $time = false) {
  7203. if (function_exists ( 'GregorianToJD' )) {
  7204. if (is_numeric ( $date )) {
  7205. $jd = GregorianToJD ( 1, 1, 1970 );
  7206. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7207. $date = explode ( '/', $gregorian );
  7208. $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" : '');
  7209. return $date_str;
  7210. }
  7211. } else {
  7212. $date = $date > 25568 ? $date + 1 : 25569;
  7213. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7214. $ofs = (70 * 365 + 17 + 2) * 86400;
  7215. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7216. }
  7217. return $date;
  7218. }
  7219. /**
  7220. * 旧输入导入
  7221. */
  7222. function _GetFileEXT($filename) {
  7223. $pics = explode ( '.', $filename );
  7224. $num = count ( $pics );
  7225. return $pics [$num - 1];
  7226. }
  7227. function showCache($path = "", $sid = 0) {
  7228. // if (file_exists ( $path )) {
  7229. // $htm = file_get_contents ( $path );
  7230. // } else {
  7231. Doo::loadModel ( 'invoiceStatistics' );
  7232. $invoiceStatistics = new invoiceStatistics ();
  7233. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7234. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7235. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7236. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7237. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7238. /*
  7239. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7240. */
  7241. file_put_contents ( $path, $htm );
  7242. // }
  7243. return $htm;
  7244. }
  7245. /**
  7246. * 生成token
  7247. * @return string
  7248. */
  7249. function set_token() {
  7250. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7251. $str = sha1 ( $str ); // 加密
  7252. return $str;
  7253. }
  7254. /**
  7255. * 获取get或者POST值
  7256. *
  7257. * @param string $name 属性名称
  7258. * @return fixed 值
  7259. */
  7260. function get_args($name) {
  7261. if (isset ( $_GET [$name] )) {
  7262. if (is_array ( $_GET [$name] ))
  7263. return $_GET [$name];
  7264. else
  7265. return addslashes ( $_GET [$name] );
  7266. } elseif (isset ( $_POST [$name] )) {
  7267. if (is_array ( $_POST [$name] ))
  7268. return $_POST [$name];
  7269. else
  7270. return addslashes ( $_POST [$name] );
  7271. } else
  7272. return false;
  7273. }
  7274. function SafeFilter(&$arr) {
  7275. $ra = Array (
  7276. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7277. '/script/',
  7278. '/javascript/',
  7279. '/vbscript/',
  7280. '/expression/',
  7281. '/applet/',
  7282. '/meta/',
  7283. '/xml/',
  7284. '/blink/',
  7285. '/link/',
  7286. '/style/',
  7287. '/embed/',
  7288. '/object/',
  7289. '/frame/',
  7290. '/layer/',
  7291. '/title/',
  7292. '/bgsound/',
  7293. '/base/',
  7294. '/onload/',
  7295. '/onunload/',
  7296. '/onchange/',
  7297. '/onsubmit/',
  7298. '/onreset/',
  7299. '/onselect/',
  7300. '/onblur/',
  7301. '/onfocus/',
  7302. '/onabort/',
  7303. '/onkeydown/',
  7304. '/onkeypress/',
  7305. '/onkeyup/',
  7306. '/onclick/',
  7307. '/ondblclick/',
  7308. '/onmousedown/',
  7309. '/onmousemove/',
  7310. '/onmouseout/',
  7311. '/onmouseover/',
  7312. '/onmouseup/',
  7313. '/onunload/'
  7314. );
  7315. if (is_array ( $arr )) {
  7316. foreach ( $arr as $key => $value ) {
  7317. if (! is_array ( $value )) {
  7318. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7319. {
  7320. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7321. }
  7322. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7323. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7324. } else {
  7325. SafeFilter ( $arr [$key] );
  7326. }
  7327. }
  7328. }
  7329. }
  7330. /**
  7331. * Escape String
  7332. *
  7333. * @access public
  7334. * @param string
  7335. * @param bool whether or not the string will be used in a LIKE condition
  7336. * @return string
  7337. */
  7338. function escape_str($str, $like = FALSE) {
  7339. if (is_array ( $str )) {
  7340. foreach ( $str as $key => $val ) {
  7341. $str [$key] = $this->escape_str ( $val, $like );
  7342. }
  7343. return $str;
  7344. }
  7345. var_dump ( Doo::db ()->getDbObject () );
  7346. die ();
  7347. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7348. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7349. } elseif (function_exists ( 'mysql_escape_string' )) {
  7350. $str = mysql_escape_string ( $str );
  7351. } else {
  7352. $str = addslashes ( $str );
  7353. }
  7354. // escape LIKE condition wildcards
  7355. if ($like === TRUE) {
  7356. $str = str_replace ( array (
  7357. '%',
  7358. '_'
  7359. ), array (
  7360. '\\%',
  7361. '\\_'
  7362. ), $str );
  7363. }
  7364. return $str;
  7365. }
  7366. /**
  7367. * 获得分页数据
  7368. * @param unknown_type $table
  7369. * @param unknown_type $condition
  7370. * @param unknown_type $on_page
  7371. * @param unknown_type $page_size
  7372. */
  7373. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7374. $page_c = "";
  7375. $page ['previous'] = $this->get_previous ( $on_page );
  7376. $page ['on_page'] = $on_page;
  7377. $total_count = $this->get_table_count ( $table, $condition );
  7378. $total = intval ( $total_count / $page_size );
  7379. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7380. $page ['total_data'] = $total_count;
  7381. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7382. $i = 1;
  7383. $page_max = 1;
  7384. $page_width = 3;
  7385. if ($on_page >= $page_width) {
  7386. $page_max = intval ( $on_page / $page_width ) + 1;
  7387. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7388. }
  7389. for(; $i <= $page ['total_page']; $i ++) {
  7390. if ($i == $on_page)
  7391. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7392. else
  7393. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7394. if ($i == ($page_width * $page_max))
  7395. break;
  7396. }
  7397. $page ['page'] = $page_c;
  7398. $page ['lower'] = (-- $on_page) * $page_size;
  7399. return $page;
  7400. }
  7401. /**
  7402. * 获取上一页
  7403. * @param unknown_type $on_page
  7404. */
  7405. function get_previous($on_page = 1) {
  7406. return $on_page != 0 ? $on_page - 1 : $on_page;
  7407. }
  7408. /**
  7409. * 获取总页数
  7410. * @param unknown_type $table
  7411. * @param unknown_type $condition
  7412. */
  7413. public function get_table_count($table = "", $condition = "") {
  7414. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7415. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7416. // echo $sql;die;
  7417. $query = Doo::db ()->query ( $sql );
  7418. $result = $query->fetch ();
  7419. return $result ['count'];
  7420. }
  7421. function isInvoiceNew($type = "GLOBAL") {
  7422. Doo::loadModel ( 'invoice' );
  7423. $invoice = new invoice ();
  7424. Doo::loadModel ( 'invoiceReceivables' );
  7425. $invoiceReceivables = new invoiceReceivables ();
  7426. Doo::loadModel ( 'staff' );
  7427. $staff = new staff ();
  7428. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7429. // 我的发票待处理
  7430. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7431. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7432. 'desc' => 'iid',
  7433. 'asArray' => TRUE
  7434. ) );
  7435. // 我的收款待入账
  7436. /*
  7437. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7438. */
  7439. // 发票审批
  7440. $approval = $invoice->getOne ( array (
  7441. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7442. 'desc' => 'iid',
  7443. 'asArray' => true
  7444. ) );
  7445. // 发票邮寄
  7446. $post = $invoice->getOne ( array (
  7447. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7448. 'asArray' => TRUE
  7449. ) );
  7450. // 发票打印
  7451. $print = $invoice->getOne ( array (
  7452. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7453. 'desc' => 'iid',
  7454. 'asArray' => TRUE
  7455. ) );
  7456. // 发票退票 printStatus=1 and
  7457. $untread = $invoice->getOne ( array (
  7458. 'where' => " untreadStatus=1 and status=2 ",
  7459. 'asArray' => TRUE
  7460. ) );
  7461. $new = array (
  7462. 'GLOBAL' => FALSE,
  7463. 'pendingInvoice' => FALSE,
  7464. // 'myClaim' => FALSE,
  7465. 'approval' => FALSE,
  7466. 'post' => FALSE,
  7467. 'print' => FALSE,
  7468. 'untread' => FALSE
  7469. );
  7470. // || ! empty ( $myClaim )
  7471. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7472. $new ['GLOBAL'] = TRUE;
  7473. if (! empty ( $pendingInvoice ))
  7474. $new ['pendingInvoice'] = TRUE;
  7475. // if (! empty ( $myClaim ))
  7476. // $new ['myClaim'] = TRUE;
  7477. if (! empty ( $approval ))
  7478. $new ['approval'] = TRUE;
  7479. if (! empty ( $post ))
  7480. $new ['post'] = TRUE;
  7481. if (! empty ( $print ))
  7482. $new ['print'] = TRUE;
  7483. if (! empty ( $untread ))
  7484. $new ['untread'] = TRUE;
  7485. return $new;
  7486. }
  7487. function setWXMsg($rid, $typeMsg = '') {
  7488. Doo::loadModel ( 'invoice' );
  7489. $invoice = new invoice ();
  7490. $invoiceDetail = $invoice->getOne ( array (
  7491. 'where' => 'iid=' . $rid,
  7492. 'asArray' => true
  7493. ) );
  7494. if (! empty ( $invoiceDetail )) {
  7495. Doo::loadModel ( 'staff' );
  7496. $staff = new staff ();
  7497. $staffmsg = $staff->getOne ( array (
  7498. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7499. 'asArray' => TRUE
  7500. ) );
  7501. if (! empty ( $staffmsg ['wxid'] )) {
  7502. require_once (SITE_PATH . '/protected/class/client.php');
  7503. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7504. $user = $staffmsg ['wxid'];
  7505. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7506. if (empty ( $expCom ))
  7507. $expCom [0] = '';
  7508. $msg = "";
  7509. if (empty ( $typeMsg ))
  7510. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7511. elseif ($typeMsg == "PRINT")
  7512. $msg = '太好了,您的发票已打印完成。';
  7513. $result = $client->SendMsg ( $user, $msg, 'text' );
  7514. }
  7515. }
  7516. }
  7517. /**
  7518. * 获取微信部门
  7519. * @param string $category
  7520. * @return number|mixed
  7521. */
  7522. function getToparty($category = '') {
  7523. $token = $this->getAccessToken (); //
  7524. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7525. $toparty = 0;
  7526. foreach ( $result ['department'] as $key => $value ) {
  7527. if ($value ['name'] == $category)
  7528. $toparty = $value ['id'];
  7529. }
  7530. return $toparty;
  7531. }
  7532. /**
  7533. * 获得某部门下的用户
  7534. * @param string $toparty
  7535. */
  7536. function getUserByToparty($toparty = '') {
  7537. $token = $this->getAccessToken (); //
  7538. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7539. $userList = array ();
  7540. foreach ( $result ['userlist'] as $key => $value ) {
  7541. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7542. }
  7543. return $userList;
  7544. }
  7545. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7546. $token = $this->getAccessToken ();
  7547. if ($text == 'text') {
  7548. $data = '{
  7549. "touser": "' . $toparty . '",
  7550. "toparty": "",
  7551. "totag": "",
  7552. "msgtype": "text",
  7553. "agentid": 1000002,
  7554. "text": {
  7555. "content": "' . $msg . '"
  7556. },
  7557. "safe":0
  7558. }';
  7559. }
  7560. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7561. if ($result->errmsg != 'ok') {
  7562. return 0;
  7563. } else {
  7564. return 1;
  7565. }
  7566. }
  7567. /**
  7568. * 获得可以发送微信用户列表
  7569. * @param string $category
  7570. * @return string
  7571. */
  7572. function getWxidByCategory($category = "") {
  7573. if (empty ( $category ))
  7574. return "";
  7575. Doo::loadModel ( 'staff' );
  7576. $staff = new staff ();
  7577. $toparty = $this->getToparty ( $category );
  7578. $wxList = array ();
  7579. $wxString = "";
  7580. if (! empty ( $toparty )) {
  7581. $userList = $this->getUserByToparty ( $toparty );
  7582. $userCon = implode ( ',', $userList );
  7583. // echo $userCon;
  7584. $sidList = $staff->getStaffByWxid ( $userCon );
  7585. foreach ( $sidList as $key => $value ) {
  7586. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7587. if ($falg) {
  7588. array_push ( $wxList, $value ['wxid'] );
  7589. }
  7590. }
  7591. $wxString = implode ( '|', $wxList );
  7592. }
  7593. return $wxString;
  7594. }
  7595. /**
  7596. * 读取发送信息规则判断是否需要发送
  7597. * @param number $sid
  7598. * @param string $sendType
  7599. * @return boolean
  7600. */
  7601. function isSendNotification($sid = 0, $sendType = '') {
  7602. Doo::loadModel ( "notificationConf" );
  7603. $notificationConf = new notificationConf ();
  7604. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7605. $conf = array ();
  7606. $sendFlag = true;
  7607. if (! empty ( $detail )) {
  7608. $conf = json_decode ( $detail ['conf'], true );
  7609. if (! empty ( $sendType )) {
  7610. if (isset ( $conf [$sendType] )) {
  7611. if ($conf [$sendType] == "CLOSE")
  7612. $sendFlag = false;
  7613. elseif ($conf [$sendType] == "Weekend") {
  7614. $day = date ( "w" );
  7615. if (1 <= $day && 5 >= $day)
  7616. $sendFlag = false;
  7617. } elseif ($conf [$sendType] == "OneToFriday") {
  7618. $day = date ( "w" );
  7619. if (0 == $day || 6 == $day)
  7620. $sendFlag = false;
  7621. }
  7622. }
  7623. } else
  7624. $sendFlag = false;
  7625. }
  7626. return $sendFlag;
  7627. }
  7628. /**
  7629. * 根据规则发送信息
  7630. * @param unknown $msg
  7631. * @param unknown $title
  7632. * @param unknown $url
  7633. * @param unknown $user
  7634. * @param string $text
  7635. * @return number
  7636. */
  7637. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7638. $token = $this->getAccessToken ();
  7639. $falg = $this->isSendNotification ( $sid, $sendType );
  7640. // if ($text == 'text') {
  7641. // $data = '{
  7642. // "touser": "' . $user . '",
  7643. // "toparty": "",
  7644. // "totag": "",
  7645. // "msgtype": "text",
  7646. // "agentid": 1000002,
  7647. // "text": {
  7648. // "content": "' . $msg . '"
  7649. // },
  7650. // "safe":0
  7651. // }';
  7652. // } else {
  7653. $data = '{
  7654. "touser": "' . $user . '",
  7655. "toparty": "",
  7656. "totag": "",
  7657. "msgtype": "news",
  7658. "agentid": 1000002,
  7659. "news": {
  7660. "articles":[
  7661. {
  7662. "title": "' . $title . '",
  7663. "description": "' . $msg . '",
  7664. "url": "' . $url . '",
  7665. "picurl": ""
  7666. }
  7667. ]
  7668. }
  7669. }';
  7670. // }
  7671. if ($falg) {
  7672. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7673. if ($result->errmsg != 'ok') {
  7674. return 0;
  7675. } else {
  7676. return 1;
  7677. }
  7678. } else
  7679. return 0;
  7680. }
  7681. private function getAccessToken() {
  7682. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7683. // $file = './access_token.txt';
  7684. // $data = json_decode ( file_get_contents ( $file ) );
  7685. // if ($data->expire_time < time () or ! $data->expire_time) {
  7686. // 如果是企业号用以下URL获取access_token
  7687. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7688. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7689. $res = json_decode ( $this->httpGet ( $url ) );
  7690. $access_token = $res->access_token;
  7691. // echo $access_token;
  7692. // if ($access_token) {
  7693. // $data->expire_time = time () + 7000;
  7694. // $data->access_token = $access_token;
  7695. // $fp = fopen ( $file, "w" );
  7696. // fwrite ( $fp, json_encode ( $data ) );
  7697. // fclose ( $fp );
  7698. // }
  7699. // } else {
  7700. // $access_token = $data->access_token;
  7701. // }
  7702. return $access_token;
  7703. }
  7704. private function httpGet($url) {
  7705. $curl = curl_init ();
  7706. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7707. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7708. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7709. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7710. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7711. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7712. curl_setopt ( $curl, CURLOPT_URL, $url );
  7713. $res = curl_exec ( $curl );
  7714. curl_close ( $curl );
  7715. return $res;
  7716. }
  7717. private function httpPost($url, $data) {
  7718. $curl = curl_init ();
  7719. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7720. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7721. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7722. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7723. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7724. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7725. curl_setopt ( $curl, CURLOPT_URL, $url );
  7726. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7727. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7728. $res = curl_exec ( $curl );
  7729. curl_close ( $curl );
  7730. return $res;
  7731. }
  7732. }
  7733. ?>