<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-list"></i> Manage Loan
                        </div>
                        <div class="col-6 d-flex justify-content-end">

                            <?php if($userType == 'superAdmin'): ?>
                                <a href="/create_old_loan">
                                    <button class="btn btn-success btn-sm me-2"><i
                                            class="menu-icon ti ti-circle-plus"></i>
                                        Create Old Loan</button>
                                </a>
                                <a href="/create_loan">
                                    <button class="btn btn-success btn-sm"><i class="menu-icon ti ti-circle-plus"></i>
                                        Create New Loan</button>
                                </a>
                            <?php else: ?>
                                <?php
                                    $userRolesArray = $getUserRole->pluck('roleName')->toArray();
                                ?>

                                <?php if(in_array($userType, $userRolesArray)): ?>
                                    <?php
                                        $usersDataPer = $permissions;
                                        $usersDataPer = json_decode($usersDataPer, true);
                                    ?>

                                    <?php if(in_array('addOldLoan', $usersDataPer)): ?>
                                        <a href="/create_old_loan">
                                            <button class="btn btn-success btn-sm me-2"><i
                                                    class="menu-icon ti ti-circle-plus"></i>
                                                Create Old Loan</button>
                                    <?php endif; ?>
                                    <?php if(in_array('addLoan', $usersDataPer)): ?>
                                        <a href="/create_loan">
                                            <button class="btn btn-success btn-sm"><i
                                                    class="menu-icon ti ti-circle-plus"></i>
                                                Create New Loan</button>
                                        </a>
                                    <?php endif; ?>
                                <?php endif; ?>
                            <?php endif; ?>


                        </div>
                    </div>

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

                        <table class="table table-sm " id="loanTableView">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Loan Id</th>
                                    <th>Member Name</th>
                                    <th>Product Name</th>
                                    <th>Division</th>
                                    <th>Village</th>
                                    <th>SmallGroup</th>
                                    <th>Amount</th>
                                    <th>Status</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $count = 1;
                                ?>
                                <?php $__currentLoopData = $getData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $data): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        $loanEncId = Crypt::encrypt($data->id);
                                    ?>
                                    <?php if(auth()->user()->userType == 'superAdmin'): ?>
                                        <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 = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if($mem->id == $data->memberId): ?>
                                                        <?php echo e($mem->firstName); ?>

                                                    <?php endif; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </td>
                                            <td>
                                                <?php $__currentLoopData = $getproduct; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pro): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if($pro->id == $data->loanProductId): ?>
                                                        <?php echo e($pro->productName); ?>

                                                    <?php endif; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </td>
                                            <td>
                                                <?php $__currentLoopData = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if($mem->id == $data->memberId): ?>
                                                        <?php
                                                            $divIdEnc = Crypt::encrypt($mem->divisionId);
                                                        ?>
                                                        <a href="<?php echo e(route('division_details', $divIdEnc)); ?>">
                                                            <?php echo e($mem->division->divisionName); ?> </a>
                                                    <?php endif; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </td>
                                            <td>
                                                <?php $__currentLoopData = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if($mem->id == $data->memberId): ?>
                                                        <?php
                                                            $villageIdEnc = Crypt::encrypt($mem->villageId);
                                                        ?>
                                                        <a href="<?php echo e(route('village_details', $villageIdEnc)); ?>">
                                                            <?php echo e($mem->village->villageName); ?> </a>
                                                    <?php endif; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </td>
                                            <td>
                                                <?php $__currentLoopData = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <?php if($mem->id == $data->memberId): ?>
                                                        <?php
                                                            $smallgroupIdEnc = Crypt::encrypt($mem->smallGroupId);
                                                        ?>
                                                        <a href="<?php echo e(route('smallgroup_details', $smallgroupIdEnc)); ?>">
                                                            <?php echo e($mem->smallgroup->smallGroupName ?? null); ?> </a>
                                                    <?php endif; ?>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                            </td>
                                            <td><?php echo e(number_format($data->principal, 2)); ?></td>
                                            <td>
                                                <?php
                                                    if ($data->loanStatus == 'Active') {
                                                        $statusClass = 'bg-success';
                                                    } elseif ($data->loanStatus == 'Rejected') {
                                                        $statusClass = 'bg-danger';
                                                    } else {
                                                        $statusClass = 'bg-primary';
                                                    }

                                                ?>
                                                <span class="badge <?php echo e($statusClass); ?>"><?php echo e($data->loanStatus); ?></span>
                                            </td>
                                            <td>
                                                <div class="dropdown">
                                                    <button type="button" class="btn p-0 dropdown-toggle hide-arrow"
                                                        data-bs-toggle="dropdown">
                                                        <i class="ti ti-dots-vertical"></i>
                                                    </button>
                                                    <div class="dropdown-menu">
                                                        <a class="dropdown-item"
                                                            href="<?php echo e(route('view_loan_details', $loanEncId)); ?>"><i
                                                                class="ti ti-eye me-1"></i> View</a>
                                                        <a class="dropdown-item" href="#"><i
                                                                class="ti ti-pencil me-1"></i> Edit</a>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>
                                    <?php else: ?>
                                     <?php
                                            $divArray = auth()->user()->division;
                                            $vilArray = auth()->user()->village;
                                        ?>
                                        <?php if($divArray != '' || $divArray != null || $vilArray != '' || $vilArray != null): ?>
                                            <?php $__currentLoopData = $getAllMemberData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $getMem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php if($getMem->id == $data->memberId): ?>
                                                    <?php if(in_array($getMem->divisionId, json_decode(auth()->user()->division)) &&
                                                            in_array($getMem->villageId, json_decode(auth()->user()->village))): ?>
                                                        <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 = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if($mem->id == $data->memberId): ?>
                                                                        <?php echo e($mem->firstName); ?>

                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </td>
                                                            <td>
                                                                <?php $__currentLoopData = $getproduct; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pro): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if($pro->id == $data->loanProductId): ?>
                                                                        <?php echo e($pro->productName); ?>

                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </td>
                                                            <td>
                                                                <?php $__currentLoopData = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if($mem->id == $data->memberId): ?>
                                                                        <?php
                                                                            $divIdEnc = Crypt::encrypt(
                                                                                $mem->divisionId,
                                                                            );
                                                                        ?>
                                                                        <a
                                                                            href="<?php echo e(route('division_details', $divIdEnc)); ?>">
                                                                            <?php echo e($mem->division->divisionName); ?> </a>
                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </td>
                                                            <td>
                                                                <?php $__currentLoopData = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if($mem->id == $data->memberId): ?>
                                                                        <?php
                                                                            $villageIdEnc = Crypt::encrypt(
                                                                                $mem->villageId,
                                                                            );
                                                                        ?>
                                                                        <a
                                                                            href="<?php echo e(route('village_details', $villageIdEnc)); ?>">
                                                                            <?php echo e($mem->village->villageName); ?> </a>
                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </td>
                                                            <td>
                                                                <?php $__currentLoopData = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if($mem->id == $data->memberId): ?>
                                                                        <?php
                                                                            $smallgroupIdEnc = Crypt::encrypt(
                                                                                $mem->smallGroupId,
                                                                            );
                                                                        ?>
                                                                        <a
                                                                            href="<?php echo e(route('smallgroup_details', $smallgroupIdEnc)); ?>">
                                                                            <?php echo e($mem->smallgroup->smallGroupName ?? null); ?>

                                                                        </a>
                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            </td>
                                                            <td><?php echo e(number_format($data->principal, 2)); ?></td>
                                                            <td>
                                                                <?php
                                                                    if ($data->loanStatus == 'Active') {
                                                                        $statusClass = 'bg-success';
                                                                    } elseif ($data->loanStatus == 'Rejected') {
                                                                        $statusClass = 'bg-danger';
                                                                    } else {
                                                                        $statusClass = 'bg-primary';
                                                                    }

                                                                ?>
                                                                <span
                                                                    class="badge <?php echo e($statusClass); ?>"><?php echo e($data->loanStatus); ?></span>
                                                            </td>
                                                            <td>
                                                                <div class="dropdown">
                                                                    <button type="button"
                                                                        class="btn p-0 dropdown-toggle hide-arrow"
                                                                        data-bs-toggle="dropdown">
                                                                        <i class="ti ti-dots-vertical"></i>
                                                                    </button>
                                                                    <div class="dropdown-menu">
                                                                        <a class="dropdown-item"
                                                                            href="<?php echo e(route('view_loan_details', $loanEncId)); ?>"><i
                                                                                class="ti ti-eye me-1"></i> View</a>
                                                                        <a class="dropdown-item" href="#"><i
                                                                                class="ti ti-pencil me-1"></i> Edit</a>
                                                                    </div>
                                                                </div>
                                                            </td>
                                                        </tr>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php /**PATH /Users/anlex/Desktop/untitled folder/ngo/resources/views/pages/allpages/loan/list_of_loan.blade.php ENDPATH**/ ?>