<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');


$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
$compcd = $_SESSION["comp_" . $dbname];

$zroot = $_SESSION["zdir"];

mysqli_select_db($conn, $zdb);

$city = $_REQUEST['city'];
$hotelnm = $_REQUEST['hotelnm'];
$roomcatg = $_REQUEST['roomcatg'];
$checkin = $_REQUEST['checkin'];
$checkout = $_REQUEST['checkout'];

if (!empty($city)) {
    $citycond = "AND a.`city`='$city'";
}
if (!empty($hotelnm)) {
    $hotelnmcond = "AND a.`hotel`='$hotelnm'";
}
if (!empty($roomcatg)) {
    $roomcatgcond = "AND a.`roomcatg`='$roomcatg'";
}
// if (empty($checkin)) {
//     browse("CheckIn Date cannot be empty");
//     echo "<script>window.location();</script>";
// }
// if (empty($checkout)) {
//     browse("CheckOut Date cannot be empty");
//     echo "<script>window.location();</script>";
// }

$gdet = mysqli_query($conn, "SELECT code,name FROM `city` where code = '$city'") or die(mysqli_error($conn));
$fetg = mysqli_fetch_array($gdet);


// $gdetails = mysqli_query($conn, "SELECT sum(qty)as qty  FROM `roomsacn` where vouchno != '' 
//                                  $citycond $hotelnmcond $roomcatgcond AND `bookdate`>='$checkin' AND `bookdate`<='$checkout' 
//                                  group by city,hotel,roomcatg,roomtype ") or die(mysqli_error($conn));
// if (mysqli_num_rows($gdetails) > 0) {
include("includes/linkshead.php");
?>
<style type="text/css">
    .rmctg {
        /*        background: rgb(255,255,255);
                background: linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(34,161,213,1) 100%); */
        /*        background: #B19CD9;*/
        text-transform: uppercase;

    }

    .stick{
        font-size: 20px;
    }

    .rmtp {
        background: lightyellow; 
        /*background: #40E0D0;*/
        /*         background: radial-gradient(circle, rgba(148, 187, 233, 1) -50000%, rgba(190, 190, 190, 1) 100%); 
                 background: radial-gradient(circle, rgba(238,174,202,1) 0%, rgba(148,187,233,1) 100%); */


    }

    /*CSS*/

    .styled-table {
        border-collapse: collapse;
        margin: 25px 0;
        font-size: 0.9em;
        font-family: sans-serif;
        min-width: 400px;
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
        border-radius: 6px 6px 0 0;
        overflow: hidden;
    }

    .styled-table thead tr {
        /*background-color: lightgray;*/
        background: linear-gradient(91.9deg, rgb(75, 207, 250) 6.3%, rgb(25, 159, 249) 98.9%);

        /* background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(124,123,136,1) 0%, rgba(255,205,0,0.7962535355939251) 0%, rgba(163,163,163,1) 60%);  */
        color: #ffffff;
        text-align: left;
    }

    .sknew {
        /*background: linear-gradient(to top right, #33ccff 0%, #ff99cc 100%);*/
        /*margin-left: 1%;*/
        color: black;
        font-family: verdana;
        font-size: 14px;
    }

    .styled-table th,
    .styled-table td {
        padding: 12px 15px;
    }

    .styled-table tbody tr {
        border-bottom: 1px solid #dddddd;
    }

    .styled-table tbody tr:nth-of-type(even) {
        background-color: #f3f3f3;
    }

    .styled-table tbody tr:last-of-type {
        border-bottom: 2px solid #c2b47e;
    }

    .styled-table tbody tr.active-row {
        font-weight: bold;
        color: grey;
    }
    @media print{
        .noPrint{
            display: none;
        }
    }

    @media screen {
        .headnw { display:none; }
    }
</style>


