<?php
session_start();
error_reporting(0);
$user_name=$_SESSION['user_name'];
if(empty($user_name))
 {
 header("location:index.php");
 }

include_once("database_connection.php"); 
$sqlu="select id,zone from user_tblsbifi where user_name='$user_name' " ;
$resultu=mysqli_query($conn,$sqlu);
$datau=mysqli_fetch_array($resultu);
$idu=$datau['id'];
if(isset($_POST['txtsubmit']) && $_POST['txtsubmit']=='Save')
	{
	$case_id  =strtoupper(trim($_POST['case_id']));
		$loan_type  =strtoupper($_POST['loan_type']);
		$loan_amount  =$_POST['loan_amount'];
		$appco_applicant  =strtoupper($_POST['appco_applicant']);
		$type  =strtoupper($_POST['type']);
		$name  =strtoupper($_POST['name']);
		$address1  =strtoupper($_POST['address1']);
		$pincode  =$_POST['pincode'];
		$mobile_no  =$_POST['mobile_no'];
		$type2  =strtoupper($_POST['type2']);
		$alt_no=strtoupper($_POST['alt_no']);
		$additional_information=strtoupper($_POST['additional_information']);
		$baddress=strtoupper($_POST['baddress']);
		$bpincode=strtoupper($_POST['bpincode']);
		$bmobile_no=strtoupper($_POST['bmobile_no']);
		$balt_no=strtoupper($_POST['balt_no']);
		$badditional_information=strtoupper($_POST['badditional_information']);
		$company_name  =strtoupper($_POST['company_name']);
		$zone  =strtoupper($_POST['zone']);
		$bank_name=strtoupper($_POST['bank_name']);
		$account_no =$_POST['account_no'];
		$ver_type =$_POST['ver_type'];
		$branch =$_POST['branch'];
		$pan_no1 =$_POST['pan_no1'];
		$pan_no2 =$_POST['pan_no2'];
		$pan_no3 =$_POST['pan_no3'];
		$pan_no=$pan_no1.$pan_no2.$pan_no3;
		$assesment_year1 =$_POST['assesment_year1'];
		$assesment_year2 =$_POST['assesment_year2'];
		$assesment_year3 =$_POST['assesment_year3'];
		$status  =1;	
		$promo_code=$_POST['promo_code'];	date_default_timezone_set('Asia/Calcutta');	
		$dump_date=date('m-d-Y');
		$month=date('M-Y');
		$entry_by=$user_name;
		$entry_date=date('d-m-Y');
		$entry_time=date('h:i A');
		if($type=="RV")
		{
		if((empty($address1)) && (empty($pincode)) && (empty($mobile_no)))
	 {
	  echo "<script type='text/javascript'>";
			echo "alert('Please fill all mandatory fields')";
			echo "</script>";
	 
	 }
	 
	 
	 else
	 {
	  $sqlsearch="select `case_id` from `sbialloc_tbl` where `case_id`='$case_id' and `appco_applicant`='$appco_applicant' and `type`='RV' and `name`='$name'  and `loan_type`='$loan_type'  and `dump_date`='$dump_date'  and  `address1`='$address1'";
	$resultsearch=mysqli_query($conn,$sqlsearch);
	$datasearch=mysqli_fetch_array($resultsearch);
	if($datasearch['case_id']==$case_id)
	{
	}
       else
	{
		$sqlinsert	="insert into `sbialloc_tbl` (`case_id`,`loan_type`,`loan_amount`,`appco_applicant`,`type`,`name`,`address1`,
					`status`,`dump_date`,`month`,`entry_by`,`entry_date`,`entry_time`,`promo_code`,`pincode`,`mobile_no`,`alt_no`,`additional_information`,`zone`)  
					    values('".$case_id."','".$loan_type."','".$loan_amount."','".$appco_applicant."','".$type."','".$name."','".$address1."',
							'".$status."','".$dump_date."','".$month."','".$entry_by."','".$entry_date."','".$entry_time."','".$promo_code."','".$pincode."',
							'".$mobile_no."','".$alt_no."','".$additional_information."','".$zone."')";
			$resultinsert=mysqli_query($conn,$sqlinsert);
		}
		}
		}
		else
		{
		}
		if($type2=="OV")
		{
		if((empty($baddress1)) && (empty($bpincode)) && (empty($bmobile_no)))
	 {
	  echo "<script type='text/javascript'>";
			echo "alert('Please fill all mandatory fields')";
			echo "</script>";
	 
	 }
	 else
	 {
		$sqlsearchov="select `case_id` from `sbialloc_tbl` where `case_id`='$case_id' and `appco_applicant`='$appco_applicant' and `type`='OV' and `name`='$name' and `loan_type`='$loan_type'  and `dump_date`='$dump_date' and `address1`='$address1'";
	$resultsearchov=mysqli_query($conn,$sqlsearchov);
	$datasearchov=mysqli_fetch_array($resultsearchov);
	if($datasearchov['case_id']==$case_id)
	{
	}
       else
	{
			$sqlinsert	="insert into `sbialloc_tbl` (`case_id`,`loan_type`,`loan_amount`,`appco_applicant`,`type`,`name`,`address1`,
					`status`,`dump_date`,`month`,`entry_by`,`entry_date`,`entry_time`,`promo_code`,`pincode`,`mobile_no`,`company_name`,`alt_no`,`additional_information`,`zone`)  
					    values('".$case_id."','".$loan_type."','".$loan_amount."','".$appco_applicant."','".$type2."','".$name."','".$baddress."',
							'".$status."','".$dump_date."','".$month."','".$entry_by."','".$entry_date."','".$entry_time."','".$promo_code."','".$bpincode."',
							'".$bmobile_no."','".$company_name."','".$balt_no."','".$badditional_information."','".$zone."')";
			$resultinsert=mysqli_query($conn,$sqlinsert);
			}
			}
			}
			else
			{
			}
		if($_POST['ver_type']=="DOCS")
		{	
	
	 if(strlen($assesment_year1) >0)
	 {
	  $sqlsearch2="select `pan_no`,`assesment_year1` from `sbialloc_tbl` where `pan_no`='$pan_no' and `assesment_year1`='$assesment_year1'   and `loan_type`='$loan_type'  and `dump_date`='$dump_date' ";
	$resultsearch2=mysqli_query($conn,$sqlsearch2);
	$datasearch2=mysqli_fetch_array($resultsearch2);   
	 
	 if((strlen($datasearch2['pan_no'])>0) and (strlen($datasearch2['assesment_year1'])>0))
	{
	}
    else
	{
	 $sqlinsertdocsy1 ="insert into `sbialloc_tbl` set `case_id`='$case_id',
			`loan_type`='$loan_type',
			`appco_applicant`='$appco_applicant',
			`type`='DOCS',
			`name`='$name',   
			`pan_no`='$pan_no',
			`assesment_year1`='$assesment_year1',
			`status`='$status',
			`dump_date`='$dump_date',
			`month`='$month',
			`entry_by`='$entry_by',
			`entry_date`='$entry_date',
			`entry_time`='$entry_time',
			`promo_code`='$promo_code',	
			`zone`='$zone'	";
		$resultinsert=mysqli_query($conn,$sqlinsertdocsy1);
	} 
	}
	if(strlen($assesment_year2) >0)
	 {
	  $sqlsearchy2="select `pan_no` from `sbialloc_tbl` where `pan_no`='$pan_no' and `assesment_year1`='$assesment_year2' and `name`='$name'  and `loan_type`='$loan_type'  and `dump_date`='$dump_date' ";
	$resultsearchy2=mysqli_query($conn,$sqlsearchy2);
	$datasearchy2=mysqli_fetch_array($resultsearchy2);   
	 
	 if($datasearchy2['pan_no']==$pan_no)
	{
	}
    else
	{
	 $sqlinsertdocsy2 ="insert into `sbialloc_tbl` set `case_id`='$case_id',
			`loan_type`='$loan_type',
			`appco_applicant`='$appco_applicant',
			`type`='DOCS',
			`name`='$name',   
			`pan_no`='$pan_no',
			`assesment_year1`='$assesment_year2',
			`status`='$status',
			`dump_date`='$dump_date',
			`month`='$month',
			`entry_by`='$entry_by',
			`entry_date`='$entry_date',
			`entry_time`='$entry_time',
			`promo_code`='$promo_code',	
			`zone`='$zone'	";
		$resultinsert=mysqli_query($conn,$sqlinsertdocsy2);
	} 
	
	} 
	if(strlen($assesment_year3) >0)
	 {
	  $sqlsearchy3="select `pan_no` from `sbialloc_tbl` where `pan_no`='$pan_no' and `assesment_year1`='$assesment_year3' and `name`='$name'  and `loan_type`='$loan_type'  and `dump_date`='$dump_date' ";
	$resultsearchy3=mysqli_query($conn,$sqlsearchy3);
	$datasearchy3=mysqli_fetch_array($resultsearchy3);   
	 
	 if($datasearchy3['pan_no']==$pan_no)
	{
	}
    else
	{
	 $sqlinsertdocsy3 ="insert into `sbialloc_tbl` set `case_id`='$case_id',
			`loan_type`='$loan_type',
			`appco_applicant`='$appco_applicant',
			`type`='DOCS',
			`name`='$name',   
			`pan_no`='$pan_no',
			`assesment_year1`='$assesment_year3',
			`status`='$status',
			`dump_date`='$dump_date',
			`month`='$month',
			`entry_by`='$entry_by',
			`entry_date`='$entry_date',
			`entry_time`='$entry_time',
			`promo_code`='$promo_code',	
			`zone`='$zone'	";
		$resultinsert=mysqli_query($conn,$sqlinsertdocsy3);
	} 
	
	} 
	elseif(strlen($bank_name)>0)
	{
	 	$sqlsearch="select `case_id` from `sbialloc_tbl` where `case_id`='$case_id' and `appco_applicant`='$appco_applicant' and `type`='DOCS' and `name`='$name'  and `loan_type`='$loan_type'  and `dump_date`='$dump_date' ";
	$resultsearch=mysqli_query($conn,$sqlsearch);
	$datasearch=mysqli_fetch_array($resultsearch);
	if($datasearch['case_id']==$case_id)
	{
	}
    else
	{   
	 $sqlinsertdocs ="insert into `sbialloc_tbl` set `case_id`='$case_id',
			`loan_type`='$loan_type',
			`appco_applicant`='$appco_applicant',
			`type`='DOCS',
			`name`='$name',
			`bank_name`='$bank_name',	
			`account_no`='$account_no',
			`branch`='$branch',
			`pan_no`='$pan_no',
			`assesment_year1`='$assesment_year1',
			`assesment_year2`='$assesment_year2',
			`assesment_year3`='$assesment_year3',
			`status`='$status',
			`dump_date`='$dump_date',
			`month`='$month',
			`entry_by`='$entry_by',
			`entry_date`='$entry_date',
			`entry_time`='$entry_time',
			`promo_code`='$promo_code',	
			`zone`='$zone'	";
		$resultinsert=mysqli_query($conn,$sqlinsertdocs);
		}
	}
		}
		else
		{
		}
			if($resultinsert)
			{
			echo "<script type='text/javascript'>";
			echo "alert('CASE SAVE SUCCESSFULLY ');";
			echo "</script>";
			echo "<script type='text/javascript'>";
			echo "window.location='home.php?Bankers=SearchSBICase'";
			echo "</script>"; 
			}
			else
			{
			}
			}
			
	
