<?php
session_start();
require_once '../utils/errorhandler.php';
require_once '../utils/response.php';
require_once '../model/dbclass.php';
require_once '../model/model.php';
require_once '../model/transaction.php';

date_default_timezone_set('Africa/Lagos');
if ($_SESSION['wuseremail'] === null || !isset($_SESSION['wuseremail'])) {
     exit(badRequest(204,'Invalid session data. Proceed to login'));
}

$startdate = (isset($_POST["startdate"]) && $_POST["startdate"] !== "") ? $_POST["startdate"] : date('Y-m-d');
$enddate = (isset($_POST["enddate"]) && $_POST["enddate"] !== "") ? $_POST["enddate"] : date('Y-m-d');
$ttype = (isset($_POST["ttype"]) && $_POST["ttype"] !== "") ? $_POST["ttype"] : '%';
$email = (isset($_POST["email"]) && $_POST["email"] !== "") ? $_POST["email"] : '%';

//exit("Startdate: " . $startdate . " Enddate: " . $enddate . " ttype: " . $_POST["ttype"]);
$transaction = new Transaction();
$tresult = $transaction->executeTransactionByQuerySelector("SELECT *,(SELECT description FROM glaccount WHERE glaccount.accountnumber = tdetail.accountnumber) AS accountname FROM tdetail WHERE status = 'POSTED' AND user LIKE '$email' AND whichaccount LIKE 'GLACCOUNT' AND DATE(transactiondate) BETWEEN '$startdate' AND '$enddate' ORDER BY transactiondate ASC");

if($tresult){
	echo success($tresult,200, "Successful" ,"Successful");
}else{
	echo badRequest(204, "Not successful");
}
?>