<?php
require_once __DIR__.'/../includes/functions.php';
require_once __DIR__.'/../includes/v292_admin_portal_helpers.php';
$admin=require_admin(); mj292_ensure_schema();
$adminTitle='Report Dashboard'; $adminSubtitle='Grouped reports for users, listings, companies, payments, invoices, wallet, receipts, revenue, expiry and admin activity.';
$stats=mj292_admin_stats();
$reports=[
 ['User Report','Users, wallet and account details','report-users.php','fas fa-users','primary',$stats['users_total']],
 ['Listing Report','Listings, sponsored, featured, expiry','report-listings.php','fas fa-tags','success',$stats['listings_total']],
 ['Company Report','Company profiles and verification','report-companies.php','fas fa-building','info',$stats['companies_total']],
 ['Payment Report','Manual/wallet payment batches','report-payments.php','fas fa-credit-card','warning',$stats['payment_pending']],
 ['Invoice Report','Paid/open invoices with print','report-invoices.php','fas fa-file-invoice','primary',$stats['invoice_open']],
 ['Wallet Report','Credits, debits and balances','report-wallets.php','fas fa-wallet','success',mj292_money0($stats['wallet_balance'],'SGD')],
 ['Receipt Report','Generated receipts and print','report-receipts.php','fas fa-receipt','info',$stats['receipts_total']],
 ['Revenue Report','Revenue by service type','report-revenue.php','fas fa-coins','success',mj292_money0($stats['receipt_amount'],'SGD')],
 ['Expiry Report','Listings/sponsor/feature expiry','report-expiry.php','fas fa-hourglass-half','danger',$stats['listings_expired']],
 ['Lead Tracking','Views, clicks, QR, shares','report-leads.php','fas fa-mouse-pointer','secondary',mj292_count('mj_lead_events')],
 ['Admin Activity','Audit and admin actions','report-admin-activity.php','fas fa-history','secondary',mj292_count('mj_admin_logs')],
 ['Reset Logs','Safe reset history','report-reset-logs.php','fas fa-undo','danger',mj292_count('mj_admin_reset_logs')],
];
include __DIR__.'/_header.php';
?>
<div class="row">
<?php foreach($reports as $r): ?>
  <div class="col-xl-3 col-md-6 mb-3"><a href="<?=e($r[2])?>" class="card mj-v292-card h-100 text-dark"><div class="card-body"><div class="d-flex justify-content-between"><div><h5 class="font-weight-bold mb-1"><?=e($r[0])?></h5><p class="text-muted mb-2"><?=e($r[1])?></p><span class="badge badge-<?=e($r[4])?> p-2"><?=e((string)$r[5])?></span></div><i class="<?=e($r[3])?> fa-2x text-<?=e($r[4])?>"></i></div></div></a></div>
<?php endforeach; ?>
</div>
<div class="card mj-v292-card"><div class="card-body"><h5 class="font-weight-bold">Report Rules</h5><p class="mb-0 text-muted">Reports are generated from live data with filters and print support. Wallet top-up funding and wallet service spending are separated so finance is not double-counted.</p></div></div>
<?php include __DIR__.'/_footer.php'; ?>
