_table . " as a left JOIN CLD_receiptTraining as b on (a.trainId=b.rtid) where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and invoiceTrainId!=0 and paidStatus=".$un." limit ".$limit; $query = Doo::db ()->query ( $sql ); $result = $query->fetchAll (); Doo::loadModel ( 'invoiceTraining' ); $invoiceTraining = new invoiceTraining (); Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 7 ); Doo::loadModel ( 'RItem' ); $RItem = new RItem (); Doo::loadModel ( 'RILecturer' ); $RILecturer = new RILecturer (); Doo::loadModel ( 'accountItem' ); $accountItem = new accountItem (); foreach ($result as $key=>$value){ $result[$key]['ridKey']= $XDeode->encode ( $value ['rid'] ); $result[$key]['iTrain']=$invoiceTraining->getInvoiceTrainingByItid ( $value ['invoiceTrainId'] ); $result[$key]['iTrain']['receivablesAmount']=sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$result[$key]['iTrain']['invoiceArriveAmount']); $RItemList = $RItem->getRItemByRid ( $value ['rid'] ); $RILecturerList = $RILecturer->getRILecturerByRid ( $value ['rid'] ); // 支出项金额详情 $expendList= $accountItem->getTrainingDetail ( $RItemList, $RILecturerList ); $result[$key]['iTrain']['expendAmount']=sprintf ( "%.2f",$expendList['total']); $result[$key]['iTrain']['profit']= sprintf ( "%.2f",$result[$key]['iTrain']['invoiceTotalAmount']-$expendList['total']); } return $result; } /** * 获得培训班 年营收图表 */ function getReceiptTrainByYearChart($year=''){ if(empty($year)){ $year=date("Y"); } $sql = "select GROUP_CONCAT(rid) as rid,GROUP_CONCAT(invoiceTrainId) as invoiceTrainId,date_format(date,\"%m\") as month from " . $this->_table . " where status not in (3,4,5) and Rtype=3 and trainId!=0 and invoiceTrainId!=0 and Year(date) =".$year." GROUP BY Month(date)"; //and paidStatus=1 $query = Doo::db ()->query ( $sql ); $result = $query->fetchAll (); Doo::loadModel ( 'RItem' ); $RItem = new RItem (); Doo::loadModel ( 'RILecturer' ); $RILecturer = new RILecturer (); Doo::loadModel ( 'accountItem' ); $accountItem = new accountItem (); Doo::loadModel ( 'invoice' ); $invoice = new invoice (); $MonthPriceList=array(); foreach ($result as $key=>$value){ //获得支出金额总和 $RIprice=$RItem->getRItemPriceByRids($value['rid']); //收款金额总和 $ITprice=$invoice->getInvoicePriceByIids($value['invoiceTrainId']); $MonthPriceList[$value['month']]=array( 'RIprice'=>$RIprice, 'ITprice'=>$ITprice ); } return $MonthPriceList; } function receiptByYear($dateCondition, $sid) { $sql = "select sum(sum) as sum from " . $this->_table . " where staff= '" . $sid . "' " . $dateCondition . " and status=2 "; // echo '
'.$sql.'
'; $query = Doo::db ()->query ( $sql ); $result = $query->fetch (); return $result; } function getReceiptBySid($sid = '', $year = '', $month = '') { Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); if (empty ( $sid )) return array (); $sql = 'select a.* from ' . $this->_table . ' as a left join CLD_receiptDetail as b on b.rid=a.rid where b.staff =' . $sid . ' and Month(b.pastDate)=' . $month . ' and Year(b.pastDate)=' . $year . ' and b.status=1 GROUP BY b.rid'; $query = Doo::db ()->query ( $sql ); $list = $query->fetchAll (); foreach ( $list as $key => $value ) { $list [$key] ['ridKey'] = $XDeode->encode ( $value ['rid'] ); } return $list; } function getReceiptByRid($rid = '') { Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); Doo::loadModel ( 'L_category' ); $Lcategory = new L_category (); Doo::loadModel ( 'staff' ); $staff = new staff (); if (! is_numeric ( $rid )) $rid = $XDeode->decode ( $rid ); $rinfo = $this->getOne ( array ( 'where' => 'rid=' . $rid, 'asArray' => true ) ); $rinfo ['ridKey'] = $XDeode->encode ( $rinfo ['rid'] ); $rinfo ['trainLoanRidKey'] = $XDeode->encode ( $rinfo ['trainLoanRid'] ); $XDeode = new XDeode ( 7 ); $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] ); $rinfo ['category'] = $Lcategory->getCategoryById ( $rinfo ['cid'] ); $rinfo ['staffDetail'] = $staff->getStaffBySid ( $rinfo ['staff'] ); // $rinfo['sum']=number_format ($rinfo['sum'],2); return $rinfo; } function getReceiptByinvoiceTrainId($invoiceTrainId = 0) { Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); Doo::loadModel ( 'L_category' ); $Lcategory = new L_category (); Doo::loadModel ( 'staff' ); $staff = new staff (); if (! is_numeric ( $invoiceTrainId )) $invoiceTrainId = $XDeode->decode ( $invoiceTrainId ); $rinfo = $this->getOne ( array ( 'where' => 'invoiceTrainId=' . $invoiceTrainId, 'asArray' => true ) ); if (empty ( $rinfo )) { return array (); } $rinfo ['ridKey'] = $XDeode->encode ( $rinfo ['rid'] ); $rinfo ['trainLoanRidKey'] = $XDeode->encode ( $rinfo ['trainLoanRid'] ); $XDeode = new XDeode ( 7 ); $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] ); $rinfo ['category'] = $Lcategory->getCategoryById ( $rinfo ['cid'] ); $rinfo ['staffDetail'] = $staff->getStaffBySid ( $rinfo ['staff'] ); return $rinfo; } /** * 默认获得10条 * @param unknown $sid * @param unknown $cid * @param unknown $limit */ function getReceiptLoanByStatus($sid, $cid, $status, $limit = 10) { $sql = ''; if ($sid !== false && is_numeric ( $sid )) { $sql .= ' and staff=' . $sid; } if ($cid !== false && is_numeric ( $cid )) { $sql .= ' and cid=' . $cid; } $list = $this->find ( array ( 'where' => 'Rtype=1 and status=' . $status . $sql, 'asArray' => true ) ); Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); foreach ( $list as $key => $value ) { $list [$key] ['ridKey'] = $XDeode->encode ( $list [$key] ['rid'] ); } return $list; } /** * 获得需要记录流水的费用 * @param unknown $status * @return string */ function getReceiptByWaste() { $list = $this->find ( array ( 'where' => 'status=2 or status=6 or status=1', 'asArray' => true ) ); Doo::loadClass ( 'XDeode' ); $XDeode = new XDeode ( 5 ); $XDeode7 = new XDeode ( 7 ); Doo::loadModel ( 'wasteBook' ); $wasteBook = new wasteBook (); $accountType = 0; foreach ( $list as $key => $value ) { $list [$key] ['ridKey7'] = $XDeode7->encode ( $list [$key] ['rid'] ); $list [$key] ['ridKey'] = $XDeode->encode ( $list [$key] ['rid'] ); if ($list [$key] ['Rtype'] == 0) { $accountType = 3; } elseif ($list [$key] ['Rtype'] == 1) { if (! empty ( $list [$key] ['accountItem'] )) $accountType = 2; else $accountType = 1; } elseif ($list [$key] ['Rtype'] == 2) { $accountType = 4; } elseif ($list [$key] ['Rtype'] == 3) { $accountType = 12; } // 是否已经生成流水 $wbDetail = array (); if (! empty ( $accountType )) { $wbDetail = $wasteBook->getWateBookByAD ( $accountType, $list [$key] ['rid'] ); if (! empty ( $wbDetail )) { unset ( $list [$key] ); } } else { unset ( $list [$key] ); } } return $list; } /** * 根据参数字段更新相应字段(主键ID必须传) * @param array $item 相关需要更新的字段信息 * @return number 返回发票ID */ public function setReceiptByCondition($item = array(), $rid = "") { $lid = 0; if (is_array ( $item ) && ! empty ( $item )) { foreach ( $item as $key => $value ) { $this->$key = $value; } if (! empty ( $isid )) { $condition = array ( 'where' => "rid in (" . $rid . ")", 'asArray' => TRUE ); $this->update ( $condition ); } else $lid = $this->update (); } return $lid; } } ?>