<?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($zdb);

$vouch = $_GET['vouchno'];

$cond = '';
$lcond = '';
$formname = "Invoice Print";

$maindb = 'order';
$trandb = 'ordertran';

$getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`orderdt`, '%d-%m-%Y')as orderdt FROM `$maindb` WHERE `vouchno`='$vouch'")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[member]'")or die(mysqli_error($conn));
//$showparty = mysqli_fetch_array($getparty);
//$nameprin = $getdata['nametoprin'];
?>

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


    <?php
//        include("includes/files.php");
//        include("includes/tabsuf.php");
    ?>
    <style>
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            /*background-color: #FAFAFA;*/
            font: 11pt "Tahoma";
        }
        @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 {
            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; 
        }
    </style>
</head>

<!--<link href="MyStyle/rep_format.css" rel="stylesheet">-->

<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: white;color:#A0B1BA;">Go Back</button>
        <div class="page">
            <!--<div class="subpage">-->
            <!--   ************Header************  -->
            <div style="border:solid 1px;" class="col-md-12" >
                <h2><center><? Echo $getcmpname['pname']; ?></center></h2>
                <h5><center><b><?php echo $formname; ?></b></center></h5>

            </div>
            <div style="border:solid 1px; padding-left: 1px ; padding-right: 1px" class="col-md-12">
                <?php
                $userid = $getdata['userid'];
                $username = $getdata['username'];

                if ($userid != 0) {
                    $getsupp = mysqli_query($conn, "SELECT `user`,`srno`,`email` FROM `site_passmain` WHERE srno= '$userid'")or die(mysqli_error($conn));
                    $supp = mysqli_fetch_array($getsupp);

                    $gcust = mysqli_query($conn, "SELECT * FROM `user_details` where user='$userid' ") or die(mysqli_error($conn));
                    $cust = mysqli_fetch_array($gcust);

                    $address = $cust['add1'] . $cust['add2'];
                    $email = $supp['email'];
                } else {
                    $address = $getdata['add1'] . $getdata['add2'];
                    $email = $getdata['email'];
                }

                if ($getdata['paymode'] == "OTH") {
                    $paytype = "ONLINE PAYMENT";
                } else {
                    $paytype = "CASH ON DELIVERY";
                }
                ?>
                <table class="table table-border table-hover" style="width:100%">
                    <tr style="font-size: 14px">
                        <td style="text-align: left; width:10%"><b>M/s.</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:10%"><?php echo $username; ?></td>
                        <td style="text-align: right ; width:30%"><b>Voucher</b></td>
                        <td style=" width:1%">:</td>
                        <td style="text-align: left; width:20%"><?php echo $getdata['vouchno']; ?></td>
                    </tr>
                    <tr style="font-size: 14px">
                        <td style="text-align: left; width:7%"><b>Address</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:40%"><?php echo $address ?></td>
                        <?php if ($getdata['paymode'] == "OTH") { ?>
                            <td style="text-align: right ; width:30%"><b>Payment ID.</b></td>
                            <td style="width:1%">:</td>
                            <td style="text-align: left; width:20%"><?php echo $getdata['payid']; ?></td>
                        <?php }
                        ?>
                    </tr>
                    <tr style="font-size: 14px">
                        <td style="text-align: left; width:7%"><b>Email Id.</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:40%"><?php echo $email; ?></td>
                        <td style="text-align: right ; width:10%"><b>Payment Mode</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:20%"><?php echo $paytype; ?></td>
                    </tr>
                    <tr style="font-size: 14px">
                        <td style="text-align: left; width:7%"><b>Mobile</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:40%"><?php echo $getdata['contact']; ?></td>
                        <td style="text-align: right ; width:10%"><b>&nbsp;</b></td>
                        <td style="width:1%">&nbsp;</td>
                        <td style="text-align: left; width:20%">&nbsp;</td>
                    </tr>
                    <tr style="font-size: 14px">
                        <td style="text-align: left; width:10%"><b>Order ID</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:20%"><?php echo $getdata['pikrord_id']; ?></td>
                        <td style="text-align: right ; width:10%"><b>Tracking Mode</b></td>
                        <td style="width:1%">:</td>
                        <td style="text-align: left; width:20%"><?php echo $getdata['pikrtrck_id']; ?></td>
                    </tr>
                </table>
            </div>
            <div>
                <table  border="solid 1px" style="border-collapse: collapse; width:100%">
                    <tr>
                        <th width="7%" class='text-right'>Sr.</th>
                        <th  width="37%" class="text-left">Product Name</th>
                        <th  width="14%" class='text-right'>Qty</th>
                        <th  width="14%" class='text-right'>Size</th>
                        <th  width="14%" class='text-right'>Price</th>
                        <th  width="14%" class='text-right'>Amount</th>
                    </tr>

                    <?php
                    $ctr = 1;
                    $ctab = 0;
                    $totqty = 0;
                    $pmvouch = $getdata['vouchno'];

                    $gettran = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno` = '$pmvouch' ")or die(mysqli_error($conn));
                    while ($showtran = mysqli_fetch_array($gettran)) {

                        $getsize = mysqli_query($conn, "SELECT `code`,`name` FROM `size` WHERE code='$showtran[size]'")or die(mysqli_error($conn));
                        $size = mysqli_fetch_array($getsize);

                        $amount = $showtran[qty] * $showtran[mrp];
                        $amt = number_format($amount, 2);
                        $mrp = round($showtran['mrp']);
                        Echo"<tr>";
                        Echo"<td style='text-align: center;'>$ctr</td>";
                        Echo"<td>$showtran[prodname]</td>";
                        Echo"<td style='text-align: center;'>$showtran[qty]</td>";
                        Echo"<td style='text-align: center;'>$size[name]</td>";
                        Echo"<td style='text-align: right;'>$mrp</td>";
                        Echo"<td style='text-align: right;'>$amt</td>";
                        Echo"</tr>";
                        $totqty = $totqty + $showtran['qty'];
                        $ctr++;
                        $ctab = $ctab + 1;
                    }

                    if ($ctab < 19) {
                        for ($i = $ctab; $i <= 19; $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>
                            </tr>      
                            <?php
                        }
                    }
                    ?>  

                    <tr style="">
                        <td colspan="3" style="border-collapse: collapse;text-align:right" >Total Qty.</td>
                        <td colspan="" style="border-collapse: collapse;text-align:center" ><? echo $totqty; ?></td>
                        <td colspan="" style="text-align: right;border:none;border-right:1px solid black" > Cart Total  </td>
                        <td style="text-align: right;border-left: none;"> <? echo $getdata['subtotal']; ?>  </td>

                    </tr>


                    <tr>
                        <td colspan="4" style="border-collapse: collapse" ><? echo " "; ?></td>
                        <td  style="text-align: right;border-right:1px solid black" class=" rnone" >  Discount  </td>
                        <td style="text-align: right; " class="lnone "> <? Echo $getdata['discount']; ?>  </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            Rupees 
                            <?php echo rsword(round($getdata[total])); ?>
                        </td>

                        <td colspan = "1" style="text-align: right;border-right:1px solid black " class=" rnone"><b>Total Amount</b></td>
                        <td style="text-align: right;" class="lnone" ><b><? Echo $getdata['total']; ?></b></td>
                    </tr>

                    <table class="border">
                        <tr>
                            <td class="border" style="width: 541px; font-size: 14px;">
                            </td>
                            <td class="border" style="width: 216px">

                                <div style=" float:right; font-size: 14px; font-weight: 900"><? echo "For  " . $getcmpname['pname']; ?></div>
                                <br>
                                <br>
                                <br>
                                <br>
                                <div style="float:right; font-size: 11px">AUTHORISED SIGNATORY</div>
                            </td>
                        </tr>
                    </table>
            </div>
        </div>    
        <?php
        include("includes/linksfoot.php");
        ?>
</body>
</html>
