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

class SalesQuotationCoverClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= SalesQuotationCoverTable::C_TABLE ;
		$this->fldid 	= SalesQuotationCoverTable::C_ID ;
	}
	function __destruct() {
	}
    function copySalesQuotation($quot_id, $new_quot_id){
        $modifydate = date_create('now')->format('Y-m-d H:i:s') ;
        $modifyby   = $_SESSION[SE_USERID];
        $ws         = $_SESSION[SE_REMOTE_IP];

        $sql = "INSERT INTO ".SalesQuotationCoverTable::C_TABLE." (" .
                SalesQuotationCoverTable::C_QUOTATION_ID.",".
                SalesQuotationCoverTable::C_LINE_NO.",".
                SalesQuotationCoverTable::C_PAGE.",".
                SalesQuotationCoverTable::C_PAGE_LINE.",".
                SalesQuotationCoverTable::C_DOCUMENT.",".
                SalesQuotationCoverTable::C_DESC.",".
                SalesQuotationCoverTable::C_PRINT.",".
                SalesQuotationCoverTable::C_PRINT_PAGE.",".
                SalesQuotationCoverTable::C_ORG_ID.",".
                SalesQuotationCoverTable::C_COY_ID.",".
                SalesQuotationCoverTable::C_ACTIVE.",".
                SalesQuotationCoverTable::C_WS_ID.",".
                SalesQuotationCoverTable::C_MODIFY_BY.",".
                SalesQuotationCoverTable::C_MODIFY_DATE.",".
                SalesQuotationCoverTable::C_CREATE_BY.",".
                SalesQuotationCoverTable::C_CREATE_DATE.",".
                SalesQuotationCoverTable::C_REF_ID.
                ") SELECT " .
                $new_quot_id.",".
                SalesQuotationCoverTable::C_LINE_NO.",".
                SalesQuotationCoverTable::C_PAGE.",".
                SalesQuotationCoverTable::C_PAGE_LINE.",".
                SalesQuotationCoverTable::C_DOCUMENT.",".
                SalesQuotationCoverTable::C_DESC.",".
                SalesQuotationCoverTable::C_PRINT.",".
                SalesQuotationCoverTable::C_PRINT_PAGE.",".
                SalesQuotationCoverTable::C_ORG_ID.",".
                SalesQuotationCoverTable::C_COY_ID.",".
                true.",".
                "'".$ws."',".
                $modifyby.",".
                "'".$modifydate."',".
                $modifyby.",".
                "'".$modifydate."'s,".
                SalesQuotationCoverTable::C_ID.
                " FROM ".SalesQuotationCoverTable::C_TABLE.
                " WHERE " . SalesQuotationCoverTable::C_QUOTATION_ID . " = " .$quot_id ;
        
		$this->db->executeSql($sql);
    }
	function getRecordByQuotationId($quot_id){
        $sql = "SELECT * FROM " . SalesQuotationCoverTable::C_TABLE .
                " WHERE " . SalesQuotationCoverTable::C_QUOTATION_ID . " = " . $quot_id .
                " ORDER BY " . SalesQuotationCoverTable::C_LINE_NO ." ASC";
        
        $rows = $this->db->getTable($sql);

        if(!is_null($rows) && count($rows) > 0){
            return $rows;
        }
        
        return null;
    }
	function deleteRecordByQuotationId($quot_id){
        $sql = "DELETE FROM " .SalesQuotationCoverTable::C_TABLE.
		" WHERE " . SalesQuotationCoverTable::C_QUOTATION_ID . " = " .$quot_id ;
        
        $this->db->executeSql($sql);
    }
}
?>