<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/

function add_latter_hand($name)
{
	$sql = "INSERT INTO ".TB_PREF."latter_head (name) VALUES (".db_escape($name) . ")";
   	db_query($sql,"The sales area could not be added");
    $latter_head_id = db_insert_id();
    return $latter_head_id;
}

function update_latter_hand($selected_id, $name)
{
	$sql = "UPDATE ".TB_PREF."latter_head SET name=".db_escape($name)." WHERE id = ".db_escape($selected_id);
   	db_query($sql,"The sales area could not be updated");
}

function delete_latter_hand($selected_id)
{
	$sql="DELETE FROM ".TB_PREF."latter_head WHERE id=".db_escape($selected_id);
	db_query($sql,"could not delete sales area");
}

function get_latter_hands($show_inactive)
{
	$sql = "SELECT * FROM ".TB_PREF."latter_head";
	if (!$show_inactive) $sql .= " WHERE !inactive";
	return db_query($sql,"could not get areas");
}

function get_latter_hand($selected_id)
{
	$sql = "SELECT * FROM ".TB_PREF."latter_head WHERE id=".db_escape($selected_id);
	$result = db_query($sql,"could not get area");
	return db_fetch($result);
}

function get_latter_hand_name($id)
{
	$sql = "SELECT name FROM ".TB_PREF."latter_head WHERE id=".db_escape($id);
	$result = db_query($sql, "could not get sales type");
	$row = db_fetch_row($result);
	return is_array($row) ? $row[0] : false;
}