<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = 'SA_SUPPTRANSVIEW';
$path_to_root = "../..";

include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
include_once($path_to_root . "/includes/ui/items_cart.inc");
include_once($path_to_root . "/includes/session.inc");

include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(900, 500);
page(_($help_context = "View Supplier Invoice"), true, false, "", $js);

if (isset($_GET["trans_no"]))
{
	$trans_no = $_GET["trans_no"];
} 
elseif (isset($_POST["trans_no"]))
{
	$trans_no = $_POST["trans_no"];
}

$supp_trans = new supp_trans(ST_SUPPINVOICE);

read_supp_invoice($trans_no, ST_SUPPINVOICE, $supp_trans);

$supplier_curr_code = get_supplier_currency($supp_trans->supplier_id);

display_heading(_("SUPPLIER INVOICE") . " # " . $trans_no);
echo "<br>";

start_table(TABLESTYLE, "width='95%'");
start_row();
label_cells(_("Supplier"), $supp_trans->supplier_name, "class='tableheader2'");
label_cells(_("Reference"), $supp_trans->reference, "class='tableheader2'");
label_cells(_("Supplier's Reference"), $supp_trans->supp_reference, "class='tableheader2'");
end_row();
start_row();
label_cells(_("Invoice Date"), $supp_trans->tran_date, "class='tableheader2'");
label_cells(_("Due Date"), $supp_trans->due_date, "class='tableheader2'");
label_cells(_("File System"), get_file_system_name($supp_trans->file_system), "class='tableheader2'");

if($supp_trans->service_order_no)
label_cells(_("View Brokery"), get_trans_view_str(ST_SUPPINVOICE,$supp_trans->service_order_no), "class='tableheader2'");

if($supp_trans->sales_invoice_no)
label_cells(_("Sales Invoice # "), get_trans_view_str(ST_SALESINVOICE,$supp_trans->sales_invoice_no), "class='tableheader2'");
if (!is_company_currency($supplier_curr_code))
	label_cells(_("Currency"), $supplier_curr_code, "class='tableheader2'");
end_row();
comments_display_row(ST_SUPPINVOICE, $trans_no);

end_table(1);
$kv_batch = get_company_pref('kv_batch');
$kv_exp_date = get_company_pref('kv_exp_date');

// $total_gl = display_gl_items($supp_trans, 2);
$total_grn = display_grn_items($supp_trans, 2, $kv_batch, $kv_exp_date);

$display_sub_tot = number_format2($total_gl+$total_grn,user_price_dec());

start_table(TABLESTYLE, "width='95%'");
foreach ($supp_trans->gl_codes as $entered_gl_code)
{
	label_row($entered_gl_code->gl_act_name, $entered_gl_code->amount, "align=right", "nowrap align=right width='15%'");
}
label_row(_("Sub Total"), $display_sub_tot, "align=right", "nowrap align=right width='15%'");


$tax_items = get_trans_tax_details(ST_SUPPINVOICE, $trans_no);
display_supp_trans_tax_details($tax_items, 1);

$display_total = number_format2($supp_trans->ov_amount + $supp_trans->ov_gst,user_price_dec());

label_row(_("TOTAL INVOICE").' ('.$supplier_curr_code.')', $display_total, "colspan=1 align=right", "nowrap align=right");

end_table(1);

$voided = is_voided_display(ST_SUPPINVOICE, $trans_no, _("This invoice has been voided."));

if (!$voided) 
{
	display_allocations_to(PT_SUPPLIER, $supp_trans->supplier_id, ST_SUPPINVOICE, $trans_no, 
		($supp_trans->ov_amount + $supp_trans->ov_gst));
}

display_heading2(_("User Details"));
 $user_row = get_audit_trail_last_data(ST_SUPPINVOICE, $trans_no);
start_table(TABLESTYLE2, "width='40%'");
label_row(_("user Created By "), $user_row['user_id'] );
end_table();

end_page(true, false, false, ST_SUPPINVOICE, $trans_no);

