<?php
 include '../config/index.php';
 include '../module/index.php';

$data = new Database;

$con  = $data->connect();

$user = new User($con);

$post = filter_var_array($_POST,FILTER_SANITIZE_FULL_SPECIAL_CHARS);

$county        = $post['country'];
$fullname      = $post['fullname'];
$city          = $post['city'];
$sort          = $post['sort'] ?? 0;
$address       = $post['address'];
$zipcode       = $post['zipcode'];
$email         = $post['email'];
$phone         = $post['phone'];
$iban          = $post['iban'];
$swiftcode     = $post['swiftcode'];
$accountnumber = $post['accountnumber'];
$bank          = $post['bank'];


$transfer = [
   'country'=>$county,
   'city'=>$city,
   'sort'=>$sort,
   'name'=>$fullname,
   'address'=>$address,
   'zipcode'=>$zipcode,
   'email'=>$email,
   'phone'=>$phone,
   'iban'=>$iban,
   'swiftcode'=>$swiftcode,
   'bank'=>$bank,
   'accountnumber'=>$accountnumber,
];

$_SESSION['int']   = $transfer;

$email = $_SESSION['email'];
$id = $_SESSION['id'];

if($user->pemission($id)->transfer == false){
   $_SESSION['t_error_c']  = "Your account has been Restricted and Suspended from initiating a fund transfer request, Kindly contact us via email at: ibanking@vaultmorebk.com  for more instruction regarding re-activation of your account before your transfer can be completed.";
   echo $data->redirect('../account/../index?wire=wire');
}else{
   
   if($user->pemission($id)->otp == false){
      $user_name = $_SESSION['first_name'];
      $type = 'Debit';
      $d = 'DT';
      $user_id = $_SESSION['id'];
      $amount = $_SESSION['inter_amount'];

      $reference = uniqid();
      $date      = new DateTime();
      $dates     = $date->format('d M y, h:i a'); // 21 Dec 22, 08:39 pm
      $status    = 'complete';

      echo $user->fundTransfer($amount);
      
      echo $user->createTransaction($amount,$user_id,$reference,'nill',$dates,$status,$type,$user_name.'/'.$d.'_'.$reference.'>'.$amount);

      echo $user->InterTransfer($_SESSION['int']['name'],$_SESSION['int']['sort'],$_SESSION['int']['accountnumber'],$_SESSION['inter_amount'],$_SESSION['int']['bank'],$_SESSION['int']['country'],$_SESSION['int']['city'],$_SESSION['description']);

      $_SESSION['t_error_c']  = 'Transaction has been successful, it may take 3 to 10 working day for it to reflect on the recipient account';

      echo $data->redirect('../account/../index?home=home');
   }else{
   
      echo $user->sendOtherOTP($email,$name=null);
      //echo $user->sendOTP($email,$name=null);
      echo $data->redirect('../account/../index?mt=mt');
   }
}

?>