invoice.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  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`,`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`)
  287. 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;
  288. $query = Doo::db ()->query ( $sql );
  289. return Doo::db ()->lastInsertId ();
  290. }
  291. function getInvoiceByInvoiceNo($invoiceNo = '') {
  292. if (empty ( $invoiceNo ))
  293. return array ();
  294. $detail = $this->getOne ( array (
  295. 'where' => "invoiceNo= '" . $invoiceNo . "'",
  296. 'asArray' => TRUE
  297. ) );
  298. return $detail;
  299. }
  300. /**
  301. * 根据标题或者开票单位获得相关信息 - 准确查询
  302. * @param string $title 查询条件
  303. * @param string $query 默认模糊查询
  304. */
  305. public function getInvoiceByTitle($title = "", $query = "FUZZY", $cond = '') {
  306. $detail = array ();
  307. if (! empty ( $title )) {
  308. $condition = array (
  309. 'asArray' => TRUE
  310. );
  311. if ($query == $this->FUZZY)
  312. $condition += array (
  313. 'where' => " (invoiceTitle like '%" . $title . "%' or invoiceCompany '%" . $title . "%') " . $cond
  314. );
  315. else
  316. $condition += array (
  317. 'where' => "(invoiceTitle = '" . $title . "' or invoiceCompany= '" . $title . "') " . $cond
  318. );
  319. $detail = $this->getOne ( $condition );
  320. if (! empty ( $detail )) {
  321. Doo::loadClass ( 'XDeode' );
  322. $XDeode = new XDeode ( 5 );
  323. $detail ['iidKey'] = $this->authcode ( $detail ['iid'], '' );
  324. $detail ['iidKeyXD'] = $XDeode->encode ( $detail ['iid'] );
  325. }
  326. }
  327. return $detail;
  328. }
  329. public function getInvoiceByIsid($iid = "", $sid = 0) {
  330. if (empty ( $iid ) || empty ( $sid ))
  331. return array ();
  332. Doo::loadClass ( 'XDeode' );
  333. $XDeode = new XDeode ( 5 );
  334. $iid = $XDeode->decode ( $iid );
  335. if (! is_numeric ( $iid ))
  336. return array ();
  337. $detail = $this->getOne ( array (
  338. 'where' => "iid= '" . $iid . "'", // and sid=".$sid,
  339. 'asArray' => TRUE
  340. ) );
  341. return $detail;
  342. }
  343. /**
  344. * 获取单个可以打印的发票数据
  345. * @param number $iid 发票id
  346. * @param number $select 需要获取的字段,为空获取全部数据
  347. * @return array|array() 返回发票数据
  348. */
  349. public function getInvoiceByPrint($iid = 0, $select = "") {
  350. $condition = array (
  351. 'where' => "iid= '" . $iid . "' and status=2 and untreadStatus=0 ",
  352. 'asArray' => TRUE
  353. );
  354. if (! empty ( $select ))
  355. $condition += array (
  356. 'select' => $select
  357. );
  358. $detail = array ();
  359. if (! empty ( $iid ) && is_numeric ( $iid ))
  360. $detail = $this->getOne ( $condition );
  361. return $detail;
  362. }
  363. /**
  364. * 添加一个发票并进入审批状态
  365. * @param array $item 发票相关数据
  366. * @return number 返回发票ID
  367. */
  368. public function addInvoice($item = array()) {
  369. $lid = 0;
  370. if (is_array ( $item ) && ! empty ( $item )) {
  371. foreach ( $item as $key => $value ) {
  372. $this->$key = $value;
  373. }
  374. $lid = $this->insert ();
  375. }
  376. return $lid;
  377. }
  378. /**
  379. * 根据参数字段更新相应字段(主键ID必须传)
  380. * @param array $item 相关需要更新的字段信息
  381. * @return number 返回发票ID
  382. */
  383. public function setInvoiceByCondition($item = array()) {
  384. $lid = 0;
  385. if (is_array ( $item ) && ! empty ( $item )) {
  386. foreach ( $item as $key => $value ) {
  387. $this->$key = $value;
  388. }
  389. $lid = $this->update ();
  390. }
  391. return $lid;
  392. }
  393. /**
  394. * 根据管理组和发票当前状态获得打印发票数据;其中当iid为空时获取所有发票数据,反之获取1条数据
  395. * @param number $sid 管理组人员ID
  396. * @param number $status 状态 为0时获取可以打印数据,为1时获取已经完成打印数据
  397. * @param number $iid 发票ID
  398. * @return array|array() 返回所有发票数据,当iid有值时返回一条数据
  399. */
  400. public function getPrintInvoiceByManage($sid = 0, $status = 0, $iid = 0) {
  401. $list = array ();
  402. if (! empty ( $sid ) && empty ( $iid ))
  403. $list = $this->find ( array (
  404. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%'",
  405. 'desc' => 'iid',
  406. 'asArray' => TRUE
  407. ) );
  408. elseif (! empty ( $sid ) && ! empty ( $iid ))
  409. $list = $this->getOne ( array (
  410. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%' and iid=" . $iid,
  411. 'asArray' => TRUE
  412. ) );
  413. return $list;
  414. }
  415. /**
  416. * 获得与我相关的发票数据,其中包含 处理中,待处理,最旧入账等数据;当iid有值时获取一条关于sid的发票
  417. * @param number $sid 用户ID
  418. * @param number $iid 发票ID
  419. * @return array|array()
  420. */
  421. public function getMyInvoice($sid = 0, $iid = 0) {
  422. Doo::loadModel ( 'invoiceOperationLog' );
  423. $invoiceOperationLog = new invoiceOperationLog ();
  424. Doo::loadClass ( 'XDeode' );
  425. $XDeode = new XDeode ( 5 );
  426. $list = array ();
  427. if (! empty ( $iid )) {
  428. $list = $this->getOne ( array (
  429. 'where' => " sid=" . $sid . " and iid=" . $iid,
  430. 'asArray' => TRUE
  431. ) );
  432. } elseif (! empty ( $sid ) && empty ( $iid )) {
  433. $list ['pendingInvoice'] = array ();
  434. $list ['handleInvoice'] = array ();
  435. $list ['pendingInvoice'] = $this->find ( array ( // 加入邮件中也为 处理中 已退票
  436. 'where' => "((status=1) or (status=2 and printStatus=0) or ( status=2 and printStatus=1 and untreadStatus=0 ) or
  437. ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=0)
  438. or (postStatus=0 and doPost=1 and status=2) ) and sid=" . $sid,
  439. 'desc' => 'iid',
  440. 'asArray' => TRUE
  441. ) );
  442. foreach ( $list ['pendingInvoice'] as $key => $value ) {
  443. $list ['pendingInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  444. $list ['pendingInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  445. }
  446. $list ['handleInvoice'] = $this->find ( array (
  447. // 需求变更 -去除出票状态的数据 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  448. // 新加入退票中 需要邮寄的发票
  449. 'where' => "(status=3 or status=4 or (status=2 and printStatus=1 and untreadStatus=2 ) or ( status=2 and untreadStatus=1 ) ) and isDelete=0 and sid=" . $sid,
  450. 'desc' => 'iid',
  451. 'asArray' => TRUE
  452. ) );
  453. foreach ( $list ['handleInvoice'] as $key => $value ) {
  454. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  455. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  456. $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  457. }
  458. }
  459. return $list;
  460. }
  461. /**
  462. * 获得所有未入账发票
  463. * @param number $invoiceTC 发票title
  464. */
  465. public function getInvoiceByUnAccount($invoiceTC = '', $iridExist = false) {
  466. Doo::loadClass ( 'XDeode' );
  467. $XDeode = new XDeode ( 5 );
  468. $title = "";
  469. if (! empty ( $invoiceTC ))
  470. $title = ' and (invoiceTitle like "%' . $invoiceTC . '%" or invoiceCompany like "%' . $invoiceTC . '%" )';
  471. $iridString = ' and irid="" ';
  472. if ($iridExist)
  473. $iridString = ' and irid!="" ';
  474. $list = $this->find ( array ( //
  475. 'where' => "status=2 and printStatus=1 " . $iridString . " and untreadStatus=0 and ( (doPost=1 and postStatus=1) or doPost=0 ) and isDelete=0 " . $title,
  476. 'desc' => 'iid',
  477. 'limit' => 5,
  478. 'asArray' => TRUE
  479. ) );
  480. foreach ( $list as $key => $value ) {
  481. $list [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  482. }
  483. return $list;
  484. }
  485. /**
  486. * 获得与我有关可收款的发票,已经出票的发票
  487. * @param number $sid 开票人ID
  488. */
  489. public function getInvoiceByReceivables($sid = 0) {
  490. Doo::loadClass ( 'XDeode' );
  491. $XDeode = new XDeode ( 5 );
  492. $list ['handleInvoice'] = $this->find ( array (
  493. 'where' => "(status=2 and printStatus=1 and untreadStatus=0 ) and isDelete=0 and sid=" . $sid,
  494. 'desc' => 'iid',
  495. 'asArray' => TRUE
  496. ) );
  497. foreach ( $list ['handleInvoice'] as $key => $value ) {
  498. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  499. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  500. // $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  501. }
  502. return $list ['handleInvoice'];
  503. }
  504. /**
  505. * 获取需要邮寄的发票
  506. * @param integer $postStatus 0为获取需要邮寄的发票,1为获取已经邮寄的发票
  507. * @return array|array() 返回相关数据
  508. */
  509. public function getPostByInvoice($postStatus = 0) {
  510. Doo::loadClass ( 'XDeode' );
  511. $XDeode = new XDeode ( 5 );
  512. $list = $this->find ( array (
  513. 'where' => "postStatus=" . $postStatus . " and printStatus=1 and untreadStatus=0 and doPost=1 and status=2 and isDelete=0",
  514. 'asArray' => TRUE
  515. ) );
  516. foreach ( $list as $key => $value ) {
  517. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  518. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  519. $list [$key] ['expressCompany'] = '';
  520. $list [$key] ['expressCom'] = '';
  521. if (! empty ( $value ['expressCompany'] )) {
  522. $express = explode ( ":", $value ['expressCompany'] );
  523. $list [$key] ['expressCompany'] = $express [0];
  524. $list [$key] ['expressCom'] = $express [1];
  525. }
  526. }
  527. return $list;
  528. }
  529. /**
  530. * 根据退票状态获得相关数据,iid有值时只获得一条数据
  531. * @param number $untreadStatus 退票状态
  532. * @param number $iid 发票ID
  533. */
  534. public function getInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0) {
  535. Doo::loadClass ( 'XDeode' );
  536. $XDeode = new XDeode ( 5 );
  537. if (empty ( $iid )) {
  538. $list = $this->find ( array (// printStatus=1 and
  539. 'where' => " untreadStatus=" . $untreadStatus . " and status=2 ",
  540. 'asArray' => TRUE
  541. ) );
  542. if ($untreadStatus == 2) {
  543. Doo::loadModel ( 'invoiceOperationLog' );
  544. $invoiceOperationLog = new invoiceOperationLog ();
  545. }
  546. foreach ( $list as $key => $value ) {
  547. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  548. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  549. $list [$key] ['untreadCompany'] = '';
  550. $list [$key] ['untreadCom'] = '';
  551. if (! empty ( $value ['untreadCompany'] )) {
  552. $express = explode ( ":", $value ['untreadCompany'] );
  553. $list [$key] ['untreadCompany'] = $express [0];
  554. $list [$key] ['untreadCom'] = $express [1];
  555. }
  556. if ($untreadStatus == 2) {
  557. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  558. }
  559. $list [$key] ['lossDetail'] = array ();
  560. if ($value ['lossIid'] != 0) {
  561. $detail = $this->getOne ( array (
  562. 'where' => "iid=" . $value ['lossIid'],
  563. 'asArray' => TRUE
  564. ) );
  565. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  566. $list [$key] ['lossDetail'] = $detail;
  567. }
  568. }
  569. } else {
  570. $list = $this->getOne ( array (
  571. 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
  572. 'asArray' => TRUE
  573. ) );
  574. }
  575. return $list;
  576. }
  577. /**
  578. * 审批中获取相关数据 包括最近的一条操作记录
  579. * @param number $status.
  580. * @param number $limit.
  581. */
  582. function getInvoiceByProcessStatus($limit = 4, $desc = 'desc') {
  583. Doo::loadClass ( 'XDeode' );
  584. $XDeode = new XDeode ( 5 );
  585. $list = $this->find ( array (
  586. 'where' => " (status=1 or status=2 or status=3 or status=4) and processApprovals!=''",
  587. 'limit' => $limit,
  588. $desc => 'iid',
  589. 'asArray' => TRUE
  590. ) );
  591. Doo::loadModel ( 'invoiceOperationLog' );
  592. $invoiceOperationLog = new invoiceOperationLog ();
  593. foreach ( $list as $key => $value ) {
  594. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  595. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  596. }
  597. return $list;
  598. }
  599. function getInvoiceByUntreadStatusPage($limit = 0, $con = "", $desc = 'desc') {
  600. if (empty ( $limit ) || empty ( $con ))
  601. return array ();
  602. $list = $this->find ( array (
  603. 'where' => $con,
  604. 'limit' => $limit,
  605. $desc => 'iid',
  606. 'asArray' => TRUE
  607. ) );
  608. Doo::loadClass ( 'XDeode' );
  609. $XDeode = new XDeode ( 5 );
  610. Doo::loadModel ( 'invoiceReceivables' );
  611. $invoiceReceivables = new invoiceReceivables ();
  612. Doo::loadModel ( 'invoiceOperationLog' );
  613. $invoiceOperationLog = new invoiceOperationLog ();
  614. foreach ( $list as $key => $value ) {
  615. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  616. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  617. $list [$key] ['untreadCompany'] = '';
  618. $list [$key] ['untreadCom'] = '';
  619. if (! empty ( $value ['untreadCompany'] )) {
  620. $express = explode ( ":", $value ['untreadCompany'] );
  621. $list [$key] ['untreadCompany'] = $express [0];
  622. $list [$key] ['untreadCom'] = $express [1];
  623. }
  624. $list [$key] ['irList'] = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  625. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  626. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  627. $list [$key] ['sumPrice'] = 0;
  628. if (! empty ( $list [$key] ['irList'] ))
  629. $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  630. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  631. $list [$key] ['lossDetail'] = array ();
  632. if ($value ['lossIid'] != 0) {
  633. $detail = $this->getOne ( array (
  634. 'where' => "iid=" . $value ['lossIid'],
  635. 'asArray' => TRUE
  636. ) );
  637. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  638. $list [$key] ['lossDetail'] = $detail;
  639. }
  640. $lossDate = strtotime ( "+1 month", strtotime ( $list [$key] ['OperationLog'] ['date'] ) );
  641. $nowDate = strtotime ( 'now' );
  642. $list [$key] ['lossShow'] = false;
  643. if ($lossDate < $nowDate)
  644. $list [$key] ['lossShow'] = true;
  645. }
  646. return $list;
  647. }
  648. /**
  649. * 加密或解密指定字符串
  650. *
  651. * @param string $string 要加密或解密的字符串
  652. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  653. * @param string $key 加解密的key
  654. * @param $expiry 超时值
  655. *
  656. */
  657. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  658. $ckey_length = 4;
  659. if (! $key) {
  660. $key = $this->INVOICEKEY;
  661. }
  662. $key = md5 ( $key );
  663. $keya = md5 ( substr ( $key, 0, 16 ) );
  664. $keyb = md5 ( substr ( $key, 16, 16 ) );
  665. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  666. $cryptkey = $keya . md5 ( $keya . $keyc );
  667. $key_length = strlen ( $cryptkey );
  668. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  669. $string_length = strlen ( $string );
  670. $result = '';
  671. $box = range ( 0, 255 );
  672. $rndkey = array ();
  673. for($i = 0; $i <= 255; $i ++) {
  674. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  675. }
  676. for($j = $i = 0; $i < 256; $i ++) {
  677. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  678. $tmp = $box [$i];
  679. $box [$i] = $box [$j];
  680. $box [$j] = $tmp;
  681. }
  682. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  683. $a = ($a + 1) % 256;
  684. $j = ($j + $box [$a]) % 256;
  685. $tmp = $box [$a];
  686. $box [$a] = $box [$j];
  687. $box [$j] = $tmp;
  688. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  689. }
  690. if ($operation == 'DECODE') {
  691. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  692. return substr ( $result, 26 );
  693. } else {
  694. return '';
  695. }
  696. } else {
  697. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  698. }
  699. }
  700. }
  701. ?>