
<?php 

function add_charge_rate_per($charges_id='', $percentage=0, $amount=0)
{
	global $Refs;

	$sql = "INSERT INTO ".TB_PREF."charges_rate_percentage (charges_id, percentage, amount) VALUES (
		".db_escape($charges_id) . ", ".db_escape($percentage) . ", ".db_escape($amount) . ")";
   	db_query($sql,"The charges_rate_percentage could not be added");
}

function update_charge_rate_per($selected_id, $percentage=0, $amount=0)
{
	$sql = "UPDATE ".TB_PREF."charges_rate_percentage SET percentage=".db_escape($percentage).", amount=".db_escape($amount)."  WHERE id = ".db_escape($selected_id);
   	db_query($sql,"The charges_rate_percentage could not be updated");
}

function delete_charge_rate_per($selected_id)
{
	$sql="DELETE FROM ".TB_PREF."charges_rate_percentage WHERE id=".db_escape($selected_id);
	db_query($sql,"could not delete charges_rate_percentage");
}

function get_charge_rate_pers($show_inactive, $charges_id='')
{
	$sql = "SELECT * FROM ".TB_PREF."charges_rate_percentage";
	if (!$show_inactive) $sql .= " WHERE !inactive";
	if($charges_id != '')
		$sql .= " AND charges_id=".db_escape($charges_id);
	// $sql .= " ORDER BY charges_rate_percentage";
	return db_query($sql,"could not charges_rate_percentage");
}

function get_charge_rate_per($selected_id)
{
	$sql = "SELECT * FROM ".TB_PREF."charges_rate_percentage WHERE id=".db_escape($selected_id);

	$result = db_query($sql,"could not charges_rate_percentage");
	return db_fetch($result);
}

function get_charge_rate_per_charges_id($charges_id, $percentage)
{
	$sql = "SELECT * FROM ".TB_PREF."charges_rate_percentage WHERE charges_id=".db_escape($charges_id) . " AND percentage<=".db_escape($percentage)." ORDER BY  percentage DESC";
	$result = db_query($sql,"could not charges_rate_percentage");
	return db_fetch($result);
}

//------------------------------------------------------------------------------------


?>