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

$admin = $_SESSION["admin_" . $dbname];
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];
mysqli_select_db($conn, $zdb);

$vouch = $_GET['vouchno'];
$type = $_GET['para'];

$cond = '';
$lcond = '';
$formname = "Price List";
$maindb = 'felocmain';
$trandb = 'feloctran';
$root = $_SESSION["zdbroot"];
$zroot = $_SESSION["zdbroot"];

if ($type == "M") {
    $party = $_POST["party"];
    $frmdt = $_POST["frmdt"];
    $todt = $_POST["todt"];
    $frminvno = $_POST["frminvno"];
    $toinvno = $_POST["toinvno"];

    if (!empty($party)) {
        $partycond = " AND `party` = '$party' ";
    }

    if (!empty($frminvno)) {
        $rangecond = "and invno between $frminvno and $toinvno ";
    }

    $getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d/%m/%Y')as mydt FROM $zroot.`$maindb`
                       WHERE vouchno != '' $rangecond $partycond and vouchdt >= '$frmdt' and vouchdt <= '$todt' ORDER BY vouchno+0")or die(mysqli_error($conn));
} else {
    $getqry = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d/%m/%Y')as mydt FROM $zroot.`$maindb`
                       WHERE vouchno='$vouch' ORDER BY vouchno+0")or die(mysqli_error($conn));
}


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




if (mysqli_num_rows($getqry) <= 0) {
    browse("Record Not Found");
}
include("includes/linkshead.php");
?>
<link href="styles/inv_format.css" rel="stylesheet">
<style>
    body{
        font-size: 13px;
    }
    .table > tbody > tr > td{
        padding: 0px;
    }

    .bor{
        border-left: 1px solid black;
        border-right:  1px solid black;
    }

    .numeric{
        text-align: right
    }

    .fontnew{
        font-family: 'Verdana';
        font-size : 13px;
        font : 'bold';
    }
    .border{
        border-top-style:solid; 
        border-right-style:solid; 
        border-bottom-style:none; 
        border-left-style:solid;
        border-width:1px black;
    }
    .border2{
        border-top-style:solid; 
        border-right-style:solid; 
        border-bottom-style:none; 
        border-left-style:none;
        border-width:1px ;
    }
    .uppercase{
        text-transform:uppercase;
    }
    th{
        font-size:10px
    }
    .table-condensed > tbody > tr > td {
        padding:3px;
        font-size:10px
    }
    .padd{
        padding-left: 2px;
    }
</style>
</head>
<body onload="">

    <?php
    $tdhg = "24px";

    $qry = mysqli_fetch_array($getqry);

    $vouchno = $qry['vouchno'];
    ?>
    <div class="page">
        <div class="subpage" style="padding-top: 16px">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 text-right">
                    <button onclick="window.print();
                            return false;" class="btn btn-primary noPrint" style="text-align: right">Print</button>
                </div>
            </div><br>
            <div class="" style="border-bottom: none">
                <table style="width:100%;height: 7%">
                    <tr>
                        <td style="width:25%">
                            <table style="width:100%">
                                <tr>
                                    <td><img src="images/logo/khlogo.jpg" style="width: 120px;height: 80px"></td> 
                                </tr>
                            </table>
                        </td>
                        <td style="width:50%">
                            <table style="width:100%">
                                <tr>
                                    <td class="uppercase" style="text-align: center;width: 100%;font-size: 35px;font-family: 'Times New Roman';">
                                        <b><? Echo $comp2['compname'] ?></b></td> 
                                </tr>
                            </table> 
                        </td>
                        <td style="width:25%">
                            <table style="width:100%">
                                <tr>
                                    <td style="text-align: right"><img src="images/logo/KH150.jpg" style="width: 120px;height: 80px"></td> 
                                </tr>
                            </table> 
                        </td>
                    </tr>
                </table>
                <table style="width:100%">
                    <tr><td class="text-center"><b>Head Office :</b>
                            <?php echo $comp2['hoadd1'] . ' ' . $comp2['hoadd2'] . ' ' . $comp2['hoadd3'] . ' ' . $comp2['hocity'] . '-' . $comp2['hopin'] . " " . "Tel :" . " " . $comp2["htel"] ?>                      
                        </td>
                    </tr>
                    <tr>
                        <td class="text-center"><b>Sales :</b>
                            <?php echo $comp2['sadd1'] . ' ' . $comp2['sadd2'] . ' ' . $comp2['sadd3']; ?>   
                        </td>
                    </tr>
                    <tr>
                        <td class="text-center"><b>Factory :</b>
                            <?php echo $comp2['fadd1'] . ' ' . $comp2['fadd2'] . ' ' . $comp2['fadd3']; ?>   
                        </td>
                    </tr>
