<?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["vouchdt"]) {

    $ctr = $_REQUEST["ctr"];
    $hide = $_REQUEST["hide"];
    $vouchdt = $_REQUEST["vouchdt"];
    $hide_var = "";

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

    $gattend = mysqli_query($conn,"SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt FROM `attend` WHERE `vouchdt` = '$vouchdt'")or die(mysqli_error($conn));

    while ($attend = mysqli_fetch_array($gattend)) {
        $mctr++;

        $gsname = mysqli_query($conn,"SELECT `code`,`name`, `salaryph` FROM `staff` WHERE `code` = '$attend[staff]'")or die(mysqli_error($conn));
        $stafname = mysqli_fetch_array($gsname);

        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' readonly></td>";

        Echo "<td><select class='form-control form staff' name='staff_$ctr'>";
        echo "<option value='$stafname[code]'>$stafname[name]</option>";
        $gstaff = mysqli_query($conn,'SELECT `code`,`name` FROM `staff` WHERE `code` != "" order by name')or die(mysqli_error($conn));
        while ($staff = mysqli_fetch_array($gstaff)) {
            Echo "<option value='$staff[code]'>$staff[name]</option>";
        }
        Echo "</select></td>";

        Echo "<td><input type='number' class='form-control form text-right salhrs'      name='salhrs_$ctr'      value='$stafname[salaryph]' readonly tabindex='-1'></td>";
        Echo "<td><input type='number' class='form-control form text-right hours'      name='hours_$ctr'      value='$attend[hours]' onkeypress='if (this.value.length == 2) return false;'></td>";
        Echo "<td><input type='number' class='form-control form text-right advance'      name='advance_$ctr'      value='$attend[advance]'></td>";
        Echo "<td><input type='text' class='form-control form remarks'      name='remarks_$ctr'      value='$attend[remark]' ></td>";
        Echo "</tr>";
        $ctr++;
    }
} else {
    echo "ERROR";
}
?>