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

$page_security = 'SA_ASSET_TRANSFER_REQUEST_INQ';
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 . "/assets/includes/db/asset_transfer_requests_inquiry_db.inc");

$js = '';

if ($SysPrefs->use_popup_windows) {
    $js .= get_js_open_window(1000, 500);
}
if (user_use_date_picker()) {
    $js .= get_js_date_picker();
}

page($help_context = "Outstanding Asset Transfer Requests Inquiry", false, false, "", $js);

simple_page_mode(true);

global $Ajax;

function _id($row){
    return get_asset_trans_view_str(ST_ASSET_TRANSFER_REQUEST, $row['id']);
}
function _reference($row){
    return $row['reference'];     
}
function _comment($row){
    return $row['comment'];     
}
function _from_project_description($row){
    return $row['from_project_description'];   
}
function _to_project_description($row){
    return $row['to_project_description'];   
}
function _from_location_name($row){
    return $row['from_location_name'];
}
function _to_location_name($row){
    return $row['to_location_name'];
}
function _approval_status($row){
    global $approval_statuses;
    return $approval_statuses[$row["approval_status"]];
}
function _requisition_transfer_link($row){  
    if ($row['approval_status'] == AS_APPROVED) {
        return pager_link(_("Asset Requisition Transfers"),"/assets/asset_requisition_transfers.php?ATRNo=".$row['id'], ICON_DOC);  
    }
    return null;		
}


start_form();

    start_table();
        start_row();
            ref_cells("Asset Transfer Request Id:", "asset_transfer_request_id");
            asset_locations_list_cells("From Location:", 'from_location', null, 'Select From Asset Location', true);       
            asset_locations_list_cells("To Location:", 'to_location', null, 'Select To Asset Location', true);       
        end_row();  
    end_table();

    start_table();
        start_row();
            project_list_cells(_("From Project:"), 'from_project_id', null, _('Select a project'), true);       
            project_list_cells(_("To Project:"), 'to_project_id', null, _('Select a project'), true);       
            submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
        end_row();

    end_table(1);


$asset_transfer_request_id = "";
if(isset($_POST['asset_transfer_request_id'])){
  $asset_transfer_request_id = $_POST['asset_transfer_request_id'];
}

$from_location = "";
if(isset($_POST['from_location'])){
  $from_location = $_POST['from_location'];
}

$to_location = "";
if(isset($_POST['to_location'])){
  $to_location = $_POST['to_location'];
}

$from_project_id = "";
if(isset($_POST['from_project_id'])){
  $from_project_id = $_POST['from_project_id'];
}

$to_project_id = "";
if(isset($_POST['to_project_id'])){
  $to_project_id = $_POST['to_project_id'];
}

$site_id = "";
if(isset($_POST['site_id'])){
  $site_id = $_POST['site_id'];
}

$sql = get_sql_for_asset_transfer_request_inquiry($asset_transfer_request_id, $from_location, $to_location, $from_project_id, $to_project_id, 
                                                  AS_APPROVED);    

$cols = array(
            _("ID")=> array('fun' => '_id', 'align' => 'center'),
            _("Reference")=> array('fun' => '_reference'),                         
            _("From Project Name")=>array('fun' => '_from_project_description'),                
            _("To Project Name")=>array('fun' => '_to_project_description'),                
            _("From Asset Location")=>array('fun' => '_from_location_name'), 
            _("To Asset Location")=>array('fun' => '_to_location_name'), 
            _("Total")=>'total', 
            _("Comment")=> array('fun' => '_comment'),
            _("Status")=> array('fun' => '_approval_status', 'align' => 'center'));

    array_append($cols, array(array('insert' => true, 'fun' => '_requisition_transfer_link', 'align' => 'center')));

$table =& new_db_pager('orders_tbl', $sql, $cols, null, null);
$table->width = "98%";
display_db_pager($table);

br();

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

?>