<?php
/**********************************************************************
***********************************************************************/
function add_holiday($holiday_date, $holiday_name, $holiday_time_code, $ot_type)
{
        $created_by = $_SESSION['wa_current_user']->user;
        $created_on = date('Y-m-d H:i:s');
        
	$sql = "INSERT INTO ".TB_PREF."holidays (holiday_date, holiday_name, 
                                        holiday_time_code, ot_type, 
                                        created_by, created_on) 
		VALUES (".db_escape($holiday_date).", ".db_escape($holiday_name).", "
                            .db_escape($holiday_time_code).", " .db_escape($ot_type).", "
                            .db_escape($created_by).", ".db_escape($created_on).")";
	
	db_query($sql,"an item price could not be added");		
}

function update_holiday($selected_id, $holiday_date, 
                            $holiday_name, $holiday_time_code, $ot_type)
{
        $updated_by = $_SESSION['wa_current_user']->user;
        $updated_on = date('Y-m-d H:i:s');
        
	$sql = "UPDATE ".TB_PREF."holidays 
                SET 
                    holiday_date=".db_escape($holiday_date).", 
                    holiday_name=".db_escape($holiday_name).", 
                    holiday_time_code=".db_escape($holiday_time_code).", 
                    ot_type=".db_escape($ot_type).", 
                    updated_by=".db_escape($updated_by).", 
                    updated_on=".db_escape($updated_on)."  
                WHERE id=".db_escape($selected_id);
	
	db_query($sql,"Holiday could not be updated");		
}

function delete_holiday($selected_id)
{
	$sql="DELETE FROM ".TB_PREF."holidays WHERE id= ".db_escape($selected_id);
	db_query($sql,"Holiday could not be deleted");			
}

function get_holidays()
{
	$sql = "SELECT 
                    h.id,
                    h.holiday_date,
                    h.holiday_name,
                    h.holiday_time_code,
                    h.ot_type,
                    lv.value_name holiday_time_name
                FROM "
                    .TB_PREF."holidays h,"
                    .TB_PREF."list_values lv 
                WHERE 
                    h.holiday_time_code = lv.value_code AND 
                    lv.list_code = 'HOLIDAY_TIME' 
		ORDER BY h.holiday_date";	
	
	return db_query($sql,"Holidays could not be retreived");
}

function get_holiday_details($selected_id)
{
	$sql = "SELECT 
                    h.id,
                    h.holiday_date,
                    h.holiday_name,
                    h.holiday_time_code,
                    h.ot_type,
                    lv.value_name holiday_time_name
                FROM "
                    .TB_PREF."holidays h,"
                    .TB_PREF."list_values lv 
                WHERE 
                    h.holiday_time_code = lv.value_code AND 
                    lv.list_code = 'HOLIDAY_TIME' AND
                    h.id = ".db_escape($selected_id);
	
	$result = db_query($sql,"price could not be retreived");
	
	return db_fetch($result);
}

function get_stock_price_type_currency2($stock_id, $type, $currency)
{
	$sql = "SELECT * FROM ".TB_PREF."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);
}
?>