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

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

        $sql = "INSERT INTO ".SalesQuotationItemsDetailTable::C_TABLE." (" .
                SalesQuotationItemsDetailTable::C_ITEMS_ID.",".
                SalesQuotationItemsDetailTable::C_QUOTATION_ID.",".
                SalesQuotationItemsDetailTable::C_LINE_NO.",".
                SalesQuotationItemsDetailTable::C_LINE_DESC.",".
                SalesQuotationItemsDetailTable::C_LINE_COMMENT.",".
                SalesQuotationItemsDetailTable::C_LINE_AMOUNT.",".
                SalesQuotationItemsDetailTable::C_LINE_DISC.",".
                SalesQuotationItemsDetailTable::C_LINE_DISC_DESC.",".
                SalesQuotationItemsDetailTable::C_LINE_UNIT_PRICE.",".
                SalesQuotationItemsDetailTable::C_LINE_QTY.",".
                SalesQuotationItemsDetailTable::C_ORG_ID.",".
                SalesQuotationItemsDetailTable::C_COY_ID.",".
                SalesQuotationItemsDetailTable::C_ACTIVE.",".
                SalesQuotationItemsDetailTable::C_WS_ID.",".
                SalesQuotationItemsDetailTable::C_MODIFY_BY.",".
                SalesQuotationItemsDetailTable::C_MODIFY_DATE.",".
                SalesQuotationItemsDetailTable::C_CREATE_BY.",".
                SalesQuotationItemsDetailTable::C_CREATE_DATE.
                ") SELECT " .
                $new_items_id.",".
                $new_quot_id.",".
                SalesQuotationItemsDetailTable::C_LINE_NO.",".
                SalesQuotationItemsDetailTable::C_LINE_DESC.",".
                SalesQuotationItemsDetailTable::C_LINE_COMMENT.",".
                SalesQuotationItemsDetailTable::C_LINE_AMOUNT.",".
                SalesQuotationItemsDetailTable::C_LINE_DISC.",".
                SalesQuotationItemsDetailTable::C_LINE_DISC_DESC.",".
                SalesQuotationItemsDetailTable::C_LINE_UNIT_PRICE.",".
                SalesQuotationItemsDetailTable::C_LINE_QTY.",".
                SalesQuotationItemsDetailTable::C_ORG_ID.",".
                SalesQuotationItemsDetailTable::C_COY_ID.",".
                true.",".
                "'".$ws."',".
                $modifyby.",".
                "'".$modifydate."',".
                $modifyby.",".
                "'".$modifydate."'".
                " FROM ".SalesQuotationItemsDetailTable::C_TABLE.
                " WHERE " . SalesQuotationItemsDetailTable::C_QUOTATION_ID . " = " .$quot_id ;
        // log::write($sql);
		$this->db->executeSql($sql);
    }
	function getRecordItemsDetail($quot_id, $items_id){
        $sql = "SELECT * FROM " .SalesQuotationItemsDetailTable::C_TABLE.
        " WHERE " . SalesQuotationItemsDetailTable::C_QUOTATION_ID . " = " .$quot_id. 
        " AND " .SalesQuotationItemsDetailTable::C_ITEMS_ID. " = " .$items_id.
        " ORDER BY " .SalesQuotationItemsDetailTable::C_LINE_NO ;
        
        $rows = $this->db->getTable($sql);

        if(!is_null($rows) && count($rows) > 0){
            return $rows;
        }
        
        return null;
    }
	function deleteRecordByItemsId($items_id){
        $sql = "DELETE FROM " .SalesQuotationItemsDetailTable::C_TABLE.
		" WHERE " . SalesQuotationItemsDetailTable::C_ITEMS_ID . " = " .$items_id ;
        
        $this->db->executeSql($sql);
    }
	function deleteRecordByQuotationId($quot_id){
        $sql = "DELETE FROM " .SalesQuotationItemsDetailTable::C_TABLE.
		" WHERE " . SalesQuotationItemsDetailTable::C_QUOTATION_ID . " = " .$quot_id ;
        
        $this->db->executeSql($sql);
    }
}
?>