<?php
require_once (PATH_TABLES . "activity/TaxesTypePercentageTable.php") ;
require_once (PATH_MODELS . "base/MasterBase.php") ;

class TaxesTypePercentageClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= TaxesTypePercentageTable::C_TABLE ;
		$this->fldid 	= TaxesTypePercentageTable::C_ID ;
	}
	function __destruct() {
	}
    
    public function getPercentages($taxesTypeId){
        $sql = "SELECT * FROM " . TaxesTypePercentageTable::C_TABLE . " WHERE " . TaxesTypePercentageTable::C_ID . " = " . $taxesTypeId;
        
        $rows = $this->db->getTable($sql);
        return $rows;
    }
    
    public function getPercentageValue($taxesTypeId, $receiptDate){
        $date = DateTime::createFromFormat("d/m/Y", $receiptDate);
        
        $sql = "SELECT * FROM " . TaxesTypePercentageTable::C_TABLE . 
                " WHERE " . TaxesTypePercentageTable::C_ID . " = " . $taxesTypeId . 
                " AND " . TaxesTypePercentageTable::C_START_DATE . " <= '" . date_format($date, "Y-m-d") . "' " . 
                " ORDER BY " . TaxesTypePercentageTable::C_START_DATE . " DESC ";
        
        $rows = $this->db->getTable($sql);
        return $rows;
    }
}
?>