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

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

        $sql = "INSERT INTO ".SalesQuotationMaintenanceDetailTable::C_TABLE." (" .
				SalesQuotationMaintenanceDetailTable::C_DETAIL_ID.",".
                SalesQuotationMaintenanceDetailTable::C_ID.",".
                SalesQuotationMaintenanceDetailTable::C_QUOTATION_ID.",".
                SalesQuotationMaintenanceDetailTable::C_DESC.",".
                SalesQuotationMaintenanceDetailTable::C_COMMENT.",".
                SalesQuotationMaintenanceDetailTable::C_AMOUNT.",".
                SalesQuotationMaintenanceDetailTable::C_ORG_ID.",".
                SalesQuotationMaintenanceDetailTable::C_COY_ID.",".
                SalesQuotationMaintenanceDetailTable::C_ACTIVE.",".
                SalesQuotationMaintenanceDetailTable::C_WS_ID.",".
                SalesQuotationMaintenanceDetailTable::C_MODIFY_BY.",".
                SalesQuotationMaintenanceDetailTable::C_MODIFY_DATE.",".
                SalesQuotationMaintenanceDetailTable::C_CREATE_BY.",".
                SalesQuotationMaintenanceDetailTable::C_CREATE_DATE.
                ") SELECT " .
				SalesQuotationMaintenanceDetailTable::C_DETAIL_ID.",".
                $new_maintenance_id.",".
                $new_quot_id.",".
                SalesQuotationMaintenanceDetailTable::C_DESC.",".
                SalesQuotationMaintenanceDetailTable::C_COMMENT.",".
                SalesQuotationMaintenanceDetailTable::C_AMOUNT.",".
                SalesQuotationMaintenanceDetailTable::C_ORG_ID.",".
                SalesQuotationMaintenanceDetailTable::C_COY_ID.",".
                true.",".
                "'".$ws."',".
                $modifyby.",".
                "'".$modifydate."',".
                $modifyby.",".
                "'".$modifydate."'".
                " FROM ".SalesQuotationMaintenanceDetailTable::C_TABLE.
                " WHERE " . SalesQuotationMaintenanceDetailTable::C_QUOTATION_ID . " = " .$quot_id ;
        
		$this->db->executeSql($sql);
    }
	function getSalesQuotationMaintenance($id, $quotId){
        $sql = "SELECT * FROM " ;
        $sql .= SalesQuotationMaintenanceDetailTable::C_TABLE . 
        		" WHERE " . SalesQuotationMaintenanceDetailTable::C_ID . " = " . $id .
        		" AND " . SalesQuotationMaintenanceDetailTable::C_QUOTATION_ID . " = " . $quotId;

        $sql .= "ORDER BY " . SalesQuotationMaintenanceDetailTable::C_DETAIL_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        if(!is_null($rows) && count($rows) > 0){
            return $rows;
        }
        
        return null;
    }
}
?>