InvoiceController.php 333 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. require "protected/services/invoice_service.php";
  10. class InvoiceController extends DooController {
  11. public $staff;
  12. public $NEW;
  13. public $data;
  14. public $invoiceService;
  15. private $INVOICEKEY = "APPROVAL";
  16. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  17. private $ACTION = '';
  18. private $appId = 'wx3ee46531947a1384';
  19. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  20. public function beforeRun($resource, $action) {
  21. Doo::loadModel ( "invoiceManage" );
  22. $invoiceManage = new invoiceManage ();
  23. Doo::loadClass ( 'XDeode' );
  24. $XDeode = new XDeode ( 5 );
  25. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  26. header ( 'Content-Type:text/html;charset=utf-8' );
  27. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  28. if (empty ( $moldList )) {
  29. $flag = false;
  30. $uGroups = 'ordinary';
  31. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  32. $flag = true;
  33. }
  34. } else {
  35. $flag = false;
  36. array_push ( $moldList, array (
  37. 'mold' => 'ordinary'
  38. ) );
  39. // 删除审批人后-加入权限问题-暂时关闭
  40. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  41. $fiML = json_decode ( $fileInvoice, true );
  42. if (empty ( $fiML ))
  43. $fiML = array ();
  44. foreach ( $fiML as $key => $value ) {
  45. $sidList = explode ( ',', $value );
  46. foreach ( $sidList as $k => $v ) {
  47. if ($v == $sid) {
  48. array_push ( $moldList, array (
  49. 'mold' => $key
  50. ) );
  51. break;
  52. }
  53. }
  54. }
  55. foreach ( $moldList as $value ) {
  56. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  57. $flag = true;
  58. break;
  59. }
  60. }
  61. }
  62. /*
  63. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  64. */
  65. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  66. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  67. Doo::loadModel ( "invoiceCategoryManage" );
  68. $invoiceCategoryManage = new invoiceCategoryManage ();
  69. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  70. if (empty ( $icm ))
  71. die ( 'illegal request-iacd' );
  72. }
  73. // 单独判断应收款访问权限
  74. if ($action == 'invoiceAggregateCompanyDetail') {
  75. Doo::loadModel ( "invoiceCompanyManage" );
  76. $invoiceCompanyManage = new invoiceCompanyManage ();
  77. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  78. if (empty ( $icm ))
  79. die ( 'illegal request' );
  80. }
  81. // 主权限获得与判断
  82. Doo::loadModel ( 'staff' );
  83. $staff = new staff ();
  84. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  85. $accessModular = 'INVOICE';
  86. if (empty ( $detail ['cldAccessArray'] ))
  87. die ( 'illegal request' );
  88. else {
  89. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  90. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  91. $flag = true;
  92. } else {
  93. $flag = false;
  94. }
  95. } else {
  96. die ( 'illegal request' );
  97. }
  98. }
  99. if (! $flag)
  100. die ( 'illegal request' );
  101. }
  102. function __construct() {
  103. $this->invoiceService = new invoice_service ();
  104. //echo $routeRs ['1'];
  105. //die('dd');
  106. if (isset ( $_COOKIE ["staff"] )) {
  107. if (! empty ( $_COOKIE ["staff"] )) {
  108. Doo::loadModel ( 'staff' );
  109. $staff = new staff ();
  110. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  111. $this->ACTION = $uriPartsOrig [1];
  112. $this->data ['new'] = $this->isInvoiceNew ();
  113. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  114. $this->data ['isStaffCompleteMsg'] = false;
  115. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  116. if (! empty ( $detail ))
  117. $this->data ['isStaffCompleteMsg'] = true;
  118. return "/";
  119. }
  120. }
  121. Doo::loadCore ( 'uri/DooUriRouter' );
  122. $router = new DooUriRouter ();
  123. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  124. if ($routeRs ['1'] != "login") {
  125. header ( 'Content-Type:text/html;charset=utf-8' );
  126. @header ( "Location: /login" );
  127. }
  128. }
  129. function testSend() {
  130. // 测试根据规则发送信息 普通发送
  131. // $pendingApprovalsSid = 41;
  132. // Doo::loadModel ( 'staff' );
  133. // $staff = new staff ();
  134. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  135. // // 发送微信审批通知
  136. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  137. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  138. // Doo::loadModel ( 'staff' );
  139. // $staff = new staff ();
  140. // $toparty = $this->getToparty ( '广东办' );
  141. // $wxList = array ();
  142. // if (! empty ( $toparty )) {
  143. // $userList = $this->getUserByToparty ( $toparty );
  144. // $userCon = implode ( ',', $userList );
  145. // // echo $userCon;
  146. // $sidList = $staff->getStaffByWxid ( $userCon );
  147. // foreach ( $sidList as $key => $value ) {
  148. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  149. // if ($falg) {
  150. // array_push ( $wxList, $value ['wxid'] );
  151. // }
  152. // }
  153. // $wxString = implode ( '|', $wxList );
  154. // print_r ( $wxList );
  155. // echo $wxString;
  156. // }
  157. // 测试发送
  158. /*
  159. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  160. */
  161. // print_r ( $userList );
  162. // $msTouser='caipin|outaozhen';
  163. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  164. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  165. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  166. // $toparty= $this->getToparty('广东办');
  167. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  168. // $toparty = 26;
  169. // $msg = '';
  170. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  171. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  172. }
  173. function invoice() {
  174. Doo::loadModel ( 'invoice' );
  175. $invoice = new invoice ();
  176. Doo::loadModel ( 'express' );
  177. $express = new express ();
  178. $expressList = $express->getExpressByAll ();
  179. $this->data ['expressList'] = $expressList;
  180. // Doo::loadModel ( 'invoiceReceivables' );
  181. // $invoiceReceivables = new invoiceReceivables ();
  182. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  183. Doo::loadClass ( 'XDeode' );
  184. $XDeode = new XDeode ( 5 );
  185. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  186. Doo::loadModel ( 'invoiceStatistics' );
  187. $invoiceStatistics = new invoiceStatistics ();
  188. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  189. // 缓存统计结果
  190. $year = date ( "Y" );
  191. $tmp_date = date ( "Ym" );
  192. $tmp_year = substr ( $tmp_date, 0, 4 );
  193. $tmp_mon = substr ( $tmp_date, 4, 2 );
  194. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  195. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  196. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  197. if (is_file ( $path ))
  198. $htm = file_get_contents ( $path );
  199. else
  200. $htm = $this->showCache ( $path, $sid );
  201. $invoiceList = $invoice->getMyInvoice ( $sid );
  202. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  203. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  204. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  205. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  206. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  207. // 获得已退票功能
  208. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  209. $this->data ['untreadStatusList'] = $untreadStatusList;
  210. // print_r($untreadStatusList);
  211. $this->data ['isMonth'] = $isMonth;
  212. $this->data ['htm'] = $htm;
  213. $this->data ['invoiceList'] = $invoiceList;
  214. $this->data ['receivablesList'] = $list;
  215. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  216. $this->data ['memu'] = "invoice";
  217. $this->data ['staff'] = $this->staff;
  218. $this->data ['receiptMemu'] = 'invoice';
  219. $this->render ( "/admin/invoice", $this->data );
  220. }
  221. function invoiceExpress() {
  222. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  223. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  224. $this->data ['expressCom'] = $expressCom;
  225. $this->data ['expressNumber'] = $expressNumber;
  226. $this->render ( "/admin/invoiceExpress", $this->data );
  227. }
  228. function invoiceAdd() {
  229. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  230. session_start ();
  231. /*Doo::loadModel ( 'invoice' );
  232. $invoice = new invoice ();
  233. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  234. Doo::loadModel ( 'L_category' );
  235. $lCategory = new L_category ();
  236. $category = $lCategory->find ( array (
  237. 'asArray' => true
  238. ) );
  239. $this->data ['category'] = $category;
  240. Doo::loadModel ( 'invoiceTraining' );
  241. $invoiceTraining = new invoiceTraining ();
  242. $itList = $invoiceTraining->findAll( array (
  243. 'where' => " cid=" . $this->staff [0] ['cid'].' or creator ='.$this->staff [0]['sid'],
  244. 'desc'=>'itid',
  245. 'asArray' => TRUE
  246. ) );
  247. //$itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  248. Doo::loadModel ( 'receipt' );
  249. $receipt = new receipt ();
  250. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  251. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  252. if (! empty ( $receiptDetail )) {
  253. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  254. unset ( $itList [$key] );
  255. }
  256. }
  257. }
  258. $this->data ['itList'] = $itList;
  259. $token = $this->set_token ();
  260. $tokenTime=time().rand(5, 15);
  261. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  262. $this->data ['token'] = $token;
  263. $this->data['tokenTime']=$tokenTime;
  264. $this->data ['memu'] = "invoice";
  265. $this->data ['staff'] = $this->staff;
  266. $this->data ['receiptMemu'] = 'invoice';
  267. $this->render ( "/admin/invoiceAdd", $this->data );
  268. }
  269. /**
  270. * 自更新发票信息库
  271. * @param unknown $invoicePrintDetail
  272. */
  273. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  274. // 发票信息库
  275. Doo::loadModel ( 'invoiceInfoBase' );
  276. $invoiceInfoBase = new invoiceInfoBase ();
  277. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  278. $TIN = $invoicePrintDetail ['TIN'];
  279. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  280. if (empty ( $invoiceTitle ))
  281. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  282. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  283. // 确认有该条发票信息
  284. $invoiceInfoBase = new invoiceInfoBase ();
  285. if (! empty ( $IIBList )) {
  286. // 发票库里的信息数量
  287. $IIBListCount = count ( $IIBList );
  288. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  289. $item = array (
  290. 'iibID' => $IIBList [0] ['iibID'],
  291. 'invoiceTitle' => $invoiceTitle,
  292. 'TIN' => $TIN
  293. );
  294. if (! empty ( $invoicePrintDetail ['address'] )) {
  295. $item += array (
  296. 'address' => $invoicePrintDetail ['address']
  297. );
  298. }
  299. if (! empty ( $invoicePrintDetail ['phone'] )) {
  300. $item += array (
  301. 'phone' => $invoicePrintDetail ['phone']
  302. );
  303. }
  304. if (! empty ( $invoicePrintDetail ['bank'] )) {
  305. $item += array (
  306. 'bank' => $invoicePrintDetail ['bank']
  307. );
  308. }
  309. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  310. $item += array (
  311. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  312. );
  313. }
  314. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  315. $item += array (
  316. 'updateDate' => $invoicePrintDetail ['date']
  317. );
  318. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  319. }
  320. } else { // 删除多张发票,重新添加发票
  321. $iibIDStr = '';
  322. $iibID = array ();
  323. foreach ( $IIBList as $key => $value ) {
  324. array_push ( $iibID, $value ['iibID'] );
  325. }
  326. $iibIDStr = implode ( ",", $iibID ); // 删除
  327. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  328. $item = array (
  329. 'invoiceTitle' => $invoiceTitle,
  330. 'TIN' => $TIN,
  331. 'address' => $invoicePrintDetail ['address'],
  332. 'phone' => $invoicePrintDetail ['phone'],
  333. 'bank' => $invoicePrintDetail ['bank'],
  334. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  335. 'updateDate' => $invoicePrintDetail ['date']
  336. );
  337. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  338. }
  339. } else { // 没有新增发票信息
  340. $item = array (
  341. 'invoiceTitle' => $invoiceTitle,
  342. 'TIN' => $TIN,
  343. 'address' => $invoicePrintDetail ['address'],
  344. 'phone' => $invoicePrintDetail ['phone'],
  345. 'bank' => $invoicePrintDetail ['bank'],
  346. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  347. 'updateDate' => $invoicePrintDetail ['date']
  348. );
  349. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  350. }
  351. }
  352. function invoiceAddFill() {
  353. session_start ();
  354. Doo::loadModel ( 'L_category' );
  355. $lCategory = new L_category ();
  356. $category = $lCategory->find ( array (
  357. 'asArray' => true
  358. ) );
  359. $this->data ['category'] = $category;
  360. Doo::loadModel ( 'invoiceTraining' );
  361. $invoiceTraining = new invoiceTraining ();
  362. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  363. $this->data ['itList'] = $itList;
  364. Doo::loadModel ( 'invoice' );
  365. $invoice = new invoice ();
  366. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  367. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  368. $token = $this->set_token ();
  369. $tokenTime=time().rand(5, 15);
  370. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  371. $this->data ['token'] = $token;
  372. $this->data['tokenTime']=$tokenTime;
  373. $this->data ['invoiceDetail'] = $detail;
  374. $this->data ['memu'] = "invoice";
  375. $this->data ['staff'] = $this->staff;
  376. $this->data ['receiptMemu'] = 'invoice';
  377. $this->render ( "/admin/invoiceAddFill", $this->data );
  378. }
  379. /**
  380. * 提交一份开票申请,并记录下操作日志
  381. *
  382. * @since 1.0.0
  383. * @var integer cid 办事处ID
  384. * @var integer invoiceType 发票类型
  385. * @var integer doPost 是否邮寄
  386. * @var integer invoicePrice 开票金额
  387. * @var string invoiceElement 开票内容
  388. * @var string invoiceTitle 发票抬头
  389. * @var string invoiceCompany 单位名称
  390. * @var string TIN 纳税人识别码
  391. * @var string address 注册地址
  392. * @var string phone 注册电话
  393. * @var string bank 开户银行
  394. * @var string bankAccount 银行账户
  395. * @var string recipients 收件人
  396. * @var string recipientsPhone 收件人手机/电话
  397. * @var string recipientsAddress 收件地址
  398. * @var string mailItems 邮寄物品
  399. * @var string remark 备注
  400. * @return string 返回跳转开票主页路径
  401. */
  402. function invoiceAddDo() {
  403. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  404. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  405. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  406. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  407. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  408. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  409. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  410. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  411. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  412. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  413. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  414. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  415. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  416. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  417. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  418. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  419. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  420. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  421. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  422. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  423. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  424. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  425. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  426. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  427. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  428. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  429. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  430. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  431. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  432. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  433. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  434. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  435. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  436. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  437. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  438. $electronicPhone= $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  439. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  440. /*
  441. * $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;
  442. */
  443. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  444. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  445. if (empty ( $token )) {
  446. die ( 'illegal request-token' );
  447. } else {
  448. session_start ();
  449. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  450. header ( 'Content-Type:text/html;charset=utf-8' );
  451. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  452. die ( '请重新刷新发票申请页面' );
  453. }elseif($_SESSION [$sessionKey]=='repeat'){
  454. die ( '请勿重复申请发票' );
  455. } else {
  456. if ($_SESSION [$sessionKey] != $token){
  457. die ( '请勿重复申请发票' );
  458. }else{
  459. $_SESSION [$sessionKey] = 'repeat';
  460. }
  461. }
  462. }
  463. if($invoiceForm=='electronic'){
  464. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  465. die ( '请至少填写一种联系方式--电子发票' );
  466. }
  467. }
  468. if ($invoiceType == 1) {
  469. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  470. if ($temporary > 100001) {
  471. header ( 'Content-Type:text/html;charset=utf-8' );
  472. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  473. }
  474. }elseif($invoiceType == 0){
  475. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  476. if ($temporary > 100001) {
  477. header ( 'Content-Type:text/html;charset=utf-8' );
  478. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  479. }
  480. }else{
  481. die ( 'illegal request-invoiceType' );
  482. }
  483. if (empty ( $this->staff [0] ))
  484. die ( 'illegal request-Please login' );
  485. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  486. Doo::loadModel ( 'invoice' );
  487. $invoice = new invoice ();
  488. Doo::loadModel ( 'L_category' );
  489. $lCategory = new L_category ();
  490. Doo::loadModel ( 'invoiceManage' );
  491. $invoiceManage = new invoiceManage ();
  492. Doo::loadModel ( 'invoiceOperationLog' );
  493. $invoiceOperationLog = new invoiceOperationLog ();
  494. Doo::loadClass ( 'XDeode' );
  495. $XDeode = new XDeode ( 5 );
  496. $trainId = $XDeode->decode ( $trainId );
  497. $categoryDetil = $lCategory->getOne ( array (
  498. 'SELECT' => 'title',
  499. 'where' => 'cid=' . $cid,
  500. 'asArray' => true
  501. ) );
  502. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  503. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  504. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  505. // print_r(current($invoiceManageDetail ['staffList']));
  506. // die;
  507. $moldManage = array ();
  508. foreach ( $invoiceManageList as $key => $value ) {
  509. if ($value ['mold'] == '发票打印')
  510. $moldManage [$value ['mold']] = $value ['staffList'];
  511. elseif ($value ['mold'] == '发票邮寄')
  512. $moldManage [$value ['mold']] = $value ['staffList'];
  513. elseif ($value ['mold'] == '发票退票')
  514. $moldManage [$value ['mold']] = $value ['staffList'];
  515. }
  516. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  517. $st = '';
  518. if ($settlementType == 'SOFTWARE') {
  519. $st = 0;
  520. $trainId = 0;
  521. } elseif ($settlementType == 'TRAINING') {
  522. $st = 1;
  523. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  524. die ( 'illegal request-trainingIdError' );
  525. }
  526. } else {
  527. die ( 'illegal request-settlementError' );
  528. }
  529. if($invoiceForm=='electronic'){
  530. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  531. $invoiceForm=1;
  532. $invoiceType=0;
  533. if(!empty($electronicPhone)||!empty($electronicEmail)){
  534. }else{
  535. die ( 'illegal request-electronicContact' );
  536. }
  537. $mailList = array ();
  538. $mailString = '备注:' . $mailItems;
  539. }elseif($invoiceForm=='paper'){
  540. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  541. $invoiceForm=0;
  542. $mailList = array (
  543. 'invoice' => 1,
  544. 'mailItems' => $mailItems
  545. );
  546. $mailString = '发票x1张,备注:' . $mailItems;
  547. }else{
  548. die ( 'illegal request-invoiceForm' );
  549. }
  550. $item = array (
  551. 'cid' => $cid,
  552. 'categoryName' => $categoryDetil ['title'],
  553. 'invoiceElement' => $invoiceElement,
  554. 'invoiceForm'=>$invoiceForm,
  555. 'electronicPhone'=>$electronicPhone,
  556. 'electronicEmail'=>$electronicEmail,
  557. 'invoiceQuantity' => $invoiceQuantity,
  558. 'invoiceUnitPrice' => $invoiceUnitPrice,
  559. 'invoicePrice' => $invoicePrice,
  560. 'invoiceType' => $invoiceType,
  561. 'settlementType' => $st,
  562. 'doPost' => $doPost,
  563. 'status' => 1,
  564. 'invoiceSerial' => $invoiceSerial,
  565. 'date' => date ( "Y-m-d H:i:s" ),
  566. 'updateTime' => date ( "Y-m-d H:i:s" ),
  567. 'sid' => $this->staff [0] ['sid'],
  568. 'userName' => $this->staff [0] ['username'],
  569. 'invoiceManage' => $invoiceManageDetail ['staff'],
  570. 'pendingApprovals' => $pendingApprovalsSid,
  571. 'moldManage' => json_encode ( $moldManage ),
  572. 'remark' => $remark,
  573. 'trainId' => $trainId
  574. );
  575. if ($invoiceType == 0)
  576. $item += array (
  577. 'invoiceTitle' => $invoiceTitle,
  578. 'TIN' => $TINT,
  579. 'address' => $addressT,
  580. 'phone' => $phoneT,
  581. 'bank' => $bankT,
  582. 'bankAccount' => $bankAccountT
  583. );
  584. else {
  585. $item += array (
  586. 'invoiceCompany' => $invoiceCompany,
  587. 'TIN' => $TIN,
  588. 'address' => $address,
  589. 'phone' => $phone,
  590. 'bank' => $bank,
  591. 'bankAccount' => $bankAccount
  592. );
  593. }
  594. if ($doPost == 1) {
  595. if (! empty ( $softLock ))
  596. $mailList += array (
  597. 'softLock' => $softLockNum
  598. );
  599. else
  600. $mailList += array (
  601. 'softLock' => 0
  602. );
  603. if (! empty ( $contract ))
  604. $mailList += array (
  605. 'contract' => $contractNum
  606. );
  607. else
  608. $mailList += array (
  609. 'contract' => 0
  610. );
  611. if (! empty ( $instructions ))
  612. $mailList += array (
  613. 'instructions' => $instructionsNum
  614. );
  615. else
  616. $mailList += array (
  617. 'instructions' => 0
  618. );
  619. if (! empty ( $remittance ))
  620. $mailList += array (
  621. 'remittance' => $remittance
  622. );
  623. else
  624. $mailList += array (
  625. 'remittance' => ''
  626. );
  627. if (! empty ( $softLock ))
  628. $mailString .= ',软件锁x' . $softLockNum . '个';
  629. if (! empty ( $contract ))
  630. $mailString .= ',合同x' . $contractNum . '份';
  631. if (! empty ( $instructions ))
  632. $mailString .= ',说明书x' . $instructionsNum . '本';
  633. if (! empty ( $remittance ))
  634. $mailString .= ',汇款账号单(张)';
  635. $item += array (
  636. 'recipients' => $recipients,
  637. 'recipientsPhone' => $recipientsPhone,
  638. 'recipientsAddress' => $recipientsAddress,
  639. 'mailItems' => $mailString,
  640. 'mailItemsJson' => json_encode ( $mailList )
  641. );
  642. }
  643. $iid = $invoice->addInvoice ( $item );
  644. // 如果是培训班结算 创建培训班发票到培训班备份中
  645. if (! empty ( $st ) && $st == 1) {
  646. Doo::loadModel ( 'invoiceStore' );
  647. $invoiceStore = new invoiceStore ();
  648. Doo::loadModel ( 'invoiceTraining' );
  649. $invoiceTraining = new invoiceTraining ();
  650. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  651. $itemIS = array (
  652. 'isid' => $isid,
  653. 'ipSource' => 1,
  654. 'apStatus' => 1,
  655. 'iid' => $iid
  656. );
  657. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  658. // 更新培训班总数量
  659. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  660. $item = array (
  661. 'itid' => $trainId,
  662. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  663. 'submitStatus' => 1
  664. );
  665. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  666. }
  667. // 操作日志
  668. $item = array (
  669. 'date' => date ( "Y-m-d H:i:s" ),
  670. 'operation' => "创建",
  671. 'status' => 1,
  672. 'img' => $this->staff [0] ['avatar'],
  673. 'username' => $this->staff [0] ['username'],
  674. 'uid' => $this->staff [0] ['sid'],
  675. 'category' => $this->staff [0] ['category'],
  676. 'iid' => $iid
  677. );
  678. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  679. $item = array (
  680. 'date' => date ( "Y-m-d H:i:s" ),
  681. 'operation' => "提交审批",
  682. 'status' => 1,
  683. 'img' => $this->staff [0] ['avatar'],
  684. 'username' => $this->staff [0] ['username'],
  685. 'uid' => $this->staff [0] ['sid'],
  686. 'category' => $this->staff [0] ['category'],
  687. 'iid' => $iid
  688. );
  689. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  690. Doo::loadModel ( 'staff' );
  691. $staff = new staff ();
  692. $username2 = $staff->getOne ( array (
  693. 'select' => 'wxid',
  694. 'where' => 'sid=' . $pendingApprovalsSid,
  695. 'asArray' => TRUE
  696. ) );
  697. // 发送微信审批通知
  698. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  699. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  700. }
  701. return "/invoice";
  702. }
  703. function invoiceEdit() {
  704. Doo::loadClass ( 'XDeode' );
  705. $XDeode = new XDeode ( 5 );
  706. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  707. $iid = $XDeode->decode ( $iid );
  708. if (! is_numeric ( $iid ))
  709. die ( 'illegal request' );
  710. Doo::loadModel ( 'invoice' );
  711. $invoice = new invoice ();
  712. Doo::loadModel ( 'invoiceOperationLog' );
  713. $invoiceOperationLog = new invoiceOperationLog ();
  714. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  715. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  716. $invoiceDetail ['mailItemsJson'] ='';
  717. if(isset($invoiceDetail ['mailItemsJson'])){
  718. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  719. }
  720. $this->data ['operation'] = $operation;
  721. $this->data ['invoiceDetail'] = $invoiceDetail;
  722. $this->data ['memu'] = "invoice";
  723. $this->data ['staff'] = $this->staff;
  724. $this->data ['receiptMemu'] = 'invoice';
  725. $this->render ( "/admin/invoiceEdit", $this->data );
  726. }
  727. /**
  728. * 重新编辑退回的发票
  729. * @return string
  730. */
  731. function invoiceEditDo() {
  732. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  733. Doo::loadModel ( 'invoice' );
  734. $invoice = new invoice ();
  735. $iid = $invoice->authcode ( $iidKey );
  736. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  737. die ( 'illegal request' );
  738. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  739. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  740. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  741. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  742. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  743. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  744. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  745. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  746. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  747. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  748. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  749. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  750. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  751. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  752. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  753. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  754. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  755. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  756. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  757. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  758. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  759. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  760. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  761. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  762. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  763. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  764. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  765. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  766. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  767. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  768. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  769. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  770. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  771. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  772. if ($invoiceType == 1) {
  773. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  774. if ($temporary > 100001)
  775. die ( 'illegal request-Please priceError' );
  776. }
  777. if($invoiceForm=='electronic'){
  778. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  779. die ( '请至少填写一种联系方式--电子发票' );
  780. }
  781. }
  782. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  783. Doo::loadModel ( 'invoiceManage' );
  784. $invoiceManage = new invoiceManage ();
  785. Doo::loadModel ( 'invoiceOperationLog' );
  786. $invoiceOperationLog = new invoiceOperationLog ();
  787. Doo::loadModel ( 'invoiceStore' );
  788. $invoiceStore = new invoiceStore ();
  789. $cid = explode ( ':', $cid );
  790. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  791. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  792. $moldManage = array ();
  793. foreach ( $invoiceManageList as $key => $value ) {
  794. if ($value ['mold'] == '发票打印')
  795. $moldManage [$value ['mold']] = $value ['staffList'];
  796. elseif ($value ['mold'] == '发票邮寄')
  797. $moldManage [$value ['mold']] = $value ['staffList'];
  798. elseif ($value ['mold'] == '发票打印')
  799. $moldManage [$value ['mold']] = $value ['staffList'];
  800. }
  801. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  802. if($invoiceForm=='electronic'){
  803. $invoiceForm=1;
  804. $invoiceType=0;
  805. if(!empty($electronicPhone)||!empty($electronicEmail)){
  806. }else{
  807. die ( 'illegal request-electronicContact' );
  808. }
  809. $mailList = array ();
  810. $mailString = '备注:' . $mailItems;
  811. }elseif($invoiceForm=='paper'){
  812. $invoiceForm=0;
  813. $mailList = array (
  814. 'invoice' => 1,
  815. 'mailItems' => $mailItems
  816. );
  817. $mailString = '发票x1张,备注:' . $mailItems;
  818. }else{
  819. die ( 'illegal request-invoiceForm' );
  820. }
  821. $item = array (
  822. 'iid' => $iid,
  823. 'cid' => $cid [0],
  824. 'categoryName' => $cid [1],
  825. 'invoiceElement' => $invoiceElement,
  826. 'invoiceForm'=>$invoiceForm,
  827. 'electronicPhone'=>$electronicPhone,
  828. 'electronicEmail'=>$electronicEmail,
  829. 'invoiceQuantity' => $invoiceQuantity,
  830. 'invoiceUnitPrice' => $invoiceUnitPrice,
  831. 'invoicePrice' => $invoicePrice,
  832. 'invoiceType' => $invoiceType,
  833. 'doPost' => $doPost,
  834. 'status' => 1,
  835. 'updateTime' => date ( "Y-m-d H:i:s" ),
  836. 'remark' => $remark
  837. );
  838. if ($invoiceType == 0)
  839. $item += array (
  840. 'invoiceTitle' => $invoiceTitle,
  841. 'TIN' => $TINT,
  842. 'address' => $addressT,
  843. 'phone' => $phoneT,
  844. 'bank' => $bankT,
  845. 'bankAccount' => $bankAccountT
  846. );
  847. else {
  848. $item += array (
  849. 'invoiceCompany' => $invoiceCompany,
  850. 'TIN' => $TIN,
  851. 'address' => $address,
  852. 'phone' => $phone,
  853. 'bank' => $bank,
  854. 'bankAccount' => $bankAccount
  855. );
  856. }
  857. if ($doPost == 1) {
  858. if (! empty ( $softLock ))
  859. $mailList += array (
  860. 'softLock' => $softLockNum
  861. );
  862. else
  863. $mailList += array (
  864. 'softLock' => '0'
  865. );
  866. if (! empty ( $contract ))
  867. $mailList += array (
  868. 'contract' => $contractNum
  869. );
  870. else
  871. $mailList += array (
  872. 'contract' => '0'
  873. );
  874. if (! empty ( $instructions ))
  875. $mailList += array (
  876. 'instructions' => $instructionsNum
  877. );
  878. else
  879. $mailList += array (
  880. 'instructions' => '0'
  881. );
  882. if (! empty ( $remittance ))
  883. $mailList += array (
  884. 'remittance' => $remittance
  885. );
  886. else
  887. $mailList += array (
  888. 'remittance' => ''
  889. );
  890. if (! empty ( $softLock ))
  891. $mailString .= ',软件锁x' . $softLockNum;
  892. if (! empty ( $contract ))
  893. $mailString .= ',合同x' . $contractNum;
  894. if (! empty ( $instructions ))
  895. $mailString .= ',说明书x' . $instructionsNum;
  896. if (! empty ( $remittance ))
  897. $mailString .= ',汇款账号单';
  898. $item += array (
  899. 'recipients' => $recipients,
  900. 'recipientsPhone' => $recipientsPhone,
  901. 'recipientsAddress' => $recipientsAddress,
  902. 'mailItems' => $mailString,
  903. 'mailItemsJson' => json_encode ( $mailList )
  904. );
  905. }
  906. $invoice->setInvoiceByCondition ( $item );
  907. // 更新培训班仓库里的发票
  908. $detail = $invoice->getInvoiceByIid ( $iid );
  909. if (! empty ( $detail ['isid'] )) {
  910. $invoiceStore->isid = $detail ['isid'];
  911. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  912. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  913. $invoiceStore->invoicePrice = $invoicePrice;
  914. $invoiceStore->update ();
  915. }
  916. $item = array (
  917. 'date' => date ( "Y-m-d H:i:s" ),
  918. 'operation' => "重新提交审批",
  919. 'status' => 1,
  920. 'img' => $this->staff [0] ['avatar'],
  921. 'username' => $this->staff [0] ['username'],
  922. 'uid' => $this->staff [0] ['sid'],
  923. 'category' => $this->staff [0] ['category'],
  924. 'iid' => $iid
  925. );
  926. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  927. }
  928. return "/invoice";
  929. }
  930. /**
  931. * 培训班
  932. */
  933. function invoiceTraining() {
  934. Doo::loadModel ( 'L_category' );
  935. $lCategory = new L_category ();
  936. Doo::loadModel ( 'invoiceTraining' );
  937. $invoiceTraining = new invoiceTraining ();
  938. Doo::loadModel ( 'invoiceTrainManage' );
  939. $invoiceTrainManage = new invoiceTrainManage ();
  940. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  941. $cidList = array ();
  942. foreach ( $imcStaff as $key => $value ) {
  943. array_push ( $cidList, $value ['cid'] );
  944. }
  945. if (empty ( $cidList )) {
  946. $cidString = $this->staff [0] ['cid'];
  947. } else {
  948. $cidString = implode ( ',', $cidList );
  949. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  950. }
  951. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  952. // $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  953. //TODO 待完成入账培训班
  954. $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  955. // if($this->staff [0] ['sid']==94){
  956. // $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  957. // }else{
  958. // $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  959. // }
  960. // $itTodoList=$this->invoiceService->getTrainByCategoryStaff(0,$cidString,$this->staff [0] ['sid']);
  961. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  962. $category = $lCategory->getCategory ();
  963. $itid = array ();
  964. foreach ( $itTodoList as $key => $value ) {
  965. array_push ( $itid, $value ['itid'] );
  966. // 如果入账100%更新为已完成
  967. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  968. $invoiceTraining = new invoiceTraining ();
  969. $invoiceTraining->itid = $value ['itid'];
  970. $invoiceTraining->status = 2;
  971. $invoiceTraining->update ();
  972. }
  973. }
  974. foreach ( $itedList as $value ) {
  975. array_push ( $itid, $value ['itid'] );
  976. }
  977. $itid = implode ( ',', $itid );
  978. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  979. // print_r($itTodoList);
  980. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  981. $this->data ['itTodoList'] = $itTodoList;
  982. $this->data ['itedList'] = $itedList;
  983. $this->data ['category'] = $category;
  984. $this->data ['memu'] = "invoice";
  985. $this->data ['staff'] = $this->staff;
  986. $this->data ['receiptMemu'] = 'invoiceTraining';
  987. $this->render ( "/admin/invoiceTraining", $this->data );
  988. }
  989. /**
  990. * 创建培训班
  991. */
  992. function invoiceTrainingAdd() {
  993. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  994. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  995. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  996. if (empty ( $this->staff [0] ))
  997. die ( 'illegal request' );
  998. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  999. Doo::loadModel ( 'invoiceTraining' );
  1000. $invoiceTraining = new invoiceTraining ();
  1001. Doo::loadModel ( 'invoice' );
  1002. $invoice = new invoice ();
  1003. Doo::loadModel ( 'L_category' );
  1004. $lCategory = new L_category ();
  1005. Doo::loadModel ( 'invoiceManage' );
  1006. $invoiceManage = new invoiceManage ();
  1007. Doo::loadModel ( 'invoiceOperationLog' );
  1008. $invoiceOperationLog = new invoiceOperationLog ();
  1009. $item = array (
  1010. 'cid' => $cid,
  1011. 'trainName' => $trainName,
  1012. 'trainDate' => $trainDate,
  1013. 'creator' => $this->staff [0] ['sid'],
  1014. 'creatorDate' => date ( "Y-m-d H:i:s" )
  1015. );
  1016. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  1017. }
  1018. return "/invoiceTraining";
  1019. }
  1020. /**
  1021. * 删除培训班
  1022. */
  1023. function invoiceTrainingDelDo() {
  1024. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1025. if (! empty ( $itid )) {
  1026. Doo::loadModel ( 'invoiceTraining' );
  1027. $invoiceTraining = new invoiceTraining ();
  1028. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1029. }
  1030. return "/invoiceTraining";
  1031. }
  1032. /**
  1033. * 培训班详情
  1034. */
  1035. function invoiceTrainingDetail() {
  1036. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1037. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1038. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1039. Doo::loadModel ( 'invoiceTraining' );
  1040. $invoiceTraining = new invoiceTraining ();
  1041. Doo::loadModel ( 'invoiceStore' );
  1042. $invoiceStore = new invoiceStore ();
  1043. if (empty ( $itid ))
  1044. die ( 'illegal request' );
  1045. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1046. if ($trainStatus == "SUBED")
  1047. $con = ' (b.untreadStatus is null ) and ';
  1048. elseif ($trainStatus == "APPROVAL")
  1049. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1050. elseif ($trainStatus == "TICKET")
  1051. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1052. elseif ($trainStatus == "TICKETING") {
  1053. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1054. }
  1055. $con.=' a.invoiceForm=0 and ';
  1056. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1057. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1058. //print_r($isList);
  1059. $trainlistJson=$this->_trainList($isList);
  1060. if (empty ( $detail ))
  1061. die ( 'illegal request' );
  1062. // 培训班结算是否有和是否已经结算完成
  1063. Doo::loadModel ( 'receipt' );
  1064. $receipt = new receipt ();
  1065. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1066. $this->data ['receiptDetail'] = $receiptDetail;
  1067. $this->data ['trainStatus'] = $trainStatus;
  1068. $this->data ['itid'] = $itid;
  1069. $this->data ['trainlistJson'] = $trainlistJson;
  1070. $this->data ['iTrainDetail'] = $detail;
  1071. $this->data ['memu'] = "invoice";
  1072. $this->data ['staff'] = $this->staff;
  1073. $this->data ['receiptMemu'] = 'invoiceTraining';
  1074. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1075. }
  1076. function invoiceTrainingElectronicDetail(){
  1077. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1078. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1079. Doo::loadModel ( 'invoiceTraining' );
  1080. $invoiceTraining = new invoiceTraining ();
  1081. Doo::loadModel ( 'invoiceStore' );
  1082. $invoiceStore = new invoiceStore ();
  1083. if (empty ( $itid ))
  1084. die ( 'illegal request' );
  1085. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1086. if ($trainStatus == "SUBED")
  1087. $con = ' (b.untreadStatus is null ) and ';
  1088. elseif ($trainStatus == "APPROVAL")
  1089. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1090. elseif ($trainStatus == "TICKET")
  1091. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1092. elseif ($trainStatus == "TICKETING") {
  1093. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1094. }
  1095. $con.=' a.invoiceForm=1 and ';
  1096. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1097. // TODO 获得电子票
  1098. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1099. //print_r($isList);
  1100. if (empty ( $detail )){
  1101. die ( 'illegal request' );
  1102. }
  1103. $trainlistJson=$this->_trainList($isList,1);
  1104. // 培训班结算是否有和是否已经结算完成
  1105. Doo::loadModel ( 'receipt' );
  1106. $receipt = new receipt ();
  1107. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1108. $this->data ['receiptDetail'] = $receiptDetail;
  1109. $this->data ['trainStatus'] = $trainStatus;
  1110. $this->data ['itid'] = $itid;
  1111. $this->data ['trainlistJson'] = $trainlistJson;
  1112. $this->data ['iTrainDetail'] = $detail;
  1113. $this->data ['memu'] = "invoice";
  1114. $this->data ['staff'] = $this->staff;
  1115. $this->data ['receiptMemu'] = 'invoiceTraining';
  1116. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1117. }
  1118. function _trainList($isList,$type=0){
  1119. $trainlist = array ();
  1120. foreach ( $isList as $key => $value ) {
  1121. $irDetail = array ();
  1122. if ($value ['apStatus'] == 1) {
  1123. // array_push ( $irDetail, '' );
  1124. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1125. } else {
  1126. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1127. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1128. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1129. }
  1130. array_push ( $irDetail, $value ['invoiceSerial'] );
  1131. if ($value ['invoiceType'] == 1)
  1132. array_push ( $irDetail, $value ['invoiceCompany'] );
  1133. else
  1134. array_push ( $irDetail, $value ['invoiceTitle'] );
  1135. array_push ( $irDetail, $value ['TIN'] );
  1136. array_push ( $irDetail, $value ['userName'] );
  1137. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1138. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1139. } else
  1140. array_push ( $irDetail, $value ['mailItems'] );
  1141. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1142. if($type==1){
  1143. array_push ( $irDetail, $value ['electronicPhone'] );
  1144. array_push ( $irDetail, $value ['electronicEmail'] );
  1145. }
  1146. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1147. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1148. array_push ( $irDetail, $value ['invoiceElement'] );
  1149. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1150. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1151. if ($value ['invoiceType'] == 1)
  1152. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1153. else
  1154. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1155. array_push ( $irDetail, $value ['remark'] );
  1156. if ($value ['status'] == 1)
  1157. array_push ( $irDetail, '审批中' );
  1158. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1159. array_push ( $irDetail, '已出票' );
  1160. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1161. array_push ( $irDetail, '已入账' );
  1162. else
  1163. array_push ( $irDetail, '' );
  1164. array_push ( $irDetail, $value ['invoiceNo'] );
  1165. array_push ( $irDetail, $value ['printTime'] );
  1166. $html = '';
  1167. foreach ( $value ['invoiceReceivables'] as $v ) {
  1168. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1169. }
  1170. array_push ( $irDetail, $html );
  1171. array_push ( $trainlist, $irDetail );
  1172. }
  1173. $trainlistJson = json_encode ( $trainlist );
  1174. return $trainlistJson;
  1175. }
  1176. /**
  1177. * 上传培训班发票
  1178. * @return string
  1179. */
  1180. function invoiceTrainingUpload() {
  1181. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1182. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1183. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1184. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1185. header ( "HTTP/1.1 500 Internal Server Error" );
  1186. echo "POST exceeded maximum allowed size.";
  1187. exit ( 0 );
  1188. }
  1189. // Settings
  1190. $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)
  1191. $upload_name = "Filedata";
  1192. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1193. $extension_whitelist = array (
  1194. "doc",
  1195. "txt",
  1196. "jpg",
  1197. "gif",
  1198. "png"
  1199. ); // Allowed file extensions
  1200. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1201. // Other variables
  1202. $MAX_FILENAME_LENGTH = 260;
  1203. $file_name = "";
  1204. $file_extension = "";
  1205. $uploadErrors = array (
  1206. 0 => "文件上传成功",
  1207. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1208. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1209. 3 => "上传的文件仅为部分文件",
  1210. 4 => "没有文件上传",
  1211. 6 => "缺少临时文件夹"
  1212. );
  1213. $nk = time ();
  1214. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1215. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1216. echo "文件无法保存.";
  1217. exit ( 0 );
  1218. }
  1219. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1220. echo json_encode ( array (
  1221. 'filename' => $file_name,
  1222. 'id' => $nk
  1223. ) );
  1224. exit ( 0 );
  1225. }
  1226. /**
  1227. * 导入发票临时仓库
  1228. */
  1229. function invoiceStoreImport() {
  1230. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1231. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1232. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1233. if ($path != "" && ! empty ( $trainingKey )) {
  1234. Doo::loadModel ( 'invoiceStore' );
  1235. Doo::loadModel ( 'staff' );
  1236. $staff = new staff ();
  1237. Doo::loadModel ( 'invoiceTraining' );
  1238. $invoiceTraining = new invoiceTraining ();
  1239. Doo::loadClass ( 'XDeode' );
  1240. $XDeode = new XDeode ( 5 );
  1241. $itid = $XDeode->decode ( $trainingKey );
  1242. // 培训班结算是否有和是否已经结算完成
  1243. Doo::loadModel ( 'receipt' );
  1244. $receipt = new receipt ();
  1245. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1246. if (! empty ( $receiptDetail )) {
  1247. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1248. die ( 'illegal request--status' );
  1249. }
  1250. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1251. $userName = $this->staff [0] ['username'];
  1252. $sDetail = $staff->getStaffByName ( $userName );
  1253. //print_r($exlArray);die;
  1254. // die('sdd');
  1255. // 可以优化
  1256. foreach ( $exlArray as $key => $value ) {
  1257. // 开票
  1258. $invoice = new invoiceStore ();
  1259. $invoice->trainId = $itid;
  1260. $invoice->invoiceType = 0;
  1261. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1262. $invoice->invoiceType = 1;
  1263. elseif($value ['invoiceType'] == '电子'){
  1264. $invoice->invoiceType = 0;
  1265. $invoice->invoiceForm=1;
  1266. }
  1267. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1268. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1269. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1270. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1271. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1272. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1273. $invoice->userName = $userName;
  1274. $invoice->sid = $sDetail ['sid'];
  1275. $invoice->cid = $sDetail ['cid'];
  1276. $invoice->categoryName = $sDetail ['category'];
  1277. $invoice->invoiceElement = $value ['invoiceElement'];
  1278. $invoice->remark = $value ['remark'];
  1279. // $invoice->date = $value ['date'];
  1280. // $invoice->printTime = $value ['date'];
  1281. $invoice->ipSource = 1;
  1282. $invoice->printStatus = 0;
  1283. $invoice->status = 0;
  1284. $invoice->postStatus = 1;
  1285. $invoice->untreadStatus = 0;
  1286. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1287. $invoice->TIN = $value ['TIN'];
  1288. $invoice->address = $value ['address'];
  1289. $invoice->phone = $value ['phone'];
  1290. $invoice->bank = $value ['bank'];
  1291. $invoice->bankAccount = $value ['bankAccount'];
  1292. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1293. $invoice->recipients = $value ['recipients'];
  1294. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1295. $invoice->electronicPhone = $value ['electronicPhone'];
  1296. $invoice->electronicEmail = $value ['electronicEmail'];
  1297. $iid = $invoice->insert ();
  1298. }
  1299. // 加入发票总数量
  1300. $item = array (
  1301. 'itid' => $itid,
  1302. 'invoiceTotal' => count ( $exlArray )
  1303. );
  1304. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1305. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1306. }
  1307. echo 'no file';
  1308. }
  1309. /**
  1310. * 编辑仓库里的发票
  1311. */
  1312. function invoiceStoreEdit() {
  1313. Doo::loadClass ( 'XDeode' );
  1314. $XDeode = new XDeode ( 5 );
  1315. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1316. $iid = $XDeode->decode ( $iid );
  1317. if (! is_numeric ( $iid ))
  1318. die ( 'illegal request' );
  1319. Doo::loadModel ( 'invoiceStore' );
  1320. $invoiceStore = new invoiceStore ();
  1321. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1322. // print_r($invoiceDetail);
  1323. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1324. $this->data ['invoiceDetail'] = $invoiceDetail;
  1325. $this->data ['memu'] = "invoice";
  1326. $this->data ['staff'] = $this->staff;
  1327. $this->data ['receiptMemu'] = 'invoiceTraining';
  1328. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1329. }
  1330. function invoiceStoreEditDo() {
  1331. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1332. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1333. Doo::loadModel ( 'invoiceStore' );
  1334. $invoice = new invoiceStore ();
  1335. Doo::loadClass ( 'XDeode' );
  1336. $XDeode = new XDeode ( 5 );
  1337. $iid = $XDeode->decode ( $storeKey );
  1338. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1339. die ( 'illegal request' );
  1340. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1341. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1342. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1343. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1344. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1345. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1346. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1347. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1348. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1349. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1350. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1351. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1352. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1353. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1354. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1355. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1356. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1357. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1358. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1359. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1360. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1361. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1362. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1363. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1364. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1365. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1366. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1367. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1368. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1369. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1370. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1371. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1372. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1373. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1374. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1375. $cid = explode ( ':', $cid );
  1376. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1377. $item = array (
  1378. 'isid' => $iid,
  1379. 'cid' => $cid [0],
  1380. 'categoryName' => $cid [1],
  1381. 'invoiceElement' => $invoiceElement,
  1382. 'invoiceQuantity' => $invoiceQuantity,
  1383. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1384. 'invoicePrice' => $invoicePrice,
  1385. 'invoiceType' => $invoiceType,
  1386. 'doPost' => $doPost,
  1387. 'status' => 1,
  1388. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1389. 'remark' => $remark
  1390. );
  1391. if ($invoiceType == 0)
  1392. $item += array (
  1393. 'invoiceTitle' => $invoiceTitle,
  1394. 'TIN' => $TINT,
  1395. 'address' => $addressT,
  1396. 'phone' => $phoneT,
  1397. 'bank' => $bankT,
  1398. 'bankAccount' => $bankAccountT
  1399. );
  1400. else {
  1401. $item += array (
  1402. 'invoiceCompany' => $invoiceCompany,
  1403. 'TIN' => $TIN,
  1404. 'address' => $address,
  1405. 'phone' => $phone,
  1406. 'bank' => $bank,
  1407. 'bankAccount' => $bankAccount
  1408. );
  1409. }
  1410. if($invoiceForm=='paper'){
  1411. $item += array (
  1412. 'invoiceForm' => 0
  1413. );
  1414. }elseif($invoiceForm=='electronic'){
  1415. $item += array (
  1416. 'invoiceForm' => 1,
  1417. 'electronicPhone' => $electronicPhone,
  1418. 'electronicEmail' => $electronicEmail,
  1419. );
  1420. }
  1421. if ($doPost == 1) {
  1422. $mailList = array (
  1423. 'invoice' => 1,
  1424. 'mailItems' => $mailItems
  1425. );
  1426. if (! empty ( $softLock ))
  1427. $mailList += array (
  1428. 'softLock' => $softLockNum
  1429. );
  1430. else
  1431. $mailList += array (
  1432. 'softLock' => '0'
  1433. );
  1434. if (! empty ( $contract ))
  1435. $mailList += array (
  1436. 'contract' => $contractNum
  1437. );
  1438. else
  1439. $mailList += array (
  1440. 'contract' => '0'
  1441. );
  1442. if (! empty ( $instructions ))
  1443. $mailList += array (
  1444. 'instructions' => $instructionsNum
  1445. );
  1446. else
  1447. $mailList += array (
  1448. 'instructions' => '0'
  1449. );
  1450. if (! empty ( $remittance ))
  1451. $mailList += array (
  1452. 'remittance' => $remittance
  1453. );
  1454. else
  1455. $mailList += array (
  1456. 'remittance' => ''
  1457. );
  1458. $mailString = '发票x1,备注:' . $mailItems;
  1459. if (! empty ( $softLock ))
  1460. $mailString .= ',软件锁x' . $softLockNum;
  1461. if (! empty ( $contract ))
  1462. $mailString .= ',合同x' . $contractNum;
  1463. if (! empty ( $instructions ))
  1464. $mailString .= ',说明书x' . $instructionsNum;
  1465. if (! empty ( $remittance ))
  1466. $mailString .= ',汇款账号单';
  1467. $item += array (
  1468. 'recipients' => $recipients,
  1469. 'recipientsPhone' => $recipientsPhone,
  1470. 'recipientsAddress' => $recipientsAddress,
  1471. 'mailItems' => $mailString,
  1472. 'mailItemsJson' => json_encode ( $mailList )
  1473. );
  1474. }
  1475. $invoice->setInvoiceStoreByCondition ( $item );
  1476. }
  1477. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1478. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1479. }else{
  1480. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1481. }
  1482. }
  1483. /**
  1484. *
  1485. * @return string
  1486. */
  1487. function invoiceStoreDelete() {
  1488. Doo::loadClass ( 'XDeode' );
  1489. $XDeode = new XDeode ( 5 );
  1490. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1491. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1492. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1493. $isid = $XDeode->decode ( $iStoreKey );
  1494. $itid = $XDeode->decode ( $trainKey );
  1495. if (! is_numeric ( $isid ))
  1496. die ( 'illegal request' );
  1497. Doo::loadModel ( 'invoiceStore' );
  1498. $invoiceStore = new invoiceStore ();
  1499. $invoiceStore->delete ( array (
  1500. 'where' => 'isid=' . $isid,
  1501. 'limit' => 1
  1502. ) );
  1503. Doo::loadModel ( 'invoiceTraining' );
  1504. $invoiceTraining = new invoiceTraining ();
  1505. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1506. $item = array (
  1507. 'itid' => $itid,
  1508. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1509. );
  1510. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1511. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1512. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1513. }else{
  1514. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1515. }
  1516. }
  1517. /**
  1518. * 批量删除库里发票
  1519. */
  1520. function invoiceStoreBatchDelete() {
  1521. Doo::loadClass ( 'XDeode' );
  1522. $XDeode = new XDeode ( 5 );
  1523. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1524. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1525. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1526. if (empty ( $trainKey ) || empty ( $storeKey ))
  1527. die ( 'illegal request-IdKey' );
  1528. $tid = $XDeode->decode ( $trainKey );
  1529. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1530. die ( 'illegal request' );
  1531. Doo::loadModel ( 'invoiceStore' );
  1532. $isidKeyList = explode ( ',', $storeKey );
  1533. $isidList = array ();
  1534. foreach ( $isidKeyList as $value ) {
  1535. $isid = $XDeode->decode ( $value );
  1536. if (! empty ( $isid ) && is_numeric ( $isid ))
  1537. array_push ( $isidList, $isid );
  1538. }
  1539. $isidString = implode ( ',', $isidList );
  1540. $invoiceStore = new invoiceStore ();
  1541. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1542. $isidList = array ();
  1543. foreach ( $isList as $key => $value ) {
  1544. if ($value ['apStatus'] == 0)
  1545. array_push ( $isidList, $value ['isid'] );
  1546. }
  1547. $isidString = implode ( ',', $isidList );
  1548. // print_r($isList);
  1549. // echo $isidString;
  1550. $invoiceStore = new invoiceStore ();
  1551. $invoiceStore->delete ( array (
  1552. 'where' => "isid in ( " . $isidString . ")",
  1553. 'asArray' => TRUE
  1554. ) );
  1555. Doo::loadModel ( 'invoiceTraining' );
  1556. $invoiceTraining = new invoiceTraining ();
  1557. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1558. $item = array (
  1559. 'itid' => $tid,
  1560. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1561. );
  1562. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1563. // echo $tid;
  1564. // echo $storeKey;
  1565. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1566. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1567. }else{
  1568. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1569. }
  1570. }
  1571. function invoiceStoreBatchElectronicPhone(){
  1572. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1573. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1574. Doo::loadClass ( 'XDeode' );
  1575. $XDeode = new XDeode ( 5 );
  1576. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1577. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1578. if (empty ( $trainKey ) || empty ( $storeKey ))
  1579. die ( 'illegal request-IdKey' );
  1580. $isidKeyList = explode ( ',', $storeKey );
  1581. $isidList = array ();
  1582. foreach ( $isidKeyList as $value ) {
  1583. $isid = $XDeode->decode ( $value );
  1584. if (! empty ( $isid ) && is_numeric ( $isid ))
  1585. array_push ( $isidList, $isid );
  1586. }
  1587. $isidString = implode ( ',', $isidList );
  1588. $trainId = $XDeode->decode ( $trainKey );
  1589. if (! is_numeric ( $isid ))
  1590. die ( 'illegal request--isid' );
  1591. Doo::loadModel ( 'invoiceStore' );
  1592. $invoiceStore = new invoiceStore ();
  1593. $item = array (
  1594. 'electronicPhone' => $electronicPhone
  1595. );
  1596. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1597. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1598. }
  1599. function invoiceStoreBatchElectronicEmail(){
  1600. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1601. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1602. Doo::loadClass ( 'XDeode' );
  1603. $XDeode = new XDeode ( 5 );
  1604. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1605. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1606. if (empty ( $trainKey ) || empty ( $storeKey ))
  1607. die ( 'illegal request-IdKey' );
  1608. $isidKeyList = explode ( ',', $storeKey );
  1609. $isidList = array ();
  1610. foreach ( $isidKeyList as $value ) {
  1611. $isid = $XDeode->decode ( $value );
  1612. if (! empty ( $isid ) && is_numeric ( $isid ))
  1613. array_push ( $isidList, $isid );
  1614. }
  1615. $isidString = implode ( ',', $isidList );
  1616. $trainId = $XDeode->decode ( $trainKey );
  1617. if (! is_numeric ( $isid ))
  1618. die ( 'illegal request' );
  1619. Doo::loadModel ( 'invoiceStore' );
  1620. $invoiceStore = new invoiceStore ();
  1621. $item = array (
  1622. 'electronicEmail' => $electronicEmail
  1623. );
  1624. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1625. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1626. }
  1627. /**
  1628. * 仓库发票提交审批
  1629. * @return string
  1630. */
  1631. function invoiceStoreApproval() {
  1632. Doo::loadClass ( 'XDeode' );
  1633. $XDeode = new XDeode ( 5 );
  1634. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1635. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1636. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1637. $isid = $XDeode->decode ( $iStoreKey );
  1638. $trainId = $XDeode->decode ( $trainKey );
  1639. if (! is_numeric ( $isid ))
  1640. die ( 'illegal request' );
  1641. Doo::loadModel ( 'invoiceStore' );
  1642. Doo::loadModel ( 'invoice' );
  1643. $invoice = new invoice ();
  1644. // 加入限制必须填写入开票内容和邮寄物品
  1645. $invoiceStore = new invoiceStore ();
  1646. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1647. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1648. header ( 'Content-Type:text/html;charset=utf-8' );
  1649. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1650. }
  1651. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1652. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1653. header ( 'Content-Type:text/html;charset=utf-8' );
  1654. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1655. }
  1656. }
  1657. // 拷贝插入一条发票数据
  1658. $invoiceStore = new invoiceStore ();
  1659. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1660. $invoiceStore = new invoiceStore ();
  1661. $item = array (
  1662. 'isid' => $isid,
  1663. 'iid' => $iid,
  1664. 'apStatus' => 1
  1665. );
  1666. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1667. Doo::loadModel ( 'invoiceManage' );
  1668. $invoiceManage = new invoiceManage ();
  1669. Doo::loadModel ( 'invoiceOperationLog' );
  1670. $invoiceOperationLog = new invoiceOperationLog ();
  1671. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1672. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1673. $moldManage = array ();
  1674. foreach ( $invoiceManageList as $key => $value ) {
  1675. if ($value ['mold'] == '发票打印')
  1676. $moldManage [$value ['mold']] = $value ['staffList'];
  1677. elseif ($value ['mold'] == '发票邮寄')
  1678. $moldManage [$value ['mold']] = $value ['staffList'];
  1679. elseif ($value ['mold'] == '发票退票')
  1680. $moldManage [$value ['mold']] = $value ['staffList'];
  1681. }
  1682. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1683. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1684. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1685. }else{
  1686. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1687. }
  1688. $item = array (
  1689. 'iid' => $iid,
  1690. 'isid' => $isid,
  1691. 'invoiceSerial' => $invoiceSerial,
  1692. 'date' => date ( "Y-m-d H:i:s" ),
  1693. 'status' => 1,
  1694. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1695. 'trainId' => $trainId,
  1696. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1697. 'moldManage' => json_encode ( $moldManage ),
  1698. 'settlementType' => 1,
  1699. 'pendingApprovals' => $pendingApprovalsSid
  1700. );
  1701. $invoice->setInvoiceByCondition ( $item );
  1702. Doo::loadModel ( 'invoiceTraining' );
  1703. $invoiceTraining = new invoiceTraining ();
  1704. $item = array (
  1705. 'itid' => $trainId,
  1706. 'submitStatus' => 1
  1707. );
  1708. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1709. $item = array (
  1710. 'date' => date ( "Y-m-d H:i:s" ),
  1711. 'operation' => "创建",
  1712. 'status' => 1,
  1713. 'img' => $this->staff [0] ['avatar'],
  1714. 'username' => $this->staff [0] ['username'],
  1715. 'uid' => $this->staff [0] ['sid'],
  1716. 'category' => $this->staff [0] ['category'],
  1717. 'iid' => $iid
  1718. );
  1719. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1720. $item = array (
  1721. 'date' => date ( "Y-m-d H:i:s" ),
  1722. 'operation' => "提交审批",
  1723. 'status' => 1,
  1724. 'img' => $this->staff [0] ['avatar'],
  1725. 'username' => $this->staff [0] ['username'],
  1726. 'uid' => $this->staff [0] ['sid'],
  1727. 'category' => $this->staff [0] ['category'],
  1728. 'iid' => $iid
  1729. );
  1730. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1731. Doo::loadModel ( 'staff' );
  1732. $staff = new staff ();
  1733. $username2 = $staff->getOne ( array (
  1734. 'select' => 'wxid',
  1735. 'where' => 'sid=' . $pendingApprovalsSid,
  1736. 'asArray' => TRUE
  1737. ) );
  1738. // 发送微信审批通知
  1739. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1740. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1741. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1742. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1743. }else{
  1744. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1745. }
  1746. }
  1747. /**
  1748. * 批量提交发票
  1749. * @return string
  1750. */
  1751. function invoiceStoreBatchApproval() {
  1752. Doo::loadClass ( 'XDeode' );
  1753. $XDeode = new XDeode ( 5 );
  1754. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1755. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1756. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1757. if (empty ( $trainKey ) || empty ( $storeKey ))
  1758. die ( 'illegal request-IdKey' );
  1759. $trainId = $XDeode->decode ( $trainKey );
  1760. $isidKeyList = explode ( ',', $storeKey );
  1761. $isidList = array ();
  1762. foreach ( $isidKeyList as $value ) {
  1763. $isid = $XDeode->decode ( $value );
  1764. if (! empty ( $isid ) && is_numeric ( $isid ))
  1765. array_push ( $isidList, $isid );
  1766. }
  1767. $isidString = implode ( ',', $isidList );
  1768. if (! is_numeric ( $trainId ))
  1769. die ( 'illegal request' );
  1770. Doo::loadModel ( 'invoiceStore' );
  1771. Doo::loadModel ( 'invoice' );
  1772. // 判断哪些已经加入审批过
  1773. // 加入限制必须填写入开票内容和邮寄物品
  1774. $invoiceStore = new invoiceStore ();
  1775. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1776. foreach ( $isList as $key => $value ) {
  1777. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1778. header ( 'Content-Type:text/html;charset=utf-8' );
  1779. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1780. }
  1781. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1782. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1783. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1784. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1785. header ( 'Content-Type:text/html;charset=utf-8' );
  1786. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1787. }
  1788. }
  1789. }
  1790. // 拷贝插入一条发票数据
  1791. $invoiceStore = new invoiceStore ();
  1792. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1793. $invoiceStore = new invoiceStore ();
  1794. $item = array (
  1795. 'apStatus' => 1
  1796. );
  1797. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1798. // 获得正式发票ID
  1799. $invoice = new invoice ();
  1800. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1801. $sqlList = array ();
  1802. $iidString = '';
  1803. $iida = array ();
  1804. foreach ( $iidList as $key => $value ) {
  1805. $sqlList [$value ['isid']] = $value ['iid'];
  1806. array_push ( $iida, $value ['iid'] );
  1807. }
  1808. $iidString = implode ( ',', $iida );
  1809. $ids = implode ( ',', array_keys ( $sqlList ) );
  1810. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1811. foreach ( $sqlList as $id => $ordinal ) {
  1812. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1813. }
  1814. $sql .= "END WHERE isid IN ($ids)";
  1815. $invoiceStore = new invoiceStore ();
  1816. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1817. Doo::loadModel ( 'invoiceManage' );
  1818. $invoiceManage = new invoiceManage ();
  1819. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1820. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1821. $moldManage = array ();
  1822. foreach ( $invoiceManageList as $key => $value ) {
  1823. if ($value ['mold'] == '发票打印')
  1824. $moldManage [$value ['mold']] = $value ['staffList'];
  1825. elseif ($value ['mold'] == '发票邮寄')
  1826. $moldManage [$value ['mold']] = $value ['staffList'];
  1827. elseif ($value ['mold'] == '发票退票')
  1828. $moldManage [$value ['mold']] = $value ['staffList'];
  1829. }
  1830. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1831. // 批量更新发票信息
  1832. $item = array (
  1833. 'date' => date ( "Y-m-d H:i:s" ),
  1834. 'status' => 1,
  1835. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1836. 'trainId' => $trainId,
  1837. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1838. 'moldManage' => json_encode ( $moldManage ),
  1839. 'settlementType' => 1,
  1840. 'pendingApprovals' => $pendingApprovalsSid
  1841. );
  1842. $invoice = new invoice ();
  1843. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1844. // 批量更新发票中仓库isid
  1845. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1846. foreach ( $sqlList as $isid => $iid ) {
  1847. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1848. }
  1849. $sql .= "END WHERE iid IN ($iidString)";
  1850. $invoice = new invoice ();
  1851. $invoice->UpdateBatchInvoice ( $sql );
  1852. // 批量更新发票序列号
  1853. $sqlList = array ();
  1854. foreach ( $iida as $value ) {
  1855. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1856. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1857. }else{
  1858. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1859. }
  1860. }
  1861. $ids = implode ( ',', array_keys ( $sqlList ) );
  1862. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1863. foreach ( $sqlList as $id => $ordinal ) {
  1864. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1865. }
  1866. $sql .= "END WHERE iid IN ($ids)";
  1867. $invoiceStore = new invoiceStore ();
  1868. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1869. // 批量生产操作日志
  1870. Doo::loadModel ( 'invoiceOperationLog' );
  1871. $sqlList = array ();
  1872. foreach ( $iida as $key => $value ) {
  1873. $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 . '"),
  1874. ("' . 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 . '") ';
  1875. array_push ( $sqlList, $sql );
  1876. }
  1877. $iolSql = implode ( ',', $sqlList );
  1878. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1879. $invoiceOperationLog = new invoiceOperationLog ();
  1880. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1881. Doo::loadModel ( 'invoiceTraining' );
  1882. $invoiceTraining = new invoiceTraining ();
  1883. $item = array (
  1884. 'itid' => $trainId,
  1885. 'submitStatus' => 1
  1886. );
  1887. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1888. Doo::loadModel ( 'staff' );
  1889. $staff = new staff ();
  1890. $username2 = $staff->getOne ( array (
  1891. 'select' => 'wxid',
  1892. 'where' => 'sid=' . $pendingApprovalsSid,
  1893. 'asArray' => TRUE
  1894. ) );
  1895. // 发送微信审批通知
  1896. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1897. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1898. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1899. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1900. }else{
  1901. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1902. }
  1903. }
  1904. /**
  1905. */
  1906. function invoiceStoreMailItemSet() {
  1907. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1908. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1909. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1910. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1911. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1912. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1913. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1914. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1915. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1916. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1917. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1918. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1919. Doo::loadClass ( 'XDeode' );
  1920. $XDeode = new XDeode ( 5 );
  1921. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1922. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1923. $isid = $XDeode->decode ( $storeKey );
  1924. $trainId = $XDeode->decode ( $trainKey );
  1925. if (! is_numeric ( $isid ))
  1926. die ( 'illegal request' );
  1927. Doo::loadModel ( 'invoiceStore' );
  1928. $invoiceStore = new invoiceStore ();
  1929. $mailList = array (
  1930. 'mailItems' => $mailItems
  1931. );
  1932. $mailString = '发票x1,备注:' . $mailItems;
  1933. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1934. $mailString = '备注:' . $mailItems;
  1935. }else{
  1936. $mailList += array (
  1937. 'invoice' => 1,
  1938. );
  1939. }
  1940. if (! empty ( $softLock ))
  1941. $mailList += array (
  1942. 'softLock' => $softLockNum
  1943. );
  1944. else
  1945. $mailList += array (
  1946. 'softLock' => 0
  1947. );
  1948. if (! empty ( $contract ))
  1949. $mailList += array (
  1950. 'contract' => $contractNum
  1951. );
  1952. else
  1953. $mailList += array (
  1954. 'contract' => 0
  1955. );
  1956. if (! empty ( $instructions ))
  1957. $mailList += array (
  1958. 'instructions' => $instructionsNum
  1959. );
  1960. else
  1961. $mailList += array (
  1962. 'instructions' => 0
  1963. );
  1964. if (! empty ( $remittance ))
  1965. $mailList += array (
  1966. 'remittance' => $remittance
  1967. );
  1968. else
  1969. $mailList += array (
  1970. 'remittance' => ''
  1971. );
  1972. if (! empty ( $softLock ))
  1973. $mailString .= ',软件锁x' . $softLockNum;
  1974. if (! empty ( $contract ))
  1975. $mailString .= ',合同x' . $contractNum;
  1976. if (! empty ( $instructions ))
  1977. $mailString .= ',说明书x' . $instructionsNum;
  1978. if (! empty ( $remittance ))
  1979. $mailString .= ',汇款账号单';
  1980. $item = array (
  1981. 'isid' => $isid,
  1982. 'doPost' => 1,
  1983. 'mailItems' => $mailString,
  1984. 'mailItemsJson' => json_encode ( $mailList )
  1985. );
  1986. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1987. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1988. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1989. }else{
  1990. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1991. }
  1992. }
  1993. /**
  1994. * 批量设置邮寄物品
  1995. */
  1996. function invoiceStoreBatchMailItemSet() {
  1997. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1998. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1999. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  2000. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  2001. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  2002. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  2003. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  2004. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  2005. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  2006. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  2007. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  2008. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  2009. Doo::loadClass ( 'XDeode' );
  2010. $XDeode = new XDeode ( 5 );
  2011. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  2012. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2013. if (empty ( $trainKey ) || empty ( $storeKey ))
  2014. die ( 'illegal request-IdKey' );
  2015. $isidKeyList = explode ( ',', $storeKey );
  2016. $isidList = array ();
  2017. foreach ( $isidKeyList as $value ) {
  2018. $isid = $XDeode->decode ( $value );
  2019. if (! empty ( $isid ) && is_numeric ( $isid ))
  2020. array_push ( $isidList, $isid );
  2021. }
  2022. $isidString = implode ( ',', $isidList );
  2023. $trainId = $XDeode->decode ( $trainKey );
  2024. if (! is_numeric ( $isid ))
  2025. die ( 'illegal request' );
  2026. Doo::loadModel ( 'invoiceStore' );
  2027. $invoiceStore = new invoiceStore ();
  2028. $mailList = array (
  2029. 'mailItems' => $mailItems
  2030. );
  2031. $mailString = '发票x1,备注:' . $mailItems;
  2032. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2033. $mailString = '备注:' . $mailItems;
  2034. }else{
  2035. $mailList += array (
  2036. 'invoice' => 1,
  2037. );
  2038. }
  2039. if (! empty ( $softLock ))
  2040. $mailList += array (
  2041. 'softLock' => $softLockNum
  2042. );
  2043. else
  2044. $mailList += array (
  2045. 'softLock' => 0
  2046. );
  2047. if (! empty ( $contract ))
  2048. $mailList += array (
  2049. 'contract' => $contractNum
  2050. );
  2051. else
  2052. $mailList += array (
  2053. 'contract' => 0
  2054. );
  2055. if (! empty ( $instructions ))
  2056. $mailList += array (
  2057. 'instructions' => $instructionsNum
  2058. );
  2059. else
  2060. $mailList += array (
  2061. 'instructions' => 0
  2062. );
  2063. if (! empty ( $remittance ))
  2064. $mailList += array (
  2065. 'remittance' => $remittance
  2066. );
  2067. else
  2068. $mailList += array (
  2069. 'remittance' => ''
  2070. );
  2071. if (! empty ( $softLock ))
  2072. $mailString .= ',软件锁x' . $softLockNum;
  2073. if (! empty ( $contract ))
  2074. $mailString .= ',合同x' . $contractNum;
  2075. if (! empty ( $instructions ))
  2076. $mailString .= ',说明书x' . $instructionsNum;
  2077. if (! empty ( $remittance ))
  2078. $mailString .= ',汇款账号单';
  2079. $item = array (
  2080. 'doPost' => 1,
  2081. 'mailItems' => $mailString,
  2082. 'mailItemsJson' => json_encode ( $mailList )
  2083. );
  2084. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2085. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2086. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2087. }else{
  2088. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2089. }
  2090. }
  2091. /**
  2092. * 废弃
  2093. */
  2094. function ajaxGetMailItemByIstore() {
  2095. Doo::loadClass ( 'XDeode' );
  2096. $XDeode = new XDeode ( 5 );
  2097. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2098. $isid = $XDeode->decode ( $storeKey );
  2099. if (! is_numeric ( $isid ))
  2100. die ( 'illegal request' );
  2101. Doo::loadModel ( 'invoiceStore' );
  2102. $invoiceStore = new invoiceStore ();
  2103. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2104. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2105. echo json_encode ( $isDetail ['mailItemsJson'] );
  2106. exit ();
  2107. }
  2108. /**
  2109. * 终止开票
  2110. */
  2111. function invoiceDroppedDo() {
  2112. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2113. Doo::loadModel ( 'invoice' );
  2114. $invoice = new invoice ();
  2115. Doo::loadModel ( 'invoiceOperationLog' );
  2116. $invoiceOperationLog = new invoiceOperationLog ();
  2117. $iid = $invoice->authcode ( $droppedIidKey );
  2118. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2119. die ( 'illegal request' );
  2120. $item = array (
  2121. 'iid' => $iid,
  2122. 'status' => 4,
  2123. 'updateTime' => date ( "Y-m-d H:i:s" )
  2124. );
  2125. $invoice->setInvoiceByCondition ( $item );
  2126. $item = array (
  2127. 'date' => date ( "Y-m-d H:i:s" ),
  2128. 'operation' => '终止了开票',
  2129. 'status' => 4,
  2130. 'img' => $this->staff [0] ['avatar'],
  2131. 'username' => $this->staff [0] ['username'],
  2132. 'uid' => $this->staff [0] ['sid'],
  2133. 'category' => $this->staff [0] ['category'],
  2134. 'iid' => $iid
  2135. );
  2136. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2137. return "/invoice";
  2138. }
  2139. /**
  2140. * 更新退票的邮寄信息
  2141. */
  2142. function invoiceUntreadMailDo() {
  2143. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2144. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2145. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2146. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2147. Doo::loadModel ( 'invoice' );
  2148. $invoice = new invoice ();
  2149. $iid = $invoice->authcode ( $untreadIidKey );
  2150. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2151. die ( 'illegal request' );
  2152. $item = array (
  2153. 'iid' => $iid,
  2154. 'untreadCompany' => $untreadCompany,
  2155. 'untreadNumber' => $untreadNumber,
  2156. 'untreadItems' => $untreadItems
  2157. );
  2158. $invoice->setInvoiceByCondition ( $item );
  2159. return "/invoice";
  2160. }
  2161. /**
  2162. * 申请退票 --
  2163. */
  2164. function invoiceUntreadDo() {
  2165. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2166. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2167. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : 0;
  2168. Doo::loadModel ( 'invoice' );
  2169. $invoice = new invoice ();
  2170. Doo::loadModel ( 'invoiceOperationLog' );
  2171. $invoiceOperationLog = new invoiceOperationLog ();
  2172. Doo::loadModel ( 'invoiceReceivables' );
  2173. $invoiceReceivables = new invoiceReceivables ();
  2174. $iid = $invoice->authcode ( $untreadIidKey );
  2175. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2176. die ( 'illegal request' );
  2177. /*
  2178. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2179. */
  2180. $item = array (
  2181. 'iid' => $iid,
  2182. 'untreadStatus' => 1,
  2183. 'untreadReason' => $untreadReason,
  2184. 'untreadPost' => $untreadPost,
  2185. 'updateTime' => date ( "Y-m-d H:i:s" )
  2186. );
  2187. $invoice->setInvoiceByCondition ( $item );
  2188. $item = array (
  2189. 'date' => date ( "Y-m-d H:i:s" ),
  2190. 'operation' => '申请退票',
  2191. 'status' => 7,
  2192. 'img' => $this->staff [0] ['avatar'],
  2193. 'username' => $this->staff [0] ['username'],
  2194. 'uid' => $this->staff [0] ['sid'],
  2195. 'category' => $this->staff [0] ['category'],
  2196. 'iid' => $iid
  2197. );
  2198. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2199. return "/invoice";
  2200. }
  2201. /**
  2202. * 删除已终止的开票
  2203. */
  2204. function invoiceDelDo() {
  2205. Doo::loadModel ( 'invoice' );
  2206. $invoice = new invoice ();
  2207. Doo::loadModel ( 'invoiceOperationLog' );
  2208. $invoiceOperationLog = new invoiceOperationLog ();
  2209. Doo::loadClass ( 'XDeode' );
  2210. $XDeode = new XDeode ( 5 );
  2211. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2212. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2213. $iid = $XDeode->decode ( $iid );
  2214. Doo::loadModel ( 'invoiceStore' );
  2215. $invoiceStore = new invoiceStore ();
  2216. if (! is_numeric ( $iid ))
  2217. die ( 'illegal request' );
  2218. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2219. if (empty ( $invoiceDetail ))
  2220. die ( 'illegal request' );
  2221. $item = array (
  2222. 'iid' => $iid,
  2223. 'isDelete' => 1,
  2224. 'updateTime' => date ( "Y-m-d H:i:s" )
  2225. );
  2226. $invoice->setInvoiceByCondition ( $item );
  2227. $item = array (
  2228. 'date' => date ( "Y-m-d H:i:s" ),
  2229. 'operation' => '删除了已终止的发票',
  2230. 'status' => 4,
  2231. 'img' => $this->staff [0] ['avatar'],
  2232. 'username' => $this->staff [0] ['username'],
  2233. 'uid' => $this->staff [0] ['sid'],
  2234. 'category' => $this->staff [0] ['category'],
  2235. 'iid' => $iid
  2236. );
  2237. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2238. // 删除培训班发票仓库里的发票
  2239. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2240. return "/invoice";
  2241. }
  2242. /**
  2243. */
  2244. function invoiceApproval() {
  2245. Doo::loadModel ( 'invoice' );
  2246. $invoice = new invoice ();
  2247. Doo::loadClass ( 'XDeode' );
  2248. $XDeode = new XDeode ( 5 );
  2249. Doo::loadModel ( 'staff' );
  2250. $staff = new staff ();
  2251. $invoiceList = $invoice->find ( array (
  2252. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2253. 'desc' => 'iid',
  2254. 'limit' => 10,
  2255. 'asArray' => true
  2256. ) );
  2257. foreach ( $invoiceList as $key => $value ) {
  2258. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2259. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2260. if (! empty ( $lastApprover )) {
  2261. $lastApproverKey = array_keys ( $lastApprover );
  2262. $lastApprover = end ( $lastApprover );
  2263. $staffDetail = $staff->getOne ( array (
  2264. 'where' => 'sid=' . end ( $lastApproverKey ),
  2265. 'asArray' => true
  2266. ) );
  2267. $lastApprover ['username'] = $staffDetail ['username'];
  2268. }
  2269. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2270. }
  2271. $ilist = $invoice->getInvoiceByProcessStatus ();
  2272. foreach ( $ilist as $key => $value ) {
  2273. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2274. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2275. if (! empty ( $lastApprover )) {
  2276. $lastApproverKey = array_keys ( $lastApprover );
  2277. $lastApprover = end ( $lastApprover );
  2278. $staffDetail = $staff->getOne ( array (
  2279. 'where' => 'sid=' . end ( $lastApproverKey ),
  2280. 'asArray' => true
  2281. ) );
  2282. $lastApprover ['username'] = $staffDetail ['username'];
  2283. }
  2284. $ilist [$key] ['lastApprover'] = $lastApprover;
  2285. }
  2286. // print_r($ilist);
  2287. $this->data ['invoiceList'] = $invoiceList;
  2288. $this->data ['ilist'] = $ilist;
  2289. $this->data ['memu'] = "invoice";
  2290. $this->data ['staff'] = $this->staff;
  2291. $this->data ['receiptMemu'] = 'invoiceApproval';
  2292. $this->render ( "/admin/invoiceApproval", $this->data );
  2293. }
  2294. function invoiceDetail() {
  2295. Doo::loadClass ( 'XDeode' );
  2296. $XDeode = new XDeode ( 5 );
  2297. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2298. $iid = $XDeode->decode ( $iid );
  2299. if (! is_numeric ( $iid ))
  2300. die ( 'illegal request' );
  2301. Doo::loadModel ( 'invoice' );
  2302. $invoice = new invoice ();
  2303. Doo::loadModel ( 'invoiceOperationLog' );
  2304. $invoiceOperationLog = new invoiceOperationLog ();
  2305. $invoiceDetail = $invoice->getOne ( array (
  2306. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2307. 'asArray' => true
  2308. ) );
  2309. if (empty ( $invoiceDetail ))
  2310. die ( 'illegal request' );
  2311. if ($invoiceDetail ['settlementType'] == 1) {
  2312. Doo::loadModel ( 'invoiceTraining' );
  2313. $invoiceTraining = new invoiceTraining ();
  2314. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2315. }
  2316. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2317. $this->data ['invoiceDetail'] = $invoiceDetail;
  2318. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2319. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2320. $this->data ['memu'] = "invoice";
  2321. $this->data ['staff'] = $this->staff;
  2322. $this->data ['receiptMemu'] = 'invoiceApproval';
  2323. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2324. }
  2325. /**
  2326. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2327. *
  2328. * @since 1.0.0
  2329. * @var integer iid 开票ID 已加密
  2330. * @var integer status 发票审批状态
  2331. * @var integer opintion 审批发票的意见
  2332. * @return string 如操作成功返回审批首页
  2333. */
  2334. function invoiceApprovalDo() {
  2335. Doo::loadModel ( 'invoice' );
  2336. $invoice = new invoice ();
  2337. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2338. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2339. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2340. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2341. $iid = $invoice->authcode ( $iid );
  2342. if (! is_numeric ( $iid ))
  2343. die ( 'illegal request' );
  2344. // && ! empty ( $opinion )
  2345. if (! empty ( $iid ) && ! empty ( $status )) {
  2346. if (! ($status == 2 || $status == 3 || $status == 4))
  2347. die ( 'illegal request' );
  2348. Doo::loadModel ( 'invoiceOperationLog' );
  2349. $invoiceOperationLog = new invoiceOperationLog ();
  2350. $invoiceDetail = $invoice->getOne ( array (
  2351. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2352. 'asArray' => true
  2353. ) );
  2354. if (empty ( $invoiceDetail ))
  2355. die ( 'illegal request' );
  2356. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2357. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2358. if ($status == 3) {
  2359. $invoice->status = $status;
  2360. $item = array (
  2361. 'operation' => $opinion
  2362. );
  2363. } else {
  2364. if (empty ( $processApprovals )) {
  2365. $processApprovals = array (
  2366. $this->staff [0] ['sid'] => array (
  2367. 'date' => date ( "Y-m-d H:i:s" ),
  2368. 'opinion' => $opinion,
  2369. 'status' => $status
  2370. )
  2371. );
  2372. // var_dump(next($invoiceManage));
  2373. $nextInvoiceManage = next ( $invoiceManage );
  2374. // print_r($nextInvoiceManage);
  2375. if ($status != 4 && $nextInvoiceManage !== false)
  2376. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2377. $invoice->processApprovals = json_encode ( $processApprovals );
  2378. // var_dump($invoice);
  2379. // print_r($invoiceManage);
  2380. } else {
  2381. $processApprovals [$this->staff [0] ['sid']] = array (
  2382. 'date' => date ( "Y-m-d H:i:s" ),
  2383. 'opinion' => $opinion,
  2384. 'status' => $status
  2385. );
  2386. $pendingApprovals = 0;
  2387. foreach ( $invoiceManage as $key => $value ) {
  2388. if ($value [0] == $this->staff [0] ['sid']) {
  2389. if (isset ( $invoiceManage [$key + 1] ))
  2390. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2391. break;
  2392. }
  2393. }
  2394. if ($status != 4 && ! empty ( $pendingApprovals ))
  2395. $invoice->pendingApprovals = $pendingApprovals;
  2396. $invoice->processApprovals = json_encode ( $processApprovals );
  2397. }
  2398. $item = array (
  2399. 'operation' => $opinion
  2400. );
  2401. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2402. $invoice->status = $status;
  2403. $invoice->pendingApprovals = 0;
  2404. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2405. } elseif ($status == 4) {
  2406. $invoice->status = $status;
  2407. $item = array (
  2408. 'operation' => $opinion
  2409. );
  2410. }
  2411. }
  2412. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2413. $invoice->update ( array (
  2414. 'where' => 'iid=' . $iid
  2415. ) );
  2416. $item += array (
  2417. 'date' => date ( "Y-m-d H:i:s" ),
  2418. 'img' => $this->staff [0] ['avatar'],
  2419. 'username' => $this->staff [0] ['username'],
  2420. 'uid' => $this->staff [0] ['sid'],
  2421. 'category' => $this->staff [0] ['category'],
  2422. 'status' => $status,
  2423. 'iid' => $iid
  2424. );
  2425. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2426. if (empty ( $divApproval ))
  2427. return '/invoiceApproval';
  2428. else
  2429. return '/invoiceApprovalAchieve/PEND';
  2430. }
  2431. die ( 'illegal request' );
  2432. }
  2433. /**
  2434. * 展示需要打印的发票数据
  2435. *
  2436. * @since 1.0.0
  2437. */
  2438. function invoicePrint() {
  2439. Doo::loadModel ( 'invoice' );
  2440. $invoice = new invoice ();
  2441. Doo::loadClass ( 'XDeode' );
  2442. $XDeode = new XDeode ( 5 );
  2443. Doo::loadModel ( 'staff' );
  2444. $staff = new staff ();
  2445. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2446. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2447. foreach ( $toPrint as $key => $value ) {
  2448. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2449. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2450. if (! empty ( $lastApprover )) {
  2451. $lastApproverKey = array_keys ( $lastApprover );
  2452. $lastApprover = end ( $lastApprover );
  2453. $staffDetail = $staff->getOne ( array (
  2454. 'where' => 'sid=' . end ( $lastApproverKey ),
  2455. 'asArray' => true
  2456. ) );
  2457. $lastApprover ['username'] = $staffDetail ['username'];
  2458. }
  2459. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2460. }
  2461. foreach ( $printed as $key => $value ) {
  2462. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2463. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2464. if (! empty ( $lastApprover )) {
  2465. $lastApproverKey = array_keys ( $lastApprover );
  2466. $lastApprover = end ( $lastApprover );
  2467. $staffDetail = $staff->getOne ( array (
  2468. 'where' => 'sid=' . end ( $lastApproverKey ),
  2469. 'asArray' => true
  2470. ) );
  2471. $lastApprover ['username'] = $staffDetail ['username'];
  2472. }
  2473. $printed [$key] ['lastApprover'] = $lastApprover;
  2474. }
  2475. $this->data ['printed'] = $printed;
  2476. $this->data ['toPrint'] = $toPrint;
  2477. $this->data ['memu'] = "invoice";
  2478. $this->data ['staff'] = $this->staff;
  2479. $this->data ['receiptMemu'] = 'invoicePrint';
  2480. $this->render ( "/admin/invoicePrint", $this->data );
  2481. }
  2482. /**
  2483. * 展示发票打印的详情页面
  2484. *
  2485. * @since 1.0.0
  2486. */
  2487. function invoicePrintDetail() {
  2488. Doo::loadClass ( 'XDeode' );
  2489. $XDeode = new XDeode ( 5 );
  2490. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2491. $iid = $XDeode->decode ( $iid );
  2492. if (! is_numeric ( $iid ))
  2493. die ( 'illegal request' );
  2494. Doo::loadModel ( 'invoice' );
  2495. $invoice = new invoice ();
  2496. Doo::loadModel ( 'invoiceOperationLog' );
  2497. $invoiceOperationLog = new invoiceOperationLog ();
  2498. Doo::loadModel ( 'invoicePaper' );
  2499. $invoicePaper = new invoicePaper ();
  2500. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2501. if (empty ( $invoiceDetail ))
  2502. die ( 'illegal request' );
  2503. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2504. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2505. if ($invoiceDetail ['settlementType'] == 1) {
  2506. Doo::loadModel ( 'invoiceTraining' );
  2507. $invoiceTraining = new invoiceTraining ();
  2508. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2509. }
  2510. $this->data ['invoicePaperList'] = $invoicePaperList;
  2511. $this->data ['invoiceDetail'] = $invoiceDetail;
  2512. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2513. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2514. $this->data ['memu'] = "invoice";
  2515. $this->data ['staff'] = $this->staff;
  2516. $this->data ['receiptMemu'] = 'invoicePrint';
  2517. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2518. }
  2519. /**
  2520. * 所有待打印 发票
  2521. */
  2522. function invoicePrintStayAchieve() {
  2523. Doo::loadModel ( 'invoice' );
  2524. $invoice = new invoice ();
  2525. Doo::loadClass ( 'XDeode' );
  2526. $XDeode = new XDeode ( 5 );
  2527. Doo::loadModel ( 'staff' );
  2528. $staff = new staff ();
  2529. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2530. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2531. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2532. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2533. Doo::loadModel ( 'invoiceTraining' );
  2534. $invoiceTraining = new invoiceTraining ();
  2535. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2536. $page_size = 12;
  2537. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2538. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2539. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2540. $get = "/" . $status;
  2541. $con = ' and status=2 ';
  2542. if ($status == 'TOPRINT')
  2543. $con = ' and status=2 and printStatus=0 ';
  2544. elseif ($status == 'PRINTED')
  2545. $con = ' and status=2 and printStatus=1';
  2546. if ($invoiceType == 'ORDINARY')
  2547. $con .= ' and invoiceType=0 and invoiceForm=0 ';
  2548. elseif ($invoiceType == 'SPECIAL'){
  2549. $con .= ' and invoiceType=1 ';
  2550. }elseif($invoiceType == 'ELECTRON'){
  2551. $con .= ' and invoiceType=0 and invoiceForm=1 ';
  2552. }
  2553. if ($invoiceTrain == 'ORDINARY')
  2554. $con .= ' and trainId=0 ';
  2555. elseif ($invoiceTrain == 'TRAIN')
  2556. $con .= ' and trainId!=0 ';
  2557. if ($invoiceTrainName != 'ALL') {
  2558. $trainId = $XDeode->decode ( $invoiceTrainName );
  2559. if (is_numeric ( $trainId ))
  2560. $con .= ' and trainId =' . $trainId;
  2561. }
  2562. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2563. $dateArr = explode ( ':', $date );
  2564. $D1 = '';
  2565. $D2 = '';
  2566. if (! empty ( $date )) {
  2567. $D1 = $dateArr [0];
  2568. $D2 = $dateArr [1];
  2569. }
  2570. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date )){
  2571. $D1= $D1.":00.00.00";
  2572. $D2= $D2.":23.59.59";
  2573. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2574. }
  2575. if (! empty ( $MebSea )) {
  2576. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2577. }
  2578. $pageinfo ['page'] = array (
  2579. 'previous' => ''
  2580. );
  2581. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2582. $sql = " (untreadStatus=0 or untreadStatus=3 or untreadStatus=4) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2583. $action = "invoicePrintStayAchieve";
  2584. //echo $sql;
  2585. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2586. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2587. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2588. $this->data ['trainList'] = $trainList;
  2589. $this->data ['invoiceType'] = $invoiceType;
  2590. $this->data ['invoiceTrain'] = $invoiceTrain;
  2591. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2592. $this->data ['MebSeaEn'] = $MebSea;
  2593. $this->data ['MebSea'] = urlencode ( $MebSea );
  2594. $this->data ['get'] = $get;
  2595. $this->data ['page'] = $pageinfo;
  2596. $this->data ['date'] = $date;
  2597. $this->data ['status'] = $status;
  2598. $this->data ['invoiceType'] = $invoiceType;
  2599. $this->data ['memu'] = "invoice";
  2600. $this->data ['staff'] = $this->staff;
  2601. foreach ( $list as $key => $value ) {
  2602. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2603. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2604. if (! empty ( $lastApprover )) {
  2605. $lastApproverKey = array_keys ( $lastApprover );
  2606. $lastApprover = end ( $lastApprover );
  2607. $staffDetail = $staff->getOne ( array (
  2608. 'where' => 'sid=' . end ( $lastApproverKey ),
  2609. 'asArray' => true
  2610. ) );
  2611. $lastApprover ['username'] = $staffDetail ['username'];
  2612. }
  2613. $list [$key] ['lastApprover'] = $lastApprover;
  2614. }
  2615. $this->data ['receiptMemu'] = 'invoicePrint';
  2616. $this->data ['list'] = $list;
  2617. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2618. }
  2619. /**
  2620. * 填写票号并完成打印
  2621. * @since 1.0.0
  2622. */
  2623. function invoicePrintDo() {
  2624. Doo::loadModel ( 'invoice' );
  2625. $invoice = new invoice ();
  2626. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2627. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2628. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2629. $iid = $invoice->authcode ( $iid );
  2630. if (! is_numeric ( $iid ))
  2631. die ( 'illegal request-iid' );
  2632. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2633. Doo::loadModel ( 'invoiceOperationLog' );
  2634. $invoiceOperationLog = new invoiceOperationLog ();
  2635. Doo::loadModel ( 'invoiceStatistics' );
  2636. $invoiceStatistics = new invoiceStatistics ();
  2637. $XDeode = new XDeode ( 5 );
  2638. Doo::loadModel ( 'invoicePaper' );
  2639. $invoicePaper = new invoicePaper ();
  2640. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2641. if (empty ( $invoicePrintDetail ))
  2642. die ( 'illegal request-data_empty' );
  2643. //
  2644. $ipid = $XDeode->decode ( $invoiceNo );
  2645. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2646. if (empty ( $paperDetail ))
  2647. die ( 'illegal request-paper_empty' );
  2648. $invoicePaper = new invoicePaper ();
  2649. $item = array (
  2650. 'iid' => $iid,
  2651. 'ipid' => $ipid
  2652. );
  2653. $invoicePaper->setInvoicePaperByCondition ( $item );
  2654. $item = array (
  2655. 'iid' => $iid,
  2656. 'printStatus' => 1,
  2657. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2658. 'printer' => $this->staff [0] ['username'],
  2659. 'printTime' => date ( "Y-m-d H:i:s" ),
  2660. 'invoiceNo' => $paperDetail ['invoiceNo']
  2661. );
  2662. $invoice->setInvoiceByCondition ( $item );
  2663. $item = array (
  2664. 'date' => date ( "Y-m-d H:i:s" ),
  2665. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2666. 'status' => 5,
  2667. 'img' => $this->staff [0] ['avatar'],
  2668. 'username' => $this->staff [0] ['username'],
  2669. 'uid' => $this->staff [0] ['sid'],
  2670. 'category' => $this->staff [0] ['category'],
  2671. 'iid' => $iid
  2672. );
  2673. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2674. // 去统计--负票不汇总
  2675. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2676. $item = array (
  2677. 'date' => date ( "Y-m-d H:i:s" ),
  2678. 'priceClass' => 1,
  2679. 'cid' => $invoicePrintDetail ['cid'],
  2680. 'staff' => $invoicePrintDetail ['sid'],
  2681. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2682. );
  2683. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2684. }
  2685. // 发送通知信息到微信-去除
  2686. // $this->setWXMsg($iid,'PRINT');
  2687. // 发票信息库
  2688. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2689. // 申请人获取微信通知
  2690. Doo::loadModel ( 'staff' );
  2691. $staff = new staff ();
  2692. Doo::loadClass ( 'XDeode' );
  2693. $XDeode = new XDeode ( 5 );
  2694. $username2 = $staff->getOne ( array (
  2695. 'select' => 'wxid',
  2696. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2697. 'asArray' => TRUE
  2698. ) );
  2699. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2700. $msg = '';
  2701. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2702. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2703. if (empty ( $invoicePrintType ))
  2704. return "/invoicePrint";
  2705. else
  2706. return "/invoicePrintStayAchieve";
  2707. }
  2708. }
  2709. /**
  2710. * 需要邮寄的发票
  2711. * @since 1.0.0
  2712. */
  2713. function invoicePost() {
  2714. Doo::loadModel ( 'invoice' );
  2715. $invoice = new invoice ();
  2716. Doo::loadModel ( 'express' );
  2717. $express = new express ();
  2718. $invoicePost = $invoice->getPostByInvoice ();
  2719. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2720. $expressList = $express->getExpressByAll ();
  2721. $invoicePostExpress = "";
  2722. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2723. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2724. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2725. $this->data ['expressList'] = $expressList;
  2726. $this->data ['invoicePost'] = $invoicePost;
  2727. $this->data ['invoicePosted'] = $invoicePosted;
  2728. $this->data ['memu'] = "invoice";
  2729. $this->data ['staff'] = $this->staff;
  2730. $this->data ['receiptMemu'] = 'invoicePost';
  2731. $this->render ( "/admin/invoicePost", $this->data );
  2732. }
  2733. /**
  2734. * 添加发票邮寄信息
  2735. */
  2736. function invoiceExpressAddDo() {
  2737. Doo::loadModel ( 'invoice' );
  2738. $invoice = new invoice ();
  2739. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2740. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2741. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2742. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2743. $iid = $iid = $invoice->authcode ( $iid );
  2744. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2745. die ( 'illegal request' );
  2746. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2747. setcookie ( 'invoicePostExpress', $expressNumber );
  2748. $item = array (
  2749. 'iid' => $iid,
  2750. 'postStatus' => 1,
  2751. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2752. 'postTime' => date ( "Y-m-d H:i:s" ),
  2753. 'expressCompany' => $expressCompany,
  2754. 'expressNumber' => $expressNumber,
  2755. 'actualItems' => $actualItems,
  2756. 'poster' => $this->staff [0] ['username']
  2757. );
  2758. $invoice->setInvoiceByCondition ( $item );
  2759. // 微信通知-去掉
  2760. // $this->setWXMsg ( $iid );
  2761. Doo::loadModel ( 'staff' );
  2762. $staff = new staff ();
  2763. Doo::loadClass ( 'XDeode' );
  2764. $XDeode = new XDeode ( 5 );
  2765. $username2 = $staff->getOne ( array (
  2766. 'select' => 'wxid',
  2767. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2768. 'asArray' => TRUE
  2769. ) );
  2770. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2771. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2772. if (empty ( $expCom ))
  2773. $expCom [0] = '';
  2774. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2775. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2776. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2777. return '/invoicePost';
  2778. }
  2779. function invoiceExpressUpdateDo() {
  2780. Doo::loadModel ( 'invoice' );
  2781. $invoice = new invoice ();
  2782. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2783. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2784. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2785. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2786. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2787. $iid = $invoice->authcode ( $iid );
  2788. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2789. die ( 'illegal request' );
  2790. $item = array (
  2791. 'iid' => $iid,
  2792. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2793. 'expressCompany' => $expressCompany,
  2794. 'expressNumber' => $expressNumber,
  2795. 'actualItems' => $actualItems,
  2796. 'poster' => $this->staff [0] ['username']
  2797. );
  2798. $invoice->setInvoiceByCondition ( $item );
  2799. return $action;
  2800. }
  2801. /**
  2802. * 可退票管理
  2803. */
  2804. function invoiceUntreadIsAchieve() {
  2805. Doo::loadModel ( 'invoice' );
  2806. $invoice = new invoice ();
  2807. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2808. /*
  2809. * 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' => '' );
  2810. */
  2811. if (empty ( $MebSea )) {//
  2812. $con = ' and invoiceNo like "NULL" ';
  2813. } else {
  2814. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2815. }
  2816. // printStatus=1 and
  2817. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2818. /*
  2819. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2820. */
  2821. $limit = '0,50';
  2822. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2823. //print_r($list);
  2824. $this->data ['MebSeaEn'] = $MebSea;
  2825. /*
  2826. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2827. */
  2828. $this->data ['list'] = $list;
  2829. $this->data ['memu'] = "invoice";
  2830. $this->data ['staff'] = $this->staff;
  2831. $this->data ['receiptMemu'] = 'invoice';
  2832. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2833. }
  2834. // 已经退票的发票
  2835. function invoiceUntreadED() {
  2836. Doo::loadModel ( 'invoice' );
  2837. $invoice = new invoice ();
  2838. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2839. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2840. Doo::loadClass ( 'XDeode' );
  2841. $XDeode = new XDeode ( 5 );
  2842. $page_size = 18;
  2843. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2844. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2845. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2846. $dateArr = explode ( ':', $date );
  2847. $D1 = '';
  2848. $D2 = '';
  2849. if (! empty ( $date )) {
  2850. $D1 = $dateArr [0];
  2851. $D2 = $dateArr [1];
  2852. }
  2853. $con = '';
  2854. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2855. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2856. }
  2857. // if ($date == 'MONTHO')
  2858. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2859. // elseif ($date == 'MONTHT')
  2860. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2861. // elseif ($date == 'MONTHY')
  2862. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2863. if (! empty ( $MebSea )) {
  2864. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2865. }
  2866. if ($invoiceType == 'ORDINARY') {
  2867. $con .= ' and invoiceType=0 ';
  2868. } elseif ($invoiceType == 'SPECIAL') {
  2869. $con .= ' and invoiceType=1 ';
  2870. }
  2871. $pageinfo ['page'] = array (
  2872. 'previous' => ''
  2873. );
  2874. // printStatus=1 and
  2875. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2876. $action = "invoiceUntreadED";
  2877. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2878. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2879. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2880. // print_r($list);
  2881. $this->data ['MebSeaEn'] = $MebSea;
  2882. $this->data ['get'] = $get;
  2883. $this->data ['page'] = $pageinfo;
  2884. $this->data ['date'] = $date;
  2885. $this->data ['invoiceType'] = $invoiceType;
  2886. $this->data ['list'] = $list;
  2887. $this->data ['memu'] = "invoice";
  2888. $this->data ['staff'] = $this->staff;
  2889. $this->data ['receiptMemu'] = 'invoice';
  2890. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2891. }
  2892. /**
  2893. * 退票处理页面
  2894. */
  2895. function invoiceUntread() {
  2896. Doo::loadModel ( 'invoice' );
  2897. $invoice = new invoice ();
  2898. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2899. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2900. //print_r($establishedInvoice);
  2901. // foreach ( $establishedInvoice as $key => $value ) {
  2902. // // months
  2903. // $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2904. // $nowDate = strtotime ( 'now' );
  2905. // $establishedInvoice [$key] ['lossShow'] = false;
  2906. // if ($lossDate < $nowDate)
  2907. // $establishedInvoice [$key] ['lossShow'] = true;
  2908. // }
  2909. $this->data ['untreadInvoice'] = $untreadInvoice;
  2910. $this->data ['establishedInvoice'] = $establishedInvoice;
  2911. $this->data ['memu'] = "invoice";
  2912. $this->data ['staff'] = $this->staff;
  2913. $this->data ['receiptMemu'] = 'invoiceUntread';
  2914. $this->render ( "/admin/invoiceUntread", $this->data );
  2915. }
  2916. /**
  2917. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2918. */
  2919. function invoiceUntreadEstablishedDo() {
  2920. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2921. Doo::loadModel ( 'invoice' );
  2922. $invoice = new invoice ();
  2923. Doo::loadModel ( 'invoiceOperationLog' );
  2924. $invoiceOperationLog = new invoiceOperationLog ();
  2925. Doo::loadModel ( 'invoiceReceivables' );
  2926. Doo::loadModel ( 'invoiceStatistics' );
  2927. $iid = $invoice->authcode ( $untreadIidKey );
  2928. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2929. die ( 'illegal request' );
  2930. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2931. if ($invoiceDetails ['untreadStatus'] != 1)
  2932. die ( 'illegal request untreadStatus error !=1' );
  2933. $item = array (
  2934. 'iid' => $iid,
  2935. // 'irid'=>'',
  2936. 'untreadStatus' => 2,
  2937. 'untreadTime'=>date ( "Y-m-d H:i:s" ) ,
  2938. 'updateTime' => date ( "Y-m-d H:i:s" )
  2939. );
  2940. $invoice->setInvoiceByCondition ( $item );
  2941. $item = array (
  2942. 'date' => date ( "Y-m-d H:i:s" ),
  2943. 'operation' => '已确认退票',
  2944. 'status' => 6,
  2945. 'img' => $this->staff [0] ['avatar'],
  2946. 'username' => $this->staff [0] ['username'],
  2947. 'uid' => $this->staff [0] ['sid'],
  2948. 'category' => $this->staff [0] ['category'],
  2949. 'iid' => $iid
  2950. );
  2951. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2952. // 收款解绑以及入账扣除 收款扣除
  2953. if (! empty ( $invoiceDetails ['irid'] )) {
  2954. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2955. foreach ( $iridList as $value ) {
  2956. $invoiceReceivables = new invoiceReceivables ();
  2957. $irDetails = $invoiceReceivables->getOne ( array (
  2958. 'where' => " irid=" . $value . ' ',
  2959. 'asArray' => TRUE
  2960. ) );
  2961. $bindPrice=$irDetails['bindPrice']-$invoiceDetails['invoicePrice'];
  2962. if($bindPrice<0){
  2963. $bindPrice=0;
  2964. }
  2965. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  2966. $item = array (
  2967. 'irid' => $value,
  2968. 'bindStatus' => 0,
  2969. 'untreadStatus' => 1,
  2970. 'bindPrice'=>$bindPrice,
  2971. 'untreadStaff' => $invoiceDetails ['userName'],
  2972. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2973. );
  2974. if($irDetails['iid']==$iid){
  2975. $item+=array(
  2976. 'iid' => 0
  2977. );
  2978. }else{
  2979. foreach ($iidExtend as $iek=>$iev){
  2980. if($iev==$iid){
  2981. unset($iidExtend[$iek]);
  2982. break;
  2983. }
  2984. }
  2985. if(empty($iidExtend)){
  2986. $item+=array(
  2987. 'iidExtend' => ''
  2988. );
  2989. }else{
  2990. $iidExtend=implode(",", $iidExtend);
  2991. $item+=array(
  2992. 'iidExtend' => $iidExtend
  2993. );
  2994. }
  2995. }
  2996. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2997. if (! empty ( $irDetails )) {
  2998. // 扣除入账
  2999. $invoiceStatistics = new invoiceStatistics ();
  3000. $item = array (
  3001. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3002. 'priceClass' => 3,
  3003. 'cid' => $invoiceDetails ['cid'],
  3004. 'staff' => $invoiceDetails ['sid'],
  3005. 'accountPrice' => - $irDetails ['receivablesPrice']
  3006. );
  3007. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3008. // 扣除收款
  3009. $invoiceStatistics = new invoiceStatistics ();
  3010. $item = array (
  3011. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  3012. 'priceClass' => 2,
  3013. 'cid' => $invoiceDetails ['cid'],
  3014. 'staff' => $invoiceDetails ['sid'],
  3015. 'irid' => $irDetails ['irid'],
  3016. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  3017. );
  3018. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3019. }
  3020. // 解绑时删除收入流水--退票不删除流水
  3021. // Doo::loadModel ( 'wasteBook' );
  3022. // $wasteBook = new wasteBook ();
  3023. // $wasteBook->delete ( array (
  3024. // 'where' => 'dataID=' . $value . ' and accountType=7',
  3025. // 'limit' => 1
  3026. // ) );
  3027. }
  3028. }
  3029. return "/invoiceUntread";
  3030. }
  3031. function invoiceUntreadRecallDo() {
  3032. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  3033. Doo::loadModel ( 'invoice' );
  3034. $invoice = new invoice ();
  3035. Doo::loadClass ( 'XDeode' );
  3036. $XDeode = new XDeode ( 5 );
  3037. Doo::loadModel ( 'invoiceOperationLog' );
  3038. $invoiceOperationLog = new invoiceOperationLog ();
  3039. $iid = $XDeode->decode ( $iidKey );
  3040. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  3041. if (empty ( $invoiceDetail )) {
  3042. die ( 'illegal request-DATANULL' );
  3043. }
  3044. $item = array (
  3045. 'iid' => $iid,
  3046. 'untreadStatus' => 0
  3047. );
  3048. $invoice->setInvoiceByCondition ( $item );
  3049. $item = array (
  3050. 'date' => date ( "Y-m-d H:i:s" ),
  3051. 'operation' => '撤回申请退票',
  3052. 'status' => 13,
  3053. 'img' => $this->staff [0] ['avatar'],
  3054. 'username' => $this->staff [0] ['username'],
  3055. 'uid' => $this->staff [0] ['sid'],
  3056. 'category' => $this->staff [0] ['category'],
  3057. 'iid' => $iid
  3058. );
  3059. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3060. return "/invoiceUntread";
  3061. }
  3062. /**
  3063. * 建立负票,关联原来发票
  3064. */
  3065. function invoiceLossDo() {
  3066. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3067. if (! empty ( $iidKey )) {
  3068. Doo::loadClass ( 'XDeode' );
  3069. $XDeode = new XDeode ( 5 );
  3070. Doo::loadModel ( 'invoice' );
  3071. $invoice = new invoice ();
  3072. Doo::loadModel ( 'invoiceOperationLog' );
  3073. $invoiceOperationLog = new invoiceOperationLog ();
  3074. $iidKey = $XDeode->decode ( $iidKey );
  3075. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3076. // 拷贝插入一条发票数据
  3077. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3078. // 更新负票
  3079. if($invoiceDetail['invoiceForm']==1){
  3080. $invoiceSerial = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3081. }else{
  3082. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3083. }
  3084. $invoice = new invoice ();
  3085. $item = array (
  3086. 'iid' => $iid,
  3087. 'sid' => $this->staff [0] ['sid'],
  3088. 'userName' => $this->staff [0] ['username'],
  3089. 'cid' => $this->staff [0] ['cid'],
  3090. 'categoryName' => $this->staff [0] ['category'],
  3091. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3092. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3093. 'invoiceSerial' => $invoiceSerial,
  3094. 'invoiceNo' => '',
  3095. 'printStatus' => 0,
  3096. 'untreadStatus' => 4,
  3097. // 关联发票号
  3098. 'lossIid' => $invoiceDetail ['iid']
  3099. );
  3100. $invoice->setInvoiceByCondition ( $item );
  3101. // 更新原发票
  3102. $invoice = new invoice ();
  3103. $item = array (
  3104. 'iid' => $invoiceDetail ['iid'],
  3105. 'lossIid' => $iid
  3106. );
  3107. $invoice->setInvoiceByCondition ( $item );
  3108. // 操作日志
  3109. $item = array (
  3110. 'date' => date ( "Y-m-d H:i:s" ),
  3111. 'operation' => "创建负票" . $invoiceSerial,
  3112. 'status' => 12,
  3113. 'img' => $this->staff [0] ['avatar'],
  3114. 'username' => $this->staff [0] ['username'],
  3115. 'uid' => $this->staff [0] ['sid'],
  3116. 'category' => $this->staff [0] ['category'],
  3117. 'iid' => $iid
  3118. );
  3119. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3120. // print_r($invoiceDetail);
  3121. // echo $iid;die;
  3122. }
  3123. return '/invoiceUntread';
  3124. }
  3125. /**
  3126. * 上传银行到账 收款文件
  3127. */
  3128. function invoiceReceivablesBankUpload() {
  3129. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3130. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3131. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3132. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3133. header ( "HTTP/1.1 500 Internal Server Error" );
  3134. echo "POST exceeded maximum allowed size.";
  3135. exit ( 0 );
  3136. }
  3137. // Settings
  3138. $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)
  3139. $upload_name = "Filedata";
  3140. $file_name = "";
  3141. $nk = time ();
  3142. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3143. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3144. echo "文件无法保存.";
  3145. exit ( 0 );
  3146. }
  3147. echo json_encode ( array (
  3148. 'filename' => $file_name,
  3149. 'id' => $nk
  3150. ) );
  3151. exit ( 0 );
  3152. }
  3153. /**
  3154. * 解析银行到账收款execl并导入库中
  3155. */
  3156. function invoiceReceivablesImport() {
  3157. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3158. if ($path != "") {
  3159. Doo::loadModel ( 'invoiceReceivables' );
  3160. $invoiceReceivables = new invoiceReceivables ();
  3161. Doo::loadClass ( 'invoice.func' );
  3162. Doo::loadModel ( 'invoiceROLog' );
  3163. $invoiceROLog = new invoiceROLog ();
  3164. Doo::loadModel ( 'invoiceStatistics' );
  3165. $invoiceStatistics = new invoiceStatistics ();
  3166. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3167. $bankBatchNumber = 'BBN_' . time ();
  3168. Doo::db ()->beginTransaction ();
  3169. // 批量存储收款--由于必须获得收款ID,
  3170. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3171. VALUES ';
  3172. $date = date ( "Y-m-d" );
  3173. $receivablesList = array ();
  3174. foreach ( $exlArray as $key => $value ) {
  3175. $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"] . '")';
  3176. array_push ( $receivablesList, $receivablesSql );
  3177. }
  3178. $sql = $sql . implode ( ',', $receivablesList );
  3179. // echo $sql;
  3180. Doo::db ()->query ( $sql );
  3181. // 批量存储收款统计
  3182. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3183. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3184. // 没有irid 回滚所有操作
  3185. if (empty ( $iridList )) {
  3186. Doo::db ()->rollBack ();
  3187. header ( 'Content-Type:text/html;charset=utf-8' );
  3188. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3189. }
  3190. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3191. VALUES ';
  3192. $statisticsList = array ();
  3193. foreach ( $iridList as $value ) {
  3194. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3195. array_push ( $statisticsList, $statisticsSql );
  3196. }
  3197. $sql = $sql . implode ( ',', $statisticsList );
  3198. Doo::db ()->query ( $sql );
  3199. // 批量存储操作日志
  3200. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3201. VALUES ';
  3202. $ROLogList = array ();
  3203. foreach ( $iridList as $value ) {
  3204. $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'] . '")';
  3205. array_push ( $ROLogList, $ROLogSql );
  3206. }
  3207. $sql = $sql . implode ( ',', $ROLogList );
  3208. Doo::db ()->query ( $sql );
  3209. // 批量写入流水
  3210. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3211. VALUES ';
  3212. $wasteBookList = array ();
  3213. foreach ( $iridList as $value ) {
  3214. $accountBank = '';
  3215. if ($value ['receivablesBank'] == '纵横广发') {
  3216. $accountBank = 'CGBDeposit';
  3217. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3218. $accountBank = 'ICBCDeposit';
  3219. } elseif ($value ['receivablesBank'] == '华润银行') {
  3220. $accountBank = 'HUADeposit';
  3221. } elseif ($value ['receivablesBank'] == '个人广发') {
  3222. $accountBank = 'PersonalDeposit';
  3223. }
  3224. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3225. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3226. array_push ( $wasteBookList, $wasteBookSql );
  3227. }
  3228. $sql = $sql . implode ( ',', $wasteBookList );
  3229. Doo::db ()->query ( $sql );
  3230. Doo::db ()->commit ();
  3231. return "/invoiceReceivables";
  3232. }
  3233. echo 'no file';
  3234. }
  3235. function invoiceReceivables() {
  3236. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3237. Doo::loadModel ( 'L_category' );
  3238. $lCategory = new L_category ();
  3239. Doo::loadModel ( 'staff' );
  3240. $staff = new staff ();
  3241. Doo::loadModel ( 'invoiceReceivables' );
  3242. $invoiceReceivables = new invoiceReceivables ();
  3243. Doo::loadModel ( 'invoice' );
  3244. $invoice = new invoice ();
  3245. Doo::loadClass ( 'XDeode' );
  3246. $XDeode = new XDeode ( 5 );
  3247. $category = $lCategory->getCategory ();
  3248. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3249. $sql = 'bindStatus=1 and iid!=0';
  3250. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3251. // 获取未入账发票
  3252. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3253. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3254. foreach ( $invoiceUnAccount as $key => $value ) {
  3255. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3256. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3257. if (! empty ( $lastApprover )) {
  3258. $lastApproverKey = array_keys ( $lastApprover );
  3259. $lastApprover = end ( $lastApprover );
  3260. $staffDetail = $staff->getOne ( array (
  3261. 'where' => 'sid=' . end ( $lastApproverKey ),
  3262. 'asArray' => true
  3263. ) );
  3264. $lastApprover ['username'] = $staffDetail ['username'];
  3265. }
  3266. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3267. }
  3268. foreach ( $invoiceExistAccount as $key => $value ) {
  3269. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3270. // if (empty ( $irList ))
  3271. // $irList [0] ['sumPrice'] = 0;
  3272. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3273. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3274. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3275. }
  3276. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3277. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3278. $this->data ['halfList'] = $halfList;
  3279. $this->data ['halfCount'] = count ( $halfList );
  3280. // print_r($receivablesList);
  3281. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3282. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3283. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3284. $this->data ['receivablesInput'] = $receivablesInput;
  3285. $this->data ['year'] = date ( 'Y' );
  3286. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3287. $this->data ['receivablesList'] = $receivablesList;
  3288. $this->data ['staffList'] = $staffList;
  3289. $this->data ['category'] = $category;
  3290. $this->data ['memu'] = "invoice";
  3291. $this->data ['staff'] = $this->staff;
  3292. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3293. $this->render ( "/admin/invoiceReceivables", $this->data );
  3294. }
  3295. /**
  3296. * 设置收款认领地区
  3297. */
  3298. function setInvoiceReceivablesClaim() {
  3299. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3300. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3301. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3302. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3303. Doo::loadModel ( 'invoiceReceivables' );
  3304. $invoiceReceivables = new invoiceReceivables ();
  3305. Doo::loadClass ( 'XDeode' );
  3306. $XDeode = new XDeode ( 5 );
  3307. Doo::loadModel ( 'invoiceROLog' );
  3308. $invoiceROLog = new invoiceROLog ();
  3309. $irid = $XDeode->decode ( $iridKey );
  3310. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3311. if (empty ( $irDetail ))
  3312. die ( 'illegal request' );
  3313. $item = array (
  3314. 'irid' => $irid,
  3315. 'receivablesCategory' => $receivablesCategory
  3316. );
  3317. if ($receivablesCategory != 'PUBLIC') {
  3318. $item += array (
  3319. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3320. 'inputType' => 1
  3321. );
  3322. }
  3323. $invoiceReceivables = new invoiceReceivables ();
  3324. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3325. // 收款操作日志
  3326. $item = array (
  3327. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3328. 'date' => date ( "Y-m-d" ),
  3329. 'status' => 1,
  3330. 'img' => $this->staff [0] ['avatar'],
  3331. 'username' => $this->staff [0] ['username'],
  3332. 'uid' => $this->staff [0] ['sid'],
  3333. 'category' => $this->staff [0] ['category'],
  3334. 'irid' => $irid
  3335. );
  3336. $invoiceROLog->setInvoiceROLog ( $item );
  3337. if (empty ( $action ))
  3338. return '/invoiceReceivables';
  3339. else
  3340. return "/invoiceReceivablesAS";
  3341. }
  3342. die ( 'illegal request' );
  3343. }
  3344. /**
  3345. * 新添加收款直接入账发票
  3346. */
  3347. function invoiceCompareClaimPrice() {
  3348. // 收款录入
  3349. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3350. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3351. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3352. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3353. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3354. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3355. Doo::loadModel ( 'invoiceReceivables' );
  3356. $invoiceReceivables = new invoiceReceivables ();
  3357. Doo::loadModel ( 'invoiceROLog' );
  3358. $invoiceROLog = new invoiceROLog ();
  3359. Doo::loadModel ( 'invoiceStatistics' );
  3360. Doo::loadModel ( 'invoice' );
  3361. $invoice = new invoice ();
  3362. Doo::loadModel ( 'bill' );
  3363. $bill = new bill ();
  3364. Doo::loadClass ( 'XDeode' );
  3365. $XDeode = new XDeode ( 5 );
  3366. Doo::loadModel ( 'invoiceOperationLog' );
  3367. $invoiceOperationLog = new invoiceOperationLog ();
  3368. $iidKey = $XDeode->decode ( $iidKey );
  3369. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3370. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3371. die ( 'illegal request' );
  3372. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3373. // 收款录入 并绑定发票
  3374. Doo::db ()->beginTransaction ();
  3375. //获得发票入账余额
  3376. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3377. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3378. $bindStatus = 0;
  3379. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3380. if($invoiceDetail ['invoiceBalance']!=0){
  3381. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3382. }
  3383. if ($receivablesPrice <= $invoiceBalance){
  3384. $bindStatus = 1;
  3385. //$bindPrice=$receivablesPrice;
  3386. }
  3387. $titleMark = $invoiceDetail ['invoiceTitle'];
  3388. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3389. $titleMark = $invoiceDetail ['invoiceCompany'];
  3390. $item = array (
  3391. 'recepitTitleMark' => $titleMark,
  3392. 'bindStatus' => $bindStatus,
  3393. 'iid' => $invoiceDetail ['iid'],
  3394. 'bindPrice' => $receivablesPrice,
  3395. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3396. 'receivablesPrice' => $receivablesPrice,
  3397. 'OriginalPrice' => $receivablesPrice,
  3398. 'receivablesMessage' => $receivablesMessage,
  3399. 'receivablesSerial' => $receivablesSerial,
  3400. 'receivablesBank' => $receivablesBank,
  3401. 'receivablesDate' => $receivablesDate,
  3402. 'inputStaff' => $this->staff [0] ['username'],
  3403. 'accountClerk' => $this->staff [0] ['username'],
  3404. 'date' => date ( "Y-m-d" ),
  3405. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3406. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3407. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3408. );
  3409. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3410. $item = array ();
  3411. // 收款操作日志
  3412. $item = array (
  3413. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3414. );
  3415. $item += array (
  3416. 'date' => date ( "Y-m-d" ),
  3417. 'status' => 1,
  3418. 'img' => $this->staff [0] ['avatar'],
  3419. 'username' => $this->staff [0] ['username'],
  3420. 'uid' => $this->staff [0] ['sid'],
  3421. 'category' => $this->staff [0] ['category'],
  3422. 'irid' => $irid
  3423. );
  3424. $invoiceROLog->setInvoiceROLog ( $item );
  3425. // 收款统计
  3426. $invoiceStatistics = new invoiceStatistics ();
  3427. $item = array (
  3428. 'date' => $receivablesDate,
  3429. 'priceClass' => 2,
  3430. 'irid' => $irid,
  3431. 'cid' => $invoiceDetail ['cid'],
  3432. 'staff' => $invoiceDetail ['sid'],
  3433. 'receivablesPrice' => $receivablesPrice
  3434. );
  3435. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3436. // 收款 入 发票
  3437. $detail = $invoiceDetail;
  3438. $iridString = "";
  3439. if (empty ( $detail ['irid'] ))
  3440. $iridString = $irid;
  3441. else
  3442. $iridString = $detail ['irid'] . ',' . $irid;
  3443. $item = array (
  3444. 'irid' => $iridString,
  3445. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3446. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3447. 'iid' => $detail ['iid']
  3448. );
  3449. // $invoiceReceivables = new invoiceReceivables ();
  3450. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3451. // $sumBind = $bindInvicePrice;
  3452. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3453. // $sum=$sumBind+$sumBalance;
  3454. // ;
  3455. if ($receivablesPrice>=$invoiceBalance){
  3456. $item += array (
  3457. 'invoiceBalance'=>0,
  3458. 'untreadStatus' => 3
  3459. );
  3460. }else{
  3461. $item += array (
  3462. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3463. );
  3464. }
  3465. $invoice->setInvoiceByCondition ( $item );
  3466. // 操作日志
  3467. $item = array (
  3468. 'date' => date ( "Y-m-d H:i:s" ),
  3469. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3470. 'status' => 8,
  3471. 'img' => $this->staff [0] ['avatar'],
  3472. 'username' => $this->staff [0] ['username'],
  3473. 'uid' => $this->staff [0] ['sid'],
  3474. 'category' => $this->staff [0] ['category'],
  3475. 'iid' => $detail ['iid']
  3476. );
  3477. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3478. // 入账汇总
  3479. $invoiceStatistics = new invoiceStatistics ();
  3480. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3481. // $accountPrice = 0;
  3482. // foreach ( $list as $key => $value ) {
  3483. // $accountPrice += $value ['receivablesPrice'];
  3484. // }
  3485. $item = array (
  3486. 'date' => $receivablesDate,
  3487. 'priceClass' => 3,
  3488. 'cid' => $invoiceDetail ['cid'],
  3489. 'staff' => $invoiceDetail ['sid'],
  3490. 'accountPrice' => $receivablesPrice
  3491. );
  3492. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3493. //发票入账记录
  3494. $bill->iid=$invoiceDetail['iid'];
  3495. $bill->trainId=$invoiceDetail['trainId'];
  3496. $bill->irid=$irid;
  3497. $bill->create_time=date ( "Y-m-d H:i:s" );
  3498. $bill->price=$invoiceBalance;
  3499. $bill->insert ();
  3500. // 公司流水记录
  3501. Doo::loadModel ( 'wasteBook' );
  3502. $wasteBook = new wasteBook ();
  3503. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3504. $accountBank=$wasteBook->_getAccountBankEN($receivablesBank);
  3505. if (empty ( $abDetail )) {
  3506. $item = array (
  3507. 'dataID' => $irid,
  3508. 'expensesType' => 1,
  3509. 'accountType' => 7,
  3510. 'accountPrice' => $receivablesPrice,
  3511. 'accountPriceShow' => $receivablesPrice,
  3512. 'accountBank' => $accountBank,
  3513. 'cid'=>$invoiceDetail['cid'],
  3514. 'category' => $invoiceDetail ['categoryName'],
  3515. 'name' => $this->staff [0] ['username'],
  3516. 'sid' => $this->staff [0] ['sid'],
  3517. 'inputDate' => $receivablesDate//date ( "Y-m-d H:i:s" )
  3518. );
  3519. $wasteBook->setAccountBookStatistics ( $item );
  3520. }
  3521. Doo::db ()->commit ();
  3522. }
  3523. return '/invoiceReceivables';
  3524. }
  3525. /**
  3526. * 录入收款数据
  3527. * @return string
  3528. */
  3529. function invoiceReceivablesDo() {
  3530. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3531. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3532. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3533. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3534. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3535. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3536. Doo::loadModel ( 'invoiceReceivables' );
  3537. $invoiceReceivables = new invoiceReceivables ();
  3538. Doo::loadModel ( 'invoiceROLog' );
  3539. $invoiceROLog = new invoiceROLog ();
  3540. Doo::loadModel ( 'invoiceStatistics' );
  3541. $invoiceStatistics = new invoiceStatistics ();
  3542. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3543. $item = array (
  3544. 'receivablesPrice' => $receivablesPrice,
  3545. 'OriginalPrice' => $receivablesPrice,
  3546. 'receivablesMessage' => $receivablesMessage,
  3547. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3548. 'receivablesBank' => $receivablesBank,
  3549. 'receivablesDate' => $receivablesDate,
  3550. 'inputStaff' => $this->staff [0] ['username'],
  3551. 'date' => date ( "Y-m-d" ),
  3552. 'receivablesCategory' => $receivablesCategory,
  3553. 'receivablesStaff' => $receivablesStaff
  3554. );
  3555. if ($receivablesCategory != 'PUBLIC') {
  3556. $item += array (
  3557. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3558. 'inputType' => 1
  3559. );
  3560. }
  3561. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3562. $item = array ();
  3563. // 收款操作日志
  3564. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3565. $item = array (
  3566. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3567. );
  3568. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3569. $item = array (
  3570. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3571. );
  3572. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3573. $receivablesStaff = explode ( '-', $receivablesStaff );
  3574. $item = array (
  3575. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3576. );
  3577. }
  3578. $item += array (
  3579. 'date' => date ( "Y-m-d" ),
  3580. 'status' => 1,
  3581. 'img' => $this->staff [0] ['avatar'],
  3582. 'username' => $this->staff [0] ['username'],
  3583. 'uid' => $this->staff [0] ['sid'],
  3584. 'category' => $this->staff [0] ['category'],
  3585. 'irid' => $irid
  3586. );
  3587. $invoiceROLog->setInvoiceROLog ( $item );
  3588. $item = array (
  3589. 'date' => $receivablesDate,
  3590. 'priceClass' => 2,
  3591. 'irid' => $irid,
  3592. 'receivablesPrice' => $receivablesPrice
  3593. );
  3594. if ($receivablesCategory != 'PUBLIC') {
  3595. $receivablesCategory = explode ( ":", $receivablesCategory );
  3596. $item += array (
  3597. 'cid' => $receivablesCategory [0]
  3598. );
  3599. }
  3600. if ($receivablesStaff2 != 'PUBLIC') {
  3601. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3602. $item += array (
  3603. 'staff' => $receivablesStaff [0]
  3604. );
  3605. }
  3606. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3607. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3608. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3609. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3610. if ($toparty != 0)
  3611. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3612. // 公司流水记录
  3613. Doo::loadModel ( 'wasteBook' );
  3614. $wasteBook = new wasteBook ();
  3615. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3616. $accountBank=$wasteBook->_getAccountBankEN($receivablesBank);
  3617. $item = array (
  3618. 'dataID' => $irid,
  3619. 'expensesType' => 1,
  3620. 'accountType' => 7,
  3621. 'accountPriceShow' => $receivablesPrice,
  3622. 'accountPrice' => $receivablesPrice,
  3623. 'accountBank' => $accountBank,
  3624. 'category' => $this->staff [0] ['category'],
  3625. 'cid' => $this->staff [0] ['cid'],
  3626. 'name' => $this->staff [0] ['username'],
  3627. 'sid' => $this->staff [0] ['sid'],
  3628. 'inputDate' => $receivablesDate ,
  3629. //'createAt'=>date ( "Y-m-d H:i:s" ) ,
  3630. 'synPaymentDate'=>1
  3631. );
  3632. $wasteBook->setAccountBookStatistics ( $item );
  3633. }
  3634. return "/invoiceReceivables";
  3635. }
  3636. /**
  3637. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3638. */
  3639. function invoiceReceivablesClaim() {
  3640. Doo::loadModel ( 'invoiceReceivables' );
  3641. $invoiceReceivables = new invoiceReceivables ();
  3642. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3643. $this->data ['receivablesList'] = $receivablesList;
  3644. $this->data ['memu'] = "invoice";
  3645. $this->data ['staff'] = $this->staff;
  3646. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3647. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3648. }
  3649. function invoiceReceivablesTitleMarkSet() {
  3650. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3651. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3652. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3653. die ( 'illegal request' );
  3654. Doo::loadModel ( 'invoiceReceivables' );
  3655. $invoiceReceivables = new invoiceReceivables ();
  3656. Doo::loadClass ( 'XDeode' );
  3657. $XDeode = new XDeode ( 5 );
  3658. $irid = $XDeode->decode ( $iridKey );
  3659. if (! is_numeric ( $irid ))
  3660. die ( 'illegal request' );
  3661. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3662. $invoiceReceivables->update ( array (
  3663. 'where' => 'irid = ' . $irid
  3664. ) );
  3665. return '/invoiceReceivablesClaim';
  3666. }
  3667. /**
  3668. * 更新收款相关数据
  3669. */
  3670. function invoiceReceivablesUpdateClaim() {
  3671. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3672. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3673. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3674. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3675. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3676. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3677. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3678. if (empty ( $claimKey ))
  3679. die ( 'illegal request' );
  3680. Doo::loadModel ( 'invoiceReceivables' );
  3681. $invoiceReceivables = new invoiceReceivables ();
  3682. Doo::loadModel ( 'invoiceROLog' );
  3683. $invoiceROLog = new invoiceROLog ();
  3684. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3685. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3686. if (empty ( $detail ))
  3687. die ( 'illegal request' );
  3688. $invoiceReceivables = new invoiceReceivables ();
  3689. $item = array (
  3690. 'irid' => $detail ['irid']
  3691. );
  3692. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3693. $item += array (
  3694. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3695. );
  3696. }
  3697. if (! empty ( $receivablesCategory ))
  3698. $item += array (
  3699. 'receivablesCategory' => $receivablesCategory
  3700. );
  3701. if (! empty ( $receivablesStaff ))
  3702. $item += array (
  3703. 'receivablesStaff' => $receivablesStaff
  3704. );
  3705. if (! empty ( $receivablesPrice ))
  3706. $item += array (
  3707. 'receivablesPrice' => $receivablesPrice
  3708. );
  3709. if (! empty ( $receivablesMessage ))
  3710. $item += array (
  3711. 'receivablesMessage' => $receivablesMessage
  3712. );
  3713. if (! empty ( $receivablesBank ))
  3714. $item += array (
  3715. 'receivablesBank' => $receivablesBank
  3716. );
  3717. if (! empty ( $receivablesDate ))
  3718. $item += array (
  3719. 'receivablesDate' => $receivablesDate
  3720. );
  3721. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3722. // 收款操作日志
  3723. $item = array ();
  3724. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3725. $item = array (
  3726. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3727. );
  3728. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3729. $item = array (
  3730. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3731. );
  3732. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3733. $receivablesStaff = explode ( '-', $receivablesStaff );
  3734. $item = array (
  3735. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3736. );
  3737. }
  3738. $item += array (
  3739. 'date' => date ( "Y-m-d" ),
  3740. 'status' => 1,
  3741. 'img' => $this->staff [0] ['avatar'],
  3742. 'username' => $this->staff [0] ['username'],
  3743. 'uid' => $this->staff [0] ['sid'],
  3744. 'category' => $this->staff [0] ['category'],
  3745. 'irid' => $detail ['irid']
  3746. );
  3747. $invoiceROLog->setInvoiceROLog ( $item );
  3748. return '/invoiceReceivablesAS';
  3749. }
  3750. function invoiceReceivablesDelete() {
  3751. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3752. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3753. if ($skll != '删除到款')
  3754. die ( 'illegal request-未填写 删除到款' );
  3755. if (empty ( $claimKey ))
  3756. die ( 'illegal request-收款key不正确' );
  3757. Doo::loadModel ( 'invoiceReceivables' );
  3758. $invoiceReceivables = new invoiceReceivables ();
  3759. $con = ' and bindStatus=0 ';
  3760. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3761. if (empty ( $detail ))
  3762. die ( 'illegal request-未找到该收款或者未解绑' );
  3763. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3764. // 扣除收款汇总信息 汇总
  3765. Doo::loadModel ( 'invoiceStatistics' );
  3766. $invoiceStatistics = new invoiceStatistics ();
  3767. $item = array (
  3768. 'date' => $detail ['receivablesDate'],
  3769. 'priceClass' => 2,
  3770. 'irid' => $detail ['irid'],
  3771. 'receivablesPrice' => - $detail ['receivablesPrice']
  3772. );
  3773. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3774. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3775. $item += array (
  3776. 'cid' => $receivablesCategory [0]
  3777. );
  3778. }
  3779. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3780. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3781. $item += array (
  3782. 'staff' => $receivablesStaff [0]
  3783. );
  3784. }
  3785. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3786. // 公司流水-删除时删除流水
  3787. Doo::loadModel ( 'wasteBook' );
  3788. $wasteBook = new wasteBook ();
  3789. $wasteBook->delete ( array (
  3790. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3791. 'limit' => 1
  3792. ) );
  3793. return '/invoiceReceivablesAS';
  3794. }
  3795. /**
  3796. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3797. */
  3798. function invoiceReceivablesAscription() {
  3799. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3800. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3801. Doo::loadModel ( 'invoiceReceivables' );
  3802. $invoiceReceivables = new invoiceReceivables ();
  3803. Doo::loadModel ( 'invoiceROLog' );
  3804. $invoiceROLog = new invoiceROLog ();
  3805. Doo::loadModel ( 'invoiceStatistics' );
  3806. $invoiceStatistics = new invoiceStatistics ();
  3807. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3808. $irid = $invoiceReceivables->authcode ( $irid );
  3809. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3810. $item = array (
  3811. 'irid' => $detail ['irid'],
  3812. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3813. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3814. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3815. 'recepitTitleMark' => $recepitTitleMark,
  3816. 'source' => 1
  3817. );
  3818. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3819. $item = array (
  3820. 'date' => date ( "Y-m-d" ),
  3821. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3822. 'status' => 2,
  3823. 'img' => $this->staff [0] ['avatar'],
  3824. 'username' => $this->staff [0] ['username'],
  3825. 'uid' => $this->staff [0] ['sid'],
  3826. 'category' => $this->staff [0] ['category'],
  3827. 'irid' => $irid
  3828. );
  3829. $invoiceROLog->setInvoiceROLog ( $item );
  3830. $item = array (
  3831. 'cid' => $this->staff [0] ['cid'],
  3832. 'staff' => $this->staff [0] ['sid']
  3833. );
  3834. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3835. //更新流水的办事处
  3836. Doo::loadModel ( 'wasteBook' );
  3837. $wasteBook = new wasteBook ();
  3838. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $detail ['irid'] );
  3839. $wasteBook->wid = $abDetail ['wid'];
  3840. $wasteBook->category = $this->staff [0] ['category'];
  3841. $wasteBook->cid = $this->staff [0] ['cid'];
  3842. $wasteBook->update ();
  3843. }
  3844. return "/invoiceReceivablesClaim";
  3845. }
  3846. /**
  3847. */
  3848. function invoiceMyReceivables() {
  3849. Doo::loadModel ( 'invoiceReceivables' );
  3850. $invoiceReceivables = new invoiceReceivables ();
  3851. Doo::loadModel ( 'invoiceStatistics' );
  3852. $invoiceStatistics = new invoiceStatistics ();
  3853. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3854. $year = date ( "Y" );
  3855. $tmp_date = date ( "Ym" );
  3856. $tmp_year = substr ( $tmp_date, 0, 4 );
  3857. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3858. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3859. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3860. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3861. $htm = $this->showCache ( $path );
  3862. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3863. $this->data ['isMonth'] = $isMonth;
  3864. $this->data ['htm'] = $htm;
  3865. $this->data ['list'] = $list;
  3866. $this->data ['memu'] = "invoice";
  3867. $this->data ['staff'] = $this->staff;
  3868. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3869. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3870. }
  3871. /**
  3872. * 纸票管理
  3873. */
  3874. function invoicePaper() {
  3875. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3876. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3877. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3878. $this->data ['dateString'] = $date;
  3879. $this->data ['status'] = $status;
  3880. $this->data ['invoiceType'] = $invoiceType;
  3881. $this->data ['memu'] = "invoice";
  3882. $this->data ['staff'] = $this->staff;
  3883. $this->data ['receiptMemu'] = 'invoicePaper';
  3884. $this->render ( "/admin/invoicePaper", $this->data );
  3885. }
  3886. /**
  3887. * 电子发票管理
  3888. */
  3889. function invoiceElectronic() {
  3890. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3891. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3892. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3893. $this->data ['dateString'] = $date;
  3894. $this->data ['status'] = $status;
  3895. $this->data ['invoiceType'] = $invoiceType;
  3896. $this->data ['memu'] = "invoice";
  3897. $this->data ['staff'] = $this->staff;
  3898. $this->data ['receiptMemu'] = 'invoicePaper';
  3899. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3900. }
  3901. /**
  3902. * 获得纸票分页数据
  3903. */
  3904. function ajaxGetinvoicePaperAchieve() {
  3905. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3906. Doo::loadModel ( 'invoicePaper' );
  3907. $invoicePaper = new invoicePaper ();
  3908. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3909. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3910. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3911. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3912. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3913. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3914. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3915. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3916. $MebSea = $this->get_args ( 'search' );
  3917. $MebSea = $MebSea ['value'];
  3918. $page_size = $length;
  3919. $con = '';
  3920. if ($status == 'ALL')
  3921. $con = ' where 1 ';
  3922. elseif ($status == 'PRINTED')
  3923. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3924. elseif ($status == 'UNPRINT')
  3925. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3926. elseif ($status == 'TICKET')
  3927. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3928. if ($invoiceType == 'ORDINARY')
  3929. $con .= ' and a.invoiceType=0 ';
  3930. elseif ($invoiceType == 'SPECIAL')
  3931. $con .= ' and a.invoiceType=1 ';
  3932. if($invoiceForm==0){
  3933. $con .= ' and a.invoiceForm=0 ';
  3934. }else{
  3935. $con .= ' and a.invoiceForm=1 ';
  3936. }
  3937. $dateArr = explode ( ':', $date );
  3938. $D1 = $dateString = '';
  3939. $D2 = '';
  3940. if (! empty ( $date )) {
  3941. $D1 = $dateArr [0];
  3942. if (isset ( $dateArr [1] ))
  3943. $D2 = $dateArr [1];
  3944. else
  3945. $D2 = '';
  3946. $dateString = $D1 . " : " . $D2;
  3947. }
  3948. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3949. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3950. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3951. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3952. if (! empty ( $MebSea ))
  3953. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3954. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3955. $sql = ' ' . $con;
  3956. $limit = $page . ',' . $page_size;
  3957. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3958. $paperList = array ();
  3959. foreach ( $list as $key => $value ) {
  3960. $irDetail = array ();
  3961. if ($value ['iid'] == 0)
  3962. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3963. else
  3964. array_push ( $irDetail, '' );
  3965. array_push ( $irDetail, $value ['invoiceCode'] );
  3966. array_push ( $irDetail, $value ['invoiceNo'] );
  3967. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3968. if ($value ['invoiceType'] == 1)
  3969. array_push ( $irDetail, $value ['invoiceCompany'] );
  3970. else
  3971. array_push ( $irDetail, $value ['invoiceTitle'] );
  3972. if ($value ['invoiceType'] == 1)
  3973. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3974. else
  3975. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3976. array_push ( $irDetail, $value ['invoiceElement'] );
  3977. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3978. array_push ( $irDetail, $value ['printTime'] );
  3979. array_push ( $paperList, $irDetail );
  3980. }
  3981. // $approvalListJson = json_encode ( $approvalList );
  3982. $recordsFiltered = $invoiceTotal;
  3983. echo json_encode ( array (
  3984. "draw" => intval ( $draw ),
  3985. "recordsTotal" => intval ( $invoiceTotal ),
  3986. "recordsFiltered" => intval ( $recordsFiltered ),
  3987. "data" => $paperList
  3988. ), JSON_UNESCAPED_UNICODE );
  3989. }
  3990. function invoicePaperDel() {
  3991. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3992. $XDeode = new XDeode ( 5 );
  3993. $ipid = $XDeode->decode ( $ipidKey );
  3994. if (empty ( $ipid ))
  3995. die ( 'illegal request' );
  3996. Doo::loadModel ( 'invoicePaper' );
  3997. $invoicePaper = new invoicePaper ();
  3998. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3999. $invoicePaper->delete ( array (
  4000. 'where' => 'ipid=' . $ipid . ' and iid=0',
  4001. 'limit' => 1
  4002. ) );
  4003. if($ipdetail['invoiceForm']==1){
  4004. return '/invoiceElectronic';
  4005. }else{
  4006. return '/invoicePaper';
  4007. }
  4008. }
  4009. /**
  4010. * 添加纸质发票号
  4011. */
  4012. function invoicePaperAdd() {
  4013. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  4014. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  4015. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  4016. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  4017. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  4018. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  4019. $sum = $invoiceNoStart + $invoiceNoTotal;
  4020. if (empty ( $sum ))
  4021. die ( 'illegal request' );
  4022. // echo $invoiceNoStart;
  4023. // echo $sum;
  4024. // echo strlen((int)$invoiceNoStart);
  4025. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  4026. if($invoiceType==0||$invoiceType==1){
  4027. }else{
  4028. die ( 'illegal request invoiceType' );
  4029. }
  4030. if($invoiceForm==1){
  4031. $invoiceType=0;
  4032. }
  4033. Doo::db ()->beginTransaction ();
  4034. // 批量存储纸质发票
  4035. $date = date ( "Y-m-d H:i:s" );
  4036. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  4037. VALUES ';
  4038. $paperList = array ();
  4039. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  4040. // 数字前面自加0
  4041. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  4042. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  4043. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  4044. array_push ( $paperList, $paperSql );
  4045. }
  4046. if (empty ( $paperList ))
  4047. die ( 'illegal request' );
  4048. $sql = $sql . implode ( ',', $paperList );
  4049. Doo::db ()->query ( $sql );
  4050. Doo::db ()->commit ();
  4051. if($invoiceForm==1){
  4052. return 'invoiceElectronic';
  4053. }else{
  4054. return 'invoicePaper';
  4055. }
  4056. }
  4057. die ( 'illegal request' );
  4058. }
  4059. /**
  4060. * 收款绑定发票 ,//一个收款只能绑定一个发票
  4061. */
  4062. function invoiceBindReceivables() {
  4063. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4064. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4065. Doo::loadModel ( 'invoice' );
  4066. $invoice = new invoice ();
  4067. Doo::loadModel ( 'invoiceReceivables' );
  4068. $invoiceReceivables = new invoiceReceivables ();
  4069. Doo::loadModel ( 'invoiceOperationLog' );
  4070. $invoiceOperationLog = new invoiceOperationLog ();
  4071. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4072. die ( 'illegal request' );
  4073. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4074. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4075. if (empty ( $detail ) && empty ( $detailM ))
  4076. die ( 'illegal request' );
  4077. if ($detail ['untreadStatus'] == 3)
  4078. die ( 'illegal request' );
  4079. // 修改 绑定状态改为 金额
  4080. $invoiceReceivables = new invoiceReceivables ();
  4081. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4082. $billPrice=0;
  4083. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4084. $item = array (
  4085. 'bindPrice' => $invoicePrice
  4086. );
  4087. $billPrice=$invoicePrice;
  4088. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) { //发票金额大于收款金额,绑定金额为收款金额
  4089. $item = array (
  4090. 'bindPrice' => $detailM ['receivablesPrice'],
  4091. 'bindStatus' => 1,
  4092. 'bindDate' => date ( "Y-m-d H:i:s" )
  4093. );
  4094. $billPrice=$detailM ['receivablesPrice'];
  4095. } else {
  4096. die ( 'illegal request' );
  4097. }
  4098. if ($detailM ['iid'] == 0) {
  4099. $item += array (
  4100. 'iid' => $detail ['iid']
  4101. );
  4102. } else {
  4103. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4104. array_push ( $iidExtend, $detail ['iid'] );
  4105. $item += array (
  4106. 'iidExtend' => implode ( ',', $iidExtend )
  4107. );
  4108. }
  4109. $titleMark = $detail ['invoiceTitle'];
  4110. if (! empty ( $detail ['invoiceCompany'] ))
  4111. $titleMark = $detail ['invoiceCompany'];
  4112. $item += array (
  4113. 'irid' => $detailM ['irid'],
  4114. 'recepitTitleMark' => $titleMark,
  4115. 'accountClerk' => $this->staff [0] ['username']
  4116. );
  4117. // 如何没有人收款 则自动绑定收款
  4118. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4119. $item += array (
  4120. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4121. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4122. );
  4123. }
  4124. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4125. $iridString = "";
  4126. if (empty ( $detail ['irid'] ))
  4127. $iridString = $detailM ['irid'];
  4128. else
  4129. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4130. // $invoiceReceivables = new invoiceReceivables ();
  4131. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4132. // //这个收款余额
  4133. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4134. // $sum=$sumBind+$sumBalance;
  4135. //这个收款余额
  4136. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4137. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4138. // die;
  4139. $invoice = new invoice ();
  4140. $item = array (
  4141. 'iid' => $detail ['iid'],
  4142. 'irid' => $iridString
  4143. );
  4144. if ($detail ['invoicePrice'] <= $sumBalance){
  4145. $item += array (
  4146. 'invoiceBalance'=>0,
  4147. 'untreadStatus' => 3,
  4148. 'bindTime' => date ( "Y-m-d H:i:s" )
  4149. );
  4150. }else{
  4151. $item += array (
  4152. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4153. );
  4154. }
  4155. // print_r($item);
  4156. // echo $sum;die;
  4157. $invoice->setInvoiceByCondition ( $item );
  4158. //发票入账记录
  4159. Doo::loadModel ( 'bill' );
  4160. $bill = new bill ();
  4161. $bill->iid=$detail ['iid'];
  4162. $bill->trainId=$detail['trainId'];
  4163. $bill->irid=$detailM ['irid'];
  4164. $bill->create_time=date ( "Y-m-d H:i:s" );
  4165. $bill->price=$billPrice;
  4166. $bill->insert ();
  4167. // 操作日志
  4168. $item = array (
  4169. 'date' => date ( "Y-m-d H:i:s" ),
  4170. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4171. 'status' => 8,
  4172. 'img' => $this->staff [0] ['avatar'],
  4173. 'username' => $this->staff [0] ['username'],
  4174. 'uid' => $this->staff [0] ['sid'],
  4175. 'category' => $this->staff [0] ['category'],
  4176. 'iid' => $detail ['iid']
  4177. );
  4178. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4179. Doo::loadModel ( 'invoiceStatistics' );
  4180. $invoiceStatistics = new invoiceStatistics ();
  4181. $item = array (
  4182. 'date' => $detailM ['receivablesDate'],
  4183. 'priceClass' => 3,
  4184. 'cid' => $detail ['cid'],
  4185. 'staff' => $detail ['sid'],
  4186. 'accountPrice' => $detailM ['receivablesPrice']
  4187. );
  4188. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4189. //TODO
  4190. // 公司流水记录
  4191. // Doo::loadModel ( 'wasteBook' );
  4192. // $wasteBook = new wasteBook ();
  4193. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4194. // $accountBank='';
  4195. // if ($detailM ['receivablesBank']=='纵横广发'){
  4196. // $accountBank='CGBDeposit';
  4197. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4198. // $accountBank='ICBCDeposit';
  4199. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4200. // $accountBank='HUADeposit';
  4201. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4202. // $accountBank='PersonalDeposit';
  4203. // }
  4204. // if (empty($abDetail)){
  4205. // $item = array (
  4206. // 'dataID' => $detail ['iid'],
  4207. // 'expensesType' => 1,
  4208. // 'accountType' => 8,
  4209. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4210. // 'accountPrice'=>$detail ['invoicePrice'],
  4211. // 'accountBank'=>$accountBank,
  4212. // 'category'=>$this->staff[0]['category'],
  4213. // 'cid'=>$this->staff[0]['cid'],
  4214. // 'name'=>$this->staff[0]['username'],
  4215. // 'sid'=>$this->staff[0]['sid'],
  4216. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4217. // );
  4218. // $wasteBook->setAccountBookStatistics($item);
  4219. // }
  4220. return "/invoiceReceivables";
  4221. }
  4222. /**
  4223. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4224. */
  4225. function invoiceAggregate() {
  4226. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4227. Doo::loadModel ( 'invoiceStatistics' );
  4228. $invoiceStatistics = new invoiceStatistics ();
  4229. Doo::loadModel ( 'L_category' );
  4230. $Lcategory = new L_category ();
  4231. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4232. $LcategoryList = $Lcategory->getCategory ();
  4233. // print_r($isList);
  4234. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4235. foreach ( $LcategoryList as $key => $value ) {
  4236. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4237. $month = 1;
  4238. $invoicePriceYear = 0;
  4239. $receivablesPriceYear = 0;
  4240. $accountPriceYear = 0;
  4241. for(; $month <= 12; $month ++) {
  4242. $flag = true;
  4243. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4244. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4245. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4246. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4247. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4248. ';
  4249. $invoicePriceYear += $v ['invoicePrice'];
  4250. $receivablesPriceYear += $v ['receivablesPrice'];
  4251. $accountPriceYear += $v ['accountPrice'];
  4252. $flag = false;
  4253. break;
  4254. }
  4255. }
  4256. if ($flag)
  4257. $html .= '<td class="taR"></td>
  4258. <td class="taR"></td>
  4259. <td class="taR"><b></b></td>
  4260. ';
  4261. }
  4262. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4263. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4264. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4265. ';
  4266. $html .= '</tr>';
  4267. }
  4268. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4269. $invoicePriceYear = 0;
  4270. $receivablesPriceYear = 0;
  4271. $accountPriceYear = 0;
  4272. for($month = 1; $month <= 12; $month ++) {
  4273. $flag = true;
  4274. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4275. if ($month == $v ['month']) {
  4276. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4277. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4278. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4279. ';
  4280. $invoicePriceYear += $v ['invoicePrice'];
  4281. $receivablesPriceYear += $v ['receivablesPrice'];
  4282. $accountPriceYear += $v ['accountPrice'];
  4283. $flag = false;
  4284. break;
  4285. }
  4286. }
  4287. if ($flag) {
  4288. $html .= '<td class="taR"></td>
  4289. <td class="taR"></td>
  4290. <td class="taR"><b></b></td>
  4291. ';
  4292. }
  4293. }
  4294. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4295. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4296. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4297. ';
  4298. $html .= '</tr>';
  4299. // print_r($isList);
  4300. $this->data ['html'] = $html;
  4301. $this->data ['LcategoryList'] = $LcategoryList;
  4302. $this->data ['isList'] = $isList;
  4303. $this->data ['year'] = $year;
  4304. $this->data ['memu'] = "invoice";
  4305. $this->data ['staff'] = $this->staff;
  4306. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4307. $this->render ( "/admin/invoiceAggregate", $this->data );
  4308. }
  4309. function invoiceAggregateStaff() {
  4310. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4311. Doo::loadModel ( 'invoiceStatistics' );
  4312. $invoiceStatistics = new invoiceStatistics ();
  4313. Doo::loadModel ( 'L_category' );
  4314. $Lcategory = new L_category ();
  4315. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4316. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4317. $cStaff = $Lcategory->getCategoryStaff ();
  4318. $html = '';
  4319. foreach ( $cStaff as $key => $value ) {
  4320. $categoryFir = true;
  4321. foreach ( $value ['staff'] as $k => $v ) {
  4322. if ($categoryFir) {
  4323. $width = count ( $value ['staff'] ) + 1;
  4324. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4325. $categoryFir = false;
  4326. } else
  4327. $html .= '<tr>';
  4328. $html .= '<th>' . $v ['username'] . '</th>';
  4329. $invoicePriceStaffYear = 0;
  4330. $receivablesPriceStaffYear = 0;
  4331. $accountPriceStaffYear = 0;
  4332. for($month = 1; $month <= 12; $month ++) {
  4333. $flag = true;
  4334. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4335. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4336. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4337. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4338. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4339. ';
  4340. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4341. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4342. $accountPriceStaffYear += $slv ['accountPrice'];
  4343. $flag = false;
  4344. break;
  4345. }
  4346. }
  4347. if ($flag)
  4348. $html .= '<td class="taR"></td>
  4349. <td class="taR"></td>
  4350. <td class="taR"><b></b></td>
  4351. ';
  4352. }
  4353. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4354. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4355. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4356. ';
  4357. }
  4358. $html .= '</tr>';
  4359. // 小计
  4360. if (! empty ( $value ['staff'] )) {
  4361. $html .= '<tr><th class="taR">小计</th>';
  4362. $invoicePriceStaffYear = 0;
  4363. $receivablesPriceStaffYear = 0;
  4364. $accountPriceStaffYear = 0;
  4365. for($month = 1; $month <= 12; $month ++) {
  4366. $flag = true;
  4367. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4368. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4369. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4370. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4371. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4372. ';
  4373. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4374. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4375. $accountPriceStaffYear += $slv ['accountPrice'];
  4376. $flag = false;
  4377. break;
  4378. }
  4379. }
  4380. if ($flag)
  4381. $html .= '<td class="taR"></td>
  4382. <td class="taR"></td>
  4383. <td class="taR"><b></b></td>
  4384. ';
  4385. }
  4386. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4387. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4388. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4389. ';
  4390. $html .= '</tr>';
  4391. }
  4392. }
  4393. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4394. $invoicePriceYear = 0;
  4395. $receivablesPriceYear = 0;
  4396. $accountPriceYear = 0;
  4397. for($month = 1; $month <= 12; $month ++) {
  4398. $flag = true;
  4399. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4400. if ($month == $v ['month']) {
  4401. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4402. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4403. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4404. ';
  4405. $invoicePriceYear += $v ['invoicePrice'];
  4406. $receivablesPriceYear += $v ['receivablesPrice'];
  4407. $accountPriceYear += $v ['accountPrice'];
  4408. $flag = false;
  4409. break;
  4410. }
  4411. }
  4412. if ($flag)
  4413. $html .= '<td class="taR"></td>
  4414. <td class="taR"></td>
  4415. <td class="taR"><b></b></td>
  4416. ';
  4417. }
  4418. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4419. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4420. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4421. ';
  4422. $html .= '</tr>';
  4423. $this->data ['html'] = $html;
  4424. $this->data ['isList'] = $toteList;
  4425. $this->data ['year'] = $year;
  4426. $this->data ['memu'] = "invoice";
  4427. $this->data ['staff'] = $this->staff;
  4428. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4429. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4430. }
  4431. function invoiceAggregateCategory() {
  4432. Doo::loadClass ( 'XDeode' );
  4433. $XDeode = new XDeode ( 5 );
  4434. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4435. $cid = $XDeode->decode ( $cid );
  4436. if (! is_numeric ( $cid ))
  4437. die ( 'illegal request' );
  4438. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4439. Doo::loadModel ( 'invoiceStatistics' );
  4440. $invoiceStatistics = new invoiceStatistics ();
  4441. Doo::loadModel ( 'staff' );
  4442. $staff = new staff ();
  4443. $list = $staff->getStaffByCid ( $cid );
  4444. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4445. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4446. if (empty ( $list ))
  4447. die ( '该办事处没有成员' );
  4448. $htmlA = $htmlB = $htmlC = $html = '';
  4449. foreach ( $list as $key => $value ) {
  4450. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4451. $htmlB = '<tr><th class="taC">收款</th>';
  4452. $htmlC = '<tr><th class="taC">入账</th>';
  4453. $invoicePriceStaffYear = 0;
  4454. $receivablesPriceStaffYear = 0;
  4455. $accountPriceStaffYear = 0;
  4456. for($month = 1; $month <= 12; $month ++) {
  4457. $flag = true;
  4458. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4459. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4460. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4461. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4462. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4463. $invoicePriceStaffYear += $v ['invoicePrice'];
  4464. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4465. $accountPriceStaffYear += $v ['accountPrice'];
  4466. $flag = false;
  4467. break;
  4468. }
  4469. }
  4470. if ($flag) {
  4471. $htmlA .= '<td class="taR">-</td>';
  4472. $htmlB .= '<td class="taR">-</td>';
  4473. $htmlC .= '<td class="taR"><b>-</b></td>';
  4474. }
  4475. }
  4476. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4477. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4478. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4479. $htmlA .= '</tr>';
  4480. $htmlB .= '</tr>';
  4481. $htmlC .= '</tr>';
  4482. $html .= $htmlA . $htmlB . $htmlC;
  4483. }
  4484. $htmlA = $htmlB = $htmlC = "";
  4485. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4486. $htmlB = '<tr><th class="taC">收款</th>';
  4487. $htmlC = '<tr><th class="taC">入账</th>';
  4488. $invoicePriceStaffYear = 0;
  4489. $receivablesPriceStaffYear = 0;
  4490. $accountPriceStaffYear = 0;
  4491. for($month = 1; $month <= 12; $month ++) {
  4492. $flag = true;
  4493. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4494. if ($month == $v ['month']) {
  4495. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4496. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4497. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4498. $invoicePriceStaffYear += $v ['invoicePrice'];
  4499. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4500. $accountPriceStaffYear += $v ['accountPrice'];
  4501. $flag = false;
  4502. break;
  4503. }
  4504. }
  4505. if ($flag) {
  4506. $htmlA .= '<td class="taR">-</td>';
  4507. $htmlB .= '<td class="taR">-</td>';
  4508. $htmlC .= '<td class="taR"><b>-</b></td>';
  4509. }
  4510. }
  4511. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4512. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4513. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4514. $htmlA .= '</tr>';
  4515. $htmlB .= '</tr>';
  4516. $htmlC .= '</tr>';
  4517. $html .= $htmlA . $htmlB . $htmlC;
  4518. $this->data ['html'] = $html;
  4519. $this->data ['cidKey'] = $cidKey;
  4520. $this->data ['slist'] = $list;
  4521. $this->data ['isList'] = $toteList;
  4522. $this->data ['year'] = $year;
  4523. $this->data ['memu'] = "invoice";
  4524. $this->data ['staff'] = $this->staff;
  4525. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4526. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4527. }
  4528. /**
  4529. * 办事处汇总信息
  4530. */
  4531. function invoiceAggregateCategoryDetail() {
  4532. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4533. Doo::loadClass ( 'XDeode' );
  4534. $XDeode = new XDeode ( 5 );
  4535. Doo::loadModel ( 'invoiceStatistics' );
  4536. $invoiceStatistics = new invoiceStatistics ();
  4537. Doo::loadModel ( 'L_category' );
  4538. $category = new L_category ();
  4539. Doo::loadModel ( 'invoice' );
  4540. $invoice = new invoice ();
  4541. Doo::loadModel ( 'staff' );
  4542. $staff = new staff ();
  4543. Doo::loadModel ( "invoiceCategoryManage" );
  4544. $invoiceCategoryManage = new invoiceCategoryManage ();
  4545. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4546. $cidList = array ();
  4547. foreach ( $imcStaff as $key => $value ) {
  4548. array_push ( $cidList, $value ['cid'] );
  4549. if (empty ( $cidKey ))
  4550. $cidKey = $XDeode->encode ( $value ['cid'] );
  4551. }
  4552. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4553. $cid = $XDeode->decode ( $cidKey );
  4554. $month = date ( "m", strtotime ( "-1 month" ) );
  4555. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4556. $redis = new Redis ();
  4557. $redis->connect ( '127.0.0.1', '6379' );
  4558. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4559. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4560. if (empty ( $redisValue )) {
  4561. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4562. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4563. // 获得办事处人员下的汇总
  4564. $slist = $staff->getStaffByCid ( $cid );
  4565. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4566. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4567. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4568. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4569. foreach ( $slist as $key => $value ) {
  4570. $slist [$key] ['invoicePrice'] = 0;
  4571. $slist [$key] ['receivablesPrice'] = 0;
  4572. $slist [$key] ['accountPrice'] = 0;
  4573. $slist [$key] ['invoiceAllPrice'] = 0;
  4574. $slist [$key] ['receivablesAllPrice'] = 0;
  4575. $slist [$key] ['accountAllPrice'] = 0;
  4576. $slist [$key] ['schedule'] = 0;
  4577. $slist [$key] ['invoiceMonthPrice'] = 0;
  4578. $slist [$key] ['receivablesMonthPrice'] = 0;
  4579. $slist [$key] ['accountMonthPrice'] = 0;
  4580. foreach ( $ismsbMonth as $y => $l ) {
  4581. if ($value ['sid'] == $l ['staff']) {
  4582. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4583. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4584. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4585. }
  4586. }
  4587. foreach ( $ismsb as $k => $v ) {
  4588. if ($value ['sid'] == $v ['staff']) {
  4589. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4590. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4591. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4592. }
  4593. }
  4594. foreach ( $ISAS as $e => $a ) {
  4595. if ($value ['sid'] == $a ['staff']) {
  4596. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4597. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4598. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4599. }
  4600. }
  4601. if (isset ( $scheduleStaff [$value ['sid']] ))
  4602. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4603. }
  4604. $this->data ['cidKey'] = $cidKey;
  4605. $schedule = ( int ) ($schedule * 100);
  4606. $this->data ['slist'] = $slist;
  4607. $this->data ['isMC'] = $isMC;
  4608. $this->data ['schedule'] = $schedule;
  4609. $slist = json_encode ( $slist );
  4610. $isMC = json_encode ( $isMC );
  4611. $schedule = json_encode ( $schedule );
  4612. $redis->lpush ( $redisKey, $slist );
  4613. $redis->lpush ( $redisKey, $isMC );
  4614. $redis->lpush ( $redisKey, $schedule );
  4615. } else {
  4616. $this->data ['cidKey'] = $cidKey;
  4617. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4618. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4619. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4620. }
  4621. $this->data ['month'] = $month;
  4622. $this->data ['categoryList'] = $categoryList;
  4623. $this->data ['memu'] = "invoice";
  4624. $this->data ['staff'] = $this->staff;
  4625. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4626. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4627. }
  4628. /**
  4629. * 办事处人员汇总详情
  4630. */
  4631. function invoiceAggregateStaffDetail() {
  4632. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4633. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4634. Doo::loadClass ( 'XDeode' );
  4635. $XDeode = new XDeode ( 5 );
  4636. Doo::loadModel ( 'invoice' );
  4637. $invoice = new invoice ();
  4638. Doo::loadModel ( 'staff' );
  4639. $staff = new staff ();
  4640. Doo::loadModel ( "invoiceCategoryManage" );
  4641. $invoiceCategoryManage = new invoiceCategoryManage ();
  4642. $sid = $XDeode->decode ( $sidKey );
  4643. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4644. $cidList = array ();
  4645. foreach ( $imcStaff as $key => $value ) {
  4646. array_push ( $cidList, $value ['cid'] );
  4647. if (empty ( $cidKey ))
  4648. $cidKey = $XDeode->encode ( $value ['cid'] );
  4649. }
  4650. $cidString = implode ( ',', $cidList );
  4651. $staffList = $staff->getStaffInCid ( $cidString );
  4652. $staffDetail = $staff->getStaffBySid ( $sid );
  4653. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4654. $page_size = 18;
  4655. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4656. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4657. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4658. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4659. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4660. $dateArr = explode ( ':', $date );
  4661. $D1 = '';
  4662. $D2 = '';
  4663. if (! empty ( $date )) {
  4664. $D1 = $dateArr [0] . " 00:00:00 ";
  4665. if (isset ( $dateArr [1] ))
  4666. $D2 = $dateArr [1] . " 23:59:59 ";
  4667. else
  4668. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4669. // $D2 = $dateArr [1];
  4670. }
  4671. $con = ' status=2 ';
  4672. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4673. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4674. if ($status == 'UNRECORD')
  4675. $con .= ' and printStatus=1 and untreadStatus=0';
  4676. elseif ($status == 'RECORD')
  4677. $con .= ' and printStatus=1 and untreadStatus=3';
  4678. elseif ($status == 'BOUNCED')
  4679. $con .= ' and untreadStatus=2';
  4680. elseif ($status == 'PARTRECORD')
  4681. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4682. elseif ($status == 'All') {
  4683. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4684. }
  4685. $con .= ' and sid=' . $sid;
  4686. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4687. if (! empty ( $MebSea )) {
  4688. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4689. }
  4690. $pageinfo ['page'] = array (
  4691. 'previous' => ''
  4692. );
  4693. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4694. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4695. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4696. $this->data ['staffDetail'] = $staffDetail;
  4697. $this->data ['staffList'] = $staffList;
  4698. $this->data ['MebSeaEn'] = $MebSea;
  4699. $this->data ['MebSea'] = urlencode ( $MebSea );
  4700. $this->data ['date'] = $date;
  4701. $this->data ['page'] = $pageinfo;
  4702. $this->data ['get'] = $get;
  4703. $this->data ['list'] = $list;
  4704. $this->data ['status'] = $status;
  4705. $this->data ['sidKey'] = $sidKey;
  4706. $this->data ['memu'] = "invoice";
  4707. $this->data ['staff'] = $this->staff;
  4708. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4709. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4710. }
  4711. /**
  4712. * 办事处人员汇总收款情
  4713. */
  4714. function invoiceAggregateStaffReceivablesDetail() {
  4715. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4716. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4717. Doo::loadModel ( 'invoiceReceivables' );
  4718. $invoiceReceivables = new invoiceReceivables ();
  4719. Doo::loadModel ( 'staff' );
  4720. $staff = new staff ();
  4721. Doo::loadModel ( "invoiceCategoryManage" );
  4722. $invoiceCategoryManage = new invoiceCategoryManage ();
  4723. Doo::loadClass ( 'XDeode' );
  4724. $XDeode = new XDeode ( 5 );
  4725. $sid = $XDeode->decode ( $sidKey );
  4726. $staffDetail = $staff->getStaffBySid ( $sid );
  4727. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4728. $cidList = array ();
  4729. foreach ( $imcStaff as $key => $value ) {
  4730. array_push ( $cidList, $value ['cid'] );
  4731. if (empty ( $cidKey ))
  4732. $cidKey = $XDeode->encode ( $value ['cid'] );
  4733. }
  4734. $cidString = implode ( ',', $cidList );
  4735. $staffList = $staff->getStaffInCid ( $cidString );
  4736. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4737. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4738. $page_size = 10;
  4739. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4740. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4741. if ($timeType == "BINDOTP") {
  4742. $status = 'Credited';
  4743. }
  4744. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4745. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4746. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4747. $dateArr = explode ( ':', $date );
  4748. $D1 = '';
  4749. $D2 = '';
  4750. if (! empty ( $date )) {
  4751. $D1 = $dateArr [0] . " 00:00:00 ";
  4752. if (isset ( $dateArr [1] ))
  4753. $D2 = $dateArr [1] . " 23:59:59 ";
  4754. else
  4755. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4756. }
  4757. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4758. $descField = 'a.bindDate';
  4759. if ($timeType == 'CREATE')
  4760. $descField = 'a.date';
  4761. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4762. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4763. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4764. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4765. if ($status == 'Unclaimed')
  4766. $con .= ' and a.bindStatus=0';
  4767. elseif ($status == 'Credited')
  4768. $con .= ' and a.bindStatus=1';
  4769. elseif ($status == 'Claim')
  4770. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4771. elseif ($status == 'BBN')
  4772. $con .= ' and a.bindPrice>a.receivablesPrice';
  4773. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4774. if (! empty ( $MebSea )) {
  4775. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4776. }
  4777. $pageinfo ['page'] = array (
  4778. 'previous' => ''
  4779. );
  4780. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4781. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4782. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4783. // where ' . $con . ' group by a.irid ';
  4784. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4785. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4786. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4787. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4788. foreach ( $list as $key => $value ) {
  4789. $list [$key] ['category'] = '';
  4790. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4791. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4792. $list [$key] ['category'] = $receivablesCategory [1];
  4793. }
  4794. }
  4795. // print_r($list);
  4796. $this->data ['staffDetail'] = $staffDetail;
  4797. $this->data ['sidKey'] = $sidKey;
  4798. $this->data ['staffList'] = $staffList;
  4799. $this->data ['timeType'] = $timeType;
  4800. $this->data ['MebSeaEn'] = $MebSea;
  4801. $this->data ['MebSea'] = urlencode ( $MebSea );
  4802. $this->data ['date'] = $date;
  4803. $this->data ['page'] = $pageinfo;
  4804. $this->data ['get'] = $get;
  4805. $this->data ['list'] = $list;
  4806. $this->data ['status'] = $status;
  4807. $this->data ['memu'] = "invoice";
  4808. $this->data ['staff'] = $this->staff;
  4809. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4810. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4811. }
  4812. function invoiceAchieve() {
  4813. Doo::loadModel ( 'invoice' );
  4814. $invoice = new invoice ();
  4815. Doo::loadClass ( 'XDeode' );
  4816. $XDeode = new XDeode ( 5 );
  4817. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4818. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4819. $page_size = 18;
  4820. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4821. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4822. $get = "/" . $date;
  4823. $con = '';
  4824. if ($date == 'MONTHO')
  4825. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4826. elseif ($date == 'MONTHT')
  4827. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4828. elseif ($date == 'MONTHY')
  4829. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4830. if (! empty ( $MebSea )) {
  4831. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4832. $get .= "/" . $MebSea;
  4833. }
  4834. $pageinfo ['page'] = array (
  4835. 'previous' => ''
  4836. );
  4837. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4838. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4839. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4840. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4841. // print_r($pageinfo);
  4842. $this->data ['MebSeaEn'] = $MebSea;
  4843. $this->data ['MebSea'] = urlencode ( $MebSea );
  4844. $this->data ['get'] = $get;
  4845. $this->data ['page'] = $pageinfo;
  4846. $this->data ['list'] = $list;
  4847. $this->data ['date'] = $date;
  4848. $this->data ['memu'] = "invoice";
  4849. $this->data ['staff'] = $this->staff;
  4850. $this->data ['receiptMemu'] = 'invoice';
  4851. $this->render ( "/admin/invoiceAchieve", $this->data );
  4852. }
  4853. /**
  4854. */
  4855. function invoiceMyUnAccountAchieve() {
  4856. Doo::loadModel ( 'invoice' );
  4857. $invoice = new invoice ();
  4858. Doo::loadClass ( 'XDeode' );
  4859. $XDeode = new XDeode ( 5 );
  4860. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4861. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4862. $page_size = 18;
  4863. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4864. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4865. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4866. $dateArr = explode ( ':', $date );
  4867. $D1 = '';
  4868. $D2 = '';
  4869. if (! empty ( $date )) {
  4870. $D1 = $dateArr [0];
  4871. $D2 = $dateArr [1];
  4872. }
  4873. $con = '';
  4874. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4875. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4876. if (! empty ( $MebSea )) {
  4877. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4878. }
  4879. $pageinfo ['page'] = array (
  4880. 'previous' => ''
  4881. );
  4882. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4883. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4884. $action = "invoiceMyUnAccountAchieve";
  4885. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4886. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4887. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4888. Doo::loadModel ( 'express' );
  4889. $express = new express ();
  4890. $expressList = $express->getExpressByAll ();
  4891. $this->data ['expressList'] = $expressList;
  4892. // print_r($list);
  4893. $this->data ['MebSeaEn'] = $MebSea;
  4894. $this->data ['get'] = $get;
  4895. $this->data ['page'] = $pageinfo;
  4896. $this->data ['date'] = $date;
  4897. $this->data ['list'] = $list;
  4898. $this->data ['memu'] = "invoice";
  4899. $this->data ['staff'] = $this->staff;
  4900. $this->data ['receiptMemu'] = 'invoice';
  4901. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4902. }
  4903. function invoiceReceivablesAchieve() {
  4904. Doo::loadModel ( 'invoiceReceivables' );
  4905. $invoiceReceivables = new invoiceReceivables ();
  4906. Doo::loadClass ( 'XDeode' );
  4907. $XDeode = new XDeode ( 5 );
  4908. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4909. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4910. $page_size = 12;
  4911. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4912. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4913. $get = "/" . $date;
  4914. $con = '';
  4915. if ($date == 'MONTHO')
  4916. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4917. elseif ($date == 'MONTHT')
  4918. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4919. elseif ($date == 'MONTHY')
  4920. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4921. if (! empty ( $MebSea )) {
  4922. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4923. $get .= "/" . $MebSea;
  4924. }
  4925. $pageinfo ['page'] = array (
  4926. 'previous' => ''
  4927. );
  4928. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4929. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4930. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4931. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4932. // print_r($pageinfo);
  4933. $this->data ['MebSeaEn'] = $MebSea;
  4934. $this->data ['MebSea'] = urlencode ( $MebSea );
  4935. $this->data ['get'] = $get;
  4936. $this->data ['page'] = $pageinfo;
  4937. $this->data ['list'] = $list;
  4938. $this->data ['date'] = $date;
  4939. $this->data ['memu'] = "invoice";
  4940. $this->data ['staff'] = $this->staff;
  4941. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4942. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4943. }
  4944. /**
  4945. * 收款解绑
  4946. */
  4947. function invoiceUnBundLing() {
  4948. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4949. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4950. Doo::loadModel ( 'invoice' );
  4951. $invoice = new invoice ();
  4952. Doo::loadModel ( 'invoiceReceivables' );
  4953. $invoiceReceivables = new invoiceReceivables ();
  4954. Doo::loadModel ( 'invoiceOperationLog' );
  4955. $invoiceOperationLog = new invoiceOperationLog ();
  4956. Doo::loadModel ( 'invoiceROLog' );
  4957. $invoiceROLog = new invoiceROLog ();
  4958. Doo::loadModel ( 'invoiceStatistics' );
  4959. Doo::loadClass ( 'XDeode' );
  4960. $XDeode = new XDeode ( 5 );
  4961. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4962. die ( 'illegal request' );
  4963. $iid = $XDeode->decode ( $iidKey );
  4964. $irid = $invoice->authcode ( $unBundKey );
  4965. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4966. die ( 'illegal request' );
  4967. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4968. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4969. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4970. die ( 'illegal request' );
  4971. // 收款
  4972. $item = array (
  4973. 'irid' => $irDetails ['irid'],
  4974. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4975. 'bindStatus' => 0
  4976. );
  4977. if ($irDetails ['iid'] == $iid)
  4978. $item += array (
  4979. 'iid' => 0
  4980. );
  4981. else {
  4982. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4983. foreach ( $iidExtend as $key => $value ) {
  4984. if ($value == $iid)
  4985. unset ( $iidExtend [$key] );
  4986. }
  4987. $iidExtend = implode ( ',', $iidExtend );
  4988. $item += array (
  4989. 'iidExtend' => $iidExtend
  4990. );
  4991. }
  4992. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4993. // 收款操作日志
  4994. $item = array (
  4995. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4996. 'date' => date ( "Y-m-d" ),
  4997. 'status' => 3,
  4998. 'img' => $this->staff [0] ['avatar'],
  4999. 'username' => $this->staff [0] ['username'],
  5000. 'uid' => $this->staff [0] ['sid'],
  5001. 'category' => $this->staff [0] ['category'],
  5002. 'irid' => $irid
  5003. );
  5004. $invoiceROLog->setInvoiceROLog ( $item );
  5005. // 扣除入账统计金额
  5006. $invoiceStatistics = new invoiceStatistics ();
  5007. $item = array (
  5008. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  5009. 'priceClass' => 3,
  5010. 'cid' => $invoiceDetails ['cid'],
  5011. 'staff' => $invoiceDetails ['sid'],
  5012. 'accountPrice' => - $invoiceDetails ['invoicePrice']
  5013. );
  5014. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5015. // 扣除收款统计金额
  5016. $invoiceStatistics = new invoiceStatistics ();
  5017. $item = array (
  5018. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  5019. 'priceClass' => 2,
  5020. 'cid' => $invoiceDetails ['cid'],
  5021. 'staff' => $invoiceDetails ['sid'],
  5022. 'irid' => $irDetails ['irid'],
  5023. 'receivablesPrice' => - $invoiceDetails ['invoicePrice']
  5024. );
  5025. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5026. // 发票解绑去收款ID
  5027. $iridString = $invoiceDetails ['irid'];
  5028. if (! empty ( $invoiceDetails ['irid'] )) {
  5029. $list = explode ( ',', $invoiceDetails ['irid'] );
  5030. foreach ( $list as $key => $value ) {
  5031. if ($value == $irDetails ['irid']) {
  5032. unset ( $list [$key] );
  5033. break;
  5034. }
  5035. }
  5036. $iridString = implode ( ",", $list );
  5037. }
  5038. //解绑后余额 加回去
  5039. $invoiceBalance=$invoiceDetails['invoiceBalance']+$irDetails['receivablesPrice'];
  5040. if ($invoiceBalance<0){
  5041. $invoiceBalance=0;
  5042. }
  5043. if($invoiceBalance>$invoiceDetails['invoicePrice']){
  5044. $invoiceBalance=$invoiceDetails['invoicePrice'];
  5045. }
  5046. $item = array (
  5047. 'iid' => $invoiceDetails ['iid'],
  5048. 'irid' => $iridString,
  5049. 'invoiceBalance'=>$invoiceBalance,
  5050. 'updateTime' => date ( "Y-m-d H:i:s" )
  5051. );
  5052. if ($invoiceDetails ['untreadStatus'] == 3)
  5053. $item += array (
  5054. 'untreadStatus' => 0
  5055. );
  5056. $invoice->setInvoiceByCondition ( $item );
  5057. Doo::loadModel ( 'bill' );
  5058. $bill = new bill ();
  5059. $bill->iid=$invoiceDetails ['iid'];
  5060. $bill->trainId=$invoiceDetails['trainId'];
  5061. $bill->irid=$irDetails ['irid'];
  5062. $bill->create_time=date ( "Y-m-d H:i:s" );
  5063. $bill->price=-$invoiceDetails ['invoicePrice'];
  5064. $bill->remark='解绑-扣除入账';
  5065. $bill->insert ();
  5066. $item = array (
  5067. 'date' => date ( "Y-m-d H:i:s" ),
  5068. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  5069. 'status' => 11,
  5070. 'img' => $this->staff [0] ['avatar'],
  5071. 'username' => $this->staff [0] ['username'],
  5072. 'uid' => $this->staff [0] ['sid'],
  5073. 'category' => $this->staff [0] ['category'],
  5074. 'iid' => $invoiceDetails ['iid']
  5075. );
  5076. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5077. // 公司流水-解绑时删除流水
  5078. // Doo::loadModel ( 'wasteBook' );
  5079. // $wasteBook = new wasteBook ();
  5080. // $wasteBook->delete ( array (
  5081. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  5082. // 'limit' => 1
  5083. // ) );
  5084. // 银行
  5085. /*
  5086. * $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); }
  5087. */
  5088. return "/invoiceReceivablesAS";
  5089. }
  5090. /**
  5091. * 或者该收款下的所以发票
  5092. */
  5093. function ajaxGetInvoiceReceivablesByInvoice() {
  5094. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  5095. Doo::loadModel ( 'invoice' );
  5096. $invoice = new invoice ();
  5097. Doo::loadModel ( 'invoiceReceivables' );
  5098. $invoiceReceivables = new invoiceReceivables ();
  5099. $irid = $invoice->authcode ( $irid );
  5100. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5101. die ( 'illegal request' );
  5102. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5103. $iidString = $irDetails ['iid'];
  5104. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5105. if (! empty ( $irDetails ['iidExtend'] ))
  5106. $iidString .= ',' . implode ( ',', $iidExtend );
  5107. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5108. $html = "";
  5109. foreach ( $invoiceList as $key => $value ) {
  5110. $title = $value ['invoiceTitle'];
  5111. if (! empty ( $value ['invoiceCompany'] ))
  5112. $title = $value ['invoiceCompany'];
  5113. $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>';
  5114. }
  5115. echo json_encode ( array (
  5116. 'status' => 1,
  5117. 'html' => $html
  5118. ) );
  5119. }
  5120. /**
  5121. * 发票管理
  5122. */
  5123. function invoiceAS() {
  5124. Doo::loadModel ( 'invoice' );
  5125. $invoice = new invoice ();
  5126. Doo::loadModel ( 'invoiceReceivables' );
  5127. $invoiceReceivables = new invoiceReceivables ();
  5128. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5129. $page_size = 18;
  5130. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5131. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5132. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5133. $dateArr = explode ( ':', $date );
  5134. $D1 = '';
  5135. $D2 = '';
  5136. if (! empty ( $date )) {
  5137. $D1 = $dateArr [0] . " 00:00:00 ";
  5138. if (isset ( $dateArr [1] ))
  5139. $D2 = $dateArr [1] . " 23:59:59 ";
  5140. else
  5141. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5142. // $D2 = $dateArr [1];
  5143. }
  5144. $con = ' status=2 ';
  5145. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5146. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5147. if ($status == 'UNRECORD')
  5148. $con .= ' and printStatus=1 and untreadStatus=0';
  5149. elseif ($status == 'BAD'){
  5150. $con .= ' and badDebt=1 ';
  5151. }elseif ($status == 'RECORD')
  5152. $con .= ' and printStatus=1 and untreadStatus=3';
  5153. elseif ($status == 'BOUNCED')
  5154. $con .= ' and untreadStatus=2';
  5155. elseif ($status == 'PARTRECORD')
  5156. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5157. elseif ($status == 'All') {
  5158. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5159. }
  5160. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5161. if (! empty ( $MebSea )) {
  5162. $con .= ' and ( invoiceSerial like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5163. }
  5164. $pageinfo ['page'] = array (
  5165. 'previous' => ''
  5166. );
  5167. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5168. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5169. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5170. $this->data ['MebSeaEn'] = $MebSea;
  5171. $this->data ['MebSea'] = urlencode ( $MebSea );
  5172. $this->data ['date'] = $date;
  5173. $this->data ['page'] = $pageinfo;
  5174. $this->data ['get'] = $get;
  5175. $this->data ['list'] = $list;
  5176. $this->data ['status'] = $status;
  5177. $this->data ['memu'] = "invoice";
  5178. $this->data ['staff'] = $this->staff;
  5179. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5180. $this->render ( "/admin/invoiceAS", $this->data );
  5181. }
  5182. /**
  5183. * 收款管理
  5184. */
  5185. function invoiceReceivablesAS() {
  5186. Doo::loadModel ( 'invoiceReceivables' );
  5187. $invoiceReceivables = new invoiceReceivables ();
  5188. Doo::loadModel ( 'L_category' );
  5189. $lCategory = new L_category ();
  5190. $category = $lCategory->getCategory ();
  5191. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5192. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5193. $page_size = 10;
  5194. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5195. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5196. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5197. $dateArr = explode ( ':', $date );
  5198. $D1 = '';
  5199. $D2 = '';
  5200. if (! empty ( $date )) {
  5201. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5202. if (isset ( $dateArr [1] ))
  5203. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5204. else
  5205. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5206. }
  5207. $descField = 'a.receivablesDate';
  5208. if ($timeType == 'CREATE')
  5209. $descField = 'a.date';
  5210. $con = ' 1 ';
  5211. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5212. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5213. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5214. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5215. if ($status == 'Unclaimed')
  5216. $con .= ' and a.bindStatus=0';
  5217. elseif ($status == 'Credited')
  5218. $con .= ' and a.bindStatus=1';
  5219. elseif ($status == 'Claim')
  5220. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5221. elseif ($status == 'BBN')
  5222. $con .= ' and a.bankBatchNumber!=""';
  5223. elseif ($status == 'REFUND')
  5224. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5225. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5226. if (! empty ( $MebSea )) {
  5227. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5228. }
  5229. $pageinfo ['page'] = array (
  5230. 'previous' => ''
  5231. );
  5232. // if(!empty($con)){
  5233. // $con=' where 1 '.$con;
  5234. // }
  5235. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5236. // ' . $con ;
  5237. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5238. //echo $sql;
  5239. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5240. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5241. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5242. foreach ( $list as $key => $value ) {
  5243. $list [$key] ['category'] = '';
  5244. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5245. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5246. $list [$key] ['category'] = $receivablesCategory [1];
  5247. }
  5248. }
  5249. // print_r($list);
  5250. $this->data ['category'] = $category;
  5251. $this->data ['timeType'] = $timeType;
  5252. $this->data ['MebSeaEn'] = $MebSea;
  5253. $this->data ['MebSea'] = urlencode ( $MebSea );
  5254. $this->data ['date'] = $date;
  5255. $this->data ['page'] = $pageinfo;
  5256. $this->data ['get'] = $get;
  5257. $this->data ['list'] = $list;
  5258. $this->data ['status'] = $status;
  5259. $this->data ['memu'] = "invoice";
  5260. $this->data ['staff'] = $this->staff;
  5261. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5262. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5263. }
  5264. /**
  5265. * 删除一条收款
  5266. */
  5267. function delInvoiceReceivables() {
  5268. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5269. if (empty ( $iridKey ))
  5270. die ( 'illegal request' );
  5271. Doo::loadClass ( 'XDeode' );
  5272. $XDeode = new XDeode ( 5 );
  5273. $irid = $XDeode->decode ( $iridKey );
  5274. Doo::loadModel ( 'invoiceReceivables' );
  5275. $invoiceReceivables = new invoiceReceivables ();
  5276. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5277. if (empty ( $detail ))
  5278. die ( 'illegal request' );
  5279. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5280. // 扣除收款汇总信息 汇总
  5281. Doo::loadModel ( 'invoiceStatistics' );
  5282. $invoiceStatistics = new invoiceStatistics ();
  5283. $item = array (
  5284. 'date' => $detail ['receivablesDate'],
  5285. 'priceClass' => 2,
  5286. 'irid' => $detail ['irid'],
  5287. 'receivablesPrice' => - $detail ['receivablesPrice']
  5288. );
  5289. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5290. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5291. $item += array (
  5292. 'cid' => $receivablesCategory [0]
  5293. );
  5294. }
  5295. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5296. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5297. $item += array (
  5298. 'staff' => $receivablesStaff [0]
  5299. );
  5300. }
  5301. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5302. return '/invoiceReceivablesAS';
  5303. }
  5304. /**
  5305. * 添加退款信息
  5306. */
  5307. function setInvoiceReceivablesRefund() {
  5308. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5309. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5310. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5311. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5312. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5313. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5314. if ($refundPrice < 0)
  5315. die ( 'illegal request' );
  5316. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5317. Doo::loadModel ( 'invoiceReceivables' );
  5318. $invoiceReceivables = new invoiceReceivables ();
  5319. Doo::loadModel ( 'invoiceRefund' );
  5320. $invoiceRefund = new invoiceRefund ();
  5321. $irid = $invoiceReceivables->authcode ( $iridKey );
  5322. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5323. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5324. die ( 'illegal request' );
  5325. $invoiceReceivables = new invoiceReceivables ();
  5326. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5327. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5328. ';
  5329. $item = array (
  5330. 'irid' => $irid,
  5331. 'refundCompany' => $refundCompany,
  5332. 'refundNumber' => $refundNumber,
  5333. 'refundPrice' => $refundPrice,
  5334. 'refundRemarks' => $refundRemarks,
  5335. 'refundLog' => $refundLog
  5336. );
  5337. if ($refundType == 1) {
  5338. $item += array (
  5339. 'refundType' => $refundType,
  5340. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5341. 'bindStatus' => 2
  5342. );
  5343. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5344. $item += array (
  5345. 'refundType' => 1,
  5346. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5347. 'bindStatus' => 2
  5348. );
  5349. } else {
  5350. $item += array (
  5351. 'refundType' => $refundType,
  5352. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5353. );
  5354. }
  5355. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5356. // 添加退款记录
  5357. $item = array (
  5358. 'irid' => $irid,
  5359. 'refundType' => $refundType,
  5360. 'refundCompany' => $refundCompany,
  5361. 'refundNumber' => $refundNumber,
  5362. 'refundPrice' => $refundPrice,
  5363. 'refundLog' => $refundLog,
  5364. 'refundRemarks' => $refundRemarks,
  5365. 'date' => date ( "Y-m-d H:i:s" )
  5366. );
  5367. $invoiceRefund->addInvoiceRefund ( $item );
  5368. // 扣除收款汇总信息 汇总
  5369. Doo::loadModel ( 'invoiceStatistics' );
  5370. $invoiceStatistics = new invoiceStatistics ();
  5371. $item = array (
  5372. 'date' => $irDetail ['receivablesDate'],
  5373. 'priceClass' => 2,
  5374. 'irid' => $irDetail ['irid'],
  5375. 'receivablesPrice' => - $refundPrice
  5376. );
  5377. $receivablesCategory=array(0=>'',1=>'');
  5378. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5379. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5380. $item += array (
  5381. 'cid' => $receivablesCategory [0]
  5382. );
  5383. }
  5384. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5385. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5386. $item += array (
  5387. 'staff' => $receivablesStaff [0]
  5388. );
  5389. }
  5390. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5391. // 公司日常支出流水
  5392. Doo::loadModel ( 'wasteBook' );
  5393. $wasteBook = new wasteBook ();
  5394. $accountBank=$wasteBook->_getAccountBankEN($irDetail ['receivablesBank']);
  5395. $itemWaste = array (
  5396. 'accountPrice' => - $refundPrice,
  5397. 'expensesType' => 2,
  5398. 'accountType' => 11,
  5399. 'accountPriceShow' => $refundPrice,
  5400. 'dataID' => $irid,
  5401. 'accountBank' => $accountBank,
  5402. 'category' => $receivablesCategory[1],
  5403. 'cid' => $receivablesCategory[0],
  5404. 'name' => $this->staff [0] ['username'],
  5405. 'sid' => $this->staff [0] ['sid'],
  5406. 'inputDate' => date ( "Y-m-d H:i:s" )
  5407. );
  5408. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5409. return '/invoiceReceivablesAS';
  5410. }
  5411. die ( 'illegal request' );
  5412. }
  5413. function ajaxCheckInvoiceReceivablesRefund() {
  5414. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5415. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5416. if ($refundPrice < 0) {
  5417. echo json_encode ( array (
  5418. 'error' => '金额不能为负'
  5419. ) );
  5420. die ();
  5421. }
  5422. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5423. Doo::loadModel ( 'invoiceReceivables' );
  5424. $invoiceReceivables = new invoiceReceivables ();
  5425. $irid = $invoiceReceivables->authcode ( $iridKey );
  5426. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5427. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5428. echo json_encode ( array (
  5429. 'error' => '退款金额不能超过收款金额'
  5430. ) );
  5431. die ();
  5432. }
  5433. echo json_encode ( array (
  5434. 'ok' => '可以使用!'
  5435. ) );
  5436. die ();
  5437. }
  5438. }
  5439. /**
  5440. * 获得收款退款信息
  5441. */
  5442. function getRefundByDetail() {
  5443. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5444. Doo::loadModel ( 'invoiceReceivables' );
  5445. $invoiceReceivables = new invoiceReceivables ();
  5446. if (! empty ( $iridKey )) {
  5447. $irid = $invoiceReceivables->authcode ( $iridKey );
  5448. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5449. echo json_encode ( array (
  5450. 'status' => 1,
  5451. 'irDetail' => $irDetail
  5452. ) );
  5453. die ();
  5454. }
  5455. echo json_encode ( array (
  5456. 'status' => 2
  5457. ) );
  5458. }
  5459. /**
  5460. * 根据收款序列号获得收款退款信息
  5461. */
  5462. function ajaxGetInvoiceReceivablesBySerial() {
  5463. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5464. if (! empty ( $receivablesSerial )) {
  5465. Doo::loadModel ( 'invoiceReceivables' );
  5466. $invoiceReceivables = new invoiceReceivables ();
  5467. // , ' and refundLog=""'
  5468. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5469. $html = '';
  5470. if (! empty ( $irDetail ))
  5471. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5472. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5473. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5474. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5475. <td>' . $irDetail ['recepitTitleMark'] . '
  5476. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5477. </td>';
  5478. echo json_encode ( array (
  5479. 'status' => 1,
  5480. 'html' => $html,
  5481. 'irDetail' => $irDetail
  5482. ) );
  5483. die ();
  5484. }
  5485. echo json_encode ( array (
  5486. 'status' => 2
  5487. ) );
  5488. }
  5489. /**
  5490. * 绑定新收款
  5491. */
  5492. function relationNewInvoiceReceivables() {
  5493. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5494. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5495. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5496. Doo::loadModel ( 'invoiceReceivables' );
  5497. $invoiceReceivables = new invoiceReceivables ();
  5498. Doo::loadClass ( 'XDeode' );
  5499. $XDeode = new XDeode ( 5 );
  5500. $irid = $XDeode->decode ( $iridKey );
  5501. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5502. echo $irid . 'bbb' . $iridOld;
  5503. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5504. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5505. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5506. die ( 'illegal request' );
  5507. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5508. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5509. ';
  5510. $invoiceReceivables = new invoiceReceivables ();
  5511. $item = array (
  5512. 'irid' => $iridOld,
  5513. 'relationIrid' => $irid,
  5514. 'relationLog' => $relationLog
  5515. );
  5516. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5517. return '/invoiceReceivablesAS';
  5518. }
  5519. die ( 'illegal request' );
  5520. }
  5521. // function invoiceApprovalAchieve() {
  5522. // Doo::loadModel ( 'invoice' );
  5523. // $invoice = new invoice ();
  5524. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5525. // $page_size = 12;
  5526. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5527. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5528. // $get = "/" . $date;
  5529. // $con = '';
  5530. // if ($date == 'MONTHO')
  5531. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5532. // elseif ($date == 'MONTHT')
  5533. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5534. // elseif ($date == 'MONTHY')
  5535. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5536. // if (! empty ( $MebSea )) {
  5537. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5538. // $get .= "/" . $MebSea;
  5539. // }
  5540. // $pageinfo ['page'] = array (
  5541. // 'previous' => ''
  5542. // );
  5543. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5544. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5545. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5546. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5547. // // print_r($list);
  5548. // $this->data ['MebSeaEn'] = $MebSea;
  5549. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5550. // $this->data ['get'] = $get;
  5551. // $this->data ['page'] = $pageinfo;
  5552. // $this->data ['list'] = $list;
  5553. // $this->data ['date'] = $date;
  5554. // $this->data ['memu'] = "invoice";
  5555. // $this->data ['staff'] = $this->staff;
  5556. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5557. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5558. // }
  5559. /**
  5560. * 获得审批发票的信息以及审批页面
  5561. */
  5562. function ajaxGetInvoiceApprovalDetail() {
  5563. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5564. if (empty ( $serial )) {
  5565. echo json_encode ( array (
  5566. 'status' => 2,
  5567. 'msg' => 'illegal request'
  5568. ) );
  5569. die ();
  5570. }
  5571. Doo::loadModel ( 'invoice' );
  5572. $invoice = new invoice ();
  5573. Doo::loadModel ( 'invoiceOperationLog' );
  5574. $invoiceOperationLog = new invoiceOperationLog ();
  5575. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5576. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5577. if (empty ( $detail ))
  5578. $html = '';
  5579. else {
  5580. $html = '
  5581. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5582. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5583. <input type="hidden" name="status" value="">
  5584. <input type="hidden" name="divApproval" value="divApproval">
  5585. <div class="modal-dialog modal-lg">
  5586. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5587. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5588. <tr>
  5589. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5590. </tr>
  5591. <tr>
  5592. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5593. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5594. </tr>
  5595. <tr>
  5596. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5597. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5598. </tr>
  5599. <tr>
  5600. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5601. </td>
  5602. </tr>
  5603. <tr>
  5604. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5605. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5606. </tr>
  5607. <tr>
  5608. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5609. </tr></tbody></table>';
  5610. if ($detail ['invoiceType'] == 0)
  5611. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5612. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5613. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5614. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5615. </tr>';
  5616. else
  5617. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5618. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5619. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5620. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5621. ';
  5622. $html .= '<tr>
  5623. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5624. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5625. </tr>
  5626. <tr>
  5627. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5628. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5629. </tr></tbody></table>';
  5630. if ($detail ['doPost'] == 1) {
  5631. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5632. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5633. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5634. </tr><tr>
  5635. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5636. </tr><tr>
  5637. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5638. </tr>
  5639. ';
  5640. if ($detail ['expressCom'] == 'SF')
  5641. $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>';
  5642. else
  5643. $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>';
  5644. $html .= '</tbody></table>';
  5645. }
  5646. if (! empty ( $invoiceOperationLogList )) {
  5647. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5648. foreach ( $invoiceOperationLogList as $key => $value ) {
  5649. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5650. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5651. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5652. if ($value ['status'] == 2) {
  5653. $html .= '<span class="colGreen">同意</span>';
  5654. } elseif ($value ['status'] == 3) {
  5655. $html .= '<span class="colOrange">退回</span>';
  5656. } elseif ($value ['status'] == 5) {
  5657. $html .= '<span class="colGreen">打印</span>';
  5658. } elseif ($value ['status'] == 4) {
  5659. $html .= '<span class="colRed">终止</span>';
  5660. }
  5661. $html .= $value ['operation'] . '</p></blockquote>';
  5662. }
  5663. }
  5664. $html .= '</td></tr></tbody></table>';
  5665. }
  5666. $html .= '</div><div class="modal-footer">
  5667. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5668. <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>
  5669. <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>
  5670. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5671. </form>
  5672. <script type="text/javascript">
  5673. $("a[node-approval^=\'approval\']").click(function() {
  5674. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5675. $("form[name=\'invoiceApproval\']").submit();
  5676. });
  5677. </script>
  5678. ';
  5679. }
  5680. echo json_encode ( array (
  5681. 'status' => 1,
  5682. 'html' => $html
  5683. ) );
  5684. die ();
  5685. }
  5686. /**
  5687. * 获得审批发票分页数据
  5688. */
  5689. function ajaxGetinvoiceApprovalAchieve() {
  5690. Doo::loadModel ( 'invoice' );
  5691. $invoice = new invoice ();
  5692. Doo::loadModel ( 'staff' );
  5693. $staff = new staff ();
  5694. Doo::loadClass ( 'XDeode' );
  5695. $XDeode = new XDeode ( 5 );
  5696. Doo::loadModel ( 'invoiceTraining' );
  5697. $invoiceTraining = new invoiceTraining ();
  5698. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5699. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5700. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5701. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5702. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5703. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5704. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5705. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5706. $MebSea = $this->get_args ( 'search' );
  5707. $MebSea = $MebSea ['value'];
  5708. $page_size = $length;
  5709. $con = '';
  5710. if ($status == 'ALL')
  5711. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5712. elseif ($status == 'PEND')
  5713. $con = ' isDelete=0 and status=1';
  5714. elseif ($status == 'APPROVED')
  5715. $con = ' isDelete=0 and status=2';
  5716. if ($invoiceType == 'ORDINARY')
  5717. $con .= ' and invoiceType=0 ';
  5718. elseif ($invoiceType == 'SPECIAL')
  5719. $con .= ' and invoiceType=1 ';
  5720. if ($invoiceTrain == 'ORDINARY')
  5721. $con .= ' and trainId=0 ';
  5722. elseif ($invoiceTrain == 'TRAIN')
  5723. $con .= ' and trainId!=0 ';
  5724. if ($invoiceTrainName != 'ALL') {
  5725. $trainId = $XDeode->decode ( $invoiceTrainName );
  5726. if (is_numeric ( $trainId ))
  5727. $con .= ' and trainId =' . $trainId;
  5728. }
  5729. $dateArr = explode ( ':', $date );
  5730. $D1 = $dateString = '';
  5731. $D2 = '';
  5732. if (! empty ( $date )) {
  5733. $D1 = $dateArr [0];
  5734. if (isset ( $dateArr [1] ))
  5735. $D2 = $dateArr [1];
  5736. else
  5737. $D2 = '';
  5738. $dateString = $D1 . " : " . $D2;
  5739. }
  5740. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5741. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5742. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5743. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5744. if (! empty ( $MebSea ))
  5745. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5746. // /
  5747. $pageinfo ['page'] = array (
  5748. 'previous' => ''
  5749. );
  5750. $sql = ' ' . $con;
  5751. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5752. $limit = $page . ',' . $page_size;
  5753. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5754. $approvalList = array ();
  5755. $html = '<script type="text/javascript">
  5756. </script>';
  5757. // 结算结束不能修改方式
  5758. Doo::loadModel ( 'receipt' );
  5759. $receipt = new receipt ();
  5760. foreach ( $list as $key => $value ) {
  5761. $irDetail = array ();
  5762. // 结算方式
  5763. $receiptDetail = array ();
  5764. if ($value ['trainId'] != 0) {
  5765. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5766. }
  5767. if (! empty ( $receiptDetail )) {
  5768. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5769. array_push ( $irDetail, '' );
  5770. } else {
  5771. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5772. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5773. } elseif ($value ['status'] == 2) {
  5774. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5775. } else
  5776. array_push ( $irDetail, '' );
  5777. }
  5778. } else {
  5779. if ($value ['status'] == 2) {
  5780. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5781. } else{
  5782. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5783. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5784. }else{
  5785. array_push ( $irDetail, '' );
  5786. }
  5787. }
  5788. }
  5789. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5790. if ($value ['invoiceType'] == 1)
  5791. array_push ( $irDetail, $value ['invoiceCompany'] );
  5792. else
  5793. array_push ( $irDetail, $value ['invoiceTitle'] );
  5794. array_push ( $irDetail, $value ['TIN'] );
  5795. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5796. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5797. array_push ( $irDetail, $value ['remark'] );
  5798. array_push ( $irDetail, $value ['invoiceElement'] );
  5799. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5800. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5801. if ($value ['invoiceType'] == 1) {
  5802. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5803. } else {
  5804. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5805. }
  5806. if ($value ['settlementType'] == 0) {
  5807. array_push ( $irDetail, '软件销售' );
  5808. } else {
  5809. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5810. array_push ( $irDetail, $itDetail ['trainName'] );
  5811. }
  5812. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5813. array_push ( $irDetail, $value ['recipientsAddress'] );
  5814. array_push ( $irDetail, $value ['mailItems'] );
  5815. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5816. $fchtml = $value ['OL'] ['operation'];
  5817. if (count ( $list ) == $page_size)
  5818. $fchtml = $value ['OL'] ['operation'] . $html;
  5819. // 最后的审批意见
  5820. array_push ( $irDetail, $fchtml );
  5821. if ($value ['status'] == 2)
  5822. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5823. elseif ($value ['status'] == 3)
  5824. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5825. elseif ($value ['status'] == 4)
  5826. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5827. else
  5828. array_push ( $irDetail, '' );
  5829. array_push ( $approvalList, $irDetail );
  5830. }
  5831. // $approvalListJson = json_encode ( $approvalList );
  5832. $recordsFiltered = $pageinfo ['total_data'];
  5833. echo json_encode ( array (
  5834. "draw" => intval ( $draw ),
  5835. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5836. "recordsFiltered" => intval ( $recordsFiltered ),
  5837. "data" => $approvalList
  5838. ), JSON_UNESCAPED_UNICODE );
  5839. }
  5840. /**
  5841. * 审批发票查看更多--重构
  5842. */
  5843. function invoiceApprovalAchieve() {
  5844. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5845. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5846. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5847. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5848. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5849. Doo::loadModel ( 'invoiceTraining' );
  5850. $invoiceTraining = new invoiceTraining ();
  5851. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5852. $this->data ['trainList'] = $trainList;
  5853. $this->data ['dateString'] = $date;
  5854. $this->data ['status'] = $status;
  5855. $this->data ['invoiceType'] = $invoiceType;
  5856. $this->data ['invoiceTrain'] = $invoiceTrain;
  5857. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5858. $this->data ['memu'] = "invoice";
  5859. $this->data ['staff'] = $this->staff;
  5860. $this->data ['receiptMemu'] = 'invoiceApproval';
  5861. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5862. }
  5863. function invoiceTAchieve() {
  5864. Doo::loadModel ( 'invoice' );
  5865. $invoice = new invoice ();
  5866. Doo::loadClass ( 'XDeode' );
  5867. $XDeode = new XDeode ( 5 );
  5868. Doo::loadModel ( 'staff' );
  5869. $staff = new staff ();
  5870. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5871. $page_size = 12;
  5872. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5873. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5874. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5875. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5876. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5877. Doo::loadModel ( 'invoiceTraining' );
  5878. $invoiceTraining = new invoiceTraining ();
  5879. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5880. $get = "/" . $date;
  5881. $con = '';
  5882. if ($date == 'MONTHO')
  5883. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5884. elseif ($date == 'MONTHT')
  5885. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5886. elseif ($date == 'MONTHY')
  5887. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5888. if ($invoiceType == 'ORDINARY')
  5889. $con .= ' and invoiceType=0 ';
  5890. elseif ($invoiceType == 'SPECIAL')
  5891. $con .= ' and invoiceType=1 ';
  5892. if ($invoiceTrain == 'ORDINARY')
  5893. $con .= ' and trainId=0 ';
  5894. elseif ($invoiceTrain == 'TRAIN')
  5895. $con .= ' and trainId!=0 ';
  5896. if ($invoiceTrainName != 'ALL') {
  5897. $trainId = $XDeode->decode ( $invoiceTrainName );
  5898. if (is_numeric ( $trainId ))
  5899. $con .= ' and trainId =' . $trainId;
  5900. }
  5901. if (! empty ( $MebSea )) {
  5902. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5903. $get .= "/" . $MebSea;
  5904. }
  5905. $pageinfo ['page'] = array (
  5906. 'previous' => ''
  5907. );
  5908. $sql = "";
  5909. $action = "";
  5910. if ($this->ACTION == 'invoicePrintAchieve') {
  5911. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5912. $action = "invoicePrintAchieve";
  5913. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5914. // and untreadStatus=0
  5915. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5916. $action = "invoicePostAchieve";
  5917. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5918. $sql = " untreadStatus=2 and status=2 " . $con;
  5919. $action = "invoiceUntreadAchieve";
  5920. }
  5921. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5922. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5923. $this->data ['MebSeaEn'] = $MebSea;
  5924. $this->data ['MebSea'] = urlencode ( $MebSea );
  5925. $this->data ['get'] = $get;
  5926. $this->data ['page'] = $pageinfo;
  5927. $this->data ['trainList'] = $trainList;
  5928. $this->data ['invoiceType'] = $invoiceType;
  5929. $this->data ['invoiceTrain'] = $invoiceTrain;
  5930. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5931. $this->data ['date'] = $date;
  5932. $this->data ['memu'] = "invoice";
  5933. $this->data ['staff'] = $this->staff;
  5934. if ($this->ACTION == 'invoicePrintAchieve') {
  5935. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5936. $this->data ['receiptMemu'] = 'invoicePrint';
  5937. $this->data ['list'] = $list;
  5938. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5939. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5940. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5941. Doo::loadModel ( 'express' );
  5942. $express = new express ();
  5943. $expressList = $express->getExpressByAll ();
  5944. $this->data ['expressList'] = $expressList;
  5945. $this->data ['receiptMemu'] = 'invoicePost';
  5946. $this->data ['list'] = $list;
  5947. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5948. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5949. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc','desc','untreadTime' );
  5950. $this->data ['receiptMemu'] = 'invoiceUntread';
  5951. $this->data ['list'] = $list;
  5952. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5953. }
  5954. }
  5955. /**
  5956. * 公司应收款
  5957. */
  5958. function invoiceAggregateCompanyDetail() {
  5959. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5960. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5961. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5962. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5963. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5964. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5965. Doo::loadClass ( 'XDeode' );
  5966. $XDeode = new XDeode ( 5 );
  5967. Doo::loadModel ( 'invoice' );
  5968. $invoice = new invoice ();
  5969. Doo::loadModel ( 'staff' );
  5970. $staff = new staff ();
  5971. Doo::loadModel ( "invoiceCompanyManage" );
  5972. $invoiceCompanyManage = new invoiceCompanyManage ();
  5973. Doo::loadModel ( 'L_category' );
  5974. $category = new L_category ();
  5975. $sid = '';
  5976. if (! empty ( $sidKey )) {
  5977. $sid = $XDeode->decode ( $sidKey );
  5978. }
  5979. $staffDetail = $staff->getStaffBySid ( $sid );
  5980. $cid = '';
  5981. if (! empty ( $cidKey )) {
  5982. $cid = $XDeode->decode ( $cidKey );
  5983. }
  5984. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5985. $cidList = array ();
  5986. foreach ( $imcStaff as $key => $value ) {
  5987. array_push ( $cidList, $value ['cid'] );
  5988. }
  5989. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5990. $cidString = implode ( ',', $cidList );
  5991. if (empty ( $cid ))
  5992. $staffList = $staff->getStaffInCid ( $cidString );
  5993. else
  5994. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5995. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5996. $page_size = 25;
  5997. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5998. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5999. $con = ' status=2 and untreadStatus!=2 and invalid=0 and isDelete=0 and badDebt=0 ';
  6000. $statisticsCon = '';
  6001. if (! empty ( $year ) && is_numeric ( $year ))
  6002. $con .= ' and Year(printTime)=' . $year . '';
  6003. if (! empty ( $month ) && is_numeric ( $month ))
  6004. $con .= ' and Month(printTime)="' . $month . '" ';
  6005. if ($status == 'UNRECORD')
  6006. $con .= ' and printStatus=1 and untreadStatus=0';
  6007. elseif ($status == 'RECORD')
  6008. $con .= ' and printStatus=1 and untreadStatus=3';
  6009. elseif ($status == 'BOUNCED')
  6010. $con .= ' and untreadStatus=2';
  6011. elseif ($status == 'PARTRECORD')
  6012. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  6013. elseif ($status == 'All') {
  6014. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  6015. }
  6016. if (! empty ( $sid ) && is_numeric ( $sid ))
  6017. $con .= ' and sid=' . $sid;
  6018. if (! empty ( $cid ) && is_numeric ( $cid ))
  6019. $con .= ' and cid=' . $cid;
  6020. else
  6021. $con .= ' and cid in (' . $cidString . ')';
  6022. // 开票内容筛选
  6023. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  6024. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  6025. }
  6026. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  6027. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  6028. if (! empty ( $titleORno )) {
  6029. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  6030. }
  6031. $pageinfo ['page'] = array (
  6032. 'previous' => ''
  6033. );
  6034. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  6035. $limit = $pageinfo ['lower'] . ',' . $page_size;
  6036. // 应收款合计
  6037. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  6038. //,'desc','desc','printTime'
  6039. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  6040. $totalPrice=array('invoicePrice'=>0.00,'receivePrice'=>0.00,'receivablesPrice'=>0.00);
  6041. foreach ($list as $key=>$value){
  6042. $totalPrice['invoicePrice']=bcadd($totalPrice['invoicePrice'], $value['invoicePrice'],2);
  6043. if($value['sumPrice']!=0){
  6044. $totalPrice['receivePrice']=bcadd($totalPrice['receivePrice'], $value['sumPrice'],2);
  6045. }
  6046. if($value['diffPrice']!=0){
  6047. $totalPrice['receivablesPrice']=bcadd($totalPrice['receivablesPrice'], $value['diffPrice'],2);
  6048. }
  6049. }
  6050. $this->data ['totalPrice'] = $totalPrice;
  6051. $monthHtml = "";
  6052. if ($year != "ALL") {
  6053. for($i = 1; $i <= 12; $i ++) {
  6054. if ($i == $month)
  6055. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  6056. else
  6057. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  6058. }
  6059. }
  6060. $this->data ['monthHtml'] = $monthHtml;
  6061. $this->data ['year'] = $year;
  6062. $this->data ['month'] = $month;
  6063. $this->data ['ics'] = $ics;
  6064. $this->data ['cidKey'] = $cidKey;
  6065. $this->data ['sid'] = $sid;
  6066. $this->data ['staffDetail'] = $staffDetail;
  6067. $this->data ['staffList'] = $staffList;
  6068. $this->data ['titleORnoEn'] = $titleORno;
  6069. $this->data ['titleORno'] = urlencode ( $titleORno );
  6070. $this->data ['invoiceDetail'] = array (
  6071. 'invoiceElement' => $invoiceElement
  6072. );
  6073. $this->data ['page'] = $pageinfo;
  6074. $this->data ['get'] = $get;
  6075. $this->data ['list'] = $list;
  6076. $this->data ['status'] = $status;
  6077. $this->data ['categoryList'] = $categoryList;
  6078. $this->data ['memu'] = "invoice";
  6079. $this->data ['staff'] = $this->staff;
  6080. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  6081. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  6082. }
  6083. /**
  6084. * 获取一条收款信息
  6085. */
  6086. function ajaxGetInvoiceReceivables() {
  6087. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  6088. Doo::loadModel ( 'invoiceReceivables' );
  6089. $invoiceReceivables = new invoiceReceivables ();
  6090. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  6091. echo json_encode ( array (
  6092. 'status' => 1,
  6093. 'detail' => $detail
  6094. ) );
  6095. }
  6096. /**
  6097. * 异步获取办事处用户
  6098. */
  6099. function ajaxGetStaffByCategory() {
  6100. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  6101. Doo::loadModel ( 'staff' );
  6102. $staff = new staff ();
  6103. if ($cid == "PUBLIC") {
  6104. echo json_encode ( array (
  6105. 'status' => 1,
  6106. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  6107. ) );
  6108. die ();
  6109. }
  6110. if (! is_numeric ( $cid )) {
  6111. echo json_encode ( array (
  6112. 'status' => 0,
  6113. 'msg' => 'illegal request'
  6114. ) );
  6115. die ();
  6116. }
  6117. $staffList = $staff->getStaffByCid ( $cid );
  6118. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6119. foreach ( $staffList as $key => $value ) {
  6120. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6121. }
  6122. echo json_encode ( array (
  6123. 'status' => 1,
  6124. 'html' => $html
  6125. ) );
  6126. }
  6127. /**
  6128. * 异步获取一条发票的邮寄信息
  6129. */
  6130. function ajaxGetInvoicePostDetail() {
  6131. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6132. Doo::loadModel ( 'invoice' );
  6133. $invoice = new invoice ();
  6134. $iid = $invoice->authcode ( $iid );
  6135. Doo::loadModel ( 'express' );
  6136. $express = new express ();
  6137. $expressList = $express->getExpressByAll ();
  6138. if (! is_numeric ( $iid )) {
  6139. echo json_encode ( array (
  6140. 'status' => 0,
  6141. 'msg' => 'illegal request'
  6142. ) );
  6143. die ();
  6144. }
  6145. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6146. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6147. $html = "";
  6148. foreach ( $expressList as $key => $value ) {
  6149. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6150. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6151. else
  6152. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6153. }
  6154. $invoiceDetail ['eaHtml'] = $html;
  6155. echo json_encode ( array (
  6156. 'status' => 1,
  6157. 'invoiceDetail' => $invoiceDetail
  6158. ) );
  6159. }
  6160. /**
  6161. *
  6162. * @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 ) ); }
  6163. */
  6164. /**
  6165. *
  6166. * @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 ) ); }
  6167. */
  6168. /**
  6169. * 我的收款中 选择哪个发票入账,进行金额判断
  6170. */
  6171. function ajaxCompareInvoicePrice() {
  6172. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6173. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6174. Doo::loadModel ( 'invoice' );
  6175. $invoice = new invoice ();
  6176. Doo::loadModel ( 'invoiceReceivables' );
  6177. $invoiceReceivables = new invoiceReceivables ();
  6178. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6179. $keyList = explode ( ';', $claimKey );
  6180. $receivablesPrice = 0;
  6181. foreach ( $keyList as $key => $value ) {
  6182. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6183. $receivablesPrice += $detailM ['receivablesPrice'];
  6184. }
  6185. if ($receivablesPrice > $detail ['invoicePrice']) {
  6186. $price = $receivablesPrice - $detail ['invoicePrice'];
  6187. echo json_encode ( array (
  6188. 'status' => 1,
  6189. 'price' => $price
  6190. ) );
  6191. } else
  6192. echo json_encode ( array (
  6193. 'status' => 2
  6194. ) );
  6195. }
  6196. /**
  6197. * 获得打印发票
  6198. */
  6199. function ajaxGetInvoiceInfoByPrint() {
  6200. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6201. if (empty ( $serial )) {
  6202. echo json_encode ( array (
  6203. 'status' => 2,
  6204. 'msg' => 'illegal request'
  6205. ) );
  6206. die ();
  6207. }
  6208. Doo::loadModel ( 'invoice' );
  6209. $invoice = new invoice ();
  6210. Doo::loadModel ( 'invoiceOperationLog' );
  6211. $invoiceOperationLog = new invoiceOperationLog ();
  6212. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6213. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6214. Doo::loadModel ( 'invoicePaper' );
  6215. $invoicePaper = new invoicePaper ();
  6216. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6217. if (empty ( $detail ))
  6218. $html = '';
  6219. else {
  6220. $html = '
  6221. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6222. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6223. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6224. <div class="modal-dialog modal-lg">
  6225. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6226. <div class="modal-body saeaList">
  6227. <table class="table table-bordered table-condensed"><tbody>
  6228. <tr>
  6229. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6230. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6231. </tr>
  6232. <tr>
  6233. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6234. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6235. </tr>
  6236. <tr>
  6237. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6238. </td>
  6239. </tr>
  6240. <tr>
  6241. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6242. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6243. </tr>
  6244. <tr>
  6245. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6246. </tr></tbody></table>';
  6247. if ($detail ['invoiceType'] == 0)
  6248. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6249. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6250. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6251. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6252. </tr>';
  6253. else
  6254. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6255. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6256. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6257. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6258. ';
  6259. $html .= '<tr>
  6260. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6261. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6262. </tr>
  6263. <tr>
  6264. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6265. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6266. </tr></tbody></table>';
  6267. if ($detail ['doPost'] == 1)
  6268. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6269. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6270. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6271. </tr><tr>
  6272. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6273. </tr><tr>
  6274. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6275. </tr></tbody></table>';
  6276. if (! empty ( $invoiceOperationLogList )) {
  6277. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6278. foreach ( $invoiceOperationLogList as $key => $value ) {
  6279. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6280. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6281. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6282. if ($value ['status'] == 2) {
  6283. $html .= '<span class="colGreen">同意</span>';
  6284. } elseif ($value ['status'] == 3) {
  6285. $html .= '<span class="colOrange">退回</span>';
  6286. } elseif ($value ['status'] == 5) {
  6287. $html .= '<span class="colGreen">打印</span>';
  6288. } elseif ($value ['status'] == 4) {
  6289. $html .= '<span class="colRed">终止</span>';
  6290. }
  6291. $html .= $value ['operation'] . '</p></blockquote>';
  6292. }
  6293. }
  6294. $html .= '</td>
  6295. <td><span class="colRed">*</span>
  6296. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6297. foreach ( $invoicePaperList as $key => $value ) {
  6298. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6299. }
  6300. $html .= '</select>
  6301. <span class="red" id="p-msg"></span>
  6302. </td>
  6303. </tr></tbody></table>';
  6304. }
  6305. $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>
  6306. </div></div></form>
  6307. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6308. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6309. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6310. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6311. ';
  6312. }
  6313. echo json_encode ( array (
  6314. 'status' => 1,
  6315. 'html' => $html
  6316. ) );
  6317. die ();
  6318. }
  6319. /**
  6320. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6321. */
  6322. function ajaxGetInvoiceInfoByType() {
  6323. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6324. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6325. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6326. // include Doo::conf()->BASE_PATH.'diagnostic/debug.php';
  6327. if (empty ( $serial )) {
  6328. echo json_encode ( array (
  6329. 'status' => 2,
  6330. 'msg' => 'illegal request'
  6331. ) );
  6332. die ();
  6333. }
  6334. if ($type == 'INVOICE') {
  6335. Doo::loadModel ( 'invoice' );
  6336. $invoice = new invoice ();
  6337. Doo::loadModel ( 'invoiceOperationLog' );
  6338. $invoiceOperationLog = new invoiceOperationLog ();
  6339. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6340. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6341. if (empty ( $detail ))
  6342. $html = '';
  6343. else {
  6344. $html = '
  6345. <div class="modal-dialog modal-lg">
  6346. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6347. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6348. <tr>
  6349. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6350. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6351. </tr>
  6352. <tr>
  6353. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6354. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6355. </tr>
  6356. <tr>
  6357. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6358. </td>
  6359. </tr>
  6360. <tr>
  6361. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6362. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6363. </tr>
  6364. <tr>
  6365. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6366. </tr>';
  6367. if ($detail ['settlementType'] == 1)
  6368. $html .= '<tr>
  6369. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6370. </tr>';
  6371. else
  6372. $html .= '<tr>
  6373. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6374. </tr>';
  6375. $html .= ' </tbody></table>';
  6376. if ($detail ['invoiceType'] == 0){
  6377. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6378. <tr><th colspan="4" class="taC">增值税普通发票';
  6379. if($detail ['invoiceForm']==1){
  6380. $html .= '( <span class="colRed">电子发票</span> )';
  6381. }
  6382. $html .= '</th></tr><tr>
  6383. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6384. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6385. </tr>';
  6386. }else{
  6387. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6388. <tr><th colspan="4" class="taC">增值税专用发票';
  6389. if($detail ['invoiceForm']==1){
  6390. $html .= '( <span class="colRed">电子发票</span> )';
  6391. }
  6392. $html .= '</th></tr><tr>
  6393. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6394. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6395. ';
  6396. }
  6397. $html .= '<tr>
  6398. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6399. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6400. </tr>
  6401. <tr>
  6402. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6403. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6404. </tr>
  6405. <tr>
  6406. <th class="taC">发票号</th><td>' . $detail ['invoiceNo'] . '</td>
  6407. <th class="taC"></th><td></td>
  6408. </tr>
  6409. </tbody></table>';
  6410. if ($detail ['doPost'] == 1) {
  6411. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6412. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6413. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6414. </tr><tr>
  6415. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6416. </tr><tr>
  6417. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6418. </tr>
  6419. ';
  6420. if ($detail ['expressCom'] == 'SF')
  6421. $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>';
  6422. else
  6423. $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>';
  6424. $html .= '</tbody></table>';
  6425. }
  6426. if ($detail ['invoiceForm'] == 1) {
  6427. $html .= '<table class="table table-bordered table-condensed">
  6428. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6429. <tr>
  6430. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6431. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6432. </tr></tbody></table>';
  6433. }
  6434. if (! empty ( $invoiceOperationLogList )) {
  6435. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6436. foreach ( $invoiceOperationLogList as $key => $value ) {
  6437. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6438. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6439. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6440. if ($value ['status'] == 2) {
  6441. $html .= '<span class="colGreen">同意</span>';
  6442. } elseif ($value ['status'] == 3) {
  6443. $html .= '<span class="colOrange">退回</span>';
  6444. } elseif ($value ['status'] == 5) {
  6445. $html .= '<span class="colGreen">打印</span>';
  6446. } elseif ($value ['status'] == 4) {
  6447. $html .= '<span class="colRed">终止</span>';
  6448. }
  6449. $html .= $value ['operation'] . '</p></blockquote>';
  6450. }
  6451. }
  6452. $html .= '</td></tr></tbody></table>';
  6453. }
  6454. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6455. }
  6456. echo json_encode ( array (
  6457. 'status' => 1,
  6458. 'html' => $html
  6459. ) );
  6460. die ();
  6461. } elseif ($type == 'RECEIVABLES') {
  6462. Doo::loadModel ( 'invoiceReceivables' );
  6463. $invoiceReceivables = new invoiceReceivables ();
  6464. Doo::loadModel ( 'invoiceRefund' );
  6465. $invoiceRefund = new invoiceRefund ();
  6466. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6467. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6468. if (empty ( $detail ))
  6469. $html = '';
  6470. else {
  6471. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6472. <table class="table table-bordered table-condensed">
  6473. <tbody><tr>
  6474. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6475. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6476. </tr><tr>
  6477. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6478. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6479. </tr>
  6480. <tr>
  6481. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6482. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6483. </tr>
  6484. <tr>
  6485. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6486. </tr>
  6487. </tbody></table>';
  6488. if (! empty ( $ireList )) {
  6489. $html .= '
  6490. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6491. <tr>
  6492. <th class="taC">退款单位名称</th>
  6493. <th class="taC">退款的账号</th>
  6494. <th class="taC">退款金额</th>
  6495. <th class="taC">退款</th>
  6496. <th class="taC">备注</th>
  6497. </tr>
  6498. ';
  6499. foreach ( $ireList as $key => $value ) {
  6500. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6501. $html .= '<tr>
  6502. <td>' . $value ['refundCompany'] . '</td>
  6503. <td>' . $value ['refundNumber'] . '</td>
  6504. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6505. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6506. <td>' . $value ['refundRemarks'] . '</td>
  6507. </tr>
  6508. ';
  6509. }
  6510. }
  6511. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6512. }
  6513. echo json_encode ( array (
  6514. 'status' => 1,
  6515. 'html' => $html
  6516. ) );
  6517. die ();
  6518. } elseif ($type == 'IRTC') {
  6519. Doo::loadModel ( 'invoice' );
  6520. $invoice = new invoice ();
  6521. Doo::loadModel ( 'invoiceOperationLog' );
  6522. $invoiceOperationLog = new invoiceOperationLog ();
  6523. // Doo::loadModel ( 'invoiceReceivables' );
  6524. // $invoiceReceivables = new invoiceReceivables ();
  6525. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6526. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6527. if (empty ( $detail ))
  6528. $html = '';
  6529. else {
  6530. $receivablesPriceedHtml = '';
  6531. $receivablesPrice = $detail ['invoicePrice'];
  6532. if (! empty ( $detail ['irid'] )) {
  6533. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6534. // if (empty ( $irList ))
  6535. // $irList [0] ['sumPrice'] = 0;
  6536. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6537. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6538. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6539. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6540. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6541. </tr></tbody></table>';
  6542. $receivablesPrice = $detail ['invoiceBalance'];
  6543. }
  6544. if ($loss)
  6545. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6546. $html = $receivablesPriceedHtml . '
  6547. <table class="table table-bordered table-condensed"><tbody>
  6548. <tr>
  6549. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6550. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6551. </tr>
  6552. <tr>
  6553. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6554. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6555. </tr>
  6556. <tr>
  6557. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6558. </tr>
  6559. <tr>
  6560. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6561. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6562. </tr>
  6563. <tr>
  6564. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6565. </tr></tbody></table>';
  6566. if ($detail ['invoiceType'] == 0) {
  6567. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6568. <tr><th colspan="4" class="taC">增值税普通发票';
  6569. if($detail ['invoiceForm']==1){
  6570. $html .= '( <span class="colRed">电子发票</span> )';
  6571. }
  6572. $html.='</th></tr><tr>
  6573. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6574. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6575. </tr>';
  6576. $receivablesMessage = $detail ['invoiceTitle'];
  6577. } else {
  6578. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6579. <tr><th colspan="4" class="taC">增值税专用发票';
  6580. if($detail ['invoiceForm']==1){
  6581. $html .= '( <span class="colRed">电子发票</span> )';
  6582. }
  6583. $html .= '</th></tr><tr>
  6584. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6585. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6586. ';
  6587. $receivablesMessage = $detail ['invoiceCompany'];
  6588. }
  6589. $html .= '<tr>
  6590. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6591. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6592. </tr>
  6593. <tr>
  6594. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6595. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6596. </tr></tbody></table>';
  6597. if ($detail ['doPost'] == 1)
  6598. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6599. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6600. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6601. </tr><tr>
  6602. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6603. </tr><tr>
  6604. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6605. </tr></tbody></table>';
  6606. if (! empty ( $invoiceOperationLogList )) {
  6607. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6608. foreach ( $invoiceOperationLogList as $key => $value ) {
  6609. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6610. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6611. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6612. if ($value ['status'] == 2) {
  6613. $html .= '<span class="colGreen">同意</span>';
  6614. } elseif ($value ['status'] == 3) {
  6615. $html .= '<span class="colOrange">退回</span>';
  6616. } elseif ($value ['status'] == 5) {
  6617. $html .= '<span class="colGreen">打印</span>';
  6618. }
  6619. $html .= $value ['operation'] . '</p></blockquote>';
  6620. }
  6621. }
  6622. $html .= '</td></tr></tbody></table>';
  6623. }
  6624. }
  6625. echo json_encode ( array (
  6626. 'status' => 1,
  6627. 'html' => $html,
  6628. 'receivablesPrice' => $receivablesPrice,
  6629. 'receivablesMessage' => $receivablesMessage,
  6630. 'receivablesDate' => date ( "Y-m-d" ),
  6631. 'iidKey' => $serial
  6632. ) );
  6633. die ();
  6634. }
  6635. }
  6636. function ajaxGetInvoiceReceivablesByStaff() {
  6637. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6638. if (empty ( $postData )) {
  6639. echo json_encode ( array (
  6640. 'status' => 2,
  6641. 'msg' => 'illegal request'
  6642. ) );
  6643. die ();
  6644. }
  6645. Doo::loadModel ( 'invoiceReceivables' );
  6646. $invoiceReceivables = new invoiceReceivables ();
  6647. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6648. if (empty ( $detail )) {
  6649. echo json_encode ( array (
  6650. 'status' => 2,
  6651. 'msg' => 'illegal request'
  6652. ) );
  6653. die ();
  6654. }
  6655. Doo::loadModel ( 'L_category' );
  6656. $lCategory = new L_category ();
  6657. Doo::loadModel ( 'staff' );
  6658. $staff = new staff ();
  6659. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6660. $category = $lCategory->getCategory ();
  6661. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6662. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6663. foreach ( $category as $key => $value ) {
  6664. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6665. if ($value ['cid'] == $detail ['cid'])
  6666. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6667. }
  6668. foreach ( $staffList as $key => $value ) {
  6669. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6670. if ($value ['sid'] == $detail ['sid'])
  6671. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6672. }
  6673. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6674. echo json_encode ( array (
  6675. 'status' => 1,
  6676. 'categoryHtml' => $categoryHtml,
  6677. 'staffHtml' => $staffHtml,
  6678. 'rbankHtml' => $rbankHtml,
  6679. 'detail' => $detail
  6680. ) );
  6681. }
  6682. function ajaxGetInvoiceReceivablesByIrid() {
  6683. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6684. if (empty ( $irid )) {
  6685. echo json_encode ( array (
  6686. 'status' => 2,
  6687. 'msg' => 'illegal request'
  6688. ) );
  6689. die ();
  6690. }
  6691. Doo::loadModel ( 'invoiceReceivables' );
  6692. $invoiceReceivables = new invoiceReceivables ();
  6693. Doo::loadModel ( 'invoice' );
  6694. $invoice = new invoice ();
  6695. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6696. $flag = true;
  6697. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6698. $bakDetail = array ();
  6699. if ($flag === false) {
  6700. array_push ( $bakDetail, $invoiceDetail );
  6701. $invoiceDetail = $bakDetail;
  6702. }
  6703. $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>
  6704. <tr>
  6705. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6706. <td>' . $detail ['receivablesMessage'] . '</td>
  6707. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6708. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6709. <td>' . $detail ['recepitTitleMark'] . '</td>
  6710. </tr></tbody></table>';
  6711. $isInvoice = false;
  6712. $invoiceHtml = '';
  6713. if (empty ( $invoiceDetail )) {
  6714. $isInvoice = true;
  6715. } else {
  6716. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6717. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6718. foreach ( $invoiceDetail as $key => $value ) {
  6719. $invoiceHtml .= '<tr>';
  6720. if (! empty ( $value ['invoiceType'] )) {
  6721. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6722. } else {
  6723. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6724. }
  6725. if (! empty ( $value ['invoiceType'] )) {
  6726. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6727. } else {
  6728. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6729. }
  6730. $invoiceHtml .= '
  6731. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6732. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6733. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6734. </tr>
  6735. ';
  6736. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6737. if (empty ( $irList ))
  6738. $irList [0] ['sumPrice'] = 0;
  6739. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6740. $priceString = '';
  6741. if ($balance < $detail ['receivablesPrice']) {
  6742. $priceString = '收款金额超过开票金额,';
  6743. }
  6744. if ($balance > $detail ['receivablesPrice']) {
  6745. $priceString = '收款金额低于开票金额,';
  6746. }
  6747. }
  6748. $invoiceHtml .= '
  6749. <script>
  6750. $(\'a[bind-receivables^="ir"]\').click(function() {
  6751. var data = $(this).attr("data-ikey");
  6752. $("input[name=\'invoiceKey\']").val(data);
  6753. var invoiceKey=data;
  6754. if(invoiceKey==""){
  6755. alert("入账错误,请重新刷新页面");
  6756. return false;
  6757. }
  6758. if(window.confirm("' . $priceString . '确定入账吗?")){
  6759. $("#IBR").submit();
  6760. }else{
  6761. return false;
  6762. }
  6763. });
  6764. </script>
  6765. ';
  6766. $invoiceHtml .= '</tbody></table>';
  6767. }
  6768. echo json_encode ( array (
  6769. 'status' => 1,
  6770. 'irkey' => $detail ['iridEn'],
  6771. 'receivablesHtml' => $receivablesHtml,
  6772. 'isInvoice' => $isInvoice,
  6773. 'invoiceHtml' => $invoiceHtml
  6774. ) );
  6775. }
  6776. function ajaxGetInvoiceReceivablesByTitle() {
  6777. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6778. if (empty ( $title )) {
  6779. echo json_encode ( array (
  6780. 'status' => 2,
  6781. 'msg' => 'illegal request'
  6782. ) );
  6783. die ();
  6784. }
  6785. Doo::loadModel ( 'invoice' );
  6786. $invoice = new invoice ();
  6787. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6788. $invoiceHtml = '';
  6789. if (! empty ( $invoiceDetail )) {
  6790. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6791. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6792. foreach ( $invoiceDetail as $key => $value ) {
  6793. if (! empty ( $value ['invoiceType'] )) {
  6794. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6795. } else {
  6796. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6797. }
  6798. if (! empty ( $value ['invoiceType'] )) {
  6799. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6800. } else {
  6801. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6802. }
  6803. $invoiceHtml .= '
  6804. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6805. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6806. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6807. </tr>
  6808. ';
  6809. }
  6810. $invoiceHtml .= '</tbody></table>
  6811. <script>
  6812. $(\'a[bind-receivables^="ir"]\').click(function() {
  6813. var data = $(this).attr("data-ikey");
  6814. $("input[name=\'invoiceKey\']").val(data);
  6815. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6816. if(invoiceKey==""){
  6817. alert("入账错误,请重新刷新页面");
  6818. return false;
  6819. }
  6820. if(window.confirm("确定入账吗?")){
  6821. $("#IBR").submit();
  6822. }else{
  6823. return false;
  6824. }
  6825. });
  6826. </script>
  6827. ';
  6828. }
  6829. echo json_encode ( array (
  6830. 'status' => 1,
  6831. 'invoiceHtml' => $invoiceHtml
  6832. ) );
  6833. }
  6834. function ajaxInvoicePushNotice() {
  6835. Doo::loadModel ( 'invoice' );
  6836. $invoice = new invoice ();
  6837. $approval = $invoice->getOne ( array (
  6838. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6839. 'desc' => 'iid',
  6840. 'asArray' => true
  6841. ) );
  6842. $isNotice = false;
  6843. if (! empty ( $approval ))
  6844. $isNotice = true;
  6845. $response = array (
  6846. 'error' => 0,
  6847. 'isNotice' => $isNotice
  6848. );
  6849. echo json_encode ( $response );
  6850. exit ();
  6851. }
  6852. public function ajaxCheckInvoiceNoUniqueness() {
  6853. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6854. Doo::loadModel ( 'invoice' );
  6855. $invoice = new invoice ();
  6856. if (! empty ( $invoiceNo )) {
  6857. Doo::loadModel ( 'invoicePaper' );
  6858. $invoicePaper = new invoicePaper ();
  6859. Doo::loadClass ( 'XDeode' );
  6860. $XDeode = new XDeode ( 5 );
  6861. $ipid = $XDeode->decode ( $invoiceNo );
  6862. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6863. $info = $invoice->getOne ( array (
  6864. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6865. 'asArray' => TRUE
  6866. ) );
  6867. if (! empty ( $info )) {
  6868. echo json_encode ( array (
  6869. 'error' => '发票号已存在'
  6870. ) );
  6871. die ();
  6872. } else
  6873. echo json_encode ( array (
  6874. 'ok' => '可以使用!'
  6875. ) );
  6876. die ();
  6877. }
  6878. }
  6879. function ajaxCheckInvoicePrice() {
  6880. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6881. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6882. Doo::loadModel ( 'invoice' );
  6883. $invoice = new invoice ();
  6884. Doo::loadModel ( 'invoiceReceivables' );
  6885. $invoiceReceivables = new invoiceReceivables ();
  6886. Doo::loadClass ( 'XDeode' );
  6887. $XDeode = new XDeode ( 5 );
  6888. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6889. $iidKey = $XDeode->decode ( $iidKey );
  6890. $info = $invoice->getInvoiceByIid ( $iidKey );
  6891. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6892. if (empty ( $irList ))
  6893. $irList [0] ['sumPrice'] = 0;
  6894. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6895. if ($balance < $receivablesPrice) {
  6896. echo json_encode ( array (
  6897. 'error' => '收款金额超过开票金额。'
  6898. ) );
  6899. die ();
  6900. }
  6901. if ($balance > $receivablesPrice) {
  6902. echo json_encode ( array (
  6903. 'error' => '收款金额低于开票金额。'
  6904. ) );
  6905. die ();
  6906. }
  6907. }
  6908. }
  6909. function ajaxGetInvoiceByNew() {
  6910. Doo::loadModel ( 'invoice' );
  6911. $invoice = new invoice ();
  6912. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6913. echo json_encode ( array (
  6914. 'status' => 1,
  6915. 'detail' => $detail
  6916. ) );
  6917. }
  6918. /**
  6919. * 旧输入导入
  6920. */
  6921. function importInvoice() {
  6922. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6923. $data ['emsg'] = "";
  6924. if ($emsg != "")
  6925. $data ['emsg'] = "请填写完整的数据";
  6926. $data ['time'] = time ();
  6927. $this->render ( "/admin/invoiceImport", $data );
  6928. }
  6929. function uploadInvoice() {
  6930. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6931. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6932. $file = $_FILES ['Filedata'] ['tmp_name'];
  6933. $error = false;
  6934. if (! is_uploaded_file ( $file )) {
  6935. $error = '400 Bad Request';
  6936. }
  6937. if ($error) {
  6938. header ( 'HTTP/1.0 ' . $error );
  6939. die ( 'Error ' . $error );
  6940. } else {
  6941. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6942. $this->IoHandler = new IoHandler ();
  6943. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6944. // $filedir=$_POST['time'];
  6945. // 调用定义物理路径
  6946. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6947. $this->IoHandler->MakeDir ( $t );
  6948. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6949. if ($filename != 'xlsx')
  6950. return "";
  6951. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6952. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6953. $upload_dir = $t . "/" . $upload_file;
  6954. $k = move_uploaded_file ( $file, $upload_dir );
  6955. if ($k) {
  6956. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6957. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6958. }
  6959. }
  6960. }
  6961. }
  6962. function importInvoiceDo() {
  6963. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6964. if ($path != "") {
  6965. Doo::loadModel ( 'invoice' );
  6966. Doo::loadModel ( 'staff' );
  6967. $staff = new staff ();
  6968. Doo::loadModel ( 'invoiceStatistics' );
  6969. Doo::loadModel ( 'invoiceOperationLog' );
  6970. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6971. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6972. // print_r ( $exlArray );
  6973. // die ();
  6974. // echo json_encode($exlArray);die;
  6975. foreach ( $exlArray as $key => $value ) {
  6976. // 开票
  6977. $invoice = new invoice ();
  6978. $invoice->invoiceNo = $value ['invoiceNo'];
  6979. $invoice->invoiceType = 0;
  6980. if ($value ['invoiceType'] == '专')
  6981. $invoice->invoiceType = 1;
  6982. $invoice->invoicePrice = $value ['invoicePrice'];
  6983. $invoice->invoiceQuantity = 1;
  6984. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6985. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6986. if ($value ['invoiceType'] == '专')
  6987. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6988. $invoice->userName = $value ['userName'];
  6989. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6990. $invoice->sid = $sDetail ['sid'];
  6991. $invoice->cid = $sDetail ['cid'];
  6992. $invoice->categoryName = $sDetail ['category'];
  6993. $invoice->invoiceElement = $value ['invoiceElement'];
  6994. $invoice->remark = $value ['remark'];
  6995. $invoice->date = $value ['date'];
  6996. $invoice->printTime = $value ['date'];
  6997. $invoice->ipSource = 1;
  6998. $invoice->printStatus = 1;
  6999. $invoice->status = 2;
  7000. $invoice->postStatus = 1;
  7001. $invoice->untreadStatus = 0;
  7002. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  7003. $iid = $invoice->insert ();
  7004. // 汇总
  7005. $invoiceStatistics = new invoiceStatistics ();
  7006. //
  7007. $item = array (
  7008. 'date' => $value ['date'],
  7009. 'priceClass' => 1,
  7010. 'cid' => $sDetail ['cid'],
  7011. 'staff' => $sDetail ['sid'],
  7012. 'invoicePrice' => $value ['invoicePrice']
  7013. );
  7014. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7015. $invoiceOperationLog = new invoiceOperationLog ();
  7016. $item = array (
  7017. 'date' => date ( "Y-m-d H:i:s" ),
  7018. 'operation' => date ( "Y-m-d" ) . " 导入",
  7019. 'status' => 1,
  7020. 'img' => $sDetail ['avatar'],
  7021. 'username' => $sDetail ['username'],
  7022. 'uid' => $sDetail ['sid'],
  7023. 'category' => $sDetail ['category'],
  7024. 'iid' => $iid
  7025. );
  7026. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  7027. }
  7028. return '/importInvoice?count=' . count ( $exlArray );
  7029. // return "/keyonline";
  7030. }
  7031. echo 'no file';
  7032. }
  7033. function importInvoiceReceivables() {
  7034. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  7035. $data ['emsg'] = "";
  7036. if ($emsg != "")
  7037. $data ['emsg'] = "请填写完整的数据";
  7038. $data ['time'] = time ();
  7039. $this->render ( "/admin/invoiceReceivablesImport", $data );
  7040. }
  7041. // 导入入账数据
  7042. function importInvoiceReceivablesDo() {
  7043. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  7044. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  7045. if ($path != "") {
  7046. Doo::loadModel ( 'invoiceReceivables' );
  7047. Doo::loadModel ( 'invoice' );
  7048. Doo::loadModel ( 'staff' );
  7049. $staff = new staff ();
  7050. Doo::loadModel ( 'invoiceStatistics' );
  7051. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  7052. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  7053. // print_r ( $exlArray );
  7054. // die ();
  7055. // echo json_encode($exlArray);die;
  7056. foreach ( $exlArray as $key => $value ) {
  7057. // 收款
  7058. $invoiceReceivables = new invoiceReceivables ();
  7059. $invoice = new invoice ();
  7060. $invoiceReceivables->bindStatus = 1;
  7061. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  7062. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  7063. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  7064. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  7065. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  7066. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  7067. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  7068. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  7069. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  7070. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  7071. $invoiceReceivables->iid = $iDetail ['iid'];
  7072. $irid = $invoiceReceivables->insert ();
  7073. // 发票绑定收款
  7074. $detail = $iDetail;
  7075. $iridString = "";
  7076. if (empty ( $detail ['irid'] ))
  7077. $iridString = $irid;
  7078. else
  7079. $iridString = $detail ['irid'] . ',' . $irid;
  7080. $item = array (
  7081. 'irid' => $iridString,
  7082. 'iid' => $detail ['iid']
  7083. );
  7084. $invoice->setInvoiceByCondition ( $item );
  7085. // 汇总
  7086. $invoiceStatistics = new invoiceStatistics ();
  7087. // 扣除入账统计金额
  7088. $item = array (
  7089. 'date' => $value ['receivablesDate'],
  7090. 'priceClass' => 3,
  7091. 'cid' => $sDetail ['cid'],
  7092. 'staff' => $sDetail ['sid'],
  7093. // 'irid' => $irid,
  7094. 'accountPrice' => $value ['receivablesPrice']
  7095. );
  7096. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7097. }
  7098. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  7099. echo 'data count ' . count ( $exlArray );
  7100. die ();
  7101. // return "/keyonline";
  7102. }
  7103. echo 'no file';
  7104. }
  7105. function formatExcelToArrayTrain($file_url = "") {
  7106. if (! file_exists ( $file_url )) {
  7107. return array ();
  7108. }
  7109. // Doo::loadClass ( 'PHPExcel' );
  7110. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7111. $PHPExcel = new PHPExcel ();
  7112. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7113. if (! $PHPReader->canRead ( $file_url )) {
  7114. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7115. if (! $PHPReader->canRead ( $file_url )) {
  7116. echo 'no Excel';
  7117. return;
  7118. }
  7119. }
  7120. $PHPExcel = $PHPReader->load ( $file_url );
  7121. /* * 读取excel文件中的第一个工作表 */
  7122. $currentSheet = $PHPExcel->getSheet ( 0 );
  7123. /* * 取得最大的列号 */
  7124. $allColumn = $currentSheet->getHighestColumn ();
  7125. /* * 取得一共有多少行 */
  7126. $allRow = $currentSheet->getHighestRow ();
  7127. $excel_array = array ();
  7128. // die($file_url);
  7129. $conk = 2;
  7130. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7131. $excel_column = array ();
  7132. // 后期改进
  7133. if ($allColumn == 'AM')
  7134. $allColumn = 'Z';
  7135. /* * 从第A列开始输出 */
  7136. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7137. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7138. if ($val instanceof PHPExcel_RichText)
  7139. $val = $val->__toString ();
  7140. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7141. // $val = "'" . addslashes ( $val ) . "'";
  7142. if ($currentColumn == 'A') {
  7143. $excel_column ['invoiceTitle'] = $val;
  7144. } elseif ($currentColumn == 'B')
  7145. $excel_column ['invoiceType'] = $val;
  7146. elseif ($currentColumn == 'C') {
  7147. $excel_column ['TIN'] = $val;
  7148. } elseif ($currentColumn == 'D') {
  7149. $excel_column ['address'] = $val;
  7150. } elseif ($currentColumn == 'E') {
  7151. $excel_column ['phone'] = $val;
  7152. } elseif ($currentColumn == 'F') {
  7153. $excel_column ['bank'] = $val;
  7154. } elseif ($currentColumn == 'G') {
  7155. $excel_column ['bankAccount'] = $val;
  7156. } elseif ($currentColumn == 'H') {
  7157. $excel_column ['invoiceElement'] = $val;
  7158. } elseif ($currentColumn == 'I') {
  7159. $excel_column ['invoiceQuantity'] = $val;
  7160. } elseif ($currentColumn == 'J') {
  7161. $excel_column ['invoiceUnitPrice'] = $val;
  7162. } elseif ($currentColumn == 'K') {
  7163. $excel_column ['remark'] = $val;
  7164. } elseif ($currentColumn == 'L') {
  7165. $excel_column ['recipientsAddress'] = $val;
  7166. } elseif ($currentColumn == 'M') {
  7167. $excel_column ['recipients'] = $val;
  7168. } elseif ($currentColumn == 'N') {
  7169. $excel_column ['recipientsPhone'] = $val;
  7170. }elseif ($currentColumn == 'O') {
  7171. $excel_column ['electronicPhone'] = $val;
  7172. } elseif ($currentColumn == 'P') {
  7173. $excel_column ['electronicEmail'] = $val;
  7174. }
  7175. }
  7176. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7177. array_push ( $excel_array, $excel_column );
  7178. }
  7179. return $excel_array;
  7180. }
  7181. /**
  7182. * 格式化excel文件为数组
  7183. * @param unknown_type $file_url
  7184. * @param unknown_type $mcid
  7185. */
  7186. function _format_excel_to_array($file_url = "", $sType = "") {
  7187. if (! file_exists ( $file_url )) {
  7188. return array ();
  7189. }
  7190. Doo::loadClass ( 'PHPExcel' );
  7191. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7192. $PHPExcel = new PHPExcel ();
  7193. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7194. if (! $PHPReader->canRead ( $file_url )) {
  7195. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7196. if (! $PHPReader->canRead ( $file_url )) {
  7197. echo 'no Excel';
  7198. return;
  7199. }
  7200. }
  7201. $PHPExcel = $PHPReader->load ( $file_url );
  7202. /* * 读取excel文件中的第一个工作表 */
  7203. $currentSheet = $PHPExcel->getSheet ( 0 );
  7204. /* * 取得最大的列号 */
  7205. $allColumn = $currentSheet->getHighestColumn ();
  7206. /* * 取得一共有多少行 */
  7207. $allRow = $currentSheet->getHighestRow ();
  7208. $excel_array = array ();
  7209. // die($file_url);
  7210. $conk = 2;
  7211. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7212. $excel_column = array ();
  7213. // 后期改进
  7214. if ($allColumn == 'AM')
  7215. $allColumn = 'Z';
  7216. /* * 从第A列开始输出 */
  7217. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7218. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7219. if ($val instanceof PHPExcel_RichText)
  7220. $val = $val->__toString ();
  7221. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7222. // $val = "'" . addslashes ( $val ) . "'";
  7223. if ($sType == 'invoiceReceivables') {
  7224. if ($currentColumn == 'A')
  7225. $excel_column ['invoiceNo'] = $val;
  7226. elseif ($currentColumn == 'B')
  7227. $excel_column ['receivablesPrice'] = $val;
  7228. elseif ($currentColumn == 'C') {
  7229. $excel_column ['receivablesMessage'] = $val;
  7230. } elseif ($currentColumn == 'D') {
  7231. $excel_column ['receivablesBank'] = $val;
  7232. } elseif ($currentColumn == 'E') {
  7233. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7234. } elseif ($currentColumn == 'F') {
  7235. $excel_column ['receivablesStaff'] = $val;
  7236. } elseif ($currentColumn == 'G') {
  7237. $excel_column ['sourcePrice'] = $val;
  7238. }
  7239. } elseif ($sType == "invoiceTrain") {
  7240. if ($currentColumn == 'A') {
  7241. $excel_column ['invoiceTitle'] = $val;
  7242. } elseif ($currentColumn == 'B')
  7243. $excel_column ['invoiceType'] = $val;
  7244. elseif ($currentColumn == 'C') {
  7245. $excel_column ['TIN'] = $val;
  7246. } elseif ($currentColumn == 'D') {
  7247. $excel_column ['address'] = $val;
  7248. } elseif ($currentColumn == 'E') {
  7249. $excel_column ['phone'] = $val;
  7250. } elseif ($currentColumn == 'F') {
  7251. $excel_column ['bank'] = $val;
  7252. } elseif ($currentColumn == 'G') {
  7253. $excel_column ['bankAccount'] = $val;
  7254. } elseif ($currentColumn == 'H') {
  7255. $excel_column ['invoiceElement'] = $val;
  7256. } elseif ($currentColumn == 'I') {
  7257. $excel_column ['invoiceQuantity'] = $val;
  7258. } elseif ($currentColumn == 'J') {
  7259. $excel_column ['invoiceUnitPrice'] = $val;
  7260. } elseif ($currentColumn == 'K') {
  7261. $excel_column ['remark'] = $val;
  7262. } elseif ($currentColumn == 'L') {
  7263. $excel_column ['recipientsAddress'] = $val;
  7264. } elseif ($currentColumn == 'M') {
  7265. $excel_column ['recipients'] = $val;
  7266. } elseif ($currentColumn == 'N') {
  7267. $excel_column ['recipientsPhone'] = $val;
  7268. }
  7269. } else {
  7270. if ($currentColumn == 'A')
  7271. $excel_column ['invoiceNo'] = $val;
  7272. elseif ($currentColumn == 'B')
  7273. $excel_column ['invoiceType'] = $val;
  7274. elseif ($currentColumn == 'C') {
  7275. $excel_column ['invoicePrice'] = $val;
  7276. } elseif ($currentColumn == 'D') {
  7277. $excel_column ['invoiceTitle'] = $val;
  7278. } elseif ($currentColumn == 'E') {
  7279. $excel_column ['userName'] = $val;
  7280. } elseif ($currentColumn == 'F') {
  7281. $excel_column ['categoryName'] = $val;
  7282. } elseif ($currentColumn == 'G') {
  7283. $excel_column ['invoiceElement'] = $val;
  7284. } elseif ($currentColumn == 'H') {
  7285. $excel_column ['remark'] = $val;
  7286. } elseif ($currentColumn == 'I') {
  7287. $excel_column ['date'] = $this->excelTime ( $val );
  7288. }
  7289. }
  7290. }
  7291. array_push ( $excel_array, $excel_column );
  7292. }
  7293. return $excel_array;
  7294. }
  7295. function excelTime($date, $time = false) {
  7296. if (function_exists ( 'GregorianToJD' )) {
  7297. if (is_numeric ( $date )) {
  7298. $jd = GregorianToJD ( 1, 1, 1970 );
  7299. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7300. $date = explode ( '/', $gregorian );
  7301. $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" : '');
  7302. return $date_str;
  7303. }
  7304. } else {
  7305. $date = $date > 25568 ? $date + 1 : 25569;
  7306. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7307. $ofs = (70 * 365 + 17 + 2) * 86400;
  7308. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7309. }
  7310. return $date;
  7311. }
  7312. /**
  7313. * 旧输入导入
  7314. */
  7315. function _GetFileEXT($filename) {
  7316. $pics = explode ( '.', $filename );
  7317. $num = count ( $pics );
  7318. return $pics [$num - 1];
  7319. }
  7320. function showCache($path = "", $sid = 0) {
  7321. // if (file_exists ( $path )) {
  7322. // $htm = file_get_contents ( $path );
  7323. // } else {
  7324. Doo::loadModel ( 'invoiceStatistics' );
  7325. $invoiceStatistics = new invoiceStatistics ();
  7326. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7327. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7328. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7329. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7330. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7331. /*
  7332. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7333. */
  7334. file_put_contents ( $path, $htm );
  7335. // }
  7336. return $htm;
  7337. }
  7338. /**
  7339. * 生成token
  7340. * @return string
  7341. */
  7342. function set_token() {
  7343. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7344. $str = sha1 ( $str ); // 加密
  7345. return $str;
  7346. }
  7347. /**
  7348. * 获取get或者POST值
  7349. *
  7350. * @param string $name 属性名称
  7351. * @return fixed 值
  7352. */
  7353. function get_args($name) {
  7354. if (isset ( $_GET [$name] )) {
  7355. if (is_array ( $_GET [$name] ))
  7356. return $_GET [$name];
  7357. else
  7358. return addslashes ( $_GET [$name] );
  7359. } elseif (isset ( $_POST [$name] )) {
  7360. if (is_array ( $_POST [$name] ))
  7361. return $_POST [$name];
  7362. else
  7363. return addslashes ( $_POST [$name] );
  7364. } else
  7365. return false;
  7366. }
  7367. function SafeFilter(&$arr) {
  7368. $ra = Array (
  7369. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7370. '/script/',
  7371. '/javascript/',
  7372. '/vbscript/',
  7373. '/expression/',
  7374. '/applet/',
  7375. '/meta/',
  7376. '/xml/',
  7377. '/blink/',
  7378. '/link/',
  7379. '/style/',
  7380. '/embed/',
  7381. '/object/',
  7382. '/frame/',
  7383. '/layer/',
  7384. '/title/',
  7385. '/bgsound/',
  7386. '/base/',
  7387. '/onload/',
  7388. '/onunload/',
  7389. '/onchange/',
  7390. '/onsubmit/',
  7391. '/onreset/',
  7392. '/onselect/',
  7393. '/onblur/',
  7394. '/onfocus/',
  7395. '/onabort/',
  7396. '/onkeydown/',
  7397. '/onkeypress/',
  7398. '/onkeyup/',
  7399. '/onclick/',
  7400. '/ondblclick/',
  7401. '/onmousedown/',
  7402. '/onmousemove/',
  7403. '/onmouseout/',
  7404. '/onmouseover/',
  7405. '/onmouseup/',
  7406. '/onunload/'
  7407. );
  7408. if (is_array ( $arr )) {
  7409. foreach ( $arr as $key => $value ) {
  7410. if (! is_array ( $value )) {
  7411. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7412. {
  7413. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7414. }
  7415. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7416. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7417. } else {
  7418. SafeFilter ( $arr [$key] );
  7419. }
  7420. }
  7421. }
  7422. }
  7423. /**
  7424. * Escape String
  7425. *
  7426. * @access public
  7427. * @param string
  7428. * @param bool whether or not the string will be used in a LIKE condition
  7429. * @return string
  7430. */
  7431. function escape_str($str, $like = FALSE) {
  7432. if (is_array ( $str )) {
  7433. foreach ( $str as $key => $val ) {
  7434. $str [$key] = $this->escape_str ( $val, $like );
  7435. }
  7436. return $str;
  7437. }
  7438. var_dump ( Doo::db ()->getDbObject () );
  7439. die ();
  7440. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7441. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7442. } elseif (function_exists ( 'mysql_escape_string' )) {
  7443. $str = mysql_escape_string ( $str );
  7444. } else {
  7445. $str = addslashes ( $str );
  7446. }
  7447. // escape LIKE condition wildcards
  7448. if ($like === TRUE) {
  7449. $str = str_replace ( array (
  7450. '%',
  7451. '_'
  7452. ), array (
  7453. '\\%',
  7454. '\\_'
  7455. ), $str );
  7456. }
  7457. return $str;
  7458. }
  7459. /**
  7460. * 获得分页数据
  7461. * @param unknown_type $table
  7462. * @param unknown_type $condition
  7463. * @param unknown_type $on_page
  7464. * @param unknown_type $page_size
  7465. */
  7466. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7467. $page_c = "";
  7468. $page ['previous'] = $this->get_previous ( $on_page );
  7469. $page ['on_page'] = $on_page;
  7470. $total_count = $this->get_table_count ( $table, $condition );
  7471. $total = intval ( $total_count / $page_size );
  7472. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7473. $page ['total_data'] = $total_count;
  7474. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7475. $i = 1;
  7476. $page_max = 1;
  7477. $page_width = 3;
  7478. if ($on_page >= $page_width) {
  7479. $page_max = intval ( $on_page / $page_width ) + 1;
  7480. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7481. }
  7482. for(; $i <= $page ['total_page']; $i ++) {
  7483. if ($i == $on_page)
  7484. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7485. else
  7486. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7487. if ($i == ($page_width * $page_max))
  7488. break;
  7489. }
  7490. $page ['page'] = $page_c;
  7491. $page ['lower'] = (-- $on_page) * $page_size;
  7492. return $page;
  7493. }
  7494. /**
  7495. * 获取上一页
  7496. * @param unknown_type $on_page
  7497. */
  7498. function get_previous($on_page = 1) {
  7499. return $on_page != 0 ? $on_page - 1 : $on_page;
  7500. }
  7501. /**
  7502. * 获取总页数
  7503. * @param unknown_type $table
  7504. * @param unknown_type $condition
  7505. */
  7506. public function get_table_count($table = "", $condition = "") {
  7507. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7508. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7509. // echo $sql;die;
  7510. $query = Doo::db ()->query ( $sql );
  7511. $result = $query->fetch ();
  7512. return $result ['count'];
  7513. }
  7514. function isInvoiceNew($type = "GLOBAL") {
  7515. Doo::loadModel ( 'invoice' );
  7516. $invoice = new invoice ();
  7517. Doo::loadModel ( 'invoiceReceivables' );
  7518. $invoiceReceivables = new invoiceReceivables ();
  7519. Doo::loadModel ( 'staff' );
  7520. $staff = new staff ();
  7521. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7522. // 我的发票待处理
  7523. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7524. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7525. 'desc' => 'iid',
  7526. 'asArray' => TRUE
  7527. ) );
  7528. // 我的收款待入账
  7529. /*
  7530. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7531. */
  7532. // 发票审批
  7533. $approval = $invoice->getOne ( array (
  7534. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7535. 'desc' => 'iid',
  7536. 'asArray' => true
  7537. ) );
  7538. // 发票邮寄
  7539. $post = $invoice->getOne ( array (
  7540. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7541. 'asArray' => TRUE
  7542. ) );
  7543. // 发票打印
  7544. $print = $invoice->getOne ( array (
  7545. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7546. 'desc' => 'iid',
  7547. 'asArray' => TRUE
  7548. ) );
  7549. // 发票退票 printStatus=1 and
  7550. $untread = $invoice->getOne ( array (
  7551. 'where' => " untreadStatus=1 and status=2 ",
  7552. 'asArray' => TRUE
  7553. ) );
  7554. $new = array (
  7555. 'GLOBAL' => FALSE,
  7556. 'pendingInvoice' => FALSE,
  7557. // 'myClaim' => FALSE,
  7558. 'approval' => FALSE,
  7559. 'post' => FALSE,
  7560. 'print' => FALSE,
  7561. 'untread' => FALSE
  7562. );
  7563. // || ! empty ( $myClaim )
  7564. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7565. $new ['GLOBAL'] = TRUE;
  7566. if (! empty ( $pendingInvoice ))
  7567. $new ['pendingInvoice'] = TRUE;
  7568. // if (! empty ( $myClaim ))
  7569. // $new ['myClaim'] = TRUE;
  7570. if (! empty ( $approval ))
  7571. $new ['approval'] = TRUE;
  7572. if (! empty ( $post ))
  7573. $new ['post'] = TRUE;
  7574. if (! empty ( $print ))
  7575. $new ['print'] = TRUE;
  7576. if (! empty ( $untread ))
  7577. $new ['untread'] = TRUE;
  7578. return $new;
  7579. }
  7580. function setWXMsg($rid, $typeMsg = '') {
  7581. Doo::loadModel ( 'invoice' );
  7582. $invoice = new invoice ();
  7583. $invoiceDetail = $invoice->getOne ( array (
  7584. 'where' => 'iid=' . $rid,
  7585. 'asArray' => true
  7586. ) );
  7587. if (! empty ( $invoiceDetail )) {
  7588. Doo::loadModel ( 'staff' );
  7589. $staff = new staff ();
  7590. $staffmsg = $staff->getOne ( array (
  7591. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7592. 'asArray' => TRUE
  7593. ) );
  7594. if (! empty ( $staffmsg ['wxid'] )) {
  7595. require_once (SITE_PATH . '/protected/class/client.php');
  7596. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7597. $user = $staffmsg ['wxid'];
  7598. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7599. if (empty ( $expCom ))
  7600. $expCom [0] = '';
  7601. $msg = "";
  7602. if (empty ( $typeMsg ))
  7603. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7604. elseif ($typeMsg == "PRINT")
  7605. $msg = '太好了,您的发票已打印完成。';
  7606. $result = $client->SendMsg ( $user, $msg, 'text' );
  7607. }
  7608. }
  7609. }
  7610. /**
  7611. * 获取微信部门
  7612. * @param string $category
  7613. * @return number|mixed
  7614. */
  7615. function getToparty($category = '') {
  7616. $token = $this->getAccessToken (); //
  7617. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7618. $toparty = 0;
  7619. foreach ( $result ['department'] as $key => $value ) {
  7620. if ($value ['name'] == $category)
  7621. $toparty = $value ['id'];
  7622. }
  7623. return $toparty;
  7624. }
  7625. /**
  7626. * 获得某部门下的用户
  7627. * @param string $toparty
  7628. */
  7629. function getUserByToparty($toparty = '') {
  7630. $token = $this->getAccessToken (); //
  7631. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7632. $userList = array ();
  7633. foreach ( $result ['userlist'] as $key => $value ) {
  7634. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7635. }
  7636. return $userList;
  7637. }
  7638. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7639. $token = $this->getAccessToken ();
  7640. if ($text == 'text') {
  7641. $data = '{
  7642. "touser": "' . $toparty . '",
  7643. "toparty": "",
  7644. "totag": "",
  7645. "msgtype": "text",
  7646. "agentid": 1000002,
  7647. "text": {
  7648. "content": "' . $msg . '"
  7649. },
  7650. "safe":0
  7651. }';
  7652. }
  7653. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7654. if ($result->errmsg != 'ok') {
  7655. return 0;
  7656. } else {
  7657. return 1;
  7658. }
  7659. }
  7660. /**
  7661. * 获得可以发送微信用户列表
  7662. * @param string $category
  7663. * @return string
  7664. */
  7665. function getWxidByCategory($category = "") {
  7666. if (empty ( $category ))
  7667. return "";
  7668. Doo::loadModel ( 'staff' );
  7669. $staff = new staff ();
  7670. $toparty = $this->getToparty ( $category );
  7671. $wxList = array ();
  7672. $wxString = "";
  7673. if (! empty ( $toparty )) {
  7674. $userList = $this->getUserByToparty ( $toparty );
  7675. $userCon = implode ( ',', $userList );
  7676. // echo $userCon;
  7677. $sidList = $staff->getStaffByWxid ( $userCon );
  7678. foreach ( $sidList as $key => $value ) {
  7679. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7680. if ($falg) {
  7681. array_push ( $wxList, $value ['wxid'] );
  7682. }
  7683. }
  7684. $wxString = implode ( '|', $wxList );
  7685. }
  7686. return $wxString;
  7687. }
  7688. /**
  7689. * 读取发送信息规则判断是否需要发送
  7690. * @param number $sid
  7691. * @param string $sendType
  7692. * @return boolean
  7693. */
  7694. function isSendNotification($sid = 0, $sendType = '') {
  7695. Doo::loadModel ( "notificationConf" );
  7696. $notificationConf = new notificationConf ();
  7697. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7698. $conf = array ();
  7699. $sendFlag = true;
  7700. if (! empty ( $detail )) {
  7701. $conf = json_decode ( $detail ['conf'], true );
  7702. if (! empty ( $sendType )) {
  7703. if (isset ( $conf [$sendType] )) {
  7704. if ($conf [$sendType] == "CLOSE")
  7705. $sendFlag = false;
  7706. elseif ($conf [$sendType] == "Weekend") {
  7707. $day = date ( "w" );
  7708. if (1 <= $day && 5 >= $day)
  7709. $sendFlag = false;
  7710. } elseif ($conf [$sendType] == "OneToFriday") {
  7711. $day = date ( "w" );
  7712. if (0 == $day || 6 == $day)
  7713. $sendFlag = false;
  7714. }
  7715. }
  7716. } else
  7717. $sendFlag = false;
  7718. }
  7719. return $sendFlag;
  7720. }
  7721. /**
  7722. * 根据规则发送信息
  7723. * @param unknown $msg
  7724. * @param unknown $title
  7725. * @param unknown $url
  7726. * @param unknown $user
  7727. * @param string $text
  7728. * @return number
  7729. */
  7730. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7731. $token = $this->getAccessToken ();
  7732. $falg = $this->isSendNotification ( $sid, $sendType );
  7733. // if ($text == 'text') {
  7734. // $data = '{
  7735. // "touser": "' . $user . '",
  7736. // "toparty": "",
  7737. // "totag": "",
  7738. // "msgtype": "text",
  7739. // "agentid": 1000002,
  7740. // "text": {
  7741. // "content": "' . $msg . '"
  7742. // },
  7743. // "safe":0
  7744. // }';
  7745. // } else {
  7746. $data = '{
  7747. "touser": "' . $user . '",
  7748. "toparty": "",
  7749. "totag": "",
  7750. "msgtype": "news",
  7751. "agentid": 1000002,
  7752. "news": {
  7753. "articles":[
  7754. {
  7755. "title": "' . $title . '",
  7756. "description": "' . $msg . '",
  7757. "url": "' . $url . '",
  7758. "picurl": ""
  7759. }
  7760. ]
  7761. }
  7762. }';
  7763. // }
  7764. if ($falg) {
  7765. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7766. if ($result->errmsg != 'ok') {
  7767. return 0;
  7768. } else {
  7769. return 1;
  7770. }
  7771. } else
  7772. return 0;
  7773. }
  7774. private function getAccessToken() {
  7775. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7776. // $file = './access_token.txt';
  7777. // $data = json_decode ( file_get_contents ( $file ) );
  7778. // if ($data->expire_time < time () or ! $data->expire_time) {
  7779. // 如果是企业号用以下URL获取access_token
  7780. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7781. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7782. $res = json_decode ( $this->httpGet ( $url ) );
  7783. $access_token = $res->access_token;
  7784. // echo $access_token;
  7785. // if ($access_token) {
  7786. // $data->expire_time = time () + 7000;
  7787. // $data->access_token = $access_token;
  7788. // $fp = fopen ( $file, "w" );
  7789. // fwrite ( $fp, json_encode ( $data ) );
  7790. // fclose ( $fp );
  7791. // }
  7792. // } else {
  7793. // $access_token = $data->access_token;
  7794. // }
  7795. return $access_token;
  7796. }
  7797. private function httpGet($url) {
  7798. $curl = curl_init ();
  7799. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7800. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7801. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7802. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7803. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7804. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7805. curl_setopt ( $curl, CURLOPT_URL, $url );
  7806. $res = curl_exec ( $curl );
  7807. curl_close ( $curl );
  7808. return $res;
  7809. }
  7810. private function httpPost($url, $data) {
  7811. $curl = curl_init ();
  7812. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7813. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7814. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7815. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7816. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7817. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7818. curl_setopt ( $curl, CURLOPT_URL, $url );
  7819. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7820. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7821. $res = curl_exec ( $curl );
  7822. curl_close ( $curl );
  7823. return $res;
  7824. }
  7825. }
  7826. ?>