@extends('layouts.sidebar') @section('content')
Unit Name | Property Name | @foreach (['Q1', 'Q2', 'Q3', 'Q4'] as $quarter){{ $quarter }} | @endforeach
---|---|---|
{{ $unit->unit_name }} | {{ $unit->property->property_name }} | @foreach (['Q1' => [1, 2, 3], 'Q2' => [4, 5, 6], 'Q3' => [7, 8, 9], 'Q4' => [10, 11, 12]] as $quarter => $months) @php $totalAmount = 0; foreach ($unit->leases as $lease) { foreach ($lease->payments as $payment) { // Check if the payment date falls within the current quarter $paymentMonth = $payment->payment_date->format('n'); $paymentYear = $payment->payment_date->format('Y'); if ($paymentYear == $year && in_array($paymentMonth, $months)) { $totalAmount += is_numeric($payment->Amount) ? $payment->Amount : 0; $totalAmount += $payment->waterPayments->sum('amount') ?? 0; $totalAmount += $payment->electricPayments->sum('amount') ?? 0; $totalAmount += $payment->additionalFees->sum('amount') ?? 0; } } } $client = $unit->leases->first()->client ?? null; $vatApplicable = $client ? $client->vat === 'vat' : false; $vatAmount = 0; if ($vatApplicable) { $vatRate = 0.12; // 12% VAT $vatAmount = $totalAmount * $vatRate; } $vatAmount = is_numeric($vatAmount) ? $vatAmount : 0; @endphp{{ number_format($vatAmount, 2) }} | @endforeach