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

class ProjectMandaysBillClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= ProjectMandaysBillTable::C_TABLE ;
		$this->fldid 	= ProjectMandaysBillTable::C_ID ;
		$this->flddesc 	= ProjectMandaysBillTable::C_INVOICE_NO ;
	}
	function __destruct() {
	}
    
    function getTotalBillPaid($projectId){
        $sql = "SELECT COUNT(*) AS [NO_INVOICE], ";
        $sql .= "   COALESCE(SUM(" . ProjectMandaysBillTable::C_INVOICE_BILLED . "),0) AS [BILLED], ";
        $sql .= "   COALESCE(SUM(" . ProjectMandaysBillTable::C_INVOICE_PAID . "),0) AS [PAID] ";
        $sql .= "FROM " . ProjectMandaysBillTable::C_TABLE . " ";
        $sql .= "WHERE " . ProjectMandaysBillTable::C_ID . " = " . $projectId . " ";
        
        $rows = $this->db->getTable($sql);
        
        return $rows;
    }
    
    function getMandaysBill($projectId){
        $sql = "SELECT * FROM " . ProjectMandaysBillTable::C_TABLE . " WHERE " . ProjectMandaysBillTable::C_ID . " = " . $projectId . " ";
        
        $rows = $this->db->getTable($sql);
        
        return $rows;
    }
}
?>