InvoiceController.php 160 KB

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