invoice.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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 $invoiceForm;
  35. public $invoiceManage;
  36. /**
  37. *
  38. * @var string $pendingApprovals 当前需要审批的人
  39. */
  40. public $pendingApprovals;
  41. /**
  42. *
  43. * @var string $processApprovals 已经审批过的人员
  44. */
  45. public $processApprovals;
  46. /**
  47. *
  48. * @var string $invoiceSerial 发票单号
  49. */
  50. public $invoiceSerial;
  51. /**
  52. *
  53. * @var integer $invoicePrice 发票金额
  54. */
  55. public $invoicePrice;
  56. public $invoiceQuantity;
  57. public $invoiceUnitPrice;
  58. public $invoiceBalance;
  59. /**
  60. * 管理组人员:发票打印,
  61. * @var unknown
  62. */
  63. public $moldManage;
  64. /**
  65. *
  66. * @var integer $cid 办事处ID
  67. */
  68. public $cid;
  69. /**
  70. *
  71. * @var string $categoryName 办事处名称
  72. */
  73. public $categoryName;
  74. /**
  75. *
  76. * @var integer $sid 提交发票人ID
  77. */
  78. public $sid;
  79. /**
  80. *
  81. * @var string $userName 提交人名字
  82. */
  83. public $printer;
  84. public $userName;
  85. /**
  86. *
  87. * @var string $remark 备注
  88. */
  89. public $remark;
  90. /**
  91. *
  92. * @var string $invoiceElement 发票内容
  93. */
  94. public $invoiceElement;
  95. /**
  96. *
  97. * @var string $invoiceType 发票类型
  98. */
  99. public $invoiceType;
  100. /**
  101. *
  102. * @var string $invoiceTitle 发票抬头
  103. */
  104. public $invoiceTitle;
  105. /**
  106. *
  107. * @var string $invoiceCompany 开票公司
  108. */
  109. public $invoiceCompany;
  110. /**
  111. *
  112. * @var string $invoiceNo 发票号
  113. */
  114. public $invoiceNo;
  115. /**
  116. *
  117. * @var string $TIN 纳税人识别码
  118. */
  119. public $TIN;
  120. /**
  121. *
  122. * @var string $address 注册地址
  123. */
  124. public $address;
  125. /**
  126. *
  127. * @var string $phone 电话
  128. */
  129. public $phone;
  130. /**
  131. *
  132. * @var string $bank 开户银行
  133. */
  134. public $bank;
  135. /**
  136. *
  137. * @var string $bankAccount 银行账户
  138. */
  139. public $bankAccount;
  140. /**
  141. *
  142. * @var integer $doPost 邮寄
  143. */
  144. public $doPost;
  145. /**
  146. *
  147. * @var string $recipients 收件人
  148. */
  149. public $recipients;
  150. /**
  151. *
  152. * @var string $recipientsPhone 收件人电话
  153. */
  154. public $recipientsPhone;
  155. /**
  156. *
  157. * @var string $recipientsAddress 收件地址
  158. */
  159. public $recipientsAddress;
  160. /**
  161. *
  162. * @var string $mailItems 邮寄物品
  163. */
  164. public $mailItems;
  165. public $mailItemsJson;
  166. public $expressCompany;
  167. public $expressNumber;
  168. public $actualItems;
  169. public $poster;
  170. public $untreadReason;
  171. public $untreadPost;
  172. public $untreadCompany;
  173. public $untreadNumber;
  174. public $untreadItems;
  175. public $untreadStatus;
  176. public $irid;
  177. public $bindTime;
  178. /**
  179. *
  180. * @var date $date 提交时间
  181. */
  182. public $date;
  183. public $isDelete;
  184. public $approvalTime;
  185. /**
  186. *
  187. * @var date $updateTime 更新时间
  188. */
  189. public $updateTime;
  190. /**
  191. *
  192. * @var date $printTime 打印时间
  193. */
  194. public $printTime;
  195. public $postTime;
  196. public $settlementType;
  197. public $accountingTime;
  198. public $parentUntreadIid;
  199. public $inheritIid;
  200. public $_table = 'CLD_invoice';
  201. public $_primarykey = 'iid';
  202. public $_fields = array (
  203. 'iid',
  204. 'isid',
  205. 'trainId',
  206. 'ipSource',
  207. 'lossIid',
  208. 'invoiceManage',
  209. 'pendingApprovals',
  210. 'processApprovals',
  211. 'invoiceSerial',
  212. 'status',
  213. 'printStatus',
  214. 'postStatus',
  215. 'untreadStatus',
  216. 'invoiceForm',
  217. 'invoiceQuantity',
  218. 'invoiceUnitPrice',
  219. 'invoicePrice',
  220. 'invoiceBalance',
  221. 'moldManage',
  222. 'cid',
  223. 'categoryName',
  224. 'irid',
  225. 'remark',
  226. 'invoiceElement',
  227. 'invoiceType',
  228. 'invoiceTitle',
  229. 'invoiceCompany',
  230. 'invoiceNo',
  231. 'TIN',
  232. 'address',
  233. 'phone',
  234. 'bank',
  235. 'bankAccount',
  236. 'doPost',
  237. 'recipients',
  238. 'recipientsPhone',
  239. 'recipientsAddress',
  240. 'mailItems',
  241. 'mailItemsJson',
  242. 'expressCompany',
  243. 'expressNumber',
  244. 'actualItems',
  245. 'untreadReason',
  246. 'untreadPost',
  247. 'untreadCompany',
  248. 'untreadNumber',
  249. 'untreadItems',
  250. 'poster',
  251. 'sid',
  252. 'userName',
  253. 'printer',
  254. 'date',
  255. 'isDelete',
  256. 'approvalTime',
  257. 'updateTime',
  258. 'printTime',
  259. 'postTime',
  260. 'bindTime',
  261. 'settlementType',
  262. 'accountingTime',
  263. 'parentUntreadIid',
  264. 'inheritIid'
  265. );
  266. /**
  267. * 获得培训班结算金额总和
  268. * @param iids $
  269. * @return int
  270. */
  271. function getInvoicePriceByIids($iids=''){
  272. if (empty($iids)){
  273. return 0;
  274. }
  275. $sum = $this->getOne ( array (
  276. 'select' => 'sum(invoicePrice) as price',
  277. 'where' => " trainId in (" .$iids.")",
  278. 'asArray' => TRUE
  279. ) );
  280. return $sum['price'];
  281. }
  282. /**
  283. * 根据发票ID获取一条发票数据
  284. * @param number $iid 发票ID
  285. * @param number $select 需要获取的字段,为空获取全部数据
  286. * @return array|array() 返回发票数据
  287. */
  288. public function getInvoiceByIid($iid = 0, $select = "") {
  289. if (! is_numeric ( $iid ))
  290. $iid = $this->authcode ( $iid );
  291. $condition = array (
  292. 'where' => "iid=" . $iid,
  293. 'asArray' => TRUE
  294. );
  295. if (! empty ( $select ))
  296. $condition += array (
  297. 'select' => $select
  298. );
  299. $Detail = array ();
  300. if (is_numeric ( $iid ) && ! empty ( $iid ))
  301. $Detail = $this->getOne ( $condition );
  302. if (empty ( $Detail ))
  303. return $Detail;
  304. if (isset ( $Detail ['expressCompany'] ) && ! empty ( $Detail ['expressCompany'] )) {
  305. $express = explode ( ":", $Detail ['expressCompany'] );
  306. $Detail ['expressCompany'] = $express [0];
  307. $Detail ['expressCom'] = $express [1];
  308. } else {
  309. $Detail ['expressCompany'] = '';
  310. $Detail ['expressCom'] = '';
  311. }
  312. Doo::loadClass ( 'XDeode' );
  313. $XDeode = new XDeode ( 5 );
  314. $Detail ['iidKeyUrl'] = $XDeode->encode ( $Detail ['iid'] );
  315. $Detail ['iidKey'] = $this->authcode ( $Detail ['iid'], '' );
  316. Doo::loadModel ( 'L_category' );
  317. $lCategory = new L_category ();
  318. $Detail ['category'] = $lCategory->getCategory ();
  319. return $Detail;
  320. }
  321. /**
  322. * 根据培训班ID获得发票
  323. */
  324. function getInvoicePrintedByItid($trainId = 0) {
  325. $sql = 'select a.*,b.RIstatus as RIstatus
  326. from ' . $this->_table . ' as a left join CLD_RIExtend as b on (a.iid=b.iid)
  327. where a.trainId = ' . $trainId . ' and a.status=2 and a.printStatus=1 and (a.untreadStatus=0 or a.untreadStatus=3) ORDER BY a.iid ASC';
  328. $query = Doo::db ()->query ( $sql );
  329. $result = $query->fetchAll ();
  330. Doo::loadClass ( 'XDeode' );
  331. $XDeode = new XDeode ( 5 );
  332. Doo::loadModel ( 'invoiceReceivables' );
  333. $invoiceReceivables = new invoiceReceivables ();
  334. $isFinance=false;
  335. foreach ($result as $key=>$value){
  336. $result [$key] ['irDetail'] =$invoiceReceivables->getInvoiceReceivablesByIridList($value ['irid']);
  337. foreach ($result [$key] ['irDetail'] as $k=>$v){
  338. if($v['receivablesBank']=='财务录入'){
  339. $isFinance=true;
  340. break;
  341. }
  342. }
  343. $result [$key] ['isFinance'] =$isFinance;
  344. $result [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  345. }
  346. return $result;
  347. // $condition = array (
  348. // 'where' => "trainId = " . $trainId . " and status=2 and printStatus=1 and (untreadStatus=0 or untreadStatus=3)",
  349. // 'asArray' => TRUE
  350. // );
  351. // $detail = $this->find ( $condition );
  352. // return $detail;
  353. }
  354. //办事处收款 有问题--已经退票的发票,还会统计到办事处收款中BUG--点击办事处已收款后,在退票就会出现统计错误
  355. function sumOfInvoiceByItid($itidSql=0){
  356. $sql = 'select sum(a.invoicePrice) as invoicePrice ,a.trainId as trainId,a.iid
  357. from CLD_RIExtend as b left join ' . $this->_table . ' as a on (a.iid=b.iid)
  358. where (a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and a.untreadStatus=3) or b.RIstatus=1
  359. GROUP BY a.trainId';
  360. //echo $sql;
  361. $query = Doo::db ()->query ( $sql );
  362. return $result = $query->fetchAll ();
  363. }
  364. /**
  365. * 根据多个iid获得多个发票
  366. * @param number $iid
  367. */
  368. function getInvoiceInIid($iid = 0, $select = '') {
  369. if (empty ( $iid ))
  370. die ( 'illegal request' );
  371. $condition = array (
  372. 'where' => "iid in ( " . $iid . ")",
  373. 'asArray' => TRUE
  374. );
  375. if (! empty ( $select ))
  376. $condition += array (
  377. 'select' => $select
  378. );
  379. $list = $this->find ( $condition );
  380. Doo::loadClass ( 'XDeode' );
  381. $XDeode = new XDeode ( 5 );
  382. foreach ( $list as $key => $value ) {
  383. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  384. }
  385. return $list;
  386. }
  387. function setInvoiceLoss($iid = "") {
  388. if (empty ( $iid ))
  389. return 0;
  390. $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`)
  391. 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;
  392. $query = Doo::db ()->query ( $sql );
  393. return Doo::db ()->lastInsertId ();
  394. }
  395. function getInvoiceByInvoiceNo($invoiceNo = '') {
  396. if (empty ( $invoiceNo ))
  397. return array ();
  398. $detail = $this->getOne ( array (
  399. 'where' => "invoiceNo= '" . $invoiceNo . "'",
  400. 'asArray' => TRUE
  401. ) );
  402. return $detail;
  403. }
  404. /**
  405. * 根据标题或者开票单位获得相关信息 - 准确查询
  406. * @param string $title 查询条件
  407. * @param string $query 默认模糊查询
  408. */
  409. public function getInvoiceByTitle($title = "", $query = "FUZZY", $cond = '', $fkq = false) {
  410. $detail = array ();
  411. if (! empty ( $title )) {
  412. $condition = array (
  413. 'asArray' => TRUE
  414. );
  415. if ($query == $this->FUZZY){
  416. $condition += array (
  417. 'where' => " (invoiceTitle like '%" . $title . "%' or invoiceCompany like '%" . $title . "%') " . $cond
  418. );
  419. //echo " (invoiceTitle like '%" . $title . "%' or invoiceCompany like '%" . $title . "%') " . $cond ;
  420. }else
  421. $condition += array (
  422. 'where' => "(invoiceTitle = '" . $title . "' or invoiceCompany= '" . $title . "') " . $cond
  423. );
  424. Doo::loadClass ( 'XDeode' );
  425. $XDeode = new XDeode ( 5 );
  426. if ($fkq) {
  427. $detail = $this->find ( $condition );
  428. foreach ( $detail as $key => $value ) {
  429. $detail [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  430. $detail [$key] ['iidKeyXD'] = $XDeode->encode ( $value ['iid'] );
  431. }
  432. } else {
  433. $detail = $this->getOne ( $condition );
  434. if (! empty ( $detail )) {
  435. $detail ['iidKey'] = $this->authcode ( $detail ['iid'], '' );
  436. $detail ['iidKeyXD'] = $XDeode->encode ( $detail ['iid'] );
  437. }
  438. }
  439. }
  440. return $detail;
  441. }
  442. public function getInvoiceByIsid($iid = "", $sid = 0) {
  443. if (empty ( $iid ) || empty ( $sid ))
  444. return array ();
  445. Doo::loadClass ( 'XDeode' );
  446. $XDeode = new XDeode ( 5 );
  447. $iid = $XDeode->decode ( $iid );
  448. if (! is_numeric ( $iid ))
  449. return array ();
  450. $detail = $this->getOne ( array (
  451. 'where' => "iid= '" . $iid . "'", // and sid=".$sid,
  452. 'asArray' => TRUE
  453. ) );
  454. $detail ['expressCompany'] = '';
  455. $detail ['expressCom'] = '';
  456. $detail ['invoiceTraining'] = array ();
  457. if (! empty ( $detail ['expressCompany'] )) {
  458. $express = explode ( ":", $detail ['expressCompany'] );
  459. $detail ['expressCompany'] = $express [0];
  460. $detail ['expressCom'] = $express [1];
  461. }
  462. // 培训班
  463. if ($detail ['settlementType'] == 1) {
  464. Doo::loadModel ( 'invoiceTraining' );
  465. $invoiceTraining = new invoiceTraining ();
  466. $detail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $detail ['trainId'] );
  467. }
  468. $detail ['iidKeyXD'] = $this->authcode ( $detail ['iid'], '' );
  469. return $detail;
  470. }
  471. /**
  472. * 统计培训班开票
  473. */
  474. function sumOfinvoiceTrain($itidSql) {
  475. // $sql = 'select sum(b.invoicePrice) as invoicePrice ,b.trainId as trainId
  476. // from CLD_invoiceStore as a left join ' . $this->_table . ' as b on (a.iid=b.iid)
  477. // where b.trainId in (' . $itidSql . ') and b.status=2 and b.printStatus=1 and (b.untreadStatus =0 or b.untreadStatus=3) and b.isDelete=0
  478. // GROUP BY b.trainId';
  479. $sql = 'select sum(b.invoicePrice) as invoicePrice ,b.trainId as trainId
  480. from ' . $this->_table . ' as b
  481. where b.trainId in (' . $itidSql . ') and b.status=2 and b.printStatus=1 and (b.untreadStatus =0 or b.untreadStatus=3) and b.isDelete=0
  482. GROUP BY b.trainId';
  483. $query = Doo::db ()->query ( $sql );
  484. return $result = $query->fetchAll ();
  485. }
  486. /**
  487. * 公司收款汇总
  488. * @param unknown $itidSql
  489. */
  490. function sumOfInvoiceRecelvablesCompany($itidSql) {
  491. $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  492. from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on (a.iid=b.iid)
  493. where a.trainId in (' . $itidSql . ') and b.receivablesBank!="财务录入" and a.status=2 and a.printStatus=1 and ( a.untreadStatus=3) and a.irid!=""
  494. GROUP BY a.trainId';
  495. $query = Doo::db ()->query ( $sql );
  496. return $result = $query->fetchAll ();
  497. }
  498. //
  499. function sumOfInvoiceRecelvablesTrain($itidSql) {
  500. // $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  501. // from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on find_in_set(a.irid,b.irid)
  502. // where a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!=""
  503. // GROUP BY a.trainId';
  504. $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  505. from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on (a.iid=b.iid)
  506. where a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!=""
  507. GROUP BY a.trainId';
  508. $query = Doo::db ()->query ( $sql );
  509. return $result = $query->fetchAll ();
  510. }
  511. // 获得培训班发票
  512. function getInvoiceByTrainingCount($itid = 0) {
  513. if (empty ( $itid ))
  514. return 0;
  515. $sql = 'select count(*) as count from CLD_invoiceStore as a left join ' . $this->_table . ' as b on (a.iid=b.iid)
  516. where a.trainId= ' . $itid . ' and b.status!=4 and (b.untreadStatus is null or b.untreadStatus!=2) and (b.isDelete is null or b.isDelete=0 )';
  517. //echo $sql;
  518. //echo $sql;
  519. $query = Doo::db ()->query ( $sql );
  520. $result = $query->fetchAll ();
  521. return $result [0] ['count'];
  522. // $detail = $this->count ( array (
  523. // 'where' => "trainId= '" . $itid . "' and untreadStatus!=2 and isDelete=0", // and sid=".$sid,
  524. // 'asArray' => TRUE
  525. // ) );
  526. // return $detail;
  527. }
  528. /**
  529. * 根据仓库ID获得发票
  530. * @param string $Istoreid
  531. * @return unknown
  532. */
  533. public function getInvoiceByIstoreid($Istoreid = "", $select = "") {
  534. if (empty ( $Istoreid ))
  535. return array ();
  536. $condition = array (
  537. 'where' => "isid in ( " . $Istoreid . ")",
  538. 'asArray' => TRUE
  539. );
  540. if (! empty ( $select ))
  541. $condition += array (
  542. 'select' => $select
  543. );
  544. $detail = $this->find ( $condition );
  545. return $detail;
  546. }
  547. /**
  548. * 获取单个可以打印的发票数据
  549. * @param number $iid 发票id
  550. * @param number $select 需要获取的字段,为空获取全部数据
  551. * @return array|array() 返回发票数据
  552. */
  553. public function getInvoiceByPrint($iid = 0, $select = "") {
  554. $condition = array (
  555. 'where' => "iid= '" . $iid . "' and status=2 and untreadStatus=0 ",
  556. 'asArray' => TRUE
  557. );
  558. if (! empty ( $select ))
  559. $condition += array (
  560. 'select' => $select
  561. );
  562. $detail = array ();
  563. if (! empty ( $iid ) && is_numeric ( $iid ))
  564. $detail = $this->getOne ( $condition );
  565. return $detail;
  566. }
  567. /**
  568. * 添加一个发票并进入审批状态
  569. * @param array $item 发票相关数据
  570. * @return number 返回发票ID
  571. */
  572. public function addInvoice($item = array()) {
  573. $lid = 0;
  574. if (is_array ( $item ) && ! empty ( $item )) {
  575. foreach ( $item as $key => $value ) {
  576. $this->$key = $value;
  577. }
  578. $lid = $this->insert ();
  579. }
  580. return $lid;
  581. }
  582. /**
  583. * 根据参数字段更新相应字段(主键ID必须传)
  584. * @param array $item 相关需要更新的字段信息
  585. * @return number 返回发票ID
  586. */
  587. public function setInvoiceByCondition($item = array()) {
  588. $lid = 0;
  589. if (is_array ( $item ) && ! empty ( $item )) {
  590. foreach ( $item as $key => $value ) {
  591. $this->$key = $value;
  592. }
  593. $lid = $this->update ();
  594. }
  595. return $lid;
  596. }
  597. /**
  598. * 根据参数字段批量更新相应字段(主键ID必须传)
  599. * @param array $item 相关需要更新的字段信息
  600. * @return number 返回发票ID
  601. */
  602. public function BatchInvoiceByCondition($item = array(), $iid = "") {
  603. $lid = 0;
  604. if (is_array ( $item ) && ! empty ( $item )) {
  605. foreach ( $item as $key => $value ) {
  606. $this->$key = $value;
  607. }
  608. if (! empty ( $iid )) {
  609. $condition = array (
  610. 'where' => "iid in (" . $iid . ")",
  611. 'asArray' => TRUE
  612. );
  613. $this->update ( $condition );
  614. } else
  615. $lid = $this->update ();
  616. }
  617. return $lid;
  618. }
  619. /**
  620. * 批量更新
  621. * @param string $isid
  622. * @return number
  623. */
  624. function UpdateBatchInvoice($sql = "") {
  625. if (empty ( $sql ))
  626. return 0;
  627. $query = Doo::db ()->query ( $sql );
  628. }
  629. /**
  630. * 根据管理组和发票当前状态获得打印发票数据;其中当iid为空时获取所有发票数据,反之获取1条数据
  631. * @param number $sid 管理组人员ID
  632. * @param number $status 状态 为0时获取可以打印数据,为1时获取已经完成打印数据
  633. * @param number $iid 发票ID
  634. * @return array|array() 返回所有发票数据,当iid有值时返回一条数据
  635. */
  636. public function getPrintInvoiceByManage($sid = 0, $status = 0, $iid = 0) {
  637. $list = array ();
  638. if (! empty ( $sid ) && empty ( $iid ))
  639. $list = $this->find ( array (
  640. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%'",
  641. 'desc' => 'approvalTime',
  642. 'limit' => 10,
  643. 'asArray' => TRUE
  644. ) );
  645. elseif (! empty ( $sid ) && ! empty ( $iid ))
  646. $list = $this->getOne ( array (
  647. 'where' => "status=2 and printStatus=" . $status . " and untreadStatus=0 and moldManage like '%[\"" . $sid . "\",%' and iid=" . $iid,
  648. 'asArray' => TRUE
  649. ) );
  650. return $list;
  651. }
  652. /**
  653. * 获得与我相关的发票数据,其中包含 处理中,待处理,最旧入账等数据;当iid有值时获取一条关于sid的发票
  654. * @param number $sid 用户ID
  655. * @param number $iid 发票ID
  656. * @return array|array()
  657. */
  658. public function getMyInvoice($sid = 0, $iid = 0) {
  659. Doo::loadModel ( 'invoiceOperationLog' );
  660. $invoiceOperationLog = new invoiceOperationLog ();
  661. Doo::loadClass ( 'XDeode' );
  662. $XDeode = new XDeode ( 5 );
  663. $list = array ();
  664. if (! empty ( $iid )) {
  665. $list = $this->getOne ( array (
  666. 'where' => " sid=" . $sid . " and iid=" . $iid,
  667. 'asArray' => TRUE
  668. ) );
  669. } elseif (! empty ( $sid ) && empty ( $iid )) {
  670. $list ['pendingInvoice'] = array ();
  671. $list ['handleInvoice'] = array ();
  672. $list ['pendingInvoice'] = $this->find ( array ( // 加入邮件中也为 处理中 已退票
  673. 'where' => "((status=1 and untreadStatus=0) or (status=2 and printStatus=0 and untreadStatus=0) or
  674. ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=0)
  675. or (postStatus=0 and doPost=1 and status=2 and untreadStatus=0) ) and isDelete=0 and sid=" . $sid,
  676. 'desc' => 'iid',
  677. 'asArray' => TRUE
  678. ) );
  679. foreach ( $list ['pendingInvoice'] as $key => $value ) {
  680. $list ['pendingInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  681. $list ['pendingInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  682. }
  683. $list ['handleInvoice'] = $this->find ( array (
  684. // 需求变更 -去除出票状态的数据 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  685. // 新加入退票中 需要邮寄的发票
  686. 'where' => "(status=3 or status=4 or (status=2 and untreadStatus=2 ) or ( status=2 and untreadStatus=1 ) ) and isDelete=0 and sid=" . $sid,
  687. 'desc' => 'iid',
  688. 'asArray' => TRUE
  689. ) );
  690. foreach ( $list ['handleInvoice'] as $key => $value ) {
  691. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  692. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  693. $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  694. }
  695. }
  696. return $list;
  697. }
  698. /**
  699. * 获得所有未入账发票
  700. * @param number $invoiceTC 发票title
  701. */
  702. public function getInvoiceByUnAccount($invoiceTC = '', $iridExist = false) {
  703. Doo::loadClass ( 'XDeode' );
  704. $XDeode = new XDeode ( 5 );
  705. $title = "";
  706. if (! empty ( $invoiceTC ))
  707. $title = ' and (invoiceTitle like "%' . $invoiceTC . '%" or invoiceCompany like "%' . $invoiceTC . '%" )';
  708. $iridString = ' and irid="" ';
  709. if ($iridExist)
  710. $iridString = ' and irid!="" ';
  711. $list = $this->find ( array ( //
  712. 'where' => "status=2 and printStatus=1 " . $iridString . " and untreadStatus=0 and ( (doPost=1 and postStatus=1) or doPost=0 ) and isDelete=0 " . $title,
  713. 'desc' => 'iid',
  714. 'limit' => 5,
  715. 'asArray' => TRUE
  716. ) );
  717. foreach ( $list as $key => $value ) {
  718. $list [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  719. }
  720. return $list;
  721. }
  722. /**
  723. * 获得与我有关可收款的发票,已经出票的发票
  724. * @param number $sid 开票人ID
  725. */
  726. public function getInvoiceByReceivables($sid = 0) {
  727. Doo::loadClass ( 'XDeode' );
  728. $XDeode = new XDeode ( 5 );
  729. $list ['handleInvoice'] = $this->find ( array (
  730. 'where' => "(status=2 and printStatus=1 and untreadStatus=0 ) and isDelete=0 and sid=" . $sid,
  731. 'desc' => 'iid',
  732. 'asArray' => TRUE
  733. ) );
  734. foreach ( $list ['handleInvoice'] as $key => $value ) {
  735. $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  736. $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
  737. // $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  738. }
  739. return $list ['handleInvoice'];
  740. }
  741. /**
  742. * 获取需要邮寄的发票
  743. * @param integer $postStatus 0为获取需要邮寄的发票,1为获取已经邮寄的发票
  744. * @return array|array() 返回相关数据
  745. */
  746. public function getPostByInvoice($postStatus = 0, $desc = "desc") {
  747. Doo::loadClass ( 'XDeode' );
  748. $XDeode = new XDeode ( 5 );
  749. $list = $this->find ( array ( // and untreadStatus=0
  750. 'where' => "postStatus=" . $postStatus . " and printStatus=1 and doPost=1 and status=2 and isDelete=0",
  751. 'limit' => 7,
  752. $desc => 'iid',
  753. 'asArray' => TRUE
  754. ) );
  755. foreach ( $list as $key => $value ) {
  756. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  757. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  758. $list [$key] ['expressCompany'] = '';
  759. $list [$key] ['expressCom'] = '';
  760. if (! empty ( $value ['expressCompany'] )) {
  761. $express = explode ( ":", $value ['expressCompany'] );
  762. $list [$key] ['expressCompany'] = $express [0];
  763. $list [$key] ['expressCom'] = $express [1];
  764. }
  765. }
  766. return $list;
  767. }
  768. /**
  769. * 根据退票状态获得相关数据,iid有值时只获得一条数据
  770. * @param number $untreadStatus 退票状态
  771. * @param number $iid 发票ID
  772. */
  773. public function getMyInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0,$limit=10,$sid=0) {
  774. Doo::loadClass ( 'XDeode' );
  775. $XDeode = new XDeode ( 5 );
  776. if (empty ( $iid )) {
  777. $list = $this->find ( array ( // printStatus=1 and
  778. 'where' => " untreadStatus=" . $untreadStatus . " and status=2 and sid=".$sid,
  779. 'limit' => $limit,
  780. 'asArray' => TRUE
  781. ) );
  782. if ($untreadStatus == 2) {
  783. Doo::loadModel ( 'invoiceOperationLog' );
  784. $invoiceOperationLog = new invoiceOperationLog ();
  785. }
  786. foreach ( $list as $key => $value ) {
  787. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  788. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  789. $list [$key] ['untreadCompany'] = '';
  790. $list [$key] ['untreadCom'] = '';
  791. if (! empty ( $value ['untreadCompany'] )) {
  792. $express = explode ( ":", $value ['untreadCompany'] );
  793. $list [$key] ['untreadCompany'] = $express [0];
  794. $list [$key] ['untreadCom'] = $express [1];
  795. }
  796. if ($untreadStatus == 2) {
  797. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  798. }
  799. $list [$key] ['lossDetail'] = array ();
  800. if ($value ['lossIid'] != 0) {
  801. $detail = $this->getOne ( array (
  802. 'where' => "iid=" . $value ['lossIid'],
  803. 'asArray' => TRUE
  804. ) );
  805. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  806. $list [$key] ['lossDetail'] = $detail;
  807. }
  808. }
  809. } else {
  810. $list = $this->getOne ( array (
  811. 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
  812. 'asArray' => TRUE
  813. ) );
  814. }
  815. return $list;
  816. }
  817. /**
  818. * 根据退票状态获得相关数据,iid有值时只获得一条数据
  819. * @param number $untreadStatus 退票状态
  820. * @param number $iid 发票ID
  821. */
  822. public function getInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0,$limit=10) {
  823. Doo::loadClass ( 'XDeode' );
  824. $XDeode = new XDeode ( 5 );
  825. if (empty ( $iid )) {
  826. $list = $this->find ( array ( // printStatus=1 and
  827. 'where' => " untreadStatus=" . $untreadStatus . " and status=2 ",
  828. 'limit' => $limit,
  829. 'asArray' => TRUE
  830. ) );
  831. if ($untreadStatus == 2) {
  832. Doo::loadModel ( 'invoiceOperationLog' );
  833. $invoiceOperationLog = new invoiceOperationLog ();
  834. }
  835. foreach ( $list as $key => $value ) {
  836. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  837. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  838. $list [$key] ['untreadCompany'] = '';
  839. $list [$key] ['untreadCom'] = '';
  840. if (! empty ( $value ['untreadCompany'] )) {
  841. $express = explode ( ":", $value ['untreadCompany'] );
  842. $list [$key] ['untreadCompany'] = $express [0];
  843. $list [$key] ['untreadCom'] = $express [1];
  844. }
  845. if ($untreadStatus == 2) {
  846. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  847. }
  848. $list [$key] ['lossDetail'] = array ();
  849. if ($value ['lossIid'] != 0) {
  850. $detail = $this->getOne ( array (
  851. 'where' => "iid=" . $value ['lossIid'],
  852. 'asArray' => TRUE
  853. ) );
  854. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  855. $list [$key] ['lossDetail'] = $detail;
  856. }
  857. }
  858. } else {
  859. $list = $this->getOne ( array (
  860. 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
  861. 'asArray' => TRUE
  862. ) );
  863. }
  864. return $list;
  865. }
  866. /**
  867. * 审批中获取相关数据 包括最近的一条操作记录
  868. * @param number $status.
  869. * @param number $limit.
  870. */
  871. function getInvoiceByProcessStatus($limit = 10, $desc = 'desc') {
  872. Doo::loadClass ( 'XDeode' );
  873. $XDeode = new XDeode ( 5 );
  874. $list = $this->find ( array (
  875. 'where' => " (status=1 or status=2 or status=3 or status=4) and processApprovals!=''",
  876. 'limit' => $limit,
  877. $desc => 'iid',
  878. 'asArray' => TRUE
  879. ) );
  880. Doo::loadModel ( 'invoiceOperationLog' );
  881. $invoiceOperationLog = new invoiceOperationLog ();
  882. foreach ( $list as $key => $value ) {
  883. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  884. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $value ['status'] );
  885. }
  886. return $list;
  887. }
  888. function getInvoiceByUntreadStatusPage($limit = "0,20", $con = "", $desc = 'desc', $olStatus = "desc",$descField="bindTime") {
  889. if ( empty ( $con ))
  890. return array ();
  891. $listCount = $this->count ( array (
  892. 'where' => $con,
  893. 'asArray' => TRUE
  894. ) );
  895. $sqlArr=array (
  896. 'where' => $con,
  897. $desc => $descField,
  898. 'asArray' => TRUE
  899. );
  900. if ($limit!==false){
  901. $sqlArr+=array (
  902. 'limit' => $limit
  903. );
  904. }
  905. $list = $this->find ( $sqlArr ); // echo $con;
  906. Doo::loadClass ( 'XDeode' );
  907. $XDeode = new XDeode ( 5 );
  908. Doo::loadModel ( 'invoiceReceivables' );
  909. $invoiceReceivables = new invoiceReceivables ();
  910. Doo::loadModel ( 'invoiceOperationLog' );
  911. $invoiceOperationLog = new invoiceOperationLog ();
  912. Doo::loadModel ( 'receipt' );
  913. $receipt = new receipt ();
  914. foreach ( $list as $key => $value ) {
  915. //培训班结算是否完成
  916. $receiptDetail=$receipt->getReceiptByinvoiceTrainId($value['trainId']);
  917. $list[$key]['settlementStatus']=false;
  918. if (!empty($receiptDetail)){
  919. if ($receiptDetail['status']==8||$receiptDetail['status']==9){
  920. $list[$key]['settlementStatus']=true;
  921. }
  922. }
  923. $list [$key] ['count'] = $listCount;
  924. $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
  925. $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
  926. $list [$key] ['trainIdKey'] = $XDeode->encode ( $value ['trainId'] );
  927. $list [$key] ['untreadCompany'] = '';
  928. $list [$key] ['untreadCom'] = '';
  929. if (! empty ( $value ['untreadCompany'] )) {
  930. $express = explode ( ":", $value ['untreadCompany'] );
  931. $list [$key] ['untreadCompany'] = $express [0];
  932. $list [$key] ['untreadCom'] = $express [1];
  933. }
  934. $paid=$value['invoicePrice']-$value['invoiceBalance'];
  935. $list [$key] ['irList'] = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );// array(0=>array('sumPrice'=>$paid)); //
  936. if(!empty($list [$key] ['irList'])){
  937. $list [$key] ['irList'][0]['sumPrice']=$paid;
  938. }
  939. if ($olStatus == 'desc')
  940. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  941. else
  942. $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $olStatus );
  943. $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
  944. $list [$key] ['OL'] = $invoiceOperationLog->getInvoiceOperationInStatus ( $value ['iid'], '2,3,4' );
  945. // print_r($list [$key] ['OperationLog']);
  946. $list [$key] ['sumPrice'] = 0;
  947. if (! empty ( $list [$key] ['irList'] )){
  948. $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
  949. if($value['invoicePrice']<=$list [$key] ['irList'] [0] ['sumPrice']){
  950. $list [$key] ['sumPrice'] = $value['invoicePrice'];
  951. }
  952. }
  953. $list [$key] ['diffPrice'] = $list [$key] ['invoicePrice'];
  954. if (! empty ( $list [$key] ['irList'] [0] ['sumPrice'] )){
  955. $diffPrice=$list [$key] ['invoicePrice'] - $list [$key] ['irList'] [0] ['sumPrice'];
  956. if($diffPrice<=0){
  957. $diffPrice=0;
  958. }
  959. $list [$key] ['diffPrice'] = $diffPrice;
  960. // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
  961. }
  962. $list [$key] ['lossDetail'] = array ();
  963. if ($value ['lossIid'] != 0) {
  964. $detail = $this->getOne ( array (
  965. 'where' => "iid=" . $value ['lossIid'],
  966. 'asArray' => TRUE
  967. ) );
  968. $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
  969. $list [$key] ['lossDetail'] = $detail;
  970. }
  971. $lossDate = strtotime ( "+1 month", strtotime ( $list [$key] ['OperationLog'] ['date'] ) );
  972. $nowDate = strtotime ( 'now' );
  973. $list [$key] ['lossShow'] = false;
  974. if ($lossDate < $nowDate)
  975. $list [$key] ['lossShow'] = true;
  976. }
  977. return $list;
  978. }
  979. /**
  980. * 公司应收款汇总
  981. * @param unknown $con
  982. */
  983. function getInvoiceCompanyStatistics($con = '') {
  984. if (empty ( $con ))
  985. return array ();
  986. $sql = 'select invoicePrice,iid
  987. from ' . $this->_table . '
  988. where ' . $con . '
  989. ';
  990. $query = Doo::db ()->query ( $sql );
  991. $result = $query->fetchAll ();
  992. $iidlist = array ();
  993. $invoicePrice = 0;
  994. foreach ( $result as $value ) {
  995. array_push ( $iidlist, $value ['iid'] );
  996. $invoicePrice += $value ['invoicePrice'];
  997. }
  998. $iidString = implode ( ',', $iidlist );
  999. // 获得已收款发票
  1000. if (! empty ( $iidString )) {
  1001. $sql = 'select sum(receivablesPrice) as receivablesPrice
  1002. from CLD_invoiceReceivables
  1003. where iid in (' . $iidString . ') and bindStatus=1
  1004. GROUP BY bindStatus';
  1005. $query = Doo::db ()->query ( $sql );
  1006. $result = $query->fetch ();
  1007. } else {
  1008. $result ['receivablesPrice'] = 0;
  1009. }
  1010. $diffPrice=$invoicePrice - $result ['receivablesPrice'];
  1011. if($diffPrice<=0){
  1012. $diffPrice=0;
  1013. }
  1014. return array (
  1015. 'invoicePrice' => $invoicePrice,
  1016. 'receivablesPrice' => $result ['receivablesPrice'],
  1017. 'diffPrice' => $diffPrice
  1018. );
  1019. }
  1020. /**
  1021. * 获得当前月份办事处入账完成度
  1022. * @param number $cid
  1023. */
  1024. function getInvoiceScheduleByCid($cid = 0, $month = true) {
  1025. if (empty ( $cid ))
  1026. return 0;
  1027. if ($month === false)
  1028. $monthSql = "";
  1029. else {
  1030. $month = date ( "m" );
  1031. $year=date('Y');
  1032. $monthSql = " and Month(date)=" . $month." and Year(date)=".$year;
  1033. }
  1034. // 完成打印
  1035. $recordCount = $this->count ( array (
  1036. 'where' => " status=2 and printStatus=1 and untreadStatus=3 " . $monthSql . " and cid =" . $cid,
  1037. 'asArray' => TRUE
  1038. ) );
  1039. // 当月创建的发票
  1040. $allCount = $this->count ( array (
  1041. 'where' => " isDelete=0 " . $monthSql . " and cid =" . $cid,
  1042. 'asArray' => TRUE
  1043. ) );
  1044. if ($recordCount == 0)
  1045. return 0;
  1046. return $recordCount / $allCount;
  1047. }
  1048. /**
  1049. * 或者办事处成员的完成度
  1050. */
  1051. function getInvoiceScheduleByCidGroupSid($cid = 0) {
  1052. if (empty ( $cid ))
  1053. return array ();
  1054. // 完成发票
  1055. $recordCount = $this->find ( array (
  1056. 'select' => 'count(*) as count,sid',
  1057. 'where' => " status=2 and printStatus=1 and untreadStatus=3 and cid =" . $cid,
  1058. 'groupby' => 'sid',
  1059. 'asArray' => TRUE
  1060. ) );
  1061. // 当月创建的发票
  1062. $allCount = $this->find ( array (
  1063. 'select' => 'count(*) as count,sid',
  1064. 'where' => " isDelete=0 and cid =" . $cid,
  1065. 'groupby' => 'sid',
  1066. 'asArray' => TRUE
  1067. ) );
  1068. $list = array ();
  1069. foreach ( $recordCount as $key => $value ) {
  1070. foreach ( $allCount as $k => $v ) {
  1071. if ($value ['sid'] == $v ['sid']) {
  1072. if ($value ['count'] == 0)
  1073. $list [$value ['sid']] = 0;
  1074. else
  1075. $list [$value ['sid']] = ( int ) (($value ['count'] / $v ['count']) * 100);
  1076. }
  1077. }
  1078. }
  1079. return $list;
  1080. }
  1081. /**
  1082. * 获得个人最新发票信息
  1083. */
  1084. function getInvoiceByNew($sid = 0) {
  1085. if (empty ( $sid ))
  1086. return array ();
  1087. $Detail = $this->getOne ( array (
  1088. 'where' => "sid=" . $sid,
  1089. 'desc' => 'iid',
  1090. 'asArray' => TRUE
  1091. ) );
  1092. return $Detail;
  1093. }
  1094. /**
  1095. * 加密或解密指定字符串
  1096. *
  1097. * @param string $string 要加密或解密的字符串
  1098. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  1099. * @param string $key 加解密的key
  1100. * @param $expiry 超时值
  1101. *
  1102. */
  1103. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  1104. $ckey_length = 4;
  1105. if (! $key) {
  1106. $key = $this->INVOICEKEY;
  1107. }
  1108. $key = md5 ( $key );
  1109. $keya = md5 ( substr ( $key, 0, 16 ) );
  1110. $keyb = md5 ( substr ( $key, 16, 16 ) );
  1111. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  1112. $cryptkey = $keya . md5 ( $keya . $keyc );
  1113. $key_length = strlen ( $cryptkey );
  1114. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  1115. $string_length = strlen ( $string );
  1116. $result = '';
  1117. $box = range ( 0, 255 );
  1118. $rndkey = array ();
  1119. for($i = 0; $i <= 255; $i ++) {
  1120. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  1121. }
  1122. for($j = $i = 0; $i < 256; $i ++) {
  1123. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  1124. $tmp = $box [$i];
  1125. $box [$i] = $box [$j];
  1126. $box [$j] = $tmp;
  1127. }
  1128. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  1129. $a = ($a + 1) % 256;
  1130. $j = ($j + $box [$a]) % 256;
  1131. $tmp = $box [$a];
  1132. $box [$a] = $box [$j];
  1133. $box [$j] = $tmp;
  1134. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  1135. }
  1136. if ($operation == 'DECODE') {
  1137. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  1138. return substr ( $result, 26 );
  1139. } else {
  1140. return '';
  1141. }
  1142. } else {
  1143. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  1144. }
  1145. }
  1146. }
  1147. ?>