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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];

$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$vouch = $_GET['vouchno'];
$imglogo = $_GET["image"];

$cond = '';
$lcond = '';

$maindb = 'hotelslmain';
$trandb = 'hotelsltran';

$saleflag = $_GET["sale"];

$formname = "Hotel Voucher";

if ($saleflag == 'Y') {
    if ($getdata['approve'] != 1) {
        $formname = "Hotel Voucher";
    }
}

$getqry = mysqli_query($conn, "SELECT m.*, DATE_FORMAT(m.`vouchdt`, '%d-%m-%Y')as mydt, a.accode,a.name AS customer FROM `$maindb`m
                                LEFT JOIN accmast a ON a.accode = m.customer
                                WHERE m.vouchno='$vouch' ORDER BY m.`vouchno`") or die(mysqli_error($conn));
$getdata = mysqli_fetch_array($getqry);

$getcomp2 = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
$comp2 = mysqli_fetch_array($getcomp2);

$compname = $comp2['compname'];
$headerimg = $comp2['reportheadimg'];
$footerimg = $comp2['footerimg'];

$title = "HOTEL VOUCHER_FD#$vouch FOR $fullname";

include("includes/print_linkshead.php");
?>

<!DOCTYPE HTML>
<html lang="en-US">
    <style>
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            font: 12pt "Arial";
        }

        @media print {
            .noprint {
                display: none;
            }
        }

        * {
            box-sizing: border-box;
            -moz-box-sizing: border-box;
        }

        .page {
            width: 210mm;
            min-height: 297mm;
            padding: 4mm;
            margin: 10mm auto;
            border: 1px #D3D3D3 solid;
            border-radius: 5px;

        }

        .subpage {
            padding: 0cm;
            height: 288mm;
            outline: 2cm #ffffff solid;
        }

        @page {
            size: A4;
            margin: 0;
        }

        @media print {
            .noPrint {
                display: none;
            }

            html,
            body {
                width: 210mm;
                height: 297mm;
            }

            .page {
                margin: 0;
                border: initial;
                border-radius: initial;
                width: initial;
                min-height: initial;
                box-shadow: initial;
                background: initial;
                page-break-after: always;
            }
        }

        .numeric {
            text-align: right;
        }

        .rnone {
            border-right: none;
        }

        .lnone {
            border-left: none;
        }

        .outer {
            width: 100%;
            border-collapse: collapse;
            border: 1px solid black;
        }

        .center {
            text-align: center;
        }

        .B {
            padding-left: 15px;
        }


        .d {
            border-collapse: inherit;
        }


        .w {
            width: 40%;
        }

        hr.sk1 {
            border: 2px solid black;
        }

        .skdiv {
            width: 50%;
            margin: auto;
            margin-top: -20px;
            margin-bottom: -20px;
        }

        .font{
            font-size:14px;
        }

        .color{
            color: black !important;;
        }
    </style>
</head>


<body id="main_container">
    <div class="book tablerep">

        <button onclick="window.print();return false;" class="btn btn-primary noPrint" style="width: 150px;height:35px;background-color: #A0B1BA;color:white;">Print</button>
        &nbsp;&nbsp;&nbsp;
        <button class="btn btn-primary goBack noPrint" onclick="window.close()" style="width: 150px;height:35px;background-color: white;color:#A0B1BA;padding-left: 1%">Go Back</button>
        <div class="page">
            <div class="">

                <?php if ($imglogo == "Yes") { ?>
                    <div class="skdiv">
                        <img style="height:auto;width:100%;" src="<?php echo $headerimg; ?>">
                    </div>
                <?php } ?>

                <br>

                <div class="row" style="text-align:center;background-color:<?= $vheadcolor; ?>;height:35px">
                    <p style="font-size: 20px;color:white;margin-top:5px">
                        <?php echo $formname ?>
                    </p>
                </div>


                <table class=" table table-borderless" style="width:100%">
                    <tbody>

                        <tr width="100%">
                            <td class="font color">Voucher &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
                                <b><?php echo $getdata['vouchno']; ?></b>
                            </td>
                            <td class="font color"> Date &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 
                                <b><?php echo $getdata['mydt']; ?></b>
                            </td>
                        </tr>

                        <tr width="100%">
                            <td colspan="2" class="font color">Agent / Customer :
                                <b><?php echo $getdata['customer']; ?></b>
                            </td>
                        </tr>
                        <tr width="100%">
                            <td class="font color">Guest Name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
                                <b><?php echo $getdata['prname']; ?></b>
                            </td>
                            <td class="font color"> Nationality : 
                                <b><?php echo $getdata['nationality']; ?></b>
                            </td>
                        </tr>

<!-- <tr width="100%">
    <td class="font color">Company &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
        <b><?php echo $fetcompany['name']; ?></b>
    </td>
    <td class="font color"> Customer Status : 
        <b><?php echo $getdata['custstatus']; ?></b>
    </td>
