<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ("includes/function.php");

$zdb = $_SESSION["zdbyear_$dbname"];
mysqli_select_db($conn, $zdb);
$zroot = $_SESSION["zdir"];

if ($_REQUEST["paraM"]) {
    $medicine = $_REQUEST["medicine"];

    $gttn = mysqli_query($conn, "SELECT rate FROM `product` where name = '$medicine'") or die(mysqli_error($conn));
    $fttn = mysqli_fetch_array($gttn);
    echo $fttn['rate'];
}

if ($_REQUEST["paraR"]) {
    $treatment = $_REQUEST["treatment"];

    $gttn = mysqli_query($conn, "SELECT rate FROM `treatment` where name = '$treatment'") or die(mysqli_error($conn));
    $fttn = mysqli_fetch_array($gttn);
    echo $fttn['rate'];
}
if ($_REQUEST["vouchno"]) {
    $vouchno = $_REQUEST["vouchno"];
    $vouchdt = $_REQUEST["vouchdt"];
    $accod = $_REQUEST["accode"];
    $treatment = $_REQUEST["treatment"];
    $scheddate = $_REQUEST["scheddate"];
    $addflg = $_REQUEST["addflg"];
    $rrclass = "disabled='disabled'";
    if ($addflg == 0) {
        $rrclass = "";
    }
    $nscheddate = date("d-m-Y", strtotime($scheddate));
    // $getdet = mysqli_query($conn, "SELECT * FROM `treatdet` WHERE vouchno='$vouchno' and scheddate = '$scheddate' and treatment='$treatment'") or die(mysqli_error($conn));
    // $fetdet = mysqli_fetch_array($getdet);

    $gttn = mysqli_query($conn, "SELECT code,name FROM `treatment` where code = '$treatment'") or die(mysqli_error($conn));
    $fttn = mysqli_fetch_array($gttn);

    $gtstf = mysqli_query($conn, "SELECT accode,name FROM `accmast` where accode = '$fetdet[staff]'") or die(mysqli_error($conn));
    $ftstf = mysqli_fetch_array($gtstf);

    echo "<h5 style='color:red'>";
    echo "Treatment Details of $fttn[name] on Schedule Date : $nscheddate";
    echo "</h5>";

    echo "<br>";

    echo "<div class='row'>";
    echo "<div class='col-lg-2 col-md-2 col-sm-3 col-xs-3 text-right'>";
    echo "<label class='label-control marg'>Done By</label>";
    echo "</div>";
    echo "<div class='col-lg-4 col-md-4 col-sm-6 col-xs-6'>";
    echo "<select class='form-control form staff' name='staff' $rrclass>";
    echo "<option  value='$ftstf[accode]'>$ftstf[name]</option>";
    $getstf = mysqli_query($conn, "SELECT accode,name FROM `accmast` where grpcode ='040' order by name") or die(mysqli_error($conn));
    while ($fetstf = mysqli_fetch_array($getstf)) {
        echo "<option value ='$fetstf[accode]'>$fetstf[name]</option>";
    }
    echo "</select>";
    echo "</div>";
    echo "</div>";
    echo "<br>";

    echo "<div class='row'>";
    echo "<div class='col-lg-2 col-md-2 col-sm-3 col-xs-3 text-right'>";
    echo "<label class='label-control marg'>Treatment Detail 1</label>";
    echo "</div>";
    echo "<div class='col-lg-4 col-md-4 col-sm-6 col-xs-6'>";
    echo "<input type='text' name='treat1' class='form-control form' name='treat1' value='$fetdet[treat1]' $rrclass>";
    echo "</div>";
    echo "</div>";

    echo "<div class='row'>";
    echo "<div class='col-lg-2 col-md-2 col-sm-3 col-xs-3 text-right'>";
    echo "<label class='label-control marg'>2</label>";
    echo "</div>";
    echo "<div class='col-lg-4 col-md-4 col-sm-6 col-xs-6'>";
    echo "<input type='text' name='treat2' class='form-control form' name='treat2' value='$fetdet[treat2]' $rrclass>";
    echo "</div>";
    echo "</div>";

    echo "<div class='row'>";
    echo "<div class='col-lg-2 col-md-2 col-sm-3 col-xs-3 text-right'>";
    echo "<label class='label-control marg'>3</label>";
    echo "</div>";
    echo "<div class='col-lg-4 col-md-4 col-sm-6 col-xs-6'>";
    echo "<input type='text' name='treat3' class='form-control form' name='treat3' value='$fetdet[treat3]' $rrclass>";
    echo "</div>";
    echo "</div>";

    echo "<div class='row'>";
    echo "<div class='col-lg-2 col-md-2 col-sm-3 col-xs-3 text-right'>";
    echo "<label class='label-control marg'>4</label>";
    echo "</div>";
    echo "<div class='col-lg-4 col-md-4 col-sm-6 col-xs-6'>";
    echo "<input type='text' name='treat4' class='form-control form' name='treat4' value='$fetdet[treat4]' $rrclass>";
    echo "</div>";
    echo "</div>";
//    echo "<input type='text' name='treat5' class='form-control form' name='treat5' value='$fetdet[treat5]' $rrclass>";
//    echo "<input type='text' name='treat6' class='form-control form' name='treat6' value='$fetdet[treat6]' $rrclass>";
    echo "</div>";
    echo "</div>";
    echo "<br>";
    echo "<div class='row'>";
    echo "<div class='col-lg-2 col-md-2 col-sm-3 col-xs-3 text-right'>";
    echo "<label class='label-control marg'>Machine Used</label>";
    echo "</div>";
    echo "<div class='col-lg-4 col-md-4 col-sm-6 col-xs-6'>";
    echo "<input type='text' name='machine1' class='form-control form machine1' name='machine1' value='$fetdet[machine1]' $rrclass>";
    echo "</div>";
    echo "</div>";
    echo "<div class='row'>";
    echo "<div class='col-lg-2 col-md-2 col-sm-3 col-xs-3 text-right'>";
    echo "<label class='label-control marg'></label>";
    echo "</div>";
    echo "<div class='col-lg-4 col-md-4 col-sm-6 col-xs-6'>";
    echo "<input type='text' name='machine2' class='form-control form machine2' name='machine2' value='$fetdet[machine2]' $rrclass>";
    echo "</div>";
    echo "</div>";
    echo "<br>";
    echo "<div class='row'>";
    echo "<div class='col-lg-4 col-md-4 col-sm-4 col-xs-4 text-right'>";
    echo "<input type='hidden' class='' name='accod' value='$accod'>";
    echo "<input type='hidden' class='' name='vouchn' value='$vouchno'>";
    echo "<input type='hidden' class='' name='treatmen' value='$treatment'>";
    echo "<input type='hidden' class='' name='scheddat' value='$scheddate'>";
    echo "<input type='hidden' class='' name='vouchd' value='$vouchdt'>";
    echo "</div>";
    echo "<div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 text-right'>";
    echo "<button type='button' class='btn form-control form saverec' $rrclass>Update</button> ";
    echo "</div>";
    echo "</div>";
}
?>