<?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];
$zroot = $_SESSION["zdbroot"];

$fseries = $_SESSION["series_" . $dbname];
$keycond = "and `series`='$fseries'";

$success = false;

if (isset($_REQUEST["vouchno"])) {

    $vouchno = $_REQUEST['vouchno'];

    $query = "SELECT * FROM `checkout` WHERE bookno ='$vouchno' $keycond";
    $result = mysqli_query($conn, $query) or die(mysqli_error($conn));
    $r = mysqli_num_rows($result);


    $query2 = "SELECT * FROM `hotmain` WHERE vouchno ='$vouchno' $keycond";
    $result2 = mysqli_query($conn, $query2) or die(mysqli_error($conn));
    $r2 = mysqli_fetch_assoc($result2);
    $r2cnt = mysqli_num_rows($result2);
    if ($r > 0) {
        $r2 = [];
    }


    $rows = array();
    $ctr = 0;
    $rows = array('success' => true,
        'recext' => "$r",
        'r2cnt' => "$r2cnt",
        'chkdt' => "$r2[chkdt]",
        'name' => "$r2[memname]",
        'outdt' => "$r2[outdt]",
        'daysno' => "$r2[daysno]",
        'billamt' => "$r2[totamt]",
        'rate' => "$r2[rate]",
        'amount' => "$r2[totamt]",
        'extra' => "$r2[extra]",
        'disc' => "$r2[disc]",
        'roomno' => "$r2[roomno]",
        'paytype' => "$r2[paytype]",
        'advance' => "$r2[advance]",
        'balance' => "$r2[balance]");
    header("Content-type: application\json");
    echo json_encode($rows);
}