invoice.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. /**
  4. * 发票审批相关信息及其操作业务逻辑
  5. * @author CP.
  6. * @version 1.0
  7. * @namespace invoice
  8. * @package invoiceModel
  9. */
  10. class invoice extends DooModel {
  11. private $INVOICEKEY = "APPROVAL";
  12. private $FUZZY = 'FUZZY';
  13. private $EXACTLY = "EXACTLY";
  14. /**
  15. *
  16. * @var integer $iid 发票ID
  17. */
  18. public $iid;
  19. public $isid;
  20. public $trainId;
  21. public $lossIid;
  22. public $ipSource;
  23. /**
  24. *
  25. * @var integer $status 审批状态
  26. */
  27. public $status;
  28. /**
  29. *
  30. * @var string $invoiceManage 当前审批组人员
  31. */
  32. public $printStatus;
  33. public $postStatus;
  34. public $invoiceManage;
  35. /**
  36. *
  37. * @var string $pendingApprovals 当前需要审批的人
  38. */
  39. public $pendingApprovals;
  40. /**
  41. *
  42. * @var string $processApprovals 已经审批过的人员
  43. */
  44. public $processApprovals;
  45. /**
  46. *
  47. * @var string $invoiceSerial 发票单号
  48. */
  49. public $invoiceSerial;
  50. /**
  51. *
  52. * @var integer $invoicePrice 发票金额
  53. */
  54. public $invoicePrice;
  55. public $invoiceQuantity;
  56. public $invoiceUnitPrice;
  57. /**
  58. * 管理组人员:发票打印,
  59. * @var unknown
  60. */
  61. public $moldManage;
  62. /**
  63. *
  64. * @var integer $cid 办事处ID
  65. */
  66. public $cid;
  67. /**
  68. *
  69. * @var string $categoryName 办事处名称
  70. */
  71. public $categoryName;
  72. /**
  73. *
  74. * @var integer $sid 提交发票人ID
  75. */
  76. public $sid;
  77. /**
  78. *
  79. * @var string $userName 提交人名字
  80. */
  81. public $printer;
  82. public $userName;
  83. /**
  84. *
  85. * @var string $remark 备注
  86. */
  87. public $remark;
  88. /**
  89. *
  90. * @var string $invoiceElement 发票内容
  91. */
  92. public $invoiceElement;
  93. /**
  94. *
  95. * @var string $invoiceType 发票类型
  96. */
  97. public $invoiceType;
  98. /**
  99. *
  100. * @var string $invoiceTitle 发票抬头
  101. */
  102. public $invoiceTitle;
  103. /**
  104. *
  105. * @var string $invoiceCompany 开票公司
  106. */
  107. public $invoiceCompany;
  108. /**
  109. *
  110. * @var string $invoiceNo 发票号
  111. */
  112. public $invoiceNo;
  113. /**
  114. *
  115. * @var string $TIN 纳税人识别码
  116. */
  117. public $TIN;
  118. /**
  119. *
  120. * @var string $address 注册地址
  121. */
  122. public $address;
  123. /**
  124. *
  125. * @var string $phone 电话
  126. */
  127. public $phone;
  128. /**
  129. *
  130. * @var string $bank 开户银行
  131. */
  132. public $bank;
  133. /**
  134. *
  135. * @var string $bankAccount 银行账户
  136. */
  137. public $bankAccount;
  138. /**
  139. *
  140. * @var integer $doPost 邮寄
  141. */
  142. public $doPost;
  143. /**
  144. *
  145. * @var string $recipients 收件人
  146. */
  147. public $recipients;
  148. /**
  149. *
  150. * @var string $recipientsPhone 收件人电话
  151. */
  152. public $recipientsPhone;
  153. /**
  154. *
  155. * @var string $recipientsAddress 收件地址
  156. */
  157. public $recipientsAddress;
  158. /**
  159. *
  160. * @var string $mailItems 邮寄物品
  161. */
  162. public $mailItems;
  163. public $mailItemsJson;
  164. public $expressCompany;
  165. public $expressNumber;
  166. public $actualItems;
  167. public $poster;
  168. public $untreadReason;
  169. public $untreadPost;
  170. public $untreadCompany;
  171. public $untreadNumber;
  172. public $untreadItems;
  173. public $untreadStatus;
  174. public $irid;
  175. public $bindTime;
  176. /**
  177. *
  178. * @var date $date 提交时间
  179. */
  180. public $date;
  181. public $isDelete;
  182. public $approvalTime;
  183. /**
  184. *
  185. * @var date $updateTime 更新时间
  186. */
  187. public $updateTime;
  188. /**
  189. *
  190. * @var date $printTime 打印时间
  191. */
  192. public $printTime;
  193. public $postTime;
  194. public $_table = 'CLD_invoice';
  195. public $_primarykey = 'iid';
  196. public $_fields = array (
  197. 'iid',
  198. 'isid',
  199. 'trainId',
  200. 'ipSource',
  201. 'lossIid',
  202. 'invoiceManage',
  203. 'pendingApprovals',
  204. 'processApprovals',
  205. 'invoiceSerial',
  206. 'status',
  207. 'printStatus',
  208. 'postStatus',
  209. 'untreadStatus',
  210. 'invoiceQuantity',
  211. 'invoiceUnitPrice',
  212. 'invoicePrice',
  213. 'moldManage',
  214. 'cid',
  215. 'categoryName',
  216. 'irid',
  217. 'remark',
  218. 'invoiceElement',
  219. 'invoiceType',
  220. 'invoiceTitle',
  221. 'invoiceCompany',
  222. 'invoiceNo',
  223. 'TIN',
  224. 'address',
  225. 'phone',
  226. 'bank',
  227. 'bankAccount',
  228. 'doPost',
  229. 'recipients',
  230. 'recipientsPhone',
  231. 'recipientsAddress',
  232. 'mailItems',
  233. 'mailItemsJson',
  234. 'expressCompany',
  235. 'expressNumber',
  236. 'actualItems',
  237. 'untreadReason',
  238. 'untreadPost',
  239. 'untreadCompany',
  240. 'untreadNumber',
  241. 'untreadItems',
  242. 'poster',
  243. 'sid',
  244. 'userName',
  245. 'printer',
  246. 'date',
  247. 'isDelete',
  248. 'approvalTime',
  249. 'updateTime',
  250. 'printTime',
  251. 'postTime',
  252. 'bindTime'
  253. );
  254. /**
  255. * 根据发票ID获取一条发票数据
  256. * @param number $iid 发票ID
  257. * @param number $select 需要获取的字段,为空获取全部数据
  258. * @return array|array() 返回发票数据
  259. */
  260. public function getInvoiceByIid($iid = 0, $select = "") {
  261. if (! is_numeric ( $iid ))
  262. $iid = $this->authcode ( $iid );
  263. $condition = array (
  264. 'where' => "iid=" . $iid,
  265. 'asArray' => TRUE
  266. );
  267. if (! empty ( $select ))
  268. $condition += array (
  269. 'select' => $select
  270. );
  271. $Detail = array ();
  272. if (is_numeric ( $iid ) && ! empty ( $iid ))
  273. $Detail = $this->getOne ( $condition );
  274. if (empty ( $Detail ))
  275. return $Detail;
  276. if (isset ( $Detail ['expressCompany'] ) && ! empty ( $Detail ['expressCompany'] )) {
  277. $express = explode ( ":", $Detail ['expressCompany'] );
  278. $Detail ['expressCompany'] = $express [0];
  279. $Detail ['expressCom'] = $express [1];
  280. } else {
  281. $Detail ['expressCompany'] = '';
  282. $Detail ['expressCom'] = '';
  283. }
  284. Doo::loadClass ( 'XDeode' );
  285. $XDeode = new XDeode ( 5 );
  286. $Detail ['iidKeyUrl'] = $XDeode->encode ( $Detail ['iid'] );
  287. $Detail ['iidKey'] = $this->authcode ( $Detail ['iid'], '' );
  288. Doo::loadModel ( 'L_category' );
  289. $lCategory = new L_category ();
  290. $Detail ['category'] = $lCategory->getCategory ();
  291. return $Detail;
  292. }
  293. /**
  294. * 根据多个iid获得多个发票
  295. * @param number $iid
  296. */
  297. function getInvoiceInIid($iid = 0, $select = '') {
  298. if (empty ( $iid ))
  299. die ( 'illegal request' );
  300. $condition = array (
  301. 'where' => "iid in ( " . $iid . ")",
  302. 'asArray' => TRUE
  303. );
  304. if (! empty ( $select ))
  305. $condition += array (
  306. 'select' => $select
  307. );
  308. $list = $this->find ( $condition );
  309. Doo::loadClass ( 'XDeode' );
  310. $XDeode = new XDeode ( 5 );
  311. foreach ($list as $key=>$value){
  312. $list [$key]['iidKey'] = $XDeode->encode ( $value ['iid'] );
  313. }
  314. return $list;
  315. }
  316. function setInvoiceLoss($iid = "") {
  317. if (empty ( $iid ))
  318. return 0;
  319. $sql = 'insert into ' . $this->_table . '(`status`, `printStatus`, `postStatus`, `untreadStatus`, `invoiceManage`, `pendingApprovals`, `processApprovals`, `invoiceSerial`,`invoiceQuantity`, `invoiceUnitPrice`, `invoicePrice`, `moldManage`, `cid`, `categoryName`, `sid`, `userName`, `printer`, `irid`, `remark`, `invoiceElement`, `invoiceType`, `invoiceTitle`, `invoiceCompany`, `invoiceNo`, `TIN`, `address`, `phone`, `bank`, `bankAccount`, `doPost`, `recipients`, `recipientsPhone`, `recipientsAddress`, `mailItems`, `mailItemsJson`, `expressCompany`, `expressNumber`, `actualItems`, `untreadReason`, `untreadPost`, `untreadCompany`, `untreadNumber`, `untreadItems`, `poster`, `date`, `isDelete`, `updateTime`, `printTime`, `postTime`, `bindTime`)
  320. select `status`, `printStatus`, `postStatus`, `untreadStatus`, `invoiceManage`, `pendingApprovals`, `processApprovals`, `invoiceSerial`,`invoiceQuantity`, `invoiceUnitPrice`, `invoicePrice`, `moldManage`, `cid`, `categoryName`, `sid`, `userName`, `printer`, `irid`, `remark`, `invoiceElement`, `invoiceType`, `invoiceTitle`, `invoiceCompany`, `invoiceNo`, `TIN`, `address`, `phone`, `bank`, `bankAccount`, `doPost`, `recipients`, `recipientsPhone`, `recipientsAddress`, `mailItems`, `mailItemsJson`, `expressCompany`, `expressNumber`, `actualItems`, `untreadReason`, `untreadPost`, `untreadCompany`, `untreadNumber`, `untreadItems`, `poster`, `date`, `isDelete`, `updateTime`, `printTime`, `postTime`, `bindTime` from ' . $this->_table . ' where iid=' . $iid;
  321. $query = Doo::db ()->query ( $sql );
  322. return Doo::db ()->lastInsertId ();
  323. }
  324. function getInvoiceByInvoiceNo($invoiceNo = '') {
  325. if (empty ( $invoiceNo ))
  326. return array ();
  327. $detail = $this->getOne ( array (
  328. 'where' => "invoiceNo= '" . $invoiceNo . "'",
  329. 'asArray' => TRUE
  330. ) );
  331. return $detail;
  332. }
  333. /**
  334. * 根据标题或者开票单位获得相关信息 - 准确查询
  335. * @param string $title 查询条件
  336. * @param string $query 默认模糊查询
  337. */
  338. public function getInvoiceByTitle($title = "", $query = "FUZZY", $cond = '', $fkq = false) {
  339. $detail = array ();
  340. if (! empty ( $title )) {
  341. $condition = array (
  342. 'asArray' => TRUE
  343. );
  344. if ($query == $this->FUZZY)
  345. $condition += array (
  346. 'where' => " (invoiceTitle like '%" . $title . "%' or invoiceCompany like '%" . $title . "%') " . $cond
  347. );
  348. else
  349. $condition += array (
  350. 'where' => "(invoiceTitle = '" . $title . "' or invoiceCompany= '" . $title . "') " . $cond
  351. );
  352. Doo::loadClass ( 'XDeode' );
  353. $XDeode = new XDeode ( 5 );
  354. if ($fkq) {
  355. $detail = $this->find ( $condition );
  356. foreach ( $detail as $key => $value ) {
  357. $detail [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  358. $detail [$key] ['iidKeyXD'] = $XDeode->encode ( $value ['iid'] );
  359. }
  360. } else {
  361. $detail = $this->getOne ( $condition );
  362. if (! empty ( $detail )) {
  363. $detail ['iidKey'] = $this->authcode ( $detail ['iid'], '' );
  364. $detail ['iidKeyXD'] = $XDeode->encode ( $detail ['iid'] );
  365. }
  366. }
  367. }
  368. return $detail;
  369. }
  370. public function getInvoiceByIsid($iid = "", $sid = 0) {
  371. if (empty ( $iid ) || empty ( $sid ))
  372. return array ();
  373. Doo::loadClass ( 'XDeode' );
  374. $XDeode = new XDeode ( 5 );
  375. $iid = $XDeode->decode ( $iid );
  376. if (! is_numeric ( $iid ))
  377. return array ();
  378. $detail = $this->getOne ( array (
  379. 'where' => "iid= '" . $iid . "'", // and sid=".$sid,
  380. 'asArray' => TRUE
  381. ) );
  382. $detail ['expressCompany'] = '';
  383. $detail ['expressCom'] = '';
  384. if (! empty ( $detail ['expressCompany'] )) {
  385. $express = explode ( ":", $detail ['expressCompany'] );
  386. $detail ['expressCompany'] = $express [0];
  387. $detail ['expressCom'] = $express [1];
  388. }
  389. $detail ['iidKeyXD'] = $this->authcode ( $detail ['iid'], '' );
  390. return $detail;
  391. }
  392. /**
  393. * 统计培训班开票
  394. */
  395. function sumOfinvoiceTrain($itidSql) {
  396. $sql = 'select sum(invoicePrice) as invoicePrice ,trainId
  397. from ' . $this->_table . '
  398. where trainId in (' . $itidSql . ') and status=2 and printStatus=1 and (untreadStatus =0 or untreadStatus=3)
  399. GROUP BY trainId';
  400. $query = Doo::db ()->query ( $sql );
  401. return $result = $query->fetchAll ();
  402. }
  403. function sumOfInvoiceRecelvablesTrain($itidSql) {
  404. $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  405. from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on find_in_set(a.irid,b.irid)
  406. where a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!=""
  407. GROUP BY a.trainId';
  408. $query = Doo::db ()->query ( $sql );
  409. return $result = $query->fetchAll ();
  410. }
  411. /**
  412. * 根据仓库ID获得发票
  413. * @param string $Istoreid
  414. * @return unknown
  415. */
  416. public function getInvoiceByIstoreid($Istoreid = "", $select = "") {
  417. if (empty ( $Istoreid ))
  418. return array ();
  419. $condition = array (
  420. 'where' => "isid in ( " . $Istoreid . ")",
  421. 'asArray' => TRUE
  422. );
  423. if (! empty ( $select ))
  424. $condition += array (
  425. 'select' => $select
  426. );
  427. $detail = $this->find ( $condition );
  428. return $detail;
  429. }
  430. /**
  431. * 获取单个可以打印的发票数据
  432. * @param number $iid 发票id
  433. * @param number $select 需要获取的字段,为空获取全部数据
  434. * @return array|array() 返回发票数据
  435. */
  436. public function getInvoiceByPrint($iid = 0, $select = "") {
  437. $condition = array (
  438. 'where' => "iid= '" . $iid . "' and status=2 and untreadStatus=0 ",
  439. 'asArray' => TRUE
  440. );
  441. if (! empty ( $select ))
  442. $condition += array (
  443. 'select' => $select
  444. );
  445. $detail = array ();
  446. if (! empty ( $iid ) && is_numeric ( $iid ))
  447. $detail = $this->getOne ( $condition );
  448. return $detail;
  449. }
  450. /**
  451. * 添加一个发票并进入审批状态
  452. * @param array $item 发票相关数据
  453. * @return number 返回发票ID
  454. */
  455. public function addInvoice($item = array()) {
  456. $lid = 0;
  457. if (is_array ( $item ) && ! empty ( $item )) {
  458. foreach ( $item as $key => $value ) {
  459. $this->$key = $value;
  460. }
  461. $lid = $this->insert ();
  462. }
  463. return $lid;
  464. }
  465. /**
  466. * 根据参数字段更新相应字段(主键ID必须传)
  467. * @param array $item 相关需要更新的字段信息
  468. * @return number 返回发票ID
  469. */
  470. public function setInvoiceByCondition($item = array()) {
  471. $lid = 0;
  472. if (is_array ( $item ) && ! empty ( $item )) {
  473. foreach ( $item as $key => $value ) {
  474. $this->$key = $value;
  475. }
  476. $lid = $this->update ();
  477. }
  478. return $lid;
  479. }
  480. /**
  481. * 根据参数字段批量更新相应字段(主键ID必须传)
  482. * @param array $item 相关需要更新的字段信息
  483. * @return number 返回发票ID
  484. */
  485. public function BatchInvoiceByCondition($item = array(), $iid = "") {
  486. $lid = 0;
  487. if (is_array ( $item ) && ! empty ( $item )) {
  488. foreach ( $item as $key => $value ) {
  489. $this->$key = $value;
  490. }
  491. if (! empty ( $iid )) {
  492. $condition = array (
  493. 'where' => "iid in (" . $iid . ")",
  494. 'asArray' => TRUE
  495. );
  496. $this->update ( $condition );
  497. } else
  498. $lid = $this->update ();
  499. }
  500. return $lid;
  501. }
  502. /**
  503. * 根据管理组和发票当前状态获得打印发票数据;其中当iid为空时获取所有发票数据,反之获取1条数据
  504. * @param number $sid 管理组人员ID
  505. * @param number $status 状态 为0时获取可以打印数据,为1时获取已经完成打印数据
  506. * @param number $iid 发票ID
  507. * @return array|array() 返回所有发票数据,当iid有值时返回一条数据
  508. */
  509. public function getPrintInvoiceByManage($sid = 0, $status = 0, $iid = 0) {
  510. $list = array ();
  511. if (! empty ( $sid ) && empty ( $iid ))
  512. $list = $this->find ( array (
  513. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%'",
  514. 'desc' => 'approvalTime',
  515. 'asArray' => TRUE
  516. ) );
  517. elseif (! empty ( $sid ) && ! empty ( $iid ))
  518. $list = $this->getOne ( array (
  519. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%' and iid=" . $iid,
  520. 'asArray' => TRUE
  521. ) );
  522. return $list;
  523. }
  524. /**
  525. * 获得与我相关的发票数据,其中包含 处理中,待处理,最旧入账等数据;当iid有值时获取一条关于sid的发票
  526. * @param number $sid 用户ID
  527. * @param number $iid 发票ID
  528. * @return array|array()
  529. */
  530. public function getMyInvoice($sid = 0, $iid = 0) {
  531. Doo::loadModel ( 'invoiceOperationLog' );
  532. $invoiceOperationLog = new invoiceOperationLog ();
  533. Doo::loadClass ( 'XDeode' );
  534. $XDeode = new XDeode ( 5 );
  535. $list = array ();
  536. if (! empty ( $iid )) {
  537. $list = $this->getOne ( array (
  538. 'where' => " sid=" . $sid . " and iid=" . $iid,
  539. 'asArray' => TRUE
  540. ) );
  541. } elseif (! empty ( $sid ) && empty ( $iid )) {
  542. $list ['pendingInvoice'] = array ();
  543. $list ['handleInvoice'] = array ();
  544. $list ['pendingInvoice'] = $this->find ( array ( // 加入邮件中也为 处理中 已退票
  545. 'where' => "((status=1 and untreadStatus=0) or (status=2 and printStatus=0 and untreadStatus=0) or
  546. ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=0)
  547. or (postStatus=0 and doPost=1 and status=2 and untreadStatus=0) ) and isDelete=0 and sid=" . $sid,
  548. 'desc' => 'iid',
  549. 'asArray' => TRUE
  550. ) );
  551. foreach ( $list ['pendingInvoice'] as $key => $value ) {
  552. $list ['pendingInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  553. $list ['pendingInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  554. }
  555. $list ['handleInvoice'] = $this->find ( array (
  556. // 需求变更 -去除出票状态的数据 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  557. // 新加入退票中 需要邮寄的发票
  558. 'where' => "(status=3 or status=4 or (status=2 and untreadStatus=2 ) or ( status=2 and untreadStatus=1 ) ) and isDelete=0 and sid=" . $sid,
  559. 'desc' => 'iid',
  560. 'asArray' => TRUE
  561. ) );
  562. foreach ( $list ['handleInvoice'] as $key => $value ) {
  563. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  564. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  565. $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  566. }
  567. }
  568. return $list;
  569. }
  570. /**
  571. * 获得所有未入账发票
  572. * @param number $invoiceTC 发票title
  573. */
  574. public function getInvoiceByUnAccount($invoiceTC = '', $iridExist = false) {
  575. Doo::loadClass ( 'XDeode' );
  576. $XDeode = new XDeode ( 5 );
  577. $title = "";
  578. if (! empty ( $invoiceTC ))
  579. $title = ' and (invoiceTitle like "%' . $invoiceTC . '%" or invoiceCompany like "%' . $invoiceTC . '%" )';
  580. $iridString = ' and irid="" ';
  581. if ($iridExist)
  582. $iridString = ' and irid!="" ';
  583. $list = $this->find ( array ( //
  584. 'where' => "status=2 and printStatus=1 " . $iridString . " and untreadStatus=0 and ( (doPost=1 and postStatus=1) or doPost=0 ) and isDelete=0 " . $title,
  585. 'desc' => 'iid',
  586. 'limit' => 5,
  587. 'asArray' => TRUE
  588. ) );
  589. foreach ( $list as $key => $value ) {
  590. $list [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  591. }
  592. return $list;
  593. }
  594. /**
  595. * 获得与我有关可收款的发票,已经出票的发票
  596. * @param number $sid 开票人ID
  597. */
  598. public function getInvoiceByReceivables($sid = 0) {
  599. Doo::loadClass ( 'XDeode' );
  600. $XDeode = new XDeode ( 5 );
  601. $list ['handleInvoice'] = $this->find ( array (
  602. 'where' => "(status=2 and printStatus=1 and untreadStatus=0 ) and isDelete=0 and sid=" . $sid,
  603. 'desc' => 'iid',
  604. 'asArray' => TRUE
  605. ) );
  606. foreach ( $list ['handleInvoice'] as $key => $value ) {
  607. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  608. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  609. // $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  610. }
  611. return $list ['handleInvoice'];
  612. }
  613. /**
  614. * 获取需要邮寄的发票
  615. * @param integer $postStatus 0为获取需要邮寄的发票,1为获取已经邮寄的发票
  616. * @return array|array() 返回相关数据
  617. */
  618. public function getPostByInvoice($postStatus = 0) {
  619. Doo::loadClass ( 'XDeode' );
  620. $XDeode = new XDeode ( 5 );
  621. $list = $this->find ( array ( // and untreadStatus=0
  622. 'where' => "postStatus=" . $postStatus . " and printStatus=1 and doPost=1 and status=2 and isDelete=0",
  623. 'limit' => 7,
  624. 'asArray' => TRUE
  625. ) );
  626. foreach ( $list as $key => $value ) {
  627. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  628. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  629. $list [$key] ['expressCompany'] = '';
  630. $list [$key] ['expressCom'] = '';
  631. if (! empty ( $value ['expressCompany'] )) {
  632. $express = explode ( ":", $value ['expressCompany'] );
  633. $list [$key] ['expressCompany'] = $express [0];
  634. $list [$key] ['expressCom'] = $express [1];
  635. }
  636. }
  637. return $list;
  638. }
  639. /**
  640. * 根据退票状态获得相关数据,iid有值时只获得一条数据
  641. * @param number $untreadStatus 退票状态
  642. * @param number $iid 发票ID
  643. */
  644. public function getInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0) {
  645. Doo::loadClass ( 'XDeode' );
  646. $XDeode = new XDeode ( 5 );
  647. if (empty ( $iid )) {
  648. $list = $this->find ( array ( // printStatus=1 and
  649. 'where' => " untreadStatus=" . $untreadStatus . " and status=2 ",
  650. 'asArray' => TRUE
  651. ) );
  652. if ($untreadStatus == 2) {
  653. Doo::loadModel ( 'invoiceOperationLog' );
  654. $invoiceOperationLog = new invoiceOperationLog ();
  655. }
  656. foreach ( $list as $key => $value ) {
  657. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  658. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  659. $list [$key] ['untreadCompany'] = '';
  660. $list [$key] ['untreadCom'] = '';
  661. if (! empty ( $value ['untreadCompany'] )) {
  662. $express = explode ( ":", $value ['untreadCompany'] );
  663. $list [$key] ['untreadCompany'] = $express [0];
  664. $list [$key] ['untreadCom'] = $express [1];
  665. }
  666. if ($untreadStatus == 2) {
  667. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  668. }
  669. $list [$key] ['lossDetail'] = array ();
  670. if ($value ['lossIid'] != 0) {
  671. $detail = $this->getOne ( array (
  672. 'where' => "iid=" . $value ['lossIid'],
  673. 'asArray' => TRUE
  674. ) );
  675. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  676. $list [$key] ['lossDetail'] = $detail;
  677. }
  678. }
  679. } else {
  680. $list = $this->getOne ( array (
  681. 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
  682. 'asArray' => TRUE
  683. ) );
  684. }
  685. return $list;
  686. }
  687. /**
  688. * 审批中获取相关数据 包括最近的一条操作记录
  689. * @param number $status.
  690. * @param number $limit.
  691. */
  692. function getInvoiceByProcessStatus($limit = 4, $desc = 'desc') {
  693. Doo::loadClass ( 'XDeode' );
  694. $XDeode = new XDeode ( 5 );
  695. $list = $this->find ( array (
  696. 'where' => " (status=1 or status=2 or status=3 or status=4) and processApprovals!=''",
  697. 'limit' => $limit,
  698. $desc => 'iid',
  699. 'asArray' => TRUE
  700. ) );
  701. Doo::loadModel ( 'invoiceOperationLog' );
  702. $invoiceOperationLog = new invoiceOperationLog ();
  703. foreach ( $list as $key => $value ) {
  704. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  705. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $value['status'] );
  706. }
  707. return $list;
  708. }
  709. function getInvoiceByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc', $olStatus = "desc") {
  710. if (empty ( $limit ) || empty ( $con ))
  711. return array ();
  712. $listCount=$this->count(array (
  713. 'where' => $con,
  714. 'asArray' => TRUE
  715. ) ) ;
  716. $list = $this->find ( array (
  717. 'where' => $con,
  718. 'limit' => $limit,
  719. $desc => 'approvalTime',
  720. 'asArray' => TRUE
  721. ) );
  722. Doo::loadClass ( 'XDeode' );
  723. $XDeode = new XDeode ( 5 );
  724. Doo::loadModel ( 'invoiceReceivables' );
  725. $invoiceReceivables = new invoiceReceivables ();
  726. Doo::loadModel ( 'invoiceOperationLog' );
  727. $invoiceOperationLog = new invoiceOperationLog ();
  728. foreach ( $list as $key => $value ) {
  729. $list [$key] ['count'] = $listCount;
  730. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  731. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  732. $list [$key] ['untreadCompany'] = '';
  733. $list [$key] ['untreadCom'] = '';
  734. if (! empty ( $value ['untreadCompany'] )) {
  735. $express = explode ( ":", $value ['untreadCompany'] );
  736. $list [$key] ['untreadCompany'] = $express [0];
  737. $list [$key] ['untreadCom'] = $express [1];
  738. }
  739. $list [$key] ['irList'] = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  740. if ($olStatus == 'desc')
  741. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  742. else
  743. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $olStatus );
  744. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  745. $list [$key] ['OL'] = $invoiceOperationLog->getInvoiceOperationInStatus ( $value ['iid'], '2,3,4' );
  746. // print_r($list [$key] ['OperationLog']);
  747. $list [$key] ['sumPrice'] = 0;
  748. if (! empty ( $list [$key] ['irList'] ))
  749. $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  750. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  751. $list [$key] ['lossDetail'] = array ();
  752. if ($value ['lossIid'] != 0) {
  753. $detail = $this->getOne ( array (
  754. 'where' => "iid=" . $value ['lossIid'],
  755. 'asArray' => TRUE
  756. ) );
  757. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  758. $list [$key] ['lossDetail'] = $detail;
  759. }
  760. $lossDate = strtotime ( "+1 month", strtotime ( $list [$key] ['OperationLog'] ['date'] ) );
  761. $nowDate = strtotime ( 'now' );
  762. $list [$key] ['lossShow'] = false;
  763. if ($lossDate < $nowDate)
  764. $list [$key] ['lossShow'] = true;
  765. }
  766. return $list;
  767. }
  768. /**
  769. * 加密或解密指定字符串
  770. *
  771. * @param string $string 要加密或解密的字符串
  772. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  773. * @param string $key 加解密的key
  774. * @param $expiry 超时值
  775. *
  776. */
  777. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  778. $ckey_length = 4;
  779. if (! $key) {
  780. $key = $this->INVOICEKEY;
  781. }
  782. $key = md5 ( $key );
  783. $keya = md5 ( substr ( $key, 0, 16 ) );
  784. $keyb = md5 ( substr ( $key, 16, 16 ) );
  785. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  786. $cryptkey = $keya . md5 ( $keya . $keyc );
  787. $key_length = strlen ( $cryptkey );
  788. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  789. $string_length = strlen ( $string );
  790. $result = '';
  791. $box = range ( 0, 255 );
  792. $rndkey = array ();
  793. for($i = 0; $i <= 255; $i ++) {
  794. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  795. }
  796. for($j = $i = 0; $i < 256; $i ++) {
  797. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  798. $tmp = $box [$i];
  799. $box [$i] = $box [$j];
  800. $box [$j] = $tmp;
  801. }
  802. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  803. $a = ($a + 1) % 256;
  804. $j = ($j + $box [$a]) % 256;
  805. $tmp = $box [$a];
  806. $box [$a] = $box [$j];
  807. $box [$j] = $tmp;
  808. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  809. }
  810. if ($operation == 'DECODE') {
  811. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  812. return substr ( $result, 26 );
  813. } else {
  814. return '';
  815. }
  816. } else {
  817. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  818. }
  819. }
  820. }
  821. ?>