<?php include('include/auth.php'); 

?>
<!doctype html>
<html class="fixed dark">
<?php 
	$pagerole="lists";
	include('include/head.php');
    $startdateinit=$_GET['sdateg3'];
    $startdate=strtotime($startdateinit);
  
    if (!empty($_GET['edateg'])){
        $enddate=$_GET['edateg'];
    }
    else {$enddate=strtotime("+14 day", $startdate);}
    
    $cargroup=$_GET['cargroup'];

    $sdate=date("Y-m-d", $startdate);
    $edate=date("Y-m-d", $enddate);
    $startdate1 = strtotime("+1 day", $startdate);

    $startdate2 = strtotime("+2 day", $startdate);
    $startdate3 = strtotime("+3 day", $startdate);
    $startdate4 = strtotime("+4 day", $startdate);
    $startdate5 = strtotime("+5 day", $startdate);
    $startdate6 = strtotime("+6 day", $startdate);
    $startdate7 = strtotime("+7 day", $startdate);
    $startdate8 = strtotime("+8 day", $startdate);
    $startdate9 = strtotime("+9 day", $startdate);
    $startdate10 = strtotime("+10 day", $startdate);
    $startdate11 = strtotime("+11 day", $startdate);
    $startdate12 = strtotime("+12 day", $startdate);
    $startdate13 = strtotime("+13 day", $startdate);
    $startdate14 = strtotime("+14 day", $startdate);
    $startdate15 = strtotime("+15 day", $startdate);
    $dtot=$edate-$sdate;
    
    $resultcat = $db->query("SELECT * FROM jos8r_vikrentcar_categories WHERE jos8r_vikrentcar_categories.id=$cargroup ");
    $rowcat =  mysqli_fetch_array( $resultcat );
    //$resultcat2 = $db->query("SELECT * FROM jos8r_vikrentcar_categories WHERE jos8r_vikrentcar_categories.id=$cargroup2 ");
   // $rowcat2 =  mysqli_fetch_array( $resultcat2 );
    
    ?>
<style>
    .green {
        background-color: green !important;
        color:#fff!important;
        font-weight:bold;
        text-align:center;
    }

    .red {
        background-color: red !important;
        color:#fff!important;
        font-weight:bold;
        text-align:center;
    }
    .orange {
        background-color: orange !important;
        color:#fff!important;
        font-weight:bold;
        text-align:center;
    }
</style>

