<?php

use JetBrains\PhpStorm\ArrayShape;

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);
$id            = $_GET['back'];

$start_date    = $post['start_date'];
$end_date      = $post['end_date'];

$type          =   $post['type'];

if($type == 'Credit'){
   $t = 'CT';
}else{
   $t ='DB';
}

$status        =  'complete';

$last_names   =  array(
   "Emily", "Madison", "Ashley", "Sarah", "Jessica", "Brianna", "Amanda", "Taylor", "Elizabeth", "Lauren",
   "Megan", "Alyssa", "Hannah", "Makayla", "Kaylee", "Mackenzie", "Abigail", "Hailey", "Alexis", "Allison", 
   "Avery", "Brooklyn", "Evelyn", "Leah", "Adriana", "Aurora", "Arianna", "Autumn", "Aaliyah", "Isabella", 
   "Gabriella", "Aubree", "Brooklynn", "Bella", "Adalynn", "Rylee", "Aubree", "Jasmine", "Eleanor", "Adeline", 
   "Avery", "Jordan", "Annabelle", "Natalie", "Faith", "Alexandra", "Sadie", "Brielle", "Karina", "Christina", 
   "Maria", "Aurora", "Naomi", "Angelina", "Aaliyah", "Allyson", "Makayla", "Avery", "Jocelyn", 
   "Kendall", "Mackenzie", "Bailey", "Gianna", "Genesis"
);

$ran_name     = array_rand($last_names);

// Create a DateTime object for the start date
$current_date = new DateTime($start_date);

// Create a DateTime object for the end date
$end_date = new DateTime($end_date);

while($current_date <= $end_date){
    $ref         = uniqid();
    $amount      = rand(200,1000);
    $ran         = rand(0,6) ?? 2;

   echo $user->createTransaction($amount,$id,$ref,'',$current_date->format('d M y, h:i a'),$status,$type,$last_names[$ran].'/'.$t.'_'.$ref.'>'.$amount.'',$amount);

   $current_date->modify('+1 day');
}

$_SESSION['t_error_c']  = 'transaction backdated successfully ';
echo $data->redirect("../account/../index?back=$id");

?>