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

$page_security = 'SA_VEHICLE_RUNNING_CHART_GROUPING';
if (!@$_GET['popup'])
    $path_to_root = "..";
else	
    $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/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/includes/approval_functions.inc");
include_once($path_to_root . "/gl/includes/db/gl_db_bank_accounts.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include_once($path_to_root . "/transport/includes/db/vehicle_running_chart_entry_grouping_db.inc");

$js = '';

if ($SysPrefs->use_popup_windows){
    $js .= get_js_open_window(900, 500);
}

if (user_use_date_picker()){
    $js .= get_js_date_picker();
}

page(_($help_context = "Vehicle Running Chart Entry Grouping"), false, false, "", $js);
simple_page_mode(true);

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

function dislay_vehicle_running_chart_grouping_details()
{
    global $Ajax, $petty_cash_float_transaction_types;   
    
    $Ajax->activate('leaves');
    div_start('leaves');
      
    start_table(TABLESTYLE, "width=90%");        
    

    $_POST['group_reference'] = get_post('group_reference');
    
    $result = get_vehicle_running_chart($_POST['from_date'], $_POST['to_date'],
                                        $_POST['view_all'], $_POST['supplier_id'], $_POST['group_reference']);

    $th = array(_("VRC#"), _("Project"), _("Package"),
                _("Vehicle"), _("Plate No:"), _("Driver"), 
                _("Cost"), _("Supplier"), _("Batch No"),_("Group Reference"), "");              
           
    table_header($th);

    $j = 0;
    $total = 0;
    while ($myrow = db_fetch($result))
    {
        alt_table_row_color($k);

        label_cells('', $myrow["id"],'', "align=center");     
        label_cells('', $myrow["project_description"]);                 
        label_cells('', $myrow["package_description"],'');        
        label_cells('', $myrow["vehicle_description"],'');           
           
        label_cells('', $myrow["plate_no"],'', "align=right");
        label_cells('', $myrow["driver_name"],'');
        label_cells('', number_format($myrow["cost"],2),'');   
        label_cells('', $myrow["supp_name"]); 
        label_cells('', $myrow["batch_no"], '',"align=center");     
        
        
        if(!(isset($_POST[$myrow["id"]."_".'group_reference']))){  
            $_POST[$myrow["id"]."_".'group_reference'] = $myrow['group_reference'];                     
        }
        text_cells(null, $myrow["id"]."_".'group_reference');   
                                   
        check_cells('', $myrow["id"]."_".'selected_'.$myrow["id"]);

        end_row();
        $j++; 
    }
    
    end_table();
    div_end();     
}



function create_vehicle_running_chart_grouping($from_date, $to_date, $new_only, $group_reference)
{
    global $Refs;    
   
    $result = get_vehicle_running_chart($from_date, $to_date, $new_only, $group_reference); 
    
    while($myrow = db_fetch($result))            
    {                    
        if((isset($_POST[$myrow["id"]."_"."selected_".$myrow["id"]])) && ($_POST[$myrow["id"]."_"."selected_".$myrow["id"]] == true))
        {           
            $group_reference = $_POST[$myrow["id"]."_".'group_reference'];
            add_vehicle_running_chart_grouping($myrow["id"], $group_reference);            
        }       
    }     
}

if(isset($_POST['update_vehicle_running_chart_grouping']))
{       
    create_vehicle_running_chart_grouping($_POST['from_date'], $_POST['to_date'], $_POST['view_all'], $_POST['supplier_id'], $_POST['group_reference'] );
}

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


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

br(); 

start_table(TABLESTYLE_NOBORDER);
    date_cells("From Date :", 'from_date', '', null, -30);
    date_cells("To Date :", 'to_date', '', null, +30);
    yesno_list_cells("New/All :", 'view_all', null, 'New Only', 'All', true);
    supplier_list_cells("Suppler", "supplier_id", null, '');
    text_cells("Group Reference :", 'group_reference');
    
    submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
end_table(1);   


dislay_vehicle_running_chart_grouping_details();

start_table(TABLESTYLE2);

end_table(TABLESTYLE2); 

submit_center_first('update_vehicle_running_chart_grouping', _("UPDATE"), '', 'default');


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



?>
