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

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


    $vouchno = $REQUEST["vouchno"];
    $itemname = $REQUEST["itemname"];
    $srno = $REQUEST["srno"];

    $qry = mysqli_query($conn, "SELECT * FROM  `salepurch` WHERE salevouch='$vouchno' and item ='$itemname'") or die(mysqli_error($conn));
    $num = mysqli_num_rows($qry);
    $ctr = 0;
    if ($num > 0) {
        $sup = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE `code`='$row[itemcode]'") or die(mysqli_error($conn));
        $fsup = mysqli_fetch_array($sup);

        Echo "<tr>";
        Echo "<td><i class='fa fa-close remove' style='display:none;'></i></td>";
        Echo "<td><input type='text' name='srno_$ctr' class='srno form-control  form'  value='$row[srno]'></td>";
        Echo "<td>";
        Echo "<select class='form-control form supplier select2' name='supplier_$ctr' style='width:100%'>";
        Echo "<option value='$fsup[code]'>$fsup[name]</option>";
        $gsupplier = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE grpcode='009' order by name")or die(mysqli_error($conn));
        while ($supplier = mysqli_fetch_array($gsupplier)) {
            Echo "<option value='$supplier[code]'>$supplier[name]</option>";
        }
        Echo "</select>";
        Echo "</td>";

//                                                                Echo "<td><input type='text' class='form-control form text-right supplier'     name='supplier_$ctr' value='$row[supplier]'></td>";
        Echo "<td><input type='text' class='form-control form billno'               name='billno_$ctr'  value='$row[billno]'></td>";
        Echo "<td><input type='date' class='form-control form billdate'            name='billdate_$ctr'  value='$row[billdate]'></td>";
        Echo "<td><input type='text' class='form-control form text-right purqty'    name='purqty_$ctr'  value='$row[purqty]'></td>";
        Echo "<td><input type='text' class='form-control form text-right purcost'    name='purcost_$ctr'  value='$row[purcost]'></td>";
        Echo "<td><input type='text' class='form-control form text-right puramt'  name='puramt_$ctr'  value='$row[puramt]' ></td>";
        Echo "</tr>";
        $ctr++;
    } 
//    else {
        ?>
<!--        <tr>                                    
            <td><i class='fa fa-close remove'></i></td>
            <td><input type='text' name='srno_0' class='srno form-control form' value='1'></td>
            <td>
            <select name='supplier_0' class='form-control form supplier select2'  style='width:100%'>
        <option value=''><?php // $fsup[name] ?></option>
        <?php
//        $gsupplier = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE grpcode='009' order by name")or die(mysqli_error($conn));
//        while ($supplier = mysqli_fetch_array($gsupplier)) {
        ?>
        <option value='<?php // echo $supplier[name] ?>'><?php // echo $supplier[name] ?></option>;
        <?php
//        }
        ?>
            </select>
            </td>
            <td><input type='text' name='supplier_0' class='supplier form-control form' value='' ></td>
            <td><input type='text' name='billno_0' class='billno form-control form' value='' ></td>
            <td><input type='date' name='billdate_0' class='billdate form-control form' value='' ></td>
            <td><input type='text' name='purqty_0' class='purqty form-control form' value='' ></td>
            <td><input type='text' name='purcost_0' class='purqty form-control form' value='' ></td>
            <td><input type='text' name='puramt_0' class='puramt form-control form' value='' ></td>
        </tr>-->
        <?php
//        $ctr = 1;
//    }
    ?>
    <input type="hidden" id="itemspur" name="itemspur" value="<?php Echo $ctr; ?>">  

