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

?>
<!doctype html>
<html class="fixed dark">
<?php 
	$pagerole="lists";
	include('include/head.php');
    if (isset($_GET['sdateg2'])  && $_GET['sdateg2']!=0) {
        $startdateinit=$_GET['sdateg2'];
    }
    else {
        $startdateinit=$_GET['sdateg4'];
    }
   
    $startdate=strtotime($startdateinit);
      if (!empty($_GET['edateg'])){
        $enddate=$_GET['edateg'];
    }
    else {$enddate=strtotime("+14 day", $startdate);}
    
    $cargroup=$_GET['cargroup'];
    $cargroup2=$_GET['cargroup2'];
    //if ($cargroup==2 || $cargroup>=21 && $cargroup<=37 || $cargroup==41 || $cargroup==42) {$fg=2;} else {$fg=1;}
  //  $categorise=$fg.";".$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 );

    
 if(is_null($cargroup2)){
   
    $sql11 = "SELECT * FROM jos8r_vikrentcar_cars WHERE jos8r_vikrentcar_cars.idcat LIKE '$cargroup%'"; 
    $resultcats = mysqli_query($db,$sql11);         
 }
 else{
     $resultcat2 = $db->query("SELECT * FROM jos8r_vikrentcar_categories WHERE jos8r_vikrentcar_categories.id=$cargroup2 ");
   $rowcat2 =  mysqli_fetch_array( $resultcat2 );
     $categorise=$cargroup.";".$cargroup2.";";
    $sql11 = "SELECT * FROM jos8r_vikrentcar_cars WHERE jos8r_vikrentcar_cars.idcat = '$categorise'"; 
    $resultcats = mysqli_query($db,$sql11); 
 }
    ?>
<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']." / ".$rowcat2['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>Vehicle</td>
                                        <th>Total 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 
 if ($resultcats->num_rows > 0) {
    while ($rowcats = mysqli_fetch_array($resultcats)) { 
        $car=$rowcats['id'];
        $resultcar = $db2->query("SELECT COUNT(*) FROM fleet WHERE fleet.veh_id=$car AND fleet.active=1");
        $rowc = $resultcar->fetch_row();
          $resultcar1 = $db2->query("SELECT * FROM jostj_vikrentcar_cars WHERE jostj_vikrentcar_cars.id=$car ");
          $rowc1 =  mysqli_fetch_array( $resultcar1 );
          $vtot=$rowc[0];	
          $result1 = $db2->query("SELECT COUNT(DISTINCT id) FROM jostj_vikrentcar_orders WHERE jostj_vikrentcar_orders.idcar=$car 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=$car 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=$car 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=$car 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=$car 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=$car 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=$car 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=$car 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=$car 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=$car 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=$car 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=$car 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=$car 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=$car 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> <?php echo $rowc1['name'];?></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": [
                        [1, "desc"]
                    ],
                    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');?>