<?php
/**********************************************************************
***********************************************************************/
$page_security = 'SA_TRANSPORT_TRANSVIEW';
$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 . "/transport/includes/db/vehicle_running_chart_entry_db.inc");
include_once($path_to_root . "/transport/includes/db/vehicle_running_chart_inquiry_db.inc");

$js = "";
if ($SysPrefs->use_popup_windows)
	$js .= get_js_open_window(800, 500);
page(_($help_context = "View Vehicle Running Chart Batch"), true, false, "", $js);

//-------------------------------------------------------------------------------------------------
$woid = 0;
if ($_GET['trans_no'] != "")
{
	$vrc_batch_no = $_GET['trans_no'];
}

display_heading("Vehicle Running Chart Batch No: " . $vrc_batch_no);

//br(1);

function display_vehicle_running_chart_batch_task_details($task_id, $vrc_batch_no)
{
    $total_cost = 0;
    
    $result = view_vehicle_running_chart_batch_task_details($task_id, $vrc_batch_no);
    while ($myrow = db_fetch($result)) 
    {
        alt_table_row_color($k);	
    //	label_cell($myrow["id"]);       
        label_cell(get_transport_trans_view_str(ST_VEHICLE_RUNNING_CHART, $myrow['id']));
    
        label_cell($myrow["package_description"]);       
        label_cell($myrow["vehicle_description"]);
        label_cell($myrow["plate_no"]);       
        amount_decimal_cell($myrow["cost"]);
        $total_cost += $myrow["cost"];
        
        amount_decimal_cell($myrow["supplier_charge"]);
        label_cell(substr($myrow["start_date_time"],0,16));       
        label_cell(substr($myrow["end_date_time"],0,16));
        label_cell(get_transport_trans_view_str(ST_VEHICLE_ALLOCATION, $myrow['vehicle_allocation_id'] > 0 ? $myrow['vehicle_allocation_id'] : ''));
        end_row();
        
        if(strlen($myrow["route"]) > 0){
            alt_table_row_color($k);
            label_cell("");
            label_cell("Route: ".$myrow["route"], "colspan=8");
            end_row();
        }
    //	label_cell($myrow["passengers"]);
    //    label_cell($myrow["supp_name"]);       
        
    }
    
    return $total_cost;
}


function display_vehicle_running_chart_batch_project_tasks($project_id, $vrc_batch_no)
{    
    $vrc_tasks_result = view_vehicle_running_chart_batch_project_tasks($project_id, $vrc_batch_no);
    while ($myrow = db_fetch($vrc_tasks_result)) 
    {
        $heading = spaces(20)."<b>Budget: </b>".$myrow["task_description"];
        label_cell($heading, "colspan=10"); 
        end_row();
        
        $total_cost = display_vehicle_running_chart_batch_task_details($myrow["task_id"], $vrc_batch_no);
        
        label_cell("Total for the budget", "align=right colspan=4");
        amount_cell($total_cost, true);
        label_cell("", "colspan=5"); 
        
        end_row();
    }

}


function display_vehicle_running_chart_batch_projects($vrc_batch_no)
{
    
    $th = array(("VRC #"),_("Package"),
            _("Vehicle"),_("Plate No"),
            "Cost", _("Supp. Charge"),_("Start Date"),_("End Date"),
            "VA #");

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

    table_header($th);
    
    $vrc_tasks_result = view_vehicle_running_chart_batch_projects($vrc_batch_no);
    while ($myrow = db_fetch($vrc_tasks_result)) 
    {
        $heading = "<b>Project: </b>".$myrow["project_description"];
        label_cell($heading, "colspan=10"); 
        end_row();
        
        display_vehicle_running_chart_batch_project_tasks($myrow["project_id"], $vrc_batch_no);
    }
    
    end_table();
}



display_vehicle_running_chart_batch_projects($vrc_batch_no);

br();


end_page(true, false, false, ST_VEHICLE_RUNNING_CHART_BATCH, $vrc_batch_no);

?>
