<div class="content-wrapper">
    <div class="container-xxl flex-grow-1 container-p-y">
        <div class="row">
            <div class="col">
                <div class="card shadow">
                    <div class="card-header text-uppercase custom-header bg-primary text-bg-info fw-bold">
                        <div class="col-6">
                            <i class="menu-icon ti ti-users-group"></i>Loan Report
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="row mt-3">
                            <div class="col d-flex justify-content-end">
                                <a class="btn btn-primary" data-bs-toggle="collapse" href="#collapseExample"
                                    role="button" aria-expanded="false" aria-controls="collapseExample">

                                    <i class="ti ti-filter-pause"></i> Filter
                                </a>
                            </div>
                            <div class="collapse mt-3" id="collapseExample">
                                <div class="card card-body">
                                    <div class="row mt-3">
                                        <div class="col-md-3 me-2">
                                            <div class="form-group">
                                                <label for="divisionId" class="form-label fw-bold">Select
                                                    Division</label>
                                                <select name="divisionId" id="divisionIdData" class="selectize">
                                                    <option value="">Select Division</option>
                                                    <?php $__currentLoopData = $getDivision; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $division): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($division->divisionName); ?>">
                                                            <?php echo e($division->divisionName); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="col-md-3 me-2">
                                            <div class="form-group">
                                                <label for="villageId" class="form-label fw-bold">Select village</label>
                                                <select name="villageId" id="villageId">
                                                    <option value="">Select Village</option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="col-md-3 me-2">
                                            <div class="form-group">
                                                <label for="smallgroupId" class="form-label fw-bold">Select Small
                                                    Group</label>
                                                <select name="smallgroupId" id="smallgroupId">
                                                    <option value="">Select Small Group</option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="col-md-3">
                                            <label class="form-label fw-bold">Loan Amount</label>
                                            <div class="d-flex">
                                                <input type="number" id="with1Min" class="form-control me-1"
                                                    placeholder="Min" />
                                                <input type="number" id="with1Max" class="form-control"
                                                    placeholder="Max" />
                                            </div>
                                        </div>

                                        <div class="col-12 d-flex justify-content-end">
                                            <a class="btn btn-primary" id="btnApplyFilters" data-bs-toggle="collapse"
                                                href="#collapseExample" role="button" aria-expanded="false"
                                                aria-controls="collapseExample">
                                                <i class="ti ti-filter-pause"></i> Filter
                                            </a>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        </div>
                        <a href="<?php echo e(route('view_pdf_loan_report')); ?>" class="mt-3" target="_blank">
                            <button class="btn btn-secondary ">
                                PDF
                            </button>
                        </a>
                        <table class="table table-sm" id="loanReportTable">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Loan ID</th>
                                    <th>Loan Purpose</th>
                                    <th>Loan Amount</th>
                                    <th>Loan Arreass</th>
                                    <th>Member Name</th>
                                    <th>Division</th>
                                    <th>Village</th>
                                    <th>Small Group</th>
                                    <th>Member NIC</th>
                                    <th>Old Account Number</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $count = 1;
                                ?>
                                <?php $__currentLoopData = $getLoanData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        $loanEncId = Crypt::encrypt($data->id);
                                    ?>
                                    <tr>
                                        <td><?php echo e($count++); ?></td>
                                        <td> <a
                                                href="<?php echo e(route('view_loan_details', $loanEncId)); ?>"><?php echo e($data->loanId); ?></a>
                                        </td>
                                        <td>
                                            <?php $__currentLoopData = $getLoanPurposeData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $LoanPur): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <?php if($LoanPur->id == $data->loanPurpose): ?>
                                            <?php echo e($LoanPur->name); ?>

                                            <?php endif; ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                        <td><?php echo e(number_format($data->principal, 2)); ?></td>
                                        <td>
                                            <?php
                                                $matchingBalances = $getAllRepaymentData
                                                    ->where('loanId', $data->id)
                                                    ->pluck('lastLoanBalance');
                                                $minBalance = $matchingBalances->min();
                                            ?>

                                            <?php if($minBalance !== null): ?>
                                                <?php echo e(number_format($minBalance, 2)); ?>

                                            <?php else: ?>
                                               <?php echo e(number_format($data->principal, 2)); ?>

                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php $__currentLoopData = $getAllMemberData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php if($mem->id == $data->memberId): ?>
                                                    <?php echo e($mem->firstName); ?> <?php echo e($mem->lastName); ?>

                                                <?php endif; ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                        <td>
                                            <?php $__currentLoopData = $getAllMemberData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php if($mem->id == $data->memberId): ?>
                                                    <?php if($mem->divisionId == ''): ?>
                                                        -
                                                    <?php else: ?>
                                                        <?php echo e($mem->division->divisionName); ?>

                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                        <td>
                                            <?php $__currentLoopData = $getAllMemberData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php if($mem->id == $data->memberId): ?>
                                                    <?php if($mem->villageId == ''): ?>
                                                        -
                                                    <?php else: ?>
                                                        <?php echo e($mem->village->villageName); ?>

                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                        <td>
                                            <?php $__currentLoopData = $getAllMemberData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php if($mem->id == $data->memberId): ?>
                                                    <?php if($mem->smallGroupId == ''): ?>
                                                        -
                                                    <?php else: ?>
                                                        <?php echo e($mem->smallgroup->smallGroupName); ?>

                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                        <td>
                                            <?php $__currentLoopData = $getAllMemberData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php if($mem->id == $data->memberId): ?>
                                                    <?php echo e($mem->nicNumber); ?>

                                                <?php endif; ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                        <td>
                                            <?php $__currentLoopData = $getAllMemberData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php if($mem->id == $data->memberId): ?>
                                                    <?php echo e($mem->oldAccountNumber); ?>

                                                <?php endif; ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

        </div>
        <div class="col-12 mt-3">
            <div class="card shadow">
                <div class="card-body">
                    <div class="row">
                        <div class="col-sm-12 col-md-3">
                            <div class="form-group">
                                <label class="fw-bold">Total Member</label>
                                <p class="total-member-count">0</p>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3">
                            <div class="form-group">
                                <label class="fw-bold">Total Division</label>
                                <p class="total-division-count">0</p>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3">
                            <div class="form-group">
                                <label class="fw-bold">Total Village</label>
                                <p class="total-village-count">0</p>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3">
                            <div class="form-group">
                                <label class="fw-bold">Total Smallgroup</label>
                                <p class="total-smallgroup-count">0</p>
                            </div>
                        </div>
                        <div class="col-sm-12 col-md-3">
                            <div class="form-group">
                                <label class="fw-bold">Total loan Amount</label>
                                <p class="total-loan-amount">0.00</p>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php /**PATH /Users/anlex/Desktop/untitled folder/ngo/resources/views/pages/allpages/reports/loan_report.blade.php ENDPATH**/ ?>