<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_TOOL_USAGE_CHARGES_VIEW';
$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/asset_usage_charges_inquiry_db.inc");
include_once($path_to_root . "/assets/includes/db/tool_issues_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(800, 500);
page(_($help_context = "View Tool Issue Detail Charges"), true, false, "", $js);

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

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

display_heading("Asset Issue Detail Id: " . $tucd_id);

br(1);

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

$myrow = view_tool_issue_detail($tucd_id);
//$tih = get_tool_issue_header_record($myrow['issue_id']);

start_row();

label_cells(_("Asset Issue"), get_asset_trans_view_str(ST_TOOL_ISSUE, $myrow['ai_id']), "class='tableheader2'");
end_row();

$asset_name = $myrow['asset_code']." - ".$myrow['asset_description']." (".$myrow['asset_id'].")";
label_cells("Tool", $asset_name, "class='tableheader2'");
end_row();

label_cells("Rate", $myrow['rate'], "class='tableheader2'");
end_row();

label_cells("From Date", $myrow['from_date'], "class='tableheader2'");
end_row();

label_cells("To Date", $myrow['to_date'], "class='tableheader2'");
end_row();



end_table(1);

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

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

display_heading("Details");

$result = view_tool_issue_detail_charge_details($tucd_id);

$th = array(_("Charge Id"),_("Charged From Date"), _('Charged Up To Date'),
            _("No Of Units"), _("Rate"), _("Charge"));  
                                     

table_header($th);
$k = 0; //row colour counter
 $total_charge = 0;
while($row_b = db_fetch($result)){
    
    alt_table_row_color($k);
     
    label_cell($row_b['charge_no']);    
    label_cell(sql2date($row_b['from_date']), "align=center");
    label_cell(sql2date($row_b['cutoff_date']), "align=center");
    label_cell($row_b['no_of_units'], "align=right");
    amount_cell($row_b['rate']);
    $line_charge = $row_b['no_of_units'] * $row_b['rate'];
    amount_cell($line_charge);
    
    $total_charge += $line_charge;
     
    $k++;
}

start_row();
label_cell("Total", "align=right colspan=5");
amount_cell($total_charge, true);
end_row();

end_table(1);


//start_table(TABLESTYLE2, "width=60%");
//
//    display_heading("Asset Issue");
//
//    $th = array(_("ID"),_("Reference"),_("Date"),_("Location"),_("Employee"));
//
//    table_header($th);
//
//    $asset_issue_details = view_asset_issue_for_asset_return($myrow['asset_issue_id']);
//    
//    while($ai_row = db_fetch($asset_issue_details)){
//        alt_table_row_color($k);
//        
//        $id = get_asset_trans_view_str(ST_ASSET_ISSUE, $ai_row['id']);
//        label_cell($id);
//        label_cell($ai_row['reference']);
//        label_cell(sql2date($ai_row['tran_date']), "align=center");
//        label_cell($ai_row['location_name']);
//        $name = get_group_company_employee_formatted_long_name($ai_row['company_code'], $ai_row['employee_code']);
//        label_cell($name) ;  
//    }
//
//end_table();

end_page(true, false, false, ST_TOOL_RETURN, $tucd_id);


?>
