<?php
/**********************************************************************
	Copyright (C) Evolve Techniologies
	Author : Evolve Technologies
	Email : info@evolve-sl.com
	Company : Evolve Technologies(pvt)Ltd
***********************************************************************/
//---------------------------------------------------------------------------------------------

function add_cheque_book($bank_id, $cheque_book_no, $bank_code, $branch_code, $starting_no, $ending_no, $user)
{

	$sql = "INSERT INTO ".TB_PREF."cheque_books (bank_id, cheqeu_book_no, branch_code, bank_code, chque_start_no, chque_end_no, added_date,next_no_payment, `user`)
		VALUES (".db_escape($bank_id).", ".db_escape($cheque_book_no).", ".db_escape($branch_code).", ".db_escape($bank_code).", ".db_escape($starting_no).", ".db_escape($ending_no).",NOW(), ".db_escape($starting_no).", ".db_escape($user).")";//-----@widanage add new field for bank short code----10.04.2013------

	db_query($sql, "could not add a Cheque book for this bank");
}


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

function update_cheque_book($id, $bank_id, $cheque_book_no, $bank_code, $branch_code, $starting_no, $ending_no, $user)
{
	$sql = "UPDATE ".TB_PREF."cheque_books SET bank_id = ".db_escape($bank_id).", cheqeu_book_no = ".db_escape($cheque_book_no).", branch_code = ".db_escape($branch_code).", bank_code = ".db_escape($bank_code).", chque_start_no = ".db_escape($starting_no).", chque_end_no = ".db_escape($ending_no).",next_no_payment=".db_escape($starting_no).", `user` = ".db_escape($user).", version = version+1, added_date = NOW() WHERE id = ".db_escape($id);
	

	db_query($sql, "could not update Cheque Book Details");
}

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

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

	db_query($sql,"could not delete bank account for $id");
}


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

function get_cheque_book($id)
{
	$sql = "SELECT * FROM ".TB_PREF."cheque_books WHERE id=".db_escape($id);

	$result = db_query($sql, "could not retreive Cheque Book details for $id");

	return db_fetch($result);
}

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

function get_cheque_books($show_inactive=false)
{
	
	$sql = "SELECT cb.*, ba.bank_account_name FROM  ".TB_PREF."cheque_books AS cb, ".TB_PREF."bank_accounts AS ba 
			WHERE cb.bank_id = ba.id";
	if (!$show_inactive) 
		$sql .= " AND !cb.inactive";
	$sql .= " ORDER BY cb.bank_id";

	return db_query($sql,"could not get Cheque book Details");
}


