invoice.php 41 KB

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