<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include('includes/function.php');

mysqli_query($conn, "SET NAMES 'utf8'");
mysqli_query($conn, 'SET CHARACTER SET utf8');

//browse('Work In Progress. Please wait');

$formname = 'Tax Invoice';
$maindb = 'salemain';
$trandb = 'saletran';
$file = '';
$source = "SL";
$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);
$mht = 'height:20px;';


$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];

$mainqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') AS vouchdt FROM `$maindb` WHERE vouchno='$vouchno'") or die(mysqli_error($conn));
$getmdata = mysqli_fetch_array($mainqry) or die(mysqli_error($conn));

//$compqry = mysqli_query($conn, "SELECT * FROM $zroot.`company` WHERE `cono`= '1'") or die(mysqli_error($conn));
//$fcomp = mysqli_fetch_array($compqry);


$getpaccode = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`= '$getmdata[party]'") or die(mysqli_error($conn));
$cust = mysqli_fetch_array($getpaccode);
$add1 = $cust['add1'];
$add2 = $cust['add2'];
$add3 = $cust['add3'];
$city = $cust['city'];
$pin  = $cust['pin'];
$paytype = $getmdata['paytype'];

//$gettrans = mysqli_query($conn, "SELECT name, code FROM `transpor` WHERE `code`= '$getmdata[transpor]'") or die(mysqli_error($conn));
//$ftrans = mysqli_fetch_array($gettrans);
?>

<!DOCTYPE HTML>
<html lang="en-US">
<?php
// include("includes/files.php");
// include("includes/tabsuf.php");
include("includes/linkshead.php");
?>
</head>
<link href="css/rep_format.css" rel="stylesheet" />
<style>
    /*    table tr td{
            font-size: 12px;
        }*/
    body {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        padding-right: 5px;
        padding-left: 5px;
        padding-top: 5px;
        padding-bottom: 0px;

        /*background-color: #FAFAFA;*/
        font: 12pt "Tahoma";
    }

    .f12 {
        font-size: 12px;
    }

    .f11 {
        font-size: 11px;
    }

    .f13 {
        font-size: 13px;
        font-weight: bold;
        padding: 3px;
    }

    .f14 {
        font-size: 14px;
    }

    .bold {
        font-weight: bold;
    }

    .page {
        width: 210mm;
        min-height: 290mm;
        padding: 1mm;
        margin: 1mm auto;
        /*border: 1px #D3D3D3 solid;*/
        /*border-radius: 1px;*/
        /*background: white;*/
        page-break-after: always;


    }

    .subpage {
        border: 1px solid black;


    }

    .border {
        border: 1px solid black;
        color: black;
        padding-right: 2px;
        padding-left: 3px;
    }

    th {
        font-weight: bold;
        font-size: 15px;
    }

    @media print {
        @page {
            size: a4;
            margin: 0;
        }


        .page {
            width: 208mm;
            min-height: 287mm;
            /* padding: 1mm; */
            /* margin: 1mm auto; */
            /*border: 1px  solid black;*/
            /*border-radius: 1px;*/
            /*background: white;*/
            page-break-after: always;

        }

        .border {
            border: 1px solid black;
            color: black;
            padding-right: 2px;
            padding-left: 3px;
        }

        th {
            font-weight: bold;
            font-size: 15px;
        }

        .table2 {
            border: 2px solid black;
        }
    }
</style>


<script>
    $(document).ready(function() {
        $('#create_excel').click(function() {
            var excel_data = $('.tablerep').html();
            var page = "excellib.php?data=" + excel_data.trim();
            console.log(page);
            var data = {
                excel_data: excel_data
            };
            window.open('data:application/vnd.ms-excel,' + encodeURIComponent(excel_data));
        });
    });
</script>
<?php
//require("includes/dbconnect.php");
$comp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_errno($conn));
$zcomp = mysqli_fetch_assoc($comp);
if ($paytype == 6) {
    $payno = $zcomp['gpaydno'];
} else {
    $payno = $zcomp['gpayno'];
}
header('Content-Type: text/html;charset=UTF-8');
ini_set('default_charset', 'utf-8');
?>
<!--<body id="main_container" onload="window.print();">-->

<body id="main_container" onload="">
    <!--<div class="book">-->
    <div class="page tablerep">
        <div class="subpage">
            <table style="width:100%">
                <tr>
                    <td style='width:80%'>
                        <table>
                            
                            <tr>
                                <td class='text-right' style='padding-left: 100px;'><b style="font-family:Serif;font-size:32px;text-align:center"><?php echo trim($zcomp['compname']) ?></b></td>
                            </tr>

                            <tr>
                                <td class='text-right' style='padding-left: 90px;'><b style="font-family:Serif;font-size:18px;text-align:center">Importers, Exporters and Wholesaler of Footwear</b></td>
                            </tr>
                        </table>
                    </td>
                    
                </tr>
                <tr>
                    <td style=""><b style="font-family:Arial;font-size:17px;">
                            <center style='padding-left: 64px;background-color:black;color:white'><u><?= $formname ?></u></center>
                        </b></td>
                </tr>
                <tr>
                    <td style=""><b style="font-family:Arial;font-size:17px;">
                            <center style='padding-left: 64px;'><u>VAT TRN No. <?= $zcomp['gstno'] ?></u></center>
                        </b></td>
                </tr>

                <div>
                    <label class="label-control marg">Mobile : +971 509786865</label>
                </div>

                <div class="col-lg-12 pad text-right">
                    <button id="create_excel" name="create_excel" style="color: #26A69A;background: white; border: 1px black solid" type="button" class="btn btn-danger"><span style="text-align: right;">&nbsp;&nbsp;Excel&nbsp;&nbsp;</span></button>
                </div>

            </table>
            <br>
            <? include("includes/inv_head2_print.php"); ?>
            <br>
            <!--<div style="border:1px solid black;">-->
            <table style="width:100%" class="">
                <tr>
                    <th class="border" style="width:5%;  text-align: center;">Sr</th>
                    <th class="border" style="width:44%; text-align: center;">Product</th>
                    <th class="border" style="width:10%; text-align: right;">Qty.</th>
                    <th class="border" style="width:10%; text-align: right;">Rate</th>
                    <th class="border" style="width:10%; text-align: right;">Amount</th>
                </tr>
                <!--</table>-->
                <!--</div>-->

                <?php
                $tranpart = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE `vouchno`='$getmdata[vouchno]' order by srno") or die(mysqli_error($conn));
                $mht = '20px';
                $ctab = 0;
                $grqty = 0;
                while ($row = mysqli_fetch_array($tranpart)) {
                    $getbrand = mysqli_query($conn, "SELECT * FROM `product` WHERE code = '$row[itemcode]'") or die(mysqli_error($conn));
                    $getb = mysqli_fetch_array($getbrand);
                ?>
                    <!--<table style="width:100%" class="mc-table ">-->
                    <tr class="" style="height:24px;">
                        <td class="border f12" style="text-align: center;"><?php echo "$row[srno]"; ?></td>
                        <td class="border f12"><?php echo "$getb[name]"; ?></td>
                        <td class="border f12" style="text-align: right;"><?php echo "$row[qty]"; ?></td>
                        <td class="border f12" style="text-align: right"><?php echo "$row[rate]"; ?></td>
                        <td class="border f12" style="text-align: right"><?php echo "$row[amount]"; ?></td>
                    </tr>
                    <!--</table>-->
                    <?
                    $ctab++;
                    if ($ctab > 19) {
                    ?>
                        <tr class="" style="height:24px;">
                            <td> </td>
                        </tr>
                        <tr class="" style="height:24px;">
                            <td> </td>
                        </tr>
                        <tr class="" style="height:24px;">
                            <td> </td>
                        </tr>
                        <tr class="" style="height:24px;">
                            <td> </td>
                        </tr>
                        <tr class="" style="height:24px;">
                            <td> </td>
                        </tr>

        </div>
    </div>

    <? include("includes/inv_foot2_print.php"); ?>
    </table>
    <br>
    <div class="subpage">
        <table style="width:100%">
            <? include("includes/inv_head1_print.php"); ?>
        </table>
        <br>
        <? include("includes/inv_head2_print.php"); ?>
        <br>
        <table style="width:100%;" class="">
            <tr>
                <th class="border" style="width:5%;  text-align: center;">Sr</th>
                <th class="border" style="width:44%; text-align: center;">Product</th>
                <th class="border" style="width:10%; text-align: right;">Qty.</th>
                <th class="border" style="width:10%; text-align: right;">Rate</th>
                <th class="border" style="width:10%; text-align: right;">Amount</th>
            </tr>
            <!--                        </table>-->
        <?php
                        $ctab = 0;
                    }

                    $grqty = $grqty + $row['qty'];
                    $totamt = $totamt + $row['amount'];
                }
                if ($ctab < 19) {
                    for ($i = $ctab; $i <= 19; $i++) {
                        $ctab = $ctab + 1;
        ?>
            <tr style="height:24px;">
                <td class="border"></td>
                <td class="border"></td>
                <td class="border"></td>
                <td class="border"></td>
                <td class="border"></td>
            </tr>
    <?php
                    }
                }
    ?>
    <? include("includes/inv_foot1_print.php"); ?>
    <? include("includes/inv_foot2_print.php"); ?>
        </table>
    </div>
    </div>
    <!--</div>-->
    <!--</div>-->
    <?php
    include("includes/linksfoot.php");
    ?>

</body>

</html>