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

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

//page(_($help_context = "View Inventory Transfer"), true);

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/material_requisitions_db.inc");
include_once($path_to_root . "/inventory/includes/db/issue_materials_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 Requisitions"), true, false, "", $js);


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

$mr_header = get_material_requisition($trans_no);

//$from_trans = $transfer_items[0];
//$to_trans = $transfer_items[1];

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

echo "<br>";
start_table(TABLESTYLE2, "width=90%");

start_row();

label_cells(_("Issuing Location"), $mr_header['issuing_location_name'], "class='tableheader2'");
label_cells(_("Project"), $mr_header['project_description'], "class='tableheader2'");

$pr_limk = "No PR";
if($mr_header['pr_no'] > 0){
    $pr_limk = get_trans_view_str(ST_PURCH_REQ,$mr_header["pr_no"]);
}
label_cells(_("PR No:"), $pr_limk, "class='tableheader2'");

end_row();

start_row();

label_cells(_("Reference"), $mr_header['reference'], "class='tableheader2'");
label_cells(_("Required Date"), sql2date($mr_header['mr_required_date']), "class='tableheader2'");
label_cells(_("Approval Path"), $mr_header['approval_path_description'], "class='tableheader2'");

end_row();

start_row();

if($mr_header['mr_complete'] == 0)
{
    label_cells(_("Requisition Complete"), "No", "class='tableheader2'");
}
else 
{
    label_cells(_("Requisition Complete"), "Yes", "class='tableheader2'");
}
    
label_cells(_("Requestor"), $mr_header['requestor_name'], "class='tableheader2'");
end_row();

start_row();
label_cells(_("Approval Status"), $approval_statuses[$mr_header['approval_status']], "class='tableheader2'");

end_row();

//comments_display_row(ST_LOCTRANSFER, $trans_no);

end_table(2);

start_table(TABLESTYLE, "width=90%");

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

display_heading('Material Requisition Items');
table_header($th);
$mr_lines = get_mr_details($trans_no);
$k = 0;
while ($item = db_fetch($mr_lines))
{
    label_cell($item['stock_id']);
    label_cell($item['description']);
    label_cell($item['requested_qty']);
    label_cell($item['units']);
    label_cell($item['issued_qty']);
    label_cell(sql2date($item['required_date']));
    label_cell($item['line_comment']);
    end_row();;
	
}

end_table(1);


br();

display_heading2('Material Issues');

$im_header_data = get_material_issues_for_mr($trans_no);
if(db_num_rows($im_header_data) > 0){

    

    start_table(TABLESTYLE, "width=80%");

    $th = array(_("MI#"), _("Project"), 
                         _("Issue Location"), _("Issued By"), _("Issued On"));


    table_header($th);
//    $im_header_data = get_material_issue_head_from_mrf($trans_no);
    $k = 0;
    while ($mr_line = db_fetch($im_header_data))
    {
        label_cell(get_trans_view_str(ST_MATERIAL_ISSUE, $mr_line['im_no']));
        label_cell($mr_line['project_description']);
        label_cell($mr_line['issuing_location_name']);
        label_cell($mr_line['created_user_name']);
        label_cell(substr($mr_line['created_on'],0,16), "align=center");
        end_row();
    }
	
    end_table(1);
}
else{
    by();
    display_note("No Material Issues for this requisition.");
}

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

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