invoice.php 22 KB

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