InvoiceController.php 227 KB

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