<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_MANUF_REQUESTS_INQ';
$path_to_root="../..";
include_once($path_to_root . "/includes/db_pager.inc");
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui/ui_input.inc");
include_once($path_to_root . "/includes/ui/ui_lists.inc");
include_once($path_to_root . "/includes/ui/ui_lists_custom.inc");
include_once($path_to_root . "/manufacturing/includes/db/manufacturing_requirements_db.inc");

include_once($path_to_root . "/reporting/includes/reporting.inc");
if (!@$_GET['popup'])
{
	$js = "";
	if ($SysPrefs->use_popup_windows)
		$js .= get_js_open_window(900, 500);
	if (user_use_date_picker())
		$js .= get_js_date_picker();
	page(_($help_context = "Manufacturing Request Inquiry"), false, false, "", $js);
}
//-----------------------------------------------------------------------------------
// Ajax updates
//
if (get_post('SearchOrders')) 
{
	$Ajax->activate('orders_tbl');
} 
//---------------------------------------------------------------------------------------------

if (!@$_GET['popup'])
	start_form();

//start_table(TABLESTYLE_NOBORDER);
//    start_row();
//    emoplyees_list_cells(_(" Employee:"), 'employee_code', null, "", false, check_value('show_inactive'));
//    end_row();
//end_table(1);

//start_table(TABLESTYLE_NOBORDER);
//    start_row();
//    text_cells(_("Employee Code:"), 'employee_code');
//    text_cells(_("Full Name:"), 'middle_name');
//    text_cells(_("Calling Name:"), 'first_name');
//
//    end_row();
//end_table(1);
//
//start_table(TABLESTYLE_NOBORDER);
//    start_row();
//    text_cells(_("NIC No:"), 'nic');
//    text_cells(_("EPF No:"), 'epf_no');
//    submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
//    end_row();
//end_table(1);

//---------------------------------------------------------------------------------------------
function format_qty_ordered($row)
{
    if($row['tran_unit_qty_ordered'] > 0){
        return number_format2($row['tran_unit_qty_ordered'], 2);
    }
    else{
        return "";
    }
}


function format_qty($row)
{
    return number_format2($row['tran_qty'], 2);
}

function edit_link($row) 
{
    if($row['tran_unit_qty_ordered'] >=  $row['tran_qty']){
        return null;
    }
    elseif($row['line_complete'] == 1){
        return null;
    }
    else{
        $modify = "ModifyMRNumber";
        return pager_link( _("Edit"), "/manufacturing/manufacturing_requests.php?$modify=" . $row['id'], ICON_EDIT);
    }

}

function view_link($row)
{
	return get_trans_view_str(ST_MANUF_REQUEST, $row['id']);
}


//---------------------------------------------------------------------------------------------

//
//$employee_code = "";
//if(isset($_POST['employee_code'])){
//    $employee_code = $_POST['employee_code'];
//}
//$first_name = "";
//if(isset($_POST['first_name'])){
//    $first_name = $_POST['first_name'];
//}
//$middle_name = "";
//if(isset($_POST['middle_name'])){
//    $middle_name = $_POST['middle_name'];
//}
//$epf_no = "";
//if(isset($_POST['epf_no'])){
//    $epf_no = $_POST['epf_no'];
//}
//$nic = "";
//if(isset($_POST['nic'])){
//    $nic = $_POST['nic'];
//}


$sql = get_sql_for_manufacturing_requests_inquiry();

$cols = array(
	_("M.No.")=> array('fun'=>'view_link') ,
	_("Project"), 
        _("Task"),
        _("Location"),
        _("Item"), 
        _("Unit") , 
        _("Quantity")=> array('fun'=>'format_qty', 'align'=>'right') , 
        _("Qty. Ordered")=> array('fun'=>'format_qty_ordered', 'align'=>'right') , 
        _("Required Date"), 
        );

array_append($cols, array(
		array('insert'=>true, 'fun'=>'edit_link'))); 
        
                    



//if (get_post('StockLocation') != $all_items) {
//	$cols[_("Location")] = 'skip';
//}
////---------------------------------------------------------------------------------------------------

$table =& new_db_pager('orders_tbl', $sql, $cols);

$table->width = "90%";

display_db_pager($table);

br();

if (!@$_GET['popup'])
{
	end_form();
	end_page();
}	
?>
