<?php
	include_once('../config.php');      
	include_once(ABS_PATH.'/custom_function/default.php'); 
    if(!isset($_SESSION['userId']))
    { 
         header("Location: ../");
         die;
    }   
    
                        
                                
                if(isset($_POST['submit']))
                {    
                    $stmt=$conn->prepare("select amt from  UI__DChstr    where Rid=:cuurentId    order by id desc  ");   
                    $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_INT);  
                    $stmt->execute(); 
                    $UI__Rgst = $stmt->fetch(PDO::FETCH_OBJ);            
                    $Amt  = $UI__Rgst->amt; 
                      
                    $stmt=$conn->prepare("select amt from  UI__InstaLoan    where custId=:cuurentId     ");   
                    $stmt->bindValue(':cuurentId',  $_SESSION['userId'] , PDO::PARAM_INT);  
                    $stmt->execute(); 
                     
                       
                    if( ($Amt>=10000) && ($_POST['amount'] <= $Amt) && ($stmt->rowCount()<1)) 
                    {
                        $stmt=$conn->prepare("insert into  UI__InstaLoan (amt,Tdate,custId) values(:amt,:Tdate,:custId)");   
                        $stmt->bindValue(':amt',  $_POST['amount'] , PDO::PARAM_STR);    
                        $stmt->bindValue(':Tdate',  date("d-M-Y") , PDO::PARAM_STR);
                        $stmt->bindValue(':custId', $_SESSION['userId']  , PDO::PARAM_STR); 
                        $stmt->execute();
                        $_SESSION['Regis'] = "Credit request sent successfully for amount ".$_POST['amount'];
                        $_SESSION['topSuc'] = 1;
                    }else
                        $_SESSION['Regis'] = "You already applied or you are not applicable for entered amount";  
                         
                    header("Location: instaloan.php");
                    die;
                }   
include_once("../view/dashboard/instaloan.php");
?>