<!--                        <tr>
                        <td style="font-size: 12px;" class="text-center"><span style="padding-left:50px"></span><b>
                                GST NO :&nbsp;
                    <?php // echo $comp2['gstno']  ?>   
                            </b>
                        </td>
                    </tr>-->
                    <tr>
                        <td>&nbsp;</td>
                    </tr>

                    <tr>
                        <td style="font-size: 15px;padding: 2%" class="text-center">
                            <b>
                                <?= $formname . ' w.e.f ' . $qry['mydt']; ?>
                            </b>
                        </td>
                    </tr>
                    <?
                    $getpartyname = mysqli_query($conn, "SELECT * FROM `accmast` WHERE `accode`='$qry[party]' AND `grpcode`='010'")or die(mysqli_error($conn));
                    $mpartyname = mysqli_fetch_array($getpartyname);
                    $partyname = $mpartyname['name'];
                    $add1 = $mpartyname['add1'];
                    $add2 = $mpartyname['add2'];
                    $add3 = $mpartyname['add3'];
                    $city = $mpartyname['city'];
                    $pin = $mpartyname['pin'];
                    $panno = $mpartyname['vattin'];
                    $pan = $mpartyname['pan'];
                    $gstno = $mpartyname['gstno'];
                    $stcode = $mpartyname['statecode'];
                    $state = $mpartyname['state'];
                    ?>
                </table>
                <table width="100%">
                    <tr>
                        <td style="width:55%; " class="text-left padd">
                            <label class="fontnew" style="text-align: left;"><b>M/s.&nbsp;:&nbsp;&nbsp;<? Echo $partyname; ?></b></label>
                        </td>
                    </tr>
                    <tr>
                        <td  class="padd" style="width:55%;">
                            <?php
                            if ($add1 != '') {
                                ?>
                                <label class="fontnew"><? Echo $add1 . '' . $add2; ?></label>
                            <?php }
                            ?>
                        </td>
                    </tr>

                </table>
            </div>

            <table class="table-condensed table-bordered" style="width: 100%">
                <tr style="background: #0098DA;color: white;border: 1px solid black; height: <?= $tdhg; ?>">
                    <th class="uppercase numeric bor text-center" style="width:2%">Sr</th>
                    <th class="uppercase bor  text-center" style="width:6%">Hsncode</th>
                    <!--<th class="uppercase bor text-center" style="width:6%">Rate Of<br>Tax</th>-->
                    <th class="uppercase bor text-center" style="width:6%">Code</th>
                    <th class="uppercase bor text-center" style="width:38%">Products</th>
                    <th class="uppercase bor text-center" style="width:6%">Weight<br>In GMS.</th>
                    <th class="uppercase bor numeric text-center" style="width:6%">M.R.P./PC</th>
                    <th class="uppercase bor numeric text-center" style="width:6%">Price /<br>DZ</th>
                    <th class="uppercase bor numeric text-center" style="width:6%">Discount<br>%</th>
                    <th class="uppercase bor numeric text-center" style="width:6%">Discount</th>
                    <th class="uppercase bor numeric text-center" style="width:6%">Rate in <br>FE</th>

                </tr>
                <?
                $ctr = 0;
                $checkgstzero = 0;
                $gettran = mysqli_query($conn, "SELECT a.*,b.nametoprint,b.prodgrp FROM $zroot.`$trandb` a, product b WHERE a.`vouchno`='$vouchno' and a.itemcode=b.prodcode order by b.prodgrp")or die(mysqli_error($conn));
                while ($tran = mysqli_fetch_array($gettran)) {
                    $getitemgrp = mysqli_query($conn, "SELECT `name` FROM `prodgrp` WHERE `code`='$tran[prodgrp]'")or die(mysqli_error($conn));
                    $fetitemgrp = mysqli_fetch_array($getitemgrp);
                    $grpname = $fetitemgrp['name'];
                    $tgrpname = $grpname;
                    $descrip = $tran['nametoprint'];
                    $ctr++;
                    if ($tgrpname != $mgrpname) {
                        echo "<tr>";
                        echo "<td colspan='10' class='text-center'><b>$grpname</b></td>";
                        echo "</tr>";
                    }
                    ?>
                    <tr style="height: <?= $tdhg; ?>;">
                        <td class="bor"><? Echo $ctr; ?></td>
                        <td class="bor"><? Echo $tran['hsncode']; ?></td>
                        <!--<td class="bor text-right"><? // Echo $tran['rate']; ?></td>-->
                        <td class="bor"><? Echo $tran['itemcode']; ?></td>
                        <td class="bor"><? Echo $descrip; ?></td>
                        <td class="bor"><? Echo $tran['gram']; ?></td>
                        <td class="bor numeric "><? Echo $tran['mrp']; ?></td>
                        <td class="bor numeric "><? Echo $tran['price_dz']; ?></td>
                        <td class="bor numeric "><? Echo $tran['discperc']; ?></td>
                        <td class="bor numeric "><? Echo $tran['discamt']; ?></td>
                        <td class="bor numeric "><? Echo $tran['ratefe']; ?></td>
                    </tr>
                    <?
                    $mgrpname = $tgrpname;
                }

                $ln = 16;

                if ($ctr < $ln) {
                    for ($i = 0; $i < $ln; $i++) {
                        ?>
                        <tr style="height: <?= $tdhg; ?>">
                            <td class="bor"></td>
                            <!--<td class="bor"></td>-->
                            <td class="bor"></td>
                            <td class="bor"></td>
                            <td class="bor"></td>
                            <td class="bor"></td>
                            <td class="bor"></td>
                            <td class="bor"></td>
                            <td class="bor"></td>
                            <td class="bor"></td>
                            <td class="bor"></td>

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



        </div>
    </div>
    <?php
//    }

    include('includes/linksfoot.php');
    ?>
