<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_VEHICLE_REQUEST_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 . "/sales/includes/sales_ui.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include_once($path_to_root . "/transport/includes/db/vehicle_requests_db.inc");
//include_once($path_to_root . "/includes/ui/ui_view.inc");
include_once($path_to_root . "/transport/includes/db/vehicle_request_inquiry_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 = "Approve Vehicle Requests Inquiry"), false, false, "", $js);

if (isset($_GET['Approves']))
{
	$_SESSION['current_user_for_mr'] = $_SESSION['wa_current_user']->user;
}

//if (isset($_GET['selected_customer']))
//{
//	$selected_customer = $_GET['selected_customer'];
//}
//elseif (isset($_POST['selected_customer']))
//{
//	$selected_customer = $_POST['selected_customer'];
//}
//else
//	$selected_customer = -1;

//---------------------------------------------------------------------------------------------
//
//if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
//	($_POST['SelectStockFromList'] != ALL_TEXT))
//{
// 	$selected_stock_item = $_POST['SelectStockFromList'];
//}
//else
//{
//	unset($selected_stock_item);
//}
//---------------------------------------------------------------------------------------------
//	Query format functions
//
//function check_overdue($row)
//{
//	global $trans_type;
//	if ($trans_type == ST_SALESQUOTE)
//		return (date1_greater_date2(Today(), sql2date($row['delivery_date'])));
////	else
////		return (date1_greater_date2(Today(), sql2date($row['mtr_required_date'])));
//}

function view_link($row)
{
//	global $trans_type;
	return get_trans_view_str(ST_VEHICLE_REQUEST, $row['id']);
}

//function prt_link($row)
//{
//	global $trans_type;
//	return print_document_link($row['order_no'], _("Print"), true, $trans_type, ICON_PRINT);
//}

//function edit_link($row) 
//{
//    if (@$_GET['popup'])
//            return '';
//    global $trans_type;
//    $modify = "ModifyMRNumber";
//    if($row['approval_status'] == AS_NEW || $row['approval_status'] == AS_WITH_THE_APPROVER || $row['approval_status'] == AS_AWAITING_APPROVAL)
//    {
//        return pager_link( _("Edit"), "/inventory/material_requisitions.php?$modify=" . $row['mr_no'], ICON_EDIT);
//    }
//    else
//    {
//        return null;
//    }
//    
//}





function status_name($row)
{
	global $approval_statuses;
    
    return $approval_statuses[$row["approval_status"]];
}



function approvel_status_link($row)
{
    if($row['closed'] == 1){
        return "Closed";
    }
    else{
        global $document_approval_statuses;
        return $document_approval_statuses[$row['approval_status']];
    }

}
function convert_from_date($row)
{

        return substr($row['from_date_time'], 0, 16);

    
}
function convert_created_date($row)
{
  return sql2date($row['to_date_time']);
}

function convert_to_date($row)
{
  return substr($row['to_date_time'], 0, 16);
}

function edit_link($row) 
{

    if($row['closed'] == 1){
        return null;
    }
    
    $modify = "ModifyVRNumber";
    if($row['approval_status'] == AS_NEW || $row['approval_status'] == AS_WITH_THE_APPROVER || $row['approval_status'] == AS_AWAITING_APPROVAL)
    {
        return pager_link( _("Edit"), "/transport/vehicle_requests.php?$modify=" . $row['id'], ICON_EDIT);
    }
    else
    {
        return null;
    }
    
}


if (get_post('SearchOrders')) 
{
	$Ajax->activate('orders_tbl');
}


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

//start_table(TABLESTYLE_NOBORDER);
//start_row();
//
//date_cells(_("Required By From:"), 'required_by_from', '', null, -15);
//date_cells(_("Required By To:"), 'required_by_to', '', null, +15);
//ref_cells(_("Vehicle Request #:"), 'vehicle_req_no', '',null, '', false);
//start_table(TABLESTYLE_NOBORDER);
//start_row();
//
////stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true, false);
//
////yesno_list_cells("Completed :", 'mr_complete');
//project_list_cells("Project :", 'project_id', null, '');
//vehicle_packages_list_cells("Package", 'package_id', null, '');
//user_list_cells("Requester", "requester_id", null, '');
////value_list_cells(_("Status:"), 'status', 'STATUS', null, null, "Select Status");
//
//
//
//submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
////hidden('order_view_mode', $_POST['order_view_mode']);
////hidden('type', $trans_type);
//
//end_row();
//
//end_table(1);
//---------------------------------------------------------------------------------------------
//	Orders inquiry table
//
$sql = get_sql_for_approve_vehicle_requests($_SESSION['wa_current_user']->user);


	$cols = array(
		_("VR #")=> array('fun'=>'view_link', 'align' => 'center') , 
//		_("Department"),
		_("Project"), 
                _("Vehicle Type"),
                _("Package"),
                _("Vehicle"),
                _("From") => array('fun'=>'convert_from_date', 'align' => 'center'),
                _("To") => array('fun'=>'convert_to_date', 'align' => 'center'),    
                _("Requestor") ,
                _("VR Date") => array('fun'=>'convert_created_date', 'align' => 'center'),
                _("Status")=>array('fun'=>'approvel_status_link','align' => 'center'),
                        );
    
    array_append($cols, array(
        array('insert'=>true, 'fun'=>'edit_link'), 
		));


$table =& new_db_pager('orders_tbl', $sql, $cols);
//$table->set_marker('check_overdue', _("Marked items are overdue."));

$table->width = "90%";

display_db_pager($table);
submit_center('Update', _("Update"), true, '', null);

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