<?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"];
    $prodtype = $_REQUEST["prodtype"];
    $addflag = $_REQUEST["addflag"];
    $hide_var = "";

    if ($hide == 0) {
        $hide_var = 'style="display:none;"';
    }
    $mctr = $ctr;
    //    $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'></td>";

    echo "<td><input type='text' class='form-control form text-right qty'     name='qty_$ctr' value='0'></td>";
    echo "<td>";
    echo "<input list='unit' name='unit_$ctr' class='unit form-control form ' autocomplete='off' value='$row[unit]'> ";
    echo "<datalist id='unit' char='#'>";
    echo "<option>";

    $mun = mysqli_query($conn, "SELECT `unit` FROM `product` group by unit") or die(mysqli_error($conn));

    while ($tun = mysqli_fetch_array($mun)) {
        $unname = $tun['name'];
        echo "<option value='$unname'>";
    }
    echo "</datalist>";
    echo "</td>";


    //    Echo "<td><input type='text' class='form-control form unit'               name='unit_$ctr'  value=''></td>";
    echo "<td>";
    echo "<input list='size' name='size_$ctr' class='size form-control form ' autocomplete='off' value=''> ";
    echo "<datalist id='size' char='#'>";
    echo "<option>";

    $msi = mysqli_query($conn, "SELECT `name` FROM `size` group by name") or die(mysqli_error($conn));

    while ($tsi = mysqli_fetch_array($msi)) {
        $szname = $tsi['name'];
        echo "<option value='$szname'>";
    }
    echo "</datalist>";
    echo "</td>";
    echo "<td><input type='text' class='form-control form text-right sqft'     name='sqft_$ctr' value='$row[sqft]'></td>";
    echo "<td>";
    echo "<select name='calby_$ctr' class='form-control form select calby'>";
    echo "<option value='P'>Pcs</option>";
    echo "<option value='S'>Sq.ft</option>";
    echo "<option value='B'>Box</option>";
    echo "</select>";
    echo "</td>";
    //    Echo "<td><input type='text' class='form-control form size'               name='size_$ctr'  value=''></td>";
    echo "<td><input type='text' class='form-control form text-right rate'    name='rate_$ctr'  value='0'></td>";
    echo "<td><input type='text' class='form-control form text-right amount'  name='amount_$ctr'  value='0'>
            <input type='hidden' class='form-control form text-right suppamt'  name='suppamt_$ctr'  value=''></td>";
    echo "<td>";
    echo "<input list='itemname' name='itemname_$ctr' class='itemname form-control form ' autocomplete='off' value=''> ";
    echo "<datalist id='itemname' char='#'>";
    echo "<option>";

    $msize = mysqli_query($conn, "SELECT `name` FROM `product` group by name") or die(mysqli_error($conn));

    while ($tsize = mysqli_fetch_array($msize)) {
        $sizename = $tsize['name'];
        echo "<option value='$sizename'>";
    }
    echo "</datalist>";
    echo "</td>";
    echo "<td><input type='date' class='form-control form delivery_date'  name='delivery_date_$ctr'  value='' ></td>";
    echo "<td><input type='number' class='form-control form delchal'  name='delchal_$ctr'  value=''  ></td>";

    echo "<td>";
    echo "<select class='form-control form mansupp select' name='mansupp_$ctr'>";
    echo "<option value=''></option>";
    $getpd12 = mysqli_query($conn, "SELECT accode,name FROM `accmast` WHERE `grpcode`='009' order by name") or die(mysqli_error($conn));
    while ($row12 = mysqli_fetch_array($getpd12)) {
        echo "<option value='$row12[accode]'>$row12[name]</option>";
    }
    echo "</select>";
    echo "</td>";

    echo "<td><input type='text' class='form-control form sldesign'  name='sldesign_$ctr' value=''></td> ";

    echo "<td><input type='number' class='form-control form mancp text-right'  name='mancp_$ctr'  value='0'  ></td>";
    echo "<td></td>";
    echo "<td></td>";
    echo "<td></td>";

    echo "</tr>";
    $ctr++;
} else {
    echo "ERROR";
}
