InvoiceController.php 303 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257
  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 ( 'invoice' );
  222. $invoice = new invoice ();
  223. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  224. Doo::loadModel ( 'L_category' );
  225. $lCategory = new L_category ();
  226. $category = $lCategory->find ( array (
  227. 'asArray' => true
  228. ) );
  229. $this->data ['category'] = $category;
  230. Doo::loadModel ( 'invoiceTraining' );
  231. $invoiceTraining = new invoiceTraining ();
  232. $itList = $invoiceTraining->getInvoiceTrainingByCid ($this->staff [0] ['cid']);
  233. $this->data ['itList'] = $itList;
  234. $this->data ['memu'] = "invoice";
  235. $this->data ['staff'] = $this->staff;
  236. $this->data ['receiptMemu'] = 'invoice';
  237. $this->render ( "/admin/invoiceAdd", $this->data );
  238. }
  239. function invoiceAddFill() {
  240. Doo::loadModel ( 'invoice' );
  241. $invoice = new invoice ();
  242. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  243. Doo::loadModel ( 'L_category' );
  244. $lCategory = new L_category ();
  245. $category = $lCategory->find ( array (
  246. 'asArray' => true
  247. ) );
  248. $this->data ['category'] = $category;
  249. Doo::loadModel ( 'invoiceTraining' );
  250. $invoiceTraining = new invoiceTraining ();
  251. $itList = $invoiceTraining->getInvoiceTrainingByCid ($this->staff [0] ['cid']);
  252. $this->data ['itList'] = $itList;
  253. Doo::loadModel ( 'invoice' );
  254. $invoice = new invoice ();
  255. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  256. $detail['mailItemsArray']=json_decode($detail['mailItemsJson'],true);
  257. $this->data ['invoiceDetail'] = $detail;
  258. $this->data ['memu'] = "invoice";
  259. $this->data ['staff'] = $this->staff;
  260. $this->data ['receiptMemu'] = 'invoice';
  261. $this->render ( "/admin/invoiceAddFill", $this->data );
  262. }
  263. /**
  264. * 提交一份开票申请,并记录下操作日志
  265. *
  266. * @since 1.0.0
  267. * @var integer cid 办事处ID
  268. * @var integer invoiceType 发票类型
  269. * @var integer doPost 是否邮寄
  270. * @var integer invoicePrice 开票金额
  271. * @var string invoiceElement 开票内容
  272. * @var string invoiceTitle 发票抬头
  273. * @var string invoiceCompany 单位名称
  274. * @var string TIN 纳税人识别码
  275. * @var string address 注册地址
  276. * @var string phone 注册电话
  277. * @var string bank 开户银行
  278. * @var string bankAccount 银行账户
  279. * @var string recipients 收件人
  280. * @var string recipientsPhone 收件人手机/电话
  281. * @var string recipientsAddress 收件地址
  282. * @var string mailItems 邮寄物品
  283. * @var string remark 备注
  284. * @return string 返回跳转开票主页路径
  285. */
  286. function invoiceAddDo() {
  287. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  288. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  289. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  290. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  291. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  292. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  293. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  294. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  295. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  296. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  297. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  298. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  299. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  300. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  301. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  302. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  303. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  304. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  305. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  306. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  307. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  308. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  309. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  310. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  311. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  312. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  313. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  314. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  315. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  316. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  317. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  318. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  319. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  320. /*
  321. * $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;
  322. */
  323. if (empty ( $this->staff [0] ))
  324. die ( 'illegal request-Please login' );
  325. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  326. Doo::loadModel ( 'invoice' );
  327. $invoice = new invoice ();
  328. Doo::loadModel ( 'L_category' );
  329. $lCategory = new L_category ();
  330. Doo::loadModel ( 'invoiceManage' );
  331. $invoiceManage = new invoiceManage ();
  332. Doo::loadModel ( 'invoiceOperationLog' );
  333. $invoiceOperationLog = new invoiceOperationLog ();
  334. Doo::loadClass ( 'XDeode' );
  335. $XDeode = new XDeode ( 5 );
  336. $trainId = $XDeode->decode ( $trainId );
  337. $categoryDetil = $lCategory->getOne ( array (
  338. 'SELECT' => 'title',
  339. 'where' => 'cid=' . $cid,
  340. 'asArray' => true
  341. ) );
  342. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  343. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  344. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  345. // print_r(current($invoiceManageDetail ['staffList']));
  346. // die;
  347. $moldManage = array ();
  348. foreach ( $invoiceManageList as $key => $value ) {
  349. if ($value ['mold'] == '发票打印')
  350. $moldManage [$value ['mold']] = $value ['staffList'];
  351. elseif ($value ['mold'] == '发票邮寄')
  352. $moldManage [$value ['mold']] = $value ['staffList'];
  353. elseif ($value ['mold'] == '发票退票')
  354. $moldManage [$value ['mold']] = $value ['staffList'];
  355. }
  356. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  357. $st = '';
  358. if ($settlementType == 'SOFTWARE') {
  359. $st = 0;
  360. $trainId=0;
  361. } elseif ($settlementType == 'TRAINING') {
  362. $st = 1;
  363. if (empty ( $trainId )&&!is_numeric($trainId)) {
  364. die ( 'illegal request-trainingIdError' );
  365. }
  366. } else {
  367. die ( 'illegal request-settlementError' );
  368. }
  369. $item = array (
  370. 'cid' => $cid,
  371. 'categoryName' => $categoryDetil ['title'],
  372. 'invoiceElement' => $invoiceElement,
  373. 'invoiceQuantity' => $invoiceQuantity,
  374. 'invoiceUnitPrice' => $invoiceUnitPrice,
  375. 'invoicePrice' => $invoicePrice,
  376. 'invoiceType' => $invoiceType,
  377. 'settlementType' => $st,
  378. 'doPost' => $doPost,
  379. 'status' => 1,
  380. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  381. 'date' => date ( "Y-m-d H:i:s" ),
  382. 'updateTime' => date ( "Y-m-d H:i:s" ),
  383. 'sid' => $this->staff [0] ['sid'],
  384. 'userName' => $this->staff [0] ['username'],
  385. 'invoiceManage' => $invoiceManageDetail ['staff'],
  386. 'pendingApprovals' => $pendingApprovalsSid,
  387. 'moldManage' => json_encode ( $moldManage ),
  388. 'remark' => $remark,
  389. 'trainId' => $trainId
  390. );
  391. if ($invoiceType == 0)
  392. $item += array (
  393. 'invoiceTitle' => $invoiceTitle,
  394. 'TIN' => $TINT,
  395. 'address' => $addressT,
  396. 'phone' => $phoneT,
  397. 'bank' => $bankT,
  398. 'bankAccount' => $bankAccountT
  399. );
  400. else {
  401. $item += array (
  402. 'invoiceCompany' => $invoiceCompany,
  403. 'TIN' => $TIN,
  404. 'address' => $address,
  405. 'phone' => $phone,
  406. 'bank' => $bank,
  407. 'bankAccount' => $bankAccount
  408. );
  409. }
  410. if ($doPost == 1) {
  411. $mailList = array (
  412. 'invoice' => 1,
  413. 'mailItems' => $mailItems
  414. );
  415. if (! empty ( $softLock ))
  416. $mailList += array (
  417. 'softLock' => $softLockNum
  418. );
  419. else
  420. $mailList += array (
  421. 'softLock' => 0
  422. );
  423. if (! empty ( $contract ))
  424. $mailList += array (
  425. 'contract' => $contractNum
  426. );
  427. else
  428. $mailList += array (
  429. 'contract' => 0
  430. );
  431. if (! empty ( $instructions ))
  432. $mailList += array (
  433. 'instructions' => $instructionsNum
  434. );
  435. else
  436. $mailList += array (
  437. 'instructions' => 0
  438. );
  439. if (! empty ( $remittance ))
  440. $mailList += array (
  441. 'remittance' => $remittance
  442. );
  443. else
  444. $mailList += array (
  445. 'remittance' => ''
  446. );
  447. $mailString = '发票x1张,备注:' . $mailItems;
  448. if (! empty ( $softLock ))
  449. $mailString .= ',软件锁x' . $softLockNum.'个';
  450. if (! empty ( $contract ))
  451. $mailString .= ',合同x' . $contractNum.'份';
  452. if (! empty ( $instructions ))
  453. $mailString .= ',说明书x' . $instructionsNum.'本';
  454. if (! empty ( $remittance ))
  455. $mailString .= ',汇款账号单(张)';
  456. $item += array (
  457. 'recipients' => $recipients,
  458. 'recipientsPhone' => $recipientsPhone,
  459. 'recipientsAddress' => $recipientsAddress,
  460. 'mailItems' => $mailString,
  461. 'mailItemsJson' => json_encode ( $mailList )
  462. );
  463. }
  464. $iid = $invoice->addInvoice ( $item );
  465. // 如果是培训班结算 创建培训班发票到培训班备份中
  466. if (! empty ( $st )&&$st==1) {
  467. Doo::loadModel ( 'invoiceStore' );
  468. $invoiceStore = new invoiceStore ();
  469. Doo::loadModel ( 'invoiceTraining' );
  470. $invoiceTraining = new invoiceTraining ();
  471. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  472. $itemIS = array (
  473. 'isid' => $isid,
  474. 'ipSource' => 1,
  475. 'apStatus'=>1,
  476. 'iid' => $iid
  477. );
  478. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  479. // 更新培训班总数量
  480. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  481. $item = array (
  482. 'itid' => $trainId,
  483. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  484. 'submitStatus' => 1
  485. );
  486. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  487. }
  488. // 操作日志
  489. $item = array (
  490. 'date' => date ( "Y-m-d H:i:s" ),
  491. 'operation' => "创建",
  492. 'status' => 1,
  493. 'img' => $this->staff [0] ['avatar'],
  494. 'username' => $this->staff [0] ['username'],
  495. 'uid' => $this->staff [0] ['sid'],
  496. 'category' => $this->staff [0] ['category'],
  497. 'iid' => $iid
  498. );
  499. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  500. $item = array (
  501. 'date' => date ( "Y-m-d H:i:s" ),
  502. 'operation' => "提交审批",
  503. 'status' => 1,
  504. 'img' => $this->staff [0] ['avatar'],
  505. 'username' => $this->staff [0] ['username'],
  506. 'uid' => $this->staff [0] ['sid'],
  507. 'category' => $this->staff [0] ['category'],
  508. 'iid' => $iid
  509. );
  510. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  511. Doo::loadModel ( 'staff' );
  512. $staff = new staff ();
  513. $username2 = $staff->getOne ( array (
  514. 'select' => 'wxid',
  515. 'where' => 'sid=' . $pendingApprovalsSid,
  516. 'asArray' => TRUE
  517. ) );
  518. // 发送微信审批通知
  519. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  520. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  521. }
  522. return "/invoice";
  523. }
  524. function invoiceEdit() {
  525. Doo::loadClass ( 'XDeode' );
  526. $XDeode = new XDeode ( 5 );
  527. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  528. $iid = $XDeode->decode ( $iid );
  529. if (! is_numeric ( $iid ))
  530. die ( 'illegal request' );
  531. Doo::loadModel ( 'invoice' );
  532. $invoice = new invoice ();
  533. Doo::loadModel ( 'invoiceOperationLog' );
  534. $invoiceOperationLog = new invoiceOperationLog ();
  535. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  536. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  537. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  538. $this->data ['operation'] = $operation;
  539. $this->data ['invoiceDetail'] = $invoiceDetail;
  540. $this->data ['memu'] = "invoice";
  541. $this->data ['staff'] = $this->staff;
  542. $this->data ['receiptMemu'] = 'invoice';
  543. $this->render ( "/admin/invoiceEdit", $this->data );
  544. }
  545. /**
  546. * 重新编辑退回的发票
  547. * @return string
  548. */
  549. function invoiceEditDo() {
  550. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  551. Doo::loadModel ( 'invoice' );
  552. $invoice = new invoice ();
  553. $iid = $invoice->authcode ( $iidKey );
  554. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  555. die ( 'illegal request' );
  556. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  557. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  558. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  559. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  560. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  561. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  562. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  563. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  564. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  565. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  566. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  567. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  568. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  569. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  570. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  571. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  572. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  573. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  574. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  575. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  576. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  577. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  578. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  579. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  580. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  581. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  582. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  583. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  584. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  585. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  586. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  587. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  588. Doo::loadModel ( 'invoiceManage' );
  589. $invoiceManage = new invoiceManage ();
  590. Doo::loadModel ( 'invoiceOperationLog' );
  591. $invoiceOperationLog = new invoiceOperationLog ();
  592. $cid = explode ( ':', $cid );
  593. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  594. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  595. $moldManage = array ();
  596. foreach ( $invoiceManageList as $key => $value ) {
  597. if ($value ['mold'] == '发票打印')
  598. $moldManage [$value ['mold']] = $value ['staffList'];
  599. elseif ($value ['mold'] == '发票邮寄')
  600. $moldManage [$value ['mold']] = $value ['staffList'];
  601. elseif ($value ['mold'] == '发票打印')
  602. $moldManage [$value ['mold']] = $value ['staffList'];
  603. }
  604. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  605. $item = array (
  606. 'iid' => $iid,
  607. 'cid' => $cid [0],
  608. 'categoryName' => $cid [1],
  609. 'invoiceElement' => $invoiceElement,
  610. 'invoiceQuantity' => $invoiceQuantity,
  611. 'invoiceUnitPrice' => $invoiceUnitPrice,
  612. 'invoicePrice' => $invoicePrice,
  613. 'invoiceType' => $invoiceType,
  614. 'doPost' => $doPost,
  615. 'status' => 1,
  616. 'updateTime' => date ( "Y-m-d H:i:s" ),
  617. 'remark' => $remark
  618. );
  619. if ($invoiceType == 0)
  620. $item += array (
  621. 'invoiceTitle' => $invoiceTitle,
  622. 'TIN' => $TINT,
  623. 'address' => $addressT,
  624. 'phone' => $phoneT,
  625. 'bank' => $bankT,
  626. 'bankAccount' => $bankAccountT
  627. );
  628. else {
  629. $item += array (
  630. 'invoiceCompany' => $invoiceCompany,
  631. 'TIN' => $TIN,
  632. 'address' => $address,
  633. 'phone' => $phone,
  634. 'bank' => $bank,
  635. 'bankAccount' => $bankAccount
  636. );
  637. }
  638. if ($doPost == 1) {
  639. $mailList = array (
  640. 'invoice' => 1,
  641. 'mailItems' => $mailItems
  642. );
  643. if (! empty ( $softLock ))
  644. $mailList += array (
  645. 'softLock' => $softLockNum
  646. );
  647. else
  648. $mailList += array (
  649. 'softLock' => '0'
  650. );
  651. if (! empty ( $contract ))
  652. $mailList += array (
  653. 'contract' => $contractNum
  654. );
  655. else
  656. $mailList += array (
  657. 'contract' => '0'
  658. );
  659. if (! empty ( $instructions ))
  660. $mailList += array (
  661. 'instructions' => $instructionsNum
  662. );
  663. else
  664. $mailList += array (
  665. 'instructions' => '0'
  666. );
  667. if (! empty ( $remittance ))
  668. $mailList += array (
  669. 'remittance' => $remittance
  670. );
  671. else
  672. $mailList += array (
  673. 'remittance' => ''
  674. );
  675. $mailString = '发票x1,备注:' . $mailItems;
  676. if (! empty ( $softLock ))
  677. $mailString .= ',软件锁x' . $softLockNum;
  678. if (! empty ( $contract ))
  679. $mailString .= ',合同x' . $contractNum;
  680. if (! empty ( $instructions ))
  681. $mailString .= ',说明书x' . $instructionsNum;
  682. if (! empty ( $remittance ))
  683. $mailString .= ',汇款账号单';
  684. $item += array (
  685. 'recipients' => $recipients,
  686. 'recipientsPhone' => $recipientsPhone,
  687. 'recipientsAddress' => $recipientsAddress,
  688. 'mailItems' => $mailString,
  689. 'mailItemsJson' => json_encode ( $mailList )
  690. );
  691. }
  692. $invoice->setInvoiceByCondition ( $item );
  693. $item = array (
  694. 'date' => date ( "Y-m-d H:i:s" ),
  695. 'operation' => "重新提交审批",
  696. 'status' => 1,
  697. 'img' => $this->staff [0] ['avatar'],
  698. 'username' => $this->staff [0] ['username'],
  699. 'uid' => $this->staff [0] ['sid'],
  700. 'category' => $this->staff [0] ['category'],
  701. 'iid' => $iid
  702. );
  703. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  704. }
  705. return "/invoice";
  706. }
  707. /**
  708. * 培训班
  709. */
  710. function invoiceTraining() {
  711. Doo::loadModel ( 'L_category' );
  712. $lCategory = new L_category ();
  713. Doo::loadModel ( 'invoiceTraining' );
  714. $invoiceTraining = new invoiceTraining ();
  715. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  716. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  717. $category = $lCategory->getCategory ();
  718. $itid = array ();
  719. foreach ( $itTodoList as $key=>$value ) {
  720. array_push ( $itid, $value ['itid'] );
  721. //如果入账100%更新为已完成
  722. if ($itTodoList [$key] ['arriveSchedule']>=100){
  723. $invoiceTraining = new invoiceTraining ();
  724. $invoiceTraining->itid = $value ['itid'];
  725. $invoiceTraining->status = 2;
  726. $invoiceTraining->update ();
  727. }
  728. }
  729. foreach ( $itedList as $value ) {
  730. array_push ( $itid, $value ['itid'] );
  731. }
  732. $itid = implode ( ',', $itid );
  733. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  734. // print_r($itTodoList);
  735. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  736. $this->data ['itTodoList'] = $itTodoList;
  737. $this->data ['itedList'] = $itedList;
  738. $this->data ['category'] = $category;
  739. $this->data ['memu'] = "invoice";
  740. $this->data ['staff'] = $this->staff;
  741. $this->data ['receiptMemu'] = 'invoiceTraining';
  742. $this->render ( "/admin/invoiceTraining", $this->data );
  743. }
  744. /**
  745. * 创建培训班
  746. */
  747. function invoiceTrainingAdd() {
  748. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  749. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  750. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  751. if (empty ( $this->staff [0] ))
  752. die ( 'illegal request' );
  753. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  754. Doo::loadModel ( 'invoiceTraining' );
  755. $invoiceTraining = new invoiceTraining ();
  756. Doo::loadModel ( 'invoice' );
  757. $invoice = new invoice ();
  758. Doo::loadModel ( 'L_category' );
  759. $lCategory = new L_category ();
  760. Doo::loadModel ( 'invoiceManage' );
  761. $invoiceManage = new invoiceManage ();
  762. Doo::loadModel ( 'invoiceOperationLog' );
  763. $invoiceOperationLog = new invoiceOperationLog ();
  764. $item = array (
  765. 'cid' => $cid,
  766. 'trainName' => $trainName,
  767. 'trainDate' => $trainDate,
  768. 'creator' => $this->staff [0] ['sid'],
  769. 'creatorDate' => date ( "Y-m-d H:i:s" )
  770. );
  771. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  772. }
  773. return "/invoiceTraining";
  774. }
  775. /**
  776. * 删除培训班
  777. */
  778. function invoiceTrainingDelDo() {
  779. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  780. if (! empty ( $itid )) {
  781. Doo::loadModel ( 'invoiceTraining' );
  782. $invoiceTraining = new invoiceTraining ();
  783. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  784. }
  785. return "/invoiceTraining";
  786. }
  787. /**
  788. * 培训班详情
  789. */
  790. function invoiceTrainingDetail() {
  791. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  792. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  793. Doo::loadModel ( 'invoiceTraining' );
  794. $invoiceTraining = new invoiceTraining ();
  795. Doo::loadModel ( 'invoiceStore' );
  796. $invoiceStore = new invoiceStore ();
  797. if (empty ( $itid ))
  798. die ( 'illegal request' );
  799. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  800. if ($trainStatus == "SUBED")
  801. $con = ' (b.untreadStatus is null ) and ';
  802. elseif ($trainStatus == "APPROVAL")
  803. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  804. elseif ($trainStatus == "TICKET")
  805. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  806. elseif($trainStatus == "TICKETING"){
  807. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  808. }
  809. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  810. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  811. // print_r($isList);
  812. $trainlist = array ();
  813. foreach ( $isList as $key => $value ) {
  814. $irDetail = array ();
  815. if ($value ['apStatus'] == 1) {
  816. // array_push ( $irDetail, '' );
  817. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  818. } else {
  819. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  820. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  821. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  822. }
  823. array_push ( $irDetail, $value ['invoiceSerial'] );
  824. if ($value ['invoiceType'] == 1)
  825. array_push ( $irDetail, $value ['invoiceCompany'] );
  826. else
  827. array_push ( $irDetail, $value ['invoiceTitle'] );
  828. array_push ( $irDetail, $value ['TIN'] );
  829. array_push ( $irDetail, $value ['userName'] );
  830. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  831. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  832. } else
  833. array_push ( $irDetail, $value ['mailItems'] );
  834. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  835. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  836. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  837. array_push ( $irDetail, $value ['invoiceElement'] );
  838. array_push ( $irDetail, $value ['invoiceQuantity'] );
  839. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  840. if ($value ['invoiceType'] == 1)
  841. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  842. else
  843. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  844. array_push ( $irDetail, $value ['remark'] );
  845. if ($value ['status'] == 1)
  846. array_push ( $irDetail, '审批中' );
  847. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  848. array_push ( $irDetail, '已出票' );
  849. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  850. array_push ( $irDetail, '已入账' );
  851. else
  852. array_push ( $irDetail, '' );
  853. array_push ( $irDetail, $value ['invoiceNo'] );
  854. array_push ( $irDetail, $value ['printTime'] );
  855. $html = '';
  856. foreach ( $value ['invoiceReceivables'] as $value ) {
  857. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  858. }
  859. array_push ( $irDetail, $html );
  860. array_push ( $trainlist, $irDetail );
  861. }
  862. $trainlistJson = json_encode ( $trainlist );
  863. if (empty ( $detail ))
  864. die ( 'illegal request' );
  865. $this->data ['trainStatus'] = $trainStatus;
  866. $this->data ['itid'] = $itid;
  867. $this->data ['trainlistJson'] = $trainlistJson;
  868. $this->data ['iTrainDetail'] = $detail;
  869. $this->data ['memu'] = "invoice";
  870. $this->data ['staff'] = $this->staff;
  871. $this->data ['receiptMemu'] = 'invoiceTraining';
  872. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  873. }
  874. /**
  875. * 上传培训班发票
  876. * @return string
  877. */
  878. function invoiceTrainingUpload() {
  879. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  880. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  881. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  882. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  883. header ( "HTTP/1.1 500 Internal Server Error" );
  884. echo "POST exceeded maximum allowed size.";
  885. exit ( 0 );
  886. }
  887. // Settings
  888. $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)
  889. $upload_name = "Filedata";
  890. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  891. $extension_whitelist = array (
  892. "doc",
  893. "txt",
  894. "jpg",
  895. "gif",
  896. "png"
  897. ); // Allowed file extensions
  898. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  899. // Other variables
  900. $MAX_FILENAME_LENGTH = 260;
  901. $file_name = "";
  902. $file_extension = "";
  903. $uploadErrors = array (
  904. 0 => "文件上传成功",
  905. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  906. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  907. 3 => "上传的文件仅为部分文件",
  908. 4 => "没有文件上传",
  909. 6 => "缺少临时文件夹"
  910. );
  911. $nk = time ();
  912. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  913. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  914. echo "文件无法保存.";
  915. exit ( 0 );
  916. }
  917. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  918. echo json_encode ( array (
  919. 'filename' => $file_name,
  920. 'id' => $nk
  921. ) );
  922. exit ( 0 );
  923. }
  924. /**
  925. * 导入发票临时仓库
  926. */
  927. function invoiceStoreImport() {
  928. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  929. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  930. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  931. if ($path != "" && ! empty ( $trainingKey )) {
  932. Doo::loadModel ( 'invoiceStore' );
  933. Doo::loadModel ( 'staff' );
  934. $staff = new staff ();
  935. Doo::loadModel ( 'invoiceTraining' );
  936. $invoiceTraining = new invoiceTraining ();
  937. Doo::loadClass ( 'XDeode' );
  938. $XDeode = new XDeode ( 5 );
  939. $itid = $XDeode->decode ( $trainingKey );
  940. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  941. $userName = $this->staff [0] ['username'];
  942. $sDetail = $staff->getStaffByName ( $userName );
  943. // die('sdd');
  944. // 可以优化
  945. foreach ( $exlArray as $key => $value ) {
  946. // 开票
  947. $invoice = new invoiceStore ();
  948. $invoice->trainId = $itid;
  949. $invoice->invoiceType = 0;
  950. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  951. $invoice->invoiceType = 1;
  952. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  953. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  954. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  955. $invoice->invoiceTitle = $value ['invoiceTitle'];
  956. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  957. $invoice->invoiceCompany = $value ['invoiceTitle'];
  958. $invoice->userName = $userName;
  959. $invoice->sid = $sDetail ['sid'];
  960. $invoice->cid = $sDetail ['cid'];
  961. $invoice->categoryName = $sDetail ['category'];
  962. $invoice->invoiceElement = $value ['invoiceElement'];
  963. $invoice->remark = $value ['remark'];
  964. // $invoice->date = $value ['date'];
  965. // $invoice->printTime = $value ['date'];
  966. $invoice->ipSource = 1;
  967. $invoice->printStatus = 0;
  968. $invoice->status = 0;
  969. $invoice->postStatus = 1;
  970. $invoice->untreadStatus = 0;
  971. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  972. $invoice->TIN = $value ['TIN'];
  973. $invoice->address = $value ['address'];
  974. $invoice->phone = $value ['phone'];
  975. $invoice->bank = $value ['bank'];
  976. $invoice->bankAccount = $value ['bankAccount'];
  977. $invoice->recipientsAddress = $value ['recipientsAddress'];
  978. $invoice->recipients = $value ['recipients'];
  979. $invoice->recipientsPhone = $value ['recipientsPhone'];
  980. $iid = $invoice->insert ();
  981. }
  982. // 加入发票总数量
  983. $item = array (
  984. 'itid' => $itid,
  985. 'invoiceTotal' => count ( $exlArray )
  986. );
  987. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  988. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  989. }
  990. echo 'no file';
  991. }
  992. /**
  993. * 编辑仓库里的发票
  994. */
  995. function invoiceStoreEdit() {
  996. Doo::loadClass ( 'XDeode' );
  997. $XDeode = new XDeode ( 5 );
  998. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  999. $iid = $XDeode->decode ( $iid );
  1000. if (! is_numeric ( $iid ))
  1001. die ( 'illegal request' );
  1002. Doo::loadModel ( 'invoiceStore' );
  1003. $invoiceStore = new invoiceStore ();
  1004. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1005. // print_r($invoiceDetail);
  1006. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1007. $this->data ['invoiceDetail'] = $invoiceDetail;
  1008. $this->data ['memu'] = "invoice";
  1009. $this->data ['staff'] = $this->staff;
  1010. $this->data ['receiptMemu'] = 'invoiceTraining';
  1011. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1012. }
  1013. function invoiceStoreEditDo() {
  1014. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1015. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1016. Doo::loadModel ( 'invoiceStore' );
  1017. $invoice = new invoiceStore ();
  1018. Doo::loadClass ( 'XDeode' );
  1019. $XDeode = new XDeode ( 5 );
  1020. $iid = $XDeode->decode ( $storeKey );
  1021. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1022. die ( 'illegal request' );
  1023. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1024. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1025. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1026. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1027. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1028. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1029. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1030. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1031. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1032. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1033. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1034. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1035. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1036. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1037. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1038. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1039. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1040. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1041. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1042. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1043. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1044. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1045. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1046. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1047. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1048. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1049. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1050. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1051. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1052. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1053. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1054. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1055. $cid = explode ( ':', $cid );
  1056. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1057. $item = array (
  1058. 'isid' => $iid,
  1059. 'cid' => $cid [0],
  1060. 'categoryName' => $cid [1],
  1061. 'invoiceElement' => $invoiceElement,
  1062. 'invoiceQuantity' => $invoiceQuantity,
  1063. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1064. 'invoicePrice' => $invoicePrice,
  1065. 'invoiceType' => $invoiceType,
  1066. 'doPost' => $doPost,
  1067. 'status' => 1,
  1068. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1069. 'remark' => $remark
  1070. );
  1071. if ($invoiceType == 0)
  1072. $item += array (
  1073. 'invoiceTitle' => $invoiceTitle,
  1074. 'TIN' => $TINT,
  1075. 'address' => $addressT,
  1076. 'phone' => $phoneT,
  1077. 'bank' => $bankT,
  1078. 'bankAccount' => $bankAccountT
  1079. );
  1080. else {
  1081. $item += array (
  1082. 'invoiceCompany' => $invoiceCompany,
  1083. 'TIN' => $TIN,
  1084. 'address' => $address,
  1085. 'phone' => $phone,
  1086. 'bank' => $bank,
  1087. 'bankAccount' => $bankAccount
  1088. );
  1089. }
  1090. if ($doPost == 1) {
  1091. $mailList = array (
  1092. 'invoice' => 1,
  1093. 'mailItems' => $mailItems
  1094. );
  1095. if (! empty ( $softLock ))
  1096. $mailList += array (
  1097. 'softLock' => $softLockNum
  1098. );
  1099. else
  1100. $mailList += array (
  1101. 'softLock' => '0'
  1102. );
  1103. if (! empty ( $contract ))
  1104. $mailList += array (
  1105. 'contract' => $contractNum
  1106. );
  1107. else
  1108. $mailList += array (
  1109. 'contract' => '0'
  1110. );
  1111. if (! empty ( $instructions ))
  1112. $mailList += array (
  1113. 'instructions' => $instructionsNum
  1114. );
  1115. else
  1116. $mailList += array (
  1117. 'instructions' => '0'
  1118. );
  1119. if (! empty ( $remittance ))
  1120. $mailList += array (
  1121. 'remittance' => $remittance
  1122. );
  1123. else
  1124. $mailList += array (
  1125. 'remittance' => ''
  1126. );
  1127. $mailString = '发票x1,备注:' . $mailItems;
  1128. if (! empty ( $softLock ))
  1129. $mailString .= ',软件锁x' . $softLockNum;
  1130. if (! empty ( $contract ))
  1131. $mailString .= ',合同x' . $contractNum;
  1132. if (! empty ( $instructions ))
  1133. $mailString .= ',说明书x' . $instructionsNum;
  1134. if (! empty ( $remittance ))
  1135. $mailString .= ',汇款账号单';
  1136. $item += array (
  1137. 'recipients' => $recipients,
  1138. 'recipientsPhone' => $recipientsPhone,
  1139. 'recipientsAddress' => $recipientsAddress,
  1140. 'mailItems' => $mailString,
  1141. 'mailItemsJson' => json_encode ( $mailList )
  1142. );
  1143. }
  1144. $invoice->setInvoiceStoreByCondition ( $item );
  1145. }
  1146. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1147. }
  1148. /**
  1149. *
  1150. * @return string
  1151. */
  1152. function invoiceStoreDelete() {
  1153. Doo::loadClass ( 'XDeode' );
  1154. $XDeode = new XDeode ( 5 );
  1155. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1156. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1157. $isid = $XDeode->decode ( $iStoreKey );
  1158. $itid = $XDeode->decode ( $trainKey );
  1159. if (! is_numeric ( $isid ))
  1160. die ( 'illegal request' );
  1161. Doo::loadModel ( 'invoiceStore' );
  1162. $invoiceStore = new invoiceStore ();
  1163. $invoiceStore->delete ( array (
  1164. 'where' => 'isid=' . $isid,
  1165. 'limit' => 1
  1166. ) );
  1167. Doo::loadModel ( 'invoiceTraining' );
  1168. $invoiceTraining = new invoiceTraining ();
  1169. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1170. $item = array (
  1171. 'itid' => $itid,
  1172. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1173. );
  1174. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1175. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1176. }
  1177. /**
  1178. * 批量删除库里发票
  1179. */
  1180. function invoiceStoreBatchDelete() {
  1181. Doo::loadClass ( 'XDeode' );
  1182. $XDeode = new XDeode ( 5 );
  1183. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1184. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1185. if (empty($trainKey)||empty($storeKey))
  1186. die ( 'illegal request-IdKey' );
  1187. $tid = $XDeode->decode ( $trainKey );
  1188. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1189. die ( 'illegal request' );
  1190. Doo::loadModel ( 'invoiceStore' );
  1191. $isidKeyList = explode ( ',', $storeKey );
  1192. $isidList = array ();
  1193. foreach ( $isidKeyList as $value ) {
  1194. $isid = $XDeode->decode ( $value );
  1195. if (! empty ( $isid ) && is_numeric ( $isid ))
  1196. array_push ( $isidList, $isid );
  1197. }
  1198. $isidString = implode ( ',', $isidList );
  1199. $invoiceStore = new invoiceStore ();
  1200. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1201. $isidList = array ();
  1202. foreach ( $isList as $key => $value ) {
  1203. if ($value ['apStatus'] == 0)
  1204. array_push ( $isidList, $value ['isid'] );
  1205. }
  1206. $isidString = implode ( ',', $isidList );
  1207. // print_r($isList);
  1208. // echo $isidString;
  1209. $invoiceStore = new invoiceStore ();
  1210. $invoiceStore->delete ( array (
  1211. 'where' => "isid in ( " . $isidString . ")",
  1212. 'asArray' => TRUE
  1213. ) );
  1214. Doo::loadModel ( 'invoiceTraining' );
  1215. $invoiceTraining = new invoiceTraining ();
  1216. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1217. $item = array (
  1218. 'itid' => $tid,
  1219. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1220. );
  1221. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1222. // echo $tid;
  1223. // echo $storeKey;
  1224. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1225. }
  1226. /**
  1227. * 仓库发票提交审批
  1228. * @return string
  1229. */
  1230. function invoiceStoreApproval() {
  1231. Doo::loadClass ( 'XDeode' );
  1232. $XDeode = new XDeode ( 5 );
  1233. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1234. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1235. $isid = $XDeode->decode ( $iStoreKey );
  1236. $trainId = $XDeode->decode ( $trainKey );
  1237. if (! is_numeric ( $isid ))
  1238. die ( 'illegal request' );
  1239. Doo::loadModel ( 'invoiceStore' );
  1240. Doo::loadModel ( 'invoice' );
  1241. $invoice = new invoice ();
  1242. // 加入限制必须填写入开票内容和邮寄物品
  1243. $invoiceStore = new invoiceStore ();
  1244. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1245. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1246. header ( 'Content-Type:text/html;charset=utf-8' );
  1247. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1248. }
  1249. // 拷贝插入一条发票数据
  1250. $invoiceStore = new invoiceStore ();
  1251. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1252. $invoiceStore = new invoiceStore ();
  1253. $item = array (
  1254. 'isid' => $isid,
  1255. 'iid' => $iid,
  1256. 'apStatus' => 1
  1257. );
  1258. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1259. Doo::loadModel ( 'invoiceManage' );
  1260. $invoiceManage = new invoiceManage ();
  1261. Doo::loadModel ( 'invoiceOperationLog' );
  1262. $invoiceOperationLog = new invoiceOperationLog ();
  1263. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1264. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1265. $moldManage = array ();
  1266. foreach ( $invoiceManageList as $key => $value ) {
  1267. if ($value ['mold'] == '发票打印')
  1268. $moldManage [$value ['mold']] = $value ['staffList'];
  1269. elseif ($value ['mold'] == '发票邮寄')
  1270. $moldManage [$value ['mold']] = $value ['staffList'];
  1271. elseif ($value ['mold'] == '发票退票')
  1272. $moldManage [$value ['mold']] = $value ['staffList'];
  1273. }
  1274. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1275. $item = array (
  1276. 'iid' => $iid,
  1277. 'isid'=>$isid,
  1278. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1279. 'date' => date ( "Y-m-d H:i:s" ),
  1280. 'status' => 1,
  1281. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1282. 'trainId' => $trainId,
  1283. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1284. 'moldManage' => json_encode ( $moldManage ),
  1285. 'settlementType'=>1,
  1286. 'pendingApprovals' => $pendingApprovalsSid
  1287. );
  1288. $invoice->setInvoiceByCondition ( $item );
  1289. Doo::loadModel ( 'invoiceTraining' );
  1290. $invoiceTraining = new invoiceTraining ();
  1291. $item = array (
  1292. 'itid' => $trainId,
  1293. 'submitStatus' => 1
  1294. );
  1295. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1296. $item = array (
  1297. 'date' => date ( "Y-m-d H:i:s" ),
  1298. 'operation' => "创建",
  1299. 'status' => 1,
  1300. 'img' => $this->staff [0] ['avatar'],
  1301. 'username' => $this->staff [0] ['username'],
  1302. 'uid' => $this->staff [0] ['sid'],
  1303. 'category' => $this->staff [0] ['category'],
  1304. 'iid' => $iid
  1305. );
  1306. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1307. $item = array (
  1308. 'date' => date ( "Y-m-d H:i:s" ),
  1309. 'operation' => "提交审批",
  1310. 'status' => 1,
  1311. 'img' => $this->staff [0] ['avatar'],
  1312. 'username' => $this->staff [0] ['username'],
  1313. 'uid' => $this->staff [0] ['sid'],
  1314. 'category' => $this->staff [0] ['category'],
  1315. 'iid' => $iid
  1316. );
  1317. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1318. Doo::loadModel ( 'staff' );
  1319. $staff = new staff ();
  1320. $username2 = $staff->getOne ( array (
  1321. 'select' => 'wxid',
  1322. 'where' => 'sid=' . $pendingApprovalsSid,
  1323. 'asArray' => TRUE
  1324. ) );
  1325. // 发送微信审批通知
  1326. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1327. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1328. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1329. }
  1330. /**
  1331. * 批量提交发票
  1332. * @return string
  1333. */
  1334. function invoiceStoreBatchApproval() {
  1335. Doo::loadClass ( 'XDeode' );
  1336. $XDeode = new XDeode ( 5 );
  1337. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1338. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1339. if (empty($trainKey)||empty($storeKey))
  1340. die ( 'illegal request-IdKey' );
  1341. $trainId = $XDeode->decode ( $trainKey );
  1342. $isidKeyList = explode ( ',', $storeKey );
  1343. $isidList = array ();
  1344. foreach ( $isidKeyList as $value ) {
  1345. $isid = $XDeode->decode ( $value );
  1346. if (! empty ( $isid ) && is_numeric ( $isid ))
  1347. array_push ( $isidList, $isid );
  1348. }
  1349. $isidString = implode ( ',', $isidList );
  1350. if (! is_numeric ( $trainId ))
  1351. die ( 'illegal request' );
  1352. Doo::loadModel ( 'invoiceStore' );
  1353. Doo::loadModel ( 'invoice' );
  1354. // 判断哪些已经加入审批过
  1355. // 加入限制必须填写入开票内容和邮寄物品
  1356. $invoiceStore = new invoiceStore ();
  1357. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1358. foreach ( $isList as $key => $value ) {
  1359. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1360. header ( 'Content-Type:text/html;charset=utf-8' );
  1361. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1362. }
  1363. }
  1364. // 拷贝插入一条发票数据
  1365. $invoiceStore = new invoiceStore ();
  1366. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1367. $invoiceStore = new invoiceStore ();
  1368. $item = array (
  1369. 'apStatus' => 1
  1370. );
  1371. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1372. // 获得正式发票ID
  1373. $invoice = new invoice ();
  1374. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1375. $sqlList = array ();
  1376. $iidString = '';
  1377. $iida = array ();
  1378. foreach ( $iidList as $key => $value ) {
  1379. $sqlList [$value ['isid']] = $value ['iid'];
  1380. array_push ( $iida, $value ['iid'] );
  1381. }
  1382. $iidString = implode ( ',', $iida );
  1383. $ids = implode ( ',', array_keys ( $sqlList ) );
  1384. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1385. foreach ( $sqlList as $id => $ordinal ) {
  1386. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1387. }
  1388. $sql .= "END WHERE isid IN ($ids)";
  1389. $invoiceStore = new invoiceStore ();
  1390. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1391. Doo::loadModel ( 'invoiceManage' );
  1392. $invoiceManage = new invoiceManage ();
  1393. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1394. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1395. $moldManage = array ();
  1396. foreach ( $invoiceManageList as $key => $value ) {
  1397. if ($value ['mold'] == '发票打印')
  1398. $moldManage [$value ['mold']] = $value ['staffList'];
  1399. elseif ($value ['mold'] == '发票邮寄')
  1400. $moldManage [$value ['mold']] = $value ['staffList'];
  1401. elseif ($value ['mold'] == '发票退票')
  1402. $moldManage [$value ['mold']] = $value ['staffList'];
  1403. }
  1404. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1405. // 批量更新发票信息
  1406. $item = array (
  1407. 'date' => date ( "Y-m-d H:i:s" ),
  1408. 'status' => 1,
  1409. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1410. 'trainId' => $trainId,
  1411. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1412. 'moldManage' => json_encode ( $moldManage ),
  1413. 'settlementType'=>1,
  1414. 'pendingApprovals' => $pendingApprovalsSid
  1415. );
  1416. $invoice = new invoice ();
  1417. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1418. //批量更新发票中仓库isid
  1419. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1420. foreach ( $sqlList as $isid => $iid ) {
  1421. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1422. }
  1423. $sql .= "END WHERE iid IN ($iidString)";
  1424. $invoice = new invoice ();
  1425. $invoice->UpdateBatchInvoice($sql);
  1426. // 批量更新发票序列号
  1427. $sqlList = array ();
  1428. foreach ( $iida as $value ) {
  1429. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1430. }
  1431. $ids = implode ( ',', array_keys ( $sqlList ) );
  1432. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1433. foreach ( $sqlList as $id => $ordinal ) {
  1434. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1435. }
  1436. $sql .= "END WHERE iid IN ($ids)";
  1437. $invoiceStore = new invoiceStore ();
  1438. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1439. // 批量生产操作日志
  1440. Doo::loadModel ( 'invoiceOperationLog' );
  1441. $sqlList = array ();
  1442. foreach ( $iida as $key => $value ) {
  1443. $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 . '"),
  1444. ("' . 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 . '") ';
  1445. array_push ( $sqlList, $sql );
  1446. }
  1447. $iolSql = implode ( ',', $sqlList );
  1448. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1449. $invoiceOperationLog = new invoiceOperationLog ();
  1450. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1451. Doo::loadModel ( 'invoiceTraining' );
  1452. $invoiceTraining = new invoiceTraining ();
  1453. $item = array (
  1454. 'itid' => $trainId,
  1455. 'submitStatus' => 1
  1456. );
  1457. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1458. Doo::loadModel ( 'staff' );
  1459. $staff = new staff ();
  1460. $username2 = $staff->getOne ( array (
  1461. 'select' => 'wxid',
  1462. 'where' => 'sid=' . $pendingApprovalsSid,
  1463. 'asArray' => TRUE
  1464. ) );
  1465. // 发送微信审批通知
  1466. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1467. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1468. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1469. }
  1470. /**
  1471. */
  1472. function invoiceStoreMailItemSet() {
  1473. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1474. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1475. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1476. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1477. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1478. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1479. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1480. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1481. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1482. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1483. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1484. Doo::loadClass ( 'XDeode' );
  1485. $XDeode = new XDeode ( 5 );
  1486. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1487. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1488. $isid = $XDeode->decode ( $storeKey );
  1489. $trainId = $XDeode->decode ( $trainKey );
  1490. if (! is_numeric ( $isid ))
  1491. die ( 'illegal request' );
  1492. Doo::loadModel ( 'invoiceStore' );
  1493. $invoiceStore = new invoiceStore ();
  1494. $mailList = array (
  1495. 'invoice' => 1,
  1496. 'mailItems' => $mailItems
  1497. );
  1498. if (! empty ( $softLock ))
  1499. $mailList += array (
  1500. 'softLock' => $softLockNum
  1501. );
  1502. else
  1503. $mailList += array (
  1504. 'softLock' => 0
  1505. );
  1506. if (! empty ( $contract ))
  1507. $mailList += array (
  1508. 'contract' => $contractNum
  1509. );
  1510. else
  1511. $mailList += array (
  1512. 'contract' => 0
  1513. );
  1514. if (! empty ( $instructions ))
  1515. $mailList += array (
  1516. 'instructions' => $instructionsNum
  1517. );
  1518. else
  1519. $mailList += array (
  1520. 'instructions' => 0
  1521. );
  1522. if (! empty ( $remittance ))
  1523. $mailList += array (
  1524. 'remittance' => $remittance
  1525. );
  1526. else
  1527. $mailList += array (
  1528. 'remittance' => ''
  1529. );
  1530. $mailString = '发票x1,备注:' . $mailItems;
  1531. if (! empty ( $softLock ))
  1532. $mailString .= ',软件锁x' . $softLockNum;
  1533. if (! empty ( $contract ))
  1534. $mailString .= ',合同x' . $contractNum;
  1535. if (! empty ( $instructions ))
  1536. $mailString .= ',说明书x' . $instructionsNum;
  1537. if (! empty ( $remittance ))
  1538. $mailString .= ',汇款账号单';
  1539. $item = array (
  1540. 'isid' => $isid,
  1541. 'doPost' => 1,
  1542. 'mailItems' => $mailString,
  1543. 'mailItemsJson' => json_encode ( $mailList )
  1544. );
  1545. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1546. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1547. }
  1548. /**
  1549. * 批量设置邮寄物品
  1550. */
  1551. function invoiceStoreBatchMailItemSet() {
  1552. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1553. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1554. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1555. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1556. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1557. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1558. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1559. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1560. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1561. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1562. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1563. Doo::loadClass ( 'XDeode' );
  1564. $XDeode = new XDeode ( 5 );
  1565. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1566. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1567. if (empty($trainKey)||empty($storeKey))
  1568. die ( 'illegal request-IdKey' );
  1569. $isidKeyList = explode ( ',', $storeKey );
  1570. $isidList = array ();
  1571. foreach ( $isidKeyList as $value ) {
  1572. $isid = $XDeode->decode ( $value );
  1573. if (! empty ( $isid ) && is_numeric ( $isid ))
  1574. array_push ( $isidList, $isid );
  1575. }
  1576. $isidString = implode ( ',', $isidList );
  1577. $trainId = $XDeode->decode ( $trainKey );
  1578. if (! is_numeric ( $isid ))
  1579. die ( 'illegal request' );
  1580. Doo::loadModel ( 'invoiceStore' );
  1581. $invoiceStore = new invoiceStore ();
  1582. $mailList = array (
  1583. 'invoice' => 1,
  1584. 'mailItems' => $mailItems
  1585. );
  1586. if (! empty ( $softLock ))
  1587. $mailList += array (
  1588. 'softLock' => $softLockNum
  1589. );
  1590. else
  1591. $mailList += array (
  1592. 'softLock' => 0
  1593. );
  1594. if (! empty ( $contract ))
  1595. $mailList += array (
  1596. 'contract' => $contractNum
  1597. );
  1598. else
  1599. $mailList += array (
  1600. 'contract' => 0
  1601. );
  1602. if (! empty ( $instructions ))
  1603. $mailList += array (
  1604. 'instructions' => $instructionsNum
  1605. );
  1606. else
  1607. $mailList += array (
  1608. 'instructions' => 0
  1609. );
  1610. if (! empty ( $remittance ))
  1611. $mailList += array (
  1612. 'remittance' => $remittance
  1613. );
  1614. else
  1615. $mailList += array (
  1616. 'remittance' => ''
  1617. );
  1618. $mailString = '发票x1,备注:' . $mailItems;
  1619. if (! empty ( $softLock ))
  1620. $mailString .= ',软件锁x' . $softLockNum;
  1621. if (! empty ( $contract ))
  1622. $mailString .= ',合同x' . $contractNum;
  1623. if (! empty ( $instructions ))
  1624. $mailString .= ',说明书x' . $instructionsNum;
  1625. if (! empty ( $remittance ))
  1626. $mailString .= ',汇款账号单';
  1627. $item = array (
  1628. 'doPost' => 1,
  1629. 'mailItems' => $mailString,
  1630. 'mailItemsJson' => json_encode ( $mailList )
  1631. );
  1632. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1633. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1634. }
  1635. /**
  1636. * 废弃
  1637. */
  1638. function ajaxGetMailItemByIstore() {
  1639. Doo::loadClass ( 'XDeode' );
  1640. $XDeode = new XDeode ( 5 );
  1641. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1642. $isid = $XDeode->decode ( $storeKey );
  1643. if (! is_numeric ( $isid ))
  1644. die ( 'illegal request' );
  1645. Doo::loadModel ( 'invoiceStore' );
  1646. $invoiceStore = new invoiceStore ();
  1647. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1648. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1649. echo json_encode ( $isDetail ['mailItemsJson'] );
  1650. exit ();
  1651. }
  1652. /**
  1653. * 终止开票
  1654. */
  1655. function invoiceDroppedDo() {
  1656. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1657. Doo::loadModel ( 'invoice' );
  1658. $invoice = new invoice ();
  1659. Doo::loadModel ( 'invoiceOperationLog' );
  1660. $invoiceOperationLog = new invoiceOperationLog ();
  1661. $iid = $invoice->authcode ( $droppedIidKey );
  1662. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1663. die ( 'illegal request' );
  1664. $item = array (
  1665. 'iid' => $iid,
  1666. 'status' => 4,
  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. return "/invoice";
  1682. }
  1683. /**
  1684. * 更新退票的邮寄信息
  1685. */
  1686. function invoiceUntreadMailDo() {
  1687. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1688. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1689. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1690. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1691. Doo::loadModel ( 'invoice' );
  1692. $invoice = new invoice ();
  1693. $iid = $invoice->authcode ( $untreadIidKey );
  1694. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1695. die ( 'illegal request' );
  1696. $item = array (
  1697. 'iid' => $iid,
  1698. 'untreadCompany' => $untreadCompany,
  1699. 'untreadNumber' => $untreadNumber,
  1700. 'untreadItems' => $untreadItems
  1701. );
  1702. $invoice->setInvoiceByCondition ( $item );
  1703. return "/invoice";
  1704. }
  1705. /**
  1706. * 申请退票 --
  1707. */
  1708. function invoiceUntreadDo() {
  1709. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1710. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1711. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1712. Doo::loadModel ( 'invoice' );
  1713. $invoice = new invoice ();
  1714. Doo::loadModel ( 'invoiceOperationLog' );
  1715. $invoiceOperationLog = new invoiceOperationLog ();
  1716. Doo::loadModel ( 'invoiceReceivables' );
  1717. $invoiceReceivables = new invoiceReceivables ();
  1718. $iid = $invoice->authcode ( $untreadIidKey );
  1719. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1720. die ( 'illegal request' );
  1721. /*
  1722. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1723. */
  1724. $item = array (
  1725. 'iid' => $iid,
  1726. 'untreadStatus' => 1,
  1727. 'untreadReason' => $untreadReason,
  1728. 'untreadPost' => $untreadPost,
  1729. 'updateTime' => date ( "Y-m-d H:i:s" )
  1730. );
  1731. $invoice->setInvoiceByCondition ( $item );
  1732. $item = array (
  1733. 'date' => date ( "Y-m-d H:i:s" ),
  1734. 'operation' => '申请退票',
  1735. 'status' => 7,
  1736. 'img' => $this->staff [0] ['avatar'],
  1737. 'username' => $this->staff [0] ['username'],
  1738. 'uid' => $this->staff [0] ['sid'],
  1739. 'category' => $this->staff [0] ['category'],
  1740. 'iid' => $iid
  1741. );
  1742. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1743. return "/invoice";
  1744. }
  1745. /**
  1746. * 删除已终止的开票
  1747. */
  1748. function invoiceDelDo() {
  1749. Doo::loadModel ( 'invoice' );
  1750. $invoice = new invoice ();
  1751. Doo::loadModel ( 'invoiceOperationLog' );
  1752. $invoiceOperationLog = new invoiceOperationLog ();
  1753. Doo::loadClass ( 'XDeode' );
  1754. $XDeode = new XDeode ( 5 );
  1755. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1756. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1757. $iid = $XDeode->decode ( $iid );
  1758. Doo::loadModel ( 'invoiceStore' );
  1759. $invoiceStore = new invoiceStore ();
  1760. if (! is_numeric ( $iid ))
  1761. die ( 'illegal request' );
  1762. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1763. if (empty ( $invoiceDetail ))
  1764. die ( 'illegal request' );
  1765. $item = array (
  1766. 'iid' => $iid,
  1767. 'isDelete' => 1,
  1768. 'updateTime' => date ( "Y-m-d H:i:s" )
  1769. );
  1770. $invoice->setInvoiceByCondition ( $item );
  1771. $item = array (
  1772. 'date' => date ( "Y-m-d H:i:s" ),
  1773. 'operation' => '删除了已终止的发票',
  1774. 'status' => 4,
  1775. 'img' => $this->staff [0] ['avatar'],
  1776. 'username' => $this->staff [0] ['username'],
  1777. 'uid' => $this->staff [0] ['sid'],
  1778. 'category' => $this->staff [0] ['category'],
  1779. 'iid' => $iid
  1780. );
  1781. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1782. // 删除培训班发票仓库里的发票
  1783. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1784. return "/invoice";
  1785. }
  1786. /**
  1787. */
  1788. function invoiceApproval() {
  1789. Doo::loadModel ( 'invoice' );
  1790. $invoice = new invoice ();
  1791. Doo::loadClass ( 'XDeode' );
  1792. $XDeode = new XDeode ( 5 );
  1793. Doo::loadModel ( 'staff' );
  1794. $staff = new staff ();
  1795. $invoiceList = $invoice->find ( array (
  1796. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1797. 'desc' => 'iid',
  1798. 'limit' => 10,
  1799. 'asArray' => true
  1800. ) );
  1801. foreach ( $invoiceList as $key => $value ) {
  1802. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1803. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1804. if (! empty ( $lastApprover )) {
  1805. $lastApproverKey = array_keys ( $lastApprover );
  1806. $lastApprover = end ( $lastApprover );
  1807. $staffDetail = $staff->getOne ( array (
  1808. 'where' => 'sid=' . end ( $lastApproverKey ),
  1809. 'asArray' => true
  1810. ) );
  1811. $lastApprover ['username'] = $staffDetail ['username'];
  1812. }
  1813. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1814. }
  1815. $ilist = $invoice->getInvoiceByProcessStatus ();
  1816. foreach ( $ilist as $key => $value ) {
  1817. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1818. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1819. if (! empty ( $lastApprover )) {
  1820. $lastApproverKey = array_keys ( $lastApprover );
  1821. $lastApprover = end ( $lastApprover );
  1822. $staffDetail = $staff->getOne ( array (
  1823. 'where' => 'sid=' . end ( $lastApproverKey ),
  1824. 'asArray' => true
  1825. ) );
  1826. $lastApprover ['username'] = $staffDetail ['username'];
  1827. }
  1828. $ilist [$key] ['lastApprover'] = $lastApprover;
  1829. }
  1830. // print_r($ilist);
  1831. $this->data ['invoiceList'] = $invoiceList;
  1832. $this->data ['ilist'] = $ilist;
  1833. $this->data ['memu'] = "invoice";
  1834. $this->data ['staff'] = $this->staff;
  1835. $this->data ['receiptMemu'] = 'invoiceApproval';
  1836. $this->render ( "/admin/invoiceApproval", $this->data );
  1837. }
  1838. function invoiceDetail() {
  1839. Doo::loadClass ( 'XDeode' );
  1840. $XDeode = new XDeode ( 5 );
  1841. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1842. $iid = $XDeode->decode ( $iid );
  1843. if (! is_numeric ( $iid ))
  1844. die ( 'illegal request' );
  1845. Doo::loadModel ( 'invoice' );
  1846. $invoice = new invoice ();
  1847. Doo::loadModel ( 'invoiceOperationLog' );
  1848. $invoiceOperationLog = new invoiceOperationLog ();
  1849. $invoiceDetail = $invoice->getOne ( array (
  1850. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1851. 'asArray' => true
  1852. ) );
  1853. if (empty ( $invoiceDetail ))
  1854. die ( 'illegal request' );
  1855. if ($invoiceDetail ['settlementType'] == 1) {
  1856. Doo::loadModel ( 'invoiceTraining' );
  1857. $invoiceTraining = new invoiceTraining ();
  1858. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  1859. }
  1860. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1861. $this->data ['invoiceDetail'] = $invoiceDetail;
  1862. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1863. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1864. $this->data ['memu'] = "invoice";
  1865. $this->data ['staff'] = $this->staff;
  1866. $this->data ['receiptMemu'] = 'invoiceApproval';
  1867. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1868. }
  1869. /**
  1870. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1871. *
  1872. * @since 1.0.0
  1873. * @var integer iid 开票ID 已加密
  1874. * @var integer status 发票审批状态
  1875. * @var integer opintion 审批发票的意见
  1876. * @return string 如操作成功返回审批首页
  1877. */
  1878. function invoiceApprovalDo() {
  1879. Doo::loadModel ( 'invoice' );
  1880. $invoice = new invoice ();
  1881. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1882. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1883. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1884. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  1885. $iid = $invoice->authcode ( $iid );
  1886. if (! is_numeric ( $iid ))
  1887. die ( 'illegal request' );
  1888. // && ! empty ( $opinion )
  1889. if (! empty ( $iid ) && ! empty ( $status )) {
  1890. if (! ($status == 2 || $status == 3 || $status == 4))
  1891. die ( 'illegal request' );
  1892. Doo::loadModel ( 'invoiceOperationLog' );
  1893. $invoiceOperationLog = new invoiceOperationLog ();
  1894. $invoiceDetail = $invoice->getOne ( array (
  1895. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1896. 'asArray' => true
  1897. ) );
  1898. if (empty ( $invoiceDetail ))
  1899. die ( 'illegal request' );
  1900. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1901. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1902. if ($status == 3) {
  1903. $invoice->status = $status;
  1904. $item = array (
  1905. 'operation' => $opinion
  1906. );
  1907. } else {
  1908. if (empty ( $processApprovals )) {
  1909. $processApprovals = array (
  1910. $this->staff [0] ['sid'] => array (
  1911. 'date' => date ( "Y-m-d H:i:s" ),
  1912. 'opinion' => $opinion,
  1913. 'status' => $status
  1914. )
  1915. );
  1916. // var_dump(next($invoiceManage));
  1917. $nextInvoiceManage = next ( $invoiceManage );
  1918. // print_r($nextInvoiceManage);
  1919. if ($status != 4 && $nextInvoiceManage !== false)
  1920. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1921. $invoice->processApprovals = json_encode ( $processApprovals );
  1922. // var_dump($invoice);
  1923. // print_r($invoiceManage);
  1924. } else {
  1925. $processApprovals [$this->staff [0] ['sid']] = array (
  1926. 'date' => date ( "Y-m-d H:i:s" ),
  1927. 'opinion' => $opinion,
  1928. 'status' => $status
  1929. );
  1930. $pendingApprovals = 0;
  1931. foreach ( $invoiceManage as $key => $value ) {
  1932. if ($value [0] == $this->staff [0] ['sid']) {
  1933. if (isset ( $invoiceManage [$key + 1] ))
  1934. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1935. break;
  1936. }
  1937. }
  1938. if ($status != 4 && ! empty ( $pendingApprovals ))
  1939. $invoice->pendingApprovals = $pendingApprovals;
  1940. $invoice->processApprovals = json_encode ( $processApprovals );
  1941. }
  1942. $item = array (
  1943. 'operation' => $opinion
  1944. );
  1945. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1946. $invoice->status = $status;
  1947. $invoice->pendingApprovals = 0;
  1948. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1949. } elseif ($status == 4) {
  1950. $invoice->status = $status;
  1951. $item = array (
  1952. 'operation' => $opinion
  1953. );
  1954. }
  1955. }
  1956. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  1957. $invoice->update ( array (
  1958. 'where' => 'iid=' . $iid
  1959. ) );
  1960. $item += array (
  1961. 'date' => date ( "Y-m-d H:i:s" ),
  1962. 'img' => $this->staff [0] ['avatar'],
  1963. 'username' => $this->staff [0] ['username'],
  1964. 'uid' => $this->staff [0] ['sid'],
  1965. 'category' => $this->staff [0] ['category'],
  1966. 'status' => $status,
  1967. 'iid' => $iid
  1968. );
  1969. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1970. if (empty ( $divApproval ))
  1971. return '/invoiceApproval';
  1972. else
  1973. return '/invoiceApprovalAchieve/PEND';
  1974. }
  1975. die ( 'illegal request' );
  1976. }
  1977. /**
  1978. * 展示需要打印的发票数据
  1979. *
  1980. * @since 1.0.0
  1981. */
  1982. function invoicePrint() {
  1983. Doo::loadModel ( 'invoice' );
  1984. $invoice = new invoice ();
  1985. Doo::loadClass ( 'XDeode' );
  1986. $XDeode = new XDeode ( 5 );
  1987. Doo::loadModel ( 'staff' );
  1988. $staff = new staff ();
  1989. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  1990. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  1991. foreach ( $toPrint as $key => $value ) {
  1992. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1993. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1994. if (! empty ( $lastApprover )) {
  1995. $lastApproverKey = array_keys ( $lastApprover );
  1996. $lastApprover = end ( $lastApprover );
  1997. $staffDetail = $staff->getOne ( array (
  1998. 'where' => 'sid=' . end ( $lastApproverKey ),
  1999. 'asArray' => true
  2000. ) );
  2001. $lastApprover ['username'] = $staffDetail ['username'];
  2002. }
  2003. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2004. }
  2005. foreach ( $printed as $key => $value ) {
  2006. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2007. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2008. if (! empty ( $lastApprover )) {
  2009. $lastApproverKey = array_keys ( $lastApprover );
  2010. $lastApprover = end ( $lastApprover );
  2011. $staffDetail = $staff->getOne ( array (
  2012. 'where' => 'sid=' . end ( $lastApproverKey ),
  2013. 'asArray' => true
  2014. ) );
  2015. $lastApprover ['username'] = $staffDetail ['username'];
  2016. }
  2017. $printed [$key] ['lastApprover'] = $lastApprover;
  2018. }
  2019. $this->data ['printed'] = $printed;
  2020. $this->data ['toPrint'] = $toPrint;
  2021. $this->data ['memu'] = "invoice";
  2022. $this->data ['staff'] = $this->staff;
  2023. $this->data ['receiptMemu'] = 'invoicePrint';
  2024. $this->render ( "/admin/invoicePrint", $this->data );
  2025. }
  2026. /**
  2027. * 展示发票打印的详情页面
  2028. *
  2029. * @since 1.0.0
  2030. */
  2031. function invoicePrintDetail() {
  2032. Doo::loadClass ( 'XDeode' );
  2033. $XDeode = new XDeode ( 5 );
  2034. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2035. $iid = $XDeode->decode ( $iid );
  2036. if (! is_numeric ( $iid ))
  2037. die ( 'illegal request' );
  2038. Doo::loadModel ( 'invoice' );
  2039. $invoice = new invoice ();
  2040. Doo::loadModel ( 'invoiceOperationLog' );
  2041. $invoiceOperationLog = new invoiceOperationLog ();
  2042. Doo::loadModel ( 'invoicePaper' );
  2043. $invoicePaper = new invoicePaper ();
  2044. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2045. if (empty ( $invoiceDetail ))
  2046. die ( 'illegal request' );
  2047. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2048. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2049. if ($invoiceDetail ['settlementType'] == 1) {
  2050. Doo::loadModel ( 'invoiceTraining' );
  2051. $invoiceTraining = new invoiceTraining ();
  2052. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2053. }
  2054. $this->data ['invoicePaperList'] = $invoicePaperList;
  2055. $this->data ['invoiceDetail'] = $invoiceDetail;
  2056. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2057. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2058. $this->data ['memu'] = "invoice";
  2059. $this->data ['staff'] = $this->staff;
  2060. $this->data ['receiptMemu'] = 'invoicePrint';
  2061. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2062. }
  2063. /**
  2064. * 所有待打印 发票
  2065. */
  2066. function invoicePrintStayAchieve() {
  2067. Doo::loadModel ( 'invoice' );
  2068. $invoice = new invoice ();
  2069. Doo::loadClass ( 'XDeode' );
  2070. $XDeode = new XDeode ( 5 );
  2071. Doo::loadModel ( 'staff' );
  2072. $staff = new staff ();
  2073. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2074. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2075. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2076. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2077. Doo::loadModel ( 'invoiceTraining' );
  2078. $invoiceTraining = new invoiceTraining ();
  2079. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2080. $page_size = 12;
  2081. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2082. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2083. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2084. $get = "/" . $status;
  2085. $con = ' and status=2 ';
  2086. if ($status == 'TOPRINT')
  2087. $con = ' and status=2 and printStatus=0 ';
  2088. elseif ($status == 'PRINTED')
  2089. $con = ' and status=2 and printStatus=1';
  2090. if ($invoiceType == 'ORDINARY')
  2091. $con .= ' and invoiceType=0 ';
  2092. elseif ($invoiceType == 'SPECIAL')
  2093. $con .= ' and invoiceType=1 ';
  2094. if ($invoiceTrain == 'ORDINARY')
  2095. $con .= ' and trainId=0 ';
  2096. elseif ($invoiceTrain == 'TRAIN')
  2097. $con .= ' and trainId!=0 ';
  2098. if ($invoiceTrainName != 'ALL') {
  2099. $trainId = $XDeode->decode ( $invoiceTrainName );
  2100. if (is_numeric ( $trainId ))
  2101. $con .= ' and trainId =' . $trainId;
  2102. }
  2103. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2104. $dateArr = explode ( ':', $date );
  2105. $D1 = '';
  2106. $D2 = '';
  2107. if (! empty ( $date )) {
  2108. $D1 = $dateArr [0];
  2109. $D2 = $dateArr [1];
  2110. }
  2111. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2112. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2113. if (! empty ( $MebSea )) {
  2114. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2115. }
  2116. $pageinfo ['page'] = array (
  2117. 'previous' => ''
  2118. );
  2119. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea )."&invoiceType=".urlencode ( $invoiceType )."&invoiceTrain=".urlencode ( $invoiceTrain )."";
  2120. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2121. $action = "invoicePrintStayAchieve";
  2122. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2123. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2124. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2125. $this->data ['trainList'] = $trainList;
  2126. $this->data ['invoiceType'] = $invoiceType;
  2127. $this->data ['invoiceTrain'] = $invoiceTrain;
  2128. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2129. $this->data ['MebSeaEn'] = $MebSea;
  2130. $this->data ['MebSea'] = urlencode ( $MebSea );
  2131. $this->data ['get'] = $get;
  2132. $this->data ['page'] = $pageinfo;
  2133. $this->data ['date'] = $date;
  2134. $this->data ['status'] = $status;
  2135. $this->data ['invoiceType'] = $invoiceType;
  2136. $this->data ['memu'] = "invoice";
  2137. $this->data ['staff'] = $this->staff;
  2138. foreach ( $list as $key => $value ) {
  2139. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2140. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2141. if (! empty ( $lastApprover )) {
  2142. $lastApproverKey = array_keys ( $lastApprover );
  2143. $lastApprover = end ( $lastApprover );
  2144. $staffDetail = $staff->getOne ( array (
  2145. 'where' => 'sid=' . end ( $lastApproverKey ),
  2146. 'asArray' => true
  2147. ) );
  2148. $lastApprover ['username'] = $staffDetail ['username'];
  2149. }
  2150. $list [$key] ['lastApprover'] = $lastApprover;
  2151. }
  2152. $this->data ['receiptMemu'] = 'invoicePrint';
  2153. $this->data ['list'] = $list;
  2154. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2155. }
  2156. /**
  2157. * 填写票号并完成打印
  2158. * @since 1.0.0
  2159. */
  2160. function invoicePrintDo() {
  2161. Doo::loadModel ( 'invoice' );
  2162. $invoice = new invoice ();
  2163. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2164. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2165. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2166. $iid = $invoice->authcode ( $iid );
  2167. if (! is_numeric ( $iid ))
  2168. die ( 'illegal request' );
  2169. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2170. Doo::loadModel ( 'invoiceOperationLog' );
  2171. $invoiceOperationLog = new invoiceOperationLog ();
  2172. Doo::loadModel ( 'invoiceStatistics' );
  2173. $invoiceStatistics = new invoiceStatistics ();
  2174. $XDeode = new XDeode ( 5 );
  2175. Doo::loadModel ( 'invoicePaper' );
  2176. $invoicePaper = new invoicePaper ();
  2177. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2178. if (empty ( $invoicePrintDetail ))
  2179. die ( 'illegal request' );
  2180. //
  2181. $ipid = $XDeode->decode ( $invoiceNo );
  2182. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2183. if (empty ( $paperDetail ))
  2184. die ( 'illegal request' );
  2185. $invoicePaper = new invoicePaper ();
  2186. $item = array (
  2187. 'iid' => $iid,
  2188. 'ipid' => $ipid
  2189. );
  2190. $invoicePaper->setInvoicePaperByCondition ( $item );
  2191. $item = array (
  2192. 'iid' => $iid,
  2193. 'printStatus' => 1,
  2194. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2195. 'printer' => $this->staff [0] ['username'],
  2196. 'printTime' => date ( "Y-m-d H:i:s" ),
  2197. 'invoiceNo' => $paperDetail ['invoiceNo']
  2198. );
  2199. $invoice->setInvoiceByCondition ( $item );
  2200. $item = array (
  2201. 'date' => date ( "Y-m-d H:i:s" ),
  2202. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2203. 'status' => 5,
  2204. 'img' => $this->staff [0] ['avatar'],
  2205. 'username' => $this->staff [0] ['username'],
  2206. 'uid' => $this->staff [0] ['sid'],
  2207. 'category' => $this->staff [0] ['category'],
  2208. 'iid' => $iid
  2209. );
  2210. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2211. // 去统计--负票不汇总
  2212. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2213. $item = array (
  2214. 'date' => date ( "Y-m-d H:i:s" ),
  2215. 'priceClass' => 1,
  2216. 'cid' => $invoicePrintDetail ['cid'],
  2217. 'staff' => $invoicePrintDetail ['sid'],
  2218. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2219. );
  2220. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2221. }
  2222. // 发送通知信息到微信-去除
  2223. // $this->setWXMsg($iid,'PRINT');
  2224. // 申请人获取微信通知
  2225. Doo::loadModel ( 'staff' );
  2226. $staff = new staff ();
  2227. Doo::loadClass ( 'XDeode' );
  2228. $XDeode = new XDeode ( 5 );
  2229. $username2 = $staff->getOne ( array (
  2230. 'select' => 'wxid',
  2231. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2232. 'asArray' => TRUE
  2233. ) );
  2234. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2235. $msg = '';
  2236. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2237. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2238. if (empty ( $invoicePrintType ))
  2239. return "/invoicePrint";
  2240. else
  2241. return "/invoicePrintStayAchieve";
  2242. }
  2243. }
  2244. /**
  2245. * 需要邮寄的发票
  2246. * @since 1.0.0
  2247. */
  2248. function invoicePost() {
  2249. Doo::loadModel ( 'invoice' );
  2250. $invoice = new invoice ();
  2251. Doo::loadModel ( 'express' );
  2252. $express = new express ();
  2253. $invoicePost = $invoice->getPostByInvoice ();
  2254. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2255. $expressList = $express->getExpressByAll ();
  2256. $invoicePostExpress = "";
  2257. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2258. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2259. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2260. $this->data ['expressList'] = $expressList;
  2261. $this->data ['invoicePost'] = $invoicePost;
  2262. $this->data ['invoicePosted'] = $invoicePosted;
  2263. $this->data ['memu'] = "invoice";
  2264. $this->data ['staff'] = $this->staff;
  2265. $this->data ['receiptMemu'] = 'invoicePost';
  2266. $this->render ( "/admin/invoicePost", $this->data );
  2267. }
  2268. /**
  2269. * 添加发票邮寄信息
  2270. */
  2271. function invoiceExpressAddDo() {
  2272. Doo::loadModel ( 'invoice' );
  2273. $invoice = new invoice ();
  2274. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2275. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2276. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2277. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2278. $iid = $iid = $invoice->authcode ( $iid );
  2279. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2280. die ( 'illegal request' );
  2281. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2282. setcookie ( 'invoicePostExpress', $expressNumber );
  2283. $item = array (
  2284. 'iid' => $iid,
  2285. 'postStatus' => 1,
  2286. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2287. 'postTime' => date ( "Y-m-d H:i:s" ),
  2288. 'expressCompany' => $expressCompany,
  2289. 'expressNumber' => $expressNumber,
  2290. 'actualItems' => $actualItems,
  2291. 'poster' => $this->staff [0] ['username']
  2292. );
  2293. $invoice->setInvoiceByCondition ( $item );
  2294. // 微信通知-去掉
  2295. // $this->setWXMsg ( $iid );
  2296. Doo::loadModel ( 'staff' );
  2297. $staff = new staff ();
  2298. Doo::loadClass ( 'XDeode' );
  2299. $XDeode = new XDeode ( 5 );
  2300. $username2 = $staff->getOne ( array (
  2301. 'select' => 'wxid',
  2302. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2303. 'asArray' => TRUE
  2304. ) );
  2305. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2306. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2307. if (empty ( $expCom ))
  2308. $expCom [0] = '';
  2309. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2310. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2311. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2312. return '/invoicePost';
  2313. }
  2314. function invoiceExpressUpdateDo() {
  2315. Doo::loadModel ( 'invoice' );
  2316. $invoice = new invoice ();
  2317. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2318. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2319. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2320. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2321. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2322. $iid = $invoice->authcode ( $iid );
  2323. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2324. die ( 'illegal request' );
  2325. $item = array (
  2326. 'iid' => $iid,
  2327. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2328. 'expressCompany' => $expressCompany,
  2329. 'expressNumber' => $expressNumber,
  2330. 'actualItems' => $actualItems,
  2331. 'poster' => $this->staff [0] ['username']
  2332. );
  2333. $invoice->setInvoiceByCondition ( $item );
  2334. return $action;
  2335. }
  2336. /**
  2337. * 可退票管理
  2338. */
  2339. function invoiceUntreadIsAchieve() {
  2340. Doo::loadModel ( 'invoice' );
  2341. $invoice = new invoice ();
  2342. Doo::loadClass ( 'XDeode' );
  2343. $XDeode = new XDeode ( 5 );
  2344. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2345. $page_size = 18;
  2346. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2347. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2348. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2349. $dateArr = explode ( ':', $date );
  2350. $D1 = '';
  2351. $D2 = '';
  2352. if (! empty ( $date )) {
  2353. $D1 = $dateArr [0];
  2354. $D2 = $dateArr [1];
  2355. }
  2356. $con = '';
  2357. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2358. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2359. // if ($date == 'MONTHO')
  2360. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2361. // elseif ($date == 'MONTHT')
  2362. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2363. // elseif ($date == 'MONTHY')
  2364. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2365. if (! empty ( $MebSea )) {
  2366. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2367. }
  2368. $pageinfo ['page'] = array (
  2369. 'previous' => ''
  2370. );
  2371. // printStatus=1 and
  2372. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2373. $action = "invoiceUntreadIsAchieve";
  2374. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2375. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2376. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2377. // print_r($list);
  2378. $this->data ['MebSeaEn'] = $MebSea;
  2379. // $this->data ['MebSea'] = urlencode ( $MebSea );
  2380. $this->data ['get'] = $get;
  2381. $this->data ['page'] = $pageinfo;
  2382. $this->data ['date'] = $date;
  2383. $this->data ['list'] = $list;
  2384. $this->data ['memu'] = "invoice";
  2385. $this->data ['staff'] = $this->staff;
  2386. $this->data ['receiptMemu'] = 'invoice';
  2387. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2388. }
  2389. /**
  2390. * 退票处理页面
  2391. */
  2392. function invoiceUntread() {
  2393. Doo::loadModel ( 'invoice' );
  2394. $invoice = new invoice ();
  2395. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 ,0,50);
  2396. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2397. foreach ( $establishedInvoice as $key => $value ) {
  2398. // months
  2399. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2400. $nowDate = strtotime ( 'now' );
  2401. $establishedInvoice [$key] ['lossShow'] = false;
  2402. if ($lossDate < $nowDate)
  2403. $establishedInvoice [$key] ['lossShow'] = true;
  2404. }
  2405. $this->data ['untreadInvoice'] = $untreadInvoice;
  2406. $this->data ['establishedInvoice'] = $establishedInvoice;
  2407. $this->data ['memu'] = "invoice";
  2408. $this->data ['staff'] = $this->staff;
  2409. $this->data ['receiptMemu'] = 'invoiceUntread';
  2410. $this->render ( "/admin/invoiceUntread", $this->data );
  2411. }
  2412. /**
  2413. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2414. */
  2415. function invoiceUntreadEstablishedDo() {
  2416. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2417. Doo::loadModel ( 'invoice' );
  2418. $invoice = new invoice ();
  2419. Doo::loadModel ( 'invoiceOperationLog' );
  2420. $invoiceOperationLog = new invoiceOperationLog ();
  2421. Doo::loadModel ( 'invoiceReceivables' );
  2422. Doo::loadModel ( 'invoiceStatistics' );
  2423. $iid = $invoice->authcode ( $untreadIidKey );
  2424. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2425. die ( 'illegal request' );
  2426. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2427. if ($invoiceDetails ['untreadStatus'] != 1)
  2428. die ( 'illegal request' );
  2429. $item = array (
  2430. 'iid' => $iid,
  2431. // 'irid'=>'',
  2432. 'untreadStatus' => 2,
  2433. 'updateTime' => date ( "Y-m-d H:i:s" )
  2434. );
  2435. $invoice->setInvoiceByCondition ( $item );
  2436. $item = array (
  2437. 'date' => date ( "Y-m-d H:i:s" ),
  2438. 'operation' => '已确认退票',
  2439. 'status' => 6,
  2440. 'img' => $this->staff [0] ['avatar'],
  2441. 'username' => $this->staff [0] ['username'],
  2442. 'uid' => $this->staff [0] ['sid'],
  2443. 'category' => $this->staff [0] ['category'],
  2444. 'iid' => $iid
  2445. );
  2446. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2447. // 收款解绑以及入账扣除 收款扣除
  2448. if (! empty ( $invoiceDetails ['irid'] )) {
  2449. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2450. foreach ( $iridList as $value ) {
  2451. $invoiceReceivables = new invoiceReceivables ();
  2452. $irDetails = $invoiceReceivables->getOne ( array (
  2453. 'where' => " irid=" . $value . ' and bindStatus=1',
  2454. 'asArray' => TRUE
  2455. ) );
  2456. $item = array (
  2457. 'irid' => $value,
  2458. 'bindStatus' => 0,
  2459. 'untreadStatus' => 1,
  2460. 'untreadStaff' => $invoiceDetails ['userName'],
  2461. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2462. 'iid' => 0
  2463. );
  2464. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2465. if (! empty ( $irDetails )) {
  2466. // 扣除入账
  2467. $invoiceStatistics = new invoiceStatistics ();
  2468. $item = array (
  2469. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2470. 'priceClass' => 3,
  2471. 'cid' => $invoiceDetails ['cid'],
  2472. 'staff' => $invoiceDetails ['sid'],
  2473. 'accountPrice' => - $irDetails ['receivablesPrice']
  2474. );
  2475. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2476. // 扣除收款
  2477. $invoiceStatistics = new invoiceStatistics ();
  2478. $item = array (
  2479. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2480. 'priceClass' => 2,
  2481. 'cid' => $invoiceDetails ['cid'],
  2482. 'staff' => $invoiceDetails ['sid'],
  2483. 'irid' => $irDetails ['irid'],
  2484. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2485. );
  2486. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2487. }
  2488. // 解绑时删除收入流水
  2489. Doo::loadModel ( 'wasteBook' );
  2490. $wasteBook = new wasteBook ();
  2491. $wasteBook->delete ( array (
  2492. 'where' => 'dataID=' . $value . ' and accountType=7',
  2493. 'limit' => 1
  2494. ) );
  2495. }
  2496. }
  2497. return "/invoiceUntread";
  2498. }
  2499. /**
  2500. * 建立负票,关联原来发票
  2501. */
  2502. function invoiceLossDo() {
  2503. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2504. if (! empty ( $iidKey )) {
  2505. Doo::loadClass ( 'XDeode' );
  2506. $XDeode = new XDeode ( 5 );
  2507. Doo::loadModel ( 'invoice' );
  2508. $invoice = new invoice ();
  2509. Doo::loadModel ( 'invoiceOperationLog' );
  2510. $invoiceOperationLog = new invoiceOperationLog ();
  2511. $iidKey = $XDeode->decode ( $iidKey );
  2512. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2513. // 拷贝插入一条发票数据
  2514. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2515. // 更新负票
  2516. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2517. $invoice = new invoice ();
  2518. $item = array (
  2519. 'iid' => $iid,
  2520. 'sid' => $this->staff [0] ['sid'],
  2521. 'userName' => $this->staff [0] ['username'],
  2522. 'cid' => $this->staff [0] ['cid'],
  2523. 'categoryName' => $this->staff [0] ['category'],
  2524. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2525. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2526. 'invoiceSerial' => $invoiceSerial,
  2527. 'invoiceNo' => '',
  2528. 'printStatus' => 0,
  2529. 'untreadStatus' => 4,
  2530. // 关联发票号
  2531. 'lossIid' => $invoiceDetail ['iid']
  2532. );
  2533. $invoice->setInvoiceByCondition ( $item );
  2534. // 更新原发票
  2535. $invoice = new invoice ();
  2536. $item = array (
  2537. 'iid' => $invoiceDetail ['iid'],
  2538. 'lossIid' => $iid
  2539. );
  2540. $invoice->setInvoiceByCondition ( $item );
  2541. // 操作日志
  2542. $item = array (
  2543. 'date' => date ( "Y-m-d H:i:s" ),
  2544. 'operation' => "创建负票" . $invoiceSerial,
  2545. 'status' => 12,
  2546. 'img' => $this->staff [0] ['avatar'],
  2547. 'username' => $this->staff [0] ['username'],
  2548. 'uid' => $this->staff [0] ['sid'],
  2549. 'category' => $this->staff [0] ['category'],
  2550. 'iid' => $iid
  2551. );
  2552. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2553. // print_r($invoiceDetail);
  2554. // echo $iid;die;
  2555. }
  2556. return '/invoiceUntread';
  2557. }
  2558. /**
  2559. * 上传银行到账 收款文件
  2560. */
  2561. function invoiceReceivablesBankUpload() {
  2562. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2563. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2564. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2565. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2566. header ( "HTTP/1.1 500 Internal Server Error" );
  2567. echo "POST exceeded maximum allowed size.";
  2568. exit ( 0 );
  2569. }
  2570. // Settings
  2571. $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)
  2572. $upload_name = "Filedata";
  2573. $file_name = "";
  2574. $nk = time ();
  2575. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2576. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2577. echo "文件无法保存.";
  2578. exit ( 0 );
  2579. }
  2580. echo json_encode ( array (
  2581. 'filename' => $file_name,
  2582. 'id' => $nk
  2583. ) );
  2584. exit ( 0 );
  2585. }
  2586. /**
  2587. * 解析银行到账收款execl并导入库中
  2588. */
  2589. function invoiceReceivablesImport() {
  2590. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2591. if ($path != "") {
  2592. Doo::loadModel ( 'invoiceReceivables' );
  2593. $invoiceReceivables = new invoiceReceivables ();
  2594. Doo::loadClass ( 'invoice.func' );
  2595. Doo::loadModel ( 'invoiceROLog' );
  2596. $invoiceROLog = new invoiceROLog ();
  2597. Doo::loadModel ( 'invoiceStatistics' );
  2598. $invoiceStatistics = new invoiceStatistics ();
  2599. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2600. $bankBatchNumber = 'BBN_' . time ();
  2601. Doo::db ()->beginTransaction ();
  2602. // 批量存储收款--由于必须获得收款ID,
  2603. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2604. VALUES ';
  2605. $date = date ( "Y-m-d" );
  2606. $receivablesList = array ();
  2607. foreach ( $exlArray as $key => $value ) {
  2608. $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"] . '")';
  2609. array_push ( $receivablesList, $receivablesSql );
  2610. }
  2611. $sql = $sql . implode ( ',', $receivablesList );
  2612. // echo $sql;
  2613. Doo::db ()->query ( $sql );
  2614. // 批量存储收款统计
  2615. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2616. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2617. // 没有irid 回滚所有操作
  2618. if (empty ( $iridList )) {
  2619. Doo::db ()->rollBack ();
  2620. header ( 'Content-Type:text/html;charset=utf-8' );
  2621. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2622. }
  2623. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2624. VALUES ';
  2625. $statisticsList = array ();
  2626. foreach ( $iridList as $value ) {
  2627. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2628. array_push ( $statisticsList, $statisticsSql );
  2629. }
  2630. $sql = $sql . implode ( ',', $statisticsList );
  2631. Doo::db ()->query ( $sql );
  2632. // 批量存储操作日志
  2633. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2634. VALUES ';
  2635. $ROLogList = array ();
  2636. foreach ( $iridList as $value ) {
  2637. $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'] . '")';
  2638. array_push ( $ROLogList, $ROLogSql );
  2639. }
  2640. $sql = $sql . implode ( ',', $ROLogList );
  2641. Doo::db ()->query ( $sql );
  2642. // 批量写入流水
  2643. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2644. VALUES ';
  2645. $wasteBookList = array ();
  2646. foreach ( $iridList as $value ) {
  2647. $accountBank = '';
  2648. if ($value ['receivablesBank'] == '纵横广发') {
  2649. $accountBank = 'CGBDeposit';
  2650. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2651. $accountBank = 'ICBCDeposit';
  2652. } elseif ($value ['receivablesBank'] == '华润银行') {
  2653. $accountBank = 'HUADeposit';
  2654. } elseif ($value ['receivablesBank'] == '个人广发') {
  2655. $accountBank = 'PersonalDeposit';
  2656. }
  2657. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2658. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2659. array_push ( $wasteBookList, $wasteBookSql );
  2660. }
  2661. $sql = $sql . implode ( ',', $wasteBookList );
  2662. Doo::db ()->query ( $sql );
  2663. Doo::db ()->commit ();
  2664. return "/invoiceReceivables";
  2665. }
  2666. echo 'no file';
  2667. }
  2668. function invoiceReceivables() {
  2669. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2670. Doo::loadModel ( 'L_category' );
  2671. $lCategory = new L_category ();
  2672. Doo::loadModel ( 'staff' );
  2673. $staff = new staff ();
  2674. Doo::loadModel ( 'invoiceReceivables' );
  2675. $invoiceReceivables = new invoiceReceivables ();
  2676. Doo::loadModel ( 'invoice' );
  2677. $invoice = new invoice ();
  2678. Doo::loadClass ( 'XDeode' );
  2679. $XDeode = new XDeode ( 5 );
  2680. $category = $lCategory->getCategory ();
  2681. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2682. $sql = 'bindStatus=1 and iid!=0';
  2683. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2684. // 获取未入账发票
  2685. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2686. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2687. foreach ( $invoiceUnAccount as $key => $value ) {
  2688. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2689. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2690. if (! empty ( $lastApprover )) {
  2691. $lastApproverKey = array_keys ( $lastApprover );
  2692. $lastApprover = end ( $lastApprover );
  2693. $staffDetail = $staff->getOne ( array (
  2694. 'where' => 'sid=' . end ( $lastApproverKey ),
  2695. 'asArray' => true
  2696. ) );
  2697. $lastApprover ['username'] = $staffDetail ['username'];
  2698. }
  2699. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2700. }
  2701. foreach ( $invoiceExistAccount as $key => $value ) {
  2702. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2703. if (empty ( $irList ))
  2704. $irList [0] ['sumPrice'] = 0;
  2705. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2706. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2707. $invoiceExistAccount [$key] ['balance'] = $balance;
  2708. }
  2709. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2710. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2711. $this->data ['halfList'] = $halfList;
  2712. $this->data ['halfCount'] = count ( $halfList );
  2713. // print_r($receivablesList);
  2714. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2715. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2716. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2717. $this->data ['receivablesInput'] = $receivablesInput;
  2718. $this->data ['year'] = date ( 'Y' );
  2719. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2720. $this->data ['receivablesList'] = $receivablesList;
  2721. $this->data ['staffList'] = $staffList;
  2722. $this->data ['category'] = $category;
  2723. $this->data ['memu'] = "invoice";
  2724. $this->data ['staff'] = $this->staff;
  2725. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2726. $this->render ( "/admin/invoiceReceivables", $this->data );
  2727. }
  2728. /**
  2729. * 设置收款认领地区
  2730. */
  2731. function setInvoiceReceivablesClaim() {
  2732. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2733. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2734. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2735. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2736. Doo::loadModel ( 'invoiceReceivables' );
  2737. $invoiceReceivables = new invoiceReceivables ();
  2738. Doo::loadClass ( 'XDeode' );
  2739. $XDeode = new XDeode ( 5 );
  2740. Doo::loadModel ( 'invoiceROLog' );
  2741. $invoiceROLog = new invoiceROLog ();
  2742. $irid = $XDeode->decode ( $iridKey );
  2743. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2744. if (empty ( $irDetail ))
  2745. die ( 'illegal request' );
  2746. $item = array (
  2747. 'irid' => $irid,
  2748. 'receivablesCategory' => $receivablesCategory
  2749. );
  2750. if ($receivablesCategory != 'PUBLIC') {
  2751. $item += array (
  2752. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2753. 'inputType' => 1
  2754. );
  2755. }
  2756. $invoiceReceivables = new invoiceReceivables ();
  2757. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2758. // 收款操作日志
  2759. $item = array (
  2760. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2761. 'date' => date ( "Y-m-d" ),
  2762. 'status' => 1,
  2763. 'img' => $this->staff [0] ['avatar'],
  2764. 'username' => $this->staff [0] ['username'],
  2765. 'uid' => $this->staff [0] ['sid'],
  2766. 'category' => $this->staff [0] ['category'],
  2767. 'irid' => $irid
  2768. );
  2769. $invoiceROLog->setInvoiceROLog ( $item );
  2770. if (empty ( $action ))
  2771. return '/invoiceReceivables';
  2772. else
  2773. return "/invoiceReceivablesAS";
  2774. }
  2775. die ( 'illegal request' );
  2776. }
  2777. /**
  2778. * 新添加收款直接入账发票
  2779. */
  2780. function invoiceCompareClaimPrice() {
  2781. // 收款录入
  2782. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2783. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2784. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2785. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2786. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2787. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2788. Doo::loadModel ( 'invoiceReceivables' );
  2789. $invoiceReceivables = new invoiceReceivables ();
  2790. Doo::loadModel ( 'invoiceROLog' );
  2791. $invoiceROLog = new invoiceROLog ();
  2792. Doo::loadModel ( 'invoiceStatistics' );
  2793. Doo::loadModel ( 'invoice' );
  2794. $invoice = new invoice ();
  2795. Doo::loadClass ( 'XDeode' );
  2796. $XDeode = new XDeode ( 5 );
  2797. Doo::loadModel ( 'invoiceOperationLog' );
  2798. $invoiceOperationLog = new invoiceOperationLog ();
  2799. $iidKey = $XDeode->decode ( $iidKey );
  2800. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2801. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2802. die ( 'illegal request' );
  2803. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2804. // 收款录入 并绑定发票
  2805. Doo::db ()->beginTransaction ();
  2806. $bindStatus = 0;
  2807. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2808. $bindStatus = 1;
  2809. $titleMark = $invoiceDetail ['invoiceTitle'];
  2810. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  2811. $titleMark = $invoiceDetail ['invoiceCompany'];
  2812. $item = array (
  2813. 'recepitTitleMark' => $titleMark,
  2814. 'bindStatus' => $bindStatus,
  2815. 'iid' => $invoiceDetail ['iid'],
  2816. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2817. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2818. 'receivablesPrice' => $receivablesPrice,
  2819. 'OriginalPrice' => $receivablesPrice,
  2820. 'receivablesMessage' => $receivablesMessage,
  2821. 'receivablesSerial' => $receivablesSerial,
  2822. 'receivablesBank' => $receivablesBank,
  2823. 'receivablesDate' => $receivablesDate,
  2824. 'inputStaff' => $this->staff [0] ['username'],
  2825. 'accountClerk' => $this->staff [0] ['username'],
  2826. 'date' => date ( "Y-m-d" ),
  2827. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2828. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2829. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2830. );
  2831. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2832. $item = array ();
  2833. // 收款操作日志
  2834. $item = array (
  2835. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2836. );
  2837. $item += array (
  2838. 'date' => date ( "Y-m-d" ),
  2839. 'status' => 1,
  2840. 'img' => $this->staff [0] ['avatar'],
  2841. 'username' => $this->staff [0] ['username'],
  2842. 'uid' => $this->staff [0] ['sid'],
  2843. 'category' => $this->staff [0] ['category'],
  2844. 'irid' => $irid
  2845. );
  2846. $invoiceROLog->setInvoiceROLog ( $item );
  2847. // 收款统计
  2848. $invoiceStatistics = new invoiceStatistics ();
  2849. $item = array (
  2850. 'date' => $receivablesDate,
  2851. 'priceClass' => 2,
  2852. 'irid' => $irid,
  2853. 'cid' => $invoiceDetail ['cid'],
  2854. 'staff' => $invoiceDetail ['sid'],
  2855. 'receivablesPrice' => $receivablesPrice
  2856. );
  2857. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2858. // 收款 入 发票
  2859. $detail = $invoiceDetail;
  2860. $iridString = "";
  2861. if (empty ( $detail ['irid'] ))
  2862. $iridString = $irid;
  2863. else
  2864. $iridString = $detail ['irid'] . ',' . $irid;
  2865. $item = array (
  2866. 'irid' => $iridString,
  2867. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2868. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2869. 'iid' => $detail ['iid']
  2870. );
  2871. $invoiceReceivables = new invoiceReceivables ();
  2872. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2873. if ($detail ['invoicePrice'] <= $sum)
  2874. $item += array (
  2875. 'untreadStatus' => 3
  2876. );
  2877. $invoice->setInvoiceByCondition ( $item );
  2878. // 操作日志
  2879. $item = array (
  2880. 'date' => date ( "Y-m-d H:i:s" ),
  2881. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  2882. 'status' => 8,
  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. 'iid' => $detail ['iid']
  2888. );
  2889. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2890. // 入账汇总
  2891. $invoiceStatistics = new invoiceStatistics ();
  2892. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  2893. // $accountPrice = 0;
  2894. // foreach ( $list as $key => $value ) {
  2895. // $accountPrice += $value ['receivablesPrice'];
  2896. // }
  2897. $item = array (
  2898. 'date' => $receivablesDate,
  2899. 'priceClass' => 3,
  2900. 'cid' => $invoiceDetail ['cid'],
  2901. 'staff' => $invoiceDetail ['sid'],
  2902. 'accountPrice' => $receivablesPrice
  2903. );
  2904. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2905. // 公司流水记录
  2906. Doo::loadModel ( 'wasteBook' );
  2907. $wasteBook = new wasteBook ();
  2908. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  2909. $accountBank = '';
  2910. if ($receivablesBank == '纵横广发') {
  2911. $accountBank = 'CGBDeposit';
  2912. } elseif ($receivablesBank == '纵横工行') {
  2913. $accountBank = 'ICBCDeposit';
  2914. } elseif ($receivablesBank == '华润银行') {
  2915. $accountBank = 'HUADeposit';
  2916. } elseif ($receivablesBank == '个人广发') {
  2917. $accountBank = 'PersonalDeposit';
  2918. }
  2919. if (empty ( $abDetail )) {
  2920. $item = array (
  2921. 'dataID' => $irid,
  2922. 'expensesType' => 1,
  2923. 'accountType' => 7,
  2924. 'accountPrice' => $receivablesPrice,
  2925. 'accountPriceShow' => $receivablesPrice,
  2926. 'accountBank' => $accountBank,
  2927. 'category' => $this->staff [0] ['category'],
  2928. 'cid' => $this->staff [0] ['cid'],
  2929. 'name' => $this->staff [0] ['username'],
  2930. 'sid' => $this->staff [0] ['sid'],
  2931. 'inputDate' => date ( "Y-m-d H:i:s" )
  2932. );
  2933. $wasteBook->setAccountBookStatistics ( $item );
  2934. }
  2935. Doo::db ()->commit ();
  2936. }
  2937. return '/invoiceReceivables';
  2938. }
  2939. /**
  2940. * 录入收款数据
  2941. * @return string
  2942. */
  2943. function invoiceReceivablesDo() {
  2944. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2945. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2946. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2947. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2948. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2949. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2950. Doo::loadModel ( 'invoiceReceivables' );
  2951. $invoiceReceivables = new invoiceReceivables ();
  2952. Doo::loadModel ( 'invoiceROLog' );
  2953. $invoiceROLog = new invoiceROLog ();
  2954. Doo::loadModel ( 'invoiceStatistics' );
  2955. $invoiceStatistics = new invoiceStatistics ();
  2956. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  2957. $item = array (
  2958. 'receivablesPrice' => $receivablesPrice,
  2959. 'OriginalPrice' => $receivablesPrice,
  2960. 'receivablesMessage' => $receivablesMessage,
  2961. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  2962. 'receivablesBank' => $receivablesBank,
  2963. 'receivablesDate' => $receivablesDate,
  2964. 'inputStaff' => $this->staff [0] ['username'],
  2965. 'date' => date ( "Y-m-d" ),
  2966. 'receivablesCategory' => $receivablesCategory,
  2967. 'receivablesStaff' => $receivablesStaff
  2968. );
  2969. if ($receivablesCategory != 'PUBLIC') {
  2970. $item += array (
  2971. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2972. 'inputType' => 1
  2973. );
  2974. }
  2975. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2976. $item = array ();
  2977. // 收款操作日志
  2978. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2979. $item = array (
  2980. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2981. );
  2982. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2983. $item = array (
  2984. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2985. );
  2986. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2987. $receivablesStaff = explode ( '-', $receivablesStaff );
  2988. $item = array (
  2989. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2990. );
  2991. }
  2992. $item += array (
  2993. 'date' => date ( "Y-m-d" ),
  2994. 'status' => 1,
  2995. 'img' => $this->staff [0] ['avatar'],
  2996. 'username' => $this->staff [0] ['username'],
  2997. 'uid' => $this->staff [0] ['sid'],
  2998. 'category' => $this->staff [0] ['category'],
  2999. 'irid' => $irid
  3000. );
  3001. $invoiceROLog->setInvoiceROLog ( $item );
  3002. $item = array (
  3003. 'date' => $receivablesDate,
  3004. 'priceClass' => 2,
  3005. 'irid' => $irid,
  3006. 'receivablesPrice' => $receivablesPrice
  3007. );
  3008. if ($receivablesCategory != 'PUBLIC') {
  3009. $receivablesCategory = explode ( ":", $receivablesCategory );
  3010. $item += array (
  3011. 'cid' => $receivablesCategory [0]
  3012. );
  3013. }
  3014. if ($receivablesStaff2 != 'PUBLIC') {
  3015. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3016. $item += array (
  3017. 'staff' => $receivablesStaff [0]
  3018. );
  3019. }
  3020. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3021. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3022. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3023. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3024. if ($toparty != 0)
  3025. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3026. // 公司流水记录
  3027. Doo::loadModel ( 'wasteBook' );
  3028. $wasteBook = new wasteBook ();
  3029. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3030. $accountBank = '';
  3031. if ($receivablesBank == '纵横广发') {
  3032. $accountBank = 'CGBDeposit';
  3033. } elseif ($receivablesBank == '纵横工行') {
  3034. $accountBank = 'ICBCDeposit';
  3035. } elseif ($receivablesBank == '华润银行') {
  3036. $accountBank = 'HUADeposit';
  3037. } elseif ($receivablesBank == '个人广发') {
  3038. $accountBank = 'PersonalDeposit';
  3039. }
  3040. $item = array (
  3041. 'dataID' => $irid,
  3042. 'expensesType' => 1,
  3043. 'accountType' => 7,
  3044. 'accountPriceShow' => $receivablesPrice,
  3045. 'accountPrice' => $receivablesPrice,
  3046. 'accountBank' => $accountBank,
  3047. 'category' => $this->staff [0] ['category'],
  3048. 'cid' => $this->staff [0] ['cid'],
  3049. 'name' => $this->staff [0] ['username'],
  3050. 'sid' => $this->staff [0] ['sid'],
  3051. 'inputDate' => date ( "Y-m-d H:i:s" )
  3052. );
  3053. $wasteBook->setAccountBookStatistics ( $item );
  3054. }
  3055. return "/invoiceReceivables";
  3056. }
  3057. /**
  3058. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3059. */
  3060. function invoiceReceivablesClaim() {
  3061. Doo::loadModel ( 'invoiceReceivables' );
  3062. $invoiceReceivables = new invoiceReceivables ();
  3063. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3064. $this->data ['receivablesList'] = $receivablesList;
  3065. $this->data ['memu'] = "invoice";
  3066. $this->data ['staff'] = $this->staff;
  3067. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3068. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3069. }
  3070. function invoiceReceivablesTitleMarkSet() {
  3071. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3072. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3073. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3074. die ( 'illegal request' );
  3075. Doo::loadModel ( 'invoiceReceivables' );
  3076. $invoiceReceivables = new invoiceReceivables ();
  3077. Doo::loadClass ( 'XDeode' );
  3078. $XDeode = new XDeode ( 5 );
  3079. $irid = $XDeode->decode ( $iridKey );
  3080. if (! is_numeric ( $irid ))
  3081. die ( 'illegal request' );
  3082. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3083. $invoiceReceivables->update ( array (
  3084. 'where' => 'irid = ' . $irid
  3085. ) );
  3086. return '/invoiceReceivablesClaim';
  3087. }
  3088. /**
  3089. * 更新收款相关数据
  3090. */
  3091. function invoiceReceivablesUpdateClaim() {
  3092. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3093. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3094. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3095. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3096. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3097. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3098. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3099. if (empty ( $claimKey ))
  3100. die ( 'illegal request' );
  3101. Doo::loadModel ( 'invoiceReceivables' );
  3102. $invoiceReceivables = new invoiceReceivables ();
  3103. Doo::loadModel ( 'invoiceROLog' );
  3104. $invoiceROLog = new invoiceROLog ();
  3105. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3106. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3107. if (empty ( $detail ))
  3108. die ( 'illegal request' );
  3109. $invoiceReceivables = new invoiceReceivables ();
  3110. $item = array (
  3111. 'irid' => $detail ['irid']
  3112. );
  3113. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3114. $item += array (
  3115. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3116. );
  3117. }
  3118. if (! empty ( $receivablesCategory ))
  3119. $item += array (
  3120. 'receivablesCategory' => $receivablesCategory
  3121. );
  3122. if (! empty ( $receivablesStaff ))
  3123. $item += array (
  3124. 'receivablesStaff' => $receivablesStaff
  3125. );
  3126. if (! empty ( $receivablesPrice ))
  3127. $item += array (
  3128. 'receivablesPrice' => $receivablesPrice
  3129. );
  3130. if (! empty ( $receivablesMessage ))
  3131. $item += array (
  3132. 'receivablesMessage' => $receivablesMessage
  3133. );
  3134. if (! empty ( $receivablesBank ))
  3135. $item += array (
  3136. 'receivablesBank' => $receivablesBank
  3137. );
  3138. if (! empty ( $receivablesDate ))
  3139. $item += array (
  3140. 'receivablesDate' => $receivablesDate
  3141. );
  3142. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3143. // 收款操作日志
  3144. $item = array ();
  3145. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3146. $item = array (
  3147. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3148. );
  3149. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3150. $item = array (
  3151. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3152. );
  3153. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3154. $receivablesStaff = explode ( '-', $receivablesStaff );
  3155. $item = array (
  3156. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3157. );
  3158. }
  3159. $item += array (
  3160. 'date' => date ( "Y-m-d" ),
  3161. 'status' => 1,
  3162. 'img' => $this->staff [0] ['avatar'],
  3163. 'username' => $this->staff [0] ['username'],
  3164. 'uid' => $this->staff [0] ['sid'],
  3165. 'category' => $this->staff [0] ['category'],
  3166. 'irid' => $detail ['irid']
  3167. );
  3168. $invoiceROLog->setInvoiceROLog ( $item );
  3169. return '/invoiceReceivablesAS';
  3170. }
  3171. function invoiceReceivablesDelete() {
  3172. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3173. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3174. if ($skll != '删除到款')
  3175. die ( 'illegal request' );
  3176. if (empty ( $claimKey ))
  3177. die ( 'illegal request' );
  3178. Doo::loadModel ( 'invoiceReceivables' );
  3179. $invoiceReceivables = new invoiceReceivables ();
  3180. $con = ' and bindStatus=0 ';
  3181. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3182. if (empty ( $detail ))
  3183. die ( 'illegal request' );
  3184. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3185. // 扣除收款汇总信息 汇总
  3186. Doo::loadModel ( 'invoiceStatistics' );
  3187. $invoiceStatistics = new invoiceStatistics ();
  3188. $item = array (
  3189. 'date' => $detail ['receivablesDate'],
  3190. 'priceClass' => 2,
  3191. 'irid' => $detail ['irid'],
  3192. 'receivablesPrice' => - $detail ['receivablesPrice']
  3193. );
  3194. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3195. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3196. $item += array (
  3197. 'cid' => $receivablesCategory [0]
  3198. );
  3199. }
  3200. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3201. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3202. $item += array (
  3203. 'staff' => $receivablesStaff [0]
  3204. );
  3205. }
  3206. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3207. // 公司流水-删除时删除流水
  3208. Doo::loadModel ( 'wasteBook' );
  3209. $wasteBook = new wasteBook ();
  3210. $wasteBook->delete ( array (
  3211. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3212. 'limit' => 1
  3213. ) );
  3214. return '/invoiceReceivablesAS';
  3215. }
  3216. /**
  3217. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3218. */
  3219. function invoiceReceivablesAscription() {
  3220. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3221. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3222. Doo::loadModel ( 'invoiceReceivables' );
  3223. $invoiceReceivables = new invoiceReceivables ();
  3224. Doo::loadModel ( 'invoiceROLog' );
  3225. $invoiceROLog = new invoiceROLog ();
  3226. Doo::loadModel ( 'invoiceStatistics' );
  3227. $invoiceStatistics = new invoiceStatistics ();
  3228. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3229. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3230. $item = array (
  3231. 'irid' => $detail ['irid'],
  3232. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3233. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3234. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3235. 'recepitTitleMark' => $recepitTitleMark,
  3236. 'source' => 1
  3237. );
  3238. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3239. $item = array (
  3240. 'date' => date ( "Y-m-d" ),
  3241. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3242. 'status' => 2,
  3243. 'img' => $this->staff [0] ['avatar'],
  3244. 'username' => $this->staff [0] ['username'],
  3245. 'uid' => $this->staff [0] ['sid'],
  3246. 'category' => $this->staff [0] ['category'],
  3247. 'irid' => $irid
  3248. );
  3249. $invoiceROLog->setInvoiceROLog ( $item );
  3250. $item = array (
  3251. 'cid' => $this->staff [0] ['cid'],
  3252. 'staff' => $this->staff [0] ['sid']
  3253. );
  3254. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3255. }
  3256. return "/invoiceReceivablesClaim";
  3257. }
  3258. /**
  3259. */
  3260. function invoiceMyReceivables() {
  3261. Doo::loadModel ( 'invoiceReceivables' );
  3262. $invoiceReceivables = new invoiceReceivables ();
  3263. Doo::loadModel ( 'invoiceStatistics' );
  3264. $invoiceStatistics = new invoiceStatistics ();
  3265. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3266. $year = date ( "Y" );
  3267. $tmp_date = date ( "Ym" );
  3268. $tmp_year = substr ( $tmp_date, 0, 4 );
  3269. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3270. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3271. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3272. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3273. $htm = $this->showCache ( $path );
  3274. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3275. $this->data ['isMonth'] = $isMonth;
  3276. $this->data ['htm'] = $htm;
  3277. $this->data ['list'] = $list;
  3278. $this->data ['memu'] = "invoice";
  3279. $this->data ['staff'] = $this->staff;
  3280. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3281. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3282. }
  3283. /**
  3284. * 纸票管理
  3285. */
  3286. function invoicePaper() {
  3287. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3288. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3289. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3290. $this->data ['dateString'] = $date;
  3291. $this->data ['status'] = $status;
  3292. $this->data ['invoiceType'] = $invoiceType;
  3293. $this->data ['memu'] = "invoice";
  3294. $this->data ['staff'] = $this->staff;
  3295. $this->data ['receiptMemu'] = 'invoicePaper';
  3296. $this->render ( "/admin/invoicePaper", $this->data );
  3297. }
  3298. /**
  3299. * 获得纸票分页数据
  3300. */
  3301. function ajaxGetinvoicePaperAchieve() {
  3302. Doo::loadModel ( 'invoicePaper' );
  3303. $invoicePaper = new invoicePaper ();
  3304. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3305. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3306. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3307. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3308. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3309. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3310. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3311. $MebSea = $this->get_args ( 'search' );
  3312. $MebSea = $MebSea ['value'];
  3313. $page_size = $length;
  3314. $con = '';
  3315. if ($status == 'ALL')
  3316. $con = ' where 1 ';
  3317. elseif ($status == 'PRINTED')
  3318. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3319. elseif ($status == 'UNPRINT')
  3320. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3321. elseif ($status == 'TICKET')
  3322. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3323. if ($invoiceType == 'ORDINARY')
  3324. $con .= ' and a.invoiceType=0 ';
  3325. elseif ($invoiceType == 'SPECIAL')
  3326. $con .= ' and a.invoiceType=1 ';
  3327. $dateArr = explode ( ':', $date );
  3328. $D1 = $dateString = '';
  3329. $D2 = '';
  3330. if (! empty ( $date )) {
  3331. $D1 = $dateArr [0];
  3332. if (isset ( $dateArr [1] ))
  3333. $D2 = $dateArr [1];
  3334. else
  3335. $D2 = '';
  3336. $dateString = $D1 . " : " . $D2;
  3337. }
  3338. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3339. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3340. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3341. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3342. if (! empty ( $MebSea ))
  3343. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3344. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3345. $sql = ' ' . $con;
  3346. $limit = $page . ',' . $page_size;
  3347. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3348. $paperList = array ();
  3349. foreach ( $list as $key => $value ) {
  3350. $irDetail = array ();
  3351. if ($value ['iid'] == 0)
  3352. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3353. else
  3354. array_push ( $irDetail, '' );
  3355. array_push ( $irDetail, $value ['invoiceCode'] );
  3356. array_push ( $irDetail, $value ['invoiceNo'] );
  3357. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3358. if ($value ['invoiceType'] == 1)
  3359. array_push ( $irDetail, $value ['invoiceCompany'] );
  3360. else
  3361. array_push ( $irDetail, $value ['invoiceTitle'] );
  3362. if ($value ['invoiceType'] == 1)
  3363. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3364. else
  3365. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3366. array_push ( $irDetail, $value ['invoiceElement'] );
  3367. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3368. array_push ( $irDetail, $value ['printTime'] );
  3369. array_push ( $paperList, $irDetail );
  3370. }
  3371. // $approvalListJson = json_encode ( $approvalList );
  3372. $recordsFiltered = $invoiceTotal;
  3373. echo json_encode ( array (
  3374. "draw" => intval ( $draw ),
  3375. "recordsTotal" => intval ( $invoiceTotal ),
  3376. "recordsFiltered" => intval ( $recordsFiltered ),
  3377. "data" => $paperList
  3378. ), JSON_UNESCAPED_UNICODE );
  3379. }
  3380. function invoicePaperDel() {
  3381. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3382. $XDeode = new XDeode ( 5 );
  3383. $ipid = $XDeode->decode ( $ipidKey );
  3384. if (empty ( $ipid ))
  3385. die ( 'illegal request' );
  3386. Doo::loadModel ( 'invoicePaper' );
  3387. $invoicePaper = new invoicePaper ();
  3388. $invoicePaper->delete ( array (
  3389. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3390. 'limit' => 1
  3391. ) );
  3392. return '/invoicePaper';
  3393. }
  3394. /**
  3395. * 添加纸质发票号
  3396. */
  3397. function invoicePaperAdd() {
  3398. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3399. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3400. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3401. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3402. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3403. $sum = $invoiceNoStart + $invoiceNoTotal;
  3404. if (empty ( $sum ))
  3405. die ( 'illegal request' );
  3406. // echo $invoiceNoStart;
  3407. // echo $sum;
  3408. // echo strlen((int)$invoiceNoStart);
  3409. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3410. Doo::db ()->beginTransaction ();
  3411. // 批量存储纸质发票
  3412. $date = date ( "Y-m-d H:i:s" );
  3413. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3414. VALUES ';
  3415. $paperList = array ();
  3416. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3417. // 数字前面自加0
  3418. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3419. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3420. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3421. array_push ( $paperList, $paperSql );
  3422. }
  3423. if (empty ( $paperList ))
  3424. die ( 'illegal request' );
  3425. $sql = $sql . implode ( ',', $paperList );
  3426. Doo::db ()->query ( $sql );
  3427. Doo::db ()->commit ();
  3428. return 'invoicePaper';
  3429. }
  3430. die ( 'illegal request' );
  3431. }
  3432. /**
  3433. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3434. */
  3435. function invoiceBindReceivables() {
  3436. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3437. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3438. Doo::loadModel ( 'invoice' );
  3439. $invoice = new invoice ();
  3440. Doo::loadModel ( 'invoiceReceivables' );
  3441. $invoiceReceivables = new invoiceReceivables ();
  3442. Doo::loadModel ( 'invoiceOperationLog' );
  3443. $invoiceOperationLog = new invoiceOperationLog ();
  3444. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3445. die ( 'illegal request' );
  3446. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3447. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3448. if (empty ( $detail ) && empty ( $detailM ))
  3449. die ( 'illegal request' );
  3450. if ($detail ['untreadStatus'] == 3)
  3451. die ( 'illegal request' );
  3452. // 修改 绑定状态改为 金额
  3453. $invoiceReceivables = new invoiceReceivables ();
  3454. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3455. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3456. $item = array (
  3457. 'bindPrice' => $invoicePrice
  3458. );
  3459. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3460. $item = array (
  3461. 'bindPrice' => $invoicePrice,
  3462. 'bindStatus' => 1,
  3463. 'bindDate' => date ( "Y-m-d H:i:s" )
  3464. );
  3465. } else {
  3466. die ( 'illegal request' );
  3467. }
  3468. if ($detailM ['iid'] == 0) {
  3469. $item += array (
  3470. 'iid' => $detail ['iid']
  3471. );
  3472. } else {
  3473. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3474. array_push ( $iidExtend, $detail ['iid'] );
  3475. $item += array (
  3476. 'iidExtend' => implode ( ',', $iidExtend )
  3477. );
  3478. }
  3479. $titleMark = $detail ['invoiceTitle'];
  3480. if (! empty ( $detail ['invoiceCompany'] ))
  3481. $titleMark = $detail ['invoiceCompany'];
  3482. $item += array (
  3483. 'irid' => $detailM ['irid'],
  3484. 'recepitTitleMark' => $titleMark,
  3485. 'accountClerk' => $this->staff [0] ['username']
  3486. );
  3487. // 如何没有人收款 则自动绑定收款
  3488. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3489. $item += array (
  3490. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3491. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3492. );
  3493. }
  3494. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3495. $iridString = "";
  3496. if (empty ( $detail ['irid'] ))
  3497. $iridString = $detailM ['irid'];
  3498. else
  3499. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3500. $item = array (
  3501. 'iid' => $detail ['iid'],
  3502. 'irid' => $iridString
  3503. );
  3504. $invoiceReceivables = new invoiceReceivables ();
  3505. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3506. if ($detail ['invoicePrice'] <= $sum)
  3507. $item += array (
  3508. 'untreadStatus' => 3,
  3509. 'bindTime' => date ( "Y-m-d H:i:s" )
  3510. );
  3511. // print_r($item);
  3512. // echo $sum;die;
  3513. $invoice->setInvoiceByCondition ( $item );
  3514. // 操作日志
  3515. $item = array (
  3516. 'date' => date ( "Y-m-d H:i:s" ),
  3517. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3518. 'status' => 8,
  3519. 'img' => $this->staff [0] ['avatar'],
  3520. 'username' => $this->staff [0] ['username'],
  3521. 'uid' => $this->staff [0] ['sid'],
  3522. 'category' => $this->staff [0] ['category'],
  3523. 'iid' => $detail ['iid']
  3524. );
  3525. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3526. Doo::loadModel ( 'invoiceStatistics' );
  3527. $invoiceStatistics = new invoiceStatistics ();
  3528. $item = array (
  3529. 'date' => $detailM ['receivablesDate'],
  3530. 'priceClass' => 3,
  3531. 'cid' => $detail ['cid'],
  3532. 'staff' => $detail ['sid'],
  3533. 'accountPrice' => $detailM ['receivablesPrice']
  3534. );
  3535. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3536. // 公司流水记录
  3537. // Doo::loadModel ( 'wasteBook' );
  3538. // $wasteBook = new wasteBook ();
  3539. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3540. // $accountBank='';
  3541. // if ($detailM ['receivablesBank']=='纵横广发'){
  3542. // $accountBank='CGBDeposit';
  3543. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3544. // $accountBank='ICBCDeposit';
  3545. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3546. // $accountBank='HUADeposit';
  3547. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3548. // $accountBank='PersonalDeposit';
  3549. // }
  3550. // if (empty($abDetail)){
  3551. // $item = array (
  3552. // 'dataID' => $detail ['iid'],
  3553. // 'expensesType' => 1,
  3554. // 'accountType' => 8,
  3555. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3556. // 'accountPrice'=>$detail ['invoicePrice'],
  3557. // 'accountBank'=>$accountBank,
  3558. // 'category'=>$this->staff[0]['category'],
  3559. // 'cid'=>$this->staff[0]['cid'],
  3560. // 'name'=>$this->staff[0]['username'],
  3561. // 'sid'=>$this->staff[0]['sid'],
  3562. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3563. // );
  3564. // $wasteBook->setAccountBookStatistics($item);
  3565. // }
  3566. return "/invoiceReceivables";
  3567. }
  3568. /**
  3569. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3570. */
  3571. function invoiceAggregate() {
  3572. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3573. Doo::loadModel ( 'invoiceStatistics' );
  3574. $invoiceStatistics = new invoiceStatistics ();
  3575. Doo::loadModel ( 'L_category' );
  3576. $Lcategory = new L_category ();
  3577. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3578. $LcategoryList = $Lcategory->getCategory ();
  3579. // print_r($isList);
  3580. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3581. foreach ( $LcategoryList as $key => $value ) {
  3582. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3583. $month = 1;
  3584. $invoicePriceYear = 0;
  3585. $receivablesPriceYear = 0;
  3586. $accountPriceYear = 0;
  3587. for(; $month <= 12; $month ++) {
  3588. $flag = true;
  3589. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3590. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3591. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3592. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3593. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3594. ';
  3595. $invoicePriceYear += $v ['invoicePrice'];
  3596. $receivablesPriceYear += $v ['receivablesPrice'];
  3597. $accountPriceYear += $v ['accountPrice'];
  3598. $flag = false;
  3599. break;
  3600. }
  3601. }
  3602. if ($flag)
  3603. $html .= '<td class="taR"></td>
  3604. <td class="taR"></td>
  3605. <td class="taR"><b></b></td>
  3606. ';
  3607. }
  3608. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3609. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3610. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3611. ';
  3612. $html .= '</tr>';
  3613. }
  3614. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3615. $invoicePriceYear = 0;
  3616. $receivablesPriceYear = 0;
  3617. $accountPriceYear = 0;
  3618. for($month = 1; $month <= 12; $month ++) {
  3619. $flag = true;
  3620. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3621. if ($month == $v ['month']) {
  3622. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3623. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3624. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3625. ';
  3626. $invoicePriceYear += $v ['invoicePrice'];
  3627. $receivablesPriceYear += $v ['receivablesPrice'];
  3628. $accountPriceYear += $v ['accountPrice'];
  3629. $flag = false;
  3630. break;
  3631. }
  3632. }
  3633. if ($flag) {
  3634. $html .= '<td class="taR"></td>
  3635. <td class="taR"></td>
  3636. <td class="taR"><b></b></td>
  3637. ';
  3638. }
  3639. }
  3640. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3641. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3642. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3643. ';
  3644. $html .= '</tr>';
  3645. // print_r($isList);
  3646. $this->data ['html'] = $html;
  3647. $this->data ['LcategoryList'] = $LcategoryList;
  3648. $this->data ['isList'] = $isList;
  3649. $this->data ['year'] = $year;
  3650. $this->data ['memu'] = "invoice";
  3651. $this->data ['staff'] = $this->staff;
  3652. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3653. $this->render ( "/admin/invoiceAggregate", $this->data );
  3654. }
  3655. function invoiceAggregateStaff() {
  3656. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3657. Doo::loadModel ( 'invoiceStatistics' );
  3658. $invoiceStatistics = new invoiceStatistics ();
  3659. Doo::loadModel ( 'L_category' );
  3660. $Lcategory = new L_category ();
  3661. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3662. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3663. $cStaff = $Lcategory->getCategoryStaff ();
  3664. $html = '';
  3665. foreach ( $cStaff as $key => $value ) {
  3666. $categoryFir = true;
  3667. foreach ( $value ['staff'] as $k => $v ) {
  3668. if ($categoryFir) {
  3669. $width = count ( $value ['staff'] ) + 1;
  3670. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3671. $categoryFir = false;
  3672. } else
  3673. $html .= '<tr>';
  3674. $html .= '<th>' . $v ['username'] . '</th>';
  3675. $invoicePriceStaffYear = 0;
  3676. $receivablesPriceStaffYear = 0;
  3677. $accountPriceStaffYear = 0;
  3678. for($month = 1; $month <= 12; $month ++) {
  3679. $flag = true;
  3680. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3681. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3682. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3683. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3684. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3685. ';
  3686. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3687. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3688. $accountPriceStaffYear += $slv ['accountPrice'];
  3689. $flag = false;
  3690. break;
  3691. }
  3692. }
  3693. if ($flag)
  3694. $html .= '<td class="taR"></td>
  3695. <td class="taR"></td>
  3696. <td class="taR"><b></b></td>
  3697. ';
  3698. }
  3699. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3700. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3701. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3702. ';
  3703. }
  3704. $html .= '</tr>';
  3705. // 小计
  3706. if (! empty ( $value ['staff'] )) {
  3707. $html .= '<tr><th class="taR">小计</th>';
  3708. $invoicePriceStaffYear = 0;
  3709. $receivablesPriceStaffYear = 0;
  3710. $accountPriceStaffYear = 0;
  3711. for($month = 1; $month <= 12; $month ++) {
  3712. $flag = true;
  3713. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3714. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3715. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3716. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3717. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3718. ';
  3719. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3720. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3721. $accountPriceStaffYear += $slv ['accountPrice'];
  3722. $flag = false;
  3723. break;
  3724. }
  3725. }
  3726. if ($flag)
  3727. $html .= '<td class="taR"></td>
  3728. <td class="taR"></td>
  3729. <td class="taR"><b></b></td>
  3730. ';
  3731. }
  3732. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3733. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3734. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3735. ';
  3736. $html .= '</tr>';
  3737. }
  3738. }
  3739. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3740. $invoicePriceYear = 0;
  3741. $receivablesPriceYear = 0;
  3742. $accountPriceYear = 0;
  3743. for($month = 1; $month <= 12; $month ++) {
  3744. $flag = true;
  3745. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3746. if ($month == $v ['month']) {
  3747. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3748. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3749. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3750. ';
  3751. $invoicePriceYear += $v ['invoicePrice'];
  3752. $receivablesPriceYear += $v ['receivablesPrice'];
  3753. $accountPriceYear += $v ['accountPrice'];
  3754. $flag = false;
  3755. break;
  3756. }
  3757. }
  3758. if ($flag)
  3759. $html .= '<td class="taR"></td>
  3760. <td class="taR"></td>
  3761. <td class="taR"><b></b></td>
  3762. ';
  3763. }
  3764. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3765. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3766. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3767. ';
  3768. $html .= '</tr>';
  3769. $this->data ['html'] = $html;
  3770. $this->data ['isList'] = $toteList;
  3771. $this->data ['year'] = $year;
  3772. $this->data ['memu'] = "invoice";
  3773. $this->data ['staff'] = $this->staff;
  3774. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3775. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3776. }
  3777. function invoiceAggregateCategory() {
  3778. Doo::loadClass ( 'XDeode' );
  3779. $XDeode = new XDeode ( 5 );
  3780. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3781. $cid = $XDeode->decode ( $cid );
  3782. if (! is_numeric ( $cid ))
  3783. die ( 'illegal request' );
  3784. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3785. Doo::loadModel ( 'invoiceStatistics' );
  3786. $invoiceStatistics = new invoiceStatistics ();
  3787. Doo::loadModel ( 'staff' );
  3788. $staff = new staff ();
  3789. $list = $staff->getStaffByCid ( $cid );
  3790. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3791. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3792. if (empty ( $list ))
  3793. die ( '该办事处没有成员' );
  3794. $htmlA = $htmlB = $htmlC = $html = '';
  3795. foreach ( $list as $key => $value ) {
  3796. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3797. $htmlB = '<tr><th class="taC">收款</th>';
  3798. $htmlC = '<tr><th class="taC">入账</th>';
  3799. $invoicePriceStaffYear = 0;
  3800. $receivablesPriceStaffYear = 0;
  3801. $accountPriceStaffYear = 0;
  3802. for($month = 1; $month <= 12; $month ++) {
  3803. $flag = true;
  3804. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3805. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3806. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3807. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3808. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3809. $invoicePriceStaffYear += $v ['invoicePrice'];
  3810. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3811. $accountPriceStaffYear += $v ['accountPrice'];
  3812. $flag = false;
  3813. break;
  3814. }
  3815. }
  3816. if ($flag) {
  3817. $htmlA .= '<td class="taR">-</td>';
  3818. $htmlB .= '<td class="taR">-</td>';
  3819. $htmlC .= '<td class="taR"><b>-</b></td>';
  3820. }
  3821. }
  3822. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3823. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3824. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3825. $htmlA .= '</tr>';
  3826. $htmlB .= '</tr>';
  3827. $htmlC .= '</tr>';
  3828. $html .= $htmlA . $htmlB . $htmlC;
  3829. }
  3830. $htmlA = $htmlB = $htmlC = "";
  3831. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3832. $htmlB = '<tr><th class="taC">收款</th>';
  3833. $htmlC = '<tr><th class="taC">入账</th>';
  3834. $invoicePriceStaffYear = 0;
  3835. $receivablesPriceStaffYear = 0;
  3836. $accountPriceStaffYear = 0;
  3837. for($month = 1; $month <= 12; $month ++) {
  3838. $flag = true;
  3839. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3840. if ($month == $v ['month']) {
  3841. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3842. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3843. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3844. $invoicePriceStaffYear += $v ['invoicePrice'];
  3845. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3846. $accountPriceStaffYear += $v ['accountPrice'];
  3847. $flag = false;
  3848. break;
  3849. }
  3850. }
  3851. if ($flag) {
  3852. $htmlA .= '<td class="taR">-</td>';
  3853. $htmlB .= '<td class="taR">-</td>';
  3854. $htmlC .= '<td class="taR"><b>-</b></td>';
  3855. }
  3856. }
  3857. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3858. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3859. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3860. $htmlA .= '</tr>';
  3861. $htmlB .= '</tr>';
  3862. $htmlC .= '</tr>';
  3863. $html .= $htmlA . $htmlB . $htmlC;
  3864. $this->data ['html'] = $html;
  3865. $this->data ['cidKey'] = $cidKey;
  3866. $this->data ['slist'] = $list;
  3867. $this->data ['isList'] = $toteList;
  3868. $this->data ['year'] = $year;
  3869. $this->data ['memu'] = "invoice";
  3870. $this->data ['staff'] = $this->staff;
  3871. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3872. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3873. }
  3874. /**
  3875. * 办事处汇总信息
  3876. */
  3877. function invoiceAggregateCategoryDetail() {
  3878. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  3879. Doo::loadClass ( 'XDeode' );
  3880. $XDeode = new XDeode ( 5 );
  3881. Doo::loadModel ( 'invoiceStatistics' );
  3882. $invoiceStatistics = new invoiceStatistics ();
  3883. Doo::loadModel ( 'L_category' );
  3884. $category = new L_category ();
  3885. Doo::loadModel ( 'invoice' );
  3886. $invoice = new invoice ();
  3887. Doo::loadModel ( 'staff' );
  3888. $staff = new staff ();
  3889. Doo::loadModel ( "invoiceCategoryManage" );
  3890. $invoiceCategoryManage = new invoiceCategoryManage ();
  3891. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3892. $cidList = array ();
  3893. foreach ( $imcStaff as $key => $value ) {
  3894. array_push ( $cidList, $value ['cid'] );
  3895. if (empty ( $cidKey ))
  3896. $cidKey = $XDeode->encode ( $value ['cid'] );
  3897. }
  3898. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  3899. $cid = $XDeode->decode ( $cidKey );
  3900. $month = date ( "m", strtotime ( "-1 month" ) );
  3901. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  3902. $redis = new Redis ();
  3903. $redis->connect ( '127.0.0.1', '6379' );
  3904. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  3905. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  3906. if (empty ( $redisValue )) {
  3907. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  3908. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  3909. // 获得办事处人员下的汇总
  3910. $slist = $staff->getStaffByCid ( $cid );
  3911. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  3912. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  3913. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  3914. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  3915. foreach ( $slist as $key => $value ) {
  3916. $slist [$key] ['invoicePrice'] = 0;
  3917. $slist [$key] ['receivablesPrice'] = 0;
  3918. $slist [$key] ['accountPrice'] = 0;
  3919. $slist [$key] ['invoiceAllPrice'] = 0;
  3920. $slist [$key] ['receivablesAllPrice'] = 0;
  3921. $slist [$key] ['accountAllPrice'] = 0;
  3922. $slist [$key] ['schedule'] = 0;
  3923. $slist [$key] ['invoiceMonthPrice'] = 0;
  3924. $slist [$key] ['receivablesMonthPrice'] = 0;
  3925. $slist [$key] ['accountMonthPrice'] = 0;
  3926. foreach ( $ismsbMonth as $y => $l ) {
  3927. if ($value ['sid'] == $l ['staff']) {
  3928. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  3929. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  3930. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  3931. }
  3932. }
  3933. foreach ( $ismsb as $k => $v ) {
  3934. if ($value ['sid'] == $v ['staff']) {
  3935. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  3936. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  3937. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  3938. }
  3939. }
  3940. foreach ( $ISAS as $e => $a ) {
  3941. if ($value ['sid'] == $a ['staff']) {
  3942. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  3943. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  3944. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  3945. }
  3946. }
  3947. if (isset ( $scheduleStaff [$value ['sid']] ))
  3948. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  3949. }
  3950. $this->data ['cidKey'] = $cidKey;
  3951. $schedule = ( int ) ($schedule * 100);
  3952. $this->data ['slist'] = $slist;
  3953. $this->data ['isMC'] = $isMC;
  3954. $this->data ['schedule'] = $schedule;
  3955. $slist = json_encode ( $slist );
  3956. $isMC = json_encode ( $isMC );
  3957. $schedule = json_encode ( $schedule );
  3958. $redis->lpush ( $redisKey, $slist );
  3959. $redis->lpush ( $redisKey, $isMC );
  3960. $redis->lpush ( $redisKey, $schedule );
  3961. } else {
  3962. $this->data ['cidKey'] = $cidKey;
  3963. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  3964. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  3965. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  3966. }
  3967. $this->data ['month'] = $month;
  3968. $this->data ['categoryList'] = $categoryList;
  3969. $this->data ['memu'] = "invoice";
  3970. $this->data ['staff'] = $this->staff;
  3971. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3972. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  3973. }
  3974. /**
  3975. * 办事处人员汇总详情
  3976. */
  3977. function invoiceAggregateStaffDetail() {
  3978. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3979. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  3980. Doo::loadClass ( 'XDeode' );
  3981. $XDeode = new XDeode ( 5 );
  3982. Doo::loadModel ( 'invoice' );
  3983. $invoice = new invoice ();
  3984. Doo::loadModel ( 'staff' );
  3985. $staff = new staff ();
  3986. Doo::loadModel ( "invoiceCategoryManage" );
  3987. $invoiceCategoryManage = new invoiceCategoryManage ();
  3988. $sid = $XDeode->decode ( $sidKey );
  3989. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3990. $cidList = array ();
  3991. foreach ( $imcStaff as $key => $value ) {
  3992. array_push ( $cidList, $value ['cid'] );
  3993. if (empty ( $cidKey ))
  3994. $cidKey = $XDeode->encode ( $value ['cid'] );
  3995. }
  3996. $cidString = implode ( ',', $cidList );
  3997. $staffList = $staff->getStaffInCid ( $cidString );
  3998. $staffDetail = $staff->getStaffBySid ( $sid );
  3999. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4000. $page_size = 18;
  4001. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4002. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4003. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4004. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4005. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4006. $dateArr = explode ( ':', $date );
  4007. $D1 = '';
  4008. $D2 = '';
  4009. if (! empty ( $date )) {
  4010. $D1 = $dateArr [0] . " 00:00:00 ";
  4011. if (isset ( $dateArr [1] ))
  4012. $D2 = $dateArr [1] . " 23:59:59 ";
  4013. else
  4014. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4015. // $D2 = $dateArr [1];
  4016. }
  4017. $con = ' status=2 ';
  4018. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4019. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4020. if ($status == 'UNRECORD')
  4021. $con .= ' and printStatus=1 and untreadStatus=0';
  4022. elseif ($status == 'RECORD')
  4023. $con .= ' and printStatus=1 and untreadStatus=3';
  4024. elseif ($status == 'BOUNCED')
  4025. $con .= ' and untreadStatus=2';
  4026. elseif ($status == 'PARTRECORD')
  4027. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4028. elseif ($status == 'All') {
  4029. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4030. }
  4031. $con .= ' and sid=' . $sid;
  4032. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4033. if (! empty ( $MebSea )) {
  4034. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4035. }
  4036. $pageinfo ['page'] = array (
  4037. 'previous' => ''
  4038. );
  4039. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4040. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4041. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4042. $this->data ['staffDetail'] = $staffDetail;
  4043. $this->data ['staffList'] = $staffList;
  4044. $this->data ['MebSeaEn'] = $MebSea;
  4045. $this->data ['MebSea'] = urlencode ( $MebSea );
  4046. $this->data ['date'] = $date;
  4047. $this->data ['page'] = $pageinfo;
  4048. $this->data ['get'] = $get;
  4049. $this->data ['list'] = $list;
  4050. $this->data ['status'] = $status;
  4051. $this->data ['sidKey'] = $sidKey;
  4052. $this->data ['memu'] = "invoice";
  4053. $this->data ['staff'] = $this->staff;
  4054. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4055. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4056. }
  4057. /**
  4058. * 办事处人员汇总收款情
  4059. */
  4060. function invoiceAggregateStaffReceivablesDetail() {
  4061. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4062. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4063. Doo::loadModel ( 'invoiceReceivables' );
  4064. $invoiceReceivables = new invoiceReceivables ();
  4065. Doo::loadModel ( 'staff' );
  4066. $staff = new staff ();
  4067. Doo::loadModel ( "invoiceCategoryManage" );
  4068. $invoiceCategoryManage = new invoiceCategoryManage ();
  4069. Doo::loadClass ( 'XDeode' );
  4070. $XDeode = new XDeode ( 5 );
  4071. $sid = $XDeode->decode ( $sidKey );
  4072. $staffDetail = $staff->getStaffBySid ( $sid );
  4073. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4074. $cidList = array ();
  4075. foreach ( $imcStaff as $key => $value ) {
  4076. array_push ( $cidList, $value ['cid'] );
  4077. if (empty ( $cidKey ))
  4078. $cidKey = $XDeode->encode ( $value ['cid'] );
  4079. }
  4080. $cidString = implode ( ',', $cidList );
  4081. $staffList = $staff->getStaffInCid ( $cidString );
  4082. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4083. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4084. $page_size = 10;
  4085. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4086. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4087. if ($timeType == "BINDOTP") {
  4088. $status = 'Credited';
  4089. }
  4090. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4091. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4092. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4093. $dateArr = explode ( ':', $date );
  4094. $D1 = '';
  4095. $D2 = '';
  4096. if (! empty ( $date )) {
  4097. $D1 = $dateArr [0] . " 00:00:00 ";
  4098. if (isset ( $dateArr [1] ))
  4099. $D2 = $dateArr [1] . " 23:59:59 ";
  4100. else
  4101. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4102. }
  4103. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4104. $descField = 'a.bindDate';
  4105. if ($timeType == 'CREATE')
  4106. $descField = 'a.date';
  4107. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4108. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4109. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4110. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4111. if ($status == 'Unclaimed')
  4112. $con .= ' and a.bindStatus=0';
  4113. elseif ($status == 'Credited')
  4114. $con .= ' and a.bindStatus=1';
  4115. elseif ($status == 'Claim')
  4116. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4117. elseif ($status == 'BBN')
  4118. $con .= ' and a.bindPrice>a.receivablesPrice';
  4119. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4120. if (! empty ( $MebSea )) {
  4121. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4122. }
  4123. $pageinfo ['page'] = array (
  4124. 'previous' => ''
  4125. );
  4126. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4127. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4128. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4129. where ' . $con . ' group by a.irid ';
  4130. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4131. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4132. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4133. foreach ( $list as $key => $value ) {
  4134. $list [$key] ['category'] = '';
  4135. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4136. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4137. $list [$key] ['category'] = $receivablesCategory [1];
  4138. }
  4139. }
  4140. // print_r($list);
  4141. $this->data ['staffDetail'] = $staffDetail;
  4142. $this->data ['sidKey'] = $sidKey;
  4143. $this->data ['staffList'] = $staffList;
  4144. $this->data ['timeType'] = $timeType;
  4145. $this->data ['MebSeaEn'] = $MebSea;
  4146. $this->data ['MebSea'] = urlencode ( $MebSea );
  4147. $this->data ['date'] = $date;
  4148. $this->data ['page'] = $pageinfo;
  4149. $this->data ['get'] = $get;
  4150. $this->data ['list'] = $list;
  4151. $this->data ['status'] = $status;
  4152. $this->data ['memu'] = "invoice";
  4153. $this->data ['staff'] = $this->staff;
  4154. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4155. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4156. }
  4157. function invoiceAchieve() {
  4158. Doo::loadModel ( 'invoice' );
  4159. $invoice = new invoice ();
  4160. Doo::loadClass ( 'XDeode' );
  4161. $XDeode = new XDeode ( 5 );
  4162. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4163. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4164. $page_size = 18;
  4165. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4166. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4167. $get = "/" . $date;
  4168. $con = '';
  4169. if ($date == 'MONTHO')
  4170. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4171. elseif ($date == 'MONTHT')
  4172. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4173. elseif ($date == 'MONTHY')
  4174. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4175. if (! empty ( $MebSea )) {
  4176. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4177. $get .= "/" . $MebSea;
  4178. }
  4179. $pageinfo ['page'] = array (
  4180. 'previous' => ''
  4181. );
  4182. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4183. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4184. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4185. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4186. // print_r($pageinfo);
  4187. $this->data ['MebSeaEn'] = $MebSea;
  4188. $this->data ['MebSea'] = urlencode ( $MebSea );
  4189. $this->data ['get'] = $get;
  4190. $this->data ['page'] = $pageinfo;
  4191. $this->data ['list'] = $list;
  4192. $this->data ['date'] = $date;
  4193. $this->data ['memu'] = "invoice";
  4194. $this->data ['staff'] = $this->staff;
  4195. $this->data ['receiptMemu'] = 'invoice';
  4196. $this->render ( "/admin/invoiceAchieve", $this->data );
  4197. }
  4198. /**
  4199. */
  4200. function invoiceMyUnAccountAchieve() {
  4201. Doo::loadModel ( 'invoice' );
  4202. $invoice = new invoice ();
  4203. Doo::loadClass ( 'XDeode' );
  4204. $XDeode = new XDeode ( 5 );
  4205. Doo::loadModel ( 'staff' );
  4206. $staff = new staff ();
  4207. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4208. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4209. $page_size = 18;
  4210. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4211. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4212. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4213. $dateArr = explode ( ':', $date );
  4214. $D1 = '';
  4215. $D2 = '';
  4216. if (! empty ( $date )) {
  4217. $D1 = $dateArr [0];
  4218. $D2 = $dateArr [1];
  4219. }
  4220. $con = '';
  4221. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4222. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4223. if (! empty ( $MebSea )) {
  4224. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4225. }
  4226. $pageinfo ['page'] = array (
  4227. 'previous' => ''
  4228. );
  4229. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4230. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4231. $action = "invoiceMyUnAccountAchieve";
  4232. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4233. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4234. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4235. Doo::loadModel ( 'express' );
  4236. $express = new express ();
  4237. $expressList = $express->getExpressByAll ();
  4238. $this->data ['expressList'] = $expressList;
  4239. // print_r($list);
  4240. $this->data ['MebSeaEn'] = $MebSea;
  4241. $this->data ['get'] = $get;
  4242. $this->data ['page'] = $pageinfo;
  4243. $this->data ['date'] = $date;
  4244. $this->data ['list'] = $list;
  4245. $this->data ['memu'] = "invoice";
  4246. $this->data ['staff'] = $this->staff;
  4247. $this->data ['receiptMemu'] = 'invoice';
  4248. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4249. }
  4250. function invoiceReceivablesAchieve() {
  4251. Doo::loadModel ( 'invoiceReceivables' );
  4252. $invoiceReceivables = new invoiceReceivables ();
  4253. Doo::loadClass ( 'XDeode' );
  4254. $XDeode = new XDeode ( 5 );
  4255. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4256. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4257. $page_size = 12;
  4258. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4259. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4260. $get = "/" . $date;
  4261. $con = '';
  4262. if ($date == 'MONTHO')
  4263. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4264. elseif ($date == 'MONTHT')
  4265. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4266. elseif ($date == 'MONTHY')
  4267. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4268. if (! empty ( $MebSea )) {
  4269. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4270. $get .= "/" . $MebSea;
  4271. }
  4272. $pageinfo ['page'] = array (
  4273. 'previous' => ''
  4274. );
  4275. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4276. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4277. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4278. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4279. // print_r($pageinfo);
  4280. $this->data ['MebSeaEn'] = $MebSea;
  4281. $this->data ['MebSea'] = urlencode ( $MebSea );
  4282. $this->data ['get'] = $get;
  4283. $this->data ['page'] = $pageinfo;
  4284. $this->data ['list'] = $list;
  4285. $this->data ['date'] = $date;
  4286. $this->data ['memu'] = "invoice";
  4287. $this->data ['staff'] = $this->staff;
  4288. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4289. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4290. }
  4291. /**
  4292. * 收款解绑
  4293. */
  4294. function invoiceUnBundLing() {
  4295. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4296. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4297. Doo::loadModel ( 'invoice' );
  4298. $invoice = new invoice ();
  4299. Doo::loadModel ( 'invoiceReceivables' );
  4300. $invoiceReceivables = new invoiceReceivables ();
  4301. Doo::loadModel ( 'invoiceOperationLog' );
  4302. $invoiceOperationLog = new invoiceOperationLog ();
  4303. Doo::loadModel ( 'invoiceROLog' );
  4304. $invoiceROLog = new invoiceROLog ();
  4305. Doo::loadModel ( 'invoiceStatistics' );
  4306. Doo::loadClass ( 'XDeode' );
  4307. $XDeode = new XDeode ( 5 );
  4308. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4309. die ( 'illegal request' );
  4310. $iid = $XDeode->decode ( $iidKey );
  4311. $irid = $invoice->authcode ( $unBundKey );
  4312. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4313. die ( 'illegal request' );
  4314. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4315. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4316. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4317. die ( 'illegal request' );
  4318. // 收款
  4319. $item = array (
  4320. 'irid' => $irDetails ['irid'],
  4321. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4322. 'bindStatus' => 0
  4323. );
  4324. if ($irDetails ['iid'] == $iid)
  4325. $item += array (
  4326. 'iid' => 0
  4327. );
  4328. else {
  4329. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4330. foreach ( $iidExtend as $key => $value ) {
  4331. if ($value == $iid)
  4332. unset ( $iidExtend [$key] );
  4333. }
  4334. $iidExtend = implode ( ',', $iidExtend );
  4335. $item += array (
  4336. 'iidExtend' => $iidExtend
  4337. );
  4338. }
  4339. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4340. // 收款操作日志
  4341. $item = array (
  4342. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4343. 'date' => date ( "Y-m-d" ),
  4344. 'status' => 3,
  4345. 'img' => $this->staff [0] ['avatar'],
  4346. 'username' => $this->staff [0] ['username'],
  4347. 'uid' => $this->staff [0] ['sid'],
  4348. 'category' => $this->staff [0] ['category'],
  4349. 'irid' => $irid
  4350. );
  4351. $invoiceROLog->setInvoiceROLog ( $item );
  4352. // 扣除入账统计金额
  4353. $invoiceStatistics = new invoiceStatistics ();
  4354. $item = array (
  4355. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4356. 'priceClass' => 3,
  4357. 'cid' => $invoiceDetails ['cid'],
  4358. 'staff' => $invoiceDetails ['sid'],
  4359. 'accountPrice' => - $irDetails ['receivablesPrice']
  4360. );
  4361. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4362. // 扣除收款统计金额
  4363. $invoiceStatistics = new invoiceStatistics ();
  4364. $item = array (
  4365. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4366. 'priceClass' => 2,
  4367. 'cid' => $invoiceDetails ['cid'],
  4368. 'staff' => $invoiceDetails ['sid'],
  4369. 'irid' => $irDetails ['irid'],
  4370. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4371. );
  4372. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4373. // 发票解绑去收款ID
  4374. $iridString = $invoiceDetails ['irid'];
  4375. if (! empty ( $invoiceDetails ['irid'] )) {
  4376. $list = explode ( ',', $invoiceDetails ['irid'] );
  4377. foreach ( $list as $key => $value ) {
  4378. if ($value == $irDetails ['irid']) {
  4379. unset ( $list [$key] );
  4380. break;
  4381. }
  4382. }
  4383. $iridString = implode ( ",", $list );
  4384. }
  4385. $item = array (
  4386. 'iid' => $invoiceDetails ['iid'],
  4387. 'irid' => $iridString,
  4388. 'updateTime' => date ( "Y-m-d H:i:s" )
  4389. );
  4390. if ($invoiceDetails ['untreadStatus'] == 3)
  4391. $item += array (
  4392. 'untreadStatus' => 0
  4393. );
  4394. $invoice->setInvoiceByCondition ( $item );
  4395. $item = array (
  4396. 'date' => date ( "Y-m-d H:i:s" ),
  4397. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4398. 'status' => 11,
  4399. 'img' => $this->staff [0] ['avatar'],
  4400. 'username' => $this->staff [0] ['username'],
  4401. 'uid' => $this->staff [0] ['sid'],
  4402. 'category' => $this->staff [0] ['category'],
  4403. 'iid' => $invoiceDetails ['iid']
  4404. );
  4405. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4406. // 公司流水-解绑时删除流水
  4407. Doo::loadModel ( 'wasteBook' );
  4408. $wasteBook = new wasteBook ();
  4409. // $wasteBook->delete ( array (
  4410. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4411. // 'limit' => 1
  4412. // ) );
  4413. // 银行
  4414. /*
  4415. * $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); }
  4416. */
  4417. return "/invoiceReceivablesAS";
  4418. }
  4419. /**
  4420. * 或者该收款下的所以发票
  4421. */
  4422. function ajaxGetInvoiceReceivablesByInvoice() {
  4423. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4424. Doo::loadModel ( 'invoice' );
  4425. $invoice = new invoice ();
  4426. Doo::loadModel ( 'invoiceReceivables' );
  4427. $invoiceReceivables = new invoiceReceivables ();
  4428. $irid = $invoice->authcode ( $irid );
  4429. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4430. die ( 'illegal request' );
  4431. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4432. $iidString = $irDetails ['iid'];
  4433. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4434. if (! empty ( $irDetails ['iidExtend'] ))
  4435. $iidString .= ',' . implode ( ',', $iidExtend );
  4436. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4437. $html = "";
  4438. foreach ( $invoiceList as $key => $value ) {
  4439. $title = $value ['invoiceTitle'];
  4440. if (! empty ( $value ['invoiceCompany'] ))
  4441. $title = $value ['invoiceCompany'];
  4442. $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>';
  4443. }
  4444. echo json_encode ( array (
  4445. 'status' => 1,
  4446. 'html' => $html
  4447. ) );
  4448. }
  4449. /**
  4450. * 发票管理
  4451. */
  4452. function invoiceAS() {
  4453. Doo::loadModel ( 'invoice' );
  4454. $invoice = new invoice ();
  4455. Doo::loadModel ( 'invoiceReceivables' );
  4456. $invoiceReceivables = new invoiceReceivables ();
  4457. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4458. $page_size = 18;
  4459. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4460. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4461. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4462. $dateArr = explode ( ':', $date );
  4463. $D1 = '';
  4464. $D2 = '';
  4465. if (! empty ( $date )) {
  4466. $D1 = $dateArr [0] . " 00:00:00 ";
  4467. if (isset ( $dateArr [1] ))
  4468. $D2 = $dateArr [1] . " 23:59:59 ";
  4469. else
  4470. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4471. // $D2 = $dateArr [1];
  4472. }
  4473. $con = ' status=2 ';
  4474. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4475. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4476. if ($status == 'UNRECORD')
  4477. $con .= ' and printStatus=1 and untreadStatus=0';
  4478. elseif ($status == 'RECORD')
  4479. $con .= ' and printStatus=1 and untreadStatus=3';
  4480. elseif ($status == 'BOUNCED')
  4481. $con .= ' and untreadStatus=2';
  4482. elseif ($status == 'PARTRECORD')
  4483. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4484. elseif ($status == 'All') {
  4485. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4486. }
  4487. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4488. if (! empty ( $MebSea )) {
  4489. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4490. }
  4491. $pageinfo ['page'] = array (
  4492. 'previous' => ''
  4493. );
  4494. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4495. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4496. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4497. $this->data ['MebSeaEn'] = $MebSea;
  4498. $this->data ['MebSea'] = urlencode ( $MebSea );
  4499. $this->data ['date'] = $date;
  4500. $this->data ['page'] = $pageinfo;
  4501. $this->data ['get'] = $get;
  4502. $this->data ['list'] = $list;
  4503. $this->data ['status'] = $status;
  4504. $this->data ['memu'] = "invoice";
  4505. $this->data ['staff'] = $this->staff;
  4506. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4507. $this->render ( "/admin/invoiceAS", $this->data );
  4508. }
  4509. /**
  4510. * 收款管理
  4511. */
  4512. function invoiceReceivablesAS() {
  4513. Doo::loadModel ( 'invoiceReceivables' );
  4514. $invoiceReceivables = new invoiceReceivables ();
  4515. Doo::loadModel ( 'L_category' );
  4516. $lCategory = new L_category ();
  4517. $category = $lCategory->getCategory ();
  4518. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4519. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4520. $page_size = 10;
  4521. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4522. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4523. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4524. $dateArr = explode ( ':', $date );
  4525. $D1 = '';
  4526. $D2 = '';
  4527. if (! empty ( $date )) {
  4528. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4529. if (isset ( $dateArr [1] ))
  4530. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4531. else
  4532. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4533. }
  4534. $descField = 'a.receivablesDate';
  4535. if ($timeType == 'CREATE')
  4536. $descField = 'a.date';
  4537. $con = '1';
  4538. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4539. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4540. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4541. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4542. if ($status == 'Unclaimed')
  4543. $con .= ' and a.bindStatus=0';
  4544. elseif ($status == 'Credited')
  4545. $con .= ' and a.bindStatus=1';
  4546. elseif ($status == 'Claim')
  4547. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4548. elseif ($status == 'BBN')
  4549. $con .= ' and a.bankBatchNumber!=""';
  4550. elseif ($status == 'REFUND')
  4551. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4552. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4553. if (! empty ( $MebSea )) {
  4554. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4555. }
  4556. $pageinfo ['page'] = array (
  4557. 'previous' => ''
  4558. );
  4559. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4560. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4561. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4562. where ' . $con . ' group by a.irid ';
  4563. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4564. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4565. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4566. foreach ( $list as $key => $value ) {
  4567. $list [$key] ['category'] = '';
  4568. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4569. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4570. $list [$key] ['category'] = $receivablesCategory [1];
  4571. }
  4572. }
  4573. // print_r($list);
  4574. $this->data ['category'] = $category;
  4575. $this->data ['timeType'] = $timeType;
  4576. $this->data ['MebSeaEn'] = $MebSea;
  4577. $this->data ['MebSea'] = urlencode ( $MebSea );
  4578. $this->data ['date'] = $date;
  4579. $this->data ['page'] = $pageinfo;
  4580. $this->data ['get'] = $get;
  4581. $this->data ['list'] = $list;
  4582. $this->data ['status'] = $status;
  4583. $this->data ['memu'] = "invoice";
  4584. $this->data ['staff'] = $this->staff;
  4585. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4586. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4587. }
  4588. /**
  4589. * 删除一条收款
  4590. */
  4591. function delInvoiceReceivables() {
  4592. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4593. if (empty ( $iridKey ))
  4594. die ( 'illegal request' );
  4595. Doo::loadClass ( 'XDeode' );
  4596. $XDeode = new XDeode ( 5 );
  4597. $irid = $XDeode->decode ( $iridKey );
  4598. Doo::loadModel ( 'invoiceReceivables' );
  4599. $invoiceReceivables = new invoiceReceivables ();
  4600. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4601. if (empty ( $detail ))
  4602. die ( 'illegal request' );
  4603. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4604. // 扣除收款汇总信息 汇总
  4605. Doo::loadModel ( 'invoiceStatistics' );
  4606. $invoiceStatistics = new invoiceStatistics ();
  4607. $item = array (
  4608. 'date' => $detail ['receivablesDate'],
  4609. 'priceClass' => 2,
  4610. 'irid' => $detail ['irid'],
  4611. 'receivablesPrice' => - $detail ['receivablesPrice']
  4612. );
  4613. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4614. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4615. $item += array (
  4616. 'cid' => $receivablesCategory [0]
  4617. );
  4618. }
  4619. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4620. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4621. $item += array (
  4622. 'staff' => $receivablesStaff [0]
  4623. );
  4624. }
  4625. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4626. return '/invoiceReceivablesAS';
  4627. }
  4628. /**
  4629. * 添加退款信息
  4630. */
  4631. function setInvoiceReceivablesRefund() {
  4632. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4633. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4634. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4635. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4636. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4637. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4638. if ($refundPrice < 0)
  4639. die ( 'illegal request' );
  4640. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4641. Doo::loadModel ( 'invoiceReceivables' );
  4642. $invoiceReceivables = new invoiceReceivables ();
  4643. Doo::loadModel ( 'invoiceRefund' );
  4644. $invoiceRefund = new invoiceRefund ();
  4645. $irid = $invoiceReceivables->authcode ( $iridKey );
  4646. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4647. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4648. die ( 'illegal request' );
  4649. $invoiceReceivables = new invoiceReceivables ();
  4650. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4651. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4652. ';
  4653. $item = array (
  4654. 'irid' => $irid,
  4655. 'refundCompany' => $refundCompany,
  4656. 'refundNumber' => $refundNumber,
  4657. 'refundPrice' => $refundPrice,
  4658. 'refundRemarks' => $refundRemarks,
  4659. 'refundLog' => $refundLog
  4660. );
  4661. if ($refundType == 1) {
  4662. $item += array (
  4663. 'refundType' => $refundType,
  4664. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4665. 'bindStatus' => 2
  4666. );
  4667. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4668. $item += array (
  4669. 'refundType' => 1,
  4670. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4671. 'bindStatus' => 2
  4672. );
  4673. } else {
  4674. $item += array (
  4675. 'refundType' => $refundType,
  4676. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4677. );
  4678. }
  4679. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4680. // 添加退款记录
  4681. $item = array (
  4682. 'irid' => $irid,
  4683. 'refundType' => $refundType,
  4684. 'refundCompany' => $refundCompany,
  4685. 'refundNumber' => $refundNumber,
  4686. 'refundPrice' => $refundPrice,
  4687. 'refundLog' => $refundLog,
  4688. 'refundRemarks' => $refundRemarks,
  4689. 'date' => date ( "Y-m-d H:i:s" )
  4690. );
  4691. $invoiceRefund->addInvoiceRefund ( $item );
  4692. // 扣除收款汇总信息 汇总
  4693. Doo::loadModel ( 'invoiceStatistics' );
  4694. $invoiceStatistics = new invoiceStatistics ();
  4695. $item = array (
  4696. 'date' => $irDetail ['receivablesDate'],
  4697. 'priceClass' => 2,
  4698. 'irid' => $irDetail ['irid'],
  4699. 'receivablesPrice' => - $refundPrice
  4700. );
  4701. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4702. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4703. $item += array (
  4704. 'cid' => $receivablesCategory [0]
  4705. );
  4706. }
  4707. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4708. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4709. $item += array (
  4710. 'staff' => $receivablesStaff [0]
  4711. );
  4712. }
  4713. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4714. // 公司日常支出流水
  4715. Doo::loadModel ( 'wasteBook' );
  4716. $wasteBook = new wasteBook ();
  4717. $accountBank = '';
  4718. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4719. $accountBank = 'CGBDeposit';
  4720. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4721. $accountBank = 'ICBCDeposit';
  4722. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4723. $accountBank = 'HUADeposit';
  4724. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4725. $accountBank = 'PersonalDeposit';
  4726. }
  4727. $itemWaste = array (
  4728. 'accountPrice' => - $refundPrice,
  4729. 'expensesType' => 2,
  4730. 'accountType' => 11,
  4731. 'accountPriceShow' => $refundPrice,
  4732. 'dataID' => $irid,
  4733. 'accountBank' => $accountBank,
  4734. 'category' => $this->staff [0] ['category'],
  4735. 'cid' => $this->staff [0] ['cid'],
  4736. 'name' => $this->staff [0] ['username'],
  4737. 'sid' => $this->staff [0] ['sid'],
  4738. 'inputDate' => date ( "Y-m-d H:i:s" )
  4739. );
  4740. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4741. return '/invoiceReceivablesAS';
  4742. }
  4743. die ( 'illegal request' );
  4744. }
  4745. function ajaxCheckInvoiceReceivablesRefund() {
  4746. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4747. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4748. if ($refundPrice < 0) {
  4749. echo json_encode ( array (
  4750. 'error' => '金额不能为负'
  4751. ) );
  4752. die ();
  4753. }
  4754. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4755. Doo::loadModel ( 'invoiceReceivables' );
  4756. $invoiceReceivables = new invoiceReceivables ();
  4757. $irid = $invoiceReceivables->authcode ( $iridKey );
  4758. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4759. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4760. echo json_encode ( array (
  4761. 'error' => '退款金额不能超过收款金额'
  4762. ) );
  4763. die ();
  4764. }
  4765. echo json_encode ( array (
  4766. 'ok' => '可以使用!'
  4767. ) );
  4768. die ();
  4769. }
  4770. }
  4771. /**
  4772. * 获得收款退款信息
  4773. */
  4774. function getRefundByDetail() {
  4775. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4776. Doo::loadModel ( 'invoiceReceivables' );
  4777. $invoiceReceivables = new invoiceReceivables ();
  4778. if (! empty ( $iridKey )) {
  4779. $irid = $invoiceReceivables->authcode ( $iridKey );
  4780. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4781. echo json_encode ( array (
  4782. 'status' => 1,
  4783. 'irDetail' => $irDetail
  4784. ) );
  4785. die ();
  4786. }
  4787. echo json_encode ( array (
  4788. 'status' => 2
  4789. ) );
  4790. }
  4791. /**
  4792. * 根据收款序列号获得收款退款信息
  4793. */
  4794. function ajaxGetInvoiceReceivablesBySerial() {
  4795. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  4796. if (! empty ( $receivablesSerial )) {
  4797. Doo::loadModel ( 'invoiceReceivables' );
  4798. $invoiceReceivables = new invoiceReceivables ();
  4799. // , ' and refundLog=""'
  4800. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  4801. $html = '';
  4802. if (! empty ( $irDetail ))
  4803. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  4804. <td>' . $irDetail ['receivablesMessage'] . '</td>
  4805. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  4806. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  4807. <td>' . $irDetail ['recepitTitleMark'] . '
  4808. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  4809. </td>';
  4810. echo json_encode ( array (
  4811. 'status' => 1,
  4812. 'html' => $html,
  4813. 'irDetail' => $irDetail
  4814. ) );
  4815. die ();
  4816. }
  4817. echo json_encode ( array (
  4818. 'status' => 2
  4819. ) );
  4820. }
  4821. /**
  4822. * 绑定新收款
  4823. */
  4824. function relationNewInvoiceReceivables() {
  4825. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  4826. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4827. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  4828. Doo::loadModel ( 'invoiceReceivables' );
  4829. $invoiceReceivables = new invoiceReceivables ();
  4830. Doo::loadClass ( 'XDeode' );
  4831. $XDeode = new XDeode ( 5 );
  4832. $irid = $XDeode->decode ( $iridKey );
  4833. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  4834. echo $irid . 'bbb' . $iridOld;
  4835. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  4836. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4837. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  4838. die ( 'illegal request' );
  4839. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  4840. <br/>' . date ( "Y-m-d H:i:s" ) . '
  4841. ';
  4842. $invoiceReceivables = new invoiceReceivables ();
  4843. $item = array (
  4844. 'irid' => $iridOld,
  4845. 'relationIrid' => $irid,
  4846. 'relationLog' => $relationLog
  4847. );
  4848. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4849. return '/invoiceReceivablesAS';
  4850. }
  4851. die ( 'illegal request' );
  4852. }
  4853. // function invoiceApprovalAchieve() {
  4854. // Doo::loadModel ( 'invoice' );
  4855. // $invoice = new invoice ();
  4856. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4857. // $page_size = 12;
  4858. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4859. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4860. // $get = "/" . $date;
  4861. // $con = '';
  4862. // if ($date == 'MONTHO')
  4863. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4864. // elseif ($date == 'MONTHT')
  4865. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4866. // elseif ($date == 'MONTHY')
  4867. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4868. // if (! empty ( $MebSea )) {
  4869. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4870. // $get .= "/" . $MebSea;
  4871. // }
  4872. // $pageinfo ['page'] = array (
  4873. // 'previous' => ''
  4874. // );
  4875. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  4876. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4877. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  4878. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4879. // // print_r($list);
  4880. // $this->data ['MebSeaEn'] = $MebSea;
  4881. // $this->data ['MebSea'] = urlencode ( $MebSea );
  4882. // $this->data ['get'] = $get;
  4883. // $this->data ['page'] = $pageinfo;
  4884. // $this->data ['list'] = $list;
  4885. // $this->data ['date'] = $date;
  4886. // $this->data ['memu'] = "invoice";
  4887. // $this->data ['staff'] = $this->staff;
  4888. // $this->data ['receiptMemu'] = 'invoiceApproval';
  4889. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4890. // }
  4891. /**
  4892. * 获得审批发票的信息以及审批页面
  4893. */
  4894. function ajaxGetInvoiceApprovalDetail() {
  4895. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4896. if (empty ( $serial )) {
  4897. echo json_encode ( array (
  4898. 'status' => 2,
  4899. 'msg' => 'illegal request'
  4900. ) );
  4901. die ();
  4902. }
  4903. Doo::loadModel ( 'invoice' );
  4904. $invoice = new invoice ();
  4905. Doo::loadModel ( 'invoiceOperationLog' );
  4906. $invoiceOperationLog = new invoiceOperationLog ();
  4907. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4908. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4909. if (empty ( $detail ))
  4910. $html = '';
  4911. else {
  4912. $html = '
  4913. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  4914. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4915. <input type="hidden" name="status" value="">
  4916. <input type="hidden" name="divApproval" value="divApproval">
  4917. <div class="modal-dialog modal-lg">
  4918. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  4919. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4920. <tr>
  4921. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  4922. </tr>
  4923. <tr>
  4924. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4925. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4926. </tr>
  4927. <tr>
  4928. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4929. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4930. </tr>
  4931. <tr>
  4932. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4933. </td>
  4934. </tr>
  4935. <tr>
  4936. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4937. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4938. </tr>
  4939. <tr>
  4940. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4941. </tr></tbody></table>';
  4942. if ($detail ['invoiceType'] == 0)
  4943. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4944. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4945. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4946. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4947. </tr>';
  4948. else
  4949. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4950. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4951. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4952. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4953. ';
  4954. $html .= '<tr>
  4955. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4956. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4957. </tr>
  4958. <tr>
  4959. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4960. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4961. </tr></tbody></table>';
  4962. if ($detail ['doPost'] == 1) {
  4963. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4964. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4965. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4966. </tr><tr>
  4967. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4968. </tr><tr>
  4969. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4970. </tr>
  4971. ';
  4972. if ($detail ['expressCom'] == 'SF')
  4973. $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>';
  4974. else
  4975. $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>';
  4976. $html .= '</tbody></table>';
  4977. }
  4978. if (! empty ( $invoiceOperationLogList )) {
  4979. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4980. foreach ( $invoiceOperationLogList as $key => $value ) {
  4981. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4982. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4983. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4984. if ($value ['status'] == 2) {
  4985. $html .= '<span class="colGreen">同意</span>';
  4986. } elseif ($value ['status'] == 3) {
  4987. $html .= '<span class="colOrange">退回</span>';
  4988. } elseif ($value ['status'] == 5) {
  4989. $html .= '<span class="colGreen">打印</span>';
  4990. } elseif ($value ['status'] == 4) {
  4991. $html .= '<span class="colRed">终止</span>';
  4992. }
  4993. $html .= $value ['operation'] . '</p></blockquote>';
  4994. }
  4995. }
  4996. $html .= '</td></tr></tbody></table>';
  4997. }
  4998. $html .= '</div><div class="modal-footer">
  4999. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5000. <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>
  5001. <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>
  5002. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5003. </form>
  5004. <script type="text/javascript">
  5005. $("a[node-approval^=\'approval\']").click(function() {
  5006. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5007. $("form[name=\'invoiceApproval\']").submit();
  5008. });
  5009. </script>
  5010. ';
  5011. }
  5012. echo json_encode ( array (
  5013. 'status' => 1,
  5014. 'html' => $html
  5015. ) );
  5016. die ();
  5017. }
  5018. /**
  5019. * 获得审批发票分页数据
  5020. */
  5021. function ajaxGetinvoiceApprovalAchieve() {
  5022. Doo::loadModel ( 'invoice' );
  5023. $invoice = new invoice ();
  5024. Doo::loadModel ( 'staff' );
  5025. $staff = new staff ();
  5026. Doo::loadClass ( 'XDeode' );
  5027. $XDeode = new XDeode ( 5 );
  5028. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5029. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5030. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5031. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5032. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5033. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5034. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5035. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5036. $MebSea = $this->get_args ( 'search' );
  5037. $MebSea = $MebSea ['value'];
  5038. $page_size = $length;
  5039. $con = '';
  5040. if ($status == 'ALL')
  5041. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5042. elseif ($status == 'PEND')
  5043. $con = ' isDelete=0 and status=1';
  5044. elseif ($status == 'APPROVED')
  5045. $con = ' isDelete=0 and status=2';
  5046. if ($invoiceType == 'ORDINARY')
  5047. $con .= ' and invoiceType=0 ';
  5048. elseif ($invoiceType == 'SPECIAL')
  5049. $con .= ' and invoiceType=1 ';
  5050. if ($invoiceTrain == 'ORDINARY')
  5051. $con .= ' and trainId=0 ';
  5052. elseif ($invoiceTrain == 'TRAIN')
  5053. $con .= ' and trainId!=0 ';
  5054. if ($invoiceTrainName != 'ALL') {
  5055. $trainId = $XDeode->decode ( $invoiceTrainName );
  5056. if (is_numeric ( $trainId ))
  5057. $con .= ' and trainId =' . $trainId;
  5058. }
  5059. $dateArr = explode ( ':', $date );
  5060. $D1 = $dateString = '';
  5061. $D2 = '';
  5062. if (! empty ( $date )) {
  5063. $D1 = $dateArr [0];
  5064. if (isset ( $dateArr [1] ))
  5065. $D2 = $dateArr [1];
  5066. else
  5067. $D2 = '';
  5068. $dateString = $D1 . " : " . $D2;
  5069. }
  5070. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5071. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5072. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5073. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5074. if (! empty ( $MebSea ))
  5075. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5076. // /
  5077. $pageinfo ['page'] = array (
  5078. 'previous' => ''
  5079. );
  5080. $sql = ' ' . $con;
  5081. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5082. $limit = $page . ',' . $page_size;
  5083. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5084. $approvalList = array ();
  5085. $html = '
  5086. <script type="text/javascript">
  5087. </script>
  5088. ';
  5089. foreach ( $list as $key => $value ) {
  5090. $irDetail = array ();
  5091. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5092. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5093. } else
  5094. array_push ( $irDetail, '' );
  5095. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5096. if ($value ['invoiceType'] == 1)
  5097. array_push ( $irDetail, $value ['invoiceCompany'] );
  5098. else
  5099. array_push ( $irDetail, $value ['invoiceTitle'] );
  5100. array_push ( $irDetail, $value ['TIN'] );
  5101. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5102. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5103. array_push ( $irDetail, $value ['remark'] );
  5104. array_push ( $irDetail, $value ['invoiceElement'] );
  5105. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5106. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5107. if ($value ['invoiceType'] == 1)
  5108. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5109. else
  5110. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5111. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5112. array_push ( $irDetail, $value ['recipientsAddress'] );
  5113. array_push ( $irDetail, $value ['mailItems'] );
  5114. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5115. $fchtml = $value ['OL'] ['operation'];
  5116. if (count ( $list ) == $page_size)
  5117. $fchtml = $value ['OL'] ['operation'] . $html;
  5118. // 最后的审批意见
  5119. array_push ( $irDetail, $fchtml );
  5120. if ($value ['status'] == 2)
  5121. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5122. elseif ($value ['status'] == 3)
  5123. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5124. elseif ($value ['status'] == 4)
  5125. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5126. else
  5127. array_push ( $irDetail, '' );
  5128. array_push ( $approvalList, $irDetail );
  5129. }
  5130. // $approvalListJson = json_encode ( $approvalList );
  5131. $recordsFiltered = $pageinfo ['total_data'];
  5132. echo json_encode ( array (
  5133. "draw" => intval ( $draw ),
  5134. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5135. "recordsFiltered" => intval ( $recordsFiltered ),
  5136. "data" => $approvalList
  5137. ), JSON_UNESCAPED_UNICODE );
  5138. }
  5139. /**
  5140. * 审批发票查看更多--重构
  5141. */
  5142. function invoiceApprovalAchieve() {
  5143. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5144. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5145. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5146. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5147. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5148. Doo::loadModel ( 'invoiceTraining' );
  5149. $invoiceTraining = new invoiceTraining ();
  5150. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5151. $this->data ['trainList'] = $trainList;
  5152. $this->data ['dateString'] = $date;
  5153. $this->data ['status'] = $status;
  5154. $this->data ['invoiceType'] = $invoiceType;
  5155. $this->data ['invoiceTrain'] = $invoiceTrain;
  5156. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5157. $this->data ['memu'] = "invoice";
  5158. $this->data ['staff'] = $this->staff;
  5159. $this->data ['receiptMemu'] = 'invoiceApproval';
  5160. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5161. }
  5162. function invoiceTAchieve() {
  5163. Doo::loadModel ( 'invoice' );
  5164. $invoice = new invoice ();
  5165. Doo::loadClass ( 'XDeode' );
  5166. $XDeode = new XDeode ( 5 );
  5167. Doo::loadModel ( 'staff' );
  5168. $staff = new staff ();
  5169. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5170. $page_size = 12;
  5171. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5172. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5173. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5174. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5175. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5176. Doo::loadModel ( 'invoiceTraining' );
  5177. $invoiceTraining = new invoiceTraining ();
  5178. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5179. $get = "/" . $date;
  5180. $con = '';
  5181. if ($date == 'MONTHO')
  5182. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5183. elseif ($date == 'MONTHT')
  5184. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5185. elseif ($date == 'MONTHY')
  5186. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5187. if ($invoiceType == 'ORDINARY')
  5188. $con .= ' and invoiceType=0 ';
  5189. elseif ($invoiceType == 'SPECIAL')
  5190. $con .= ' and invoiceType=1 ';
  5191. if ($invoiceTrain == 'ORDINARY')
  5192. $con .= ' and trainId=0 ';
  5193. elseif ($invoiceTrain == 'TRAIN')
  5194. $con .= ' and trainId!=0 ';
  5195. if ($invoiceTrainName != 'ALL') {
  5196. $trainId = $XDeode->decode ( $invoiceTrainName );
  5197. if (is_numeric ( $trainId ))
  5198. $con .= ' and trainId =' . $trainId;
  5199. }
  5200. if (! empty ( $MebSea )) {
  5201. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5202. $get .= "/" . $MebSea;
  5203. }
  5204. $pageinfo ['page'] = array (
  5205. 'previous' => ''
  5206. );
  5207. $sql = "";
  5208. $action = "";
  5209. if ($this->ACTION == 'invoicePrintAchieve') {
  5210. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5211. $action = "invoicePrintAchieve";
  5212. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5213. // and untreadStatus=0
  5214. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5215. $action = "invoicePostAchieve";
  5216. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5217. $sql = " untreadStatus=2 and status=2 " . $con;
  5218. $action = "invoiceUntreadAchieve";
  5219. }
  5220. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5221. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5222. $this->data ['MebSeaEn'] = $MebSea;
  5223. $this->data ['MebSea'] = urlencode ( $MebSea );
  5224. $this->data ['get'] = $get;
  5225. $this->data ['page'] = $pageinfo;
  5226. $this->data ['trainList'] = $trainList;
  5227. $this->data ['invoiceType'] = $invoiceType;
  5228. $this->data ['invoiceTrain'] = $invoiceTrain;
  5229. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5230. $this->data ['date'] = $date;
  5231. $this->data ['memu'] = "invoice";
  5232. $this->data ['staff'] = $this->staff;
  5233. if ($this->ACTION == 'invoicePrintAchieve') {
  5234. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5235. $this->data ['receiptMemu'] = 'invoicePrint';
  5236. $this->data ['list'] = $list;
  5237. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5238. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5239. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5240. Doo::loadModel ( 'express' );
  5241. $express = new express ();
  5242. $expressList = $express->getExpressByAll ();
  5243. $this->data ['expressList'] = $expressList;
  5244. $this->data ['receiptMemu'] = 'invoicePost';
  5245. $this->data ['list'] = $list;
  5246. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5247. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5248. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5249. $this->data ['receiptMemu'] = 'invoiceUntread';
  5250. $this->data ['list'] = $list;
  5251. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5252. }
  5253. }
  5254. /**
  5255. * 公司应收款
  5256. */
  5257. function invoiceAggregateCompanyDetail() {
  5258. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5259. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5260. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5261. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5262. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5263. Doo::loadClass ( 'XDeode' );
  5264. $XDeode = new XDeode ( 5 );
  5265. Doo::loadModel ( 'invoice' );
  5266. $invoice = new invoice ();
  5267. Doo::loadModel ( 'staff' );
  5268. $staff = new staff ();
  5269. Doo::loadModel ( "invoiceCompanyManage" );
  5270. $invoiceCompanyManage = new invoiceCompanyManage ();
  5271. Doo::loadModel ( 'L_category' );
  5272. $category = new L_category ();
  5273. $sid = '';
  5274. if (! empty ( $sidKey )) {
  5275. $sid = $XDeode->decode ( $sidKey );
  5276. }
  5277. $staffDetail = $staff->getStaffBySid ( $sid );
  5278. $cid = '';
  5279. if (! empty ( $cidKey )) {
  5280. $cid = $XDeode->decode ( $cidKey );
  5281. }
  5282. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5283. $cidList = array ();
  5284. foreach ( $imcStaff as $key => $value ) {
  5285. array_push ( $cidList, $value ['cid'] );
  5286. }
  5287. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5288. $cidString = implode ( ',', $cidList );
  5289. if (empty ( $cid ))
  5290. $staffList = $staff->getStaffInCid ( $cidString );
  5291. else
  5292. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5293. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5294. $page_size = 25;
  5295. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5296. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5297. $con = ' status=2 and untreadStatus!=2 ';
  5298. $statisticsCon = '';
  5299. if (! empty ( $year ) && is_numeric ( $year ))
  5300. $con .= ' and Year(printTime)=' . $year . '';
  5301. if (! empty ( $month ) && is_numeric ( $month ))
  5302. $con .= ' and Month(printTime)="' . $month . '" ';
  5303. if ($status == 'UNRECORD')
  5304. $con .= ' and printStatus=1 and untreadStatus=0';
  5305. elseif ($status == 'RECORD')
  5306. $con .= ' and printStatus=1 and untreadStatus=3';
  5307. elseif ($status == 'BOUNCED')
  5308. $con .= ' and untreadStatus=2';
  5309. elseif ($status == 'PARTRECORD')
  5310. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5311. elseif ($status == 'All') {
  5312. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5313. }
  5314. if (! empty ( $sid ) && is_numeric ( $sid ))
  5315. $con .= ' and sid=' . $sid;
  5316. if (! empty ( $cid ) && is_numeric ( $cid ))
  5317. $con .= ' and cid=' . $cid;
  5318. else
  5319. $con .= ' and cid in (' . $cidString . ')';
  5320. // 开票内容筛选
  5321. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5322. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5323. }
  5324. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5325. if (! empty ( $MebSea )) {
  5326. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5327. }
  5328. $pageinfo ['page'] = array (
  5329. 'previous' => ''
  5330. );
  5331. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5332. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5333. // 应收款合计
  5334. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5335. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5336. $monthHtml = "";
  5337. if ($year != "ALL") {
  5338. for($i = 1; $i <= 12; $i ++) {
  5339. if ($i == $month)
  5340. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5341. else
  5342. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5343. }
  5344. }
  5345. $this->data ['monthHtml'] = $monthHtml;
  5346. $this->data ['year'] = $year;
  5347. $this->data ['month'] = $month;
  5348. $this->data ['ics'] = $ics;
  5349. $this->data ['cidKey'] = $cidKey;
  5350. $this->data ['sid'] = $sid;
  5351. $this->data ['staffDetail'] = $staffDetail;
  5352. $this->data ['staffList'] = $staffList;
  5353. $this->data ['MebSeaEn'] = $MebSea;
  5354. $this->data ['MebSea'] = urlencode ( $MebSea );
  5355. $this->data ['invoiceDetail'] = array (
  5356. 'invoiceElement' => $invoiceElement
  5357. );
  5358. $this->data ['page'] = $pageinfo;
  5359. $this->data ['get'] = $get;
  5360. $this->data ['list'] = $list;
  5361. $this->data ['status'] = $status;
  5362. $this->data ['categoryList'] = $categoryList;
  5363. $this->data ['memu'] = "invoice";
  5364. $this->data ['staff'] = $this->staff;
  5365. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5366. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5367. }
  5368. /**
  5369. * 获取一条收款信息
  5370. */
  5371. function ajaxGetInvoiceReceivables() {
  5372. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5373. Doo::loadModel ( 'invoiceReceivables' );
  5374. $invoiceReceivables = new invoiceReceivables ();
  5375. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5376. echo json_encode ( array (
  5377. 'status' => 1,
  5378. 'detail' => $detail
  5379. ) );
  5380. }
  5381. /**
  5382. * 异步获取办事处用户
  5383. */
  5384. function ajaxGetStaffByCategory() {
  5385. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5386. Doo::loadModel ( 'staff' );
  5387. $staff = new staff ();
  5388. if ($cid == "PUBLIC") {
  5389. echo json_encode ( array (
  5390. 'status' => 1,
  5391. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5392. ) );
  5393. die ();
  5394. }
  5395. if (! is_numeric ( $cid )) {
  5396. echo json_encode ( array (
  5397. 'status' => 0,
  5398. 'msg' => 'illegal request'
  5399. ) );
  5400. die ();
  5401. }
  5402. $staffList = $staff->getStaffByCid ( $cid );
  5403. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5404. foreach ( $staffList as $key => $value ) {
  5405. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5406. }
  5407. echo json_encode ( array (
  5408. 'status' => 1,
  5409. 'html' => $html
  5410. ) );
  5411. }
  5412. /**
  5413. * 异步获取一条发票的邮寄信息
  5414. */
  5415. function ajaxGetInvoicePostDetail() {
  5416. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5417. Doo::loadModel ( 'invoice' );
  5418. $invoice = new invoice ();
  5419. $iid = $invoice->authcode ( $iid );
  5420. Doo::loadModel ( 'express' );
  5421. $express = new express ();
  5422. $expressList = $express->getExpressByAll ();
  5423. if (! is_numeric ( $iid )) {
  5424. echo json_encode ( array (
  5425. 'status' => 0,
  5426. 'msg' => 'illegal request'
  5427. ) );
  5428. die ();
  5429. }
  5430. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5431. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5432. $html = "";
  5433. foreach ( $expressList as $key => $value ) {
  5434. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5435. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5436. else
  5437. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5438. }
  5439. $invoiceDetail ['eaHtml'] = $html;
  5440. echo json_encode ( array (
  5441. 'status' => 1,
  5442. 'invoiceDetail' => $invoiceDetail
  5443. ) );
  5444. }
  5445. /**
  5446. *
  5447. * @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 ) ); }
  5448. */
  5449. /**
  5450. *
  5451. * @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 ) ); }
  5452. */
  5453. /**
  5454. * 我的收款中 选择哪个发票入账,进行金额判断
  5455. */
  5456. function ajaxCompareInvoicePrice() {
  5457. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5458. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5459. Doo::loadModel ( 'invoice' );
  5460. $invoice = new invoice ();
  5461. Doo::loadModel ( 'invoiceReceivables' );
  5462. $invoiceReceivables = new invoiceReceivables ();
  5463. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5464. $keyList = explode ( ';', $claimKey );
  5465. $receivablesPrice = 0;
  5466. foreach ( $keyList as $key => $value ) {
  5467. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5468. $receivablesPrice += $detailM ['receivablesPrice'];
  5469. }
  5470. if ($receivablesPrice > $detail ['invoicePrice']) {
  5471. $price = $receivablesPrice - $detail ['invoicePrice'];
  5472. echo json_encode ( array (
  5473. 'status' => 1,
  5474. 'price' => $price
  5475. ) );
  5476. } else
  5477. echo json_encode ( array (
  5478. 'status' => 2
  5479. ) );
  5480. }
  5481. /**
  5482. * 获得打印发票
  5483. */
  5484. function ajaxGetInvoiceInfoByPrint() {
  5485. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5486. if (empty ( $serial )) {
  5487. echo json_encode ( array (
  5488. 'status' => 2,
  5489. 'msg' => 'illegal request'
  5490. ) );
  5491. die ();
  5492. }
  5493. Doo::loadModel ( 'invoice' );
  5494. $invoice = new invoice ();
  5495. Doo::loadModel ( 'invoiceOperationLog' );
  5496. $invoiceOperationLog = new invoiceOperationLog ();
  5497. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5498. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5499. Doo::loadModel ( 'invoicePaper' );
  5500. $invoicePaper = new invoicePaper ();
  5501. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5502. if (empty ( $detail ))
  5503. $html = '';
  5504. else {
  5505. $html = '
  5506. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5507. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5508. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5509. <div class="modal-dialog modal-lg">
  5510. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5511. <div class="modal-body saeaList">
  5512. <table class="table table-bordered table-condensed"><tbody>
  5513. <tr>
  5514. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5515. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5516. </tr>
  5517. <tr>
  5518. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5519. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5520. </tr>
  5521. <tr>
  5522. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5523. </td>
  5524. </tr>
  5525. <tr>
  5526. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5527. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5528. </tr>
  5529. <tr>
  5530. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5531. </tr></tbody></table>';
  5532. if ($detail ['invoiceType'] == 0)
  5533. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5534. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5535. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5536. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5537. </tr>';
  5538. else
  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 ['invoiceCompany'] . '</td>
  5542. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5543. ';
  5544. $html .= '<tr>
  5545. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5546. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5547. </tr>
  5548. <tr>
  5549. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5550. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5551. </tr></tbody></table>';
  5552. if ($detail ['doPost'] == 1)
  5553. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5554. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5555. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5556. </tr><tr>
  5557. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5558. </tr><tr>
  5559. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5560. </tr></tbody></table>';
  5561. if (! empty ( $invoiceOperationLogList )) {
  5562. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5563. foreach ( $invoiceOperationLogList as $key => $value ) {
  5564. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5565. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5566. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5567. if ($value ['status'] == 2) {
  5568. $html .= '<span class="colGreen">同意</span>';
  5569. } elseif ($value ['status'] == 3) {
  5570. $html .= '<span class="colOrange">退回</span>';
  5571. } elseif ($value ['status'] == 5) {
  5572. $html .= '<span class="colGreen">打印</span>';
  5573. } elseif ($value ['status'] == 4) {
  5574. $html .= '<span class="colRed">终止</span>';
  5575. }
  5576. $html .= $value ['operation'] . '</p></blockquote>';
  5577. }
  5578. }
  5579. $html .= '</td>
  5580. <td><span class="colRed">*</span>
  5581. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5582. foreach ( $invoicePaperList as $key => $value ) {
  5583. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5584. }
  5585. $html .= '</select>
  5586. <span class="red" id="p-msg"></span>
  5587. </td>
  5588. </tr></tbody></table>';
  5589. }
  5590. $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>
  5591. </div></div></form>
  5592. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5593. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5594. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5595. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5596. ';
  5597. }
  5598. echo json_encode ( array (
  5599. 'status' => 1,
  5600. 'html' => $html
  5601. ) );
  5602. die ();
  5603. }
  5604. /**
  5605. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5606. */
  5607. function ajaxGetInvoiceInfoByType() {
  5608. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5609. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5610. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5611. if (empty ( $serial )) {
  5612. echo json_encode ( array (
  5613. 'status' => 2,
  5614. 'msg' => 'illegal request'
  5615. ) );
  5616. die ();
  5617. }
  5618. if ($type == 'INVOICE') {
  5619. Doo::loadModel ( 'invoice' );
  5620. $invoice = new invoice ();
  5621. Doo::loadModel ( 'invoiceOperationLog' );
  5622. $invoiceOperationLog = new invoiceOperationLog ();
  5623. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5624. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5625. if (empty ( $detail ))
  5626. $html = '';
  5627. else {
  5628. $html = '
  5629. <div class="modal-dialog modal-lg">
  5630. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5631. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5632. <tr>
  5633. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5634. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5635. </tr>
  5636. <tr>
  5637. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5638. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5639. </tr>
  5640. <tr>
  5641. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5642. </td>
  5643. </tr>
  5644. <tr>
  5645. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5646. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5647. </tr>
  5648. <tr>
  5649. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5650. </tr>';
  5651. if ($detail ['settlementType'] == 1)
  5652. $html .= '<tr>
  5653. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5654. </tr>';
  5655. else
  5656. $html .= '<tr>
  5657. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5658. </tr>';
  5659. $html .= ' </tbody></table>';
  5660. if ($detail ['invoiceType'] == 0)
  5661. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5662. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5663. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5664. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5665. </tr>';
  5666. else
  5667. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5668. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5669. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5670. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5671. ';
  5672. $html .= '<tr>
  5673. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5674. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5675. </tr>
  5676. <tr>
  5677. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5678. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5679. </tr></tbody></table>';
  5680. if ($detail ['doPost'] == 1) {
  5681. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5682. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5683. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5684. </tr><tr>
  5685. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5686. </tr><tr>
  5687. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5688. </tr>
  5689. ';
  5690. if ($detail ['expressCom'] == 'SF')
  5691. $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>';
  5692. else
  5693. $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>';
  5694. $html .= '</tbody></table>';
  5695. }
  5696. if (! empty ( $invoiceOperationLogList )) {
  5697. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5698. foreach ( $invoiceOperationLogList as $key => $value ) {
  5699. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5700. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5701. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5702. if ($value ['status'] == 2) {
  5703. $html .= '<span class="colGreen">同意</span>';
  5704. } elseif ($value ['status'] == 3) {
  5705. $html .= '<span class="colOrange">退回</span>';
  5706. } elseif ($value ['status'] == 5) {
  5707. $html .= '<span class="colGreen">打印</span>';
  5708. } elseif ($value ['status'] == 4) {
  5709. $html .= '<span class="colRed">终止</span>';
  5710. }
  5711. $html .= $value ['operation'] . '</p></blockquote>';
  5712. }
  5713. }
  5714. $html .= '</td></tr></tbody></table>';
  5715. }
  5716. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5717. }
  5718. echo json_encode ( array (
  5719. 'status' => 1,
  5720. 'html' => $html
  5721. ) );
  5722. die ();
  5723. } elseif ($type == 'RECEIVABLES') {
  5724. Doo::loadModel ( 'invoiceReceivables' );
  5725. $invoiceReceivables = new invoiceReceivables ();
  5726. Doo::loadModel ( 'invoiceRefund' );
  5727. $invoiceRefund = new invoiceRefund ();
  5728. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5729. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5730. if (empty ( $detail ))
  5731. $html = '';
  5732. else {
  5733. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5734. <table class="table table-bordered table-condensed">
  5735. <tbody><tr>
  5736. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  5737. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  5738. </tr><tr>
  5739. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5740. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  5741. </tr>
  5742. <tr>
  5743. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  5744. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  5745. </tr>
  5746. <tr>
  5747. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  5748. </tr>
  5749. </tbody></table>';
  5750. if (! empty ( $ireList )) {
  5751. $html .= '
  5752. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  5753. <tr>
  5754. <th class="taC">退款单位名称</th>
  5755. <th class="taC">退款的账号</th>
  5756. <th class="taC">退款金额</th>
  5757. <th class="taC">退款</th>
  5758. <th class="taC">备注</th>
  5759. </tr>
  5760. ';
  5761. foreach ( $ireList as $key => $value ) {
  5762. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  5763. $html .= '<tr>
  5764. <td>' . $value ['refundCompany'] . '</td>
  5765. <td>' . $value ['refundNumber'] . '</td>
  5766. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  5767. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  5768. <td>' . $value ['refundRemarks'] . '</td>
  5769. </tr>
  5770. ';
  5771. }
  5772. }
  5773. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5774. }
  5775. echo json_encode ( array (
  5776. 'status' => 1,
  5777. 'html' => $html
  5778. ) );
  5779. die ();
  5780. } elseif ($type == 'IRTC') {
  5781. Doo::loadModel ( 'invoice' );
  5782. $invoice = new invoice ();
  5783. Doo::loadModel ( 'invoiceOperationLog' );
  5784. $invoiceOperationLog = new invoiceOperationLog ();
  5785. Doo::loadModel ( 'invoiceReceivables' );
  5786. $invoiceReceivables = new invoiceReceivables ();
  5787. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5788. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5789. if (empty ( $detail ))
  5790. $html = '';
  5791. else {
  5792. $receivablesPriceedHtml = '';
  5793. $receivablesPrice = $detail ['invoicePrice'];
  5794. if (! empty ( $detail ['irid'] )) {
  5795. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  5796. if (empty ( $irList ))
  5797. $irList [0] ['sumPrice'] = 0;
  5798. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  5799. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  5800. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  5801. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  5802. </tr></tbody></table>';
  5803. $receivablesPrice = $balance;
  5804. }
  5805. if ($loss)
  5806. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  5807. $html = $receivablesPriceedHtml . '
  5808. <table class="table table-bordered table-condensed"><tbody>
  5809. <tr>
  5810. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5811. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5812. </tr>
  5813. <tr>
  5814. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5815. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5816. </tr>
  5817. <tr>
  5818. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  5819. </tr>
  5820. <tr>
  5821. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5822. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5823. </tr>
  5824. <tr>
  5825. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5826. </tr></tbody></table>';
  5827. if ($detail ['invoiceType'] == 0) {
  5828. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5829. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5830. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5831. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5832. </tr>';
  5833. $receivablesMessage = $detail ['invoiceTitle'];
  5834. } else {
  5835. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5836. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5837. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5838. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5839. ';
  5840. $receivablesMessage = $detail ['invoiceCompany'];
  5841. }
  5842. $html .= '<tr>
  5843. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5844. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5845. </tr>
  5846. <tr>
  5847. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  5848. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  5849. </tr></tbody></table>';
  5850. if ($detail ['doPost'] == 1)
  5851. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5852. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5853. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5854. </tr><tr>
  5855. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5856. </tr><tr>
  5857. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5858. </tr></tbody></table>';
  5859. if (! empty ( $invoiceOperationLogList )) {
  5860. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5861. foreach ( $invoiceOperationLogList as $key => $value ) {
  5862. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5863. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5864. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5865. if ($value ['status'] == 2) {
  5866. $html .= '<span class="colGreen">同意</span>';
  5867. } elseif ($value ['status'] == 3) {
  5868. $html .= '<span class="colOrange">退回</span>';
  5869. } elseif ($value ['status'] == 5) {
  5870. $html .= '<span class="colGreen">打印</span>';
  5871. }
  5872. $html .= $value ['operation'] . '</p></blockquote>';
  5873. }
  5874. }
  5875. $html .= '</td></tr></tbody></table>';
  5876. }
  5877. }
  5878. echo json_encode ( array (
  5879. 'status' => 1,
  5880. 'html' => $html,
  5881. 'receivablesPrice' => $receivablesPrice,
  5882. 'receivablesMessage' => $receivablesMessage,
  5883. 'receivablesDate' => date ( "Y-m-d" ),
  5884. 'iidKey' => $serial
  5885. ) );
  5886. die ();
  5887. }
  5888. }
  5889. function ajaxGetInvoiceReceivablesByStaff() {
  5890. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  5891. if (empty ( $postData )) {
  5892. echo json_encode ( array (
  5893. 'status' => 2,
  5894. 'msg' => 'illegal request'
  5895. ) );
  5896. die ();
  5897. }
  5898. Doo::loadModel ( 'invoiceReceivables' );
  5899. $invoiceReceivables = new invoiceReceivables ();
  5900. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  5901. if (empty ( $detail )) {
  5902. echo json_encode ( array (
  5903. 'status' => 2,
  5904. 'msg' => 'illegal request'
  5905. ) );
  5906. die ();
  5907. }
  5908. Doo::loadModel ( 'L_category' );
  5909. $lCategory = new L_category ();
  5910. Doo::loadModel ( 'staff' );
  5911. $staff = new staff ();
  5912. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  5913. $category = $lCategory->getCategory ();
  5914. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  5915. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  5916. foreach ( $category as $key => $value ) {
  5917. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5918. if ($value ['cid'] == $detail ['cid'])
  5919. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5920. }
  5921. foreach ( $staffList as $key => $value ) {
  5922. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5923. if ($value ['sid'] == $detail ['sid'])
  5924. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5925. }
  5926. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  5927. echo json_encode ( array (
  5928. 'status' => 1,
  5929. 'categoryHtml' => $categoryHtml,
  5930. 'staffHtml' => $staffHtml,
  5931. 'rbankHtml' => $rbankHtml,
  5932. 'detail' => $detail
  5933. ) );
  5934. }
  5935. function ajaxGetInvoiceReceivablesByIrid() {
  5936. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  5937. if (empty ( $irid )) {
  5938. echo json_encode ( array (
  5939. 'status' => 2,
  5940. 'msg' => 'illegal request'
  5941. ) );
  5942. die ();
  5943. }
  5944. Doo::loadModel ( 'invoiceReceivables' );
  5945. $invoiceReceivables = new invoiceReceivables ();
  5946. Doo::loadModel ( 'invoice' );
  5947. $invoice = new invoice ();
  5948. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  5949. $flag = true;
  5950. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  5951. $bakDetail = array ();
  5952. if ($flag === false) {
  5953. array_push ( $bakDetail, $invoiceDetail );
  5954. $invoiceDetail = $bakDetail;
  5955. }
  5956. $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>
  5957. <tr>
  5958. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5959. <td>' . $detail ['receivablesMessage'] . '</td>
  5960. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  5961. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  5962. <td>' . $detail ['recepitTitleMark'] . '</td>
  5963. </tr></tbody></table>';
  5964. $isInvoice = false;
  5965. $invoiceHtml = '';
  5966. if (empty ( $invoiceDetail )) {
  5967. $isInvoice = true;
  5968. } else {
  5969. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5970. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  5971. foreach ( $invoiceDetail as $key => $value ) {
  5972. $invoiceHtml .= '<tr>';
  5973. if (! empty ( $value ['invoiceType'] )) {
  5974. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5975. } else {
  5976. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5977. }
  5978. if (! empty ( $value ['invoiceType'] )) {
  5979. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5980. } else {
  5981. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5982. }
  5983. $invoiceHtml .= '
  5984. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5985. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5986. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  5987. </tr>
  5988. ';
  5989. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  5990. if (empty ( $irList ))
  5991. $irList [0] ['sumPrice'] = 0;
  5992. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  5993. $priceString = '';
  5994. if ($balance < $detail ['receivablesPrice']) {
  5995. $priceString = '收款金额超过开票金额,';
  5996. }
  5997. if ($balance > $detail ['receivablesPrice']) {
  5998. $priceString = '收款金额低于开票金额,';
  5999. }
  6000. }
  6001. $invoiceHtml .= '
  6002. <script>
  6003. $(\'a[bind-receivables^="ir"]\').click(function() {
  6004. var data = $(this).attr("data-ikey");
  6005. $("input[name=\'invoiceKey\']").val(data);
  6006. var invoiceKey=data;
  6007. if(invoiceKey==""){
  6008. alert("入账错误,请重新刷新页面");
  6009. return false;
  6010. }
  6011. if(window.confirm("' . $priceString . '确定入账吗?")){
  6012. $("#IBR").submit();
  6013. }else{
  6014. return false;
  6015. }
  6016. });
  6017. </script>
  6018. ';
  6019. $invoiceHtml .= '</tbody></table>';
  6020. }
  6021. echo json_encode ( array (
  6022. 'status' => 1,
  6023. 'irkey' => $detail ['iridEn'],
  6024. 'receivablesHtml' => $receivablesHtml,
  6025. 'isInvoice' => $isInvoice,
  6026. 'invoiceHtml' => $invoiceHtml
  6027. ) );
  6028. }
  6029. function ajaxGetInvoiceReceivablesByTitle() {
  6030. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6031. if (empty ( $title )) {
  6032. echo json_encode ( array (
  6033. 'status' => 2,
  6034. 'msg' => 'illegal request'
  6035. ) );
  6036. die ();
  6037. }
  6038. Doo::loadModel ( 'invoice' );
  6039. $invoice = new invoice ();
  6040. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6041. $invoiceHtml = '';
  6042. if (! empty ( $invoiceDetail )) {
  6043. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6044. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6045. foreach ( $invoiceDetail as $key => $value ) {
  6046. if (! empty ( $value ['invoiceType'] )) {
  6047. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6048. } else {
  6049. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6050. }
  6051. if (! empty ( $value ['invoiceType'] )) {
  6052. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6053. } else {
  6054. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6055. }
  6056. $invoiceHtml .= '
  6057. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6058. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6059. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6060. </tr>
  6061. ';
  6062. }
  6063. $invoiceHtml .= '</tbody></table>
  6064. <script>
  6065. $(\'a[bind-receivables^="ir"]\').click(function() {
  6066. var data = $(this).attr("data-ikey");
  6067. $("input[name=\'invoiceKey\']").val(data);
  6068. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6069. if(invoiceKey==""){
  6070. alert("入账错误,请重新刷新页面");
  6071. return false;
  6072. }
  6073. if(window.confirm("确定入账吗?")){
  6074. $("#IBR").submit();
  6075. }else{
  6076. return false;
  6077. }
  6078. });
  6079. </script>
  6080. ';
  6081. }
  6082. echo json_encode ( array (
  6083. 'status' => 1,
  6084. 'invoiceHtml' => $invoiceHtml
  6085. ) );
  6086. }
  6087. function ajaxInvoicePushNotice() {
  6088. Doo::loadModel ( 'invoice' );
  6089. $invoice = new invoice ();
  6090. $approval = $invoice->getOne ( array (
  6091. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6092. 'desc' => 'iid',
  6093. 'asArray' => true
  6094. ) );
  6095. $isNotice = false;
  6096. if (! empty ( $approval ))
  6097. $isNotice = true;
  6098. $response = array (
  6099. 'error' => 0,
  6100. 'isNotice' => $isNotice
  6101. );
  6102. echo json_encode ( $response );
  6103. exit ();
  6104. }
  6105. public function ajaxCheckInvoiceNoUniqueness() {
  6106. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6107. Doo::loadModel ( 'invoice' );
  6108. $invoice = new invoice ();
  6109. if (! empty ( $invoiceNo )) {
  6110. Doo::loadModel ( 'invoicePaper' );
  6111. $invoicePaper = new invoicePaper ();
  6112. Doo::loadClass ( 'XDeode' );
  6113. $XDeode = new XDeode ( 5 );
  6114. $ipid = $XDeode->decode ( $invoiceNo );
  6115. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6116. $info = $invoice->getOne ( array (
  6117. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6118. 'asArray' => TRUE
  6119. ) );
  6120. if (! empty ( $info )) {
  6121. echo json_encode ( array (
  6122. 'error' => '发票号已存在'
  6123. ) );
  6124. die ();
  6125. } else
  6126. echo json_encode ( array (
  6127. 'ok' => '可以使用!'
  6128. ) );
  6129. die ();
  6130. }
  6131. }
  6132. function ajaxCheckInvoicePrice() {
  6133. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6134. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6135. Doo::loadModel ( 'invoice' );
  6136. $invoice = new invoice ();
  6137. Doo::loadModel ( 'invoiceReceivables' );
  6138. $invoiceReceivables = new invoiceReceivables ();
  6139. Doo::loadClass ( 'XDeode' );
  6140. $XDeode = new XDeode ( 5 );
  6141. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6142. $iidKey = $XDeode->decode ( $iidKey );
  6143. $info = $invoice->getInvoiceByIid ( $iidKey );
  6144. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6145. if (empty ( $irList ))
  6146. $irList [0] ['sumPrice'] = 0;
  6147. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6148. if ($balance < $receivablesPrice) {
  6149. echo json_encode ( array (
  6150. 'error' => '收款金额超过开票金额。'
  6151. ) );
  6152. die ();
  6153. }
  6154. if ($balance > $receivablesPrice) {
  6155. echo json_encode ( array (
  6156. 'error' => '收款金额低于开票金额。'
  6157. ) );
  6158. die ();
  6159. }
  6160. }
  6161. }
  6162. function ajaxGetInvoiceByNew(){
  6163. Doo::loadModel ( 'invoice' );
  6164. $invoice = new invoice ();
  6165. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  6166. echo json_encode ( array (
  6167. 'status' => 1,
  6168. 'detail' => $detail
  6169. ) );
  6170. }
  6171. /**
  6172. * 旧输入导入
  6173. */
  6174. function importInvoice() {
  6175. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6176. $data ['emsg'] = "";
  6177. if ($emsg != "")
  6178. $data ['emsg'] = "请填写完整的数据";
  6179. $data ['time'] = time ();
  6180. $this->render ( "/admin/invoiceImport", $data );
  6181. }
  6182. function uploadInvoice() {
  6183. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6184. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6185. $file = $_FILES ['Filedata'] ['tmp_name'];
  6186. $error = false;
  6187. if (! is_uploaded_file ( $file )) {
  6188. $error = '400 Bad Request';
  6189. }
  6190. if ($error) {
  6191. header ( 'HTTP/1.0 ' . $error );
  6192. die ( 'Error ' . $error );
  6193. } else {
  6194. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6195. $this->IoHandler = new IoHandler ();
  6196. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6197. // $filedir=$_POST['time'];
  6198. // 调用定义物理路径
  6199. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6200. $this->IoHandler->MakeDir ( $t );
  6201. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6202. if ($filename != 'xlsx')
  6203. return "";
  6204. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6205. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6206. $upload_dir = $t . "/" . $upload_file;
  6207. $k = move_uploaded_file ( $file, $upload_dir );
  6208. if ($k) {
  6209. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6210. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6211. }
  6212. }
  6213. }
  6214. }
  6215. function importInvoiceDo() {
  6216. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6217. if ($path != "") {
  6218. Doo::loadModel ( 'invoice' );
  6219. Doo::loadModel ( 'staff' );
  6220. $staff = new staff ();
  6221. Doo::loadModel ( 'invoiceStatistics' );
  6222. Doo::loadModel ( 'invoiceOperationLog' );
  6223. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6224. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6225. // print_r ( $exlArray );
  6226. // die ();
  6227. // echo json_encode($exlArray);die;
  6228. foreach ( $exlArray as $key => $value ) {
  6229. // 开票
  6230. $invoice = new invoice ();
  6231. $invoice->invoiceNo = $value ['invoiceNo'];
  6232. $invoice->invoiceType = 0;
  6233. if ($value ['invoiceType'] == '专')
  6234. $invoice->invoiceType = 1;
  6235. $invoice->invoicePrice = $value ['invoicePrice'];
  6236. $invoice->invoiceQuantity = 1;
  6237. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6238. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6239. if ($value ['invoiceType'] == '专')
  6240. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6241. $invoice->userName = $value ['userName'];
  6242. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6243. $invoice->sid = $sDetail ['sid'];
  6244. $invoice->cid = $sDetail ['cid'];
  6245. $invoice->categoryName = $sDetail ['category'];
  6246. $invoice->invoiceElement = $value ['invoiceElement'];
  6247. $invoice->remark = $value ['remark'];
  6248. $invoice->date = $value ['date'];
  6249. $invoice->printTime = $value ['date'];
  6250. $invoice->ipSource = 1;
  6251. $invoice->printStatus = 1;
  6252. $invoice->status = 2;
  6253. $invoice->postStatus = 1;
  6254. $invoice->untreadStatus = 0;
  6255. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6256. $iid = $invoice->insert ();
  6257. // 汇总
  6258. $invoiceStatistics = new invoiceStatistics ();
  6259. //
  6260. $item = array (
  6261. 'date' => $value ['date'],
  6262. 'priceClass' => 1,
  6263. 'cid' => $sDetail ['cid'],
  6264. 'staff' => $sDetail ['sid'],
  6265. 'invoicePrice' => $value ['invoicePrice']
  6266. );
  6267. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6268. $invoiceOperationLog = new invoiceOperationLog ();
  6269. $item = array (
  6270. 'date' => date ( "Y-m-d H:i:s" ),
  6271. 'operation' => date ( "Y-m-d" ) . " 导入",
  6272. 'status' => 1,
  6273. 'img' => $sDetail ['avatar'],
  6274. 'username' => $sDetail ['username'],
  6275. 'uid' => $sDetail ['sid'],
  6276. 'category' => $sDetail ['category'],
  6277. 'iid' => $iid
  6278. );
  6279. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6280. }
  6281. return '/importInvoice?count=' . count ( $exlArray );
  6282. // return "/keyonline";
  6283. }
  6284. echo 'no file';
  6285. }
  6286. function importInvoiceReceivables() {
  6287. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6288. $data ['emsg'] = "";
  6289. if ($emsg != "")
  6290. $data ['emsg'] = "请填写完整的数据";
  6291. $data ['time'] = time ();
  6292. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6293. }
  6294. // 导入入账数据
  6295. function importInvoiceReceivablesDo() {
  6296. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6297. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6298. if ($path != "") {
  6299. Doo::loadModel ( 'invoiceReceivables' );
  6300. Doo::loadModel ( 'invoice' );
  6301. Doo::loadModel ( 'staff' );
  6302. $staff = new staff ();
  6303. Doo::loadModel ( 'invoiceStatistics' );
  6304. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6305. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6306. // print_r ( $exlArray );
  6307. // die ();
  6308. // echo json_encode($exlArray);die;
  6309. foreach ( $exlArray as $key => $value ) {
  6310. // 收款
  6311. $invoiceReceivables = new invoiceReceivables ();
  6312. $invoice = new invoice ();
  6313. $invoiceReceivables->bindStatus = 1;
  6314. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6315. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6316. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6317. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6318. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6319. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6320. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6321. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6322. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6323. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6324. $invoiceReceivables->iid = $iDetail ['iid'];
  6325. $irid = $invoiceReceivables->insert ();
  6326. // 发票绑定收款
  6327. $detail = $iDetail;
  6328. $iridString = "";
  6329. if (empty ( $detail ['irid'] ))
  6330. $iridString = $irid;
  6331. else
  6332. $iridString = $detail ['irid'] . ',' . $irid;
  6333. $item = array (
  6334. 'irid' => $iridString,
  6335. 'iid' => $detail ['iid']
  6336. );
  6337. $invoice->setInvoiceByCondition ( $item );
  6338. // 汇总
  6339. $invoiceStatistics = new invoiceStatistics ();
  6340. // 扣除入账统计金额
  6341. $item = array (
  6342. 'date' => $value ['receivablesDate'],
  6343. 'priceClass' => 3,
  6344. 'cid' => $sDetail ['cid'],
  6345. 'staff' => $sDetail ['sid'],
  6346. // 'irid' => $irid,
  6347. 'accountPrice' => $value ['receivablesPrice']
  6348. );
  6349. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6350. }
  6351. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6352. echo 'data count ' . count ( $exlArray );
  6353. die ();
  6354. // return "/keyonline";
  6355. }
  6356. echo 'no file';
  6357. }
  6358. function formatExcelToArrayTrain($file_url = "") {
  6359. if (! file_exists ( $file_url )) {
  6360. return array ();
  6361. }
  6362. // Doo::loadClass ( 'PHPExcel' );
  6363. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6364. $PHPExcel = new PHPExcel ();
  6365. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6366. if (! $PHPReader->canRead ( $file_url )) {
  6367. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6368. if (! $PHPReader->canRead ( $file_url )) {
  6369. echo 'no Excel';
  6370. return;
  6371. }
  6372. }
  6373. $PHPExcel = $PHPReader->load ( $file_url );
  6374. /* * 读取excel文件中的第一个工作表 */
  6375. $currentSheet = $PHPExcel->getSheet ( 0 );
  6376. /* * 取得最大的列号 */
  6377. $allColumn = $currentSheet->getHighestColumn ();
  6378. /* * 取得一共有多少行 */
  6379. $allRow = $currentSheet->getHighestRow ();
  6380. $excel_array = array ();
  6381. // die($file_url);
  6382. $conk = 2;
  6383. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6384. $excel_column = array ();
  6385. // 后期改进
  6386. if ($allColumn == 'AM')
  6387. $allColumn = 'Z';
  6388. /* * 从第A列开始输出 */
  6389. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6390. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6391. if ($val instanceof PHPExcel_RichText)
  6392. $val = $val->__toString ();
  6393. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6394. // $val = "'" . addslashes ( $val ) . "'";
  6395. if ($currentColumn == 'A') {
  6396. $excel_column ['invoiceTitle'] = $val;
  6397. } elseif ($currentColumn == 'B')
  6398. $excel_column ['invoiceType'] = $val;
  6399. elseif ($currentColumn == 'C') {
  6400. $excel_column ['TIN'] = $val;
  6401. } elseif ($currentColumn == 'D') {
  6402. $excel_column ['address'] = $val;
  6403. } elseif ($currentColumn == 'E') {
  6404. $excel_column ['phone'] = $val;
  6405. } elseif ($currentColumn == 'F') {
  6406. $excel_column ['bank'] = $val;
  6407. } elseif ($currentColumn == 'G') {
  6408. $excel_column ['bankAccount'] = $val;
  6409. } elseif ($currentColumn == 'H') {
  6410. $excel_column ['invoiceElement'] = $val;
  6411. } elseif ($currentColumn == 'I') {
  6412. $excel_column ['invoiceQuantity'] = $val;
  6413. } elseif ($currentColumn == 'J') {
  6414. $excel_column ['invoiceUnitPrice'] = $val;
  6415. } elseif ($currentColumn == 'K') {
  6416. $excel_column ['remark'] = $val;
  6417. } elseif ($currentColumn == 'L') {
  6418. $excel_column ['recipientsAddress'] = $val;
  6419. } elseif ($currentColumn == 'M') {
  6420. $excel_column ['recipients'] = $val;
  6421. } elseif ($currentColumn == 'N') {
  6422. $excel_column ['recipientsPhone'] = $val;
  6423. }
  6424. }
  6425. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6426. array_push ( $excel_array, $excel_column );
  6427. }
  6428. return $excel_array;
  6429. }
  6430. /**
  6431. * 格式化excel文件为数组
  6432. * @param unknown_type $file_url
  6433. * @param unknown_type $mcid
  6434. */
  6435. function _format_excel_to_array($file_url = "", $sType = "") {
  6436. if (! file_exists ( $file_url )) {
  6437. return array ();
  6438. }
  6439. Doo::loadClass ( 'PHPExcel' );
  6440. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6441. $PHPExcel = new PHPExcel ();
  6442. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6443. if (! $PHPReader->canRead ( $file_url )) {
  6444. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6445. if (! $PHPReader->canRead ( $file_url )) {
  6446. echo 'no Excel';
  6447. return;
  6448. }
  6449. }
  6450. $PHPExcel = $PHPReader->load ( $file_url );
  6451. /* * 读取excel文件中的第一个工作表 */
  6452. $currentSheet = $PHPExcel->getSheet ( 0 );
  6453. /* * 取得最大的列号 */
  6454. $allColumn = $currentSheet->getHighestColumn ();
  6455. /* * 取得一共有多少行 */
  6456. $allRow = $currentSheet->getHighestRow ();
  6457. $excel_array = array ();
  6458. // die($file_url);
  6459. $conk = 2;
  6460. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6461. $excel_column = array ();
  6462. // 后期改进
  6463. if ($allColumn == 'AM')
  6464. $allColumn = 'Z';
  6465. /* * 从第A列开始输出 */
  6466. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6467. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6468. if ($val instanceof PHPExcel_RichText)
  6469. $val = $val->__toString ();
  6470. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6471. // $val = "'" . addslashes ( $val ) . "'";
  6472. if ($sType == 'invoiceReceivables') {
  6473. if ($currentColumn == 'A')
  6474. $excel_column ['invoiceNo'] = $val;
  6475. elseif ($currentColumn == 'B')
  6476. $excel_column ['receivablesPrice'] = $val;
  6477. elseif ($currentColumn == 'C') {
  6478. $excel_column ['receivablesMessage'] = $val;
  6479. } elseif ($currentColumn == 'D') {
  6480. $excel_column ['receivablesBank'] = $val;
  6481. } elseif ($currentColumn == 'E') {
  6482. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6483. } elseif ($currentColumn == 'F') {
  6484. $excel_column ['receivablesStaff'] = $val;
  6485. } elseif ($currentColumn == 'G') {
  6486. $excel_column ['sourcePrice'] = $val;
  6487. }
  6488. } elseif ($sType == "invoiceTrain") {
  6489. if ($currentColumn == 'A') {
  6490. $excel_column ['invoiceTitle'] = $val;
  6491. } elseif ($currentColumn == 'B')
  6492. $excel_column ['invoiceType'] = $val;
  6493. elseif ($currentColumn == 'C') {
  6494. $excel_column ['TIN'] = $val;
  6495. } elseif ($currentColumn == 'D') {
  6496. $excel_column ['address'] = $val;
  6497. } elseif ($currentColumn == 'E') {
  6498. $excel_column ['phone'] = $val;
  6499. } elseif ($currentColumn == 'F') {
  6500. $excel_column ['bank'] = $val;
  6501. } elseif ($currentColumn == 'G') {
  6502. $excel_column ['bankAccount'] = $val;
  6503. } elseif ($currentColumn == 'H') {
  6504. $excel_column ['invoiceElement'] = $val;
  6505. } elseif ($currentColumn == 'I') {
  6506. $excel_column ['invoiceQuantity'] = $val;
  6507. } elseif ($currentColumn == 'J') {
  6508. $excel_column ['invoiceUnitPrice'] = $val;
  6509. } elseif ($currentColumn == 'K') {
  6510. $excel_column ['remark'] = $val;
  6511. } elseif ($currentColumn == 'L') {
  6512. $excel_column ['recipientsAddress'] = $val;
  6513. } elseif ($currentColumn == 'M') {
  6514. $excel_column ['recipients'] = $val;
  6515. } elseif ($currentColumn == 'N') {
  6516. $excel_column ['recipientsPhone'] = $val;
  6517. }
  6518. } else {
  6519. if ($currentColumn == 'A')
  6520. $excel_column ['invoiceNo'] = $val;
  6521. elseif ($currentColumn == 'B')
  6522. $excel_column ['invoiceType'] = $val;
  6523. elseif ($currentColumn == 'C') {
  6524. $excel_column ['invoicePrice'] = $val;
  6525. } elseif ($currentColumn == 'D') {
  6526. $excel_column ['invoiceTitle'] = $val;
  6527. } elseif ($currentColumn == 'E') {
  6528. $excel_column ['userName'] = $val;
  6529. } elseif ($currentColumn == 'F') {
  6530. $excel_column ['categoryName'] = $val;
  6531. } elseif ($currentColumn == 'G') {
  6532. $excel_column ['invoiceElement'] = $val;
  6533. } elseif ($currentColumn == 'H') {
  6534. $excel_column ['remark'] = $val;
  6535. } elseif ($currentColumn == 'I') {
  6536. $excel_column ['date'] = $this->excelTime ( $val );
  6537. }
  6538. }
  6539. }
  6540. array_push ( $excel_array, $excel_column );
  6541. }
  6542. return $excel_array;
  6543. }
  6544. function excelTime($date, $time = false) {
  6545. if (function_exists ( 'GregorianToJD' )) {
  6546. if (is_numeric ( $date )) {
  6547. $jd = GregorianToJD ( 1, 1, 1970 );
  6548. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6549. $date = explode ( '/', $gregorian );
  6550. $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" : '');
  6551. return $date_str;
  6552. }
  6553. } else {
  6554. $date = $date > 25568 ? $date + 1 : 25569;
  6555. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6556. $ofs = (70 * 365 + 17 + 2) * 86400;
  6557. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6558. }
  6559. return $date;
  6560. }
  6561. /**
  6562. * 旧输入导入
  6563. */
  6564. function _GetFileEXT($filename) {
  6565. $pics = explode ( '.', $filename );
  6566. $num = count ( $pics );
  6567. return $pics [$num - 1];
  6568. }
  6569. function showCache($path = "", $sid = 0) {
  6570. // if (file_exists ( $path )) {
  6571. // $htm = file_get_contents ( $path );
  6572. // } else {
  6573. Doo::loadModel ( 'invoiceStatistics' );
  6574. $invoiceStatistics = new invoiceStatistics ();
  6575. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6576. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6577. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6578. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6579. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6580. /*
  6581. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6582. */
  6583. file_put_contents ( $path, $htm );
  6584. // }
  6585. return $htm;
  6586. }
  6587. /**
  6588. * 获取get或者POST值
  6589. *
  6590. * @param string $name 属性名称
  6591. * @return fixed 值
  6592. */
  6593. function get_args($name) {
  6594. if (isset ( $_GET [$name] )) {
  6595. if (is_array ( $_GET [$name] ))
  6596. return $_GET [$name];
  6597. else
  6598. return addslashes ( $_GET [$name] );
  6599. } elseif (isset ( $_POST [$name] )) {
  6600. if (is_array ( $_POST [$name] ))
  6601. return $_POST [$name];
  6602. else
  6603. return addslashes ( $_POST [$name] );
  6604. } else
  6605. return false;
  6606. }
  6607. function SafeFilter(&$arr) {
  6608. $ra = Array (
  6609. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6610. '/script/',
  6611. '/javascript/',
  6612. '/vbscript/',
  6613. '/expression/',
  6614. '/applet/',
  6615. '/meta/',
  6616. '/xml/',
  6617. '/blink/',
  6618. '/link/',
  6619. '/style/',
  6620. '/embed/',
  6621. '/object/',
  6622. '/frame/',
  6623. '/layer/',
  6624. '/title/',
  6625. '/bgsound/',
  6626. '/base/',
  6627. '/onload/',
  6628. '/onunload/',
  6629. '/onchange/',
  6630. '/onsubmit/',
  6631. '/onreset/',
  6632. '/onselect/',
  6633. '/onblur/',
  6634. '/onfocus/',
  6635. '/onabort/',
  6636. '/onkeydown/',
  6637. '/onkeypress/',
  6638. '/onkeyup/',
  6639. '/onclick/',
  6640. '/ondblclick/',
  6641. '/onmousedown/',
  6642. '/onmousemove/',
  6643. '/onmouseout/',
  6644. '/onmouseover/',
  6645. '/onmouseup/',
  6646. '/onunload/'
  6647. );
  6648. if (is_array ( $arr )) {
  6649. foreach ( $arr as $key => $value ) {
  6650. if (! is_array ( $value )) {
  6651. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6652. {
  6653. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6654. }
  6655. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6656. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6657. } else {
  6658. SafeFilter ( $arr [$key] );
  6659. }
  6660. }
  6661. }
  6662. }
  6663. /**
  6664. * Escape String
  6665. *
  6666. * @access public
  6667. * @param string
  6668. * @param bool whether or not the string will be used in a LIKE condition
  6669. * @return string
  6670. */
  6671. function escape_str($str, $like = FALSE) {
  6672. if (is_array ( $str )) {
  6673. foreach ( $str as $key => $val ) {
  6674. $str [$key] = $this->escape_str ( $val, $like );
  6675. }
  6676. return $str;
  6677. }
  6678. var_dump ( Doo::db ()->getDbObject () );
  6679. die ();
  6680. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6681. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6682. } elseif (function_exists ( 'mysql_escape_string' )) {
  6683. $str = mysql_escape_string ( $str );
  6684. } else {
  6685. $str = addslashes ( $str );
  6686. }
  6687. // escape LIKE condition wildcards
  6688. if ($like === TRUE) {
  6689. $str = str_replace ( array (
  6690. '%',
  6691. '_'
  6692. ), array (
  6693. '\\%',
  6694. '\\_'
  6695. ), $str );
  6696. }
  6697. return $str;
  6698. }
  6699. /**
  6700. * 获得分页数据
  6701. * @param unknown_type $table
  6702. * @param unknown_type $condition
  6703. * @param unknown_type $on_page
  6704. * @param unknown_type $page_size
  6705. */
  6706. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6707. $page_c = "";
  6708. $page ['previous'] = $this->get_previous ( $on_page );
  6709. $page ['on_page'] = $on_page;
  6710. $total_count = $this->get_table_count ( $table, $condition );
  6711. $total = intval ( $total_count / $page_size );
  6712. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6713. $page ['total_data'] = $total_count;
  6714. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6715. $i = 1;
  6716. $page_max = 1;
  6717. $page_width = 3;
  6718. if ($on_page >= $page_width) {
  6719. $page_max = intval ( $on_page / $page_width ) + 1;
  6720. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6721. }
  6722. for(; $i <= $page ['total_page']; $i ++) {
  6723. if ($i == $on_page)
  6724. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6725. else
  6726. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6727. if ($i == ($page_width * $page_max))
  6728. break;
  6729. }
  6730. $page ['page'] = $page_c;
  6731. $page ['lower'] = (-- $on_page) * $page_size;
  6732. return $page;
  6733. }
  6734. /**
  6735. * 获取上一页
  6736. * @param unknown_type $on_page
  6737. */
  6738. function get_previous($on_page = 1) {
  6739. return $on_page != 0 ? $on_page - 1 : $on_page;
  6740. }
  6741. /**
  6742. * 获取总页数
  6743. * @param unknown_type $table
  6744. * @param unknown_type $condition
  6745. */
  6746. public function get_table_count($table = "", $condition = "") {
  6747. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6748. $sql = "select count(*) as count from " . $table . " where " . $condition;
  6749. // echo $sql;die;
  6750. $query = Doo::db ()->query ( $sql );
  6751. $result = $query->fetch ();
  6752. return $result ['count'];
  6753. }
  6754. /**
  6755. * 获得分页数据
  6756. * @param unknown_type $table
  6757. * @param unknown_type $condition
  6758. * @param unknown_type $on_page
  6759. * @param unknown_type $page_size
  6760. */
  6761. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6762. $page_c = "";
  6763. $page ['previous'] = $this->get_previous ( $on_page );
  6764. $page ['on_page'] = $on_page;
  6765. $total_count = $this->getTableCountBySql ( $sql );
  6766. $total = intval ( $total_count / $page_size );
  6767. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6768. $page ['total_data'] = $total_count;
  6769. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6770. $i = 1;
  6771. $page_max = 1;
  6772. $page_width = 3;
  6773. if ($on_page >= $page_width) {
  6774. $page_max = intval ( $on_page / $page_width ) + 1;
  6775. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6776. }
  6777. for(; $i <= $page ['total_page']; $i ++) {
  6778. if ($i == $on_page)
  6779. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6780. else
  6781. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6782. if ($i == ($page_width * $page_max))
  6783. break;
  6784. }
  6785. $page ['page'] = $page_c;
  6786. $page ['lower'] = (-- $on_page) * $page_size;
  6787. return $page;
  6788. }
  6789. /**
  6790. * 获得总页数 sql
  6791. * @param string $type
  6792. * @return boolean[]
  6793. */
  6794. public function getTableCountBySql($sql = "") {
  6795. $query = Doo::db ()->query ( $sql );
  6796. $result = $query->fetchAll ();
  6797. return count ( $result );
  6798. }
  6799. function isInvoiceNew($type = "GLOBAL") {
  6800. Doo::loadModel ( 'invoice' );
  6801. $invoice = new invoice ();
  6802. Doo::loadModel ( 'invoiceReceivables' );
  6803. $invoiceReceivables = new invoiceReceivables ();
  6804. Doo::loadModel ( 'staff' );
  6805. $staff = new staff ();
  6806. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  6807. // 我的发票待处理
  6808. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  6809. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  6810. 'desc' => 'iid',
  6811. 'asArray' => TRUE
  6812. ) );
  6813. // 我的收款待入账
  6814. /*
  6815. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  6816. */
  6817. // 发票审批
  6818. $approval = $invoice->getOne ( array (
  6819. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  6820. 'desc' => 'iid',
  6821. 'asArray' => true
  6822. ) );
  6823. // 发票邮寄
  6824. $post = $invoice->getOne ( array (
  6825. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  6826. 'asArray' => TRUE
  6827. ) );
  6828. // 发票打印
  6829. $print = $invoice->getOne ( array (
  6830. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  6831. 'desc' => 'iid',
  6832. 'asArray' => TRUE
  6833. ) );
  6834. // 发票退票 printStatus=1 and
  6835. $untread = $invoice->getOne ( array (
  6836. 'where' => " untreadStatus=1 and status=2 ",
  6837. 'asArray' => TRUE
  6838. ) );
  6839. $new = array (
  6840. 'GLOBAL' => FALSE,
  6841. 'pendingInvoice' => FALSE,
  6842. // 'myClaim' => FALSE,
  6843. 'approval' => FALSE,
  6844. 'post' => FALSE,
  6845. 'print' => FALSE,
  6846. 'untread' => FALSE
  6847. );
  6848. // || ! empty ( $myClaim )
  6849. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  6850. $new ['GLOBAL'] = TRUE;
  6851. if (! empty ( $pendingInvoice ))
  6852. $new ['pendingInvoice'] = TRUE;
  6853. // if (! empty ( $myClaim ))
  6854. // $new ['myClaim'] = TRUE;
  6855. if (! empty ( $approval ))
  6856. $new ['approval'] = TRUE;
  6857. if (! empty ( $post ))
  6858. $new ['post'] = TRUE;
  6859. if (! empty ( $print ))
  6860. $new ['print'] = TRUE;
  6861. if (! empty ( $untread ))
  6862. $new ['untread'] = TRUE;
  6863. return $new;
  6864. }
  6865. function setWXMsg($rid, $typeMsg = '') {
  6866. Doo::loadModel ( 'invoice' );
  6867. $invoice = new invoice ();
  6868. $invoiceDetail = $invoice->getOne ( array (
  6869. 'where' => 'iid=' . $rid,
  6870. 'asArray' => true
  6871. ) );
  6872. if (! empty ( $invoiceDetail )) {
  6873. Doo::loadModel ( 'staff' );
  6874. $staff = new staff ();
  6875. $staffmsg = $staff->getOne ( array (
  6876. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  6877. 'asArray' => TRUE
  6878. ) );
  6879. if (! empty ( $staffmsg ['wxid'] )) {
  6880. require_once (SITE_PATH . '/protected/class/client.php');
  6881. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  6882. $user = $staffmsg ['wxid'];
  6883. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  6884. if (empty ( $expCom ))
  6885. $expCom [0] = '';
  6886. $msg = "";
  6887. if (empty ( $typeMsg ))
  6888. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  6889. elseif ($typeMsg == "PRINT")
  6890. $msg = '太好了,您的发票已打印完成。';
  6891. $result = $client->SendMsg ( $user, $msg, 'text' );
  6892. }
  6893. }
  6894. }
  6895. /**
  6896. * 获取微信部门
  6897. * @param string $category
  6898. * @return number|mixed
  6899. */
  6900. function getToparty($category = '') {
  6901. $token = $this->getAccessToken (); //
  6902. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  6903. $toparty = 0;
  6904. foreach ( $result ['department'] as $key => $value ) {
  6905. if ($value ['name'] == $category)
  6906. $toparty = $value ['id'];
  6907. }
  6908. return $toparty;
  6909. }
  6910. /**
  6911. * 获得某部门下的用户
  6912. * @param string $toparty
  6913. */
  6914. function getUserByToparty($toparty = '') {
  6915. $token = $this->getAccessToken (); //
  6916. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  6917. $userList = array ();
  6918. foreach ( $result ['userlist'] as $key => $value ) {
  6919. array_push ( $userList, "'" . $value ['userid'] . "'" );
  6920. }
  6921. return $userList;
  6922. }
  6923. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  6924. $token = $this->getAccessToken ();
  6925. if ($text == 'text') {
  6926. $data = '{
  6927. "touser": "' . $toparty . '",
  6928. "toparty": "",
  6929. "totag": "",
  6930. "msgtype": "text",
  6931. "agentid": 1000002,
  6932. "text": {
  6933. "content": "' . $msg . '"
  6934. },
  6935. "safe":0
  6936. }';
  6937. }
  6938. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6939. if ($result->errmsg != 'ok') {
  6940. return 0;
  6941. } else {
  6942. return 1;
  6943. }
  6944. }
  6945. /**
  6946. * 获得可以发送微信用户列表
  6947. * @param string $category
  6948. * @return string
  6949. */
  6950. function getWxidByCategory($category = "") {
  6951. if (empty ( $category ))
  6952. return "";
  6953. Doo::loadModel ( 'staff' );
  6954. $staff = new staff ();
  6955. $toparty = $this->getToparty ( $category );
  6956. $wxList = array ();
  6957. $wxString = "";
  6958. if (! empty ( $toparty )) {
  6959. $userList = $this->getUserByToparty ( $toparty );
  6960. $userCon = implode ( ',', $userList );
  6961. // echo $userCon;
  6962. $sidList = $staff->getStaffByWxid ( $userCon );
  6963. foreach ( $sidList as $key => $value ) {
  6964. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  6965. if ($falg) {
  6966. array_push ( $wxList, $value ['wxid'] );
  6967. }
  6968. }
  6969. $wxString = implode ( '|', $wxList );
  6970. }
  6971. return $wxString;
  6972. }
  6973. /**
  6974. * 读取发送信息规则判断是否需要发送
  6975. * @param number $sid
  6976. * @param string $sendType
  6977. * @return boolean
  6978. */
  6979. function isSendNotification($sid = 0, $sendType = '') {
  6980. Doo::loadModel ( "notificationConf" );
  6981. $notificationConf = new notificationConf ();
  6982. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  6983. $conf = array ();
  6984. $sendFlag = true;
  6985. if (! empty ( $detail )) {
  6986. $conf = json_decode ( $detail ['conf'], true );
  6987. if (! empty ( $sendType )) {
  6988. if (isset ( $conf [$sendType] )) {
  6989. if ($conf [$sendType] == "CLOSE")
  6990. $sendFlag = false;
  6991. elseif ($conf [$sendType] == "Weekend") {
  6992. $day = date ( "w" );
  6993. if (1 <= $day && 5 >= $day)
  6994. $sendFlag = false;
  6995. } elseif ($conf [$sendType] == "OneToFriday") {
  6996. $day = date ( "w" );
  6997. if (0 == $day || 6 == $day)
  6998. $sendFlag = false;
  6999. }
  7000. }
  7001. } else
  7002. $sendFlag = false;
  7003. }
  7004. return $sendFlag;
  7005. }
  7006. /**
  7007. * 根据规则发送信息
  7008. * @param unknown $msg
  7009. * @param unknown $title
  7010. * @param unknown $url
  7011. * @param unknown $user
  7012. * @param string $text
  7013. * @return number
  7014. */
  7015. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7016. $token = $this->getAccessToken ();
  7017. $falg = $this->isSendNotification ( $sid, $sendType );
  7018. // if ($text == 'text') {
  7019. // $data = '{
  7020. // "touser": "' . $user . '",
  7021. // "toparty": "",
  7022. // "totag": "",
  7023. // "msgtype": "text",
  7024. // "agentid": 1000002,
  7025. // "text": {
  7026. // "content": "' . $msg . '"
  7027. // },
  7028. // "safe":0
  7029. // }';
  7030. // } else {
  7031. $data = '{
  7032. "touser": "' . $user . '",
  7033. "toparty": "",
  7034. "totag": "",
  7035. "msgtype": "news",
  7036. "agentid": 1000002,
  7037. "news": {
  7038. "articles":[
  7039. {
  7040. "title": "' . $title . '",
  7041. "description": "' . $msg . '",
  7042. "url": "' . $url . '",
  7043. "picurl": ""
  7044. }
  7045. ]
  7046. }
  7047. }';
  7048. // }
  7049. if ($falg) {
  7050. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7051. if ($result->errmsg != 'ok') {
  7052. return 0;
  7053. } else {
  7054. return 1;
  7055. }
  7056. } else
  7057. return 0;
  7058. }
  7059. private function getAccessToken() {
  7060. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7061. // $file = './access_token.txt';
  7062. // $data = json_decode ( file_get_contents ( $file ) );
  7063. // if ($data->expire_time < time () or ! $data->expire_time) {
  7064. // 如果是企业号用以下URL获取access_token
  7065. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7066. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7067. $res = json_decode ( $this->httpGet ( $url ) );
  7068. $access_token = $res->access_token;
  7069. // echo $access_token;
  7070. // if ($access_token) {
  7071. // $data->expire_time = time () + 7000;
  7072. // $data->access_token = $access_token;
  7073. // $fp = fopen ( $file, "w" );
  7074. // fwrite ( $fp, json_encode ( $data ) );
  7075. // fclose ( $fp );
  7076. // }
  7077. // } else {
  7078. // $access_token = $data->access_token;
  7079. // }
  7080. return $access_token;
  7081. }
  7082. private function httpGet($url) {
  7083. $curl = curl_init ();
  7084. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7085. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7086. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7087. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7088. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7089. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7090. curl_setopt ( $curl, CURLOPT_URL, $url );
  7091. $res = curl_exec ( $curl );
  7092. curl_close ( $curl );
  7093. return $res;
  7094. }
  7095. private function httpPost($url, $data) {
  7096. $curl = curl_init ();
  7097. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7098. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7099. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7100. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7101. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7102. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7103. curl_setopt ( $curl, CURLOPT_URL, $url );
  7104. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7105. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7106. $res = curl_exec ( $curl );
  7107. curl_close ( $curl );
  7108. return $res;
  7109. }
  7110. }
  7111. ?>