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

$page_security = 'SA_ASSET_QUANTITY_ADJUSTMENT_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/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/inventory.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/assets/includes/db/asset_quantity_adjustment_inquiry_db.inc");
include_once($path_to_root . "/includes/ui/ui_lists_group_companies.inc");
include_once($path_to_root . "/includes/db/group_companies_db.inc");

$js = '';

if($use_popup_windows){
    $js .= get_js_open_window(1000, 500);
}
if($use_date_picker){
    $js .= get_js_date_picker();
}

page($help_context = "Asset Quantity Adjustment Inquiry", false, false, "", $js);
//---------------------------------------------------------------------------------------------

simple_page_mode(true);

global $Ajax;

function _id($row){
    return get_asset_trans_view_str(ST_ASSET_QUANTITY_ADJUSTMENT, $row['id']);
}
function _req_id($row){
    return get_asset_trans_view_str(ST_ASSET_QUANTITY_ADJUSTMENT_REQUEST, $row['req_id']);
}
function _reference($row){
    return $row['reference'];     
}
function _company($row){
    return get_group_company_name($row['company_code']);   
}
function _employee_name($row){
    $employee_name = get_group_company_employee($row['company_code'], $row['employee_code']);
    return $employee_name['employee_code'].' - '.$employee_name['initials'].' '.$employee_name['last_name'];
}
function _comment($row){
    return $row['comment'];     
}
function _tran_date($row){
    return sql2date($row['tran_date']);     
}
function _total($row){
    return number_format($row['total'], 2);     
}

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

if (!@$_GET['popup'])
	start_form();
start_table();
    start_row();
        ref_cells("Asset Quantity Adjustment Request ID:", "asset_qty_ajt_req_id");
        group_companies_list_cells("Company:", 'company_code', null, "Select a company", true);
        group_company_employees_simple_list_cells("Employee:", 'employee_code', $_POST['company_code'], null, "Select an employee", true);
        submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
    end_row();  
end_table(1);

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

$asset_qty_ajt_req_id = "";
if(isset($_POST['asset_qty_ajt_req_id'])){
  $asset_qty_ajt_req_id = $_POST['asset_qty_ajt_req_id'];
}
$company_code = "";
if(isset($_POST['company_code'])){
  $company_code = $_POST['company_code'];
}
$employee_code = "";
if(isset($_POST['employee_code'])){
  $employee_code = $_POST['employee_code'];
}

$sql = get_sql_for_asset_quantity_adjustment_inquiry($asset_qty_ajt_req_id, $company_code, $employee_code);    

$cols = array(
            _("ID")=> array('fun' => '_id', 'align' => 'center'),                      
            _("Req.ID")=> array('fun' => '_req_id', 'align' => 'center'),                      
            _("Reference")=> 'reference',                          
            _("Company")=> array('fun' => '_company'),                                            
            _("Employee")=> array('fun' => '_employee_name'),
            _("Date")=>array('fun' => '_tran_date', 'align' => 'center'),    
            _("Comment")=> array('fun' => '_comment'),
            _("Total")=> array('fun' => '_total', 'align' => 'right'));

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

?>