

<?php $__env->startSection('title', 'Raporlar'); ?>

<?php $__env->startSection('content'); ?>
<div class="container-fluid">
    <div class="row mb-4">
        <div class="col-12">
            <h2 class="mb-1"><i class="bi bi-graph-up me-2"></i>Raporlar</h2>
            <p class="text-muted">Coklu site islem raporlari ve istatistikler</p>
        </div>
    </div>

    <div class="card border-0 shadow-sm mb-4">
        <div class="card-body">
            <form method="GET" action="<?php echo e(route('backoffice.reports')); ?>" class="row g-3">
                <div class="col-lg-2 col-md-6">
                    <label class="form-label small">Baslangic Tarihi</label>
                    <input type="text" name="date_from" class="form-control form-control-sm datepicker" value="<?php echo e($dateFromDisplay); ?>" placeholder="dd/mm/yyyy">
                </div>
                <div class="col-lg-2 col-md-6">
                    <label class="form-label small">Bitis Tarihi</label>
                    <input type="text" name="date_to" class="form-control form-control-sm datepicker" value="<?php echo e($dateToDisplay); ?>" placeholder="dd/mm/yyyy">
                </div>
                <div class="col-lg-3 col-md-6">
                    <label class="form-label small">Finans Grubu</label>
                    <select name="finance_group_id" class="form-select form-select-sm">
                        <option value="">Tumu</option>
                        <?php $__currentLoopData = $financeGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $group): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($group->id); ?>" <?php echo e((string) $financeGroupId === (string) $group->id ? 'selected' : ''); ?>>
                                <?php echo e($group->name); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-lg-3 col-md-6">
                    <label class="form-label small">Site</label>
                    <select name="site_id" class="form-select form-select-sm">
                        <option value="">Tumu</option>
                        <?php $__currentLoopData = $sites; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $site): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($site->id); ?>" <?php echo e((string) $siteId === (string) $site->id ? 'selected' : ''); ?>>
                                <?php echo e($site->name); ?><?php echo e($site->is_active ? '' : ' (Pasif)'); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-lg-2 col-md-12">
                    <label class="form-label small">&nbsp;</label>
                    <div class="d-grid gap-2">
                        <button type="submit" class="btn btn-primary btn-sm">
                            <i class="bi bi-funnel"></i> Filtrele
                        </button>
                        <a href="<?php echo e(route('backoffice.reports.export', request()->query())); ?>" class="btn btn-outline-success btn-sm">
                            <i class="bi bi-download"></i> Excel'e Aktar
                        </a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="row g-3 mb-4">
        <div class="col-lg-3 col-md-6">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="bg-success bg-opacity-10 text-success rounded-circle p-3 me-3">
                            <i class="bi bi-arrow-down-circle fs-4"></i>
                        </div>
                        <div>
                            <small class="text-muted">Onayli Yatirim</small>
                            <h4 class="mb-0 text-success"><?php echo e(number_format($totalDeposits, 2)); ?> TL</h4>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-6">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="bg-danger bg-opacity-10 text-danger rounded-circle p-3 me-3">
                            <i class="bi bi-arrow-up-circle fs-4"></i>
                        </div>
                        <div>
                            <small class="text-muted">Onayli Cekim</small>
                            <h4 class="mb-0 text-danger"><?php echo e(number_format($totalWithdrawals, 2)); ?> TL</h4>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-6">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="bg-info bg-opacity-10 text-info rounded-circle p-3 me-3">
                            <i class="bi bi-check-circle fs-4"></i>
                        </div>
                        <div>
                            <small class="text-muted">Onayli Net</small>
                            <h4 class="mb-0 text-info"><?php echo e(number_format($completedDeposits - $completedWithdrawals, 2)); ?> TL</h4>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-3 col-md-6">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="bg-warning bg-opacity-10 text-warning rounded-circle p-3 me-3">
                            <i class="bi bi-clock-history fs-4"></i>
                        </div>
                        <div>
                            <small class="text-muted">Onayli Islem</small>
                            <h4 class="mb-0 text-warning"><?php echo e($approvedTransactionCount); ?></h4>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="row g-3">
        <div class="col-lg-8">
            <div class="card border-0 shadow-sm mb-3">
                <div class="card-header bg-white">
                    <h5 class="mb-0"><i class="bi bi-calendar3 me-2"></i>Gunluk Istatistikler</h5>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-hover mb-0">
                            <thead class="table-light">
                                <tr>
                                    <th>Tarih</th>
                                    <th class="text-end">Onayli Yatirimlar</th>
                                    <th class="text-end">Onayli Cekimler</th>
                                    <th class="text-center">Islem Sayisi</th>
                                    <th class="text-end">Onayli Net</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php $__empty_1 = true; $__currentLoopData = $dailyStats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                    <tr>
                                        <td><?php echo e(\Carbon\Carbon::parse($stat->date)->format('d.m.Y')); ?></td>
                                        <td class="text-end text-success">+<?php echo e(number_format($stat->total_deposits, 2)); ?> TL</td>
                                        <td class="text-end text-danger">-<?php echo e(number_format($stat->total_withdrawals, 2)); ?> TL</td>
                                        <td class="text-center">
                                            <span class="badge bg-success"><?php echo e($stat->deposit_count); ?></span>
                                            <span class="badge bg-danger"><?php echo e($stat->withdrawal_count); ?></span>
                                        </td>
                                        <td class="text-end fw-bold <?php echo e(($stat->total_deposits - $stat->total_withdrawals) >= 0 ? 'text-success' : 'text-danger'); ?>">
                                            <?php echo e(number_format($stat->total_deposits - $stat->total_withdrawals, 2)); ?> TL
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                    <tr>
                                        <td colspan="5" class="text-center text-muted">Veri bulunamadi</td>
                                    </tr>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-lg-4">
            <div class="card border-0 shadow-sm mb-3">
                <div class="card-header bg-white">
                    <h5 class="mb-0"><i class="bi bi-diagram-3 me-2"></i>Finans Gruplari</h5>
                </div>
                <div class="card-body p-0">
                    <div class="list-group list-group-flush">
                        <?php $__empty_1 = true; $__currentLoopData = $groupStats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <div class="list-group-item">
                                <div class="d-flex justify-content-between align-items-start gap-2">
                                    <div>
                                        <h6 class="mb-1"><?php echo e($stat->financeGroup ? $stat->financeGroup->name : 'Bilinmeyen Grup'); ?></h6>
                                        <small class="text-success">+<?php echo e(number_format($stat->total_deposits, 2)); ?> TL</small><br>
                                        <small class="text-danger">-<?php echo e(number_format($stat->total_withdrawals, 2)); ?> TL</small>
                                    </div>
                                    <span class="badge bg-primary rounded-pill"><?php echo e($stat->transaction_count); ?></span>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <div class="list-group-item text-center text-muted">
                                Veri bulunamadi
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card border-0 shadow-sm">
        <div class="card-header bg-white">
            <h5 class="mb-0"><i class="bi bi-globe2 me-2"></i>Site Bazli Ozet</h5>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>Site</th>
                            <th class="text-end">Onayli Yatirim</th>
                            <th class="text-end">Onayli Cekim</th>
                            <th class="text-center">Islem</th>
                            <th class="text-end">Onayli Net</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $siteStats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                                $site = $stat->site;
                                $siteLabel = $site ? $site->name : 'Bilinmeyen Site';
                                $sitePassive = $site && !$site->is_active;
                                $netAmount = (float) $stat->total_deposits - (float) $stat->total_withdrawals;
                            ?>
                            <tr>
                                <td>
                                    <?php echo e($siteLabel); ?>

                                    <?php if($sitePassive): ?>
                                        <span class="badge bg-secondary ms-1">Pasif</span>
                                    <?php endif; ?>
                                </td>
                                <td class="text-end text-success">+<?php echo e(number_format($stat->completed_deposits, 2)); ?> TL</td>
                                <td class="text-end text-danger">-<?php echo e(number_format($stat->completed_withdrawals, 2)); ?> TL</td>
                                <td class="text-center"><span class="badge bg-primary"><?php echo e($stat->transaction_count); ?></span></td>
                                <td class="text-end fw-bold <?php echo e($netAmount >= 0 ? 'text-success' : 'text-danger'); ?>">
                                    <?php echo e(number_format($netAmount, 2)); ?> TL
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="5" class="text-center text-muted">Veri bulunamadi</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="card border-0 shadow-sm mt-4">
        <div class="card-header bg-white">
            <h5 class="mb-0"><i class="bi bi-check2-circle me-2"></i>Site + Tarih Onayli Toplamlar</h5>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>Tarih</th>
                            <th>Site</th>
                            <th class="text-end">Onayli Yatirim</th>
                            <th class="text-end">Onayli Cekim</th>
                            <th class="text-center">Yatirim Adet</th>
                            <th class="text-center">Cekim Adet</th>
                            <th class="text-end">Onayli Net</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $siteDateApprovedStats; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                                $siteLabel = $stat->site ? $stat->site->name : 'Bilinmeyen Site';
                                $approvedNet = (float) $stat->approved_deposits - (float) $stat->approved_withdrawals;
                            ?>
                            <tr>
                                <td><?php echo e(\Carbon\Carbon::parse($stat->date)->format('d.m.Y')); ?></td>
                                <td><?php echo e($siteLabel); ?></td>
                                <td class="text-end text-success">+<?php echo e(number_format($stat->approved_deposits, 2)); ?> TL</td>
                                <td class="text-end text-danger">-<?php echo e(number_format($stat->approved_withdrawals, 2)); ?> TL</td>
                                <td class="text-center"><?php echo e($stat->approved_deposit_count); ?></td>
                                <td class="text-center"><?php echo e($stat->approved_withdrawal_count); ?></td>
                                <td class="text-end fw-bold <?php echo e($approvedNet >= 0 ? 'text-success' : 'text-danger'); ?>">
                                    <?php echo e(number_format($approvedNet, 2)); ?> TL
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="7" class="text-center text-muted">Veri bulunamadi</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="card border-0 shadow-sm mt-4">
        <div class="card-header bg-white">
            <h5 class="mb-0"><i class="bi bi-speedometer2 me-2"></i>Performans: Site + Finans Grubu + Tarih</h5>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead class="table-light">
                        <tr>
                            <th>Tarih</th>
                            <th>Site</th>
                            <th>Finans Grubu</th>
                            <th class="text-end">Onayli Yatirim</th>
                            <th class="text-end">Onayli Cekim</th>
                            <th class="text-center">Onayli Islem</th>
                            <th class="text-end">Onayli Net</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $siteGroupDatePerformance; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                                $siteLabel = $stat->site ? $stat->site->name : 'Bilinmeyen Site';
                                $groupLabel = $stat->financeGroup ? $stat->financeGroup->name : 'Bilinmeyen Grup';
                                $approvedNet = (float) $stat->approved_deposits - (float) $stat->approved_withdrawals;
                            ?>
                            <tr>
                                <td><?php echo e(\Carbon\Carbon::parse($stat->date)->format('d.m.Y')); ?></td>
                                <td><?php echo e($siteLabel); ?></td>
                                <td><?php echo e($groupLabel); ?></td>
                                <td class="text-end text-success"><?php echo e(number_format($stat->approved_deposits, 2)); ?> TL</td>
                                <td class="text-end text-danger"><?php echo e(number_format($stat->approved_withdrawals, 2)); ?> TL</td>
                                <td class="text-center"><?php echo e($stat->approved_transaction_count); ?></td>
                                <td class="text-end fw-bold <?php echo e($approvedNet >= 0 ? 'text-success' : 'text-danger'); ?>">
                                    <?php echo e(number_format($approvedNet, 2)); ?> TL
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="7" class="text-center text-muted">Veri bulunamadi</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('styles'); ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-datepicker@1.10.0/dist/css/bootstrap-datepicker.min.css">
<?php $__env->stopPush(); ?>

<?php $__env->startPush('scripts'); ?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap-datepicker@1.10.0/dist/js/bootstrap-datepicker.min.js"></script>
<script>
$(document).ready(function() {
    $('.datepicker').datepicker({
        format: 'dd/mm/yyyy',
        autoclose: true,
        todayHighlight: true
    });

    const $dateFromInput = $('input[name="date_from"]');
    if (!$dateFromInput.val()) {
        const now = new Date();
        const businessDate = new Date(now);
        if (now.getHours() < 6) {
            businessDate.setDate(now.getDate() - 1);
        }
        $dateFromInput.datepicker('setDate', businessDate);
    }
});
</script>
<?php $__env->stopPush(); ?>



<?php echo $__env->make('backoffice.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/cmummhol/public_html/zoom/resources/views/backoffice/reports/index.blade.php ENDPATH**/ ?>