InvoiceController.php 259 KB

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