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

$maindb = "item";
$trandb = "itemtran";
$formname = "Item Print";
$file = "itemprint.php";

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

$vouchno = $_GET[vouchno];
browse($vouchno);

$getpmain = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE `code` = '$vouchno'")or die(mysqli_error($conn));
$get = mysqli_fetch_array($getpmain);

$finditemgrp = mysqli_query($conn, "SELECT * FROM `itemgrp` WHERE `code`='$get[itemgrp]'") or die(mysqli_error($conn));
$fitemgrp = mysqli_fetch_array($finditemgrp);

$finditemsub = mysqli_query($conn, "SELECT * FROM `itemsubgrp` WHERE `code`='$get[itemsubgrp]'") or die(mysqli_error($conn));
$fitemsub = mysqli_fetch_array($finditemsub);

$getimg = mysqli_query($conn, "SELECT * FROM `itemimage` WHERE `vouchno`='$qvouch'")or die(mysqli_error($conn));
$img = mysqli_fetch_array($getimg);
$imgpath = $img[imgpath] . "?a=" . mt_rand();

include("includes/linkshead.php");
?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
        <div class="row">
            <table>

                <tr>
                    <td style="text-align:right" width="30%">
                        <label class="control-label">Code </label>	
                    </td>
                    <td style="padding-left:14px">
                        <?= $get[code]; ?>
                    </td>
                </tr>
                <tr>		
                    <td style="text-align:right">
                        <label class="control-label">Name </label>	
                    </td>
                    <td style="padding-left: 14px" colspan="3">
                        <?= $get[name]; ?>
                    </td>
                </tr>
                <tr>		
                    <td style="text-align:right">
                        <label class="control-label">Item-Group </label>	
                    </td>
                    <td style="padding-left: 14px" colspan="2">
                        <?= $fitemgrp[name]; ?>
                    </td>
                </tr>
                <tr>		
                    <td style="text-align:right">
                        <label class="control-label">Item-Sub-Group </label>	
                    </td>
                    <td style="padding-left: 14px" colspan="2">
                        <?= $fitemsub[name]; ?>
                    </td>
                </tr>
                <tr>		
                    <td style="text-align:right">
                        <label class="control-label">Name To Print </label>	
                    </td>
                    <td style="padding-left: 14px" colspan="3">
                        <?= $get[nameprint]; ?>

                    </td>
                </tr>
                <tr>		
                    <td style="text-align:right">
                        <label class="control-label">HSN Code </label>	
                    </td>
                    <td style="padding-left: 14px">
                        <?= $get[hsncode]; ?>
                    </td>
                    <td style="text-align:right" width="10%">
                        <label class="control-label">GST %</label>	
                    </td>
                    <td style="padding-left: 10px">
                        <?= $get[gstperc]; ?>
                    </td>
                </tr>
                <tr>		
                    <td style="text-align:right">
                        <label class="control-label">PCS per </label>	
                    </td>
                    <td style="padding-left: 14px">
                                                <?= $get[gstperc]; ?>

                    </td>
                    <td style="text-align:right" width="5%">
                        <label class="control-label for="pcs">PCS</label>	
                    </td>
                    <td style="padding-left: 10px">
                        <input type="text" class="form-control" id="pcs">
                    </td>
                </tr>
                <tr>		
                    <td style="text-align:right">
                        <label class="control-label for="pcmt">Cost </label>	
                    </td>
                    <td style="padding-left: 14px">
                        <input type="text" class="form-control" id="pcmt">
                    </td>
                </tr>
                <tr>		
                    <td style="text-align:right">
                        <label class="control-label for="rate">Rate </label>	
                    </td>
                    <td style="padding-left: 14px">
                        <input type="text" class="form-control" id="rate">
                    </td>
                </tr>

            </table>
        </div>
        <div class="row">
            <div class="col-lg-12 pad">
                <table style="width:100%;background: white" class="table table-condensed table-bordered">
                    <thead>
                        <tr style="height:10px;" class="mySearchTr">
                            <th style="width:5%">Sr</th>
                            <th style="width:18%">Item Name</th>
                            <th style="width:18%">Sub Name</th>
                            <th style="width:11%">Group Name</th>
                            <th style="width:11%">SubGroup Name</th>
                            <th style="width:11%">Karigar</th>
                            <th style="width:11%"class='numeric'>Cost</th>
                            <th style="width:11%"class='numeric'>Rate</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $ctr = 0;
                        while ($pmain = mysqli_fetch_array($getpmain)) {
                            $getitemgrp = mysqli_query($conn, "SELECT * FROM `itemgrp` WHERE `code`='$pmain[itemgrp]'")or die(mysqli_error($conn));
                            $grpit = mysqli_fetch_array($getitemgrp);
                            $finditemsub = mysqli_query($conn, "SELECT * FROM `itemsubgrp` WHERE `code`='$pmain[itemsubgrp]'") or die(mysqli_error($conn));
                            $fitemsub = mysqli_fetch_array($finditemsub);

//                            while ($itemgrp = mysqli_fetch_object($getitemgrp)) {
                            $ctr++;
                            Echo "<tr>";
                            Echo "<td style='width:5%'>$ctr</td>";
//                                Echo "<td style='width:5%'>$pmain[code]</td>";
                            Echo "<td style='width:5%'>$pmain[name]</td>";
                            Echo "<td style='width:5%'>$pmain[subname]</td>";
                            Echo "<td style='width:5%'>$grpit[name]</td>";
                            Echo "<td style='width:5%'>$fitemsub[name]</td>";
                            Echo "<td style='width:5%' >$pmain[kargname]</td>";
                            Echo "<td style='width:5%' class='numeric'>$pmain[cost]</td>";
                            Echo "<td style='width:5%' class='numeric'>$pmain[rate]</td>";

                            Echo "</tr>";
                        }
                        ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <?php include("includes/linksfoot.php"); ?>
</body>
</html>