InvoiceController.php 177 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704
  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. /*
  90. * $pendingApprovalsSid = 41; Doo::loadModel ( 'staff' ); $staff = new staff (); $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) ); // 发送微信审批通知 $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。'; $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  91. */
  92. Doo::loadModel ( 'staff' );
  93. $staff = new staff ();
  94. $toparty = $this->getToparty ( '广东办' );
  95. $wxList = array ();
  96. if (! empty ( $toparty )) {
  97. $userList = $this->getUserByToparty ( $toparty );
  98. $userCon = implode ( ',', $userList );
  99. // echo $userCon;
  100. $sidList = $staff->getStaffByWxid ( $userCon );
  101. foreach ( $sidList as $key => $value ) {
  102. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  103. if ($falg) {
  104. array_push ( $wxList, $value ['wxid'] );
  105. }
  106. }
  107. $wxString = implode ( '|', $wxList );
  108. print_r ( $wxList );
  109. echo $wxString;
  110. }
  111. // 测试发送
  112. /*
  113. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  114. */
  115. // print_r ( $userList );
  116. // $msTouser='caipin|outaozhen';
  117. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  118. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  119. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  120. // $toparty= $this->getToparty('广东办');
  121. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  122. // $toparty = 26;
  123. // $msg = '';
  124. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  125. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  126. }
  127. function invoice() {
  128. Doo::loadModel ( 'invoice' );
  129. $invoice = new invoice ();
  130. Doo::loadModel ( 'express' );
  131. $express = new express ();
  132. $expressList = $express->getExpressByAll ();
  133. $this->data ['expressList'] = $expressList;
  134. // Doo::loadModel ( 'invoiceReceivables' );
  135. // $invoiceReceivables = new invoiceReceivables ();
  136. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  137. Doo::loadModel ( 'invoiceStatistics' );
  138. $invoiceStatistics = new invoiceStatistics ();
  139. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  140. $year = date ( "Y" );
  141. $tmp_date = date ( "Ym" );
  142. $tmp_year = substr ( $tmp_date, 0, 4 );
  143. $tmp_mon = substr ( $tmp_date, 4, 2 );
  144. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  145. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  146. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  147. $htm = $this->showCache ( $path );
  148. Doo::loadClass ( 'XDeode' );
  149. $XDeode = new XDeode ( 5 );
  150. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  151. $invoiceList = $invoice->getMyInvoice ( $sid );
  152. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  153. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  154. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  155. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  156. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  157. // print_r($myInvoiceUnAccount);
  158. $this->data ['isMonth'] = $isMonth;
  159. $this->data ['htm'] = $htm;
  160. $this->data ['invoiceList'] = $invoiceList;
  161. $this->data ['receivablesList'] = $list;
  162. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  163. $this->data ['memu'] = "invoice";
  164. $this->data ['staff'] = $this->staff;
  165. $this->data ['receiptMemu'] = 'invoice';
  166. $this->render ( "/admin/invoice", $this->data );
  167. }
  168. function invoiceAdd() {
  169. Doo::loadModel ( 'L_category' );
  170. $lCategory = new L_category ();
  171. $category = $lCategory->find ( array (
  172. 'asArray' => true
  173. ) );
  174. $this->data ['category'] = $category;
  175. $this->data ['memu'] = "invoice";
  176. $this->data ['staff'] = $this->staff;
  177. $this->data ['receiptMemu'] = 'invoice';
  178. $this->render ( "/admin/invoiceAdd", $this->data );
  179. }
  180. /**
  181. * 提交一份开票申请,并记录下操作日志
  182. *
  183. * @since 1.0.0
  184. * @var integer cid 办事处ID
  185. * @var integer invoiceType 发票类型
  186. * @var integer doPost 是否邮寄
  187. * @var integer invoicePrice 开票金额
  188. * @var string invoiceElement 开票内容
  189. * @var string invoiceTitle 发票抬头
  190. * @var string invoiceCompany 单位名称
  191. * @var string TIN 纳税人识别码
  192. * @var string address 注册地址
  193. * @var string phone 注册电话
  194. * @var string bank 开户银行
  195. * @var string bankAccount 银行账户
  196. * @var string recipients 收件人
  197. * @var string recipientsPhone 收件人手机/电话
  198. * @var string recipientsAddress 收件地址
  199. * @var string mailItems 邮寄物品
  200. * @var string remark 备注
  201. * @return string 返回跳转开票主页路径
  202. */
  203. function invoiceAddDo() {
  204. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  205. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  206. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  207. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  208. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  209. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  210. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  211. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  212. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  213. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  214. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  215. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  216. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  217. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  218. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  219. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  220. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  221. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  222. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  223. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  224. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  225. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  226. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  227. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  228. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  229. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  230. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  231. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  232. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  233. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  234. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  235. /*
  236. * $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;
  237. */
  238. if (empty ( $this->staff [0] ))
  239. die ( 'illegal request' );
  240. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  241. Doo::loadModel ( 'invoice' );
  242. $invoice = new invoice ();
  243. Doo::loadModel ( 'L_category' );
  244. $lCategory = new L_category ();
  245. Doo::loadModel ( 'invoiceManage' );
  246. $invoiceManage = new invoiceManage ();
  247. Doo::loadModel ( 'invoiceOperationLog' );
  248. $invoiceOperationLog = new invoiceOperationLog ();
  249. $categoryDetil = $lCategory->getOne ( array (
  250. 'SELECT' => 'title',
  251. 'where' => 'cid=' . $cid,
  252. 'asArray' => true
  253. ) );
  254. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  255. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  256. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  257. // print_r(current($invoiceManageDetail ['staffList']));
  258. // die;
  259. $moldManage = array ();
  260. foreach ( $invoiceManageList as $key => $value ) {
  261. if ($value ['mold'] == '发票打印')
  262. $moldManage [$value ['mold']] = $value ['staffList'];
  263. elseif ($value ['mold'] == '发票邮寄')
  264. $moldManage [$value ['mold']] = $value ['staffList'];
  265. elseif ($value ['mold'] == '发票退票')
  266. $moldManage [$value ['mold']] = $value ['staffList'];
  267. }
  268. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  269. $item = array (
  270. 'cid' => $cid,
  271. 'categoryName' => $categoryDetil ['title'],
  272. 'invoiceElement' => $invoiceElement,
  273. 'invoiceQuantity' => $invoiceQuantity,
  274. 'invoiceUnitPrice' => $invoiceUnitPrice,
  275. 'invoicePrice' => $invoicePrice,
  276. 'invoiceType' => $invoiceType,
  277. 'doPost' => $doPost,
  278. 'status' => 1,
  279. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  280. 'date' => date ( "Y-m-d H:i:s" ),
  281. 'updateTime' => date ( "Y-m-d H:i:s" ),
  282. 'sid' => $this->staff [0] ['sid'],
  283. 'userName' => $this->staff [0] ['username'],
  284. 'invoiceManage' => $invoiceManageDetail ['staff'],
  285. 'pendingApprovals' => $pendingApprovalsSid,
  286. 'moldManage' => json_encode ( $moldManage ),
  287. 'remark' => $remark
  288. );
  289. if ($invoiceType == 0)
  290. $item += array (
  291. 'invoiceTitle' => $invoiceTitle,
  292. 'TIN' => $TINT,
  293. 'address' => $addressT,
  294. 'phone' => $phoneT,
  295. 'bank' => $bankT,
  296. 'bankAccount' => $bankAccountT
  297. );
  298. else {
  299. $item += array (
  300. 'invoiceCompany' => $invoiceCompany,
  301. 'TIN' => $TIN,
  302. 'address' => $address,
  303. 'phone' => $phone,
  304. 'bank' => $bank,
  305. 'bankAccount' => $bankAccount
  306. );
  307. }
  308. if ($doPost == 1) {
  309. $mailList = array (
  310. 'invoice' => 1,
  311. 'mailItems' => $mailItems
  312. );
  313. if (! empty ( $softLock ))
  314. $mailList += array (
  315. 'softLock' => $softLockNum
  316. );
  317. else
  318. $mailList += array (
  319. 'softLock' => 0
  320. );
  321. if (! empty ( $contract ))
  322. $mailList += array (
  323. 'contract' => $contractNum
  324. );
  325. else
  326. $mailList += array (
  327. 'contract' => 0
  328. );
  329. if (! empty ( $instructions ))
  330. $mailList += array (
  331. 'instructions' => $instructionsNum
  332. );
  333. else
  334. $mailList += array (
  335. 'instructions' => 0
  336. );
  337. if (! empty ( $remittance ))
  338. $mailList += array (
  339. 'remittance' => $remittance
  340. );
  341. else
  342. $mailList += array (
  343. 'remittance' => ''
  344. );
  345. $mailString = '发票x1,备注:' . $mailItems;
  346. if (! empty ( $softLock ))
  347. $mailString .= ',软件锁x' . $softLockNum;
  348. if (! empty ( $contract ))
  349. $mailString .= ',合同x' . $contractNum;
  350. if (! empty ( $instructions ))
  351. $mailString .= ',说明书x' . $instructionsNum;
  352. if (! empty ( $remittance ))
  353. $mailString .= ',汇款账号单';
  354. $item += array (
  355. 'recipients' => $recipients,
  356. 'recipientsPhone' => $recipientsPhone,
  357. 'recipientsAddress' => $recipientsAddress,
  358. 'mailItems' => $mailString,
  359. 'mailItemsJson' => json_encode ( $mailList )
  360. );
  361. }
  362. $iid = $invoice->addInvoice ( $item );
  363. $item = array (
  364. 'date' => date ( "Y-m-d H:i:s" ),
  365. 'operation' => "创建",
  366. 'status' => 1,
  367. 'img' => $this->staff [0] ['avatar'],
  368. 'username' => $this->staff [0] ['username'],
  369. 'uid' => $this->staff [0] ['sid'],
  370. 'category' => $this->staff [0] ['category'],
  371. 'iid' => $iid
  372. );
  373. $invoiceOperationLog->setInvoiceOperationLog ( $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. Doo::loadModel ( 'staff' );
  386. $staff = new staff ();
  387. $username2 = $staff->getOne ( array (
  388. 'select' => 'wxid',
  389. 'where' => 'sid=' . $pendingApprovalsSid,
  390. 'asArray' => TRUE
  391. ) );
  392. // 发送微信审批通知
  393. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  394. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  395. }
  396. return "/invoice";
  397. }
  398. function invoiceEdit() {
  399. Doo::loadClass ( 'XDeode' );
  400. $XDeode = new XDeode ( 5 );
  401. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  402. $iid = $XDeode->decode ( $iid );
  403. if (! is_numeric ( $iid ))
  404. die ( 'illegal request' );
  405. Doo::loadModel ( 'invoice' );
  406. $invoice = new invoice ();
  407. Doo::loadModel ( 'invoiceOperationLog' );
  408. $invoiceOperationLog = new invoiceOperationLog ();
  409. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  410. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  411. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  412. $this->data ['operation'] = $operation;
  413. $this->data ['invoiceDetail'] = $invoiceDetail;
  414. $this->data ['memu'] = "invoice";
  415. $this->data ['staff'] = $this->staff;
  416. $this->data ['receiptMemu'] = 'invoice';
  417. $this->render ( "/admin/invoiceEdit", $this->data );
  418. }
  419. /**
  420. * 重新编辑退回的发票
  421. * @return string
  422. */
  423. function invoiceEditDo() {
  424. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  425. Doo::loadModel ( 'invoice' );
  426. $invoice = new invoice ();
  427. $iid = $invoice->authcode ( $iidKey );
  428. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  429. die ( 'illegal request' );
  430. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  431. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  432. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  433. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  434. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  435. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  436. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  437. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  438. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  439. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  440. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  441. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  442. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  443. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  444. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  445. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  446. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  447. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  448. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  449. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  450. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  451. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  452. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  453. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  454. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  455. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  456. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  457. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  458. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  459. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  460. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  461. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  462. Doo::loadModel ( 'invoiceManage' );
  463. $invoiceManage = new invoiceManage ();
  464. Doo::loadModel ( 'invoiceOperationLog' );
  465. $invoiceOperationLog = new invoiceOperationLog ();
  466. $cid = explode ( ':', $cid );
  467. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  468. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  469. $moldManage = array ();
  470. foreach ( $invoiceManageList as $key => $value ) {
  471. if ($value ['mold'] == '发票打印')
  472. $moldManage [$value ['mold']] = $value ['staffList'];
  473. elseif ($value ['mold'] == '发票邮寄')
  474. $moldManage [$value ['mold']] = $value ['staffList'];
  475. elseif ($value ['mold'] == '发票打印')
  476. $moldManage [$value ['mold']] = $value ['staffList'];
  477. }
  478. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  479. $item = array (
  480. 'iid' => $iid,
  481. 'cid' => $cid [0],
  482. 'categoryName' => $cid [1],
  483. 'invoiceElement' => $invoiceElement,
  484. 'invoiceQuantity' => $invoiceQuantity,
  485. 'invoiceUnitPrice' => $invoiceUnitPrice,
  486. 'invoicePrice' => $invoicePrice,
  487. 'invoiceType' => $invoiceType,
  488. 'doPost' => $doPost,
  489. 'status' => 1,
  490. 'updateTime' => date ( "Y-m-d H:i:s" ),
  491. 'remark' => $remark
  492. );
  493. if ($invoiceType == 0)
  494. $item += array (
  495. 'invoiceTitle' => $invoiceTitle,
  496. 'TIN' => $TINT,
  497. 'address' => $addressT,
  498. 'phone' => $phoneT,
  499. 'bank' => $bankT,
  500. 'bankAccount' => $bankAccountT
  501. );
  502. else {
  503. $item += array (
  504. 'invoiceCompany' => $invoiceCompany,
  505. 'TIN' => $TIN,
  506. 'address' => $address,
  507. 'phone' => $phone,
  508. 'bank' => $bank,
  509. 'bankAccount' => $bankAccount
  510. );
  511. }
  512. if ($doPost == 1) {
  513. $mailList = array (
  514. 'invoice' => 1,
  515. 'mailItems' => $mailItems
  516. );
  517. if (! empty ( $softLock ))
  518. $mailList += array (
  519. 'softLock' => $softLockNum
  520. );
  521. else
  522. $mailList += array (
  523. 'softLock' => '0'
  524. );
  525. if (! empty ( $contract ))
  526. $mailList += array (
  527. 'contract' => $contractNum
  528. );
  529. else
  530. $mailList += array (
  531. 'contract' => '0'
  532. );
  533. if (! empty ( $instructions ))
  534. $mailList += array (
  535. 'instructions' => $instructionsNum
  536. );
  537. else
  538. $mailList += array (
  539. 'instructions' => '0'
  540. );
  541. if (! empty ( $remittance ))
  542. $mailList += array (
  543. 'remittance' => $remittance
  544. );
  545. else
  546. $mailList += array (
  547. 'remittance' => ''
  548. );
  549. $mailString = '发票x1,备注:' . $mailItems;
  550. if (! empty ( $softLock ))
  551. $mailString .= ',软件锁x' . $softLockNum;
  552. if (! empty ( $contract ))
  553. $mailString .= ',合同x' . $contractNum;
  554. if (! empty ( $instructions ))
  555. $mailString .= ',说明书x' . $instructionsNum;
  556. if (! empty ( $remittance ))
  557. $mailString .= ',汇款账号单';
  558. $item += array (
  559. 'recipients' => $recipients,
  560. 'recipientsPhone' => $recipientsPhone,
  561. 'recipientsAddress' => $recipientsAddress,
  562. 'mailItems' => $mailString,
  563. 'mailItemsJson' => json_encode ( $mailList )
  564. );
  565. }
  566. $invoice->setInvoiceByCondition ( $item );
  567. $item = array (
  568. 'date' => date ( "Y-m-d H:i:s" ),
  569. 'operation' => "重新提交审批",
  570. 'status' => 1,
  571. 'img' => $this->staff [0] ['avatar'],
  572. 'username' => $this->staff [0] ['username'],
  573. 'uid' => $this->staff [0] ['sid'],
  574. 'category' => $this->staff [0] ['category'],
  575. 'iid' => $iid
  576. );
  577. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  578. }
  579. return "/invoice";
  580. }
  581. /**
  582. * 培训班
  583. */
  584. function invoiceTraining() {
  585. Doo::loadModel ( 'L_category' );
  586. $lCategory = new L_category ();
  587. Doo::loadModel ( 'invoiceTraining' );
  588. $invoiceTraining = new invoiceTraining ();
  589. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ();
  590. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2 );
  591. $category = $lCategory->getCategory ();
  592. // print_r($itList);
  593. $this->data ['itTodoList'] = $itTodoList;
  594. $this->data ['itedList'] = $itedList;
  595. $this->data ['category'] = $category;
  596. $this->data ['memu'] = "invoice";
  597. $this->data ['staff'] = $this->staff;
  598. $this->data ['receiptMemu'] = 'invoiceTraining';
  599. $this->render ( "/admin/invoiceTraining", $this->data );
  600. }
  601. /**
  602. * 创建培训班
  603. */
  604. function invoiceTrainingAdd() {
  605. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  606. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  607. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  608. if (empty ( $this->staff [0] ))
  609. die ( 'illegal request' );
  610. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  611. Doo::loadModel ( 'invoiceTraining' );
  612. $invoiceTraining = new invoiceTraining ();
  613. Doo::loadModel ( 'invoice' );
  614. $invoice = new invoice ();
  615. Doo::loadModel ( 'L_category' );
  616. $lCategory = new L_category ();
  617. Doo::loadModel ( 'invoiceManage' );
  618. $invoiceManage = new invoiceManage ();
  619. Doo::loadModel ( 'invoiceOperationLog' );
  620. $invoiceOperationLog = new invoiceOperationLog ();
  621. $item = array (
  622. 'cid' => $cid,
  623. 'trainName' => $trainName,
  624. 'trainDate' => $trainDate,
  625. 'creator' => $this->staff [0] ['sid'],
  626. 'creatorDate' => date ( "Y-m-d H:i:s" )
  627. );
  628. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  629. // 统计相关
  630. // $item = array (
  631. // 'date' => date ( "Y-m-d H:i:s" ),
  632. // 'operation' => "创建",
  633. // 'status' => 1,
  634. // 'img' => $this->staff [0] ['avatar'],
  635. // 'username' => $this->staff [0] ['username'],
  636. // 'uid' => $this->staff [0] ['sid'],
  637. // 'category' => $this->staff [0] ['category'],
  638. // 'iid' => $iid
  639. // );
  640. // $invoiceOperationLog->setInvoiceOperationLog ( $item );
  641. // $item = array (
  642. // 'date' => date ( "Y-m-d H:i:s" ),
  643. // 'operation' => "提交审批",
  644. // 'status' => 1,
  645. // 'img' => $this->staff [0] ['avatar'],
  646. // 'username' => $this->staff [0] ['username'],
  647. // 'uid' => $this->staff [0] ['sid'],
  648. // 'category' => $this->staff [0] ['category'],
  649. // 'iid' => $iid
  650. // );
  651. // $invoiceOperationLog->setInvoiceOperationLog ( $item );
  652. }
  653. return "/invoiceTraining";
  654. }
  655. /**
  656. * 删除培训班
  657. */
  658. function invoiceTrainingDelDo(){
  659. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  660. if (!empty($itid)){
  661. Doo::loadModel ( 'invoiceTraining' );
  662. $invoiceTraining = new invoiceTraining ();
  663. }
  664. return "/invoiceTraining";
  665. }
  666. /**
  667. * 终止开票
  668. */
  669. function invoiceDroppedDo() {
  670. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  671. Doo::loadModel ( 'invoice' );
  672. $invoice = new invoice ();
  673. Doo::loadModel ( 'invoiceOperationLog' );
  674. $invoiceOperationLog = new invoiceOperationLog ();
  675. $iid = $invoice->authcode ( $droppedIidKey );
  676. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  677. die ( 'illegal request' );
  678. $item = array (
  679. 'iid' => $iid,
  680. 'status' => 4,
  681. 'updateTime' => date ( "Y-m-d H:i:s" )
  682. );
  683. $invoice->setInvoiceByCondition ( $item );
  684. $item = array (
  685. 'date' => date ( "Y-m-d H:i:s" ),
  686. 'operation' => '终止了开票',
  687. 'status' => 4,
  688. 'img' => $this->staff [0] ['avatar'],
  689. 'username' => $this->staff [0] ['username'],
  690. 'uid' => $this->staff [0] ['sid'],
  691. 'category' => $this->staff [0] ['category'],
  692. 'iid' => $iid
  693. );
  694. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  695. return "/invoice";
  696. }
  697. /**
  698. * 更新退票的邮寄信息
  699. */
  700. function invoiceUntreadMailDo() {
  701. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  702. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  703. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  704. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  705. Doo::loadModel ( 'invoice' );
  706. $invoice = new invoice ();
  707. $iid = $invoice->authcode ( $untreadIidKey );
  708. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  709. die ( 'illegal request' );
  710. $item = array (
  711. 'iid' => $iid,
  712. 'untreadCompany' => $untreadCompany,
  713. 'untreadNumber' => $untreadNumber,
  714. 'untreadItems' => $untreadItems
  715. );
  716. $invoice->setInvoiceByCondition ( $item );
  717. return "/invoice";
  718. }
  719. /**
  720. * 申请退票 --
  721. */
  722. function invoiceUntreadDo() {
  723. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  724. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  725. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  726. Doo::loadModel ( 'invoice' );
  727. $invoice = new invoice ();
  728. Doo::loadModel ( 'invoiceOperationLog' );
  729. $invoiceOperationLog = new invoiceOperationLog ();
  730. Doo::loadModel ( 'invoiceReceivables' );
  731. $invoiceReceivables = new invoiceReceivables ();
  732. $iid = $invoice->authcode ( $untreadIidKey );
  733. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  734. die ( 'illegal request' );
  735. /*
  736. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  737. */
  738. $item = array (
  739. 'iid' => $iid,
  740. 'untreadStatus' => 1,
  741. 'untreadReason' => $untreadReason,
  742. 'untreadPost' => $untreadPost,
  743. 'updateTime' => date ( "Y-m-d H:i:s" )
  744. );
  745. $invoice->setInvoiceByCondition ( $item );
  746. $item = array (
  747. 'date' => date ( "Y-m-d H:i:s" ),
  748. 'operation' => '申请退票',
  749. 'status' => 7,
  750. 'img' => $this->staff [0] ['avatar'],
  751. 'username' => $this->staff [0] ['username'],
  752. 'uid' => $this->staff [0] ['sid'],
  753. 'category' => $this->staff [0] ['category'],
  754. 'iid' => $iid
  755. );
  756. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  757. return "/invoice";
  758. }
  759. /**
  760. * 删除已终止的开票
  761. */
  762. function invoiceDelDo() {
  763. Doo::loadClass ( 'XDeode' );
  764. $XDeode = new XDeode ( 5 );
  765. Doo::loadModel ( 'invoice' );
  766. $invoice = new invoice ();
  767. Doo::loadModel ( 'invoiceOperationLog' );
  768. $invoiceOperationLog = new invoiceOperationLog ();
  769. Doo::loadClass ( 'XDeode' );
  770. $XDeode = new XDeode ( 5 );
  771. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  772. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  773. $iid = $XDeode->decode ( $iid );
  774. if (! is_numeric ( $iid ))
  775. die ( 'illegal request' );
  776. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  777. if (empty ( $invoiceDetail ))
  778. die ( 'illegal request' );
  779. $item = array (
  780. 'iid' => $iid,
  781. 'isDelete' => 1,
  782. 'updateTime' => date ( "Y-m-d H:i:s" )
  783. );
  784. $invoice->setInvoiceByCondition ( $item );
  785. $item = array (
  786. 'date' => date ( "Y-m-d H:i:s" ),
  787. 'operation' => '删除了已终止的发票',
  788. 'status' => 4,
  789. 'img' => $this->staff [0] ['avatar'],
  790. 'username' => $this->staff [0] ['username'],
  791. 'uid' => $this->staff [0] ['sid'],
  792. 'category' => $this->staff [0] ['category'],
  793. 'iid' => $iid
  794. );
  795. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  796. return "/invoice";
  797. }
  798. function invoiceApproval() {
  799. Doo::loadModel ( 'invoice' );
  800. $invoice = new invoice ();
  801. Doo::loadClass ( 'XDeode' );
  802. $XDeode = new XDeode ( 5 );
  803. Doo::loadModel ( 'staff' );
  804. $staff = new staff ();
  805. $invoiceList = $invoice->find ( array (
  806. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  807. 'desc' => 'iid',
  808. 'asArray' => true
  809. ) );
  810. foreach ( $invoiceList as $key => $value ) {
  811. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  812. $lastApprover = json_decode ( $value ['processApprovals'], true );
  813. if (! empty ( $lastApprover )) {
  814. $lastApproverKey = array_keys ( $lastApprover );
  815. $lastApprover = end ( $lastApprover );
  816. $staffDetail = $staff->getOne ( array (
  817. 'where' => 'sid=' . end ( $lastApproverKey ),
  818. 'asArray' => true
  819. ) );
  820. $lastApprover ['username'] = $staffDetail ['username'];
  821. }
  822. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  823. }
  824. $ilist = $invoice->getInvoiceByProcessStatus ();
  825. // print_r($ilist);
  826. $this->data ['invoiceList'] = $invoiceList;
  827. $this->data ['ilist'] = $ilist;
  828. $this->data ['memu'] = "invoice";
  829. $this->data ['staff'] = $this->staff;
  830. $this->data ['receiptMemu'] = 'invoiceApproval';
  831. $this->render ( "/admin/invoiceApproval", $this->data );
  832. }
  833. function invoiceDetail() {
  834. Doo::loadClass ( 'XDeode' );
  835. $XDeode = new XDeode ( 5 );
  836. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  837. $iid = $XDeode->decode ( $iid );
  838. if (! is_numeric ( $iid ))
  839. die ( 'illegal request' );
  840. Doo::loadModel ( 'invoice' );
  841. $invoice = new invoice ();
  842. Doo::loadModel ( 'invoiceOperationLog' );
  843. $invoiceOperationLog = new invoiceOperationLog ();
  844. $invoiceDetail = $invoice->getOne ( array (
  845. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  846. 'asArray' => true
  847. ) );
  848. if (empty ( $invoiceDetail ))
  849. die ( 'illegal request' );
  850. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  851. $this->data ['invoiceDetail'] = $invoiceDetail;
  852. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  853. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  854. $this->data ['memu'] = "invoice";
  855. $this->data ['staff'] = $this->staff;
  856. $this->data ['receiptMemu'] = 'invoiceApproval';
  857. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  858. }
  859. /**
  860. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  861. *
  862. * @since 1.0.0
  863. * @var integer iid 开票ID 已加密
  864. * @var integer status 发票审批状态
  865. * @var integer opintion 审批发票的意见
  866. * @return string 如操作成功返回审批首页
  867. */
  868. function invoiceApprovalDo() {
  869. Doo::loadModel ( 'invoice' );
  870. $invoice = new invoice ();
  871. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  872. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  873. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  874. $iid = $invoice->authcode ( $iid );
  875. if (! is_numeric ( $iid ))
  876. die ( 'illegal request' );
  877. // && ! empty ( $opinion )
  878. if (! empty ( $iid ) && ! empty ( $status )) {
  879. if (! ($status == 2 || $status == 3 || $status == 4))
  880. die ( 'illegal request' );
  881. Doo::loadModel ( 'invoiceOperationLog' );
  882. $invoiceOperationLog = new invoiceOperationLog ();
  883. $invoiceDetail = $invoice->getOne ( array (
  884. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  885. 'asArray' => true
  886. ) );
  887. if (empty ( $invoiceDetail ))
  888. die ( 'illegal request' );
  889. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  890. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  891. if ($status == 3) {
  892. $invoice->status = $status;
  893. $item = array (
  894. 'operation' => $opinion
  895. );
  896. } else {
  897. if (empty ( $processApprovals )) {
  898. $processApprovals = array (
  899. $this->staff [0] ['sid'] => array (
  900. 'date' => date ( "Y-m-d H:i:s" ),
  901. 'opinion' => $opinion,
  902. 'status' => $status
  903. )
  904. );
  905. // var_dump(next($invoiceManage));
  906. $nextInvoiceManage = next ( $invoiceManage );
  907. // print_r($nextInvoiceManage);
  908. if ($status != 4 && $nextInvoiceManage !== false)
  909. $invoice->pendingApprovals = $nextInvoiceManage [0];
  910. $invoice->processApprovals = json_encode ( $processApprovals );
  911. // var_dump($invoice);
  912. // print_r($invoiceManage);
  913. } else {
  914. $processApprovals [$this->staff [0] ['sid']] = array (
  915. 'date' => date ( "Y-m-d H:i:s" ),
  916. 'opinion' => $opinion,
  917. 'status' => $status
  918. );
  919. $pendingApprovals = 0;
  920. foreach ( $invoiceManage as $key => $value ) {
  921. if ($value [0] == $this->staff [0] ['sid']) {
  922. if (isset ( $invoiceManage [$key + 1] ))
  923. $pendingApprovals = $invoiceManage [$key + 1] [0];
  924. break;
  925. }
  926. }
  927. if ($status != 4 && ! empty ( $pendingApprovals ))
  928. $invoice->pendingApprovals = $pendingApprovals;
  929. $invoice->processApprovals = json_encode ( $processApprovals );
  930. }
  931. $item = array (
  932. 'operation' => $opinion
  933. );
  934. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  935. $invoice->status = $status;
  936. $invoice->pendingApprovals = 0;
  937. } elseif ($status == 4) {
  938. $invoice->status = $status;
  939. $item = array (
  940. 'operation' => $opinion
  941. );
  942. }
  943. }
  944. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  945. $invoice->update ( array (
  946. 'where' => 'iid=' . $iid
  947. ) );
  948. $item += array (
  949. 'date' => date ( "Y-m-d H:i:s" ),
  950. 'img' => $this->staff [0] ['avatar'],
  951. 'username' => $this->staff [0] ['username'],
  952. 'uid' => $this->staff [0] ['sid'],
  953. 'category' => $this->staff [0] ['category'],
  954. 'status' => $status,
  955. 'iid' => $iid
  956. );
  957. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  958. return '/invoiceApproval';
  959. }
  960. die ( 'illegal request' );
  961. }
  962. /**
  963. * 展示需要打印的发票数据
  964. *
  965. * @since 1.0.0
  966. */
  967. function invoicePrint() {
  968. Doo::loadModel ( 'invoice' );
  969. $invoice = new invoice ();
  970. Doo::loadClass ( 'XDeode' );
  971. $XDeode = new XDeode ( 5 );
  972. Doo::loadModel ( 'staff' );
  973. $staff = new staff ();
  974. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  975. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  976. foreach ( $toPrint as $key => $value ) {
  977. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  978. $lastApprover = json_decode ( $value ['processApprovals'], true );
  979. if (! empty ( $lastApprover )) {
  980. $lastApproverKey = array_keys ( $lastApprover );
  981. $lastApprover = end ( $lastApprover );
  982. $staffDetail = $staff->getOne ( array (
  983. 'where' => 'sid=' . end ( $lastApproverKey ),
  984. 'asArray' => true
  985. ) );
  986. $lastApprover ['username'] = $staffDetail ['username'];
  987. }
  988. $toPrint [$key] ['lastApprover'] = $lastApprover;
  989. }
  990. foreach ( $printed as $key => $value ) {
  991. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  992. $lastApprover = json_decode ( $value ['processApprovals'], true );
  993. if (! empty ( $lastApprover )) {
  994. $lastApproverKey = array_keys ( $lastApprover );
  995. $lastApprover = end ( $lastApprover );
  996. $staffDetail = $staff->getOne ( array (
  997. 'where' => 'sid=' . end ( $lastApproverKey ),
  998. 'asArray' => true
  999. ) );
  1000. $lastApprover ['username'] = $staffDetail ['username'];
  1001. }
  1002. $printed [$key] ['lastApprover'] = $lastApprover;
  1003. }
  1004. $this->data ['printed'] = $printed;
  1005. $this->data ['toPrint'] = $toPrint;
  1006. $this->data ['memu'] = "invoice";
  1007. $this->data ['staff'] = $this->staff;
  1008. $this->data ['receiptMemu'] = 'invoicePrint';
  1009. $this->render ( "/admin/invoicePrint", $this->data );
  1010. }
  1011. /**
  1012. * 展示发票打印的详情页面
  1013. *
  1014. * @since 1.0.0
  1015. */
  1016. function invoicePrintDetail() {
  1017. Doo::loadClass ( 'XDeode' );
  1018. $XDeode = new XDeode ( 5 );
  1019. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1020. $iid = $XDeode->decode ( $iid );
  1021. if (! is_numeric ( $iid ))
  1022. die ( 'illegal request' );
  1023. Doo::loadModel ( 'invoice' );
  1024. $invoice = new invoice ();
  1025. Doo::loadModel ( 'invoiceOperationLog' );
  1026. $invoiceOperationLog = new invoiceOperationLog ();
  1027. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  1028. if (empty ( $invoiceDetail ))
  1029. die ( 'illegal request' );
  1030. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1031. $this->data ['invoiceDetail'] = $invoiceDetail;
  1032. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1033. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1034. $this->data ['memu'] = "invoice";
  1035. $this->data ['staff'] = $this->staff;
  1036. $this->data ['receiptMemu'] = 'invoicePrint';
  1037. $this->render ( "/admin/invoicePrintDetail", $this->data );
  1038. }
  1039. /**
  1040. * 填写票号并完成打印
  1041. * @since 1.0.0
  1042. */
  1043. function invoicePrintDo() {
  1044. Doo::loadModel ( 'invoice' );
  1045. $invoice = new invoice ();
  1046. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1047. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  1048. $iid = $invoice->authcode ( $iid );
  1049. if (! is_numeric ( $iid ))
  1050. die ( 'illegal request' );
  1051. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  1052. Doo::loadModel ( 'invoiceOperationLog' );
  1053. $invoiceOperationLog = new invoiceOperationLog ();
  1054. Doo::loadModel ( 'invoiceStatistics' );
  1055. $invoiceStatistics = new invoiceStatistics ();
  1056. // $info=$invoice->getOne(array('where'=>"invoiceNo = '".$invoiceNo."'",'asArray' => TRUE));
  1057. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  1058. if (empty ( $invoicePrintDetail ))
  1059. die ( 'illegal request' );
  1060. $item = array (
  1061. 'iid' => $iid,
  1062. 'printStatus' => 1,
  1063. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1064. 'printer' => $this->staff [0] ['username'],
  1065. 'printTime' => date ( "Y-m-d H:i:s" ),
  1066. 'invoiceNo' => $invoiceNo
  1067. );
  1068. $invoice->setInvoiceByCondition ( $item );
  1069. $item = array (
  1070. 'date' => date ( "Y-m-d H:i:s" ),
  1071. 'operation' => $invoiceNo,
  1072. 'status' => 5,
  1073. 'img' => $this->staff [0] ['avatar'],
  1074. 'username' => $this->staff [0] ['username'],
  1075. 'uid' => $this->staff [0] ['sid'],
  1076. 'category' => $this->staff [0] ['category'],
  1077. 'iid' => $iid
  1078. );
  1079. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1080. // 去统计--负票不汇总
  1081. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  1082. $item = array (
  1083. 'date' => date ( "Y-m-d H:i:s" ),
  1084. 'priceClass' => 1,
  1085. 'cid' => $invoicePrintDetail ['cid'],
  1086. 'staff' => $invoicePrintDetail ['sid'],
  1087. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  1088. );
  1089. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1090. }
  1091. // 发送通知信息到微信-去除
  1092. // $this->setWXMsg($iid,'PRINT');
  1093. // 申请人获取微信通知
  1094. Doo::loadModel ( 'staff' );
  1095. $staff = new staff ();
  1096. Doo::loadClass ( 'XDeode' );
  1097. $XDeode = new XDeode ( 5 );
  1098. $username2 = $staff->getOne ( array (
  1099. 'select' => 'wxid',
  1100. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  1101. 'asArray' => TRUE
  1102. ) );
  1103. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  1104. $msg = '';
  1105. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  1106. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  1107. return "/invoicePrint";
  1108. }
  1109. }
  1110. /**
  1111. * 需要邮寄的发票
  1112. * @since 1.0.0
  1113. */
  1114. function invoicePost() {
  1115. Doo::loadModel ( 'invoice' );
  1116. $invoice = new invoice ();
  1117. Doo::loadModel ( 'express' );
  1118. $express = new express ();
  1119. $invoicePost = $invoice->getPostByInvoice ();
  1120. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  1121. $expressList = $express->getExpressByAll ();
  1122. $this->data ['expressList'] = $expressList;
  1123. $this->data ['invoicePost'] = $invoicePost;
  1124. $this->data ['invoicePosted'] = $invoicePosted;
  1125. $this->data ['memu'] = "invoice";
  1126. $this->data ['staff'] = $this->staff;
  1127. $this->data ['receiptMemu'] = 'invoicePost';
  1128. $this->render ( "/admin/invoicePost", $this->data );
  1129. }
  1130. /**
  1131. * 添加发票邮寄信息
  1132. */
  1133. function invoiceExpressAddDo() {
  1134. Doo::loadModel ( 'invoice' );
  1135. $invoice = new invoice ();
  1136. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1137. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  1138. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  1139. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  1140. $iid = $iid = $invoice->authcode ( $iid );
  1141. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  1142. die ( 'illegal request' );
  1143. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  1144. $item = array (
  1145. 'iid' => $iid,
  1146. 'postStatus' => 1,
  1147. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1148. 'postTime' => date ( "Y-m-d H:i:s" ),
  1149. 'expressCompany' => $expressCompany,
  1150. 'expressNumber' => $expressNumber,
  1151. 'actualItems' => $actualItems,
  1152. 'poster' => $this->staff [0] ['username']
  1153. );
  1154. $invoice->setInvoiceByCondition ( $item );
  1155. // 微信通知-去掉
  1156. // $this->setWXMsg ( $iid );
  1157. Doo::loadModel ( 'staff' );
  1158. $staff = new staff ();
  1159. Doo::loadClass ( 'XDeode' );
  1160. $XDeode = new XDeode ( 5 );
  1161. $username2 = $staff->getOne ( array (
  1162. 'select' => 'wxid',
  1163. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  1164. 'asArray' => TRUE
  1165. ) );
  1166. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  1167. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  1168. if (empty ( $expCom ))
  1169. $expCom [0] = '';
  1170. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  1171. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  1172. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  1173. return '/invoicePost';
  1174. }
  1175. function invoiceExpressUpdateDo() {
  1176. Doo::loadModel ( 'invoice' );
  1177. $invoice = new invoice ();
  1178. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  1179. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1180. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  1181. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  1182. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  1183. $iid = $invoice->authcode ( $iid );
  1184. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  1185. die ( 'illegal request' );
  1186. $item = array (
  1187. 'iid' => $iid,
  1188. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1189. 'expressCompany' => $expressCompany,
  1190. 'expressNumber' => $expressNumber,
  1191. 'actualItems' => $actualItems,
  1192. 'poster' => $this->staff [0] ['username']
  1193. );
  1194. $invoice->setInvoiceByCondition ( $item );
  1195. return $action;
  1196. }
  1197. /**
  1198. * 可退票管理
  1199. */
  1200. function invoiceUntreadIsAchieve() {
  1201. Doo::loadModel ( 'invoice' );
  1202. $invoice = new invoice ();
  1203. Doo::loadClass ( 'XDeode' );
  1204. $XDeode = new XDeode ( 5 );
  1205. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  1206. $page_size = 18;
  1207. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1208. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1209. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  1210. $dateArr = explode ( ':', $date );
  1211. $D1 = '';
  1212. $D2 = '';
  1213. if (! empty ( $date )) {
  1214. $D1 = $dateArr [0];
  1215. $D2 = $dateArr [1];
  1216. }
  1217. $con = '';
  1218. if (! empty ( $D1 ) && ! empty ( $D2 ))
  1219. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  1220. // if ($date == 'MONTHO')
  1221. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1222. // elseif ($date == 'MONTHT')
  1223. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1224. // elseif ($date == 'MONTHY')
  1225. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1226. if (! empty ( $MebSea )) {
  1227. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1228. }
  1229. $pageinfo ['page'] = array (
  1230. 'previous' => ''
  1231. );
  1232. // printStatus=1 and
  1233. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  1234. $action = "invoiceUntreadIsAchieve";
  1235. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1236. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1237. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  1238. // print_r($list);
  1239. $this->data ['MebSeaEn'] = $MebSea;
  1240. // $this->data ['MebSea'] = urlencode ( $MebSea );
  1241. $this->data ['get'] = $get;
  1242. $this->data ['page'] = $pageinfo;
  1243. $this->data ['date'] = $date;
  1244. $this->data ['list'] = $list;
  1245. $this->data ['memu'] = "invoice";
  1246. $this->data ['staff'] = $this->staff;
  1247. $this->data ['receiptMemu'] = 'invoice';
  1248. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  1249. }
  1250. /**
  1251. * 退票处理页面
  1252. */
  1253. function invoiceUntread() {
  1254. Doo::loadModel ( 'invoice' );
  1255. $invoice = new invoice ();
  1256. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  1257. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  1258. foreach ( $establishedInvoice as $key => $value ) {
  1259. // months
  1260. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  1261. $nowDate = strtotime ( 'now' );
  1262. $establishedInvoice [$key] ['lossShow'] = false;
  1263. if ($lossDate < $nowDate)
  1264. $establishedInvoice [$key] ['lossShow'] = true;
  1265. }
  1266. $this->data ['untreadInvoice'] = $untreadInvoice;
  1267. $this->data ['establishedInvoice'] = $establishedInvoice;
  1268. $this->data ['memu'] = "invoice";
  1269. $this->data ['staff'] = $this->staff;
  1270. $this->data ['receiptMemu'] = 'invoiceUntread';
  1271. $this->render ( "/admin/invoiceUntread", $this->data );
  1272. }
  1273. /**
  1274. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  1275. */
  1276. function invoiceUntreadEstablishedDo() {
  1277. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1278. Doo::loadModel ( 'invoice' );
  1279. $invoice = new invoice ();
  1280. Doo::loadModel ( 'invoiceOperationLog' );
  1281. $invoiceOperationLog = new invoiceOperationLog ();
  1282. Doo::loadModel ( 'invoiceReceivables' );
  1283. Doo::loadModel ( 'invoiceStatistics' );
  1284. $iid = $invoice->authcode ( $untreadIidKey );
  1285. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1286. die ( 'illegal request' );
  1287. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  1288. if ($invoiceDetails ['untreadStatus'] != 1)
  1289. die ( 'illegal request' );
  1290. $item = array (
  1291. 'iid' => $iid,
  1292. // 'irid'=>'',
  1293. 'untreadStatus' => 2,
  1294. 'updateTime' => date ( "Y-m-d H:i:s" )
  1295. );
  1296. $invoice->setInvoiceByCondition ( $item );
  1297. $item = array (
  1298. 'date' => date ( "Y-m-d H:i:s" ),
  1299. 'operation' => '已确认退票',
  1300. 'status' => 6,
  1301. 'img' => $this->staff [0] ['avatar'],
  1302. 'username' => $this->staff [0] ['username'],
  1303. 'uid' => $this->staff [0] ['sid'],
  1304. 'category' => $this->staff [0] ['category'],
  1305. 'iid' => $iid
  1306. );
  1307. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1308. // 收款解绑以及入账扣除 收款扣除
  1309. if (! empty ( $invoiceDetails ['irid'] )) {
  1310. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  1311. foreach ( $iridList as $value ) {
  1312. $invoiceReceivables = new invoiceReceivables ();
  1313. $irDetails = $invoiceReceivables->getOne ( array (
  1314. 'where' => " irid=" . $value . ' and bindStatus=1',
  1315. 'asArray' => TRUE
  1316. ) );
  1317. $item = array (
  1318. 'irid' => $value,
  1319. 'bindStatus' => 0,
  1320. 'untreadStatus' => 1,
  1321. 'untreadStaff' => $invoiceDetails ['userName'],
  1322. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  1323. 'iid' => 0
  1324. );
  1325. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1326. if (! empty ( $irDetails )) {
  1327. // 扣除入账
  1328. $invoiceStatistics = new invoiceStatistics ();
  1329. $item = array (
  1330. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  1331. 'priceClass' => 3,
  1332. 'cid' => $invoiceDetails ['cid'],
  1333. 'staff' => $invoiceDetails ['sid'],
  1334. 'accountPrice' => - $irDetails ['receivablesPrice']
  1335. );
  1336. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1337. // 扣除收款
  1338. $invoiceStatistics = new invoiceStatistics ();
  1339. $item = array (
  1340. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  1341. 'priceClass' => 2,
  1342. 'cid' => $invoiceDetails ['cid'],
  1343. 'staff' => $invoiceDetails ['sid'],
  1344. 'irid' => $irDetails ['irid'],
  1345. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  1346. );
  1347. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1348. }
  1349. }
  1350. }
  1351. return "/invoiceUntread";
  1352. }
  1353. /**
  1354. * 建立负票,关联原来发票
  1355. */
  1356. function invoiceLossDo() {
  1357. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1358. if (! empty ( $iidKey )) {
  1359. Doo::loadClass ( 'XDeode' );
  1360. $XDeode = new XDeode ( 5 );
  1361. Doo::loadModel ( 'invoice' );
  1362. $invoice = new invoice ();
  1363. Doo::loadModel ( 'invoiceOperationLog' );
  1364. $invoiceOperationLog = new invoiceOperationLog ();
  1365. $iidKey = $XDeode->decode ( $iidKey );
  1366. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  1367. // 拷贝插入一条发票数据
  1368. $iid = $invoice->setInvoiceLoss ( $iidKey );
  1369. // 更新负票
  1370. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1371. $invoice = new invoice ();
  1372. $item = array (
  1373. 'iid' => $iid,
  1374. 'sid' => $this->staff [0] ['sid'],
  1375. 'userName' => $this->staff [0] ['username'],
  1376. 'cid' => $this->staff [0] ['cid'],
  1377. 'categoryName' => $this->staff [0] ['category'],
  1378. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  1379. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  1380. 'invoiceSerial' => $invoiceSerial,
  1381. 'invoiceNo' => '',
  1382. 'printStatus' => 0,
  1383. 'untreadStatus' => 4,
  1384. // 关联发票号
  1385. 'lossIid' => $invoiceDetail ['iid']
  1386. );
  1387. $invoice->setInvoiceByCondition ( $item );
  1388. // 更新原发票
  1389. $invoice = new invoice ();
  1390. $item = array (
  1391. 'iid' => $invoiceDetail ['iid'],
  1392. 'lossIid' => $iid
  1393. );
  1394. $invoice->setInvoiceByCondition ( $item );
  1395. // 操作日志
  1396. $item = array (
  1397. 'date' => date ( "Y-m-d H:i:s" ),
  1398. 'operation' => "创建负票" . $invoiceSerial,
  1399. 'status' => 12,
  1400. 'img' => $this->staff [0] ['avatar'],
  1401. 'username' => $this->staff [0] ['username'],
  1402. 'uid' => $this->staff [0] ['sid'],
  1403. 'category' => $this->staff [0] ['category'],
  1404. 'iid' => $iid
  1405. );
  1406. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1407. // print_r($invoiceDetail);
  1408. // echo $iid;die;
  1409. }
  1410. return '/invoiceUntread';
  1411. }
  1412. function invoiceReceivables() {
  1413. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  1414. Doo::loadModel ( 'L_category' );
  1415. $lCategory = new L_category ();
  1416. Doo::loadModel ( 'staff' );
  1417. $staff = new staff ();
  1418. Doo::loadModel ( 'invoiceReceivables' );
  1419. $invoiceReceivables = new invoiceReceivables ();
  1420. Doo::loadModel ( 'invoice' );
  1421. $invoice = new invoice ();
  1422. Doo::loadClass ( 'XDeode' );
  1423. $XDeode = new XDeode ( 5 );
  1424. $category = $lCategory->getCategory ();
  1425. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  1426. $sql = 'bindStatus=1 and iid!=0';
  1427. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  1428. // 获取未入账发票
  1429. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  1430. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  1431. foreach ( $invoiceUnAccount as $key => $value ) {
  1432. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1433. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1434. if (! empty ( $lastApprover )) {
  1435. $lastApproverKey = array_keys ( $lastApprover );
  1436. $lastApprover = end ( $lastApprover );
  1437. $staffDetail = $staff->getOne ( array (
  1438. 'where' => 'sid=' . end ( $lastApproverKey ),
  1439. 'asArray' => true
  1440. ) );
  1441. $lastApprover ['username'] = $staffDetail ['username'];
  1442. }
  1443. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  1444. }
  1445. foreach ( $invoiceExistAccount as $key => $value ) {
  1446. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  1447. if (empty ( $irList ))
  1448. $irList [0] ['sumPrice'] = 0;
  1449. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  1450. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  1451. $invoiceExistAccount [$key] ['balance'] = $balance;
  1452. }
  1453. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  1454. // print_r($receivablesList);
  1455. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  1456. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  1457. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  1458. $this->data ['receivablesInput'] = $receivablesInput;
  1459. $this->data ['year'] = date ( 'Y' );
  1460. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  1461. $this->data ['receivablesList'] = $receivablesList;
  1462. $this->data ['staffList'] = $staffList;
  1463. $this->data ['category'] = $category;
  1464. $this->data ['memu'] = "invoice";
  1465. $this->data ['staff'] = $this->staff;
  1466. $this->data ['receiptMemu'] = 'invoiceReceivables';
  1467. $this->render ( "/admin/invoiceReceivables", $this->data );
  1468. }
  1469. /**
  1470. * 新添加收款直接入账发票
  1471. */
  1472. function invoiceCompareClaimPrice() {
  1473. // 收款录入
  1474. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1475. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  1476. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  1477. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  1478. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1479. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  1480. Doo::loadModel ( 'invoiceReceivables' );
  1481. $invoiceReceivables = new invoiceReceivables ();
  1482. Doo::loadModel ( 'invoiceROLog' );
  1483. $invoiceROLog = new invoiceROLog ();
  1484. Doo::loadModel ( 'invoiceStatistics' );
  1485. Doo::loadModel ( 'invoice' );
  1486. $invoice = new invoice ();
  1487. Doo::loadClass ( 'XDeode' );
  1488. $XDeode = new XDeode ( 5 );
  1489. Doo::loadModel ( 'invoiceOperationLog' );
  1490. $invoiceOperationLog = new invoiceOperationLog ();
  1491. $iidKey = $XDeode->decode ( $iidKey );
  1492. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  1493. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  1494. die ( 'illegal request' );
  1495. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1496. // 收款录入 并绑定发票
  1497. Doo::db ()->beginTransaction ();
  1498. $item = array (
  1499. 'bindStatus' => 1,
  1500. 'iid' => $invoiceDetail ['iid'],
  1501. 'bindDate' => date ( "Y-m-d H:i:s" ),
  1502. 'receivablesPrice' => $receivablesPrice,
  1503. 'receivablesMessage' => $receivablesMessage,
  1504. 'receivablesSerial' => $receivablesSerial,
  1505. 'receivablesBank' => $receivablesBank,
  1506. 'receivablesDate' => $receivablesDate,
  1507. 'inputStaff' => $this->staff [0] ['username'],
  1508. 'accountClerk' => $this->staff [0] ['username'],
  1509. 'date' => date ( "Y-m-d" ),
  1510. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  1511. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  1512. 'confirmTime' => date ( "Y-m-d H:i:s" )
  1513. );
  1514. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  1515. $item = array ();
  1516. // 收款操作日志
  1517. $item = array (
  1518. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  1519. );
  1520. $item += array (
  1521. 'date' => date ( "Y-m-d" ),
  1522. 'status' => 1,
  1523. 'img' => $this->staff [0] ['avatar'],
  1524. 'username' => $this->staff [0] ['username'],
  1525. 'uid' => $this->staff [0] ['sid'],
  1526. 'category' => $this->staff [0] ['category'],
  1527. 'irid' => $irid
  1528. );
  1529. $invoiceROLog->setInvoiceROLog ( $item );
  1530. // 收款统计
  1531. $invoiceStatistics = new invoiceStatistics ();
  1532. $item = array (
  1533. 'date' => $receivablesDate,
  1534. 'priceClass' => 2,
  1535. 'irid' => $irid,
  1536. 'cid' => $invoiceDetail ['cid'],
  1537. 'staff' => $invoiceDetail ['sid'],
  1538. 'receivablesPrice' => $receivablesPrice
  1539. );
  1540. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1541. // 收款 入 发票
  1542. $detail = $invoiceDetail;
  1543. $iridString = "";
  1544. if (empty ( $detail ['irid'] ))
  1545. $iridString = $irid;
  1546. else
  1547. $iridString = $detail ['irid'] . ',' . $irid;
  1548. $item = array (
  1549. 'irid' => $iridString,
  1550. 'bindTime' => date ( "Y-m-d H:i:s" ),
  1551. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1552. 'iid' => $detail ['iid']
  1553. );
  1554. $invoiceReceivables = new invoiceReceivables ();
  1555. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  1556. if ($detail ['invoicePrice'] <= $sum)
  1557. $item += array (
  1558. 'untreadStatus' => 3
  1559. );
  1560. $invoice->setInvoiceByCondition ( $item );
  1561. // 操作日志
  1562. $item = array (
  1563. 'date' => date ( "Y-m-d H:i:s" ),
  1564. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  1565. 'status' => 8,
  1566. 'img' => $this->staff [0] ['avatar'],
  1567. 'username' => $this->staff [0] ['username'],
  1568. 'uid' => $this->staff [0] ['sid'],
  1569. 'category' => $this->staff [0] ['category'],
  1570. 'iid' => $detail ['iid']
  1571. );
  1572. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1573. // 入账汇总
  1574. $invoiceStatistics = new invoiceStatistics ();
  1575. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  1576. // $accountPrice = 0;
  1577. // foreach ( $list as $key => $value ) {
  1578. // $accountPrice += $value ['receivablesPrice'];
  1579. // }
  1580. $item = array (
  1581. 'date' => $receivablesDate,
  1582. 'priceClass' => 3,
  1583. 'cid' => $invoiceDetail ['cid'],
  1584. 'staff' => $invoiceDetail ['sid'],
  1585. 'accountPrice' => $receivablesPrice
  1586. );
  1587. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1588. Doo::db ()->commit ();
  1589. }
  1590. return '/invoiceReceivables';
  1591. }
  1592. /**
  1593. * 检索未入账发票数据 function sir() { }
  1594. */
  1595. /**
  1596. * 录入收款数据
  1597. * @return string
  1598. */
  1599. function invoiceReceivablesDo() {
  1600. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  1601. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  1602. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  1603. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1604. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  1605. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  1606. Doo::loadModel ( 'invoiceReceivables' );
  1607. $invoiceReceivables = new invoiceReceivables ();
  1608. Doo::loadModel ( 'invoiceROLog' );
  1609. $invoiceROLog = new invoiceROLog ();
  1610. Doo::loadModel ( 'invoiceStatistics' );
  1611. $invoiceStatistics = new invoiceStatistics ();
  1612. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  1613. $item = array (
  1614. 'receivablesPrice' => $receivablesPrice,
  1615. 'receivablesMessage' => $receivablesMessage,
  1616. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1617. 'receivablesBank' => $receivablesBank,
  1618. 'receivablesDate' => $receivablesDate,
  1619. 'inputStaff' => $this->staff [0] ['username'],
  1620. 'date' => date ( "Y-m-d" ),
  1621. 'receivablesCategory' => $receivablesCategory,
  1622. 'receivablesStaff' => $receivablesStaff
  1623. );
  1624. if ($receivablesCategory != 'PUBLIC') {
  1625. $item += array (
  1626. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  1627. 'inputType' => 1
  1628. );
  1629. }
  1630. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  1631. $item = array ();
  1632. // 收款操作日志
  1633. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1634. $item = array (
  1635. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  1636. );
  1637. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1638. $item = array (
  1639. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  1640. );
  1641. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1642. $receivablesStaff = explode ( '-', $receivablesStaff );
  1643. $item = array (
  1644. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  1645. );
  1646. }
  1647. $item += array (
  1648. 'date' => date ( "Y-m-d" ),
  1649. 'status' => 1,
  1650. 'img' => $this->staff [0] ['avatar'],
  1651. 'username' => $this->staff [0] ['username'],
  1652. 'uid' => $this->staff [0] ['sid'],
  1653. 'category' => $this->staff [0] ['category'],
  1654. 'irid' => $irid
  1655. );
  1656. $invoiceROLog->setInvoiceROLog ( $item );
  1657. $item = array (
  1658. 'date' => $receivablesDate,
  1659. 'priceClass' => 2,
  1660. 'irid' => $irid,
  1661. 'receivablesPrice' => $receivablesPrice
  1662. );
  1663. if ($receivablesCategory != 'PUBLIC') {
  1664. $receivablesCategory = explode ( ":", $receivablesCategory );
  1665. $item += array (
  1666. 'cid' => $receivablesCategory [0]
  1667. );
  1668. }
  1669. if ($receivablesStaff2 != 'PUBLIC') {
  1670. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  1671. $item += array (
  1672. 'staff' => $receivablesStaff [0]
  1673. );
  1674. }
  1675. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1676. // $toparty = $this->getWxidByCategory( $receivablesCategory [1] );
  1677. $toparty = $this->getToparty ( $receivablesCategory [1] );
  1678. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  1679. if ($toparty != 0)
  1680. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  1681. }
  1682. return "/invoiceReceivables";
  1683. }
  1684. /**
  1685. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  1686. */
  1687. function invoiceReceivablesClaim() {
  1688. Doo::loadModel ( 'invoiceReceivables' );
  1689. $invoiceReceivables = new invoiceReceivables ();
  1690. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  1691. $this->data ['receivablesList'] = $receivablesList;
  1692. $this->data ['memu'] = "invoice";
  1693. $this->data ['staff'] = $this->staff;
  1694. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  1695. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  1696. }
  1697. /**
  1698. * 更新收款相关数据
  1699. */
  1700. function invoiceReceivablesUpdateClaim() {
  1701. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  1702. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  1703. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  1704. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1705. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  1706. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  1707. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1708. if (empty ( $claimKey ))
  1709. die ( 'illegal request' );
  1710. Doo::loadModel ( 'invoiceReceivables' );
  1711. $invoiceReceivables = new invoiceReceivables ();
  1712. Doo::loadModel ( 'invoiceROLog' );
  1713. $invoiceROLog = new invoiceROLog ();
  1714. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  1715. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1716. if (empty ( $detail ))
  1717. die ( 'illegal request' );
  1718. $invoiceReceivables = new invoiceReceivables ();
  1719. $item = array (
  1720. 'irid' => $detail ['irid']
  1721. );
  1722. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1723. $item += array (
  1724. 'confirmTime' => date ( "Y-m-d H:i:s" )
  1725. );
  1726. }
  1727. if (! empty ( $receivablesCategory ))
  1728. $item += array (
  1729. 'receivablesCategory' => $receivablesCategory
  1730. );
  1731. if (! empty ( $receivablesStaff ))
  1732. $item += array (
  1733. 'receivablesStaff' => $receivablesStaff
  1734. );
  1735. if (! empty ( $receivablesPrice ))
  1736. $item += array (
  1737. 'receivablesPrice' => $receivablesPrice
  1738. );
  1739. if (! empty ( $receivablesMessage ))
  1740. $item += array (
  1741. 'receivablesMessage' => $receivablesMessage
  1742. );
  1743. if (! empty ( $receivablesBank ))
  1744. $item += array (
  1745. 'receivablesBank' => $receivablesBank
  1746. );
  1747. if (! empty ( $receivablesDate ))
  1748. $item += array (
  1749. 'receivablesDate' => $receivablesDate
  1750. );
  1751. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1752. // 收款操作日志
  1753. $item = array ();
  1754. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1755. $item = array (
  1756. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  1757. );
  1758. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1759. $item = array (
  1760. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  1761. );
  1762. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1763. $receivablesStaff = explode ( '-', $receivablesStaff );
  1764. $item = array (
  1765. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  1766. );
  1767. }
  1768. $item += array (
  1769. 'date' => date ( "Y-m-d" ),
  1770. 'status' => 1,
  1771. 'img' => $this->staff [0] ['avatar'],
  1772. 'username' => $this->staff [0] ['username'],
  1773. 'uid' => $this->staff [0] ['sid'],
  1774. 'category' => $this->staff [0] ['category'],
  1775. 'irid' => $detail ['irid']
  1776. );
  1777. $invoiceROLog->setInvoiceROLog ( $item );
  1778. return '/invoiceReceivablesAS';
  1779. }
  1780. function invoiceReceivablesDelete() {
  1781. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1782. if (empty ( $claimKey ))
  1783. die ( 'illegal request' );
  1784. Doo::loadModel ( 'invoiceReceivables' );
  1785. $invoiceReceivables = new invoiceReceivables ();
  1786. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  1787. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1788. if (empty ( $detail ))
  1789. die ( 'illegal request' );
  1790. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  1791. return '/invoiceReceivablesAS';
  1792. }
  1793. /**
  1794. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  1795. */
  1796. function invoiceReceivablesAscription() {
  1797. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1798. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  1799. Doo::loadModel ( 'invoiceReceivables' );
  1800. $invoiceReceivables = new invoiceReceivables ();
  1801. Doo::loadModel ( 'invoiceROLog' );
  1802. $invoiceROLog = new invoiceROLog ();
  1803. Doo::loadModel ( 'invoiceStatistics' );
  1804. $invoiceStatistics = new invoiceStatistics ();
  1805. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1806. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  1807. $item = array (
  1808. 'irid' => $detail ['irid'],
  1809. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  1810. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  1811. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  1812. 'recepitTitleMark' => $recepitTitleMark,
  1813. 'source' => 1
  1814. );
  1815. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1816. $item = array (
  1817. 'date' => date ( "Y-m-d" ),
  1818. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  1819. 'status' => 2,
  1820. 'img' => $this->staff [0] ['avatar'],
  1821. 'username' => $this->staff [0] ['username'],
  1822. 'uid' => $this->staff [0] ['sid'],
  1823. 'category' => $this->staff [0] ['category'],
  1824. 'irid' => $irid
  1825. );
  1826. $invoiceROLog->setInvoiceROLog ( $item );
  1827. $item = array (
  1828. 'cid' => $this->staff [0] ['cid'],
  1829. 'staff' => $this->staff [0] ['sid']
  1830. );
  1831. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  1832. }
  1833. return "/invoiceReceivablesClaim";
  1834. }
  1835. /**
  1836. */
  1837. function invoiceMyReceivables() {
  1838. Doo::loadModel ( 'invoiceReceivables' );
  1839. $invoiceReceivables = new invoiceReceivables ();
  1840. Doo::loadModel ( 'invoiceStatistics' );
  1841. $invoiceStatistics = new invoiceStatistics ();
  1842. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  1843. $year = date ( "Y" );
  1844. $tmp_date = date ( "Ym" );
  1845. $tmp_year = substr ( $tmp_date, 0, 4 );
  1846. $tmp_mon = substr ( $tmp_date, 4, 2 );
  1847. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  1848. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  1849. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  1850. $htm = $this->showCache ( $path );
  1851. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  1852. $this->data ['isMonth'] = $isMonth;
  1853. $this->data ['htm'] = $htm;
  1854. $this->data ['list'] = $list;
  1855. $this->data ['memu'] = "invoice";
  1856. $this->data ['staff'] = $this->staff;
  1857. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  1858. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  1859. }
  1860. /**
  1861. * 收款绑定发票 ,一个收款只能绑定一个发票
  1862. */
  1863. function invoiceBindReceivables() {
  1864. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1865. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1866. Doo::loadModel ( 'invoice' );
  1867. $invoice = new invoice ();
  1868. Doo::loadModel ( 'invoiceReceivables' );
  1869. $invoiceReceivables = new invoiceReceivables ();
  1870. Doo::loadModel ( 'invoiceOperationLog' );
  1871. $invoiceOperationLog = new invoiceOperationLog ();
  1872. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  1873. die ( 'illegal request' );
  1874. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1875. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  1876. if (empty ( $detail ) && empty ( $detailM ))
  1877. die ( 'illegal request' );
  1878. if ($detail ['untreadStatus'] == 3)
  1879. die ( 'illegal request' );
  1880. // if ($detailM ['receivablesPrice'] >= $detail ['invoicePrice']) {
  1881. // $price = $detailM ['receivablesPrice'] - $detail ['invoicePrice'];
  1882. // die ( '<p>收款金额超出开票金额 ¥' . $price . '元,请谨慎操作</p><a href="/invoiceMyReceivables">返回</a>' );
  1883. // }
  1884. $item = array (
  1885. 'irid' => $detailM ['irid'],
  1886. 'bindStatus' => 1,
  1887. 'iid' => $detail ['iid'],
  1888. 'accountClerk' => $this->staff [0] ['username'],
  1889. 'bindDate' => date ( "Y-m-d H:i:s" )
  1890. );
  1891. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1892. $iridString = "";
  1893. if (empty ( $detail ['irid'] ))
  1894. $iridString = $detailM ['irid'];
  1895. else
  1896. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  1897. $item = array (
  1898. 'iid' => $detail ['iid'],
  1899. 'irid' => $iridString
  1900. );
  1901. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  1902. if ($detail ['invoicePrice'] <= $sum)
  1903. $item += array (
  1904. 'untreadStatus' => 3
  1905. );
  1906. $invoice->setInvoiceByCondition ( $item );
  1907. // 操作日志
  1908. $item = array (
  1909. 'date' => date ( "Y-m-d H:i:s" ),
  1910. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  1911. 'status' => 8,
  1912. 'img' => $this->staff [0] ['avatar'],
  1913. 'username' => $this->staff [0] ['username'],
  1914. 'uid' => $this->staff [0] ['sid'],
  1915. 'category' => $this->staff [0] ['category'],
  1916. 'iid' => $detail ['iid']
  1917. );
  1918. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1919. Doo::loadModel ( 'invoiceStatistics' );
  1920. $invoiceStatistics = new invoiceStatistics ();
  1921. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  1922. // $accountPrice = 0;
  1923. // foreach ( $list as $key => $value ) {
  1924. // $accountPrice += $value ['receivablesPrice'];
  1925. // }
  1926. $item = array (
  1927. 'date' => $detailM ['receivablesDate'],
  1928. 'priceClass' => 3,
  1929. 'cid' => $detail ['cid'],
  1930. 'staff' => $detail ['sid'],
  1931. 'accountPrice' => $detailM ['receivablesPrice']
  1932. );
  1933. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1934. return "/invoiceReceivables";
  1935. }
  1936. /**
  1937. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  1938. */
  1939. function invoiceAggregate() {
  1940. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1941. Doo::loadModel ( 'invoiceStatistics' );
  1942. $invoiceStatistics = new invoiceStatistics ();
  1943. Doo::loadModel ( 'L_category' );
  1944. $Lcategory = new L_category ();
  1945. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  1946. $LcategoryList = $Lcategory->getCategory ();
  1947. // print_r($isList);
  1948. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  1949. foreach ( $LcategoryList as $key => $value ) {
  1950. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  1951. $month = 1;
  1952. $invoicePriceYear = 0;
  1953. $receivablesPriceYear = 0;
  1954. $accountPriceYear = 0;
  1955. for(; $month <= 12; $month ++) {
  1956. $flag = true;
  1957. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  1958. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  1959. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1960. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1961. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1962. ';
  1963. $invoicePriceYear += $v ['invoicePrice'];
  1964. $receivablesPriceYear += $v ['receivablesPrice'];
  1965. $accountPriceYear += $v ['accountPrice'];
  1966. $flag = false;
  1967. break;
  1968. }
  1969. }
  1970. if ($flag)
  1971. $html .= '<td class="taR"></td>
  1972. <td class="taR"></td>
  1973. <td class="taR"><b></b></td>
  1974. ';
  1975. }
  1976. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1977. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1978. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1979. ';
  1980. $html .= '</tr>';
  1981. }
  1982. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  1983. $invoicePriceYear = 0;
  1984. $receivablesPriceYear = 0;
  1985. $accountPriceYear = 0;
  1986. for($month = 1; $month <= 12; $month ++) {
  1987. $flag = true;
  1988. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  1989. if ($month == $v ['month']) {
  1990. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1991. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1992. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1993. ';
  1994. $invoicePriceYear += $v ['invoicePrice'];
  1995. $receivablesPriceYear += $v ['receivablesPrice'];
  1996. $accountPriceYear += $v ['accountPrice'];
  1997. $flag = false;
  1998. break;
  1999. }
  2000. }
  2001. if ($flag) {
  2002. $html .= '<td class="taR"></td>
  2003. <td class="taR"></td>
  2004. <td class="taR"><b></b></td>
  2005. ';
  2006. }
  2007. }
  2008. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  2009. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  2010. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  2011. ';
  2012. $html .= '</tr>';
  2013. // print_r($isList);
  2014. $this->data ['html'] = $html;
  2015. $this->data ['LcategoryList'] = $LcategoryList;
  2016. $this->data ['isList'] = $isList;
  2017. $this->data ['year'] = $year;
  2018. $this->data ['memu'] = "invoice";
  2019. $this->data ['staff'] = $this->staff;
  2020. $this->data ['receiptMemu'] = 'invoiceAggregate';
  2021. $this->render ( "/admin/invoiceAggregate", $this->data );
  2022. }
  2023. function invoiceAggregateStaff() {
  2024. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2025. Doo::loadModel ( 'invoiceStatistics' );
  2026. $invoiceStatistics = new invoiceStatistics ();
  2027. Doo::loadModel ( 'L_category' );
  2028. $Lcategory = new L_category ();
  2029. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  2030. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  2031. $cStaff = $Lcategory->getCategoryStaff ();
  2032. $html = '';
  2033. foreach ( $cStaff as $key => $value ) {
  2034. $categoryFir = true;
  2035. foreach ( $value ['staff'] as $k => $v ) {
  2036. if ($categoryFir) {
  2037. $width = count ( $value ['staff'] ) + 1;
  2038. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  2039. $categoryFir = false;
  2040. } else
  2041. $html .= '<tr>';
  2042. $html .= '<th>' . $v ['username'] . '</th>';
  2043. $invoicePriceStaffYear = 0;
  2044. $receivablesPriceStaffYear = 0;
  2045. $accountPriceStaffYear = 0;
  2046. for($month = 1; $month <= 12; $month ++) {
  2047. $flag = true;
  2048. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  2049. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  2050. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  2051. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  2052. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  2053. ';
  2054. $invoicePriceStaffYear += $slv ['invoicePrice'];
  2055. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  2056. $accountPriceStaffYear += $slv ['accountPrice'];
  2057. $flag = false;
  2058. break;
  2059. }
  2060. }
  2061. if ($flag)
  2062. $html .= '<td class="taR"></td>
  2063. <td class="taR"></td>
  2064. <td class="taR"><b></b></td>
  2065. ';
  2066. }
  2067. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  2068. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  2069. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  2070. ';
  2071. }
  2072. $html .= '</tr>';
  2073. // 小计
  2074. if (! empty ( $value ['staff'] )) {
  2075. $html .= '<tr><th class="taR">小计</th>';
  2076. $invoicePriceStaffYear = 0;
  2077. $receivablesPriceStaffYear = 0;
  2078. $accountPriceStaffYear = 0;
  2079. for($month = 1; $month <= 12; $month ++) {
  2080. $flag = true;
  2081. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  2082. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  2083. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  2084. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  2085. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  2086. ';
  2087. $invoicePriceStaffYear += $slv ['invoicePrice'];
  2088. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  2089. $accountPriceStaffYear += $slv ['accountPrice'];
  2090. $flag = false;
  2091. break;
  2092. }
  2093. }
  2094. if ($flag)
  2095. $html .= '<td class="taR"></td>
  2096. <td class="taR"></td>
  2097. <td class="taR"><b></b></td>
  2098. ';
  2099. }
  2100. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  2101. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  2102. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  2103. ';
  2104. $html .= '</tr>';
  2105. }
  2106. }
  2107. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  2108. $invoicePriceYear = 0;
  2109. $receivablesPriceYear = 0;
  2110. $accountPriceYear = 0;
  2111. for($month = 1; $month <= 12; $month ++) {
  2112. $flag = true;
  2113. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  2114. if ($month == $v ['month']) {
  2115. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  2116. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  2117. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  2118. ';
  2119. $invoicePriceYear += $v ['invoicePrice'];
  2120. $receivablesPriceYear += $v ['receivablesPrice'];
  2121. $accountPriceYear += $v ['accountPrice'];
  2122. $flag = false;
  2123. break;
  2124. }
  2125. }
  2126. if ($flag)
  2127. $html .= '<td class="taR"></td>
  2128. <td class="taR"></td>
  2129. <td class="taR"><b></b></td>
  2130. ';
  2131. }
  2132. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  2133. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  2134. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  2135. ';
  2136. $html .= '</tr>';
  2137. $this->data ['html'] = $html;
  2138. $this->data ['isList'] = $toteList;
  2139. $this->data ['year'] = $year;
  2140. $this->data ['memu'] = "invoice";
  2141. $this->data ['staff'] = $this->staff;
  2142. $this->data ['receiptMemu'] = 'invoiceAggregate';
  2143. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  2144. }
  2145. function invoiceAggregateCategory() {
  2146. Doo::loadClass ( 'XDeode' );
  2147. $XDeode = new XDeode ( 5 );
  2148. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  2149. $cid = $XDeode->decode ( $cid );
  2150. if (! is_numeric ( $cid ))
  2151. die ( 'illegal request' );
  2152. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2153. Doo::loadModel ( 'invoiceStatistics' );
  2154. $invoiceStatistics = new invoiceStatistics ();
  2155. Doo::loadModel ( 'staff' );
  2156. $staff = new staff ();
  2157. $list = $staff->getStaffByCid ( $cid );
  2158. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  2159. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  2160. if (empty ( $list ))
  2161. die ( '该办事处没有成员' );
  2162. $htmlA = $htmlB = $htmlC = $html = '';
  2163. foreach ( $list as $key => $value ) {
  2164. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  2165. $htmlB = '<tr><th class="taC">收款</th>';
  2166. $htmlC = '<tr><th class="taC">入账</th>';
  2167. $invoicePriceStaffYear = 0;
  2168. $receivablesPriceStaffYear = 0;
  2169. $accountPriceStaffYear = 0;
  2170. for($month = 1; $month <= 12; $month ++) {
  2171. $flag = true;
  2172. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  2173. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  2174. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  2175. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  2176. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  2177. $invoicePriceStaffYear += $v ['invoicePrice'];
  2178. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  2179. $accountPriceStaffYear += $v ['accountPrice'];
  2180. $flag = false;
  2181. break;
  2182. }
  2183. }
  2184. if ($flag) {
  2185. $htmlA .= '<td class="taR">-</td>';
  2186. $htmlB .= '<td class="taR">-</td>';
  2187. $htmlC .= '<td class="taR"><b>-</b></td>';
  2188. }
  2189. }
  2190. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  2191. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  2192. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  2193. $htmlA .= '</tr>';
  2194. $htmlB .= '</tr>';
  2195. $htmlC .= '</tr>';
  2196. $html .= $htmlA . $htmlB . $htmlC;
  2197. }
  2198. $htmlA = $htmlB = $htmlC = "";
  2199. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  2200. $htmlB = '<tr><th class="taC">收款</th>';
  2201. $htmlC = '<tr><th class="taC">入账</th>';
  2202. $invoicePriceStaffYear = 0;
  2203. $receivablesPriceStaffYear = 0;
  2204. $accountPriceStaffYear = 0;
  2205. for($month = 1; $month <= 12; $month ++) {
  2206. $flag = true;
  2207. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  2208. if ($month == $v ['month']) {
  2209. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  2210. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  2211. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  2212. $invoicePriceStaffYear += $v ['invoicePrice'];
  2213. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  2214. $accountPriceStaffYear += $v ['accountPrice'];
  2215. $flag = false;
  2216. break;
  2217. }
  2218. }
  2219. if ($flag) {
  2220. $htmlA .= '<td class="taR">-</td>';
  2221. $htmlB .= '<td class="taR">-</td>';
  2222. $htmlC .= '<td class="taR"><b>-</b></td>';
  2223. }
  2224. }
  2225. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  2226. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  2227. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  2228. $htmlA .= '</tr>';
  2229. $htmlB .= '</tr>';
  2230. $htmlC .= '</tr>';
  2231. $html .= $htmlA . $htmlB . $htmlC;
  2232. $this->data ['html'] = $html;
  2233. $this->data ['cidKey'] = $cidKey;
  2234. $this->data ['slist'] = $list;
  2235. $this->data ['isList'] = $toteList;
  2236. $this->data ['year'] = $year;
  2237. $this->data ['memu'] = "invoice";
  2238. $this->data ['staff'] = $this->staff;
  2239. $this->data ['receiptMemu'] = 'invoiceAggregate';
  2240. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  2241. }
  2242. function invoiceAchieve() {
  2243. Doo::loadModel ( 'invoice' );
  2244. $invoice = new invoice ();
  2245. Doo::loadClass ( 'XDeode' );
  2246. $XDeode = new XDeode ( 5 );
  2247. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2248. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2249. $page_size = 18;
  2250. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2251. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2252. $get = "/" . $date;
  2253. $con = '';
  2254. if ($date == 'MONTHO')
  2255. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2256. elseif ($date == 'MONTHT')
  2257. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2258. elseif ($date == 'MONTHY')
  2259. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2260. if (! empty ( $MebSea )) {
  2261. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2262. $get .= "/" . $MebSea;
  2263. }
  2264. $pageinfo ['page'] = array (
  2265. 'previous' => ''
  2266. );
  2267. $sql = 'status=2 and printStatus=1 and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  2268. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  2269. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2270. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2271. // print_r($pageinfo);
  2272. $this->data ['MebSeaEn'] = $MebSea;
  2273. $this->data ['MebSea'] = urlencode ( $MebSea );
  2274. $this->data ['get'] = $get;
  2275. $this->data ['page'] = $pageinfo;
  2276. $this->data ['list'] = $list;
  2277. $this->data ['date'] = $date;
  2278. $this->data ['memu'] = "invoice";
  2279. $this->data ['staff'] = $this->staff;
  2280. $this->data ['receiptMemu'] = 'invoice';
  2281. $this->render ( "/admin/invoiceAchieve", $this->data );
  2282. }
  2283. function invoiceMyUnAccountAchieve() {
  2284. Doo::loadModel ( 'invoice' );
  2285. $invoice = new invoice ();
  2286. Doo::loadClass ( 'XDeode' );
  2287. $XDeode = new XDeode ( 5 );
  2288. Doo::loadModel ( 'staff' );
  2289. $staff = new staff ();
  2290. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2291. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2292. $page_size = 18;
  2293. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2294. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2295. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2296. $dateArr = explode ( ':', $date );
  2297. $D1 = '';
  2298. $D2 = '';
  2299. if (! empty ( $date )) {
  2300. $D1 = $dateArr [0];
  2301. $D2 = $dateArr [1];
  2302. }
  2303. $con = '';
  2304. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2305. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2306. if (! empty ( $MebSea )) {
  2307. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2308. }
  2309. $pageinfo ['page'] = array (
  2310. 'previous' => ''
  2311. );
  2312. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  2313. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  2314. $action = "invoiceMyUnAccountAchieve";
  2315. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2316. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2317. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2318. Doo::loadModel ( 'express' );
  2319. $express = new express ();
  2320. $expressList = $express->getExpressByAll ();
  2321. $this->data ['expressList'] = $expressList;
  2322. // print_r($list);
  2323. $this->data ['MebSeaEn'] = $MebSea;
  2324. $this->data ['get'] = $get;
  2325. $this->data ['page'] = $pageinfo;
  2326. $this->data ['date'] = $date;
  2327. $this->data ['list'] = $list;
  2328. $this->data ['memu'] = "invoice";
  2329. $this->data ['staff'] = $this->staff;
  2330. $this->data ['receiptMemu'] = 'invoice';
  2331. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  2332. }
  2333. function invoiceReceivablesAchieve() {
  2334. Doo::loadModel ( 'invoiceReceivables' );
  2335. $invoiceReceivables = new invoiceReceivables ();
  2336. Doo::loadClass ( 'XDeode' );
  2337. $XDeode = new XDeode ( 5 );
  2338. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2339. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2340. $page_size = 1;
  2341. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2342. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2343. $get = "/" . $date;
  2344. $con = '';
  2345. if ($date == 'MONTHO')
  2346. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2347. elseif ($date == 'MONTHT')
  2348. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2349. elseif ($date == 'MONTHY')
  2350. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2351. if (! empty ( $MebSea )) {
  2352. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  2353. $get .= "/" . $MebSea;
  2354. }
  2355. $pageinfo ['page'] = array (
  2356. 'previous' => ''
  2357. );
  2358. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  2359. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  2360. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2361. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  2362. // print_r($pageinfo);
  2363. $this->data ['MebSeaEn'] = $MebSea;
  2364. $this->data ['MebSea'] = urlencode ( $MebSea );
  2365. $this->data ['get'] = $get;
  2366. $this->data ['page'] = $pageinfo;
  2367. $this->data ['list'] = $list;
  2368. $this->data ['date'] = $date;
  2369. $this->data ['memu'] = "invoice";
  2370. $this->data ['staff'] = $this->staff;
  2371. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  2372. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  2373. }
  2374. /**
  2375. * 收款解绑
  2376. */
  2377. function invoiceUnBundLing() {
  2378. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  2379. Doo::loadModel ( 'invoice' );
  2380. $invoice = new invoice ();
  2381. Doo::loadModel ( 'invoiceReceivables' );
  2382. $invoiceReceivables = new invoiceReceivables ();
  2383. Doo::loadModel ( 'invoiceOperationLog' );
  2384. $invoiceOperationLog = new invoiceOperationLog ();
  2385. Doo::loadModel ( 'invoiceROLog' );
  2386. $invoiceROLog = new invoiceROLog ();
  2387. Doo::loadModel ( 'invoiceStatistics' );
  2388. $irid = $invoice->authcode ( $unBundKey );
  2389. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  2390. die ( 'illegal request' );
  2391. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2392. $invoiceDetails = $invoice->getInvoiceByIid ( $irDetails ['iid'] );
  2393. if (empty ( $irDetails ) || $irDetails ['bindStatus'] == 0 || $invoiceDetails ['untreadStatus'] == 2)
  2394. die ( 'illegal request' );
  2395. // 收款
  2396. $item = array (
  2397. 'irid' => $irDetails ['irid'],
  2398. 'bindStatus' => 0,
  2399. 'iid' => 0
  2400. );
  2401. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2402. // 收款操作日志
  2403. $item = array (
  2404. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  2405. 'date' => date ( "Y-m-d" ),
  2406. 'status' => 3,
  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. 'irid' => $irid
  2412. );
  2413. $invoiceROLog->setInvoiceROLog ( $item );
  2414. // 扣除入账统计金额
  2415. $invoiceStatistics = new invoiceStatistics ();
  2416. $item = array (
  2417. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2418. 'priceClass' => 3,
  2419. 'cid' => $invoiceDetails ['cid'],
  2420. 'staff' => $invoiceDetails ['sid'],
  2421. 'accountPrice' => - $irDetails ['receivablesPrice']
  2422. );
  2423. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2424. // 扣除收款统计金额
  2425. $invoiceStatistics = new invoiceStatistics ();
  2426. $item = array (
  2427. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2428. 'priceClass' => 2,
  2429. 'cid' => $invoiceDetails ['cid'],
  2430. 'staff' => $invoiceDetails ['sid'],
  2431. 'irid' => $irDetails ['irid'],
  2432. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2433. );
  2434. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2435. // 发票解绑去收款ID
  2436. $iridString = $invoiceDetails ['irid'];
  2437. if (! empty ( $invoiceDetails ['irid'] )) {
  2438. $list = explode ( ',', $invoiceDetails ['irid'] );
  2439. foreach ( $list as $key => $value ) {
  2440. if ($value == $irDetails ['irid']) {
  2441. unset ( $list [$key] );
  2442. break;
  2443. }
  2444. }
  2445. $iridString = implode ( ",", $list );
  2446. }
  2447. $item = array (
  2448. 'iid' => $invoiceDetails ['iid'],
  2449. 'irid' => $iridString,
  2450. 'updateTime' => date ( "Y-m-d H:i:s" )
  2451. );
  2452. if ($invoiceDetails ['untreadStatus'] == 3)
  2453. $item += array (
  2454. 'untreadStatus' => 0
  2455. );
  2456. $invoice->setInvoiceByCondition ( $item );
  2457. $item = array (
  2458. 'date' => date ( "Y-m-d H:i:s" ),
  2459. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  2460. 'status' => 11,
  2461. 'img' => $this->staff [0] ['avatar'],
  2462. 'username' => $this->staff [0] ['username'],
  2463. 'uid' => $this->staff [0] ['sid'],
  2464. 'category' => $this->staff [0] ['category'],
  2465. 'iid' => $invoiceDetails ['iid']
  2466. );
  2467. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2468. return "/invoiceReceivablesAS";
  2469. }
  2470. /**
  2471. * 发票管理
  2472. */
  2473. function invoiceAS() {
  2474. Doo::loadModel ( 'invoice' );
  2475. $invoice = new invoice ();
  2476. Doo::loadModel ( 'invoiceReceivables' );
  2477. $invoiceReceivables = new invoiceReceivables ();
  2478. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2479. $page_size = 18;
  2480. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2481. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  2482. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2483. $dateArr = explode ( ':', $date );
  2484. $D1 = '';
  2485. $D2 = '';
  2486. if (! empty ( $date )) {
  2487. $D1 = $dateArr [0] . " 00:00:00 ";
  2488. if (isset ( $dateArr [1] ))
  2489. $D2 = $dateArr [1] . " 23:59:59 ";
  2490. else
  2491. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  2492. // $D2 = $dateArr [1];
  2493. }
  2494. $con = ' status=2 ';
  2495. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2496. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2497. if ($status == 'UNRECORD')
  2498. $con .= ' and printStatus=1 and untreadStatus=0';
  2499. elseif ($status == 'RECORD')
  2500. $con .= ' and printStatus=1 and untreadStatus=3';
  2501. elseif ($status == 'BOUNCED')
  2502. $con .= ' and untreadStatus=2';
  2503. elseif ($status == 'PARTRECORD')
  2504. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  2505. elseif ($status == 'All') {
  2506. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  2507. }
  2508. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2509. if (! empty ( $MebSea )) {
  2510. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2511. }
  2512. $pageinfo ['page'] = array (
  2513. 'previous' => ''
  2514. );
  2515. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  2516. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2517. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  2518. // foreach ($list as $key=>$value){
  2519. // $list[$key]['rpSum']=0;
  2520. // if (!empty($value['irid']))
  2521. // $list[$key]['rpSum']=$invoiceReceivables->getSumOfReceivablesPrice($value['irid']);
  2522. // }
  2523. $this->data ['MebSeaEn'] = $MebSea;
  2524. $this->data ['MebSea'] = urlencode ( $MebSea );
  2525. $this->data ['date'] = $date;
  2526. $this->data ['page'] = $pageinfo;
  2527. $this->data ['get'] = $get;
  2528. $this->data ['list'] = $list;
  2529. $this->data ['status'] = $status;
  2530. $this->data ['memu'] = "invoice";
  2531. $this->data ['staff'] = $this->staff;
  2532. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2533. $this->render ( "/admin/invoiceAS", $this->data );
  2534. }
  2535. /**
  2536. * 收款管理
  2537. */
  2538. function invoiceReceivablesAS() {
  2539. Doo::loadModel ( 'invoiceReceivables' );
  2540. $invoiceReceivables = new invoiceReceivables ();
  2541. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2542. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  2543. $page_size = 6;
  2544. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2545. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  2546. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2547. $dateArr = explode ( ':', $date );
  2548. $D1 = '';
  2549. $D2 = '';
  2550. if (! empty ( $date )) {
  2551. $D1 = $dateArr [0]; // ." 00:00:00 ";
  2552. if (isset ( $dateArr [1] ))
  2553. $D2 = $dateArr [1]; // ." 23:59:59 ";
  2554. else
  2555. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  2556. }
  2557. $descField = 'receivablesDate';
  2558. if ($timeType == 'CREATE')
  2559. $descField = 'date';
  2560. $con = '1';
  2561. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2562. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2563. // echo $con;
  2564. if ($status == 'Unclaimed')
  2565. $con .= ' and bindStatus=0';
  2566. elseif ($status == 'Credited')
  2567. $con .= ' and bindStatus=1';
  2568. elseif ($status == 'Claim')
  2569. $con .= ' and bindStatus=0 and receivablesStaff="PUBLIC"';
  2570. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2571. if (! empty ( $MebSea )) {
  2572. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  2573. }
  2574. $pageinfo ['page'] = array (
  2575. 'previous' => ''
  2576. );
  2577. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  2578. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2579. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $con, 'desc', $descField );
  2580. // print_r($list);
  2581. $this->data ['timeType'] = $timeType;
  2582. $this->data ['MebSeaEn'] = $MebSea;
  2583. $this->data ['MebSea'] = urlencode ( $MebSea );
  2584. $this->data ['date'] = $date;
  2585. $this->data ['page'] = $pageinfo;
  2586. $this->data ['get'] = $get;
  2587. $this->data ['list'] = $list;
  2588. $this->data ['status'] = $status;
  2589. $this->data ['memu'] = "invoice";
  2590. $this->data ['staff'] = $this->staff;
  2591. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2592. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  2593. }
  2594. function invoiceApprovalAchieve() {
  2595. Doo::loadModel ( 'invoice' );
  2596. $invoice = new invoice ();
  2597. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2598. $page_size = 12;
  2599. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2600. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2601. $get = "/" . $date;
  2602. $con = '';
  2603. if ($date == 'MONTHO')
  2604. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2605. elseif ($date == 'MONTHT')
  2606. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2607. elseif ($date == 'MONTHY')
  2608. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2609. if (! empty ( $MebSea )) {
  2610. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2611. $get .= "/" . $MebSea;
  2612. }
  2613. $pageinfo ['page'] = array (
  2614. 'previous' => ''
  2615. );
  2616. $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  2617. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  2618. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2619. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2620. // print_r($list);
  2621. $this->data ['MebSeaEn'] = $MebSea;
  2622. $this->data ['MebSea'] = urlencode ( $MebSea );
  2623. $this->data ['get'] = $get;
  2624. $this->data ['page'] = $pageinfo;
  2625. $this->data ['list'] = $list;
  2626. $this->data ['date'] = $date;
  2627. $this->data ['memu'] = "invoice";
  2628. $this->data ['staff'] = $this->staff;
  2629. $this->data ['receiptMemu'] = 'invoiceApproval';
  2630. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  2631. }
  2632. function invoiceTAchieve() {
  2633. Doo::loadModel ( 'invoice' );
  2634. $invoice = new invoice ();
  2635. Doo::loadClass ( 'XDeode' );
  2636. $XDeode = new XDeode ( 5 );
  2637. Doo::loadModel ( 'staff' );
  2638. $staff = new staff ();
  2639. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2640. $page_size = 2;
  2641. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2642. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2643. $get = "/" . $date;
  2644. $con = '';
  2645. if ($date == 'MONTHO')
  2646. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2647. elseif ($date == 'MONTHT')
  2648. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2649. elseif ($date == 'MONTHY')
  2650. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2651. if (! empty ( $MebSea )) {
  2652. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2653. $get .= "/" . $MebSea;
  2654. }
  2655. $pageinfo ['page'] = array (
  2656. 'previous' => ''
  2657. );
  2658. $sql = "";
  2659. $action = "";
  2660. if ($this->ACTION == 'invoicePrintAchieve') {
  2661. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2662. $action = "invoicePrintAchieve";
  2663. } elseif ($this->ACTION == 'invoicePostAchieve') {
  2664. // and untreadStatus=0
  2665. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  2666. $action = "invoicePostAchieve";
  2667. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  2668. $sql = " untreadStatus=2 and status=2 " . $con;
  2669. $action = "invoiceUntreadAchieve";
  2670. }
  2671. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2672. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2673. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2674. $this->data ['MebSeaEn'] = $MebSea;
  2675. $this->data ['MebSea'] = urlencode ( $MebSea );
  2676. $this->data ['get'] = $get;
  2677. $this->data ['page'] = $pageinfo;
  2678. $this->data ['date'] = $date;
  2679. $this->data ['memu'] = "invoice";
  2680. $this->data ['staff'] = $this->staff;
  2681. if ($this->ACTION == 'invoicePrintAchieve') {
  2682. foreach ( $list as $key => $value ) {
  2683. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2684. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2685. if (! empty ( $lastApprover )) {
  2686. $lastApproverKey = array_keys ( $lastApprover );
  2687. $lastApprover = end ( $lastApprover );
  2688. $staffDetail = $staff->getOne ( array (
  2689. 'where' => 'sid=' . end ( $lastApproverKey ),
  2690. 'asArray' => true
  2691. ) );
  2692. $lastApprover ['username'] = $staffDetail ['username'];
  2693. }
  2694. $list [$key] ['lastApprover'] = $lastApprover;
  2695. }
  2696. $this->data ['receiptMemu'] = 'invoicePrint';
  2697. $this->data ['list'] = $list;
  2698. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  2699. } elseif ($this->ACTION == 'invoicePostAchieve') {
  2700. Doo::loadModel ( 'express' );
  2701. $express = new express ();
  2702. $expressList = $express->getExpressByAll ();
  2703. $this->data ['expressList'] = $expressList;
  2704. $this->data ['receiptMemu'] = 'invoicePost';
  2705. $this->data ['list'] = $list;
  2706. $this->render ( "/admin/invoicePostAchieve", $this->data );
  2707. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  2708. $this->data ['receiptMemu'] = 'invoiceUntread';
  2709. $this->data ['list'] = $list;
  2710. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  2711. }
  2712. }
  2713. /**
  2714. *
  2715. * @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 ) ); }
  2716. */
  2717. /**
  2718. * 获取一条收款信息
  2719. */
  2720. function ajaxGetInvoiceReceivables() {
  2721. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2722. Doo::loadModel ( 'invoiceReceivables' );
  2723. $invoiceReceivables = new invoiceReceivables ();
  2724. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2725. echo json_encode ( array (
  2726. 'status' => 1,
  2727. 'detail' => $detail
  2728. ) );
  2729. }
  2730. /**
  2731. * 异步获取办事处用户
  2732. */
  2733. function ajaxGetStaffByCategory() {
  2734. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  2735. Doo::loadModel ( 'staff' );
  2736. $staff = new staff ();
  2737. if ($cid == "PUBLIC") {
  2738. echo json_encode ( array (
  2739. 'status' => 1,
  2740. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  2741. ) );
  2742. die ();
  2743. }
  2744. if (! is_numeric ( $cid )) {
  2745. echo json_encode ( array (
  2746. 'status' => 0,
  2747. 'msg' => 'illegal request'
  2748. ) );
  2749. die ();
  2750. }
  2751. $staffList = $staff->getStaffByCid ( $cid );
  2752. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  2753. foreach ( $staffList as $key => $value ) {
  2754. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2755. }
  2756. echo json_encode ( array (
  2757. 'status' => 1,
  2758. 'html' => $html
  2759. ) );
  2760. }
  2761. /**
  2762. * 异步获取一条发票的邮寄信息
  2763. */
  2764. function ajaxGetInvoicePostDetail() {
  2765. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2766. Doo::loadModel ( 'invoice' );
  2767. $invoice = new invoice ();
  2768. $iid = $invoice->authcode ( $iid );
  2769. Doo::loadModel ( 'express' );
  2770. $express = new express ();
  2771. $expressList = $express->getExpressByAll ();
  2772. if (! is_numeric ( $iid )) {
  2773. echo json_encode ( array (
  2774. 'status' => 0,
  2775. 'msg' => 'illegal request'
  2776. ) );
  2777. die ();
  2778. }
  2779. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  2780. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  2781. $html = "";
  2782. foreach ( $expressList as $key => $value ) {
  2783. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  2784. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  2785. else
  2786. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  2787. }
  2788. $invoiceDetail ['eaHtml'] = $html;
  2789. echo json_encode ( array (
  2790. 'status' => 1,
  2791. 'invoiceDetail' => $invoiceDetail
  2792. ) );
  2793. }
  2794. /**
  2795. *
  2796. * @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 ) ); }
  2797. */
  2798. /**
  2799. *
  2800. * @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 ) ); }
  2801. */
  2802. /**
  2803. * 我的收款中 选择哪个发票入账,进行金额判断
  2804. */
  2805. function ajaxCompareInvoicePrice() {
  2806. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2807. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2808. Doo::loadModel ( 'invoice' );
  2809. $invoice = new invoice ();
  2810. Doo::loadModel ( 'invoiceReceivables' );
  2811. $invoiceReceivables = new invoiceReceivables ();
  2812. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2813. $keyList = explode ( ';', $claimKey );
  2814. $receivablesPrice = 0;
  2815. foreach ( $keyList as $key => $value ) {
  2816. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  2817. $receivablesPrice += $detailM ['receivablesPrice'];
  2818. }
  2819. if ($receivablesPrice > $detail ['invoicePrice']) {
  2820. $price = $receivablesPrice - $detail ['invoicePrice'];
  2821. echo json_encode ( array (
  2822. 'status' => 1,
  2823. 'price' => $price
  2824. ) );
  2825. } else
  2826. echo json_encode ( array (
  2827. 'status' => 2
  2828. ) );
  2829. }
  2830. /**
  2831. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  2832. */
  2833. function ajaxGetInvoiceInfoByType() {
  2834. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  2835. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  2836. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  2837. if (empty ( $serial )) {
  2838. echo json_encode ( array (
  2839. 'status' => 2,
  2840. 'msg' => 'illegal request'
  2841. ) );
  2842. die ();
  2843. }
  2844. if ($type == 'INVOICE') {
  2845. Doo::loadModel ( 'invoice' );
  2846. $invoice = new invoice ();
  2847. Doo::loadModel ( 'invoiceOperationLog' );
  2848. $invoiceOperationLog = new invoiceOperationLog ();
  2849. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  2850. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  2851. if (empty ( $detail ))
  2852. $html = '';
  2853. else {
  2854. $html = '
  2855. <div class="modal-dialog modal-lg">
  2856. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  2857. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  2858. <tr>
  2859. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  2860. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  2861. </tr>
  2862. <tr>
  2863. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  2864. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  2865. </tr>
  2866. <tr>
  2867. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  2868. </td>
  2869. </tr>
  2870. <tr>
  2871. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  2872. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  2873. </tr>
  2874. <tr>
  2875. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  2876. </tr></tbody></table>';
  2877. if ($detail ['invoiceType'] == 0)
  2878. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2879. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  2880. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  2881. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  2882. </tr>';
  2883. else
  2884. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2885. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  2886. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  2887. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  2888. ';
  2889. $html .= '<tr>
  2890. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  2891. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  2892. </tr>
  2893. <tr>
  2894. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  2895. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  2896. </tr></tbody></table>';
  2897. if ($detail ['doPost'] == 1)
  2898. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  2899. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  2900. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  2901. </tr><tr>
  2902. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  2903. </tr><tr>
  2904. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  2905. </tr></tbody></table>';
  2906. if (! empty ( $invoiceOperationLogList )) {
  2907. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  2908. foreach ( $invoiceOperationLogList as $key => $value ) {
  2909. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  2910. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  2911. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  2912. if ($value ['status'] == 2) {
  2913. $html .= '<span class="colGreen">同意</span>';
  2914. } elseif ($value ['status'] == 3) {
  2915. $html .= '<span class="colOrange">退回</span>';
  2916. } elseif ($value ['status'] == 5) {
  2917. $html .= '<span class="colGreen">打印</span>';
  2918. } elseif ($value ['status'] == 4) {
  2919. $html .= '<span class="colRed">终止</span>';
  2920. }
  2921. $html .= $value ['operation'] . '</p></blockquote>';
  2922. }
  2923. }
  2924. $html .= '</td></tr></tbody></table>';
  2925. }
  2926. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2927. }
  2928. echo json_encode ( array (
  2929. 'status' => 1,
  2930. 'html' => $html
  2931. ) );
  2932. die ();
  2933. } elseif ($type == 'RECEIVABLES') {
  2934. Doo::loadModel ( 'invoiceReceivables' );
  2935. $invoiceReceivables = new invoiceReceivables ();
  2936. //
  2937. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  2938. if (empty ( $detail ))
  2939. $html = '';
  2940. else {
  2941. $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">
  2942. <tbody><tr>
  2943. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  2944. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  2945. </tr><tr>
  2946. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  2947. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  2948. </tr>
  2949. <tr>
  2950. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  2951. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  2952. </tr>
  2953. <tr>
  2954. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['bindDate'] . '</td>
  2955. </tr>
  2956. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2957. }
  2958. echo json_encode ( array (
  2959. 'status' => 1,
  2960. 'html' => $html
  2961. ) );
  2962. die ();
  2963. } elseif ($type == 'IRTC') {
  2964. Doo::loadModel ( 'invoice' );
  2965. $invoice = new invoice ();
  2966. Doo::loadModel ( 'invoiceOperationLog' );
  2967. $invoiceOperationLog = new invoiceOperationLog ();
  2968. Doo::loadModel ( 'invoiceReceivables' );
  2969. $invoiceReceivables = new invoiceReceivables ();
  2970. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  2971. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  2972. if (empty ( $detail ))
  2973. $html = '';
  2974. else {
  2975. $receivablesPriceedHtml = '';
  2976. $receivablesPrice = $detail ['invoicePrice'];
  2977. if (! empty ( $detail ['irid'] )) {
  2978. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  2979. if (empty ( $irList ))
  2980. $irList [0] ['sumPrice'] = 0;
  2981. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  2982. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  2983. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  2984. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  2985. </tr></tbody></table>';
  2986. $receivablesPrice = $balance;
  2987. }
  2988. if ($loss)
  2989. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  2990. $html = $receivablesPriceedHtml . '
  2991. <table class="table table-bordered table-condensed"><tbody>
  2992. <tr>
  2993. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  2994. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  2995. </tr>
  2996. <tr>
  2997. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  2998. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  2999. </tr>
  3000. <tr>
  3001. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  3002. </tr>
  3003. <tr>
  3004. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  3005. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  3006. </tr>
  3007. <tr>
  3008. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  3009. </tr></tbody></table>';
  3010. if ($detail ['invoiceType'] == 0) {
  3011. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3012. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  3013. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  3014. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  3015. </tr>';
  3016. $receivablesMessage = $detail ['invoiceTitle'];
  3017. } else {
  3018. $html .= '<table class="table table-bordered table-condensed"><tbody>
  3019. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  3020. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  3021. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  3022. ';
  3023. $receivablesMessage = $detail ['invoiceCompany'];
  3024. }
  3025. $html .= '<tr>
  3026. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  3027. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  3028. </tr>
  3029. <tr>
  3030. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  3031. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  3032. </tr></tbody></table>';
  3033. if ($detail ['doPost'] == 1)
  3034. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  3035. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  3036. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  3037. </tr><tr>
  3038. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  3039. </tr><tr>
  3040. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  3041. </tr></tbody></table>';
  3042. if (! empty ( $invoiceOperationLogList )) {
  3043. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  3044. foreach ( $invoiceOperationLogList as $key => $value ) {
  3045. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  3046. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  3047. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  3048. if ($value ['status'] == 2) {
  3049. $html .= '<span class="colGreen">同意</span>';
  3050. } elseif ($value ['status'] == 3) {
  3051. $html .= '<span class="colOrange">退回</span>';
  3052. } elseif ($value ['status'] == 5) {
  3053. $html .= '<span class="colGreen">打印</span>';
  3054. }
  3055. $html .= $value ['operation'] . '</p></blockquote>';
  3056. }
  3057. }
  3058. $html .= '</td></tr></tbody></table>';
  3059. }
  3060. }
  3061. echo json_encode ( array (
  3062. 'status' => 1,
  3063. 'html' => $html,
  3064. 'receivablesPrice' => $receivablesPrice,
  3065. 'receivablesMessage' => $receivablesMessage,
  3066. 'receivablesDate' => date ( "Y-m-d" ),
  3067. 'iidKey' => $serial
  3068. ) );
  3069. die ();
  3070. }
  3071. }
  3072. function ajaxGetInvoiceReceivablesByStaff() {
  3073. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  3074. if (empty ( $postData )) {
  3075. echo json_encode ( array (
  3076. 'status' => 2,
  3077. 'msg' => 'illegal request'
  3078. ) );
  3079. die ();
  3080. }
  3081. Doo::loadModel ( 'invoiceReceivables' );
  3082. $invoiceReceivables = new invoiceReceivables ();
  3083. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  3084. if (empty ( $detail )) {
  3085. echo json_encode ( array (
  3086. 'status' => 2,
  3087. 'msg' => 'illegal request'
  3088. ) );
  3089. die ();
  3090. }
  3091. Doo::loadModel ( 'L_category' );
  3092. $lCategory = new L_category ();
  3093. Doo::loadModel ( 'staff' );
  3094. $staff = new staff ();
  3095. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  3096. $category = $lCategory->getCategory ();
  3097. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  3098. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  3099. foreach ( $category as $key => $value ) {
  3100. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  3101. if ($value ['cid'] == $detail ['cid'])
  3102. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  3103. }
  3104. foreach ( $staffList as $key => $value ) {
  3105. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  3106. if ($value ['sid'] == $detail ['sid'])
  3107. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  3108. }
  3109. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  3110. echo json_encode ( array (
  3111. 'status' => 1,
  3112. 'categoryHtml' => $categoryHtml,
  3113. 'staffHtml' => $staffHtml,
  3114. 'rbankHtml' => $rbankHtml,
  3115. 'detail' => $detail
  3116. ) );
  3117. }
  3118. function ajaxGetInvoiceReceivablesByIrid() {
  3119. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  3120. if (empty ( $irid )) {
  3121. echo json_encode ( array (
  3122. 'status' => 2,
  3123. 'msg' => 'illegal request'
  3124. ) );
  3125. die ();
  3126. }
  3127. Doo::loadModel ( 'invoiceReceivables' );
  3128. $invoiceReceivables = new invoiceReceivables ();
  3129. Doo::loadModel ( 'invoice' );
  3130. $invoice = new invoice ();
  3131. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  3132. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 " ); //
  3133. $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>
  3134. <tr>
  3135. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  3136. <td>' . $detail ['receivablesMessage'] . '</td>
  3137. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  3138. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  3139. <td>' . $detail ['recepitTitleMark'] . '</td>
  3140. </tr></tbody></table>';
  3141. $isInvoice = false;
  3142. $invoiceHtml = '';
  3143. if (empty ( $invoiceDetail )) {
  3144. $isInvoice = true;
  3145. } else {
  3146. $invoiceHtml = '<table class="table table-bordered table-condensed">
  3147. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  3148. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  3149. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceCompany'] . '</td>';
  3150. } else {
  3151. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceTitle'] . '</td>';
  3152. }
  3153. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  3154. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '专</td>';
  3155. } else {
  3156. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '</td>';
  3157. }
  3158. $invoiceHtml .= '
  3159. <td>' . $invoiceDetail ['categoryName'] . $invoiceDetail ['userName'] . ' ' . $invoiceDetail ['date'] . '</td>
  3160. <td>' . $invoiceDetail ['printer'] . ' ' . $invoiceDetail ['printTime'] . '</td>
  3161. <td>' . $invoiceDetail ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '" data-ikey="' . $invoiceDetail ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  3162. </tr>
  3163. ';
  3164. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $invoiceDetail ['irid'] );
  3165. if (empty ( $irList ))
  3166. $irList [0] ['sumPrice'] = 0;
  3167. $balance = $invoiceDetail ['invoicePrice'] - $irList [0] ['sumPrice'];
  3168. $priceString = '';
  3169. if ($balance < $detail ['receivablesPrice']) {
  3170. $priceString = '收款金额超过开票金额,';
  3171. }
  3172. if ($balance > $detail ['receivablesPrice']) {
  3173. $priceString = '收款金额低于开票金额,';
  3174. }
  3175. $invoiceHtml .= '</tbody></table>
  3176. <script>
  3177. $(\'a[bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '"]\').click(function() {
  3178. $("input[name=\'invoiceKey\']").val("' . $invoiceDetail ['iidKey'] . '");
  3179. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  3180. if(invoiceKey==""){
  3181. alert("入账错误,请重新刷新页面");
  3182. return false;
  3183. }
  3184. if(window.confirm("' . $priceString . '确定入账吗?")){
  3185. $("#IBR").submit();
  3186. }else{
  3187. return false;
  3188. }
  3189. });
  3190. </script>
  3191. ';
  3192. }
  3193. echo json_encode ( array (
  3194. 'status' => 1,
  3195. 'irkey' => $detail ['iridEn'],
  3196. 'receivablesHtml' => $receivablesHtml,
  3197. 'isInvoice' => $isInvoice,
  3198. 'invoiceHtml' => $invoiceHtml
  3199. ) );
  3200. }
  3201. function ajaxGetInvoiceReceivablesByTitle() {
  3202. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  3203. if (empty ( $title )) {
  3204. echo json_encode ( array (
  3205. 'status' => 2,
  3206. 'msg' => 'illegal request'
  3207. ) );
  3208. die ();
  3209. }
  3210. Doo::loadModel ( 'invoice' );
  3211. $invoice = new invoice ();
  3212. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 " );
  3213. $invoiceHtml = '';
  3214. if (! empty ( $invoiceDetail )) {
  3215. $invoiceHtml = '<table class="table table-bordered table-condensed">
  3216. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  3217. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  3218. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceCompany'] . '</td>';
  3219. } else {
  3220. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceTitle'] . '</td>';
  3221. }
  3222. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  3223. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '专</td>';
  3224. } else {
  3225. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '</td>';
  3226. }
  3227. $invoiceHtml .= '
  3228. <td>' . $invoiceDetail ['categoryName'] . $invoiceDetail ['userName'] . ' ' . $invoiceDetail ['date'] . '</td>
  3229. <td>' . $invoiceDetail ['printer'] . ' ' . $invoiceDetail ['printTime'] . '</td>
  3230. <td>' . $invoiceDetail ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '" data-ikey="' . $invoiceDetail ['iidKey'] . '" href="#">入账</a></td>
  3231. </tr>
  3232. ';
  3233. $invoiceHtml .= '</tbody></table>
  3234. <script>
  3235. $(\'a[bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '"]\').click(function() {
  3236. $("input[name=\'invoiceKey\']").val("' . $invoiceDetail ['iidKey'] . '");
  3237. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  3238. if(invoiceKey==""){
  3239. alert("入账错误,请重新刷新页面");
  3240. return false;
  3241. }
  3242. if(window.confirm("确定入账吗?")){
  3243. $("#IBR").submit();
  3244. }else{
  3245. return false;
  3246. }
  3247. });
  3248. </script>
  3249. ';
  3250. }
  3251. echo json_encode ( array (
  3252. 'status' => 1,
  3253. 'invoiceHtml' => $invoiceHtml
  3254. ) );
  3255. }
  3256. function ajaxInvoicePushNotice() {
  3257. Doo::loadModel ( 'invoice' );
  3258. $invoice = new invoice ();
  3259. $approval = $invoice->getOne ( array (
  3260. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  3261. 'desc' => 'iid',
  3262. 'asArray' => true
  3263. ) );
  3264. $isNotice = false;
  3265. if (! empty ( $approval ))
  3266. $isNotice = true;
  3267. $response = array (
  3268. 'error' => 0,
  3269. 'isNotice' => $isNotice
  3270. );
  3271. echo json_encode ( $response );
  3272. exit ();
  3273. }
  3274. public function ajaxCheckInvoiceNoUniqueness() {
  3275. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  3276. Doo::loadModel ( 'invoice' );
  3277. $invoice = new invoice ();
  3278. if (! empty ( $invoiceNo )) {
  3279. $info = $invoice->getOne ( array (
  3280. 'where' => "invoiceNo = '" . $invoiceNo . "'",
  3281. 'asArray' => TRUE
  3282. ) );
  3283. if (! empty ( $info )) {
  3284. echo json_encode ( array (
  3285. 'error' => '发票号已存在'
  3286. ) );
  3287. die ();
  3288. } else
  3289. echo json_encode ( array (
  3290. 'ok' => '可以使用!'
  3291. ) );
  3292. die ();
  3293. }
  3294. }
  3295. function ajaxCheckInvoicePrice() {
  3296. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3297. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3298. Doo::loadModel ( 'invoice' );
  3299. $invoice = new invoice ();
  3300. Doo::loadModel ( 'invoiceReceivables' );
  3301. $invoiceReceivables = new invoiceReceivables ();
  3302. Doo::loadClass ( 'XDeode' );
  3303. $XDeode = new XDeode ( 5 );
  3304. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  3305. $iidKey = $XDeode->decode ( $iidKey );
  3306. $info = $invoice->getInvoiceByIid ( $iidKey );
  3307. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  3308. if (empty ( $irList ))
  3309. $irList [0] ['sumPrice'] = 0;
  3310. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  3311. if ($balance < $receivablesPrice) {
  3312. echo json_encode ( array (
  3313. 'error' => '收款金额超过开票金额。'
  3314. ) );
  3315. die ();
  3316. }
  3317. if ($balance > $receivablesPrice) {
  3318. echo json_encode ( array (
  3319. 'error' => '收款金额低于开票金额。'
  3320. ) );
  3321. die ();
  3322. }
  3323. }
  3324. }
  3325. /**
  3326. * 旧输入导入
  3327. */
  3328. function importInvoice() {
  3329. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  3330. $data ['emsg'] = "";
  3331. if ($emsg != "")
  3332. $data ['emsg'] = "请填写完整的数据";
  3333. $data ['time'] = time ();
  3334. $this->render ( "/admin/invoiceImport", $data );
  3335. }
  3336. function uploadInvoice() {
  3337. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  3338. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  3339. $file = $_FILES ['Filedata'] ['tmp_name'];
  3340. $error = false;
  3341. if (! is_uploaded_file ( $file )) {
  3342. $error = '400 Bad Request';
  3343. }
  3344. if ($error) {
  3345. header ( 'HTTP/1.0 ' . $error );
  3346. die ( 'Error ' . $error );
  3347. } else {
  3348. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  3349. $this->IoHandler = new IoHandler ();
  3350. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  3351. // $filedir=$_POST['time'];
  3352. // 调用定义物理路径
  3353. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  3354. $this->IoHandler->MakeDir ( $t );
  3355. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  3356. if ($filename != 'xlsx')
  3357. return "";
  3358. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  3359. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  3360. $upload_dir = $t . "/" . $upload_file;
  3361. $k = move_uploaded_file ( $file, $upload_dir );
  3362. if ($k) {
  3363. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  3364. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  3365. }
  3366. }
  3367. }
  3368. }
  3369. function importInvoiceDo() {
  3370. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  3371. if ($path != "") {
  3372. Doo::loadModel ( 'invoice' );
  3373. Doo::loadModel ( 'staff' );
  3374. $staff = new staff ();
  3375. Doo::loadModel ( 'invoiceStatistics' );
  3376. Doo::loadModel ( 'invoiceOperationLog' );
  3377. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  3378. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  3379. // print_r ( $exlArray );
  3380. // die ();
  3381. // echo json_encode($exlArray);die;
  3382. foreach ( $exlArray as $key => $value ) {
  3383. // 开票
  3384. $invoice = new invoice ();
  3385. $invoice->invoiceNo = $value ['invoiceNo'];
  3386. $invoice->invoiceType = 0;
  3387. if ($value ['invoiceType'] == '专')
  3388. $invoice->invoiceType = 1;
  3389. $invoice->invoicePrice = $value ['invoicePrice'];
  3390. $invoice->invoiceQuantity = 1;
  3391. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  3392. $invoice->invoiceTitle = $value ['invoiceTitle'];
  3393. if ($value ['invoiceType'] == '专')
  3394. $invoice->invoiceCompany = $value ['invoiceTitle'];
  3395. $invoice->userName = $value ['userName'];
  3396. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  3397. $invoice->sid = $sDetail ['sid'];
  3398. $invoice->cid = $sDetail ['cid'];
  3399. $invoice->categoryName = $sDetail ['category'];
  3400. $invoice->invoiceElement = $value ['invoiceElement'];
  3401. $invoice->remark = $value ['remark'];
  3402. $invoice->date = $value ['date'];
  3403. $invoice->printTime = $value ['date'];
  3404. $invoice->ipSource = 1;
  3405. $invoice->printStatus = 1;
  3406. $invoice->status = 2;
  3407. $invoice->postStatus = 1;
  3408. $invoice->untreadStatus = 0;
  3409. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3410. $iid = $invoice->insert ();
  3411. // 汇总
  3412. $invoiceStatistics = new invoiceStatistics ();
  3413. //
  3414. $item = array (
  3415. 'date' => $value ['date'],
  3416. 'priceClass' => 1,
  3417. 'cid' => $sDetail ['cid'],
  3418. 'staff' => $sDetail ['sid'],
  3419. 'invoicePrice' => $value ['invoicePrice']
  3420. );
  3421. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3422. $invoiceOperationLog = new invoiceOperationLog ();
  3423. $item = array (
  3424. 'date' => date ( "Y-m-d H:i:s" ),
  3425. 'operation' => date ( "Y-m-d" ) . " 导入",
  3426. 'status' => 1,
  3427. 'img' => $sDetail ['avatar'],
  3428. 'username' => $sDetail ['username'],
  3429. 'uid' => $sDetail ['sid'],
  3430. 'category' => $sDetail ['category'],
  3431. 'iid' => $iid
  3432. );
  3433. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3434. }
  3435. return '/importInvoice?count=' . count ( $exlArray );
  3436. // return "/keyonline";
  3437. }
  3438. echo 'no file';
  3439. }
  3440. function importInvoiceReceivables() {
  3441. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  3442. $data ['emsg'] = "";
  3443. if ($emsg != "")
  3444. $data ['emsg'] = "请填写完整的数据";
  3445. $data ['time'] = time ();
  3446. $this->render ( "/admin/invoiceReceivablesImport", $data );
  3447. }
  3448. // 导入入账数据
  3449. function importInvoiceReceivablesDo() {
  3450. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  3451. include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3452. if ($path != "") {
  3453. Doo::loadModel ( 'invoiceReceivables' );
  3454. Doo::loadModel ( 'invoice' );
  3455. Doo::loadModel ( 'staff' );
  3456. $staff = new staff ();
  3457. Doo::loadModel ( 'invoiceStatistics' );
  3458. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  3459. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  3460. // print_r ( $exlArray );
  3461. // die ();
  3462. // echo json_encode($exlArray);die;
  3463. foreach ( $exlArray as $key => $value ) {
  3464. // 收款
  3465. $invoiceReceivables = new invoiceReceivables ();
  3466. $invoice = new invoice ();
  3467. $invoiceReceivables->bindStatus = 1;
  3468. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  3469. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  3470. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  3471. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  3472. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  3473. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  3474. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  3475. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3476. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  3477. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  3478. $invoiceReceivables->iid = $iDetail ['iid'];
  3479. $irid = $invoiceReceivables->insert ();
  3480. // 发票绑定收款
  3481. $detail = $iDetail;
  3482. $iridString = "";
  3483. if (empty ( $detail ['irid'] ))
  3484. $iridString = $irid;
  3485. else
  3486. $iridString = $detail ['irid'] . ',' . $irid;
  3487. $item = array (
  3488. 'irid' => $iridString,
  3489. 'iid' => $detail ['iid']
  3490. );
  3491. $invoice->setInvoiceByCondition ( $item );
  3492. // 汇总
  3493. $invoiceStatistics = new invoiceStatistics ();
  3494. // 扣除入账统计金额
  3495. $item = array (
  3496. 'date' => $value ['receivablesDate'],
  3497. 'priceClass' => 3,
  3498. 'cid' => $sDetail ['cid'],
  3499. 'staff' => $sDetail ['sid'],
  3500. // 'irid' => $irid,
  3501. 'accountPrice' => $value ['receivablesPrice']
  3502. );
  3503. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3504. }
  3505. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  3506. echo 'data count ' . count ( $exlArray );
  3507. die ();
  3508. // return "/keyonline";
  3509. }
  3510. echo 'no file';
  3511. }
  3512. /**
  3513. * 格式化excel文件为数组
  3514. * @param unknown_type $file_url
  3515. * @param unknown_type $mcid
  3516. */
  3517. function _format_excel_to_array($file_url = "", $sType = "") {
  3518. if (! file_exists ( $file_url )) {
  3519. return array ();
  3520. }
  3521. Doo::loadClass ( 'PHPExcel' );
  3522. $PHPExcel = new PHPExcel ();
  3523. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  3524. if (! $PHPReader->canRead ( $file_url )) {
  3525. $PHPReader = new PHPExcel_Reader_Excel5 ();
  3526. if (! $PHPReader->canRead ( $file_url )) {
  3527. echo 'no Excel';
  3528. return;
  3529. }
  3530. }
  3531. $PHPExcel = $PHPReader->load ( $file_url );
  3532. /* * 读取excel文件中的第一个工作表 */
  3533. $currentSheet = $PHPExcel->getSheet ( 0 );
  3534. /* * 取得最大的列号 */
  3535. $allColumn = $currentSheet->getHighestColumn ();
  3536. /* * 取得一共有多少行 */
  3537. $allRow = $currentSheet->getHighestRow ();
  3538. $excel_array = array ();
  3539. $conk = 2;
  3540. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  3541. $excel_column = array ();
  3542. // 后期改进
  3543. if ($allColumn == 'AM')
  3544. $allColumn = 'Z';
  3545. /* * 从第A列开始输出 */
  3546. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  3547. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  3548. if ($val instanceof PHPExcel_RichText)
  3549. $val = $val->__toString ();
  3550. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  3551. // $val = "'" . addslashes ( $val ) . "'";
  3552. if ($sType == 'invoiceReceivables') {
  3553. if ($currentColumn == 'A')
  3554. $excel_column ['invoiceNo'] = $val;
  3555. elseif ($currentColumn == 'B')
  3556. $excel_column ['receivablesPrice'] = $val;
  3557. elseif ($currentColumn == 'C') {
  3558. $excel_column ['receivablesMessage'] = $val;
  3559. } elseif ($currentColumn == 'D') {
  3560. $excel_column ['receivablesBank'] = $val;
  3561. } elseif ($currentColumn == 'E') {
  3562. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  3563. } elseif ($currentColumn == 'F') {
  3564. $excel_column ['receivablesStaff'] = $val;
  3565. } elseif ($currentColumn == 'G') {
  3566. $excel_column ['sourcePrice'] = $val;
  3567. }
  3568. } else {
  3569. if ($currentColumn == 'A')
  3570. $excel_column ['invoiceNo'] = $val;
  3571. elseif ($currentColumn == 'B')
  3572. $excel_column ['invoiceType'] = $val;
  3573. elseif ($currentColumn == 'C') {
  3574. $excel_column ['invoicePrice'] = $val;
  3575. } elseif ($currentColumn == 'D') {
  3576. $excel_column ['invoiceTitle'] = $val;
  3577. } elseif ($currentColumn == 'E') {
  3578. $excel_column ['userName'] = $val;
  3579. } elseif ($currentColumn == 'F') {
  3580. $excel_column ['categoryName'] = $val;
  3581. } elseif ($currentColumn == 'G') {
  3582. $excel_column ['invoiceElement'] = $val;
  3583. } elseif ($currentColumn == 'H') {
  3584. $excel_column ['remark'] = $val;
  3585. } elseif ($currentColumn == 'I') {
  3586. $excel_column ['date'] = $this->excelTime ( $val );
  3587. }
  3588. }
  3589. }
  3590. array_push ( $excel_array, $excel_column );
  3591. }
  3592. return $excel_array;
  3593. }
  3594. function excelTime($date, $time = false) {
  3595. if (function_exists ( 'GregorianToJD' )) {
  3596. if (is_numeric ( $date )) {
  3597. $jd = GregorianToJD ( 1, 1, 1970 );
  3598. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  3599. $date = explode ( '/', $gregorian );
  3600. $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" : '');
  3601. return $date_str;
  3602. }
  3603. } else {
  3604. $date = $date > 25568 ? $date + 1 : 25569;
  3605. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  3606. $ofs = (70 * 365 + 17 + 2) * 86400;
  3607. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  3608. }
  3609. return $date;
  3610. }
  3611. /**
  3612. * 旧输入导入
  3613. */
  3614. function _GetFileEXT($filename) {
  3615. $pics = explode ( '.', $filename );
  3616. $num = count ( $pics );
  3617. return $pics [$num - 1];
  3618. }
  3619. function showCache($path = "") {
  3620. // if (file_exists ( $path )) {
  3621. // $htm = file_get_contents ( $path );
  3622. // } else {
  3623. Doo::loadModel ( 'invoiceStatistics' );
  3624. $invoiceStatistics = new invoiceStatistics ();
  3625. $isBriefly = $invoiceStatistics->getBrieflyStatistics ();
  3626. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  3627. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  3628. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  3629. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  3630. /*
  3631. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  3632. */
  3633. file_put_contents ( $path, $htm, FILE_APPEND );
  3634. // }
  3635. return $htm;
  3636. }
  3637. /**
  3638. * 获取get或者POST值
  3639. *
  3640. * @param string $name 属性名称
  3641. * @return fixed 值
  3642. */
  3643. function get_args($name) {
  3644. if (isset ( $_GET [$name] )) {
  3645. if (is_array ( $_GET [$name] ))
  3646. return $_GET [$name];
  3647. else
  3648. return addslashes ( $_GET [$name] );
  3649. } elseif (isset ( $_POST [$name] )) {
  3650. if (is_array ( $_POST [$name] ))
  3651. return $_POST [$name];
  3652. else
  3653. return addslashes ( $_POST [$name] );
  3654. } else
  3655. return false;
  3656. }
  3657. function SafeFilter(&$arr) {
  3658. $ra = Array (
  3659. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  3660. '/script/',
  3661. '/javascript/',
  3662. '/vbscript/',
  3663. '/expression/',
  3664. '/applet/',
  3665. '/meta/',
  3666. '/xml/',
  3667. '/blink/',
  3668. '/link/',
  3669. '/style/',
  3670. '/embed/',
  3671. '/object/',
  3672. '/frame/',
  3673. '/layer/',
  3674. '/title/',
  3675. '/bgsound/',
  3676. '/base/',
  3677. '/onload/',
  3678. '/onunload/',
  3679. '/onchange/',
  3680. '/onsubmit/',
  3681. '/onreset/',
  3682. '/onselect/',
  3683. '/onblur/',
  3684. '/onfocus/',
  3685. '/onabort/',
  3686. '/onkeydown/',
  3687. '/onkeypress/',
  3688. '/onkeyup/',
  3689. '/onclick/',
  3690. '/ondblclick/',
  3691. '/onmousedown/',
  3692. '/onmousemove/',
  3693. '/onmouseout/',
  3694. '/onmouseover/',
  3695. '/onmouseup/',
  3696. '/onunload/'
  3697. );
  3698. if (is_array ( $arr )) {
  3699. foreach ( $arr as $key => $value ) {
  3700. if (! is_array ( $value )) {
  3701. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  3702. {
  3703. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  3704. }
  3705. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  3706. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  3707. } else {
  3708. SafeFilter ( $arr [$key] );
  3709. }
  3710. }
  3711. }
  3712. }
  3713. /**
  3714. * Escape String
  3715. *
  3716. * @access public
  3717. * @param string
  3718. * @param bool whether or not the string will be used in a LIKE condition
  3719. * @return string
  3720. */
  3721. function escape_str($str, $like = FALSE) {
  3722. if (is_array ( $str )) {
  3723. foreach ( $str as $key => $val ) {
  3724. $str [$key] = $this->escape_str ( $val, $like );
  3725. }
  3726. return $str;
  3727. }
  3728. var_dump ( Doo::db ()->getDbObject () );
  3729. die ();
  3730. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  3731. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  3732. } elseif (function_exists ( 'mysql_escape_string' )) {
  3733. $str = mysql_escape_string ( $str );
  3734. } else {
  3735. $str = addslashes ( $str );
  3736. }
  3737. // escape LIKE condition wildcards
  3738. if ($like === TRUE) {
  3739. $str = str_replace ( array (
  3740. '%',
  3741. '_'
  3742. ), array (
  3743. '\\%',
  3744. '\\_'
  3745. ), $str );
  3746. }
  3747. return $str;
  3748. }
  3749. /**
  3750. * 获得分页数据
  3751. * @param unknown_type $table
  3752. * @param unknown_type $condition
  3753. * @param unknown_type $on_page
  3754. * @param unknown_type $page_size
  3755. */
  3756. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  3757. $page_c = "";
  3758. $page ['previous'] = $this->get_previous ( $on_page );
  3759. $page ['on_page'] = $on_page;
  3760. $total_count = $this->get_table_count ( $table, $condition );
  3761. $total = intval ( $total_count / $page_size );
  3762. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  3763. $page ['total_data'] = $total_count;
  3764. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  3765. $i = 1;
  3766. $page_max = 1;
  3767. $page_width = 3;
  3768. if ($on_page >= $page_width) {
  3769. $page_max = intval ( $on_page / $page_width ) + 1;
  3770. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  3771. }
  3772. for(; $i <= $page ['total_page']; $i ++) {
  3773. if ($i == $on_page)
  3774. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  3775. else
  3776. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  3777. if ($i == ($page_width * $page_max))
  3778. break;
  3779. }
  3780. $page ['page'] = $page_c;
  3781. $page ['lower'] = (-- $on_page) * $page_size;
  3782. return $page;
  3783. }
  3784. /**
  3785. * 获取上一页
  3786. * @param unknown_type $on_page
  3787. */
  3788. function get_previous($on_page = 1) {
  3789. return $on_page != 0 ? $on_page - 1 : $on_page;
  3790. }
  3791. /**
  3792. * 获取总页数
  3793. * @param unknown_type $table
  3794. * @param unknown_type $condition
  3795. */
  3796. public function get_table_count($table = "", $condition = "") {
  3797. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  3798. $sql = "select count(*) as count from " . $table . " where " . $condition;
  3799. // echo $sql;die;
  3800. $query = Doo::db ()->query ( $sql );
  3801. $result = $query->fetch ();
  3802. return $result ['count'];
  3803. }
  3804. function isInvoiceNew($type = "GLOBAL") {
  3805. Doo::loadModel ( 'invoice' );
  3806. $invoice = new invoice ();
  3807. Doo::loadModel ( 'invoiceReceivables' );
  3808. $invoiceReceivables = new invoiceReceivables ();
  3809. Doo::loadModel ( 'staff' );
  3810. $staff = new staff ();
  3811. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  3812. // 我的发票待处理
  3813. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  3814. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  3815. 'desc' => 'iid',
  3816. 'asArray' => TRUE
  3817. ) );
  3818. // 我的收款待入账
  3819. /*
  3820. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  3821. */
  3822. // 发票审批
  3823. $approval = $invoice->getOne ( array (
  3824. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  3825. 'desc' => 'iid',
  3826. 'asArray' => true
  3827. ) );
  3828. // 发票邮寄
  3829. $post = $invoice->getOne ( array (
  3830. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  3831. 'asArray' => TRUE
  3832. ) );
  3833. // 发票打印
  3834. $print = $invoice->getOne ( array (
  3835. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  3836. 'desc' => 'iid',
  3837. 'asArray' => TRUE
  3838. ) );
  3839. // 发票退票 printStatus=1 and
  3840. $untread = $invoice->getOne ( array (
  3841. 'where' => " untreadStatus=1 and status=2 ",
  3842. 'asArray' => TRUE
  3843. ) );
  3844. $new = array (
  3845. 'GLOBAL' => FALSE,
  3846. 'pendingInvoice' => FALSE,
  3847. // 'myClaim' => FALSE,
  3848. 'approval' => FALSE,
  3849. 'post' => FALSE,
  3850. 'print' => FALSE,
  3851. 'untread' => FALSE
  3852. );
  3853. // || ! empty ( $myClaim )
  3854. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  3855. $new ['GLOBAL'] = TRUE;
  3856. if (! empty ( $pendingInvoice ))
  3857. $new ['pendingInvoice'] = TRUE;
  3858. // if (! empty ( $myClaim ))
  3859. // $new ['myClaim'] = TRUE;
  3860. if (! empty ( $approval ))
  3861. $new ['approval'] = TRUE;
  3862. if (! empty ( $post ))
  3863. $new ['post'] = TRUE;
  3864. if (! empty ( $print ))
  3865. $new ['print'] = TRUE;
  3866. if (! empty ( $untread ))
  3867. $new ['untread'] = TRUE;
  3868. return $new;
  3869. }
  3870. function setWXMsg($rid, $typeMsg = '') {
  3871. Doo::loadModel ( 'invoice' );
  3872. $invoice = new invoice ();
  3873. $invoiceDetail = $invoice->getOne ( array (
  3874. 'where' => 'iid=' . $rid,
  3875. 'asArray' => true
  3876. ) );
  3877. if (! empty ( $invoiceDetail )) {
  3878. Doo::loadModel ( 'staff' );
  3879. $staff = new staff ();
  3880. $staffmsg = $staff->getOne ( array (
  3881. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  3882. 'asArray' => TRUE
  3883. ) );
  3884. if (! empty ( $staffmsg ['wxid'] )) {
  3885. require_once (SITE_PATH . '/protected/class/client.php');
  3886. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  3887. $user = $staffmsg ['wxid'];
  3888. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  3889. if (empty ( $expCom ))
  3890. $expCom [0] = '';
  3891. $msg = "";
  3892. if (empty ( $typeMsg ))
  3893. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  3894. elseif ($typeMsg == "PRINT")
  3895. $msg = '太好了,您的发票已打印完成。';
  3896. $result = $client->SendMsg ( $user, $msg, 'text' );
  3897. }
  3898. }
  3899. }
  3900. /**
  3901. * 获取微信部门
  3902. * @param string $category
  3903. * @return number|mixed
  3904. */
  3905. function getToparty($category = '') {
  3906. $token = $this->getAccessToken (); //
  3907. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  3908. $toparty = 0;
  3909. foreach ( $result ['department'] as $key => $value ) {
  3910. if ($value ['name'] == $category)
  3911. $toparty = $value ['id'];
  3912. }
  3913. return $toparty;
  3914. }
  3915. /**
  3916. * 获得某部门下的用户
  3917. * @param string $toparty
  3918. */
  3919. function getUserByToparty($toparty = '') {
  3920. $token = $this->getAccessToken (); //
  3921. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  3922. $userList = array ();
  3923. foreach ( $result ['userlist'] as $key => $value ) {
  3924. array_push ( $userList, "'" . $value ['userid'] . "'" );
  3925. }
  3926. return $userList;
  3927. }
  3928. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  3929. $token = $this->getAccessToken ();
  3930. if ($text == 'text') {
  3931. $data = '{
  3932. "touser": "",
  3933. "toparty": "' . $toparty . '",
  3934. "totag": "",
  3935. "msgtype": "text",
  3936. "agentid": 1000002,
  3937. "text": {
  3938. "content": "' . $msg . '"
  3939. },
  3940. "safe":0
  3941. }';
  3942. }
  3943. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  3944. if ($result->errmsg != 'ok') {
  3945. return 0;
  3946. } else {
  3947. return 1;
  3948. }
  3949. }
  3950. /**
  3951. * 获得可以发送微信用户列表
  3952. * @param string $category
  3953. * @return string
  3954. */
  3955. function getWxidByCategory($category = "") {
  3956. if (empty ( $category ))
  3957. return "";
  3958. Doo::loadModel ( 'staff' );
  3959. $staff = new staff ();
  3960. $toparty = $this->getToparty ( $category );
  3961. $wxList = array ();
  3962. $wxString = "";
  3963. if (! empty ( $toparty )) {
  3964. $userList = $this->getUserByToparty ( $toparty );
  3965. $userCon = implode ( ',', $userList );
  3966. // echo $userCon;
  3967. $sidList = $staff->getStaffByWxid ( $userCon );
  3968. foreach ( $sidList as $key => $value ) {
  3969. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  3970. if ($falg) {
  3971. array_push ( $wxList, $value ['wxid'] );
  3972. }
  3973. }
  3974. $wxString = implode ( '|', $wxList );
  3975. }
  3976. return $wxString;
  3977. }
  3978. /**
  3979. * 读取发送信息规则判断是否需要发送
  3980. * @param number $sid
  3981. * @param string $sendType
  3982. * @return boolean
  3983. */
  3984. function isSendNotification($sid = 0, $sendType = '') {
  3985. Doo::loadModel ( "notificationConf" );
  3986. $notificationConf = new notificationConf ();
  3987. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  3988. $conf = array ();
  3989. $sendFlag = true;
  3990. if (! empty ( $detail )) {
  3991. $conf = json_decode ( $detail ['conf'], true );
  3992. if (! empty ( $sendType )) {
  3993. if (isset ( $conf [$sendType] )) {
  3994. if ($conf [$sendType] == "CLOSE")
  3995. $sendFlag = false;
  3996. elseif ($conf [$sendType] == "Weekend") {
  3997. $day = date ( "w" );
  3998. if (1 <= $day && 5 >= $day)
  3999. $sendFlag = false;
  4000. } elseif ($conf [$sendType] == "OneToFriday") {
  4001. $day = date ( "w" );
  4002. if (0 == $day || 6 == $day)
  4003. $sendFlag = false;
  4004. }
  4005. }
  4006. } else
  4007. $sendFlag = false;
  4008. }
  4009. return $sendFlag;
  4010. }
  4011. /**
  4012. * 根据规则发送信息
  4013. * @param unknown $msg
  4014. * @param unknown $title
  4015. * @param unknown $url
  4016. * @param unknown $user
  4017. * @param string $text
  4018. * @return number
  4019. */
  4020. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  4021. $token = $this->getAccessToken ();
  4022. $falg = $this->isSendNotification ( $sid, $sendType );
  4023. // if ($text == 'text') {
  4024. // $data = '{
  4025. // "touser": "' . $user . '",
  4026. // "toparty": "",
  4027. // "totag": "",
  4028. // "msgtype": "text",
  4029. // "agentid": 1000002,
  4030. // "text": {
  4031. // "content": "' . $msg . '"
  4032. // },
  4033. // "safe":0
  4034. // }';
  4035. // } else {
  4036. $data = '{
  4037. "touser": "' . $user . '",
  4038. "toparty": "",
  4039. "totag": "",
  4040. "msgtype": "news",
  4041. "agentid": 1000002,
  4042. "news": {
  4043. "articles":[
  4044. {
  4045. "title": "' . $title . '",
  4046. "description": "' . $msg . '",
  4047. "url": "' . $url . '",
  4048. "picurl": ""
  4049. }
  4050. ]
  4051. }
  4052. }';
  4053. // }
  4054. if ($falg) {
  4055. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  4056. if ($result->errmsg != 'ok') {
  4057. return 0;
  4058. } else {
  4059. return 1;
  4060. }
  4061. } else
  4062. return 0;
  4063. }
  4064. private function getAccessToken() {
  4065. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  4066. // $file = './access_token.txt';
  4067. // $data = json_decode ( file_get_contents ( $file ) );
  4068. // if ($data->expire_time < time () or ! $data->expire_time) {
  4069. // 如果是企业号用以下URL获取access_token
  4070. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  4071. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  4072. $res = json_decode ( $this->httpGet ( $url ) );
  4073. $access_token = $res->access_token;
  4074. // echo $access_token;
  4075. // if ($access_token) {
  4076. // $data->expire_time = time () + 7000;
  4077. // $data->access_token = $access_token;
  4078. // $fp = fopen ( $file, "w" );
  4079. // fwrite ( $fp, json_encode ( $data ) );
  4080. // fclose ( $fp );
  4081. // }
  4082. // } else {
  4083. // $access_token = $data->access_token;
  4084. // }
  4085. return $access_token;
  4086. }
  4087. private function httpGet($url) {
  4088. $curl = curl_init ();
  4089. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  4090. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  4091. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  4092. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  4093. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  4094. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  4095. curl_setopt ( $curl, CURLOPT_URL, $url );
  4096. $res = curl_exec ( $curl );
  4097. curl_close ( $curl );
  4098. return $res;
  4099. }
  4100. private function httpPost($url, $data) {
  4101. $curl = curl_init ();
  4102. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  4103. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  4104. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  4105. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  4106. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  4107. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  4108. curl_setopt ( $curl, CURLOPT_URL, $url );
  4109. curl_setopt ( $curl, CURLOPT_POST, 1 );
  4110. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  4111. $res = curl_exec ( $curl );
  4112. curl_close ( $curl );
  4113. return $res;
  4114. }
  4115. }
  4116. ?>