<body>
    <section class="body">

        <!-- start: header -->
        <header class="header">
            <div class="logo-container">
                <a href="index.php" class="logo">
                    <img src="img/logo-light.png" width="75" height="35" alt="Web Voyage" />
                </a>
                <div class="d-md-none toggle-sidebar-left" data-toggle-class="sidebar-left-opened" data-target="html"
                    data-fire-event="sidebar-left-opened">
                    <i class="fas fa-bars" aria-label="Toggle sidebar"></i>
                </div>
            </div>

            <!-- start: search & user box -->
            <div class="header-right">
                <?php include('include/search.php');?>


                <span class="separator"></span>
                <?php include('include/notifications.php');?>


                <span class="separator"></span>
                <?php include('include/userbox.php');?>

            </div>
            <!-- end: search & user box -->
        </header>
        <!-- end: header -->

        <div class="inner-wrapper">
            <!-- start: sidebar -->
            <?php include('include/nav.php');?>
            <!-- end: sidebar -->

            <section role="main" class="content-body">
                <header class="page-header">
                    <h2>MotorClub Availability <?php echo $rowcat['name'];?> </h2>
                   
                    <div class="right-wrapper text-right">
                        <ol class="breadcrumbs">
                            <li>
                                <a href="index.php">
                                    <i class="fas fa-home"></i>
                                </a>
                            </li>
                            <li><span>WV Admin</span></li>
                            <li><span>MotorClub Availability</span></li>
                        </ol>

                        <a class="sidebar-right-toggle" data-open="sidebar-right"><i
                                class="fas fa-chevron-left"></i></a>
                    </div>
                </header>
                <?php if($userrole==2){echo "Δεν έχετε Διακαιώματα για αυτή την λειτουργία";}
				else {

?>
                       
                <div class="row">
                    <div class="col">
                        <section class="card">
                            <header class="card-header">
                                <div class="card-actions">
                                    <a href="#" class="card-action card-action-toggle" data-card-toggle></a>
                                    <a href="#" class="card-action card-action-dismiss" data-card-dismiss></a>
                                </div>

                                <h2 class="card-title"> Available vehicles From: <?php echo date("d/m/Y", $startdate1);?>
                            To: <?php echo date("d/m/Y", $startdate14);?> </h2>
                            </header>

                            <div class="card-body">

                                <table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
                                    <thead>
                                        <tr>
                                        <th class="hidden">Order</td>
                                        <th>Group</td>
                                        <th>Units</td>
                                        <th><?php echo date("d/m", $startdate1);?></th>
                                        <th><?php echo date("d/m", $startdate2);?></th>
                                        <th><?php echo date("d/m", $startdate3);?></th>
                                        <th><?php echo date("d/m", $startdate4);?></th>
                                        <th><?php echo date("d/m", $startdate5);?></th>
                                        <th><?php echo date("d/m", $startdate6);?></th>
                                        <th><?php echo date("d/m", $startdate7);?></th>
                                        <th><?php echo date("d/m", $startdate8);?></th>
                                        <th><?php echo date("d/m", $startdate9);?></th>
                                        <th><?php echo date("d/m", $startdate10);?></th>
                                        <th><?php echo date("d/m", $startdate11);?></th>
                                        <th><?php echo date("d/m", $startdate12);?></th>
                                        <th><?php echo date("d/m", $startdate13);?></th>
                                        <th><?php echo date("d/m", $startdate14);?></th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php 
                                        $sql11 = "SELECT * FROM jos8r_vikrentcar_categories WHERE jos8r_vikrentcar_categories.vtype='$cargroup' "; 
                                        $resultcats = mysqli_query($db,$sql11); 
 if ($resultcats->num_rows > 0) {
    while ($rowcats = mysqli_fetch_array($resultcats)) { 
       
        $idgrp=$rowcats['id'];
        $categorise=$cargroup.";".$idgrp.";";
        
if ($idgrp==4){
    $car1=1;
    $car2=29;
    $car3=48;
    $car4=57;
    $car5=60;
    $car6=61;
    $car7=72;
    $car8=73;
   
}
elseif($idgrp==5){
    $car1=6;
    $car2=7;
    $car3=10;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;

}
elseif($idgrp==6){
    $car1=9;
    $car2=62;
    $car3=63;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;

}
elseif($idgrp==7){
    $car1=2;
    $car2=12;
    $car3=49;
    $car4=64;
    $car5=77;
    $car6=0;
    $car7=0;
    $car8=0;
 
}
elseif($idgrp==8){
    $car1=5;
    $car2=8;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==9){
    $car1=50;
    $car2=51;
    $car3=55;
    $car4=59;
    $car5=76;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==10){
    $car1=3;
    $car2=11;
    $car3=66;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==11){
    $car1=20;
    $car2=75;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==12){
    $car1=22;
    $car2=52;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==13){
    $car1=19;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==15){
    $car1=28;
    $car2=54;
    $car3=67;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==16){
    $car1=21;
    $car2=24;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==17){
    $car1=16;
    $car2=17;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==18){
    $car1=23;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==19){
    $car1=53;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==20){
    $car1=25;
    $car2=65;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==38){
    $car1=13;
    $car2=14;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==39){
    $car1=18;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==40){
    $car1=15;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==43){
    $car1=56;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==44){
    $car1=26;
    $car2=68;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}

elseif($idgrp==21){
    $car1=41;
    $car2=42;
    $car3=69;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==22){
    $car1=0;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==23){
    $car1=45;
    $car2=46;
    $car3=70;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==25){
    $car1=30;
    $car2=31;
    $car3=47;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==26){
    $car1=33;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==27){
    $car1=32;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==28){
    $car1=36;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==29){
    $car1=34;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==30){
    $car1=40;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==31){
    $car1=35;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==32){
    $car1=43;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==33){
    $car1=44;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==34){
    $car1=71;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==35){
    $car1=39;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==36){
    $car1=38;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==37){
    $car1=37;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==41){
    $car1=39;
    $car2=38;
    $car3=37;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
elseif($idgrp==42){
    $car1=46;
    $car2=45;
    $car3=69;
    $car4=42;
    $car5=70;
    $car6=41;
    $car7=0;
    $car8=0;
}
elseif($idgrp==45){
    $car1=74;
    $car2=0;
    $car3=0;
    $car4=0;
    $car5=0;
    $car6=0;
    $car7=0;
    $car8=0;
}
$resultcar = $db2->query("SELECT COUNT(*) FROM fleet WHERE (fleet.veh_id= '$car1' OR fleet.veh_id= '$car2' OR fleet.veh_id= '$car3'  OR fleet.veh_id= '$car4' OR fleet.veh_id= '$car5'  OR fleet.veh_id= '$car6'  OR fleet.veh_id= '$car7'  OR fleet.veh_id= '$car8') AND fleet.active=1");
        $rowc = $resultcar->fetch_row();
       $vtot=$rowc[0];	//lathos
$car=$car1;
        
    
$result1 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate BETWEEN ritiro AND consegna) OR ($startdate1 BETWEEN ritiro AND consegna))
           ");
 $row1 = $result1->fetch_row();
          $result2 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate1 BETWEEN ritiro AND consegna) OR ($startdate2 BETWEEN ritiro AND consegna))
          ");
         $row2 = $result2->fetch_row();
        
         $result3 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate2 BETWEEN ritiro AND consegna) OR ($startdate3 BETWEEN ritiro AND consegna))
         ");
        $row3 = $result3->fetch_row();
        $result4 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate3 BETWEEN ritiro AND consegna) OR ($startdate4 BETWEEN ritiro AND consegna))
        ");
       $row4 = $result4->fetch_row();
       $result5 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate4 BETWEEN ritiro AND consegna) OR ($startdate5 BETWEEN ritiro AND consegna))
       ");
      $row5 = $result5->fetch_row();
      $result6 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate5 BETWEEN ritiro AND consegna) OR ($startdate6 BETWEEN ritiro AND consegna))
      ");
     $row6 = $result6->fetch_row();
     $result7 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate6 BETWEEN ritiro AND consegna) OR ($startdate7 BETWEEN ritiro AND consegna))
     ");
    $row7 = $result7->fetch_row();
    $result8 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate7 BETWEEN ritiro AND consegna) OR ($startdate8 BETWEEN ritiro AND consegna))
    ");
   $row8 = $result8->fetch_row();
   $result9 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate8 BETWEEN ritiro AND consegna) OR ($startdate9 BETWEEN ritiro AND consegna))
   ");
  $row9 = $result9->fetch_row();
  $result10 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate9 BETWEEN ritiro AND consegna) OR ($startdate10 BETWEEN ritiro AND consegna))
  ");
  $row10 = $result10->fetch_row();
  $result11 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate10 BETWEEN ritiro AND consegna) OR ($startdate11 BETWEEN ritiro AND consegna))
  ");
  $row11 = $result11->fetch_row();
  $result12 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate11 BETWEEN ritiro AND consegna) OR ($startdate12 BETWEEN ritiro AND consegna))
  ");
  $row12 = $result12->fetch_row();
  $result13 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate12 BETWEEN ritiro AND consegna) OR ($startdate13 BETWEEN ritiro AND consegna))
  ");
  $row13 = $result13->fetch_row();
  $result14 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE (jostj_vikrentcar_orders.idcar=$car1 OR jostj_vikrentcar_orders.idcar=$car2 OR jostj_vikrentcar_orders.idcar=$car3 OR jostj_vikrentcar_orders.idcar=$car4 OR jostj_vikrentcar_orders.idcar=$car5 OR jostj_vikrentcar_orders.idcar=$car6 OR jostj_vikrentcar_orders.idcar=$car7 OR jostj_vikrentcar_orders.idcar=$car8) AND jostj_vikrentcar_orders.status!='cancelled' AND (($startdate13 BETWEEN ritiro AND consegna) OR ($startdate14 BETWEEN ritiro AND consegna))
  ");
  $row14 = $result14->fetch_row();
  
          $avail_1=$vtot-$row1[0];
          $avail_2=$vtot-$row2[0];
          $avail_3=$vtot-$row3[0];
          $avail_4=$vtot-$row4[0];
          $avail_5=$vtot-$row5[0];
          $avail_6=$vtot-$row6[0];
          $avail_7=$vtot-$row7[0];
          $avail_8=$vtot-$row8[0];
          $avail_9=$vtot-$row9[0];
          $avail_10=$vtot-$row10[0];
          $avail_11=$vtot-$row11[0];
          $avail_12=$vtot-$row12[0];
          $avail_13=$vtot-$row13[0];
          $avail_14=$vtot-$row14[0];
                                                        
                                                     
                                                    
									 ?>

                                        <tr>
                                        <td class="hidden"> <?php echo $rowcats['ordering'];?></td>
                                            <td> <?php echo $rowcats['name'];?> - <a href="totalavail.php?sdateg2=<?php echo $startdate;?>&cargroup=<?php echo $cargroup;?>&cargroup2=<?php echo $idgrp;?>" target="_blank"
                                                    class="on-default edit-row"><i class="fa fa-eye"></i></a></td>
                                            <td><?php echo $vtot;?></td>
                                            <td class="<?php if($avail_1<1){echo "red";} elseif($avail_1<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_1;?></td>
                                        <td class="<?php if($avail_2<1){echo "red";} elseif($avail_2<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_2;?></td>
                                        <td class="<?php if($avail_3<1){echo "red";} elseif($avail_3<2) {echo "orange";} else {echo "green";}?>"> <?php echo $avail_3;?></td>
                                        <td class="<?php if($avail_4<1){echo "red";} elseif($avail_4<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_4;?></td>
                                        <td class="<?php if($avail_5<1){echo "red";} elseif($avail_5<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_5;?></td>
                                        <td class="<?php if($avail_6<1){echo "red";} elseif($avail_6<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_6;?></td>
                                        <td class="<?php if($avail_7<1){echo "red";} elseif($avail_7<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_7;?></td>
                                        <td class="<?php if($avail_8<1){echo "red";} elseif($avail_8<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_8;?></td>
                                        <td class="<?php if($avail_9<1){echo "red";} elseif($avail_9<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_9;?></td>
                                        <td class="<?php if($avail_10<1){echo "red";} elseif($avail_10<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_10;?></td>
                                        <td class="<?php if($avail_11<1){echo "red";} elseif($avail_11<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_11;?></td>
                                        <td class="<?php if($avail_12<1){echo "red";} elseif($avail_12<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_12;?></td>
                                        <td class="<?php if($avail_13<1){echo "red";} elseif($avail_13<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_13;?></td>
                                        <td class="<?php if($avail_14<1){echo "red";} elseif($avail_14<2) {echo "orange";} else {echo "green";}?>"><?php echo $avail_14;?></td>
                                        </tr>
                                        <?php }  ?>
                                    </tbody>
                                   
                                </table>
                            </div>

                        </section>

                    </div>
                </div>
                <?php } }?>
                <!-- end: page -->
            </section>
        </div>

        <?php include('include/aside.php');?>

    </section>


    <!-- Vendor -->
    <script src="vendor/jquery/jquery.js"></script>
    <script src="vendor/jquery-browser-mobile/jquery.browser.mobile.js"></script>
    <script src="vendor/popper/umd/popper.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.js"></script>
    <script src="vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
    <script src="vendor/common/common.js"></script>
    <script src="vendor/nanoscroller/nanoscroller.js"></script>
    <script src="vendor/magnific-popup/jquery.magnific-popup.js"></script>
    <script src="vendor/jquery-placeholder/jquery.placeholder.js"></script>

    <!-- Specific Page Vendor -->
    <script src="vendor/select2/js/select2.js"></script>
    <script src="vendor/datatables/media/js/jquery.dataTables.min.js"></script>
    <script src="vendor/datatables/media/js/dataTables.bootstrap4.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/dataTables.buttons.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/buttons.bootstrap4.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/buttons.html5.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/Buttons-1.4.2/js/buttons.print.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/JSZip-2.5.0/jszip.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/pdfmake-0.1.32/pdfmake.min.js"></script>
    <script src="vendor/datatables/extras/TableTools/pdfmake-0.1.32/vfs_fonts.js"></script>


    <!--(remove-empty-lines-end)-->

    <!-- Theme Base, Components and Settings -->
    <script src="js/theme.js"></script>

    <!-- Theme Custom -->
    <script src="js/custom.js"></script>

    <!-- Theme Initialization Files -->
    <script src="js/theme.init.js"></script>

    <!-- Examples -->
    <script src="js/examples/examples.datatables.default.js"></script>
    <script src="  //cdn.datatables.net/plug-ins/1.10.24/api/sum().js"></script>
    <script>
        (function ($) {

            'use strict';

            var datatableInit = function () {
                var $table = $('#datatable-tabletools');


                var table = $table.dataTable({
                    "pageLength": 100,
                    "order": [
                        [0, "asc"]
                    ],
                    sDom: '<"text-right mb-md"T><"row"<"col-lg-6"l><"col-lg-6"f>><"table-responsive"t>p',
                    buttons: [{
                            extend: 'print',
                            text: 'Print'
                        },
                        {
                            extend: 'excel',
                            text: 'Excel'
                        },
                        {
                            extend: 'pdf',
                            text: 'PDF',
                            customize: function (doc) {
                                var colCount = new Array();
                                $('#datatable-tabletools').find('tbody tr:first-child td').each(
                                    function () {
                                        if ($(this).attr('colspan')) {
                                            for (var i = 1; i <= $(this).attr(
                                                    'colspan'); $i++) {
                                                colCount.push('*');
                                            }
                                        } else {
                                            colCount.push('*');
                                        }
                                    });
                                doc.content[1].table.widths = colCount;
                            }
                        }
                    ]
                });

                $('<div />').addClass('dt-buttons mb-2 pb-1 text-right').prependTo(
                    '#datatable-tabletools_wrapper');

                $table.DataTable().buttons().container().prependTo('#datatable-tabletools_wrapper .dt-buttons');

                $('#datatable-tabletools_wrapper').find('.btn-secondary').removeClass('btn-secondary').addClass(
                    'btn-default');
            };

            $(function () {
                datatableInit();
            });

        }).apply(this, [jQuery]);
    </script>
</body>

</html>
<?php  include('include/footer.php');?>