<?php
/**********************************************************************
***********************************************************************/
/*
	item_codes table is used to store both multiply foreign codes and 
	sale kits definition.
*/
function update_bank_branch($selected_id, $bank_id, $branch_name, $branch_code, $branch_address)
{
    
    $updated_by = $_SESSION['wa_current_user']->user;
    $updated_on = date('Y-m-d H:i:s');
    
	$sql = "UPDATE ".TB_PREF."bank_branches SET
                    bank_id = ".db_escape($bank_id).",
                    branch_name = ".db_escape($branch_name).",
                    branch_code = ".db_escape($branch_code).",
                    branch_address = ".db_escape($branch_address).",
                    updated_by=".db_escape($updated_by).",
                    updated_on=".db_escape($updated_on)."
        	WHERE id = ".db_escape($selected_id);

	db_query($sql,"Selected bank branch could not be updated");
}
//
function add_bank_branch($bank_id, $branch_name, $branch_code, $branch_address)
{
    
    $created_by = $_SESSION['wa_current_user']->user;
    $created_on = date('Y-m-d H:i:s');
    
	$sql = "INSERT INTO ".TB_PREF."bank_branches
                            (bank_id, branch_name, branch_code, branch_address, created_by, created_on) 
			VALUES( ".db_escape($bank_id).",".db_escape($branch_name).",
                                   ".db_escape($branch_code).",".db_escape($branch_address).","
                                   .db_escape($created_by).", " .db_escape($created_on).")";;

	db_query($sql,"New bank branch could not be added");
}
//
function delete_bank_branch($id)
{
    $sql="DELETE FROM ".TB_PREF."bank_branches WHERE id=".db_escape($id);
    
    db_query($sql,"Bank branch could not be deleted");
}

function get_branches_list($bank_id)
{
	$sql="SELECT bb.*,
                bn.value_name bank_name
            
            FROM ".TB_PREF."bank_branches bb,
                    ".TB_PREF."list_values bn 
            WHERE
                bb.bank_id = bn.id AND
                bank_id=".db_escape($bank_id);

	return db_query($sql,"Bank branches could not be retrieved");
}

function get_branch_details($selected_id)
{

	$sql="SELECT * FROM ".TB_PREF."bank_branches WHERE id=".db_escape($selected_id);

	$result = db_query($sql,"Selected bank branch could not be retrieved");

	return db_fetch($result);
}

function get_existing_bank_branches($bank_id, $branch_code)
{

	$sql="SELECT * FROM ".TB_PREF."bank_branches 
            WHERE bank_id = ".db_escape($bank_id)." AND
                    branch_code = ".db_escape($branch_code)."
                ";

	$result = db_query($sql,"Existing bank branches could not be retrieved");

	return db_fetch($result);
}
?>