<?php
if (!auth_can('payments.view')) return;
$db = Database::getInstance();
$todayRevenue = (float)$db->fetchColumn("SELECT COALESCE(SUM(amount),0) FROM payments WHERE payment_date=CURDATE() AND status='completed' AND is_deleted=0");
$yesterdayRevenue = (float)$db->fetchColumn("SELECT COALESCE(SUM(amount),0) FROM payments WHERE payment_date=DATE_SUB(CURDATE(), INTERVAL 1 DAY) AND status='completed' AND is_deleted=0");
$trend = $yesterdayRevenue > 0 ? round(($todayRevenue - $yesterdayRevenue) / $yesterdayRevenue * 100) : 0;
?>
<div class="card border-success h-100">
    <div class="card-body">
        <div class="d-flex justify-content-between">
            <div>
                <h6 class="text-muted mb-1"><?= lang('finance.revenue_today') ?></h6>
                <h3 class="mb-0"><?= money($todayRevenue) ?></h3>
                <?php if ($trend != 0): ?>
                <small class="<?= $trend > 0 ? 'text-success' : 'text-danger' ?>">
                    <i class="fas fa-arrow-<?= $trend > 0 ? 'up' : 'down' ?>"></i> <?= abs($trend) ?>%
                </small>
                <?php endif; ?>
            </div>
            <div class="align-self-center"><i class="fas fa-coins fa-2x text-success opacity-50"></i></div>
        </div>
    </div>
</div>