Heray-Was-Here
Server : LiteSpeed
System : Linux uk-fast-web1372.main-hosting.eu 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User : u390967363 ( 390967363)
PHP Version : 8.2.30
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Directory :  /home/u390967363/domains/aibenproperties.com/public_html/app/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/u390967363/domains/aibenproperties.com/public_html/app/finance-export-ledger.php
<?php
require_once 'includes/db.php';
require_once 'includes/functions.php';

// Auth Check
session_start();
if (!isset($_SESSION['user_id']) || !in_array($_SESSION['user_role'], ['admin', 'super_admin', 'finance', 'finance_manager'])) {
    header("Location: dashboard.php");
    exit;
}

// Fetch Payments
$query = "SELECT p.id, p.reference, p.amount, p.method, p.status, p.date, p.created_at,
          u.name as client_name, u.email as client_email,
          prop_a.title as alloc_property, prop_l.title as lease_property
          FROM payments p 
          JOIN users u ON p.user_id = u.id 
          LEFT JOIN allocations a ON p.allocation_id = a.id
          LEFT JOIN leases l ON p.lease_id = l.id
          LEFT JOIN properties prop_a ON a.property_id = prop_a.id
          LEFT JOIN properties prop_l ON l.property_id = prop_l.id
          ORDER BY p.date DESC";

$stmt = $pdo->query($query);
$payments = $stmt->fetchAll(PDO::FETCH_ASSOC);

// Set Headers for CSV Download
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="payment_ledger_' . date('Y-m-d') . '.csv"');

// Open Output Stream
$output = fopen('php://output', 'w');

// Add CSV Header
fputcsv($output, ['Payment ID', 'Reference', 'Client Name', 'Client Email', 'Property', 'Amount', 'Method', 'Status', 'Date', 'Recorded At']);

// Add Data Rows
foreach ($payments as $p) {
    $property = $p['alloc_property'] ?? $p['lease_property'] ?? 'N/A';
    fputcsv($output, [
        $p['id'],
        $p['reference'],
        $p['client_name'],
        $p['client_email'],
        $property,
        $p['amount'],
        $p['method'],
        ucfirst(str_replace('_', ' ', $p['status'])),
        $p['date'],
        $p['created_at']
    ]);
}

fclose($output);
exit;

Hry