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

$page_security = 'SA_TOOL_USAGE_CHARGES_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 . "/assets/includes/db/vehicle_requests_db.inc");
include_once($path_to_root . "/assets/includes/db/asset_usage_charges_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 ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
if (user_use_date_picker())
	$js .= get_js_date_picker();
page(_($help_context = "Tool Usage Charges Inquiry"), false, false, "", $js);

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


function asset_issue_id($row)
{  
    return get_asset_trans_view_str(ST_TOOL_ISSUE, $row['issue_id']);
}

function tool_usage_charge_id($row)
{  
    return get_asset_trans_view_str(ST_TOOL_USAGE_CHARGE, $row['id']);
}

function tool_issue_detail_usage_charges($row)
{  
    return get_asset_trans_view_str(ST_TOOL_ISSUE_DETAIL_USAGE_CHARGES, $row['issue_detail_id']);
}

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

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

function charged_from_date($row)
{
    return sql2date($row['from_date']);
}

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


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

function comment($row)
{
    return $row['comments'];
}

function tool_description($row)
{
    $name = $row['asset_code']." - ".$row['description']." (".$row['asset_id'].")";
    return $name;  
}

//function return_link($row)
//{
//    if($row['fully_returned']){
//        return null;
//    }
//    
//    $modify = "AINo";
//        return pager_link( _("Return"), "/assets/tool_returns.php?$modify=".$row['asset_issue_id'], ICON_RECEIVE);    
//}




    $Ajax->activate('orders_tbl');



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

start_table();
start_row();
    ref_cells(text_bold("Tool Issue Id:"), "asset_issue_id", null, null, null, true);
    date_cells(_("Cutoff Date From:"), 'from_date', '', null, -60, null, null, null, true);
    date_cells(_("CutOff Date To:"), 'to_date', '', null, +15, null, null, null, true);
//    asset_list_cells("Asset:", 'asset_id', null, 'Select an asset', true, null);

    project_list_cells("Project:", 'project_id', null, _('Select a project'), true);  

    submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');

end_row();


end_table(1);

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

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

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



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

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



  $sql = get_sql_for_tool_usage_charges_inquiry($project_id, $asset_issue_id, $from_date, $to_date);    
    
    $cols = array(
                _("Charge Id")=> array('fun'=>'tool_usage_charge_id', 'align'=>'center'),
                _("Tool Issue Id")=> array('fun'=>'asset_issue_id', 'align'=>'center'),
                _("Project")=> array('fun'=>'project_description'),
                _("Detail Id")=> array('fun'=>'tool_issue_detail_usage_charges', 'align'=>'center'),
                _("Tool")=> array('fun'=>'tool_description'),         
                _("Charged From Date")=> array('fun'=>'charged_from_date', 'align'=>'center'),
                _("Charged Up To Date")=> array('fun'=>'cutoff_date', 'align'=>'center'),
                          
                _("Units")=> array('align'=>'right'),               
                _("Rate")=> array('align'=>'right'),                
                _("Total")=> array('align'=>'right')

            );
    
//    array_append($cols, array(
//        array('insert'=>true, 'fun'=>'return_link')       
//    ));


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

$table->width = "95%";

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

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



?>
