<?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 = "Invoice";

$maindb = 'tiktnewmain';
$trandb = 'tiktnewtran';

$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);


$magent = mysqli_query($conn, "SELECT accode,name FROM accmast where accode='$getdata[customer]'") or die(mysqli_error($conn));
$lagent = mysqli_fetch_array($magent);

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

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

$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: 4mm;
        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;
        }

        .sktbl {
            background-color: transparent !important;
        }

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

    .skdiv {
        width: 50%;
        margin: auto;
    }



    img {
        width: 50%;
        margin: auto;
        margin-top: -20px;
        margin-bottom: -20px;
    }
</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="">
                <table class="table table-borderless" style="width:100%">
                    <tr>
                        <?php if ($comp2['iatano'] != "") { ?>
                            <td style="width:60%;">
                                <img style="height:auto;width:100%; " src="<?php echo $headerimg; ?>">
                            </td>
                            <td style="width:40%;text-align: right;">
                                <img style="height:auto;width:40%;" src="images/iata_logo.png">
                            </td>
                        <?php } else { ?>

                            <div class="skdiv">
                                <img style="height:auto;width:100%;margin-bottom:5px" src="<?php echo $headerimg; ?>">
                            </div>

                        <?php } ?>
                    </tr>
                    <?php if ($comp2['iatano'] != "") { ?>
                        <tr>
                            <td style="width:60%;">
                            </td>
                            <td style="width:40%;text-align: right;" class="f14"><b> IATA NO. : <?= $comp2['iatano']; ?></b></td>
                        </tr>
                    <?php } ?>
                </table>

                <div class="row" style="text-align:center;background-color:<?= $vheadcolor; ?> !important;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="sktbl" style="width:100%;margin:1%">
                    <tbody>
                        <tr width="100%">
                            <td class="f14"><span style="padding-right:5px"> Invoice No. </span> : <b> <?= $getdata['vouchno']; ?></b></td>
                            <td class="f14"><span style="padding-right:30px"> Date </span> : <b> <?= $getdata['mydt']; ?></b></td>
                        </tr>


                        <tr width="100%">
                            <td class=""><span style="padding-right:18px"> LEAD PAX </span> : <b>
                                    <?= $lagent['name']; ?>
                                </b></td>
                            <?php if ($getdata['gstno'] != "") { ?>
                                <td class="f14"><span style="padding-right:5px"> GST No. </span> : <b> <?= $getdata['gstno']; ?></b></td>
                            <?php } else { ?>
                                <td class="f14"><span style="padding-right:5px"></b></td>
                            <?php } ?>

                        </tr>
                    </tbody>
                </table>

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

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

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

                            $ctr++;
                            echo "<tr style='font-size: 11px;'>";
                            echo "<td>$ctr</td>";
                            echo "<td>$row[paxname]</td>";
                            echo "<td>$row[from]</td>";
                            echo "<td>$row[to]</td>";
                            echo "<td style='font-size:10px'>$row[travdate]</td>";
                            echo "<td>$fetho[name]</td>";
                            echo "<td>$row[ppno]</td>";
                            echo "<td>$row[ticketno]</td>";
                            echo "<td style=''>$row[flightno]</td>";
                            echo "<td style=''>$row[pnr]</td>";
                            echo "<td style='text-align:right'>$row[amount]</td>";
                            echo "</tr>";
                        }
                        ?>


                    </table>
                </div>
                <br>


                <table class="table table-bordered">
                    <tr class="">
                        <td style="width:50%">
                            <table style="width:100"></table>
                        </td>
                        <td style="width:50%">
                            <table style="width:100%" class="tecle table-bordered">
                                <?php
                                $gst = $_REQUEST['gst'];
                                $tiktsubtot = $getdata['subtot'];
                                $tikthandchg = $getdata['handchg'];
                                $tiktgstamt = $getdata['gstamt'];

                                if ($getdata['pstatecode'] == $hostatecode) {
                                    $tiktcgstamt = $tiktgstamt / 2;
                                    $tiktsgstamt = $tiktgstamt / 2;
                                }

                                ?>
                                <tr>
                                    <td style="width:50%" class="text-right" colspan="2">
                                        <b style="font-size:14px">Ticket Subtotal</b>
                                    </td>

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

                                <?php if ($tikthandchg > 0) { ?>
                                    <tr>
                                        <td style="width:50%" class="text-right" colspan="2">
                                            <b style="font-size:13px">Handling Charges</b>
                                        </td>
                                        <td style="width:50%" class="text-right">
                                            <b style="font-size:18px"><?= number_format($tikthandchg, 2); ?></b>
                                        </td>
                                    </tr>
                                <?php } ?>

                                <?php 

                                    if ($getdata['pstatecode'] == $hostatecode) {  ?>

                                        <tr>
                                            <td style="width:50%" class="text-right" colspan="2">
                                                <b style="font-size:13px">CGST</b>
                                            </td>
                                            <td style="width:50%" class="text-right">
                                                <b style="font-size:18px"><?= number_format($tiktcgstamt, 2); ?></b>
                                            </td>
                                        </tr>

                                        <tr>
                                            <td style="width:50%" class="text-right" colspan="2">
                                                <b style="font-size:13px">SGST</b>
                                            </td>
                                            <td style="width:50%" class="text-right">
                                                <b style="font-size:18px"><?= number_format($tiktsgstamt, 2); ?></b>
                                            </td>
                                        </tr>
                                    <?php } else { ?>

                                        <tr>
                                            <td style="width:50%" class="text-right" colspan="2">
                                                <b style="font-size:13px">IGST</b>
                                            </td>
                                            <td style="width:50%" class="text-right">
                                                <b style="font-size:18px"><?= number_format($tiktgstamt, 2); ?></b>
                                            </td>
                                        </tr>

                                    <?php } ?>
                                    <tr>
                                        <td style="width:50%" class="text-right" colspan="2">
                                            <b style="font-size:16px">Ticket Final</b>
                                        </td>
                                        <td style="width:50%" class="text-right">
                                            <b style="font-size:18px"><?= number_format($getdata['totamt'], 2); ?></b>
                                        </td>
                                    </tr>
                                <?php
                                $totamt = $getdata['totamt'];
                                ?>

                                <tr>
                                    <td style="width:25%">

                                    </td>
                                    <td style="width:25%">
                                        <b style="font-size:18px;color:green !important">Total INR</b>
                                    </td>
                                    <td style="width:50%" class="text-right">
                                        <b style="font-size:18px;color:green !important"><?= rajnumformat($totamt) ?></b>
                                    </td>
                                </tr>

                            </table>
                        </td>
                    </tr>
                </table>
                <p>Amount in Words : <?php echo rsword($totamt) ?></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>
                    <?php
                    echo "<tr><td style='text-align: left;'>$comp2[invnote1]</td></tr>";
                    echo "<tr><td style='text-align: left;'>$comp2[invnote2]</td></tr>";
                    echo "<tr><td style='text-align: left;'>$comp2[invnote3]</td></tr>";
                    echo "<tr><td style='text-align: left;'>$comp2[invnote4]  $comp2[invnote5] </td></tr>";
                    echo "<tr><td style='text-align: left;'>$comp2[invnote6]</td></tr>";
                    ?>
                </table>

            </div>


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

            <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>

            <br>

            <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>

            <?php if ($comp2['gstno'] != "") { ?>
                <div class="row" style="text-align:center;background-color:lightgrey !important; ">
                    <b> <span style="font-family: verdana;font-size: 14px"> GST No.<?= $comp2["gstno"]; ?></span></b>
                </div>
            <?php } ?>

            <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>
            
        </div>
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>

</body>

</html>