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

class SalesQuotationAppendixClass extends MasterBase {
	function __construct($db) {
		$this->db 		= $db ;
		$this->tbl 		= SalesQuotationAppendixTable::C_TABLE ;
		$this->fldid 	= SalesQuotationAppendixTable::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 ".SalesQuotationAppendixTable::C_TABLE." (" .
                SalesQuotationAppendixTable::C_APPENDIX_ID.",".
                SalesQuotationAppendixTable::C_ID.",".
                SalesQuotationAppendixTable::C_SECTION.",".
                SalesQuotationAppendixTable::C_SUBJECT.",".
                SalesQuotationAppendixTable::C_DESC.",".
                SalesQuotationAppendixTable::C_ORG_ID.",".
                SalesQuotationAppendixTable::C_COY_ID.",".
                SalesQuotationAppendixTable::C_ACTIVE.",".
                SalesQuotationAppendixTable::C_WS_ID.",".
                SalesQuotationAppendixTable::C_MODIFY_BY.",".
                SalesQuotationAppendixTable::C_MODIFY_DATE.",".
                SalesQuotationAppendixTable::C_CREATE_BY.",".
                SalesQuotationAppendixTable::C_CREATE_DATE.
                ") SELECT " .
                SalesQuotationAppendixTable::C_APPENDIX_ID.",".
                $new_quot_id.",".
                SalesQuotationAppendixTable::C_SECTION.",".
                SalesQuotationAppendixTable::C_SUBJECT.",".
                SalesQuotationAppendixTable::C_DESC.",".
                SalesQuotationAppendixTable::C_ORG_ID.",".
                SalesQuotationAppendixTable::C_COY_ID.",".
                true.",".
                "'".$ws."',".
                $modifyby.",".
                "'".$modifydate."',".
                $modifyby.",".
                "'".$modifydate."'".
                " FROM ".SalesQuotationAppendixTable::C_TABLE.
                " WHERE " . SalesQuotationAppendixTable::C_ID . " = " .$quot_id ;
        
		$this->db->executeSql($sql);
    }
	function getSalesQuotationAppendix($id){
        $sql = "SELECT * FROM " ;
        $sql .= SalesQuotationAppendixTable::C_TABLE . " WHERE " . SalesQuotationAppendixTable::C_ID . " = " . $id;
        $sql .= "ORDER BY " . SalesQuotationAppendixTable::C_APPENDIX_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

        if(!is_null($rows) && count($rows) > 0){
            return $rows;
        }
        
        return null;
    }
    function getSalesQuotationAppendixBySection($id, $section_id){
        $sql = "SELECT * FROM " .SalesQuotationAppendixTable::C_TABLE . 
            " WHERE " . SalesQuotationAppendixTable::C_ID . " = " . $id .
            " AND " . SalesQuotationAppendixTable::C_SECTION . " = " . $section_id .
            " ORDER BY " . SalesQuotationAppendixTable::C_APPENDIX_ID ." ASC";
        
        $rows = $this->db->getTable($sql);

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