<?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"];
    $dosage = $_REQUEST["dosage"];
    $hide = $_REQUEST["hide"];
    $hide_var = "";
    if ($hide == 0) {
        $hide_var = 'style="display:none;"';
    }
    $mctr = $ctr;
    $mctr++;

    echo "<tr>";
    echo " <td><i class='fa fa-trash remove' style='display:none;font-size:24px'></i></td>";

    echo "<td><input type='text' class='form-control form srno' value='$mctr' name='bsrno_$ctr'></td>";
    echo "<td>";
    echo "<select class='form-control form medicine cmedicine select2 fetchpart_$ctr' name='bmedicine_$ctr' style='width:100%'>";
    echo "<option value=''></option>";
    $gitem = mysqli_query($conn, "SELECT `code`,`name` FROM `product`  order by name") or die(mysqli_error($conn));
    while ($item = mysqli_fetch_array($gitem)) {
        echo "<option value='$item[code]'>$item[name]</option>";
    }
    echo "</select>";
//    echo "<input list='medicine' name='bmedicine_$ctr' class='medicine form-control form cmedicine' autocomplete='off' value=''> ";
//    echo "<datalist id='medicine' char='#'>";
//    echo "<option>";
//    $mit2 = mysqli_query($conn, "SELECT `name` FROM `product` group by name  order by name") or die(mysqli_error($conn));
//
//    while ($tit2 = mysqli_fetch_array($mit2)) {
//        $itname2 = $tit2['name'];
//        echo "<option value='$itname2'>";
//    }
//    echo "</datalist>";
    echo "</td>";
    echo "<td><input type='text' class='form-control form text-right mqty' value='' name='bmqty_$ctr'></td>";
    echo "<td><input type='text' class='form-control form text-right mrate' value='' name='bmrate_$ctr'></td>";
    echo "<td><input type='text' class='form-control form text-right mamt' value='' name='bmamt_$ctr'  readonly></td>";

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