<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> View Savings
                        </div>
                        <div class="col-6 d-flex justify-content-end">
                            <?php if($userType == 'superAdmin'): ?>
                                <button class="btn btn-light btn-sm" data-bs-toggle="modal"
                                    data-bs-target="#withdrawalModal">Withdrawal</button>
                            <?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('Withdrawal', $usersDataPer)): ?>
                                        <button class="btn btn-light btn-sm" data-bs-toggle="modal"
                                            data-bs-target="#withdrawalModal">Withdrawal</button>
                                    <?php endif; ?>
                                <?php endif; ?>
                            <?php endif; ?>

                        </div>
                    </div>
                    <div class="card-body">
    <div class="row mt-3">
        <div class="table-responsive" style="max-height: 500px; overflow-y: auto;">
            <table class="table table-sm datatableView table-striped table-bordered align-middle">
                <thead class="table-light">
                    <tr>
                        <th>#</th>
                        <th>Id</th>
                        <th>Name</th>
                        <th>NIC number</th>
                        <th>Division</th>
                        <th>Village</th>
                        <th>Small Group</th>
                        <th>Old Account Number</th>
                        <th>Total</th>
                    </tr>
                </thead>
                <tbody>
    <?php $count = 1; ?>
    <?php $__currentLoopData = $getSavings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $savings): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <?php 
            $encryptedSavingId = encrypt($savings->savingsId);
            $memberId = $savings->member?->id;
            $encryptedMemberId = $memberId ? encrypt($memberId) : null;
        ?>

        <?php if(auth()->user()->userType == 'superAdmin'): ?>
            <tr>
                <td><?php echo e($count++); ?></td>
                <td>
                    <a href="<?php echo e(route('view_saving_history', $encryptedSavingId)); ?>">
                        <?php echo e($savings->savingsId ?? 'N/A'); ?>

                    </a>
                </td>
                <td>
                    <?php if($encryptedMemberId): ?>
                        <a href="<?php echo e(route('view_member', $encryptedMemberId)); ?>">
                            <?php echo e($savings->member?->firstName); ?> <?php echo e($savings->member?->lastName); ?>

                        </a>
                    <?php else: ?>
                        N/A
                    <?php endif; ?>
                </td>
                <td><?php echo e($savings->member?->nicNumber ?? 'N/A'); ?></td>
                <td><?php echo e($savings->member?->division?->divisionName ?? '-'); ?></td>
                <td><?php echo e($savings->member?->village?->villageName ?? '-'); ?></td>
                <td><?php echo e($savings->member?->smallgroup?->smallGroupName ?? '-'); ?></td>
                <td><?php echo e($savings->member?->oldAccountNumber ?? '-'); ?></td>
                <td>Rs.<?php echo e(isset($savings->totalAmount) ? number_format($savings->totalAmount, 2) : 'N/A'); ?></td>
            </tr>
        <?php else: ?>
            <?php
                $divArray = json_decode(auth()->user()->division ?? '[]', true) ?? [];
                $vilArray = json_decode(auth()->user()->village ?? '[]', true) ?? [];
            ?>

            <?php if(in_array($savings->member?->divisionId, $divArray, true) &&
                 in_array($savings->member?->villageId, $vilArray, true)): ?>
                <tr>
                    <td><?php echo e($count++); ?></td>
                    <td>
                        <a href="<?php echo e(route('view_saving_history', $encryptedSavingId)); ?>">
                            <?php echo e($savings->savingsId ?? 'N/A'); ?>

                        </a>
                    </td>
                    <td>
                        <?php if($encryptedMemberId): ?>
                            <a href="<?php echo e(route('view_member', $encryptedMemberId)); ?>">
                                <?php echo e($savings->member?->firstName); ?> <?php echo e($savings->member?->lastName); ?>

                            </a>
                        <?php else: ?>
                            N/A
                        <?php endif; ?>
                    </td>
                    <td><?php echo e($savings->member?->nicNumber ?? 'N/A'); ?></td>
                    <td><?php echo e($savings->member?->division?->divisionName ?? '-'); ?></td>
                    <td><?php echo e($savings->member?->village?->villageName ?? '-'); ?></td>
                    <td><?php echo e($savings->member?->smallgroup?->smallGroupName ?? '-'); ?></td>
                    <td><?php echo e($savings->member?->oldAccountNumber ?? '-'); ?></td>
                    <td>Rs.<?php echo e(isset($savings->totalAmount) ? number_format($savings->totalAmount, 2) : 'N/A'); ?></td>
                </tr>
            <?php endif; ?>
        <?php endif; ?>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</tbody>

            </table>
        </div>
    </div>
</div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="withdrawalModal" tabindex="-1" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-simple">
        <div class="modal-content">
            <div class="modal-body">
                <button type="button" class="btn-close btn-pinned" data-bs-dismiss="modal" aria-label="Close"></button>
                <div class="text-center mb-6">
                    <h4 class="mb-2">Withdrawal 1st request</h4>
                    <p>Wthdrawal</p>
                </div>
                <div class="col-12 mb-4">
                    <label class="form-label" for="txtMember">Member</label>
                    <select class="selectize" id="txtMember">
                        <option value="">---Select---</option>
                        <?php $__currentLoopData = $getAllMemberData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $member): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php if(auth()->user()->userType == 'superAdmin'): ?>
                                <option value="<?php echo e($member->uniqueId); ?>"><?php echo e($member->firstName); ?> <?php echo e($member->lastName); ?></option>
                            <?php else: ?>
                                <?php
                                    $divArray = auth()->user()->division;
                                    $vilArray = auth()->user()->village;
                                ?>
                                <?php if($divArray != '' || $divArray != null || $vilArray != '' || $vilArray != null): ?>
                                    <?php if(in_array($member->divisionId, json_decode(auth()->user()->division)) &&
                                            in_array($member->villageId, json_decode(auth()->user()->village))): ?>
                                             <option value="<?php echo e($member->uniqueId); ?>"><?php echo e($member->firstName); ?> <?php echo e($member->lastName); ?></option>
                                    <?php endif; ?>
                                <?php endif; ?>
                            <?php endif; ?>

                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-12 mb-4" hidden id="txtGetAccDiv">
                    <label class="form-label" for="txtSavingAccount">Saving Account</label>
                    <select id="txtSavingAccount">
                    </select>
                </div>
                <div class="col-12 mb-4">
                    <label class="form-label" for="txtAmount">Amount</label>
                    <input type="text" id="txtAmount" class="form-control" placeholder="Enter Amount" />
                </div>
                <div class="col-12 mb-4">
                    <label>Approve User</label>
                    <select class="selectize" id="txtApproveUser">
                        <option value="">Select user</option>
                        <?php $__currentLoopData = $getUserRole; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $userRole): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($userRole->id); ?>"><?php echo e($userRole->roleName); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-12 mb-4">
                    <label class="form-label" for="txtReason">Reason</label>
                    <input type="text" id="txtReason" class="form-control" placeholder="Enter Reason" />
                </div>

                <div class="col-12 text-center demo-vertical-spacing">
                    <button class="btn btn-primary me-4" id="btnWithdrawalRequest">Request</button>
                    <button type="reset" class="btn btn-label-secondary" data-bs-dismiss="modal" aria-label="Close">
                        Discard
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>
<?php /**PATH /home/techhdyz/new.technathi.cloud/resources/views/pages/allpages/manage_savings.blade.php ENDPATH**/ ?>