<?php  
// Include main file
include_once('../libs/main.php');
// Check Login
include_once('checkLogin.php');

$manualentry_srnoObj = new manual_entry_appoinment_sr();

if(isset($_REQUEST['select_data'])  && $_REQUEST['select_data']!="" && isset($_REQUEST['act']) && $_REQUEST['act'] == 'appointments')
{

    $fields = array("MAX(CAST(SUBSTRING(manual_entry_sr_no, 4, length(manual_entry_sr_no)-3) AS UNSIGNED)) as serialno");
    $where = array("manual_entry_type="=>$_REQUEST['select_data']);
    $manualentry_appoinmentArg    = array('fields' => $fields,'where' => $where);
    $manualentry_appoinment = $manualentry_srnoObj->fromFields($manualentry_appoinmentArg);
    //print_r($manualentry_appoinment);exit;
    $manualentry_appoinmentsrno = $manualentry_appoinment->serialno;
    if(isset($manualentry_appoinmentsrno) && $manualentry_appoinmentsrno != '')
    {
        $appserial = $manualentry_appoinment->serialno+1;
        $app_sr_no='XRA'.$appserial;
    }else{
        $app_sr_no='XRA40001';
    }
    echo  json_encode(array("app_sr_no"=>$app_sr_no));
    exit;
}
if(isset($_REQUEST['select_data'])  && $_REQUEST['select_data']!="" && isset($_REQUEST['act']) && $_REQUEST['act'] == 'guranoters')
{
    $fields = array("MAX(CAST(SUBSTRING(manual_entry_sr_no, 4, length(manual_entry_sr_no)-3) AS UNSIGNED)) as serialno");
    $where = array("manual_entry_type="=>$_REQUEST['select_data']);
    $manualentry_guarantorArg    = array('fields' => $fields,'where' => $where);
    $manualentry_guarantor = $manualentry_srnoObj->fromFields($manualentry_guarantorArg);
    //print_r($manualentry_guarantor);exit;
    $manualentry_guarantorsrno = $manualentry_guarantor->serialno;
    if(isset($manualentry_guarantorsrno) && $manualentry_guarantorsrno != '')
    {
        $guarantorserial = $manualentry_guarantor->serialno+1;
        $guarantor_sr_no='XRG'.$guarantorserial;
    }else{
        $guarantor_sr_no='XRG30001';
    }
    echo  json_encode(array("guarantor_sr_no"=>$guarantor_sr_no));
    exit;
}
if(isset($_REQUEST['select_data'])  && $_REQUEST['select_data']!="" && isset($_REQUEST['act']) && $_REQUEST['act'] == 'patient')
{

    $fields = array("MAX(CAST(SUBSTRING(manual_entry_sr_no, 4, length(manual_entry_sr_no)-3) AS UNSIGNED)) as serialno");
    $where = array("manual_entry_type="=>$_REQUEST['select_data']);
    $manualentry_patientArg    = array('fields' => $fields,'where' => $where);
    $manualentry_patient = $manualentry_srnoObj->fromFields($manualentry_patientArg);
    //print_r($manualentry_patient);exit;
    $manualentry_patientsrno = $manualentry_patient->serialno;
    if(isset($manualentry_patientsrno) && $manualentry_patientsrno != '')
    {
        $patientserial = $manualentry_patient->serialno+1;
        $patient_sr_no='XRP'.$patientserial;
    }else{
        $patient_sr_no='XRP20001';
    }
    echo  json_encode(array("patient_sr_no"=>$patient_sr_no));
    exit;
}
//manual_patient_id

?>