<?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 . "/gl/includes/gl_db.inc");
include_once($path_to_root . "/inventory/includes/db/stock_reservations_db.inc");

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
if (user_use_date_picker())
	$js .= get_js_date_picker();
page(_($help_context = "View Material Reservations"), true, false, "", $js);


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

$sr_header = get_stock_reservation($trans_no);

display_heading('Material Reservations' . " #$trans_no");

echo "<br>";
    start_outer_table(TABLESTYLE2, "width=60%");
    
        table_section(1, '40%');

            label_row(_("Location:"), $sr_header['location_name'], "class='tableheader2'");
            label_row(_("Project:"), $sr_header['project_description'], "class='tableheader2'");
            label_row(_("Requestor:"), $sr_header['requestor_name'], "class='tableheader2'");
            label_row(_("Reference:"), $sr_header['reference'], "class='tableheader2'");

        table_section(2, '60%');
            label_row(_("Date:"), sql2date($sr_header['sr_date']), "class='tableheader2'");
            if($sr_header['sr_complete'] == 0)
            {
                label_row(_("Requisition Complete:"), "No", "class='tableheader2'");
            }
            else 
            {
                label_row(_("Requisition Complete:"), "Yes", "class='tableheader2'");
            }

            global $inventory_movement_type_linked_fields;
            label_row(_("Movement Type:"), $sr_header['movement_type_name'], "class='tableheader2'");

            if ($sr_header['linked_field_type'] != IMLF_NOT_LINKED) {
                $link_field = get_movement_type_linked_field_values($sr_header['linked_field_type'], $sr_header['linked_field_id']);
                label_row(_($inventory_movement_type_linked_fields[$sr_header['linked_field_type']].":"), $link_field['value'], "class='tableheader2'");
            }

    end_outer_table(2);
    
    if (strlen($sr_header['comments']) > 0) {
        start_table(TABLESTYLE);
            label_row('Comment:', nl2br($sr_header['comments']), "class='tableheader2'");
        end_table(3);
    }
    
    
start_table(TABLESTYLE, "width=75%");

    $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"),  _("Required Date"), _("Comment"));

    display_heading('Material Reservation Items');
    table_header($th);
        $mr_lines = get_stock_reservation_details($trans_no);
            $k = 0;
            while ($item = db_fetch($mr_lines)) {
                alt_table_row_color($k);
                    label_cell($item['stock_id']);
                    label_cell($item['description']);
                    label_cell(number_format($item['reserved_unit_qty'], 2), "align=right");
                    label_cell($item['reserved_unit']);
                    label_cell(sql2date($item['releasing_date']));
                    label_cell($item['line_comment']);
                end_row();
            }

    end_table(3);

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

?>