InvoiceController.php 307 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397
  1. <?php
  2. /**
  3. * 开票功能控制器
  4. * @author CP
  5. * @version 1.0
  6. * @namespace invoice
  7. * @package invoiceController
  8. */
  9. class InvoiceController extends DooController {
  10. public $staff;
  11. public $NEW;
  12. public $data;
  13. private $INVOICEKEY = "APPROVAL";
  14. private $INVOICECOLLECTPATH = "protected/cache/invoiceCollect/";
  15. private $ACTION = '';
  16. private $appId = 'wx3ee46531947a1384';
  17. private $appSecret = 'awGWzy3J5q_96VXKBLA2BQ9RpiT0LiPXnkMF-xV6h5o'; // awGWzy3J5q_96VXKBLA2BXU6mVCGynPGD-sxUCsdNDE //'PeiQVH8tbQE7pM9pVO4AIPlX9FFNpwu7O6Iy6VFcAVtpjTA3Qn42dbNmktBFkUHo';
  18. public function beforeRun($resource, $action) {
  19. Doo::loadModel ( "invoiceManage" );
  20. $invoiceManage = new invoiceManage ();
  21. Doo::loadClass ( 'XDeode' );
  22. $XDeode = new XDeode ( 5 );
  23. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  24. header ( 'Content-Type:text/html;charset=utf-8' );
  25. $moldList = $invoiceManage->getInvoiceByStaff ( $sid );
  26. if (empty ( $moldList )) {
  27. $flag = false;
  28. $uGroups = 'ordinary';
  29. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  30. $flag = true;
  31. }
  32. } else {
  33. $flag = false;
  34. array_push ( $moldList, array (
  35. 'mold' => 'ordinary'
  36. ) );
  37. // 删除审批人后-加入权限问题-暂时关闭
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fiML = json_decode ( $fileInvoice, true );
  40. if (empty ( $fiML ))
  41. $fiML = array ();
  42. foreach ( $fiML as $key => $value ) {
  43. $sidList = explode ( ',', $value );
  44. foreach ( $sidList as $k => $v ) {
  45. if ($v == $sid) {
  46. array_push ( $moldList, array (
  47. 'mold' => $key
  48. ) );
  49. break;
  50. }
  51. }
  52. }
  53. foreach ( $moldList as $value ) {
  54. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  55. $flag = true;
  56. break;
  57. }
  58. }
  59. }
  60. /*
  61. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  62. */
  63. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  64. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  65. Doo::loadModel ( "invoiceCategoryManage" );
  66. $invoiceCategoryManage = new invoiceCategoryManage ();
  67. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  68. if (empty ( $icm ))
  69. die ( 'illegal request' );
  70. }
  71. // 单独判断应收款访问权限
  72. if ($action == 'invoiceAggregateCompanyDetail') {
  73. Doo::loadModel ( "invoiceCompanyManage" );
  74. $invoiceCompanyManage = new invoiceCompanyManage ();
  75. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  76. if (empty ( $icm ))
  77. die ( 'illegal request' );
  78. }
  79. // 主权限获得与判断
  80. Doo::loadModel ( 'staff' );
  81. $staff = new staff ();
  82. $detail = $staff->getStaffBySid ( $_COOKIE ["staff"] );
  83. $accessModular = 'INVOICE';
  84. if (empty ( $detail ['cldAccessArray'] ))
  85. die ( 'illegal request' );
  86. else {
  87. if (in_array ( $accessModular, $detail ['cldAccessArray'] )) {
  88. if (Doo::acl ()->isAllowed ( $accessModular, $resource, $action )) {
  89. $flag = true;
  90. } else {
  91. $flag = false;
  92. }
  93. } else {
  94. die ( 'illegal request' );
  95. }
  96. }
  97. if (! $flag)
  98. die ( 'illegal request' );
  99. }
  100. function __construct() {
  101. if (isset ( $_COOKIE ["staff"] )) {
  102. if (! empty ( $_COOKIE ["staff"] )) {
  103. Doo::loadModel ( 'staff' );
  104. $staff = new staff ();
  105. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  106. $this->ACTION = $uriPartsOrig [1];
  107. $this->data ['new'] = $this->isInvoiceNew ();
  108. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  109. $this->data ['isStaffCompleteMsg'] = false;
  110. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  111. if (! empty ( $detail ))
  112. $this->data ['isStaffCompleteMsg'] = true;
  113. return "/";
  114. }
  115. }
  116. Doo::loadCore ( 'uri/DooUriRouter' );
  117. $router = new DooUriRouter ();
  118. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  119. if ($routeRs ['1'] != "login") {
  120. header ( 'Content-Type:text/html;charset=utf-8' );
  121. @header ( "Location: /login" );
  122. }
  123. }
  124. function testSend() {
  125. // 测试根据规则发送信息 普通发送
  126. // $pendingApprovalsSid = 41;
  127. // Doo::loadModel ( 'staff' );
  128. // $staff = new staff ();
  129. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  130. // // 发送微信审批通知
  131. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  132. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  133. // Doo::loadModel ( 'staff' );
  134. // $staff = new staff ();
  135. // $toparty = $this->getToparty ( '广东办' );
  136. // $wxList = array ();
  137. // if (! empty ( $toparty )) {
  138. // $userList = $this->getUserByToparty ( $toparty );
  139. // $userCon = implode ( ',', $userList );
  140. // // echo $userCon;
  141. // $sidList = $staff->getStaffByWxid ( $userCon );
  142. // foreach ( $sidList as $key => $value ) {
  143. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  144. // if ($falg) {
  145. // array_push ( $wxList, $value ['wxid'] );
  146. // }
  147. // }
  148. // $wxString = implode ( '|', $wxList );
  149. // print_r ( $wxList );
  150. // echo $wxString;
  151. // }
  152. // 测试发送
  153. /*
  154. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  155. */
  156. // print_r ( $userList );
  157. // $msTouser='caipin|outaozhen';
  158. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  159. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  160. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  161. // $toparty= $this->getToparty('广东办');
  162. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  163. // $toparty = 26;
  164. // $msg = '';
  165. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  166. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  167. }
  168. function invoice() {
  169. Doo::loadModel ( 'invoice' );
  170. $invoice = new invoice ();
  171. Doo::loadModel ( 'express' );
  172. $express = new express ();
  173. $expressList = $express->getExpressByAll ();
  174. $this->data ['expressList'] = $expressList;
  175. // Doo::loadModel ( 'invoiceReceivables' );
  176. // $invoiceReceivables = new invoiceReceivables ();
  177. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  178. Doo::loadClass ( 'XDeode' );
  179. $XDeode = new XDeode ( 5 );
  180. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  181. Doo::loadModel ( 'invoiceStatistics' );
  182. $invoiceStatistics = new invoiceStatistics ();
  183. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  184. // 缓存统计结果
  185. $year = date ( "Y" );
  186. $tmp_date = date ( "Ym" );
  187. $tmp_year = substr ( $tmp_date, 0, 4 );
  188. $tmp_mon = substr ( $tmp_date, 4, 2 );
  189. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  190. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  191. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  192. if (is_file ( $path ))
  193. $htm = file_get_contents ( $path );
  194. else
  195. $htm = $this->showCache ( $path, $sid );
  196. $invoiceList = $invoice->getMyInvoice ( $sid );
  197. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  198. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  199. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  200. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  201. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  202. //获得已退票功能
  203. $untreadStatusList=$invoice->getInvoiceByUntreadStatus(2,0,5);
  204. $this->data ['untreadStatusList'] = $untreadStatusList;
  205. //print_r($untreadStatusList);
  206. $this->data ['isMonth'] = $isMonth;
  207. $this->data ['htm'] = $htm;
  208. $this->data ['invoiceList'] = $invoiceList;
  209. $this->data ['receivablesList'] = $list;
  210. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  211. $this->data ['memu'] = "invoice";
  212. $this->data ['staff'] = $this->staff;
  213. $this->data ['receiptMemu'] = 'invoice';
  214. $this->render ( "/admin/invoice", $this->data );
  215. }
  216. function invoiceExpress() {
  217. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  218. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  219. $this->data ['expressCom'] = $expressCom;
  220. $this->data ['expressNumber'] = $expressNumber;
  221. $this->render ( "/admin/invoiceExpress", $this->data );
  222. }
  223. function invoiceAdd() {
  224. Doo::loadModel ( 'invoice' );
  225. $invoice = new invoice ();
  226. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  227. Doo::loadModel ( 'L_category' );
  228. $lCategory = new L_category ();
  229. $category = $lCategory->find ( array (
  230. 'asArray' => true
  231. ) );
  232. $this->data ['category'] = $category;
  233. Doo::loadModel ( 'invoiceTraining' );
  234. $invoiceTraining = new invoiceTraining ();
  235. $itList = $invoiceTraining->getInvoiceTrainingByCid ($this->staff [0] ['cid']);
  236. Doo::loadModel ( 'receipt' );
  237. $receipt = new receipt ();
  238. foreach ($itList as $key=>$value){//不展示已结算完结的培训班
  239. $receiptDetail=$receipt->getReceiptByinvoiceTrainId($value['itid']);
  240. if (!empty($receiptDetail)){
  241. if($receiptDetail['status']==8||$receiptDetail['status']==9){
  242. unset($itList[$key]);
  243. }
  244. }
  245. }
  246. $this->data ['itList'] = $itList;
  247. $this->data ['memu'] = "invoice";
  248. $this->data ['staff'] = $this->staff;
  249. $this->data ['receiptMemu'] = 'invoice';
  250. $this->render ( "/admin/invoiceAdd", $this->data );
  251. }
  252. function invoiceAddFill() {
  253. Doo::loadModel ( 'invoice' );
  254. $invoice = new invoice ();
  255. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  256. Doo::loadModel ( 'L_category' );
  257. $lCategory = new L_category ();
  258. $category = $lCategory->find ( array (
  259. 'asArray' => true
  260. ) );
  261. $this->data ['category'] = $category;
  262. Doo::loadModel ( 'invoiceTraining' );
  263. $invoiceTraining = new invoiceTraining ();
  264. $itList = $invoiceTraining->getInvoiceTrainingByCid ($this->staff [0] ['cid']);
  265. $this->data ['itList'] = $itList;
  266. Doo::loadModel ( 'invoice' );
  267. $invoice = new invoice ();
  268. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  269. $detail['mailItemsArray']=json_decode($detail['mailItemsJson'],true);
  270. $this->data ['invoiceDetail'] = $detail;
  271. $this->data ['memu'] = "invoice";
  272. $this->data ['staff'] = $this->staff;
  273. $this->data ['receiptMemu'] = 'invoice';
  274. $this->render ( "/admin/invoiceAddFill", $this->data );
  275. }
  276. /**
  277. * 提交一份开票申请,并记录下操作日志
  278. *
  279. * @since 1.0.0
  280. * @var integer cid 办事处ID
  281. * @var integer invoiceType 发票类型
  282. * @var integer doPost 是否邮寄
  283. * @var integer invoicePrice 开票金额
  284. * @var string invoiceElement 开票内容
  285. * @var string invoiceTitle 发票抬头
  286. * @var string invoiceCompany 单位名称
  287. * @var string TIN 纳税人识别码
  288. * @var string address 注册地址
  289. * @var string phone 注册电话
  290. * @var string bank 开户银行
  291. * @var string bankAccount 银行账户
  292. * @var string recipients 收件人
  293. * @var string recipientsPhone 收件人手机/电话
  294. * @var string recipientsAddress 收件地址
  295. * @var string mailItems 邮寄物品
  296. * @var string remark 备注
  297. * @return string 返回跳转开票主页路径
  298. */
  299. function invoiceAddDo() {
  300. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  301. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  302. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  303. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  304. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  305. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  306. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  307. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  308. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  309. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  310. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  311. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  312. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  313. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  314. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  315. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  316. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  317. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  318. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  319. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  320. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  321. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  322. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  323. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  324. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  325. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  326. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  327. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  328. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  329. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  330. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  331. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  332. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  333. /*
  334. * $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;
  335. */
  336. if($invoiceType==1){
  337. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  338. if ($temporary>10000)
  339. die ( 'illegal request-Please priceError' );
  340. }
  341. if (empty ( $this->staff [0] ))
  342. die ( 'illegal request-Please login' );
  343. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )) {
  344. Doo::loadModel ( 'invoice' );
  345. $invoice = new invoice ();
  346. Doo::loadModel ( 'L_category' );
  347. $lCategory = new L_category ();
  348. Doo::loadModel ( 'invoiceManage' );
  349. $invoiceManage = new invoiceManage ();
  350. Doo::loadModel ( 'invoiceOperationLog' );
  351. $invoiceOperationLog = new invoiceOperationLog ();
  352. Doo::loadClass ( 'XDeode' );
  353. $XDeode = new XDeode ( 5 );
  354. $trainId = $XDeode->decode ( $trainId );
  355. $categoryDetil = $lCategory->getOne ( array (
  356. 'SELECT' => 'title',
  357. 'where' => 'cid=' . $cid,
  358. 'asArray' => true
  359. ) );
  360. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  361. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  362. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  363. // print_r(current($invoiceManageDetail ['staffList']));
  364. // die;
  365. $moldManage = array ();
  366. foreach ( $invoiceManageList as $key => $value ) {
  367. if ($value ['mold'] == '发票打印')
  368. $moldManage [$value ['mold']] = $value ['staffList'];
  369. elseif ($value ['mold'] == '发票邮寄')
  370. $moldManage [$value ['mold']] = $value ['staffList'];
  371. elseif ($value ['mold'] == '发票退票')
  372. $moldManage [$value ['mold']] = $value ['staffList'];
  373. }
  374. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  375. $st = '';
  376. if ($settlementType == 'SOFTWARE') {
  377. $st = 0;
  378. $trainId=0;
  379. } elseif ($settlementType == 'TRAINING') {
  380. $st = 1;
  381. if (empty ( $trainId )&&!is_numeric($trainId)) {
  382. die ( 'illegal request-trainingIdError' );
  383. }
  384. } else {
  385. die ( 'illegal request-settlementError' );
  386. }
  387. $item = array (
  388. 'cid' => $cid,
  389. 'categoryName' => $categoryDetil ['title'],
  390. 'invoiceElement' => $invoiceElement,
  391. 'invoiceQuantity' => $invoiceQuantity,
  392. 'invoiceUnitPrice' => $invoiceUnitPrice,
  393. 'invoicePrice' => $invoicePrice,
  394. 'invoiceType' => $invoiceType,
  395. 'settlementType' => $st,
  396. 'doPost' => $doPost,
  397. 'status' => 1,
  398. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  399. 'date' => date ( "Y-m-d H:i:s" ),
  400. 'updateTime' => date ( "Y-m-d H:i:s" ),
  401. 'sid' => $this->staff [0] ['sid'],
  402. 'userName' => $this->staff [0] ['username'],
  403. 'invoiceManage' => $invoiceManageDetail ['staff'],
  404. 'pendingApprovals' => $pendingApprovalsSid,
  405. 'moldManage' => json_encode ( $moldManage ),
  406. 'remark' => $remark,
  407. 'trainId' => $trainId
  408. );
  409. if ($invoiceType == 0)
  410. $item += array (
  411. 'invoiceTitle' => $invoiceTitle,
  412. 'TIN' => $TINT,
  413. 'address' => $addressT,
  414. 'phone' => $phoneT,
  415. 'bank' => $bankT,
  416. 'bankAccount' => $bankAccountT
  417. );
  418. else {
  419. $item += array (
  420. 'invoiceCompany' => $invoiceCompany,
  421. 'TIN' => $TIN,
  422. 'address' => $address,
  423. 'phone' => $phone,
  424. 'bank' => $bank,
  425. 'bankAccount' => $bankAccount
  426. );
  427. }
  428. if ($doPost == 1) {
  429. $mailList = array (
  430. 'invoice' => 1,
  431. 'mailItems' => $mailItems
  432. );
  433. if (! empty ( $softLock ))
  434. $mailList += array (
  435. 'softLock' => $softLockNum
  436. );
  437. else
  438. $mailList += array (
  439. 'softLock' => 0
  440. );
  441. if (! empty ( $contract ))
  442. $mailList += array (
  443. 'contract' => $contractNum
  444. );
  445. else
  446. $mailList += array (
  447. 'contract' => 0
  448. );
  449. if (! empty ( $instructions ))
  450. $mailList += array (
  451. 'instructions' => $instructionsNum
  452. );
  453. else
  454. $mailList += array (
  455. 'instructions' => 0
  456. );
  457. if (! empty ( $remittance ))
  458. $mailList += array (
  459. 'remittance' => $remittance
  460. );
  461. else
  462. $mailList += array (
  463. 'remittance' => ''
  464. );
  465. $mailString = '发票x1张,备注:' . $mailItems;
  466. if (! empty ( $softLock ))
  467. $mailString .= ',软件锁x' . $softLockNum.'个';
  468. if (! empty ( $contract ))
  469. $mailString .= ',合同x' . $contractNum.'份';
  470. if (! empty ( $instructions ))
  471. $mailString .= ',说明书x' . $instructionsNum.'本';
  472. if (! empty ( $remittance ))
  473. $mailString .= ',汇款账号单(张)';
  474. $item += array (
  475. 'recipients' => $recipients,
  476. 'recipientsPhone' => $recipientsPhone,
  477. 'recipientsAddress' => $recipientsAddress,
  478. 'mailItems' => $mailString,
  479. 'mailItemsJson' => json_encode ( $mailList )
  480. );
  481. }
  482. $iid = $invoice->addInvoice ( $item );
  483. // 如果是培训班结算 创建培训班发票到培训班备份中
  484. if (! empty ( $st )&&$st==1) {
  485. Doo::loadModel ( 'invoiceStore' );
  486. $invoiceStore = new invoiceStore ();
  487. Doo::loadModel ( 'invoiceTraining' );
  488. $invoiceTraining = new invoiceTraining ();
  489. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  490. $itemIS = array (
  491. 'isid' => $isid,
  492. 'ipSource' => 1,
  493. 'apStatus'=>1,
  494. 'iid' => $iid
  495. );
  496. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  497. // 更新培训班总数量
  498. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  499. $item = array (
  500. 'itid' => $trainId,
  501. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  502. 'submitStatus' => 1
  503. );
  504. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  505. }
  506. // 操作日志
  507. $item = array (
  508. 'date' => date ( "Y-m-d H:i:s" ),
  509. 'operation' => "创建",
  510. 'status' => 1,
  511. 'img' => $this->staff [0] ['avatar'],
  512. 'username' => $this->staff [0] ['username'],
  513. 'uid' => $this->staff [0] ['sid'],
  514. 'category' => $this->staff [0] ['category'],
  515. 'iid' => $iid
  516. );
  517. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  518. $item = array (
  519. 'date' => date ( "Y-m-d H:i:s" ),
  520. 'operation' => "提交审批",
  521. 'status' => 1,
  522. 'img' => $this->staff [0] ['avatar'],
  523. 'username' => $this->staff [0] ['username'],
  524. 'uid' => $this->staff [0] ['sid'],
  525. 'category' => $this->staff [0] ['category'],
  526. 'iid' => $iid
  527. );
  528. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  529. Doo::loadModel ( 'staff' );
  530. $staff = new staff ();
  531. $username2 = $staff->getOne ( array (
  532. 'select' => 'wxid',
  533. 'where' => 'sid=' . $pendingApprovalsSid,
  534. 'asArray' => TRUE
  535. ) );
  536. // 发送微信审批通知
  537. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  538. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  539. }
  540. return "/invoice";
  541. }
  542. function invoiceEdit() {
  543. Doo::loadClass ( 'XDeode' );
  544. $XDeode = new XDeode ( 5 );
  545. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  546. $iid = $XDeode->decode ( $iid );
  547. if (! is_numeric ( $iid ))
  548. die ( 'illegal request' );
  549. Doo::loadModel ( 'invoice' );
  550. $invoice = new invoice ();
  551. Doo::loadModel ( 'invoiceOperationLog' );
  552. $invoiceOperationLog = new invoiceOperationLog ();
  553. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  554. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  555. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  556. $this->data ['operation'] = $operation;
  557. $this->data ['invoiceDetail'] = $invoiceDetail;
  558. $this->data ['memu'] = "invoice";
  559. $this->data ['staff'] = $this->staff;
  560. $this->data ['receiptMemu'] = 'invoice';
  561. $this->render ( "/admin/invoiceEdit", $this->data );
  562. }
  563. /**
  564. * 重新编辑退回的发票
  565. * @return string
  566. */
  567. function invoiceEditDo() {
  568. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  569. Doo::loadModel ( 'invoice' );
  570. $invoice = new invoice ();
  571. $iid = $invoice->authcode ( $iidKey );
  572. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  573. die ( 'illegal request' );
  574. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  575. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  576. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  577. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  578. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  579. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  580. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  581. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  582. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  583. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  584. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  585. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  586. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  587. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  588. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  589. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  590. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  591. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  592. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  593. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  594. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  595. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  596. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  597. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  598. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  599. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  600. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  601. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  602. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  603. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  604. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  605. if($invoiceType==1){
  606. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  607. if ($temporary>10000)
  608. die ( 'illegal request-Please priceError' );
  609. }
  610. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  611. Doo::loadModel ( 'invoiceManage' );
  612. $invoiceManage = new invoiceManage ();
  613. Doo::loadModel ( 'invoiceOperationLog' );
  614. $invoiceOperationLog = new invoiceOperationLog ();
  615. $cid = explode ( ':', $cid );
  616. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  617. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  618. $moldManage = array ();
  619. foreach ( $invoiceManageList as $key => $value ) {
  620. if ($value ['mold'] == '发票打印')
  621. $moldManage [$value ['mold']] = $value ['staffList'];
  622. elseif ($value ['mold'] == '发票邮寄')
  623. $moldManage [$value ['mold']] = $value ['staffList'];
  624. elseif ($value ['mold'] == '发票打印')
  625. $moldManage [$value ['mold']] = $value ['staffList'];
  626. }
  627. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  628. $item = array (
  629. 'iid' => $iid,
  630. 'cid' => $cid [0],
  631. 'categoryName' => $cid [1],
  632. 'invoiceElement' => $invoiceElement,
  633. 'invoiceQuantity' => $invoiceQuantity,
  634. 'invoiceUnitPrice' => $invoiceUnitPrice,
  635. 'invoicePrice' => $invoicePrice,
  636. 'invoiceType' => $invoiceType,
  637. 'doPost' => $doPost,
  638. 'status' => 1,
  639. 'updateTime' => date ( "Y-m-d H:i:s" ),
  640. 'remark' => $remark
  641. );
  642. if ($invoiceType == 0)
  643. $item += array (
  644. 'invoiceTitle' => $invoiceTitle,
  645. 'TIN' => $TINT,
  646. 'address' => $addressT,
  647. 'phone' => $phoneT,
  648. 'bank' => $bankT,
  649. 'bankAccount' => $bankAccountT
  650. );
  651. else {
  652. $item += array (
  653. 'invoiceCompany' => $invoiceCompany,
  654. 'TIN' => $TIN,
  655. 'address' => $address,
  656. 'phone' => $phone,
  657. 'bank' => $bank,
  658. 'bankAccount' => $bankAccount
  659. );
  660. }
  661. if ($doPost == 1) {
  662. $mailList = array (
  663. 'invoice' => 1,
  664. 'mailItems' => $mailItems
  665. );
  666. if (! empty ( $softLock ))
  667. $mailList += array (
  668. 'softLock' => $softLockNum
  669. );
  670. else
  671. $mailList += array (
  672. 'softLock' => '0'
  673. );
  674. if (! empty ( $contract ))
  675. $mailList += array (
  676. 'contract' => $contractNum
  677. );
  678. else
  679. $mailList += array (
  680. 'contract' => '0'
  681. );
  682. if (! empty ( $instructions ))
  683. $mailList += array (
  684. 'instructions' => $instructionsNum
  685. );
  686. else
  687. $mailList += array (
  688. 'instructions' => '0'
  689. );
  690. if (! empty ( $remittance ))
  691. $mailList += array (
  692. 'remittance' => $remittance
  693. );
  694. else
  695. $mailList += array (
  696. 'remittance' => ''
  697. );
  698. $mailString = '发票x1,备注:' . $mailItems;
  699. if (! empty ( $softLock ))
  700. $mailString .= ',软件锁x' . $softLockNum;
  701. if (! empty ( $contract ))
  702. $mailString .= ',合同x' . $contractNum;
  703. if (! empty ( $instructions ))
  704. $mailString .= ',说明书x' . $instructionsNum;
  705. if (! empty ( $remittance ))
  706. $mailString .= ',汇款账号单';
  707. $item += array (
  708. 'recipients' => $recipients,
  709. 'recipientsPhone' => $recipientsPhone,
  710. 'recipientsAddress' => $recipientsAddress,
  711. 'mailItems' => $mailString,
  712. 'mailItemsJson' => json_encode ( $mailList )
  713. );
  714. }
  715. $invoice->setInvoiceByCondition ( $item );
  716. $item = array (
  717. 'date' => date ( "Y-m-d H:i:s" ),
  718. 'operation' => "重新提交审批",
  719. 'status' => 1,
  720. 'img' => $this->staff [0] ['avatar'],
  721. 'username' => $this->staff [0] ['username'],
  722. 'uid' => $this->staff [0] ['sid'],
  723. 'category' => $this->staff [0] ['category'],
  724. 'iid' => $iid
  725. );
  726. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  727. }
  728. return "/invoice";
  729. }
  730. /**
  731. * 培训班
  732. */
  733. function invoiceTraining() {
  734. Doo::loadModel ( 'L_category' );
  735. $lCategory = new L_category ();
  736. Doo::loadModel ( 'invoiceTraining' );
  737. $invoiceTraining = new invoiceTraining ();
  738. Doo::loadModel ( 'invoiceTrainManage' );
  739. $invoiceTrainManage = new invoiceTrainManage ();
  740. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  741. $cidList = array ();
  742. foreach ( $imcStaff as $key => $value ) {
  743. array_push ( $cidList, $value ['cid'] );
  744. }
  745. if(empty($cidList)){
  746. $cidString = $this->staff [0] ['cid'];
  747. }else{
  748. $cidString = implode ( ',', $cidList );
  749. $cidString.=$cidString.','.$this->staff [0] ['cid'];
  750. }
  751. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  752. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  753. $category = $lCategory->getCategory ();
  754. $itid = array ();
  755. foreach ( $itTodoList as $key=>$value ) {
  756. array_push ( $itid, $value ['itid'] );
  757. //如果入账100%更新为已完成
  758. if ($itTodoList [$key] ['arriveSchedule']>=100){
  759. $invoiceTraining = new invoiceTraining ();
  760. $invoiceTraining->itid = $value ['itid'];
  761. $invoiceTraining->status = 2;
  762. $invoiceTraining->update ();
  763. }
  764. }
  765. foreach ( $itedList as $value ) {
  766. array_push ( $itid, $value ['itid'] );
  767. }
  768. $itid = implode ( ',', $itid );
  769. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  770. // print_r($itTodoList);
  771. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  772. $this->data ['itTodoList'] = $itTodoList;
  773. $this->data ['itedList'] = $itedList;
  774. $this->data ['category'] = $category;
  775. $this->data ['memu'] = "invoice";
  776. $this->data ['staff'] = $this->staff;
  777. $this->data ['receiptMemu'] = 'invoiceTraining';
  778. $this->render ( "/admin/invoiceTraining", $this->data );
  779. }
  780. /**
  781. * 创建培训班
  782. */
  783. function invoiceTrainingAdd() {
  784. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  785. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  786. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  787. if (empty ( $this->staff [0] ))
  788. die ( 'illegal request' );
  789. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  790. Doo::loadModel ( 'invoiceTraining' );
  791. $invoiceTraining = new invoiceTraining ();
  792. Doo::loadModel ( 'invoice' );
  793. $invoice = new invoice ();
  794. Doo::loadModel ( 'L_category' );
  795. $lCategory = new L_category ();
  796. Doo::loadModel ( 'invoiceManage' );
  797. $invoiceManage = new invoiceManage ();
  798. Doo::loadModel ( 'invoiceOperationLog' );
  799. $invoiceOperationLog = new invoiceOperationLog ();
  800. $item = array (
  801. 'cid' => $cid,
  802. 'trainName' => $trainName,
  803. 'trainDate' => $trainDate,
  804. 'creator' => $this->staff [0] ['sid'],
  805. 'creatorDate' => date ( "Y-m-d H:i:s" )
  806. );
  807. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  808. }
  809. return "/invoiceTraining";
  810. }
  811. /**
  812. * 删除培训班
  813. */
  814. function invoiceTrainingDelDo() {
  815. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  816. if (! empty ( $itid )) {
  817. Doo::loadModel ( 'invoiceTraining' );
  818. $invoiceTraining = new invoiceTraining ();
  819. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  820. }
  821. return "/invoiceTraining";
  822. }
  823. /**
  824. * 培训班详情
  825. */
  826. function invoiceTrainingDetail() {
  827. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  828. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  829. Doo::loadModel ( 'invoiceTraining' );
  830. $invoiceTraining = new invoiceTraining ();
  831. Doo::loadModel ( 'invoiceStore' );
  832. $invoiceStore = new invoiceStore ();
  833. if (empty ( $itid ))
  834. die ( 'illegal request' );
  835. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  836. if ($trainStatus == "SUBED")
  837. $con = ' (b.untreadStatus is null ) and ';
  838. elseif ($trainStatus == "APPROVAL")
  839. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  840. elseif ($trainStatus == "TICKET")
  841. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  842. elseif($trainStatus == "TICKETING"){
  843. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  844. }
  845. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  846. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con );
  847. // print_r($isList);
  848. $trainlist = array ();
  849. foreach ( $isList as $key => $value ) {
  850. $irDetail = array ();
  851. if ($value ['apStatus'] == 1) {
  852. // array_push ( $irDetail, '' );
  853. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  854. } else {
  855. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  856. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  857. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  858. }
  859. array_push ( $irDetail, $value ['invoiceSerial'] );
  860. if ($value ['invoiceType'] == 1)
  861. array_push ( $irDetail, $value ['invoiceCompany'] );
  862. else
  863. array_push ( $irDetail, $value ['invoiceTitle'] );
  864. array_push ( $irDetail, $value ['TIN'] );
  865. array_push ( $irDetail, $value ['userName'] );
  866. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  867. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  868. } else
  869. array_push ( $irDetail, $value ['mailItems'] );
  870. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  871. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  872. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  873. array_push ( $irDetail, $value ['invoiceElement'] );
  874. array_push ( $irDetail, $value ['invoiceQuantity'] );
  875. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  876. if ($value ['invoiceType'] == 1)
  877. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  878. else
  879. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  880. array_push ( $irDetail, $value ['remark'] );
  881. if ($value ['status'] == 1)
  882. array_push ( $irDetail, '审批中' );
  883. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  884. array_push ( $irDetail, '已出票' );
  885. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  886. array_push ( $irDetail, '已入账' );
  887. else
  888. array_push ( $irDetail, '' );
  889. array_push ( $irDetail, $value ['invoiceNo'] );
  890. array_push ( $irDetail, $value ['printTime'] );
  891. $html = '';
  892. foreach ( $value ['invoiceReceivables'] as $value ) {
  893. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  894. }
  895. array_push ( $irDetail, $html );
  896. array_push ( $trainlist, $irDetail );
  897. }
  898. $trainlistJson = json_encode ( $trainlist );
  899. if (empty ( $detail ))
  900. die ( 'illegal request' );
  901. //培训班结算是否有和是否已经结算完成
  902. Doo::loadModel ( 'receipt' );
  903. $receipt = new receipt ();
  904. $receiptDetail=$receipt->getReceiptByinvoiceTrainId($itid);
  905. $this->data ['receiptDetail'] = $receiptDetail;
  906. $this->data ['trainStatus'] = $trainStatus;
  907. $this->data ['itid'] = $itid;
  908. $this->data ['trainlistJson'] = $trainlistJson;
  909. $this->data ['iTrainDetail'] = $detail;
  910. $this->data ['memu'] = "invoice";
  911. $this->data ['staff'] = $this->staff;
  912. $this->data ['receiptMemu'] = 'invoiceTraining';
  913. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  914. }
  915. /**
  916. * 上传培训班发票
  917. * @return string
  918. */
  919. function invoiceTrainingUpload() {
  920. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  921. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  922. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  923. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  924. header ( "HTTP/1.1 500 Internal Server Error" );
  925. echo "POST exceeded maximum allowed size.";
  926. exit ( 0 );
  927. }
  928. // Settings
  929. $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)
  930. $upload_name = "Filedata";
  931. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  932. $extension_whitelist = array (
  933. "doc",
  934. "txt",
  935. "jpg",
  936. "gif",
  937. "png"
  938. ); // Allowed file extensions
  939. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  940. // Other variables
  941. $MAX_FILENAME_LENGTH = 260;
  942. $file_name = "";
  943. $file_extension = "";
  944. $uploadErrors = array (
  945. 0 => "文件上传成功",
  946. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  947. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  948. 3 => "上传的文件仅为部分文件",
  949. 4 => "没有文件上传",
  950. 6 => "缺少临时文件夹"
  951. );
  952. $nk = time ();
  953. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  954. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  955. echo "文件无法保存.";
  956. exit ( 0 );
  957. }
  958. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  959. echo json_encode ( array (
  960. 'filename' => $file_name,
  961. 'id' => $nk
  962. ) );
  963. exit ( 0 );
  964. }
  965. /**
  966. * 导入发票临时仓库
  967. */
  968. function invoiceStoreImport() {
  969. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  970. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  971. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  972. if ($path != "" && ! empty ( $trainingKey )) {
  973. Doo::loadModel ( 'invoiceStore' );
  974. Doo::loadModel ( 'staff' );
  975. $staff = new staff ();
  976. Doo::loadModel ( 'invoiceTraining' );
  977. $invoiceTraining = new invoiceTraining ();
  978. Doo::loadClass ( 'XDeode' );
  979. $XDeode = new XDeode ( 5 );
  980. $itid = $XDeode->decode ( $trainingKey );
  981. //培训班结算是否有和是否已经结算完成
  982. Doo::loadModel ( 'receipt' );
  983. $receipt = new receipt ();
  984. $receiptDetail=$receipt->getReceiptByinvoiceTrainId($itid);
  985. if (!empty($receiptDetail)){
  986. if ($receiptDetail['status']==8||$receiptDetail['status']==9)
  987. die ( 'illegal request--status' );
  988. }
  989. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  990. $userName = $this->staff [0] ['username'];
  991. $sDetail = $staff->getStaffByName ( $userName );
  992. // die('sdd');
  993. // 可以优化
  994. foreach ( $exlArray as $key => $value ) {
  995. // 开票
  996. $invoice = new invoiceStore ();
  997. $invoice->trainId = $itid;
  998. $invoice->invoiceType = 0;
  999. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1000. $invoice->invoiceType = 1;
  1001. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1002. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1003. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1004. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1005. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1006. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1007. $invoice->userName = $userName;
  1008. $invoice->sid = $sDetail ['sid'];
  1009. $invoice->cid = $sDetail ['cid'];
  1010. $invoice->categoryName = $sDetail ['category'];
  1011. $invoice->invoiceElement = $value ['invoiceElement'];
  1012. $invoice->remark = $value ['remark'];
  1013. // $invoice->date = $value ['date'];
  1014. // $invoice->printTime = $value ['date'];
  1015. $invoice->ipSource = 1;
  1016. $invoice->printStatus = 0;
  1017. $invoice->status = 0;
  1018. $invoice->postStatus = 1;
  1019. $invoice->untreadStatus = 0;
  1020. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1021. $invoice->TIN = $value ['TIN'];
  1022. $invoice->address = $value ['address'];
  1023. $invoice->phone = $value ['phone'];
  1024. $invoice->bank = $value ['bank'];
  1025. $invoice->bankAccount = $value ['bankAccount'];
  1026. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1027. $invoice->recipients = $value ['recipients'];
  1028. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1029. $iid = $invoice->insert ();
  1030. }
  1031. // 加入发票总数量
  1032. $item = array (
  1033. 'itid' => $itid,
  1034. 'invoiceTotal' => count ( $exlArray )
  1035. );
  1036. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1037. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1038. }
  1039. echo 'no file';
  1040. }
  1041. /**
  1042. * 编辑仓库里的发票
  1043. */
  1044. function invoiceStoreEdit() {
  1045. Doo::loadClass ( 'XDeode' );
  1046. $XDeode = new XDeode ( 5 );
  1047. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1048. $iid = $XDeode->decode ( $iid );
  1049. if (! is_numeric ( $iid ))
  1050. die ( 'illegal request' );
  1051. Doo::loadModel ( 'invoiceStore' );
  1052. $invoiceStore = new invoiceStore ();
  1053. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1054. // print_r($invoiceDetail);
  1055. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1056. $this->data ['invoiceDetail'] = $invoiceDetail;
  1057. $this->data ['memu'] = "invoice";
  1058. $this->data ['staff'] = $this->staff;
  1059. $this->data ['receiptMemu'] = 'invoiceTraining';
  1060. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1061. }
  1062. function invoiceStoreEditDo() {
  1063. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1064. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1065. Doo::loadModel ( 'invoiceStore' );
  1066. $invoice = new invoiceStore ();
  1067. Doo::loadClass ( 'XDeode' );
  1068. $XDeode = new XDeode ( 5 );
  1069. $iid = $XDeode->decode ( $storeKey );
  1070. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1071. die ( 'illegal request' );
  1072. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1073. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1074. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1075. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1076. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1077. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1078. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1079. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1080. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1081. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1082. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1083. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1084. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1085. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1086. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1087. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1088. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1089. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1090. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1091. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1092. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1093. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1094. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1095. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1096. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1097. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1098. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1099. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1100. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1101. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1102. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1103. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1104. $cid = explode ( ':', $cid );
  1105. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1106. $item = array (
  1107. 'isid' => $iid,
  1108. 'cid' => $cid [0],
  1109. 'categoryName' => $cid [1],
  1110. 'invoiceElement' => $invoiceElement,
  1111. 'invoiceQuantity' => $invoiceQuantity,
  1112. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1113. 'invoicePrice' => $invoicePrice,
  1114. 'invoiceType' => $invoiceType,
  1115. 'doPost' => $doPost,
  1116. 'status' => 1,
  1117. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1118. 'remark' => $remark
  1119. );
  1120. if ($invoiceType == 0)
  1121. $item += array (
  1122. 'invoiceTitle' => $invoiceTitle,
  1123. 'TIN' => $TINT,
  1124. 'address' => $addressT,
  1125. 'phone' => $phoneT,
  1126. 'bank' => $bankT,
  1127. 'bankAccount' => $bankAccountT
  1128. );
  1129. else {
  1130. $item += array (
  1131. 'invoiceCompany' => $invoiceCompany,
  1132. 'TIN' => $TIN,
  1133. 'address' => $address,
  1134. 'phone' => $phone,
  1135. 'bank' => $bank,
  1136. 'bankAccount' => $bankAccount
  1137. );
  1138. }
  1139. if ($doPost == 1) {
  1140. $mailList = array (
  1141. 'invoice' => 1,
  1142. 'mailItems' => $mailItems
  1143. );
  1144. if (! empty ( $softLock ))
  1145. $mailList += array (
  1146. 'softLock' => $softLockNum
  1147. );
  1148. else
  1149. $mailList += array (
  1150. 'softLock' => '0'
  1151. );
  1152. if (! empty ( $contract ))
  1153. $mailList += array (
  1154. 'contract' => $contractNum
  1155. );
  1156. else
  1157. $mailList += array (
  1158. 'contract' => '0'
  1159. );
  1160. if (! empty ( $instructions ))
  1161. $mailList += array (
  1162. 'instructions' => $instructionsNum
  1163. );
  1164. else
  1165. $mailList += array (
  1166. 'instructions' => '0'
  1167. );
  1168. if (! empty ( $remittance ))
  1169. $mailList += array (
  1170. 'remittance' => $remittance
  1171. );
  1172. else
  1173. $mailList += array (
  1174. 'remittance' => ''
  1175. );
  1176. $mailString = '发票x1,备注:' . $mailItems;
  1177. if (! empty ( $softLock ))
  1178. $mailString .= ',软件锁x' . $softLockNum;
  1179. if (! empty ( $contract ))
  1180. $mailString .= ',合同x' . $contractNum;
  1181. if (! empty ( $instructions ))
  1182. $mailString .= ',说明书x' . $instructionsNum;
  1183. if (! empty ( $remittance ))
  1184. $mailString .= ',汇款账号单';
  1185. $item += array (
  1186. 'recipients' => $recipients,
  1187. 'recipientsPhone' => $recipientsPhone,
  1188. 'recipientsAddress' => $recipientsAddress,
  1189. 'mailItems' => $mailString,
  1190. 'mailItemsJson' => json_encode ( $mailList )
  1191. );
  1192. }
  1193. $invoice->setInvoiceStoreByCondition ( $item );
  1194. }
  1195. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1196. }
  1197. /**
  1198. *
  1199. * @return string
  1200. */
  1201. function invoiceStoreDelete() {
  1202. Doo::loadClass ( 'XDeode' );
  1203. $XDeode = new XDeode ( 5 );
  1204. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1205. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1206. $isid = $XDeode->decode ( $iStoreKey );
  1207. $itid = $XDeode->decode ( $trainKey );
  1208. if (! is_numeric ( $isid ))
  1209. die ( 'illegal request' );
  1210. Doo::loadModel ( 'invoiceStore' );
  1211. $invoiceStore = new invoiceStore ();
  1212. $invoiceStore->delete ( array (
  1213. 'where' => 'isid=' . $isid,
  1214. 'limit' => 1
  1215. ) );
  1216. Doo::loadModel ( 'invoiceTraining' );
  1217. $invoiceTraining = new invoiceTraining ();
  1218. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1219. $item = array (
  1220. 'itid' => $itid,
  1221. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1222. );
  1223. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1224. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1225. }
  1226. /**
  1227. * 批量删除库里发票
  1228. */
  1229. function invoiceStoreBatchDelete() {
  1230. Doo::loadClass ( 'XDeode' );
  1231. $XDeode = new XDeode ( 5 );
  1232. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1233. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1234. if (empty($trainKey)||empty($storeKey))
  1235. die ( 'illegal request-IdKey' );
  1236. $tid = $XDeode->decode ( $trainKey );
  1237. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1238. die ( 'illegal request' );
  1239. Doo::loadModel ( 'invoiceStore' );
  1240. $isidKeyList = explode ( ',', $storeKey );
  1241. $isidList = array ();
  1242. foreach ( $isidKeyList as $value ) {
  1243. $isid = $XDeode->decode ( $value );
  1244. if (! empty ( $isid ) && is_numeric ( $isid ))
  1245. array_push ( $isidList, $isid );
  1246. }
  1247. $isidString = implode ( ',', $isidList );
  1248. $invoiceStore = new invoiceStore ();
  1249. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1250. $isidList = array ();
  1251. foreach ( $isList as $key => $value ) {
  1252. if ($value ['apStatus'] == 0)
  1253. array_push ( $isidList, $value ['isid'] );
  1254. }
  1255. $isidString = implode ( ',', $isidList );
  1256. // print_r($isList);
  1257. // echo $isidString;
  1258. $invoiceStore = new invoiceStore ();
  1259. $invoiceStore->delete ( array (
  1260. 'where' => "isid in ( " . $isidString . ")",
  1261. 'asArray' => TRUE
  1262. ) );
  1263. Doo::loadModel ( 'invoiceTraining' );
  1264. $invoiceTraining = new invoiceTraining ();
  1265. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1266. $item = array (
  1267. 'itid' => $tid,
  1268. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1269. );
  1270. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1271. // echo $tid;
  1272. // echo $storeKey;
  1273. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1274. }
  1275. /**
  1276. * 仓库发票提交审批
  1277. * @return string
  1278. */
  1279. function invoiceStoreApproval() {
  1280. Doo::loadClass ( 'XDeode' );
  1281. $XDeode = new XDeode ( 5 );
  1282. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1283. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1284. $isid = $XDeode->decode ( $iStoreKey );
  1285. $trainId = $XDeode->decode ( $trainKey );
  1286. if (! is_numeric ( $isid ))
  1287. die ( 'illegal request' );
  1288. Doo::loadModel ( 'invoiceStore' );
  1289. Doo::loadModel ( 'invoice' );
  1290. $invoice = new invoice ();
  1291. // 加入限制必须填写入开票内容和邮寄物品
  1292. $invoiceStore = new invoiceStore ();
  1293. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1294. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1295. header ( 'Content-Type:text/html;charset=utf-8' );
  1296. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1297. }
  1298. // 拷贝插入一条发票数据
  1299. $invoiceStore = new invoiceStore ();
  1300. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1301. $invoiceStore = new invoiceStore ();
  1302. $item = array (
  1303. 'isid' => $isid,
  1304. 'iid' => $iid,
  1305. 'apStatus' => 1
  1306. );
  1307. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1308. Doo::loadModel ( 'invoiceManage' );
  1309. $invoiceManage = new invoiceManage ();
  1310. Doo::loadModel ( 'invoiceOperationLog' );
  1311. $invoiceOperationLog = new invoiceOperationLog ();
  1312. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1313. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1314. $moldManage = array ();
  1315. foreach ( $invoiceManageList as $key => $value ) {
  1316. if ($value ['mold'] == '发票打印')
  1317. $moldManage [$value ['mold']] = $value ['staffList'];
  1318. elseif ($value ['mold'] == '发票邮寄')
  1319. $moldManage [$value ['mold']] = $value ['staffList'];
  1320. elseif ($value ['mold'] == '发票退票')
  1321. $moldManage [$value ['mold']] = $value ['staffList'];
  1322. }
  1323. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1324. $item = array (
  1325. 'iid' => $iid,
  1326. 'isid'=>$isid,
  1327. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1328. 'date' => date ( "Y-m-d H:i:s" ),
  1329. 'status' => 1,
  1330. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1331. 'trainId' => $trainId,
  1332. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1333. 'moldManage' => json_encode ( $moldManage ),
  1334. 'settlementType'=>1,
  1335. 'pendingApprovals' => $pendingApprovalsSid
  1336. );
  1337. $invoice->setInvoiceByCondition ( $item );
  1338. Doo::loadModel ( 'invoiceTraining' );
  1339. $invoiceTraining = new invoiceTraining ();
  1340. $item = array (
  1341. 'itid' => $trainId,
  1342. 'submitStatus' => 1
  1343. );
  1344. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1345. $item = array (
  1346. 'date' => date ( "Y-m-d H:i:s" ),
  1347. 'operation' => "创建",
  1348. 'status' => 1,
  1349. 'img' => $this->staff [0] ['avatar'],
  1350. 'username' => $this->staff [0] ['username'],
  1351. 'uid' => $this->staff [0] ['sid'],
  1352. 'category' => $this->staff [0] ['category'],
  1353. 'iid' => $iid
  1354. );
  1355. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1356. $item = array (
  1357. 'date' => date ( "Y-m-d H:i:s" ),
  1358. 'operation' => "提交审批",
  1359. 'status' => 1,
  1360. 'img' => $this->staff [0] ['avatar'],
  1361. 'username' => $this->staff [0] ['username'],
  1362. 'uid' => $this->staff [0] ['sid'],
  1363. 'category' => $this->staff [0] ['category'],
  1364. 'iid' => $iid
  1365. );
  1366. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1367. Doo::loadModel ( 'staff' );
  1368. $staff = new staff ();
  1369. $username2 = $staff->getOne ( array (
  1370. 'select' => 'wxid',
  1371. 'where' => 'sid=' . $pendingApprovalsSid,
  1372. 'asArray' => TRUE
  1373. ) );
  1374. // 发送微信审批通知
  1375. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1376. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1377. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1378. }
  1379. /**
  1380. * 批量提交发票
  1381. * @return string
  1382. */
  1383. function invoiceStoreBatchApproval() {
  1384. Doo::loadClass ( 'XDeode' );
  1385. $XDeode = new XDeode ( 5 );
  1386. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1387. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1388. if (empty($trainKey)||empty($storeKey))
  1389. die ( 'illegal request-IdKey' );
  1390. $trainId = $XDeode->decode ( $trainKey );
  1391. $isidKeyList = explode ( ',', $storeKey );
  1392. $isidList = array ();
  1393. foreach ( $isidKeyList as $value ) {
  1394. $isid = $XDeode->decode ( $value );
  1395. if (! empty ( $isid ) && is_numeric ( $isid ))
  1396. array_push ( $isidList, $isid );
  1397. }
  1398. $isidString = implode ( ',', $isidList );
  1399. if (! is_numeric ( $trainId ))
  1400. die ( 'illegal request' );
  1401. Doo::loadModel ( 'invoiceStore' );
  1402. Doo::loadModel ( 'invoice' );
  1403. // 判断哪些已经加入审批过
  1404. // 加入限制必须填写入开票内容和邮寄物品
  1405. $invoiceStore = new invoiceStore ();
  1406. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1407. foreach ( $isList as $key => $value ) {
  1408. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1409. header ( 'Content-Type:text/html;charset=utf-8' );
  1410. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1411. }
  1412. }
  1413. // 拷贝插入一条发票数据
  1414. $invoiceStore = new invoiceStore ();
  1415. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1416. $invoiceStore = new invoiceStore ();
  1417. $item = array (
  1418. 'apStatus' => 1
  1419. );
  1420. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1421. // 获得正式发票ID
  1422. $invoice = new invoice ();
  1423. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1424. $sqlList = array ();
  1425. $iidString = '';
  1426. $iida = array ();
  1427. foreach ( $iidList as $key => $value ) {
  1428. $sqlList [$value ['isid']] = $value ['iid'];
  1429. array_push ( $iida, $value ['iid'] );
  1430. }
  1431. $iidString = implode ( ',', $iida );
  1432. $ids = implode ( ',', array_keys ( $sqlList ) );
  1433. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1434. foreach ( $sqlList as $id => $ordinal ) {
  1435. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1436. }
  1437. $sql .= "END WHERE isid IN ($ids)";
  1438. $invoiceStore = new invoiceStore ();
  1439. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1440. Doo::loadModel ( 'invoiceManage' );
  1441. $invoiceManage = new invoiceManage ();
  1442. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1443. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1444. $moldManage = array ();
  1445. foreach ( $invoiceManageList as $key => $value ) {
  1446. if ($value ['mold'] == '发票打印')
  1447. $moldManage [$value ['mold']] = $value ['staffList'];
  1448. elseif ($value ['mold'] == '发票邮寄')
  1449. $moldManage [$value ['mold']] = $value ['staffList'];
  1450. elseif ($value ['mold'] == '发票退票')
  1451. $moldManage [$value ['mold']] = $value ['staffList'];
  1452. }
  1453. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1454. // 批量更新发票信息
  1455. $item = array (
  1456. 'date' => date ( "Y-m-d H:i:s" ),
  1457. 'status' => 1,
  1458. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1459. 'trainId' => $trainId,
  1460. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1461. 'moldManage' => json_encode ( $moldManage ),
  1462. 'settlementType'=>1,
  1463. 'pendingApprovals' => $pendingApprovalsSid
  1464. );
  1465. $invoice = new invoice ();
  1466. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1467. //批量更新发票中仓库isid
  1468. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1469. foreach ( $sqlList as $isid => $iid ) {
  1470. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1471. }
  1472. $sql .= "END WHERE iid IN ($iidString)";
  1473. $invoice = new invoice ();
  1474. $invoice->UpdateBatchInvoice($sql);
  1475. // 批量更新发票序列号
  1476. $sqlList = array ();
  1477. foreach ( $iida as $value ) {
  1478. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1479. }
  1480. $ids = implode ( ',', array_keys ( $sqlList ) );
  1481. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1482. foreach ( $sqlList as $id => $ordinal ) {
  1483. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1484. }
  1485. $sql .= "END WHERE iid IN ($ids)";
  1486. $invoiceStore = new invoiceStore ();
  1487. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1488. // 批量生产操作日志
  1489. Doo::loadModel ( 'invoiceOperationLog' );
  1490. $sqlList = array ();
  1491. foreach ( $iida as $key => $value ) {
  1492. $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 . '"),
  1493. ("' . 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 . '") ';
  1494. array_push ( $sqlList, $sql );
  1495. }
  1496. $iolSql = implode ( ',', $sqlList );
  1497. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1498. $invoiceOperationLog = new invoiceOperationLog ();
  1499. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1500. Doo::loadModel ( 'invoiceTraining' );
  1501. $invoiceTraining = new invoiceTraining ();
  1502. $item = array (
  1503. 'itid' => $trainId,
  1504. 'submitStatus' => 1
  1505. );
  1506. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1507. Doo::loadModel ( 'staff' );
  1508. $staff = new staff ();
  1509. $username2 = $staff->getOne ( array (
  1510. 'select' => 'wxid',
  1511. 'where' => 'sid=' . $pendingApprovalsSid,
  1512. 'asArray' => TRUE
  1513. ) );
  1514. // 发送微信审批通知
  1515. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1516. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1517. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1518. }
  1519. /**
  1520. */
  1521. function invoiceStoreMailItemSet() {
  1522. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1523. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1524. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1525. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1526. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1527. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1528. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1529. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1530. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1531. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1532. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1533. Doo::loadClass ( 'XDeode' );
  1534. $XDeode = new XDeode ( 5 );
  1535. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1536. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1537. $isid = $XDeode->decode ( $storeKey );
  1538. $trainId = $XDeode->decode ( $trainKey );
  1539. if (! is_numeric ( $isid ))
  1540. die ( 'illegal request' );
  1541. Doo::loadModel ( 'invoiceStore' );
  1542. $invoiceStore = new invoiceStore ();
  1543. $mailList = array (
  1544. 'invoice' => 1,
  1545. 'mailItems' => $mailItems
  1546. );
  1547. if (! empty ( $softLock ))
  1548. $mailList += array (
  1549. 'softLock' => $softLockNum
  1550. );
  1551. else
  1552. $mailList += array (
  1553. 'softLock' => 0
  1554. );
  1555. if (! empty ( $contract ))
  1556. $mailList += array (
  1557. 'contract' => $contractNum
  1558. );
  1559. else
  1560. $mailList += array (
  1561. 'contract' => 0
  1562. );
  1563. if (! empty ( $instructions ))
  1564. $mailList += array (
  1565. 'instructions' => $instructionsNum
  1566. );
  1567. else
  1568. $mailList += array (
  1569. 'instructions' => 0
  1570. );
  1571. if (! empty ( $remittance ))
  1572. $mailList += array (
  1573. 'remittance' => $remittance
  1574. );
  1575. else
  1576. $mailList += array (
  1577. 'remittance' => ''
  1578. );
  1579. $mailString = '发票x1,备注:' . $mailItems;
  1580. if (! empty ( $softLock ))
  1581. $mailString .= ',软件锁x' . $softLockNum;
  1582. if (! empty ( $contract ))
  1583. $mailString .= ',合同x' . $contractNum;
  1584. if (! empty ( $instructions ))
  1585. $mailString .= ',说明书x' . $instructionsNum;
  1586. if (! empty ( $remittance ))
  1587. $mailString .= ',汇款账号单';
  1588. $item = array (
  1589. 'isid' => $isid,
  1590. 'doPost' => 1,
  1591. 'mailItems' => $mailString,
  1592. 'mailItemsJson' => json_encode ( $mailList )
  1593. );
  1594. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1595. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1596. }
  1597. /**
  1598. * 批量设置邮寄物品
  1599. */
  1600. function invoiceStoreBatchMailItemSet() {
  1601. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1602. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1603. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1604. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1605. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1606. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1607. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1608. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1609. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1610. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1611. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1612. Doo::loadClass ( 'XDeode' );
  1613. $XDeode = new XDeode ( 5 );
  1614. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1615. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1616. if (empty($trainKey)||empty($storeKey))
  1617. die ( 'illegal request-IdKey' );
  1618. $isidKeyList = explode ( ',', $storeKey );
  1619. $isidList = array ();
  1620. foreach ( $isidKeyList as $value ) {
  1621. $isid = $XDeode->decode ( $value );
  1622. if (! empty ( $isid ) && is_numeric ( $isid ))
  1623. array_push ( $isidList, $isid );
  1624. }
  1625. $isidString = implode ( ',', $isidList );
  1626. $trainId = $XDeode->decode ( $trainKey );
  1627. if (! is_numeric ( $isid ))
  1628. die ( 'illegal request' );
  1629. Doo::loadModel ( 'invoiceStore' );
  1630. $invoiceStore = new invoiceStore ();
  1631. $mailList = array (
  1632. 'invoice' => 1,
  1633. 'mailItems' => $mailItems
  1634. );
  1635. if (! empty ( $softLock ))
  1636. $mailList += array (
  1637. 'softLock' => $softLockNum
  1638. );
  1639. else
  1640. $mailList += array (
  1641. 'softLock' => 0
  1642. );
  1643. if (! empty ( $contract ))
  1644. $mailList += array (
  1645. 'contract' => $contractNum
  1646. );
  1647. else
  1648. $mailList += array (
  1649. 'contract' => 0
  1650. );
  1651. if (! empty ( $instructions ))
  1652. $mailList += array (
  1653. 'instructions' => $instructionsNum
  1654. );
  1655. else
  1656. $mailList += array (
  1657. 'instructions' => 0
  1658. );
  1659. if (! empty ( $remittance ))
  1660. $mailList += array (
  1661. 'remittance' => $remittance
  1662. );
  1663. else
  1664. $mailList += array (
  1665. 'remittance' => ''
  1666. );
  1667. $mailString = '发票x1,备注:' . $mailItems;
  1668. if (! empty ( $softLock ))
  1669. $mailString .= ',软件锁x' . $softLockNum;
  1670. if (! empty ( $contract ))
  1671. $mailString .= ',合同x' . $contractNum;
  1672. if (! empty ( $instructions ))
  1673. $mailString .= ',说明书x' . $instructionsNum;
  1674. if (! empty ( $remittance ))
  1675. $mailString .= ',汇款账号单';
  1676. $item = array (
  1677. 'doPost' => 1,
  1678. 'mailItems' => $mailString,
  1679. 'mailItemsJson' => json_encode ( $mailList )
  1680. );
  1681. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1682. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1683. }
  1684. /**
  1685. * 废弃
  1686. */
  1687. function ajaxGetMailItemByIstore() {
  1688. Doo::loadClass ( 'XDeode' );
  1689. $XDeode = new XDeode ( 5 );
  1690. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1691. $isid = $XDeode->decode ( $storeKey );
  1692. if (! is_numeric ( $isid ))
  1693. die ( 'illegal request' );
  1694. Doo::loadModel ( 'invoiceStore' );
  1695. $invoiceStore = new invoiceStore ();
  1696. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1697. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1698. echo json_encode ( $isDetail ['mailItemsJson'] );
  1699. exit ();
  1700. }
  1701. /**
  1702. * 终止开票
  1703. */
  1704. function invoiceDroppedDo() {
  1705. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1706. Doo::loadModel ( 'invoice' );
  1707. $invoice = new invoice ();
  1708. Doo::loadModel ( 'invoiceOperationLog' );
  1709. $invoiceOperationLog = new invoiceOperationLog ();
  1710. $iid = $invoice->authcode ( $droppedIidKey );
  1711. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1712. die ( 'illegal request' );
  1713. $item = array (
  1714. 'iid' => $iid,
  1715. 'status' => 4,
  1716. 'updateTime' => date ( "Y-m-d H:i:s" )
  1717. );
  1718. $invoice->setInvoiceByCondition ( $item );
  1719. $item = array (
  1720. 'date' => date ( "Y-m-d H:i:s" ),
  1721. 'operation' => '终止了开票',
  1722. 'status' => 4,
  1723. 'img' => $this->staff [0] ['avatar'],
  1724. 'username' => $this->staff [0] ['username'],
  1725. 'uid' => $this->staff [0] ['sid'],
  1726. 'category' => $this->staff [0] ['category'],
  1727. 'iid' => $iid
  1728. );
  1729. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1730. return "/invoice";
  1731. }
  1732. /**
  1733. * 更新退票的邮寄信息
  1734. */
  1735. function invoiceUntreadMailDo() {
  1736. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1737. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1738. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1739. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1740. Doo::loadModel ( 'invoice' );
  1741. $invoice = new invoice ();
  1742. $iid = $invoice->authcode ( $untreadIidKey );
  1743. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1744. die ( 'illegal request' );
  1745. $item = array (
  1746. 'iid' => $iid,
  1747. 'untreadCompany' => $untreadCompany,
  1748. 'untreadNumber' => $untreadNumber,
  1749. 'untreadItems' => $untreadItems
  1750. );
  1751. $invoice->setInvoiceByCondition ( $item );
  1752. return "/invoice";
  1753. }
  1754. /**
  1755. * 申请退票 --
  1756. */
  1757. function invoiceUntreadDo() {
  1758. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1759. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1760. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1761. Doo::loadModel ( 'invoice' );
  1762. $invoice = new invoice ();
  1763. Doo::loadModel ( 'invoiceOperationLog' );
  1764. $invoiceOperationLog = new invoiceOperationLog ();
  1765. Doo::loadModel ( 'invoiceReceivables' );
  1766. $invoiceReceivables = new invoiceReceivables ();
  1767. $iid = $invoice->authcode ( $untreadIidKey );
  1768. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1769. die ( 'illegal request' );
  1770. /*
  1771. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1772. */
  1773. $item = array (
  1774. 'iid' => $iid,
  1775. 'untreadStatus' => 1,
  1776. 'untreadReason' => $untreadReason,
  1777. 'untreadPost' => $untreadPost,
  1778. 'updateTime' => date ( "Y-m-d H:i:s" )
  1779. );
  1780. $invoice->setInvoiceByCondition ( $item );
  1781. $item = array (
  1782. 'date' => date ( "Y-m-d H:i:s" ),
  1783. 'operation' => '申请退票',
  1784. 'status' => 7,
  1785. 'img' => $this->staff [0] ['avatar'],
  1786. 'username' => $this->staff [0] ['username'],
  1787. 'uid' => $this->staff [0] ['sid'],
  1788. 'category' => $this->staff [0] ['category'],
  1789. 'iid' => $iid
  1790. );
  1791. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1792. return "/invoice";
  1793. }
  1794. /**
  1795. * 删除已终止的开票
  1796. */
  1797. function invoiceDelDo() {
  1798. Doo::loadModel ( 'invoice' );
  1799. $invoice = new invoice ();
  1800. Doo::loadModel ( 'invoiceOperationLog' );
  1801. $invoiceOperationLog = new invoiceOperationLog ();
  1802. Doo::loadClass ( 'XDeode' );
  1803. $XDeode = new XDeode ( 5 );
  1804. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1805. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1806. $iid = $XDeode->decode ( $iid );
  1807. Doo::loadModel ( 'invoiceStore' );
  1808. $invoiceStore = new invoiceStore ();
  1809. if (! is_numeric ( $iid ))
  1810. die ( 'illegal request' );
  1811. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1812. if (empty ( $invoiceDetail ))
  1813. die ( 'illegal request' );
  1814. $item = array (
  1815. 'iid' => $iid,
  1816. 'isDelete' => 1,
  1817. 'updateTime' => date ( "Y-m-d H:i:s" )
  1818. );
  1819. $invoice->setInvoiceByCondition ( $item );
  1820. $item = array (
  1821. 'date' => date ( "Y-m-d H:i:s" ),
  1822. 'operation' => '删除了已终止的发票',
  1823. 'status' => 4,
  1824. 'img' => $this->staff [0] ['avatar'],
  1825. 'username' => $this->staff [0] ['username'],
  1826. 'uid' => $this->staff [0] ['sid'],
  1827. 'category' => $this->staff [0] ['category'],
  1828. 'iid' => $iid
  1829. );
  1830. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1831. // 删除培训班发票仓库里的发票
  1832. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1833. return "/invoice";
  1834. }
  1835. /**
  1836. */
  1837. function invoiceApproval() {
  1838. Doo::loadModel ( 'invoice' );
  1839. $invoice = new invoice ();
  1840. Doo::loadClass ( 'XDeode' );
  1841. $XDeode = new XDeode ( 5 );
  1842. Doo::loadModel ( 'staff' );
  1843. $staff = new staff ();
  1844. $invoiceList = $invoice->find ( array (
  1845. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1846. 'desc' => 'iid',
  1847. 'limit' => 10,
  1848. 'asArray' => true
  1849. ) );
  1850. foreach ( $invoiceList as $key => $value ) {
  1851. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1852. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1853. if (! empty ( $lastApprover )) {
  1854. $lastApproverKey = array_keys ( $lastApprover );
  1855. $lastApprover = end ( $lastApprover );
  1856. $staffDetail = $staff->getOne ( array (
  1857. 'where' => 'sid=' . end ( $lastApproverKey ),
  1858. 'asArray' => true
  1859. ) );
  1860. $lastApprover ['username'] = $staffDetail ['username'];
  1861. }
  1862. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1863. }
  1864. $ilist = $invoice->getInvoiceByProcessStatus ();
  1865. foreach ( $ilist as $key => $value ) {
  1866. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1867. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1868. if (! empty ( $lastApprover )) {
  1869. $lastApproverKey = array_keys ( $lastApprover );
  1870. $lastApprover = end ( $lastApprover );
  1871. $staffDetail = $staff->getOne ( array (
  1872. 'where' => 'sid=' . end ( $lastApproverKey ),
  1873. 'asArray' => true
  1874. ) );
  1875. $lastApprover ['username'] = $staffDetail ['username'];
  1876. }
  1877. $ilist [$key] ['lastApprover'] = $lastApprover;
  1878. }
  1879. // print_r($ilist);
  1880. $this->data ['invoiceList'] = $invoiceList;
  1881. $this->data ['ilist'] = $ilist;
  1882. $this->data ['memu'] = "invoice";
  1883. $this->data ['staff'] = $this->staff;
  1884. $this->data ['receiptMemu'] = 'invoiceApproval';
  1885. $this->render ( "/admin/invoiceApproval", $this->data );
  1886. }
  1887. function invoiceDetail() {
  1888. Doo::loadClass ( 'XDeode' );
  1889. $XDeode = new XDeode ( 5 );
  1890. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1891. $iid = $XDeode->decode ( $iid );
  1892. if (! is_numeric ( $iid ))
  1893. die ( 'illegal request' );
  1894. Doo::loadModel ( 'invoice' );
  1895. $invoice = new invoice ();
  1896. Doo::loadModel ( 'invoiceOperationLog' );
  1897. $invoiceOperationLog = new invoiceOperationLog ();
  1898. $invoiceDetail = $invoice->getOne ( array (
  1899. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1900. 'asArray' => true
  1901. ) );
  1902. if (empty ( $invoiceDetail ))
  1903. die ( 'illegal request' );
  1904. if ($invoiceDetail ['settlementType'] == 1) {
  1905. Doo::loadModel ( 'invoiceTraining' );
  1906. $invoiceTraining = new invoiceTraining ();
  1907. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  1908. }
  1909. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1910. $this->data ['invoiceDetail'] = $invoiceDetail;
  1911. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1912. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1913. $this->data ['memu'] = "invoice";
  1914. $this->data ['staff'] = $this->staff;
  1915. $this->data ['receiptMemu'] = 'invoiceApproval';
  1916. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1917. }
  1918. /**
  1919. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1920. *
  1921. * @since 1.0.0
  1922. * @var integer iid 开票ID 已加密
  1923. * @var integer status 发票审批状态
  1924. * @var integer opintion 审批发票的意见
  1925. * @return string 如操作成功返回审批首页
  1926. */
  1927. function invoiceApprovalDo() {
  1928. Doo::loadModel ( 'invoice' );
  1929. $invoice = new invoice ();
  1930. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1931. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1932. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1933. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  1934. $iid = $invoice->authcode ( $iid );
  1935. if (! is_numeric ( $iid ))
  1936. die ( 'illegal request' );
  1937. // && ! empty ( $opinion )
  1938. if (! empty ( $iid ) && ! empty ( $status )) {
  1939. if (! ($status == 2 || $status == 3 || $status == 4))
  1940. die ( 'illegal request' );
  1941. Doo::loadModel ( 'invoiceOperationLog' );
  1942. $invoiceOperationLog = new invoiceOperationLog ();
  1943. $invoiceDetail = $invoice->getOne ( array (
  1944. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1945. 'asArray' => true
  1946. ) );
  1947. if (empty ( $invoiceDetail ))
  1948. die ( 'illegal request' );
  1949. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1950. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1951. if ($status == 3) {
  1952. $invoice->status = $status;
  1953. $item = array (
  1954. 'operation' => $opinion
  1955. );
  1956. } else {
  1957. if (empty ( $processApprovals )) {
  1958. $processApprovals = array (
  1959. $this->staff [0] ['sid'] => array (
  1960. 'date' => date ( "Y-m-d H:i:s" ),
  1961. 'opinion' => $opinion,
  1962. 'status' => $status
  1963. )
  1964. );
  1965. // var_dump(next($invoiceManage));
  1966. $nextInvoiceManage = next ( $invoiceManage );
  1967. // print_r($nextInvoiceManage);
  1968. if ($status != 4 && $nextInvoiceManage !== false)
  1969. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1970. $invoice->processApprovals = json_encode ( $processApprovals );
  1971. // var_dump($invoice);
  1972. // print_r($invoiceManage);
  1973. } else {
  1974. $processApprovals [$this->staff [0] ['sid']] = array (
  1975. 'date' => date ( "Y-m-d H:i:s" ),
  1976. 'opinion' => $opinion,
  1977. 'status' => $status
  1978. );
  1979. $pendingApprovals = 0;
  1980. foreach ( $invoiceManage as $key => $value ) {
  1981. if ($value [0] == $this->staff [0] ['sid']) {
  1982. if (isset ( $invoiceManage [$key + 1] ))
  1983. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1984. break;
  1985. }
  1986. }
  1987. if ($status != 4 && ! empty ( $pendingApprovals ))
  1988. $invoice->pendingApprovals = $pendingApprovals;
  1989. $invoice->processApprovals = json_encode ( $processApprovals );
  1990. }
  1991. $item = array (
  1992. 'operation' => $opinion
  1993. );
  1994. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1995. $invoice->status = $status;
  1996. $invoice->pendingApprovals = 0;
  1997. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1998. } elseif ($status == 4) {
  1999. $invoice->status = $status;
  2000. $item = array (
  2001. 'operation' => $opinion
  2002. );
  2003. }
  2004. }
  2005. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2006. $invoice->update ( array (
  2007. 'where' => 'iid=' . $iid
  2008. ) );
  2009. $item += array (
  2010. 'date' => date ( "Y-m-d H:i:s" ),
  2011. 'img' => $this->staff [0] ['avatar'],
  2012. 'username' => $this->staff [0] ['username'],
  2013. 'uid' => $this->staff [0] ['sid'],
  2014. 'category' => $this->staff [0] ['category'],
  2015. 'status' => $status,
  2016. 'iid' => $iid
  2017. );
  2018. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2019. if (empty ( $divApproval ))
  2020. return '/invoiceApproval';
  2021. else
  2022. return '/invoiceApprovalAchieve/PEND';
  2023. }
  2024. die ( 'illegal request' );
  2025. }
  2026. /**
  2027. * 展示需要打印的发票数据
  2028. *
  2029. * @since 1.0.0
  2030. */
  2031. function invoicePrint() {
  2032. Doo::loadModel ( 'invoice' );
  2033. $invoice = new invoice ();
  2034. Doo::loadClass ( 'XDeode' );
  2035. $XDeode = new XDeode ( 5 );
  2036. Doo::loadModel ( 'staff' );
  2037. $staff = new staff ();
  2038. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2039. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2040. foreach ( $toPrint as $key => $value ) {
  2041. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2042. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2043. if (! empty ( $lastApprover )) {
  2044. $lastApproverKey = array_keys ( $lastApprover );
  2045. $lastApprover = end ( $lastApprover );
  2046. $staffDetail = $staff->getOne ( array (
  2047. 'where' => 'sid=' . end ( $lastApproverKey ),
  2048. 'asArray' => true
  2049. ) );
  2050. $lastApprover ['username'] = $staffDetail ['username'];
  2051. }
  2052. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2053. }
  2054. foreach ( $printed as $key => $value ) {
  2055. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2056. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2057. if (! empty ( $lastApprover )) {
  2058. $lastApproverKey = array_keys ( $lastApprover );
  2059. $lastApprover = end ( $lastApprover );
  2060. $staffDetail = $staff->getOne ( array (
  2061. 'where' => 'sid=' . end ( $lastApproverKey ),
  2062. 'asArray' => true
  2063. ) );
  2064. $lastApprover ['username'] = $staffDetail ['username'];
  2065. }
  2066. $printed [$key] ['lastApprover'] = $lastApprover;
  2067. }
  2068. $this->data ['printed'] = $printed;
  2069. $this->data ['toPrint'] = $toPrint;
  2070. $this->data ['memu'] = "invoice";
  2071. $this->data ['staff'] = $this->staff;
  2072. $this->data ['receiptMemu'] = 'invoicePrint';
  2073. $this->render ( "/admin/invoicePrint", $this->data );
  2074. }
  2075. /**
  2076. * 展示发票打印的详情页面
  2077. *
  2078. * @since 1.0.0
  2079. */
  2080. function invoicePrintDetail() {
  2081. Doo::loadClass ( 'XDeode' );
  2082. $XDeode = new XDeode ( 5 );
  2083. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2084. $iid = $XDeode->decode ( $iid );
  2085. if (! is_numeric ( $iid ))
  2086. die ( 'illegal request' );
  2087. Doo::loadModel ( 'invoice' );
  2088. $invoice = new invoice ();
  2089. Doo::loadModel ( 'invoiceOperationLog' );
  2090. $invoiceOperationLog = new invoiceOperationLog ();
  2091. Doo::loadModel ( 'invoicePaper' );
  2092. $invoicePaper = new invoicePaper ();
  2093. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2094. if (empty ( $invoiceDetail ))
  2095. die ( 'illegal request' );
  2096. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  2097. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2098. if ($invoiceDetail ['settlementType'] == 1) {
  2099. Doo::loadModel ( 'invoiceTraining' );
  2100. $invoiceTraining = new invoiceTraining ();
  2101. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2102. }
  2103. $this->data ['invoicePaperList'] = $invoicePaperList;
  2104. $this->data ['invoiceDetail'] = $invoiceDetail;
  2105. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2106. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2107. $this->data ['memu'] = "invoice";
  2108. $this->data ['staff'] = $this->staff;
  2109. $this->data ['receiptMemu'] = 'invoicePrint';
  2110. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2111. }
  2112. /**
  2113. * 所有待打印 发票
  2114. */
  2115. function invoicePrintStayAchieve() {
  2116. Doo::loadModel ( 'invoice' );
  2117. $invoice = new invoice ();
  2118. Doo::loadClass ( 'XDeode' );
  2119. $XDeode = new XDeode ( 5 );
  2120. Doo::loadModel ( 'staff' );
  2121. $staff = new staff ();
  2122. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2123. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2124. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2125. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2126. Doo::loadModel ( 'invoiceTraining' );
  2127. $invoiceTraining = new invoiceTraining ();
  2128. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2129. $page_size = 12;
  2130. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2131. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2132. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2133. $get = "/" . $status;
  2134. $con = ' and status=2 ';
  2135. if ($status == 'TOPRINT')
  2136. $con = ' and status=2 and printStatus=0 ';
  2137. elseif ($status == 'PRINTED')
  2138. $con = ' and status=2 and printStatus=1';
  2139. if ($invoiceType == 'ORDINARY')
  2140. $con .= ' and invoiceType=0 ';
  2141. elseif ($invoiceType == 'SPECIAL')
  2142. $con .= ' and invoiceType=1 ';
  2143. if ($invoiceTrain == 'ORDINARY')
  2144. $con .= ' and trainId=0 ';
  2145. elseif ($invoiceTrain == 'TRAIN')
  2146. $con .= ' and trainId!=0 ';
  2147. if ($invoiceTrainName != 'ALL') {
  2148. $trainId = $XDeode->decode ( $invoiceTrainName );
  2149. if (is_numeric ( $trainId ))
  2150. $con .= ' and trainId =' . $trainId;
  2151. }
  2152. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2153. $dateArr = explode ( ':', $date );
  2154. $D1 = '';
  2155. $D2 = '';
  2156. if (! empty ( $date )) {
  2157. $D1 = $dateArr [0];
  2158. $D2 = $dateArr [1];
  2159. }
  2160. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2161. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2162. if (! empty ( $MebSea )) {
  2163. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2164. }
  2165. $pageinfo ['page'] = array (
  2166. 'previous' => ''
  2167. );
  2168. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea )."&invoiceType=".urlencode ( $invoiceType )."&invoiceTrain=".urlencode ( $invoiceTrain )."";
  2169. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2170. $action = "invoicePrintStayAchieve";
  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, 'desc', 5 );
  2174. $this->data ['trainList'] = $trainList;
  2175. $this->data ['invoiceType'] = $invoiceType;
  2176. $this->data ['invoiceTrain'] = $invoiceTrain;
  2177. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2178. $this->data ['MebSeaEn'] = $MebSea;
  2179. $this->data ['MebSea'] = urlencode ( $MebSea );
  2180. $this->data ['get'] = $get;
  2181. $this->data ['page'] = $pageinfo;
  2182. $this->data ['date'] = $date;
  2183. $this->data ['status'] = $status;
  2184. $this->data ['invoiceType'] = $invoiceType;
  2185. $this->data ['memu'] = "invoice";
  2186. $this->data ['staff'] = $this->staff;
  2187. foreach ( $list as $key => $value ) {
  2188. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2189. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2190. if (! empty ( $lastApprover )) {
  2191. $lastApproverKey = array_keys ( $lastApprover );
  2192. $lastApprover = end ( $lastApprover );
  2193. $staffDetail = $staff->getOne ( array (
  2194. 'where' => 'sid=' . end ( $lastApproverKey ),
  2195. 'asArray' => true
  2196. ) );
  2197. $lastApprover ['username'] = $staffDetail ['username'];
  2198. }
  2199. $list [$key] ['lastApprover'] = $lastApprover;
  2200. }
  2201. $this->data ['receiptMemu'] = 'invoicePrint';
  2202. $this->data ['list'] = $list;
  2203. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2204. }
  2205. /**
  2206. * 填写票号并完成打印
  2207. * @since 1.0.0
  2208. */
  2209. function invoicePrintDo() {
  2210. Doo::loadModel ( 'invoice' );
  2211. $invoice = new invoice ();
  2212. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2213. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2214. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2215. $iid = $invoice->authcode ( $iid );
  2216. if (! is_numeric ( $iid ))
  2217. die ( 'illegal request' );
  2218. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2219. Doo::loadModel ( 'invoiceOperationLog' );
  2220. $invoiceOperationLog = new invoiceOperationLog ();
  2221. Doo::loadModel ( 'invoiceStatistics' );
  2222. $invoiceStatistics = new invoiceStatistics ();
  2223. $XDeode = new XDeode ( 5 );
  2224. Doo::loadModel ( 'invoicePaper' );
  2225. $invoicePaper = new invoicePaper ();
  2226. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2227. if (empty ( $invoicePrintDetail ))
  2228. die ( 'illegal request' );
  2229. //
  2230. $ipid = $XDeode->decode ( $invoiceNo );
  2231. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2232. if (empty ( $paperDetail ))
  2233. die ( 'illegal request' );
  2234. $invoicePaper = new invoicePaper ();
  2235. $item = array (
  2236. 'iid' => $iid,
  2237. 'ipid' => $ipid
  2238. );
  2239. $invoicePaper->setInvoicePaperByCondition ( $item );
  2240. $item = array (
  2241. 'iid' => $iid,
  2242. 'printStatus' => 1,
  2243. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2244. 'printer' => $this->staff [0] ['username'],
  2245. 'printTime' => date ( "Y-m-d H:i:s" ),
  2246. 'invoiceNo' => $paperDetail ['invoiceNo']
  2247. );
  2248. $invoice->setInvoiceByCondition ( $item );
  2249. $item = array (
  2250. 'date' => date ( "Y-m-d H:i:s" ),
  2251. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2252. 'status' => 5,
  2253. 'img' => $this->staff [0] ['avatar'],
  2254. 'username' => $this->staff [0] ['username'],
  2255. 'uid' => $this->staff [0] ['sid'],
  2256. 'category' => $this->staff [0] ['category'],
  2257. 'iid' => $iid
  2258. );
  2259. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2260. // 去统计--负票不汇总
  2261. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2262. $item = array (
  2263. 'date' => date ( "Y-m-d H:i:s" ),
  2264. 'priceClass' => 1,
  2265. 'cid' => $invoicePrintDetail ['cid'],
  2266. 'staff' => $invoicePrintDetail ['sid'],
  2267. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2268. );
  2269. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2270. }
  2271. // 发送通知信息到微信-去除
  2272. // $this->setWXMsg($iid,'PRINT');
  2273. // 申请人获取微信通知
  2274. Doo::loadModel ( 'staff' );
  2275. $staff = new staff ();
  2276. Doo::loadClass ( 'XDeode' );
  2277. $XDeode = new XDeode ( 5 );
  2278. $username2 = $staff->getOne ( array (
  2279. 'select' => 'wxid',
  2280. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2281. 'asArray' => TRUE
  2282. ) );
  2283. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2284. $msg = '';
  2285. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2286. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2287. if (empty ( $invoicePrintType ))
  2288. return "/invoicePrint";
  2289. else
  2290. return "/invoicePrintStayAchieve";
  2291. }
  2292. }
  2293. /**
  2294. * 需要邮寄的发票
  2295. * @since 1.0.0
  2296. */
  2297. function invoicePost() {
  2298. Doo::loadModel ( 'invoice' );
  2299. $invoice = new invoice ();
  2300. Doo::loadModel ( 'express' );
  2301. $express = new express ();
  2302. $invoicePost = $invoice->getPostByInvoice ();
  2303. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2304. $expressList = $express->getExpressByAll ();
  2305. $invoicePostExpress = "";
  2306. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2307. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2308. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2309. $this->data ['expressList'] = $expressList;
  2310. $this->data ['invoicePost'] = $invoicePost;
  2311. $this->data ['invoicePosted'] = $invoicePosted;
  2312. $this->data ['memu'] = "invoice";
  2313. $this->data ['staff'] = $this->staff;
  2314. $this->data ['receiptMemu'] = 'invoicePost';
  2315. $this->render ( "/admin/invoicePost", $this->data );
  2316. }
  2317. /**
  2318. * 添加发票邮寄信息
  2319. */
  2320. function invoiceExpressAddDo() {
  2321. Doo::loadModel ( 'invoice' );
  2322. $invoice = new invoice ();
  2323. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2324. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2325. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2326. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2327. $iid = $iid = $invoice->authcode ( $iid );
  2328. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2329. die ( 'illegal request' );
  2330. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2331. setcookie ( 'invoicePostExpress', $expressNumber );
  2332. $item = array (
  2333. 'iid' => $iid,
  2334. 'postStatus' => 1,
  2335. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2336. 'postTime' => date ( "Y-m-d H:i:s" ),
  2337. 'expressCompany' => $expressCompany,
  2338. 'expressNumber' => $expressNumber,
  2339. 'actualItems' => $actualItems,
  2340. 'poster' => $this->staff [0] ['username']
  2341. );
  2342. $invoice->setInvoiceByCondition ( $item );
  2343. // 微信通知-去掉
  2344. // $this->setWXMsg ( $iid );
  2345. Doo::loadModel ( 'staff' );
  2346. $staff = new staff ();
  2347. Doo::loadClass ( 'XDeode' );
  2348. $XDeode = new XDeode ( 5 );
  2349. $username2 = $staff->getOne ( array (
  2350. 'select' => 'wxid',
  2351. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2352. 'asArray' => TRUE
  2353. ) );
  2354. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2355. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2356. if (empty ( $expCom ))
  2357. $expCom [0] = '';
  2358. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2359. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2360. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2361. return '/invoicePost';
  2362. }
  2363. function invoiceExpressUpdateDo() {
  2364. Doo::loadModel ( 'invoice' );
  2365. $invoice = new invoice ();
  2366. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2367. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2368. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2369. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2370. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2371. $iid = $invoice->authcode ( $iid );
  2372. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2373. die ( 'illegal request' );
  2374. $item = array (
  2375. 'iid' => $iid,
  2376. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2377. 'expressCompany' => $expressCompany,
  2378. 'expressNumber' => $expressNumber,
  2379. 'actualItems' => $actualItems,
  2380. 'poster' => $this->staff [0] ['username']
  2381. );
  2382. $invoice->setInvoiceByCondition ( $item );
  2383. return $action;
  2384. }
  2385. /**
  2386. * 可退票管理
  2387. */
  2388. function invoiceUntreadIsAchieve() {
  2389. Doo::loadModel ( 'invoice' );
  2390. $invoice = new invoice ();
  2391. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2392. /*
  2393. Doo::loadClass ( 'XDeode' );
  2394. $XDeode = new XDeode ( 5 );
  2395. $page_size = 18;
  2396. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2397. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2398. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2399. $dateArr = explode ( ':', $date );
  2400. $D1 = '';
  2401. $D2 = '';
  2402. if (! empty ( $date )) {
  2403. $D1 = $dateArr [0];
  2404. $D2 = $dateArr [1];
  2405. }
  2406. $con = '';
  2407. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2408. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2409. // if ($date == 'MONTHO')
  2410. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2411. // elseif ($date == 'MONTHT')
  2412. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2413. // elseif ($date == 'MONTHY')
  2414. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2415. if (! empty ( $MebSea )) {
  2416. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2417. }
  2418. $pageinfo ['page'] = array (
  2419. 'previous' => ''
  2420. );
  2421. */
  2422. if (empty($MebSea)){
  2423. $con = ' and invoiceNo like "NULL" ';
  2424. }else {
  2425. $con = ' and invoiceNo like "%' . $MebSea . '%" ';
  2426. }
  2427. // printStatus=1 and
  2428. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] .$con ;
  2429. /*
  2430. $action = "invoiceUntreadIsAchieve";
  2431. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2432. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2433. */
  2434. $limit = '0,1' ;
  2435. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2436. //print_r($list);
  2437. $this->data ['MebSeaEn'] = $MebSea;
  2438. /*
  2439. $this->data ['get'] = $get;
  2440. $this->data ['page'] = $pageinfo;
  2441. $this->data ['date'] = $date;
  2442. */
  2443. $this->data ['list'] = $list;
  2444. $this->data ['memu'] = "invoice";
  2445. $this->data ['staff'] = $this->staff;
  2446. $this->data ['receiptMemu'] = 'invoice';
  2447. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2448. }
  2449. //已经退票的发票
  2450. function invoiceUntreadED(){
  2451. Doo::loadModel ( 'invoice' );
  2452. $invoice = new invoice ();
  2453. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2454. /*
  2455. Doo::loadClass ( 'XDeode' );
  2456. $XDeode = new XDeode ( 5 );
  2457. $page_size = 18;
  2458. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2459. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2460. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2461. $dateArr = explode ( ':', $date );
  2462. $D1 = '';
  2463. $D2 = '';
  2464. if (! empty ( $date )) {
  2465. $D1 = $dateArr [0];
  2466. $D2 = $dateArr [1];
  2467. }
  2468. $con = '';
  2469. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2470. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2471. // if ($date == 'MONTHO')
  2472. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2473. // elseif ($date == 'MONTHT')
  2474. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2475. // elseif ($date == 'MONTHY')
  2476. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2477. if (! empty ( $MebSea )) {
  2478. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2479. }
  2480. $pageinfo ['page'] = array (
  2481. 'previous' => ''
  2482. );
  2483. */
  2484. if (empty($MebSea)){
  2485. $con = ' and invoiceNo like "NULL" ';
  2486. }else {
  2487. $con = ' and invoiceNo like "%' . $MebSea . '%" ';
  2488. }
  2489. // printStatus=1 and
  2490. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] .$con ;
  2491. /*
  2492. $action = "invoiceUntreadIsAchieve";
  2493. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2494. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2495. */
  2496. $limit = '0,1' ;
  2497. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2498. //print_r($list);
  2499. $this->data ['MebSeaEn'] = $MebSea;
  2500. /*
  2501. $this->data ['get'] = $get;
  2502. $this->data ['page'] = $pageinfo;
  2503. $this->data ['date'] = $date;
  2504. */
  2505. $this->data ['list'] = $list;
  2506. $this->data ['memu'] = "invoice";
  2507. $this->data ['staff'] = $this->staff;
  2508. $this->data ['receiptMemu'] = 'invoice';
  2509. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2510. }
  2511. /**
  2512. * 退票处理页面
  2513. */
  2514. function invoiceUntread() {
  2515. Doo::loadModel ( 'invoice' );
  2516. $invoice = new invoice ();
  2517. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 ,0,50);
  2518. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2519. foreach ( $establishedInvoice as $key => $value ) {
  2520. // months
  2521. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2522. $nowDate = strtotime ( 'now' );
  2523. $establishedInvoice [$key] ['lossShow'] = false;
  2524. if ($lossDate < $nowDate)
  2525. $establishedInvoice [$key] ['lossShow'] = true;
  2526. }
  2527. $this->data ['untreadInvoice'] = $untreadInvoice;
  2528. $this->data ['establishedInvoice'] = $establishedInvoice;
  2529. $this->data ['memu'] = "invoice";
  2530. $this->data ['staff'] = $this->staff;
  2531. $this->data ['receiptMemu'] = 'invoiceUntread';
  2532. $this->render ( "/admin/invoiceUntread", $this->data );
  2533. }
  2534. /**
  2535. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2536. */
  2537. function invoiceUntreadEstablishedDo() {
  2538. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2539. Doo::loadModel ( 'invoice' );
  2540. $invoice = new invoice ();
  2541. Doo::loadModel ( 'invoiceOperationLog' );
  2542. $invoiceOperationLog = new invoiceOperationLog ();
  2543. Doo::loadModel ( 'invoiceReceivables' );
  2544. Doo::loadModel ( 'invoiceStatistics' );
  2545. $iid = $invoice->authcode ( $untreadIidKey );
  2546. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2547. die ( 'illegal request' );
  2548. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2549. if ($invoiceDetails ['untreadStatus'] != 1)
  2550. die ( 'illegal request' );
  2551. $item = array (
  2552. 'iid' => $iid,
  2553. // 'irid'=>'',
  2554. 'untreadStatus' => 2,
  2555. 'updateTime' => date ( "Y-m-d H:i:s" )
  2556. );
  2557. $invoice->setInvoiceByCondition ( $item );
  2558. $item = array (
  2559. 'date' => date ( "Y-m-d H:i:s" ),
  2560. 'operation' => '已确认退票',
  2561. 'status' => 6,
  2562. 'img' => $this->staff [0] ['avatar'],
  2563. 'username' => $this->staff [0] ['username'],
  2564. 'uid' => $this->staff [0] ['sid'],
  2565. 'category' => $this->staff [0] ['category'],
  2566. 'iid' => $iid
  2567. );
  2568. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2569. // 收款解绑以及入账扣除 收款扣除
  2570. if (! empty ( $invoiceDetails ['irid'] )) {
  2571. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2572. foreach ( $iridList as $value ) {
  2573. $invoiceReceivables = new invoiceReceivables ();
  2574. $irDetails = $invoiceReceivables->getOne ( array (
  2575. 'where' => " irid=" . $value . ' and bindStatus=1',
  2576. 'asArray' => TRUE
  2577. ) );
  2578. $item = array (
  2579. 'irid' => $value,
  2580. 'bindStatus' => 0,
  2581. 'untreadStatus' => 1,
  2582. 'untreadStaff' => $invoiceDetails ['userName'],
  2583. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2584. 'iid' => 0
  2585. );
  2586. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2587. if (! empty ( $irDetails )) {
  2588. // 扣除入账
  2589. $invoiceStatistics = new invoiceStatistics ();
  2590. $item = array (
  2591. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2592. 'priceClass' => 3,
  2593. 'cid' => $invoiceDetails ['cid'],
  2594. 'staff' => $invoiceDetails ['sid'],
  2595. 'accountPrice' => - $irDetails ['receivablesPrice']
  2596. );
  2597. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2598. // 扣除收款
  2599. $invoiceStatistics = new invoiceStatistics ();
  2600. $item = array (
  2601. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2602. 'priceClass' => 2,
  2603. 'cid' => $invoiceDetails ['cid'],
  2604. 'staff' => $invoiceDetails ['sid'],
  2605. 'irid' => $irDetails ['irid'],
  2606. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2607. );
  2608. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2609. }
  2610. // 解绑时删除收入流水
  2611. Doo::loadModel ( 'wasteBook' );
  2612. $wasteBook = new wasteBook ();
  2613. $wasteBook->delete ( array (
  2614. 'where' => 'dataID=' . $value . ' and accountType=7',
  2615. 'limit' => 1
  2616. ) );
  2617. }
  2618. }
  2619. return "/invoiceUntread";
  2620. }
  2621. /**
  2622. * 建立负票,关联原来发票
  2623. */
  2624. function invoiceLossDo() {
  2625. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2626. if (! empty ( $iidKey )) {
  2627. Doo::loadClass ( 'XDeode' );
  2628. $XDeode = new XDeode ( 5 );
  2629. Doo::loadModel ( 'invoice' );
  2630. $invoice = new invoice ();
  2631. Doo::loadModel ( 'invoiceOperationLog' );
  2632. $invoiceOperationLog = new invoiceOperationLog ();
  2633. $iidKey = $XDeode->decode ( $iidKey );
  2634. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2635. // 拷贝插入一条发票数据
  2636. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2637. // 更新负票
  2638. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2639. $invoice = new invoice ();
  2640. $item = array (
  2641. 'iid' => $iid,
  2642. 'sid' => $this->staff [0] ['sid'],
  2643. 'userName' => $this->staff [0] ['username'],
  2644. 'cid' => $this->staff [0] ['cid'],
  2645. 'categoryName' => $this->staff [0] ['category'],
  2646. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2647. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2648. 'invoiceSerial' => $invoiceSerial,
  2649. 'invoiceNo' => '',
  2650. 'printStatus' => 0,
  2651. 'untreadStatus' => 4,
  2652. // 关联发票号
  2653. 'lossIid' => $invoiceDetail ['iid']
  2654. );
  2655. $invoice->setInvoiceByCondition ( $item );
  2656. // 更新原发票
  2657. $invoice = new invoice ();
  2658. $item = array (
  2659. 'iid' => $invoiceDetail ['iid'],
  2660. 'lossIid' => $iid
  2661. );
  2662. $invoice->setInvoiceByCondition ( $item );
  2663. // 操作日志
  2664. $item = array (
  2665. 'date' => date ( "Y-m-d H:i:s" ),
  2666. 'operation' => "创建负票" . $invoiceSerial,
  2667. 'status' => 12,
  2668. 'img' => $this->staff [0] ['avatar'],
  2669. 'username' => $this->staff [0] ['username'],
  2670. 'uid' => $this->staff [0] ['sid'],
  2671. 'category' => $this->staff [0] ['category'],
  2672. 'iid' => $iid
  2673. );
  2674. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2675. // print_r($invoiceDetail);
  2676. // echo $iid;die;
  2677. }
  2678. return '/invoiceUntread';
  2679. }
  2680. /**
  2681. * 上传银行到账 收款文件
  2682. */
  2683. function invoiceReceivablesBankUpload() {
  2684. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2685. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2686. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2687. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2688. header ( "HTTP/1.1 500 Internal Server Error" );
  2689. echo "POST exceeded maximum allowed size.";
  2690. exit ( 0 );
  2691. }
  2692. // Settings
  2693. $save_path = DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/"; // The path were we will save the file (getcwd() may not be reliable and should be tested in your environment)
  2694. $upload_name = "Filedata";
  2695. $file_name = "";
  2696. $nk = time ();
  2697. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2698. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2699. echo "文件无法保存.";
  2700. exit ( 0 );
  2701. }
  2702. echo json_encode ( array (
  2703. 'filename' => $file_name,
  2704. 'id' => $nk
  2705. ) );
  2706. exit ( 0 );
  2707. }
  2708. /**
  2709. * 解析银行到账收款execl并导入库中
  2710. */
  2711. function invoiceReceivablesImport() {
  2712. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2713. if ($path != "") {
  2714. Doo::loadModel ( 'invoiceReceivables' );
  2715. $invoiceReceivables = new invoiceReceivables ();
  2716. Doo::loadClass ( 'invoice.func' );
  2717. Doo::loadModel ( 'invoiceROLog' );
  2718. $invoiceROLog = new invoiceROLog ();
  2719. Doo::loadModel ( 'invoiceStatistics' );
  2720. $invoiceStatistics = new invoiceStatistics ();
  2721. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2722. $bankBatchNumber = 'BBN_' . time ();
  2723. Doo::db ()->beginTransaction ();
  2724. // 批量存储收款--由于必须获得收款ID,
  2725. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2726. VALUES ';
  2727. $date = date ( "Y-m-d" );
  2728. $receivablesList = array ();
  2729. foreach ( $exlArray as $key => $value ) {
  2730. $receivablesSql = '(' . $value ["receivablesPrice"] . ',' . $value ["receivablesPrice"] . ',"' . $value ["receivablesMessage"] . '",' . '"#SK' . date ( "Ymd" ) . mt_rand ( 1000, 9999 ) . '","' . $value ["receivablesBank"] . '","' . $value ["receivablesDate"] . '","' . $this->staff [0] ['username'] . '","' . $date . '","PUBLIC","PUBLIC","' . $bankBatchNumber . '","' . $value ["receivablesMessage"] . '")';
  2731. array_push ( $receivablesList, $receivablesSql );
  2732. }
  2733. $sql = $sql . implode ( ',', $receivablesList );
  2734. // echo $sql;
  2735. Doo::db ()->query ( $sql );
  2736. // 批量存储收款统计
  2737. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2738. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2739. // 没有irid 回滚所有操作
  2740. if (empty ( $iridList )) {
  2741. Doo::db ()->rollBack ();
  2742. header ( 'Content-Type:text/html;charset=utf-8' );
  2743. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2744. }
  2745. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2746. VALUES ';
  2747. $statisticsList = array ();
  2748. foreach ( $iridList as $value ) {
  2749. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2750. array_push ( $statisticsList, $statisticsSql );
  2751. }
  2752. $sql = $sql . implode ( ',', $statisticsList );
  2753. Doo::db ()->query ( $sql );
  2754. // 批量存储操作日志
  2755. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2756. VALUES ';
  2757. $ROLogList = array ();
  2758. foreach ( $iridList as $value ) {
  2759. $ROLogSql = '("' . $this->staff [0] ['username'] . ' 转入 公共待认领款项","' . $date . '",1,"' . $this->staff [0] ['avatar'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . $this->staff [0] ['category'] . '","' . $value ['irid'] . '")';
  2760. array_push ( $ROLogList, $ROLogSql );
  2761. }
  2762. $sql = $sql . implode ( ',', $ROLogList );
  2763. Doo::db ()->query ( $sql );
  2764. // 批量写入流水
  2765. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  2766. VALUES ';
  2767. $wasteBookList = array ();
  2768. foreach ( $iridList as $value ) {
  2769. $accountBank = '';
  2770. if ($value ['receivablesBank'] == '纵横广发') {
  2771. $accountBank = 'CGBDeposit';
  2772. } elseif ($value ['receivablesBank'] == '纵横工行') {
  2773. $accountBank = 'ICBCDeposit';
  2774. } elseif ($value ['receivablesBank'] == '华润银行') {
  2775. $accountBank = 'HUADeposit';
  2776. } elseif ($value ['receivablesBank'] == '个人广发') {
  2777. $accountBank = 'PersonalDeposit';
  2778. }
  2779. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  2780. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  2781. array_push ( $wasteBookList, $wasteBookSql );
  2782. }
  2783. $sql = $sql . implode ( ',', $wasteBookList );
  2784. Doo::db ()->query ( $sql );
  2785. Doo::db ()->commit ();
  2786. return "/invoiceReceivables";
  2787. }
  2788. echo 'no file';
  2789. }
  2790. function invoiceReceivables() {
  2791. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2792. Doo::loadModel ( 'L_category' );
  2793. $lCategory = new L_category ();
  2794. Doo::loadModel ( 'staff' );
  2795. $staff = new staff ();
  2796. Doo::loadModel ( 'invoiceReceivables' );
  2797. $invoiceReceivables = new invoiceReceivables ();
  2798. Doo::loadModel ( 'invoice' );
  2799. $invoice = new invoice ();
  2800. Doo::loadClass ( 'XDeode' );
  2801. $XDeode = new XDeode ( 5 );
  2802. $category = $lCategory->getCategory ();
  2803. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2804. $sql = 'bindStatus=1 and iid!=0';
  2805. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2806. // 获取未入账发票
  2807. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2808. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2809. foreach ( $invoiceUnAccount as $key => $value ) {
  2810. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2811. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2812. if (! empty ( $lastApprover )) {
  2813. $lastApproverKey = array_keys ( $lastApprover );
  2814. $lastApprover = end ( $lastApprover );
  2815. $staffDetail = $staff->getOne ( array (
  2816. 'where' => 'sid=' . end ( $lastApproverKey ),
  2817. 'asArray' => true
  2818. ) );
  2819. $lastApprover ['username'] = $staffDetail ['username'];
  2820. }
  2821. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2822. }
  2823. foreach ( $invoiceExistAccount as $key => $value ) {
  2824. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2825. if (empty ( $irList ))
  2826. $irList [0] ['sumPrice'] = 0;
  2827. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2828. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2829. $invoiceExistAccount [$key] ['balance'] = $balance;
  2830. }
  2831. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2832. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2833. $this->data ['halfList'] = $halfList;
  2834. $this->data ['halfCount'] = count ( $halfList );
  2835. // print_r($receivablesList);
  2836. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2837. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2838. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2839. $this->data ['receivablesInput'] = $receivablesInput;
  2840. $this->data ['year'] = date ( 'Y' );
  2841. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2842. $this->data ['receivablesList'] = $receivablesList;
  2843. $this->data ['staffList'] = $staffList;
  2844. $this->data ['category'] = $category;
  2845. $this->data ['memu'] = "invoice";
  2846. $this->data ['staff'] = $this->staff;
  2847. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2848. $this->render ( "/admin/invoiceReceivables", $this->data );
  2849. }
  2850. /**
  2851. * 设置收款认领地区
  2852. */
  2853. function setInvoiceReceivablesClaim() {
  2854. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2855. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2856. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2857. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2858. Doo::loadModel ( 'invoiceReceivables' );
  2859. $invoiceReceivables = new invoiceReceivables ();
  2860. Doo::loadClass ( 'XDeode' );
  2861. $XDeode = new XDeode ( 5 );
  2862. Doo::loadModel ( 'invoiceROLog' );
  2863. $invoiceROLog = new invoiceROLog ();
  2864. $irid = $XDeode->decode ( $iridKey );
  2865. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2866. if (empty ( $irDetail ))
  2867. die ( 'illegal request' );
  2868. $item = array (
  2869. 'irid' => $irid,
  2870. 'receivablesCategory' => $receivablesCategory
  2871. );
  2872. if ($receivablesCategory != 'PUBLIC') {
  2873. $item += array (
  2874. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2875. 'inputType' => 1
  2876. );
  2877. }
  2878. $invoiceReceivables = new invoiceReceivables ();
  2879. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2880. // 收款操作日志
  2881. $item = array (
  2882. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2883. 'date' => date ( "Y-m-d" ),
  2884. 'status' => 1,
  2885. 'img' => $this->staff [0] ['avatar'],
  2886. 'username' => $this->staff [0] ['username'],
  2887. 'uid' => $this->staff [0] ['sid'],
  2888. 'category' => $this->staff [0] ['category'],
  2889. 'irid' => $irid
  2890. );
  2891. $invoiceROLog->setInvoiceROLog ( $item );
  2892. if (empty ( $action ))
  2893. return '/invoiceReceivables';
  2894. else
  2895. return "/invoiceReceivablesAS";
  2896. }
  2897. die ( 'illegal request' );
  2898. }
  2899. /**
  2900. * 新添加收款直接入账发票
  2901. */
  2902. function invoiceCompareClaimPrice() {
  2903. // 收款录入
  2904. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2905. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2906. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2907. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2908. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2909. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2910. Doo::loadModel ( 'invoiceReceivables' );
  2911. $invoiceReceivables = new invoiceReceivables ();
  2912. Doo::loadModel ( 'invoiceROLog' );
  2913. $invoiceROLog = new invoiceROLog ();
  2914. Doo::loadModel ( 'invoiceStatistics' );
  2915. Doo::loadModel ( 'invoice' );
  2916. $invoice = new invoice ();
  2917. Doo::loadClass ( 'XDeode' );
  2918. $XDeode = new XDeode ( 5 );
  2919. Doo::loadModel ( 'invoiceOperationLog' );
  2920. $invoiceOperationLog = new invoiceOperationLog ();
  2921. $iidKey = $XDeode->decode ( $iidKey );
  2922. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2923. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2924. die ( 'illegal request' );
  2925. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2926. // 收款录入 并绑定发票
  2927. Doo::db ()->beginTransaction ();
  2928. $bindStatus = 0;
  2929. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2930. $bindStatus = 1;
  2931. $titleMark = $invoiceDetail ['invoiceTitle'];
  2932. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  2933. $titleMark = $invoiceDetail ['invoiceCompany'];
  2934. $item = array (
  2935. 'recepitTitleMark' => $titleMark,
  2936. 'bindStatus' => $bindStatus,
  2937. 'iid' => $invoiceDetail ['iid'],
  2938. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2939. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2940. 'receivablesPrice' => $receivablesPrice,
  2941. 'OriginalPrice' => $receivablesPrice,
  2942. 'receivablesMessage' => $receivablesMessage,
  2943. 'receivablesSerial' => $receivablesSerial,
  2944. 'receivablesBank' => $receivablesBank,
  2945. 'receivablesDate' => $receivablesDate,
  2946. 'inputStaff' => $this->staff [0] ['username'],
  2947. 'accountClerk' => $this->staff [0] ['username'],
  2948. 'date' => date ( "Y-m-d" ),
  2949. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2950. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2951. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2952. );
  2953. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2954. $item = array ();
  2955. // 收款操作日志
  2956. $item = array (
  2957. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2958. );
  2959. $item += array (
  2960. 'date' => date ( "Y-m-d" ),
  2961. 'status' => 1,
  2962. 'img' => $this->staff [0] ['avatar'],
  2963. 'username' => $this->staff [0] ['username'],
  2964. 'uid' => $this->staff [0] ['sid'],
  2965. 'category' => $this->staff [0] ['category'],
  2966. 'irid' => $irid
  2967. );
  2968. $invoiceROLog->setInvoiceROLog ( $item );
  2969. // 收款统计
  2970. $invoiceStatistics = new invoiceStatistics ();
  2971. $item = array (
  2972. 'date' => $receivablesDate,
  2973. 'priceClass' => 2,
  2974. 'irid' => $irid,
  2975. 'cid' => $invoiceDetail ['cid'],
  2976. 'staff' => $invoiceDetail ['sid'],
  2977. 'receivablesPrice' => $receivablesPrice
  2978. );
  2979. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2980. // 收款 入 发票
  2981. $detail = $invoiceDetail;
  2982. $iridString = "";
  2983. if (empty ( $detail ['irid'] ))
  2984. $iridString = $irid;
  2985. else
  2986. $iridString = $detail ['irid'] . ',' . $irid;
  2987. $item = array (
  2988. 'irid' => $iridString,
  2989. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2990. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2991. 'iid' => $detail ['iid']
  2992. );
  2993. $invoiceReceivables = new invoiceReceivables ();
  2994. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2995. if ($detail ['invoicePrice'] <= $sum)
  2996. $item += array (
  2997. 'untreadStatus' => 3
  2998. );
  2999. $invoice->setInvoiceByCondition ( $item );
  3000. // 操作日志
  3001. $item = array (
  3002. 'date' => date ( "Y-m-d H:i:s" ),
  3003. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3004. 'status' => 8,
  3005. 'img' => $this->staff [0] ['avatar'],
  3006. 'username' => $this->staff [0] ['username'],
  3007. 'uid' => $this->staff [0] ['sid'],
  3008. 'category' => $this->staff [0] ['category'],
  3009. 'iid' => $detail ['iid']
  3010. );
  3011. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3012. // 入账汇总
  3013. $invoiceStatistics = new invoiceStatistics ();
  3014. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3015. // $accountPrice = 0;
  3016. // foreach ( $list as $key => $value ) {
  3017. // $accountPrice += $value ['receivablesPrice'];
  3018. // }
  3019. $item = array (
  3020. 'date' => $receivablesDate,
  3021. 'priceClass' => 3,
  3022. 'cid' => $invoiceDetail ['cid'],
  3023. 'staff' => $invoiceDetail ['sid'],
  3024. 'accountPrice' => $receivablesPrice
  3025. );
  3026. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3027. // 公司流水记录
  3028. Doo::loadModel ( 'wasteBook' );
  3029. $wasteBook = new wasteBook ();
  3030. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3031. $accountBank = '';
  3032. if ($receivablesBank == '纵横广发') {
  3033. $accountBank = 'CGBDeposit';
  3034. } elseif ($receivablesBank == '纵横工行') {
  3035. $accountBank = 'ICBCDeposit';
  3036. } elseif ($receivablesBank == '华润银行') {
  3037. $accountBank = 'HUADeposit';
  3038. } elseif ($receivablesBank == '个人广发') {
  3039. $accountBank = 'PersonalDeposit';
  3040. }
  3041. if (empty ( $abDetail )) {
  3042. $item = array (
  3043. 'dataID' => $irid,
  3044. 'expensesType' => 1,
  3045. 'accountType' => 7,
  3046. 'accountPrice' => $receivablesPrice,
  3047. 'accountPriceShow' => $receivablesPrice,
  3048. 'accountBank' => $accountBank,
  3049. 'category' => $this->staff [0] ['category'],
  3050. 'cid' => $this->staff [0] ['cid'],
  3051. 'name' => $this->staff [0] ['username'],
  3052. 'sid' => $this->staff [0] ['sid'],
  3053. 'inputDate' => date ( "Y-m-d H:i:s" )
  3054. );
  3055. $wasteBook->setAccountBookStatistics ( $item );
  3056. }
  3057. Doo::db ()->commit ();
  3058. }
  3059. return '/invoiceReceivables';
  3060. }
  3061. /**
  3062. * 录入收款数据
  3063. * @return string
  3064. */
  3065. function invoiceReceivablesDo() {
  3066. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3067. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3068. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3069. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3070. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3071. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3072. Doo::loadModel ( 'invoiceReceivables' );
  3073. $invoiceReceivables = new invoiceReceivables ();
  3074. Doo::loadModel ( 'invoiceROLog' );
  3075. $invoiceROLog = new invoiceROLog ();
  3076. Doo::loadModel ( 'invoiceStatistics' );
  3077. $invoiceStatistics = new invoiceStatistics ();
  3078. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3079. $item = array (
  3080. 'receivablesPrice' => $receivablesPrice,
  3081. 'OriginalPrice' => $receivablesPrice,
  3082. 'receivablesMessage' => $receivablesMessage,
  3083. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3084. 'receivablesBank' => $receivablesBank,
  3085. 'receivablesDate' => $receivablesDate,
  3086. 'inputStaff' => $this->staff [0] ['username'],
  3087. 'date' => date ( "Y-m-d" ),
  3088. 'receivablesCategory' => $receivablesCategory,
  3089. 'receivablesStaff' => $receivablesStaff
  3090. );
  3091. if ($receivablesCategory != 'PUBLIC') {
  3092. $item += array (
  3093. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3094. 'inputType' => 1
  3095. );
  3096. }
  3097. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3098. $item = array ();
  3099. // 收款操作日志
  3100. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3101. $item = array (
  3102. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3103. );
  3104. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3105. $item = array (
  3106. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3107. );
  3108. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3109. $receivablesStaff = explode ( '-', $receivablesStaff );
  3110. $item = array (
  3111. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3112. );
  3113. }
  3114. $item += array (
  3115. 'date' => date ( "Y-m-d" ),
  3116. 'status' => 1,
  3117. 'img' => $this->staff [0] ['avatar'],
  3118. 'username' => $this->staff [0] ['username'],
  3119. 'uid' => $this->staff [0] ['sid'],
  3120. 'category' => $this->staff [0] ['category'],
  3121. 'irid' => $irid
  3122. );
  3123. $invoiceROLog->setInvoiceROLog ( $item );
  3124. $item = array (
  3125. 'date' => $receivablesDate,
  3126. 'priceClass' => 2,
  3127. 'irid' => $irid,
  3128. 'receivablesPrice' => $receivablesPrice
  3129. );
  3130. if ($receivablesCategory != 'PUBLIC') {
  3131. $receivablesCategory = explode ( ":", $receivablesCategory );
  3132. $item += array (
  3133. 'cid' => $receivablesCategory [0]
  3134. );
  3135. }
  3136. if ($receivablesStaff2 != 'PUBLIC') {
  3137. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3138. $item += array (
  3139. 'staff' => $receivablesStaff [0]
  3140. );
  3141. }
  3142. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3143. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3144. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3145. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3146. if ($toparty != 0)
  3147. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3148. // 公司流水记录
  3149. Doo::loadModel ( 'wasteBook' );
  3150. $wasteBook = new wasteBook ();
  3151. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3152. $accountBank = '';
  3153. if ($receivablesBank == '纵横广发') {
  3154. $accountBank = 'CGBDeposit';
  3155. } elseif ($receivablesBank == '纵横工行') {
  3156. $accountBank = 'ICBCDeposit';
  3157. } elseif ($receivablesBank == '华润银行') {
  3158. $accountBank = 'HUADeposit';
  3159. } elseif ($receivablesBank == '个人广发') {
  3160. $accountBank = 'PersonalDeposit';
  3161. }
  3162. $item = array (
  3163. 'dataID' => $irid,
  3164. 'expensesType' => 1,
  3165. 'accountType' => 7,
  3166. 'accountPriceShow' => $receivablesPrice,
  3167. 'accountPrice' => $receivablesPrice,
  3168. 'accountBank' => $accountBank,
  3169. 'category' => $this->staff [0] ['category'],
  3170. 'cid' => $this->staff [0] ['cid'],
  3171. 'name' => $this->staff [0] ['username'],
  3172. 'sid' => $this->staff [0] ['sid'],
  3173. 'inputDate' => date ( "Y-m-d H:i:s" )
  3174. );
  3175. $wasteBook->setAccountBookStatistics ( $item );
  3176. }
  3177. return "/invoiceReceivables";
  3178. }
  3179. /**
  3180. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3181. */
  3182. function invoiceReceivablesClaim() {
  3183. Doo::loadModel ( 'invoiceReceivables' );
  3184. $invoiceReceivables = new invoiceReceivables ();
  3185. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3186. $this->data ['receivablesList'] = $receivablesList;
  3187. $this->data ['memu'] = "invoice";
  3188. $this->data ['staff'] = $this->staff;
  3189. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3190. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3191. }
  3192. function invoiceReceivablesTitleMarkSet() {
  3193. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3194. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3195. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3196. die ( 'illegal request' );
  3197. Doo::loadModel ( 'invoiceReceivables' );
  3198. $invoiceReceivables = new invoiceReceivables ();
  3199. Doo::loadClass ( 'XDeode' );
  3200. $XDeode = new XDeode ( 5 );
  3201. $irid = $XDeode->decode ( $iridKey );
  3202. if (! is_numeric ( $irid ))
  3203. die ( 'illegal request' );
  3204. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3205. $invoiceReceivables->update ( array (
  3206. 'where' => 'irid = ' . $irid
  3207. ) );
  3208. return '/invoiceReceivablesClaim';
  3209. }
  3210. /**
  3211. * 更新收款相关数据
  3212. */
  3213. function invoiceReceivablesUpdateClaim() {
  3214. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3215. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3216. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3217. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3218. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3219. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3220. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3221. if (empty ( $claimKey ))
  3222. die ( 'illegal request' );
  3223. Doo::loadModel ( 'invoiceReceivables' );
  3224. $invoiceReceivables = new invoiceReceivables ();
  3225. Doo::loadModel ( 'invoiceROLog' );
  3226. $invoiceROLog = new invoiceROLog ();
  3227. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3228. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3229. if (empty ( $detail ))
  3230. die ( 'illegal request' );
  3231. $invoiceReceivables = new invoiceReceivables ();
  3232. $item = array (
  3233. 'irid' => $detail ['irid']
  3234. );
  3235. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3236. $item += array (
  3237. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3238. );
  3239. }
  3240. if (! empty ( $receivablesCategory ))
  3241. $item += array (
  3242. 'receivablesCategory' => $receivablesCategory
  3243. );
  3244. if (! empty ( $receivablesStaff ))
  3245. $item += array (
  3246. 'receivablesStaff' => $receivablesStaff
  3247. );
  3248. if (! empty ( $receivablesPrice ))
  3249. $item += array (
  3250. 'receivablesPrice' => $receivablesPrice
  3251. );
  3252. if (! empty ( $receivablesMessage ))
  3253. $item += array (
  3254. 'receivablesMessage' => $receivablesMessage
  3255. );
  3256. if (! empty ( $receivablesBank ))
  3257. $item += array (
  3258. 'receivablesBank' => $receivablesBank
  3259. );
  3260. if (! empty ( $receivablesDate ))
  3261. $item += array (
  3262. 'receivablesDate' => $receivablesDate
  3263. );
  3264. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3265. // 收款操作日志
  3266. $item = array ();
  3267. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3268. $item = array (
  3269. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3270. );
  3271. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3272. $item = array (
  3273. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3274. );
  3275. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3276. $receivablesStaff = explode ( '-', $receivablesStaff );
  3277. $item = array (
  3278. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3279. );
  3280. }
  3281. $item += array (
  3282. 'date' => date ( "Y-m-d" ),
  3283. 'status' => 1,
  3284. 'img' => $this->staff [0] ['avatar'],
  3285. 'username' => $this->staff [0] ['username'],
  3286. 'uid' => $this->staff [0] ['sid'],
  3287. 'category' => $this->staff [0] ['category'],
  3288. 'irid' => $detail ['irid']
  3289. );
  3290. $invoiceROLog->setInvoiceROLog ( $item );
  3291. return '/invoiceReceivablesAS';
  3292. }
  3293. function invoiceReceivablesDelete() {
  3294. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3295. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3296. if ($skll != '删除到款')
  3297. die ( 'illegal request' );
  3298. if (empty ( $claimKey ))
  3299. die ( 'illegal request' );
  3300. Doo::loadModel ( 'invoiceReceivables' );
  3301. $invoiceReceivables = new invoiceReceivables ();
  3302. $con = ' and bindStatus=0 ';
  3303. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3304. if (empty ( $detail ))
  3305. die ( 'illegal request' );
  3306. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3307. // 扣除收款汇总信息 汇总
  3308. Doo::loadModel ( 'invoiceStatistics' );
  3309. $invoiceStatistics = new invoiceStatistics ();
  3310. $item = array (
  3311. 'date' => $detail ['receivablesDate'],
  3312. 'priceClass' => 2,
  3313. 'irid' => $detail ['irid'],
  3314. 'receivablesPrice' => - $detail ['receivablesPrice']
  3315. );
  3316. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3317. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3318. $item += array (
  3319. 'cid' => $receivablesCategory [0]
  3320. );
  3321. }
  3322. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3323. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3324. $item += array (
  3325. 'staff' => $receivablesStaff [0]
  3326. );
  3327. }
  3328. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3329. // 公司流水-删除时删除流水
  3330. Doo::loadModel ( 'wasteBook' );
  3331. $wasteBook = new wasteBook ();
  3332. $wasteBook->delete ( array (
  3333. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3334. 'limit' => 1
  3335. ) );
  3336. return '/invoiceReceivablesAS';
  3337. }
  3338. /**
  3339. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3340. */
  3341. function invoiceReceivablesAscription() {
  3342. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3343. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3344. Doo::loadModel ( 'invoiceReceivables' );
  3345. $invoiceReceivables = new invoiceReceivables ();
  3346. Doo::loadModel ( 'invoiceROLog' );
  3347. $invoiceROLog = new invoiceROLog ();
  3348. Doo::loadModel ( 'invoiceStatistics' );
  3349. $invoiceStatistics = new invoiceStatistics ();
  3350. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3351. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3352. $item = array (
  3353. 'irid' => $detail ['irid'],
  3354. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3355. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3356. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3357. 'recepitTitleMark' => $recepitTitleMark,
  3358. 'source' => 1
  3359. );
  3360. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3361. $item = array (
  3362. 'date' => date ( "Y-m-d" ),
  3363. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3364. 'status' => 2,
  3365. 'img' => $this->staff [0] ['avatar'],
  3366. 'username' => $this->staff [0] ['username'],
  3367. 'uid' => $this->staff [0] ['sid'],
  3368. 'category' => $this->staff [0] ['category'],
  3369. 'irid' => $irid
  3370. );
  3371. $invoiceROLog->setInvoiceROLog ( $item );
  3372. $item = array (
  3373. 'cid' => $this->staff [0] ['cid'],
  3374. 'staff' => $this->staff [0] ['sid']
  3375. );
  3376. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3377. }
  3378. return "/invoiceReceivablesClaim";
  3379. }
  3380. /**
  3381. */
  3382. function invoiceMyReceivables() {
  3383. Doo::loadModel ( 'invoiceReceivables' );
  3384. $invoiceReceivables = new invoiceReceivables ();
  3385. Doo::loadModel ( 'invoiceStatistics' );
  3386. $invoiceStatistics = new invoiceStatistics ();
  3387. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3388. $year = date ( "Y" );
  3389. $tmp_date = date ( "Ym" );
  3390. $tmp_year = substr ( $tmp_date, 0, 4 );
  3391. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3392. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3393. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3394. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3395. $htm = $this->showCache ( $path );
  3396. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3397. $this->data ['isMonth'] = $isMonth;
  3398. $this->data ['htm'] = $htm;
  3399. $this->data ['list'] = $list;
  3400. $this->data ['memu'] = "invoice";
  3401. $this->data ['staff'] = $this->staff;
  3402. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3403. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3404. }
  3405. /**
  3406. * 纸票管理
  3407. */
  3408. function invoicePaper() {
  3409. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3410. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3411. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3412. $this->data ['dateString'] = $date;
  3413. $this->data ['status'] = $status;
  3414. $this->data ['invoiceType'] = $invoiceType;
  3415. $this->data ['memu'] = "invoice";
  3416. $this->data ['staff'] = $this->staff;
  3417. $this->data ['receiptMemu'] = 'invoicePaper';
  3418. $this->render ( "/admin/invoicePaper", $this->data );
  3419. }
  3420. /**
  3421. * 获得纸票分页数据
  3422. */
  3423. function ajaxGetinvoicePaperAchieve() {
  3424. Doo::loadModel ( 'invoicePaper' );
  3425. $invoicePaper = new invoicePaper ();
  3426. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3427. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3428. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3429. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3430. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3431. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3432. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3433. $MebSea = $this->get_args ( 'search' );
  3434. $MebSea = $MebSea ['value'];
  3435. $page_size = $length;
  3436. $con = '';
  3437. if ($status == 'ALL')
  3438. $con = ' where 1 ';
  3439. elseif ($status == 'PRINTED')
  3440. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3441. elseif ($status == 'UNPRINT')
  3442. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3443. elseif ($status == 'TICKET')
  3444. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3445. if ($invoiceType == 'ORDINARY')
  3446. $con .= ' and a.invoiceType=0 ';
  3447. elseif ($invoiceType == 'SPECIAL')
  3448. $con .= ' and a.invoiceType=1 ';
  3449. $dateArr = explode ( ':', $date );
  3450. $D1 = $dateString = '';
  3451. $D2 = '';
  3452. if (! empty ( $date )) {
  3453. $D1 = $dateArr [0];
  3454. if (isset ( $dateArr [1] ))
  3455. $D2 = $dateArr [1];
  3456. else
  3457. $D2 = '';
  3458. $dateString = $D1 . " : " . $D2;
  3459. }
  3460. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3461. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3462. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3463. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3464. if (! empty ( $MebSea ))
  3465. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3466. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3467. $sql = ' ' . $con;
  3468. $limit = $page . ',' . $page_size;
  3469. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3470. $paperList = array ();
  3471. foreach ( $list as $key => $value ) {
  3472. $irDetail = array ();
  3473. if ($value ['iid'] == 0)
  3474. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3475. else
  3476. array_push ( $irDetail, '' );
  3477. array_push ( $irDetail, $value ['invoiceCode'] );
  3478. array_push ( $irDetail, $value ['invoiceNo'] );
  3479. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3480. if ($value ['invoiceType'] == 1)
  3481. array_push ( $irDetail, $value ['invoiceCompany'] );
  3482. else
  3483. array_push ( $irDetail, $value ['invoiceTitle'] );
  3484. if ($value ['invoiceType'] == 1)
  3485. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3486. else
  3487. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3488. array_push ( $irDetail, $value ['invoiceElement'] );
  3489. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3490. array_push ( $irDetail, $value ['printTime'] );
  3491. array_push ( $paperList, $irDetail );
  3492. }
  3493. // $approvalListJson = json_encode ( $approvalList );
  3494. $recordsFiltered = $invoiceTotal;
  3495. echo json_encode ( array (
  3496. "draw" => intval ( $draw ),
  3497. "recordsTotal" => intval ( $invoiceTotal ),
  3498. "recordsFiltered" => intval ( $recordsFiltered ),
  3499. "data" => $paperList
  3500. ), JSON_UNESCAPED_UNICODE );
  3501. }
  3502. function invoicePaperDel() {
  3503. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3504. $XDeode = new XDeode ( 5 );
  3505. $ipid = $XDeode->decode ( $ipidKey );
  3506. if (empty ( $ipid ))
  3507. die ( 'illegal request' );
  3508. Doo::loadModel ( 'invoicePaper' );
  3509. $invoicePaper = new invoicePaper ();
  3510. $invoicePaper->delete ( array (
  3511. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3512. 'limit' => 1
  3513. ) );
  3514. return '/invoicePaper';
  3515. }
  3516. /**
  3517. * 添加纸质发票号
  3518. */
  3519. function invoicePaperAdd() {
  3520. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3521. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3522. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3523. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3524. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3525. $sum = $invoiceNoStart + $invoiceNoTotal;
  3526. if (empty ( $sum ))
  3527. die ( 'illegal request' );
  3528. // echo $invoiceNoStart;
  3529. // echo $sum;
  3530. // echo strlen((int)$invoiceNoStart);
  3531. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  3532. Doo::db ()->beginTransaction ();
  3533. // 批量存储纸质发票
  3534. $date = date ( "Y-m-d H:i:s" );
  3535. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3536. VALUES ';
  3537. $paperList = array ();
  3538. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3539. // 数字前面自加0
  3540. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  3541. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  3542. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '")';
  3543. array_push ( $paperList, $paperSql );
  3544. }
  3545. if (empty ( $paperList ))
  3546. die ( 'illegal request' );
  3547. $sql = $sql . implode ( ',', $paperList );
  3548. Doo::db ()->query ( $sql );
  3549. Doo::db ()->commit ();
  3550. return 'invoicePaper';
  3551. }
  3552. die ( 'illegal request' );
  3553. }
  3554. /**
  3555. * 收款绑定发票 ,//一个收款只能绑定一个发票
  3556. */
  3557. function invoiceBindReceivables() {
  3558. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3559. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3560. Doo::loadModel ( 'invoice' );
  3561. $invoice = new invoice ();
  3562. Doo::loadModel ( 'invoiceReceivables' );
  3563. $invoiceReceivables = new invoiceReceivables ();
  3564. Doo::loadModel ( 'invoiceOperationLog' );
  3565. $invoiceOperationLog = new invoiceOperationLog ();
  3566. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3567. die ( 'illegal request' );
  3568. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3569. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3570. if (empty ( $detail ) && empty ( $detailM ))
  3571. die ( 'illegal request' );
  3572. if ($detail ['untreadStatus'] == 3)
  3573. die ( 'illegal request' );
  3574. // 修改 绑定状态改为 金额
  3575. $invoiceReceivables = new invoiceReceivables ();
  3576. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3577. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3578. $item = array (
  3579. 'bindPrice' => $invoicePrice
  3580. );
  3581. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3582. $item = array (
  3583. 'bindPrice' => $invoicePrice,
  3584. 'bindStatus' => 1,
  3585. 'bindDate' => date ( "Y-m-d H:i:s" )
  3586. );
  3587. } else {
  3588. die ( 'illegal request' );
  3589. }
  3590. if ($detailM ['iid'] == 0) {
  3591. $item += array (
  3592. 'iid' => $detail ['iid']
  3593. );
  3594. } else {
  3595. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3596. array_push ( $iidExtend, $detail ['iid'] );
  3597. $item += array (
  3598. 'iidExtend' => implode ( ',', $iidExtend )
  3599. );
  3600. }
  3601. $titleMark = $detail ['invoiceTitle'];
  3602. if (! empty ( $detail ['invoiceCompany'] ))
  3603. $titleMark = $detail ['invoiceCompany'];
  3604. $item += array (
  3605. 'irid' => $detailM ['irid'],
  3606. 'recepitTitleMark' => $titleMark,
  3607. 'accountClerk' => $this->staff [0] ['username']
  3608. );
  3609. // 如何没有人收款 则自动绑定收款
  3610. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3611. $item += array (
  3612. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3613. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3614. );
  3615. }
  3616. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3617. $iridString = "";
  3618. if (empty ( $detail ['irid'] ))
  3619. $iridString = $detailM ['irid'];
  3620. else
  3621. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3622. $item = array (
  3623. 'iid' => $detail ['iid'],
  3624. 'irid' => $iridString
  3625. );
  3626. $invoiceReceivables = new invoiceReceivables ();
  3627. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3628. if ($detail ['invoicePrice'] <= $sum)
  3629. $item += array (
  3630. 'untreadStatus' => 3,
  3631. 'bindTime' => date ( "Y-m-d H:i:s" )
  3632. );
  3633. // print_r($item);
  3634. // echo $sum;die;
  3635. $invoice->setInvoiceByCondition ( $item );
  3636. // 操作日志
  3637. $item = array (
  3638. 'date' => date ( "Y-m-d H:i:s" ),
  3639. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3640. 'status' => 8,
  3641. 'img' => $this->staff [0] ['avatar'],
  3642. 'username' => $this->staff [0] ['username'],
  3643. 'uid' => $this->staff [0] ['sid'],
  3644. 'category' => $this->staff [0] ['category'],
  3645. 'iid' => $detail ['iid']
  3646. );
  3647. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3648. Doo::loadModel ( 'invoiceStatistics' );
  3649. $invoiceStatistics = new invoiceStatistics ();
  3650. $item = array (
  3651. 'date' => $detailM ['receivablesDate'],
  3652. 'priceClass' => 3,
  3653. 'cid' => $detail ['cid'],
  3654. 'staff' => $detail ['sid'],
  3655. 'accountPrice' => $detailM ['receivablesPrice']
  3656. );
  3657. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3658. // 公司流水记录
  3659. // Doo::loadModel ( 'wasteBook' );
  3660. // $wasteBook = new wasteBook ();
  3661. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  3662. // $accountBank='';
  3663. // if ($detailM ['receivablesBank']=='纵横广发'){
  3664. // $accountBank='CGBDeposit';
  3665. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  3666. // $accountBank='ICBCDeposit';
  3667. // }elseif($detailM ['receivablesBank']=='华润银行'){
  3668. // $accountBank='HUADeposit';
  3669. // }elseif($detailM ['receivablesBank']=='个人广发'){
  3670. // $accountBank='PersonalDeposit';
  3671. // }
  3672. // if (empty($abDetail)){
  3673. // $item = array (
  3674. // 'dataID' => $detail ['iid'],
  3675. // 'expensesType' => 1,
  3676. // 'accountType' => 8,
  3677. // 'accountPriceShow'=>$detail ['invoicePrice'],
  3678. // 'accountPrice'=>$detail ['invoicePrice'],
  3679. // 'accountBank'=>$accountBank,
  3680. // 'category'=>$this->staff[0]['category'],
  3681. // 'cid'=>$this->staff[0]['cid'],
  3682. // 'name'=>$this->staff[0]['username'],
  3683. // 'sid'=>$this->staff[0]['sid'],
  3684. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  3685. // );
  3686. // $wasteBook->setAccountBookStatistics($item);
  3687. // }
  3688. return "/invoiceReceivables";
  3689. }
  3690. /**
  3691. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3692. */
  3693. function invoiceAggregate() {
  3694. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3695. Doo::loadModel ( 'invoiceStatistics' );
  3696. $invoiceStatistics = new invoiceStatistics ();
  3697. Doo::loadModel ( 'L_category' );
  3698. $Lcategory = new L_category ();
  3699. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3700. $LcategoryList = $Lcategory->getCategory ();
  3701. // print_r($isList);
  3702. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3703. foreach ( $LcategoryList as $key => $value ) {
  3704. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3705. $month = 1;
  3706. $invoicePriceYear = 0;
  3707. $receivablesPriceYear = 0;
  3708. $accountPriceYear = 0;
  3709. for(; $month <= 12; $month ++) {
  3710. $flag = true;
  3711. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3712. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3713. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3714. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3715. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3716. ';
  3717. $invoicePriceYear += $v ['invoicePrice'];
  3718. $receivablesPriceYear += $v ['receivablesPrice'];
  3719. $accountPriceYear += $v ['accountPrice'];
  3720. $flag = false;
  3721. break;
  3722. }
  3723. }
  3724. if ($flag)
  3725. $html .= '<td class="taR"></td>
  3726. <td class="taR"></td>
  3727. <td class="taR"><b></b></td>
  3728. ';
  3729. }
  3730. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3731. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3732. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3733. ';
  3734. $html .= '</tr>';
  3735. }
  3736. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3737. $invoicePriceYear = 0;
  3738. $receivablesPriceYear = 0;
  3739. $accountPriceYear = 0;
  3740. for($month = 1; $month <= 12; $month ++) {
  3741. $flag = true;
  3742. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3743. if ($month == $v ['month']) {
  3744. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3745. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3746. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3747. ';
  3748. $invoicePriceYear += $v ['invoicePrice'];
  3749. $receivablesPriceYear += $v ['receivablesPrice'];
  3750. $accountPriceYear += $v ['accountPrice'];
  3751. $flag = false;
  3752. break;
  3753. }
  3754. }
  3755. if ($flag) {
  3756. $html .= '<td class="taR"></td>
  3757. <td class="taR"></td>
  3758. <td class="taR"><b></b></td>
  3759. ';
  3760. }
  3761. }
  3762. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3763. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3764. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3765. ';
  3766. $html .= '</tr>';
  3767. // print_r($isList);
  3768. $this->data ['html'] = $html;
  3769. $this->data ['LcategoryList'] = $LcategoryList;
  3770. $this->data ['isList'] = $isList;
  3771. $this->data ['year'] = $year;
  3772. $this->data ['memu'] = "invoice";
  3773. $this->data ['staff'] = $this->staff;
  3774. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3775. $this->render ( "/admin/invoiceAggregate", $this->data );
  3776. }
  3777. function invoiceAggregateStaff() {
  3778. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3779. Doo::loadModel ( 'invoiceStatistics' );
  3780. $invoiceStatistics = new invoiceStatistics ();
  3781. Doo::loadModel ( 'L_category' );
  3782. $Lcategory = new L_category ();
  3783. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3784. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3785. $cStaff = $Lcategory->getCategoryStaff ();
  3786. $html = '';
  3787. foreach ( $cStaff as $key => $value ) {
  3788. $categoryFir = true;
  3789. foreach ( $value ['staff'] as $k => $v ) {
  3790. if ($categoryFir) {
  3791. $width = count ( $value ['staff'] ) + 1;
  3792. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3793. $categoryFir = false;
  3794. } else
  3795. $html .= '<tr>';
  3796. $html .= '<th>' . $v ['username'] . '</th>';
  3797. $invoicePriceStaffYear = 0;
  3798. $receivablesPriceStaffYear = 0;
  3799. $accountPriceStaffYear = 0;
  3800. for($month = 1; $month <= 12; $month ++) {
  3801. $flag = true;
  3802. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3803. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3804. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3805. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3806. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3807. ';
  3808. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3809. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3810. $accountPriceStaffYear += $slv ['accountPrice'];
  3811. $flag = false;
  3812. break;
  3813. }
  3814. }
  3815. if ($flag)
  3816. $html .= '<td class="taR"></td>
  3817. <td class="taR"></td>
  3818. <td class="taR"><b></b></td>
  3819. ';
  3820. }
  3821. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3822. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3823. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3824. ';
  3825. }
  3826. $html .= '</tr>';
  3827. // 小计
  3828. if (! empty ( $value ['staff'] )) {
  3829. $html .= '<tr><th class="taR">小计</th>';
  3830. $invoicePriceStaffYear = 0;
  3831. $receivablesPriceStaffYear = 0;
  3832. $accountPriceStaffYear = 0;
  3833. for($month = 1; $month <= 12; $month ++) {
  3834. $flag = true;
  3835. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3836. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3837. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3838. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3839. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3840. ';
  3841. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3842. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3843. $accountPriceStaffYear += $slv ['accountPrice'];
  3844. $flag = false;
  3845. break;
  3846. }
  3847. }
  3848. if ($flag)
  3849. $html .= '<td class="taR"></td>
  3850. <td class="taR"></td>
  3851. <td class="taR"><b></b></td>
  3852. ';
  3853. }
  3854. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3855. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3856. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3857. ';
  3858. $html .= '</tr>';
  3859. }
  3860. }
  3861. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3862. $invoicePriceYear = 0;
  3863. $receivablesPriceYear = 0;
  3864. $accountPriceYear = 0;
  3865. for($month = 1; $month <= 12; $month ++) {
  3866. $flag = true;
  3867. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3868. if ($month == $v ['month']) {
  3869. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3870. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3871. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3872. ';
  3873. $invoicePriceYear += $v ['invoicePrice'];
  3874. $receivablesPriceYear += $v ['receivablesPrice'];
  3875. $accountPriceYear += $v ['accountPrice'];
  3876. $flag = false;
  3877. break;
  3878. }
  3879. }
  3880. if ($flag)
  3881. $html .= '<td class="taR"></td>
  3882. <td class="taR"></td>
  3883. <td class="taR"><b></b></td>
  3884. ';
  3885. }
  3886. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3887. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3888. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3889. ';
  3890. $html .= '</tr>';
  3891. $this->data ['html'] = $html;
  3892. $this->data ['isList'] = $toteList;
  3893. $this->data ['year'] = $year;
  3894. $this->data ['memu'] = "invoice";
  3895. $this->data ['staff'] = $this->staff;
  3896. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3897. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3898. }
  3899. function invoiceAggregateCategory() {
  3900. Doo::loadClass ( 'XDeode' );
  3901. $XDeode = new XDeode ( 5 );
  3902. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3903. $cid = $XDeode->decode ( $cid );
  3904. if (! is_numeric ( $cid ))
  3905. die ( 'illegal request' );
  3906. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3907. Doo::loadModel ( 'invoiceStatistics' );
  3908. $invoiceStatistics = new invoiceStatistics ();
  3909. Doo::loadModel ( 'staff' );
  3910. $staff = new staff ();
  3911. $list = $staff->getStaffByCid ( $cid );
  3912. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3913. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3914. if (empty ( $list ))
  3915. die ( '该办事处没有成员' );
  3916. $htmlA = $htmlB = $htmlC = $html = '';
  3917. foreach ( $list as $key => $value ) {
  3918. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3919. $htmlB = '<tr><th class="taC">收款</th>';
  3920. $htmlC = '<tr><th class="taC">入账</th>';
  3921. $invoicePriceStaffYear = 0;
  3922. $receivablesPriceStaffYear = 0;
  3923. $accountPriceStaffYear = 0;
  3924. for($month = 1; $month <= 12; $month ++) {
  3925. $flag = true;
  3926. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3927. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3928. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3929. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3930. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3931. $invoicePriceStaffYear += $v ['invoicePrice'];
  3932. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3933. $accountPriceStaffYear += $v ['accountPrice'];
  3934. $flag = false;
  3935. break;
  3936. }
  3937. }
  3938. if ($flag) {
  3939. $htmlA .= '<td class="taR">-</td>';
  3940. $htmlB .= '<td class="taR">-</td>';
  3941. $htmlC .= '<td class="taR"><b>-</b></td>';
  3942. }
  3943. }
  3944. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3945. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3946. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3947. $htmlA .= '</tr>';
  3948. $htmlB .= '</tr>';
  3949. $htmlC .= '</tr>';
  3950. $html .= $htmlA . $htmlB . $htmlC;
  3951. }
  3952. $htmlA = $htmlB = $htmlC = "";
  3953. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3954. $htmlB = '<tr><th class="taC">收款</th>';
  3955. $htmlC = '<tr><th class="taC">入账</th>';
  3956. $invoicePriceStaffYear = 0;
  3957. $receivablesPriceStaffYear = 0;
  3958. $accountPriceStaffYear = 0;
  3959. for($month = 1; $month <= 12; $month ++) {
  3960. $flag = true;
  3961. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3962. if ($month == $v ['month']) {
  3963. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3964. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3965. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3966. $invoicePriceStaffYear += $v ['invoicePrice'];
  3967. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3968. $accountPriceStaffYear += $v ['accountPrice'];
  3969. $flag = false;
  3970. break;
  3971. }
  3972. }
  3973. if ($flag) {
  3974. $htmlA .= '<td class="taR">-</td>';
  3975. $htmlB .= '<td class="taR">-</td>';
  3976. $htmlC .= '<td class="taR"><b>-</b></td>';
  3977. }
  3978. }
  3979. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3980. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3981. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3982. $htmlA .= '</tr>';
  3983. $htmlB .= '</tr>';
  3984. $htmlC .= '</tr>';
  3985. $html .= $htmlA . $htmlB . $htmlC;
  3986. $this->data ['html'] = $html;
  3987. $this->data ['cidKey'] = $cidKey;
  3988. $this->data ['slist'] = $list;
  3989. $this->data ['isList'] = $toteList;
  3990. $this->data ['year'] = $year;
  3991. $this->data ['memu'] = "invoice";
  3992. $this->data ['staff'] = $this->staff;
  3993. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3994. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3995. }
  3996. /**
  3997. * 办事处汇总信息
  3998. */
  3999. function invoiceAggregateCategoryDetail() {
  4000. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4001. Doo::loadClass ( 'XDeode' );
  4002. $XDeode = new XDeode ( 5 );
  4003. Doo::loadModel ( 'invoiceStatistics' );
  4004. $invoiceStatistics = new invoiceStatistics ();
  4005. Doo::loadModel ( 'L_category' );
  4006. $category = new L_category ();
  4007. Doo::loadModel ( 'invoice' );
  4008. $invoice = new invoice ();
  4009. Doo::loadModel ( 'staff' );
  4010. $staff = new staff ();
  4011. Doo::loadModel ( "invoiceCategoryManage" );
  4012. $invoiceCategoryManage = new invoiceCategoryManage ();
  4013. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4014. $cidList = array ();
  4015. foreach ( $imcStaff as $key => $value ) {
  4016. array_push ( $cidList, $value ['cid'] );
  4017. if (empty ( $cidKey ))
  4018. $cidKey = $XDeode->encode ( $value ['cid'] );
  4019. }
  4020. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4021. $cid = $XDeode->decode ( $cidKey );
  4022. $month = date ( "m", strtotime ( "-1 month" ) );
  4023. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4024. $redis = new Redis ();
  4025. $redis->connect ( '127.0.0.1', '6379' );
  4026. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4027. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4028. if (empty ( $redisValue )) {
  4029. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4030. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4031. // 获得办事处人员下的汇总
  4032. $slist = $staff->getStaffByCid ( $cid );
  4033. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4034. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4035. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4036. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4037. foreach ( $slist as $key => $value ) {
  4038. $slist [$key] ['invoicePrice'] = 0;
  4039. $slist [$key] ['receivablesPrice'] = 0;
  4040. $slist [$key] ['accountPrice'] = 0;
  4041. $slist [$key] ['invoiceAllPrice'] = 0;
  4042. $slist [$key] ['receivablesAllPrice'] = 0;
  4043. $slist [$key] ['accountAllPrice'] = 0;
  4044. $slist [$key] ['schedule'] = 0;
  4045. $slist [$key] ['invoiceMonthPrice'] = 0;
  4046. $slist [$key] ['receivablesMonthPrice'] = 0;
  4047. $slist [$key] ['accountMonthPrice'] = 0;
  4048. foreach ( $ismsbMonth as $y => $l ) {
  4049. if ($value ['sid'] == $l ['staff']) {
  4050. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4051. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4052. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4053. }
  4054. }
  4055. foreach ( $ismsb as $k => $v ) {
  4056. if ($value ['sid'] == $v ['staff']) {
  4057. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4058. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4059. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4060. }
  4061. }
  4062. foreach ( $ISAS as $e => $a ) {
  4063. if ($value ['sid'] == $a ['staff']) {
  4064. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4065. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4066. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4067. }
  4068. }
  4069. if (isset ( $scheduleStaff [$value ['sid']] ))
  4070. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4071. }
  4072. $this->data ['cidKey'] = $cidKey;
  4073. $schedule = ( int ) ($schedule * 100);
  4074. $this->data ['slist'] = $slist;
  4075. $this->data ['isMC'] = $isMC;
  4076. $this->data ['schedule'] = $schedule;
  4077. $slist = json_encode ( $slist );
  4078. $isMC = json_encode ( $isMC );
  4079. $schedule = json_encode ( $schedule );
  4080. $redis->lpush ( $redisKey, $slist );
  4081. $redis->lpush ( $redisKey, $isMC );
  4082. $redis->lpush ( $redisKey, $schedule );
  4083. } else {
  4084. $this->data ['cidKey'] = $cidKey;
  4085. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4086. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4087. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4088. }
  4089. $this->data ['month'] = $month;
  4090. $this->data ['categoryList'] = $categoryList;
  4091. $this->data ['memu'] = "invoice";
  4092. $this->data ['staff'] = $this->staff;
  4093. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4094. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4095. }
  4096. /**
  4097. * 办事处人员汇总详情
  4098. */
  4099. function invoiceAggregateStaffDetail() {
  4100. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4101. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4102. Doo::loadClass ( 'XDeode' );
  4103. $XDeode = new XDeode ( 5 );
  4104. Doo::loadModel ( 'invoice' );
  4105. $invoice = new invoice ();
  4106. Doo::loadModel ( 'staff' );
  4107. $staff = new staff ();
  4108. Doo::loadModel ( "invoiceCategoryManage" );
  4109. $invoiceCategoryManage = new invoiceCategoryManage ();
  4110. $sid = $XDeode->decode ( $sidKey );
  4111. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4112. $cidList = array ();
  4113. foreach ( $imcStaff as $key => $value ) {
  4114. array_push ( $cidList, $value ['cid'] );
  4115. if (empty ( $cidKey ))
  4116. $cidKey = $XDeode->encode ( $value ['cid'] );
  4117. }
  4118. $cidString = implode ( ',', $cidList );
  4119. $staffList = $staff->getStaffInCid ( $cidString );
  4120. $staffDetail = $staff->getStaffBySid ( $sid );
  4121. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4122. $page_size = 18;
  4123. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4124. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4125. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4126. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4127. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4128. $dateArr = explode ( ':', $date );
  4129. $D1 = '';
  4130. $D2 = '';
  4131. if (! empty ( $date )) {
  4132. $D1 = $dateArr [0] . " 00:00:00 ";
  4133. if (isset ( $dateArr [1] ))
  4134. $D2 = $dateArr [1] . " 23:59:59 ";
  4135. else
  4136. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4137. // $D2 = $dateArr [1];
  4138. }
  4139. $con = ' status=2 ';
  4140. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4141. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4142. if ($status == 'UNRECORD')
  4143. $con .= ' and printStatus=1 and untreadStatus=0';
  4144. elseif ($status == 'RECORD')
  4145. $con .= ' and printStatus=1 and untreadStatus=3';
  4146. elseif ($status == 'BOUNCED')
  4147. $con .= ' and untreadStatus=2';
  4148. elseif ($status == 'PARTRECORD')
  4149. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4150. elseif ($status == 'All') {
  4151. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4152. }
  4153. $con .= ' and sid=' . $sid;
  4154. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4155. if (! empty ( $MebSea )) {
  4156. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4157. }
  4158. $pageinfo ['page'] = array (
  4159. 'previous' => ''
  4160. );
  4161. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4162. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4163. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4164. $this->data ['staffDetail'] = $staffDetail;
  4165. $this->data ['staffList'] = $staffList;
  4166. $this->data ['MebSeaEn'] = $MebSea;
  4167. $this->data ['MebSea'] = urlencode ( $MebSea );
  4168. $this->data ['date'] = $date;
  4169. $this->data ['page'] = $pageinfo;
  4170. $this->data ['get'] = $get;
  4171. $this->data ['list'] = $list;
  4172. $this->data ['status'] = $status;
  4173. $this->data ['sidKey'] = $sidKey;
  4174. $this->data ['memu'] = "invoice";
  4175. $this->data ['staff'] = $this->staff;
  4176. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4177. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4178. }
  4179. /**
  4180. * 办事处人员汇总收款情
  4181. */
  4182. function invoiceAggregateStaffReceivablesDetail() {
  4183. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4184. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4185. Doo::loadModel ( 'invoiceReceivables' );
  4186. $invoiceReceivables = new invoiceReceivables ();
  4187. Doo::loadModel ( 'staff' );
  4188. $staff = new staff ();
  4189. Doo::loadModel ( "invoiceCategoryManage" );
  4190. $invoiceCategoryManage = new invoiceCategoryManage ();
  4191. Doo::loadClass ( 'XDeode' );
  4192. $XDeode = new XDeode ( 5 );
  4193. $sid = $XDeode->decode ( $sidKey );
  4194. $staffDetail = $staff->getStaffBySid ( $sid );
  4195. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4196. $cidList = array ();
  4197. foreach ( $imcStaff as $key => $value ) {
  4198. array_push ( $cidList, $value ['cid'] );
  4199. if (empty ( $cidKey ))
  4200. $cidKey = $XDeode->encode ( $value ['cid'] );
  4201. }
  4202. $cidString = implode ( ',', $cidList );
  4203. $staffList = $staff->getStaffInCid ( $cidString );
  4204. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4205. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4206. $page_size = 10;
  4207. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4208. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4209. if ($timeType == "BINDOTP") {
  4210. $status = 'Credited';
  4211. }
  4212. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4213. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4214. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4215. $dateArr = explode ( ':', $date );
  4216. $D1 = '';
  4217. $D2 = '';
  4218. if (! empty ( $date )) {
  4219. $D1 = $dateArr [0] . " 00:00:00 ";
  4220. if (isset ( $dateArr [1] ))
  4221. $D2 = $dateArr [1] . " 23:59:59 ";
  4222. else
  4223. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4224. }
  4225. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4226. $descField = 'a.bindDate';
  4227. if ($timeType == 'CREATE')
  4228. $descField = 'a.date';
  4229. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4230. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4231. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4232. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4233. if ($status == 'Unclaimed')
  4234. $con .= ' and a.bindStatus=0';
  4235. elseif ($status == 'Credited')
  4236. $con .= ' and a.bindStatus=1';
  4237. elseif ($status == 'Claim')
  4238. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4239. elseif ($status == 'BBN')
  4240. $con .= ' and a.bindPrice>a.receivablesPrice';
  4241. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4242. if (! empty ( $MebSea )) {
  4243. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4244. }
  4245. $pageinfo ['page'] = array (
  4246. 'previous' => ''
  4247. );
  4248. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4249. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4250. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4251. where ' . $con . ' group by a.irid ';
  4252. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4253. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4254. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  4255. foreach ( $list as $key => $value ) {
  4256. $list [$key] ['category'] = '';
  4257. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4258. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4259. $list [$key] ['category'] = $receivablesCategory [1];
  4260. }
  4261. }
  4262. // print_r($list);
  4263. $this->data ['staffDetail'] = $staffDetail;
  4264. $this->data ['sidKey'] = $sidKey;
  4265. $this->data ['staffList'] = $staffList;
  4266. $this->data ['timeType'] = $timeType;
  4267. $this->data ['MebSeaEn'] = $MebSea;
  4268. $this->data ['MebSea'] = urlencode ( $MebSea );
  4269. $this->data ['date'] = $date;
  4270. $this->data ['page'] = $pageinfo;
  4271. $this->data ['get'] = $get;
  4272. $this->data ['list'] = $list;
  4273. $this->data ['status'] = $status;
  4274. $this->data ['memu'] = "invoice";
  4275. $this->data ['staff'] = $this->staff;
  4276. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4277. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4278. }
  4279. function invoiceAchieve() {
  4280. Doo::loadModel ( 'invoice' );
  4281. $invoice = new invoice ();
  4282. Doo::loadClass ( 'XDeode' );
  4283. $XDeode = new XDeode ( 5 );
  4284. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4285. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4286. $page_size = 18;
  4287. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4288. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4289. $get = "/" . $date;
  4290. $con = '';
  4291. if ($date == 'MONTHO')
  4292. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4293. elseif ($date == 'MONTHT')
  4294. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4295. elseif ($date == 'MONTHY')
  4296. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4297. if (! empty ( $MebSea )) {
  4298. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4299. $get .= "/" . $MebSea;
  4300. }
  4301. $pageinfo ['page'] = array (
  4302. 'previous' => ''
  4303. );
  4304. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4305. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4306. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4307. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4308. // print_r($pageinfo);
  4309. $this->data ['MebSeaEn'] = $MebSea;
  4310. $this->data ['MebSea'] = urlencode ( $MebSea );
  4311. $this->data ['get'] = $get;
  4312. $this->data ['page'] = $pageinfo;
  4313. $this->data ['list'] = $list;
  4314. $this->data ['date'] = $date;
  4315. $this->data ['memu'] = "invoice";
  4316. $this->data ['staff'] = $this->staff;
  4317. $this->data ['receiptMemu'] = 'invoice';
  4318. $this->render ( "/admin/invoiceAchieve", $this->data );
  4319. }
  4320. /**
  4321. */
  4322. function invoiceMyUnAccountAchieve() {
  4323. Doo::loadModel ( 'invoice' );
  4324. $invoice = new invoice ();
  4325. Doo::loadClass ( 'XDeode' );
  4326. $XDeode = new XDeode ( 5 );
  4327. Doo::loadModel ( 'staff' );
  4328. $staff = new staff ();
  4329. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4330. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4331. $page_size = 18;
  4332. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4333. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4334. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4335. $dateArr = explode ( ':', $date );
  4336. $D1 = '';
  4337. $D2 = '';
  4338. if (! empty ( $date )) {
  4339. $D1 = $dateArr [0];
  4340. $D2 = $dateArr [1];
  4341. }
  4342. $con = '';
  4343. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4344. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4345. if (! empty ( $MebSea )) {
  4346. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4347. }
  4348. $pageinfo ['page'] = array (
  4349. 'previous' => ''
  4350. );
  4351. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4352. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4353. $action = "invoiceMyUnAccountAchieve";
  4354. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4355. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4356. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4357. Doo::loadModel ( 'express' );
  4358. $express = new express ();
  4359. $expressList = $express->getExpressByAll ();
  4360. $this->data ['expressList'] = $expressList;
  4361. // print_r($list);
  4362. $this->data ['MebSeaEn'] = $MebSea;
  4363. $this->data ['get'] = $get;
  4364. $this->data ['page'] = $pageinfo;
  4365. $this->data ['date'] = $date;
  4366. $this->data ['list'] = $list;
  4367. $this->data ['memu'] = "invoice";
  4368. $this->data ['staff'] = $this->staff;
  4369. $this->data ['receiptMemu'] = 'invoice';
  4370. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4371. }
  4372. function invoiceReceivablesAchieve() {
  4373. Doo::loadModel ( 'invoiceReceivables' );
  4374. $invoiceReceivables = new invoiceReceivables ();
  4375. Doo::loadClass ( 'XDeode' );
  4376. $XDeode = new XDeode ( 5 );
  4377. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4378. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4379. $page_size = 12;
  4380. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4381. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4382. $get = "/" . $date;
  4383. $con = '';
  4384. if ($date == 'MONTHO')
  4385. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4386. elseif ($date == 'MONTHT')
  4387. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4388. elseif ($date == 'MONTHY')
  4389. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4390. if (! empty ( $MebSea )) {
  4391. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4392. $get .= "/" . $MebSea;
  4393. }
  4394. $pageinfo ['page'] = array (
  4395. 'previous' => ''
  4396. );
  4397. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4398. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4399. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4400. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4401. // print_r($pageinfo);
  4402. $this->data ['MebSeaEn'] = $MebSea;
  4403. $this->data ['MebSea'] = urlencode ( $MebSea );
  4404. $this->data ['get'] = $get;
  4405. $this->data ['page'] = $pageinfo;
  4406. $this->data ['list'] = $list;
  4407. $this->data ['date'] = $date;
  4408. $this->data ['memu'] = "invoice";
  4409. $this->data ['staff'] = $this->staff;
  4410. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4411. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4412. }
  4413. /**
  4414. * 收款解绑
  4415. */
  4416. function invoiceUnBundLing() {
  4417. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4418. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4419. Doo::loadModel ( 'invoice' );
  4420. $invoice = new invoice ();
  4421. Doo::loadModel ( 'invoiceReceivables' );
  4422. $invoiceReceivables = new invoiceReceivables ();
  4423. Doo::loadModel ( 'invoiceOperationLog' );
  4424. $invoiceOperationLog = new invoiceOperationLog ();
  4425. Doo::loadModel ( 'invoiceROLog' );
  4426. $invoiceROLog = new invoiceROLog ();
  4427. Doo::loadModel ( 'invoiceStatistics' );
  4428. Doo::loadClass ( 'XDeode' );
  4429. $XDeode = new XDeode ( 5 );
  4430. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4431. die ( 'illegal request' );
  4432. $iid = $XDeode->decode ( $iidKey );
  4433. $irid = $invoice->authcode ( $unBundKey );
  4434. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4435. die ( 'illegal request' );
  4436. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4437. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4438. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4439. die ( 'illegal request' );
  4440. // 收款
  4441. $item = array (
  4442. 'irid' => $irDetails ['irid'],
  4443. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4444. 'bindStatus' => 0
  4445. );
  4446. if ($irDetails ['iid'] == $iid)
  4447. $item += array (
  4448. 'iid' => 0
  4449. );
  4450. else {
  4451. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4452. foreach ( $iidExtend as $key => $value ) {
  4453. if ($value == $iid)
  4454. unset ( $iidExtend [$key] );
  4455. }
  4456. $iidExtend = implode ( ',', $iidExtend );
  4457. $item += array (
  4458. 'iidExtend' => $iidExtend
  4459. );
  4460. }
  4461. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4462. // 收款操作日志
  4463. $item = array (
  4464. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4465. 'date' => date ( "Y-m-d" ),
  4466. 'status' => 3,
  4467. 'img' => $this->staff [0] ['avatar'],
  4468. 'username' => $this->staff [0] ['username'],
  4469. 'uid' => $this->staff [0] ['sid'],
  4470. 'category' => $this->staff [0] ['category'],
  4471. 'irid' => $irid
  4472. );
  4473. $invoiceROLog->setInvoiceROLog ( $item );
  4474. // 扣除入账统计金额
  4475. $invoiceStatistics = new invoiceStatistics ();
  4476. $item = array (
  4477. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4478. 'priceClass' => 3,
  4479. 'cid' => $invoiceDetails ['cid'],
  4480. 'staff' => $invoiceDetails ['sid'],
  4481. 'accountPrice' => - $irDetails ['receivablesPrice']
  4482. );
  4483. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4484. // 扣除收款统计金额
  4485. $invoiceStatistics = new invoiceStatistics ();
  4486. $item = array (
  4487. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4488. 'priceClass' => 2,
  4489. 'cid' => $invoiceDetails ['cid'],
  4490. 'staff' => $invoiceDetails ['sid'],
  4491. 'irid' => $irDetails ['irid'],
  4492. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4493. );
  4494. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4495. // 发票解绑去收款ID
  4496. $iridString = $invoiceDetails ['irid'];
  4497. if (! empty ( $invoiceDetails ['irid'] )) {
  4498. $list = explode ( ',', $invoiceDetails ['irid'] );
  4499. foreach ( $list as $key => $value ) {
  4500. if ($value == $irDetails ['irid']) {
  4501. unset ( $list [$key] );
  4502. break;
  4503. }
  4504. }
  4505. $iridString = implode ( ",", $list );
  4506. }
  4507. $item = array (
  4508. 'iid' => $invoiceDetails ['iid'],
  4509. 'irid' => $iridString,
  4510. 'updateTime' => date ( "Y-m-d H:i:s" )
  4511. );
  4512. if ($invoiceDetails ['untreadStatus'] == 3)
  4513. $item += array (
  4514. 'untreadStatus' => 0
  4515. );
  4516. $invoice->setInvoiceByCondition ( $item );
  4517. $item = array (
  4518. 'date' => date ( "Y-m-d H:i:s" ),
  4519. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4520. 'status' => 11,
  4521. 'img' => $this->staff [0] ['avatar'],
  4522. 'username' => $this->staff [0] ['username'],
  4523. 'uid' => $this->staff [0] ['sid'],
  4524. 'category' => $this->staff [0] ['category'],
  4525. 'iid' => $invoiceDetails ['iid']
  4526. );
  4527. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4528. // 公司流水-解绑时删除流水
  4529. Doo::loadModel ( 'wasteBook' );
  4530. $wasteBook = new wasteBook ();
  4531. // $wasteBook->delete ( array (
  4532. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  4533. // 'limit' => 1
  4534. // ) );
  4535. // 银行
  4536. /*
  4537. * $abDetail = $wasteBook->getAccountBookByAid (2,7,$irDetails ['irid'] ); $accountBank=''; if ($irDetails ['receivablesBank']=='纵横广发'){ $accountBank='CGBDeposit'; }elseif($irDetails ['receivablesBank']=='纵横工行'){ $accountBank='ICBCDeposit'; }elseif($irDetails ['receivablesBank']=='华润银行'){ $accountBank='HUADeposit'; }elseif($irDetails ['receivablesBank']=='个人广发'){ $accountBank='PersonalDeposit'; } if (empty($abDetail)){ $item = array ( 'dataID' => $irDetails ['irid'], 'expensesType' => 2, 'accountType' => 7, 'accountPriceShow'=>$irDetails ['receivablesPrice'], 'accountPrice' => -$irDetails ['receivablesPrice'], 'accountBank'=>$accountBank, 'cid'=>$this->staff[0]['cid'], 'name'=>$this->staff[0]['username'], 'sid'=>$this->staff[0]['sid'], 'inputDate'=>date ( "Y-m-d H:i:s" ) ); $wasteBook->setAccountBookStatistics($item); }
  4538. */
  4539. return "/invoiceReceivablesAS";
  4540. }
  4541. /**
  4542. * 或者该收款下的所以发票
  4543. */
  4544. function ajaxGetInvoiceReceivablesByInvoice() {
  4545. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4546. Doo::loadModel ( 'invoice' );
  4547. $invoice = new invoice ();
  4548. Doo::loadModel ( 'invoiceReceivables' );
  4549. $invoiceReceivables = new invoiceReceivables ();
  4550. $irid = $invoice->authcode ( $irid );
  4551. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4552. die ( 'illegal request' );
  4553. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4554. $iidString = $irDetails ['iid'];
  4555. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4556. if (! empty ( $irDetails ['iidExtend'] ))
  4557. $iidString .= ',' . implode ( ',', $iidExtend );
  4558. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4559. $html = "";
  4560. foreach ( $invoiceList as $key => $value ) {
  4561. $title = $value ['invoiceTitle'];
  4562. if (! empty ( $value ['invoiceCompany'] ))
  4563. $title = $value ['invoiceCompany'];
  4564. $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>';
  4565. }
  4566. echo json_encode ( array (
  4567. 'status' => 1,
  4568. 'html' => $html
  4569. ) );
  4570. }
  4571. /**
  4572. * 发票管理
  4573. */
  4574. function invoiceAS() {
  4575. Doo::loadModel ( 'invoice' );
  4576. $invoice = new invoice ();
  4577. Doo::loadModel ( 'invoiceReceivables' );
  4578. $invoiceReceivables = new invoiceReceivables ();
  4579. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4580. $page_size = 18;
  4581. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4582. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4583. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4584. $dateArr = explode ( ':', $date );
  4585. $D1 = '';
  4586. $D2 = '';
  4587. if (! empty ( $date )) {
  4588. $D1 = $dateArr [0] . " 00:00:00 ";
  4589. if (isset ( $dateArr [1] ))
  4590. $D2 = $dateArr [1] . " 23:59:59 ";
  4591. else
  4592. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4593. // $D2 = $dateArr [1];
  4594. }
  4595. $con = ' status=2 ';
  4596. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4597. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4598. if ($status == 'UNRECORD')
  4599. $con .= ' and printStatus=1 and untreadStatus=0';
  4600. elseif ($status == 'RECORD')
  4601. $con .= ' and printStatus=1 and untreadStatus=3';
  4602. elseif ($status == 'BOUNCED')
  4603. $con .= ' and untreadStatus=2';
  4604. elseif ($status == 'PARTRECORD')
  4605. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4606. elseif ($status == 'All') {
  4607. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  4608. }
  4609. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4610. if (! empty ( $MebSea )) {
  4611. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  4612. }
  4613. $pageinfo ['page'] = array (
  4614. 'previous' => ''
  4615. );
  4616. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4617. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4618. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4619. $this->data ['MebSeaEn'] = $MebSea;
  4620. $this->data ['MebSea'] = urlencode ( $MebSea );
  4621. $this->data ['date'] = $date;
  4622. $this->data ['page'] = $pageinfo;
  4623. $this->data ['get'] = $get;
  4624. $this->data ['list'] = $list;
  4625. $this->data ['status'] = $status;
  4626. $this->data ['memu'] = "invoice";
  4627. $this->data ['staff'] = $this->staff;
  4628. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4629. $this->render ( "/admin/invoiceAS", $this->data );
  4630. }
  4631. /**
  4632. * 收款管理
  4633. */
  4634. function invoiceReceivablesAS() {
  4635. Doo::loadModel ( 'invoiceReceivables' );
  4636. $invoiceReceivables = new invoiceReceivables ();
  4637. Doo::loadModel ( 'L_category' );
  4638. $lCategory = new L_category ();
  4639. $category = $lCategory->getCategory ();
  4640. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4641. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4642. $page_size = 10;
  4643. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4644. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4645. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4646. $dateArr = explode ( ':', $date );
  4647. $D1 = '';
  4648. $D2 = '';
  4649. if (! empty ( $date )) {
  4650. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4651. if (isset ( $dateArr [1] ))
  4652. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4653. else
  4654. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4655. }
  4656. $descField = 'a.receivablesDate';
  4657. if ($timeType == 'CREATE')
  4658. $descField = 'a.date';
  4659. $con = '1';
  4660. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4661. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4662. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4663. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4664. if ($status == 'Unclaimed')
  4665. $con .= ' and a.bindStatus=0';
  4666. elseif ($status == 'Credited')
  4667. $con .= ' and a.bindStatus=1';
  4668. elseif ($status == 'Claim')
  4669. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4670. elseif ($status == 'BBN')
  4671. $con .= ' and a.bankBatchNumber!=""';
  4672. elseif ($status == 'REFUND')
  4673. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  4674. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4675. if (! empty ( $MebSea )) {
  4676. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  4677. }
  4678. $pageinfo ['page'] = array (
  4679. 'previous' => ''
  4680. );
  4681. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4682. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4683. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4684. where ' . $con . ' group by a.irid ';
  4685. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4686. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4687. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4688. foreach ( $list as $key => $value ) {
  4689. $list [$key] ['category'] = '';
  4690. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4691. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4692. $list [$key] ['category'] = $receivablesCategory [1];
  4693. }
  4694. }
  4695. // print_r($list);
  4696. $this->data ['category'] = $category;
  4697. $this->data ['timeType'] = $timeType;
  4698. $this->data ['MebSeaEn'] = $MebSea;
  4699. $this->data ['MebSea'] = urlencode ( $MebSea );
  4700. $this->data ['date'] = $date;
  4701. $this->data ['page'] = $pageinfo;
  4702. $this->data ['get'] = $get;
  4703. $this->data ['list'] = $list;
  4704. $this->data ['status'] = $status;
  4705. $this->data ['memu'] = "invoice";
  4706. $this->data ['staff'] = $this->staff;
  4707. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4708. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4709. }
  4710. /**
  4711. * 删除一条收款
  4712. */
  4713. function delInvoiceReceivables() {
  4714. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  4715. if (empty ( $iridKey ))
  4716. die ( 'illegal request' );
  4717. Doo::loadClass ( 'XDeode' );
  4718. $XDeode = new XDeode ( 5 );
  4719. $irid = $XDeode->decode ( $iridKey );
  4720. Doo::loadModel ( 'invoiceReceivables' );
  4721. $invoiceReceivables = new invoiceReceivables ();
  4722. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4723. if (empty ( $detail ))
  4724. die ( 'illegal request' );
  4725. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  4726. // 扣除收款汇总信息 汇总
  4727. Doo::loadModel ( 'invoiceStatistics' );
  4728. $invoiceStatistics = new invoiceStatistics ();
  4729. $item = array (
  4730. 'date' => $detail ['receivablesDate'],
  4731. 'priceClass' => 2,
  4732. 'irid' => $detail ['irid'],
  4733. 'receivablesPrice' => - $detail ['receivablesPrice']
  4734. );
  4735. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  4736. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  4737. $item += array (
  4738. 'cid' => $receivablesCategory [0]
  4739. );
  4740. }
  4741. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  4742. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  4743. $item += array (
  4744. 'staff' => $receivablesStaff [0]
  4745. );
  4746. }
  4747. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4748. return '/invoiceReceivablesAS';
  4749. }
  4750. /**
  4751. * 添加退款信息
  4752. */
  4753. function setInvoiceReceivablesRefund() {
  4754. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4755. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  4756. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  4757. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  4758. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4759. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  4760. if ($refundPrice < 0)
  4761. die ( 'illegal request' );
  4762. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  4763. Doo::loadModel ( 'invoiceReceivables' );
  4764. $invoiceReceivables = new invoiceReceivables ();
  4765. Doo::loadModel ( 'invoiceRefund' );
  4766. $invoiceRefund = new invoiceRefund ();
  4767. $irid = $invoiceReceivables->authcode ( $iridKey );
  4768. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4769. if ($irDetail ['receivablesPrice'] < $refundPrice)
  4770. die ( 'illegal request' );
  4771. $invoiceReceivables = new invoiceReceivables ();
  4772. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  4773. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  4774. ';
  4775. $item = array (
  4776. 'irid' => $irid,
  4777. 'refundCompany' => $refundCompany,
  4778. 'refundNumber' => $refundNumber,
  4779. 'refundPrice' => $refundPrice,
  4780. 'refundRemarks' => $refundRemarks,
  4781. 'refundLog' => $refundLog
  4782. );
  4783. if ($refundType == 1) {
  4784. $item += array (
  4785. 'refundType' => $refundType,
  4786. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4787. 'bindStatus' => 2
  4788. );
  4789. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  4790. $item += array (
  4791. 'refundType' => 1,
  4792. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  4793. 'bindStatus' => 2
  4794. );
  4795. } else {
  4796. $item += array (
  4797. 'refundType' => $refundType,
  4798. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  4799. );
  4800. }
  4801. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4802. // 添加退款记录
  4803. $item = array (
  4804. 'irid' => $irid,
  4805. 'refundType' => $refundType,
  4806. 'refundCompany' => $refundCompany,
  4807. 'refundNumber' => $refundNumber,
  4808. 'refundPrice' => $refundPrice,
  4809. 'refundLog' => $refundLog,
  4810. 'refundRemarks' => $refundRemarks,
  4811. 'date' => date ( "Y-m-d H:i:s" )
  4812. );
  4813. $invoiceRefund->addInvoiceRefund ( $item );
  4814. // 扣除收款汇总信息 汇总
  4815. Doo::loadModel ( 'invoiceStatistics' );
  4816. $invoiceStatistics = new invoiceStatistics ();
  4817. $item = array (
  4818. 'date' => $irDetail ['receivablesDate'],
  4819. 'priceClass' => 2,
  4820. 'irid' => $irDetail ['irid'],
  4821. 'receivablesPrice' => - $refundPrice
  4822. );
  4823. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  4824. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  4825. $item += array (
  4826. 'cid' => $receivablesCategory [0]
  4827. );
  4828. }
  4829. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  4830. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  4831. $item += array (
  4832. 'staff' => $receivablesStaff [0]
  4833. );
  4834. }
  4835. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4836. // 公司日常支出流水
  4837. Doo::loadModel ( 'wasteBook' );
  4838. $wasteBook = new wasteBook ();
  4839. $accountBank = '';
  4840. if ($irDetail ['receivablesBank'] == '纵横广发') {
  4841. $accountBank = 'CGBDeposit';
  4842. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  4843. $accountBank = 'ICBCDeposit';
  4844. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  4845. $accountBank = 'HUADeposit';
  4846. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  4847. $accountBank = 'PersonalDeposit';
  4848. }
  4849. $itemWaste = array (
  4850. 'accountPrice' => - $refundPrice,
  4851. 'expensesType' => 2,
  4852. 'accountType' => 11,
  4853. 'accountPriceShow' => $refundPrice,
  4854. 'dataID' => $irid,
  4855. 'accountBank' => $accountBank,
  4856. 'category' => $this->staff [0] ['category'],
  4857. 'cid' => $this->staff [0] ['cid'],
  4858. 'name' => $this->staff [0] ['username'],
  4859. 'sid' => $this->staff [0] ['sid'],
  4860. 'inputDate' => date ( "Y-m-d H:i:s" )
  4861. );
  4862. $wasteBook->setAccountBookStatistics ( $itemWaste );
  4863. return '/invoiceReceivablesAS';
  4864. }
  4865. die ( 'illegal request' );
  4866. }
  4867. function ajaxCheckInvoiceReceivablesRefund() {
  4868. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4869. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  4870. if ($refundPrice < 0) {
  4871. echo json_encode ( array (
  4872. 'error' => '金额不能为负'
  4873. ) );
  4874. die ();
  4875. }
  4876. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  4877. Doo::loadModel ( 'invoiceReceivables' );
  4878. $invoiceReceivables = new invoiceReceivables ();
  4879. $irid = $invoiceReceivables->authcode ( $iridKey );
  4880. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4881. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  4882. echo json_encode ( array (
  4883. 'error' => '退款金额不能超过收款金额'
  4884. ) );
  4885. die ();
  4886. }
  4887. echo json_encode ( array (
  4888. 'ok' => '可以使用!'
  4889. ) );
  4890. die ();
  4891. }
  4892. }
  4893. /**
  4894. * 获得收款退款信息
  4895. */
  4896. function getRefundByDetail() {
  4897. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4898. Doo::loadModel ( 'invoiceReceivables' );
  4899. $invoiceReceivables = new invoiceReceivables ();
  4900. if (! empty ( $iridKey )) {
  4901. $irid = $invoiceReceivables->authcode ( $iridKey );
  4902. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4903. echo json_encode ( array (
  4904. 'status' => 1,
  4905. 'irDetail' => $irDetail
  4906. ) );
  4907. die ();
  4908. }
  4909. echo json_encode ( array (
  4910. 'status' => 2
  4911. ) );
  4912. }
  4913. /**
  4914. * 根据收款序列号获得收款退款信息
  4915. */
  4916. function ajaxGetInvoiceReceivablesBySerial() {
  4917. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  4918. if (! empty ( $receivablesSerial )) {
  4919. Doo::loadModel ( 'invoiceReceivables' );
  4920. $invoiceReceivables = new invoiceReceivables ();
  4921. // , ' and refundLog=""'
  4922. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  4923. $html = '';
  4924. if (! empty ( $irDetail ))
  4925. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  4926. <td>' . $irDetail ['receivablesMessage'] . '</td>
  4927. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  4928. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  4929. <td>' . $irDetail ['recepitTitleMark'] . '
  4930. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  4931. </td>';
  4932. echo json_encode ( array (
  4933. 'status' => 1,
  4934. 'html' => $html,
  4935. 'irDetail' => $irDetail
  4936. ) );
  4937. die ();
  4938. }
  4939. echo json_encode ( array (
  4940. 'status' => 2
  4941. ) );
  4942. }
  4943. /**
  4944. * 绑定新收款
  4945. */
  4946. function relationNewInvoiceReceivables() {
  4947. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  4948. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  4949. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  4950. Doo::loadModel ( 'invoiceReceivables' );
  4951. $invoiceReceivables = new invoiceReceivables ();
  4952. Doo::loadClass ( 'XDeode' );
  4953. $XDeode = new XDeode ( 5 );
  4954. $irid = $XDeode->decode ( $iridKey );
  4955. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  4956. echo $irid . 'bbb' . $iridOld;
  4957. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  4958. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4959. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  4960. die ( 'illegal request' );
  4961. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  4962. <br/>' . date ( "Y-m-d H:i:s" ) . '
  4963. ';
  4964. $invoiceReceivables = new invoiceReceivables ();
  4965. $item = array (
  4966. 'irid' => $iridOld,
  4967. 'relationIrid' => $irid,
  4968. 'relationLog' => $relationLog
  4969. );
  4970. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4971. return '/invoiceReceivablesAS';
  4972. }
  4973. die ( 'illegal request' );
  4974. }
  4975. // function invoiceApprovalAchieve() {
  4976. // Doo::loadModel ( 'invoice' );
  4977. // $invoice = new invoice ();
  4978. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4979. // $page_size = 12;
  4980. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4981. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4982. // $get = "/" . $date;
  4983. // $con = '';
  4984. // if ($date == 'MONTHO')
  4985. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4986. // elseif ($date == 'MONTHT')
  4987. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4988. // elseif ($date == 'MONTHY')
  4989. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4990. // if (! empty ( $MebSea )) {
  4991. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4992. // $get .= "/" . $MebSea;
  4993. // }
  4994. // $pageinfo ['page'] = array (
  4995. // 'previous' => ''
  4996. // );
  4997. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  4998. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4999. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5000. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5001. // // print_r($list);
  5002. // $this->data ['MebSeaEn'] = $MebSea;
  5003. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5004. // $this->data ['get'] = $get;
  5005. // $this->data ['page'] = $pageinfo;
  5006. // $this->data ['list'] = $list;
  5007. // $this->data ['date'] = $date;
  5008. // $this->data ['memu'] = "invoice";
  5009. // $this->data ['staff'] = $this->staff;
  5010. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5011. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5012. // }
  5013. /**
  5014. * 获得审批发票的信息以及审批页面
  5015. */
  5016. function ajaxGetInvoiceApprovalDetail() {
  5017. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5018. if (empty ( $serial )) {
  5019. echo json_encode ( array (
  5020. 'status' => 2,
  5021. 'msg' => 'illegal request'
  5022. ) );
  5023. die ();
  5024. }
  5025. Doo::loadModel ( 'invoice' );
  5026. $invoice = new invoice ();
  5027. Doo::loadModel ( 'invoiceOperationLog' );
  5028. $invoiceOperationLog = new invoiceOperationLog ();
  5029. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5030. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5031. if (empty ( $detail ))
  5032. $html = '';
  5033. else {
  5034. $html = '
  5035. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5036. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5037. <input type="hidden" name="status" value="">
  5038. <input type="hidden" name="divApproval" value="divApproval">
  5039. <div class="modal-dialog modal-lg">
  5040. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5041. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5042. <tr>
  5043. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5044. </tr>
  5045. <tr>
  5046. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5047. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5048. </tr>
  5049. <tr>
  5050. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5051. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5052. </tr>
  5053. <tr>
  5054. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5055. </td>
  5056. </tr>
  5057. <tr>
  5058. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5059. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5060. </tr>
  5061. <tr>
  5062. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5063. </tr></tbody></table>';
  5064. if ($detail ['invoiceType'] == 0)
  5065. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5066. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5067. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5068. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5069. </tr>';
  5070. else
  5071. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5072. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5073. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5074. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5075. ';
  5076. $html .= '<tr>
  5077. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5078. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5079. </tr>
  5080. <tr>
  5081. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5082. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5083. </tr></tbody></table>';
  5084. if ($detail ['doPost'] == 1) {
  5085. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5086. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5087. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5088. </tr><tr>
  5089. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5090. </tr><tr>
  5091. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5092. </tr>
  5093. ';
  5094. if ($detail ['expressCom'] == 'SF')
  5095. $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>';
  5096. else
  5097. $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>';
  5098. $html .= '</tbody></table>';
  5099. }
  5100. if (! empty ( $invoiceOperationLogList )) {
  5101. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5102. foreach ( $invoiceOperationLogList as $key => $value ) {
  5103. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5104. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5105. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5106. if ($value ['status'] == 2) {
  5107. $html .= '<span class="colGreen">同意</span>';
  5108. } elseif ($value ['status'] == 3) {
  5109. $html .= '<span class="colOrange">退回</span>';
  5110. } elseif ($value ['status'] == 5) {
  5111. $html .= '<span class="colGreen">打印</span>';
  5112. } elseif ($value ['status'] == 4) {
  5113. $html .= '<span class="colRed">终止</span>';
  5114. }
  5115. $html .= $value ['operation'] . '</p></blockquote>';
  5116. }
  5117. }
  5118. $html .= '</td></tr></tbody></table>';
  5119. }
  5120. $html .= '</div><div class="modal-footer">
  5121. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5122. <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>
  5123. <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>
  5124. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5125. </form>
  5126. <script type="text/javascript">
  5127. $("a[node-approval^=\'approval\']").click(function() {
  5128. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5129. $("form[name=\'invoiceApproval\']").submit();
  5130. });
  5131. </script>
  5132. ';
  5133. }
  5134. echo json_encode ( array (
  5135. 'status' => 1,
  5136. 'html' => $html
  5137. ) );
  5138. die ();
  5139. }
  5140. /**
  5141. * 获得审批发票分页数据
  5142. */
  5143. function ajaxGetinvoiceApprovalAchieve() {
  5144. Doo::loadModel ( 'invoice' );
  5145. $invoice = new invoice ();
  5146. Doo::loadModel ( 'staff' );
  5147. $staff = new staff ();
  5148. Doo::loadClass ( 'XDeode' );
  5149. $XDeode = new XDeode ( 5 );
  5150. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5151. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5152. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5153. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5154. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5155. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5156. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5157. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5158. $MebSea = $this->get_args ( 'search' );
  5159. $MebSea = $MebSea ['value'];
  5160. $page_size = $length;
  5161. $con = '';
  5162. if ($status == 'ALL')
  5163. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5164. elseif ($status == 'PEND')
  5165. $con = ' isDelete=0 and status=1';
  5166. elseif ($status == 'APPROVED')
  5167. $con = ' isDelete=0 and status=2';
  5168. if ($invoiceType == 'ORDINARY')
  5169. $con .= ' and invoiceType=0 ';
  5170. elseif ($invoiceType == 'SPECIAL')
  5171. $con .= ' and invoiceType=1 ';
  5172. if ($invoiceTrain == 'ORDINARY')
  5173. $con .= ' and trainId=0 ';
  5174. elseif ($invoiceTrain == 'TRAIN')
  5175. $con .= ' and trainId!=0 ';
  5176. if ($invoiceTrainName != 'ALL') {
  5177. $trainId = $XDeode->decode ( $invoiceTrainName );
  5178. if (is_numeric ( $trainId ))
  5179. $con .= ' and trainId =' . $trainId;
  5180. }
  5181. $dateArr = explode ( ':', $date );
  5182. $D1 = $dateString = '';
  5183. $D2 = '';
  5184. if (! empty ( $date )) {
  5185. $D1 = $dateArr [0];
  5186. if (isset ( $dateArr [1] ))
  5187. $D2 = $dateArr [1];
  5188. else
  5189. $D2 = '';
  5190. $dateString = $D1 . " : " . $D2;
  5191. }
  5192. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5193. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5194. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5195. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5196. if (! empty ( $MebSea ))
  5197. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5198. // /
  5199. $pageinfo ['page'] = array (
  5200. 'previous' => ''
  5201. );
  5202. $sql = ' ' . $con;
  5203. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5204. $limit = $page . ',' . $page_size;
  5205. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5206. $approvalList = array ();
  5207. $html = '
  5208. <script type="text/javascript">
  5209. </script>
  5210. ';
  5211. foreach ( $list as $key => $value ) {
  5212. $irDetail = array ();
  5213. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5214. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5215. } else
  5216. array_push ( $irDetail, '' );
  5217. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5218. if ($value ['invoiceType'] == 1)
  5219. array_push ( $irDetail, $value ['invoiceCompany'] );
  5220. else
  5221. array_push ( $irDetail, $value ['invoiceTitle'] );
  5222. array_push ( $irDetail, $value ['TIN'] );
  5223. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5224. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5225. array_push ( $irDetail, $value ['remark'] );
  5226. array_push ( $irDetail, $value ['invoiceElement'] );
  5227. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5228. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5229. if ($value ['invoiceType'] == 1)
  5230. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5231. else
  5232. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5233. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5234. array_push ( $irDetail, $value ['recipientsAddress'] );
  5235. array_push ( $irDetail, $value ['mailItems'] );
  5236. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5237. $fchtml = $value ['OL'] ['operation'];
  5238. if (count ( $list ) == $page_size)
  5239. $fchtml = $value ['OL'] ['operation'] . $html;
  5240. // 最后的审批意见
  5241. array_push ( $irDetail, $fchtml );
  5242. if ($value ['status'] == 2)
  5243. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5244. elseif ($value ['status'] == 3)
  5245. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5246. elseif ($value ['status'] == 4)
  5247. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5248. else
  5249. array_push ( $irDetail, '' );
  5250. array_push ( $approvalList, $irDetail );
  5251. }
  5252. // $approvalListJson = json_encode ( $approvalList );
  5253. $recordsFiltered = $pageinfo ['total_data'];
  5254. echo json_encode ( array (
  5255. "draw" => intval ( $draw ),
  5256. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5257. "recordsFiltered" => intval ( $recordsFiltered ),
  5258. "data" => $approvalList
  5259. ), JSON_UNESCAPED_UNICODE );
  5260. }
  5261. /**
  5262. * 审批发票查看更多--重构
  5263. */
  5264. function invoiceApprovalAchieve() {
  5265. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5266. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5267. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5268. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5269. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5270. Doo::loadModel ( 'invoiceTraining' );
  5271. $invoiceTraining = new invoiceTraining ();
  5272. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5273. $this->data ['trainList'] = $trainList;
  5274. $this->data ['dateString'] = $date;
  5275. $this->data ['status'] = $status;
  5276. $this->data ['invoiceType'] = $invoiceType;
  5277. $this->data ['invoiceTrain'] = $invoiceTrain;
  5278. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5279. $this->data ['memu'] = "invoice";
  5280. $this->data ['staff'] = $this->staff;
  5281. $this->data ['receiptMemu'] = 'invoiceApproval';
  5282. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5283. }
  5284. function invoiceTAchieve() {
  5285. Doo::loadModel ( 'invoice' );
  5286. $invoice = new invoice ();
  5287. Doo::loadClass ( 'XDeode' );
  5288. $XDeode = new XDeode ( 5 );
  5289. Doo::loadModel ( 'staff' );
  5290. $staff = new staff ();
  5291. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5292. $page_size = 12;
  5293. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5294. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5295. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5296. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5297. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5298. Doo::loadModel ( 'invoiceTraining' );
  5299. $invoiceTraining = new invoiceTraining ();
  5300. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5301. $get = "/" . $date;
  5302. $con = '';
  5303. if ($date == 'MONTHO')
  5304. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5305. elseif ($date == 'MONTHT')
  5306. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5307. elseif ($date == 'MONTHY')
  5308. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5309. if ($invoiceType == 'ORDINARY')
  5310. $con .= ' and invoiceType=0 ';
  5311. elseif ($invoiceType == 'SPECIAL')
  5312. $con .= ' and invoiceType=1 ';
  5313. if ($invoiceTrain == 'ORDINARY')
  5314. $con .= ' and trainId=0 ';
  5315. elseif ($invoiceTrain == 'TRAIN')
  5316. $con .= ' and trainId!=0 ';
  5317. if ($invoiceTrainName != 'ALL') {
  5318. $trainId = $XDeode->decode ( $invoiceTrainName );
  5319. if (is_numeric ( $trainId ))
  5320. $con .= ' and trainId =' . $trainId;
  5321. }
  5322. if (! empty ( $MebSea )) {
  5323. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5324. $get .= "/" . $MebSea;
  5325. }
  5326. $pageinfo ['page'] = array (
  5327. 'previous' => ''
  5328. );
  5329. $sql = "";
  5330. $action = "";
  5331. if ($this->ACTION == 'invoicePrintAchieve') {
  5332. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5333. $action = "invoicePrintAchieve";
  5334. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5335. // and untreadStatus=0
  5336. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5337. $action = "invoicePostAchieve";
  5338. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5339. $sql = " untreadStatus=2 and status=2 " . $con;
  5340. $action = "invoiceUntreadAchieve";
  5341. }
  5342. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5343. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5344. $this->data ['MebSeaEn'] = $MebSea;
  5345. $this->data ['MebSea'] = urlencode ( $MebSea );
  5346. $this->data ['get'] = $get;
  5347. $this->data ['page'] = $pageinfo;
  5348. $this->data ['trainList'] = $trainList;
  5349. $this->data ['invoiceType'] = $invoiceType;
  5350. $this->data ['invoiceTrain'] = $invoiceTrain;
  5351. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5352. $this->data ['date'] = $date;
  5353. $this->data ['memu'] = "invoice";
  5354. $this->data ['staff'] = $this->staff;
  5355. if ($this->ACTION == 'invoicePrintAchieve') {
  5356. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5357. $this->data ['receiptMemu'] = 'invoicePrint';
  5358. $this->data ['list'] = $list;
  5359. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5360. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5361. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5362. Doo::loadModel ( 'express' );
  5363. $express = new express ();
  5364. $expressList = $express->getExpressByAll ();
  5365. $this->data ['expressList'] = $expressList;
  5366. $this->data ['receiptMemu'] = 'invoicePost';
  5367. $this->data ['list'] = $list;
  5368. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5369. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5370. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5371. $this->data ['receiptMemu'] = 'invoiceUntread';
  5372. $this->data ['list'] = $list;
  5373. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5374. }
  5375. }
  5376. /**
  5377. * 公司应收款
  5378. */
  5379. function invoiceAggregateCompanyDetail() {
  5380. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5381. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5382. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5383. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5384. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5385. Doo::loadClass ( 'XDeode' );
  5386. $XDeode = new XDeode ( 5 );
  5387. Doo::loadModel ( 'invoice' );
  5388. $invoice = new invoice ();
  5389. Doo::loadModel ( 'staff' );
  5390. $staff = new staff ();
  5391. Doo::loadModel ( "invoiceCompanyManage" );
  5392. $invoiceCompanyManage = new invoiceCompanyManage ();
  5393. Doo::loadModel ( 'L_category' );
  5394. $category = new L_category ();
  5395. $sid = '';
  5396. if (! empty ( $sidKey )) {
  5397. $sid = $XDeode->decode ( $sidKey );
  5398. }
  5399. $staffDetail = $staff->getStaffBySid ( $sid );
  5400. $cid = '';
  5401. if (! empty ( $cidKey )) {
  5402. $cid = $XDeode->decode ( $cidKey );
  5403. }
  5404. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5405. $cidList = array ();
  5406. foreach ( $imcStaff as $key => $value ) {
  5407. array_push ( $cidList, $value ['cid'] );
  5408. }
  5409. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5410. $cidString = implode ( ',', $cidList );
  5411. if (empty ( $cid ))
  5412. $staffList = $staff->getStaffInCid ( $cidString );
  5413. else
  5414. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5415. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5416. $page_size = 25;
  5417. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5418. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5419. $con = ' status=2 and untreadStatus!=2 ';
  5420. $statisticsCon = '';
  5421. if (! empty ( $year ) && is_numeric ( $year ))
  5422. $con .= ' and Year(printTime)=' . $year . '';
  5423. if (! empty ( $month ) && is_numeric ( $month ))
  5424. $con .= ' and Month(printTime)="' . $month . '" ';
  5425. if ($status == 'UNRECORD')
  5426. $con .= ' and printStatus=1 and untreadStatus=0';
  5427. elseif ($status == 'RECORD')
  5428. $con .= ' and printStatus=1 and untreadStatus=3';
  5429. elseif ($status == 'BOUNCED')
  5430. $con .= ' and untreadStatus=2';
  5431. elseif ($status == 'PARTRECORD')
  5432. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5433. elseif ($status == 'All') {
  5434. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5435. }
  5436. if (! empty ( $sid ) && is_numeric ( $sid ))
  5437. $con .= ' and sid=' . $sid;
  5438. if (! empty ( $cid ) && is_numeric ( $cid ))
  5439. $con .= ' and cid=' . $cid;
  5440. else
  5441. $con .= ' and cid in (' . $cidString . ')';
  5442. // 开票内容筛选
  5443. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5444. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5445. }
  5446. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month . "&invoiceElement=" . $invoiceElement;
  5447. if (! empty ( $MebSea )) {
  5448. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  5449. }
  5450. $pageinfo ['page'] = array (
  5451. 'previous' => ''
  5452. );
  5453. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  5454. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5455. // 应收款合计
  5456. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  5457. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5458. $monthHtml = "";
  5459. if ($year != "ALL") {
  5460. for($i = 1; $i <= 12; $i ++) {
  5461. if ($i == $month)
  5462. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  5463. else
  5464. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  5465. }
  5466. }
  5467. $this->data ['monthHtml'] = $monthHtml;
  5468. $this->data ['year'] = $year;
  5469. $this->data ['month'] = $month;
  5470. $this->data ['ics'] = $ics;
  5471. $this->data ['cidKey'] = $cidKey;
  5472. $this->data ['sid'] = $sid;
  5473. $this->data ['staffDetail'] = $staffDetail;
  5474. $this->data ['staffList'] = $staffList;
  5475. $this->data ['MebSeaEn'] = $MebSea;
  5476. $this->data ['MebSea'] = urlencode ( $MebSea );
  5477. $this->data ['invoiceDetail'] = array (
  5478. 'invoiceElement' => $invoiceElement
  5479. );
  5480. $this->data ['page'] = $pageinfo;
  5481. $this->data ['get'] = $get;
  5482. $this->data ['list'] = $list;
  5483. $this->data ['status'] = $status;
  5484. $this->data ['categoryList'] = $categoryList;
  5485. $this->data ['memu'] = "invoice";
  5486. $this->data ['staff'] = $this->staff;
  5487. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  5488. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  5489. }
  5490. /**
  5491. * 获取一条收款信息
  5492. */
  5493. function ajaxGetInvoiceReceivables() {
  5494. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  5495. Doo::loadModel ( 'invoiceReceivables' );
  5496. $invoiceReceivables = new invoiceReceivables ();
  5497. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5498. echo json_encode ( array (
  5499. 'status' => 1,
  5500. 'detail' => $detail
  5501. ) );
  5502. }
  5503. /**
  5504. * 异步获取办事处用户
  5505. */
  5506. function ajaxGetStaffByCategory() {
  5507. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  5508. Doo::loadModel ( 'staff' );
  5509. $staff = new staff ();
  5510. if ($cid == "PUBLIC") {
  5511. echo json_encode ( array (
  5512. 'status' => 1,
  5513. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  5514. ) );
  5515. die ();
  5516. }
  5517. if (! is_numeric ( $cid )) {
  5518. echo json_encode ( array (
  5519. 'status' => 0,
  5520. 'msg' => 'illegal request'
  5521. ) );
  5522. die ();
  5523. }
  5524. $staffList = $staff->getStaffByCid ( $cid );
  5525. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  5526. foreach ( $staffList as $key => $value ) {
  5527. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5528. }
  5529. echo json_encode ( array (
  5530. 'status' => 1,
  5531. 'html' => $html
  5532. ) );
  5533. }
  5534. /**
  5535. * 异步获取一条发票的邮寄信息
  5536. */
  5537. function ajaxGetInvoicePostDetail() {
  5538. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5539. Doo::loadModel ( 'invoice' );
  5540. $invoice = new invoice ();
  5541. $iid = $invoice->authcode ( $iid );
  5542. Doo::loadModel ( 'express' );
  5543. $express = new express ();
  5544. $expressList = $express->getExpressByAll ();
  5545. if (! is_numeric ( $iid )) {
  5546. echo json_encode ( array (
  5547. 'status' => 0,
  5548. 'msg' => 'illegal request'
  5549. ) );
  5550. die ();
  5551. }
  5552. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  5553. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  5554. $html = "";
  5555. foreach ( $expressList as $key => $value ) {
  5556. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  5557. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5558. else
  5559. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  5560. }
  5561. $invoiceDetail ['eaHtml'] = $html;
  5562. echo json_encode ( array (
  5563. 'status' => 1,
  5564. 'invoiceDetail' => $invoiceDetail
  5565. ) );
  5566. }
  5567. /**
  5568. *
  5569. * @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 ) ); }
  5570. */
  5571. /**
  5572. *
  5573. * @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 ) ); }
  5574. */
  5575. /**
  5576. * 我的收款中 选择哪个发票入账,进行金额判断
  5577. */
  5578. function ajaxCompareInvoicePrice() {
  5579. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  5580. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  5581. Doo::loadModel ( 'invoice' );
  5582. $invoice = new invoice ();
  5583. Doo::loadModel ( 'invoiceReceivables' );
  5584. $invoiceReceivables = new invoiceReceivables ();
  5585. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  5586. $keyList = explode ( ';', $claimKey );
  5587. $receivablesPrice = 0;
  5588. foreach ( $keyList as $key => $value ) {
  5589. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  5590. $receivablesPrice += $detailM ['receivablesPrice'];
  5591. }
  5592. if ($receivablesPrice > $detail ['invoicePrice']) {
  5593. $price = $receivablesPrice - $detail ['invoicePrice'];
  5594. echo json_encode ( array (
  5595. 'status' => 1,
  5596. 'price' => $price
  5597. ) );
  5598. } else
  5599. echo json_encode ( array (
  5600. 'status' => 2
  5601. ) );
  5602. }
  5603. /**
  5604. * 获得打印发票
  5605. */
  5606. function ajaxGetInvoiceInfoByPrint() {
  5607. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5608. if (empty ( $serial )) {
  5609. echo json_encode ( array (
  5610. 'status' => 2,
  5611. 'msg' => 'illegal request'
  5612. ) );
  5613. die ();
  5614. }
  5615. Doo::loadModel ( 'invoice' );
  5616. $invoice = new invoice ();
  5617. Doo::loadModel ( 'invoiceOperationLog' );
  5618. $invoiceOperationLog = new invoiceOperationLog ();
  5619. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5620. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5621. Doo::loadModel ( 'invoicePaper' );
  5622. $invoicePaper = new invoicePaper ();
  5623. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  5624. if (empty ( $detail ))
  5625. $html = '';
  5626. else {
  5627. $html = '
  5628. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  5629. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5630. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  5631. <div class="modal-dialog modal-lg">
  5632. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5633. <div class="modal-body saeaList">
  5634. <table class="table table-bordered table-condensed"><tbody>
  5635. <tr>
  5636. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5637. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5638. </tr>
  5639. <tr>
  5640. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5641. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5642. </tr>
  5643. <tr>
  5644. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5645. </td>
  5646. </tr>
  5647. <tr>
  5648. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5649. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5650. </tr>
  5651. <tr>
  5652. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5653. </tr></tbody></table>';
  5654. if ($detail ['invoiceType'] == 0)
  5655. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5656. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5657. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5658. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5659. </tr>';
  5660. else
  5661. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5662. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5663. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5664. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5665. ';
  5666. $html .= '<tr>
  5667. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5668. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5669. </tr>
  5670. <tr>
  5671. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5672. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5673. </tr></tbody></table>';
  5674. if ($detail ['doPost'] == 1)
  5675. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5676. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5677. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5678. </tr><tr>
  5679. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5680. </tr><tr>
  5681. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5682. </tr></tbody></table>';
  5683. if (! empty ( $invoiceOperationLogList )) {
  5684. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  5685. foreach ( $invoiceOperationLogList as $key => $value ) {
  5686. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5687. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5688. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5689. if ($value ['status'] == 2) {
  5690. $html .= '<span class="colGreen">同意</span>';
  5691. } elseif ($value ['status'] == 3) {
  5692. $html .= '<span class="colOrange">退回</span>';
  5693. } elseif ($value ['status'] == 5) {
  5694. $html .= '<span class="colGreen">打印</span>';
  5695. } elseif ($value ['status'] == 4) {
  5696. $html .= '<span class="colRed">终止</span>';
  5697. }
  5698. $html .= $value ['operation'] . '</p></blockquote>';
  5699. }
  5700. }
  5701. $html .= '</td>
  5702. <td><span class="colRed">*</span>
  5703. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  5704. foreach ( $invoicePaperList as $key => $value ) {
  5705. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  5706. }
  5707. $html .= '</select>
  5708. <span class="red" id="p-msg"></span>
  5709. </td>
  5710. </tr></tbody></table>';
  5711. }
  5712. $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>
  5713. </div></div></form>
  5714. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  5715. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  5716. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  5717. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  5718. ';
  5719. }
  5720. echo json_encode ( array (
  5721. 'status' => 1,
  5722. 'html' => $html
  5723. ) );
  5724. die ();
  5725. }
  5726. /**
  5727. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5728. */
  5729. function ajaxGetInvoiceInfoByType() {
  5730. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5731. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5732. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5733. if (empty ( $serial )) {
  5734. echo json_encode ( array (
  5735. 'status' => 2,
  5736. 'msg' => 'illegal request'
  5737. ) );
  5738. die ();
  5739. }
  5740. if ($type == 'INVOICE') {
  5741. Doo::loadModel ( 'invoice' );
  5742. $invoice = new invoice ();
  5743. Doo::loadModel ( 'invoiceOperationLog' );
  5744. $invoiceOperationLog = new invoiceOperationLog ();
  5745. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5746. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5747. if (empty ( $detail ))
  5748. $html = '';
  5749. else {
  5750. $html = '
  5751. <div class="modal-dialog modal-lg">
  5752. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5753. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5754. <tr>
  5755. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5756. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5757. </tr>
  5758. <tr>
  5759. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5760. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5761. </tr>
  5762. <tr>
  5763. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5764. </td>
  5765. </tr>
  5766. <tr>
  5767. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5768. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5769. </tr>
  5770. <tr>
  5771. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5772. </tr>';
  5773. if ($detail ['settlementType'] == 1)
  5774. $html .= '<tr>
  5775. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  5776. </tr>';
  5777. else
  5778. $html .= '<tr>
  5779. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  5780. </tr>';
  5781. $html .= ' </tbody></table>';
  5782. if ($detail ['invoiceType'] == 0)
  5783. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5784. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5785. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5786. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5787. </tr>';
  5788. else
  5789. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5790. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5791. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5792. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5793. ';
  5794. $html .= '<tr>
  5795. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5796. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5797. </tr>
  5798. <tr>
  5799. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5800. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5801. </tr></tbody></table>';
  5802. if ($detail ['doPost'] == 1) {
  5803. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5804. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5805. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5806. </tr><tr>
  5807. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5808. </tr><tr>
  5809. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5810. </tr>
  5811. ';
  5812. if ($detail ['expressCom'] == 'SF')
  5813. $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>';
  5814. else
  5815. $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>';
  5816. $html .= '</tbody></table>';
  5817. }
  5818. if (! empty ( $invoiceOperationLogList )) {
  5819. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5820. foreach ( $invoiceOperationLogList as $key => $value ) {
  5821. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5822. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5823. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5824. if ($value ['status'] == 2) {
  5825. $html .= '<span class="colGreen">同意</span>';
  5826. } elseif ($value ['status'] == 3) {
  5827. $html .= '<span class="colOrange">退回</span>';
  5828. } elseif ($value ['status'] == 5) {
  5829. $html .= '<span class="colGreen">打印</span>';
  5830. } elseif ($value ['status'] == 4) {
  5831. $html .= '<span class="colRed">终止</span>';
  5832. }
  5833. $html .= $value ['operation'] . '</p></blockquote>';
  5834. }
  5835. }
  5836. $html .= '</td></tr></tbody></table>';
  5837. }
  5838. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5839. }
  5840. echo json_encode ( array (
  5841. 'status' => 1,
  5842. 'html' => $html
  5843. ) );
  5844. die ();
  5845. } elseif ($type == 'RECEIVABLES') {
  5846. Doo::loadModel ( 'invoiceReceivables' );
  5847. $invoiceReceivables = new invoiceReceivables ();
  5848. Doo::loadModel ( 'invoiceRefund' );
  5849. $invoiceRefund = new invoiceRefund ();
  5850. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5851. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  5852. if (empty ( $detail ))
  5853. $html = '';
  5854. else {
  5855. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  5856. <table class="table table-bordered table-condensed">
  5857. <tbody><tr>
  5858. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  5859. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  5860. </tr><tr>
  5861. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5862. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  5863. </tr>
  5864. <tr>
  5865. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  5866. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  5867. </tr>
  5868. <tr>
  5869. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  5870. </tr>
  5871. </tbody></table>';
  5872. if (! empty ( $ireList )) {
  5873. $html .= '
  5874. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  5875. <tr>
  5876. <th class="taC">退款单位名称</th>
  5877. <th class="taC">退款的账号</th>
  5878. <th class="taC">退款金额</th>
  5879. <th class="taC">退款</th>
  5880. <th class="taC">备注</th>
  5881. </tr>
  5882. ';
  5883. foreach ( $ireList as $key => $value ) {
  5884. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  5885. $html .= '<tr>
  5886. <td>' . $value ['refundCompany'] . '</td>
  5887. <td>' . $value ['refundNumber'] . '</td>
  5888. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  5889. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  5890. <td>' . $value ['refundRemarks'] . '</td>
  5891. </tr>
  5892. ';
  5893. }
  5894. }
  5895. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5896. }
  5897. echo json_encode ( array (
  5898. 'status' => 1,
  5899. 'html' => $html
  5900. ) );
  5901. die ();
  5902. } elseif ($type == 'IRTC') {
  5903. Doo::loadModel ( 'invoice' );
  5904. $invoice = new invoice ();
  5905. Doo::loadModel ( 'invoiceOperationLog' );
  5906. $invoiceOperationLog = new invoiceOperationLog ();
  5907. Doo::loadModel ( 'invoiceReceivables' );
  5908. $invoiceReceivables = new invoiceReceivables ();
  5909. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5910. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5911. if (empty ( $detail ))
  5912. $html = '';
  5913. else {
  5914. $receivablesPriceedHtml = '';
  5915. $receivablesPrice = $detail ['invoicePrice'];
  5916. if (! empty ( $detail ['irid'] )) {
  5917. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  5918. if (empty ( $irList ))
  5919. $irList [0] ['sumPrice'] = 0;
  5920. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  5921. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  5922. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  5923. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  5924. </tr></tbody></table>';
  5925. $receivablesPrice = $balance;
  5926. }
  5927. if ($loss)
  5928. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  5929. $html = $receivablesPriceedHtml . '
  5930. <table class="table table-bordered table-condensed"><tbody>
  5931. <tr>
  5932. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5933. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5934. </tr>
  5935. <tr>
  5936. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5937. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5938. </tr>
  5939. <tr>
  5940. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  5941. </tr>
  5942. <tr>
  5943. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5944. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5945. </tr>
  5946. <tr>
  5947. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5948. </tr></tbody></table>';
  5949. if ($detail ['invoiceType'] == 0) {
  5950. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5951. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5952. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5953. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5954. </tr>';
  5955. $receivablesMessage = $detail ['invoiceTitle'];
  5956. } else {
  5957. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5958. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5959. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5960. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5961. ';
  5962. $receivablesMessage = $detail ['invoiceCompany'];
  5963. }
  5964. $html .= '<tr>
  5965. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5966. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5967. </tr>
  5968. <tr>
  5969. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  5970. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  5971. </tr></tbody></table>';
  5972. if ($detail ['doPost'] == 1)
  5973. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5974. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5975. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5976. </tr><tr>
  5977. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5978. </tr><tr>
  5979. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5980. </tr></tbody></table>';
  5981. if (! empty ( $invoiceOperationLogList )) {
  5982. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5983. foreach ( $invoiceOperationLogList as $key => $value ) {
  5984. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5985. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5986. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5987. if ($value ['status'] == 2) {
  5988. $html .= '<span class="colGreen">同意</span>';
  5989. } elseif ($value ['status'] == 3) {
  5990. $html .= '<span class="colOrange">退回</span>';
  5991. } elseif ($value ['status'] == 5) {
  5992. $html .= '<span class="colGreen">打印</span>';
  5993. }
  5994. $html .= $value ['operation'] . '</p></blockquote>';
  5995. }
  5996. }
  5997. $html .= '</td></tr></tbody></table>';
  5998. }
  5999. }
  6000. echo json_encode ( array (
  6001. 'status' => 1,
  6002. 'html' => $html,
  6003. 'receivablesPrice' => $receivablesPrice,
  6004. 'receivablesMessage' => $receivablesMessage,
  6005. 'receivablesDate' => date ( "Y-m-d" ),
  6006. 'iidKey' => $serial
  6007. ) );
  6008. die ();
  6009. }
  6010. }
  6011. function ajaxGetInvoiceReceivablesByStaff() {
  6012. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6013. if (empty ( $postData )) {
  6014. echo json_encode ( array (
  6015. 'status' => 2,
  6016. 'msg' => 'illegal request'
  6017. ) );
  6018. die ();
  6019. }
  6020. Doo::loadModel ( 'invoiceReceivables' );
  6021. $invoiceReceivables = new invoiceReceivables ();
  6022. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6023. if (empty ( $detail )) {
  6024. echo json_encode ( array (
  6025. 'status' => 2,
  6026. 'msg' => 'illegal request'
  6027. ) );
  6028. die ();
  6029. }
  6030. Doo::loadModel ( 'L_category' );
  6031. $lCategory = new L_category ();
  6032. Doo::loadModel ( 'staff' );
  6033. $staff = new staff ();
  6034. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6035. $category = $lCategory->getCategory ();
  6036. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6037. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6038. foreach ( $category as $key => $value ) {
  6039. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6040. if ($value ['cid'] == $detail ['cid'])
  6041. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6042. }
  6043. foreach ( $staffList as $key => $value ) {
  6044. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6045. if ($value ['sid'] == $detail ['sid'])
  6046. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6047. }
  6048. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6049. echo json_encode ( array (
  6050. 'status' => 1,
  6051. 'categoryHtml' => $categoryHtml,
  6052. 'staffHtml' => $staffHtml,
  6053. 'rbankHtml' => $rbankHtml,
  6054. 'detail' => $detail
  6055. ) );
  6056. }
  6057. function ajaxGetInvoiceReceivablesByIrid() {
  6058. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6059. if (empty ( $irid )) {
  6060. echo json_encode ( array (
  6061. 'status' => 2,
  6062. 'msg' => 'illegal request'
  6063. ) );
  6064. die ();
  6065. }
  6066. Doo::loadModel ( 'invoiceReceivables' );
  6067. $invoiceReceivables = new invoiceReceivables ();
  6068. Doo::loadModel ( 'invoice' );
  6069. $invoice = new invoice ();
  6070. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6071. $flag = true;
  6072. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6073. $bakDetail = array ();
  6074. if ($flag === false) {
  6075. array_push ( $bakDetail, $invoiceDetail );
  6076. $invoiceDetail = $bakDetail;
  6077. }
  6078. $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>
  6079. <tr>
  6080. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6081. <td>' . $detail ['receivablesMessage'] . '</td>
  6082. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6083. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6084. <td>' . $detail ['recepitTitleMark'] . '</td>
  6085. </tr></tbody></table>';
  6086. $isInvoice = false;
  6087. $invoiceHtml = '';
  6088. if (empty ( $invoiceDetail )) {
  6089. $isInvoice = true;
  6090. } else {
  6091. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6092. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6093. foreach ( $invoiceDetail as $key => $value ) {
  6094. $invoiceHtml .= '<tr>';
  6095. if (! empty ( $value ['invoiceType'] )) {
  6096. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6097. } else {
  6098. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6099. }
  6100. if (! empty ( $value ['invoiceType'] )) {
  6101. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6102. } else {
  6103. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6104. }
  6105. $invoiceHtml .= '
  6106. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6107. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6108. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6109. </tr>
  6110. ';
  6111. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6112. if (empty ( $irList ))
  6113. $irList [0] ['sumPrice'] = 0;
  6114. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6115. $priceString = '';
  6116. if ($balance < $detail ['receivablesPrice']) {
  6117. $priceString = '收款金额超过开票金额,';
  6118. }
  6119. if ($balance > $detail ['receivablesPrice']) {
  6120. $priceString = '收款金额低于开票金额,';
  6121. }
  6122. }
  6123. $invoiceHtml .= '
  6124. <script>
  6125. $(\'a[bind-receivables^="ir"]\').click(function() {
  6126. var data = $(this).attr("data-ikey");
  6127. $("input[name=\'invoiceKey\']").val(data);
  6128. var invoiceKey=data;
  6129. if(invoiceKey==""){
  6130. alert("入账错误,请重新刷新页面");
  6131. return false;
  6132. }
  6133. if(window.confirm("' . $priceString . '确定入账吗?")){
  6134. $("#IBR").submit();
  6135. }else{
  6136. return false;
  6137. }
  6138. });
  6139. </script>
  6140. ';
  6141. $invoiceHtml .= '</tbody></table>';
  6142. }
  6143. echo json_encode ( array (
  6144. 'status' => 1,
  6145. 'irkey' => $detail ['iridEn'],
  6146. 'receivablesHtml' => $receivablesHtml,
  6147. 'isInvoice' => $isInvoice,
  6148. 'invoiceHtml' => $invoiceHtml
  6149. ) );
  6150. }
  6151. function ajaxGetInvoiceReceivablesByTitle() {
  6152. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6153. if (empty ( $title )) {
  6154. echo json_encode ( array (
  6155. 'status' => 2,
  6156. 'msg' => 'illegal request'
  6157. ) );
  6158. die ();
  6159. }
  6160. Doo::loadModel ( 'invoice' );
  6161. $invoice = new invoice ();
  6162. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  6163. $invoiceHtml = '';
  6164. if (! empty ( $invoiceDetail )) {
  6165. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6166. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6167. foreach ( $invoiceDetail as $key => $value ) {
  6168. if (! empty ( $value ['invoiceType'] )) {
  6169. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6170. } else {
  6171. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6172. }
  6173. if (! empty ( $value ['invoiceType'] )) {
  6174. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6175. } else {
  6176. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6177. }
  6178. $invoiceHtml .= '
  6179. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6180. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6181. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6182. </tr>
  6183. ';
  6184. }
  6185. $invoiceHtml .= '</tbody></table>
  6186. <script>
  6187. $(\'a[bind-receivables^="ir"]\').click(function() {
  6188. var data = $(this).attr("data-ikey");
  6189. $("input[name=\'invoiceKey\']").val(data);
  6190. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6191. if(invoiceKey==""){
  6192. alert("入账错误,请重新刷新页面");
  6193. return false;
  6194. }
  6195. if(window.confirm("确定入账吗?")){
  6196. $("#IBR").submit();
  6197. }else{
  6198. return false;
  6199. }
  6200. });
  6201. </script>
  6202. ';
  6203. }
  6204. echo json_encode ( array (
  6205. 'status' => 1,
  6206. 'invoiceHtml' => $invoiceHtml
  6207. ) );
  6208. }
  6209. function ajaxInvoicePushNotice() {
  6210. Doo::loadModel ( 'invoice' );
  6211. $invoice = new invoice ();
  6212. $approval = $invoice->getOne ( array (
  6213. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6214. 'desc' => 'iid',
  6215. 'asArray' => true
  6216. ) );
  6217. $isNotice = false;
  6218. if (! empty ( $approval ))
  6219. $isNotice = true;
  6220. $response = array (
  6221. 'error' => 0,
  6222. 'isNotice' => $isNotice
  6223. );
  6224. echo json_encode ( $response );
  6225. exit ();
  6226. }
  6227. public function ajaxCheckInvoiceNoUniqueness() {
  6228. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6229. Doo::loadModel ( 'invoice' );
  6230. $invoice = new invoice ();
  6231. if (! empty ( $invoiceNo )) {
  6232. Doo::loadModel ( 'invoicePaper' );
  6233. $invoicePaper = new invoicePaper ();
  6234. Doo::loadClass ( 'XDeode' );
  6235. $XDeode = new XDeode ( 5 );
  6236. $ipid = $XDeode->decode ( $invoiceNo );
  6237. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6238. $info = $invoice->getOne ( array (
  6239. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6240. 'asArray' => TRUE
  6241. ) );
  6242. if (! empty ( $info )) {
  6243. echo json_encode ( array (
  6244. 'error' => '发票号已存在'
  6245. ) );
  6246. die ();
  6247. } else
  6248. echo json_encode ( array (
  6249. 'ok' => '可以使用!'
  6250. ) );
  6251. die ();
  6252. }
  6253. }
  6254. function ajaxCheckInvoicePrice() {
  6255. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6256. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6257. Doo::loadModel ( 'invoice' );
  6258. $invoice = new invoice ();
  6259. Doo::loadModel ( 'invoiceReceivables' );
  6260. $invoiceReceivables = new invoiceReceivables ();
  6261. Doo::loadClass ( 'XDeode' );
  6262. $XDeode = new XDeode ( 5 );
  6263. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6264. $iidKey = $XDeode->decode ( $iidKey );
  6265. $info = $invoice->getInvoiceByIid ( $iidKey );
  6266. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6267. if (empty ( $irList ))
  6268. $irList [0] ['sumPrice'] = 0;
  6269. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6270. if ($balance < $receivablesPrice) {
  6271. echo json_encode ( array (
  6272. 'error' => '收款金额超过开票金额。'
  6273. ) );
  6274. die ();
  6275. }
  6276. if ($balance > $receivablesPrice) {
  6277. echo json_encode ( array (
  6278. 'error' => '收款金额低于开票金额。'
  6279. ) );
  6280. die ();
  6281. }
  6282. }
  6283. }
  6284. function ajaxGetInvoiceByNew(){
  6285. Doo::loadModel ( 'invoice' );
  6286. $invoice = new invoice ();
  6287. $detail=$invoice->getInvoiceByNew($this->staff [0] ['sid']);
  6288. echo json_encode ( array (
  6289. 'status' => 1,
  6290. 'detail' => $detail
  6291. ) );
  6292. }
  6293. /**
  6294. * 旧输入导入
  6295. */
  6296. function importInvoice() {
  6297. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6298. $data ['emsg'] = "";
  6299. if ($emsg != "")
  6300. $data ['emsg'] = "请填写完整的数据";
  6301. $data ['time'] = time ();
  6302. $this->render ( "/admin/invoiceImport", $data );
  6303. }
  6304. function uploadInvoice() {
  6305. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6306. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6307. $file = $_FILES ['Filedata'] ['tmp_name'];
  6308. $error = false;
  6309. if (! is_uploaded_file ( $file )) {
  6310. $error = '400 Bad Request';
  6311. }
  6312. if ($error) {
  6313. header ( 'HTTP/1.0 ' . $error );
  6314. die ( 'Error ' . $error );
  6315. } else {
  6316. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6317. $this->IoHandler = new IoHandler ();
  6318. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6319. // $filedir=$_POST['time'];
  6320. // 调用定义物理路径
  6321. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6322. $this->IoHandler->MakeDir ( $t );
  6323. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6324. if ($filename != 'xlsx')
  6325. return "";
  6326. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6327. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6328. $upload_dir = $t . "/" . $upload_file;
  6329. $k = move_uploaded_file ( $file, $upload_dir );
  6330. if ($k) {
  6331. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6332. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6333. }
  6334. }
  6335. }
  6336. }
  6337. function importInvoiceDo() {
  6338. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6339. if ($path != "") {
  6340. Doo::loadModel ( 'invoice' );
  6341. Doo::loadModel ( 'staff' );
  6342. $staff = new staff ();
  6343. Doo::loadModel ( 'invoiceStatistics' );
  6344. Doo::loadModel ( 'invoiceOperationLog' );
  6345. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6346. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6347. // print_r ( $exlArray );
  6348. // die ();
  6349. // echo json_encode($exlArray);die;
  6350. foreach ( $exlArray as $key => $value ) {
  6351. // 开票
  6352. $invoice = new invoice ();
  6353. $invoice->invoiceNo = $value ['invoiceNo'];
  6354. $invoice->invoiceType = 0;
  6355. if ($value ['invoiceType'] == '专')
  6356. $invoice->invoiceType = 1;
  6357. $invoice->invoicePrice = $value ['invoicePrice'];
  6358. $invoice->invoiceQuantity = 1;
  6359. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6360. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6361. if ($value ['invoiceType'] == '专')
  6362. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6363. $invoice->userName = $value ['userName'];
  6364. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6365. $invoice->sid = $sDetail ['sid'];
  6366. $invoice->cid = $sDetail ['cid'];
  6367. $invoice->categoryName = $sDetail ['category'];
  6368. $invoice->invoiceElement = $value ['invoiceElement'];
  6369. $invoice->remark = $value ['remark'];
  6370. $invoice->date = $value ['date'];
  6371. $invoice->printTime = $value ['date'];
  6372. $invoice->ipSource = 1;
  6373. $invoice->printStatus = 1;
  6374. $invoice->status = 2;
  6375. $invoice->postStatus = 1;
  6376. $invoice->untreadStatus = 0;
  6377. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6378. $iid = $invoice->insert ();
  6379. // 汇总
  6380. $invoiceStatistics = new invoiceStatistics ();
  6381. //
  6382. $item = array (
  6383. 'date' => $value ['date'],
  6384. 'priceClass' => 1,
  6385. 'cid' => $sDetail ['cid'],
  6386. 'staff' => $sDetail ['sid'],
  6387. 'invoicePrice' => $value ['invoicePrice']
  6388. );
  6389. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6390. $invoiceOperationLog = new invoiceOperationLog ();
  6391. $item = array (
  6392. 'date' => date ( "Y-m-d H:i:s" ),
  6393. 'operation' => date ( "Y-m-d" ) . " 导入",
  6394. 'status' => 1,
  6395. 'img' => $sDetail ['avatar'],
  6396. 'username' => $sDetail ['username'],
  6397. 'uid' => $sDetail ['sid'],
  6398. 'category' => $sDetail ['category'],
  6399. 'iid' => $iid
  6400. );
  6401. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6402. }
  6403. return '/importInvoice?count=' . count ( $exlArray );
  6404. // return "/keyonline";
  6405. }
  6406. echo 'no file';
  6407. }
  6408. function importInvoiceReceivables() {
  6409. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6410. $data ['emsg'] = "";
  6411. if ($emsg != "")
  6412. $data ['emsg'] = "请填写完整的数据";
  6413. $data ['time'] = time ();
  6414. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6415. }
  6416. // 导入入账数据
  6417. function importInvoiceReceivablesDo() {
  6418. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6419. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6420. if ($path != "") {
  6421. Doo::loadModel ( 'invoiceReceivables' );
  6422. Doo::loadModel ( 'invoice' );
  6423. Doo::loadModel ( 'staff' );
  6424. $staff = new staff ();
  6425. Doo::loadModel ( 'invoiceStatistics' );
  6426. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6427. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6428. // print_r ( $exlArray );
  6429. // die ();
  6430. // echo json_encode($exlArray);die;
  6431. foreach ( $exlArray as $key => $value ) {
  6432. // 收款
  6433. $invoiceReceivables = new invoiceReceivables ();
  6434. $invoice = new invoice ();
  6435. $invoiceReceivables->bindStatus = 1;
  6436. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  6437. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  6438. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  6439. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  6440. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  6441. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  6442. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  6443. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6444. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  6445. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  6446. $invoiceReceivables->iid = $iDetail ['iid'];
  6447. $irid = $invoiceReceivables->insert ();
  6448. // 发票绑定收款
  6449. $detail = $iDetail;
  6450. $iridString = "";
  6451. if (empty ( $detail ['irid'] ))
  6452. $iridString = $irid;
  6453. else
  6454. $iridString = $detail ['irid'] . ',' . $irid;
  6455. $item = array (
  6456. 'irid' => $iridString,
  6457. 'iid' => $detail ['iid']
  6458. );
  6459. $invoice->setInvoiceByCondition ( $item );
  6460. // 汇总
  6461. $invoiceStatistics = new invoiceStatistics ();
  6462. // 扣除入账统计金额
  6463. $item = array (
  6464. 'date' => $value ['receivablesDate'],
  6465. 'priceClass' => 3,
  6466. 'cid' => $sDetail ['cid'],
  6467. 'staff' => $sDetail ['sid'],
  6468. // 'irid' => $irid,
  6469. 'accountPrice' => $value ['receivablesPrice']
  6470. );
  6471. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6472. }
  6473. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  6474. echo 'data count ' . count ( $exlArray );
  6475. die ();
  6476. // return "/keyonline";
  6477. }
  6478. echo 'no file';
  6479. }
  6480. function formatExcelToArrayTrain($file_url = "") {
  6481. if (! file_exists ( $file_url )) {
  6482. return array ();
  6483. }
  6484. // Doo::loadClass ( 'PHPExcel' );
  6485. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6486. $PHPExcel = new PHPExcel ();
  6487. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6488. if (! $PHPReader->canRead ( $file_url )) {
  6489. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6490. if (! $PHPReader->canRead ( $file_url )) {
  6491. echo 'no Excel';
  6492. return;
  6493. }
  6494. }
  6495. $PHPExcel = $PHPReader->load ( $file_url );
  6496. /* * 读取excel文件中的第一个工作表 */
  6497. $currentSheet = $PHPExcel->getSheet ( 0 );
  6498. /* * 取得最大的列号 */
  6499. $allColumn = $currentSheet->getHighestColumn ();
  6500. /* * 取得一共有多少行 */
  6501. $allRow = $currentSheet->getHighestRow ();
  6502. $excel_array = array ();
  6503. // die($file_url);
  6504. $conk = 2;
  6505. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6506. $excel_column = array ();
  6507. // 后期改进
  6508. if ($allColumn == 'AM')
  6509. $allColumn = 'Z';
  6510. /* * 从第A列开始输出 */
  6511. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6512. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6513. if ($val instanceof PHPExcel_RichText)
  6514. $val = $val->__toString ();
  6515. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6516. // $val = "'" . addslashes ( $val ) . "'";
  6517. if ($currentColumn == 'A') {
  6518. $excel_column ['invoiceTitle'] = $val;
  6519. } elseif ($currentColumn == 'B')
  6520. $excel_column ['invoiceType'] = $val;
  6521. elseif ($currentColumn == 'C') {
  6522. $excel_column ['TIN'] = $val;
  6523. } elseif ($currentColumn == 'D') {
  6524. $excel_column ['address'] = $val;
  6525. } elseif ($currentColumn == 'E') {
  6526. $excel_column ['phone'] = $val;
  6527. } elseif ($currentColumn == 'F') {
  6528. $excel_column ['bank'] = $val;
  6529. } elseif ($currentColumn == 'G') {
  6530. $excel_column ['bankAccount'] = $val;
  6531. } elseif ($currentColumn == 'H') {
  6532. $excel_column ['invoiceElement'] = $val;
  6533. } elseif ($currentColumn == 'I') {
  6534. $excel_column ['invoiceQuantity'] = $val;
  6535. } elseif ($currentColumn == 'J') {
  6536. $excel_column ['invoiceUnitPrice'] = $val;
  6537. } elseif ($currentColumn == 'K') {
  6538. $excel_column ['remark'] = $val;
  6539. } elseif ($currentColumn == 'L') {
  6540. $excel_column ['recipientsAddress'] = $val;
  6541. } elseif ($currentColumn == 'M') {
  6542. $excel_column ['recipients'] = $val;
  6543. } elseif ($currentColumn == 'N') {
  6544. $excel_column ['recipientsPhone'] = $val;
  6545. }
  6546. }
  6547. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  6548. array_push ( $excel_array, $excel_column );
  6549. }
  6550. return $excel_array;
  6551. }
  6552. /**
  6553. * 格式化excel文件为数组
  6554. * @param unknown_type $file_url
  6555. * @param unknown_type $mcid
  6556. */
  6557. function _format_excel_to_array($file_url = "", $sType = "") {
  6558. if (! file_exists ( $file_url )) {
  6559. return array ();
  6560. }
  6561. Doo::loadClass ( 'PHPExcel' );
  6562. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  6563. $PHPExcel = new PHPExcel ();
  6564. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  6565. if (! $PHPReader->canRead ( $file_url )) {
  6566. $PHPReader = new PHPExcel_Reader_Excel5 ();
  6567. if (! $PHPReader->canRead ( $file_url )) {
  6568. echo 'no Excel';
  6569. return;
  6570. }
  6571. }
  6572. $PHPExcel = $PHPReader->load ( $file_url );
  6573. /* * 读取excel文件中的第一个工作表 */
  6574. $currentSheet = $PHPExcel->getSheet ( 0 );
  6575. /* * 取得最大的列号 */
  6576. $allColumn = $currentSheet->getHighestColumn ();
  6577. /* * 取得一共有多少行 */
  6578. $allRow = $currentSheet->getHighestRow ();
  6579. $excel_array = array ();
  6580. // die($file_url);
  6581. $conk = 2;
  6582. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  6583. $excel_column = array ();
  6584. // 后期改进
  6585. if ($allColumn == 'AM')
  6586. $allColumn = 'Z';
  6587. /* * 从第A列开始输出 */
  6588. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  6589. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  6590. if ($val instanceof PHPExcel_RichText)
  6591. $val = $val->__toString ();
  6592. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  6593. // $val = "'" . addslashes ( $val ) . "'";
  6594. if ($sType == 'invoiceReceivables') {
  6595. if ($currentColumn == 'A')
  6596. $excel_column ['invoiceNo'] = $val;
  6597. elseif ($currentColumn == 'B')
  6598. $excel_column ['receivablesPrice'] = $val;
  6599. elseif ($currentColumn == 'C') {
  6600. $excel_column ['receivablesMessage'] = $val;
  6601. } elseif ($currentColumn == 'D') {
  6602. $excel_column ['receivablesBank'] = $val;
  6603. } elseif ($currentColumn == 'E') {
  6604. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  6605. } elseif ($currentColumn == 'F') {
  6606. $excel_column ['receivablesStaff'] = $val;
  6607. } elseif ($currentColumn == 'G') {
  6608. $excel_column ['sourcePrice'] = $val;
  6609. }
  6610. } elseif ($sType == "invoiceTrain") {
  6611. if ($currentColumn == 'A') {
  6612. $excel_column ['invoiceTitle'] = $val;
  6613. } elseif ($currentColumn == 'B')
  6614. $excel_column ['invoiceType'] = $val;
  6615. elseif ($currentColumn == 'C') {
  6616. $excel_column ['TIN'] = $val;
  6617. } elseif ($currentColumn == 'D') {
  6618. $excel_column ['address'] = $val;
  6619. } elseif ($currentColumn == 'E') {
  6620. $excel_column ['phone'] = $val;
  6621. } elseif ($currentColumn == 'F') {
  6622. $excel_column ['bank'] = $val;
  6623. } elseif ($currentColumn == 'G') {
  6624. $excel_column ['bankAccount'] = $val;
  6625. } elseif ($currentColumn == 'H') {
  6626. $excel_column ['invoiceElement'] = $val;
  6627. } elseif ($currentColumn == 'I') {
  6628. $excel_column ['invoiceQuantity'] = $val;
  6629. } elseif ($currentColumn == 'J') {
  6630. $excel_column ['invoiceUnitPrice'] = $val;
  6631. } elseif ($currentColumn == 'K') {
  6632. $excel_column ['remark'] = $val;
  6633. } elseif ($currentColumn == 'L') {
  6634. $excel_column ['recipientsAddress'] = $val;
  6635. } elseif ($currentColumn == 'M') {
  6636. $excel_column ['recipients'] = $val;
  6637. } elseif ($currentColumn == 'N') {
  6638. $excel_column ['recipientsPhone'] = $val;
  6639. }
  6640. } else {
  6641. if ($currentColumn == 'A')
  6642. $excel_column ['invoiceNo'] = $val;
  6643. elseif ($currentColumn == 'B')
  6644. $excel_column ['invoiceType'] = $val;
  6645. elseif ($currentColumn == 'C') {
  6646. $excel_column ['invoicePrice'] = $val;
  6647. } elseif ($currentColumn == 'D') {
  6648. $excel_column ['invoiceTitle'] = $val;
  6649. } elseif ($currentColumn == 'E') {
  6650. $excel_column ['userName'] = $val;
  6651. } elseif ($currentColumn == 'F') {
  6652. $excel_column ['categoryName'] = $val;
  6653. } elseif ($currentColumn == 'G') {
  6654. $excel_column ['invoiceElement'] = $val;
  6655. } elseif ($currentColumn == 'H') {
  6656. $excel_column ['remark'] = $val;
  6657. } elseif ($currentColumn == 'I') {
  6658. $excel_column ['date'] = $this->excelTime ( $val );
  6659. }
  6660. }
  6661. }
  6662. array_push ( $excel_array, $excel_column );
  6663. }
  6664. return $excel_array;
  6665. }
  6666. function excelTime($date, $time = false) {
  6667. if (function_exists ( 'GregorianToJD' )) {
  6668. if (is_numeric ( $date )) {
  6669. $jd = GregorianToJD ( 1, 1, 1970 );
  6670. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  6671. $date = explode ( '/', $gregorian );
  6672. $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" : '');
  6673. return $date_str;
  6674. }
  6675. } else {
  6676. $date = $date > 25568 ? $date + 1 : 25569;
  6677. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  6678. $ofs = (70 * 365 + 17 + 2) * 86400;
  6679. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  6680. }
  6681. return $date;
  6682. }
  6683. /**
  6684. * 旧输入导入
  6685. */
  6686. function _GetFileEXT($filename) {
  6687. $pics = explode ( '.', $filename );
  6688. $num = count ( $pics );
  6689. return $pics [$num - 1];
  6690. }
  6691. function showCache($path = "", $sid = 0) {
  6692. // if (file_exists ( $path )) {
  6693. // $htm = file_get_contents ( $path );
  6694. // } else {
  6695. Doo::loadModel ( 'invoiceStatistics' );
  6696. $invoiceStatistics = new invoiceStatistics ();
  6697. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  6698. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  6699. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  6700. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  6701. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  6702. /*
  6703. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  6704. */
  6705. file_put_contents ( $path, $htm );
  6706. // }
  6707. return $htm;
  6708. }
  6709. /**
  6710. * 获取get或者POST值
  6711. *
  6712. * @param string $name 属性名称
  6713. * @return fixed 值
  6714. */
  6715. function get_args($name) {
  6716. if (isset ( $_GET [$name] )) {
  6717. if (is_array ( $_GET [$name] ))
  6718. return $_GET [$name];
  6719. else
  6720. return addslashes ( $_GET [$name] );
  6721. } elseif (isset ( $_POST [$name] )) {
  6722. if (is_array ( $_POST [$name] ))
  6723. return $_POST [$name];
  6724. else
  6725. return addslashes ( $_POST [$name] );
  6726. } else
  6727. return false;
  6728. }
  6729. function SafeFilter(&$arr) {
  6730. $ra = Array (
  6731. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  6732. '/script/',
  6733. '/javascript/',
  6734. '/vbscript/',
  6735. '/expression/',
  6736. '/applet/',
  6737. '/meta/',
  6738. '/xml/',
  6739. '/blink/',
  6740. '/link/',
  6741. '/style/',
  6742. '/embed/',
  6743. '/object/',
  6744. '/frame/',
  6745. '/layer/',
  6746. '/title/',
  6747. '/bgsound/',
  6748. '/base/',
  6749. '/onload/',
  6750. '/onunload/',
  6751. '/onchange/',
  6752. '/onsubmit/',
  6753. '/onreset/',
  6754. '/onselect/',
  6755. '/onblur/',
  6756. '/onfocus/',
  6757. '/onabort/',
  6758. '/onkeydown/',
  6759. '/onkeypress/',
  6760. '/onkeyup/',
  6761. '/onclick/',
  6762. '/ondblclick/',
  6763. '/onmousedown/',
  6764. '/onmousemove/',
  6765. '/onmouseout/',
  6766. '/onmouseover/',
  6767. '/onmouseup/',
  6768. '/onunload/'
  6769. );
  6770. if (is_array ( $arr )) {
  6771. foreach ( $arr as $key => $value ) {
  6772. if (! is_array ( $value )) {
  6773. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6774. {
  6775. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6776. }
  6777. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6778. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6779. } else {
  6780. SafeFilter ( $arr [$key] );
  6781. }
  6782. }
  6783. }
  6784. }
  6785. /**
  6786. * Escape String
  6787. *
  6788. * @access public
  6789. * @param string
  6790. * @param bool whether or not the string will be used in a LIKE condition
  6791. * @return string
  6792. */
  6793. function escape_str($str, $like = FALSE) {
  6794. if (is_array ( $str )) {
  6795. foreach ( $str as $key => $val ) {
  6796. $str [$key] = $this->escape_str ( $val, $like );
  6797. }
  6798. return $str;
  6799. }
  6800. var_dump ( Doo::db ()->getDbObject () );
  6801. die ();
  6802. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6803. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6804. } elseif (function_exists ( 'mysql_escape_string' )) {
  6805. $str = mysql_escape_string ( $str );
  6806. } else {
  6807. $str = addslashes ( $str );
  6808. }
  6809. // escape LIKE condition wildcards
  6810. if ($like === TRUE) {
  6811. $str = str_replace ( array (
  6812. '%',
  6813. '_'
  6814. ), array (
  6815. '\\%',
  6816. '\\_'
  6817. ), $str );
  6818. }
  6819. return $str;
  6820. }
  6821. /**
  6822. * 获得分页数据
  6823. * @param unknown_type $table
  6824. * @param unknown_type $condition
  6825. * @param unknown_type $on_page
  6826. * @param unknown_type $page_size
  6827. */
  6828. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6829. $page_c = "";
  6830. $page ['previous'] = $this->get_previous ( $on_page );
  6831. $page ['on_page'] = $on_page;
  6832. $total_count = $this->get_table_count ( $table, $condition );
  6833. $total = intval ( $total_count / $page_size );
  6834. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6835. $page ['total_data'] = $total_count;
  6836. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6837. $i = 1;
  6838. $page_max = 1;
  6839. $page_width = 3;
  6840. if ($on_page >= $page_width) {
  6841. $page_max = intval ( $on_page / $page_width ) + 1;
  6842. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6843. }
  6844. for(; $i <= $page ['total_page']; $i ++) {
  6845. if ($i == $on_page)
  6846. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6847. else
  6848. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6849. if ($i == ($page_width * $page_max))
  6850. break;
  6851. }
  6852. $page ['page'] = $page_c;
  6853. $page ['lower'] = (-- $on_page) * $page_size;
  6854. return $page;
  6855. }
  6856. /**
  6857. * 获取上一页
  6858. * @param unknown_type $on_page
  6859. */
  6860. function get_previous($on_page = 1) {
  6861. return $on_page != 0 ? $on_page - 1 : $on_page;
  6862. }
  6863. /**
  6864. * 获取总页数
  6865. * @param unknown_type $table
  6866. * @param unknown_type $condition
  6867. */
  6868. public function get_table_count($table = "", $condition = "") {
  6869. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6870. $sql = "select count(*) as count from " . $table . " where " . $condition;
  6871. // echo $sql;die;
  6872. $query = Doo::db ()->query ( $sql );
  6873. $result = $query->fetch ();
  6874. return $result ['count'];
  6875. }
  6876. /**
  6877. * 获得分页数据
  6878. * @param unknown_type $table
  6879. * @param unknown_type $condition
  6880. * @param unknown_type $on_page
  6881. * @param unknown_type $page_size
  6882. */
  6883. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6884. $page_c = "";
  6885. $page ['previous'] = $this->get_previous ( $on_page );
  6886. $page ['on_page'] = $on_page;
  6887. $total_count = $this->getTableCountBySql ( $sql );
  6888. $total = intval ( $total_count / $page_size );
  6889. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6890. $page ['total_data'] = $total_count;
  6891. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6892. $i = 1;
  6893. $page_max = 1;
  6894. $page_width = 3;
  6895. if ($on_page >= $page_width) {
  6896. $page_max = intval ( $on_page / $page_width ) + 1;
  6897. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6898. }
  6899. for(; $i <= $page ['total_page']; $i ++) {
  6900. if ($i == $on_page)
  6901. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6902. else
  6903. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6904. if ($i == ($page_width * $page_max))
  6905. break;
  6906. }
  6907. $page ['page'] = $page_c;
  6908. $page ['lower'] = (-- $on_page) * $page_size;
  6909. return $page;
  6910. }
  6911. /**
  6912. * 获得总页数 sql
  6913. * @param string $type
  6914. * @return boolean[]
  6915. */
  6916. public function getTableCountBySql($sql = "") {
  6917. $query = Doo::db ()->query ( $sql );
  6918. $result = $query->fetchAll ();
  6919. return count ( $result );
  6920. }
  6921. function isInvoiceNew($type = "GLOBAL") {
  6922. Doo::loadModel ( 'invoice' );
  6923. $invoice = new invoice ();
  6924. Doo::loadModel ( 'invoiceReceivables' );
  6925. $invoiceReceivables = new invoiceReceivables ();
  6926. Doo::loadModel ( 'staff' );
  6927. $staff = new staff ();
  6928. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  6929. // 我的发票待处理
  6930. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  6931. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  6932. 'desc' => 'iid',
  6933. 'asArray' => TRUE
  6934. ) );
  6935. // 我的收款待入账
  6936. /*
  6937. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  6938. */
  6939. // 发票审批
  6940. $approval = $invoice->getOne ( array (
  6941. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  6942. 'desc' => 'iid',
  6943. 'asArray' => true
  6944. ) );
  6945. // 发票邮寄
  6946. $post = $invoice->getOne ( array (
  6947. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  6948. 'asArray' => TRUE
  6949. ) );
  6950. // 发票打印
  6951. $print = $invoice->getOne ( array (
  6952. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  6953. 'desc' => 'iid',
  6954. 'asArray' => TRUE
  6955. ) );
  6956. // 发票退票 printStatus=1 and
  6957. $untread = $invoice->getOne ( array (
  6958. 'where' => " untreadStatus=1 and status=2 ",
  6959. 'asArray' => TRUE
  6960. ) );
  6961. $new = array (
  6962. 'GLOBAL' => FALSE,
  6963. 'pendingInvoice' => FALSE,
  6964. // 'myClaim' => FALSE,
  6965. 'approval' => FALSE,
  6966. 'post' => FALSE,
  6967. 'print' => FALSE,
  6968. 'untread' => FALSE
  6969. );
  6970. // || ! empty ( $myClaim )
  6971. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  6972. $new ['GLOBAL'] = TRUE;
  6973. if (! empty ( $pendingInvoice ))
  6974. $new ['pendingInvoice'] = TRUE;
  6975. // if (! empty ( $myClaim ))
  6976. // $new ['myClaim'] = TRUE;
  6977. if (! empty ( $approval ))
  6978. $new ['approval'] = TRUE;
  6979. if (! empty ( $post ))
  6980. $new ['post'] = TRUE;
  6981. if (! empty ( $print ))
  6982. $new ['print'] = TRUE;
  6983. if (! empty ( $untread ))
  6984. $new ['untread'] = TRUE;
  6985. return $new;
  6986. }
  6987. function setWXMsg($rid, $typeMsg = '') {
  6988. Doo::loadModel ( 'invoice' );
  6989. $invoice = new invoice ();
  6990. $invoiceDetail = $invoice->getOne ( array (
  6991. 'where' => 'iid=' . $rid,
  6992. 'asArray' => true
  6993. ) );
  6994. if (! empty ( $invoiceDetail )) {
  6995. Doo::loadModel ( 'staff' );
  6996. $staff = new staff ();
  6997. $staffmsg = $staff->getOne ( array (
  6998. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  6999. 'asArray' => TRUE
  7000. ) );
  7001. if (! empty ( $staffmsg ['wxid'] )) {
  7002. require_once (SITE_PATH . '/protected/class/client.php');
  7003. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7004. $user = $staffmsg ['wxid'];
  7005. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7006. if (empty ( $expCom ))
  7007. $expCom [0] = '';
  7008. $msg = "";
  7009. if (empty ( $typeMsg ))
  7010. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7011. elseif ($typeMsg == "PRINT")
  7012. $msg = '太好了,您的发票已打印完成。';
  7013. $result = $client->SendMsg ( $user, $msg, 'text' );
  7014. }
  7015. }
  7016. }
  7017. /**
  7018. * 获取微信部门
  7019. * @param string $category
  7020. * @return number|mixed
  7021. */
  7022. function getToparty($category = '') {
  7023. $token = $this->getAccessToken (); //
  7024. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7025. $toparty = 0;
  7026. foreach ( $result ['department'] as $key => $value ) {
  7027. if ($value ['name'] == $category)
  7028. $toparty = $value ['id'];
  7029. }
  7030. return $toparty;
  7031. }
  7032. /**
  7033. * 获得某部门下的用户
  7034. * @param string $toparty
  7035. */
  7036. function getUserByToparty($toparty = '') {
  7037. $token = $this->getAccessToken (); //
  7038. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7039. $userList = array ();
  7040. foreach ( $result ['userlist'] as $key => $value ) {
  7041. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7042. }
  7043. return $userList;
  7044. }
  7045. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7046. $token = $this->getAccessToken ();
  7047. if ($text == 'text') {
  7048. $data = '{
  7049. "touser": "' . $toparty . '",
  7050. "toparty": "",
  7051. "totag": "",
  7052. "msgtype": "text",
  7053. "agentid": 1000002,
  7054. "text": {
  7055. "content": "' . $msg . '"
  7056. },
  7057. "safe":0
  7058. }';
  7059. }
  7060. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7061. if ($result->errmsg != 'ok') {
  7062. return 0;
  7063. } else {
  7064. return 1;
  7065. }
  7066. }
  7067. /**
  7068. * 获得可以发送微信用户列表
  7069. * @param string $category
  7070. * @return string
  7071. */
  7072. function getWxidByCategory($category = "") {
  7073. if (empty ( $category ))
  7074. return "";
  7075. Doo::loadModel ( 'staff' );
  7076. $staff = new staff ();
  7077. $toparty = $this->getToparty ( $category );
  7078. $wxList = array ();
  7079. $wxString = "";
  7080. if (! empty ( $toparty )) {
  7081. $userList = $this->getUserByToparty ( $toparty );
  7082. $userCon = implode ( ',', $userList );
  7083. // echo $userCon;
  7084. $sidList = $staff->getStaffByWxid ( $userCon );
  7085. foreach ( $sidList as $key => $value ) {
  7086. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7087. if ($falg) {
  7088. array_push ( $wxList, $value ['wxid'] );
  7089. }
  7090. }
  7091. $wxString = implode ( '|', $wxList );
  7092. }
  7093. return $wxString;
  7094. }
  7095. /**
  7096. * 读取发送信息规则判断是否需要发送
  7097. * @param number $sid
  7098. * @param string $sendType
  7099. * @return boolean
  7100. */
  7101. function isSendNotification($sid = 0, $sendType = '') {
  7102. Doo::loadModel ( "notificationConf" );
  7103. $notificationConf = new notificationConf ();
  7104. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7105. $conf = array ();
  7106. $sendFlag = true;
  7107. if (! empty ( $detail )) {
  7108. $conf = json_decode ( $detail ['conf'], true );
  7109. if (! empty ( $sendType )) {
  7110. if (isset ( $conf [$sendType] )) {
  7111. if ($conf [$sendType] == "CLOSE")
  7112. $sendFlag = false;
  7113. elseif ($conf [$sendType] == "Weekend") {
  7114. $day = date ( "w" );
  7115. if (1 <= $day && 5 >= $day)
  7116. $sendFlag = false;
  7117. } elseif ($conf [$sendType] == "OneToFriday") {
  7118. $day = date ( "w" );
  7119. if (0 == $day || 6 == $day)
  7120. $sendFlag = false;
  7121. }
  7122. }
  7123. } else
  7124. $sendFlag = false;
  7125. }
  7126. return $sendFlag;
  7127. }
  7128. /**
  7129. * 根据规则发送信息
  7130. * @param unknown $msg
  7131. * @param unknown $title
  7132. * @param unknown $url
  7133. * @param unknown $user
  7134. * @param string $text
  7135. * @return number
  7136. */
  7137. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7138. $token = $this->getAccessToken ();
  7139. $falg = $this->isSendNotification ( $sid, $sendType );
  7140. // if ($text == 'text') {
  7141. // $data = '{
  7142. // "touser": "' . $user . '",
  7143. // "toparty": "",
  7144. // "totag": "",
  7145. // "msgtype": "text",
  7146. // "agentid": 1000002,
  7147. // "text": {
  7148. // "content": "' . $msg . '"
  7149. // },
  7150. // "safe":0
  7151. // }';
  7152. // } else {
  7153. $data = '{
  7154. "touser": "' . $user . '",
  7155. "toparty": "",
  7156. "totag": "",
  7157. "msgtype": "news",
  7158. "agentid": 1000002,
  7159. "news": {
  7160. "articles":[
  7161. {
  7162. "title": "' . $title . '",
  7163. "description": "' . $msg . '",
  7164. "url": "' . $url . '",
  7165. "picurl": ""
  7166. }
  7167. ]
  7168. }
  7169. }';
  7170. // }
  7171. if ($falg) {
  7172. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7173. if ($result->errmsg != 'ok') {
  7174. return 0;
  7175. } else {
  7176. return 1;
  7177. }
  7178. } else
  7179. return 0;
  7180. }
  7181. private function getAccessToken() {
  7182. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7183. // $file = './access_token.txt';
  7184. // $data = json_decode ( file_get_contents ( $file ) );
  7185. // if ($data->expire_time < time () or ! $data->expire_time) {
  7186. // 如果是企业号用以下URL获取access_token
  7187. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7188. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7189. $res = json_decode ( $this->httpGet ( $url ) );
  7190. $access_token = $res->access_token;
  7191. // echo $access_token;
  7192. // if ($access_token) {
  7193. // $data->expire_time = time () + 7000;
  7194. // $data->access_token = $access_token;
  7195. // $fp = fopen ( $file, "w" );
  7196. // fwrite ( $fp, json_encode ( $data ) );
  7197. // fclose ( $fp );
  7198. // }
  7199. // } else {
  7200. // $access_token = $data->access_token;
  7201. // }
  7202. return $access_token;
  7203. }
  7204. private function httpGet($url) {
  7205. $curl = curl_init ();
  7206. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7207. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7208. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7209. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7210. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7211. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7212. curl_setopt ( $curl, CURLOPT_URL, $url );
  7213. $res = curl_exec ( $curl );
  7214. curl_close ( $curl );
  7215. return $res;
  7216. }
  7217. private function httpPost($url, $data) {
  7218. $curl = curl_init ();
  7219. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7220. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7221. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7222. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7223. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7224. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7225. curl_setopt ( $curl, CURLOPT_URL, $url );
  7226. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7227. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7228. $res = curl_exec ( $curl );
  7229. curl_close ( $curl );
  7230. return $res;
  7231. }
  7232. }
  7233. ?>