?>
<html>
<body style='bgcolor="#E6E6FA" border="10px;solid black;" width=100%; height=100%'>
<head>
  <title>Create:New Case</title>
    <script type="text/javascript">
    function noBack() { window.history.forward(); }
    noBack();
    window.onload = noBack;
    window.onpageshow = function (evt) { if (evt.persisted) noBack(); }
    window.onunload = function () { void (0); }
	</script>	
  <style>
  #searchbutton  {
	background-color:#228B22;
	color:#FFF;
	padding:5px;
	border-radius:8px;
	font-weight:bold;
}
#searchbutton:hover  {
	background-color:#228B22;
	color:#FFF;
	padding:5px;
	border-radius:8px;
}
.button {
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}
.button {background-color: #008CBA;}

	#rv {display: none}
	#ov {display: none}
	#Docs {display: none}
</style>
<script type="text/javascript"> 
	
	function showMe (it, box) { 
	  var vis = (box.checked) ? "block" : "none"; 
	  document.getElementById(it).style.display = vis;
	} 
	function showOV (it, box) { 
	  var vis = (box.checked) ? "block" : "none"; 
	  document.getElementById(it).style.display = vis;
	} 
	function showDOCS (it, box) { 
	  var vis = (box.checked) ? "block" : "none"; 
	  document.getElementById(it).style.display = vis;
	} 
</script>
  <link type="text/css" href="menu/menu_admin.css" rel="stylesheet" />
  <script>
      function getXMLHTTP() { //fuction to return the xml http object

	var xmlhttp=false;	

	try{

	xmlhttp=new XMLHttpRequest();

	}

	catch(e)	{		

	try{			

	xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");

	}

	catch(e){

	try{

	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

	}

	catch(e1){

	xmlhttp=false;

	}

	}

	}
	return xmlhttp;

	}
	function getVertype(strURL) {
		var req = getXMLHTTP();
		if (req) {
		req.onreadystatechange = function() {

		if (req.readyState == 4) {
		
		if (req.status == 200) {						

		document.getElementById('vertypediv').innerHTML=req.responseText;						

		} else {

		alert("There was a problem while using XMLHTTP:\n" + req.statusText);

		}

		}				

		}			

		req.open("GET", strURL, true);

		req.send(null);
		}
		}
		function getDocs(strURL) {
		var req = getXMLHTTP();
		if (req) {
		req.onreadystatechange = function() {

		if (req.readyState == 4) {
		
		if (req.status == 200) {						

		document.getElementById('docsdiv').innerHTML=req.responseText;						

		} else {

		alert("There was a problem while using XMLHTTP:\n" + req.statusText);

		}

		}				

		}			

		req.open("GET", strURL, true);

		req.send(null);
		}
		}

  </script>
  </head>
<body>
<div class="background">
<form method ="post" action=""/>

<?php
	include("header2.php");
	if(($_SESSION['unique_id']=='B'))
	{
	include("menu/menu_bank.php");
	}	
	else
	{
	header("location:index.php");
	}
	?>
	<table style="width:1025px;" align="center">
<tr >
<td bgcolor="#008CBA" style="width:1000px;height:35px;" ><font color="white" font size="6px;"><b>Create Case</b>  &nbsp;&nbsp;</font></td>
</tr>
</table>
<table border="0" cellpadding="0" cellspacing="1" width="900" align="center">	
		<td>
		<fieldset style="width:1000px; margin-top:2px;">
		<table  style="width:1000px;" cellspacing="5" align="center">
		<tr>
		<td><b>Reference No</b><span><font color="red">*</font></span> </td>
		<td><input type="text" name="case_id" class="field"  style="width:350px; height:35px;text-transform: uppercase;" placeholder="Reference No" required /></td>			
		</tr>
		<input type="hidden" name="promo_code" value="<?php echo $datau['id']; ?>"/ >
		<input type="hidden" name="zone" value="<?php echo $datau['zone']; ?>"/ >
		<tr>
		<td><b>Type Verification</b><span><font color="red">*</font></span> </td>
		<td><select name="ver_type" id="ver_type" class="field"  style="width:350px; height:35px;" onChange="getVertype('vertype_list.php?ver_type='+this.value)" required >
			<option value="">--Select Verification Type--</option>
			<option value="FI">FI</option>
			<option value="DOCS">DOCS</option>
		</select>
		</td>			
		</tr>
		</table>
		<table  style="width:1000px;" cellspacing="5" align="center"id="vertypediv">
		<tr>
		<td><b>Type of Loan</b><span><font color="red">*</font></span> </td>
		<td ><select name="loan_type" class="field"  style="width:350px; height:35px;" required >
			<option value="">--Select Product--</option>
			<option value="Personal Loan">Personal Loan</option>
			<option value="Auto Loan">Auto Loan</option>
			<option value="Education Loan">Education Loan</option>
			<option value="Housing Loan">Housing Loan</option>
			<option value="Seller-FI">Seller-FI</option>
			<option value="BSV">BSV</option>
			<option value="ITR">ITR</option>
			<option value="Bank Statement">Bank Statement</option>
			<option value="Current Account">Current Account</option>
			<option value="Form16">Form16</option>
			<option value="Form26">Form26</option>
			</select>
		</td>			
		</tr>
	    
		<tr>
		<td><b>Type of Applicant</b><span><font color="red">*</font></span> </td>
		<td><select name="appco_applicant" class="field"  style="width:350px; height:35px;" required >
			<option value="">--Select --</option>
			<option value="Applicant">Applicant</option>
			<option value="Co-Applicant">Co-Applicant</option>
			<option value="Guarantor">Guarantor</option>
			</select>
		</td>			
		</tr>
		<tr>
		<td><b>Applicant Name</b><span><font color="red">*</font></span> </td>
		<td><input type="text" name="name" class="field"  style="width:350px; height:35px;text-transform: uppercase;" placeholder="Applicant Name"  required/></td>			
		</tr>
			<tr>
		<td><b>FI Type</b><span><font color="red">*</font></span> </td>		
		<td><input type="checkbox" name="type" value="RV" onclick="showMe('divnb', this)">&nbsp; RV &nbsp;<input type="checkbox" name="type2" value="OV" onclick="showOV('divov', this)"> &nbsp; BV</td>			
		</tr>
			<tr>
		<td><b>Loan Amount</b> </td>
		<td><input type="text" name="loan_amount" class="field"  style="width:350px; height:35px;text-transform: uppercase;" placeholder="Amount" /></td>			
		</tr>
		
		</table>
		<table  style="width:1000px;" cellspacing="5" align="center" id="docsdiv">
		    
		</table>
		
		
		<div class="row" id="divnb" style="display:none">
		<table  style="width:1000px;" cellspacing="5" align="center"  >			
		<tr>
		<td><b>Residence Address </b><span><font color="red">*</font></span> </td>
		<td><input type="text" name="address1" class="field"  style="width:350px; height:35px;text-transform: uppercase;" placeholder="Residence Address" value="<?php if(isset($address1)){echo $address1;} ?>"  <?php if(isset($code) && $code == 1){ echo "autofocus"; }  ?>  /></td>			
		</tr>
		<tr>
		<td><b>Pincode</b> </td>
		<td><input type="text" name="pincode" class="field"  style="width:350px; height:35px;" placeholder="Residence Pincode" /></td>			
		</tr>
		<tr>
		<td><b>Contact Number</b> <span><font color="red">*</font></span></td>
		<td><input type="text" name="mobile_no" class="field"  style="width:350px; height:35px;" placeholder="Phone No"   /></td>			
		</tr>
		<tr>
		<td><b>Alternate Number</b> </td>
		<td><input type="text" name="alt_no" class="field"  style="width:350px; height:35px;" placeholder="Alternate No"   /></td>			
		</tr>
		<tr>
		<td><b>Additional Information</b> </td>
		<td><input type="text" name="additional_information" class="field"  style="width:350px; height:35px;text-transform: uppercase;" placeholder="Additional Information"  /></td>			
		</tr>
		</table>
		</div>
		<div class="row" id="divov" style="display:none">
		<table  style="width:1000px;" cellspacing="5" align="center" >			
		<tr>
		<td><b>Business  Address </b><span><font color="red">*</font></span> </td>
		<td><input type="text" name="baddress" class="field"  style="width:350px; height:35px;text-transform: uppercase;" placeholder="Business Address" /></td>			
		</tr>
		<tr>
		<td><b>Pincode</b><span><font color="red">*</font></span> </td>
		<td><input type="text" name="bpincode" class="field"  style="width:350px; height:35px;" placeholder="Pincode"  /></td>			
		</tr>
		<tr>
		<td><b>Contact Number</b> <span><font color="red">*</font></span></td>
		<td><input type="text" name="bmobile_no" class="field"  style="width:350px; height:35px;" placeholder="Phone No"   /></td>			
		</tr>
		<tr>
		<td><b>Alternate Number</b> </span></td>
		<td><input type="text" name="balt_no" class="field"  style="width:350px; height:35px;" placeholder="Alternate No"  /></td>			
		</tr>
		<tr>
		<td><b>Additional Information</b> </td>
		<td><input type="text" name="badditional_information" class="field"  style="width:350px; height:35px;text-transform: uppercase;" placeholder="Additional Information"  /></td>			
		</tr>
		<tr>
		<td><b>Company Name</b> </td>
		<td><input type="text" name="company_name" class="field"  style="width:350px; height:35px;text-transform: uppercase;" placeholder="Company Name"  /></td>			
		</tr>	
		</table>
		</div>
		
	
		<table  style="width:1000px;" cellspacing="5" align="center">
		
		<tr>
		<td style="width:400px;" >&nbsp;</td>
		<td  ><input type="submit" name="txtsubmit" button class="button button" value="Save"></button></td>			
			</tr>
		</table>		
			</fieldset>
			</td>
			</tr>			
			</table>			
			</form>
			</body>
			</html>

