InvoiceController.php 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015
  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. public function beforeRun($resource, $action) {
  17. Doo::loadModel ( "invoiceManage" );
  18. $invoiceManage = new invoiceManage ();
  19. header ( 'Content-Type:text/html;charset=utf-8' );
  20. $moldList = $invoiceManage->getInvoiceByStaff ( $_COOKIE ["staff"] );
  21. // print_r($moldList);
  22. if (empty ( $moldList )) {
  23. $flag = false;
  24. $uGroups = 'ordinary';
  25. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  26. $flag = true;
  27. }
  28. } else {
  29. $flag = false;
  30. array_push ( $moldList, array (
  31. 'mold' => 'ordinary'
  32. ) );
  33. foreach ( $moldList as $value ) {
  34. // echo $value['mold'];
  35. // echo $action;
  36. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  37. $flag = true;
  38. break;
  39. }
  40. }
  41. }
  42. /*
  43. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  44. */
  45. // var_dump($flag) ;
  46. if (! $flag)
  47. die ( 'illegal request' );
  48. }
  49. function __construct() {
  50. if (isset ( $_COOKIE ["staff"] )) {
  51. if (! empty ( $_COOKIE ["staff"] )) {
  52. Doo::loadModel ( 'staff' );
  53. $staff = new staff ();
  54. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  55. $this->ACTION = $uriPartsOrig [1];
  56. $this->data ['new'] = $this->isInvoiceNew ();
  57. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  58. return "/";
  59. }
  60. }
  61. Doo::loadCore ( 'uri/DooUriRouter' );
  62. $router = new DooUriRouter ();
  63. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  64. if ($routeRs ['1'] != "login") {
  65. header ( 'Content-Type:text/html;charset=utf-8' );
  66. @header ( "Location: /login" );
  67. }
  68. }
  69. function invoice() {
  70. Doo::loadModel ( 'invoice' );
  71. $invoice = new invoice ();
  72. Doo::loadModel ( 'express' );
  73. $express = new express ();
  74. Doo::loadModel ( 'invoiceReceivables' );
  75. $invoiceReceivables = new invoiceReceivables ();
  76. Doo::loadModel ( 'invoiceStatistics' );
  77. $invoiceStatistics = new invoiceStatistics ();
  78. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  79. $year = date ( "Y" );
  80. $tmp_date = date ( "Ym" );
  81. $tmp_year = substr ( $tmp_date, 0, 4 );
  82. $tmp_mon = substr ( $tmp_date, 4, 2 );
  83. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  84. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  85. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  86. $htm = $this->showCache ( $path );
  87. $expressList = $express->getExpressByAll ();
  88. $invoiceList = $invoice->getMyInvoice ( $_COOKIE ["staff"] );
  89. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  90. $sql = 'status=2 and untreadStatus=3 and sid=' . $_COOKIE ["staff"];
  91. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  92. // print_r($list);
  93. $this->data ['isMonth'] = $isMonth;
  94. $this->data ['htm'] = $htm;
  95. $this->data ['expressList'] = $expressList;
  96. $this->data ['invoiceList'] = $invoiceList;
  97. $this->data ['receivablesList'] = $list;
  98. $this->data ['memu'] = "invoice";
  99. $this->data ['staff'] = $this->staff;
  100. $this->data ['receiptMemu'] = 'invoice';
  101. $this->render ( "/admin/invoice", $this->data );
  102. }
  103. function invoiceAdd() {
  104. Doo::loadModel ( 'L_category' );
  105. $lCategory = new L_category ();
  106. $category = $lCategory->find ( array (
  107. 'asArray' => true
  108. ) );
  109. $this->data ['category'] = $category;
  110. $this->data ['memu'] = "invoice";
  111. $this->data ['staff'] = $this->staff;
  112. $this->data ['receiptMemu'] = 'invoice';
  113. $this->render ( "/admin/invoiceAdd", $this->data );
  114. }
  115. /**
  116. * 提交一份开票申请,并记录下操作日志
  117. *
  118. * @since 1.0.0
  119. * @var integer cid 办事处ID
  120. * @var integer invoiceType 发票类型
  121. * @var integer doPost 是否邮寄
  122. * @var integer invoicePrice 开票金额
  123. * @var string invoiceElement 开票内容
  124. * @var string invoiceTitle 发票抬头
  125. * @var string invoiceCompany 单位名称
  126. * @var string TIN 纳税人识别码
  127. * @var string address 注册地址
  128. * @var string phone 注册电话
  129. * @var string bank 开户银行
  130. * @var string bankAccount 银行账户
  131. * @var string recipients 收件人
  132. * @var string recipientsPhone 收件人手机/电话
  133. * @var string recipientsAddress 收件地址
  134. * @var string mailItems 邮寄物品
  135. * @var string remark 备注
  136. * @return string 返回跳转开票主页路径
  137. */
  138. function invoiceAddDo() {
  139. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  140. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  141. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  142. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  143. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  144. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  145. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  146. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  147. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  148. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  149. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  150. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  151. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  152. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  153. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  154. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  155. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  156. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement )) {
  157. Doo::loadModel ( 'invoice' );
  158. $invoice = new invoice ();
  159. Doo::loadModel ( 'L_category' );
  160. $lCategory = new L_category ();
  161. Doo::loadModel ( 'invoiceManage' );
  162. $invoiceManage = new invoiceManage ();
  163. Doo::loadModel ( 'invoiceOperationLog' );
  164. $invoiceOperationLog = new invoiceOperationLog ();
  165. Doo::loadModel ( 'invoiceStatistics' );
  166. $invoiceStatistics = new invoiceStatistics ();
  167. $categoryDetil = $lCategory->getOne ( array (
  168. 'SELECT' => 'title',
  169. 'where' => 'cid=' . $cid,
  170. 'asArray' => true
  171. ) );
  172. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  173. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  174. $moldManage = array ();
  175. foreach ( $invoiceManageList as $key => $value ) {
  176. if ($value ['mold'] == '发票打印')
  177. $moldManage [$value ['mold']] = $value ['staffList'];
  178. elseif ($value ['mold'] == '发票邮寄')
  179. $moldManage [$value ['mold']] = $value ['staffList'];
  180. elseif ($value ['mold'] == '发票退票')
  181. $moldManage [$value ['mold']] = $value ['staffList'];
  182. }
  183. $item = array (
  184. 'cid' => $cid,
  185. 'categoryName' => $categoryDetil ['title'],
  186. 'invoiceElement' => $invoiceElement,
  187. 'invoicePrice' => $invoicePrice,
  188. 'invoiceType' => $invoiceType,
  189. 'doPost' => $doPost,
  190. 'status' => 1,
  191. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  192. 'date' => date ( "Y-m-d H:i:s" ),
  193. 'updateTime' => date ( "Y-m-d H:i:s" ),
  194. 'sid' => $this->staff [0] ['sid'],
  195. 'userName' => $this->staff [0] ['username'],
  196. 'invoiceManage' => $invoiceManageDetail ['staff'],
  197. 'pendingApprovals' => $invoiceManageDetail ['staffList'] [0] [0],
  198. 'moldManage' => json_encode ( $moldManage ),
  199. 'remark' => $remark
  200. );
  201. if ($invoiceType == 0)
  202. $item += array (
  203. 'invoiceTitle' => $invoiceTitle
  204. );
  205. else {
  206. $item += array (
  207. 'invoiceCompany' => $invoiceCompany,
  208. 'TIN' => $TIN,
  209. 'address' => $address,
  210. 'phone' => $phone,
  211. 'bank' => $bank,
  212. 'bankAccount' => $bankAccount
  213. );
  214. }
  215. if ($doPost == 1) {
  216. $item += array (
  217. 'recipients' => $recipients,
  218. 'recipientsPhone' => $recipientsPhone,
  219. 'recipientsAddress' => $recipientsAddress,
  220. 'mailItems' => $mailItems
  221. );
  222. }
  223. $iid = $invoice->addInvoice ( $item );
  224. $item = array (
  225. 'date' => date ( "Y-m-d H:i:s" ),
  226. 'operation' => "创建",
  227. 'status' => 1,
  228. 'img' => $this->staff [0] ['avatar'],
  229. 'username' => $this->staff [0] ['username'],
  230. 'uid' => $this->staff [0] ['sid'],
  231. 'category' => $this->staff [0] ['category'],
  232. 'iid' => $iid
  233. );
  234. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  235. $item = array (
  236. 'date' => date ( "Y-m-d H:i:s" ),
  237. 'operation' => "提交审批",
  238. 'status' => 1,
  239. 'img' => $this->staff [0] ['avatar'],
  240. 'username' => $this->staff [0] ['username'],
  241. 'uid' => $this->staff [0] ['sid'],
  242. 'category' => $this->staff [0] ['category'],
  243. 'iid' => $iid
  244. );
  245. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  246. $item = array (
  247. 'date' => date ( "Y-m-d H:i:s" ),
  248. 'priceClass' => 1,
  249. 'cid' => $this->staff [0] ['cid'],
  250. 'staff' => $this->staff [0] ['sid'],
  251. 'invoicePrice' => $invoicePrice
  252. );
  253. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  254. }
  255. return "/invoice";
  256. }
  257. function invoiceEdit() {
  258. Doo::loadClass ( 'XDeode' );
  259. $XDeode = new XDeode ( 5 );
  260. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  261. $iid = $XDeode->decode ( $iid );
  262. if (! is_numeric ( $iid ))
  263. die ( 'illegal request' );
  264. Doo::loadModel ( 'invoice' );
  265. $invoice = new invoice ();
  266. Doo::loadModel ( 'invoiceOperationLog' );
  267. $invoiceOperationLog = new invoiceOperationLog ();
  268. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  269. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  270. $this->data ['operation'] = $operation;
  271. $this->data ['invoiceDetail'] = $invoiceDetail;
  272. $this->data ['memu'] = "invoice";
  273. $this->data ['staff'] = $this->staff;
  274. $this->data ['receiptMemu'] = 'invoice';
  275. $this->render ( "/admin/invoiceEdit", $this->data );
  276. }
  277. /**
  278. * 重新编辑退回的发票
  279. * @return string
  280. */
  281. function invoiceEditDo() {
  282. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  283. Doo::loadModel ( 'invoice' );
  284. $invoice = new invoice ();
  285. $iid = $invoice->authcode ( $iidKey );
  286. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  287. die ( 'illegal request' );
  288. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  289. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  290. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  291. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  292. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  293. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  294. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  295. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  296. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  297. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  298. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  299. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  300. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  301. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  302. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  303. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  304. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  305. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  306. Doo::loadModel ( 'invoiceManage' );
  307. $invoiceManage = new invoiceManage ();
  308. Doo::loadModel ( 'invoiceOperationLog' );
  309. $invoiceOperationLog = new invoiceOperationLog ();
  310. $cid = explode ( ':', $cid );
  311. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  312. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  313. $moldManage = array ();
  314. foreach ( $invoiceManageList as $key => $value ) {
  315. if ($value ['mold'] == '发票打印')
  316. $moldManage [$value ['mold']] = $value ['staffList'];
  317. elseif ($value ['mold'] == '发票邮寄')
  318. $moldManage [$value ['mold']] = $value ['staffList'];
  319. elseif ($value ['mold'] == '发票打印')
  320. $moldManage [$value ['mold']] = $value ['staffList'];
  321. }
  322. $item = array (
  323. 'iid' => $iid,
  324. 'cid' => $cid [0],
  325. 'categoryName' => $cid [1],
  326. 'invoiceElement' => $invoiceElement,
  327. 'invoicePrice' => $invoicePrice,
  328. 'invoiceType' => $invoiceType,
  329. 'doPost' => $doPost,
  330. 'status' => 1,
  331. 'updateTime' => date ( "Y-m-d H:i:s" ),
  332. 'remark' => $remark
  333. );
  334. if ($invoiceType == 0)
  335. $item += array (
  336. 'invoiceTitle' => $invoiceTitle
  337. );
  338. else {
  339. $item += array (
  340. 'invoiceCompany' => $invoiceCompany,
  341. 'TIN' => $TIN,
  342. 'address' => $address,
  343. 'phone' => $phone,
  344. 'bank' => $bank,
  345. 'bankAccount' => $bankAccount
  346. );
  347. }
  348. if ($doPost == 1) {
  349. $item += array (
  350. 'recipients' => $recipients,
  351. 'recipientsPhone' => $recipientsPhone,
  352. 'recipientsAddress' => $recipientsAddress,
  353. 'mailItems' => $mailItems
  354. );
  355. }
  356. $invoice->setInvoiceByCondition ( $item );
  357. $item = array (
  358. 'date' => date ( "Y-m-d H:i:s" ),
  359. 'operation' => "重新提交审批",
  360. 'status' => 1,
  361. 'img' => $this->staff [0] ['avatar'],
  362. 'username' => $this->staff [0] ['username'],
  363. 'uid' => $this->staff [0] ['sid'],
  364. 'category' => $this->staff [0] ['category'],
  365. 'iid' => $iid
  366. );
  367. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  368. }
  369. return "/invoice";
  370. }
  371. /**
  372. * 终止开票
  373. */
  374. function invoiceDroppedDo() {
  375. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  376. Doo::loadModel ( 'invoice' );
  377. $invoice = new invoice ();
  378. Doo::loadModel ( 'invoiceOperationLog' );
  379. $invoiceOperationLog = new invoiceOperationLog ();
  380. $iid = $invoice->authcode ( $droppedIidKey );
  381. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  382. die ( 'illegal request' );
  383. $item = array (
  384. 'iid' => $iid,
  385. 'status' => 4,
  386. 'updateTime' => date ( "Y-m-d H:i:s" )
  387. );
  388. $invoice->setInvoiceByCondition ( $item );
  389. $item = array (
  390. 'date' => date ( "Y-m-d H:i:s" ),
  391. 'operation' => '终止了开票',
  392. 'status' => 4,
  393. 'img' => $this->staff [0] ['avatar'],
  394. 'username' => $this->staff [0] ['username'],
  395. 'uid' => $this->staff [0] ['sid'],
  396. 'category' => $this->staff [0] ['category'],
  397. 'iid' => $iid
  398. );
  399. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  400. return "/invoice";
  401. }
  402. /**
  403. * 申请退票
  404. */
  405. function invoiceUntreadDo() {
  406. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  407. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  408. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  409. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  410. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  411. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  412. Doo::loadModel ( 'invoice' );
  413. $invoice = new invoice ();
  414. Doo::loadModel ( 'invoiceOperationLog' );
  415. $invoiceOperationLog = new invoiceOperationLog ();
  416. Doo::loadModel ( 'invoiceReceivables' );
  417. $invoiceReceivables = new invoiceReceivables ();
  418. $iid = $invoice->authcode ( $untreadIidKey );
  419. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  420. die ( 'illegal request' );
  421. $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey );
  422. if (! empty ( $lt )) {
  423. header ( 'Content-Type:text/html;charset=utf-8' );
  424. die ( '该发票有收款绑定,请先移除!' );
  425. }
  426. $item = array (
  427. 'iid' => $iid,
  428. 'untreadStatus' => 1,
  429. 'untreadReason' => $untreadReason,
  430. 'untreadPost' => $untreadPost,
  431. 'updateTime' => date ( "Y-m-d H:i:s" )
  432. );
  433. if ($untreadPost == 1) {
  434. $item += array (
  435. 'untreadCompany' => $untreadCompany,
  436. 'untreadNumber' => $untreadNumber,
  437. 'untreadItems' => $untreadItems
  438. );
  439. }
  440. $invoice->setInvoiceByCondition ( $item );
  441. $item = array (
  442. 'date' => date ( "Y-m-d H:i:s" ),
  443. 'operation' => '申请退票',
  444. 'status' => 7,
  445. 'img' => $this->staff [0] ['avatar'],
  446. 'username' => $this->staff [0] ['username'],
  447. 'uid' => $this->staff [0] ['sid'],
  448. 'category' => $this->staff [0] ['category'],
  449. 'iid' => $iid
  450. );
  451. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  452. return "/invoice";
  453. }
  454. /**
  455. * 删除已终止的开票
  456. */
  457. function invoiceDelDo() {
  458. Doo::loadClass ( 'XDeode' );
  459. $XDeode = new XDeode ( 5 );
  460. Doo::loadModel ( 'invoice' );
  461. $invoice = new invoice ();
  462. Doo::loadModel ( 'invoiceOperationLog' );
  463. $invoiceOperationLog = new invoiceOperationLog ();
  464. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  465. $iid = $XDeode->decode ( $iid );
  466. if (! is_numeric ( $iid ))
  467. die ( 'illegal request' );
  468. $invoiceDetail = $invoice->getMyInvoice ( $_COOKIE ["staff"], $iid );
  469. if (empty ( $invoiceDetail ))
  470. die ( 'illegal request' );
  471. $item = array (
  472. 'iid' => $iid,
  473. 'isDelete' => 1,
  474. 'updateTime' => date ( "Y-m-d H:i:s" )
  475. );
  476. $invoice->setInvoiceByCondition ( $item );
  477. $item = array (
  478. 'date' => date ( "Y-m-d H:i:s" ),
  479. 'operation' => '删除了已终止的发票',
  480. 'status' => 4,
  481. 'img' => $this->staff [0] ['avatar'],
  482. 'username' => $this->staff [0] ['username'],
  483. 'uid' => $this->staff [0] ['sid'],
  484. 'category' => $this->staff [0] ['category'],
  485. 'iid' => $iid
  486. );
  487. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  488. return "/invoice";
  489. }
  490. function invoiceApproval() {
  491. Doo::loadModel ( 'invoice' );
  492. $invoice = new invoice ();
  493. Doo::loadClass ( 'XDeode' );
  494. $XDeode = new XDeode ( 5 );
  495. Doo::loadModel ( 'staff' );
  496. $staff = new staff ();
  497. $invoiceList = $invoice->find ( array (
  498. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  499. 'desc' => 'iid',
  500. 'asArray' => true
  501. ) );
  502. foreach ( $invoiceList as $key => $value ) {
  503. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  504. $lastApprover = json_decode ( $value ['processApprovals'], true );
  505. if (! empty ( $lastApprover )) {
  506. $lastApproverKey = array_keys ( $lastApprover );
  507. $lastApprover = end ( $lastApprover );
  508. $staffDetail = $staff->getOne ( array (
  509. 'where' => 'sid=' . end ( $lastApproverKey ),
  510. 'asArray' => true
  511. ) );
  512. $lastApprover ['username'] = $staffDetail ['username'];
  513. }
  514. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  515. }
  516. $ilist = $invoice->getInvoiceByProcessStatus ();
  517. // print_r($ilist);
  518. $this->data ['invoiceList'] = $invoiceList;
  519. $this->data ['ilist'] = $ilist;
  520. $this->data ['memu'] = "invoice";
  521. $this->data ['staff'] = $this->staff;
  522. $this->data ['receiptMemu'] = 'invoiceApproval';
  523. $this->render ( "/admin/invoiceApproval", $this->data );
  524. }
  525. function invoiceDetail() {
  526. Doo::loadClass ( 'XDeode' );
  527. $XDeode = new XDeode ( 5 );
  528. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  529. $iid = $XDeode->decode ( $iid );
  530. if (! is_numeric ( $iid ))
  531. die ( 'illegal request' );
  532. Doo::loadModel ( 'invoice' );
  533. $invoice = new invoice ();
  534. Doo::loadModel ( 'invoiceOperationLog' );
  535. $invoiceOperationLog = new invoiceOperationLog ();
  536. $invoiceDetail = $invoice->getOne ( array (
  537. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  538. 'asArray' => true
  539. ) );
  540. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  541. $this->data ['invoiceDetail'] = $invoiceDetail;
  542. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  543. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  544. $this->data ['memu'] = "invoice";
  545. $this->data ['staff'] = $this->staff;
  546. $this->data ['receiptMemu'] = 'invoiceApproval';
  547. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  548. }
  549. /**
  550. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  551. *
  552. * @since 1.0.0
  553. * @var integer iid 开票ID 已加密
  554. * @var integer status 发票审批状态
  555. * @var integer opintion 审批发票的意见
  556. * @return string 如操作成功返回审批首页
  557. */
  558. function invoiceApprovalDo() {
  559. Doo::loadModel ( 'invoice' );
  560. $invoice = new invoice ();
  561. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  562. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  563. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  564. $iid = $invoice->authcode ( $iid );
  565. if (! is_numeric ( $iid ))
  566. die ( 'illegal request' );
  567. if (! empty ( $iid ) && ! empty ( $status ) && ! empty ( $opinion )) {
  568. if (! ($status == 2 || $status == 3 || $status == 4))
  569. die ( 'illegal request' );
  570. Doo::loadModel ( 'invoiceOperationLog' );
  571. $invoiceOperationLog = new invoiceOperationLog ();
  572. $invoiceDetail = $invoice->getOne ( array (
  573. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  574. 'asArray' => true
  575. ) );
  576. if (empty ( $invoiceDetail ))
  577. die ( 'illegal request' );
  578. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  579. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  580. if ($status == 3) {
  581. $invoice->status = $status;
  582. $item = array (
  583. 'operation' => $opinion
  584. );
  585. } else {
  586. if (empty ( $processApprovals )) {
  587. $processApprovals = array (
  588. $this->staff [0] ['sid'] => array (
  589. 'date' => date ( "Y-m-d H:i:s" ),
  590. 'opinion' => $opinion,
  591. 'status' => $status
  592. )
  593. );
  594. if ($status != 4 && isset ( $invoiceManage [1] ))
  595. $invoice->pendingApprovals = $invoiceManage [1] [0];
  596. $invoice->processApprovals = json_encode ( $processApprovals );
  597. } else {
  598. $processApprovals [$this->staff [0] ['sid']] = array (
  599. 'date' => date ( "Y-m-d H:i:s" ),
  600. 'opinion' => $opinion,
  601. 'status' => $status
  602. );
  603. $pendingApprovals = 0;
  604. foreach ( $invoiceManage as $key => $value ) {
  605. if ($value [0] == $this->staff [0] ['sid']) {
  606. if (isset ( $invoiceManage [$key + 1] ))
  607. $pendingApprovals = $invoiceManage [$key + 1] [0];
  608. break;
  609. }
  610. }
  611. if ($status != 4 && ! empty ( $pendingApprovals ))
  612. $invoice->pendingApprovals = $pendingApprovals;
  613. $invoice->processApprovals = json_encode ( $processApprovals );
  614. }
  615. $item = array (
  616. 'operation' => $opinion
  617. );
  618. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  619. $invoice->status = $status;
  620. $invoice->pendingApprovals = 0;
  621. } elseif ($status == 4) {
  622. $invoice->status = $status;
  623. $item = array (
  624. 'operation' => $opinion
  625. );
  626. }
  627. }
  628. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  629. $invoice->update ( array (
  630. 'where' => 'iid=' . $iid
  631. ) );
  632. $item += array (
  633. 'date' => date ( "Y-m-d H:i:s" ),
  634. 'img' => $this->staff [0] ['avatar'],
  635. 'username' => $this->staff [0] ['username'],
  636. 'uid' => $this->staff [0] ['sid'],
  637. 'category' => $this->staff [0] ['category'],
  638. 'status' => $status,
  639. 'iid' => $iid
  640. );
  641. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  642. return '/invoiceApproval';
  643. }
  644. die ( 'illegal request' );
  645. }
  646. /**
  647. * 展示需要打印的发票数据
  648. *
  649. * @since 1.0.0
  650. */
  651. function invoicePrint() {
  652. Doo::loadModel ( 'invoice' );
  653. $invoice = new invoice ();
  654. Doo::loadClass ( 'XDeode' );
  655. $XDeode = new XDeode ( 5 );
  656. Doo::loadModel ( 'staff' );
  657. $staff = new staff ();
  658. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  659. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  660. foreach ( $toPrint as $key => $value ) {
  661. $toPrint [$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. $toPrint [$key] ['lastApprover'] = $lastApprover;
  673. }
  674. foreach ( $printed as $key => $value ) {
  675. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  676. $lastApprover = json_decode ( $value ['processApprovals'], true );
  677. if (! empty ( $lastApprover )) {
  678. $lastApproverKey = array_keys ( $lastApprover );
  679. $lastApprover = end ( $lastApprover );
  680. $staffDetail = $staff->getOne ( array (
  681. 'where' => 'sid=' . end ( $lastApproverKey ),
  682. 'asArray' => true
  683. ) );
  684. $lastApprover ['username'] = $staffDetail ['username'];
  685. }
  686. $printed [$key] ['lastApprover'] = $lastApprover;
  687. }
  688. $this->data ['printed'] = $printed;
  689. $this->data ['toPrint'] = $toPrint;
  690. $this->data ['memu'] = "invoice";
  691. $this->data ['staff'] = $this->staff;
  692. $this->data ['receiptMemu'] = 'invoicePrint';
  693. $this->render ( "/admin/invoicePrint", $this->data );
  694. }
  695. /**
  696. * 展示发票打印的详情页面
  697. *
  698. * @since 1.0.0
  699. */
  700. function invoicePrintDetail() {
  701. Doo::loadClass ( 'XDeode' );
  702. $XDeode = new XDeode ( 5 );
  703. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  704. $iid = $XDeode->decode ( $iid );
  705. if (! is_numeric ( $iid ))
  706. die ( 'illegal request' );
  707. Doo::loadModel ( 'invoice' );
  708. $invoice = new invoice ();
  709. Doo::loadModel ( 'invoiceOperationLog' );
  710. $invoiceOperationLog = new invoiceOperationLog ();
  711. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  712. // if (empty ( $invoiceDetail ))
  713. // die ( 'illegal request' );
  714. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  715. $this->data ['invoiceDetail'] = $invoiceDetail;
  716. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  717. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  718. $this->data ['memu'] = "invoice";
  719. $this->data ['staff'] = $this->staff;
  720. $this->data ['receiptMemu'] = 'invoicePrint';
  721. $this->render ( "/admin/invoicePrintDetail", $this->data );
  722. }
  723. /**
  724. * 填写票号并完成打印
  725. * @since 1.0.0
  726. */
  727. function invoicePrintDo() {
  728. Doo::loadModel ( 'invoice' );
  729. $invoice = new invoice ();
  730. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  731. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  732. $iid = $invoice->authcode ( $iid );
  733. if (! is_numeric ( $iid ))
  734. die ( 'illegal request' );
  735. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  736. Doo::loadModel ( 'invoiceOperationLog' );
  737. $invoiceOperationLog = new invoiceOperationLog ();
  738. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  739. if (empty ( $invoicePrintDetail ))
  740. die ( 'illegal request' );
  741. $item = array (
  742. 'iid' => $iid,
  743. 'printStatus' => 1,
  744. 'updateTime' => date ( "Y-m-d H:i:s" ),
  745. 'printTime' => date ( "Y-m-d H:i:s" ),
  746. 'invoiceNo' => $invoiceNo
  747. );
  748. $invoice->setInvoiceByCondition ( $item );
  749. $item = array (
  750. 'date' => date ( "Y-m-d H:i:s" ),
  751. 'operation' => $invoiceNo,
  752. 'status' => 5,
  753. 'img' => $this->staff [0] ['avatar'],
  754. 'username' => $this->staff [0] ['username'],
  755. 'uid' => $this->staff [0] ['sid'],
  756. 'category' => $this->staff [0] ['category'],
  757. 'iid' => $iid
  758. );
  759. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  760. return "/invoicePrint";
  761. }
  762. }
  763. /**
  764. * 需要邮寄的发票
  765. * @since 1.0.0
  766. */
  767. function invoicePost() {
  768. Doo::loadModel ( 'invoice' );
  769. $invoice = new invoice ();
  770. Doo::loadModel ( 'express' );
  771. $express = new express ();
  772. $invoicePost = $invoice->getPostByInvoice ();
  773. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  774. $expressList = $express->getExpressByAll ();
  775. $this->data ['expressList'] = $expressList;
  776. $this->data ['invoicePost'] = $invoicePost;
  777. $this->data ['invoicePosted'] = $invoicePosted;
  778. $this->data ['memu'] = "invoice";
  779. $this->data ['staff'] = $this->staff;
  780. $this->data ['receiptMemu'] = 'invoicePost';
  781. $this->render ( "/admin/invoicePost", $this->data );
  782. }
  783. /**
  784. * 添加发票邮寄信息
  785. */
  786. function invoiceExpressAddDo() {
  787. Doo::loadModel ( 'invoice' );
  788. $invoice = new invoice ();
  789. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  790. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  791. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  792. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  793. $iid = $iid = $invoice->authcode ( $iid );
  794. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  795. die ( 'illegal request' );
  796. $item = array (
  797. 'iid' => $iid,
  798. 'postStatus' => 1,
  799. 'updateTime' => date ( "Y-m-d H:i:s" ),
  800. 'postTime' => date ( "Y-m-d H:i:s" ),
  801. 'expressCompany' => $expressCompany,
  802. 'expressNumber' => $expressNumber,
  803. 'actualItems' => $actualItems,
  804. 'poster' => $this->staff [0] ['username']
  805. );
  806. $invoice->setInvoiceByCondition ( $item );
  807. return '/invoicePost';
  808. }
  809. function invoiceExpressUpdateDo() {
  810. Doo::loadModel ( 'invoice' );
  811. $invoice = new invoice ();
  812. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  813. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  814. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  815. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  816. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  817. $iid = $invoice->authcode ( $iid );
  818. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  819. die ( 'illegal request' );
  820. $item = array (
  821. 'iid' => $iid,
  822. 'updateTime' => date ( "Y-m-d H:i:s" ),
  823. 'expressCompany' => $expressCompany,
  824. 'expressNumber' => $expressNumber,
  825. 'actualItems' => $actualItems,
  826. 'poster' => $this->staff [0] ['username']
  827. );
  828. $invoice->setInvoiceByCondition ( $item );
  829. return $action;
  830. }
  831. /**
  832. * 退票处理页面
  833. */
  834. function invoiceUntread() {
  835. Doo::loadModel ( 'invoice' );
  836. $invoice = new invoice ();
  837. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  838. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  839. $this->data ['untreadInvoice'] = $untreadInvoice;
  840. $this->data ['establishedInvoice'] = $establishedInvoice;
  841. $this->data ['memu'] = "invoice";
  842. $this->data ['staff'] = $this->staff;
  843. $this->data ['receiptMemu'] = 'invoiceUntread';
  844. $this->render ( "/admin/invoiceUntread", $this->data );
  845. }
  846. /**
  847. * 确认收到退回的发票,开票状态为退回
  848. */
  849. function invoiceUntreadEstablishedDo() {
  850. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  851. Doo::loadModel ( 'invoice' );
  852. $invoice = new invoice ();
  853. Doo::loadModel ( 'invoiceOperationLog' );
  854. $invoiceOperationLog = new invoiceOperationLog ();
  855. $iid = $invoice->authcode ( $untreadIidKey );
  856. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  857. die ( 'illegal request' );
  858. $item = array (
  859. 'iid' => $iid,
  860. 'untreadStatus' => 2,
  861. 'updateTime' => date ( "Y-m-d H:i:s" )
  862. );
  863. $invoice->setInvoiceByCondition ( $item );
  864. $item = array (
  865. 'date' => date ( "Y-m-d H:i:s" ),
  866. 'operation' => '已确认退票',
  867. 'status' => 6,
  868. 'img' => $this->staff [0] ['avatar'],
  869. 'username' => $this->staff [0] ['username'],
  870. 'uid' => $this->staff [0] ['sid'],
  871. 'category' => $this->staff [0] ['category'],
  872. 'iid' => $iid
  873. );
  874. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  875. return "/invoiceUntread";
  876. }
  877. function invoiceReceivables() {
  878. Doo::loadModel ( 'L_category' );
  879. $lCategory = new L_category ();
  880. Doo::loadModel ( 'staff' );
  881. $staff = new staff ();
  882. Doo::loadModel ( 'invoiceReceivables' );
  883. $invoiceReceivables = new invoiceReceivables ();
  884. $category = $lCategory->getCategory ();
  885. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  886. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ();
  887. // print_r($receivablesList);
  888. $this->data ['receivablesList'] = $receivablesList;
  889. $this->data ['staffList'] = $staffList;
  890. $this->data ['category'] = $category;
  891. $this->data ['memu'] = "invoice";
  892. $this->data ['staff'] = $this->staff;
  893. $this->data ['receiptMemu'] = 'invoiceReceivables';
  894. $this->render ( "/admin/invoiceReceivables", $this->data );
  895. }
  896. /**
  897. * 录入收款数据
  898. * @return string
  899. */
  900. function invoiceReceivablesDo() {
  901. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  902. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  903. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  904. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  905. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  906. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  907. Doo::loadModel ( 'invoiceReceivables' );
  908. $invoiceReceivables = new invoiceReceivables ();
  909. Doo::loadModel ( 'invoiceROLog' );
  910. $invoiceROLog = new invoiceROLog ();
  911. Doo::loadModel ( 'invoiceStatistics' );
  912. $invoiceStatistics = new invoiceStatistics ();
  913. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  914. $item = array (
  915. 'receivablesPrice' => $receivablesPrice,
  916. 'receivablesMessage' => $receivablesMessage,
  917. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  918. 'receivablesBank' => $receivablesBank,
  919. 'receivablesDate' => $receivablesDate,
  920. 'inputStaff' => $this->staff [0] ['username'],
  921. 'date' => date ( "Y-m-d" ),
  922. 'receivablesCategory' => $receivablesCategory,
  923. 'receivablesStaff' => $receivablesStaff
  924. );
  925. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  926. $item += array (
  927. 'confirmTime' => date ( "Y-m-d H:i:s" )
  928. );
  929. }
  930. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  931. $item = array ();
  932. // 收款操作日志
  933. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  934. $item = array (
  935. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  936. );
  937. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  938. $item = array (
  939. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  940. );
  941. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  942. $receivablesStaff = explode ( '-', $receivablesStaff );
  943. $item = array (
  944. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  945. );
  946. }
  947. $item += array (
  948. 'date' => date ( "Y-m-d" ),
  949. 'status' => 1,
  950. 'img' => $this->staff [0] ['avatar'],
  951. 'username' => $this->staff [0] ['username'],
  952. 'uid' => $this->staff [0] ['sid'],
  953. 'category' => $this->staff [0] ['category'],
  954. 'irid' => $irid
  955. );
  956. $invoiceROLog->setInvoiceROLog ( $item );
  957. $item = array (
  958. 'date' => date ( "Y-m-d H:i:s" ),
  959. 'priceClass' => 2,
  960. 'irid' => $irid,
  961. 'receivablesPrice' => $receivablesPrice
  962. );
  963. if ($receivablesCategory != 'PUBLIC') {
  964. $receivablesCategory = explode ( ":", $receivablesCategory );
  965. $item += array (
  966. 'cid' => $receivablesCategory [0]
  967. );
  968. }
  969. if ($receivablesStaff2 != 'PUBLIC') {
  970. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  971. $item += array (
  972. 'staff' => $receivablesStaff [0]
  973. );
  974. }
  975. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  976. }
  977. return "/invoiceReceivables";
  978. }
  979. /**
  980. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  981. */
  982. function invoiceReceivablesClaim() {
  983. Doo::loadModel ( 'invoiceReceivables' );
  984. $invoiceReceivables = new invoiceReceivables ();
  985. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'] );
  986. $this->data ['receivablesList'] = $receivablesList;
  987. $this->data ['memu'] = "invoice";
  988. $this->data ['staff'] = $this->staff;
  989. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  990. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  991. }
  992. /**
  993. * 更新收款相关数据
  994. */
  995. function invoiceReceivablesUpdateClaim() {
  996. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  997. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  998. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  999. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1000. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  1001. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  1002. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1003. if (empty ( $claimKey ))
  1004. die ( 'illegal request' );
  1005. Doo::loadModel ( 'invoiceReceivables' );
  1006. $invoiceReceivables = new invoiceReceivables ();
  1007. Doo::loadModel ( 'invoiceROLog' );
  1008. $invoiceROLog = new invoiceROLog ();
  1009. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  1010. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1011. if (empty ( $detail ))
  1012. die ( 'illegal request' );
  1013. $invoiceReceivables = new invoiceReceivables ();
  1014. $item = array (
  1015. 'irid' => $detail ['irid']
  1016. );
  1017. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1018. $item += array (
  1019. 'confirmTime' => date ( "Y-m-d H:i:s" )
  1020. );
  1021. }
  1022. if (! empty ( $receivablesCategory ))
  1023. $item += array (
  1024. 'receivablesCategory' => $receivablesCategory
  1025. );
  1026. if (! empty ( $receivablesStaff ))
  1027. $item += array (
  1028. 'receivablesStaff' => $receivablesStaff
  1029. );
  1030. if (! empty ( $receivablesPrice ))
  1031. $item += array (
  1032. 'receivablesPrice' => $receivablesPrice
  1033. );
  1034. if (! empty ( $receivablesMessage ))
  1035. $item += array (
  1036. 'receivablesMessage' => $receivablesMessage
  1037. );
  1038. if (! empty ( $receivablesBank ))
  1039. $item += array (
  1040. 'receivablesBank' => $receivablesBank
  1041. );
  1042. if (! empty ( $receivablesDate ))
  1043. $item += array (
  1044. 'receivablesDate' => $receivablesDate
  1045. );
  1046. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1047. // 收款操作日志
  1048. $item = array ();
  1049. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1050. $item = array (
  1051. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  1052. );
  1053. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1054. $item = array (
  1055. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  1056. );
  1057. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1058. $receivablesStaff = explode ( '-', $receivablesStaff );
  1059. $item = array (
  1060. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  1061. );
  1062. }
  1063. $item += array (
  1064. 'date' => date ( "Y-m-d" ),
  1065. 'status' => 1,
  1066. 'img' => $this->staff [0] ['avatar'],
  1067. 'username' => $this->staff [0] ['username'],
  1068. 'uid' => $this->staff [0] ['sid'],
  1069. 'category' => $this->staff [0] ['category'],
  1070. 'irid' => $detail ['irid']
  1071. );
  1072. $invoiceROLog->setInvoiceROLog ( $item );
  1073. return '/invoiceReceivablesAS';
  1074. }
  1075. function invoiceReceivablesDelete() {
  1076. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1077. if (empty ( $claimKey ))
  1078. die ( 'illegal request' );
  1079. Doo::loadModel ( 'invoiceReceivables' );
  1080. $invoiceReceivables = new invoiceReceivables ();
  1081. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  1082. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1083. if (empty ( $detail ))
  1084. die ( 'illegal request' );
  1085. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  1086. return '/invoiceReceivablesAS';
  1087. }
  1088. /**
  1089. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  1090. */
  1091. function invoiceReceivablesAscription() {
  1092. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1093. Doo::loadModel ( 'invoiceReceivables' );
  1094. $invoiceReceivables = new invoiceReceivables ();
  1095. Doo::loadModel ( 'invoiceROLog' );
  1096. $invoiceROLog = new invoiceROLog ();
  1097. Doo::loadModel ( 'invoiceStatistics' );
  1098. $invoiceStatistics = new invoiceStatistics ();
  1099. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1100. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC') {
  1101. $item = array (
  1102. 'irid' => $detail ['irid'],
  1103. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  1104. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  1105. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  1106. 'source' => 1
  1107. );
  1108. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1109. $item = array (
  1110. 'date' => date ( "Y-m-d" ),
  1111. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  1112. 'status' => 2,
  1113. 'img' => $this->staff [0] ['avatar'],
  1114. 'username' => $this->staff [0] ['username'],
  1115. 'uid' => $this->staff [0] ['sid'],
  1116. 'category' => $this->staff [0] ['category'],
  1117. 'irid' => $irid
  1118. );
  1119. $invoiceROLog->setInvoiceROLog ( $item );
  1120. $item = array (
  1121. 'cid' => $this->staff [0] ['cid'],
  1122. 'staff' => $this->staff [0] ['sid']
  1123. );
  1124. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'] );
  1125. }
  1126. return "/invoiceReceivablesClaim";
  1127. }
  1128. /**
  1129. */
  1130. function invoiceMyReceivables() {
  1131. Doo::loadModel ( 'invoiceReceivables' );
  1132. $invoiceReceivables = new invoiceReceivables ();
  1133. Doo::loadModel ( 'invoiceStatistics' );
  1134. $invoiceStatistics = new invoiceStatistics ();
  1135. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  1136. $year = date ( "Y" );
  1137. $tmp_date = date ( "Ym" );
  1138. $tmp_year = substr ( $tmp_date, 0, 4 );
  1139. $tmp_mon = substr ( $tmp_date, 4, 2 );
  1140. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  1141. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  1142. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  1143. $htm = $this->showCache ( $path );
  1144. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  1145. $this->data ['isMonth'] = $isMonth;
  1146. $this->data ['htm'] = $htm;
  1147. $this->data ['list'] = $list;
  1148. $this->data ['memu'] = "invoice";
  1149. $this->data ['staff'] = $this->staff;
  1150. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  1151. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  1152. }
  1153. /**
  1154. * 收款绑定发票 ,一个收款只能绑定一个发票
  1155. */
  1156. function invoiceBindReceivables() {
  1157. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1158. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1159. Doo::loadModel ( 'invoice' );
  1160. $invoice = new invoice ();
  1161. Doo::loadModel ( 'invoiceReceivables' );
  1162. $invoiceReceivables = new invoiceReceivables ();
  1163. Doo::loadModel ( 'invoiceOperationLog' );
  1164. $invoiceOperationLog = new invoiceOperationLog ();
  1165. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  1166. die ( 'illegal request' );
  1167. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1168. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  1169. if (empty ( $detail ) && empty ( $detailM ))
  1170. die ( 'illegal request' );
  1171. // if ($detailM ['receivablesPrice'] >= $detail ['invoicePrice']) {
  1172. // $price = $detailM ['receivablesPrice'] - $detail ['invoicePrice'];
  1173. // die ( '<p>收款金额超出开票金额 ¥' . $price . '元,请谨慎操作</p><a href="/invoiceMyReceivables">返回</a>' );
  1174. // }
  1175. $item = array (
  1176. 'irid' => $detailM ['irid'],
  1177. 'bindStatus' => 1,
  1178. 'iid' => $detail ['iid'],
  1179. 'bindDate' => date ( "Y-m-d H:i:s" )
  1180. );
  1181. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1182. $iridString = "";
  1183. if (empty ( $detail ['irid'] ))
  1184. $iridString = $detailM ['irid'];
  1185. else
  1186. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  1187. $item = array (
  1188. 'iid' => $detail ['iid'],
  1189. 'irid' => $iridString
  1190. );
  1191. $invoice->setInvoiceByCondition ( $item );
  1192. // 操作日志
  1193. $item = array (
  1194. 'date' => date ( "Y-m-d H:i:s" ),
  1195. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  1196. 'status' => 8,
  1197. 'img' => $this->staff [0] ['avatar'],
  1198. 'username' => $this->staff [0] ['username'],
  1199. 'uid' => $this->staff [0] ['sid'],
  1200. 'category' => $this->staff [0] ['category'],
  1201. 'iid' => $detail ['iid']
  1202. );
  1203. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1204. return "/invoiceMyReceivables";
  1205. }
  1206. /**
  1207. * 发票收款完成
  1208. */
  1209. function invoiceEnterReceivables() {
  1210. $invoiceKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1211. // $invoiceClaim = $this->get_args ( 'invoiceClaim' ) ? $this->get_args ( 'invoiceClaim' ) : "";
  1212. Doo::loadModel ( 'invoice' );
  1213. $invoice = new invoice ();
  1214. Doo::loadModel ( 'invoiceOperationLog' );
  1215. $invoiceOperationLog = new invoiceOperationLog ();
  1216. Doo::loadModel ( 'invoiceStatistics' );
  1217. $invoiceStatistics = new invoiceStatistics ();
  1218. Doo::loadModel ( 'invoiceReceivables' );
  1219. $invoiceReceivables = new invoiceReceivables ();
  1220. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1221. if (empty ( $detail ))
  1222. die ( 'illegal request' );
  1223. if (empty ( $detail ['irid'] ))
  1224. die ( 'illegal request' );
  1225. $item = array (
  1226. 'untreadStatus' => 3,
  1227. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1228. 'iid' => $detail ['iid']
  1229. );
  1230. $invoice->setInvoiceByCondition ( $item );
  1231. // 操作日志
  1232. $item = array (
  1233. 'date' => date ( "Y-m-d H:i:s" ),
  1234. 'operation' => "发票" . $detail ['invoiceSerial'] . "收款完成",
  1235. 'status' => 9,
  1236. 'img' => $this->staff [0] ['avatar'],
  1237. 'username' => $this->staff [0] ['username'],
  1238. 'uid' => $this->staff [0] ['sid'],
  1239. 'category' => $this->staff [0] ['category'],
  1240. 'iid' => $detail ['iid']
  1241. );
  1242. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1243. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  1244. $accountPrice = 0;
  1245. foreach ( $list as $key => $value ) {
  1246. $accountPrice += $value ['receivablesPrice'];
  1247. }
  1248. $item = array (
  1249. 'date' => date ( "Y-m-d H:i:s" ),
  1250. 'priceClass' => 3,
  1251. 'cid' => $this->staff [0] ['cid'],
  1252. 'staff' => $this->staff [0] ['sid'],
  1253. 'accountPrice' => $accountPrice
  1254. );
  1255. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1256. return "/invoice";
  1257. }
  1258. function invoiceAggregate() {
  1259. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1260. Doo::loadModel ( 'invoiceStatistics' );
  1261. $invoiceStatistics = new invoiceStatistics ();
  1262. Doo::loadModel ( 'L_category' );
  1263. $Lcategory = new L_category ();
  1264. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  1265. $LcategoryList = $Lcategory->getCategory ();
  1266. // print_r($isList);
  1267. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  1268. foreach ( $LcategoryList as $key => $value ) {
  1269. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  1270. $month = 1;
  1271. $invoicePriceYear = 0;
  1272. $receivablesPriceYear = 0;
  1273. $accountPriceYear = 0;
  1274. for(; $month <= 12; $month ++) {
  1275. $flag = true;
  1276. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  1277. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  1278. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1279. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1280. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1281. ';
  1282. $invoicePriceYear += $v ['invoicePrice'];
  1283. $receivablesPriceYear += $v ['receivablesPrice'];
  1284. $accountPriceYear += $v ['accountPrice'];
  1285. $flag = false;
  1286. break;
  1287. }
  1288. }
  1289. if ($flag)
  1290. $html .= '<td class="taR"></td>
  1291. <td class="taR"></td>
  1292. <td class="taR"><b></b></td>
  1293. ';
  1294. }
  1295. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1296. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1297. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1298. ';
  1299. $html .= '</tr>';
  1300. }
  1301. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  1302. $invoicePriceYear = 0;
  1303. $receivablesPriceYear = 0;
  1304. $accountPriceYear = 0;
  1305. for($month = 1; $month <= 12; $month ++) {
  1306. $flag = true;
  1307. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  1308. if ($month == $v ['month']) {
  1309. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1310. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1311. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1312. ';
  1313. $invoicePriceYear += $v ['invoicePrice'];
  1314. $receivablesPriceYear += $v ['receivablesPrice'];
  1315. $accountPriceYear += $v ['accountPrice'];
  1316. $flag = false;
  1317. break;
  1318. }
  1319. if ($flag)
  1320. $html .= '<td class="taR"></td>
  1321. <td class="taR"></td>
  1322. <td class="taR"><b></b></td>
  1323. ';
  1324. }
  1325. }
  1326. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1327. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1328. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1329. ';
  1330. $html .= '</tr>';
  1331. $this->data ['html'] = $html;
  1332. $this->data ['LcategoryList'] = $LcategoryList;
  1333. $this->data ['isList'] = $isList;
  1334. $this->data ['year'] = $year;
  1335. $this->data ['memu'] = "invoice";
  1336. $this->data ['staff'] = $this->staff;
  1337. $this->data ['receiptMemu'] = 'invoiceAggregate';
  1338. $this->render ( "/admin/invoiceAggregate", $this->data );
  1339. }
  1340. function invoiceAggregateStaff() {
  1341. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1342. Doo::loadModel ( 'invoiceStatistics' );
  1343. $invoiceStatistics = new invoiceStatistics ();
  1344. Doo::loadModel ( 'L_category' );
  1345. $Lcategory = new L_category ();
  1346. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  1347. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  1348. $cStaff = $Lcategory->getCategoryStaff ();
  1349. $html = '';
  1350. foreach ( $cStaff as $key => $value ) {
  1351. $categoryFir = true;
  1352. foreach ( $value ['staff'] as $k => $v ) {
  1353. if ($categoryFir) {
  1354. $width = count ( $value ['staff'] ) + 1;
  1355. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  1356. $categoryFir = false;
  1357. } else
  1358. $html .= '<tr>';
  1359. $html .= '<th>' . $v ['username'] . '</th>';
  1360. $invoicePriceStaffYear = 0;
  1361. $receivablesPriceStaffYear = 0;
  1362. $accountPriceStaffYear = 0;
  1363. for($month = 1; $month <= 12; $month ++) {
  1364. $flag = true;
  1365. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  1366. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  1367. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  1368. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  1369. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  1370. ';
  1371. $invoicePriceStaffYear += $slv ['invoicePrice'];
  1372. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  1373. $accountPriceStaffYear += $slv ['accountPrice'];
  1374. $flag = false;
  1375. break;
  1376. }
  1377. }
  1378. if ($flag)
  1379. $html .= '<td class="taR"></td>
  1380. <td class="taR"></td>
  1381. <td class="taR"><b></b></td>
  1382. ';
  1383. }
  1384. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  1385. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  1386. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  1387. ';
  1388. }
  1389. $html .= '</tr>';
  1390. // 小计
  1391. if (! empty ( $value ['staff'] )) {
  1392. $html .= '<tr><th class="taR">小计</th>';
  1393. $invoicePriceStaffYear = 0;
  1394. $receivablesPriceStaffYear = 0;
  1395. $accountPriceStaffYear = 0;
  1396. for($month = 1; $month <= 12; $month ++) {
  1397. $flag = true;
  1398. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  1399. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  1400. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  1401. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  1402. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  1403. ';
  1404. $invoicePriceStaffYear += $slv ['invoicePrice'];
  1405. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  1406. $accountPriceStaffYear += $slv ['accountPrice'];
  1407. $flag = false;
  1408. break;
  1409. }
  1410. }
  1411. if ($flag)
  1412. $html .= '<td class="taR"></td>
  1413. <td class="taR"></td>
  1414. <td class="taR"><b></b></td>
  1415. ';
  1416. }
  1417. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  1418. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  1419. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  1420. ';
  1421. $html .= '</tr>';
  1422. }
  1423. }
  1424. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  1425. $invoicePriceYear = 0;
  1426. $receivablesPriceYear = 0;
  1427. $accountPriceYear = 0;
  1428. for($month = 1; $month <= 12; $month ++) {
  1429. $flag = true;
  1430. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  1431. if ($month == $v ['month']) {
  1432. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  1433. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  1434. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  1435. ';
  1436. $invoicePriceYear += $v ['invoicePrice'];
  1437. $receivablesPriceYear += $v ['receivablesPrice'];
  1438. $accountPriceYear += $v ['accountPrice'];
  1439. $flag = false;
  1440. break;
  1441. }
  1442. if ($flag)
  1443. $html .= '<td class="taR"></td>
  1444. <td class="taR"></td>
  1445. <td class="taR"><b></b></td>
  1446. ';
  1447. }
  1448. }
  1449. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1450. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1451. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1452. ';
  1453. $html .= '</tr>';
  1454. $this->data ['html'] = $html;
  1455. $this->data ['isList'] = $toteList;
  1456. $this->data ['year'] = $year;
  1457. $this->data ['memu'] = "invoice";
  1458. $this->data ['staff'] = $this->staff;
  1459. $this->data ['receiptMemu'] = 'invoiceAggregate';
  1460. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  1461. }
  1462. function invoiceAggregateCategory() {
  1463. Doo::loadClass ( 'XDeode' );
  1464. $XDeode = new XDeode ( 5 );
  1465. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  1466. $cid = $XDeode->decode ( $cid );
  1467. if (! is_numeric ( $cid ))
  1468. die ( 'illegal request' );
  1469. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1470. Doo::loadModel ( 'invoiceStatistics' );
  1471. $invoiceStatistics = new invoiceStatistics ();
  1472. Doo::loadModel ( 'staff' );
  1473. $staff = new staff ();
  1474. $list = $staff->getStaffByCid ( $cid );
  1475. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  1476. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  1477. if (empty ( $list ))
  1478. die ( '该办事处没有成员' );
  1479. $htmlA = $htmlB = $htmlC = $html = '';
  1480. foreach ( $list as $key => $value ) {
  1481. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  1482. $htmlB = '<tr><th class="taC">收款</th>';
  1483. $htmlC = '<tr><th class="taC">入账</th>';
  1484. $invoicePriceStaffYear = 0;
  1485. $receivablesPriceStaffYear = 0;
  1486. $accountPriceStaffYear = 0;
  1487. for($month = 1; $month <= 12; $month ++) {
  1488. $flag = true;
  1489. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  1490. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  1491. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  1492. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  1493. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  1494. $invoicePriceStaffYear += $v ['invoicePrice'];
  1495. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  1496. $accountPriceStaffYear += $v ['accountPrice'];
  1497. $flag = false;
  1498. break;
  1499. }
  1500. }
  1501. if ($flag) {
  1502. $htmlA .= '<td class="taR">-</td>';
  1503. $htmlB .= '<td class="taR">-</td>';
  1504. $htmlC .= '<td class="taR"><b>-</b></td>';
  1505. }
  1506. }
  1507. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  1508. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  1509. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  1510. $htmlA .= '</tr>';
  1511. $htmlB .= '</tr>';
  1512. $htmlC .= '</tr>';
  1513. $html .= $htmlA . $htmlB . $htmlC;
  1514. }
  1515. $htmlA = $htmlB = $htmlC = "";
  1516. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  1517. $htmlB = '<tr><th class="taC">收款</th>';
  1518. $htmlC = '<tr><th class="taC">入账</th>';
  1519. $invoicePriceStaffYear = 0;
  1520. $receivablesPriceStaffYear = 0;
  1521. $accountPriceStaffYear = 0;
  1522. for($month = 1; $month <= 12; $month ++) {
  1523. $flag = true;
  1524. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  1525. if ($month == $v ['month']) {
  1526. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  1527. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  1528. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  1529. $invoicePriceStaffYear += $v ['invoicePrice'];
  1530. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  1531. $accountPriceStaffYear += $v ['accountPrice'];
  1532. $flag = false;
  1533. break;
  1534. }
  1535. }
  1536. if ($flag) {
  1537. $htmlA .= '<td class="taR">-</td>';
  1538. $htmlB .= '<td class="taR">-</td>';
  1539. $htmlC .= '<td class="taR"><b>-</b></td>';
  1540. }
  1541. }
  1542. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  1543. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  1544. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  1545. $htmlA .= '</tr>';
  1546. $htmlB .= '</tr>';
  1547. $htmlC .= '</tr>';
  1548. $html .= $htmlA . $htmlB . $htmlC;
  1549. $this->data ['html'] = $html;
  1550. $this->data ['cidKey'] = $cidKey;
  1551. $this->data ['slist'] = $list;
  1552. $this->data ['isList'] = $toteList;
  1553. $this->data ['year'] = $year;
  1554. $this->data ['memu'] = "invoice";
  1555. $this->data ['staff'] = $this->staff;
  1556. $this->data ['receiptMemu'] = 'invoiceAggregate';
  1557. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  1558. }
  1559. function invoiceAchieve() {
  1560. Doo::loadModel ( 'invoice' );
  1561. $invoice = new invoice ();
  1562. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1563. $page_size = 1;
  1564. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1565. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  1566. $get = "/" . $date;
  1567. $con = '';
  1568. if ($date == 'MONTHO')
  1569. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1570. elseif ($date == 'MONTHT')
  1571. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1572. elseif ($date == 'MONTHY')
  1573. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1574. if (! empty ( $MebSea )) {
  1575. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1576. $get .= "/" . $MebSea;
  1577. }
  1578. $pageinfo ['page'] = array (
  1579. 'previous' => ''
  1580. );
  1581. $sql = 'status=2 and untreadStatus=3 and sid=' . $_COOKIE ["staff"] . $con;
  1582. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  1583. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1584. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  1585. // print_r($pageinfo);
  1586. $this->data ['MebSeaEn'] = $MebSea;
  1587. $this->data ['MebSea'] = urlencode ( $MebSea );
  1588. $this->data ['get'] = $get;
  1589. $this->data ['page'] = $pageinfo;
  1590. $this->data ['list'] = $list;
  1591. $this->data ['date'] = $date;
  1592. $this->data ['memu'] = "invoice";
  1593. $this->data ['staff'] = $this->staff;
  1594. $this->data ['receiptMemu'] = 'invoice';
  1595. $this->render ( "/admin/invoiceAchieve", $this->data );
  1596. }
  1597. function invoiceReceivablesAchieve() {
  1598. Doo::loadModel ( 'invoiceReceivables' );
  1599. $invoiceReceivables = new invoiceReceivables ();
  1600. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1601. $page_size = 1;
  1602. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1603. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  1604. $get = "/" . $date;
  1605. $con = '';
  1606. if ($date == 'MONTHO')
  1607. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1608. elseif ($date == 'MONTHT')
  1609. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1610. elseif ($date == 'MONTHY')
  1611. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1612. if (! empty ( $MebSea )) {
  1613. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  1614. $get .= "/" . $MebSea;
  1615. }
  1616. $pageinfo ['page'] = array (
  1617. 'previous' => ''
  1618. );
  1619. $sql = " bindStatus=1 and receivablesStaff like '" . $_COOKIE ["staff"] . "_%' " . $con;
  1620. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  1621. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1622. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  1623. // print_r($pageinfo);
  1624. $this->data ['MebSeaEn'] = $MebSea;
  1625. $this->data ['MebSea'] = urlencode ( $MebSea );
  1626. $this->data ['get'] = $get;
  1627. $this->data ['page'] = $pageinfo;
  1628. $this->data ['list'] = $list;
  1629. $this->data ['date'] = $date;
  1630. $this->data ['memu'] = "invoice";
  1631. $this->data ['staff'] = $this->staff;
  1632. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  1633. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  1634. }
  1635. function invoiceReceivablesAS() {
  1636. Doo::loadModel ( 'invoiceReceivables' );
  1637. $invoiceReceivables = new invoiceReceivables ();
  1638. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1639. $page_size = 12;
  1640. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1641. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  1642. $year = isset ( $this->params ['year'] ) && is_numeric ( $this->params ['year'] ) ? $this->params ['year'] : date ( 'Y' );
  1643. $month = isset ( $this->params ['month'] ) && is_numeric ( $this->params ['month'] ) ? $this->params ['month'] : "All";
  1644. $con = "Year(date) =" . $year;
  1645. if ($month != "All")
  1646. $con = "Year(date) =" . $year . " and Month(date) = " . $month;
  1647. if ($status == 'Unclaimed')
  1648. $con .= ' and bindStatus=0';
  1649. elseif ($status == 'Credited')
  1650. $con .= ' and bindStatus=1';
  1651. $get = "/" . $status . "/" . $year . "/" . $month;
  1652. if (! empty ( $MebSea )) {
  1653. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  1654. $get .= "/" . $MebSea;
  1655. }
  1656. $pageinfo ['page'] = array (
  1657. 'previous' => ''
  1658. );
  1659. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  1660. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1661. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $con );
  1662. // print_r($pageinfo);
  1663. $mothHtml = "";
  1664. for($i = 1; $i <= 12; $i ++) {
  1665. if ($month == $i)
  1666. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  1667. else
  1668. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  1669. }
  1670. $this->data ['MebSeaEn'] = $MebSea;
  1671. $this->data ['MebSea'] = urlencode ( $MebSea );
  1672. $this->data ['mothHtml'] = $mothHtml;
  1673. $this->data ['year'] = $year;
  1674. $this->data ['month'] = $month;
  1675. $this->data ['page'] = $pageinfo;
  1676. $this->data ['get'] = $get;
  1677. $this->data ['list'] = $list;
  1678. $this->data ['status'] = $status;
  1679. $this->data ['memu'] = "invoice";
  1680. $this->data ['staff'] = $this->staff;
  1681. $this->data ['receiptMemu'] = 'invoiceReceivables';
  1682. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  1683. }
  1684. function invoiceApprovalAchieve() {
  1685. Doo::loadModel ( 'invoice' );
  1686. $invoice = new invoice ();
  1687. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1688. $page_size = 2;
  1689. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1690. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  1691. $get = "/" . $date;
  1692. $con = '';
  1693. if ($date == 'MONTHO')
  1694. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1695. elseif ($date == 'MONTHT')
  1696. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1697. elseif ($date == 'MONTHY')
  1698. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1699. if (! empty ( $MebSea )) {
  1700. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1701. $get .= "/" . $MebSea;
  1702. }
  1703. $pageinfo ['page'] = array (
  1704. 'previous' => ''
  1705. );
  1706. $sql = '(status=1 or status=3 or status=4) and processApprovals!=""' . $con;
  1707. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  1708. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1709. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  1710. // print_r($list);
  1711. $this->data ['MebSeaEn'] = $MebSea;
  1712. $this->data ['MebSea'] = urlencode ( $MebSea );
  1713. $this->data ['get'] = $get;
  1714. $this->data ['page'] = $pageinfo;
  1715. $this->data ['list'] = $list;
  1716. $this->data ['date'] = $date;
  1717. $this->data ['memu'] = "invoice";
  1718. $this->data ['staff'] = $this->staff;
  1719. $this->data ['receiptMemu'] = 'invoiceApproval';
  1720. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  1721. }
  1722. function invoiceTAchieve() {
  1723. Doo::loadModel ( 'invoice' );
  1724. $invoice = new invoice ();
  1725. Doo::loadClass ( 'XDeode' );
  1726. $XDeode = new XDeode ( 5 );
  1727. Doo::loadModel ( 'staff' );
  1728. $staff = new staff ();
  1729. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1730. $page_size = 2;
  1731. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1732. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  1733. $get = "/" . $date;
  1734. $con = '';
  1735. if ($date == 'MONTHO')
  1736. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1737. elseif ($date == 'MONTHT')
  1738. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1739. elseif ($date == 'MONTHY')
  1740. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1741. if (! empty ( $MebSea )) {
  1742. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1743. $get .= "/" . $MebSea;
  1744. }
  1745. $pageinfo ['page'] = array (
  1746. 'previous' => ''
  1747. );
  1748. $sql = "";
  1749. $action = "";
  1750. if ($this->ACTION == 'invoicePrintAchieve') {
  1751. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  1752. $action = "invoicePrintAchieve";
  1753. } elseif ($this->ACTION == 'invoicePostAchieve') {
  1754. // and untreadStatus=0
  1755. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  1756. $action = "invoicePostAchieve";
  1757. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  1758. $sql = " printStatus=1 and untreadStatus=2 and status=2 " . $con;
  1759. $action = "invoiceUntreadAchieve";
  1760. }
  1761. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1762. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1763. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  1764. $this->data ['MebSeaEn'] = $MebSea;
  1765. $this->data ['MebSea'] = urlencode ( $MebSea );
  1766. $this->data ['get'] = $get;
  1767. $this->data ['page'] = $pageinfo;
  1768. $this->data ['date'] = $date;
  1769. $this->data ['memu'] = "invoice";
  1770. $this->data ['staff'] = $this->staff;
  1771. if ($this->ACTION == 'invoicePrintAchieve') {
  1772. foreach ( $list as $key => $value ) {
  1773. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1774. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1775. if (! empty ( $lastApprover )) {
  1776. $lastApproverKey = array_keys ( $lastApprover );
  1777. $lastApprover = end ( $lastApprover );
  1778. $staffDetail = $staff->getOne ( array (
  1779. 'where' => 'sid=' . end ( $lastApproverKey ),
  1780. 'asArray' => true
  1781. ) );
  1782. $lastApprover ['username'] = $staffDetail ['username'];
  1783. }
  1784. $list [$key] ['lastApprover'] = $lastApprover;
  1785. }
  1786. $this->data ['receiptMemu'] = 'invoicePrint';
  1787. $this->data ['list'] = $list;
  1788. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  1789. } elseif ($this->ACTION == 'invoicePostAchieve') {
  1790. Doo::loadModel ( 'express' );
  1791. $express = new express ();
  1792. $expressList = $express->getExpressByAll ();
  1793. $this->data ['expressList'] = $expressList;
  1794. $this->data ['receiptMemu'] = 'invoicePost';
  1795. $this->data ['list'] = $list;
  1796. $this->render ( "/admin/invoicePostAchieve", $this->data );
  1797. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  1798. $this->data ['receiptMemu'] = 'invoiceUntread';
  1799. $this->data ['list'] = $list;
  1800. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  1801. }
  1802. }
  1803. /**
  1804. * 获得与我有关可收款的发票
  1805. */
  1806. function ajaxGetInvoiceByStaff() {
  1807. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1808. Doo::loadModel ( 'invoice' );
  1809. $invoice = new invoice ();
  1810. $list = $invoice->getInvoiceByReceivables ( $this->staff [0] ['sid'] );
  1811. $html = "";
  1812. $i = 1;
  1813. foreach ( $list as $key => $value ) {
  1814. $html .= '<tr>
  1815. <td>' . $value ['invoiceElement'] . '</td>
  1816. <td>¥' . $value ['invoicePrice'] . '</td>';
  1817. if (! empty ( $value ['invoiceType'] )) {
  1818. $html .= '<td>增值税专用发票</td>
  1819. <td>' . $value ['invoiceCompany'] . '</td>';
  1820. } else {
  1821. $html .= '<td>增值税普通发票</td>
  1822. <td>' . $value ['invoiceTitle'] . '</td>';
  1823. }
  1824. $html .= '<td><label><input type="radio" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim"> 使用Ta</label></td></tr>
  1825. <script>
  1826. $(\'input[node-Claim="true_' . $i . '"]\').click(function() {
  1827. var invoiceKey= $(this).attr("p-data");
  1828. var claimKey=$("input[name=\'key\']").val();
  1829. $("p[node-msg=\"true\"]").hide();
  1830. var url = "/ajaxCompareInvoicePrice";
  1831. $.ajax({
  1832. url : url,
  1833. type : "post",
  1834. cache : false,
  1835. dataType : "json",
  1836. data : {
  1837. claimKey : claimKey,
  1838. invoiceKey:invoiceKey
  1839. },
  1840. global : true,
  1841. success : function(data) {
  1842. $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '");
  1843. if (data.status == 1) {
  1844. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1845. $("p[node-msg=\"true\"]").show();
  1846. }
  1847. },
  1848. error : function(err) {
  1849. }
  1850. });
  1851. });
  1852. </script>
  1853. ';
  1854. $i ++;
  1855. }
  1856. echo json_encode ( array (
  1857. 'status' => 1,
  1858. 'html' => $html
  1859. ) );
  1860. }
  1861. /**
  1862. * 获取一条收款信息
  1863. */
  1864. function ajaxGetInvoiceReceivables() {
  1865. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1866. Doo::loadModel ( 'invoiceReceivables' );
  1867. $invoiceReceivables = new invoiceReceivables ();
  1868. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1869. echo json_encode ( array (
  1870. 'status' => 1,
  1871. 'detail' => $detail
  1872. ) );
  1873. }
  1874. /**
  1875. * 异步获取办事处用户
  1876. */
  1877. function ajaxGetStaffByCategory() {
  1878. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  1879. Doo::loadModel ( 'staff' );
  1880. $staff = new staff ();
  1881. if ($cid == "PUBLIC") {
  1882. echo json_encode ( array (
  1883. 'status' => 1,
  1884. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  1885. ) );
  1886. die ();
  1887. }
  1888. if (! is_numeric ( $cid )) {
  1889. echo json_encode ( array (
  1890. 'status' => 0,
  1891. 'msg' => 'illegal request'
  1892. ) );
  1893. die ();
  1894. }
  1895. $staffList = $staff->getStaffByCid ( $cid );
  1896. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  1897. foreach ( $staffList as $key => $value ) {
  1898. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  1899. }
  1900. echo json_encode ( array (
  1901. 'status' => 1,
  1902. 'html' => $html
  1903. ) );
  1904. }
  1905. /**
  1906. * 异步获取一条发票的邮寄信息
  1907. */
  1908. function ajaxGetInvoicePostDetail() {
  1909. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1910. Doo::loadModel ( 'invoice' );
  1911. $invoice = new invoice ();
  1912. $iid = $invoice->authcode ( $iid );
  1913. Doo::loadModel ( 'express' );
  1914. $express = new express ();
  1915. $expressList = $express->getExpressByAll ();
  1916. if (! is_numeric ( $iid )) {
  1917. echo json_encode ( array (
  1918. 'status' => 0,
  1919. 'msg' => 'illegal request'
  1920. ) );
  1921. die ();
  1922. }
  1923. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  1924. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  1925. $html = "";
  1926. foreach ( $expressList as $key => $value ) {
  1927. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  1928. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  1929. else
  1930. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  1931. }
  1932. $invoiceDetail ['eaHtml'] = $html;
  1933. echo json_encode ( array (
  1934. 'status' => 1,
  1935. 'invoiceDetail' => $invoiceDetail
  1936. ) );
  1937. }
  1938. function ajaxCompareClaimPrice() {
  1939. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  1940. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1941. Doo::loadModel ( 'invoice' );
  1942. $invoice = new invoice ();
  1943. Doo::loadModel ( 'invoiceReceivables' );
  1944. $invoiceReceivables = new invoiceReceivables ();
  1945. Doo::loadModel ( 'invoiceOperationLog' );
  1946. $invoiceOperationLog = new invoiceOperationLog ();
  1947. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1948. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1949. if (empty ( $detail ) || empty ( $detailM )) {
  1950. echo json_encode ( array (
  1951. 'status' => 2,
  1952. 'msg' => '非法请求,请重新登录'
  1953. ) );
  1954. die ();
  1955. }
  1956. $iridString = "";
  1957. if (empty ( $detail ['irid'] ))
  1958. $iridString = $detailM ['irid'];
  1959. else
  1960. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  1961. $item = array (
  1962. 'irid' => $iridString,
  1963. 'bindTime' => date ( "Y-m-d H:i:s" ),
  1964. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1965. 'iid' => $detail ['iid']
  1966. );
  1967. $invoice->setInvoiceByCondition ( $item );
  1968. // 操作日志
  1969. $item = array (
  1970. 'date' => date ( "Y-m-d H:i:s" ),
  1971. 'operation' => "收款入账" . $detailM ['receivablesSerial'] . "到发票" . $detail ['invoiceSerial'],
  1972. 'status' => 8,
  1973. 'img' => $this->staff [0] ['avatar'],
  1974. 'username' => $this->staff [0] ['username'],
  1975. 'uid' => $this->staff [0] ['sid'],
  1976. 'category' => $this->staff [0] ['category'],
  1977. 'iid' => $detail ['iid']
  1978. );
  1979. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1980. $item = array (
  1981. 'iid' => $detail ['iid'],
  1982. 'irid' => $detailM ['irid'],
  1983. 'bindDate' => date ( "Y-m-d H:i:s" ),
  1984. 'bindStatus' => 1
  1985. );
  1986. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1987. $price = 0;
  1988. $priceStatus = 0;
  1989. $isReceivables = 0;
  1990. $invoiceReceivables = new invoiceReceivables ();
  1991. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  1992. if (! empty ( $list ))
  1993. $isReceivables = 1;
  1994. $receivablesPrice = 0;
  1995. foreach ( $list as $key => $value ) {
  1996. $receivablesPrice += $value ['receivablesPrice'];
  1997. }
  1998. if ($receivablesPrice > $detail ['invoicePrice']) {
  1999. $price = $receivablesPrice - $detail ['invoicePrice'];
  2000. $priceStatus = 1;
  2001. } elseif ($receivablesPrice < $detail ['invoicePrice']) {
  2002. $price = $detail ['invoicePrice'] - $receivablesPrice;
  2003. $priceStatus = 2;
  2004. }
  2005. echo json_encode ( array (
  2006. 'status' => 1,
  2007. 'html' => '<tr><td>¥' . $detailM ['receivablesPrice'] . '</td><td>' . $detailM ['receivablesMessage'] . '</td><td>' . $detailM ['receivablesBank'] . '</td>
  2008. <td>' . $detailM ['receivablesDate'] . '</td><td><a node-remove="Da' . $detailM ['iridKey'] . '" href="javascript:void(0);">移除</a></td></tr>
  2009. <script>
  2010. $(\'a[node-remove="Da' . $detailM ['iridKey'] . '"]\').click(function() {
  2011. var invoiceKey=$("input[name=\'key\']").val();
  2012. var irid= $(this).attr("p-data");
  2013. var iridKey="' . $detailM ["iridEn"] . '";
  2014. var element=($(this));
  2015. $("p[node-loading=\"true\"]").show();
  2016. $("p[node-loading=\"true\"]").html("移除处理中...");
  2017. $("p[node-msg=\"true2\"]").hide();
  2018. $("p[node-msg=\"true\"]").hide();
  2019. var url = "/ajaxReceivablesRemove";
  2020. $.ajax({
  2021. url : url,
  2022. type : "post",
  2023. cache : false,
  2024. dataType : "json",
  2025. data : {
  2026. key : iridKey,
  2027. invoiceKey:invoiceKey
  2028. },
  2029. global : true,
  2030. success : function(data) {
  2031. $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '");
  2032. if (data.status == 1) {
  2033. $(element).parent().parent().remove();
  2034. $("tbody[data-invoice=\"myReceivables\"]").append(data.html);
  2035. $("p[node-loading=\"true\"]").hide();
  2036. if(data.priceStatus == 1){
  2037. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  2038. $("p[node-msg=\"true\"]").show();
  2039. }else if(data.priceStatus == 2&& data.isReceivables != 0){
  2040. $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。");
  2041. $("p[node-msg=\"true\"]").show();
  2042. }
  2043. }else if(data.status == 2){
  2044. $("p[node-loading=\"true\"]").html(data.msg);
  2045. }
  2046. },
  2047. error : function(err) {
  2048. }
  2049. });
  2050. });
  2051. </script>
  2052. ',
  2053. 'price' => $price,
  2054. 'priceStatus' => $priceStatus,
  2055. 'isReceivables' => $isReceivables
  2056. ) );
  2057. }
  2058. /**
  2059. * 从发票中移除已经入账的收款
  2060. */
  2061. function ajaxReceivablesRemove() {
  2062. $iridKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2063. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2064. Doo::loadModel ( 'invoice' );
  2065. $invoice = new invoice ();
  2066. Doo::loadModel ( 'invoiceReceivables' );
  2067. $invoiceReceivables = new invoiceReceivables ();
  2068. Doo::loadModel ( 'invoiceOperationLog' );
  2069. $invoiceOperationLog = new invoiceOperationLog ();
  2070. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2071. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridKey );
  2072. // echo $detail['irid']."<br/>";
  2073. $invoiceIrid = explode ( ",", $detail ['irid'] );
  2074. foreach ( $invoiceIrid as $key => $value ) {
  2075. if ($value == $detailM ['irid'])
  2076. unset ( $invoiceIrid [$key] );
  2077. }
  2078. $invoiceIrid = implode ( ",", $invoiceIrid );
  2079. // echo $invoiceIrid."ddd";
  2080. // print_r($invoiceIrid);
  2081. $item = array (
  2082. 'irid' => $invoiceIrid,
  2083. 'iid' => $detail ['iid']
  2084. );
  2085. $invoice->setInvoiceByCondition ( $item );
  2086. $item = array (
  2087. 'iid' => 0,
  2088. 'irid' => $detailM ['irid'],
  2089. 'bindDate' => '',
  2090. 'bindStatus' => 0
  2091. );
  2092. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2093. // 操作日志
  2094. $item = array (
  2095. 'date' => date ( "Y-m-d H:i:s" ),
  2096. 'operation' => "收款移除" . $detailM ['receivablesSerial'],
  2097. 'status' => 10,
  2098. 'img' => $this->staff [0] ['avatar'],
  2099. 'username' => $this->staff [0] ['username'],
  2100. 'uid' => $this->staff [0] ['sid'],
  2101. 'category' => $this->staff [0] ['category'],
  2102. 'iid' => $detail ['iid']
  2103. );
  2104. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2105. $price = 0;
  2106. $priceStatus = 0;
  2107. $isReceivables = 0;
  2108. $invoiceReceivables = new invoiceReceivables ();
  2109. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $invoiceIrid );
  2110. if (! empty ( $list ))
  2111. $isReceivables = 1;
  2112. $receivablesPrice = 0;
  2113. foreach ( $list as $key => $value ) {
  2114. $receivablesPrice += $value ['receivablesPrice'];
  2115. }
  2116. if ($receivablesPrice > $detail ['invoicePrice']) {
  2117. $price = $receivablesPrice - $detail ['invoicePrice'];
  2118. $priceStatus = 1;
  2119. } elseif ($receivablesPrice < $detail ['invoicePrice']) {
  2120. $price = $detail ['invoicePrice'] - $receivablesPrice;
  2121. $priceStatus = 2;
  2122. }
  2123. echo json_encode ( array (
  2124. 'status' => 1,
  2125. 'html' => '<tr id="' . $detailM ['receivablesSerial'] . '" >
  2126. <td>¥' . $detailM ['receivablesPrice'] . '</td>
  2127. <td>' . $detailM ['receivablesMessage'] . '</td>
  2128. <td>' . $detailM ['receivablesBank'] . '</td>
  2129. <td>' . $detailM ['receivablesDate'] . '</td><td>
  2130. <a href="javascript:void(0)" node-Claim="true_' . $detailM ['iridKey'] . '" p-data="' . $detailM ['iridEn'] . '" name="invoiceClaim" class="button">入账</a>
  2131. </td></tr>
  2132. <script>
  2133. $(\'a[node-Claim="true_' . $detailM ['iridKey'] . '"]\').click(function() {
  2134. var invoiceKey=$("input[name=\'key\']").val();
  2135. var irid= $(this).attr("p-data");
  2136. var element=($(this));
  2137. $("p[node-loading=\"true\"]").show();
  2138. $("p[node-loading=\"true\"]").html("入账处理中...");
  2139. $("p[node-msg=\"true2\"]").hide();
  2140. $("p[node-msg=\"true\"]").hide();
  2141. var url = "/ajaxCompareClaimPrice";
  2142. $.ajax({
  2143. url : url,
  2144. type : "post",
  2145. cache : false,
  2146. dataType : "json",
  2147. data : {
  2148. irid : irid,
  2149. invoiceKey:invoiceKey
  2150. },
  2151. global : true,
  2152. success : function(data) {
  2153. $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '");
  2154. if (data.status == 1) {
  2155. $(element).parent().parent().remove();
  2156. $("tbody[box-enter=\"true\"]").append(data.html);
  2157. $("p[node-loading=\"true\"]").hide();
  2158. if(data.priceStatus == 1){
  2159. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  2160. $("p[node-msg=\"true\"]").show();
  2161. }else if(data.priceStatus == 2&& data.isReceivables != 0){
  2162. $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。");
  2163. $("p[node-msg=\"true\"]").show();
  2164. }
  2165. }else if(data.status == 2){
  2166. $("p[node-loading=\"true\"]").html(data.msg);
  2167. }
  2168. },
  2169. error : function(err) {
  2170. }
  2171. });
  2172. });
  2173. </script>
  2174. ',
  2175. 'price' => $price,
  2176. 'priceStatus' => $priceStatus,
  2177. 'isReceivables' => $isReceivables
  2178. ) );
  2179. }
  2180. /**
  2181. * 我的收款中 选择哪个发票入账,进行金额判断
  2182. */
  2183. function ajaxCompareInvoicePrice() {
  2184. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2185. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2186. Doo::loadModel ( 'invoice' );
  2187. $invoice = new invoice ();
  2188. Doo::loadModel ( 'invoiceReceivables' );
  2189. $invoiceReceivables = new invoiceReceivables ();
  2190. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2191. $keyList = explode ( ';', $claimKey );
  2192. $receivablesPrice = 0;
  2193. foreach ( $keyList as $key => $value ) {
  2194. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  2195. $receivablesPrice += $detailM ['receivablesPrice'];
  2196. }
  2197. if ($receivablesPrice > $detail ['invoicePrice']) {
  2198. $price = $receivablesPrice - $detail ['invoicePrice'];
  2199. echo json_encode ( array (
  2200. 'status' => 1,
  2201. 'price' => $price
  2202. ) );
  2203. } else
  2204. echo json_encode ( array (
  2205. 'status' => 2
  2206. ) );
  2207. }
  2208. /*
  2209. * 获得与我有关收款数据
  2210. */
  2211. function ajaxGetReceivalblesByStaff() {
  2212. $iid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2213. Doo::loadModel ( 'invoiceReceivables' );
  2214. $invoiceReceivables = new invoiceReceivables ();
  2215. Doo::loadModel ( 'invoice' );
  2216. $invoice = new invoice ();
  2217. $detail = $invoice->getInvoiceByIid ( $iid );
  2218. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2219. $html = "";
  2220. $i = 1;
  2221. foreach ( $list ['myClaim'] as $key => $value ) {
  2222. $html .= '<tr id="' . $value ['receivablesSerial'] . '" >
  2223. <td>¥' . $value ['receivablesPrice'] . '</td>
  2224. <td>' . $value ['receivablesMessage'] . '</td>
  2225. <td>' . $value ['receivablesBank'] . '</td>
  2226. <td>' . $value ['receivablesDate'] . '</td>';
  2227. $html .= '<td>
  2228. <a href="javascript:void(0)" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim" class="button">入账</a>
  2229. </td></tr>
  2230. <script>
  2231. $(\'a[node-Claim="true_' . $i . '"]\').click(function() {
  2232. var invoiceKey=$("input[name=\'key\']").val();
  2233. var irid= $(this).attr("p-data");
  2234. var element=($(this));
  2235. $("p[node-loading=\"true\"]").show();
  2236. $("p[node-loading=\"true\"]").html("入账处理中...");
  2237. $("p[node-msg=\"true2\"]").hide();
  2238. $("p[node-msg=\"true\"]").hide();
  2239. var url = "/ajaxCompareClaimPrice";
  2240. $.ajax({
  2241. url : url,
  2242. type : "post",
  2243. cache : false,
  2244. dataType : "json",
  2245. data : {
  2246. irid : irid,
  2247. invoiceKey:invoiceKey
  2248. },
  2249. global : true,
  2250. success : function(data) {
  2251. $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '");
  2252. if (data.status == 1) {
  2253. $(element).parent().parent().remove();
  2254. $("tbody[box-enter=\"true\"]").append(data.html);
  2255. $("p[node-loading=\"true\"]").hide();
  2256. if(data.priceStatus == 1){
  2257. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  2258. $("p[node-msg=\"true\"]").show();
  2259. }else if(data.priceStatus == 2&& data.isReceivables != 0){
  2260. $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。");
  2261. $("p[node-msg=\"true\"]").show();
  2262. }
  2263. }else if(data.status == 2){
  2264. $("p[node-loading=\"true\"]").html(data.msg);
  2265. }
  2266. },
  2267. error : function(err) {
  2268. }
  2269. });
  2270. });
  2271. </script>
  2272. ';
  2273. $i ++;
  2274. }
  2275. $html2 = "";
  2276. $list2 = $invoiceReceivables->getInvoiceReceivablesByIid ( $iid, 1 );
  2277. foreach ( $list2 as $key => $value ) {
  2278. $html2 .= '<tr id="' . $value ['receivablesSerial'] . '" >
  2279. <td>¥' . $value ['receivablesPrice'] . '</td>
  2280. <td>' . $value ['receivablesMessage'] . '</td>
  2281. <td>' . $value ['receivablesBank'] . '</td>
  2282. <td>' . $value ['receivablesDate'] . '</td>';
  2283. $html2 .= '<td>
  2284. <a href="javascript:void(0)" node-remove="Da' . $value ['iridKey'] . '" >移除</a>
  2285. </td></tr>
  2286. <script>
  2287. $(\'a[node-remove="Da' . $value ['iridKey'] . '"]\').click(function() {
  2288. var invoiceKey=$("input[name=\'key\']").val();
  2289. var irid= $(this).attr("p-data");
  2290. var iridKey="' . $value ["iidKey"] . '";
  2291. var element=($(this));
  2292. $("p[node-loading=\"true\"]").show();
  2293. $("p[node-loading=\"true\"]").html("移除处理中...");
  2294. $("p[node-msg=\"true2\"]").hide();
  2295. $("p[node-msg=\"true\"]").hide();
  2296. var url = "/ajaxReceivablesRemove";
  2297. $.ajax({
  2298. url : url,
  2299. type : "post",
  2300. cache : false,
  2301. dataType : "json",
  2302. data : {
  2303. key : iridKey,
  2304. invoiceKey:invoiceKey
  2305. },
  2306. global : true,
  2307. success : function(data) {
  2308. $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '");
  2309. if (data.status == 1) {
  2310. $(element).parent().parent().remove();
  2311. $("tbody[data-invoice=\"myReceivables\"]").append(data.html);
  2312. $("p[node-loading=\"true\"]").hide();
  2313. if(data.priceStatus == 1){
  2314. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  2315. $("p[node-msg=\"true\"]").show();
  2316. }else if(data.priceStatus == 2&& data.isReceivables != 0){
  2317. $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。");
  2318. $("p[node-msg=\"true\"]").show();
  2319. }
  2320. }else if(data.status == 2){
  2321. $("p[node-loading=\"true\"]").html(data.msg);
  2322. }
  2323. },
  2324. error : function(err) {
  2325. }
  2326. });
  2327. });
  2328. </script>
  2329. ';
  2330. $i ++;
  2331. }
  2332. $price = 0;
  2333. $priceStatus = 0;
  2334. $isReceivables = 0;
  2335. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  2336. if (! empty ( $list ))
  2337. $isReceivables = 1;
  2338. $receivablesPrice = 0;
  2339. foreach ( $list as $key => $value ) {
  2340. $receivablesPrice += $value ['receivablesPrice'];
  2341. }
  2342. if ($receivablesPrice > $detail ['invoicePrice']) {
  2343. $price = $receivablesPrice - $detail ['invoicePrice'];
  2344. $priceStatus = 1;
  2345. } elseif ($receivablesPrice < $detail ['invoicePrice']) {
  2346. $price = $detail ['invoicePrice'] - $receivablesPrice;
  2347. $priceStatus = 2;
  2348. }
  2349. echo json_encode ( array (
  2350. 'status' => 1,
  2351. 'html' => $html,
  2352. 'html2' => $html2,
  2353. 'price' => $price,
  2354. 'priceStatus' => $priceStatus,
  2355. 'isReceivables' => $isReceivables
  2356. ) );
  2357. }
  2358. function ajaxGetInvoiceInfoByType() {
  2359. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  2360. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  2361. if (empty ( $serial )) {
  2362. echo json_encode ( array (
  2363. 'status' => 2,
  2364. 'msg' => 'illegal request'
  2365. ) );
  2366. die ();
  2367. }
  2368. if ($type == 'INVOICE') {
  2369. Doo::loadModel ( 'invoice' );
  2370. $invoice = new invoice ();
  2371. Doo::loadModel ( 'invoiceOperationLog' );
  2372. $invoiceOperationLog = new invoiceOperationLog ();
  2373. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  2374. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  2375. if (empty ( $detail ))
  2376. $html = '';
  2377. else {
  2378. $html = '
  2379. <div class="modal-dialog modal-lg">
  2380. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  2381. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  2382. <tr>
  2383. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  2384. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  2385. </tr>
  2386. <tr>
  2387. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  2388. <th class="taC" width="150">备注</th><td>' . $detail ['remark'] . '</td>
  2389. </tr>
  2390. <tr>
  2391. <th class="taC">开票金额</th><td><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  2392. <th class="taC">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  2393. </tr></tbody></table>';
  2394. if ($detail ['invoiceType'] == 0)
  2395. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  2396. <th class="taC" width="150">发票抬头</th><td colspan="3">' . $detail ['invoiceTitle'] . '</td></tr></tbody></table>';
  2397. else
  2398. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  2399. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  2400. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr><tr>
  2401. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  2402. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  2403. </tr><tr>
  2404. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  2405. <th class="taC">银行账户</th><td>' . $detail ['bank'] . '</td>
  2406. </tr></tbody></table>';
  2407. if ($detail ['doPost'] == 1)
  2408. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  2409. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  2410. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  2411. </tr><tr>
  2412. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  2413. </tr><tr>
  2414. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  2415. </tr></tbody></table>';
  2416. if (! empty ( $invoiceOperationLogList )) {
  2417. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  2418. foreach ( $invoiceOperationLogList as $key => $value ) {
  2419. if($value ['status']==1||$value ['status']==2||$value ['status']==3||$value ['status']==4){
  2420. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  2421. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  2422. if ($value ['status'] == 2) {
  2423. $html .= '<span class="colGreen">同意</span>';
  2424. } elseif ($value ['status'] == 3) {
  2425. $html .= '<span class="colOrange">退回</span>';
  2426. } elseif ($value ['status'] == 5) {
  2427. $html .= '<span class="colGreen">打印</span>';
  2428. }
  2429. $html .= $value ['operation'] . '</p></blockquote>';
  2430. }
  2431. }
  2432. $html .= '</td></tr></tbody></table>';
  2433. }
  2434. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2435. }
  2436. echo json_encode ( array (
  2437. 'status' => 1,
  2438. 'html' => $html
  2439. ) );
  2440. die ();
  2441. } elseif ($type == 'RECEIVABLES') {
  2442. Doo::loadModel ( 'invoiceReceivables' );
  2443. $invoiceReceivables = new invoiceReceivables ();
  2444. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial, $this->staff [0] ['sid'] );
  2445. if (empty ( $detail ))
  2446. $html = '';
  2447. else {
  2448. $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">
  2449. <tbody><tr>
  2450. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  2451. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  2452. </tr><tr>
  2453. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  2454. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  2455. </tr>
  2456. <tr>
  2457. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  2458. <th class="taC">银行到帐</th><td>' . $detail ['receivablesDate'] . '</td>
  2459. </tr>
  2460. <tr>
  2461. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['bindDate'] . '</td>
  2462. </tr>
  2463. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2464. }
  2465. echo json_encode ( array (
  2466. 'status' => 1,
  2467. 'html' => $html
  2468. ) );
  2469. die ();
  2470. }
  2471. }
  2472. function ajaxGetInvoiceReceivablesByStaff() {
  2473. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  2474. if (empty ( $postData )) {
  2475. echo json_encode ( array (
  2476. 'status' => 2,
  2477. 'msg' => 'illegal request'
  2478. ) );
  2479. die ();
  2480. }
  2481. Doo::loadModel ( 'invoiceReceivables' );
  2482. $invoiceReceivables = new invoiceReceivables ();
  2483. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  2484. if (empty ( $detail )) {
  2485. echo json_encode ( array (
  2486. 'status' => 2,
  2487. 'msg' => 'illegal request'
  2488. ) );
  2489. die ();
  2490. }
  2491. Doo::loadModel ( 'L_category' );
  2492. $lCategory = new L_category ();
  2493. Doo::loadModel ( 'staff' );
  2494. $staff = new staff ();
  2495. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  2496. $category = $lCategory->getCategory ();
  2497. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  2498. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  2499. foreach ( $category as $key => $value ) {
  2500. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  2501. if ($value ['cid'] == $detail ['cid'])
  2502. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  2503. }
  2504. foreach ( $staffList as $key => $value ) {
  2505. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2506. if ($value ['sid'] == $detail ['sid'])
  2507. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2508. }
  2509. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  2510. echo json_encode ( array (
  2511. 'status' => 1,
  2512. 'categoryHtml' => $categoryHtml,
  2513. 'staffHtml' => $staffHtml,
  2514. 'rbankHtml' => $rbankHtml,
  2515. 'detail' => $detail
  2516. ) );
  2517. }
  2518. function _GetFileEXT($filename) {
  2519. $pics = explode ( '.', $filename );
  2520. $num = count ( $pics );
  2521. return $pics [$num - 1];
  2522. }
  2523. function showCache($path = "") {
  2524. if (file_exists ( $path )) {
  2525. $htm = file_get_contents ( $path );
  2526. } else {
  2527. Doo::loadModel ( 'invoiceStatistics' );
  2528. $invoiceStatistics = new invoiceStatistics ();
  2529. $isBriefly = $invoiceStatistics->getBrieflyStatistics ();
  2530. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  2531. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  2532. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  2533. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  2534. /*
  2535. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  2536. */
  2537. file_put_contents ( $path, $htm, FILE_APPEND );
  2538. }
  2539. return $htm;
  2540. }
  2541. /**
  2542. * 获取get或者POST值
  2543. *
  2544. * @param string $name 属性名称
  2545. * @return fixed 值
  2546. */
  2547. function get_args($name) {
  2548. if (isset ( $_GET [$name] )) {
  2549. if (is_array ( $_GET [$name] ))
  2550. return $_GET [$name];
  2551. else
  2552. return addslashes ( $_GET [$name] );
  2553. } elseif (isset ( $_POST [$name] )) {
  2554. if (is_array ( $_POST [$name] ))
  2555. return $_POST [$name];
  2556. else
  2557. return addslashes ( $_POST [$name] );
  2558. } else
  2559. return false;
  2560. }
  2561. /**
  2562. * 获得分页数据
  2563. * @param unknown_type $table
  2564. * @param unknown_type $condition
  2565. * @param unknown_type $on_page
  2566. * @param unknown_type $page_size
  2567. */
  2568. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  2569. $page_c = "";
  2570. $page ['previous'] = $this->get_previous ( $on_page );
  2571. $page ['on_page'] = $on_page;
  2572. $total_count = $this->get_table_count ( $table, $condition );
  2573. $total = intval ( $total_count / $page_size );
  2574. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  2575. $page ['total_data'] = $total_count;
  2576. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  2577. $i = 1;
  2578. $page_max = 1;
  2579. $page_width = 3;
  2580. if ($on_page >= $page_width) {
  2581. $page_max = intval ( $on_page / $page_width ) + 1;
  2582. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  2583. }
  2584. for(; $i <= $page ['total_page']; $i ++) {
  2585. if ($i == $on_page)
  2586. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  2587. else
  2588. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  2589. if ($i == ($page_width * $page_max))
  2590. break;
  2591. }
  2592. $page ['page'] = $page_c;
  2593. $page ['lower'] = (-- $on_page) * $page_size;
  2594. return $page;
  2595. }
  2596. /**
  2597. * 获取上一页
  2598. * @param unknown_type $on_page
  2599. */
  2600. function get_previous($on_page = 1) {
  2601. return $on_page != 0 ? $on_page - 1 : $on_page;
  2602. }
  2603. /**
  2604. * 获取总页数
  2605. * @param unknown_type $table
  2606. * @param unknown_type $condition
  2607. */
  2608. public function get_table_count($table = "", $condition = "") {
  2609. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  2610. $sql = "select count(*) as count from " . $table . " where " . $condition;
  2611. // echo $sql;die;
  2612. $query = Doo::db ()->query ( $sql );
  2613. $result = $query->fetch ();
  2614. return $result ['count'];
  2615. }
  2616. function isInvoiceNew($type = "GLOBAL") {
  2617. Doo::loadModel ( 'invoice' );
  2618. $invoice = new invoice ();
  2619. Doo::loadModel ( 'invoiceReceivables' );
  2620. $invoiceReceivables = new invoiceReceivables ();
  2621. Doo::loadModel ( 'staff' );
  2622. $staff = new staff ();
  2623. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  2624. // 我的发票待处理
  2625. $pendingInvoice = $invoice->getOne ( array (
  2626. 'where' => "(status=3 or status=4 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 ) ) and isDelete=0 and sid=" . $_COOKIE ["staff"],
  2627. 'desc' => 'iid',
  2628. 'asArray' => TRUE
  2629. ) );
  2630. // 我的收款待入账
  2631. $myClaim = $invoiceReceivables->getOne ( array (
  2632. 'where' => " receivablesStaff like '" . $_COOKIE ["staff"] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0",
  2633. 'desc' => 'irid',
  2634. 'asArray' => TRUE
  2635. ) );
  2636. // 发票审批
  2637. $approval = $invoice->getOne ( array (
  2638. 'where' => 'status=1 and pendingApprovals=' . $_COOKIE ["staff"],
  2639. 'desc' => 'iid',
  2640. 'asArray' => true
  2641. ) );
  2642. // 发票邮寄
  2643. $post = $invoice->getOne ( array (
  2644. 'where' => "postStatus=0 and doPost=1 and status=2",
  2645. 'asArray' => TRUE
  2646. ) );
  2647. // 发票打印
  2648. $print = $invoice->getOne ( array (
  2649. 'where' => "status=2 and printStatus=0 and moldManage like '%[\"" . $_COOKIE ["staff"] . "\",%'",
  2650. 'desc' => 'iid',
  2651. 'asArray' => TRUE
  2652. ) );
  2653. // 发票退票
  2654. $untread = $invoice->getOne ( array (
  2655. 'where' => " printStatus=1 and untreadStatus=1 and status=2 ",
  2656. 'asArray' => TRUE
  2657. ) );
  2658. $new = array (
  2659. 'GLOBAL' => FALSE,
  2660. 'pendingInvoice' => FALSE,
  2661. 'myClaim' => FALSE,
  2662. 'approval' => FALSE,
  2663. 'post' => FALSE,
  2664. 'print' => FALSE,
  2665. 'untread' => FALSE
  2666. );
  2667. if (! empty ( $pendingInvoice ) || ! empty ( $myClaim ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  2668. $new ['GLOBAL'] = TRUE;
  2669. if (! empty ( $pendingInvoice ))
  2670. $new ['pendingInvoice'] = TRUE;
  2671. if (! empty ( $myClaim ))
  2672. $new ['myClaim'] = TRUE;
  2673. if (! empty ( $approval ))
  2674. $new ['approval'] = TRUE;
  2675. if (! empty ( $post ))
  2676. $new ['post'] = TRUE;
  2677. if (! empty ( $print ))
  2678. $new ['print'] = TRUE;
  2679. if (! empty ( $untread ))
  2680. $new ['untread'] = TRUE;
  2681. return $new;
  2682. }
  2683. }
  2684. ?>