<?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];
$zroot = $_SESSION["zdbroot"];

if ($_REQUEST["godown"]) {
    $godown = $_REQUEST["godown"];

    $gettran = mysqli_query($conn, "SELECT * FROM `packsacn` WHERE `godown`='$godown' and `source`='OP' order by `srno`")or die(mysqli_error($conn));
    $ctr = 1;
    while ($row = mysqli_fetch_array($gettran)) {
        
        $getsupplier = mysqli_query($conn, "SELECT `accode`, `name` FROM `accmast` where  accode = '$row[accode]' ")or die(mysqli_error($conn));
        $fsupplier = mysqli_fetch_array($getsupplier);
        $suppname = $fsupplier["name"];
        
        Echo "<tr>";
        Echo "<td><i class='fa fa-close remove' $hide_var ></i></td>";
        Echo "<td><input type='text' name='srno_$ctr' class='srno form-control  form'  value='$row[srno]' readonly></td>";
        Echo "<td>";
        Echo "<input type='text' name='itemname_$ctr' required='true' class='itemname form-control  form' value='$row[itemname]' readonly required>";
        Echo "</td>";
        Echo "<td><input type='text' name='hsncode_$ctr' class='hsncode form-control  form' value='$row[hsncode]' readonly></td>";
        Echo "<td><input type='text' name='gstperc_$ctr' class='gstperc form-control text-right form' value='$row[gstperc]' readonly></td>";
        Echo "<td><input type='text' name='unit_$ctr' class='unit form-control  form' value='$row[unit]' readonly></td>";
        Echo "<td><input type='number' name='qty_$ctr' class='qty form-control  text-right form' step='any' value='$row[qty]' ></td>";
        Echo "<td><input type='number' name='idno_$ctr' class='qty form-control  text-right form' step='any' value='$row[idno]' ></td>";
        Echo "<td>";
        Echo "<select class='form-control select2 supplier' name='supplier_$ctr' style='width: 100%''>";
        Echo "<option value = '$row[accode]'>$suppname</option>";
        $gsupplier = mysqli_query($conn, "SELECT `accode`, `name` FROM `accmast` where grpcode = '009' GROUP by name ORDER by name")or die(mysqli_error($conn));
        while ($fsupp = mysqli_fetch_array($gsupplier)) {
            $scode = $fsupp['accode'];
            $sname = $fsupp['name'];

            Echo "<option value = '$scode'>$sname</option > ";
        }
        Echo "</select>";
        Echo "</td>";
        Echo "</tr>";
        $ctr++;
    }
    $ctr++;
}
?>