<?php

Doo::loadCore('db/DooModel');

class receipt extends DooModel {

    public $rid;
    public $accountItem;
    
    public $loanItem;
    
    public $staff;
    
    public $sum;
    public $date;
    public $pastDate;
    public $executeDate;
    public $loanDate;
    
    
    public $cid;
    public $status;
    public $Rtype;
    public $isBK;
    
    public $loanSum;
    public $loanRid;
    
    public $reviseDetail;
    public $revisePrice;
    public $receiptOrder;
    public $verify;
   	public $verifyStaff;
   	
   	public $executeCopy;
   	public $executeStaff;
   	
   	public $verifyBreakup;
   	
   	public $nowStaff;
   	
    public $explanation;
    public $implementOpinions;
    public $notice;
    public $amount;
    public $remittanceName;
    public $bankName;
    public $bankNumber;
    public $coupletNumber;
    public $remittanceBankType;
    
    public $_table = 'CLD_receipt';
    public $_primarykey = 'rid';
    
    public $_fields = array('aid', 'accountItem', 'staff', 'sum', 'date','pastDate' ,'cid', 'status', 'reviseDetail', 'revisePrice', 'verify','verifyStaff',
    'nowStaff','receiptOrder','explanation','notice','Rtype','loanItem','loanRid','loanSum','implementOpinions','isBK','executeCopy','executeStaff','verifyBreakup','executeDate'
    		,'amount','loanDate','remittanceName',
			'bankName',
			'bankNumber',
			'coupletNumber','remittanceBankType');

	function receiptByYear($dateCondition,$sid){
    	$sql = "select sum(sum) as sum from " . $this->_table . " where staff= '".$sid."' ".$dateCondition." and status=2 ";
    	//echo '<div style="display:none">'.$sql.'</div>';
    	$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;	
    }
   
}

?>