<?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];
$success = false;

$bankname = $_REQUEST['bankname'];
$cashdb = $_REQUEST['cashdb'];
$vouchno = $_REQUEST['vouchno'];



$genrecp = mysqli_query($conn, "SELECT * FROM `$cashdb` where `vouchno` = '$vouchno'") or die(mysqli_error($conn));
if (mysqli_num_rows($genrecp) > 0) {
    $fetrecp = mysqli_fetch_assoc($genrecp);
    $mrecpno = $fetrecp[recpno];
} else {

    $gen2 = mysqli_query($conn, "SELECT MAX(recpno) AS maxrecp FROM `$cashdb` where bankname = '$bankname'  LIMIT 0,1 ") or die(mysqli_error($conn));
//                $gvouch = mysqli_fetch_assoc($gen2);
    if (mysqli_num_rows($gen2) > 0) {
        $gvouch = mysqli_fetch_assoc($gen2);
        $mrecpno = $gvouch["maxrecp"] + 1;
    } else {
        $mrecpno = '1';
    }
}
echo "$mrecpno";