InvoiceController.php 275 KB

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