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

include($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/inventory/includes/db/site_material_returns_inquiry_db.inc");
include_once($path_to_root . "/includes/common_functions.inc");
include_once($path_to_root . "/includes/db/group_companies_db.inc");

page(_($help_context = "View Site Material Return"), true);

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

global $approval_statuses;

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

br(1);
$adjustment_items = view_site_material_returns($trans_no);
$k = 0;
$header_shown = false;
$total = 0;
    while($adjustment = db_fetch($adjustment_items)){
	if(!$header_shown){
            start_table(TABLESTYLE2, "width=80%");
                start_row();
                    label_cells(_("Reference:"), $adjustment['reference'], "class='tableheader2'", "colspan=");
                    label_cells(_("From Project:"), $adjustment['from_project_description'], "class='tableheader2'");
                    label_cells(_("Company:"), $adjustment['company_name'], "class='tableheader2'");
                end_row();
                
                start_row();
                    label_cells(_("To Location:"), $adjustment['to_location_name'], "class='tableheader2'");
                    label_cells(_("To Project:"), $adjustment['to_project_description'], "class='tableheader2'");
                    label_cells(_("Employee:"), get_group_company_employee_formatted_long_name($adjustment['company_code'], $adjustment['employee_code']), 
                                "class='tableheader2'", "colspan=3");
                end_row();
                
                start_row();
                    label_cells(_("Date:"), sql2date($adjustment['tran_date']), "class='tableheader2'");
                    label_cells(_("Status:"), $approval_statuses[$adjustment['status']], "class='tableheader2'");
                    
                start_row();
                    label_cells(_("Comment:"), $adjustment['comments'], "class='tableheader2'", "colspan=6");
                end_row();

            end_table();
            $header_shown = true;

            br(2);
            display_heading($systypes_array[ST_SITE_MATERIAL_RETURN]." Details");
            br();
            start_table(TABLESTYLE, "width=90%");
                $th = array(_("Id"), _("Item"), _("Item Description"), _("Units"), _("Quantity"), _("Unit Cost"), _("From Budget"), _("To Budget"), _("From Site"), 
                            _("To Site"), _("Total"));
                table_header($th);
	}
        
        $total += ($adjustment['tran_unit_cost'] * $adjustment['tran_qty']);
        alt_table_row_color($k);
            label_cell($adjustment['id'], "align_center");
            label_cell($adjustment['stock_id']);
            label_cell($adjustment['item_description']);
            label_cell($adjustment['tran_unit']);
            qty_cell($adjustment['tran_qty'], false, 2);
            amount_cell($adjustment['standard_cost']);
            label_cell($adjustment['from_task_description']);
            label_cell($adjustment['to_task_description']);
            label_cell($adjustment['from_project_site_description']);
            label_cell($adjustment['to_project_site_description']);
            amount_decimal_cell($adjustment['line_total']);  
        end_row();
    }
    
    start_row();
        label_row(_("Total:"), number_format2($total,user_price_dec()), "align=right colspan=10", "align=right");
    end_row();

end_table(1);

is_voided_display(ST_SITE_MATERIAL_RETURN, $trans_no, _("This site material return has been voided."));

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

?>