<?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 * FROM accmast WHERE `accode` = '$getdata[agent]'")or die(mysqli_error($conn));
$showparty = mysqli_fetch_array($getparty);


?>

<!DOCTYPE HTML>
<html lang="en-US">


    <style>
        @media print {
            .noprint {
                display: none;
            }
        }
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            /*background-color: #FAFAFA;*/
            font: 12pt "Arial";
        }
        * {
            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;
        }
        table td{
            padding:2px;
        }
        table th{
            padding:2px;
        }



    </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: #b91646 ;color:white;">Go Back</button>
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <div style="border:solid 1px;" class="col-md-12" >
                <h2><center><?php echo $getcmpname['pname']; ?></center></h2>
                <!-- <img src="images/logoeng.png" style="width:660px;margin-bottom:-50px"> -->
                <!-- <center><?php echo $getcmpname['hoadd1'] . " " . $getcmpname['hoadd2'] . " " . $getcmpname['hoadd3']; ?></center> -->
                <!-- <center><?php echo "Contact No :" . $getcmpname['htel']; ?></center> -->
                <h4><center><b><?php echo $formname; ?></b></center></h4>
                <!-- <h5><center><b><?php echo "GST No:" . " " . $getcmpname['gstno']; ?></b></center></h5> -->

            </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[agent]' ") or die(mysqli_error($conn));
                $cust = mysqli_fetch_array($gcust);
                ?>
                <table class="table table-border table-hover" style="width:100%;padding: 5px">
                    <tr>
                        <td style="text-align: left; width:5%"><b>Voucher</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:40%"><?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:5%"><b>Agent</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:40%"><?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>
                    <tr>
                        <td style="text-align: left; width:5%"><b>Address</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:40%"><?php echo $showparty['add1']; ?></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>
                    <tr>
                        <td style="text-align: left; width:5%"><b></b></td>
                        <td style="width:1%"></td>
                        <td style="text-align: left; width:40%"><?php echo $showparty['add2']; ?></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>
                    
                    <tr>
                        <td style="text-align: left; width:5%"><b></b></td>
                        <td style="width:1%"></td>
                        <td style="text-align: left; width:40%"><?php echo $showparty['add3']; ?></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: #b91646; color:#ffffff;height:27px;-webkit-print-color-adjust: exact;">
                        <th style="width:3%;"><label>Sr.</label></th>
                        <th style="width: 10%;text-align:left"><label>Passport</label></th>
                        <th style="width: 20%;text-align:left"><label>Pax Name</label></th>
                        <th style="width: 10%;text-align:left"><label>Immigration</label></th>
                        <th style="width: 10%;text-align:left"><label>Mofa No.</label></th>
                        <th style="width: 10%;text-align:left"><label>Submission </label></th>
                        <th style="width: 10%;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;
                    while ($showtran = mysqli_fetch_array($qry)) {
                        
                        $passport = $showtran['passport'];
                        $paxname = $showtran['paxname'];
                        $mofano = $showtran['mofano'];
                        $mofano2 = $showtran['mofano2'];
                        $submissiondt = $showtran['submissiondt'];
                        $memcash = $showtran['memcash'];
                        $delvstatus = $showtran['delvstatus'];
                        
                        if($delvstatus == "E"){
                            $delv = "ECR";
                        } elseif($delvstatus == "N"){
                           $delv = "ECNR";
                        }else{
                            $delv = "";
                        }
                        
                        if($submissiondt == '00-00-0000'){
                            $submidt = "";
                        }else{
                            $submidt = $submissiondt;
                        }
                        $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:left;'>$delv</td>";
                        Echo"<td style='text-align:left'>$mofano</td>";
                        Echo"<td style='text-align:left'>$submidt</td>";
                        Echo"<td style=' text-align:right;'>$memcash</td>";
                        Echo"</tr>";

                        $totcash = $totcash + $memcash;
                        $ctab = $ctab + 1;
                    }
                    if ($ctab < 20) {
                        for ($i = $ctab; $i <= 20; $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>
                            </tr>      
                            <?php
                        }
                    }
                    ?>  
                    <tr style="height:26px;">
                        <td class="border"   colspan="5"></td>
                        <td class="text-right border"><b>Total</b></td>
                        <td class="text-right border"><b><?php echo $totcash; ?></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: #b91646"><? 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>
