<?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];

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

    echo "<tr>";
    echo "<td><i class='fa fa-close remove' style=''></i></td>";
    echo "<td><input type='text' class='form-control form text-right srno' name='srno_$ctr' value='$mctr'></td>";
    echo "<td>";
    echo "<input list='brand' name='brand_$ctr' class='brand form-control form ' autocomplete='off' value=''> ";
    echo "<datalist id='brand' char='#'>";
    echo "<option>";

    $gbrand = mysqli_query($conn, 'SELECT * FROM `brand`') or die(mysqli_error($conn));
    while ($brand = mysqli_fetch_array($gbrand)) {
        echo "<option value='$brand[name]'>";
    }
    echo "</datalist>";
    echo "</td>";

    echo "<td>";
    echo "<input list='itemcode' name='itemcode_$ctr' class='itemcode form-control form ' autocomplete='off' value=''> ";
    echo "<datalist id='itemcode' char='#'>";
    echo "<option>";

    $gitemcode = mysqli_query($conn, 'SELECT * FROM `item`') or die(mysqli_error($conn));
    while ($fitemcode = mysqli_fetch_array($gitemcode)) {
        echo "<option value='$fitemcode[code]'></option>";
    }
    echo "</datalist>";
    echo "</td>";

    echo "<td>";
    echo "<input list='item' name='item_$ctr' class='item form-control form ' autocomplete='off' value=''> ";
    echo "<datalist id='item' char='#'>";
    //    echo"<option>";

    $gitem = mysqli_query($conn, 'SELECT * FROM `item`') or die(mysqli_error($conn));
    while ($item = mysqli_fetch_array($gitem)) {
        echo "<option value='$item[name]'></option>";
    }
    echo "</datalist>";
    echo "</td>";
    echo "<td><input type='text' class='form-control form text-right qty'       name='qty_$ctr'         value=''></td>";

    echo "<td>";
    echo "<input list='baleqty' name='baleqty_$ctr' class='form-control form text-right baleqty' autocomplete='off' value=''> ";
    echo "<datalist id='baleqty' char='#'>";
    echo "<option>";

    $gitem1 = mysqli_query($conn, 'SELECT * FROM `balewgt`') or die(mysqli_error($conn));
    while ($item1 = mysqli_fetch_array($gitem1)) {
        echo "<option value='$item1[balewgt]'></option>";
    }
    echo "</datalist>";
    echo "</td>";

    echo "<td><input type='text' class='form-control form text-right totqty'    name='totqty_$ctr'      value='' readonly></td>";
    echo "<td><input type='text' class='form-control form text-right rate'      name='rate_$ctr'        value=''></td>";
    echo "<td><input type='text' class='form-control form text-right amount'    name='amount_$ctr'      value='' readonly></td>";
    echo "<td>";
    echo "<select name='godown_$ctr' class='godown form-control form ' style='width:100%'>";
    echo "<option value= ''></option>";
    $getgodown = mysqli_query($conn, "SELECT `code`,`gocode` FROM `godown` order by name ") or die(mysqli_error($conn));
    while ($fetgodown = mysqli_fetch_array($getgodown)) {
        echo "<option value='$fetgodown[code]'>$fetgodown[gocode]</option>";
    }
    echo "</select>";
    echo "</td>";
    echo "</tr >";
    $ctr++;
} else {
    echo "ERROR";
}
