<?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["zdir"];

if ($_REQUEST["ctr"]) {
    $ctr = $_REQUEST["ctr"];
    $hide = $_REQUEST["hide"];
    $prodtype = $_REQUEST["prodtype"];
    $hide_var = "";

    if ($hide == 0) {
        $hide_var = 'style="display:none;"';
    }
    $mctr = $ctr;

    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='$mctr' readonly></td>";
    Echo "<td>";
    Echo "<input type='text' name='itemname_$ctr' required='true' class='itemname focusFld_$ctr form-control  form' value=''  required>";
    Echo "</td>";
    Echo "<td><input type='text' name='hsncode_$ctr' class='hsncode form-control  form' value='' readonly></td>";
    Echo "<td><input type='text' name='gstperc_$ctr' class='gstperc form-control  form' value='' readonly></td>";
    Echo "<td><input type='text' name='unit_$ctr' class='unit form-control  form' value='' readonly></td>";
    Echo "<td><input type='number'  step='any' name='qty_$ctr' class='qty form-control text-right form' value='0'></td>";
    Echo "<td><input type='text' name='idno_$ctr' class='form-control  idno form' value='' ></td>";
    Echo "<td><input type='text' name='reportno_$ctr' class='form-control  form' value='' ></td>";
    Echo "<td>";
    Echo "<select class='form-control select2 supplier' name='supplier_$ctr' style='width: 100%''>";
    Echo "<option value = ''></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 supplier' name='classify_$ctr' style='width: 100%''>";
    Echo "<option value = ''></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['code'];
        $cname = $fclass['name'];

        Echo "<option value='$ccode'>$cname</option>";
    }
    Echo "</select>";
    Echo "</td>";
    Echo "</tr>";
    $mctr++;
    $ctr++;
} else {
    echo "ERROR";
}
?>
