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

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

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

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

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