@php
$limit_programmes = Auth::check() ? 999 : 3; // Limiter à 3 si non connecté
@endphp
@foreach($programs as $program)
@if($limit_programmes > 0)
@php
// Image
$firstMedia = $program->getFirstMedia('images');
$imageUrl = $firstMedia ? getImageFromCDN($firstMedia, 'miniature') : secure_asset('assets/img/logo_mpp.svg');
// Prix minimum
$minPriceLot = $program->lots()
->where('is_active', true)
->whereHas('prices', function($q) {
$q->where('type', 'prix_ttc')
->where('value', '>', 0);
})
->with(['prices' => function($q) {
$q->where('type', 'prix_ttc')
->where('value', '>', 0)
->orderBy('value', 'asc');
}])
->first();
$minPrice = $minPriceLot && $minPriceLot->prices->first() ? $minPriceLot->prices->first()->value : 0;
// Ville
$address = $program->addresses()->first();
$city = $address ? $address->city : 'N/A';
// Date de livraison
$deliveryDate = $program->dates()->where('type', 'date_livraison')->first();
$deliveryYear = $deliveryDate ? \Carbon\Carbon::parse($deliveryDate->value)->format('Y') : 'N/A';
// Fiscalités
$fiscalites = $program->fiscalites->pluck('type')->map(fn($f) => $f->label())->toArray();
$fiscaliteLibelle = !empty($fiscalites) ? implode(', ', $fiscalites) : 'N/A';
// TVA 5.5%
$hasTva5 = $program->lots()
->whereHas('prices', function($q) {
$q->where('type', PriceType::PRIX_TVA_5_5->value)
->where('value', '>', 0);
})
->exists();
// LLI (TVA 10%)
$hasLli = $program->lots()
->whereHas('prices', function($q) {
$q->where('type', PriceType::PRIX_TVA_10->value)
->where('value', '>', 0);
})
->exists();
// Exclusivité
$hasExclusivite = $program->marketingTags()->where('type', MarketingTagType::EXCLUSIVITE->value)->exists();
// Opérations commerciales
$hasOpeComs = $program->opeComs()->exists() || $program->lots()->whereHas('opeComs')->exists();
// Quote/travaux
$quoteTravaux = null;
$lotsWithTravaux = $program->lots()
->whereHas('prices', function($q) {
$q->whereIn('type', [
\App\Enums\PriceTypeTravaux::PRIX_TRAVAUX_ELIGIBLE->value,
\App\Enums\PriceTypeTravaux::PRIX_TRAVAUX_NON_ELIGIBLE->value
])
->where('value', '>', 0);
})
->with(['prices' => function($q) {
$q->whereIn('type', [
'prix_ttc',
\App\Enums\PriceTypeTravaux::PRIX_TRAVAUX_ELIGIBLE->value,
\App\Enums\PriceTypeTravaux::PRIX_TRAVAUX_NON_ELIGIBLE->value
]);
}])
->get();
if ($lotsWithTravaux->count() > 0) {
$quotes = [];
foreach ($lotsWithTravaux as $lot) {
$prixTTC = $lot->prices->where('type', 'prix_ttc')->first()?->value ?? 0;
$prixTravaux = $lot->prices
->whereIn('type', [
\App\Enums\PriceTypeTravaux::PRIX_TRAVAUX_ELIGIBLE->value,
\App\Enums\PriceTypeTravaux::PRIX_TRAVAUX_NON_ELIGIBLE->value
])
->sum('value');
if ($prixTTC > 0 && $prixTravaux > 0) {
$quotes[] = ($prixTravaux / $prixTTC) * 100;
}
}
if (!empty($quotes)) {
$quoteTravaux = round(max($quotes));
}
}
// Déterminer si TTC ou HT
$isHT = false;
$mainFiscalite = $program->fiscalites->first();
if ($mainFiscalite && $mainFiscalite->type->value === 'monument_historique') {
$isHT = true;
}
@endphp
{{ ucwords(mb_strtolower($program->name)) }}
à partir de
{{ $minPrice > 0 ? number_format($minPrice, 0, ',', ' ') : '0' }} €
{{ $isHT ? 'HT' : 'TTC' }}
@php
if (!Auth::check()) {
$limit_programmes--;
}
@endphp
@endif
@endforeach