invoice.php 25 KB

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