<?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['hotel'];
$roomcatg = $_REQUEST['roomcatg'];
$checkin = $_REQUEST['checkin'];
$checkout = $_REQUEST['checkout'];
$roomtype = $_REQUEST['roomtype'];

switch ($roomtype) {
    case "1":
        $rmtype = "Single";

        break;
    case "2":
        $rmtype = "Double";

        break;
    case "3":
        $rmtype = "Triple";

        break;
    case "4":
        $rmtype = "Quad";

        break;
    case "5":
        $rmtype = "Quint";

        break;
    case "6":
        $rmtype = "Suite";

        break;

    default:
        break;
}

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

$ghot = mysqli_query($conn, "SELECT code,hotelnm FROM `hotels` where code = '$hotelnm'") or die(mysqli_error($conn));
$fhot = mysqli_fetch_array($ghot);

if ($checkin != "") {
    $getpmain = mysqli_query($conn, "SELECT * FROM `roomsacn` where `bookdate`='$checkin' and city='$city' and checkin ='1' and hotel='$hotelnm' and roomtype='$roomtype'") or die(mysqli_error($conn));
} elseif ($checkout != "") {
    $getpmain = mysqli_query($conn, "SELECT * FROM `roomsacn` where `bookdate`='$checkout' and city='$city' and checkout ='1' and hotel='$hotelnm' and roomtype='$roomtype'") or die(mysqli_error($conn));
} else {
    echo "<script>window.close();</script>";
}

include("includes/linkshead.php");


// $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) {
?>
<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;

    }

    .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;
    }

    .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;
    }
</style>





<body>
    <div class="container">
        <?php include("includes/head_rep.php"); ?>
        <div class="row">
            <div class="col-lg-12">

                <p> City : <b style="font-size:19px;color:green"> <?php echo $fetg['name']; ?></b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

                    <?php if ($checkin != "") { ?>
                        Check In Date: <b style="font-size:19px;color:green">  <?php echo date('d-m-Y', strtotime($checkin)); ?> </b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><br>
                    <?php
                    } if ($checkout != "") {
                        $nchkout = date('d-m-Y', strtotime($checkout . ' + 1 days'));
                        ?>
                        Check Out Date: <b style="font-size:19px;color:red">  <?php echo date('d-m-Y', strtotime($nchkout)); ?> </b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br><br>
                    <?php } ?>
                    Hotel : <b style="font-size:19px;color:green">  <?php echo $fhot['hotelnm']; ?> </b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                    Room Type : <b style="font-size:19px;color:green">  <?php echo $rmtype; ?> </b>
                </p>
                <table class="table table-condensed table-bordered">
                    <tr class="mySearchTr">
                        <th width="10%">Source</th>
                        <th width="10%">Voucher No.</th>
                        <th width="10%">Date</th>
                        <th width="30%">Pax Name</th>
                        <th width="10%">Mobile</th>
                        <th width="10%">Dept. Date</th>
                        <th width="10%" class="text-right">Room Qty.</th>
                        <th width="10%" class="text-right">Net Amount</th>
                    </tr>
                    <?php
                    $ctr = 1;
                    while ($pmain = mysqli_fetch_array($getpmain)) {

                        $source = $pmain['source'];
                        $vouchno = $pmain['vouchno'];

                        $rmqty = abs($pmain['qty']);

                        if ($source == "BOOK") {
                            $getdata = mysqli_query($conn, "Select * from bookform where vouchno='$vouchno'");
                            $fetdata = mysqli_fetch_array($getdata);
                            $vouchdt = date("d-m-Y", strtotime($fetdata['vouchdt']));
                            $paxname = $fetdata['fname'];
                            $mvouch = $fetdata["regnno"];

                            $url = "bookform.php?vouchno=$vouchno&mode=edit";
                        $depdate = date("d-m-Y", strtotime($fetdata['depdate']));
                        } else {
                            $getdata = mysqli_query($conn, "Select * from pax where vouchno='$vouchno'");
                            $fetdata = mysqli_fetch_array($getdata);
                            $vouchdt = date("d-m-Y", strtotime($fetdata['date']));
                            $paxname = $fetdata["name"] . " " . $fetdata["midname"] . " " . $fetdata["surnname"];
                            $mvouch = $vouchno;
                            $url = "fit_ent.php?paxid=$mvouch&mode=edit";
                        $depdate = date("d-m-Y", strtotime($fetdata['deptdate']));
                        }




                        Echo "<tr class='clickable-row2' data-href='$url' target='_blank' >";
                        Echo "<td>$source</td>";
                        Echo "<td>$mvouch</td>";
                        Echo "<td>$vouchdt</td>";
                        Echo "<td>$paxname</td>";
                        Echo "<td>$fetdata[mobile]</td>";
                        Echo "<td >$depdate</td>";
                        Echo "<td class='text-right'>$rmqty</td>";
                        Echo "<td class='text-right'>$fetdata[netamt]</td>";
                        Echo "</tr>";
                        $tqty = $tqty + $rmqty;
                        $tnetamt = $tnetamt + $fetdata['netamt'];
                        $ctr++;
                    }
                    Echo "<tr>";
                    Echo "<td></td>";
                    Echo "<td></td>";
                    Echo "<td></td>";
                    Echo "<td></td>";
                    Echo "<td></td>";
                    Echo "<td class='text-right'><b>Total</b></td>";
                    Echo "<td class='text-right'><b>$tqty</b></td>";
                    Echo "<td class='text-right'><b>$tnetamt</b></td>";
                    Echo "</tr>";
                    ?>
                </table>
            </div>
        </div>
    </div>

    <?php include("includes/linksfoot.php"); ?>
</body>
<?php
// } else {
//     echo "<b style='color:red'>No Data as per your Requirement</b>";
// }
?>