<style>
    .custom-schedule-repay-table th,
    .custom-schedule-repay-table td {
        font-size: 12px;
        padding: 4px 6px;
        vertical-align: middle;
    }

    .custom-schedule-repay-table thead th {
        white-space: nowrap;
    }

    .custom-schedule-repay-table .section-header {
        font-size: 13px;
        font-weight: 600;
        padding: 6px;
    }

    @media (max-width: 768px) {
        .custom-schedule-repay-table th,
        .custom-schedule-repay-table td {
            font-size: 11px;
            padding: 3px 4px;
        }
    }
</style>

<?php
    use Carbon\Carbon;

    $combinedData = [];

    // Add schedule data
    foreach ($getScheduleData as $schedule) {
        $combinedData[] = [
            'type' => 'Schedule',
            'date' => $schedule->paymentDate,
            'amount' => $schedule->monthlyPayment,
            'principal' => $schedule->principalPayment,
            'interest' => $schedule->interestPayment,
            'balance' => $schedule->balance,
            'status' => $schedule->status,
        ];
    }

    // Add repayment data
    foreach ($getRepaymentDetails as $repayment) {
        $combinedData[] = [
            'type' => 'Repayment',
            'date' => $repayment->repaymentDate,
            'amount' => $repayment->repaymentAmount,
            'principal' => $repayment->principalAmount,
            'interest' => $repayment->interest,
            'balance' => $repayment->lastLoanBalance,
            'status' => null,
        ];
    }

    // Sort by date
    usort($combinedData, function ($a, $b) {
        return strtotime($a['date']) <=> strtotime($b['date']);
    });
?>

<div class="table-responsive">
    <table class="table table-bordered table-sm text-center align-middle custom-schedule-repay-table">
        <thead>
            <tr>
                <th colspan="7" class="bg-info text-white section-header">Schedule</th>
                <th colspan="7" class="bg-primary text-white section-header">Repayment</th>
            </tr>
            <tr>
                
                <th>#</th>
                <th>Date</th>
                <th>Amount</th>
                <th>Principal</th>
                <th>Interest</th>
                <th>Balance</th>
                <th>Status</th>

                
                <th>#</th>
                <th>Date</th>
                <th>Amount</th>
                <th>Principal</th>
                <th>Interest</th>
                <th>Balance</th>
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            <?php
                $maxRows = max(count($getScheduleData), count($getRepaymentDetails));
            ?>

            <?php for($i = 0; $i < $maxRows; $i++): ?>
                <tr>
                    
                    <?php if(isset($getScheduleData[$i])): ?>
                        <?php
                            $schedule = $getScheduleData[$i];
                            $status = strtolower($schedule->status);
                        ?>
                        <td><?php echo e($i + 1); ?></td>
                        <td><?php echo e($schedule->paymentDate); ?></td>
                        <td><?php echo e(number_format($schedule->monthlyPayment, 2)); ?></td>
                        <td><?php echo e(number_format($schedule->principalPayment, 2)); ?></td>
                        <td><?php echo e(number_format($schedule->interestPayment, 2)); ?></td>
                        <td><?php echo e(number_format($schedule->balance, 2)); ?></td>
                        <td>
                            <span class="badge
                                <?php if($status == 'paid'): ?> bg-success
                                <?php elseif($status == 'unpaid'): ?> bg-warning
                                <?php elseif($status == 'interest wise'): ?> bg-primary
                                <?php elseif($status == 'write off'): ?> bg-danger
                                <?php else: ?> bg-secondary <?php endif; ?>
                            ">
                                <?php echo e(ucfirst($schedule->status)); ?>

                            </span>
                        </td>
                    <?php else: ?>
                        
                        <td colspan="7">—</td>
                    <?php endif; ?>

                    
                    <?php if(isset($getRepaymentDetails[$i])): ?>
                        <?php
                            $repayment = $getRepaymentDetails[$i];
                        ?>
                        <td><?php echo e($i + 1); ?></td>
                        <td><?php echo e($repayment->repaymentDate); ?></td>
                        <td><?php echo e(number_format($repayment->repaymentAmount, 2)); ?></td>
                        <td><?php echo e(number_format($repayment->principalAmount, 2)); ?></td>
                        <td><?php echo e(number_format($repayment->interest, 2)); ?></td>
                        <td><?php echo e(number_format($repayment->lastLoanBalance, 2)); ?></td>
                        <td>—</td>
                    <?php else: ?>
                        
                        <td colspan="7">—</td>
                    <?php endif; ?>
                </tr>
            <?php endfor; ?>
        </tbody>
    </table>
</div>
<?php /**PATH /Users/anlex/Desktop/untitled folder/ngo/resources/views/pages/allpages/loan/repayment_schedule_view.blade.php ENDPATH**/ ?>