InvoiceController.php 213 KB

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