<?php
/**********************************************************************
***********************************************************************/
function add_asset_categories($description, $rate, $asset_account, 
                                $depreciation_account, $accumulated_account, 
                                $valuation_account, $disposal_account, 
                                $asset_adjustment_account)
{
	$sql = "INSERT INTO ".TB_PREF."asset_catergories(description, depreciation_rate, asset_account,
                                                         depreciation_account, accumulated_account, 
                                                         valuation_account, disposal_account, asset_adjustment_account)
                                                    
		VALUES (". db_escape($description).",".db_escape($rate).",".db_escape($asset_account).", "
                        .db_escape($depreciation_account).",".db_escape($accumulated_account).","
                        .db_escape($valuation_account).",".db_escape($disposal_account).",".db_escape($asset_adjustment_account).")";

 db_query($sql, "could not add asset types");
 return db_insert_id();
 
}

function update_asset_categories($id, $description, $rate, $asset_account, $depreciation_account, 
                                    $accumulated_account, $valuation_account, 
                                    $disposal_account, $asset_adjustment_account)
{
	$sql = "UPDATE ".TB_PREF."asset_catergories  SET 
                         description=".db_escape($description)
			.",depreciation_rate=".db_escape($rate)
			.", asset_account=".db_escape($asset_account)
			.", depreciation_account=".db_escape($depreciation_account)
			.", accumulated_account=".db_escape($accumulated_account)
			.", valuation_account=".db_escape($valuation_account)
			.", disposal_account=".db_escape($disposal_account)
			.", asset_adjustment_account=".db_escape($asset_adjustment_account)
			." WHERE id=".db_escape($id);

	db_query($sql, "could not update asset type");
}

function get_all_asset_categories($all=false)
{
	$sql = "SELECT * FROM ".TB_PREF."asset_catergories ";
	if (!$all) $sql .= " WHERE !inactive";

	return db_query($sql, "could not get all asset types");
}

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

	$result = db_query($sql, "could not get asset type");

	return db_fetch($result);
}

function delete_asset_categories($id)
{
	$sql="DELETE FROM ".TB_PREF."asset_catergories WHERE id=".db_escape($id);

	db_query($sql, "could not delete asset type");
}

function asset_categories_in_assets($selected_id)
{
	$sql="SELECT COUNT(*) FROM ".TB_PREF."asset_master WHERE type=".db_escape($selected_id);

	$result = db_query($sql, "could not query assets");
	$myrow = db_fetch_row($result);
	return ($myrow[0] > 0); 
}

?>
