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

class SalesQuotationMaintenanceClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= SalesQuotationMaintenanceTable::C_TABLE ;
		$this->fldid 	= SalesQuotationMaintenanceTable::C_QUOTATION_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 ".SalesQuotationMaintenanceTable::C_TABLE." (" .
                SalesQuotationMaintenanceTable::C_QUOTATION_ID.",".
                SalesQuotationMaintenanceTable::C_CURRENCY.",".
                SalesQuotationMaintenanceTable::C_SUBTOTAL.",".
                SalesQuotationMaintenanceTable::C_DISC_TYPE.",".
                SalesQuotationMaintenanceTable::C_DISC_PERCENTAGE.",".
                SalesQuotationMaintenanceTable::C_DISC_TOTAL.",".
                SalesQuotationMaintenanceTable::C_GST_PERCENTAGE.",".
                SalesQuotationMaintenanceTable::C_GST_TOTAL.",".
                SalesQuotationMaintenanceTable::C_GRAND_TOTAL.",".
                SalesQuotationMaintenanceTable::C_ORG_ID.",".
                SalesQuotationMaintenanceTable::C_COY_ID.",".
                SalesQuotationMaintenanceTable::C_ACTIVE.",".
                SalesQuotationMaintenanceTable::C_WS_ID.",".
                SalesQuotationMaintenanceTable::C_MODIFY_BY.",".
                SalesQuotationMaintenanceTable::C_MODIFY_DATE.",".
                SalesQuotationMaintenanceTable::C_CREATE_BY.",".
                SalesQuotationMaintenanceTable::C_CREATE_DATE.",".
                SalesQuotationMaintenanceTable::C_REF_ID.
                ") SELECT " .
                $new_quot_id.",".
                SalesQuotationMaintenanceTable::C_CURRENCY.",".
                SalesQuotationMaintenanceTable::C_SUBTOTAL.",".
                SalesQuotationMaintenanceTable::C_DISC_TYPE.",".
                SalesQuotationMaintenanceTable::C_DISC_PERCENTAGE.",".
                SalesQuotationMaintenanceTable::C_DISC_TOTAL.",".
                SalesQuotationMaintenanceTable::C_GST_PERCENTAGE.",".
                SalesQuotationMaintenanceTable::C_GST_TOTAL.",".
                SalesQuotationMaintenanceTable::C_GRAND_TOTAL.",".
                SalesQuotationMaintenanceTable::C_ORG_ID.",".
                SalesQuotationMaintenanceTable::C_COY_ID.",".
                true.",".
                "'".$ws."',".
                $modifyby.",".
                "'".$modifydate."',".
                $modifyby.",".
                "'".$modifydate."',".
                SalesQuotationMaintenanceTable::C_ID.
                " FROM ".SalesQuotationMaintenanceTable::C_TABLE.
                " WHERE " . SalesQuotationMaintenanceTable::C_QUOTATION_ID . " = " .$quot_id ;
        
		$this->db->executeSql($sql);
		
		$sql = " SELECT TOP 1 * FROM " . SalesQuotationMaintenanceTable::C_TABLE . " ".
                " WHERE " . SalesQuotationMaintenanceTable::C_QUOTATION_ID . " = " .$new_quot_id.
                " ORDER BY " . SalesQuotationMaintenanceTable::C_ID . " DESC ";
        
        $row = $this->db->getTable($sql);
        
        if(!is_null($row) && count($row) > 0)
            return $row[0][SalesQuotationMaintenanceTable::C_ID];
        else
            return 0;
    }
	// function getMaintenanceByQuotId($quot_id){
    //     $sql = "SELECT * FROM " .SalesQuotationMaintenanceTable::C_TABLE.
	// 	" WHERE " . SalesQuotationMaintenanceTable::C_QUOTATION_ID . " = " .$quot_id ;
        
    //     $rows = $this->db->getTable($sql);

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