<?php

session_start();

require('../lib/dbclass.php');




require('../PhpXlsxGenerator.php') ;


// Filter the excel data
function filterData(&$str)
{
    $str = preg_replace("/\t/", '\\t', $str);
    $str = preg_replace("/\r?\n/", '\\n', $str);

    if (strstr($str, '"')) {
        $str = '"' . str_replace('"', '""', $str) . '"';
    }
}

// Excel file name for download
$fileName = 'Volunteer Settlement Details.xlsx';

// Column names
$excelData[] = ['Name','Date','Amount','Transaction ID'];


$wherenew = $_SESSION['wherenew'];

$data = findQuery("SELECT ca_receipt.*,tbl_user.name,ca_receipt.amount Received  FROM `ca_receipt` inner join tbl_user on tbl_user.id=ca_receipt.userid
     where $wherenew");

if ($data) {
    // Output each row of the data
    foreach ($data as $index => $row) {
        $lineData = [
                        $row['name'],
                        date('d-m-Y', strtotime($row['send_date'])),
                        $row['amount'],
                        $row['transid'],
                        ];
        $excelData[] = $lineData;
    }
} else {
    $excelData .= 'No records found...' . "\n";
}

// Export data to excel and download as xlsx file
$xlsx = CodexWorld\PhpXlsxGenerator::fromArray($excelData);
$xlsx->downloadAs($fileName);

exit;
