<?php
/**********************************************************************
***********************************************************************/


function add_utility_expense_type($description, $debit_account, $coc_account)                                 
{
    $created_by = $_SESSION['wa_current_user']->user;
    $created_on = date('Y-m-d H:i:s');
    
	$sql = "INSERT INTO ".TB_PREF."utility_expense_types
                        (description, debit_account, coc_account,
                        created_by, created_on)
                                                    
		VALUES (". db_escape($description).",".db_escape($debit_account).", ".db_escape($coc_account).", 
                        ".db_escape($created_by).", ".db_escape($created_on).")";
                    
 db_query($sql, "could not add_utility_expense_type");
 return db_insert_id();
 
}

function update_utility_expense_type($id, $description, $debit_account, $coc_account)
{
    $updated_by = $_SESSION['wa_current_user']->user;
    $updated_on = date('Y-m-d H:i:s');
    
    $sql = "UPDATE ".TB_PREF."utility_expense_types  SET 
                    description=".db_escape($description).",
                    debit_account=".db_escape($debit_account).",
                    coc_account=".db_escape($coc_account).",
                    updated_by=".db_escape($updated_by).",
                    updated_on=".db_escape($updated_on)."                        

            WHERE id=".db_escape($id);

    db_query($sql, "could not update_utility_expense_type");
}

function get_all_utility_expense_types()
{
    $sql = "SELECT *,
                    da.account_name debit_account_name,
                    ca.account_name coc_account_name 
            FROM ".TB_PREF."utility_expense_types uet 
                LEFT JOIN ".TB_PREF."chart_master da ON 
                    uet.debit_account = da.account_code 
                LEFT JOIN ".TB_PREF."chart_master ca ON 
                    uet.coc_account = ca.account_code     
            WHERE 1=1 
            ORDER BY uet.description";	

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

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

	$result = db_query($sql, "could not get_utility_expense_type");

	return db_fetch($result);
}

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

	db_query($sql, "could not delete_utility_expense_type");
}



?>
