<?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 = 'invmain';
$trandb = 'invtran';

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


$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company` where `code`='1'") or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);

$getparty = mysqli_query($conn, "SELECT `accode`,`name` From accmast WHERE `accode` = '$getdata[agent]'") or die(mysqli_error($conn));
$showparty = mysqli_fetch_array($getparty);
?>

<!DOCTYPE HTML>
<html lang="en-US">
<title>RAHAMAN INTERNATIONAL</title>
<style>
    @media print {
        .noprint {
            display: none;
        }
    }

    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        /*background-color: #FAFAFA;*/
        font: 12pt "Tahoma";
    }

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

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

    .text-right {
        text-align: right;
    }

    .text-center {
        text-align: center;
    }
</style>
</head>


<body id="main_container">
    <div class="book">
        <button class="btn btn-primary goBack noprint" onclick="window.close()" style="float: right;width: 150px;height:35px;background-color: #4385f4 ;color:white;">Go Back</button>
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <div style="border:solid 1px;" class="col-md-12">
                <!-- <img src="images/alfauz.png" align="right" style="width: 120px;height: 100px;margin-left:-120px;margin-right: 30px;"> -->
                <h3 style="margin-top: 10px;margin-bottom:2px">
                    <center style="color: #4385f4"><? echo $getcmpname['name']; ?></center>
                </h3>
                <center>Address : <?php echo $getcmpname['add1'] . " " . $getcmpname['add2'] . " " . $getcmpname['add3']; ?></center>
                <h4>
                    <center><b><?php echo $formname; ?></b></center>
                </h4>

            </div>
            <div style="border:solid 1px;" class="col-md-12" style="padding-left: 1px ; padding-right: 1px">
                <?php
                $gcust = mysqli_query($conn, "SELECT * FROM `accmast` where accode = '$getdata[party]' ") or die(mysqli_error($conn));
                $cust = mysqli_fetch_array($gcust);
                ?>
                <table class="table table-border table-hover " style="width:100%">
                    <tr>
                        <td style="text-align: left; width:15%"><b>Invoice  No.</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:30%"><?php echo $getdata['vouchno']; ?></td>
                        <td style="text-align: right ; width:30%"><b>Date</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:20%"><?php echo $getdata['vouchdt']; ?></td>
                    </tr>
                    <tr>
                        <td style="text-align: left; width:15%"><b>Agent</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:30%" colspan="3"><?php echo $showparty['name']; ?></td>
                        <!-- <td style="text-align: right ; width:30%"><b></b></td>
                        <td style="width:1%"></td>
                        <td style="text-align: left; width:20%; margin-right: 15px;"></td> -->
                    </tr>

                </table>
            </div>
            <div>
                <table border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr style="background-color: #4385f4; color:#ffffff;height:27px;-webkit-print-color-adjust: exact;">
                        <th style="width:3%;"><label>Sr.</label></th>
                        <th style="width: 8%;text-align:left"><label>Passport</label></th>
                        <th style="width: 30%;text-align:left"><label>Pax Name</label></th>
                        <th style="width: 12%;text-align:right"><label>Stamp Amt</label></th>
                        <th style="width: 12%;text-align:right"><label>Imig Amt</label></th>
                        <th style="width: 12%;text-align:right"><label>Mofa Amt</label></th>
                        <th style="width: 12%;text-align:right"><label>Other</label></th>
                        <th style="width: 12%;text-align: right;"><label>Amount</label></th>
                    </tr>

                    <?php
                    $ctr = 0;
                    $qry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`submissiondt`, '%d-%m-%Y')as submissiondt FROM  `$trandb` WHERE  `vouchno`='$vouch'  ORDER BY srno") or die(mysqli_error($conn));
                    $ctab = $totqty = $totamt = 0;
                    // $gettran = mysqli_query($conn, "SELECT `srno`,`itemcode`, `gram`, `unit`, `qty`, `batch` FROM `$trandb` WHERE `vouchno`='$vouch' order by srno")or die(mysqli_error($conn));
                    while ($showtran = mysqli_fetch_array($qry)) {



                        $passport = $showtran['passport'];
                        $paxname = $showtran['paxname'];
                        $mofamt = $showtran['mofamt'];
                        $imigamt = $showtran['imigamt'];
                        $stampamt = $showtran['stampamt'];
                        $miscamt = $showtran['miscamt'];
                        $submissiondt = $showtran['submissiondt'];
                        $memcash = $showtran['memcash'];

                        $ctr++;

                        echo "<tr>";
                        echo "<td style='text-align:center'>$ctr</td>";
                        echo "<td style='text-align:left'>$passport</td>";
                        echo "<td style='text-align:left'>$paxname</td>";
                        echo "<td style='text-align:right'>$stampamt</td>";
                        echo "<td style='text-align:right;'>$imigamt</td>";
                        echo "<td style='text-align:right;'>$mofamt</td>";
                        echo "<td style='text-align:right;'>$miscamt</td>";
                        echo "<td style=' text-align:right;'>$memcash</td>";
                        echo "</tr>";

                        $totcash = $totcash + $memcash;
                        $ctab = $ctab + 1;
                    }
                    if ($ctab < 15) {
                        for ($i = $ctab; $i <= 15; $i++) {
                            $ctab = $ctab + 1;
                    ?>
                            <tr style="height:26px;">
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                                <td class="border"></td>
                            </tr>
                    <?php
                        }
                    }
                    ?>
                    <tr style="height:26px;">
                        <td class="text-right border" colspan="7"><b>Sub Total</b></td>
                        <td class="text-right border" colspan="2"><b><?php echo $getdata['subtot']; ?></b></td>
                    </tr>
                    <?php if ($getdata['courier'] > 0) { ?>
                        <tr style="height:26px;">
                            <td class="text-right border" colspan="7"><b>Courier</b></td>
                            <td class="text-right border" colspan="2"><b><?php echo $getdata['courier']; ?></b></td>
                        </tr>
                    <?php } ?>
                    <?php if ($getdata['misc'] > 0) { ?>
                        <tr style="height:26px;">
                            <td class="text-right border" colspan="7"><b>Additional Charges</b></td>
                            <td class="text-right border" colspan="2"><b><?php echo $getdata['misc']; ?></b></td>
                        </tr>
                    <?php } ?>
                    <tr style="height:26px;">
                        <td class="text-right border" colspan="7"><b>Total</b></td>
                        <td class="text-right border" colspan="2"><b><?php echo $getdata['totamt']; ?></b></td>
                    </tr>

                    <?php if ($getdata['totamt'] != 0) { ?>
                        <tr>
                            <td colspan="8">
                                Rupees
                                <?php echo rsword(round($getdata['totamt'])); ?>
                            </td>

                        </tr>
                    <?php } ?>
                </table>
            </div>

            <div>
                <table class="border">
                    <tr>
                        <td class="border" style="width: 541px; font-size: 14px;">
                        </td>
                        <td class="border" style="width: 216px">
                            <?php
                            require("includes/dbconnect.php");
                            ?>
                            <div style="width:300px; text-align:right; font-size: 14px; font-weight: 900">For&nbsp;<b style="color: #4385f4"><? echo "$getcmpname[name]"; ?></b></div>
                            <br>
                            <br>
                            <br>
                            <div style=" margin-left: 120px; font-size: 11px">AUTHORISED SIGNATORY</div>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    <?php
    include("includes/linksfoot.php");
    ?>
    <script>
        $(function() {
            formGeneral();
        });
    </script>
</body>

</html>