Month: {{ \DateTime::createFromFormat('!m', request('month'))->format('F') }}
Year: {{ request('year') }}
{{ $property1->property_name }}
@endif @if (request()->has('month') && request()->has('year') && request()->has('property_id')) @php $totalrate = 0; $totalAmount1 = 0; @endphp @php $deposit = 0; $noData = true; // Flag to check if there is any data for the filtered month and year // Get all units for the given property $units = \App\Models\Lease::with('property', 'client', 'unit') ->where('property_id', request()->input('property_id')) ->whereHas('unit', function ($q) { $q->orderByRaw('CAST(SUBSTRING(unit_name, -1) AS UNSIGNED) ASC, unit_name'); // Order by the last number in the unit name }) ->get(); @endphp @forelse ($units as $unit) @php // Check if there is a new payment for the current unit $entry = $newPayments->firstWhere('lease.unit_id', $unit->unit_id); $totalRent = 0; @endphp @if ($entry) @php $noData = false; // Ensure entry->lease exists before accessing its properties if ($entry->lease) { $client = \App\Models\Client::find($entry->lease->client_id); $deposit += $entry->lease->security_deposit + $entry->lease->utilities; // Calculate total payments with penalty if applicable $pastPaymentsTotal = \App\Models\Payment::with([ 'lease', 'electricPayments', 'waterPayments', 'newPayments', ]) ->where('lease_id', $entry->lease_id) ->where('payment_date', '<=', $entry->payment_date) ->get() ->sum(function ($payment) use ($client) { // Ensure the lease and payment are valid $totalRent = 0; // Check if payment is valid before proceeding if ($payment instanceof \App\Models\Payment) { // Correctly access the lease associated with this payment $rentAmount = $payment->Amount; $rentAmount = $payment->lease->getEscalatedRentPenaltyAmountWithPenalty( $payment->payment_date, $payment->lease->escalation ?? 12, ); $totalRent += $rentAmount; } return $totalRent; }); $pastPaidTotal = \App\Models\Payment::with([ 'lease', 'electricPayments', 'newPayments', 'waterPayments', ]) ->where('lease_id', $entry->lease_id) ->where('payment_date', '<=', $entry->payment_date) ->get() ->sum(function ($payment) { $rentalAmount = $payment->newPayments->sum('rental_amount'); $electricBillAmount = $payment->newPayments->sum( 'electricbill_amount', ); $waterBillAmount = $payment->newPayments->sum( 'waterbill_amount', ); return $rentalAmount + $electricBillAmount + $waterBillAmount; }); $totalAmount = $pastPaymentsTotal - $pastPaidTotal; $totalAmount1 += $totalAmount; } @endphp @else @php $month = request()->input('month'); $year = request()->input('year'); $deposit += $unit->security_deposit + $unit->utilities; @endphp @endif @empty @if ($noData) @endif @endforelseUnit | Names | Due Date | Rental Rate | Outstanding Deposit | Balance/Collectibles |
---|---|---|---|---|---|
{{ $entry->lease->unit->unit_name }} | {{ $entry->lease->client->owners_name }} | {{ \Carbon\Carbon::parse($entry->payment_date)->addMonth()->format('d-M-y') }} | {{ number_format($entry->Amount, 2) }} | {{ number_format($entry->lease->security_deposit + $entry->lease->utilities, 2) }} | {{ $totalAmount >= 0 ? number_format($totalAmount, 2) : '0.00' }} |
{{ $unit->unit->unit_name }} | {{ $unit->client->owners_name }} | {{ \Carbon\Carbon::create($year, $month, 1)->addMonth()->format('d-M-y') }} | {{ number_format($unit->rent_amount, 2) }} | {{ number_format($unit->security_deposit + $unit->utilities, 2) }} | 0.00 |
No data available for the selected filters | |||||
Total: | {{ number_format($deposit, 2) }} | {{ number_format($totalAmount1, 2) }} |