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

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

include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/inventory.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
include_once($path_to_root . "/manufacturing/includes/db/manufacturing_requirements_db.inc");
include_once($path_to_root . "/manufacturing/includes/manufacturing_ui.inc");
$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "View Manufacturing Requirement"), true, false, "", $js);

//-------------------------------------------------------------------------------------------------
$woid = 0;
if ($_GET['trans_no'] != "")
{
	$manuf_reqr_id = $_GET['trans_no'];
}
function display_row($name, $value)
{
    start_row();        
    label_cells($name, $value, "width=70px class='tableheader2'", "width=60px");
    end_row();
    
}
global $systypes_array;
$source_type = substr( $manuf_reqr_id, 0, strrpos( $manuf_reqr_id, '-' ) );
$order_no= substr($manuf_reqr_id,strrpos( $manuf_reqr_id, '-' )+1);
display_heading('Manufacturing Order Breakup');
    
    

br(2);

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

display_heading('Ordering Source'." - ".$systypes_array[$source_type]);


//table_header($th);
if($source_type==ST_MANUF_REQUEST){
    
    $myrow = view_manuf_request($order_no);
    display_row("Id:",$myrow["id"]);
    display_row("Order No:",get_trans_view_str(ST_MANUF_REQUEST,$myrow["id"]));
    display_row("Project :",$myrow["project"]);
    display_row("Task",$myrow["task"]);
    display_row("Item code",$myrow["stock_id"]);
    display_row("Item Description",$myrow["stock_item"]);
    display_row("Required Qty",$myrow["tran_qty"]);
    display_row("Unit",$myrow["unit_name"]);
    display_row("Required Date",sql2date($myrow["req_date"]));
       
}
else{
    $myrow = view_sales_order($order_no,$source_type);
    display_row("Id:",$myrow["id"]);
    display_row("Order No:",get_trans_view_str(ST_SALESORDER,$myrow["order_no"]));
    display_row("Project :",$myrow["project"]);    
    display_row("Item code",$myrow["stock_id"]);
    display_row("Item Description",$myrow["stock_item"]);
    display_row("Required Qty",$myrow["tran_qty"]);
    display_row("Unit",$myrow["unit_name"]);
    display_row("Required Date",sql2date($myrow["req_date"]));
 
   
}
   
 

end_row();

end_table(1);

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

display_heading('Manufacturing Requirement Details');

$th = array(_("Id"),_("Order Type"), _("Unit"), _("Qty"), _("Complete Before"), _("Location"));
table_header($th);
$k = 0;

$order_type_name="";
$data = view_manuf_requirement_by_order_no($order_no,$source_type,$order_no);
while($mr_req=db_fetch($data))
{
label_cell($mr_req["mr_id"]);
 if($mr_req["order_type"] == ST_WORKORDER){
        $order_type_name = "Work Order";
    }
    elseif($mr_req["order_type"] == ST_PURCH_REQ){
        $order_type_name = "Purchase Requisition";
    }
label_cell($order_type_name);
label_cell($mr_req["manufacturing_unit"]);
label_cell($mr_req["manufacturing_unit_qty"]);
label_cell(sql2date($mr_req["required_by"]));
label_cell($mr_req["location"]);
end_row();

$k++;
}

end_row();

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

end_page(true, false, false, ST_WORKORDER, $woid);

?>
