<?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 = '';
$formname = "Ticket & Airline Voucher";

$maindb = 'pax';
$accdb = 'actran';
$fooddb = 'foodent';
$launddb = 'laundent';
$visadb = 'visaent';
$tiktdb = 'tiktent';
$transdb = 'transent';
$tranpurchdb = 'tranpurch';

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`date`, '%d-%m-%Y')as mydt   FROM `$maindb` WHERE vouchno='$vouch' ORDER BY `vouchno`") or die(mysqli_error($conn));

$getdata = mysqli_fetch_array($getqry);

$getagent = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE accode='$getdata[agent]'") or die(mysqli_error($conn));
$fetagent = mysqli_fetch_array($getagent);
$agentname = $fetagent['name'];
$fullname = $getdata['surname'] . " " . $getdata['name'] . " " . $getdata['midname'];
if ($agentname != "") {
    $paxname = $agentname;
} else {
    $paxname = $fullname;
}

$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 = "TICKET VOUCHER_PUTK#$vouch FOR $fullname";

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

<!DOCTYPE HTML>
<html lang="en-US">
<style>
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        /*background-color: #FAFAFA;*/
        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;
        /*background: white;*/

    }

    .subpage {
        padding: 0cm;
        /*        border: 1px solid;*/
        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;
    }

    .table1>tbody>tr>td {
        padding: 2px;
        line-height: 1.42857143;
        /* vertical-align: top; */
        /* border-top: 1px solid #ddd; */
    }
</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=" table1 table-borderless" style="width:100%">

                    <tbody>

                        <tr width="100%">
                            <td><b style="font-size:17px;color:<?= $vheadcolor; ?> ">
                                 PUTK# <?php echo $getdata['vouchno']; ?>   </b></td>
                        </tr>

                        <tr width="100%">
                            <td><span style="padding-right:48px"> Date </span> : <b>
                                    <?php echo $getdata['mydt']; ?>  </b></td>
                        </tr>

                        <?php if ($agentname != "") { ?>
                            <tr width="100%">

                                <td><span style="padding-right:60px"> To </span> : <b>
                                        <?php echo $paxname; ?>  </b></td>
                                <td style="width: 40%;text-align:right"></td>
                            </tr>
                        <?php } ?>

                        <tr width="100%">
                            <?php $fullname = $getdata['surname'] . " " . $getdata['name'] . " " . $getdata['midname']; ?>
                            <td><span style="padding-right:5px"> Guest Name </span> : <b>
                                    <?php echo $fullname; ?>  </b></td>
                            <td style="width: 40%;text-align:left"><span style="padding-right:5px"> Staff</span> : <b>
                                    <?php
                                    if ($getdata["edituser"] != '') {
                                        $user = strtoupper($getdata["edituser"]);
                                    } else {
                                        $user = strtoupper($getdata["adduser"]);
                                    }
                                    echo $user;
                                    ?>
                                </b></td>
                        </tr>
                        <tr width="100%">
                            <td><span style="padding-right:16px"> Nationality </span> : <b>
                                    <?php echo $getdata['nationality']; ?> </b></td>
                        </tr>
                    </tbody>
                </table>

                <br>

                <div>
                    <table style="width:100%" class="table table-bordered">
                        <tr class="mySearchTr" style="font-size: 13px; ">
                            <th style="width: 7%">From</th>
                            <th style="width: 7%;">To</th>
                            <th style="width: 10%;">Airline</th>
                            <th style="width: 8%;">Ticket No.</th>
                            <th style='width: 7%'>Flight No.</th>
                            <th style='width: 10%'>PNR</th>
                            <th style='width: 10%'>Date</th>
                            <th style='width: 5%' class="text-right">No. Pax</th>
                        </tr>

                        <?php
                        $ctr = 0;
                        $ctab = 0;
                        $totqty = 0;
                        $gettiktdtl = mysqli_query($conn, "SELECT *,DATE_FORMAT(`travdate`,'%d-%m-%Y')as travdate from `$tiktdb` where vouchno ='$getdata[vouchno]' order by srno") or die(mysqli_error($conn));

                        while ($fettikt = mysqli_fetch_array($gettiktdtl)) {
                            $getho = mysqli_query($conn, "SELECT `code`,`name` FROM `airline` where code='$fettikt[airline]'") or die(mysqli_error($conn));
                            $fetho = mysqli_fetch_array($getho);

                            echo "<tr style='font-size: 11px;'>";
                            echo "<td style=''>$fettikt[fromdes]</td>";
                            echo "<td>$fettikt[todes]</td>";
                            echo "<td>$fetho[name]</td>";
                            echo "<td>$fettikt[ticketno]</td>";
                            echo "<td style=''>$fettikt[flightno]</td>";
                            echo "<td style=''>$fettikt[pnrno]</td>";
                            echo "<td style='font-size:10px'>$fettikt[travdate]</td>";
                            echo "<td style='text-align:right'>$fettikt[nopax]</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>
                                </tr>
                        <?php
                            }
                        }
                        ?>

                        <!-- <tr>
                            <td style="text-align: left;"> <b></b></td>
                            <td style="text-align: right;"></td>
                            <td style="text-align: left;"> <b></b></td>
                            <td style="text-align: left;"> <b></b></td>
                            <td style="text-align: left;"> <b></b></td>
                            <td style="text-align: left;"> <b></b></td>
                            <td style="text-align: right;"> <b>Total</b></td>
                            <td style="text-align: right;"> <b>
                                    <?= $getdata['tiktpax'] ?>
                                </b></td>
                        </tr> -->
                    </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;">Incase of No show full amount will be charged</td>
                    </tr>
                    <tr>
                        <td style="text-align: left;">Check-in time: 16:00 & Check-out time: 12:00</td>
                    </tr>
                    <tr>
                        <td style="text-align: left;">Your booking is confirmed. However, your name will be listed in
                            the hotel’s reservation system closer to your arrival date.</td>
                    </tr>
                    <tr>
                        <td style="text-align: left;">Extra-person and/or Extra-bed charges may apply and vary depending
                            on property policy.</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>