<?php
require_once (PATH_TABLES . "activity/ActivityExpenseDetailTable.php") ;
require_once (PATH_MODELS . "activity/ExpenseItemClass.php") ;
//require_once (PATH_MODELS . "activity/ActivityTypeClass.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class ActivityExpenseDetailClass extends MasterBase {
  
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= ActivityExpenseDetailTable::C_TABLE ;
		$this->fldid 	= ActivityExpenseDetailTable::C_ID ;
	}
	function __destruct() {
	}

	function getExpenseListItem($id,$line='') {  

		$clsItem        = new ExpenseItemClass($this->db);
		//$clsType        = new ActivityTypeClass($this->db);
        
        $sql = "SELECT * FROM " .ActivityExpenseDetailTable::C_TABLE . 
                " WHERE " . ActivityExpenseDetailTable::C_ID . " = " . $id;

        if($line){
            $sql .= " AND ".ActivityExpenseDetailTable::C_LINE. " = ".$line;
        }
        
        $rows=$this->db->getTable($sql);
        
        $list = array() ;
        if(!is_null($rows) && count($rows) > 0){
            foreach($rows as $row){

             $data = array() ;
             $data[ActivityExpenseDetailTable::C_ID]    		= $row[ActivityExpenseDetailTable::C_ID];
             $data[ActivityExpenseDetailTable::C_LINE] 			= $row[ActivityExpenseDetailTable::C_LINE];
             $data[ActivityExpenseDetailTable::C_ITEM_ID] 		= $row[ActivityExpenseDetailTable::C_ITEM_ID];
             $data[ActivityExpenseDetailTable::C_RECEIPT_NO] 	= $row[ActivityExpenseDetailTable::C_RECEIPT_NO];
             $data[ActivityExpenseDetailTable::C_TYPE] 			= $row[ActivityExpenseDetailTable::C_TYPE];
             $data[ActivityExpenseDetailTable::C_AMOUNT] 		= $row[ActivityExpenseDetailTable::C_AMOUNT];
             $data[ActivityExpenseDetailTable::C_TAX_ID] 		= $row[ActivityExpenseDetailTable::C_TAX_ID];
             $data[ActivityExpenseDetailTable::C_TAX] 			= $row[ActivityExpenseDetailTable::C_TAX];
             $data[ActivityExpenseDetailTable::C_AMOUNT_NET] 	= $row[ActivityExpenseDetailTable::C_AMOUNT_NET];
             $data[ActivityExpenseDetailTable::C_DESC] 			= $row[ActivityExpenseDetailTable::C_DESC];

             $data['item_desc'] 			= $clsItem->getRecord($data[ActivityExpenseDetailTable::C_ITEM_ID])[ExpenseItemTable::C_DESC];
             //$data['type_desc'] 			= $clsType->getRecord($data[ActivityExpenseDetailTable::C_TYPE])[ActivityTypeTable::C_DESC];
             $data['type_desc'] 			= ($data[ActivityExpenseDetailTable::C_TYPE]==1)?'Customer':'Self';

            $list[] = $data;
         	unset($data);

        	}
    	}
    	return $list;

	}


}
?>