|
@@ -38,6 +38,7 @@ class receipt extends DooModel {
|
|
|
public $trainLoanRid;
|
|
|
public $invoiceTrainId;
|
|
|
public $paidStatus;
|
|
|
+ public $statusTrain;
|
|
|
|
|
|
public $_table = 'CLD_receipt';
|
|
|
public $_primarykey = 'rid';
|
|
@@ -78,16 +79,21 @@ class receipt extends DooModel {
|
|
|
'trainId',
|
|
|
'trainLoanRid',
|
|
|
'invoiceTrainId' ,
|
|
|
- 'paidStatus'
|
|
|
+ 'paidStatus',
|
|
|
+ 'statusTrain'
|
|
|
);
|
|
|
|
|
|
/**
|
|
|
* 获得培训班结算未收款
|
|
|
*/
|
|
|
- function getReceiptTrainByPaid($un=0,$limit=5){
|
|
|
+ function getReceiptTrainByPaid($un=0,$limit=5,$cid=''){
|
|
|
+ if (empty($cid)){
|
|
|
+ return array();
|
|
|
+ }
|
|
|
+
|
|
|
$sql = "select b.* ,a.invoiceTrainId,a.rid,a.executeDate
|
|
|
from " . $this->_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;
|
|
|
+ where a.status not in (3,4,5) and a.Rtype=3 and a.trainId!=0 and invoiceTrainId!=0 and a.cid in (".$cid.") and paidStatus=".$un." limit ".$limit;
|
|
|
|
|
|
$query = Doo::db ()->query ( $sql );
|
|
|
$result = $query->fetchAll ();
|
|
@@ -122,7 +128,7 @@ class receipt extends DooModel {
|
|
|
/**
|
|
|
* 获得所有培训班结算
|
|
|
*/
|
|
|
- function getReceiptTrainByPaidAll($un='',$cid='',$dateSql='',$limit='0,18'){
|
|
|
+ function getReceiptTrainByPaidAll($un='',$cid='',$dateSql='',$limit='0,18',$cidString="",$where=""){
|
|
|
$psSql='';
|
|
|
if(!empty($un)){
|
|
|
$psSql=" and paidStatus=".$un." ";
|
|
@@ -130,11 +136,15 @@ class receipt extends DooModel {
|
|
|
$cidSql="";
|
|
|
if(!empty($cid)){
|
|
|
$cidSql=" and a.cid=".$cid." ";
|
|
|
+ }elseif(!empty($cidString)){
|
|
|
+ $cidSql=" and a.cid in (".$cidString.") ";
|
|
|
+ }else{
|
|
|
+ return array();
|
|
|
}
|
|
|
|
|
|
$sql = "select b.* ,a.invoiceTrainId,a.rid
|
|
|
from " . $this->_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 ".$psSql.$cidSql.$dateSql." limit ".$limit;
|
|
|
+ ".$where.$psSql.$cidSql.$dateSql." limit ".$limit;
|
|
|
|
|
|
$query = Doo::db ()->query ( $sql );
|
|
|
$result = $query->fetchAll ();
|
|
@@ -157,6 +167,7 @@ class receipt extends DooModel {
|
|
|
$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']);
|
|
@@ -170,18 +181,108 @@ class receipt extends DooModel {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获得培训班结算的合计金额
|
|
|
+ * @param string $itid 发票培训班ID
|
|
|
+ */
|
|
|
+ function getReceiptTrainSumByItid($sql=""){
|
|
|
+ Doo::loadModel ( 'invoice' );
|
|
|
+ $invoice = new invoice ();
|
|
|
+
|
|
|
+ $query = Doo::db ()->query ( $sql );
|
|
|
+ $result = $query->fetchAll ();
|
|
|
+ //组合发票培训班ID
|
|
|
+ $itidList = array ();$ridList=array();
|
|
|
+ foreach ($result as $key=>$value){
|
|
|
+ array_push ( $itidList, $value ['invoiceTrainId'] );
|
|
|
+ array_push ( $ridList, $value ['rid'] );
|
|
|
+ }
|
|
|
+ $itidList = array_unique($itidList);
|
|
|
+ $itidString=implode ( ',', $itidList );
|
|
|
+ $ridList = array_unique($ridList);
|
|
|
+ $ridString=implode ( ',', $ridList );
|
|
|
+
|
|
|
+ //发票培训班ID-整合出开票金额合计-入账金额合计
|
|
|
+ $invoiceList = $invoice->sumOfinvoiceTrain ( $itidString );//开票合计-开票收入
|
|
|
+ $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidString );//入账合计-实际收入
|
|
|
+ $invoiceTotalAmount=0;//开票金额合计
|
|
|
+ $receivablesTotalAmount=0;//入账金额合计
|
|
|
+ foreach ( $invoiceList as $k => $v ) {
|
|
|
+ $invoiceTotalAmount+=$v ['invoicePrice'];
|
|
|
+ }
|
|
|
+ foreach ( $invoiceRecelvablesList as $i => $o ) {
|
|
|
+ $receivablesTotalAmount+=$o ['receivablesPrice'];
|
|
|
+ }
|
|
|
+ //未收款
|
|
|
+ $unReceivablesTotalAmount=sprintf ( "%.2f",$invoiceTotalAmount-$receivablesTotalAmount);
|
|
|
+ //获得支出金额合计
|
|
|
+ Doo::loadModel ( 'RItem' );
|
|
|
+ $RItem = new RItem ();
|
|
|
+ Doo::loadModel ( 'RILecturer' );
|
|
|
+ $RILecturer = new RILecturer ();
|
|
|
+ $RItemPrice=$RItem->getRItemPriceByRids($ridString);
|
|
|
+ $RILecturerPrice=$RILecturer->getRILecturerPriceByRids($ridString);
|
|
|
+ $payPrice=$RItemPrice+$RILecturerPrice;//支出金额合计
|
|
|
+ $profit=$invoiceTotalAmount-$payPrice;
|
|
|
+
|
|
|
+ return array('invoiceTotalAmount'=>sprintf ( "%.2f",$invoiceTotalAmount),
|
|
|
+ 'payPrice'=>sprintf ( "%.2f",$payPrice),
|
|
|
+ 'profit'=>sprintf ( "%.2f",$profit),
|
|
|
+ 'unReceivablesTotalAmount'=>$unReceivablesTotalAmount,
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $sql
|
|
|
+ */
|
|
|
+ function initReceiptTrainRevenue($sql=""){
|
|
|
+ Doo::loadModel ( 'invoice' );
|
|
|
+ $invoice = new invoice ();
|
|
|
+
|
|
|
+ $query = Doo::db ()->query ( $sql );
|
|
|
+ $result = $query->fetchAll ();
|
|
|
+
|
|
|
+ foreach ($result as $key=>$value){
|
|
|
+
|
|
|
+ $invoiceList = $invoice->sumOfinvoiceTrain ( $value['invoiceTrainId'] );//开票合计-开票收入
|
|
|
+ $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $value['invoiceTrainId'] );//入账合计-实际收入
|
|
|
+ $invoiceTotalAmount=0;//开票金额合计
|
|
|
+ $receivablesTotalAmount=0;//入账金额合计
|
|
|
+ foreach ( $invoiceList as $k => $v ) {
|
|
|
+ $invoiceTotalAmount+=$v ['invoicePrice'];
|
|
|
+ }
|
|
|
+ foreach ( $invoiceRecelvablesList as $i => $o ) {
|
|
|
+ $receivablesTotalAmount+=$o ['receivablesPrice'];
|
|
|
+ }
|
|
|
+//echo $invoiceTotalAmount.'-'.$receivablesTotalAmount.'</br>';
|
|
|
+ if ($invoiceTotalAmount<=$receivablesTotalAmount){
|
|
|
+ $itemData = array (
|
|
|
+ 'rid' => $value['rid'],
|
|
|
+ 'paidStatus' => 1,
|
|
|
+ );
|
|
|
+ $this->setReceiptByCondition($itemData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获得培训班 年营收图表
|
|
|
*/
|
|
|
- function getReceiptTrainByYearChart($year=''){
|
|
|
+ function getReceiptTrainByYearChart($cid='',$year=''){
|
|
|
+ if (empty($cid)){
|
|
|
+ return array();
|
|
|
+ }
|
|
|
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 paidStatus=1 and Year(date) =".$year."
|
|
|
+ where status not in (3,4,5) and Rtype=3 and trainId!=0 and invoiceTrainId!=0 and cid in (".$cid.") and paidStatus=1 and Year(date) =".$year."
|
|
|
GROUP BY Month(date)";
|
|
|
//
|
|
|
+
|
|
|
$query = Doo::db ()->query ( $sql );
|
|
|
$result = $query->fetchAll ();
|
|
|
|
|
@@ -189,15 +290,16 @@ class receipt extends DooModel {
|
|
|
$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']);
|
|
|
+ $RItemPrice=$RItem->getRItemPriceByRids($value['rid']);
|
|
|
+ $RILecturerPrice=$RILecturer->getRILecturerPriceByRids($value['rid']);
|
|
|
+ $RIprice=$RItemPrice+$RILecturerPrice;//支出金额合计
|
|
|
+
|
|
|
//收款金额总和
|
|
|
$ITprice=$invoice->getInvoicePriceByIids($value['invoiceTrainId']);
|
|
|
|
|
@@ -267,6 +369,38 @@ class receipt extends DooModel {
|
|
|
|
|
|
return $rinfo;
|
|
|
}
|
|
|
+
|
|
|
+ function getReceiptByTrainLoanRid($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' => 'trainLoanRid=' . $rid,
|
|
|
+ 'asArray' => true
|
|
|
+ ) );
|
|
|
+
|
|
|
+
|
|
|
+ $XDeode = new XDeode ( 7 );
|
|
|
+ $rinfo ['ridKey7'] = $XDeode->encode ( $rinfo ['rid'] );
|
|
|
+
|
|
|
+
|
|
|
+// $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 );
|