<?php $__env->startSection('content'); ?>
<div class="container">
    <h3>Commission Reports</h3>

    <form method="GET" action="<?php echo e(route('commission.reports')); ?>" class="row mb-4 align-items-end">
    <!-- Status Filter -->
    <div class="col-md-2">
        <label>Status</label>
        <select name="status" class="form-control" onchange="this.form.submit()">
            <option value="">All</option>
            <option value="unpaid" <?php echo e(request('status') == 'unpaid' ? 'selected' : ''); ?>>Unpaid</option>
            <option value="paid" <?php echo e(request('status') == 'paid' ? 'selected' : ''); ?>>Paid</option>
        </select>
    </div>

    <!-- Receiver Filter -->
    <div class="col-md-2">
        <label>Receiver</label>
        <select name="receiver_name" class="form-control" onchange="this.form.submit()">
            <option value="">All</option>
            <?php $__currentLoopData = $receivers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $receiver_name): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($receiver_name); ?>" <?php echo e(request('receiver_name') == $receiver_name ? 'selected' : ''); ?>>
                    <?php echo e($receiver_name); ?>

                </option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
        </select>
    </div>

    <!-- Buyer Filter -->
    <div class="col-md-2">
        <label>Buyer</label>
        <select name="buyer_name" class="form-control" onchange="this.form.submit()">
            <option value="">All</option>
            <?php $__currentLoopData = $buyers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $buyer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($buyer); ?>" <?php echo e(request('buyer_name') == $buyer ? 'selected' : ''); ?>>
                    <?php echo e($buyer); ?>

                </option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
        </select>
    </div>

    <!-- Seller Filter -->
    <div class="col-md-2">
        <label>Seller</label>
        <select name="seller_name" class="form-control" onchange="this.form.submit()">
            <option value="">All</option>
            <?php $__currentLoopData = $sellers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $seller): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($seller); ?>" <?php echo e(request('seller_name') == $seller ? 'selected' : ''); ?>>
                    <?php echo e($seller); ?>

                </option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?> 
        </select>
    </div>

    <!-- Month-Year Filter -->
    <div class="col-md-2">
        <label>Month & Year</label>
        <input type="month" name="month_year" value="<?php echo e(request('month_year')); ?>" class="form-control" onchange="this.form.submit()">
    </div>

    <div class="col-md-1 d-flex">
        <a href="<?php echo e(route('commission.reports')); ?>" class="btn btn-success btn-sm">Reset</a>
    </div>
</form>



        <table class="table table-bordered table-striped" id="commissionTable">
            <thead>
                <tr>
                    <th>Car Sale</th>
                    <th >Buyer Commission</th>
                    <th>Paid</th>
                    <th >Seller Commission</th>
                    <th>Paid</th>
                    <th>Receiver</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php $__currentLoopData = $commissions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $commission): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                    <td><?php echo e($commission->carSale->registration_no); ?> | <?php echo e($commission->carSale->make); ?> | <?php echo e($commission->carSale->varient); ?> | <?php echo e($commission->carSale->model); ?> <br> (<?php echo e($commission->carSale->buyer_name); ?> → <?php echo e($commission->carSale->seller_name); ?>)</td>
                        <td><?php echo e($commission->carSale->buyer_name ?? '-'); ?></td>
                        <td><?php echo e(number_format($commission->buyer_commission)); ?></td>
                        <td><?php echo e($commission->carSale->seller_name ?? '-'); ?></td>
                        <td><?php echo e(number_format($commission->seller_commission)); ?></td>
                        <td><?php echo e($commission->receiver_name); ?></td>
                        <td>
                            <?php if(($commission->buyer_commission > 0) && ($commission->seller_commission > 0)): ?>
                                Paid
                            <?php else: ?>
                                Unpaid    
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>



            </tbody>
                <!-- Totals Row -->
                <tr class="table-secondary fw-bold total-row">
                    <th style="text-align:center;"> → </th>
                    <td>Total Buyer Commission</td>
                    <td><?php echo e(number_format($totals['buyer_commission'])); ?></td>
                    <td>Total Seller Commission</td>
                    <td><?php echo e(number_format($totals['seller_commission'])); ?></td>
                    <th></th>
                    <td>Grand Total: <?php echo e(number_format($totals['grand_total'])); ?></td>
                </tr>
        </table>
        <script>
            $(document).ready(function() {
                $('#commissionTable').DataTable({
                    dom: 'Bfrtip',
                    paging: false,   // no pagination
                    info: false,     // hide "Showing X of Y entries"
                    searching: true, // keep search box
                    buttons: [
                        { extend: 'copy', text: 'Copy' },
                        { extend: 'excel', text: 'Export to Excel' },
                        { extend: 'pdf', text: 'Export to PDF' },
                        { extend: 'print', text: 'Print' }
                    ]
                });
            });
</script>



    <!-- <?php echo e($commissions->links()); ?> -->
</div>
<?php $__env->stopSection(); ?>


<style>
    .total-row th,
    .total-row td {
        border: 1px solid gray !important;
    }
</style>


<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/laravel-app12/resources/views/commissions/reports.blade.php ENDPATH**/ ?>