<?php
/**********************************************************************
***********************************************************************/
function add_item_pos_price($stock_id, $sales_type_id, $curr_abrev, $pos_price,$effective_date,$expiry_date)
{
        $id_user = $_SESSION['wa_current_user']->user;
        $datetime = date('Y-m-d H:i:s');
        
        $sql = "INSERT INTO ".TB_PREF."pos_prices (
                        stock_id, sales_type_id, 
                        curr_abrev, pos_price,
                        created_by,created_on,
                        effective_date,expiry_date) 
                VALUES (".db_escape($stock_id).", ".db_escape($sales_type_id).", "
                        .db_escape($curr_abrev).", ".db_escape($pos_price).", "
                        .db_escape($id_user).", ".db_escape($datetime).", "
                        .db_escape(date2sql($effective_date)).", ".db_escape(date2sql($expiry_date)).")";

        db_query($sql,"Item POS price could not be added");		
}

function update_item_pos_price($price_id, $sales_type_id, $curr_abrev, $pos_price,$effective_date,$expiry_date)
{
        $id_user = $_SESSION['wa_current_user']->user;
        $datetime = date('Y-m-d H:i:s');
                
        $sql = "UPDATE ".TB_PREF."pos_prices 
                SET curr_abrev=".db_escape($curr_abrev).", 
                    updated_by=".db_escape($id_user).",
                    updated_on=".db_escape($datetime).",
                    effective_date=".db_escape(date2sql($effective_date)).",
                    expiry_date=".db_escape(date2sql($expiry_date)).",
                    pos_price=".db_escape($pos_price)." 
                WHERE sales_type_id = ".db_escape($sales_type_id)." AND 
                    id=".db_escape($price_id);

        db_query($sql,"Item POS price could not be updated");		
}

function delete_item_pos_price($price_id)
{
	$sql="DELETE FROM ".TB_PREF."pos_prices WHERE id= ".db_escape($price_id);
	db_query($sql,"Item POS price could not be deleted");			
}

function get_item_pos_prices($stock_id)
{
	$sql = "SELECT "
                        .TB_PREF."sales_types.sales_type, "
                        .TB_PREF."pos_prices.* 
		FROM "
                        .TB_PREF."pos_prices, "
                        .TB_PREF."sales_types 
		WHERE "
                        .TB_PREF."pos_prices.sales_type_id = ".TB_PREF."sales_types.id AND 
                        stock_id=".db_escape($stock_id)." 
                ORDER BY 
                        curr_abrev, sales_type_id";	
	
	return db_query($sql,"Item POS prices could not be retreived");
}

function get_stock_pos_price($price_id)
{
	$sql = "SELECT * FROM ".TB_PREF."pos_prices WHERE id=".db_escape($price_id);
	
	$result = db_query($sql,"Item POS price could not be retreived");
	
	return db_fetch($result);
}

function get_stock_pos_price_type_currency($stock_id, $type, $currency)
{
	$sql = "SELECT * FROM ".TB_PREF."pos_prices WHERE stock_id=".db_escape($stock_id)."
		AND sales_type_id=".db_escape($type)."
		AND curr_abrev=".db_escape($currency);
	
	$result = db_query($sql,"price could not be retreived");
	
	return db_fetch($result);
}
?>