<?php include('include/auth.php'); 
?>
<!doctype html>
<html class="fixed dark">
<?php 
	$pagerole="lists";
	include('include/head.php');?>
<style>
    .green{color:green;}
    .red{color:red;}
</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>API Rates Dashboard</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>API Rates Dashboard</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">Rates Stats</h2>
                                </header>

                                <div class="card-body">

                                    <table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
                                        <thead>
                                        <tr>
                                        <th>Car Model</th>
												<th>Seasons</th>
                                                <th>Days</th>
                                                <th>Days with 0€</th>
												<th>Duplicate Entry</th>
												<th>Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody>

                                        <?php 
			$sql = "SELECT DISTINCT api_ext_rate_acriss FROM api_ext_rates
		";
            
$result = mysqli_query($db2,$sql);

if ($result->num_rows > 0) {
    // output data of each row
   while($row = mysqli_fetch_array($result)) {
	   $acc=$row['api_ext_rate_acriss'];
	   $sql111 = $db2->query("SELECT * FROM api_fleet LEFT JOIN jostj_vikrentcar_cars ON jostj_vikrentcar_cars.id=api_fleet.api_fleet_idcar WHERE api_fleet.api_fleet_acriss='$acc' AND api_fleet.api_fleet_partner='1006'  ") or die(mysql_error());
	   $row111 = mysqli_fetch_array( $sql111 );
	$result1 = $db2->query("SELECT COUNT(DISTINCT api_ext_rate_seasid) FROM api_ext_rates WHERE api_ext_rates.api_ext_rate_acriss='{$acc}'");
	$rowm1 = $result1->fetch_row();
	$totdays=$rowm1[0]*30;
	$result2 = $db2->query("SELECT COUNT(api_ext_rate_day) FROM api_ext_rates WHERE api_ext_rates.api_ext_rate_acriss='{$acc}'");
	$rowm2 = $result2->fetch_row();
	$result3 = $db2->query("SELECT COUNT(api_ext_rate_price) FROM api_ext_rates WHERE api_ext_rates.api_ext_rate_acriss='{$acc}' AND api_ext_rates.api_ext_rate_price='0.00'");
	$rowm3 = $result3->fetch_row();
	$result4 = $db2->query("SELECT api_ext_rate_acriss, api_ext_rate_seasid, api_ext_rate_day, COUNT(*)
	FROM api_ext_rates
	WHERE  api_ext_rates.api_ext_rate_acriss='{$acc}'
	GROUP BY api_ext_rate_acriss, api_ext_rate_seasid,api_ext_rate_day
	HAVING COUNT(*) > 1");
	$rowm4 = $result4->fetch_row();
     ?>
                                            <tr>
											
                                            <td><?php echo $row['api_ext_rate_acriss']." (".$row111['name']." )";?></td>
                                            <td><?php echo $rowm1[0];?></td>
                                            <td><?php echo $rowm2[0];?> / <?php echo $totdays;?></td>
                                            <td class="actions"><?php echo $rowm3[0]; if ($rowm3[0]!=0){?>  <a href="apiextrates.php?acriss=<?php echo $row["api_ext_rate_acriss"];?>&price=0.00"
                                                class="on-default edit-row"><i class="fa fa-eye"></i></a> <?php }?></td>
                                            <td>
                                            <?php if ($result4->num_rows > 1) {echo "Yes";}?>
                                                <!--<div class="progress progress-sm progress-half-rounded m-0 mt-1 light">
                                                    <div class="progress-bar progress-bar-primary" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 100%;">
                                                        100%
                                                    </div>
                                                </div>-->
                                            </td>
                                            <td class="actions">
                                            <a href="apiextrates.php?acriss=<?php echo $row["api_ext_rate_acriss"];?>"
                                                class="on-default edit-row"><i class="fa fa-eye"></i></a>
</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>
        (function ($) {

            'use strict';

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


                var table = $table.dataTable({
                    
                    "pageLength": 30,
                    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');?>