</tr> -->
                    </tbody>
                </table>

                <div>
                    <table style="width:100%" class="table table-bordered">
                        <tr class="mySearchTr" style="font-size: 13px;">
                            <th style="width:8%">City</th>
                            <th style="width:10%">Check In</th>
                            <th style="width:11%">Check Out</th>
                            <th style="width:20%">Hotel Name</th>
                            <th style="width:5%">Nights</th>
                            <th style="width:6%"># Pax</th>
                            <th style="width:7%">Meal Type</th>
                            <!-- <th style="width:10%">Week Day Night</th>
                            <th style="width:10%">Week End Night</th> -->
                            <!-- <th style="width:10%">Room Category</th> -->
                            <th style="width:7%">Type</th>
                            <th style="width:9%">View</th>
                            <th width="4%" class='text-right'>Qty.</th>

                            <th style="width:8%">CNF No.</th>
                            <th style="width:10%">Remarks</th>
                        </tr>

                        <?php
                        $ctr = 0;
                        $ctab = 0;
                        $totqty = 0;

                        $gettran = mysqli_query($conn, "SELECT t.*,DATE_FORMAT(`checkin`, '%d-%m-%Y') AS checkin, DATE_FORMAT(`checkout`, '%d-%m-%Y') AS checkout, 
                        c.code, c.name AS city, h.code, h.hotelnm AS hotel, r.code, r.name AS room, n.code, n.name AS rtype, v.name as viewname FROM `$trandb` t
                        LEFT JOIN city c     ON c.code = t.city 
                        LEFT JOIN hotels h   ON h.code = t.hotelnm 
                        LEFT JOIN roomcatg r ON r.code = t.roomcatg
                        LEFT JOIN roomtype n ON n.code = t.roomtype
                        LEFT JOIN roomview v ON v.code = t.roomview
                        WHERE vouchno ='$getdata[vouchno]' ORDER BY srno") or die(mysqli_error($conn));
                        while ($fettran = mysqli_fetch_array($gettran)) {

                            $mmeal = mysqli_query($conn, "SELECT code,name FROM $zroot.mealtype WHERE code ='$fettran[mealtype]'") or die(mysqli_error($conn));
                            $tmeal = mysqli_fetch_array($mmeal);

                            echo "<tr style='font-size: 11px;'>";
                            echo "<td>$fettran[city]</td>";
                            echo "<td>$fettran[checkin]</td>";
                            echo "<td>$fettran[checkout]</td>";
                            echo "<td>$fettran[hotel]</td>";
                            echo "<td style='text-align: right;'>$fettran[nonights]</td>";
                            echo "<td style='text-align: right;'>$fettran[hotelpax]</td>";
                            echo "<td style='font-size:10px'>$tmeal[name]</td>";
                            echo "<td>$fettran[rtype]</td>";
                            echo "<td>$fettran[viewname]</td>";
                            echo "<td style='text-align:right'>$fettran[qty]</td>";
                            echo "<td style='text-align: right;'>$fettran[cnfno]</td>";
                            echo "<td>$fettran[remarks]</td>";
                            echo "</tr>";
                            $ctab = $ctab + 1;
                        }
                        if ($ctab < 6) {
                            for ($i = $ctab; $i < 7; $i++) {
                                ?>
                                <tr style="height:30px;">
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                    <td></td>
                                </tr>
                                <?php
                            }
                        }
                        ?>

                    </table>
                </div>

            </div>


            <div style="border:1px solid black">

                <table>
                    <tr>
                        <td style="text-align: left;"><b>NOTES</b></td>
                    </tr>
                    <tr>
                        <td style="text-align: left;">Emergency Contact details: <?= $comp2['emergencyno']; ?>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align: left;">Extra-person charges may apply</td>
                    </tr>

                </table>

            </div>
            <tr>
                <td style="text-align: left;">&nbsp;</td>
            </tr>

            <?php
            require("includes/dbconnect.php");
            ?>

            <div>
                <table style="width:100%">
                    <tr style="width:100%">
                        <td style="width:50%;text-align: left;font-size:14px;">Helpline Makkah : <b>
                                <?= "$comp2[helpmak]"; ?>
                            </b></td>
                        <td style="width:50%;text-align: right;font-size:14px;">Helpline Medina : <b>
                                <?= "$comp2[helpmed]"; ?>
                            </b></td>
                    </tr>
                </table>
            </div>
            <div class="row" style="background-color:<?= $vheadcolor; ?>  !important;height:35px">
                <table class="border" style="height:35px;width:100%">
                    <tr>
                        <td width="35%" class="padd">&nbsp;&nbsp;</td>
                        <td width="30%" class="padd" style="text-align: center;"></td>
                        <td width="35%" class="right padd" style="text-align: center;"></td>
                    </tr>
                </table>
            </div>
            <br>

            <?php if ($imglogo == "Yes") { ?>
                <div class="row" style="text-align:center;background-color:lightgrey !important;">
                    <?php
                    $ztel = $comp2['htel'];
                    $zadd = $comp2["hoadd1"] . " " . $comp2["hoadd2"] . " " . $comp2["hoadd3"] . " " . $comp2["hocity"] . " " . $comp2["hopin"];
                    ?>
                    <b> Regd. Ofc. </b><span style="font-family: verdana;font-size: 14px"><?= $zadd ?></span> <b>Tel.:<?= $ztel ?></b>
                </div>

                <div class="row" style="background-color:<?= $vheadcolor; ?>  !important;height:35px">
                    <table class="border" style="height:35px;width:100%">
                        <tr>
                            <td width="35%" class="padd">&nbsp;&nbsp;<b style="font-size: 14px;color:white !important"><?php echo $comp2['compname']; ?></b></td>
                            <td width="30%" class="padd" style="text-align: center;"><b style="font-size: 12px;color:white !important">Email : <?php echo $comp2['email']; ?></b></td>
                            <td width="35%" class="right padd" style="text-align: center;"><b style="font-size: 12px;color:white !important">Website :&nbsp;<?php echo $comp2['website']; ?></b></td>
                        </tr>
                    </table>
                </div>
            <?php } ?>

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

</body>

</html>