<?php
 include '../config/index.php';
 include '../module/index.php';
 
$data = new Database;

$con  = $data->connect();
$user = new user($con);

foreach($user->getAll('site_setting') as $val):
endforeach;

$post = filter_var_array($_POST,FILTER_SANITIZE_FULL_SPECIAL_CHARS);

$bal       = $post['balance'];
$amount    = $post['amount'];
$account   = $post['account'];
$id        = $_SESSION['id'];

if($amount > $bal){
   $_SESSION['t_error_c']  = 'insufficient balance';
   echo $data->redirect('../account/../index?wire=wire');
   
}else if($user->pemission($id)->transfer == false){
   $_SESSION['t_error_c']  = "Your account has been Restricted and Suspended from initiating a fund transfer request, please contact  support for more instruction regarding your account re-activation  before your fund transfer can be completed.";
   echo $data->redirect('../account/../index?local=local');

}else if($data->checkAcc($account) == true){
   $_SESSION['t_error_c']  = 'Account number does not exist';
   echo $data->redirect('../account/../index?local=local');
}else{
   $_SESSION['amount']     = $amount;
   $_SESSION['account_tr'] = $account;

   if($user->pemission($id)->otp == false){

      $id = $user->getByAccountNo($account)->id;
      $name = $user->getByAccountNo($account)->first_name;
      $user_name = $_SESSION['first_name'];
      $type = 'Debit';
      $d = 'DT';
      $c = 'CT';
      $user_id = $_SESSION['id'];

      $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->creditTransfer($amount,$id);
      
      echo $user->createTransaction($amount,$user_id,$reference,'nill',$dates,$status,$type,$name.'/'.$d.'_'.$reference.'>'.$amount);
      echo $user->createTransaction($amount,$id,$reference,'nill',$dates,$status,'Credit',$user_name.'/'.$c.'_'.$reference.'>'.$amount);

      $_SESSION['t_error_c']  = 'Transaction complete sucessfully';

      echo $data->redirect('../account/../index?home=home');
   }else{
      echo $data->redirect('../account/../index?pin=pin');
   }
}

?>