12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412 |
- <?php
- Doo::loadCore ( 'db/DooModel' );
- /**
- * 发票审批相关信息及其操作业务逻辑
- * @author CP.
- * @version 1.0
- * @namespace invoice
- * @package invoiceModel
- */
- class invoice extends DooModel {
- private $INVOICEKEY = "APPROVAL";
- private $FUZZY = 'FUZZY';
- private $EXACTLY = "EXACTLY";
-
- /**
- *
- * @var integer $iid 发票ID
- */
- public $iid;
- public $isid;
- public $trainId;
- public $lossIid;
- public $ipSource;
- /**
- *
- * @var integer $status 审批状态
- */
- public $status;
- /**
- *
- * @var string $invoiceManage 当前审批组人员
- */
- public $printStatus;
- public $postStatus;
-
- public $invoiceForm;
- public $invoiceManage;
- /**
- *
- * @var string $pendingApprovals 当前需要审批的人
- */
- public $pendingApprovals;
- /**
- *
- * @var string $processApprovals 已经审批过的人员
- */
- public $processApprovals;
- /**
- *
- * @var string $invoiceSerial 发票单号
- */
- public $invoiceSerial;
- /**
- *
- * @var integer $invoicePrice 发票金额
- */
- public $invoicePrice;
- public $invoiceQuantity;
- public $invoiceUnitPrice;
- public $invoiceBalance;
-
- /**
- * 管理组人员:发票打印,
- * @var unknown
- */
- public $moldManage;
- /**
- *
- * @var integer $cid 办事处ID
- */
- public $cid;
- /**
- *
- * @var string $categoryName 办事处名称
- */
- public $categoryName;
- /**
- *
- * @var integer $sid 提交发票人ID
- */
- public $sid;
- /**
- *
- * @var string $userName 提交人名字
- */
- public $printer;
- public $userName;
- /**
- *
- * @var string $remark 备注
- */
- public $remark;
- /**
- *
- * @var string $invoiceElement 发票内容
- */
- public $invoiceElement;
- /**
- *
- * @var string $invoiceType 发票类型
- */
- public $invoiceType;
- /**
- *
- * @var string $invoiceTitle 发票抬头
- */
- public $invoiceTitle;
- /**
- *
- * @var string $invoiceCompany 开票公司
- */
- public $invoiceCompany;
- /**
- *
- * @var string $invoiceNo 发票号
- */
- public $invoiceNo;
- /**
- *
- * @var string $TIN 纳税人识别码
- */
- public $TIN;
- /**
- *
- * @var string $address 注册地址
- */
- public $address;
- /**
- *
- * @var string $phone 电话
- */
- public $phone;
- /**
- *
- * @var string $bank 开户银行
- */
- public $bank;
- /**
- *
- * @var string $bankAccount 银行账户
- */
- public $bankAccount;
- /**
- *
- * @var integer $doPost 邮寄
- */
- public $doPost;
- /**
- *
- * @var string $recipients 收件人
- */
- public $recipients;
- /**
- *
- * @var string $recipientsPhone 收件人电话
- */
- public $recipientsPhone;
- /**
- *
- * @var string $recipientsAddress 收件地址
- */
- public $recipientsAddress;
- /**
- *
- * @var string $mailItems 邮寄物品
- */
- public $mailItems;
- public $mailItemsJson;
- public $expressCompany;
- public $expressNumber;
- public $actualItems;
- public $poster;
- public $untreadReason;
- public $untreadPost;
- public $untreadCompany;
- public $untreadNumber;
- public $untreadItems;
- public $untreadStatus;
- public $irid;
- public $bindTime;
- /**
- *
- * @var date $date 提交时间
- */
- public $date;
- public $isDelete;
- public $approvalTime;
- /**
- *
- * @var date $updateTime 更新时间
- */
- public $updateTime;
- /**
- *
- * @var date $printTime 打印时间
- */
- public $printTime;
- public $postTime;
- public $settlementType;
- public $accountingTime;
- public $parentUntreadIid;
- public $inheritIid;
-
- public $electronicPhone;
- public $electronicEmail;
-
- public $invalid;
- public $badDebt;
- public $untreadTime;
- public $_table = 'CLD_invoice';
- public $_primarykey = 'iid';
- public $_fields = array (
- 'iid',
- 'isid',
- 'trainId',
- 'ipSource',
- 'lossIid',
- 'invoiceManage',
- 'pendingApprovals',
- 'processApprovals',
- 'invoiceSerial',
- 'status',
- 'printStatus',
- 'postStatus',
- 'untreadStatus',
- 'invoiceForm',
- 'invoiceQuantity',
- 'invoiceUnitPrice',
- 'invoicePrice',
- 'invoiceBalance',
- 'moldManage',
- 'cid',
- 'categoryName',
- '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',
- 'sid',
- 'userName',
- 'printer',
- 'date',
- 'isDelete',
- 'approvalTime',
- 'updateTime',
- 'printTime',
- 'postTime',
- 'bindTime',
- 'settlementType',
- 'accountingTime',
- 'parentUntreadIid',
- 'inheritIid',
- 'electronicPhone',
- 'electronicEmail',
- 'invalid',
- 'badDebt',
- 'untreadTime',
- );
- function get_invoice($filter){
-
- $qualification=array('limit'=>20,'desc'=>'iid','asArray' => TRUE);
-
- if(isset($filter['fields'])){
- $qualification+=array('select'=> $filter['fields']);
- }
-
- if(isset($filter['where'])){
- $parameter=$condition=array();
- foreach ($filter['where'] as $wk=>$wv){
- $formula=explode('_', $wk);
- $field=$formula[0];
- $symbol='=';
- if (isset($formula[1])&&$formula[1]=='like'){
- $symbol='like';
- }elseif(isset($formula[1])&&$formula[1]=='or'){
- $symbol='or';
- }
- if(empty($wv)){
- $wv='';
- }
-
-
- if($symbol=='like'&&!empty($wv)){
- if($field=='invoiceTitle'&&!empty($wk)){
- array_push($condition, ' ('.$field.' like ? or invoiceCompany like ? ) ');
- array_push($parameter, '%'.$wv.'%');array_push($parameter, '%'.$wv.'%');
- }else{
- array_push($condition, $field.' like ?');
- array_push($parameter, '%'.$wv.'%');
- }
-
- }elseif($symbol=='or'&&!empty($wv)){
- array_push($condition, $field.' in ( ? )');
- $wv=implode(',', $wv);
- array_push($parameter, $wv);
- }else{
- array_push($condition, $field.'=?');
- array_push($parameter, $wv);
- }
-
-
-
- /* if($field=='invoiceTitle'&&!empty($wk)){//特殊处理字段
- if($symbol=='like'&&!empty($wv)){
- array_push($condition, ' ('.$field.' like ? or invoiceCompany like ? ) ');
- array_push($parameter, '%'.$wv.'%');array_push($parameter, '%'.$wv.'%');
- }else{
- array_push($condition, ' ('.$field.'=? ) ');
- array_push($parameter, $wv);
- }
- }else{
- if($symbol=='like'&&!empty($wv)){
- array_push($condition, $field.' like ?');
- array_push($parameter, '%'.$wv.'%');
- }elseif($symbol=='or'&&!empty($wv)){
- echo $wv;
- }else{
- array_push($condition, $field.'=?');
- array_push($parameter, $wv);
- }
- } */
-
- }
- $condition=implode(' and ', $condition);
-
- $qualification+=array(
- 'where'=> $condition,
- 'param' => $parameter
- );
- }
-
- //print_r($qualification);
-
- $result=$this->find($qualification);
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- foreach ($result as $key=>$value){
- if(!empty($value['invoiceCompany'])){
- $result[$key]['invoiceTitle']= $value ['invoiceCompany'] ;
- }
-
- if($value['printTime']==null){
- $result[$key]['printTime']= '' ;
- }
-
-
- $result[$key]['iid']=$XDeode->encode ( $value ['iid'] );
- $result[$key]['cid']=$XDeode->encode ( $value ['cid'] );
- $result[$key]['sid']=$XDeode->encode ( $value ['sid'] );
- $result[$key]['trainId']=$XDeode->encode ( $value ['trainId'] );
- $result[$key]['lossIid']=$XDeode->encode ( $value ['lossIid'] );
- $result[$key]['isid']=$XDeode->encode ( $value ['isid'] );
- }
-
- return $result;
- }
-
- /**
- * 获得培训班结算金额总和
- * @param iids $
- * @return int
- */
- function getInvoicePriceByIids($iids=''){
- if (empty($iids)){
- return 0;
- }
- $sum = $this->getOne ( array (
- 'select' => 'sum(invoicePrice) as price',
- 'where' => " trainId in (" .$iids.")",
- 'asArray' => TRUE
- ) );
- return $sum['price'];
- }
- /**
- * 根据发票ID获取一条发票数据
- * @param number $iid 发票ID
- * @param number $select 需要获取的字段,为空获取全部数据
- * @return array|array() 返回发票数据
- */
- public function getInvoiceByIid($iid = 0, $select = "") {
- if (! is_numeric ( $iid ))
- $iid = $this->authcode ( $iid );
-
- $condition = array (
- 'where' => "iid=" . $iid,
- 'asArray' => TRUE
- );
- if (! empty ( $select ))
- $condition += array (
- 'select' => $select
- );
-
- $Detail = array ();
- if (is_numeric ( $iid ) && ! empty ( $iid ))
- $Detail = $this->getOne ( $condition );
-
- if (empty ( $Detail ))
- return $Detail;
- if (isset ( $Detail ['expressCompany'] ) && ! empty ( $Detail ['expressCompany'] )) {
- $express = explode ( ":", $Detail ['expressCompany'] );
- $Detail ['expressCompany'] = $express [0];
- $Detail ['expressCom'] = $express [1];
- } else {
- $Detail ['expressCompany'] = '';
- $Detail ['expressCom'] = '';
- }
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- $Detail ['iidKeyUrl'] = $XDeode->encode ( $Detail ['iid'] );
-
- $Detail ['iidKey'] = $this->authcode ( $Detail ['iid'], '' );
- Doo::loadModel ( 'L_category' );
- $lCategory = new L_category ();
- $Detail ['category'] = $lCategory->getCategory ();
-
- return $Detail;
- }
-
- /**
- * 根据培训班ID获得发票
- */
- function getInvoicePrintedByItid($trainId = 0) {
-
- $sql = 'select a.*,b.RIstatus as RIstatus
- from ' . $this->_table . ' as a left join CLD_RIExtend as b on (a.iid=b.iid)
- 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';
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- Doo::loadModel ( 'invoiceReceivables' );
- $invoiceReceivables = new invoiceReceivables ();
- $isFinance=false;
- foreach ($result as $key=>$value){
- $result [$key] ['irDetail'] =$invoiceReceivables->getInvoiceReceivablesByIridList($value ['irid']);
- foreach ($result [$key] ['irDetail'] as $k=>$v){
- if($v['receivablesBank']=='财务录入'){
- $isFinance=true;
- break;
- }
- }
- $result [$key] ['isFinance'] =$isFinance;
- $result [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
- }
-
- return $result;
-
- // $condition = array (
- // 'where' => "trainId = " . $trainId . " and status=2 and printStatus=1 and (untreadStatus=0 or untreadStatus=3)",
- // 'asArray' => TRUE
- // );
- // $detail = $this->find ( $condition );
-
- // return $detail;
- }
-
- //办事处收款 有问题--已经退票的发票,还会统计到办事处收款中BUG--点击办事处已收款后,在退票就会出现统计错误
- function sumOfInvoiceByItid($itidSql=0){
- $sql = 'select sum(a.invoicePrice) as invoicePrice ,a.trainId as trainId,a.iid
- from CLD_RIExtend as b left join ' . $this->_table . ' as a on (a.iid=b.iid)
- where (a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and a.untreadStatus=3) or b.RIstatus=1
- GROUP BY a.trainId';
- //echo $sql;
- $query = Doo::db ()->query ( $sql );
- return $result = $query->fetchAll ();
- }
-
- /**
- * 根据多个iid获得多个发票
- * @param number $iid
- */
- function getInvoiceInIid($iid = 0, $select = '') {
- if (empty ( $iid ))
- die ( 'illegal request' );
-
- $condition = array (
- 'where' => "iid in ( " . $iid . ")",
- 'asArray' => TRUE
- );
-
- if (! empty ( $select ))
- $condition += array (
- 'select' => $select
- );
- $list = $this->find ( $condition );
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- foreach ( $list as $key => $value ) {
- $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
- }
- return $list;
- }
- function setInvoiceLoss($iid = "") {
- if (empty ( $iid ))
- return 0;
-
- $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`)
- 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;
- $query = Doo::db ()->query ( $sql );
-
- return Doo::db ()->lastInsertId ();
- }
- function getInvoiceByInvoiceNo($invoiceNo = '') {
- if (empty ( $invoiceNo ))
- return array ();
- $detail = $this->getOne ( array (
- 'where' => "invoiceNo= '" . $invoiceNo . "'",
- 'asArray' => TRUE
- ) );
-
- return $detail;
- }
-
- /**
- * 根据标题或者开票单位获得相关信息 - 准确查询
- * @param string $title 查询条件
- * @param string $query 默认模糊查询
- */
- public function getInvoiceByTitle($title = "", $query = "FUZZY", $cond = '', $fkq = false) {
- $detail = array ();
- if (! empty ( $title )) {
- $condition = array (
- 'asArray' => TRUE
- );
-
- if ($query == $this->FUZZY){
- $condition += array (
- 'where' => " (invoiceTitle like '%" . $title . "%' or invoiceCompany like '%" . $title . "%') " . $cond
- );
- //echo " (invoiceTitle like '%" . $title . "%' or invoiceCompany like '%" . $title . "%') " . $cond ;
- }else
- $condition += array (
- 'where' => "(invoiceTitle = '" . $title . "' or invoiceCompany= '" . $title . "') " . $cond
- );
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- if ($fkq) {
-
- $detail = $this->find ( $condition );
-
- foreach ( $detail as $key => $value ) {
- $detail [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $detail [$key] ['iidKeyXD'] = $XDeode->encode ( $value ['iid'] );
- }
- } else {
- $detail = $this->getOne ( $condition );
- if (! empty ( $detail )) {
-
- $detail ['iidKey'] = $this->authcode ( $detail ['iid'], '' );
- $detail ['iidKeyXD'] = $XDeode->encode ( $detail ['iid'] );
- }
- }
- }
-
- return $detail;
- }
- public function getInvoiceByIsid($iid = "", $sid = 0) {
- if (empty ( $iid ) || empty ( $sid ))
- return array ();
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $iid = $XDeode->decode ( $iid );
- if (! is_numeric ( $iid ))
- return array ();
-
- $detail = $this->getOne ( array (
- 'where' => "iid= '" . $iid . "'", // and sid=".$sid,
- 'asArray' => TRUE
- ) );
-
- $detail ['expressCompany'] = '';
- $detail ['expressCom'] = '';
- $detail ['invoiceTraining'] = array ();
- if (! empty ( $detail ['expressCompany'] )) {
- $express = explode ( ":", $detail ['expressCompany'] );
- $detail ['expressCompany'] = $express [0];
- $detail ['expressCom'] = $express [1];
- }
- // 培训班
- if ($detail ['settlementType'] == 1) {
- Doo::loadModel ( 'invoiceTraining' );
- $invoiceTraining = new invoiceTraining ();
- $detail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $detail ['trainId'] );
- }
-
- $detail ['iidKeyXD'] = $this->authcode ( $detail ['iid'], '' );
-
- return $detail;
- }
-
- /**
- * 统计培训班开票
- */
- function sumOfinvoiceTrain($itidSql) {
- // $sql = 'select sum(b.invoicePrice) as invoicePrice ,b.trainId as trainId
- // from CLD_invoiceStore as a left join ' . $this->_table . ' as b on (a.iid=b.iid)
- // 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
- // GROUP BY b.trainId';
- $sql = 'select sum(b.invoicePrice) as invoicePrice ,b.trainId as trainId
- from ' . $this->_table . ' as b
- 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
- GROUP BY b.trainId';
-
- $query = Doo::db ()->query ( $sql );
- return $result = $query->fetchAll ();
- }
-
- /**
- * 公司收款汇总
- * @param unknown $itidSql
- */
- function sumOfInvoiceRecelvablesCompany($itidSql) {
- $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
- from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on (a.iid=b.iid)
- where a.trainId in (' . $itidSql . ') and b.receivablesBank!="财务录入" and a.status=2 and a.printStatus=1 and ( a.untreadStatus=3) and a.irid!=""
- GROUP BY a.trainId';
-
- $query = Doo::db ()->query ( $sql );
-
- return $result = $query->fetchAll ();
- }
-
- //
- function sumOfInvoiceRecelvablesTrain($itidSql) {
- // $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
- // from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on find_in_set(a.irid,b.irid)
- // where a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!=""
- // GROUP BY a.trainId';
- $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
- from ' . $this->_table . ' as a left join CLD_invoiceReceivables as b on (a.iid=b.iid)
- where a.trainId in (' . $itidSql . ') and a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!=""
- GROUP BY a.trainId';
- $query = Doo::db ()->query ( $sql );
-
- return $result = $query->fetchAll ();
- }
-
-
-
- /**
- * 获得培训班发票
- *
- * @param integer $itid
- * @return void
- */
- function getInvoiceByTrainingCount($itid = 0) {
- if (empty ( $itid ))
- return 0;
- $sql = 'select count(*) as count from CLD_invoiceStore as a left join ' . $this->_table . ' as b on (a.iid=b.iid)
- 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 )';
- //echo $sql;
- //echo $sql;
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
- return $result [0] ['count'];
-
- // $detail = $this->count ( array (
- // 'where' => "trainId= '" . $itid . "' and untreadStatus!=2 and isDelete=0", // and sid=".$sid,
- // 'asArray' => TRUE
- // ) );
- // return $detail;
- }
-
- /**
- * 根据仓库ID获得发票
- * @param string $Istoreid
- * @return unknown
- */
- public function getInvoiceByIstoreid($Istoreid = "", $select = "") {
- if (empty ( $Istoreid ))
- return array ();
-
- $condition = array (
- 'where' => "isid in ( " . $Istoreid . ")",
- 'asArray' => TRUE
- );
-
- if (! empty ( $select ))
- $condition += array (
- 'select' => $select
- );
-
- $detail = $this->find ( $condition );
-
- return $detail;
- }
-
- /**
- * 获取单个可以打印的发票数据
- * @param number $iid 发票id
- * @param number $select 需要获取的字段,为空获取全部数据
- * @return array|array() 返回发票数据
- */
- public function getInvoiceByPrint($iid = 0, $select = "") {
- $condition = array (
- 'where' => "iid= '" . $iid . "' and status=2 and (untreadStatus=0 or untreadStatus=4 )",
- 'asArray' => TRUE
- );
- if (! empty ( $select ))
- $condition += array (
- 'select' => $select
- );
- $detail = array ();
- if (! empty ( $iid ) && is_numeric ( $iid ))
- $detail = $this->getOne ( $condition );
- return $detail;
- }
- /**
- * 添加一个发票并进入审批状态
- * @param array $item 发票相关数据
- * @return number 返回发票ID
- */
- public function addInvoice($item = array()) {
- $lid = 0;
- if (is_array ( $item ) && ! empty ( $item )) {
- foreach ( $item as $key => $value ) {
- $this->$key = $value;
- }
- $lid = $this->insert ();
- }
- return $lid;
- }
- /**
- * 根据参数字段更新相应字段(主键ID必须传)
- * @param array $item 相关需要更新的字段信息
- * @return number 返回发票ID
- */
- public function setInvoiceByCondition($item = array()) {
- $lid = 0;
- if (is_array ( $item ) && ! empty ( $item )) {
- foreach ( $item as $key => $value ) {
- $this->$key = $value;
- }
- $lid = $this->update ();
- }
- return $lid;
- }
-
- /**
- * 根据参数字段批量更新相应字段(主键ID必须传)
- * @param array $item 相关需要更新的字段信息
- * @return number 返回发票ID
- */
- public function BatchInvoiceByCondition($item = array(), $iid = "") {
- $lid = 0;
-
- if (is_array ( $item ) && ! empty ( $item )) {
- foreach ( $item as $key => $value ) {
- $this->$key = $value;
- }
-
- if (! empty ( $iid )) {
- $condition = array (
- 'where' => "iid in (" . $iid . ")",
- 'asArray' => TRUE
- );
- $this->update ( $condition );
- } else
- $lid = $this->update ();
- }
- return $lid;
- }
-
- /**
- * 批量更新
- * @param string $isid
- * @return number
- */
- function UpdateBatchInvoice($sql = "") {
- if (empty ( $sql ))
- return 0;
-
- $query = Doo::db ()->query ( $sql );
- }
-
- /**
- * 根据管理组和发票当前状态获得打印发票数据;其中当iid为空时获取所有发票数据,反之获取1条数据
- * @param number $sid 管理组人员ID
- * @param number $status 状态 为0时获取可以打印数据,为1时获取已经完成打印数据
- * @param number $iid 发票ID
- * @return array|array() 返回所有发票数据,当iid有值时返回一条数据
- */
- public function getPrintInvoiceByManage($sid = 0, $status = 0, $iid = 0) {
- $list = array ();
- if (! empty ( $sid ) && empty ( $iid ))
- $list = $this->find ( array (
- 'where' => "status=2 and printStatus=" . $status . " and (untreadStatus=0 or untreadStatus=4) and moldManage like '%[\"" . $sid . "\",%'",
- 'desc' => 'approvalTime',
- 'limit' => 10,
- 'asArray' => TRUE
- ) );
- elseif (! empty ( $sid ) && ! empty ( $iid ))
- $list = $this->getOne ( array (
- 'where' => "status=2 and printStatus=" . $status . " and (untreadStatus=0 or untreadStatus=4) and moldManage like '%[\"" . $sid . "\",%' and iid=" . $iid,
-
- 'asArray' => TRUE
- ) );
- return $list;
- }
-
- /**
- * 获得与我相关的发票数据,其中包含 处理中,待处理,最旧入账等数据;当iid有值时获取一条关于sid的发票
- * @param number $sid 用户ID
- * @param number $iid 发票ID
- * @return array|array()
- */
- public function getMyInvoice($sid = 0, $iid = 0) {
- Doo::loadModel ( 'invoiceOperationLog' );
- $invoiceOperationLog = new invoiceOperationLog ();
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $list = array ();
- if (! empty ( $iid )) {
- $list = $this->getOne ( array (
- 'where' => " sid=" . $sid . " and iid=" . $iid,
- 'asArray' => TRUE
- ) );
- } elseif (! empty ( $sid ) && empty ( $iid )) {
- $list ['pendingInvoice'] = array ();
- $list ['handleInvoice'] = array ();
- $list ['pendingInvoice'] = $this->find ( array ( // 加入邮件中也为 处理中 已退票
- 'where' => "((status=1 and untreadStatus=0) or (status=2 and printStatus=0 and untreadStatus=0) or
- ( status=2 and printStatus=1 and untreadStatus=1 and untreadPost=0)
- or (postStatus=0 and doPost=1 and status=2 and untreadStatus=0) ) and isDelete=0 and sid=" . $sid,
- 'desc' => 'iid',
- 'asArray' => TRUE
- ) );
- foreach ( $list ['pendingInvoice'] as $key => $value ) {
- $list ['pendingInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
- $list ['pendingInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
- }
-
- $list ['handleInvoice'] = $this->find ( array (
- // 需求变更 -去除出票状态的数据 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
- // 新加入退票中 需要邮寄的发票
- 'where' => "(status=3 or status=4 or (status=2 and untreadStatus=2 ) or ( status=2 and untreadStatus=1 ) ) and isDelete=0 and sid=" . $sid,
- 'desc' => 'iid',
- 'asArray' => TRUE
- ) );
-
- foreach ( $list ['handleInvoice'] as $key => $value ) {
- $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
- $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
- }
- }
-
- return $list;
- }
-
-
-
- /**
- * 获得所有未入账发票
- * @param number $invoiceTC 发票title
- */
- public function getInvoiceByUnAccount($invoiceTC = '', $iridExist = false) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- $title = "";
- if (! empty ( $invoiceTC ))
- $title = ' and (invoiceTitle like "%' . $invoiceTC . '%" or invoiceCompany like "%' . $invoiceTC . '%" )';
-
- $iridString = ' and irid="" ';
- if ($iridExist)
- $iridString = ' and irid!="" ';
-
- $list = $this->find ( array ( //
- 'where' => "status=2 and printStatus=1 " . $iridString . " and untreadStatus=0 and ( (doPost=1 and postStatus=1) or doPost=0 ) and isDelete=0 " . $title,
- 'desc' => 'iid',
- 'limit' => 5,
- 'asArray' => TRUE
- ) );
- foreach ( $list as $key => $value ) {
- $list [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
- }
- return $list;
- }
-
- /**
- * 获得与我有关可收款的发票,已经出票的发票
- * @param number $sid 开票人ID
- */
- public function getInvoiceByReceivables($sid = 0) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $list ['handleInvoice'] = $this->find ( array (
- 'where' => "(status=2 and printStatus=1 and untreadStatus=0 ) and isDelete=0 and sid=" . $sid,
- 'desc' => 'iid',
- 'asArray' => TRUE
- ) );
- foreach ( $list ['handleInvoice'] as $key => $value ) {
- $list ['handleInvoice'] [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $list ['handleInvoice'] [$key] ['iidKeyUrl'] = $XDeode->encode ( $value ['iid'] );
- // $list ['handleInvoice'] [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
- }
- return $list ['handleInvoice'];
- }
-
- /**
- * 获取需要邮寄的发票
- * @param integer $postStatus 0为获取需要邮寄的发票,1为获取已经邮寄的发票
- * @return array|array() 返回相关数据
- */
- public function getPostByInvoice($postStatus = 0, $desc = "desc") {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $list = $this->find ( array ( // and untreadStatus=0
- 'where' => "postStatus=" . $postStatus . " and printStatus=1 and doPost=1 and status=2 and isDelete=0",
- 'limit' => 7,
- $desc => 'iid',
- 'asArray' => TRUE
- ) );
- foreach ( $list as $key => $value ) {
- $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
- $list [$key] ['expressCompany'] = '';
- $list [$key] ['expressCom'] = '';
- if (! empty ( $value ['expressCompany'] )) {
- $express = explode ( ":", $value ['expressCompany'] );
- $list [$key] ['expressCompany'] = $express [0];
- $list [$key] ['expressCom'] = $express [1];
- }
- }
- return $list;
- }
-
- /**
- * 根据退票状态获得相关数据,iid有值时只获得一条数据
- * @param number $untreadStatus 退票状态
- * @param number $iid 发票ID
- */
- public function getMyInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0,$limit=10,$sid=0) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- if (empty ( $iid )) {
- $list = $this->find ( array ( // printStatus=1 and
- 'where' => " untreadStatus=" . $untreadStatus . " and status=2 and sid=".$sid,
- 'limit' => $limit,
- 'asArray' => TRUE
- ) );
-
- if ($untreadStatus == 2) {
- Doo::loadModel ( 'invoiceOperationLog' );
- $invoiceOperationLog = new invoiceOperationLog ();
- }
- foreach ( $list as $key => $value ) {
- $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
- $list [$key] ['untreadCompany'] = '';
- $list [$key] ['untreadCom'] = '';
- if (! empty ( $value ['untreadCompany'] )) {
- $express = explode ( ":", $value ['untreadCompany'] );
- $list [$key] ['untreadCompany'] = $express [0];
- $list [$key] ['untreadCom'] = $express [1];
- }
- if ($untreadStatus == 2) {
- $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
- }
-
- $list [$key] ['lossDetail'] = array ();
- if ($value ['lossIid'] != 0) {
- $detail = $this->getOne ( array (
- 'where' => "iid=" . $value ['lossIid'],
- 'asArray' => TRUE
- ) );
- $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
- $list [$key] ['lossDetail'] = $detail;
- }
- }
- } else {
- $list = $this->getOne ( array (
- 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
- 'asArray' => TRUE
- ) );
- }
- return $list;
- }
-
- /**
- * 根据退票状态获得相关数据,iid有值时只获得一条数据
- * @param number $untreadStatus 退票状态
- * @param number $iid 发票ID
- */
- public function getInvoiceByUntreadStatus($untreadStatus = 1, $iid = 0,$limit=10) {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- if (empty ( $iid )) {
- $list = $this->find ( array ( // printStatus=1 and
- 'where' => " untreadStatus=" . $untreadStatus . " and status=2 ",
- 'limit' => $limit,
- 'asArray' => TRUE
- ) );
-
- if ($untreadStatus == 2) {
- Doo::loadModel ( 'invoiceOperationLog' );
- $invoiceOperationLog = new invoiceOperationLog ();
- }
- foreach ( $list as $key => $value ) {
- $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
- $list [$key] ['untreadCompany'] = '';
- $list [$key] ['untreadCom'] = '';
- if (! empty ( $value ['untreadCompany'] )) {
- $express = explode ( ":", $value ['untreadCompany'] );
- $list [$key] ['untreadCompany'] = $express [0];
- $list [$key] ['untreadCom'] = $express [1];
- }
- if ($untreadStatus == 2) {
- $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
- }
-
- $list [$key] ['lossDetail'] = array ();
- if ($value ['lossIid'] != 0) {
- $detail = $this->getOne ( array (
- 'where' => "iid=" . $value ['lossIid'],
- 'asArray' => TRUE
- ) );
- $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
- $list [$key] ['lossDetail'] = $detail;
- }
-
- $lossDate=0;
- if(isset($list [$key] ['OperationLog'])){
- $lossDate= date('m',strtotime ( $list [$key] ['OperationLog'] ['date'] ));
- }
-
- $printMonth=date('m',strtotime ( $value['printTime']));
- $list [$key] ['lossShow'] = false;
- if($printMonth<$lossDate){
- $list [$key] ['lossShow'] = true;
- }
-
- }
- } else {
- $list = $this->getOne ( array (
- 'where' => "iid=" . $iid . " and printStatus=1 and untreadStatus=" . $untreadStatus . " and status=2",
- 'asArray' => TRUE
- ) );
- }
- return $list;
- }
- /**
- * 审批中获取相关数据 包括最近的一条操作记录
- * @param number $status.
- * @param number $limit.
- */
- function getInvoiceByProcessStatus($limit = 10, $desc = 'desc') {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $list = $this->find ( array (
- 'where' => " (status=1 or status=2 or status=3 or status=4) and processApprovals!=''",
- 'limit' => $limit,
- $desc => 'iid',
- 'asArray' => TRUE
- ) );
-
- Doo::loadModel ( 'invoiceOperationLog' );
- $invoiceOperationLog = new invoiceOperationLog ();
-
- foreach ( $list as $key => $value ) {
- $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
- $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $value ['status'] );
- }
-
- return $list;
- }
- function getInvoiceByUntreadStatusPage($limit = "0,20", $con = "", $desc = 'desc', $olStatus = "desc",$descField="bindTime") {
- if ( empty ( $con ))
- return array ();
-
- $listCount = $this->count ( array (
- 'where' => $con,
- 'asArray' => TRUE
- ) );
- $sqlArr=array (
- 'where' => $con,
- $desc => $descField,
- 'asArray' => TRUE
- );
- if ($limit!==false){
- $sqlArr+=array (
- 'limit' => $limit
- );
- }
- $list = $this->find ( $sqlArr ); // echo $con;
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- Doo::loadModel ( 'invoiceReceivables' );
- $invoiceReceivables = new invoiceReceivables ();
- Doo::loadModel ( 'invoiceOperationLog' );
- $invoiceOperationLog = new invoiceOperationLog ();
- Doo::loadModel ( 'receipt' );
- $receipt = new receipt ();
-
-
-
- foreach ( $list as $key => $value ) {
- //培训班结算是否完成
- $receiptDetail=$receipt->getReceiptByinvoiceTrainId($value['trainId']);
- $list[$key]['settlementStatus']=false;
- if (!empty($receiptDetail)){
- if ($receiptDetail['status']==8||$receiptDetail['status']==9){
- $list[$key]['settlementStatus']=true;
- }
- }
-
- $list [$key] ['count'] = $listCount;
- $list [$key] ['iidKey'] = $this->authcode ( $value ['iid'], '' );
- $list [$key] ['iidKeyK'] = $XDeode->encode ( $value ['iid'] );
- $list [$key] ['trainIdKey'] = $XDeode->encode ( $value ['trainId'] );
-
- $list [$key] ['untreadCompany'] = '';
- $list [$key] ['untreadCom'] = '';
- if (! empty ( $value ['untreadCompany'] )) {
- $express = explode ( ":", $value ['untreadCompany'] );
- $list [$key] ['untreadCompany'] = $express [0];
- $list [$key] ['untreadCom'] = $express [1];
- }
-
- $paid=$value['invoicePrice']-$value['invoiceBalance'];
-
- $list [$key] ['irList'] = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );// array(0=>array('sumPrice'=>$paid)); //
- if(!empty($list [$key] ['irList'])){
- $list [$key] ['irList'][0]['sumPrice']=$paid;
- }
-
-
- if ($olStatus == 'desc')
- $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
- else
- $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], $olStatus );
-
- $list [$key] ['OperationLog'] = $invoiceOperationLog->getInvoiceOperationByStatus ( $value ['iid'], 6 );
- $list [$key] ['OL'] = $invoiceOperationLog->getInvoiceOperationInStatus ( $value ['iid'], '2,3,4' );
-
- // print_r($list [$key] ['OperationLog']);
- $list [$key] ['sumPrice'] = 0;
- if (! empty ( $list [$key] ['irList'] )){
- $list [$key] ['sumPrice'] = $list [$key] ['irList'] [0] ['sumPrice'];
- if($value['invoicePrice']<=$list [$key] ['irList'] [0] ['sumPrice']){
- $list [$key] ['sumPrice'] = $value['invoicePrice'];
- }
- }
- $list [$key] ['diffPrice'] = $list [$key] ['invoicePrice'];
- if (! empty ( $list [$key] ['irList'] [0] ['sumPrice'] )){
- $diffPrice=$list [$key] ['invoicePrice'] - $list [$key] ['irList'] [0] ['sumPrice'];
- if($diffPrice<=0){
- $diffPrice=0;
- }
- $list [$key] ['diffPrice'] = $diffPrice;
- // $list [$key] ['operationLog'] = $invoiceOperationLog->getInvoiceOperationLogByIid ( $value ['iid'], 'desc' );
- }
- $list [$key] ['lossDetail'] = array ();
- if ($value ['lossIid'] != 0) {
- $detail = $this->getOne ( array (
- 'where' => "iid=" . $value ['lossIid'],
- 'asArray' => TRUE
- ) );
- $detail ['iidKeyK'] = $XDeode->encode ( $detail ['iid'] );
- $list [$key] ['lossDetail'] = $detail;
- }
- //$lossDate = strtotime ( "+1 month", strtotime ( $list [$key] ['OperationLog'] ['date'] ) );
- //$nowDate = strtotime ( 'now' );
- // $list [$key] ['lossShow'] = false;
- // if ($lossDate < $nowDate){
- // $list [$key] ['lossShow'] = true;
- // }
-
- $lossDate= date('m',strtotime ( $list [$key] ['OperationLog'] ['date'] ));
- $printMonth=date('m',strtotime ( $value['printTime']));
- $list [$key] ['lossShow'] = false;
- if($printMonth<$lossDate){
- $list [$key] ['lossShow'] = true;
- }
-
-
- }
-
- return $list;
- }
-
- /**
- * 公司应收款汇总
- * @param unknown $con
- */
- function getInvoiceCompanyStatistics($con = '') {
- if (empty ( $con ))
- return array ();
- $sql = 'select invoicePrice,iid
- from ' . $this->_table . '
- where ' . $con . '
- ';
-
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetchAll ();
- $iidlist = array ();
- $invoicePrice = 0;
- foreach ( $result as $value ) {
- array_push ( $iidlist, $value ['iid'] );
- $invoicePrice += $value ['invoicePrice'];
- }
- $iidString = implode ( ',', $iidlist );
-
- // 获得已收款发票
- if (! empty ( $iidString )) {
- $sql = 'select sum(receivablesPrice) as receivablesPrice
- from CLD_invoiceReceivables
- where iid in (' . $iidString . ') and bindStatus=1
- GROUP BY bindStatus';
- $query = Doo::db ()->query ( $sql );
- $result = $query->fetch ();
- } else {
- $result ['receivablesPrice'] = 0;
- }
-
-
- $diffPrice=$invoicePrice - $result ['receivablesPrice'];
-
- if($diffPrice<=0){
- $diffPrice=0;
- }
-
- return array (
- 'invoicePrice' => $invoicePrice,
- 'receivablesPrice' => $result ['receivablesPrice'],
- 'diffPrice' => $diffPrice
- );
- }
-
- /**
- * 获得当前月份办事处入账完成度
- * @param number $cid
- */
- function getInvoiceScheduleByCid($cid = 0, $month = true) {
- if (empty ( $cid ))
- return 0;
-
- if ($month === false)
- $monthSql = "";
- else {
- $month = date ( "m" );
- $year=date('Y');
- $monthSql = " and Month(date)=" . $month." and Year(date)=".$year;
- }
-
- // 完成打印
- $recordCount = $this->count ( array (
- 'where' => " status=2 and printStatus=1 and untreadStatus=3 " . $monthSql . " and cid =" . $cid,
- 'asArray' => TRUE
- ) );
-
- // 当月创建的发票
- $allCount = $this->count ( array (
- 'where' => " isDelete=0 " . $monthSql . " and cid =" . $cid,
- 'asArray' => TRUE
- ) );
-
- if ($recordCount == 0)
- return 0;
- return $recordCount / $allCount;
- }
-
- /**
- * 或者办事处成员的完成度
- */
- function getInvoiceScheduleByCidGroupSid($cid = 0) {
- if (empty ( $cid ))
- return array ();
-
- // 完成发票
- $recordCount = $this->find ( array (
- 'select' => 'count(*) as count,sid',
- 'where' => " status=2 and printStatus=1 and untreadStatus=3 and cid =" . $cid,
- 'groupby' => 'sid',
- 'asArray' => TRUE
- ) );
-
- // 当月创建的发票
- $allCount = $this->find ( array (
- 'select' => 'count(*) as count,sid',
- 'where' => " isDelete=0 and cid =" . $cid,
- 'groupby' => 'sid',
- 'asArray' => TRUE
- ) );
-
- $list = array ();
- foreach ( $recordCount as $key => $value ) {
- foreach ( $allCount as $k => $v ) {
- if ($value ['sid'] == $v ['sid']) {
- if ($value ['count'] == 0)
- $list [$value ['sid']] = 0;
- else
- $list [$value ['sid']] = ( int ) (($value ['count'] / $v ['count']) * 100);
- }
- }
- }
-
- return $list;
- }
-
- /**
- * 获得个人最新发票信息
- */
- function getInvoiceByNew($sid = 0) {
- if (empty ( $sid ))
- return array ();
-
- $Detail = $this->getOne ( array (
- 'where' => "sid=" . $sid,
- 'desc' => 'iid',
- 'asArray' => TRUE
- ) );
- return $Detail;
- }
-
- /**
- * 加密或解密指定字符串
- *
- * @param string $string 要加密或解密的字符串
- * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
- * @param string $key 加解密的key
- * @param $expiry 超时值
- *
- */
- function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
- $ckey_length = 4;
- if (! $key) {
- $key = $this->INVOICEKEY;
- }
- $key = md5 ( $key );
- $keya = md5 ( substr ( $key, 0, 16 ) );
- $keyb = md5 ( substr ( $key, 16, 16 ) );
- $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
-
- $cryptkey = $keya . md5 ( $keya . $keyc );
- $key_length = strlen ( $cryptkey );
-
- $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
- $string_length = strlen ( $string );
-
- $result = '';
- $box = range ( 0, 255 );
-
- $rndkey = array ();
- for($i = 0; $i <= 255; $i ++) {
- $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
- }
-
- for($j = $i = 0; $i < 256; $i ++) {
- $j = ($j + $box [$i] + $rndkey [$i]) % 256;
- $tmp = $box [$i];
- $box [$i] = $box [$j];
- $box [$j] = $tmp;
- }
-
- for($a = $j = $i = 0; $i < $string_length; $i ++) {
- $a = ($a + 1) % 256;
- $j = ($j + $box [$a]) % 256;
- $tmp = $box [$a];
- $box [$a] = $box [$j];
- $box [$j] = $tmp;
- $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
- }
-
- if ($operation == 'DECODE') {
- if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
- return substr ( $result, 26 );
- } else {
- return '';
- }
- } else {
- return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
- }
- }
- }
- ?>
|