@forelse ($payments as $payment)
@foreach ($payment->waterPayments as $waterbill)
@php
// Initialize rate variables
$baseRate = 0;
$bracket1Rate = 0;
$bracket2Rate = 0;
$bracket3Rate = 0;
$bracket4Rate = 0;
// Find the matching rate from the waterRates collection
$rateInfo = $waterRates->firstWhere('name', $waterbill->rate);
if ($rateInfo) {
$baseRate = $rateInfo->{'0_10'}; // Assuming base_rate is the correct field name
$bracket4Rate = $rateInfo->{'41_up'};
$bracket3Rate = $rateInfo->{'31_40'};
$bracket2Rate = $rateInfo->{'21_30'};
$bracket1Rate = $rateInfo->{'11_20'};
}
$amount = 0;
$details = [];
if ($waterbill->consumption <= 10) {
$amount = $baseRate;
$details[] = number_format($baseRate, 2);
} else {
$amount = $baseRate;
$details[] = number_format($baseRate, 2);
if ($waterbill->consumption <= 20) {
$additionalUnits = $waterbill->consumption - 10;
$amount += $additionalUnits * $bracket1Rate;
$details[] = number_format($additionalUnits * $bracket1Rate, 2);
} elseif ($waterbill->consumption <= 30) {
$additionalUnits1 = 10;
$additionalUnits2 = $waterbill->consumption - 20;
$amount +=
$additionalUnits1 * $bracket1Rate +
$additionalUnits2 * $bracket2Rate;
$details[] = number_format($additionalUnits1 * $bracket1Rate, 2);
$details[] = number_format($additionalUnits2 * $bracket2Rate, 2);
} elseif ($waterbill->consumption <= 40) {
$additionalUnits1 = 10;
$additionalUnits2 = 10;
$additionalUnits3 = $waterbill->consumption - 30;
$amount +=
$additionalUnits1 * $bracket1Rate +
$additionalUnits2 * $bracket2Rate +
$additionalUnits3 * $bracket3Rate;
$details[] = number_format($additionalUnits1 * $bracket1Rate, 2);
$details[] = number_format($additionalUnits2 * $bracket2Rate, 2);
$details[] = number_format($additionalUnits3 * $bracket3Rate, 2);
} else {
$additionalUnits1 = 10;
$additionalUnits2 = 10;
$additionalUnits3 = 10;
$additionalUnits4 = $waterbill->consumption - 40;
$amount +=
$additionalUnits1 * $bracket1Rate +
$additionalUnits2 * $bracket2Rate +
$additionalUnits3 * $bracket3Rate +
$additionalUnits4 * $bracket4Rate;
$details[] = number_format($additionalUnits1 * $bracket1Rate, 2);
$details[] = number_format($additionalUnits2 * $bracket2Rate, 2);
$details[] = number_format($additionalUnits3 * $bracket3Rate, 2);
$details[] = number_format($additionalUnits4 * $bracket4Rate, 2);
}
}
$totalCollection = $totalWaterAmountpaid ?? 0; // Ensure this is defined somewhere in your code
$percentageOfTotalCollection =
$totalCollection > 0 ? ($amount / $totalCollection) * 100 : 0;
@endphp
{{ $payment->lease->unit->unit_name ?? 'N/A' }}
|
{{ $payment->lease->client->owners_name ?? 'N/A' }}
|
{{ $waterbill->previous_reading ?? 'N/A' }}
|
{{ $waterbill->present_reading ?? 'N/A' }}
|
{{ number_format($waterbill->consumption, 2) ?? 'N/A' }}
|
{{ $waterbill->rate ?? 'N/A' }}
|
{{ number_format($waterbill->amount, 2) ?? 'N/A' }}
|
@if ($totalWaterAmountpaid > 0)
{{ number_format(($waterbill->amount / $totalWaterAmountpaid) * 100, 2) }}%
@else
0.00%
@endif
|
N/A |
N/A
|
N/A |
{{ isset($details[0]) ? $details[0] : 'N/A' }}
|
{{ isset($details[1]) ? $details[1] : 'N/A' }}
|
{{ isset($details[2]) ? $details[2] : 'N/A' }}
|
{{ isset($details[3]) ? $details[3] : 'N/A' }}
|
{{ isset($details[4]) ? $details[4] : 'N/A' }}
|
{{ number_format($amount, 2) ?: 'N/A' }}
|
@endforeach
@empty
No data
available |
@endforelse
Total: |
{{ $totalWaterAmountpaid }} |
0.00%
|
0.00 |
0.00 |
0.00 |
|
|
|
|
|
|