<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_VEHICLE_ALLOCATION_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_allocation_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 = "Vehicle Allocations Inquiry"), false, false, "", $js);

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






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



function approvel_status_link($row)
{
    if($row['approval_status'] == AS_APPROVED)
    {
        
        return "Approved";
    }
    if($row['approval_status'] == AS_AWAITING_APPROVAL)
    {
        return "Awaiting Approval";
    }
     if($row['approval_status'] == AS_NEW)
    {
        return "New";
    }
}

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 format_amount($row)
{
    return number_format($row['amount'],2);
}


if (get_post('SearchOrders')) 
{
	$Ajax->activate('orders_tbl');
}
function view_request($row)
{
    if($row['vehicle_request_id'] > 0){
        return get_transport_trans_view_str(ST_VEHICLE_REQUEST, $row['vehicle_request_id']);
    }
    else{
        return null;
    }
}
function view_allocation($row)
{
//	global $trans_type;
	return get_transport_trans_view_str(ST_VEHICLE_ALLOCATION, $row['id']);
}
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);

//end_row();
//end_table();
//
//start_table(TABLESTYLE_NOBORDER);
//start_row();

ref_cells(_("Vehicle Request #:"), 'vehicle_req_no', '',null, '', false);
ref_cells(_("Vehicle Allo. #:"), 'vehicle_all_no', '',null, '', false);
//ref_cells(_("MR Ref"), 'mr_reference', '',null, '', false);

//end_row();
//end_table();
//
start_table(TABLESTYLE_NOBORDER);
start_row();

//stock_items_list_cells(_("Item:"), 'SelectStockFromList', null, true, false);

//yesno_list_cells("Completed :", 'mr_complete');

//value_list_cells(_("Department:"), 'department_id', 'DEPARTMENTS', null,"Select a Department");


project_list_cells("Project :", 'project_id', null, '');
vehicles_list_cells(_("Vehicle:"), 'vehicle_id', null, '');
user_list_cells("Requester", "requester_id", null, '');

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_vehicle_allocation_view(@$_POST['required_by_from'], @$_POST['required_by_to'],
            @$_POST['project_id'], @$_POST['vehicle_all_no'],@$_POST['vehicle_id'],@$_POST['vehicle_req_no'],@$_POST['requester_id']);


	$cols = array(
		_("VA. #")=> array('fun'=>'view_allocation', 'align' => 'center'), 
        _("VR #")=> array('fun'=>'view_request', 'align' => 'center') ,
        _("Project"), 
        _("Vehicle Package"),
        _("Vehicle"),
        _("From Date") => array('fun'=>'convert_from_date', 'align' => 'center'),
        _("To Date") => array('fun'=>'convert_to_date', 'align' => 'center'),
//        _("Amount")=> array('fun'=>'format_amount', 'align' => 'right'), 
		_("Requested By") ,
        _("VA Date") => array('fun'=>'convert_created_date', 'align' => 'center'),
		);

//	array_append($cols, array(
//        array('insert'=>true, 'fun'=>'edit_link'),
//        array('insert'=>true, 'fun'=>'order_link', 'align' => 'center'), 
//		array('insert'=>true, 'fun'=>'dispatch_link', 'align' => 'center'), 
//        array('insert'=>true, 'fun'=>'return_link', 'align' => 'center'), 
//		));


$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();
}
?>
