<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_OUTSIDE_MATERIAL_RECEIPT';

if (!@$_GET['popup'])
	$path_to_root = "../..";
else	
	$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.inc");
include_once($path_to_root . "/inventory/includes/db/outside_material_receipts_db.inc"); 

$js = '';
$js .= get_js_open_window(900, 500);
$js .= get_js_date_picker();

page($help_context = 'Approve '.$systypes_array[ST_OUTSIDE_MATERIAL_RECEIPT], false, false, "", $js);

function _trans_no($row){ 
    return get_inventory_trans_view_str($row['type'], $row['trans_no']);
}

function _req_trans_no($row){ 
    return get_inventory_trans_view_str($row['req_type'], $row['req_trans_no']);
}

function _jo_id($row){ 
    $jo_id = $row['jo_id'];
    if ($jo_id > 0) {
        return get_service_trans_view_str(ST_JOB_ORDER, $jo_id);
    } else {
        return;
    }
}

function _reference($row){
    return $row['reference'];
}

function _from_location($row){
    return $row['from_location'];
}

function _to_location($row){
    return $row['to_location_name'];
}

function _project_name($row){
    return $row['project_description'];
}

function _tran_date($row){
    return sql2date($row['tran_date']);
}

function _created_by($row){
    return $row['real_name'];
}

function _created_on($row){
    return $row['created_on'];
}

function _approval_status($row){
    global $approval_statuses;
    return $approval_statuses[$row['approval_status']];
}

function _edit_link($row){
    $name_value = "omrc_no=".$row['id'];
    return pager_link( _("Edit"), "/inventory/outside_material_receipts.php?$name_value", ICON_EDIT);
}

start_form();

    $sql = get_sql_for_approve_outside_material_receipts($_SESSION['wa_current_user']->user, ST_OUTSIDE_MATERIAL_RECEIPT);    
    
        $cols = array(  _("Trans #") => array('fun'=>'_trans_no', 'align'=>'center'), 
                        _("Req. Trans #") => array('fun'=>'_req_trans_no', 'align'=>'center'),
                        _("Job Card #") => array('fun'=>'_jo_id', 'align'=>'center'),
                        _("Ref") => array('fun'=>'_reference', 'align'=>'left'), 
                        _("Date") => array('fun'=>'_tran_date', 'align'=>'center'),
                        _("From Location") => array('fun'=>'_from_location'), 
                        _("To Location") => array('fun'=>'_to_location'), 
                        _("Project") => array('fun'=>'_project_name'),      
                        _("Created By") => array('fun'=>'_created_by', 'align'=>'left'),
                        _("Created On") => array('fun'=>'_created_on', 'align'=>'center'),
                        _("Approval Status") => array('fun'=>'_approval_status', 'align'=>'center'), 
                    );
    
        array_append($cols, array(array('insert'=>true, 'fun'=>'_edit_link', 'align'=>'center')));

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

    $table->width = "90%";

    display_db_pager($table);

end_form(2);
end_page();

?>