<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_BANKTRANSVIEW';
$path_to_root="../..";

include($path_to_root . "/includes/session.inc");

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "View Bank Transfer"), true, false, "", $js);

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/gl/includes/gl_db.inc");
include_once($path_to_root . "/gl/includes/db/batch_bank_transfer_db.inc");

if (isset($_GET["trans_no"])){

	$trans_no = $_GET["trans_no"];
}

$result = get_bank_trans(ST_BANKTRANSFER, $trans_no);

if (db_num_rows($result) != 2)
	display_db_error("Bank transfer does not contain two records");

$trans1 = db_fetch($result);
$trans2 = db_fetch($result);

if ($trans1["amount"] < 0) 
{
    $from_trans = $trans1; // from trans is the negative one
    $to_trans = $trans2;
} 
else 
{
	$from_trans = $trans2;
	$to_trans = $trans1;
}

$company_currency = get_company_currency();

$show_currencies = false;
$show_both_amounts = false;

if (($from_trans['bank_curr_code'] != $company_currency) || ($to_trans['bank_curr_code'] != $company_currency))
	$show_currencies = true;

if ($from_trans['bank_curr_code'] != $to_trans['bank_curr_code']) 
{
	$show_currencies = true;
	$show_both_amounts = true;
}

display_heading($systypes_array[ST_BANKTRANSFER] . " #$trans_no");

echo "<br>";
start_table(TABLESTYLE, "width=40%");
label_row(_("Reference"), $from_trans['ref'], "class='tableheader2'");
label_row(_("Date"), sql2date($from_trans['trans_date']), "class='tableheader2'");

label_row(_("From Bank Account"), $from_trans['bank_account_name'], "class='tableheader2'");
if ($show_currencies)
	label_row(_("Currency"), $from_trans['bank_curr_code'], "class='tableheader2'");
label_row(_("Amount"), number_format2(-$from_trans['amount'], user_price_dec()), "class='tableheader2'", "align=right");
	
label_row(_("To Bank Account"), $to_trans['bank_account_name'], "class='tableheader2'");
if ($show_currencies)
	label_row(_("Currency"), $to_trans['bank_curr_code'], "class='tableheader2'");
if ($show_both_amounts)
	label_row(_("Amount"), number_format2($to_trans['amount'], user_price_dec()), "class='tableheader2'", "align=right");


label_row(_("Transfer Type"), $bank_transfer_types[$from_trans['account_type']],
	 "class='tableheader2'");

$batch = get_batch_bank_transfer_record_by_fund_transfer_no($trans_no);
if(is_array($batch)){
    $bbtr_link = get_banking_trans_view_str(ST_BATCH_BANK_TRANSFER_REQ, $batch["trans_no"]);
    label_row(_($systypes_array[ST_BATCH_BANK_TRANSFER_REQ]." #"), $bbtr_link, "class='tableheader2'");
}

comments_display_row(ST_BANKTRANSFER, $trans_no);

end_table(1);

is_voided_display(ST_BANKTRANSFER, $trans_no, _("This transfer has been voided."));

end_page(true, false, false, ST_BANKTRANSFER, $trans_no);
?>