<?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"];
//include("includes/linkshead.php");

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

    $gettran = mysqli_query($conn, "SELECT * FROM `rawsacn` WHERE `godown`='$godown' and `series`='$series' 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"];
    $getclassify = mysqli_query($conn, "SELECT `code`, `name` FROM $zroot.`classify` where code = '$row[classify]' ")or die(mysqli_error($conn));
    $fclassify = mysqli_fetch_array($getclassify);
    $cname = $fclassify["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='text' name='idno_$ctr' class='unit form-control  form' value='$row[idno]' ></td>";
        Echo "<td><input type='text' name='reportno_$ctr' class='unit form-control  form' value='$row[reportno]' ></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 "<td>";
        Echo "<select class='form-control select2 classify' name='classify_$ctr' style='width: 100%''>";
        Echo "<option value = '$row[classify]'>$cname</option>";
        $gclass = mysqli_query($conn, "SELECT `code`,`name` FROM $zroot.`classify` GROUP by name ORDER by name")or die(mysqli_error($conn));
        while ($fclass = mysqli_fetch_array($gclass)) {
            $ccode = $fclass['accode'];
            $cname = $fclass['name'];

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