<?php
	require_once('functions.php');
date_default_timezone_set('AFRICA/NAIROBI');
$session=session_id();
  if(isset($_POST['submitted'])){
      $current = $_POST['date'];
      $id= $_SESSION['id'];
      $_SESSION['f']=$session;
       $con=mysqli_connect("localhost","gurudumu_bazuu2","@@karishop@@2023!!","gurudumu_pos");
      $name=mysqli_real_escape_string($con,trim($_POST['name']));
            $wage=mysqli_real_escape_string($con,trim($_POST['salary']));
            $vt=$wage*3;
            
                  $mont=mysqli_real_escape_string($con,trim($_POST['mont']));
                        $tpy=mysqli_real_escape_string($con,trim($_POST['tpy']));
                         $amnt=mysqli_real_escape_string($con,trim($_POST['amnt']));
                         $vf=$tpy+$vt;
                           $new_date = date('Y-m-d', strtotime($current . ' + ' . $mont . ' months'));
                           if($vt>=$tpy){
      $mh=mysqli_query($con,("insert into lones(lab_id,name,amnt,wage,dat,datt,tpy,sessio)values('$id','$name','$amnt','$wage','$current','$new_date','$tpy','$session')"));
      
                               $gj="insert into loans(date,credit,description,account_id,froms,session,mat_date,dat)values
('$current','$tpy','LOAN APPLICATION','4', '$id', '$session','$new_date',NOW())";
$koo=mysqli_query($dbc,$gj);
$kii="insert into loans(date,debit,description,account_id,froms,session,mat_date,dat)
values('$current','$tpy','LOAN APPLICATION','$id', '4', '$session','$new_date',NOW())";
   $mi=mysqli_query($dbc,$kii);
                           }else{
                              $error='Sorry But The Applicant is not Eligible for   Such An Amount!!';
                              $_SESSION['ERR']=$error;
                              	$url="lones.php";
ob_end_clean();
header("Location: $url");
                           }
                          
  }
  	$url="lones.php";
ob_end_clean();
header("Location: $url");
mysqli_close($dbc);
session_regenerate_id();