<?php
    use Carbon\Carbon;
?>
<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>Member Saving Report
                        </div>
                    </div>
                    <div class="card-body">
                        <table class="table table-sm mt-3 datatableView">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Date</th>
                                    <th>Name</th>
                                    <th>NIC number</th>
                                    <th>Division</th>
                                    <th>Village</th>
                                    <th>Small Group</th>
                                    <th>Old Account Number</th>
                                    <th>January</th>
                                    <th>February</th>
                                    <th>March</th>
                                    <th>April</th>
                                    <th>May</th>
                                    <th>June</th>
                                    <th>July</th>
                                    <th>August</th>
                                    <th>September</th>
                                    <th>October</th>
                                    <th>November</th>
                                    <th>December</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if(session('success')): ?>
                                    <div class="mt-3 alert alert-success success-alert">
                                        <?php echo e(session('success')); ?>

                                    </div>
                                <?php endif; ?>

                                <?php if(session('error')): ?>
                                    <div class="mt-3 alert alert-danger danger-alert">
                                        <?php echo e(session('error')); ?>

                                    </div>
                                <?php endif; ?>
                                <?php
                                    $count = 1;
                                ?>
                                <?php $__currentLoopData = $getMember; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $member): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        $encryptedId = encrypt($member->id);
                                    ?>
                                    <?php
                                        $memberLoans = $getLoansData
                                            ->where('memberId', $member->id)
                                            ->where('loanStatus', 'Active')
                                            ->values();
                                        $totalLoanAmount = $memberLoans->sum('principal');
                                        $ageString = '-';

                                        if (!empty($member->dateOfBirth)) {
                                            try {
                                                $dob = \Carbon\Carbon::parse($member->dateOfBirth)->startOfDay();
                                                $now = \Carbon\Carbon::now()->startOfDay();
                                                $diff = $dob->diff($now);
                                                $ageString = "{$diff->y} years, {$diff->m} months, {$diff->d} days";
                                            } catch (\Exception $e) {
                                                $ageString = '-';
                                            }
                                        }
                                    ?>

                                    <?php

                                        $januaryTotal = 0;
                                        $februaryTotal = 0;
                                        $marchTootal = 0;
                                        $aprilTotal = 0;
                                        $mayTotal = 0;
                                        $juneTotal = 0;
                                        $julyTotal = 0;
                                        $augustTotal = 0;
                                        $septemberTotal = 0;
                                        $octoberTotal = 0;
                                        $novemberTotal = 0;
                                        $decemberTotal = 0;
                                    ?>
                                    <?php $__currentLoopData = $getData; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $getD): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php if($getD->memberId == $member->uniqueId && $getD->type == 'Credit'): ?>
                                            <?php
                                                $carbonDate = Carbon::parse($getD->created_at);
                                                $monthNumber = $carbonDate->format('m');
                                                if ($monthNumber == '01' || $monthNumber == 1) {
                                                    $januaryTotal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == '02' || $monthNumber == 2) {
                                                    $februaryTotal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == '03' || $monthNumber == 3) {
                                                    $marchTootal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == '04' || $monthNumber == 4) {
                                                    $aprilTotal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == 05 || $monthNumber == 5) {
                                                    $mayTotal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == '06' || $monthNumber == 6) {
                                                    $juneTotal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == '07' || $monthNumber == 7) {
                                                    $julyTotal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == '08' || $monthNumber == 8) {
                                                    $augustTotal += $getD->amount ?? 0;
                                                }

                                                if ($monthNumber == '09' || $monthNumber == 9) {
                                                    $septemberTotal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == "10") {
                                                    $octoberTotal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == "11") {
                                                    $novemberTotal += $getD->amount ?? 0;
                                                }
                                                if ($monthNumber == "12") {
                                                    $decemberTotal += $getD->amount ?? 0;
                                                }
                                            ?>
                                        <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <tr>
                                        <td><?php echo e($count++); ?></td>
                                        <td><?php echo e(\Carbon\Carbon::parse($member->create_at)->format('Y-m-d')); ?></td>

                                        <td> <a href="<?php echo e(route('view_member_saving_report', $encryptedId)); ?>">
                                                <?php echo e($member->firstName); ?> <?php echo e($member->lastName); ?></a></td>
                                        <td><?php echo e($member->nicNumber); ?></td>
                                        <td>
                                            <?php
                                                $divIdEnc = encrypt($member->divisionId);
                                            ?>
                                            <?php if($member->divisionId == ''): ?>
                                                -
                                            <?php else: ?>
                                                <a href="<?php echo e(route('division_details', $divIdEnc)); ?>">
                                                    <?php echo e($member->division->divisionName); ?> </a>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <?php
                                                $villageIdEnc = encrypt($member->villageId);
                                            ?>
                                            <?php if($member->villageId == ''): ?>
                                                -
                                            <?php else: ?>
                                                <a href="<?php echo e(route('village_details', $villageIdEnc)); ?>">
                                                    <?php echo e($member->village->villageName); ?> </a>
                                            <?php endif; ?>
                                        </td>
                                        <?php
                                            $smallgroupIdEnc = encrypt($member->smallGroupId);
                                        ?>
                                        <?php if($member->smallGroupId == ''): ?>
                                            <td>-</td>
                                        <?php else: ?>
                                            <td><a
                                                    href="<?php echo e(route('smallgroup_details', $smallgroupIdEnc)); ?>"><?php echo e($member->smallgroup->smallGroupName); ?></a>
                                            </td>
                                        <?php endif; ?>


                                        <td><?php echo e($member->oldAccountNumber); ?></td>
                                        <td><?php echo e(number_format($januaryTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($februaryTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($marchTootal, 2)); ?></td>
                                        <td><?php echo e(number_format($aprilTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($mayTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($juneTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($julyTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($augustTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($septemberTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($octoberTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($novemberTotal, 2)); ?></td>
                                        <td><?php echo e(number_format($decemberTotal, 2)); ?></td>
                                    </tr>
                                <?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/reports/member_savings_report.blade.php ENDPATH**/ ?>