<?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"];
$zcomp = $_SESSION["comp_" . $dbname];

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

$vouch = $_GET['vouchno'];

$cond = '';
$lcond = '';
$formname = "Visa New Invoice";

$maindb = 'visanewmain';
// $accdb = 'actran';
// $fooddb = 'foodent';
// $launddb = 'laundent';
// $visadb = 'visaent';
// $tiktdb = 'tiktent';
$trandb = 'visanewtran';
// $tranpurchdb = 'tranpurch';

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%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[customer]'") or die(mysqli_error($conn));
$fetagent = mysqli_fetch_array($getagent);
$agentname = $fetagent['name'];


$paxname = $agentname;

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

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

$title = "INVOICE NO. $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: 290mm;
            padding: 2mm;
            margin: 5mm auto;
            border: 1px #D3D3D3 solid;
            border-radius: 2px;
            /*background: white;*/

        }

        .subpage {
            padding: 0cm;
            /*        border: 1px solid;*/
            height: 280mm;
            outline: 2cm #ffffff solid;
        }

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

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

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

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

        .f13 {
            font-size: 13px;
        }

        .f14 {
            font-size: 14px;
        }
    </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="">
                <div class="row" style="text-align:center;">
                    <img style="width:100%; height:155px;width:400px;margin-top: -20px;margin-bottom: -20px;" src="<?php echo $headerimg; ?>">
                </div>
                <br>

                <div class="row" style="text-align:center;background-color:<?= $vheadcolor; ?> !important;-webkit-print-color-adjust: exact;height:35px;;margin-left: -1%;width: 102%">
                    <p style="font-size: 20px;color:white;margin-top:5px;color:white !important;">
                        <?php echo $formname ?></p>
                </div>

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

                    <tbody>

                        <tr width="100%">
                            <td class="f14"><span style="padding-right:5px"> Invoice No. </span> : <b> <?php echo $getdata['vouchno']; ?></b></td>
                            <td class="f14"><span style="padding-right:15px"> Date </span> : <b> <?php echo $getdata['mydt']; ?></b></td>
                        </tr>

                        <?php if ($agentname != "") { ?>
                            <tr width="100%">
                                <td class="f14"><span style="padding-right:60px"> To </span> : <b> <?php echo $paxname; ?></b></td>
                            </tr>
                        <?php } ?>
                        <tr width="100%">
                            <?php $fullname = $getdata['surname'] . " " . $getdata['name'] . " " . $getdata['midname']; ?>
                            <td><span style="padding-right:42px"> Group </span> : <b>
                                    <?php echo $getdata['visagrpcode']; ?>
                                </b></td>

                        </tr>
                    </tbody>
                </table>
                <div>
                    <br>
                    <!-- <div>Ticket & Airline Details</div> -->
                    <table style="width:100%" class="table table-bordered">
                        <!-- <tr style="background-color:#2fbffe !important; -webkit-print-color-adjust: exact;"> -->
                        <tr class="mySearchTr" style="font-size: 13px; ">
                            <th style="width: 5%;-webkit-print-color-adjust:  exact;background-color:  <?= $vmidcolor; ?>  !important;color:white !important">Sr</th>
                            <th style="width: 20%;-webkit-print-color-adjust: exact;background-color:  <?= $vmidcolor; ?>  !important;color:white !important">Paxname</th>
                            <th style="width: 15%;-webkit-print-color-adjust: exact;background-color:  <?= $vmidcolor; ?>  !important;color:white !important">Passport</th>
                            <th style="width: 10%;-webkit-print-color-adjust: exact;background-color:  <?= $vmidcolor; ?>  !important;color:white !important">DOB</th>
                            <th style='width: 10%;-webkit-print-color-adjust: exact;background-color:  <?= $vmidcolor; ?>  !important;color:white !important'>DOI</th>
                            <th style='width: 10%;-webkit-print-color-adjust: exact;background-color:  <?= $vmidcolor; ?>  !important;color:white !important'>DOE</th>
                            <th style='width: 10%;-webkit-print-color-adjust: exact;background-color:  <?= $vmidcolor; ?>  !important;color:white !important'>Visa No</th>
                            <th style='width: 10%;-webkit-print-color-adjust: exact;background-color:  <?= $vmidcolor; ?>  !important;color:white !important'>Period</th>
                            <th style='width: 10%;-webkit-print-color-adjust: exact;background-color:  <?= $vmidcolor; ?>  !important;color:white !important'>Type</th>
                        </tr>

                        <?php
                        $ctr = 0;
                        $ctab = 0;
                        $totqty = 0;
                        $gettran = mysqli_query($conn, "Select *,DATE_FORMAT(`dob`,'%d-%m-%Y')as dob,DATE_FORMAT(`doi`,'%d-%m-%Y')as doi,
                                                        DATE_FORMAT(`doe`,'%d-%m-%Y')as doe from `$trandb` where vouchno ='$getdata[vouchno]' order by srno") or die(mysqli_error($conn));


                        while ($tran = mysqli_fetch_array($gettran)) {
                            $ctr++;

                            echo "<tr style='font-size: 11px;'>";
                            echo "<td style=''>$ctr</td>";
                            echo "<td>$tran[paxname]</td>";
                            echo "<td>$tran[ppno]</td>";
                            echo "<td>$tran[dob]</td>";
                            echo "<td>$tran[doi]</td>";
                            echo "<td>$tran[doe]</td>";
                            echo "<td>$tran[visano]</td>";
                            echo "<td>$tran[period]</td>";
                            echo "<td>$tran[type]</td>";
                            echo "</tr>";
                        }
                        ?>
                    </table>
                </div>
                <br>
                <table class="table table-bordered">
                    <tr>
                        <td style="width:50%">
                            <table style="width:100"></table>
                        </td>
                        <td style="width:50%">
                            <table style="width:100%" class="tecle table-bordered">

                                <?php
                                $netamt = $getdata['totamt'];
                                ?>

                                <tr>

                                    <td colspan="2" style="width:50%" class="text-right">
                                        <b style="font-size:18px;color:green;">Total INR</b>
                                    </td>
                                    <td style="width:50%" class="text-right">
                                        <b style="font-size:18px;color:green"><?= number_format($netamt, 2) ?></b>
                                    </td>
                                </tr>

                            </table>
                        </td>
                    </tr>
                </table>
                <p>Amount in Words : <?php echo rsword($netamt) ?></p>
                <!-- <p style="font-weight:bold">All Rates are mentioned in SAR. ( ROE : <?= $getdata['roe'] ?> )</p> -->

            </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>
                    <tr style="width:100%">
                        <td style="width:55%;text-align: left;padding-right:180px;font-size:14px;">Helpline Makkah : <b>
                                <?= "$comp2[helpmak]"; ?>
                            </b></td>
                        <td style="width:45%;text-align: right;font-size:14px;">Helpline Medina : <b>
                                <?= "$comp2[helpmed]"; ?>
                            </b></td>
                    </tr>
                </table>

            </div>
            <br>
            <div class="row" style="text-align:center;">
                <?php // if (file_exists($footerimg)) {  
                ?>
                <!--<img style="height: 60px;width: 763px;margin-top: -10px;" src="<?php echo $footerimg; ?>">-->
                <?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>-->
                <b> Regd. Ofc. </b><span style="font-family: verdana;font-size: 14px"><?= $zadd ?> Tel.:<?= $ztel ?></span>
            </div>

            <div class="row" style="background-color:<?= $vheadcolor; ?> !important;height:35px;width: 102%;margin-left: -1%;">
                <table style="width:98%">
                    <tr>
                        <td style="width:40%">
                            <p style="font-size: 15px;color:white !important;margin-top:5px;font-weight: bold;margin-left: 5px">
                                <?php echo $comp2['compname']; ?></p>
                        </td>
                        <td style="width:25%" align='center'>
                            <p style="font-size: 12px;color:white !important;margin-top:5px;font-weight: bold;">
                                Email : <?php echo $comp2['email']; ?></p>
                        </td>
                        <td style="width:25%;">
                            <p style="font-size: 12px;color:white !important;margin-top:5px;font-weight: bold;">
                                Website : <?php echo $comp2['website']; ?></p>
                        </td>
                    </tr>
                </table>

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

</body>

</html>