<div class="container">
    <div class="headnw">

        <?php
        include("includes/head_rep.php");
        ?>
    </div>


        <button onclick="window.print();return false;" class="btn btn-primary noPrint" style="text-align: right;font-weight:bold;">Print</button>
        <br>
    <p> City : <b style="font-size:19px;color:green"> <?php echo $fetg['name']; ?></b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </b> 
    <div class="row">
        <div class="col-lg-6">
            <b style="font-size:19px;color:green"> CHECK IN</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </b> <br>

            Date: <b style="font-size:19px;color:green">  <?php echo date('d-m-Y', strtotime($checkin)); ?> </b> &nbsp;&nbsp; &nbsp; </p>
            <?php // include("includes/head_rep.php");  ?>
            <table style="background: white;width: 100%" class="table table-bordered styled-table newtab">
                <thead style="background: #64CCFC !important ;">
                    <tr>

                        <th style="width:40%;font-size: 20px;" class="stick" align="center" >Hotels / Room Type</th>
                        <th style="width:4%" class="stick text-center">Single</th>
                        <th style="width:4%" class="stick text-center">Double</th>
                        <th style="width:4%" class="stick text-center">Triple</th>
                        <th style="width:4%" class="stick text-center">Quad</th>
                        <th style="width:4%" class="stick text-center">Quint</th>
                        <th style="width:4%" class="stick text-center">Suite</th>
                        <!--<th style="width:4%" class="stick text-right">Total</th>-->
                        <!--<th style="width:4%" class="stick text-right">Total</th>-->

                    </tr>
                </thead>
                <tbody>

                    <?php
                    $rm1 = $rm2 = $rm3 = $rm4 = $rm5 = $rm6 = 0;
                    $colr1 = $colr2 = $colr3 = $colr4 = $colr5 = $colr6 = 0;
