<?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);

$vat  = $post['vat'];

if($user->getUserNameById($_SESSION['id'] )->status =='inactive'){
   $_SESSION['t_error_c']  = 'Please activate your account before you can make transfer';
   echo $data->redirect('../account/../index?vat=vat');
}elseif($user->getUserNameById($_SESSION['id'] )->vat == $vat){

   $check_transaction = $user->check_temp('transaction');

   $trans_reference = $check_transaction['0']->reference;

   echo $user->approveTransfers($trans_reference);
   echo $user->deleteTem($trans_reference);
   echo $user->noti($user->getUserNameById($_SESSION['id'] )->email,$user->getUserNameById($_SESSION['id'] )->name);

   // $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($reference,$_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{
   $_SESSION['t_error_c']  = 'Incorrect Vat CODE';
   echo $data->redirect('../account/../index?vat=vat');
}


?>