<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_SUPPTRANSVIEW';
$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 . "/purchasing/includes/db/purchase_indents_db.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'] != "")
{
	$indent_id = $_GET['trans_no'];
}



function display_row($name, $value)
{
    start_row();        
    label_cells($name, $value, "width=70px class='tableheader2'", "width=60px");
    end_row();
    
}
br(2);

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

display_heading('Purchase Indent Header');


//table_header($th);

    $myrow = view_purch_indent_header($indent_id);
     if($myrow["supplier_id"] !='')
    {
       $supplier = $myrow["supp_name"]; 
       $address = $myrow["supp_address"]; 
    }
    else
    {
       $supplier = $myrow["new_supplier_name"];  
       $address = $myrow["new_supp_address"]; 
        
    }
    if($myrow["location"] !='')
    {
        $location = $myrow["location_name"];
    }
    else
    {
        $location = $myrow["new_location_address"];
    }
    display_row("Indent No:",$myrow["indent_id"]);
    //display_row("Order No:",get_trans_view_str(ST_MANUF_REQUEST,$myrow["id"]));
    display_row("Supplier :",$supplier);
    display_row("Supplier Address",$address);
    display_row("Location",$location);
    display_row("Required Date",sql2date($myrow["required_date"]),2);
    
       
   
 

end_row();

end_table(1);

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

global $systypes_array;



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

display_heading('Purchase Indents');

$th = array("PR No", _("Location"),_("Item Code"),_("Item Description"), _("Unit"), _("Quantity"));
table_header($th);
$k = 0;
$supplier = '';
$address = '';
$location = '';
$order_type_name="";
$data = view_purchase_indent($indent_id);
while($pi_lines=db_fetch($data))
{

//    if($pi_lines["supplier_id"] !='')
//    {
//       $supplier = $pi_lines["supp_name"]; 
//       $address = $pi_lines["supp_address"]; 
//    }
//    else
//    {
//       $supplier = $pi_lines["new_supplier_name"];  
//       $address = $pi_lines["new_supp_address"]; 
//        
//    }
    if($pi_lines["location"] !='')
    {
        $location = $pi_lines["location_name"];
    }
    else
    {
        $location = $pi_lines["new_location_address"];
    }
//    label_cell($supplier,"align=left");
    
    label_cell(get_supplier_trans_view_str(ST_PURCH_REQ, $pi_lines["requisition_id"], $pi_lines["requisition_id"]),"align=left");
    label_cell($location,"align=left");
    label_cell($pi_lines["item_code"],"align=left");
        
	$transaction_saved_description = $pi_lines["indent_item_description"];
    if(!(strlen($transaction_saved_description) > 0)){
        $transaction_saved_description = $pi_lines["item_pr_description"];
    }    
    $item_formatted_name = get_stock_item_formatted_name($pi_lines["item_code"], $pi_lines["editable"], $pi_lines["stock_item_description"], $transaction_saved_description);
    label_cell($item_formatted_name,"align=left");
	
    label_cell($pi_lines["tran_unit"],"align=left");
    amount_cell($pi_lines["qty"],"align=right");
//    label_cell(get_trans_view_str(ST_PURCH_REQ,$mr_req["pr_no"]), "align=center");

    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);

?>
