@php $canLotsWrite = $canLotsWrite ?? auth()->user()->canAccessPartnerLotsWrite(); $canProgramsWrite = auth()->user()->canAccessPartnerProgramsWrite(); $priceableAnnexes = $program->annexes() ->with(['parentProduct.states', 'prices', 'surfaces', 'states']) ->get() ->filter(fn ($annexe) => $annexe->type && $annexe->type->priceable()) ->sortBy('id') ->values(); $annexeTypes = \App\Enums\ProductType::priceableAnnexeTypes(); @endphp
{{ $priceableAnnexes->count() }} {{ $priceableAnnexes->count() > 1 ? 'annexes' : 'annexe' }} @if($canProgramsWrite) @endif
@forelse($priceableAnnexes as $annexe) @php $parentLot = $annexe->parentProduct; $state = $annexe->current_state; $surface = $annexe->surfaces->first(); $ttcPrice = $annexe->prices->firstWhere('type', \App\Enums\PriceTypeAnnexe::PRIX_TTC->value); $allPrices = $annexe->prices->sortBy('type')->values(); $canDetach = $parentLot && $state === \App\Enums\ProductState::LIBRE && $parentLot->current_state === \App\Enums\ProductState::LIBRE; $annexeSalePriceTypesForInclude = [ \App\Enums\PriceTypeAnnexe::PRIX_TTC->value, \App\Enums\PriceTypeAnnexe::PRIX_TVA_5_5->value, \App\Enums\PriceTypeAnnexe::PRIX_TVA_10->value, \App\Enums\PriceTypeAnnexe::PRIX_HT->value, ]; $isAnnexeIncludedInLotPrice = $annexe->prices->first(fn ($p) => in_array($p->type, $annexeSalePriceTypesForInclude, true) && $p->read_only) ? true : false; $parentLotTtcPrice = $parentLot?->prices?->firstWhere('type', \App\Enums\PriceType::PRIX_TTC->value); try { $parentLotTypeLabel = $parentLot?->type ? $parentLot->type->label() : ''; } catch (\Throwable $e) { $parentLotTypeLabel = ''; } $annexeSurfaceLabel = $surface ? (fmod((float) $surface->value, 1.0) === 0.0 ? number_format((float) $surface->value, 0, ',', ' ') : number_format((float) $surface->value, 2, ',', ' ')).' m²' : ''; @endphp @empty @endforelse
{{ $annexe->type?->label() ?? 'Type inconnu' }} {{ $annexe->number ?: '—' }} @if($surface) {{ fmod((float) $surface->value, 1.0) === 0.0 ? number_format((float) $surface->value, 0, ',', ' ') : number_format((float) $surface->value, 2, ',', ' ') }} m² @else — @endif @if($parentLot)
Lot {{ $parentLot->number }} @if($canProgramsWrite) @if($canDetach) @else @endif @endif
@else @if($state === \App\Enums\ProductState::LIBRE && $canProgramsWrite) @else Non rattachée @endif @endif
{{ $ttcPrice ? number_format((float) $ttcPrice->value, 0, ',', ' ') . ' €' : '—' }} {{ $state->label() }}
@if($parentLot) @else @endif
Aucune annexe

Ce programme ne contient pas encore d'annexe vendable.

@foreach($priceableAnnexes as $annexe) @php $annexeSalePrices = $annexe->prices->filter(fn ($price) => in_array($price->type, [ \App\Enums\PriceTypeAnnexe::PRIX_TTC->value, \App\Enums\PriceTypeAnnexe::PRIX_TVA_5_5->value, \App\Enums\PriceTypeAnnexe::PRIX_TVA_10->value, \App\Enums\PriceTypeAnnexe::PRIX_HT->value, ], true)); $annexeRentalPrices = $annexe->prices->filter(fn ($price) => in_array($price->type, [ \App\Enums\PriceTypeLoyer::MENSUEL_TTC->value, \App\Enums\PriceTypeLoyer::MENSUEL_HT->value, \App\Enums\PriceTypeLoyer::MENSUEL_DENORMANDIE_TTC->value, \App\Enums\PriceTypeLoyer::MENSUEL_DENORMANDIE_HT->value, \App\Enums\PriceTypeLoyer::MENSUEL_PLAFONNE_DISPOSITIF_FISCAL->value, \App\Enums\PriceTypeLoyer::MENSUEL_SOCIAL_JEAN_BRUN->value, \App\Enums\PriceTypeLoyer::MENSUEL_TRES_SOCIAL_JEAN_BRUN->value, ], true)); @endphp @endforeach @if($canProgramsWrite) @endif @push('scripts') @endpush