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

$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);

$trandb = "bilpktran";
$orddb  = "packtran";

if ($_REQUEST["code"]) {
    $code = $_REQUEST["code"];
    $vouchno = $_REQUEST["vouchno"];
    ?>
    <table id="data" border="1px" width="100%">

        <tr>
            <td width="40px"  align="center"><label class="control-label">SR.</label></td>
            <td width="180px" align="center"><label class="control-label">ARTICLE</label></td>
            <td width="50px"  align="center"><label class="control-label">SIZE</label></td>
            <td width="60px"  align="center"><label class="control-label">COLOUR</label></td>
            <td width="230px" align="center"><label class="control-label">DESCRIPTION</label></td>
            <td width="40px"  align="center"><label class="control-label">PACKING</label></td>
            <td width="40px"  align="center"><label class="control-label">CARTONS</label></td>
            <td width="70px"  align="center"><label class="control-label">PAIRS</label></td>
            <td width="80px"  align="center"><label class="control-label">RATE</label></td>
            <td width="120px" align="center"><label class="control-label">AMOUNT</label></td>
        </tr>
        
        <?php
        $chkqry = mysqli_query($conn, "SELECT * FROM `$trandb` WHERE vouchno='$vouchno'") or die(mysqli_error($conn));
        if (mysqli_num_rows($chkqry) > 0) {
            $qry2 = mysqli_query($conn, "SELECT * FROM  `$trandb` WHERE vouchno='$vouchno' ORDER BY srno") or die(mysqli_error($conn));
        } else {
            $qry2 = mysqli_query($conn, "SELECT * FROM  `$orddb` WHERE vouchno='$code' ORDER BY srno") or die(mysqli_error($conn));
        }
        $ctr = 0;
        
                    while ($row = mysqli_fetch_array($qry2)) {
                        
                    echo "<tr>";
                        echo "<td align='left'><input type='text'  name='srno_$ctr' class='sno form-control' value='$row[srno]'/></td>";
                        echo "<td align='left'><input type='text'  name='article_$ctr' class='article form-control' value='$row[article]' /></td>";
                        echo "<td align='left'><input type='text' name='size_$ctr' class='size form-control' value='$row[size]'/></td>";
                        echo "<td align='center'><input type='text'  name='color_$ctr' class='color form-control' value='$row[color]'/></td>";
                        echo "<td align='center'><input type='text'  name='descrip_$ctr' class='descrip form-control' value='$row[descrip]'/></td>";
                        echo "<td align='center' style='text-align:right;'><input type='text' name='packing_$ctr' class='packing form-control' style='text-align:right' value='$row[packing]'/></td>";
                        echo "<td align='center' style='text-align:right;'><input type='text' name='carton_$ctr'  class='carton form-control' style='text-align:right' value='$row[cartons]'/></td>";
                        echo "<td align='center' style='text-align:right;'><input type='text' name='pair_$ctr'  class='pair form-control' style='text-align:right' value='$row[pairs]' readonly/></td>";
                        echo "<td align='center' style='text-align:right;'><input type='text' name='rate_$ctr' class='rate form-control' style='text-align:right' value='$row[rate]'></td>";
                        echo "<td align='center' style='text-align:right;'><input type='text' name='amount_$ctr' class='amount form-control' style='text-align:right' value='$row[amount]' readonly></td>";
                    echo "</tr>";
                        $ctr++;
                    }
                ?>
                 
   </table>
      <input type="hidden" id="items" name="items" value="<?php echo $ctr; ?>" />  
                    
    <?php    
//    echo $ctr ;    
}
else{
    echo "ERROR";
}?>
