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

        <!-- Page Header -->
        <div class="row mb-3">
            <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>
            </div>
        </div>

        <!-- Filters Card -->
        <div class="row">
            <div class="col">
                <div class="card shadow-sm mb-3">
                    <div class="card-body py-3">
                        <form method="GET" action="<?php echo e(url('/loan_report')); ?>">
                            <div class="row g-2 align-items-end">
                                <div class="col-md-3">
                                    <label for="fromDate" class="form-label fw-bold">From Date</label>
                                    <input type="date" name="fromDate" id="fromDate"
                                           value="<?php echo e($fromDate); ?>"
                                           class="form-control form-control-sm">
                                </div>
                                <div class="col-md-3">
                                    <label for="toDate" class="form-label fw-bold">To Date</label>
                                    <input type="date" name="toDate" id="toDate"
                                           value="<?php echo e($toDate); ?>"
                                           class="form-control form-control-sm">
                                </div>
                                <div class="col-md-2">
                                    <button type="submit" class="btn btn-primary btn-sm w-100">
                                        <i class="bx bx-filter-alt"></i> Apply
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <!-- Report Table Card -->
        <div class="row">
            <div class="col">
                <div class="card shadow mb-3">
                    <div class="card-body">
                        <div class="table-responsive">
                            <table class="table table-sm table-bordered" id="loanReportTable">
                                <thead class="table-light">
                                    <tr>
                                        <th>#</th>
                                        <th>Division</th>
                                        <th>Village</th>
                                        <th>Small Group</th>
                                        <th>Member Name</th>
                                        <th>Member NIC</th>
                                        <th>Old Account Number</th>
                                        <th>Loan ID</th>
                                        <th>Loan Purpose Category</th>
                                        <th>Loan Purpose</th>
                                        <th>Loan Amount</th>
                                        <th>Loan Outstanding</th>
                                        <th>Loan Terms</th>
                                        <th>Interest Rate</th>
                                        <th>FO Name</th>
                                        <th>Loan Date</th>
                                        <th>Loan Status</th>
                                        <th>Loan Type</th>
                                        </tr>
                                </thead>
                                <tbody>
                                    <?php $count = 1; ?>
                                    <?php $__currentLoopData = $getLoansData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php 
                                            $loanEncId = Crypt::encrypt($data->id); 
                                            $member = $getAllMemberData->firstWhere('id', $data->memberId);
                                        ?>
                                        <tr>
                                            <td><?php echo e($count++); ?></td>
                                            <td><?php echo e(optional($member?->division)?->divisionName ?? '-'); ?></td>
                                            <td><?php echo e(optional($member?->village)?->villageName ?? '-'); ?></td>
                                            <td><?php echo e(optional($member?->smallgroup)?->smallGroupName ?? '-'); ?></td>
                                            <td><?php echo e($member ? $member->firstName . ' ' . $member->lastName : '-'); ?></td>
                                            <td><?php echo e($member?->nicNumber ?? '-'); ?></td>
                                            <td><?php echo e($member?->oldAccountNumber ?? '-'); ?></td>
                                            <td><a href="<?php echo e(route('view_loan_details', $loanEncId)); ?>"><?php echo e($data->loanId); ?></a></td>
                                            <td><?php echo e(optional($getLoanPurposeData->firstWhere('id', $data->loanPurpose))->name ?? '-'); ?></td>
                                            <td><?php echo e(optional($getLoanPurposeData->firstWhere('id', $data->loanPurposeSub))->name ?? '-'); ?></td>
                                            <td><?php echo e(number_format($data->principal, 2)); ?></td>
                                            <td><?php echo e(number_format(($data->principal - $getAllRepaymentData->where('loanId', $data->id)->sum('principalAmount')), 2)); ?></td>
                                            <td><?php echo e($data->loanterm); ?> Months</td>
                                            <td><?php echo e($data->interestRate); ?>%</td>
                                            <td><?php echo e($data->loanOfficerName ?? 'N/A'); ?></td>
                                            <td><?php echo e($data->loanDate ?? '-'); ?></td>
                                            <td><?php echo e($data->loanStatus); ?></td>
                                            <td><?php echo e($data->loanType); ?></td>
                                            
                                        </tr>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Totals Card -->
        <div class="row">
            <div class="col-12">
                <div class="card shadow">
                    <div class="card-body">
                        <div class="row g-3">
                            <div class="col-md-3">
                                <label class="fw-bold">Total Member</label>
                                <p class="total-member-count">0</p>
                            </div>
                            <div class="col-md-3">
                                <label class="fw-bold">Total Division</label>
                                <p class="total-division-count">0</p>
                            </div>
                            <div class="col-md-3">
                                <label class="fw-bold">Total Village</label>
                                <p class="total-village-count">0</p>
                            </div>
                            <div class="col-md-3">
                                <label class="fw-bold">Total Smallgroup</label>
                                <p class="total-smallgroup-count">0</p>
                            </div>
                            <div class="col-md-3 mt-3">
                                <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 /home/techhdyz/swd.technathi.cloud/resources/views/pages/allpages/reports/loan_report.blade.php ENDPATH**/ ?>