<?php 
// ALTER TABLE `0_cancel_cheque` ADD `user_id` INT NOT NULL AFTER `cheque_no`, ADD `currentdate` DATE NOT NULL DEFAULT '0000-00-00' AFTER `user_id`;

function cancel_cheque($account_type_id, $bank_account_id, $cheque_no)
{
	// display_error($cheque_no);
	$user_id = $_SESSION["wa_current_user"]->user;
	$currentdate = date2sql(Today());
	$sql = "INSERT INTO ".TB_PREF."cancel_cheque (account_type_id, bank_account_id, cheque_no, user_id, currentdate) VALUES (".db_escape($account_type_id) . ", ".db_escape($bank_account_id) . ", ".db_escape($cheque_no) . ", ".db_escape($user_id) . ", ".db_escape($currentdate) . ")";
   	db_query($sql,"The brand could not be added");
}

function update_cheque($selected_id, $account_type_id, $bank_account_id, $cheque_no)
{
	$sql = "UPDATE ".TB_PREF."cancel_cheque SET account_type_id=".db_escape($account_type_id).",
	bank_account_id=".db_escape($bank_account_id).",
	cheque_no=".db_escape($cheque_no).",
	WHERE id = ".db_escape($selected_id);
   	db_query($sql,"The cheque no could not be updated");
}

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

function get_cheque_num($show_inactive,$bank_id=0)
{
	$sql = "SELECT * FROM ".TB_PREF."cancel_cheque";
	if (!$show_inactive) $sql .= " WHERE !inactive";
	if ($bank_id) 
	$sql .= " AND bank_account_id=".db_escape($bank_id);
	$sql .= " ORDER BY cheque_no";
	return db_query($sql,"could not brand");
}

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

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

function check_cancel_cheque_no($bank_id, $cheque_no)
{
	// display_error($bank_id.'=='. $cheque_no);
	$sql = "SELECT * FROM ".TB_PREF."cancel_cheque WHERE bank_account_id=".db_escape($bank_id);
	$sql .= " AND cheque_no=".db_escape($cheque_no);
	// display_error($sql);
	$result = db_query($sql,"could not brand");
	return db_fetch($result);

	// return $result;
}

// function get_brand_name($id)
// {
// 	$sql = "SELECT brand FROM ".TB_PREF."brand WHERE id = ".db_escape($id);
// 	$result = db_query($sql, "could not brand");
// 	$row = db_fetch($result);
// 	return is_array($row) ? $row[0] : false;
// }

// function duplicate_item_brand($brand)
// {
// 	$sql = "SELECT brand FROM ".TB_PREF."brand WHERE brand = ".db_escape(trim($brand));
// 	$result = db_query($sql, "could not duplicate brand");
// 	$data = db_num_rows($result);
// 	return $data;
// }


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


// function add_item_brand($stock_id, $brand_id)
// {
// 	$sql = "INSERT INTO ".TB_PREF."item_brands (stock_id, brand_id) VALUES (".db_escape($stock_id) .", ".db_escape($brand_id) . ")";
//    	db_query($sql,"The brand could not be added");
// }

// function update_item_brand($selected_id, $brand_id)
// {
// 	$sql = "UPDATE ".TB_PREF."item_brands SET brand_id=".db_escape($brand_id)." WHERE id = ".db_escape($selected_id);
//    	db_query($sql,"The brand could not be updated");
// }

// function delete_item_brand($selected_id)
// {
// 	$sql="DELETE FROM ".TB_PREF."item_brands WHERE id=".db_escape($selected_id);
// 	db_query($sql,"could not delete brand");
// }

// function get_item_brands($show_inactive, $stock_id)
// { 
// 	$sql = "SELECT * FROM ".TB_PREF."item_brands as item";
// 	if (!$show_inactive) $sql .= " WHERE !inactive";
// 	if ($stock_id) {
// 		$sql .= " AND item.stock_id = ".db_escape($stock_id);
// 	}
// 	$sql .= " ORDER BY brand_id";
// 	// display_error($sql);
// 	return db_query($sql,"could not brand");
// }

// function get_item_brand($selected_id)
// {
// 	$sql = "SELECT * FROM ".TB_PREF."item_brands WHERE id=".db_escape($selected_id);

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

// function get_item_brand_name($id)
// {
// 	$sql = "SELECT brand_id FROM ".TB_PREF."item_brands WHERE id = ".db_escape($id);
// 	$result = db_query($sql, "could not brand");
// 	$row = db_fetch($result);
// 	return is_array($row) ? $row[0] : false;
// }


?>