//            $getroomcatg = mysqli_query($conn, "SELECT roomcatg FROM `roomsacn` where `bookdate`>='$checkin' AND `bookdate`<='$checkout' $roomcatgcond  $citycond $hotelnmcond  group by roomcatg having sum(qty) > 0  order by roomcatg") or die(mysqli_error($conn));
                    $gethotl = mysqli_query($conn, "SELECT a.*,b.hotelnm FROM `roomsacn` a, hotels b where a.`bookdate`='$checkin' and a.checkin ='1'
                                               and a.hotel=b.code $citycond $hotelnmcond $roomcatgcond group by hotel") or die(mysqli_error($conn));
                    while ($fethotl = mysqli_fetch_array($gethotl)) {

                        $getrm1 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$checkin' and checkin ='1' and hotel='$fethotl[hotel]' and roomtype='1'") or die(mysqli_error($conn));
                        $fetrm1 = mysqli_fetch_array($getrm1);
                        $rm1 = abs($fetrm1['tqty']);

                        $getrm2 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$checkin' and checkin ='1' and hotel='$fethotl[hotel]' and roomtype='2'") or die(mysqli_error($conn));
                        $fetrm2 = mysqli_fetch_array($getrm2);
                        $rm2 = abs($fetrm2['tqty']);

                        $getrm3 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$checkin' and checkin ='1' and hotel='$fethotl[hotel]' and roomtype='3'") or die(mysqli_error($conn));
                        $fetrm3 = mysqli_fetch_array($getrm3);
                        $rm3 = abs($fetrm3['tqty']);

                        $getrm4 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$checkin' and checkin ='1' and hotel='$fethotl[hotel]' and roomtype='4'") or die(mysqli_error($conn));
                        $fetrm4 = mysqli_fetch_array($getrm4);
                        $rm4 = abs($fetrm4['tqty']);

                        $getrm5 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$checkin' and checkin ='1' and hotel='$fethotl[hotel]' and roomtype='5'") or die(mysqli_error($conn));
                        $fetrm5 = mysqli_fetch_array($getrm5);
                        $rm5 = abs($fetrm5['tqty']);

                        $getrm6 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$checkin' and checkin ='1' and hotel='$fethotl[hotel]' and roomtype='6'") or die(mysqli_error($conn));
                        $fetrm6 = mysqli_fetch_array($getrm6);
                        $rm6 = abs($fetrm6['tqty']);

                        if ($rm1 > 0) {
                            $colr1 = "green;font-size:20px";
                        } else {
                            $colr1 = "blue;font-size:15px";
                        }
                        if ($rm2 > 0) {
                            $colr2 = "green;font-size:20px";
                        } else {
                            $colr2 = "blue;font-size:15px";
                        }
                        if ($rm3 > 0) {
                            $colr3 = "green;font-size:20px";
                        } else {
                            $colr3 = "blue;font-size:15px";
                        }
                        if ($rm4 > 0) {
                            $colr4 = "green;font-size:20px";
                        } else {
                            $colr4 = "blue;font-size:15px";
                        }
                        if ($rm5 > 0) {
                            $colr5 = "green;font-size:20px";
                        } else {
                            $colr5 = "blue;font-size:15px";
                        }
                        if ($rm6 > 0) {
                            $colr6 = "green;font-size:20px";
                        } else {
                            $colr6 = "blue;font-size:15px";
                        }

                        echo "<tr class='rmctg'>";
                        echo "<td class='sknew'>$fethotl[hotelnm]</th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=1&checkin=$checkin' target='_blank'><b style='color:$colr1'>$rm1</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=2&checkin=$checkin' target='_blank'><b style='color:$colr2'>$rm2</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=3&checkin=$checkin' target='_blank'><b style='color:$colr3'>$rm3</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=4&checkin=$checkin' target='_blank'><b style='color:$colr4'>$rm4</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=5&checkin=$checkin' target='_blank'><b style='color:$colr5'>$rm5</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=6&checkin=$checkin' target='_blank'><b style='color:$colr6'>$rm6</b></a></th>";
                        echo "</tr>";
                    }
                    ?>

                </tbody>
            </table>

        </div>

        <div class="col-lg-6">
            <b style="font-size:19px;color:red"> CHECK OUT</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  </b> <br>

            Date: <b style="font-size:19px;color:red">  <?php echo date('d-m-Y', strtotime($checkin)); ?> </b> &nbsp;&nbsp; &nbsp; </p>
            <?php // include("includes/head_rep.php");  ?>
            <table style="background: white;width: 100%" class="table table-bordered styled-table newtab">
                <thead style="background: #64CCFC !important ;">
                    <tr>

                        <th style="width:40%;font-size: 20px;" class="stick" align="center" >Hotels / Room Type</th>
                        <th style="width:4%" class="stick text-center">Single</th>
                        <th style="width:4%" class="stick text-center">Double</th>
                        <th style="width:4%" class="stick text-center">Triple</th>
                        <th style="width:4%" class="stick text-center">Quad</th>
                        <th style="width:4%" class="stick text-center">Quint</th>
                        <th style="width:4%" class="stick text-center">Suite</th>
                        <!--<th style="width:4%" class="stick text-right">Total</th>-->
                        <!--<th style="width:4%" class="stick text-right">Total</th>-->

                    </tr>
                </thead>
                <tbody>

                    <?php
                    $bckdate = date('Y-m-d', strtotime($checkin . ' - 1 days'));

                    $orm1 = $orm2 = $orm3 = $orm4 = $orm5 = $orm6 = 0;
                    $ocolr1 = $ocolr2 = $ocolr3 = $ocolr4 = $ocolr5 = $ocolr6 = 0;
//            $getroomcatg = mysqli_query($conn, "SELECT roomcatg FROM `roomsacn` where `bookdate`>='$checkin' AND `bookdate`<='$checkout' $roomcatgcond  $citycond $hotelnmcond  group by roomcatg having sum(qty) > 0  order by roomcatg") or die(mysqli_error($conn));
                    $gethotlo = mysqli_query($conn, "SELECT a.*,b.hotelnm FROM `roomsacn` a, hotels b where a.`bookdate`='$bckdate' and a.checkout ='1'
                                               and a.hotel=b.code $citycond $hotelnmcond $roomcatgcond group by hotel") or die(mysqli_error($conn));

                    while ($fethotl = mysqli_fetch_array($gethotlo)) {

                        $getrm1 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$bckdate' and checkout ='1' and hotel='$fethotl[hotel]' and roomtype='1'") or die(mysqli_error($conn));
                        $fetrm1 = mysqli_fetch_array($getrm1);
                        $orm1 = abs($fetrm1['tqty']);

                        $getrm2 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$bckdate' and checkout ='1' and hotel='$fethotl[hotel]' and roomtype='2'") or die(mysqli_error($conn));
                        $fetrm2 = mysqli_fetch_array($getrm2);
                        $orm2 = abs($fetrm2['tqty']);

                        $getrm3 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$bckdate' and checkout ='1' and hotel='$fethotl[hotel]' and roomtype='3'") or die(mysqli_error($conn));
                        $fetrm3 = mysqli_fetch_array($getrm3);
                        $orm3 = abs($fetrm3['tqty']);

                        $getrm4 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$bckdate' and checkout ='1' and hotel='$fethotl[hotel]' and roomtype='4'") or die(mysqli_error($conn));
                        $fetrm4 = mysqli_fetch_array($getrm4);
                        $orm4 = abs($fetrm4['tqty']);

                        $getrm5 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$bckdate' and checkout ='1' and hotel='$fethotl[hotel]' and roomtype='5'") or die(mysqli_error($conn));
                        $fetrm5 = mysqli_fetch_array($getrm5);
                        $orm5 = abs($fetrm5['tqty']);

                        $getrm6 = mysqli_query($conn, "SELECT roomtype, sum(qty) as tqty FROM `roomsacn` where `bookdate`='$bckdate' and checkout ='1' and hotel='$fethotl[hotel]' and roomtype='6'") or die(mysqli_error($conn));
                        $fetrm6 = mysqli_fetch_array($getrm6);
                        $orm6 = abs($fetrm6['tqty']);

                        if ($orm1 > 0) {
                            $ocolr1 = "green;font-size:20px";
                        } else {
                            $ocolr1 = "blue;font-size:15px";
                        }
                        if ($orm2 > 0) {
                            $ocolr2 = "green;font-size:20px";
                        } else {
                            $ocolr2 = "blue;font-size:15px";
                        }
                        if ($orm3 > 0) {
                            $ocolr3 = "green;font-size:20px";
                        } else {
                            $ocolr3 = "blue;font-size:15px";
                        }
                        if ($orm4 > 0) {
                            $ocolr4 = "green;font-size:20px";
                        } else {
                            $ocolr4 = "blue;font-size:15px";
                        }
                        if ($orm5 > 0) {
                            $ocolr5 = "green;font-size:20px";
                        } else {
                            $ocolr5 = "blue;font-size:15px";
                        }
                        if ($rm6 > 0) {
                            $ocolr6 = "green;font-size:20px";
                        } else {
                            $ocolr6 = "blue;font-size:15px";
                        }

                        echo "<tr class='rmctg'>";
                        echo "<td class='sknew'>$fethotl[hotelnm]</th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=1&checkout=$bckdate' target='_blank'><b style='color:$ocolr1'>$orm1</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=2&checkout=$bckdate' target='_blank'><b style='color:$ocolr2'>$orm2</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=3&checkout=$bckdate' target='_blank'><b style='color:$ocolr3'>$orm3</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=4&checkout=$bckdate' target='_blank'><b style='color:$ocolr4'>$orm4</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=5&checkout=$bckdate' target='_blank'><b style='color:$ocolr5'>$orm5</b></a></th>";
                        echo "<td class='text-center'><a href='chekin_details.php?city=$city&hotel=$fethotl[hotel]&roomtype=6&checkout=$bckdate' target='_blank'><b style='color:$ocolr6'>$orm6</b></a></th>";
                        echo "</tr>";
                    }
                    ?>

                </tbody>
            </table>

        </div>
    </div>
</div>