InvoiceController.php 297 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. // print_r($myInvoiceUnAccount);
  203. $this->data ['isMonth'] = $isMonth;
  204. $this->data ['htm'] = $htm;
  205. $this->data ['invoiceList'] = $invoiceList;
  206. $this->data ['receivablesList'] = $list;
  207. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  208. $this->data ['memu'] = "invoice";
  209. $this->data ['staff'] = $this->staff;
  210. $this->data ['receiptMemu'] = 'invoice';
  211. $this->render ( "/admin/invoice", $this->data );
  212. }
  213. function invoiceExpress() {
  214. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  215. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  216. $this->data ['expressCom'] = $expressCom;
  217. $this->data ['expressNumber'] = $expressNumber;
  218. $this->render ( "/admin/invoiceExpress", $this->data );
  219. }
  220. function invoiceAdd() {
  221. Doo::loadModel ( 'L_category' );
  222. $lCategory = new L_category ();
  223. $category = $lCategory->find ( array (
  224. 'asArray' => true
  225. ) );
  226. $this->data ['category'] = $category;
  227. $this->data ['memu'] = "invoice";
  228. $this->data ['staff'] = $this->staff;
  229. $this->data ['receiptMemu'] = 'invoice';
  230. $this->render ( "/admin/invoiceAdd", $this->data );
  231. }
  232. /**
  233. * 提交一份开票申请,并记录下操作日志
  234. *
  235. * @since 1.0.0
  236. * @var integer cid 办事处ID
  237. * @var integer invoiceType 发票类型
  238. * @var integer doPost 是否邮寄
  239. * @var integer invoicePrice 开票金额
  240. * @var string invoiceElement 开票内容
  241. * @var string invoiceTitle 发票抬头
  242. * @var string invoiceCompany 单位名称
  243. * @var string TIN 纳税人识别码
  244. * @var string address 注册地址
  245. * @var string phone 注册电话
  246. * @var string bank 开户银行
  247. * @var string bankAccount 银行账户
  248. * @var string recipients 收件人
  249. * @var string recipientsPhone 收件人手机/电话
  250. * @var string recipientsAddress 收件地址
  251. * @var string mailItems 邮寄物品
  252. * @var string remark 备注
  253. * @return string 返回跳转开票主页路径
  254. */
  255. function invoiceAddDo() {
  256. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  257. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  258. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  259. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  260. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  261. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  262. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  263. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  264. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  265. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  266. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  267. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  268. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  269. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  270. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  271. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  272. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  273. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  274. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  275. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  276. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  277. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  278. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  279. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  280. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  281. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  282. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  283. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  284. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  285. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  286. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  287. /*
  288. * $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;
  289. */
  290. if (empty ( $this->staff [0] ))
  291. die ( 'illegal request' );
  292. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  293. Doo::loadModel ( 'invoice' );
  294. $invoice = new invoice ();
  295. Doo::loadModel ( 'L_category' );
  296. $lCategory = new L_category ();
  297. Doo::loadModel ( 'invoiceManage' );
  298. $invoiceManage = new invoiceManage ();
  299. Doo::loadModel ( 'invoiceOperationLog' );
  300. $invoiceOperationLog = new invoiceOperationLog ();
  301. $categoryDetil = $lCategory->getOne ( array (
  302. 'SELECT' => 'title',
  303. 'where' => 'cid=' . $cid,
  304. 'asArray' => true
  305. ) );
  306. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  307. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  308. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  309. // print_r(current($invoiceManageDetail ['staffList']));
  310. // die;
  311. $moldManage = array ();
  312. foreach ( $invoiceManageList as $key => $value ) {
  313. if ($value ['mold'] == '发票打印')
  314. $moldManage [$value ['mold']] = $value ['staffList'];
  315. elseif ($value ['mold'] == '发票邮寄')
  316. $moldManage [$value ['mold']] = $value ['staffList'];
  317. elseif ($value ['mold'] == '发票退票')
  318. $moldManage [$value ['mold']] = $value ['staffList'];
  319. }
  320. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  321. $item = array (
  322. 'cid' => $cid,
  323. 'categoryName' => $categoryDetil ['title'],
  324. 'invoiceElement' => $invoiceElement,
  325. 'invoiceQuantity' => $invoiceQuantity,
  326. 'invoiceUnitPrice' => $invoiceUnitPrice,
  327. 'invoicePrice' => $invoicePrice,
  328. 'invoiceType' => $invoiceType,
  329. 'doPost' => $doPost,
  330. 'status' => 1,
  331. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  332. 'date' => date ( "Y-m-d H:i:s" ),
  333. 'updateTime' => date ( "Y-m-d H:i:s" ),
  334. 'sid' => $this->staff [0] ['sid'],
  335. 'userName' => $this->staff [0] ['username'],
  336. 'invoiceManage' => $invoiceManageDetail ['staff'],
  337. 'pendingApprovals' => $pendingApprovalsSid,
  338. 'moldManage' => json_encode ( $moldManage ),
  339. 'remark' => $remark
  340. );
  341. if ($invoiceType == 0)
  342. $item += array (
  343. 'invoiceTitle' => $invoiceTitle,
  344. 'TIN' => $TINT,
  345. 'address' => $addressT,
  346. 'phone' => $phoneT,
  347. 'bank' => $bankT,
  348. 'bankAccount' => $bankAccountT
  349. );
  350. else {
  351. $item += array (
  352. 'invoiceCompany' => $invoiceCompany,
  353. 'TIN' => $TIN,
  354. 'address' => $address,
  355. 'phone' => $phone,
  356. 'bank' => $bank,
  357. 'bankAccount' => $bankAccount
  358. );
  359. }
  360. if ($doPost == 1) {
  361. $mailList = array (
  362. 'invoice' => 1,
  363. 'mailItems' => $mailItems
  364. );
  365. if (! empty ( $softLock ))
  366. $mailList += array (
  367. 'softLock' => $softLockNum
  368. );
  369. else
  370. $mailList += array (
  371. 'softLock' => 0
  372. );
  373. if (! empty ( $contract ))
  374. $mailList += array (
  375. 'contract' => $contractNum
  376. );
  377. else
  378. $mailList += array (
  379. 'contract' => 0
  380. );
  381. if (! empty ( $instructions ))
  382. $mailList += array (
  383. 'instructions' => $instructionsNum
  384. );
  385. else
  386. $mailList += array (
  387. 'instructions' => 0
  388. );
  389. if (! empty ( $remittance ))
  390. $mailList += array (
  391. 'remittance' => $remittance
  392. );
  393. else
  394. $mailList += array (
  395. 'remittance' => ''
  396. );
  397. $mailString = '发票x1,备注:' . $mailItems;
  398. if (! empty ( $softLock ))
  399. $mailString .= ',软件锁x' . $softLockNum;
  400. if (! empty ( $contract ))
  401. $mailString .= ',合同x' . $contractNum;
  402. if (! empty ( $instructions ))
  403. $mailString .= ',说明书x' . $instructionsNum;
  404. if (! empty ( $remittance ))
  405. $mailString .= ',汇款账号单';
  406. $item += array (
  407. 'recipients' => $recipients,
  408. 'recipientsPhone' => $recipientsPhone,
  409. 'recipientsAddress' => $recipientsAddress,
  410. 'mailItems' => $mailString,
  411. 'mailItemsJson' => json_encode ( $mailList )
  412. );
  413. }
  414. $iid = $invoice->addInvoice ( $item );
  415. $item = array (
  416. 'date' => date ( "Y-m-d H:i:s" ),
  417. 'operation' => "创建",
  418. 'status' => 1,
  419. 'img' => $this->staff [0] ['avatar'],
  420. 'username' => $this->staff [0] ['username'],
  421. 'uid' => $this->staff [0] ['sid'],
  422. 'category' => $this->staff [0] ['category'],
  423. 'iid' => $iid
  424. );
  425. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  426. $item = array (
  427. 'date' => date ( "Y-m-d H:i:s" ),
  428. 'operation' => "提交审批",
  429. 'status' => 1,
  430. 'img' => $this->staff [0] ['avatar'],
  431. 'username' => $this->staff [0] ['username'],
  432. 'uid' => $this->staff [0] ['sid'],
  433. 'category' => $this->staff [0] ['category'],
  434. 'iid' => $iid
  435. );
  436. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  437. Doo::loadModel ( 'staff' );
  438. $staff = new staff ();
  439. $username2 = $staff->getOne ( array (
  440. 'select' => 'wxid',
  441. 'where' => 'sid=' . $pendingApprovalsSid,
  442. 'asArray' => TRUE
  443. ) );
  444. // 发送微信审批通知
  445. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  446. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  447. }
  448. return "/invoice";
  449. }
  450. function invoiceEdit() {
  451. Doo::loadClass ( 'XDeode' );
  452. $XDeode = new XDeode ( 5 );
  453. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  454. $iid = $XDeode->decode ( $iid );
  455. if (! is_numeric ( $iid ))
  456. die ( 'illegal request' );
  457. Doo::loadModel ( 'invoice' );
  458. $invoice = new invoice ();
  459. Doo::loadModel ( 'invoiceOperationLog' );
  460. $invoiceOperationLog = new invoiceOperationLog ();
  461. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  462. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  463. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  464. $this->data ['operation'] = $operation;
  465. $this->data ['invoiceDetail'] = $invoiceDetail;
  466. $this->data ['memu'] = "invoice";
  467. $this->data ['staff'] = $this->staff;
  468. $this->data ['receiptMemu'] = 'invoice';
  469. $this->render ( "/admin/invoiceEdit", $this->data );
  470. }
  471. /**
  472. * 重新编辑退回的发票
  473. * @return string
  474. */
  475. function invoiceEditDo() {
  476. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  477. Doo::loadModel ( 'invoice' );
  478. $invoice = new invoice ();
  479. $iid = $invoice->authcode ( $iidKey );
  480. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  481. die ( 'illegal request' );
  482. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  483. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  484. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  485. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  486. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  487. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  488. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  489. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  490. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  491. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  492. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  493. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  494. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  495. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  496. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  497. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  498. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  499. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  500. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  501. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  502. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  503. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  504. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  505. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  506. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  507. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  508. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  509. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  510. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  511. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  512. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  513. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  514. Doo::loadModel ( 'invoiceManage' );
  515. $invoiceManage = new invoiceManage ();
  516. Doo::loadModel ( 'invoiceOperationLog' );
  517. $invoiceOperationLog = new invoiceOperationLog ();
  518. $cid = explode ( ':', $cid );
  519. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  520. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  521. $moldManage = array ();
  522. foreach ( $invoiceManageList as $key => $value ) {
  523. if ($value ['mold'] == '发票打印')
  524. $moldManage [$value ['mold']] = $value ['staffList'];
  525. elseif ($value ['mold'] == '发票邮寄')
  526. $moldManage [$value ['mold']] = $value ['staffList'];
  527. elseif ($value ['mold'] == '发票打印')
  528. $moldManage [$value ['mold']] = $value ['staffList'];
  529. }
  530. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  531. $item = array (
  532. 'iid' => $iid,
  533. 'cid' => $cid [0],
  534. 'categoryName' => $cid [1],
  535. 'invoiceElement' => $invoiceElement,
  536. 'invoiceQuantity' => $invoiceQuantity,
  537. 'invoiceUnitPrice' => $invoiceUnitPrice,
  538. 'invoicePrice' => $invoicePrice,
  539. 'invoiceType' => $invoiceType,
  540. 'doPost' => $doPost,
  541. 'status' => 1,
  542. 'updateTime' => date ( "Y-m-d H:i:s" ),
  543. 'remark' => $remark
  544. );
  545. if ($invoiceType == 0)
  546. $item += array (
  547. 'invoiceTitle' => $invoiceTitle,
  548. 'TIN' => $TINT,
  549. 'address' => $addressT,
  550. 'phone' => $phoneT,
  551. 'bank' => $bankT,
  552. 'bankAccount' => $bankAccountT
  553. );
  554. else {
  555. $item += array (
  556. 'invoiceCompany' => $invoiceCompany,
  557. 'TIN' => $TIN,
  558. 'address' => $address,
  559. 'phone' => $phone,
  560. 'bank' => $bank,
  561. 'bankAccount' => $bankAccount
  562. );
  563. }
  564. if ($doPost == 1) {
  565. $mailList = array (
  566. 'invoice' => 1,
  567. 'mailItems' => $mailItems
  568. );
  569. if (! empty ( $softLock ))
  570. $mailList += array (
  571. 'softLock' => $softLockNum
  572. );
  573. else
  574. $mailList += array (
  575. 'softLock' => '0'
  576. );
  577. if (! empty ( $contract ))
  578. $mailList += array (
  579. 'contract' => $contractNum
  580. );
  581. else
  582. $mailList += array (
  583. 'contract' => '0'
  584. );
  585. if (! empty ( $instructions ))
  586. $mailList += array (
  587. 'instructions' => $instructionsNum
  588. );
  589. else
  590. $mailList += array (
  591. 'instructions' => '0'
  592. );
  593. if (! empty ( $remittance ))
  594. $mailList += array (
  595. 'remittance' => $remittance
  596. );
  597. else
  598. $mailList += array (
  599. 'remittance' => ''
  600. );
  601. $mailString = '发票x1,备注:' . $mailItems;
  602. if (! empty ( $softLock ))
  603. $mailString .= ',软件锁x' . $softLockNum;
  604. if (! empty ( $contract ))
  605. $mailString .= ',合同x' . $contractNum;
  606. if (! empty ( $instructions ))
  607. $mailString .= ',说明书x' . $instructionsNum;
  608. if (! empty ( $remittance ))
  609. $mailString .= ',汇款账号单';
  610. $item += array (
  611. 'recipients' => $recipients,
  612. 'recipientsPhone' => $recipientsPhone,
  613. 'recipientsAddress' => $recipientsAddress,
  614. 'mailItems' => $mailString,
  615. 'mailItemsJson' => json_encode ( $mailList )
  616. );
  617. }
  618. $invoice->setInvoiceByCondition ( $item );
  619. $item = array (
  620. 'date' => date ( "Y-m-d H:i:s" ),
  621. 'operation' => "重新提交审批",
  622. 'status' => 1,
  623. 'img' => $this->staff [0] ['avatar'],
  624. 'username' => $this->staff [0] ['username'],
  625. 'uid' => $this->staff [0] ['sid'],
  626. 'category' => $this->staff [0] ['category'],
  627. 'iid' => $iid
  628. );
  629. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  630. }
  631. return "/invoice";
  632. }
  633. /**
  634. * 培训班
  635. */
  636. function invoiceTraining() {
  637. Doo::loadModel ( 'L_category' );
  638. $lCategory = new L_category ();
  639. Doo::loadModel ( 'invoiceTraining' );
  640. $invoiceTraining = new invoiceTraining ();
  641. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  642. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  643. $category = $lCategory->getCategory ();
  644. $itid = array ();
  645. foreach ( $itTodoList as $value ) {
  646. array_push ( $itid, $value ['itid'] );
  647. }
  648. foreach ( $itedList as $value ) {
  649. array_push ( $itid, $value ['itid'] );
  650. }
  651. $itid = implode ( ',', $itid );
  652. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  653. // print_r($itTodoList);
  654. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  655. $this->data ['itTodoList'] = $itTodoList;
  656. $this->data ['itedList'] = $itedList;
  657. $this->data ['category'] = $category;
  658. $this->data ['memu'] = "invoice";
  659. $this->data ['staff'] = $this->staff;
  660. $this->data ['receiptMemu'] = 'invoiceTraining';
  661. $this->render ( "/admin/invoiceTraining", $this->data );
  662. }
  663. /**
  664. * 创建培训班
  665. */
  666. function invoiceTrainingAdd() {
  667. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  668. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  669. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  670. if (empty ( $this->staff [0] ))
  671. die ( 'illegal request' );
  672. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  673. Doo::loadModel ( 'invoiceTraining' );
  674. $invoiceTraining = new invoiceTraining ();
  675. Doo::loadModel ( 'invoice' );
  676. $invoice = new invoice ();
  677. Doo::loadModel ( 'L_category' );
  678. $lCategory = new L_category ();
  679. Doo::loadModel ( 'invoiceManage' );
  680. $invoiceManage = new invoiceManage ();
  681. Doo::loadModel ( 'invoiceOperationLog' );
  682. $invoiceOperationLog = new invoiceOperationLog ();
  683. $item = array (
  684. 'cid' => $cid,
  685. 'trainName' => $trainName,
  686. 'trainDate' => $trainDate,
  687. 'creator' => $this->staff [0] ['sid'],
  688. 'creatorDate' => date ( "Y-m-d H:i:s" )
  689. );
  690. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  691. }
  692. return "/invoiceTraining";
  693. }
  694. /**
  695. * 删除培训班
  696. */
  697. function invoiceTrainingDelDo() {
  698. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  699. if (! empty ( $itid )) {
  700. Doo::loadModel ( 'invoiceTraining' );
  701. $invoiceTraining = new invoiceTraining ();
  702. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  703. }
  704. return "/invoiceTraining";
  705. }
  706. /**
  707. * 培训班详情
  708. */
  709. function invoiceTrainingDetail() {
  710. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  711. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  712. Doo::loadModel ( 'invoiceTraining' );
  713. $invoiceTraining = new invoiceTraining ();
  714. Doo::loadModel ( 'invoiceStore' );
  715. $invoiceStore = new invoiceStore ();
  716. if (empty ( $itid ))
  717. die ( 'illegal request' );
  718. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  719. if ($trainStatus == "SUBED")
  720. $con = ' (b.untreadStatus is null ) and ';
  721. elseif ($trainStatus == "APPROVAL")
  722. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  723. elseif ($trainStatus == "TICKET")
  724. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  725. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  726. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  727. // print_r($isList);
  728. $trainlist = array ();
  729. foreach ( $isList as $key => $value ) {
  730. $irDetail = array ();
  731. if ($value ['apStatus'] == 1) {
  732. // array_push ( $irDetail, '' );
  733. array_push ( $irDetail, '<input disabled type="checkbox" >' );
  734. } else {
  735. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  736. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  737. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  738. }
  739. array_push ( $irDetail, $value ['invoiceSerial'] );
  740. if ($value ['invoiceType'] == 1)
  741. array_push ( $irDetail, $value ['invoiceCompany'] );
  742. else
  743. array_push ( $irDetail, $value ['invoiceTitle'] );
  744. array_push ( $irDetail, $value ['TIN'] );
  745. array_push ( $irDetail, $value ['userName'] );
  746. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  747. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  748. } else
  749. array_push ( $irDetail, $value ['mailItems'] );
  750. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  751. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  752. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  753. array_push ( $irDetail, $value ['invoiceElement'] );
  754. array_push ( $irDetail, $value ['invoiceQuantity'] );
  755. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  756. if ($value ['invoiceType'] == 1)
  757. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  758. else
  759. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  760. array_push ( $irDetail, $value ['remark'] );
  761. if ($value ['status'] == 1)
  762. array_push ( $irDetail, '审批中' );
  763. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  764. array_push ( $irDetail, '已出票' );
  765. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  766. array_push ( $irDetail, '已入账' );
  767. else
  768. array_push ( $irDetail, '' );
  769. array_push ( $irDetail, $value ['invoiceNo'] );
  770. array_push ( $irDetail, $value ['printTime'] );
  771. $html = '';
  772. foreach ( $value ['invoiceReceivables'] as $value ) {
  773. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  774. }
  775. array_push ( $irDetail, $html );
  776. array_push ( $trainlist, $irDetail );
  777. }
  778. $trainlistJson = json_encode ( $trainlist );
  779. if (empty ( $detail ))
  780. die ( 'illegal request' );
  781. $this->data ['trainStatus'] = $trainStatus;
  782. $this->data ['itid'] = $itid;
  783. $this->data ['trainlistJson'] = $trainlistJson;
  784. $this->data ['iTrainDetail'] = $detail;
  785. $this->data ['memu'] = "invoice";
  786. $this->data ['staff'] = $this->staff;
  787. $this->data ['receiptMemu'] = 'invoiceTraining';
  788. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  789. }
  790. /**
  791. * 上传培训班发票
  792. * @return string
  793. */
  794. function invoiceTrainingUpload() {
  795. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  796. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  797. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  798. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  799. header ( "HTTP/1.1 500 Internal Server Error" );
  800. echo "POST exceeded maximum allowed size.";
  801. exit ( 0 );
  802. }
  803. // Settings
  804. $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)
  805. $upload_name = "Filedata";
  806. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  807. $extension_whitelist = array (
  808. "doc",
  809. "txt",
  810. "jpg",
  811. "gif",
  812. "png"
  813. ); // Allowed file extensions
  814. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  815. // Other variables
  816. $MAX_FILENAME_LENGTH = 260;
  817. $file_name = "";
  818. $file_extension = "";
  819. $uploadErrors = array (
  820. 0 => "文件上传成功",
  821. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  822. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  823. 3 => "上传的文件仅为部分文件",
  824. 4 => "没有文件上传",
  825. 6 => "缺少临时文件夹"
  826. );
  827. $nk = time ();
  828. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  829. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  830. echo "文件无法保存.";
  831. exit ( 0 );
  832. }
  833. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  834. echo json_encode ( array (
  835. 'filename' => $file_name,
  836. 'id' => $nk
  837. ) );
  838. exit ( 0 );
  839. }
  840. /**
  841. * 导入发票临时仓库
  842. */
  843. function invoiceStoreImport() {
  844. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  845. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  846. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  847. if ($path != "" && ! empty ( $trainingKey )) {
  848. Doo::loadModel ( 'invoiceStore' );
  849. Doo::loadModel ( 'staff' );
  850. $staff = new staff ();
  851. Doo::loadModel ( 'invoiceTraining' );
  852. $invoiceTraining = new invoiceTraining ();
  853. Doo::loadClass ( 'XDeode' );
  854. $XDeode = new XDeode ( 5 );
  855. $itid = $XDeode->decode ( $trainingKey );
  856. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  857. $userName = $this->staff [0] ['username'];
  858. $sDetail = $staff->getStaffByName ( $userName );
  859. // die('sdd');
  860. // 可以优化
  861. foreach ( $exlArray as $key => $value ) {
  862. // 开票
  863. $invoice = new invoiceStore ();
  864. $invoice->trainId = $itid;
  865. $invoice->invoiceType = 0;
  866. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  867. $invoice->invoiceType = 1;
  868. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  869. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  870. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  871. $invoice->invoiceTitle = $value ['invoiceTitle'];
  872. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  873. $invoice->invoiceCompany = $value ['invoiceTitle'];
  874. $invoice->userName = $userName;
  875. $invoice->sid = $sDetail ['sid'];
  876. $invoice->cid = $sDetail ['cid'];
  877. $invoice->categoryName = $sDetail ['category'];
  878. $invoice->invoiceElement = $value ['invoiceElement'];
  879. $invoice->remark = $value ['remark'];
  880. // $invoice->date = $value ['date'];
  881. // $invoice->printTime = $value ['date'];
  882. $invoice->ipSource = 1;
  883. $invoice->printStatus = 1;
  884. $invoice->status = 2;
  885. $invoice->postStatus = 1;
  886. $invoice->untreadStatus = 0;
  887. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  888. $invoice->TIN = $value ['TIN'];
  889. $invoice->address = $value ['address'];
  890. $invoice->phone = $value ['phone'];
  891. $invoice->bank = $value ['bank'];
  892. $invoice->bankAccount = $value ['bankAccount'];
  893. $invoice->recipientsAddress = $value ['recipientsAddress'];
  894. $invoice->recipients = $value ['recipients'];
  895. $invoice->recipientsPhone = $value ['recipientsPhone'];
  896. $iid = $invoice->insert ();
  897. }
  898. // 加入发票总数量
  899. $item = array (
  900. 'itid' => $itid,
  901. 'invoiceTotal' => count ( $exlArray )
  902. );
  903. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  904. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  905. }
  906. echo 'no file';
  907. }
  908. /**
  909. * 编辑仓库里的发票
  910. */
  911. function invoiceStoreEdit() {
  912. Doo::loadClass ( 'XDeode' );
  913. $XDeode = new XDeode ( 5 );
  914. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  915. $iid = $XDeode->decode ( $iid );
  916. if (! is_numeric ( $iid ))
  917. die ( 'illegal request' );
  918. Doo::loadModel ( 'invoiceStore' );
  919. $invoiceStore = new invoiceStore ();
  920. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  921. // print_r($invoiceDetail);
  922. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  923. $this->data ['invoiceDetail'] = $invoiceDetail;
  924. $this->data ['memu'] = "invoice";
  925. $this->data ['staff'] = $this->staff;
  926. $this->data ['receiptMemu'] = 'invoiceTraining';
  927. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  928. }
  929. function invoiceStoreEditDo() {
  930. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  931. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  932. Doo::loadModel ( 'invoiceStore' );
  933. $invoice = new invoiceStore ();
  934. Doo::loadClass ( 'XDeode' );
  935. $XDeode = new XDeode ( 5 );
  936. $iid = $XDeode->decode ( $storeKey );
  937. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  938. die ( 'illegal request' );
  939. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  940. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  941. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  942. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  943. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  944. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  945. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  946. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  947. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  948. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  949. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  950. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  951. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  952. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  953. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  954. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  955. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  956. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  957. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  958. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  959. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  960. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  961. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  962. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  963. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  964. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  965. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  966. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  967. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  968. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  969. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  970. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  971. $cid = explode ( ':', $cid );
  972. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  973. $item = array (
  974. 'isid' => $iid,
  975. 'cid' => $cid [0],
  976. 'categoryName' => $cid [1],
  977. 'invoiceElement' => $invoiceElement,
  978. 'invoiceQuantity' => $invoiceQuantity,
  979. 'invoiceUnitPrice' => $invoiceUnitPrice,
  980. 'invoicePrice' => $invoicePrice,
  981. 'invoiceType' => $invoiceType,
  982. 'doPost' => $doPost,
  983. 'status' => 1,
  984. 'updateTime' => date ( "Y-m-d H:i:s" ),
  985. 'remark' => $remark
  986. );
  987. if ($invoiceType == 0)
  988. $item += array (
  989. 'invoiceTitle' => $invoiceTitle,
  990. 'TIN' => $TINT,
  991. 'address' => $addressT,
  992. 'phone' => $phoneT,
  993. 'bank' => $bankT,
  994. 'bankAccount' => $bankAccountT
  995. );
  996. else {
  997. $item += array (
  998. 'invoiceCompany' => $invoiceCompany,
  999. 'TIN' => $TIN,
  1000. 'address' => $address,
  1001. 'phone' => $phone,
  1002. 'bank' => $bank,
  1003. 'bankAccount' => $bankAccount
  1004. );
  1005. }
  1006. if ($doPost == 1) {
  1007. $mailList = array (
  1008. 'invoice' => 1,
  1009. 'mailItems' => $mailItems
  1010. );
  1011. if (! empty ( $softLock ))
  1012. $mailList += array (
  1013. 'softLock' => $softLockNum
  1014. );
  1015. else
  1016. $mailList += array (
  1017. 'softLock' => '0'
  1018. );
  1019. if (! empty ( $contract ))
  1020. $mailList += array (
  1021. 'contract' => $contractNum
  1022. );
  1023. else
  1024. $mailList += array (
  1025. 'contract' => '0'
  1026. );
  1027. if (! empty ( $instructions ))
  1028. $mailList += array (
  1029. 'instructions' => $instructionsNum
  1030. );
  1031. else
  1032. $mailList += array (
  1033. 'instructions' => '0'
  1034. );
  1035. if (! empty ( $remittance ))
  1036. $mailList += array (
  1037. 'remittance' => $remittance
  1038. );
  1039. else
  1040. $mailList += array (
  1041. 'remittance' => ''
  1042. );
  1043. $mailString = '发票x1,备注:' . $mailItems;
  1044. if (! empty ( $softLock ))
  1045. $mailString .= ',软件锁x' . $softLockNum;
  1046. if (! empty ( $contract ))
  1047. $mailString .= ',合同x' . $contractNum;
  1048. if (! empty ( $instructions ))
  1049. $mailString .= ',说明书x' . $instructionsNum;
  1050. if (! empty ( $remittance ))
  1051. $mailString .= ',汇款账号单';
  1052. $item += array (
  1053. 'recipients' => $recipients,
  1054. 'recipientsPhone' => $recipientsPhone,
  1055. 'recipientsAddress' => $recipientsAddress,
  1056. 'mailItems' => $mailString,
  1057. 'mailItemsJson' => json_encode ( $mailList )
  1058. );
  1059. }
  1060. $invoice->setInvoiceStoreByCondition ( $item );
  1061. }
  1062. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1063. }
  1064. /**
  1065. *
  1066. * @return string
  1067. */
  1068. function invoiceStoreDelete() {
  1069. Doo::loadClass ( 'XDeode' );
  1070. $XDeode = new XDeode ( 5 );
  1071. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1072. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1073. $isid = $XDeode->decode ( $iStoreKey );
  1074. $itid = $XDeode->decode ( $trainKey );
  1075. if (! is_numeric ( $isid ))
  1076. die ( 'illegal request' );
  1077. Doo::loadModel ( 'invoiceStore' );
  1078. $invoiceStore = new invoiceStore ();
  1079. $invoiceStore->delete ( array (
  1080. 'where' => 'isid=' . $isid,
  1081. 'limit' => 1
  1082. ) );
  1083. Doo::loadModel ( 'invoiceTraining' );
  1084. $invoiceTraining = new invoiceTraining ();
  1085. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1086. $item = array (
  1087. 'itid' => $itid,
  1088. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1089. );
  1090. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1091. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1092. }
  1093. /**
  1094. * 批量删除库里发票
  1095. */
  1096. function invoiceStoreBatchDelete() {
  1097. Doo::loadClass ( 'XDeode' );
  1098. $XDeode = new XDeode ( 5 );
  1099. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1100. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1101. $tid = $XDeode->decode ( $trainKey );
  1102. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1103. die ( 'illegal request' );
  1104. Doo::loadModel ( 'invoiceStore' );
  1105. $isidKeyList = explode ( ',', $storeKey );
  1106. $isidList = array ();
  1107. foreach ( $isidKeyList as $value ) {
  1108. $isid = $XDeode->decode ( $value );
  1109. if (! empty ( $isid ) && is_numeric ( $isid ))
  1110. array_push ( $isidList, $isid );
  1111. }
  1112. $isidString = implode ( ',', $isidList );
  1113. $invoiceStore = new invoiceStore ();
  1114. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1115. $isidList = array ();
  1116. foreach ( $isList as $key => $value ) {
  1117. if ($value ['apStatus'] == 0)
  1118. array_push ( $isidList, $value ['isid'] );
  1119. }
  1120. $isidString = implode ( ',', $isidList );
  1121. // print_r($isList);
  1122. // echo $isidString;
  1123. $invoiceStore = new invoiceStore ();
  1124. $invoiceStore->delete ( array (
  1125. 'where' => "isid in ( " . $isidString . ")",
  1126. 'asArray' => TRUE
  1127. ) );
  1128. Doo::loadModel ( 'invoiceTraining' );
  1129. $invoiceTraining = new invoiceTraining ();
  1130. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1131. $item = array (
  1132. 'itid' => $tid,
  1133. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1134. );
  1135. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1136. // echo $tid;
  1137. // echo $storeKey;
  1138. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1139. }
  1140. /**
  1141. * 仓库发票提交审批
  1142. * @return string
  1143. */
  1144. function invoiceStoreApproval() {
  1145. Doo::loadClass ( 'XDeode' );
  1146. $XDeode = new XDeode ( 5 );
  1147. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1148. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1149. $isid = $XDeode->decode ( $iStoreKey );
  1150. $trainId = $XDeode->decode ( $trainKey );
  1151. if (! is_numeric ( $isid ))
  1152. die ( 'illegal request' );
  1153. Doo::loadModel ( 'invoiceStore' );
  1154. Doo::loadModel ( 'invoice' );
  1155. $invoice = new invoice ();
  1156. // 加入限制必须填写入开票内容和邮寄物品
  1157. $invoiceStore = new invoiceStore ();
  1158. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1159. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1160. header ( 'Content-Type:text/html;charset=utf-8' );
  1161. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1162. }
  1163. // 拷贝插入一条发票数据
  1164. $invoiceStore = new invoiceStore ();
  1165. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1166. $invoiceStore = new invoiceStore ();
  1167. $item = array (
  1168. 'isid' => $isid,
  1169. 'iid' => $iid,
  1170. 'apStatus' => 1
  1171. );
  1172. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1173. Doo::loadModel ( 'invoiceManage' );
  1174. $invoiceManage = new invoiceManage ();
  1175. Doo::loadModel ( 'invoiceOperationLog' );
  1176. $invoiceOperationLog = new invoiceOperationLog ();
  1177. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1178. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1179. $moldManage = array ();
  1180. foreach ( $invoiceManageList as $key => $value ) {
  1181. if ($value ['mold'] == '发票打印')
  1182. $moldManage [$value ['mold']] = $value ['staffList'];
  1183. elseif ($value ['mold'] == '发票邮寄')
  1184. $moldManage [$value ['mold']] = $value ['staffList'];
  1185. elseif ($value ['mold'] == '发票退票')
  1186. $moldManage [$value ['mold']] = $value ['staffList'];
  1187. }
  1188. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1189. $item = array (
  1190. 'iid' => $iid,
  1191. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1192. 'date' => date ( "Y-m-d H:i:s" ),
  1193. 'status' => 1,
  1194. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1195. 'trainId' => $trainId,
  1196. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1197. 'moldManage' => json_encode ( $moldManage ),
  1198. 'pendingApprovals' => $pendingApprovalsSid
  1199. );
  1200. $invoice->setInvoiceByCondition ( $item );
  1201. Doo::loadModel ( 'invoiceTraining' );
  1202. $invoiceTraining = new invoiceTraining ();
  1203. $item = array (
  1204. 'itid' => $trainId,
  1205. 'submitStatus' => 1
  1206. );
  1207. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1208. $item = array (
  1209. 'date' => date ( "Y-m-d H:i:s" ),
  1210. 'operation' => "创建",
  1211. 'status' => 1,
  1212. 'img' => $this->staff [0] ['avatar'],
  1213. 'username' => $this->staff [0] ['username'],
  1214. 'uid' => $this->staff [0] ['sid'],
  1215. 'category' => $this->staff [0] ['category'],
  1216. 'iid' => $iid
  1217. );
  1218. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1219. $item = array (
  1220. 'date' => date ( "Y-m-d H:i:s" ),
  1221. 'operation' => "提交审批",
  1222. 'status' => 1,
  1223. 'img' => $this->staff [0] ['avatar'],
  1224. 'username' => $this->staff [0] ['username'],
  1225. 'uid' => $this->staff [0] ['sid'],
  1226. 'category' => $this->staff [0] ['category'],
  1227. 'iid' => $iid
  1228. );
  1229. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1230. Doo::loadModel ( 'staff' );
  1231. $staff = new staff ();
  1232. $username2 = $staff->getOne ( array (
  1233. 'select' => 'wxid',
  1234. 'where' => 'sid=' . $pendingApprovalsSid,
  1235. 'asArray' => TRUE
  1236. ) );
  1237. // 发送微信审批通知
  1238. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1239. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1240. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1241. }
  1242. /**
  1243. * 批量提交发票
  1244. * @return string
  1245. */
  1246. function invoiceStoreBatchApproval() {
  1247. Doo::loadClass ( 'XDeode' );
  1248. $XDeode = new XDeode ( 5 );
  1249. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1250. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1251. $trainId = $XDeode->decode ( $trainKey );
  1252. $isidKeyList = explode ( ',', $storeKey );
  1253. $isidList = array ();
  1254. foreach ( $isidKeyList as $value ) {
  1255. $isid = $XDeode->decode ( $value );
  1256. if (! empty ( $isid ) && is_numeric ( $isid ))
  1257. array_push ( $isidList, $isid );
  1258. }
  1259. $isidString = implode ( ',', $isidList );
  1260. if (! is_numeric ( $trainId ))
  1261. die ( 'illegal request' );
  1262. Doo::loadModel ( 'invoiceStore' );
  1263. Doo::loadModel ( 'invoice' );
  1264. // 判断哪些已经加入审批过
  1265. // 加入限制必须填写入开票内容和邮寄物品
  1266. $invoiceStore = new invoiceStore ();
  1267. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1268. foreach ( $isList as $key => $value ) {
  1269. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1270. header ( 'Content-Type:text/html;charset=utf-8' );
  1271. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1272. }
  1273. }
  1274. // 拷贝插入一条发票数据
  1275. $invoiceStore = new invoiceStore ();
  1276. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1277. $invoiceStore = new invoiceStore ();
  1278. $item = array (
  1279. 'apStatus' => 1
  1280. );
  1281. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1282. // 获得正式发票ID
  1283. $invoice = new invoice ();
  1284. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1285. $sqlList = array ();
  1286. $iidString = '';
  1287. $iida = array ();
  1288. foreach ( $iidList as $key => $value ) {
  1289. $sqlList [$value ['isid']] = $value ['iid'];
  1290. array_push ( $iida, $value ['iid'] );
  1291. }
  1292. $iidString = implode ( ',', $iida );
  1293. $ids = implode ( ',', array_keys ( $sqlList ) );
  1294. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1295. foreach ( $sqlList as $id => $ordinal ) {
  1296. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1297. }
  1298. $sql .= "END WHERE isid IN ($ids)";
  1299. $invoiceStore = new invoiceStore ();
  1300. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1301. Doo::loadModel ( 'invoiceManage' );
  1302. $invoiceManage = new invoiceManage ();
  1303. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1304. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1305. $moldManage = array ();
  1306. foreach ( $invoiceManageList as $key => $value ) {
  1307. if ($value ['mold'] == '发票打印')
  1308. $moldManage [$value ['mold']] = $value ['staffList'];
  1309. elseif ($value ['mold'] == '发票邮寄')
  1310. $moldManage [$value ['mold']] = $value ['staffList'];
  1311. elseif ($value ['mold'] == '发票退票')
  1312. $moldManage [$value ['mold']] = $value ['staffList'];
  1313. }
  1314. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1315. // 批量更新发票信息
  1316. $item = array (
  1317. 'date' => date ( "Y-m-d H:i:s" ),
  1318. 'status' => 1,
  1319. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1320. 'trainId' => $trainId,
  1321. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1322. 'moldManage' => json_encode ( $moldManage ),
  1323. 'pendingApprovals' => $pendingApprovalsSid
  1324. );
  1325. $invoice = new invoice ();
  1326. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1327. // 批量更新发票序列号
  1328. $sqlList = array ();
  1329. foreach ( $iida as $value ) {
  1330. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1331. }
  1332. $ids = implode ( ',', array_keys ( $sqlList ) );
  1333. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1334. foreach ( $sqlList as $id => $ordinal ) {
  1335. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1336. }
  1337. $sql .= "END WHERE iid IN ($ids)";
  1338. $invoiceStore = new invoiceStore ();
  1339. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1340. // 批量生产操作日志
  1341. Doo::loadModel ( 'invoiceOperationLog' );
  1342. $sqlList = array ();
  1343. foreach ( $iida as $key => $value ) {
  1344. $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 . '"),
  1345. ("' . 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 . '") ';
  1346. array_push ( $sqlList, $sql );
  1347. }
  1348. $iolSql = implode ( ',', $sqlList );
  1349. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1350. $invoiceOperationLog = new invoiceOperationLog ();
  1351. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1352. Doo::loadModel ( 'invoiceTraining' );
  1353. $invoiceTraining = new invoiceTraining ();
  1354. $item = array (
  1355. 'itid' => $trainId,
  1356. 'submitStatus' => 1
  1357. );
  1358. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1359. Doo::loadModel ( 'staff' );
  1360. $staff = new staff ();
  1361. $username2 = $staff->getOne ( array (
  1362. 'select' => 'wxid',
  1363. 'where' => 'sid=' . $pendingApprovalsSid,
  1364. 'asArray' => TRUE
  1365. ) );
  1366. // 发送微信审批通知
  1367. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1368. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1369. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1370. }
  1371. /**
  1372. */
  1373. function invoiceStoreMailItemSet() {
  1374. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1375. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1376. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1377. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1378. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1379. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1380. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1381. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1382. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1383. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1384. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1385. Doo::loadClass ( 'XDeode' );
  1386. $XDeode = new XDeode ( 5 );
  1387. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1388. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1389. $isid = $XDeode->decode ( $storeKey );
  1390. $trainId = $XDeode->decode ( $trainKey );
  1391. if (! is_numeric ( $isid ))
  1392. die ( 'illegal request' );
  1393. Doo::loadModel ( 'invoiceStore' );
  1394. $invoiceStore = new invoiceStore ();
  1395. $mailList = array (
  1396. 'invoice' => 1,
  1397. 'mailItems' => $mailItems
  1398. );
  1399. if (! empty ( $softLock ))
  1400. $mailList += array (
  1401. 'softLock' => $softLockNum
  1402. );
  1403. else
  1404. $mailList += array (
  1405. 'softLock' => 0
  1406. );
  1407. if (! empty ( $contract ))
  1408. $mailList += array (
  1409. 'contract' => $contractNum
  1410. );
  1411. else
  1412. $mailList += array (
  1413. 'contract' => 0
  1414. );
  1415. if (! empty ( $instructions ))
  1416. $mailList += array (
  1417. 'instructions' => $instructionsNum
  1418. );
  1419. else
  1420. $mailList += array (
  1421. 'instructions' => 0
  1422. );
  1423. if (! empty ( $remittance ))
  1424. $mailList += array (
  1425. 'remittance' => $remittance
  1426. );
  1427. else
  1428. $mailList += array (
  1429. 'remittance' => ''
  1430. );
  1431. $mailString = '发票x1,备注:' . $mailItems;
  1432. if (! empty ( $softLock ))
  1433. $mailString .= ',软件锁x' . $softLockNum;
  1434. if (! empty ( $contract ))
  1435. $mailString .= ',合同x' . $contractNum;
  1436. if (! empty ( $instructions ))
  1437. $mailString .= ',说明书x' . $instructionsNum;
  1438. if (! empty ( $remittance ))
  1439. $mailString .= ',汇款账号单';
  1440. $item = array (
  1441. 'isid' => $isid,
  1442. 'doPost' => 1,
  1443. 'mailItems' => $mailString,
  1444. 'mailItemsJson' => json_encode ( $mailList )
  1445. );
  1446. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1447. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1448. }
  1449. /**
  1450. * 批量设置邮寄物品
  1451. */
  1452. function invoiceStoreBatchMailItemSet() {
  1453. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1454. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1455. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1456. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1457. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1458. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1459. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1460. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1461. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1462. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1463. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1464. Doo::loadClass ( 'XDeode' );
  1465. $XDeode = new XDeode ( 5 );
  1466. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1467. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1468. $isidKeyList = explode ( ',', $storeKey );
  1469. $isidList = array ();
  1470. foreach ( $isidKeyList as $value ) {
  1471. $isid = $XDeode->decode ( $value );
  1472. if (! empty ( $isid ) && is_numeric ( $isid ))
  1473. array_push ( $isidList, $isid );
  1474. }
  1475. $isidString = implode ( ',', $isidList );
  1476. $trainId = $XDeode->decode ( $trainKey );
  1477. if (! is_numeric ( $isid ))
  1478. die ( 'illegal request' );
  1479. Doo::loadModel ( 'invoiceStore' );
  1480. $invoiceStore = new invoiceStore ();
  1481. $mailList = array (
  1482. 'invoice' => 1,
  1483. 'mailItems' => $mailItems
  1484. );
  1485. if (! empty ( $softLock ))
  1486. $mailList += array (
  1487. 'softLock' => $softLockNum
  1488. );
  1489. else
  1490. $mailList += array (
  1491. 'softLock' => 0
  1492. );
  1493. if (! empty ( $contract ))
  1494. $mailList += array (
  1495. 'contract' => $contractNum
  1496. );
  1497. else
  1498. $mailList += array (
  1499. 'contract' => 0
  1500. );
  1501. if (! empty ( $instructions ))
  1502. $mailList += array (
  1503. 'instructions' => $instructionsNum
  1504. );
  1505. else
  1506. $mailList += array (
  1507. 'instructions' => 0
  1508. );
  1509. if (! empty ( $remittance ))
  1510. $mailList += array (
  1511. 'remittance' => $remittance
  1512. );
  1513. else
  1514. $mailList += array (
  1515. 'remittance' => ''
  1516. );
  1517. $mailString = '发票x1,备注:' . $mailItems;
  1518. if (! empty ( $softLock ))
  1519. $mailString .= ',软件锁x' . $softLockNum;
  1520. if (! empty ( $contract ))
  1521. $mailString .= ',合同x' . $contractNum;
  1522. if (! empty ( $instructions ))
  1523. $mailString .= ',说明书x' . $instructionsNum;
  1524. if (! empty ( $remittance ))
  1525. $mailString .= ',汇款账号单';
  1526. $item = array (
  1527. 'doPost' => 1,
  1528. 'mailItems' => $mailString,
  1529. 'mailItemsJson' => json_encode ( $mailList )
  1530. );
  1531. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1532. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1533. }
  1534. /**
  1535. * 废弃
  1536. */
  1537. function ajaxGetMailItemByIstore() {
  1538. Doo::loadClass ( 'XDeode' );
  1539. $XDeode = new XDeode ( 5 );
  1540. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1541. $isid = $XDeode->decode ( $storeKey );
  1542. if (! is_numeric ( $isid ))
  1543. die ( 'illegal request' );
  1544. Doo::loadModel ( 'invoiceStore' );
  1545. $invoiceStore = new invoiceStore ();
  1546. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1547. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1548. echo json_encode ( $isDetail ['mailItemsJson'] );
  1549. exit ();
  1550. }
  1551. /**
  1552. * 终止开票
  1553. */
  1554. function invoiceDroppedDo() {
  1555. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1556. Doo::loadModel ( 'invoice' );
  1557. $invoice = new invoice ();
  1558. Doo::loadModel ( 'invoiceOperationLog' );
  1559. $invoiceOperationLog = new invoiceOperationLog ();
  1560. $iid = $invoice->authcode ( $droppedIidKey );
  1561. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1562. die ( 'illegal request' );
  1563. $item = array (
  1564. 'iid' => $iid,
  1565. 'status' => 4,
  1566. 'updateTime' => date ( "Y-m-d H:i:s" )
  1567. );
  1568. $invoice->setInvoiceByCondition ( $item );
  1569. $item = array (
  1570. 'date' => date ( "Y-m-d H:i:s" ),
  1571. 'operation' => '终止了开票',
  1572. 'status' => 4,
  1573. 'img' => $this->staff [0] ['avatar'],
  1574. 'username' => $this->staff [0] ['username'],
  1575. 'uid' => $this->staff [0] ['sid'],
  1576. 'category' => $this->staff [0] ['category'],
  1577. 'iid' => $iid
  1578. );
  1579. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1580. return "/invoice";
  1581. }
  1582. /**
  1583. * 更新退票的邮寄信息
  1584. */
  1585. function invoiceUntreadMailDo() {
  1586. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1587. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1588. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1589. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1590. Doo::loadModel ( 'invoice' );
  1591. $invoice = new invoice ();
  1592. $iid = $invoice->authcode ( $untreadIidKey );
  1593. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1594. die ( 'illegal request' );
  1595. $item = array (
  1596. 'iid' => $iid,
  1597. 'untreadCompany' => $untreadCompany,
  1598. 'untreadNumber' => $untreadNumber,
  1599. 'untreadItems' => $untreadItems
  1600. );
  1601. $invoice->setInvoiceByCondition ( $item );
  1602. return "/invoice";
  1603. }
  1604. /**
  1605. * 申请退票 --
  1606. */
  1607. function invoiceUntreadDo() {
  1608. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1609. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1610. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1611. Doo::loadModel ( 'invoice' );
  1612. $invoice = new invoice ();
  1613. Doo::loadModel ( 'invoiceOperationLog' );
  1614. $invoiceOperationLog = new invoiceOperationLog ();
  1615. Doo::loadModel ( 'invoiceReceivables' );
  1616. $invoiceReceivables = new invoiceReceivables ();
  1617. $iid = $invoice->authcode ( $untreadIidKey );
  1618. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1619. die ( 'illegal request' );
  1620. /*
  1621. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1622. */
  1623. $item = array (
  1624. 'iid' => $iid,
  1625. 'untreadStatus' => 1,
  1626. 'untreadReason' => $untreadReason,
  1627. 'untreadPost' => $untreadPost,
  1628. 'updateTime' => date ( "Y-m-d H:i:s" )
  1629. );
  1630. $invoice->setInvoiceByCondition ( $item );
  1631. $item = array (
  1632. 'date' => date ( "Y-m-d H:i:s" ),
  1633. 'operation' => '申请退票',
  1634. 'status' => 7,
  1635. 'img' => $this->staff [0] ['avatar'],
  1636. 'username' => $this->staff [0] ['username'],
  1637. 'uid' => $this->staff [0] ['sid'],
  1638. 'category' => $this->staff [0] ['category'],
  1639. 'iid' => $iid
  1640. );
  1641. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1642. return "/invoice";
  1643. }
  1644. /**
  1645. * 删除已终止的开票
  1646. */
  1647. function invoiceDelDo() {
  1648. Doo::loadModel ( 'invoice' );
  1649. $invoice = new invoice ();
  1650. Doo::loadModel ( 'invoiceOperationLog' );
  1651. $invoiceOperationLog = new invoiceOperationLog ();
  1652. Doo::loadClass ( 'XDeode' );
  1653. $XDeode = new XDeode ( 5 );
  1654. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1655. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1656. $iid = $XDeode->decode ( $iid );
  1657. Doo::loadModel ( 'invoiceStore' );
  1658. $invoiceStore = new invoiceStore ();
  1659. if (! is_numeric ( $iid ))
  1660. die ( 'illegal request' );
  1661. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1662. if (empty ( $invoiceDetail ))
  1663. die ( 'illegal request' );
  1664. $item = array (
  1665. 'iid' => $iid,
  1666. 'isDelete' => 1,
  1667. 'updateTime' => date ( "Y-m-d H:i:s" )
  1668. );
  1669. $invoice->setInvoiceByCondition ( $item );
  1670. $item = array (
  1671. 'date' => date ( "Y-m-d H:i:s" ),
  1672. 'operation' => '删除了已终止的发票',
  1673. 'status' => 4,
  1674. 'img' => $this->staff [0] ['avatar'],
  1675. 'username' => $this->staff [0] ['username'],
  1676. 'uid' => $this->staff [0] ['sid'],
  1677. 'category' => $this->staff [0] ['category'],
  1678. 'iid' => $iid
  1679. );
  1680. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1681. // 删除培训班发票仓库里的发票
  1682. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1683. return "/invoice";
  1684. }
  1685. /**
  1686. */
  1687. function invoiceApproval() {
  1688. Doo::loadModel ( 'invoice' );
  1689. $invoice = new invoice ();
  1690. Doo::loadClass ( 'XDeode' );
  1691. $XDeode = new XDeode ( 5 );
  1692. Doo::loadModel ( 'staff' );
  1693. $staff = new staff ();
  1694. $invoiceList = $invoice->find ( array (
  1695. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1696. 'desc' => 'iid',
  1697. 'limit' => 10,
  1698. 'asArray' => true
  1699. ) );
  1700. foreach ( $invoiceList as $key => $value ) {
  1701. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1702. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1703. if (! empty ( $lastApprover )) {
  1704. $lastApproverKey = array_keys ( $lastApprover );
  1705. $lastApprover = end ( $lastApprover );
  1706. $staffDetail = $staff->getOne ( array (
  1707. 'where' => 'sid=' . end ( $lastApproverKey ),
  1708. 'asArray' => true
  1709. ) );
  1710. $lastApprover ['username'] = $staffDetail ['username'];
  1711. }
  1712. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1713. }
  1714. $ilist = $invoice->getInvoiceByProcessStatus ();
  1715. foreach ( $ilist as $key => $value ) {
  1716. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1717. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1718. if (! empty ( $lastApprover )) {
  1719. $lastApproverKey = array_keys ( $lastApprover );
  1720. $lastApprover = end ( $lastApprover );
  1721. $staffDetail = $staff->getOne ( array (
  1722. 'where' => 'sid=' . end ( $lastApproverKey ),
  1723. 'asArray' => true
  1724. ) );
  1725. $lastApprover ['username'] = $staffDetail ['username'];
  1726. }
  1727. $ilist [$key] ['lastApprover'] = $lastApprover;
  1728. }
  1729. // print_r($ilist);
  1730. $this->data ['invoiceList'] = $invoiceList;
  1731. $this->data ['ilist'] = $ilist;
  1732. $this->data ['memu'] = "invoice";
  1733. $this->data ['staff'] = $this->staff;
  1734. $this->data ['receiptMemu'] = 'invoiceApproval';
  1735. $this->render ( "/admin/invoiceApproval", $this->data );
  1736. }
  1737. function invoiceDetail() {
  1738. Doo::loadClass ( 'XDeode' );
  1739. $XDeode = new XDeode ( 5 );
  1740. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1741. $iid = $XDeode->decode ( $iid );
  1742. if (! is_numeric ( $iid ))
  1743. die ( 'illegal request' );
  1744. Doo::loadModel ( 'invoice' );
  1745. $invoice = new invoice ();
  1746. Doo::loadModel ( 'invoiceOperationLog' );
  1747. $invoiceOperationLog = new invoiceOperationLog ();
  1748. $invoiceDetail = $invoice->getOne ( array (
  1749. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1750. 'asArray' => true
  1751. ) );
  1752. if (empty ( $invoiceDetail ))
  1753. die ( 'illegal request' );
  1754. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1755. $this->data ['invoiceDetail'] = $invoiceDetail;
  1756. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1757. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1758. $this->data ['memu'] = "invoice";
  1759. $this->data ['staff'] = $this->staff;
  1760. $this->data ['receiptMemu'] = 'invoiceApproval';
  1761. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1762. }
  1763. /**
  1764. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1765. *
  1766. * @since 1.0.0
  1767. * @var integer iid 开票ID 已加密
  1768. * @var integer status 发票审批状态
  1769. * @var integer opintion 审批发票的意见
  1770. * @return string 如操作成功返回审批首页
  1771. */
  1772. function invoiceApprovalDo() {
  1773. Doo::loadModel ( 'invoice' );
  1774. $invoice = new invoice ();
  1775. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1776. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1777. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1778. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  1779. $iid = $invoice->authcode ( $iid );
  1780. if (! is_numeric ( $iid ))
  1781. die ( 'illegal request' );
  1782. // && ! empty ( $opinion )
  1783. if (! empty ( $iid ) && ! empty ( $status )) {
  1784. if (! ($status == 2 || $status == 3 || $status == 4))
  1785. die ( 'illegal request' );
  1786. Doo::loadModel ( 'invoiceOperationLog' );
  1787. $invoiceOperationLog = new invoiceOperationLog ();
  1788. $invoiceDetail = $invoice->getOne ( array (
  1789. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1790. 'asArray' => true
  1791. ) );
  1792. if (empty ( $invoiceDetail ))
  1793. die ( 'illegal request' );
  1794. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1795. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1796. if ($status == 3) {
  1797. $invoice->status = $status;
  1798. $item = array (
  1799. 'operation' => $opinion
  1800. );
  1801. } else {
  1802. if (empty ( $processApprovals )) {
  1803. $processApprovals = array (
  1804. $this->staff [0] ['sid'] => array (
  1805. 'date' => date ( "Y-m-d H:i:s" ),
  1806. 'opinion' => $opinion,
  1807. 'status' => $status
  1808. )
  1809. );
  1810. // var_dump(next($invoiceManage));
  1811. $nextInvoiceManage = next ( $invoiceManage );
  1812. // print_r($nextInvoiceManage);
  1813. if ($status != 4 && $nextInvoiceManage !== false)
  1814. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1815. $invoice->processApprovals = json_encode ( $processApprovals );
  1816. // var_dump($invoice);
  1817. // print_r($invoiceManage);
  1818. } else {
  1819. $processApprovals [$this->staff [0] ['sid']] = array (
  1820. 'date' => date ( "Y-m-d H:i:s" ),
  1821. 'opinion' => $opinion,
  1822. 'status' => $status
  1823. );
  1824. $pendingApprovals = 0;
  1825. foreach ( $invoiceManage as $key => $value ) {
  1826. if ($value [0] == $this->staff [0] ['sid']) {
  1827. if (isset ( $invoiceManage [$key + 1] ))
  1828. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1829. break;
  1830. }
  1831. }
  1832. if ($status != 4 && ! empty ( $pendingApprovals ))
  1833. $invoice->pendingApprovals = $pendingApprovals;
  1834. $invoice->processApprovals = json_encode ( $processApprovals );
  1835. }
  1836. $item = array (
  1837. 'operation' => $opinion
  1838. );
  1839. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1840. $invoice->status = $status;
  1841. $invoice->pendingApprovals = 0;
  1842. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1843. } elseif ($status == 4) {
  1844. $invoice->status = $status;
  1845. $item = array (
  1846. 'operation' => $opinion
  1847. );
  1848. }
  1849. }
  1850. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  1851. $invoice->update ( array (
  1852. 'where' => 'iid=' . $iid
  1853. ) );
  1854. $item += array (
  1855. 'date' => date ( "Y-m-d H:i:s" ),
  1856. 'img' => $this->staff [0] ['avatar'],
  1857. 'username' => $this->staff [0] ['username'],
  1858. 'uid' => $this->staff [0] ['sid'],
  1859. 'category' => $this->staff [0] ['category'],
  1860. 'status' => $status,
  1861. 'iid' => $iid
  1862. );
  1863. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1864. if (empty ( $divApproval ))
  1865. return '/invoiceApproval';
  1866. else
  1867. return '/invoiceApprovalAchieve/PEND';
  1868. }
  1869. die ( 'illegal request' );
  1870. }
  1871. /**
  1872. * 展示需要打印的发票数据
  1873. *
  1874. * @since 1.0.0
  1875. */
  1876. function invoicePrint() {
  1877. Doo::loadModel ( 'invoice' );
  1878. $invoice = new invoice ();
  1879. Doo::loadClass ( 'XDeode' );
  1880. $XDeode = new XDeode ( 5 );
  1881. Doo::loadModel ( 'staff' );
  1882. $staff = new staff ();
  1883. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  1884. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  1885. foreach ( $toPrint as $key => $value ) {
  1886. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1887. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1888. if (! empty ( $lastApprover )) {
  1889. $lastApproverKey = array_keys ( $lastApprover );
  1890. $lastApprover = end ( $lastApprover );
  1891. $staffDetail = $staff->getOne ( array (
  1892. 'where' => 'sid=' . end ( $lastApproverKey ),
  1893. 'asArray' => true
  1894. ) );
  1895. $lastApprover ['username'] = $staffDetail ['username'];
  1896. }
  1897. $toPrint [$key] ['lastApprover'] = $lastApprover;
  1898. }
  1899. foreach ( $printed as $key => $value ) {
  1900. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1901. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1902. if (! empty ( $lastApprover )) {
  1903. $lastApproverKey = array_keys ( $lastApprover );
  1904. $lastApprover = end ( $lastApprover );
  1905. $staffDetail = $staff->getOne ( array (
  1906. 'where' => 'sid=' . end ( $lastApproverKey ),
  1907. 'asArray' => true
  1908. ) );
  1909. $lastApprover ['username'] = $staffDetail ['username'];
  1910. }
  1911. $printed [$key] ['lastApprover'] = $lastApprover;
  1912. }
  1913. $this->data ['printed'] = $printed;
  1914. $this->data ['toPrint'] = $toPrint;
  1915. $this->data ['memu'] = "invoice";
  1916. $this->data ['staff'] = $this->staff;
  1917. $this->data ['receiptMemu'] = 'invoicePrint';
  1918. $this->render ( "/admin/invoicePrint", $this->data );
  1919. }
  1920. /**
  1921. * 展示发票打印的详情页面
  1922. *
  1923. * @since 1.0.0
  1924. */
  1925. function invoicePrintDetail() {
  1926. Doo::loadClass ( 'XDeode' );
  1927. $XDeode = new XDeode ( 5 );
  1928. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1929. $iid = $XDeode->decode ( $iid );
  1930. if (! is_numeric ( $iid ))
  1931. die ( 'illegal request' );
  1932. Doo::loadModel ( 'invoice' );
  1933. $invoice = new invoice ();
  1934. Doo::loadModel ( 'invoiceOperationLog' );
  1935. $invoiceOperationLog = new invoiceOperationLog ();
  1936. Doo::loadModel ( 'invoicePaper' );
  1937. $invoicePaper = new invoicePaper ();
  1938. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  1939. if (empty ( $invoiceDetail ))
  1940. die ( 'illegal request' );
  1941. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  1942. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1943. $this->data ['invoicePaperList'] = $invoicePaperList;
  1944. $this->data ['invoiceDetail'] = $invoiceDetail;
  1945. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1946. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1947. $this->data ['memu'] = "invoice";
  1948. $this->data ['staff'] = $this->staff;
  1949. $this->data ['receiptMemu'] = 'invoicePrint';
  1950. $this->render ( "/admin/invoicePrintDetail", $this->data );
  1951. }
  1952. /**
  1953. * 所有待打印 发票
  1954. */
  1955. function invoicePrintStayAchieve() {
  1956. Doo::loadModel ( 'invoice' );
  1957. $invoice = new invoice ();
  1958. Doo::loadClass ( 'XDeode' );
  1959. $XDeode = new XDeode ( 5 );
  1960. Doo::loadModel ( 'staff' );
  1961. $staff = new staff ();
  1962. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  1963. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  1964. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  1965. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  1966. Doo::loadModel ( 'invoiceTraining' );
  1967. $invoiceTraining = new invoiceTraining ();
  1968. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  1969. $page_size = 12;
  1970. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1971. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  1972. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  1973. $get = "/" . $status;
  1974. $con = ' and status=2 ';
  1975. if ($status == 'TOPRINT')
  1976. $con = ' and status=2 and printStatus=0 ';
  1977. elseif ($status == 'PRINTED')
  1978. $con = ' and status=2 and printStatus=1';
  1979. if ($invoiceType == 'ORDINARY')
  1980. $con .= ' and invoiceType=0 ';
  1981. elseif ($invoiceType == 'SPECIAL')
  1982. $con .= ' and invoiceType=1 ';
  1983. if ($invoiceTrain == 'ORDINARY')
  1984. $con .= ' and trainId=0 ';
  1985. elseif ($invoiceTrain == 'TRAIN')
  1986. $con .= ' and trainId!=0 ';
  1987. if ($invoiceTrainName != 'ALL') {
  1988. $trainId = $XDeode->decode ( $invoiceTrainName );
  1989. if (is_numeric ( $trainId ))
  1990. $con .= ' and trainId =' . $trainId;
  1991. }
  1992. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1993. $dateArr = explode ( ':', $date );
  1994. $D1 = '';
  1995. $D2 = '';
  1996. if (! empty ( $date )) {
  1997. $D1 = $dateArr [0];
  1998. $D2 = $dateArr [1];
  1999. }
  2000. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2001. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2002. if (! empty ( $MebSea )) {
  2003. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2004. }
  2005. $pageinfo ['page'] = array (
  2006. 'previous' => ''
  2007. );
  2008. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2009. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2010. $action = "invoicePrintStayAchieve";
  2011. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2012. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2013. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2014. $this->data ['trainList'] = $trainList;
  2015. $this->data ['invoiceType'] = $invoiceType;
  2016. $this->data ['invoiceTrain'] = $invoiceTrain;
  2017. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2018. $this->data ['MebSeaEn'] = $MebSea;
  2019. $this->data ['MebSea'] = urlencode ( $MebSea );
  2020. $this->data ['get'] = $get;
  2021. $this->data ['page'] = $pageinfo;
  2022. $this->data ['date'] = $date;
  2023. $this->data ['status'] = $status;
  2024. $this->data ['memu'] = "invoice";
  2025. $this->data ['staff'] = $this->staff;
  2026. foreach ( $list as $key => $value ) {
  2027. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2028. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2029. if (! empty ( $lastApprover )) {
  2030. $lastApproverKey = array_keys ( $lastApprover );
  2031. $lastApprover = end ( $lastApprover );
  2032. $staffDetail = $staff->getOne ( array (
  2033. 'where' => 'sid=' . end ( $lastApproverKey ),
  2034. 'asArray' => true
  2035. ) );
  2036. $lastApprover ['username'] = $staffDetail ['username'];
  2037. }
  2038. $list [$key] ['lastApprover'] = $lastApprover;
  2039. }
  2040. $this->data ['receiptMemu'] = 'invoicePrint';
  2041. $this->data ['list'] = $list;
  2042. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2043. }
  2044. /**
  2045. * 填写票号并完成打印
  2046. * @since 1.0.0
  2047. */
  2048. function invoicePrintDo() {
  2049. Doo::loadModel ( 'invoice' );
  2050. $invoice = new invoice ();
  2051. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2052. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2053. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2054. $iid = $invoice->authcode ( $iid );
  2055. if (! is_numeric ( $iid ))
  2056. die ( 'illegal request' );
  2057. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2058. Doo::loadModel ( 'invoiceOperationLog' );
  2059. $invoiceOperationLog = new invoiceOperationLog ();
  2060. Doo::loadModel ( 'invoiceStatistics' );
  2061. $invoiceStatistics = new invoiceStatistics ();
  2062. $XDeode = new XDeode ( 5 );
  2063. Doo::loadModel ( 'invoicePaper' );
  2064. $invoicePaper = new invoicePaper ();
  2065. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2066. if (empty ( $invoicePrintDetail ))
  2067. die ( 'illegal request' );
  2068. //
  2069. $ipid = $XDeode->decode ( $invoiceNo );
  2070. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2071. if (empty ( $paperDetail ))
  2072. die ( 'illegal request' );
  2073. $invoicePaper = new invoicePaper ();
  2074. $item = array (
  2075. 'iid' => $iid,
  2076. 'ipid' => $ipid
  2077. );
  2078. $invoicePaper->setInvoicePaperByCondition ( $item );
  2079. $item = array (
  2080. 'iid' => $iid,
  2081. 'printStatus' => 1,
  2082. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2083. 'printer' => $this->staff [0] ['username'],
  2084. 'printTime' => date ( "Y-m-d H:i:s" ),
  2085. 'invoiceNo' => $paperDetail ['invoiceNo']
  2086. );
  2087. $invoice->setInvoiceByCondition ( $item );
  2088. $item = array (
  2089. 'date' => date ( "Y-m-d H:i:s" ),
  2090. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2091. 'status' => 5,
  2092. 'img' => $this->staff [0] ['avatar'],
  2093. 'username' => $this->staff [0] ['username'],
  2094. 'uid' => $this->staff [0] ['sid'],
  2095. 'category' => $this->staff [0] ['category'],
  2096. 'iid' => $iid
  2097. );
  2098. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2099. // 去统计--负票不汇总
  2100. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2101. $item = array (
  2102. 'date' => date ( "Y-m-d H:i:s" ),
  2103. 'priceClass' => 1,
  2104. 'cid' => $invoicePrintDetail ['cid'],
  2105. 'staff' => $invoicePrintDetail ['sid'],
  2106. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2107. );
  2108. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2109. }
  2110. // 发送通知信息到微信-去除
  2111. // $this->setWXMsg($iid,'PRINT');
  2112. // 申请人获取微信通知
  2113. Doo::loadModel ( 'staff' );
  2114. $staff = new staff ();
  2115. Doo::loadClass ( 'XDeode' );
  2116. $XDeode = new XDeode ( 5 );
  2117. $username2 = $staff->getOne ( array (
  2118. 'select' => 'wxid',
  2119. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2120. 'asArray' => TRUE
  2121. ) );
  2122. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2123. $msg = '';
  2124. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2125. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2126. if (empty ( $invoicePrintType ))
  2127. return "/invoicePrint";
  2128. else
  2129. return "/invoicePrintStayAchieve";
  2130. }
  2131. }
  2132. /**
  2133. * 需要邮寄的发票
  2134. * @since 1.0.0
  2135. */
  2136. function invoicePost() {
  2137. Doo::loadModel ( 'invoice' );
  2138. $invoice = new invoice ();
  2139. Doo::loadModel ( 'express' );
  2140. $express = new express ();
  2141. $invoicePost = $invoice->getPostByInvoice ();
  2142. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2143. $expressList = $express->getExpressByAll ();
  2144. $invoicePostExpress = "";
  2145. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2146. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2147. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2148. $this->data ['expressList'] = $expressList;
  2149. $this->data ['invoicePost'] = $invoicePost;
  2150. $this->data ['invoicePosted'] = $invoicePosted;
  2151. $this->data ['memu'] = "invoice";
  2152. $this->data ['staff'] = $this->staff;
  2153. $this->data ['receiptMemu'] = 'invoicePost';
  2154. $this->render ( "/admin/invoicePost", $this->data );
  2155. }
  2156. /**
  2157. * 添加发票邮寄信息
  2158. */
  2159. function invoiceExpressAddDo() {
  2160. Doo::loadModel ( 'invoice' );
  2161. $invoice = new invoice ();
  2162. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2163. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2164. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2165. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2166. $iid = $iid = $invoice->authcode ( $iid );
  2167. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2168. die ( 'illegal request' );
  2169. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2170. setcookie ( 'invoicePostExpress', $expressNumber );
  2171. $item = array (
  2172. 'iid' => $iid,
  2173. 'postStatus' => 1,
  2174. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2175. 'postTime' => date ( "Y-m-d H:i:s" ),
  2176. 'expressCompany' => $expressCompany,
  2177. 'expressNumber' => $expressNumber,
  2178. 'actualItems' => $actualItems,
  2179. 'poster' => $this->staff [0] ['username']
  2180. );
  2181. $invoice->setInvoiceByCondition ( $item );
  2182. // 微信通知-去掉
  2183. // $this->setWXMsg ( $iid );
  2184. Doo::loadModel ( 'staff' );
  2185. $staff = new staff ();
  2186. Doo::loadClass ( 'XDeode' );
  2187. $XDeode = new XDeode ( 5 );
  2188. $username2 = $staff->getOne ( array (
  2189. 'select' => 'wxid',
  2190. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2191. 'asArray' => TRUE
  2192. ) );
  2193. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2194. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2195. if (empty ( $expCom ))
  2196. $expCom [0] = '';
  2197. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2198. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2199. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2200. return '/invoicePost';
  2201. }
  2202. function invoiceExpressUpdateDo() {
  2203. Doo::loadModel ( 'invoice' );
  2204. $invoice = new invoice ();
  2205. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2206. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2207. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2208. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2209. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2210. $iid = $invoice->authcode ( $iid );
  2211. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2212. die ( 'illegal request' );
  2213. $item = array (
  2214. 'iid' => $iid,
  2215. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2216. 'expressCompany' => $expressCompany,
  2217. 'expressNumber' => $expressNumber,
  2218. 'actualItems' => $actualItems,
  2219. 'poster' => $this->staff [0] ['username']
  2220. );
  2221. $invoice->setInvoiceByCondition ( $item );
  2222. return $action;
  2223. }
  2224. /**
  2225. * 可退票管理
  2226. */
  2227. function invoiceUntreadIsAchieve() {
  2228. Doo::loadModel ( 'invoice' );
  2229. $invoice = new invoice ();
  2230. Doo::loadClass ( 'XDeode' );
  2231. $XDeode = new XDeode ( 5 );
  2232. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2233. $page_size = 18;
  2234. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2235. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2236. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2237. $dateArr = explode ( ':', $date );
  2238. $D1 = '';
  2239. $D2 = '';
  2240. if (! empty ( $date )) {
  2241. $D1 = $dateArr [0];
  2242. $D2 = $dateArr [1];
  2243. }
  2244. $con = '';
  2245. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2246. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2247. // if ($date == 'MONTHO')
  2248. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2249. // elseif ($date == 'MONTHT')
  2250. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2251. // elseif ($date == 'MONTHY')
  2252. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2253. if (! empty ( $MebSea )) {
  2254. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2255. }
  2256. $pageinfo ['page'] = array (
  2257. 'previous' => ''
  2258. );
  2259. // printStatus=1 and
  2260. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2261. $action = "invoiceUntreadIsAchieve";
  2262. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2263. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2264. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2265. // print_r($list);
  2266. $this->data ['MebSeaEn'] = $MebSea;
  2267. // $this->data ['MebSea'] = urlencode ( $MebSea );
  2268. $this->data ['get'] = $get;
  2269. $this->data ['page'] = $pageinfo;
  2270. $this->data ['date'] = $date;
  2271. $this->data ['list'] = $list;
  2272. $this->data ['memu'] = "invoice";
  2273. $this->data ['staff'] = $this->staff;
  2274. $this->data ['receiptMemu'] = 'invoice';
  2275. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2276. }
  2277. /**
  2278. * 退票处理页面
  2279. */
  2280. function invoiceUntread() {
  2281. Doo::loadModel ( 'invoice' );
  2282. $invoice = new invoice ();
  2283. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  2284. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2285. foreach ( $establishedInvoice as $key => $value ) {
  2286. // months
  2287. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2288. $nowDate = strtotime ( 'now' );
  2289. $establishedInvoice [$key] ['lossShow'] = false;
  2290. if ($lossDate < $nowDate)
  2291. $establishedInvoice [$key] ['lossShow'] = true;
  2292. }
  2293. $this->data ['untreadInvoice'] = $untreadInvoice;
  2294. $this->data ['establishedInvoice'] = $establishedInvoice;
  2295. $this->data ['memu'] = "invoice";
  2296. $this->data ['staff'] = $this->staff;
  2297. $this->data ['receiptMemu'] = 'invoiceUntread';
  2298. $this->render ( "/admin/invoiceUntread", $this->data );
  2299. }
  2300. /**
  2301. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2302. */
  2303. function invoiceUntreadEstablishedDo() {
  2304. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2305. Doo::loadModel ( 'invoice' );
  2306. $invoice = new invoice ();
  2307. Doo::loadModel ( 'invoiceOperationLog' );
  2308. $invoiceOperationLog = new invoiceOperationLog ();
  2309. Doo::loadModel ( 'invoiceReceivables' );
  2310. Doo::loadModel ( 'invoiceStatistics' );
  2311. $iid = $invoice->authcode ( $untreadIidKey );
  2312. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2313. die ( 'illegal request' );
  2314. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2315. if ($invoiceDetails ['untreadStatus'] != 1)
  2316. die ( 'illegal request' );
  2317. $item = array (
  2318. 'iid' => $iid,
  2319. // 'irid'=>'',
  2320. 'untreadStatus' => 2,
  2321. 'updateTime' => date ( "Y-m-d H:i:s" )
  2322. );
  2323. $invoice->setInvoiceByCondition ( $item );
  2324. $item = array (
  2325. 'date' => date ( "Y-m-d H:i:s" ),
  2326. 'operation' => '已确认退票',
  2327. 'status' => 6,
  2328. 'img' => $this->staff [0] ['avatar'],
  2329. 'username' => $this->staff [0] ['username'],
  2330. 'uid' => $this->staff [0] ['sid'],
  2331. 'category' => $this->staff [0] ['category'],
  2332. 'iid' => $iid
  2333. );
  2334. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2335. // 收款解绑以及入账扣除 收款扣除
  2336. if (! empty ( $invoiceDetails ['irid'] )) {
  2337. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2338. foreach ( $iridList as $value ) {
  2339. $invoiceReceivables = new invoiceReceivables ();
  2340. $irDetails = $invoiceReceivables->getOne ( array (
  2341. 'where' => " irid=" . $value . ' and bindStatus=1',
  2342. 'asArray' => TRUE
  2343. ) );
  2344. $item = array (
  2345. 'irid' => $value,
  2346. 'bindStatus' => 0,
  2347. 'untreadStatus' => 1,
  2348. 'untreadStaff' => $invoiceDetails ['userName'],
  2349. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2350. 'iid' => 0
  2351. );
  2352. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2353. if (! empty ( $irDetails )) {
  2354. // 扣除入账
  2355. $invoiceStatistics = new invoiceStatistics ();
  2356. $item = array (
  2357. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2358. 'priceClass' => 3,
  2359. 'cid' => $invoiceDetails ['cid'],
  2360. 'staff' => $invoiceDetails ['sid'],
  2361. 'accountPrice' => - $irDetails ['receivablesPrice']
  2362. );
  2363. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2364. // 扣除收款
  2365. $invoiceStatistics = new invoiceStatistics ();
  2366. $item = array (
  2367. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2368. 'priceClass' => 2,
  2369. 'cid' => $invoiceDetails ['cid'],
  2370. 'staff' => $invoiceDetails ['sid'],
  2371. 'irid' => $irDetails ['irid'],
  2372. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2373. );
  2374. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2375. }
  2376. // 解绑时删除收入流水
  2377. Doo::loadModel ( 'wasteBook' );
  2378. $wasteBook = new wasteBook ();
  2379. $wasteBook->delete ( array (
  2380. 'where' => 'dataID=' . $value . ' and accountType=7',
  2381. 'limit' => 1
  2382. ) );
  2383. }
  2384. }
  2385. return "/invoiceUntread";
  2386. }
  2387. /**
  2388. * 建立负票,关联原来发票
  2389. */
  2390. function invoiceLossDo() {
  2391. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2392. if (! empty ( $iidKey )) {
  2393. Doo::loadClass ( 'XDeode' );
  2394. $XDeode = new XDeode ( 5 );
  2395. Doo::loadModel ( 'invoice' );
  2396. $invoice = new invoice ();
  2397. Doo::loadModel ( 'invoiceOperationLog' );
  2398. $invoiceOperationLog = new invoiceOperationLog ();
  2399. $iidKey = $XDeode->decode ( $iidKey );
  2400. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2401. // 拷贝插入一条发票数据
  2402. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2403. // 更新负票
  2404. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2405. $invoice = new invoice ();
  2406. $item = array (
  2407. 'iid' => $iid,
  2408. 'sid' => $this->staff [0] ['sid'],
  2409. 'userName' => $this->staff [0] ['username'],
  2410. 'cid' => $this->staff [0] ['cid'],
  2411. 'categoryName' => $this->staff [0] ['category'],
  2412. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2413. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2414. 'invoiceSerial' => $invoiceSerial,
  2415. 'invoiceNo' => '',
  2416. 'printStatus' => 0,
  2417. 'untreadStatus' => 4,
  2418. // 关联发票号
  2419. 'lossIid' => $invoiceDetail ['iid']
  2420. );
  2421. $invoice->setInvoiceByCondition ( $item );
  2422. // 更新原发票
  2423. $invoice = new invoice ();
  2424. $item = array (
  2425. 'iid' => $invoiceDetail ['iid'],
  2426. 'lossIid' => $iid
  2427. );
  2428. $invoice->setInvoiceByCondition ( $item );
  2429. // 操作日志
  2430. $item = array (
  2431. 'date' => date ( "Y-m-d H:i:s" ),
  2432. 'operation' => "创建负票" . $invoiceSerial,
  2433. 'status' => 12,
  2434. 'img' => $this->staff [0] ['avatar'],
  2435. 'username' => $this->staff [0] ['username'],
  2436. 'uid' => $this->staff [0] ['sid'],
  2437. 'category' => $this->staff [0] ['category'],
  2438. 'iid' => $iid
  2439. );
  2440. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2441. // print_r($invoiceDetail);
  2442. // echo $iid;die;
  2443. }
  2444. return '/invoiceUntread';
  2445. }
  2446. /**
  2447. * 上传银行到账 收款文件
  2448. */
  2449. function invoiceReceivablesBankUpload() {
  2450. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2451. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2452. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2453. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2454. header ( "HTTP/1.1 500 Internal Server Error" );
  2455. echo "POST exceeded maximum allowed size.";
  2456. exit ( 0 );
  2457. }
  2458. // Settings
  2459. $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)
  2460. $upload_name = "Filedata";
  2461. $file_name = "";
  2462. $nk = time ();
  2463. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2464. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2465. echo "文件无法保存.";
  2466. exit ( 0 );
  2467. }
  2468. echo json_encode ( array (
  2469. 'filename' => $file_name,
  2470. 'id' => $nk
  2471. ) );
  2472. exit ( 0 );
  2473. }
  2474. /**
  2475. * 解析银行到账收款execl并导入库中
  2476. */
  2477. function invoiceReceivablesImport() {
  2478. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2479. if ($path != "") {
  2480. Doo::loadModel ( 'invoiceReceivables' );
  2481. $invoiceReceivables = new invoiceReceivables ();
  2482. Doo::loadClass ( 'invoice.func' );
  2483. Doo::loadModel ( 'invoiceROLog' );
  2484. $invoiceROLog = new invoiceROLog ();
  2485. Doo::loadModel ( 'invoiceStatistics' );
  2486. $invoiceStatistics = new invoiceStatistics ();
  2487. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2488. $bankBatchNumber = 'BBN_' . time ();
  2489. Doo::db ()->beginTransaction ();
  2490. // 批量存储收款--由于必须获得收款ID,
  2491. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2492. VALUES ';
  2493. $date = date ( "Y-m-d" );
  2494. $receivablesList = array ();
  2495. foreach ( $exlArray as $key => $value ) {
  2496. $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"] . '")';
  2497. array_push ( $receivablesList, $receivablesSql );
  2498. }
  2499. $sql = $sql . implode ( ',', $receivablesList );
  2500. // echo $sql;
  2501. Doo::db ()->query ( $sql );
  2502. // 批量存储收款统计
  2503. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2504. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2505. // 没有irid 回滚所有操作
  2506. if (empty ( $iridList )) {
  2507. Doo::db ()->rollBack ();
  2508. header ( 'Content-Type:text/html;charset=utf-8' );
  2509. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2510. }
  2511. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2512. VALUES ';
  2513. $statisticsList = array ();
  2514. foreach ( $iridList as $value ) {
  2515. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2516. array_push ( $statisticsList, $statisticsSql );
  2517. }
  2518. $sql = $sql . implode ( ',', $statisticsList );
  2519. Doo::db ()->query ( $sql );
  2520. // 批量存储操作日志
  2521. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2522. VALUES ';
  2523. $ROLogList = array ();
  2524. foreach ( $iridList as $value ) {
  2525. $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'] . '")';
  2526. array_push ( $ROLogList, $ROLogSql );
  2527. }
  2528. $sql = $sql . implode ( ',', $ROLogList );
  2529. Doo::db ()->query ( $sql );
  2530. //批量写入流水
  2531. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2532. VALUES ';
  2533. $wasteBookList=array();
  2534. foreach ( $iridList as $value ) {
  2535. $accountBank='';
  2536. if ($value ['receivablesBank']=='纵横广发'){
  2537. $accountBank='CGBDeposit';
  2538. }elseif($value ['receivablesBank']=='纵横工行'){
  2539. $accountBank='ICBCDeposit';
  2540. }elseif($value ['receivablesBank']=='华润银行'){
  2541. $accountBank='HUADeposit';
  2542. }elseif($value ['receivablesBank']=='个人广发'){
  2543. $accountBank='PersonalDeposit';
  2544. }
  2545. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2546. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2547. array_push ( $wasteBookList, $wasteBookSql );
  2548. }
  2549. $sql = $sql . implode ( ',', $wasteBookList );
  2550. Doo::db ()->query ( $sql );
  2551. Doo::db ()->commit ();
  2552. return "/invoiceReceivables";
  2553. }
  2554. echo 'no file';
  2555. }
  2556. function invoiceReceivables() {
  2557. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2558. Doo::loadModel ( 'L_category' );
  2559. $lCategory = new L_category ();
  2560. Doo::loadModel ( 'staff' );
  2561. $staff = new staff ();
  2562. Doo::loadModel ( 'invoiceReceivables' );
  2563. $invoiceReceivables = new invoiceReceivables ();
  2564. Doo::loadModel ( 'invoice' );
  2565. $invoice = new invoice ();
  2566. Doo::loadClass ( 'XDeode' );
  2567. $XDeode = new XDeode ( 5 );
  2568. $category = $lCategory->getCategory ();
  2569. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2570. $sql = 'bindStatus=1 and iid!=0';
  2571. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2572. // 获取未入账发票
  2573. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2574. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2575. foreach ( $invoiceUnAccount as $key => $value ) {
  2576. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2577. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2578. if (! empty ( $lastApprover )) {
  2579. $lastApproverKey = array_keys ( $lastApprover );
  2580. $lastApprover = end ( $lastApprover );
  2581. $staffDetail = $staff->getOne ( array (
  2582. 'where' => 'sid=' . end ( $lastApproverKey ),
  2583. 'asArray' => true
  2584. ) );
  2585. $lastApprover ['username'] = $staffDetail ['username'];
  2586. }
  2587. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2588. }
  2589. foreach ( $invoiceExistAccount as $key => $value ) {
  2590. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2591. if (empty ( $irList ))
  2592. $irList [0] ['sumPrice'] = 0;
  2593. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2594. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2595. $invoiceExistAccount [$key] ['balance'] = $balance;
  2596. }
  2597. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2598. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2599. $this->data ['halfList'] = $halfList;
  2600. $this->data ['halfCount'] = count ( $halfList );
  2601. // print_r($receivablesList);
  2602. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2603. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2604. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2605. $this->data ['receivablesInput'] = $receivablesInput;
  2606. $this->data ['year'] = date ( 'Y' );
  2607. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2608. $this->data ['receivablesList'] = $receivablesList;
  2609. $this->data ['staffList'] = $staffList;
  2610. $this->data ['category'] = $category;
  2611. $this->data ['memu'] = "invoice";
  2612. $this->data ['staff'] = $this->staff;
  2613. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2614. $this->render ( "/admin/invoiceReceivables", $this->data );
  2615. }
  2616. /**
  2617. * 设置收款认领地区
  2618. */
  2619. function setInvoiceReceivablesClaim() {
  2620. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2621. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2622. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2623. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2624. Doo::loadModel ( 'invoiceReceivables' );
  2625. $invoiceReceivables = new invoiceReceivables ();
  2626. Doo::loadClass ( 'XDeode' );
  2627. $XDeode = new XDeode ( 5 );
  2628. Doo::loadModel ( 'invoiceROLog' );
  2629. $invoiceROLog = new invoiceROLog ();
  2630. $irid = $XDeode->decode ( $iridKey );
  2631. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2632. if (empty ( $irDetail ))
  2633. die ( 'illegal request' );
  2634. $item = array (
  2635. 'irid' => $irid,
  2636. 'receivablesCategory' => $receivablesCategory
  2637. );
  2638. if ($receivablesCategory != 'PUBLIC') {
  2639. $item += array (
  2640. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2641. 'inputType' => 1
  2642. );
  2643. }
  2644. $invoiceReceivables = new invoiceReceivables ();
  2645. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2646. // 收款操作日志
  2647. $item = array (
  2648. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2649. 'date' => date ( "Y-m-d" ),
  2650. 'status' => 1,
  2651. 'img' => $this->staff [0] ['avatar'],
  2652. 'username' => $this->staff [0] ['username'],
  2653. 'uid' => $this->staff [0] ['sid'],
  2654. 'category' => $this->staff [0] ['category'],
  2655. 'irid' => $irid
  2656. );
  2657. $invoiceROLog->setInvoiceROLog ( $item );
  2658. if (empty ( $action ))
  2659. return '/invoiceReceivables';
  2660. else
  2661. return "/invoiceReceivablesAS";
  2662. }
  2663. die ( 'illegal request' );
  2664. }
  2665. /**
  2666. * 新添加收款直接入账发票
  2667. */
  2668. function invoiceCompareClaimPrice() {
  2669. // 收款录入
  2670. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2671. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2672. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2673. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2674. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2675. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2676. Doo::loadModel ( 'invoiceReceivables' );
  2677. $invoiceReceivables = new invoiceReceivables ();
  2678. Doo::loadModel ( 'invoiceROLog' );
  2679. $invoiceROLog = new invoiceROLog ();
  2680. Doo::loadModel ( 'invoiceStatistics' );
  2681. Doo::loadModel ( 'invoice' );
  2682. $invoice = new invoice ();
  2683. Doo::loadClass ( 'XDeode' );
  2684. $XDeode = new XDeode ( 5 );
  2685. Doo::loadModel ( 'invoiceOperationLog' );
  2686. $invoiceOperationLog = new invoiceOperationLog ();
  2687. $iidKey = $XDeode->decode ( $iidKey );
  2688. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2689. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2690. die ( 'illegal request' );
  2691. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2692. // 收款录入 并绑定发票
  2693. Doo::db ()->beginTransaction ();
  2694. $bindStatus = 0;
  2695. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2696. $bindStatus = 1;
  2697. $titleMark=$invoiceDetail['invoiceTitle'];
  2698. if (!empty($invoiceDetail['invoiceCompany']))
  2699. $titleMark=$invoiceDetail['invoiceCompany'];
  2700. $item = array (
  2701. 'recepitTitleMark'=>$titleMark,
  2702. 'bindStatus' => $bindStatus,
  2703. 'iid' => $invoiceDetail ['iid'],
  2704. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2705. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2706. 'receivablesPrice' => $receivablesPrice,
  2707. 'OriginalPrice' => $receivablesPrice,
  2708. 'receivablesMessage' => $receivablesMessage,
  2709. 'receivablesSerial' => $receivablesSerial,
  2710. 'receivablesBank' => $receivablesBank,
  2711. 'receivablesDate' => $receivablesDate,
  2712. 'inputStaff' => $this->staff [0] ['username'],
  2713. 'accountClerk' => $this->staff [0] ['username'],
  2714. 'date' => date ( "Y-m-d" ),
  2715. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2716. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2717. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2718. );
  2719. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2720. $item = array ();
  2721. // 收款操作日志
  2722. $item = array (
  2723. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2724. );
  2725. $item += array (
  2726. 'date' => date ( "Y-m-d" ),
  2727. 'status' => 1,
  2728. 'img' => $this->staff [0] ['avatar'],
  2729. 'username' => $this->staff [0] ['username'],
  2730. 'uid' => $this->staff [0] ['sid'],
  2731. 'category' => $this->staff [0] ['category'],
  2732. 'irid' => $irid
  2733. );
  2734. $invoiceROLog->setInvoiceROLog ( $item );
  2735. // 收款统计
  2736. $invoiceStatistics = new invoiceStatistics ();
  2737. $item = array (
  2738. 'date' => $receivablesDate,
  2739. 'priceClass' => 2,
  2740. 'irid' => $irid,
  2741. 'cid' => $invoiceDetail ['cid'],
  2742. 'staff' => $invoiceDetail ['sid'],
  2743. 'receivablesPrice' => $receivablesPrice
  2744. );
  2745. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2746. // 收款 入 发票
  2747. $detail = $invoiceDetail;
  2748. $iridString = "";
  2749. if (empty ( $detail ['irid'] ))
  2750. $iridString = $irid;
  2751. else
  2752. $iridString = $detail ['irid'] . ',' . $irid;
  2753. $item = array (
  2754. 'irid' => $iridString,
  2755. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2756. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2757. 'iid' => $detail ['iid']
  2758. );
  2759. $invoiceReceivables = new invoiceReceivables ();
  2760. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2761. if ($detail ['invoicePrice'] <= $sum)
  2762. $item += array (
  2763. 'untreadStatus' => 3
  2764. );
  2765. $invoice->setInvoiceByCondition ( $item );
  2766. // 操作日志
  2767. $item = array (
  2768. 'date' => date ( "Y-m-d H:i:s" ),
  2769. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  2770. 'status' => 8,
  2771. 'img' => $this->staff [0] ['avatar'],
  2772. 'username' => $this->staff [0] ['username'],
  2773. 'uid' => $this->staff [0] ['sid'],
  2774. 'category' => $this->staff [0] ['category'],
  2775. 'iid' => $detail ['iid']
  2776. );
  2777. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2778. // 入账汇总
  2779. $invoiceStatistics = new invoiceStatistics ();
  2780. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  2781. // $accountPrice = 0;
  2782. // foreach ( $list as $key => $value ) {
  2783. // $accountPrice += $value ['receivablesPrice'];
  2784. // }
  2785. $item = array (
  2786. 'date' => $receivablesDate,
  2787. 'priceClass' => 3,
  2788. 'cid' => $invoiceDetail ['cid'],
  2789. 'staff' => $invoiceDetail ['sid'],
  2790. 'accountPrice' => $receivablesPrice
  2791. );
  2792. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2793. // 公司流水记录
  2794. Doo::loadModel ( 'wasteBook' );
  2795. $wasteBook = new wasteBook ();
  2796. $abDetail = $wasteBook->getAccountBookByAid (2,7,$irid );
  2797. $accountBank='';
  2798. if ($receivablesBank=='纵横广发'){
  2799. $accountBank='CGBDeposit';
  2800. }elseif($receivablesBank=='纵横工行'){
  2801. $accountBank='ICBCDeposit';
  2802. }elseif($receivablesBank=='华润银行'){
  2803. $accountBank='HUADeposit';
  2804. }elseif($receivablesBank=='个人广发'){
  2805. $accountBank='PersonalDeposit';
  2806. }
  2807. if (empty($abDetail)){
  2808. $item = array (
  2809. 'dataID' => $irid,
  2810. 'expensesType' => 1,
  2811. 'accountType' => 7,
  2812. 'accountPrice'=>$receivablesPrice,
  2813. 'accountPriceShow'=>$receivablesPrice,
  2814. 'accountBank'=>$accountBank,
  2815. 'category'=>$this->staff[0]['category'],
  2816. 'cid'=>$this->staff[0]['cid'],
  2817. 'name'=>$this->staff[0]['username'],
  2818. 'sid'=>$this->staff[0]['sid'],
  2819. 'inputDate'=>date ( "Y-m-d H:i:s" )
  2820. );
  2821. $wasteBook->setAccountBookStatistics($item);
  2822. }
  2823. Doo::db ()->commit ();
  2824. }
  2825. return '/invoiceReceivables';
  2826. }
  2827. /**
  2828. * 录入收款数据
  2829. * @return string
  2830. */
  2831. function invoiceReceivablesDo() {
  2832. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2833. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2834. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2835. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2836. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2837. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2838. Doo::loadModel ( 'invoiceReceivables' );
  2839. $invoiceReceivables = new invoiceReceivables ();
  2840. Doo::loadModel ( 'invoiceROLog' );
  2841. $invoiceROLog = new invoiceROLog ();
  2842. Doo::loadModel ( 'invoiceStatistics' );
  2843. $invoiceStatistics = new invoiceStatistics ();
  2844. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  2845. $item = array (
  2846. 'receivablesPrice' => $receivablesPrice,
  2847. 'OriginalPrice' => $receivablesPrice,
  2848. 'receivablesMessage' => $receivablesMessage,
  2849. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  2850. 'receivablesBank' => $receivablesBank,
  2851. 'receivablesDate' => $receivablesDate,
  2852. 'inputStaff' => $this->staff [0] ['username'],
  2853. 'date' => date ( "Y-m-d" ),
  2854. 'receivablesCategory' => $receivablesCategory,
  2855. 'receivablesStaff' => $receivablesStaff
  2856. );
  2857. if ($receivablesCategory != 'PUBLIC') {
  2858. $item += array (
  2859. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2860. 'inputType' => 1
  2861. );
  2862. }
  2863. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2864. $item = array ();
  2865. // 收款操作日志
  2866. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2867. $item = array (
  2868. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2869. );
  2870. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2871. $item = array (
  2872. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2873. );
  2874. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2875. $receivablesStaff = explode ( '-', $receivablesStaff );
  2876. $item = array (
  2877. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2878. );
  2879. }
  2880. $item += array (
  2881. 'date' => date ( "Y-m-d" ),
  2882. 'status' => 1,
  2883. 'img' => $this->staff [0] ['avatar'],
  2884. 'username' => $this->staff [0] ['username'],
  2885. 'uid' => $this->staff [0] ['sid'],
  2886. 'category' => $this->staff [0] ['category'],
  2887. 'irid' => $irid
  2888. );
  2889. $invoiceROLog->setInvoiceROLog ( $item );
  2890. $item = array (
  2891. 'date' => $receivablesDate,
  2892. 'priceClass' => 2,
  2893. 'irid' => $irid,
  2894. 'receivablesPrice' => $receivablesPrice
  2895. );
  2896. if ($receivablesCategory != 'PUBLIC') {
  2897. $receivablesCategory = explode ( ":", $receivablesCategory );
  2898. $item += array (
  2899. 'cid' => $receivablesCategory [0]
  2900. );
  2901. }
  2902. if ($receivablesStaff2 != 'PUBLIC') {
  2903. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  2904. $item += array (
  2905. 'staff' => $receivablesStaff [0]
  2906. );
  2907. }
  2908. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2909. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  2910. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  2911. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  2912. if ($toparty != 0)
  2913. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  2914. // 公司流水记录
  2915. Doo::loadModel ( 'wasteBook' );
  2916. $wasteBook = new wasteBook ();
  2917. $abDetail = $wasteBook->getAccountBookByAid (1,7,$irid );
  2918. $accountBank='';
  2919. if ($receivablesBank=='纵横广发'){
  2920. $accountBank='CGBDeposit';
  2921. }elseif($receivablesBank=='纵横工行'){
  2922. $accountBank='ICBCDeposit';
  2923. }elseif($receivablesBank=='华润银行'){
  2924. $accountBank='HUADeposit';
  2925. }elseif($receivablesBank=='个人广发'){
  2926. $accountBank='PersonalDeposit';
  2927. }
  2928. $item = array (
  2929. 'dataID' => $irid,
  2930. 'expensesType' => 1,
  2931. 'accountType' => 7,
  2932. 'accountPriceShow'=>$receivablesPrice,
  2933. 'accountPrice'=>$receivablesPrice,
  2934. 'accountBank'=>$accountBank,
  2935. 'category'=>$this->staff[0]['category'],
  2936. 'cid'=>$this->staff[0]['cid'],
  2937. 'name'=>$this->staff[0]['username'],
  2938. 'sid'=>$this->staff[0]['sid'],
  2939. 'inputDate'=>date ( "Y-m-d H:i:s" )
  2940. );
  2941. $wasteBook->setAccountBookStatistics($item);
  2942. }
  2943. return "/invoiceReceivables";
  2944. }
  2945. /**
  2946. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  2947. */
  2948. function invoiceReceivablesClaim() {
  2949. Doo::loadModel ( 'invoiceReceivables' );
  2950. $invoiceReceivables = new invoiceReceivables ();
  2951. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2952. $this->data ['receivablesList'] = $receivablesList;
  2953. $this->data ['memu'] = "invoice";
  2954. $this->data ['staff'] = $this->staff;
  2955. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  2956. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  2957. }
  2958. function invoiceReceivablesTitleMarkSet() {
  2959. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2960. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2961. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  2962. die ( 'illegal request' );
  2963. Doo::loadModel ( 'invoiceReceivables' );
  2964. $invoiceReceivables = new invoiceReceivables ();
  2965. Doo::loadClass ( 'XDeode' );
  2966. $XDeode = new XDeode ( 5 );
  2967. $irid = $XDeode->decode ( $iridKey );
  2968. if (! is_numeric ( $irid ))
  2969. die ( 'illegal request' );
  2970. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  2971. $invoiceReceivables->update ( array (
  2972. 'where' => 'irid = ' . $irid
  2973. ) );
  2974. return '/invoiceReceivablesClaim';
  2975. }
  2976. /**
  2977. * 更新收款相关数据
  2978. */
  2979. function invoiceReceivablesUpdateClaim() {
  2980. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2981. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2982. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2983. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2984. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2985. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2986. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2987. if (empty ( $claimKey ))
  2988. die ( 'illegal request' );
  2989. Doo::loadModel ( 'invoiceReceivables' );
  2990. $invoiceReceivables = new invoiceReceivables ();
  2991. Doo::loadModel ( 'invoiceROLog' );
  2992. $invoiceROLog = new invoiceROLog ();
  2993. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  2994. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2995. if (empty ( $detail ))
  2996. die ( 'illegal request' );
  2997. $invoiceReceivables = new invoiceReceivables ();
  2998. $item = array (
  2999. 'irid' => $detail ['irid']
  3000. );
  3001. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3002. $item += array (
  3003. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3004. );
  3005. }
  3006. if (! empty ( $receivablesCategory ))
  3007. $item += array (
  3008. 'receivablesCategory' => $receivablesCategory
  3009. );
  3010. if (! empty ( $receivablesStaff ))
  3011. $item += array (
  3012. 'receivablesStaff' => $receivablesStaff
  3013. );
  3014. if (! empty ( $receivablesPrice ))
  3015. $item += array (
  3016. 'receivablesPrice' => $receivablesPrice
  3017. );
  3018. if (! empty ( $receivablesMessage ))
  3019. $item += array (
  3020. 'receivablesMessage' => $receivablesMessage
  3021. );
  3022. if (! empty ( $receivablesBank ))
  3023. $item += array (
  3024. 'receivablesBank' => $receivablesBank
  3025. );
  3026. if (! empty ( $receivablesDate ))
  3027. $item += array (
  3028. 'receivablesDate' => $receivablesDate
  3029. );
  3030. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3031. // 收款操作日志
  3032. $item = array ();
  3033. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3034. $item = array (
  3035. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3036. );
  3037. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3038. $item = array (
  3039. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3040. );
  3041. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3042. $receivablesStaff = explode ( '-', $receivablesStaff );
  3043. $item = array (
  3044. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3045. );
  3046. }
  3047. $item += array (
  3048. 'date' => date ( "Y-m-d" ),
  3049. 'status' => 1,
  3050. 'img' => $this->staff [0] ['avatar'],
  3051. 'username' => $this->staff [0] ['username'],
  3052. 'uid' => $this->staff [0] ['sid'],
  3053. 'category' => $this->staff [0] ['category'],
  3054. 'irid' => $detail ['irid']
  3055. );
  3056. $invoiceROLog->setInvoiceROLog ( $item );
  3057. return '/invoiceReceivablesAS';
  3058. }
  3059. function invoiceReceivablesDelete() {
  3060. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3061. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3062. if ($skll != '删除到款')
  3063. die ( 'illegal request' );
  3064. if (empty ( $claimKey ))
  3065. die ( 'illegal request' );
  3066. Doo::loadModel ( 'invoiceReceivables' );
  3067. $invoiceReceivables = new invoiceReceivables ();
  3068. $con = ' and bindStatus=0 ';
  3069. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3070. if (empty ( $detail ))
  3071. die ( 'illegal request' );
  3072. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3073. // 扣除收款汇总信息 汇总
  3074. Doo::loadModel ( 'invoiceStatistics' );
  3075. $invoiceStatistics = new invoiceStatistics ();
  3076. $item = array (
  3077. 'date' => $detail ['receivablesDate'],
  3078. 'priceClass' => 2,
  3079. 'irid' => $detail ['irid'],
  3080. 'receivablesPrice' => - $detail ['receivablesPrice']
  3081. );
  3082. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3083. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3084. $item += array (
  3085. 'cid' => $receivablesCategory [0]
  3086. );
  3087. }
  3088. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3089. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3090. $item += array (
  3091. 'staff' => $receivablesStaff [0]
  3092. );
  3093. }
  3094. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3095. // 公司流水-删除时删除流水
  3096. Doo::loadModel ( 'wasteBook' );
  3097. $wasteBook = new wasteBook ();
  3098. $wasteBook->delete ( array (
  3099. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3100. 'limit' => 1
  3101. ) );
  3102. return '/invoiceReceivablesAS';
  3103. }
  3104. /**
  3105. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3106. */
  3107. function invoiceReceivablesAscription() {
  3108. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3109. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3110. Doo::loadModel ( 'invoiceReceivables' );
  3111. $invoiceReceivables = new invoiceReceivables ();
  3112. Doo::loadModel ( 'invoiceROLog' );
  3113. $invoiceROLog = new invoiceROLog ();
  3114. Doo::loadModel ( 'invoiceStatistics' );
  3115. $invoiceStatistics = new invoiceStatistics ();
  3116. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3117. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3118. $item = array (
  3119. 'irid' => $detail ['irid'],
  3120. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3121. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3122. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3123. 'recepitTitleMark' => $recepitTitleMark,
  3124. 'source' => 1
  3125. );
  3126. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3127. $item = array (
  3128. 'date' => date ( "Y-m-d" ),
  3129. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3130. 'status' => 2,
  3131. 'img' => $this->staff [0] ['avatar'],
  3132. 'username' => $this->staff [0] ['username'],
  3133. 'uid' => $this->staff [0] ['sid'],
  3134. 'category' => $this->staff [0] ['category'],
  3135. 'irid' => $irid
  3136. );
  3137. $invoiceROLog->setInvoiceROLog ( $item );
  3138. $item = array (
  3139. 'cid' => $this->staff [0] ['cid'],
  3140. 'staff' => $this->staff [0] ['sid']
  3141. );
  3142. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3143. }
  3144. return "/invoiceReceivablesClaim";
  3145. }
  3146. /**
  3147. */
  3148. function invoiceMyReceivables() {
  3149. Doo::loadModel ( 'invoiceReceivables' );
  3150. $invoiceReceivables = new invoiceReceivables ();
  3151. Doo::loadModel ( 'invoiceStatistics' );
  3152. $invoiceStatistics = new invoiceStatistics ();
  3153. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3154. $year = date ( "Y" );
  3155. $tmp_date = date ( "Ym" );
  3156. $tmp_year = substr ( $tmp_date, 0, 4 );
  3157. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3158. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3159. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3160. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3161. $htm = $this->showCache ( $path );
  3162. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3163. $this->data ['isMonth'] = $isMonth;
  3164. $this->data ['htm'] = $htm;
  3165. $this->data ['list'] = $list;
  3166. $this->data ['memu'] = "invoice";
  3167. $this->data ['staff'] = $this->staff;
  3168. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3169. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3170. }
  3171. /**
  3172. * 纸票管理
  3173. */
  3174. function invoicePaper() {
  3175. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3176. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3177. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3178. $this->data ['dateString'] = $date;
  3179. $this->data ['status'] = $status;
  3180. $this->data ['invoiceType'] = $invoiceType;
  3181. $this->data ['memu'] = "invoice";
  3182. $this->data ['staff'] = $this->staff;
  3183. $this->data ['receiptMemu'] = 'invoicePaper';
  3184. $this->render ( "/admin/invoicePaper", $this->data );
  3185. }
  3186. /**
  3187. * 获得纸票分页数据
  3188. */
  3189. function ajaxGetinvoicePaperAchieve() {
  3190. Doo::loadModel ( 'invoicePaper' );
  3191. $invoicePaper = new invoicePaper ();
  3192. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3193. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3194. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3195. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3196. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3197. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3198. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3199. $MebSea = $this->get_args ( 'search' );
  3200. $MebSea = $MebSea ['value'];
  3201. $page_size = $length;
  3202. $con = '';
  3203. if ($status == 'ALL')
  3204. $con = ' where 1 ';
  3205. elseif ($status == 'PRINTED')
  3206. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=1 ';
  3207. elseif ($status == 'UNPRINT')
  3208. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=0 ';
  3209. elseif ($status == 'TICKET')
  3210. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3211. if ($invoiceType == 'ORDINARY')
  3212. $con .= ' and a.invoiceType=0 ';
  3213. elseif ($invoiceType == 'SPECIAL')
  3214. $con .= ' and a.invoiceType=1 ';
  3215. $dateArr = explode ( ':', $date );
  3216. $D1 = $dateString = '';
  3217. $D2 = '';
  3218. if (! empty ( $date )) {
  3219. $D1 = $dateArr [0];
  3220. if (isset ( $dateArr [1] ))
  3221. $D2 = $dateArr [1];
  3222. else
  3223. $D2 = '';
  3224. $dateString = $D1 . " : " . $D2;
  3225. }
  3226. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3227. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3228. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3229. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3230. if (! empty ( $MebSea ))
  3231. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3232. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3233. $sql = ' ' . $con;
  3234. $limit = $page . ',' . $page_size;
  3235. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3236. $paperList = array ();
  3237. foreach ( $list as $key => $value ) {
  3238. $irDetail = array ();
  3239. if ($value ['iid'] == 0)
  3240. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3241. else
  3242. array_push ( $irDetail, '' );
  3243. array_push ( $irDetail, $value ['invoiceCode'] );
  3244. array_push ( $irDetail, $value ['invoiceNo'] );
  3245. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3246. if ($value ['invoiceType'] == 1)
  3247. array_push ( $irDetail, $value ['invoiceCompany'] );
  3248. else
  3249. array_push ( $irDetail, $value ['invoiceTitle'] );
  3250. if ($value ['invoiceType'] == 1)
  3251. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3252. else
  3253. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3254. array_push ( $irDetail, $value ['invoiceElement'] );
  3255. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3256. array_push ( $irDetail, $value ['printTime'] );
  3257. array_push ( $paperList, $irDetail );
  3258. }
  3259. // $approvalListJson = json_encode ( $approvalList );
  3260. $recordsFiltered = $invoiceTotal;
  3261. echo json_encode ( array (
  3262. "draw" => intval ( $draw ),
  3263. "recordsTotal" => intval ( $invoiceTotal ),
  3264. "recordsFiltered" => intval ( $recordsFiltered ),
  3265. "data" => $paperList
  3266. ), JSON_UNESCAPED_UNICODE );
  3267. }
  3268. function invoicePaperDel() {
  3269. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3270. $XDeode = new XDeode ( 5 );
  3271. $ipid = $XDeode->decode ( $ipidKey );
  3272. if (empty ( $ipid ))
  3273. die ( 'illegal request' );
  3274. Doo::loadModel ( 'invoicePaper' );
  3275. $invoicePaper = new invoicePaper ();
  3276. $invoicePaper->delete ( array (
  3277. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3278. 'limit' => 1
  3279. ) );
  3280. return '/invoicePaper';
  3281. }
  3282. /**
  3283. * 添加纸质发票号
  3284. */
  3285. function invoicePaperAdd() {
  3286. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3287. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3288. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3289. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3290. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3291. $sum = $invoiceNoStart + $invoiceNoTotal;
  3292. if (empty ( $sum ))
  3293. die ( 'illegal request' );
  3294. // echo $invoiceNoStart;
  3295. // echo $sum;
  3296. // echo strlen((int)$invoiceNoStart);
  3297. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3298. Doo::db ()->beginTransaction ();
  3299. // 批量存储纸质发票
  3300. $date = date ( "Y-m-d H:i:s" );
  3301. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3302. VALUES ';
  3303. $paperList = array ();
  3304. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3305. // 数字前面自加0
  3306. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3307. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3308. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3309. array_push ( $paperList, $paperSql );
  3310. }
  3311. if (empty ( $paperList ))
  3312. die ( 'illegal request' );
  3313. $sql = $sql . implode ( ',', $paperList );
  3314. Doo::db ()->query ( $sql );
  3315. Doo::db ()->commit ();
  3316. return 'invoicePaper';
  3317. }
  3318. die ( 'illegal request' );
  3319. }
  3320. /**
  3321. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3322. */
  3323. function invoiceBindReceivables() {
  3324. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3325. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3326. Doo::loadModel ( 'invoice' );
  3327. $invoice = new invoice ();
  3328. Doo::loadModel ( 'invoiceReceivables' );
  3329. $invoiceReceivables = new invoiceReceivables ();
  3330. Doo::loadModel ( 'invoiceOperationLog' );
  3331. $invoiceOperationLog = new invoiceOperationLog ();
  3332. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3333. die ( 'illegal request' );
  3334. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3335. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3336. if (empty ( $detail ) && empty ( $detailM ))
  3337. die ( 'illegal request' );
  3338. if ($detail ['untreadStatus'] == 3)
  3339. die ( 'illegal request' );
  3340. // 修改 绑定状态改为 金额
  3341. $invoiceReceivables = new invoiceReceivables ();
  3342. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3343. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3344. $item = array (
  3345. 'bindPrice' => $invoicePrice
  3346. );
  3347. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3348. $item = array (
  3349. 'bindPrice' => $invoicePrice,
  3350. 'bindStatus' => 1,
  3351. 'bindDate' => date ( "Y-m-d H:i:s" )
  3352. );
  3353. } else {
  3354. die ( 'illegal request' );
  3355. }
  3356. if ($detailM ['iid'] == 0) {
  3357. $item += array (
  3358. 'iid' => $detail ['iid']
  3359. );
  3360. } else {
  3361. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3362. array_push ( $iidExtend, $detail ['iid'] );
  3363. $item += array (
  3364. 'iidExtend' => implode ( ',', $iidExtend )
  3365. );
  3366. }
  3367. $titleMark=$detail['invoiceTitle'];
  3368. if (!empty($detail['invoiceCompany']))
  3369. $titleMark=$detail['invoiceCompany'];
  3370. $item += array (
  3371. 'irid' => $detailM ['irid'],
  3372. 'recepitTitleMark'=>$titleMark,
  3373. 'accountClerk' => $this->staff [0] ['username']
  3374. );
  3375. // 如何没有人收款 则自动绑定收款
  3376. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3377. $item += array (
  3378. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3379. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3380. );
  3381. }
  3382. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3383. $iridString = "";
  3384. if (empty ( $detail ['irid'] ))
  3385. $iridString = $detailM ['irid'];
  3386. else
  3387. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3388. $item = array (
  3389. 'iid' => $detail ['iid'],
  3390. 'irid' => $iridString
  3391. );
  3392. $invoiceReceivables = new invoiceReceivables ();
  3393. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3394. if ($detail ['invoicePrice'] <= $sum)
  3395. $item += array (
  3396. 'untreadStatus' => 3,
  3397. 'bindTime' => date ( "Y-m-d H:i:s" )
  3398. );
  3399. // print_r($item);
  3400. // echo $sum;die;
  3401. $invoice->setInvoiceByCondition ( $item );
  3402. // 操作日志
  3403. $item = array (
  3404. 'date' => date ( "Y-m-d H:i:s" ),
  3405. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3406. 'status' => 8,
  3407. 'img' => $this->staff [0] ['avatar'],
  3408. 'username' => $this->staff [0] ['username'],
  3409. 'uid' => $this->staff [0] ['sid'],
  3410. 'category' => $this->staff [0] ['category'],
  3411. 'iid' => $detail ['iid']
  3412. );
  3413. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3414. Doo::loadModel ( 'invoiceStatistics' );
  3415. $invoiceStatistics = new invoiceStatistics ();
  3416. $item = array (
  3417. 'date' => $detailM ['receivablesDate'],
  3418. 'priceClass' => 3,
  3419. 'cid' => $detail ['cid'],
  3420. 'staff' => $detail ['sid'],
  3421. 'accountPrice' => $detailM ['receivablesPrice']
  3422. );
  3423. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3424. // 公司流水记录
  3425. // Doo::loadModel ( 'wasteBook' );
  3426. // $wasteBook = new wasteBook ();
  3427. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3428. // $accountBank='';
  3429. // if ($detailM ['receivablesBank']=='纵横广发'){
  3430. // $accountBank='CGBDeposit';
  3431. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3432. // $accountBank='ICBCDeposit';
  3433. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3434. // $accountBank='HUADeposit';
  3435. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3436. // $accountBank='PersonalDeposit';
  3437. // }
  3438. // if (empty($abDetail)){
  3439. // $item = array (
  3440. // 'dataID' => $detail ['iid'],
  3441. // 'expensesType' => 1,
  3442. // 'accountType' => 8,
  3443. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3444. // 'accountPrice'=>$detail ['invoicePrice'],
  3445. // 'accountBank'=>$accountBank,
  3446. // 'category'=>$this->staff[0]['category'],
  3447. // 'cid'=>$this->staff[0]['cid'],
  3448. // 'name'=>$this->staff[0]['username'],
  3449. // 'sid'=>$this->staff[0]['sid'],
  3450. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3451. // );
  3452. // $wasteBook->setAccountBookStatistics($item);
  3453. // }
  3454. return "/invoiceReceivables";
  3455. }
  3456. /**
  3457. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3458. */
  3459. function invoiceAggregate() {
  3460. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3461. Doo::loadModel ( 'invoiceStatistics' );
  3462. $invoiceStatistics = new invoiceStatistics ();
  3463. Doo::loadModel ( 'L_category' );
  3464. $Lcategory = new L_category ();
  3465. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3466. $LcategoryList = $Lcategory->getCategory ();
  3467. // print_r($isList);
  3468. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3469. foreach ( $LcategoryList as $key => $value ) {
  3470. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3471. $month = 1;
  3472. $invoicePriceYear = 0;
  3473. $receivablesPriceYear = 0;
  3474. $accountPriceYear = 0;
  3475. for(; $month <= 12; $month ++) {
  3476. $flag = true;
  3477. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3478. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3479. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3480. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3481. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3482. ';
  3483. $invoicePriceYear += $v ['invoicePrice'];
  3484. $receivablesPriceYear += $v ['receivablesPrice'];
  3485. $accountPriceYear += $v ['accountPrice'];
  3486. $flag = false;
  3487. break;
  3488. }
  3489. }
  3490. if ($flag)
  3491. $html .= '<td class="taR"></td>
  3492. <td class="taR"></td>
  3493. <td class="taR"><b></b></td>
  3494. ';
  3495. }
  3496. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3497. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3498. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3499. ';
  3500. $html .= '</tr>';
  3501. }
  3502. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3503. $invoicePriceYear = 0;
  3504. $receivablesPriceYear = 0;
  3505. $accountPriceYear = 0;
  3506. for($month = 1; $month <= 12; $month ++) {
  3507. $flag = true;
  3508. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3509. if ($month == $v ['month']) {
  3510. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3511. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3512. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3513. ';
  3514. $invoicePriceYear += $v ['invoicePrice'];
  3515. $receivablesPriceYear += $v ['receivablesPrice'];
  3516. $accountPriceYear += $v ['accountPrice'];
  3517. $flag = false;
  3518. break;
  3519. }
  3520. }
  3521. if ($flag) {
  3522. $html .= '<td class="taR"></td>
  3523. <td class="taR"></td>
  3524. <td class="taR"><b></b></td>
  3525. ';
  3526. }
  3527. }
  3528. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3529. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3530. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3531. ';
  3532. $html .= '</tr>';
  3533. // print_r($isList);
  3534. $this->data ['html'] = $html;
  3535. $this->data ['LcategoryList'] = $LcategoryList;
  3536. $this->data ['isList'] = $isList;
  3537. $this->data ['year'] = $year;
  3538. $this->data ['memu'] = "invoice";
  3539. $this->data ['staff'] = $this->staff;
  3540. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3541. $this->render ( "/admin/invoiceAggregate", $this->data );
  3542. }
  3543. function invoiceAggregateStaff() {
  3544. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3545. Doo::loadModel ( 'invoiceStatistics' );
  3546. $invoiceStatistics = new invoiceStatistics ();
  3547. Doo::loadModel ( 'L_category' );
  3548. $Lcategory = new L_category ();
  3549. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3550. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3551. $cStaff = $Lcategory->getCategoryStaff ();
  3552. $html = '';
  3553. foreach ( $cStaff as $key => $value ) {
  3554. $categoryFir = true;
  3555. foreach ( $value ['staff'] as $k => $v ) {
  3556. if ($categoryFir) {
  3557. $width = count ( $value ['staff'] ) + 1;
  3558. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3559. $categoryFir = false;
  3560. } else
  3561. $html .= '<tr>';
  3562. $html .= '<th>' . $v ['username'] . '</th>';
  3563. $invoicePriceStaffYear = 0;
  3564. $receivablesPriceStaffYear = 0;
  3565. $accountPriceStaffYear = 0;
  3566. for($month = 1; $month <= 12; $month ++) {
  3567. $flag = true;
  3568. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3569. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3570. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3571. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3572. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3573. ';
  3574. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3575. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3576. $accountPriceStaffYear += $slv ['accountPrice'];
  3577. $flag = false;
  3578. break;
  3579. }
  3580. }
  3581. if ($flag)
  3582. $html .= '<td class="taR"></td>
  3583. <td class="taR"></td>
  3584. <td class="taR"><b></b></td>
  3585. ';
  3586. }
  3587. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3588. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3589. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3590. ';
  3591. }
  3592. $html .= '</tr>';
  3593. // 小计
  3594. if (! empty ( $value ['staff'] )) {
  3595. $html .= '<tr><th class="taR">小计</th>';
  3596. $invoicePriceStaffYear = 0;
  3597. $receivablesPriceStaffYear = 0;
  3598. $accountPriceStaffYear = 0;
  3599. for($month = 1; $month <= 12; $month ++) {
  3600. $flag = true;
  3601. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3602. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3603. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3604. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3605. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3606. ';
  3607. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3608. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3609. $accountPriceStaffYear += $slv ['accountPrice'];
  3610. $flag = false;
  3611. break;
  3612. }
  3613. }
  3614. if ($flag)
  3615. $html .= '<td class="taR"></td>
  3616. <td class="taR"></td>
  3617. <td class="taR"><b></b></td>
  3618. ';
  3619. }
  3620. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3621. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3622. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3623. ';
  3624. $html .= '</tr>';
  3625. }
  3626. }
  3627. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3628. $invoicePriceYear = 0;
  3629. $receivablesPriceYear = 0;
  3630. $accountPriceYear = 0;
  3631. for($month = 1; $month <= 12; $month ++) {
  3632. $flag = true;
  3633. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3634. if ($month == $v ['month']) {
  3635. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3636. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3637. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3638. ';
  3639. $invoicePriceYear += $v ['invoicePrice'];
  3640. $receivablesPriceYear += $v ['receivablesPrice'];
  3641. $accountPriceYear += $v ['accountPrice'];
  3642. $flag = false;
  3643. break;
  3644. }
  3645. }
  3646. if ($flag)
  3647. $html .= '<td class="taR"></td>
  3648. <td class="taR"></td>
  3649. <td class="taR"><b></b></td>
  3650. ';
  3651. }
  3652. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3653. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3654. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3655. ';
  3656. $html .= '</tr>';
  3657. $this->data ['html'] = $html;
  3658. $this->data ['isList'] = $toteList;
  3659. $this->data ['year'] = $year;
  3660. $this->data ['memu'] = "invoice";
  3661. $this->data ['staff'] = $this->staff;
  3662. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3663. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3664. }
  3665. function invoiceAggregateCategory() {
  3666. Doo::loadClass ( 'XDeode' );
  3667. $XDeode = new XDeode ( 5 );
  3668. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3669. $cid = $XDeode->decode ( $cid );
  3670. if (! is_numeric ( $cid ))
  3671. die ( 'illegal request' );
  3672. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3673. Doo::loadModel ( 'invoiceStatistics' );
  3674. $invoiceStatistics = new invoiceStatistics ();
  3675. Doo::loadModel ( 'staff' );
  3676. $staff = new staff ();
  3677. $list = $staff->getStaffByCid ( $cid );
  3678. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3679. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3680. if (empty ( $list ))
  3681. die ( '该办事处没有成员' );
  3682. $htmlA = $htmlB = $htmlC = $html = '';
  3683. foreach ( $list as $key => $value ) {
  3684. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3685. $htmlB = '<tr><th class="taC">收款</th>';
  3686. $htmlC = '<tr><th class="taC">入账</th>';
  3687. $invoicePriceStaffYear = 0;
  3688. $receivablesPriceStaffYear = 0;
  3689. $accountPriceStaffYear = 0;
  3690. for($month = 1; $month <= 12; $month ++) {
  3691. $flag = true;
  3692. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3693. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3694. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3695. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3696. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3697. $invoicePriceStaffYear += $v ['invoicePrice'];
  3698. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3699. $accountPriceStaffYear += $v ['accountPrice'];
  3700. $flag = false;
  3701. break;
  3702. }
  3703. }
  3704. if ($flag) {
  3705. $htmlA .= '<td class="taR">-</td>';
  3706. $htmlB .= '<td class="taR">-</td>';
  3707. $htmlC .= '<td class="taR"><b>-</b></td>';
  3708. }
  3709. }
  3710. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3711. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3712. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3713. $htmlA .= '</tr>';
  3714. $htmlB .= '</tr>';
  3715. $htmlC .= '</tr>';
  3716. $html .= $htmlA . $htmlB . $htmlC;
  3717. }
  3718. $htmlA = $htmlB = $htmlC = "";
  3719. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3720. $htmlB = '<tr><th class="taC">收款</th>';
  3721. $htmlC = '<tr><th class="taC">入账</th>';
  3722. $invoicePriceStaffYear = 0;
  3723. $receivablesPriceStaffYear = 0;
  3724. $accountPriceStaffYear = 0;
  3725. for($month = 1; $month <= 12; $month ++) {
  3726. $flag = true;
  3727. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3728. if ($month == $v ['month']) {
  3729. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3730. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3731. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3732. $invoicePriceStaffYear += $v ['invoicePrice'];
  3733. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3734. $accountPriceStaffYear += $v ['accountPrice'];
  3735. $flag = false;
  3736. break;
  3737. }
  3738. }
  3739. if ($flag) {
  3740. $htmlA .= '<td class="taR">-</td>';
  3741. $htmlB .= '<td class="taR">-</td>';
  3742. $htmlC .= '<td class="taR"><b>-</b></td>';
  3743. }
  3744. }
  3745. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3746. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3747. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3748. $htmlA .= '</tr>';
  3749. $htmlB .= '</tr>';
  3750. $htmlC .= '</tr>';
  3751. $html .= $htmlA . $htmlB . $htmlC;
  3752. $this->data ['html'] = $html;
  3753. $this->data ['cidKey'] = $cidKey;
  3754. $this->data ['slist'] = $list;
  3755. $this->data ['isList'] = $toteList;
  3756. $this->data ['year'] = $year;
  3757. $this->data ['memu'] = "invoice";
  3758. $this->data ['staff'] = $this->staff;
  3759. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3760. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3761. }
  3762. /**
  3763. * 办事处汇总信息
  3764. */
  3765. function invoiceAggregateCategoryDetail() {
  3766. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  3767. Doo::loadClass ( 'XDeode' );
  3768. $XDeode = new XDeode ( 5 );
  3769. Doo::loadModel ( 'invoiceStatistics' );
  3770. $invoiceStatistics = new invoiceStatistics ();
  3771. Doo::loadModel ( 'L_category' );
  3772. $category = new L_category ();
  3773. Doo::loadModel ( 'invoice' );
  3774. $invoice = new invoice ();
  3775. Doo::loadModel ( 'staff' );
  3776. $staff = new staff ();
  3777. Doo::loadModel ( "invoiceCategoryManage" );
  3778. $invoiceCategoryManage = new invoiceCategoryManage ();
  3779. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3780. $cidList = array ();
  3781. foreach ( $imcStaff as $key => $value ) {
  3782. array_push ( $cidList, $value ['cid'] );
  3783. if (empty ( $cidKey ))
  3784. $cidKey = $XDeode->encode ( $value ['cid'] );
  3785. }
  3786. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  3787. $cid = $XDeode->decode ( $cidKey );
  3788. $month = date ( "m", strtotime ( "-1 month" ) );
  3789. $redis = new Redis ();
  3790. $redis->connect ( '127.0.0.1', '6379' );
  3791. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  3792. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  3793. if (empty ( $redisValue )) {
  3794. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  3795. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  3796. // 获得办事处人员下的汇总
  3797. $slist = $staff->getStaffByCid ( $cid );
  3798. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $month ); // 上一个月的汇总
  3799. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  3800. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  3801. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  3802. foreach ( $slist as $key => $value ) {
  3803. $slist [$key] ['invoicePrice'] = 0;
  3804. $slist [$key] ['receivablesPrice'] = 0;
  3805. $slist [$key] ['accountPrice'] = 0;
  3806. $slist [$key] ['invoiceAllPrice'] = 0;
  3807. $slist [$key] ['receivablesAllPrice'] = 0;
  3808. $slist [$key] ['accountAllPrice'] = 0;
  3809. $slist [$key] ['schedule'] = 0;
  3810. $slist [$key] ['invoiceMonthPrice'] = 0;
  3811. $slist [$key] ['receivablesMonthPrice'] = 0;
  3812. $slist [$key] ['accountMonthPrice'] = 0;
  3813. foreach ( $ismsbMonth as $y => $l ) {
  3814. if ($value ['sid'] == $l ['staff']) {
  3815. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  3816. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  3817. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  3818. }
  3819. }
  3820. foreach ( $ismsb as $k => $v ) {
  3821. if ($value ['sid'] == $v ['staff']) {
  3822. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  3823. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  3824. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  3825. }
  3826. }
  3827. foreach ( $ISAS as $e => $a ) {
  3828. if ($value ['sid'] == $a ['staff']) {
  3829. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  3830. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  3831. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  3832. }
  3833. }
  3834. if (isset ( $scheduleStaff [$value ['sid']] ))
  3835. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  3836. }
  3837. $this->data ['cidKey'] = $cidKey;
  3838. $schedule = ( int ) ($schedule * 100);
  3839. $this->data ['slist'] = $slist;
  3840. $this->data ['isMC'] = $isMC;
  3841. $this->data ['schedule'] = $schedule;
  3842. $slist = json_encode ( $slist );
  3843. $isMC = json_encode ( $isMC );
  3844. $schedule = json_encode ( $schedule );
  3845. $redis->lpush ( $redisKey, $slist );
  3846. $redis->lpush ( $redisKey, $isMC );
  3847. $redis->lpush ( $redisKey, $schedule );
  3848. } else {
  3849. $this->data ['cidKey'] = $cidKey;
  3850. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  3851. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  3852. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  3853. }
  3854. $this->data ['month'] = $month;
  3855. $this->data ['categoryList'] = $categoryList;
  3856. $this->data ['memu'] = "invoice";
  3857. $this->data ['staff'] = $this->staff;
  3858. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3859. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  3860. }
  3861. /**
  3862. * 办事处人员汇总详情
  3863. */
  3864. function invoiceAggregateStaffDetail() {
  3865. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3866. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  3867. Doo::loadClass ( 'XDeode' );
  3868. $XDeode = new XDeode ( 5 );
  3869. Doo::loadModel ( 'invoice' );
  3870. $invoice = new invoice ();
  3871. Doo::loadModel ( 'staff' );
  3872. $staff = new staff ();
  3873. Doo::loadModel ( "invoiceCategoryManage" );
  3874. $invoiceCategoryManage = new invoiceCategoryManage ();
  3875. $sid = $XDeode->decode ( $sidKey );
  3876. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3877. $cidList = array ();
  3878. foreach ( $imcStaff as $key => $value ) {
  3879. array_push ( $cidList, $value ['cid'] );
  3880. if (empty ( $cidKey ))
  3881. $cidKey = $XDeode->encode ( $value ['cid'] );
  3882. }
  3883. $cidString = implode ( ',', $cidList );
  3884. $staffList = $staff->getStaffInCid ( $cidString );
  3885. $staffDetail = $staff->getStaffBySid ( $sid );
  3886. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3887. $page_size = 18;
  3888. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3889. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3890. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3891. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3892. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3893. $dateArr = explode ( ':', $date );
  3894. $D1 = '';
  3895. $D2 = '';
  3896. if (! empty ( $date )) {
  3897. $D1 = $dateArr [0] . " 00:00:00 ";
  3898. if (isset ( $dateArr [1] ))
  3899. $D2 = $dateArr [1] . " 23:59:59 ";
  3900. else
  3901. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3902. // $D2 = $dateArr [1];
  3903. }
  3904. $con = ' status=2 ';
  3905. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3906. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3907. if ($status == 'UNRECORD')
  3908. $con .= ' and printStatus=1 and untreadStatus=0';
  3909. elseif ($status == 'RECORD')
  3910. $con .= ' and printStatus=1 and untreadStatus=3';
  3911. elseif ($status == 'BOUNCED')
  3912. $con .= ' and untreadStatus=2';
  3913. elseif ($status == 'PARTRECORD')
  3914. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  3915. elseif ($status == 'All') {
  3916. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  3917. }
  3918. $con .= ' and sid=' . $sid;
  3919. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  3920. if (! empty ( $MebSea )) {
  3921. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  3922. }
  3923. $pageinfo ['page'] = array (
  3924. 'previous' => ''
  3925. );
  3926. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  3927. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3928. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  3929. $this->data ['staffDetail'] = $staffDetail;
  3930. $this->data ['staffList'] = $staffList;
  3931. $this->data ['MebSeaEn'] = $MebSea;
  3932. $this->data ['MebSea'] = urlencode ( $MebSea );
  3933. $this->data ['date'] = $date;
  3934. $this->data ['page'] = $pageinfo;
  3935. $this->data ['get'] = $get;
  3936. $this->data ['list'] = $list;
  3937. $this->data ['status'] = $status;
  3938. $this->data ['sidKey'] = $sidKey;
  3939. $this->data ['memu'] = "invoice";
  3940. $this->data ['staff'] = $this->staff;
  3941. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3942. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  3943. }
  3944. /**
  3945. * 办事处人员汇总收款情
  3946. */
  3947. function invoiceAggregateStaffReceivablesDetail() {
  3948. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3949. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3950. Doo::loadModel ( 'invoiceReceivables' );
  3951. $invoiceReceivables = new invoiceReceivables ();
  3952. Doo::loadModel ( 'staff' );
  3953. $staff = new staff ();
  3954. Doo::loadModel ( "invoiceCategoryManage" );
  3955. $invoiceCategoryManage = new invoiceCategoryManage ();
  3956. Doo::loadClass ( 'XDeode' );
  3957. $XDeode = new XDeode ( 5 );
  3958. $sid = $XDeode->decode ( $sidKey );
  3959. $staffDetail = $staff->getStaffBySid ( $sid );
  3960. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3961. $cidList = array ();
  3962. foreach ( $imcStaff as $key => $value ) {
  3963. array_push ( $cidList, $value ['cid'] );
  3964. if (empty ( $cidKey ))
  3965. $cidKey = $XDeode->encode ( $value ['cid'] );
  3966. }
  3967. $cidString = implode ( ',', $cidList );
  3968. $staffList = $staff->getStaffInCid ( $cidString );
  3969. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3970. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  3971. $page_size = 10;
  3972. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3973. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3974. if ($timeType == "BINDOTP") {
  3975. $status = 'Credited';
  3976. }
  3977. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3978. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3979. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3980. $dateArr = explode ( ':', $date );
  3981. $D1 = '';
  3982. $D2 = '';
  3983. if (! empty ( $date )) {
  3984. $D1 = $dateArr [0] . " 00:00:00 ";
  3985. if (isset ( $dateArr [1] ))
  3986. $D2 = $dateArr [1] . " 23:59:59 ";
  3987. else
  3988. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3989. }
  3990. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  3991. $descField = 'a.bindDate';
  3992. if ($timeType == 'CREATE')
  3993. $descField = 'a.date';
  3994. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3995. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3996. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3997. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  3998. if ($status == 'Unclaimed')
  3999. $con .= ' and a.bindStatus=0';
  4000. elseif ($status == 'Credited')
  4001. $con .= ' and a.bindStatus=1';
  4002. elseif ($status == 'Claim')
  4003. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4004. elseif ($status == 'BBN')
  4005. $con .= ' and a.bindPrice>a.receivablesPrice';
  4006. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4007. if (! empty ( $MebSea )) {
  4008. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4009. }
  4010. $pageinfo ['page'] = array (
  4011. 'previous' => ''
  4012. );
  4013. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4014. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4015. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4016. where ' . $con . ' group by a.irid ';
  4017. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4018. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4019. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4020. foreach ( $list as $key => $value ) {
  4021. $list [$key] ['category'] = '';
  4022. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4023. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4024. $list [$key] ['category'] = $receivablesCategory [1];
  4025. }
  4026. }
  4027. // print_r($list);
  4028. $this->data ['staffDetail'] = $staffDetail;
  4029. $this->data ['sidKey'] = $sidKey;
  4030. $this->data ['staffList'] = $staffList;
  4031. $this->data ['timeType'] = $timeType;
  4032. $this->data ['MebSeaEn'] = $MebSea;
  4033. $this->data ['MebSea'] = urlencode ( $MebSea );
  4034. $this->data ['date'] = $date;
  4035. $this->data ['page'] = $pageinfo;
  4036. $this->data ['get'] = $get;
  4037. $this->data ['list'] = $list;
  4038. $this->data ['status'] = $status;
  4039. $this->data ['memu'] = "invoice";
  4040. $this->data ['staff'] = $this->staff;
  4041. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4042. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4043. }
  4044. function invoiceAchieve() {
  4045. Doo::loadModel ( 'invoice' );
  4046. $invoice = new invoice ();
  4047. Doo::loadClass ( 'XDeode' );
  4048. $XDeode = new XDeode ( 5 );
  4049. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4050. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4051. $page_size = 18;
  4052. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4053. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4054. $get = "/" . $date;
  4055. $con = '';
  4056. if ($date == 'MONTHO')
  4057. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4058. elseif ($date == 'MONTHT')
  4059. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4060. elseif ($date == 'MONTHY')
  4061. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4062. if (! empty ( $MebSea )) {
  4063. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4064. $get .= "/" . $MebSea;
  4065. }
  4066. $pageinfo ['page'] = array (
  4067. 'previous' => ''
  4068. );
  4069. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4070. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4071. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4072. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4073. // print_r($pageinfo);
  4074. $this->data ['MebSeaEn'] = $MebSea;
  4075. $this->data ['MebSea'] = urlencode ( $MebSea );
  4076. $this->data ['get'] = $get;
  4077. $this->data ['page'] = $pageinfo;
  4078. $this->data ['list'] = $list;
  4079. $this->data ['date'] = $date;
  4080. $this->data ['memu'] = "invoice";
  4081. $this->data ['staff'] = $this->staff;
  4082. $this->data ['receiptMemu'] = 'invoice';
  4083. $this->render ( "/admin/invoiceAchieve", $this->data );
  4084. }
  4085. /**
  4086. */
  4087. function invoiceMyUnAccountAchieve() {
  4088. Doo::loadModel ( 'invoice' );
  4089. $invoice = new invoice ();
  4090. Doo::loadClass ( 'XDeode' );
  4091. $XDeode = new XDeode ( 5 );
  4092. Doo::loadModel ( 'staff' );
  4093. $staff = new staff ();
  4094. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4095. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4096. $page_size = 18;
  4097. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4098. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4099. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4100. $dateArr = explode ( ':', $date );
  4101. $D1 = '';
  4102. $D2 = '';
  4103. if (! empty ( $date )) {
  4104. $D1 = $dateArr [0];
  4105. $D2 = $dateArr [1];
  4106. }
  4107. $con = '';
  4108. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4109. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4110. if (! empty ( $MebSea )) {
  4111. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4112. }
  4113. $pageinfo ['page'] = array (
  4114. 'previous' => ''
  4115. );
  4116. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4117. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4118. $action = "invoiceMyUnAccountAchieve";
  4119. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4120. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4121. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4122. Doo::loadModel ( 'express' );
  4123. $express = new express ();
  4124. $expressList = $express->getExpressByAll ();
  4125. $this->data ['expressList'] = $expressList;
  4126. // print_r($list);
  4127. $this->data ['MebSeaEn'] = $MebSea;
  4128. $this->data ['get'] = $get;
  4129. $this->data ['page'] = $pageinfo;
  4130. $this->data ['date'] = $date;
  4131. $this->data ['list'] = $list;
  4132. $this->data ['memu'] = "invoice";
  4133. $this->data ['staff'] = $this->staff;
  4134. $this->data ['receiptMemu'] = 'invoice';
  4135. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4136. }
  4137. function invoiceReceivablesAchieve() {
  4138. Doo::loadModel ( 'invoiceReceivables' );
  4139. $invoiceReceivables = new invoiceReceivables ();
  4140. Doo::loadClass ( 'XDeode' );
  4141. $XDeode = new XDeode ( 5 );
  4142. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4143. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4144. $page_size = 12;
  4145. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4146. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4147. $get = "/" . $date;
  4148. $con = '';
  4149. if ($date == 'MONTHO')
  4150. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4151. elseif ($date == 'MONTHT')
  4152. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4153. elseif ($date == 'MONTHY')
  4154. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4155. if (! empty ( $MebSea )) {
  4156. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4157. $get .= "/" . $MebSea;
  4158. }
  4159. $pageinfo ['page'] = array (
  4160. 'previous' => ''
  4161. );
  4162. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  4163. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4164. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4165. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4166. // print_r($pageinfo);
  4167. $this->data ['MebSeaEn'] = $MebSea;
  4168. $this->data ['MebSea'] = urlencode ( $MebSea );
  4169. $this->data ['get'] = $get;
  4170. $this->data ['page'] = $pageinfo;
  4171. $this->data ['list'] = $list;
  4172. $this->data ['date'] = $date;
  4173. $this->data ['memu'] = "invoice";
  4174. $this->data ['staff'] = $this->staff;
  4175. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4176. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4177. }
  4178. /**
  4179. * 收款解绑
  4180. */
  4181. function invoiceUnBundLing() {
  4182. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4183. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4184. Doo::loadModel ( 'invoice' );
  4185. $invoice = new invoice ();
  4186. Doo::loadModel ( 'invoiceReceivables' );
  4187. $invoiceReceivables = new invoiceReceivables ();
  4188. Doo::loadModel ( 'invoiceOperationLog' );
  4189. $invoiceOperationLog = new invoiceOperationLog ();
  4190. Doo::loadModel ( 'invoiceROLog' );
  4191. $invoiceROLog = new invoiceROLog ();
  4192. Doo::loadModel ( 'invoiceStatistics' );
  4193. Doo::loadClass ( 'XDeode' );
  4194. $XDeode = new XDeode ( 5 );
  4195. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4196. die ( 'illegal request' );
  4197. $iid = $XDeode->decode ( $iidKey );
  4198. $irid = $invoice->authcode ( $unBundKey );
  4199. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4200. die ( 'illegal request' );
  4201. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4202. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4203. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4204. die ( 'illegal request' );
  4205. // 收款
  4206. $item = array (
  4207. 'irid' => $irDetails ['irid'],
  4208. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4209. 'bindStatus' => 0
  4210. );
  4211. if ($irDetails ['iid'] == $iid)
  4212. $item += array (
  4213. 'iid' => 0
  4214. );
  4215. else {
  4216. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4217. foreach ( $iidExtend as $key => $value ) {
  4218. if ($value == $iid)
  4219. unset ( $iidExtend [$key] );
  4220. }
  4221. $iidExtend = implode ( ',', $iidExtend );
  4222. $item += array (
  4223. 'iidExtend' => $iidExtend
  4224. );
  4225. }
  4226. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4227. // 收款操作日志
  4228. $item = array (
  4229. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4230. 'date' => date ( "Y-m-d" ),
  4231. 'status' => 3,
  4232. 'img' => $this->staff [0] ['avatar'],
  4233. 'username' => $this->staff [0] ['username'],
  4234. 'uid' => $this->staff [0] ['sid'],
  4235. 'category' => $this->staff [0] ['category'],
  4236. 'irid' => $irid
  4237. );
  4238. $invoiceROLog->setInvoiceROLog ( $item );
  4239. // 扣除入账统计金额
  4240. $invoiceStatistics = new invoiceStatistics ();
  4241. $item = array (
  4242. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4243. 'priceClass' => 3,
  4244. 'cid' => $invoiceDetails ['cid'],
  4245. 'staff' => $invoiceDetails ['sid'],
  4246. 'accountPrice' => - $irDetails ['receivablesPrice']
  4247. );
  4248. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4249. // 扣除收款统计金额
  4250. $invoiceStatistics = new invoiceStatistics ();
  4251. $item = array (
  4252. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4253. 'priceClass' => 2,
  4254. 'cid' => $invoiceDetails ['cid'],
  4255. 'staff' => $invoiceDetails ['sid'],
  4256. 'irid' => $irDetails ['irid'],
  4257. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4258. );
  4259. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4260. // 发票解绑去收款ID
  4261. $iridString = $invoiceDetails ['irid'];
  4262. if (! empty ( $invoiceDetails ['irid'] )) {
  4263. $list = explode ( ',', $invoiceDetails ['irid'] );
  4264. foreach ( $list as $key => $value ) {
  4265. if ($value == $irDetails ['irid']) {
  4266. unset ( $list [$key] );
  4267. break;
  4268. }
  4269. }
  4270. $iridString = implode ( ",", $list );
  4271. }
  4272. $item = array (
  4273. 'iid' => $invoiceDetails ['iid'],
  4274. 'irid' => $iridString,
  4275. 'updateTime' => date ( "Y-m-d H:i:s" )
  4276. );
  4277. if ($invoiceDetails ['untreadStatus'] == 3)
  4278. $item += array (
  4279. 'untreadStatus' => 0
  4280. );
  4281. $invoice->setInvoiceByCondition ( $item );
  4282. $item = array (
  4283. 'date' => date ( "Y-m-d H:i:s" ),
  4284. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4285. 'status' => 11,
  4286. 'img' => $this->staff [0] ['avatar'],
  4287. 'username' => $this->staff [0] ['username'],
  4288. 'uid' => $this->staff [0] ['sid'],
  4289. 'category' => $this->staff [0] ['category'],
  4290. 'iid' => $invoiceDetails ['iid']
  4291. );
  4292. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4293. // 公司流水-解绑时删除流水
  4294. Doo::loadModel ( 'wasteBook' );
  4295. $wasteBook = new wasteBook ();
  4296. // $wasteBook->delete ( array (
  4297. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4298. // 'limit' => 1
  4299. // ) );
  4300. // 银行
  4301. /*
  4302. * $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); }
  4303. */
  4304. return "/invoiceReceivablesAS";
  4305. }
  4306. /**
  4307. * 或者该收款下的所以发票
  4308. */
  4309. function ajaxGetInvoiceReceivablesByInvoice() {
  4310. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4311. Doo::loadModel ( 'invoice' );
  4312. $invoice = new invoice ();
  4313. Doo::loadModel ( 'invoiceReceivables' );
  4314. $invoiceReceivables = new invoiceReceivables ();
  4315. $irid = $invoice->authcode ( $irid );
  4316. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4317. die ( 'illegal request' );
  4318. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4319. $iidString = $irDetails ['iid'];
  4320. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4321. if (! empty ( $irDetails ['iidExtend'] ))
  4322. $iidString .= ',' . implode ( ',', $iidExtend );
  4323. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4324. $html = "";
  4325. foreach ( $invoiceList as $key => $value ) {
  4326. $title = $value ['invoiceTitle'];
  4327. if (! empty ( $value ['invoiceCompany'] ))
  4328. $title = $value ['invoiceCompany'];
  4329. $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>';
  4330. }
  4331. echo json_encode ( array (
  4332. 'status' => 1,
  4333. 'html' => $html
  4334. ) );
  4335. }
  4336. /**
  4337. * 发票管理
  4338. */
  4339. function invoiceAS() {
  4340. Doo::loadModel ( 'invoice' );
  4341. $invoice = new invoice ();
  4342. Doo::loadModel ( 'invoiceReceivables' );
  4343. $invoiceReceivables = new invoiceReceivables ();
  4344. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4345. $page_size = 18;
  4346. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4347. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4348. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4349. $dateArr = explode ( ':', $date );
  4350. $D1 = '';
  4351. $D2 = '';
  4352. if (! empty ( $date )) {
  4353. $D1 = $dateArr [0] . " 00:00:00 ";
  4354. if (isset ( $dateArr [1] ))
  4355. $D2 = $dateArr [1] . " 23:59:59 ";
  4356. else
  4357. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4358. // $D2 = $dateArr [1];
  4359. }
  4360. $con = ' status=2 ';
  4361. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4362. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4363. if ($status == 'UNRECORD')
  4364. $con .= ' and printStatus=1 and untreadStatus=0';
  4365. elseif ($status == 'RECORD')
  4366. $con .= ' and printStatus=1 and untreadStatus=3';
  4367. elseif ($status == 'BOUNCED')
  4368. $con .= ' and untreadStatus=2';
  4369. elseif ($status == 'PARTRECORD')
  4370. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4371. elseif ($status == 'All') {
  4372. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4373. }
  4374. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4375. if (! empty ( $MebSea )) {
  4376. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4377. }
  4378. $pageinfo ['page'] = array (
  4379. 'previous' => ''
  4380. );
  4381. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4382. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4383. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4384. $this->data ['MebSeaEn'] = $MebSea;
  4385. $this->data ['MebSea'] = urlencode ( $MebSea );
  4386. $this->data ['date'] = $date;
  4387. $this->data ['page'] = $pageinfo;
  4388. $this->data ['get'] = $get;
  4389. $this->data ['list'] = $list;
  4390. $this->data ['status'] = $status;
  4391. $this->data ['memu'] = "invoice";
  4392. $this->data ['staff'] = $this->staff;
  4393. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4394. $this->render ( "/admin/invoiceAS", $this->data );
  4395. }
  4396. /**
  4397. * 收款管理
  4398. */
  4399. function invoiceReceivablesAS() {
  4400. Doo::loadModel ( 'invoiceReceivables' );
  4401. $invoiceReceivables = new invoiceReceivables ();
  4402. Doo::loadModel ( 'L_category' );
  4403. $lCategory = new L_category ();
  4404. $category = $lCategory->getCategory ();
  4405. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4406. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4407. $page_size = 10;
  4408. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4409. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4410. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4411. $dateArr = explode ( ':', $date );
  4412. $D1 = '';
  4413. $D2 = '';
  4414. if (! empty ( $date )) {
  4415. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4416. if (isset ( $dateArr [1] ))
  4417. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4418. else
  4419. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4420. }
  4421. $descField = 'a.receivablesDate';
  4422. if ($timeType == 'CREATE')
  4423. $descField = 'a.date';
  4424. $con = '1';
  4425. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4426. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4427. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4428. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4429. if ($status == 'Unclaimed')
  4430. $con .= ' and a.bindStatus=0';
  4431. elseif ($status == 'Credited')
  4432. $con .= ' and a.bindStatus=1';
  4433. elseif ($status == 'Claim')
  4434. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4435. elseif ($status == 'BBN')
  4436. $con .= ' and a.bankBatchNumber!=""';
  4437. elseif ($status == 'REFUND')
  4438. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4439. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4440. if (! empty ( $MebSea )) {
  4441. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4442. }
  4443. $pageinfo ['page'] = array (
  4444. 'previous' => ''
  4445. );
  4446. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4447. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4448. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4449. where ' . $con . ' group by a.irid ';
  4450. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4451. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4452. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4453. foreach ( $list as $key => $value ) {
  4454. $list [$key] ['category'] = '';
  4455. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4456. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4457. $list [$key] ['category'] = $receivablesCategory [1];
  4458. }
  4459. }
  4460. // print_r($list);
  4461. $this->data ['category'] = $category;
  4462. $this->data ['timeType'] = $timeType;
  4463. $this->data ['MebSeaEn'] = $MebSea;
  4464. $this->data ['MebSea'] = urlencode ( $MebSea );
  4465. $this->data ['date'] = $date;
  4466. $this->data ['page'] = $pageinfo;
  4467. $this->data ['get'] = $get;
  4468. $this->data ['list'] = $list;
  4469. $this->data ['status'] = $status;
  4470. $this->data ['memu'] = "invoice";
  4471. $this->data ['staff'] = $this->staff;
  4472. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4473. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4474. }
  4475. /**
  4476. * 删除一条收款
  4477. */
  4478. function delInvoiceReceivables() {
  4479. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4480. if (empty ( $iridKey ))
  4481. die ( 'illegal request' );
  4482. Doo::loadClass ( 'XDeode' );
  4483. $XDeode = new XDeode ( 5 );
  4484. $irid = $XDeode->decode ( $iridKey );
  4485. Doo::loadModel ( 'invoiceReceivables' );
  4486. $invoiceReceivables = new invoiceReceivables ();
  4487. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4488. if (empty ( $detail ))
  4489. die ( 'illegal request' );
  4490. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4491. // 扣除收款汇总信息 汇总
  4492. Doo::loadModel ( 'invoiceStatistics' );
  4493. $invoiceStatistics = new invoiceStatistics ();
  4494. $item = array (
  4495. 'date' => $detail ['receivablesDate'],
  4496. 'priceClass' => 2,
  4497. 'irid' => $detail ['irid'],
  4498. 'receivablesPrice' => - $detail ['receivablesPrice']
  4499. );
  4500. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4501. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4502. $item += array (
  4503. 'cid' => $receivablesCategory [0]
  4504. );
  4505. }
  4506. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4507. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4508. $item += array (
  4509. 'staff' => $receivablesStaff [0]
  4510. );
  4511. }
  4512. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4513. return '/invoiceReceivablesAS';
  4514. }
  4515. /**
  4516. * 添加退款信息
  4517. */
  4518. function setInvoiceReceivablesRefund() {
  4519. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4520. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4521. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4522. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4523. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4524. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4525. if ($refundPrice < 0)
  4526. die ( 'illegal request' );
  4527. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4528. Doo::loadModel ( 'invoiceReceivables' );
  4529. $invoiceReceivables = new invoiceReceivables ();
  4530. Doo::loadModel ( 'invoiceRefund' );
  4531. $invoiceRefund = new invoiceRefund ();
  4532. $irid = $invoiceReceivables->authcode ( $iridKey );
  4533. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4534. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4535. die ( 'illegal request' );
  4536. $invoiceReceivables = new invoiceReceivables ();
  4537. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4538. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4539. ';
  4540. $item = array (
  4541. 'irid' => $irid,
  4542. 'refundCompany' => $refundCompany,
  4543. 'refundNumber' => $refundNumber,
  4544. 'refundPrice' => $refundPrice,
  4545. 'refundRemarks' => $refundRemarks,
  4546. 'refundLog' => $refundLog
  4547. );
  4548. if ($refundType == 1) {
  4549. $item += array (
  4550. 'refundType' => $refundType,
  4551. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4552. 'bindStatus' => 2
  4553. );
  4554. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4555. $item += array (
  4556. 'refundType' => 1,
  4557. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4558. 'bindStatus' => 2
  4559. );
  4560. } else {
  4561. $item += array (
  4562. 'refundType' => $refundType,
  4563. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4564. );
  4565. }
  4566. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4567. // 添加退款记录
  4568. $item = array (
  4569. 'irid' => $irid,
  4570. 'refundType' => $refundType,
  4571. 'refundCompany' => $refundCompany,
  4572. 'refundNumber' => $refundNumber,
  4573. 'refundPrice' => $refundPrice,
  4574. 'refundLog' => $refundLog,
  4575. 'refundRemarks' => $refundRemarks,
  4576. 'date' => date ( "Y-m-d H:i:s" )
  4577. );
  4578. $invoiceRefund->addInvoiceRefund ( $item );
  4579. // 扣除收款汇总信息 汇总
  4580. Doo::loadModel ( 'invoiceStatistics' );
  4581. $invoiceStatistics = new invoiceStatistics ();
  4582. $item = array (
  4583. 'date' => $irDetail ['receivablesDate'],
  4584. 'priceClass' => 2,
  4585. 'irid' => $irDetail ['irid'],
  4586. 'receivablesPrice' => - $refundPrice
  4587. );
  4588. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4589. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4590. $item += array (
  4591. 'cid' => $receivablesCategory [0]
  4592. );
  4593. }
  4594. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4595. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4596. $item += array (
  4597. 'staff' => $receivablesStaff [0]
  4598. );
  4599. }
  4600. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4601. // 公司日常支出流水
  4602. Doo::loadModel ( 'wasteBook' );
  4603. $wasteBook = new wasteBook ();
  4604. $accountBank = '';
  4605. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4606. $accountBank = 'CGBDeposit';
  4607. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4608. $accountBank = 'ICBCDeposit';
  4609. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4610. $accountBank = 'HUADeposit';
  4611. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4612. $accountBank = 'PersonalDeposit';
  4613. }
  4614. $itemWaste = array (
  4615. 'accountPrice' => - $refundPrice,
  4616. 'expensesType' => 2,
  4617. 'accountType' => 11,
  4618. 'accountPriceShow' => $refundPrice,
  4619. 'dataID' => $irid,
  4620. 'accountBank' => $accountBank,
  4621. 'category' => $this->staff [0] ['category'],
  4622. 'cid' => $this->staff [0] ['cid'],
  4623. 'name' => $this->staff [0] ['username'],
  4624. 'sid' => $this->staff [0] ['sid'],
  4625. 'inputDate' => date ( "Y-m-d H:i:s" )
  4626. );
  4627. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4628. return '/invoiceReceivablesAS';
  4629. }
  4630. die ( 'illegal request' );
  4631. }
  4632. function ajaxCheckInvoiceReceivablesRefund() {
  4633. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4634. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4635. if ($refundPrice < 0) {
  4636. echo json_encode ( array (
  4637. 'error' => '金额不能为负'
  4638. ) );
  4639. die ();
  4640. }
  4641. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4642. Doo::loadModel ( 'invoiceReceivables' );
  4643. $invoiceReceivables = new invoiceReceivables ();
  4644. $irid = $invoiceReceivables->authcode ( $iridKey );
  4645. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4646. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4647. echo json_encode ( array (
  4648. 'error' => '退款金额不能超过收款金额'
  4649. ) );
  4650. die ();
  4651. }
  4652. echo json_encode ( array (
  4653. 'ok' => '可以使用!'
  4654. ) );
  4655. die ();
  4656. }
  4657. }
  4658. /**
  4659. * 获得收款退款信息
  4660. */
  4661. function getRefundByDetail() {
  4662. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4663. Doo::loadModel ( 'invoiceReceivables' );
  4664. $invoiceReceivables = new invoiceReceivables ();
  4665. if (! empty ( $iridKey )) {
  4666. $irid = $invoiceReceivables->authcode ( $iridKey );
  4667. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4668. echo json_encode ( array (
  4669. 'status' => 1,
  4670. 'irDetail' => $irDetail
  4671. ) );
  4672. die ();
  4673. }
  4674. echo json_encode ( array (
  4675. 'status' => 2
  4676. ) );
  4677. }
  4678. /**
  4679. * 根据收款序列号获得收款退款信息
  4680. */
  4681. function ajaxGetInvoiceReceivablesBySerial() {
  4682. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  4683. if (! empty ( $receivablesSerial )) {
  4684. Doo::loadModel ( 'invoiceReceivables' );
  4685. $invoiceReceivables = new invoiceReceivables ();
  4686. // , ' and refundLog=""'
  4687. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  4688. $html = '';
  4689. if (! empty ( $irDetail ))
  4690. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  4691. <td>' . $irDetail ['receivablesMessage'] . '</td>
  4692. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  4693. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  4694. <td>' . $irDetail ['recepitTitleMark'] . '
  4695. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  4696. </td>';
  4697. echo json_encode ( array (
  4698. 'status' => 1,
  4699. 'html' => $html,
  4700. 'irDetail' => $irDetail
  4701. ) );
  4702. die ();
  4703. }
  4704. echo json_encode ( array (
  4705. 'status' => 2
  4706. ) );
  4707. }
  4708. /**
  4709. * 绑定新收款
  4710. */
  4711. function relationNewInvoiceReceivables() {
  4712. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  4713. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4714. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  4715. Doo::loadModel ( 'invoiceReceivables' );
  4716. $invoiceReceivables = new invoiceReceivables ();
  4717. Doo::loadClass ( 'XDeode' );
  4718. $XDeode = new XDeode ( 5 );
  4719. $irid = $XDeode->decode ( $iridKey );
  4720. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  4721. echo $irid . 'bbb' . $iridOld;
  4722. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  4723. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4724. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  4725. die ( 'illegal request' );
  4726. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  4727. <br/>' . date ( "Y-m-d H:i:s" ) . '
  4728. ';
  4729. $invoiceReceivables = new invoiceReceivables ();
  4730. $item = array (
  4731. 'irid' => $iridOld,
  4732. 'relationIrid' => $irid,
  4733. 'relationLog' => $relationLog
  4734. );
  4735. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4736. return '/invoiceReceivablesAS';
  4737. }
  4738. die ( 'illegal request' );
  4739. }
  4740. // function invoiceApprovalAchieve() {
  4741. // Doo::loadModel ( 'invoice' );
  4742. // $invoice = new invoice ();
  4743. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4744. // $page_size = 12;
  4745. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4746. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4747. // $get = "/" . $date;
  4748. // $con = '';
  4749. // if ($date == 'MONTHO')
  4750. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4751. // elseif ($date == 'MONTHT')
  4752. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4753. // elseif ($date == 'MONTHY')
  4754. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4755. // if (! empty ( $MebSea )) {
  4756. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4757. // $get .= "/" . $MebSea;
  4758. // }
  4759. // $pageinfo ['page'] = array (
  4760. // 'previous' => ''
  4761. // );
  4762. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  4763. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4764. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  4765. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4766. // // print_r($list);
  4767. // $this->data ['MebSeaEn'] = $MebSea;
  4768. // $this->data ['MebSea'] = urlencode ( $MebSea );
  4769. // $this->data ['get'] = $get;
  4770. // $this->data ['page'] = $pageinfo;
  4771. // $this->data ['list'] = $list;
  4772. // $this->data ['date'] = $date;
  4773. // $this->data ['memu'] = "invoice";
  4774. // $this->data ['staff'] = $this->staff;
  4775. // $this->data ['receiptMemu'] = 'invoiceApproval';
  4776. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4777. // }
  4778. /**
  4779. * 获得审批发票的信息以及审批页面
  4780. */
  4781. function ajaxGetInvoiceApprovalDetail() {
  4782. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4783. if (empty ( $serial )) {
  4784. echo json_encode ( array (
  4785. 'status' => 2,
  4786. 'msg' => 'illegal request'
  4787. ) );
  4788. die ();
  4789. }
  4790. Doo::loadModel ( 'invoice' );
  4791. $invoice = new invoice ();
  4792. Doo::loadModel ( 'invoiceOperationLog' );
  4793. $invoiceOperationLog = new invoiceOperationLog ();
  4794. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4795. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4796. if (empty ( $detail ))
  4797. $html = '';
  4798. else {
  4799. $html = '
  4800. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  4801. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4802. <input type="hidden" name="status" value="">
  4803. <input type="hidden" name="divApproval" value="divApproval">
  4804. <div class="modal-dialog modal-lg">
  4805. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  4806. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4807. <tr>
  4808. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  4809. </tr>
  4810. <tr>
  4811. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4812. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4813. </tr>
  4814. <tr>
  4815. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4816. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4817. </tr>
  4818. <tr>
  4819. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4820. </td>
  4821. </tr>
  4822. <tr>
  4823. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4824. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4825. </tr>
  4826. <tr>
  4827. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4828. </tr></tbody></table>';
  4829. if ($detail ['invoiceType'] == 0)
  4830. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4831. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4832. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4833. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4834. </tr>';
  4835. else
  4836. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4837. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4838. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4839. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4840. ';
  4841. $html .= '<tr>
  4842. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4843. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4844. </tr>
  4845. <tr>
  4846. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4847. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4848. </tr></tbody></table>';
  4849. if ($detail ['doPost'] == 1) {
  4850. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4851. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4852. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4853. </tr><tr>
  4854. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4855. </tr><tr>
  4856. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4857. </tr>
  4858. ';
  4859. if ($detail ['expressCom'] == 'SF')
  4860. $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>';
  4861. else
  4862. $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>';
  4863. $html .= '</tbody></table>';
  4864. }
  4865. if (! empty ( $invoiceOperationLogList )) {
  4866. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4867. foreach ( $invoiceOperationLogList as $key => $value ) {
  4868. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4869. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4870. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4871. if ($value ['status'] == 2) {
  4872. $html .= '<span class="colGreen">同意</span>';
  4873. } elseif ($value ['status'] == 3) {
  4874. $html .= '<span class="colOrange">退回</span>';
  4875. } elseif ($value ['status'] == 5) {
  4876. $html .= '<span class="colGreen">打印</span>';
  4877. } elseif ($value ['status'] == 4) {
  4878. $html .= '<span class="colRed">终止</span>';
  4879. }
  4880. $html .= $value ['operation'] . '</p></blockquote>';
  4881. }
  4882. }
  4883. $html .= '</td></tr></tbody></table>';
  4884. }
  4885. $html .= '</div><div class="modal-footer">
  4886. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  4887. <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>
  4888. <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>
  4889. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  4890. </form>
  4891. <script type="text/javascript">
  4892. $("a[node-approval^=\'approval\']").click(function() {
  4893. $("input[name=\'status\']").val($(this).attr("diss-data"));
  4894. $("form[name=\'invoiceApproval\']").submit();
  4895. });
  4896. </script>
  4897. ';
  4898. }
  4899. echo json_encode ( array (
  4900. 'status' => 1,
  4901. 'html' => $html
  4902. ) );
  4903. die ();
  4904. }
  4905. /**
  4906. * 获得审批发票分页数据
  4907. */
  4908. function ajaxGetinvoiceApprovalAchieve() {
  4909. Doo::loadModel ( 'invoice' );
  4910. $invoice = new invoice ();
  4911. Doo::loadModel ( 'staff' );
  4912. $staff = new staff ();
  4913. Doo::loadClass ( 'XDeode' );
  4914. $XDeode = new XDeode ( 5 );
  4915. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  4916. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4917. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4918. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4919. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4920. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  4921. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  4922. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  4923. $MebSea = $this->get_args ( 'search' );
  4924. $MebSea = $MebSea ['value'];
  4925. $page_size = $length;
  4926. $con = '';
  4927. if ($status == 'ALL')
  4928. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  4929. elseif ($status == 'PEND')
  4930. $con = ' isDelete=0 and status=1';
  4931. elseif ($status == 'APPROVED')
  4932. $con = ' isDelete=0 and status=2';
  4933. if ($invoiceType == 'ORDINARY')
  4934. $con .= ' and invoiceType=0 ';
  4935. elseif ($invoiceType == 'SPECIAL')
  4936. $con .= ' and invoiceType=1 ';
  4937. if ($invoiceTrain == 'ORDINARY')
  4938. $con .= ' and trainId=0 ';
  4939. elseif ($invoiceTrain == 'TRAIN')
  4940. $con .= ' and trainId!=0 ';
  4941. if ($invoiceTrainName != 'ALL') {
  4942. $trainId = $XDeode->decode ( $invoiceTrainName );
  4943. if (is_numeric ( $trainId ))
  4944. $con .= ' and trainId =' . $trainId;
  4945. }
  4946. $dateArr = explode ( ':', $date );
  4947. $D1 = $dateString = '';
  4948. $D2 = '';
  4949. if (! empty ( $date )) {
  4950. $D1 = $dateArr [0];
  4951. if (isset ( $dateArr [1] ))
  4952. $D2 = $dateArr [1];
  4953. else
  4954. $D2 = '';
  4955. $dateString = $D1 . " : " . $D2;
  4956. }
  4957. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4958. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4959. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4960. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  4961. if (! empty ( $MebSea ))
  4962. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  4963. // /
  4964. $pageinfo ['page'] = array (
  4965. 'previous' => ''
  4966. );
  4967. $sql = ' ' . $con;
  4968. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  4969. $limit = $page . ',' . $page_size;
  4970. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4971. $approvalList = array ();
  4972. $html = '
  4973. <script type="text/javascript">
  4974. </script>
  4975. ';
  4976. foreach ( $list as $key => $value ) {
  4977. $irDetail = array ();
  4978. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  4979. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  4980. } else
  4981. array_push ( $irDetail, '' );
  4982. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  4983. if ($value ['invoiceType'] == 1)
  4984. array_push ( $irDetail, $value ['invoiceCompany'] );
  4985. else
  4986. array_push ( $irDetail, $value ['invoiceTitle'] );
  4987. array_push ( $irDetail, $value ['TIN'] );
  4988. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  4989. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  4990. array_push ( $irDetail, $value ['remark'] );
  4991. array_push ( $irDetail, $value ['invoiceElement'] );
  4992. array_push ( $irDetail, $value ['invoiceQuantity'] );
  4993. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  4994. if ($value ['invoiceType'] == 1)
  4995. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  4996. else
  4997. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  4998. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  4999. array_push ( $irDetail, $value ['recipientsAddress'] );
  5000. array_push ( $irDetail, $value ['mailItems'] );
  5001. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5002. $fchtml = $value ['OL'] ['operation'];
  5003. if (count ( $list ) == $page_size)
  5004. $fchtml = $value ['OL'] ['operation'] . $html;
  5005. // 最后的审批意见
  5006. array_push ( $irDetail, $fchtml );
  5007. if ($value ['status'] == 2)
  5008. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5009. elseif ($value ['status'] == 3)
  5010. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5011. elseif ($value ['status'] == 4)
  5012. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5013. else
  5014. array_push ( $irDetail, '' );
  5015. array_push ( $approvalList, $irDetail );
  5016. }
  5017. // $approvalListJson = json_encode ( $approvalList );
  5018. $recordsFiltered = $pageinfo ['total_data'];
  5019. echo json_encode ( array (
  5020. "draw" => intval ( $draw ),
  5021. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5022. "recordsFiltered" => intval ( $recordsFiltered ),
  5023. "data" => $approvalList
  5024. ), JSON_UNESCAPED_UNICODE );
  5025. }
  5026. /**
  5027. * 审批发票查看更多--重构
  5028. */
  5029. function invoiceApprovalAchieve() {
  5030. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5031. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5032. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5033. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5034. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5035. Doo::loadModel ( 'invoiceTraining' );
  5036. $invoiceTraining = new invoiceTraining ();
  5037. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5038. $this->data ['trainList'] = $trainList;
  5039. $this->data ['dateString'] = $date;
  5040. $this->data ['status'] = $status;
  5041. $this->data ['invoiceType'] = $invoiceType;
  5042. $this->data ['invoiceTrain'] = $invoiceTrain;
  5043. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5044. $this->data ['memu'] = "invoice";
  5045. $this->data ['staff'] = $this->staff;
  5046. $this->data ['receiptMemu'] = 'invoiceApproval';
  5047. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5048. }
  5049. function invoiceTAchieve() {
  5050. Doo::loadModel ( 'invoice' );
  5051. $invoice = new invoice ();
  5052. Doo::loadClass ( 'XDeode' );
  5053. $XDeode = new XDeode ( 5 );
  5054. Doo::loadModel ( 'staff' );
  5055. $staff = new staff ();
  5056. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5057. $page_size = 12;
  5058. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5059. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5060. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5061. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5062. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5063. Doo::loadModel ( 'invoiceTraining' );
  5064. $invoiceTraining = new invoiceTraining ();
  5065. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5066. $get = "/" . $date;
  5067. $con = '';
  5068. if ($date == 'MONTHO')
  5069. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5070. elseif ($date == 'MONTHT')
  5071. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5072. elseif ($date == 'MONTHY')
  5073. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5074. if ($invoiceType == 'ORDINARY')
  5075. $con .= ' and invoiceType=0 ';
  5076. elseif ($invoiceType == 'SPECIAL')
  5077. $con .= ' and invoiceType=1 ';
  5078. if ($invoiceTrain == 'ORDINARY')
  5079. $con .= ' and trainId=0 ';
  5080. elseif ($invoiceTrain == 'TRAIN')
  5081. $con .= ' and trainId!=0 ';
  5082. if ($invoiceTrainName != 'ALL') {
  5083. $trainId = $XDeode->decode ( $invoiceTrainName );
  5084. if (is_numeric ( $trainId ))
  5085. $con .= ' and trainId =' . $trainId;
  5086. }
  5087. if (! empty ( $MebSea )) {
  5088. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5089. $get .= "/" . $MebSea;
  5090. }
  5091. $pageinfo ['page'] = array (
  5092. 'previous' => ''
  5093. );
  5094. $sql = "";
  5095. $action = "";
  5096. if ($this->ACTION == 'invoicePrintAchieve') {
  5097. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5098. $action = "invoicePrintAchieve";
  5099. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5100. // and untreadStatus=0
  5101. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5102. $action = "invoicePostAchieve";
  5103. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5104. $sql = " untreadStatus=2 and status=2 " . $con;
  5105. $action = "invoiceUntreadAchieve";
  5106. }
  5107. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5108. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5109. $this->data ['MebSeaEn'] = $MebSea;
  5110. $this->data ['MebSea'] = urlencode ( $MebSea );
  5111. $this->data ['get'] = $get;
  5112. $this->data ['page'] = $pageinfo;
  5113. $this->data ['trainList'] = $trainList;
  5114. $this->data ['invoiceType'] = $invoiceType;
  5115. $this->data ['invoiceTrain'] = $invoiceTrain;
  5116. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5117. $this->data ['date'] = $date;
  5118. $this->data ['memu'] = "invoice";
  5119. $this->data ['staff'] = $this->staff;
  5120. if ($this->ACTION == 'invoicePrintAchieve') {
  5121. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5122. $this->data ['receiptMemu'] = 'invoicePrint';
  5123. $this->data ['list'] = $list;
  5124. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5125. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5126. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5127. Doo::loadModel ( 'express' );
  5128. $express = new express ();
  5129. $expressList = $express->getExpressByAll ();
  5130. $this->data ['expressList'] = $expressList;
  5131. $this->data ['receiptMemu'] = 'invoicePost';
  5132. $this->data ['list'] = $list;
  5133. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5134. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5135. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5136. $this->data ['receiptMemu'] = 'invoiceUntread';
  5137. $this->data ['list'] = $list;
  5138. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5139. }
  5140. }
  5141. /**
  5142. * 公司应收款
  5143. */
  5144. function invoiceAggregateCompanyDetail() {
  5145. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5146. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5147. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5148. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5149. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5150. Doo::loadClass ( 'XDeode' );
  5151. $XDeode = new XDeode ( 5 );
  5152. Doo::loadModel ( 'invoice' );
  5153. $invoice = new invoice ();
  5154. Doo::loadModel ( 'staff' );
  5155. $staff = new staff ();
  5156. Doo::loadModel ( "invoiceCompanyManage" );
  5157. $invoiceCompanyManage = new invoiceCompanyManage ();
  5158. Doo::loadModel ( 'L_category' );
  5159. $category = new L_category ();
  5160. $sid = '';
  5161. if (! empty ( $sidKey )) {
  5162. $sid = $XDeode->decode ( $sidKey );
  5163. }
  5164. $staffDetail = $staff->getStaffBySid ( $sid );
  5165. $cid = '';
  5166. if (! empty ( $cidKey )) {
  5167. $cid = $XDeode->decode ( $cidKey );
  5168. }
  5169. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5170. $cidList = array ();
  5171. foreach ( $imcStaff as $key => $value ) {
  5172. array_push ( $cidList, $value ['cid'] );
  5173. }
  5174. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5175. $cidString = implode ( ',', $cidList );
  5176. if (empty ( $cid ))
  5177. $staffList = $staff->getStaffInCid ( $cidString );
  5178. else
  5179. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5180. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5181. $page_size = 25;
  5182. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5183. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5184. $con = ' status=2 and untreadStatus!=2 ';
  5185. $statisticsCon = '';
  5186. if (! empty ( $year ) && is_numeric ( $year ))
  5187. $con .= ' and Year(printTime)=' . $year . '';
  5188. if (! empty ( $month ) && is_numeric ( $month ))
  5189. $con .= ' and Month(printTime)="' . $month . '" ';
  5190. if ($status == 'UNRECORD')
  5191. $con .= ' and printStatus=1 and untreadStatus=0';
  5192. elseif ($status == 'RECORD')
  5193. $con .= ' and printStatus=1 and untreadStatus=3';
  5194. elseif ($status == 'BOUNCED')
  5195. $con .= ' and untreadStatus=2';
  5196. elseif ($status == 'PARTRECORD')
  5197. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5198. elseif ($status == 'All') {
  5199. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5200. }
  5201. if (! empty ( $sid ) && is_numeric ( $sid ))
  5202. $con .= ' and sid=' . $sid;
  5203. if (! empty ( $cid ) && is_numeric ( $cid ))
  5204. $con .= ' and cid=' . $cid;
  5205. else
  5206. $con .= ' and cid in (' . $cidString . ')';
  5207. // 开票内容筛选
  5208. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5209. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5210. }
  5211. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5212. if (! empty ( $MebSea )) {
  5213. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5214. }
  5215. $pageinfo ['page'] = array (
  5216. 'previous' => ''
  5217. );
  5218. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5219. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5220. // 应收款合计
  5221. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5222. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5223. $monthHtml = "";
  5224. if ($year != "ALL") {
  5225. for($i = 1; $i <= 12; $i ++) {
  5226. if ($i == $month)
  5227. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5228. else
  5229. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5230. }
  5231. }
  5232. $this->data ['monthHtml'] = $monthHtml;
  5233. $this->data ['year'] = $year;
  5234. $this->data ['month'] = $month;
  5235. $this->data ['ics'] = $ics;
  5236. $this->data ['cidKey'] = $cidKey;
  5237. $this->data ['sid'] = $sid;
  5238. $this->data ['staffDetail'] = $staffDetail;
  5239. $this->data ['staffList'] = $staffList;
  5240. $this->data ['MebSeaEn'] = $MebSea;
  5241. $this->data ['MebSea'] = urlencode ( $MebSea );
  5242. $this->data ['invoiceDetail'] = array (
  5243. 'invoiceElement' => $invoiceElement
  5244. );
  5245. $this->data ['page'] = $pageinfo;
  5246. $this->data ['get'] = $get;
  5247. $this->data ['list'] = $list;
  5248. $this->data ['status'] = $status;
  5249. $this->data ['categoryList'] = $categoryList;
  5250. $this->data ['memu'] = "invoice";
  5251. $this->data ['staff'] = $this->staff;
  5252. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5253. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5254. }
  5255. /**
  5256. * 获取一条收款信息
  5257. */
  5258. function ajaxGetInvoiceReceivables() {
  5259. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5260. Doo::loadModel ( 'invoiceReceivables' );
  5261. $invoiceReceivables = new invoiceReceivables ();
  5262. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5263. echo json_encode ( array (
  5264. 'status' => 1,
  5265. 'detail' => $detail
  5266. ) );
  5267. }
  5268. /**
  5269. * 异步获取办事处用户
  5270. */
  5271. function ajaxGetStaffByCategory() {
  5272. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5273. Doo::loadModel ( 'staff' );
  5274. $staff = new staff ();
  5275. if ($cid == "PUBLIC") {
  5276. echo json_encode ( array (
  5277. 'status' => 1,
  5278. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5279. ) );
  5280. die ();
  5281. }
  5282. if (! is_numeric ( $cid )) {
  5283. echo json_encode ( array (
  5284. 'status' => 0,
  5285. 'msg' => 'illegal request'
  5286. ) );
  5287. die ();
  5288. }
  5289. $staffList = $staff->getStaffByCid ( $cid );
  5290. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5291. foreach ( $staffList as $key => $value ) {
  5292. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5293. }
  5294. echo json_encode ( array (
  5295. 'status' => 1,
  5296. 'html' => $html
  5297. ) );
  5298. }
  5299. /**
  5300. * 异步获取一条发票的邮寄信息
  5301. */
  5302. function ajaxGetInvoicePostDetail() {
  5303. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5304. Doo::loadModel ( 'invoice' );
  5305. $invoice = new invoice ();
  5306. $iid = $invoice->authcode ( $iid );
  5307. Doo::loadModel ( 'express' );
  5308. $express = new express ();
  5309. $expressList = $express->getExpressByAll ();
  5310. if (! is_numeric ( $iid )) {
  5311. echo json_encode ( array (
  5312. 'status' => 0,
  5313. 'msg' => 'illegal request'
  5314. ) );
  5315. die ();
  5316. }
  5317. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5318. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5319. $html = "";
  5320. foreach ( $expressList as $key => $value ) {
  5321. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5322. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5323. else
  5324. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5325. }
  5326. $invoiceDetail ['eaHtml'] = $html;
  5327. echo json_encode ( array (
  5328. 'status' => 1,
  5329. 'invoiceDetail' => $invoiceDetail
  5330. ) );
  5331. }
  5332. /**
  5333. *
  5334. * @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 ) ); }
  5335. */
  5336. /**
  5337. *
  5338. * @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 ) ); }
  5339. */
  5340. /**
  5341. * 我的收款中 选择哪个发票入账,进行金额判断
  5342. */
  5343. function ajaxCompareInvoicePrice() {
  5344. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5345. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5346. Doo::loadModel ( 'invoice' );
  5347. $invoice = new invoice ();
  5348. Doo::loadModel ( 'invoiceReceivables' );
  5349. $invoiceReceivables = new invoiceReceivables ();
  5350. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5351. $keyList = explode ( ';', $claimKey );
  5352. $receivablesPrice = 0;
  5353. foreach ( $keyList as $key => $value ) {
  5354. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5355. $receivablesPrice += $detailM ['receivablesPrice'];
  5356. }
  5357. if ($receivablesPrice > $detail ['invoicePrice']) {
  5358. $price = $receivablesPrice - $detail ['invoicePrice'];
  5359. echo json_encode ( array (
  5360. 'status' => 1,
  5361. 'price' => $price
  5362. ) );
  5363. } else
  5364. echo json_encode ( array (
  5365. 'status' => 2
  5366. ) );
  5367. }
  5368. /**
  5369. * 获得打印发票
  5370. */
  5371. function ajaxGetInvoiceInfoByPrint() {
  5372. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5373. if (empty ( $serial )) {
  5374. echo json_encode ( array (
  5375. 'status' => 2,
  5376. 'msg' => 'illegal request'
  5377. ) );
  5378. die ();
  5379. }
  5380. Doo::loadModel ( 'invoice' );
  5381. $invoice = new invoice ();
  5382. Doo::loadModel ( 'invoiceOperationLog' );
  5383. $invoiceOperationLog = new invoiceOperationLog ();
  5384. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5385. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5386. Doo::loadModel ( 'invoicePaper' );
  5387. $invoicePaper = new invoicePaper ();
  5388. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5389. if (empty ( $detail ))
  5390. $html = '';
  5391. else {
  5392. $html = '
  5393. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5394. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5395. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5396. <div class="modal-dialog modal-lg">
  5397. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5398. <div class="modal-body saeaList">
  5399. <table class="table table-bordered table-condensed"><tbody>
  5400. <tr>
  5401. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5402. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5403. </tr>
  5404. <tr>
  5405. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5406. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5407. </tr>
  5408. <tr>
  5409. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5410. </td>
  5411. </tr>
  5412. <tr>
  5413. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5414. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5415. </tr>
  5416. <tr>
  5417. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5418. </tr></tbody></table>';
  5419. if ($detail ['invoiceType'] == 0)
  5420. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5421. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5422. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5423. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5424. </tr>';
  5425. else
  5426. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5427. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5428. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5429. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5430. ';
  5431. $html .= '<tr>
  5432. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5433. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5434. </tr>
  5435. <tr>
  5436. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5437. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5438. </tr></tbody></table>';
  5439. if ($detail ['doPost'] == 1)
  5440. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5441. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5442. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5443. </tr><tr>
  5444. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5445. </tr><tr>
  5446. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5447. </tr></tbody></table>';
  5448. if (! empty ( $invoiceOperationLogList )) {
  5449. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5450. foreach ( $invoiceOperationLogList as $key => $value ) {
  5451. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5452. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5453. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5454. if ($value ['status'] == 2) {
  5455. $html .= '<span class="colGreen">同意</span>';
  5456. } elseif ($value ['status'] == 3) {
  5457. $html .= '<span class="colOrange">退回</span>';
  5458. } elseif ($value ['status'] == 5) {
  5459. $html .= '<span class="colGreen">打印</span>';
  5460. } elseif ($value ['status'] == 4) {
  5461. $html .= '<span class="colRed">终止</span>';
  5462. }
  5463. $html .= $value ['operation'] . '</p></blockquote>';
  5464. }
  5465. }
  5466. $html .= '</td>
  5467. <td><span class="colRed">*</span>
  5468. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5469. foreach ( $invoicePaperList as $key => $value ) {
  5470. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5471. }
  5472. $html .= '</select>
  5473. <span class="red" id="p-msg"></span>
  5474. </td>
  5475. </tr></tbody></table>';
  5476. }
  5477. $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>
  5478. </div></div></form>
  5479. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5480. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5481. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5482. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5483. ';
  5484. }
  5485. echo json_encode ( array (
  5486. 'status' => 1,
  5487. 'html' => $html
  5488. ) );
  5489. die ();
  5490. }
  5491. /**
  5492. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5493. */
  5494. function ajaxGetInvoiceInfoByType() {
  5495. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5496. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5497. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5498. if (empty ( $serial )) {
  5499. echo json_encode ( array (
  5500. 'status' => 2,
  5501. 'msg' => 'illegal request'
  5502. ) );
  5503. die ();
  5504. }
  5505. if ($type == 'INVOICE') {
  5506. Doo::loadModel ( 'invoice' );
  5507. $invoice = new invoice ();
  5508. Doo::loadModel ( 'invoiceOperationLog' );
  5509. $invoiceOperationLog = new invoiceOperationLog ();
  5510. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5511. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5512. if (empty ( $detail ))
  5513. $html = '';
  5514. else {
  5515. $html = '
  5516. <div class="modal-dialog modal-lg">
  5517. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5518. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5519. <tr>
  5520. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5521. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5522. </tr>
  5523. <tr>
  5524. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5525. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5526. </tr>
  5527. <tr>
  5528. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5529. </td>
  5530. </tr>
  5531. <tr>
  5532. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5533. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5534. </tr>
  5535. <tr>
  5536. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5537. </tr></tbody></table>';
  5538. if ($detail ['invoiceType'] == 0)
  5539. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5540. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5541. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5542. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5543. </tr>';
  5544. else
  5545. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5546. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5547. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5548. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5549. ';
  5550. $html .= '<tr>
  5551. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5552. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5553. </tr>
  5554. <tr>
  5555. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5556. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5557. </tr></tbody></table>';
  5558. if ($detail ['doPost'] == 1) {
  5559. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5560. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5561. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5562. </tr><tr>
  5563. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5564. </tr><tr>
  5565. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5566. </tr>
  5567. ';
  5568. if ($detail ['expressCom'] == 'SF')
  5569. $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>';
  5570. else
  5571. $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>';
  5572. $html .= '</tbody></table>';
  5573. }
  5574. if (! empty ( $invoiceOperationLogList )) {
  5575. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5576. foreach ( $invoiceOperationLogList as $key => $value ) {
  5577. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5578. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5579. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5580. if ($value ['status'] == 2) {
  5581. $html .= '<span class="colGreen">同意</span>';
  5582. } elseif ($value ['status'] == 3) {
  5583. $html .= '<span class="colOrange">退回</span>';
  5584. } elseif ($value ['status'] == 5) {
  5585. $html .= '<span class="colGreen">打印</span>';
  5586. } elseif ($value ['status'] == 4) {
  5587. $html .= '<span class="colRed">终止</span>';
  5588. }
  5589. $html .= $value ['operation'] . '</p></blockquote>';
  5590. }
  5591. }
  5592. $html .= '</td></tr></tbody></table>';
  5593. }
  5594. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5595. }
  5596. echo json_encode ( array (
  5597. 'status' => 1,
  5598. 'html' => $html
  5599. ) );
  5600. die ();
  5601. } elseif ($type == 'RECEIVABLES') {
  5602. Doo::loadModel ( 'invoiceReceivables' );
  5603. $invoiceReceivables = new invoiceReceivables ();
  5604. Doo::loadModel ( 'invoiceRefund' );
  5605. $invoiceRefund = new invoiceRefund ();
  5606. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5607. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5608. if (empty ( $detail ))
  5609. $html = '';
  5610. else {
  5611. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5612. <table class="table table-bordered table-condensed">
  5613. <tbody><tr>
  5614. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  5615. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  5616. </tr><tr>
  5617. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5618. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  5619. </tr>
  5620. <tr>
  5621. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  5622. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  5623. </tr>
  5624. <tr>
  5625. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  5626. </tr>
  5627. </tbody></table>';
  5628. if (! empty ( $ireList )) {
  5629. $html .= '
  5630. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  5631. <tr>
  5632. <th class="taC">退款单位名称</th>
  5633. <th class="taC">退款的账号</th>
  5634. <th class="taC">退款金额</th>
  5635. <th class="taC">退款</th>
  5636. <th class="taC">备注</th>
  5637. </tr>
  5638. ';
  5639. foreach ( $ireList as $key => $value ) {
  5640. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  5641. $html .= '<tr>
  5642. <td>' . $value ['refundCompany'] . '</td>
  5643. <td>' . $value ['refundNumber'] . '</td>
  5644. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  5645. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  5646. <td>' . $value ['refundRemarks'] . '</td>
  5647. </tr>
  5648. ';
  5649. }
  5650. }
  5651. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5652. }
  5653. echo json_encode ( array (
  5654. 'status' => 1,
  5655. 'html' => $html
  5656. ) );
  5657. die ();
  5658. } elseif ($type == 'IRTC') {
  5659. Doo::loadModel ( 'invoice' );
  5660. $invoice = new invoice ();
  5661. Doo::loadModel ( 'invoiceOperationLog' );
  5662. $invoiceOperationLog = new invoiceOperationLog ();
  5663. Doo::loadModel ( 'invoiceReceivables' );
  5664. $invoiceReceivables = new invoiceReceivables ();
  5665. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5666. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5667. if (empty ( $detail ))
  5668. $html = '';
  5669. else {
  5670. $receivablesPriceedHtml = '';
  5671. $receivablesPrice = $detail ['invoicePrice'];
  5672. if (! empty ( $detail ['irid'] )) {
  5673. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  5674. if (empty ( $irList ))
  5675. $irList [0] ['sumPrice'] = 0;
  5676. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  5677. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  5678. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  5679. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  5680. </tr></tbody></table>';
  5681. $receivablesPrice = $balance;
  5682. }
  5683. if ($loss)
  5684. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  5685. $html = $receivablesPriceedHtml . '
  5686. <table class="table table-bordered table-condensed"><tbody>
  5687. <tr>
  5688. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5689. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5690. </tr>
  5691. <tr>
  5692. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5693. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5694. </tr>
  5695. <tr>
  5696. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  5697. </tr>
  5698. <tr>
  5699. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5700. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5701. </tr>
  5702. <tr>
  5703. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5704. </tr></tbody></table>';
  5705. if ($detail ['invoiceType'] == 0) {
  5706. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5707. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5708. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5709. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5710. </tr>';
  5711. $receivablesMessage = $detail ['invoiceTitle'];
  5712. } else {
  5713. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5714. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5715. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5716. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5717. ';
  5718. $receivablesMessage = $detail ['invoiceCompany'];
  5719. }
  5720. $html .= '<tr>
  5721. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5722. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5723. </tr>
  5724. <tr>
  5725. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  5726. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  5727. </tr></tbody></table>';
  5728. if ($detail ['doPost'] == 1)
  5729. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5730. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5731. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5732. </tr><tr>
  5733. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5734. </tr><tr>
  5735. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5736. </tr></tbody></table>';
  5737. if (! empty ( $invoiceOperationLogList )) {
  5738. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5739. foreach ( $invoiceOperationLogList as $key => $value ) {
  5740. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5741. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5742. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5743. if ($value ['status'] == 2) {
  5744. $html .= '<span class="colGreen">同意</span>';
  5745. } elseif ($value ['status'] == 3) {
  5746. $html .= '<span class="colOrange">退回</span>';
  5747. } elseif ($value ['status'] == 5) {
  5748. $html .= '<span class="colGreen">打印</span>';
  5749. }
  5750. $html .= $value ['operation'] . '</p></blockquote>';
  5751. }
  5752. }
  5753. $html .= '</td></tr></tbody></table>';
  5754. }
  5755. }
  5756. echo json_encode ( array (
  5757. 'status' => 1,
  5758. 'html' => $html,
  5759. 'receivablesPrice' => $receivablesPrice,
  5760. 'receivablesMessage' => $receivablesMessage,
  5761. 'receivablesDate' => date ( "Y-m-d" ),
  5762. 'iidKey' => $serial
  5763. ) );
  5764. die ();
  5765. }
  5766. }
  5767. function ajaxGetInvoiceReceivablesByStaff() {
  5768. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  5769. if (empty ( $postData )) {
  5770. echo json_encode ( array (
  5771. 'status' => 2,
  5772. 'msg' => 'illegal request'
  5773. ) );
  5774. die ();
  5775. }
  5776. Doo::loadModel ( 'invoiceReceivables' );
  5777. $invoiceReceivables = new invoiceReceivables ();
  5778. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  5779. if (empty ( $detail )) {
  5780. echo json_encode ( array (
  5781. 'status' => 2,
  5782. 'msg' => 'illegal request'
  5783. ) );
  5784. die ();
  5785. }
  5786. Doo::loadModel ( 'L_category' );
  5787. $lCategory = new L_category ();
  5788. Doo::loadModel ( 'staff' );
  5789. $staff = new staff ();
  5790. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  5791. $category = $lCategory->getCategory ();
  5792. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  5793. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  5794. foreach ( $category as $key => $value ) {
  5795. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5796. if ($value ['cid'] == $detail ['cid'])
  5797. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5798. }
  5799. foreach ( $staffList as $key => $value ) {
  5800. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5801. if ($value ['sid'] == $detail ['sid'])
  5802. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5803. }
  5804. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  5805. echo json_encode ( array (
  5806. 'status' => 1,
  5807. 'categoryHtml' => $categoryHtml,
  5808. 'staffHtml' => $staffHtml,
  5809. 'rbankHtml' => $rbankHtml,
  5810. 'detail' => $detail
  5811. ) );
  5812. }
  5813. function ajaxGetInvoiceReceivablesByIrid() {
  5814. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  5815. if (empty ( $irid )) {
  5816. echo json_encode ( array (
  5817. 'status' => 2,
  5818. 'msg' => 'illegal request'
  5819. ) );
  5820. die ();
  5821. }
  5822. Doo::loadModel ( 'invoiceReceivables' );
  5823. $invoiceReceivables = new invoiceReceivables ();
  5824. Doo::loadModel ( 'invoice' );
  5825. $invoice = new invoice ();
  5826. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  5827. $flag = true;
  5828. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  5829. $bakDetail = array ();
  5830. if ($flag === false) {
  5831. array_push ( $bakDetail, $invoiceDetail );
  5832. $invoiceDetail = $bakDetail;
  5833. }
  5834. $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>
  5835. <tr>
  5836. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5837. <td>' . $detail ['receivablesMessage'] . '</td>
  5838. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  5839. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  5840. <td>' . $detail ['recepitTitleMark'] . '</td>
  5841. </tr></tbody></table>';
  5842. $isInvoice = false;
  5843. $invoiceHtml = '';
  5844. if (empty ( $invoiceDetail )) {
  5845. $isInvoice = true;
  5846. } else {
  5847. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5848. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  5849. foreach ( $invoiceDetail as $key => $value ) {
  5850. $invoiceHtml .= '<tr>';
  5851. if (! empty ( $value ['invoiceType'] )) {
  5852. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5853. } else {
  5854. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5855. }
  5856. if (! empty ( $value ['invoiceType'] )) {
  5857. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5858. } else {
  5859. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5860. }
  5861. $invoiceHtml .= '
  5862. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5863. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5864. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  5865. </tr>
  5866. ';
  5867. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  5868. if (empty ( $irList ))
  5869. $irList [0] ['sumPrice'] = 0;
  5870. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  5871. $priceString = '';
  5872. if ($balance < $detail ['receivablesPrice']) {
  5873. $priceString = '收款金额超过开票金额,';
  5874. }
  5875. if ($balance > $detail ['receivablesPrice']) {
  5876. $priceString = '收款金额低于开票金额,';
  5877. }
  5878. }
  5879. $invoiceHtml .= '
  5880. <script>
  5881. $(\'a[bind-receivables^="ir"]\').click(function() {
  5882. var data = $(this).attr("data-ikey");
  5883. $("input[name=\'invoiceKey\']").val(data);
  5884. var invoiceKey=data;
  5885. if(invoiceKey==""){
  5886. alert("入账错误,请重新刷新页面");
  5887. return false;
  5888. }
  5889. if(window.confirm("' . $priceString . '确定入账吗?")){
  5890. $("#IBR").submit();
  5891. }else{
  5892. return false;
  5893. }
  5894. });
  5895. </script>
  5896. ';
  5897. $invoiceHtml .= '</tbody></table>';
  5898. }
  5899. echo json_encode ( array (
  5900. 'status' => 1,
  5901. 'irkey' => $detail ['iridEn'],
  5902. 'receivablesHtml' => $receivablesHtml,
  5903. 'isInvoice' => $isInvoice,
  5904. 'invoiceHtml' => $invoiceHtml
  5905. ) );
  5906. }
  5907. function ajaxGetInvoiceReceivablesByTitle() {
  5908. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  5909. if (empty ( $title )) {
  5910. echo json_encode ( array (
  5911. 'status' => 2,
  5912. 'msg' => 'illegal request'
  5913. ) );
  5914. die ();
  5915. }
  5916. Doo::loadModel ( 'invoice' );
  5917. $invoice = new invoice ();
  5918. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  5919. $invoiceHtml = '';
  5920. if (! empty ( $invoiceDetail )) {
  5921. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5922. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  5923. foreach ( $invoiceDetail as $key => $value ) {
  5924. if (! empty ( $value ['invoiceType'] )) {
  5925. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5926. } else {
  5927. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5928. }
  5929. if (! empty ( $value ['invoiceType'] )) {
  5930. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5931. } else {
  5932. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5933. }
  5934. $invoiceHtml .= '
  5935. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5936. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5937. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  5938. </tr>
  5939. ';
  5940. }
  5941. $invoiceHtml .= '</tbody></table>
  5942. <script>
  5943. $(\'a[bind-receivables^="ir"]\').click(function() {
  5944. var data = $(this).attr("data-ikey");
  5945. $("input[name=\'invoiceKey\']").val(data);
  5946. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  5947. if(invoiceKey==""){
  5948. alert("入账错误,请重新刷新页面");
  5949. return false;
  5950. }
  5951. if(window.confirm("确定入账吗?")){
  5952. $("#IBR").submit();
  5953. }else{
  5954. return false;
  5955. }
  5956. });
  5957. </script>
  5958. ';
  5959. }
  5960. echo json_encode ( array (
  5961. 'status' => 1,
  5962. 'invoiceHtml' => $invoiceHtml
  5963. ) );
  5964. }
  5965. function ajaxInvoicePushNotice() {
  5966. Doo::loadModel ( 'invoice' );
  5967. $invoice = new invoice ();
  5968. $approval = $invoice->getOne ( array (
  5969. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  5970. 'desc' => 'iid',
  5971. 'asArray' => true
  5972. ) );
  5973. $isNotice = false;
  5974. if (! empty ( $approval ))
  5975. $isNotice = true;
  5976. $response = array (
  5977. 'error' => 0,
  5978. 'isNotice' => $isNotice
  5979. );
  5980. echo json_encode ( $response );
  5981. exit ();
  5982. }
  5983. public function ajaxCheckInvoiceNoUniqueness() {
  5984. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  5985. Doo::loadModel ( 'invoice' );
  5986. $invoice = new invoice ();
  5987. if (! empty ( $invoiceNo )) {
  5988. Doo::loadModel ( 'invoicePaper' );
  5989. $invoicePaper = new invoicePaper ();
  5990. Doo::loadClass ( 'XDeode' );
  5991. $XDeode = new XDeode ( 5 );
  5992. $ipid = $XDeode->decode ( $invoiceNo );
  5993. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  5994. $info = $invoice->getOne ( array (
  5995. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  5996. 'asArray' => TRUE
  5997. ) );
  5998. if (! empty ( $info )) {
  5999. echo json_encode ( array (
  6000. 'error' => '发票号已存在'
  6001. ) );
  6002. die ();
  6003. } else
  6004. echo json_encode ( array (
  6005. 'ok' => '可以使用!'
  6006. ) );
  6007. die ();
  6008. }
  6009. }
  6010. function ajaxCheckInvoicePrice() {
  6011. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6012. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6013. Doo::loadModel ( 'invoice' );
  6014. $invoice = new invoice ();
  6015. Doo::loadModel ( 'invoiceReceivables' );
  6016. $invoiceReceivables = new invoiceReceivables ();
  6017. Doo::loadClass ( 'XDeode' );
  6018. $XDeode = new XDeode ( 5 );
  6019. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6020. $iidKey = $XDeode->decode ( $iidKey );
  6021. $info = $invoice->getInvoiceByIid ( $iidKey );
  6022. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6023. if (empty ( $irList ))
  6024. $irList [0] ['sumPrice'] = 0;
  6025. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6026. if ($balance < $receivablesPrice) {
  6027. echo json_encode ( array (
  6028. 'error' => '收款金额超过开票金额。'
  6029. ) );
  6030. die ();
  6031. }
  6032. if ($balance > $receivablesPrice) {
  6033. echo json_encode ( array (
  6034. 'error' => '收款金额低于开票金额。'
  6035. ) );
  6036. die ();
  6037. }
  6038. }
  6039. }
  6040. /**
  6041. * 旧输入导入
  6042. */
  6043. function importInvoice() {
  6044. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6045. $data ['emsg'] = "";
  6046. if ($emsg != "")
  6047. $data ['emsg'] = "请填写完整的数据";
  6048. $data ['time'] = time ();
  6049. $this->render ( "/admin/invoiceImport", $data );
  6050. }
  6051. function uploadInvoice() {
  6052. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6053. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6054. $file = $_FILES ['Filedata'] ['tmp_name'];
  6055. $error = false;
  6056. if (! is_uploaded_file ( $file )) {
  6057. $error = '400 Bad Request';
  6058. }
  6059. if ($error) {
  6060. header ( 'HTTP/1.0 ' . $error );
  6061. die ( 'Error ' . $error );
  6062. } else {
  6063. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6064. $this->IoHandler = new IoHandler ();
  6065. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6066. // $filedir=$_POST['time'];
  6067. // 调用定义物理路径
  6068. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6069. $this->IoHandler->MakeDir ( $t );
  6070. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6071. if ($filename != 'xlsx')
  6072. return "";
  6073. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6074. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6075. $upload_dir = $t . "/" . $upload_file;
  6076. $k = move_uploaded_file ( $file, $upload_dir );
  6077. if ($k) {
  6078. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6079. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6080. }
  6081. }
  6082. }
  6083. }
  6084. function importInvoiceDo() {
  6085. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6086. if ($path != "") {
  6087. Doo::loadModel ( 'invoice' );
  6088. Doo::loadModel ( 'staff' );
  6089. $staff = new staff ();
  6090. Doo::loadModel ( 'invoiceStatistics' );
  6091. Doo::loadModel ( 'invoiceOperationLog' );
  6092. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6093. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6094. // print_r ( $exlArray );
  6095. // die ();
  6096. // echo json_encode($exlArray);die;
  6097. foreach ( $exlArray as $key => $value ) {
  6098. // 开票
  6099. $invoice = new invoice ();
  6100. $invoice->invoiceNo = $value ['invoiceNo'];
  6101. $invoice->invoiceType = 0;
  6102. if ($value ['invoiceType'] == '专')
  6103. $invoice->invoiceType = 1;
  6104. $invoice->invoicePrice = $value ['invoicePrice'];
  6105. $invoice->invoiceQuantity = 1;
  6106. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6107. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6108. if ($value ['invoiceType'] == '专')
  6109. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6110. $invoice->userName = $value ['userName'];
  6111. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6112. $invoice->sid = $sDetail ['sid'];
  6113. $invoice->cid = $sDetail ['cid'];
  6114. $invoice->categoryName = $sDetail ['category'];
  6115. $invoice->invoiceElement = $value ['invoiceElement'];
  6116. $invoice->remark = $value ['remark'];
  6117. $invoice->date = $value ['date'];
  6118. $invoice->printTime = $value ['date'];
  6119. $invoice->ipSource = 1;
  6120. $invoice->printStatus = 1;
  6121. $invoice->status = 2;
  6122. $invoice->postStatus = 1;
  6123. $invoice->untreadStatus = 0;
  6124. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6125. $iid = $invoice->insert ();
  6126. // 汇总
  6127. $invoiceStatistics = new invoiceStatistics ();
  6128. //
  6129. $item = array (
  6130. 'date' => $value ['date'],
  6131. 'priceClass' => 1,
  6132. 'cid' => $sDetail ['cid'],
  6133. 'staff' => $sDetail ['sid'],
  6134. 'invoicePrice' => $value ['invoicePrice']
  6135. );
  6136. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6137. $invoiceOperationLog = new invoiceOperationLog ();
  6138. $item = array (
  6139. 'date' => date ( "Y-m-d H:i:s" ),
  6140. 'operation' => date ( "Y-m-d" ) . " 导入",
  6141. 'status' => 1,
  6142. 'img' => $sDetail ['avatar'],
  6143. 'username' => $sDetail ['username'],
  6144. 'uid' => $sDetail ['sid'],
  6145. 'category' => $sDetail ['category'],
  6146. 'iid' => $iid
  6147. );
  6148. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6149. }
  6150. return '/importInvoice?count=' . count ( $exlArray );
  6151. // return "/keyonline";
  6152. }
  6153. echo 'no file';
  6154. }
  6155. function importInvoiceReceivables() {
  6156. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6157. $data ['emsg'] = "";
  6158. if ($emsg != "")
  6159. $data ['emsg'] = "请填写完整的数据";
  6160. $data ['time'] = time ();
  6161. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6162. }
  6163. // 导入入账数据
  6164. function importInvoiceReceivablesDo() {
  6165. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6166. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6167. if ($path != "") {
  6168. Doo::loadModel ( 'invoiceReceivables' );
  6169. Doo::loadModel ( 'invoice' );
  6170. Doo::loadModel ( 'staff' );
  6171. $staff = new staff ();
  6172. Doo::loadModel ( 'invoiceStatistics' );
  6173. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6174. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6175. // print_r ( $exlArray );
  6176. // die ();
  6177. // echo json_encode($exlArray);die;
  6178. foreach ( $exlArray as $key => $value ) {
  6179. // 收款
  6180. $invoiceReceivables = new invoiceReceivables ();
  6181. $invoice = new invoice ();
  6182. $invoiceReceivables->bindStatus = 1;
  6183. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6184. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6185. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6186. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6187. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6188. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6189. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6190. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6191. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6192. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6193. $invoiceReceivables->iid = $iDetail ['iid'];
  6194. $irid = $invoiceReceivables->insert ();
  6195. // 发票绑定收款
  6196. $detail = $iDetail;
  6197. $iridString = "";
  6198. if (empty ( $detail ['irid'] ))
  6199. $iridString = $irid;
  6200. else
  6201. $iridString = $detail ['irid'] . ',' . $irid;
  6202. $item = array (
  6203. 'irid' => $iridString,
  6204. 'iid' => $detail ['iid']
  6205. );
  6206. $invoice->setInvoiceByCondition ( $item );
  6207. // 汇总
  6208. $invoiceStatistics = new invoiceStatistics ();
  6209. // 扣除入账统计金额
  6210. $item = array (
  6211. 'date' => $value ['receivablesDate'],
  6212. 'priceClass' => 3,
  6213. 'cid' => $sDetail ['cid'],
  6214. 'staff' => $sDetail ['sid'],
  6215. // 'irid' => $irid,
  6216. 'accountPrice' => $value ['receivablesPrice']
  6217. );
  6218. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6219. }
  6220. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6221. echo 'data count ' . count ( $exlArray );
  6222. die ();
  6223. // return "/keyonline";
  6224. }
  6225. echo 'no file';
  6226. }
  6227. function formatExcelToArrayTrain($file_url = "") {
  6228. if (! file_exists ( $file_url )) {
  6229. return array ();
  6230. }
  6231. // Doo::loadClass ( 'PHPExcel' );
  6232. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6233. $PHPExcel = new PHPExcel ();
  6234. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6235. if (! $PHPReader->canRead ( $file_url )) {
  6236. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6237. if (! $PHPReader->canRead ( $file_url )) {
  6238. echo 'no Excel';
  6239. return;
  6240. }
  6241. }
  6242. $PHPExcel = $PHPReader->load ( $file_url );
  6243. /* * 读取excel文件中的第一个工作表 */
  6244. $currentSheet = $PHPExcel->getSheet ( 0 );
  6245. /* * 取得最大的列号 */
  6246. $allColumn = $currentSheet->getHighestColumn ();
  6247. /* * 取得一共有多少行 */
  6248. $allRow = $currentSheet->getHighestRow ();
  6249. $excel_array = array ();
  6250. // die($file_url);
  6251. $conk = 2;
  6252. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6253. $excel_column = array ();
  6254. // 后期改进
  6255. if ($allColumn == 'AM')
  6256. $allColumn = 'Z';
  6257. /* * 从第A列开始输出 */
  6258. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6259. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6260. if ($val instanceof PHPExcel_RichText)
  6261. $val = $val->__toString ();
  6262. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6263. // $val = "'" . addslashes ( $val ) . "'";
  6264. if ($currentColumn == 'A') {
  6265. $excel_column ['invoiceTitle'] = $val;
  6266. } elseif ($currentColumn == 'B')
  6267. $excel_column ['invoiceType'] = $val;
  6268. elseif ($currentColumn == 'C') {
  6269. $excel_column ['TIN'] = $val;
  6270. } elseif ($currentColumn == 'D') {
  6271. $excel_column ['address'] = $val;
  6272. } elseif ($currentColumn == 'E') {
  6273. $excel_column ['phone'] = $val;
  6274. } elseif ($currentColumn == 'F') {
  6275. $excel_column ['bank'] = $val;
  6276. } elseif ($currentColumn == 'G') {
  6277. $excel_column ['bankAccount'] = $val;
  6278. } elseif ($currentColumn == 'H') {
  6279. $excel_column ['invoiceElement'] = $val;
  6280. } elseif ($currentColumn == 'I') {
  6281. $excel_column ['invoiceQuantity'] = $val;
  6282. } elseif ($currentColumn == 'J') {
  6283. $excel_column ['invoiceUnitPrice'] = $val;
  6284. } elseif ($currentColumn == 'K') {
  6285. $excel_column ['remark'] = $val;
  6286. } elseif ($currentColumn == 'L') {
  6287. $excel_column ['recipientsAddress'] = $val;
  6288. } elseif ($currentColumn == 'M') {
  6289. $excel_column ['recipients'] = $val;
  6290. } elseif ($currentColumn == 'N') {
  6291. $excel_column ['recipientsPhone'] = $val;
  6292. }
  6293. }
  6294. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6295. array_push ( $excel_array, $excel_column );
  6296. }
  6297. return $excel_array;
  6298. }
  6299. /**
  6300. * 格式化excel文件为数组
  6301. * @param unknown_type $file_url
  6302. * @param unknown_type $mcid
  6303. */
  6304. function _format_excel_to_array($file_url = "", $sType = "") {
  6305. if (! file_exists ( $file_url )) {
  6306. return array ();
  6307. }
  6308. Doo::loadClass ( 'PHPExcel' );
  6309. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6310. $PHPExcel = new PHPExcel ();
  6311. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6312. if (! $PHPReader->canRead ( $file_url )) {
  6313. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6314. if (! $PHPReader->canRead ( $file_url )) {
  6315. echo 'no Excel';
  6316. return;
  6317. }
  6318. }
  6319. $PHPExcel = $PHPReader->load ( $file_url );
  6320. /* * 读取excel文件中的第一个工作表 */
  6321. $currentSheet = $PHPExcel->getSheet ( 0 );
  6322. /* * 取得最大的列号 */
  6323. $allColumn = $currentSheet->getHighestColumn ();
  6324. /* * 取得一共有多少行 */
  6325. $allRow = $currentSheet->getHighestRow ();
  6326. $excel_array = array ();
  6327. // die($file_url);
  6328. $conk = 2;
  6329. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6330. $excel_column = array ();
  6331. // 后期改进
  6332. if ($allColumn == 'AM')
  6333. $allColumn = 'Z';
  6334. /* * 从第A列开始输出 */
  6335. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6336. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6337. if ($val instanceof PHPExcel_RichText)
  6338. $val = $val->__toString ();
  6339. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6340. // $val = "'" . addslashes ( $val ) . "'";
  6341. if ($sType == 'invoiceReceivables') {
  6342. if ($currentColumn == 'A')
  6343. $excel_column ['invoiceNo'] = $val;
  6344. elseif ($currentColumn == 'B')
  6345. $excel_column ['receivablesPrice'] = $val;
  6346. elseif ($currentColumn == 'C') {
  6347. $excel_column ['receivablesMessage'] = $val;
  6348. } elseif ($currentColumn == 'D') {
  6349. $excel_column ['receivablesBank'] = $val;
  6350. } elseif ($currentColumn == 'E') {
  6351. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6352. } elseif ($currentColumn == 'F') {
  6353. $excel_column ['receivablesStaff'] = $val;
  6354. } elseif ($currentColumn == 'G') {
  6355. $excel_column ['sourcePrice'] = $val;
  6356. }
  6357. } elseif ($sType == "invoiceTrain") {
  6358. if ($currentColumn == 'A') {
  6359. $excel_column ['invoiceTitle'] = $val;
  6360. } elseif ($currentColumn == 'B')
  6361. $excel_column ['invoiceType'] = $val;
  6362. elseif ($currentColumn == 'C') {
  6363. $excel_column ['TIN'] = $val;
  6364. } elseif ($currentColumn == 'D') {
  6365. $excel_column ['address'] = $val;
  6366. } elseif ($currentColumn == 'E') {
  6367. $excel_column ['phone'] = $val;
  6368. } elseif ($currentColumn == 'F') {
  6369. $excel_column ['bank'] = $val;
  6370. } elseif ($currentColumn == 'G') {
  6371. $excel_column ['bankAccount'] = $val;
  6372. } elseif ($currentColumn == 'H') {
  6373. $excel_column ['invoiceElement'] = $val;
  6374. } elseif ($currentColumn == 'I') {
  6375. $excel_column ['invoiceQuantity'] = $val;
  6376. } elseif ($currentColumn == 'J') {
  6377. $excel_column ['invoiceUnitPrice'] = $val;
  6378. } elseif ($currentColumn == 'K') {
  6379. $excel_column ['remark'] = $val;
  6380. } elseif ($currentColumn == 'L') {
  6381. $excel_column ['recipientsAddress'] = $val;
  6382. } elseif ($currentColumn == 'M') {
  6383. $excel_column ['recipients'] = $val;
  6384. } elseif ($currentColumn == 'N') {
  6385. $excel_column ['recipientsPhone'] = $val;
  6386. }
  6387. } else {
  6388. if ($currentColumn == 'A')
  6389. $excel_column ['invoiceNo'] = $val;
  6390. elseif ($currentColumn == 'B')
  6391. $excel_column ['invoiceType'] = $val;
  6392. elseif ($currentColumn == 'C') {
  6393. $excel_column ['invoicePrice'] = $val;
  6394. } elseif ($currentColumn == 'D') {
  6395. $excel_column ['invoiceTitle'] = $val;
  6396. } elseif ($currentColumn == 'E') {
  6397. $excel_column ['userName'] = $val;
  6398. } elseif ($currentColumn == 'F') {
  6399. $excel_column ['categoryName'] = $val;
  6400. } elseif ($currentColumn == 'G') {
  6401. $excel_column ['invoiceElement'] = $val;
  6402. } elseif ($currentColumn == 'H') {
  6403. $excel_column ['remark'] = $val;
  6404. } elseif ($currentColumn == 'I') {
  6405. $excel_column ['date'] = $this->excelTime ( $val );
  6406. }
  6407. }
  6408. }
  6409. array_push ( $excel_array, $excel_column );
  6410. }
  6411. return $excel_array;
  6412. }
  6413. function excelTime($date, $time = false) {
  6414. if (function_exists ( 'GregorianToJD' )) {
  6415. if (is_numeric ( $date )) {
  6416. $jd = GregorianToJD ( 1, 1, 1970 );
  6417. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6418. $date = explode ( '/', $gregorian );
  6419. $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" : '');
  6420. return $date_str;
  6421. }
  6422. } else {
  6423. $date = $date > 25568 ? $date + 1 : 25569;
  6424. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6425. $ofs = (70 * 365 + 17 + 2) * 86400;
  6426. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6427. }
  6428. return $date;
  6429. }
  6430. /**
  6431. * 旧输入导入
  6432. */
  6433. function _GetFileEXT($filename) {
  6434. $pics = explode ( '.', $filename );
  6435. $num = count ( $pics );
  6436. return $pics [$num - 1];
  6437. }
  6438. function showCache($path = "", $sid = 0) {
  6439. // if (file_exists ( $path )) {
  6440. // $htm = file_get_contents ( $path );
  6441. // } else {
  6442. Doo::loadModel ( 'invoiceStatistics' );
  6443. $invoiceStatistics = new invoiceStatistics ();
  6444. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6445. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6446. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6447. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6448. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6449. /*
  6450. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6451. */
  6452. file_put_contents ( $path, $htm );
  6453. // }
  6454. return $htm;
  6455. }
  6456. /**
  6457. * 获取get或者POST值
  6458. *
  6459. * @param string $name 属性名称
  6460. * @return fixed 值
  6461. */
  6462. function get_args($name) {
  6463. if (isset ( $_GET [$name] )) {
  6464. if (is_array ( $_GET [$name] ))
  6465. return $_GET [$name];
  6466. else
  6467. return addslashes ( $_GET [$name] );
  6468. } elseif (isset ( $_POST [$name] )) {
  6469. if (is_array ( $_POST [$name] ))
  6470. return $_POST [$name];
  6471. else
  6472. return addslashes ( $_POST [$name] );
  6473. } else
  6474. return false;
  6475. }
  6476. function SafeFilter(&$arr) {
  6477. $ra = Array (
  6478. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6479. '/script/',
  6480. '/javascript/',
  6481. '/vbscript/',
  6482. '/expression/',
  6483. '/applet/',
  6484. '/meta/',
  6485. '/xml/',
  6486. '/blink/',
  6487. '/link/',
  6488. '/style/',
  6489. '/embed/',
  6490. '/object/',
  6491. '/frame/',
  6492. '/layer/',
  6493. '/title/',
  6494. '/bgsound/',
  6495. '/base/',
  6496. '/onload/',
  6497. '/onunload/',
  6498. '/onchange/',
  6499. '/onsubmit/',
  6500. '/onreset/',
  6501. '/onselect/',
  6502. '/onblur/',
  6503. '/onfocus/',
  6504. '/onabort/',
  6505. '/onkeydown/',
  6506. '/onkeypress/',
  6507. '/onkeyup/',
  6508. '/onclick/',
  6509. '/ondblclick/',
  6510. '/onmousedown/',
  6511. '/onmousemove/',
  6512. '/onmouseout/',
  6513. '/onmouseover/',
  6514. '/onmouseup/',
  6515. '/onunload/'
  6516. );
  6517. if (is_array ( $arr )) {
  6518. foreach ( $arr as $key => $value ) {
  6519. if (! is_array ( $value )) {
  6520. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6521. {
  6522. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6523. }
  6524. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6525. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6526. } else {
  6527. SafeFilter ( $arr [$key] );
  6528. }
  6529. }
  6530. }
  6531. }
  6532. /**
  6533. * Escape String
  6534. *
  6535. * @access public
  6536. * @param string
  6537. * @param bool whether or not the string will be used in a LIKE condition
  6538. * @return string
  6539. */
  6540. function escape_str($str, $like = FALSE) {
  6541. if (is_array ( $str )) {
  6542. foreach ( $str as $key => $val ) {
  6543. $str [$key] = $this->escape_str ( $val, $like );
  6544. }
  6545. return $str;
  6546. }
  6547. var_dump ( Doo::db ()->getDbObject () );
  6548. die ();
  6549. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6550. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6551. } elseif (function_exists ( 'mysql_escape_string' )) {
  6552. $str = mysql_escape_string ( $str );
  6553. } else {
  6554. $str = addslashes ( $str );
  6555. }
  6556. // escape LIKE condition wildcards
  6557. if ($like === TRUE) {
  6558. $str = str_replace ( array (
  6559. '%',
  6560. '_'
  6561. ), array (
  6562. '\\%',
  6563. '\\_'
  6564. ), $str );
  6565. }
  6566. return $str;
  6567. }
  6568. /**
  6569. * 获得分页数据
  6570. * @param unknown_type $table
  6571. * @param unknown_type $condition
  6572. * @param unknown_type $on_page
  6573. * @param unknown_type $page_size
  6574. */
  6575. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6576. $page_c = "";
  6577. $page ['previous'] = $this->get_previous ( $on_page );
  6578. $page ['on_page'] = $on_page;
  6579. $total_count = $this->get_table_count ( $table, $condition );
  6580. $total = intval ( $total_count / $page_size );
  6581. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6582. $page ['total_data'] = $total_count;
  6583. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6584. $i = 1;
  6585. $page_max = 1;
  6586. $page_width = 3;
  6587. if ($on_page >= $page_width) {
  6588. $page_max = intval ( $on_page / $page_width ) + 1;
  6589. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6590. }
  6591. for(; $i <= $page ['total_page']; $i ++) {
  6592. if ($i == $on_page)
  6593. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6594. else
  6595. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6596. if ($i == ($page_width * $page_max))
  6597. break;
  6598. }
  6599. $page ['page'] = $page_c;
  6600. $page ['lower'] = (-- $on_page) * $page_size;
  6601. return $page;
  6602. }
  6603. /**
  6604. * 获取上一页
  6605. * @param unknown_type $on_page
  6606. */
  6607. function get_previous($on_page = 1) {
  6608. return $on_page != 0 ? $on_page - 1 : $on_page;
  6609. }
  6610. /**
  6611. * 获取总页数
  6612. * @param unknown_type $table
  6613. * @param unknown_type $condition
  6614. */
  6615. public function get_table_count($table = "", $condition = "") {
  6616. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6617. $sql = "select count(*) as count from " . $table . " where " . $condition;
  6618. // echo $sql;die;
  6619. $query = Doo::db ()->query ( $sql );
  6620. $result = $query->fetch ();
  6621. return $result ['count'];
  6622. }
  6623. /**
  6624. * 获得分页数据
  6625. * @param unknown_type $table
  6626. * @param unknown_type $condition
  6627. * @param unknown_type $on_page
  6628. * @param unknown_type $page_size
  6629. */
  6630. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6631. $page_c = "";
  6632. $page ['previous'] = $this->get_previous ( $on_page );
  6633. $page ['on_page'] = $on_page;
  6634. $total_count = $this->getTableCountBySql ( $sql );
  6635. $total = intval ( $total_count / $page_size );
  6636. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6637. $page ['total_data'] = $total_count;
  6638. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6639. $i = 1;
  6640. $page_max = 1;
  6641. $page_width = 3;
  6642. if ($on_page >= $page_width) {
  6643. $page_max = intval ( $on_page / $page_width ) + 1;
  6644. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6645. }
  6646. for(; $i <= $page ['total_page']; $i ++) {
  6647. if ($i == $on_page)
  6648. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6649. else
  6650. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6651. if ($i == ($page_width * $page_max))
  6652. break;
  6653. }
  6654. $page ['page'] = $page_c;
  6655. $page ['lower'] = (-- $on_page) * $page_size;
  6656. return $page;
  6657. }
  6658. /**
  6659. * 获得总页数 sql
  6660. * @param string $type
  6661. * @return boolean[]
  6662. */
  6663. public function getTableCountBySql($sql = "") {
  6664. $query = Doo::db ()->query ( $sql );
  6665. $result = $query->fetchAll ();
  6666. return count ( $result );
  6667. }
  6668. function isInvoiceNew($type = "GLOBAL") {
  6669. Doo::loadModel ( 'invoice' );
  6670. $invoice = new invoice ();
  6671. Doo::loadModel ( 'invoiceReceivables' );
  6672. $invoiceReceivables = new invoiceReceivables ();
  6673. Doo::loadModel ( 'staff' );
  6674. $staff = new staff ();
  6675. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  6676. // 我的发票待处理
  6677. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  6678. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  6679. 'desc' => 'iid',
  6680. 'asArray' => TRUE
  6681. ) );
  6682. // 我的收款待入账
  6683. /*
  6684. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  6685. */
  6686. // 发票审批
  6687. $approval = $invoice->getOne ( array (
  6688. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  6689. 'desc' => 'iid',
  6690. 'asArray' => true
  6691. ) );
  6692. // 发票邮寄
  6693. $post = $invoice->getOne ( array (
  6694. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  6695. 'asArray' => TRUE
  6696. ) );
  6697. // 发票打印
  6698. $print = $invoice->getOne ( array (
  6699. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  6700. 'desc' => 'iid',
  6701. 'asArray' => TRUE
  6702. ) );
  6703. // 发票退票 printStatus=1 and
  6704. $untread = $invoice->getOne ( array (
  6705. 'where' => " untreadStatus=1 and status=2 ",
  6706. 'asArray' => TRUE
  6707. ) );
  6708. $new = array (
  6709. 'GLOBAL' => FALSE,
  6710. 'pendingInvoice' => FALSE,
  6711. // 'myClaim' => FALSE,
  6712. 'approval' => FALSE,
  6713. 'post' => FALSE,
  6714. 'print' => FALSE,
  6715. 'untread' => FALSE
  6716. );
  6717. // || ! empty ( $myClaim )
  6718. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  6719. $new ['GLOBAL'] = TRUE;
  6720. if (! empty ( $pendingInvoice ))
  6721. $new ['pendingInvoice'] = TRUE;
  6722. // if (! empty ( $myClaim ))
  6723. // $new ['myClaim'] = TRUE;
  6724. if (! empty ( $approval ))
  6725. $new ['approval'] = TRUE;
  6726. if (! empty ( $post ))
  6727. $new ['post'] = TRUE;
  6728. if (! empty ( $print ))
  6729. $new ['print'] = TRUE;
  6730. if (! empty ( $untread ))
  6731. $new ['untread'] = TRUE;
  6732. return $new;
  6733. }
  6734. function setWXMsg($rid, $typeMsg = '') {
  6735. Doo::loadModel ( 'invoice' );
  6736. $invoice = new invoice ();
  6737. $invoiceDetail = $invoice->getOne ( array (
  6738. 'where' => 'iid=' . $rid,
  6739. 'asArray' => true
  6740. ) );
  6741. if (! empty ( $invoiceDetail )) {
  6742. Doo::loadModel ( 'staff' );
  6743. $staff = new staff ();
  6744. $staffmsg = $staff->getOne ( array (
  6745. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  6746. 'asArray' => TRUE
  6747. ) );
  6748. if (! empty ( $staffmsg ['wxid'] )) {
  6749. require_once (SITE_PATH . '/protected/class/client.php');
  6750. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  6751. $user = $staffmsg ['wxid'];
  6752. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  6753. if (empty ( $expCom ))
  6754. $expCom [0] = '';
  6755. $msg = "";
  6756. if (empty ( $typeMsg ))
  6757. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  6758. elseif ($typeMsg == "PRINT")
  6759. $msg = '太好了,您的发票已打印完成。';
  6760. $result = $client->SendMsg ( $user, $msg, 'text' );
  6761. }
  6762. }
  6763. }
  6764. /**
  6765. * 获取微信部门
  6766. * @param string $category
  6767. * @return number|mixed
  6768. */
  6769. function getToparty($category = '') {
  6770. $token = $this->getAccessToken (); //
  6771. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  6772. $toparty = 0;
  6773. foreach ( $result ['department'] as $key => $value ) {
  6774. if ($value ['name'] == $category)
  6775. $toparty = $value ['id'];
  6776. }
  6777. return $toparty;
  6778. }
  6779. /**
  6780. * 获得某部门下的用户
  6781. * @param string $toparty
  6782. */
  6783. function getUserByToparty($toparty = '') {
  6784. $token = $this->getAccessToken (); //
  6785. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  6786. $userList = array ();
  6787. foreach ( $result ['userlist'] as $key => $value ) {
  6788. array_push ( $userList, "'" . $value ['userid'] . "'" );
  6789. }
  6790. return $userList;
  6791. }
  6792. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  6793. $token = $this->getAccessToken ();
  6794. if ($text == 'text') {
  6795. $data = '{
  6796. "touser": "' . $toparty . '",
  6797. "toparty": "",
  6798. "totag": "",
  6799. "msgtype": "text",
  6800. "agentid": 1000002,
  6801. "text": {
  6802. "content": "' . $msg . '"
  6803. },
  6804. "safe":0
  6805. }';
  6806. }
  6807. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6808. if ($result->errmsg != 'ok') {
  6809. return 0;
  6810. } else {
  6811. return 1;
  6812. }
  6813. }
  6814. /**
  6815. * 获得可以发送微信用户列表
  6816. * @param string $category
  6817. * @return string
  6818. */
  6819. function getWxidByCategory($category = "") {
  6820. if (empty ( $category ))
  6821. return "";
  6822. Doo::loadModel ( 'staff' );
  6823. $staff = new staff ();
  6824. $toparty = $this->getToparty ( $category );
  6825. $wxList = array ();
  6826. $wxString = "";
  6827. if (! empty ( $toparty )) {
  6828. $userList = $this->getUserByToparty ( $toparty );
  6829. $userCon = implode ( ',', $userList );
  6830. // echo $userCon;
  6831. $sidList = $staff->getStaffByWxid ( $userCon );
  6832. foreach ( $sidList as $key => $value ) {
  6833. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  6834. if ($falg) {
  6835. array_push ( $wxList, $value ['wxid'] );
  6836. }
  6837. }
  6838. $wxString = implode ( '|', $wxList );
  6839. }
  6840. return $wxString;
  6841. }
  6842. /**
  6843. * 读取发送信息规则判断是否需要发送
  6844. * @param number $sid
  6845. * @param string $sendType
  6846. * @return boolean
  6847. */
  6848. function isSendNotification($sid = 0, $sendType = '') {
  6849. Doo::loadModel ( "notificationConf" );
  6850. $notificationConf = new notificationConf ();
  6851. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  6852. $conf = array ();
  6853. $sendFlag = true;
  6854. if (! empty ( $detail )) {
  6855. $conf = json_decode ( $detail ['conf'], true );
  6856. if (! empty ( $sendType )) {
  6857. if (isset ( $conf [$sendType] )) {
  6858. if ($conf [$sendType] == "CLOSE")
  6859. $sendFlag = false;
  6860. elseif ($conf [$sendType] == "Weekend") {
  6861. $day = date ( "w" );
  6862. if (1 <= $day && 5 >= $day)
  6863. $sendFlag = false;
  6864. } elseif ($conf [$sendType] == "OneToFriday") {
  6865. $day = date ( "w" );
  6866. if (0 == $day || 6 == $day)
  6867. $sendFlag = false;
  6868. }
  6869. }
  6870. } else
  6871. $sendFlag = false;
  6872. }
  6873. return $sendFlag;
  6874. }
  6875. /**
  6876. * 根据规则发送信息
  6877. * @param unknown $msg
  6878. * @param unknown $title
  6879. * @param unknown $url
  6880. * @param unknown $user
  6881. * @param string $text
  6882. * @return number
  6883. */
  6884. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  6885. $token = $this->getAccessToken ();
  6886. $falg = $this->isSendNotification ( $sid, $sendType );
  6887. // if ($text == 'text') {
  6888. // $data = '{
  6889. // "touser": "' . $user . '",
  6890. // "toparty": "",
  6891. // "totag": "",
  6892. // "msgtype": "text",
  6893. // "agentid": 1000002,
  6894. // "text": {
  6895. // "content": "' . $msg . '"
  6896. // },
  6897. // "safe":0
  6898. // }';
  6899. // } else {
  6900. $data = '{
  6901. "touser": "' . $user . '",
  6902. "toparty": "",
  6903. "totag": "",
  6904. "msgtype": "news",
  6905. "agentid": 1000002,
  6906. "news": {
  6907. "articles":[
  6908. {
  6909. "title": "' . $title . '",
  6910. "description": "' . $msg . '",
  6911. "url": "' . $url . '",
  6912. "picurl": ""
  6913. }
  6914. ]
  6915. }
  6916. }';
  6917. // }
  6918. if ($falg) {
  6919. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6920. if ($result->errmsg != 'ok') {
  6921. return 0;
  6922. } else {
  6923. return 1;
  6924. }
  6925. } else
  6926. return 0;
  6927. }
  6928. private function getAccessToken() {
  6929. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  6930. // $file = './access_token.txt';
  6931. // $data = json_decode ( file_get_contents ( $file ) );
  6932. // if ($data->expire_time < time () or ! $data->expire_time) {
  6933. // 如果是企业号用以下URL获取access_token
  6934. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  6935. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  6936. $res = json_decode ( $this->httpGet ( $url ) );
  6937. $access_token = $res->access_token;
  6938. // echo $access_token;
  6939. // if ($access_token) {
  6940. // $data->expire_time = time () + 7000;
  6941. // $data->access_token = $access_token;
  6942. // $fp = fopen ( $file, "w" );
  6943. // fwrite ( $fp, json_encode ( $data ) );
  6944. // fclose ( $fp );
  6945. // }
  6946. // } else {
  6947. // $access_token = $data->access_token;
  6948. // }
  6949. return $access_token;
  6950. }
  6951. private function httpGet($url) {
  6952. $curl = curl_init ();
  6953. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6954. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6955. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6956. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6957. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6958. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6959. curl_setopt ( $curl, CURLOPT_URL, $url );
  6960. $res = curl_exec ( $curl );
  6961. curl_close ( $curl );
  6962. return $res;
  6963. }
  6964. private function httpPost($url, $data) {
  6965. $curl = curl_init ();
  6966. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6967. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6968. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6969. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6970. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6971. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6972. curl_setopt ( $curl, CURLOPT_URL, $url );
  6973. curl_setopt ( $curl, CURLOPT_POST, 1 );
  6974. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  6975. $res = curl_exec ( $curl );
  6976. curl_close ( $curl );
  6977. return $res;
  6978. }
  6979. }
  6980. ?>