InvoiceController.php 251 KB

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