<?php

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

class receiptDetail extends DooModel {

    public $rdid;
    public $item;
    public $staff;
    
    public $itemCategory;
    public $price;
    
    public $date;
    public $pastDate;
    public $cid;
    
    public $rid;
    public $status;
    
    public $_table = 'CLD_receiptDetail';
    public $_primarykey = 'rdid';
    
    public $_fields = array('rdid', 'item', 'staff', 'itemCategory', 'price', 'date','pastDate', 'cid', 'rid', 'status');

    /**
     * 按人员年月合计报销单项目金额
     * @param string $sid
     * @param string $year
     * @param string $month
     * @return unknown
     */
    function getReceiptTotalItem($sid='',$year='',$month=''){
    	if(empty($sid))
    		return array();
    	$list=$this->find ( array (
    			'select' => 'staff,item,sum(price) as price,itemCategory,Month(date) as month',
    			'where' => 'staff=' . $sid . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
    			'groupby' => 'item,Month(date),itemCategory',
    			'asArray' => true
    	) );
    	return $list;
    }
    
    /**
     * 按人员年月合计报销单大项金额
     * @param string $sid
     * @param string $year
     * @param string $month
     * @return unknown
     */
    function getReceiptTotalItemCategory($sid='',$year='',$month=''){
    	if(empty($sid))
    		return array();
    	$list=$this->find ( array (
    			'select' => 'staff,sum(price) as price,itemCategory,Month(date) as month',
    			'where' => 'staff=' . $sid . " and status=1 and Year(date)=" . $year . ' and Month(date)=' . $month,
    			'groupby' => 'Month(date),itemCategory',
    			'asArray' => true
    	) );
    	return $list;
    }
}

?>