invoice.php 22 KB

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