<?php
    use Carbon\Carbon;
?>

<div class="content-wrapper">
    <div class="container-xxl flex-grow-1 container-p-y">

        <div class="card shadow">
            <div class="card-header text-uppercase custom-header bg-primary text-bg-info fw-bold">
                <i class="menu-icon ti ti-device-desktop-cog"></i> Manage Collection VS Deposit Reports
            </div>

            <div class="card-body">

                
                <a href="<?php echo e(route('view_collection_vs_deposit_report')); ?>" class="mt-3" target="_blank">
                    <button class="btn btn-secondary">
                        PDF
                    </button>
                </a>

                
                <form method="GET" action="<?php echo e(route('collectionvsdeposit')); ?>" class="row g-3 mb-3 mt-3">
                    <div class="col-md-3">
                        <label class="form-label">Start Date</label>
                        <input type="date" name="start_date" class="form-control" value="<?php echo e($startDate ?? ''); ?>">
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">End Date</label>
                        <input type="date" name="end_date" class="form-control" value="<?php echo e($endDate ?? ''); ?>">
                    </div>
                    <div class="col-md-3 align-self-end">
                        <button type="submit" class="btn btn-primary">Filter</button>
                        <a href="<?php echo e(route('collectionvsdeposit')); ?>" class="btn btn-secondary">Reset</a>
                    </div>
                </form>

                
                <table class="table table-sm table-striped table-bordered" id="collectionvsdeposittable">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Date</th>
                            <th>User</th>
                            <th>Collection Amount</th>
                            <th>Deposit Amount</th>
                            <th>Difference</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                            $count = 1;
                            $grandTotalCollection = 0;
                            $grandTotalDeposit = 0;
                            $grandTotalDifference = 0;
                        ?>

                        <?php $__currentLoopData = $reportData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $userName = $getUser->firstWhere('id', $row->depositBy)?->name ?? 'N/A';
                                $difference = $row->totalCollectionAmount - $row->totalDepositAmount;

                                $grandTotalCollection += $row->totalCollectionAmount;
                                $grandTotalDeposit += $row->totalDepositAmount;
                                $grandTotalDifference += $difference;
                            ?>
                            <tr>
                                <td><?php echo e($count++); ?></td>
                                <td><?php echo e($row->dateOnly); ?></td>
                                <td><?php echo e($userName); ?></td>
                                <td><?php echo e(number_format($row->totalCollectionAmount, 2)); ?></td>
                                <td><?php echo e(number_format($row->totalDepositAmount, 2)); ?></td>
                                <td><?php echo e(number_format($difference, 2)); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                    <tfoot>
                        <tr class="fw-bold bg-light">
                            <td colspan="3" class="text-end">Grand Total</td>
                            <td><?php echo e(number_format($grandTotalCollection, 2)); ?></td>
                            <td><?php echo e(number_format($grandTotalDeposit, 2)); ?></td>
                            <td><?php echo e(number_format($grandTotalDifference, 2)); ?></td>
                        </tr>
                    </tfoot>
                </table>

            </div>
        </div>
    </div>
</div>
<?php /**PATH /home/techhdyz/swd.technathi.cloud/resources/views/pages/allpages/collection/collection_vs_deposit_reports.blade.php ENDPATH**/ ?>