<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_TOOL_ISSUE_INQ';
$path_to_root = "../..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/assets/includes/db/tool_issues_inquiry_db.inc");
include_once($path_to_root . "/assets/includes/db/asset_usage_charges_inquiry_db.inc");
include_once($path_to_root . "/includes/common_functions.inc");     
include_once($path_to_root . "/includes/db/group_companies_db.inc");   

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(1000, 500);
page(_($help_context = "View Tool Issue"), true, false, "", $js);

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

if ($_GET['trans_no'] != "")
{
    $asset_issue_id = $_GET['trans_no'];
}

display_heading("Tool Issue No: " . $asset_issue_id);

start_table(TABLESTYLE2, "width=60%");

$myrow = view_tool_issue($asset_issue_id);

start_row();
label_cells("Reference", $myrow['reference'], "class='tableheader2'");
end_row();

label_cells(_("Project"), $myrow['project_name'], "class='tableheader2'");
end_row();

label_cells("Company", $myrow['company_code'], "class='tableheader2'");
end_row();

label_cells(_("Employee"), $myrow['employee_code']." - ".$myrow['initials']."  ".$myrow['employee_last_name'], "class='tableheader2'");
end_row();

label_cells(_("Location"), $myrow['location_name'], "class='tableheader2'");
end_row();

label_cells(_("Date"), sql2date($myrow['tran_date']), "class='tableheader2'");
end_row();

label_cells(_("Comment"), $myrow['comments'], "class='tableheader2'");
end_row();

//label_cells(_("Asset Request"), $myrow['ar_id'], "class='tableheader2'");
label_cells(_("Tool Request"), get_asset_trans_view_str(ST_TOOL_REQUEST, $myrow['ar_id']), "class='tableheader2'");
end_row();

end_table(1);

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

start_table(TABLESTYLE2, "width=95%");

display_heading("Details ");

$result = view_tool_issue_details($asset_issue_id);

$th = array(_("ID"),_("Tool"), _('Budget'),
            _('Site'), _("From Date"),_("To Date"),
            _('Days'), _('Rate'), _("Qty"),_("Rtnd Qty"),_("Charge"));  
                          

table_header($th);
$k = 0; //row colour counter
  
while($row_b = db_fetch($result)){
    
    alt_table_row_color($k);
     
    label_cell($row_b['id']);
    
    label_cell($row_b['asset_code']."-".$row_b['asset_description']."-"."(".$row_b['asset_id'].")");
    
    label_cell($row_b['task_description']);
    label_cell($row_b['site_name']);
    label_cell(sql2date($row_b['from_date']), "align=center");
    label_cell(sql2date($row_b['to_date']), "align=center");  
    label_cell($row_b['no_of_days'], "align=right");
    amount_decimal_cell($row_b['rate']);
    label_cell($row_b['quantity'], "align=right");
    label_cell($row_b['returned_qty'], "align=right");
    
    $total_charge = get_tool_issue_detail_usage_total_charge($row_b['id']);    
    $link = get_asset_trans_view_str(ST_TOOL_ISSUE_DETAIL_USAGE_CHARGES, $row_b['id'], number_format($total_charge,2));
    label_cell($link, "align=right");
//    amount_decimal_cell($total_charge);
    
    if(strlen($row_b['line_comment']) > 1){
        end_row();
        alt_table_row_color($k);
        label_cell($row_b['line_comment'], "colspan=4 align=center");
        end_row();
    }
    
    $k++;
}
end_table(1);


start_table(TABLESTYLE2, "width=60%");

    display_heading("Tool Returns");

    $th = array(_("ID"),_("Reference"),_("Date"),_("Location"),_("Employee"));

    table_header($th);

    $asset_return_details = view_tool_returns_for_tool_issue($asset_issue_id);
    
    while($ar_row = db_fetch($asset_return_details)){
        alt_table_row_color($k);
        
        $id = get_asset_trans_view_str(ST_TOOL_RETURN, $ar_row['id']);
        label_cell($id);
        label_cell($ar_row['reference']);
        label_cell(sql2date($ar_row['tran_date']), "align=center");
        label_cell($ar_row['location_name']);
        $name = get_group_company_employee_formatted_long_name($ar_row['company_code'], $ar_row['employee_code']);
        label_cell($name) ;  
    }

end_table();


end_page(true, false, false, ST_TOOL_ISSUE, $asset_issue_id);

?>
