@extends('docs.master', ['title'=> 'Project Report ']) @section('content')

{{ settings()->get('company_name') }}

Dated: {{ date('d-m-Y') }}
{{-- -------------------------- SOLD UNIT SECTION -------------------------- --}} @php $i = 1; $total_units = 0; $total_sold_area = 0; $total_sale_price = 0; $total_receipts = 0; $total_units_total = 0; // Create a mapping of sold units for available calculation $sold_units_mapping = []; @endphp @foreach($model['sold'] as $item) @php $total_units_total += $item->total_units_total; $total_units += $item->total_units; $total_sold_area += $item->unit_gross_area; $total_sale_price += $item->unit_sale_price; $total_receipts += $item->unit_total_received; // Store sold units for calculation $key = $item->project_id . '_' . $item->unit_type_id; $sold_units_mapping[$key] = [ 'total_units_total' => $item->total_units_total, 'sold_units' => $item->total_units, 'project' => $item->project, 'unit_type' => $item->unit_type ]; @endphp @endforeach {{-- TOTAL ROW --}}
Sold Unit
# Project Unit Type Total Unit Sold Unit Sold Area Sold Price Rate / SQFT Receipts Receipts % Balance
{{ $i++ }} {{ $item->project }} {{ $item->unit_type }} {{ $item->total_units_total }} {{ $item->total_units }} {{ number_format($item->unit_gross_area, 0) }} {{ number_format($item->unit_sale_price, 0) }} {{ number_format($item->unit_gross_area > 0 ? $item->unit_sale_price / $item->unit_gross_area : 0) }} {{ number_format($item->unit_total_received, 0) }} {{ number_format($item->unit_sale_price > 0 ? ($item->unit_total_received / $item->unit_sale_price) * 100 : 0) }} {{ number_format($item->unit_sale_price - $item->unit_total_received) }}
Total {{ number_format($total_units_total) }} {{ number_format($total_units) }} {{ number_format($total_sold_area) }} {{ number_format($total_sale_price) }} {{ number_format($total_sold_area > 0 ? $total_sale_price / $total_sold_area : 0) }} {{ number_format($total_receipts) }} {{ number_format($total_sale_price > 0 ? ($total_receipts / $total_sale_price) * 100 : 0) }}% {{ number_format($total_sale_price - $total_receipts) }}
{{-- Replace your existing Available Unit section with this code --}} {{-- -------------------------- AVAILABLE UNIT SECTION -------------------------- --}}


@php $j = 1; $total_avail_units_count = 0; $total_avail_area = 0; $total_avail_price = 0; $total_avail_units_amount = 0; @endphp @foreach($model['available'] as $item) @php // Only use name-based matching since IDs don't exist $soldData = null; // Try to find matching sold data by unit type name foreach($model['sold'] as $sold) { $soldUnitType = strtolower(trim($sold->unit_type ?? '')); $availableUnitType = strtolower(trim($item->unittypedetail ?? '')); if ($soldUnitType === $availableUnitType) { $soldData = $sold; break; } } // Get total units from available data $totalUnitsFromAvailable = (int)($item->total_units_total ?? $item->total_units ?? 0); // Get sold units from matching sold data $soldUnitsFromSold = $soldData ? (int)($soldData->total_units ?? 0) : 0; // SIMPLE CALCULATION: Total - Sold = Available $calculatedAvailableUnits = $item->available_units; // Add to totals $total_avail_area += $item->gross_area ?? 0; $total_avail_price += $item->total_price ?? 0; $total_avail_units_amount += $totalUnitsFromAvailable; $total_avail_units_count += $calculatedAvailableUnits; @endphp @endforeach {{-- TOTAL ROW --}}
Available Unit
# Project Unit Type Total Unit Available Unit Avail Area Available Price Rate / SQFT
{{ $j++ }} {{ $item->projectname ?? 'N/A' }} {{ $item->unittype ?? 'N/A' }} {{ number_format($totalUnitsFromAvailable) }} {{ number_format($calculatedAvailableUnits) }} {{ number_format($item->gross_area ?? 0, 0) }} {{ number_format($item->total_price ?? 0, 0) }} {{ number_format(($item->gross_area ?? 0) > 0 ? ($item->total_price ?? 0) / ($item->gross_area ?? 0) : 0) }}
Total {{ number_format($total_avail_units_amount) }} {{ number_format($total_avail_units_count) }} {{ number_format($total_avail_area) }} {{ number_format($total_avail_price) }} {{ number_format($total_avail_area > 0 ? $total_avail_price / $total_avail_area : 0) }}
{{-- FOOTER --}}

Printed On: {{ date('d-m-Y h:i:s A') }} by {{ Auth::user()->name }}

@endsection