InvoiceController.php 167 KB

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