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

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

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