@php use App\Enums\ProposalStatus; use App\Enums\JobType; $statusLabel = $proposal->status?->label() ?? '—'; $statusValue = $proposal->status?->value; $statusPalette = [ 'talep' => ['#dbeafe','#1e40af','#93c5fd'], 'kesif' => ['#ede9fe','#5b21b6','#c4b5fd'], 'taslak' => ['var(--ks-surface-3)','#475569','#cbd5e1'], 'hazirlaniyor' => ['#cffafe','#155e75','#67e8f9'], 'beklemede' => ['#fef3c7','#92400e','#fcd34d'], 'kabul_edildi' => ['#d1fae5','#065f46','#6ee7b7'], 'onaylandi' => ['#d1fae5','#065f46','#6ee7b7'], 'reddedildi' => ['#fee2e2','#991b1b','#fca5a5'], 'iptal' => ['var(--ks-surface-3)','#475569','#cbd5e1'], 'zaman_asimi' => ['#fee2e2','#991b1b','#fca5a5'], 'proje_oldu' => ['#d1fae5','#047857','#6ee7b7'], 'gonderildi' => ['#cffafe','#155e75','#67e8f9'], 'revize' => ['#f3e8ff','#7e22ce','#d8b4fe'], 'revizyon' => ['#f3e8ff','#7e22ce','#d8b4fe'], ]; [$stBg, $stColor, $stBorder] = $statusPalette[$statusValue] ?? ['var(--ks-surface-3)','#475569','#cbd5e1']; $jt = $proposal->job_type ? JobType::tryFrom($proposal->job_type) : null; $propDate = $proposal->requested_at ?? $proposal->created_at; // Totals // ARA TOPLAM BRÜT (iskontosuz) — teklif iskontosu kalemlere dağıtıldı, fark = ek iskonto satırı $araToplamHaric = $proposal->grossSubtotal(); $globalDiscAmt = $proposal->globalDiscountAmount(); $hasGlobalDisc = $globalDiscAmt > 0; $netToplamHaric = $araToplamHaric - $globalDiscAmt; $kdvTutari = $proposal->items->sum(function ($item) { $rate = $item->serviceItem->kdv_rate ?? 0; return $item->total_price * $rate / 100; }); $genelToplam = $netToplamHaric + $kdvTutari; $kdvOranlari = $proposal->items ->filter(fn($i) => $i->serviceItem && ($i->serviceItem->kdv_rate ?? 0) > 0) ->map(fn($i) => '%' . $i->serviceItem->kdv_rate) ->unique()->values()->implode(', '); $hasAmount = $genelToplam > 0; $locationStr = $proposal->city ? implode(' / ', array_filter([$proposal->city, $proposal->district, $proposal->neighborhood])) : null; $adaParselStr = collect([ $proposal->ada ? 'Ada '.$proposal->ada : null, $proposal->parcel ? 'Parsel '.$proposal->parcel : null, ])->filter()->implode(' / ') ?: null; $requesterStr = $proposal->requester_work_type ?: null; // Kamu işi durumu (3 seçenekli) $pwLabel = match($proposal->public_work_type) { 'evet' => 'Evet — Kamu İşi', 'hayir' => 'Hayır — Özel İş', 'diger' => 'Diğer' . ($proposal->public_work_note ? ' — ' . $proposal->public_work_note : ''), default => ($proposal->is_public_work ? 'Evet — Kamu İşi' : null), }; $allQa = array_filter([ 'Teklif Tarihi' => $propDate->format('d.m.Y'), 'Geçerlilik Süresi' => $proposal->validity_days ? $proposal->validity_days . ' gün' : null, 'Hazırlayan' => $proposal->preparedBy?->name ?? ($proposal->prepared_by_name ?: null), 'Teklif Dosya No' => $proposal->offer_file_no ?: null, 'İş Türü' => $jt ? $jt->label() : ($proposal->job_type ?: null), 'Revizyon' => $proposal->isRevision() ? ('REV'.$proposal->revision_number.' — '.$proposal->created_at->format('d.m.Y')) : null, 'İl / İlçe / Mahalle' => $locationStr, 'Ada / Parsel' => $adaParselStr, 'Pafta' => $proposal->pafta ?: null, 'Alan' => $proposal->area_m2 ? number_format($proposal->area_m2, 2, ',', '.').' m²' : null, 'Teklifin Amacı' => $proposal->purpose, 'Mal Sahibi / İş Adı' => $proposal->property_owner, 'Teklif İsteyen Durumu' => $requesterStr, 'Kamu İşi mi?' => $pwLabel, 'Referans' => $proposal->reference, 'Denetleyici Kurum' => $proposal->supervising_authority, 'Kontrol Müh. Notları' => $proposal->inspector_notes, 'Arazi Ulaşım Görüşü' => $proposal->site_access_notes, 'Jeolojik / Zemin Bilgisi' => $proposal->geological_info, 'İSG Gereksinimleri' => $proposal->isg_requirements, 'Sondaj Makinası Tipi' => $proposal->drilling_machine_type, 'Arazi Çalışma Günü' => $proposal->field_work_days ? $proposal->field_work_days.' gün' : null, 'İşe Başlama Tarihi' => $proposal->start_date ? $proposal->start_date->format('d.m.Y') : null, 'Toplam İşgünü' => $proposal->total_work_days ? $proposal->total_work_days.' gün' : null, 'Günlük Yatış Bedeli' => $proposal->daily_delay_fee, ]); $groupedItems = \App\Models\ServiceItem::sortGroupedByCategory( $proposal->items->groupBy(function($item) { return $item->serviceItem ? ($item->serviceItem->category ?? '__other__') : '__other__'; }) ); $catPalette = [ 'sondaj' => ['bg'=>'linear-gradient(135deg,#eff6ff,#dbeafe)','border'=>'#3b82f6','text'=>'#1e40af','total'=>'#1d4ed8'], 'jeofizik' => ['bg'=>'linear-gradient(135deg,#fffbeb,#fef3c7)','border'=>'#f59e0b','text'=>'#78350f','total'=>'#b45309'], 'arazi_deneyleri' => ['bg'=>'linear-gradient(135deg,#f0fdf4,#d1fae5)','border'=>'#10b981','text'=>'#064e3b','total'=>'#059669'], '__other__' => ['bg'=>'linear-gradient(135deg,var(--ks-surface-alt),var(--ks-surface-3))','border'=>'#94a3b8','text'=>'#334155','total'=>'#475569'], ]; // Ödeme Planı $sahaItems = $proposal->paymentPlanItems->where('phase','saha')->values(); $labItems = $proposal->paymentPlanItems->where('phase','lab')->values(); $sahaTotal = (float) $sahaItems->sum('percentage'); $labTotal = (float) $labItems->sum('percentage'); $ppGrandTotal = $sahaTotal + $labTotal; @endphp
{{-- ═══════ HEADER ═══════ --}}
@if($firmaLogoBase64) @endif
{{ $firmaSettings['firma_kisa_adi'] ?: $firmaSettings['firma_adi'] }}
@if($firmaSettings['firma_telefon'] || $firmaSettings['firma_email'] || $firmaSettings['firma_adres'])
@if($firmaSettings['firma_telefon']){{ $firmaSettings['firma_telefon'] }}@endif @if($firmaSettings['firma_telefon'] && $firmaSettings['firma_email']) · @endif @if($firmaSettings['firma_email']){{ $firmaSettings['firma_email'] }}@endif @if(($firmaSettings['firma_telefon'] || $firmaSettings['firma_email']) && $firmaSettings['firma_adres']) · @endif @if($firmaSettings['firma_adres']){{ Str::limit($firmaSettings['firma_adres'], 60) }}@endif
@endif
TEKLİF
{{ Str::limit($proposal->title, 50) }}
{{ $proposal->proposal_number }}
{{ ($proposal->updated_at ?? $proposal->created_at)->format('d.m.Y') }}
{{-- ═══════ HERO 4-UP KARTLAR — Teklif Başlığı solda ═══════ --}}
Teklif Başlığı
{{ $proposal->title ?: '—' }}
{{ $proposal->proposal_number }} @if($proposal->isRevision()) REV{{ $proposal->revision_number }} @endif
Müşteri
{{ $proposal->contact?->display_name ?? $proposal->contact?->name ?? '—' }}
@if($proposal->contact?->phone)
📞 {{ $proposal->contact->phone }}
@endif
Genel Toplam (KDV Dahil)
{{ $hasAmount ? number_format($genelToplam, 2, ',', '.') : '—' }}@if($hasAmount){{ $proposal->currency ?? '₺' }}@endif
Durum
{{ $statusLabel }}
{{ $propDate->format('d.m.Y') }}
{{-- Açıklama bloğu kaldırıldı (aynı içerik aşağıdaki Notlar kartında gösteriliyor) --}} {{-- ═══════ Q&A ═══════ --}} @if(count($allQa) > 0) @php $qaPadCount = (3 - (count($allQa) % 3)) % 3; @endphp
📋 Teklif Detay Bilgileri
@foreach($allQa as $lbl => $val)
{{ $lbl }} {{ $val }}
@endforeach {{-- Son satırı boş hücrelerle doldur — sütun hizalaması bozulmasın --}} @for($qpi = 0; $qpi < $qaPadCount; $qpi++)
@endfor
@endif {{-- ═══════ HİZMET KALEMLERİ + TOTALS (tfoot) ═══════ --}} @if($proposal->items->isNotEmpty())
≡
Hizmet Kalemleri
Teklif kapsamındaki iş kalemleri
{{ $proposal->items->count() }} kalem
@foreach($groupedItems as $catSlug => $items) @php $metaRow = ($allCategoriesMeta ?? [])[$catSlug] ?? null; $cName = $metaRow['label'] ?? (\App\Models\ServiceItem::$categoryLabels[$catSlug] ?? null) ?? ($catSlug === '__other__' ? 'Katalog Dışı' : ucfirst((string) $catSlug)); if (isset($catPalette[$catSlug])) { $cPal = $catPalette[$catSlug]; } elseif ($metaRow) { $cColor = $metaRow['color'] ?? '#6b7280'; $cPal = ['bg' => $cColor.'14', 'border' => $cColor, 'text' => $cColor, 'total' => $cColor]; } else { $cPal = $catPalette['__other__']; } $cTotal = $items->sum('total_price'); @endphp @foreach($items as $item) @php $iDiscType = $item->discount_type ?? 'percent'; $iDiscVal = $item->discount_value ? (float)$item->discount_value : 0; @endphp @endforeach @endforeach {{-- TOTALS — show sayfasındaki tfoot ile birebir --}} {{-- Ara Toplam --}} {{-- Teklif İskontosu — her zaman göster --}} {{-- Net Toplam — yalnızca iskonto varsa --}} @if($hasGlobalDisc) @endif {{-- KDV Tutarı --}} {{-- Genel Toplam --}}
Kod Hizmet Adı / Açıklama Birim Miktar Birim Fiyat İskonto Toplam
{{ $cName }} {{ number_format($cTotal, 2, ',', '.') }} ₺
@if($item->serviceItem){{ $item->serviceItem->code }}@else —@endif
{{ $item->serviceItem?->name ?? 'Kalem' }}
@if($item->description)
{{ $item->description }}
@endif
{{ $item->unit ?? '—' }} {{ number_format((float)$item->quantity, 2, ',', '.') }} {{ number_format((float)$item->unit_price, 2, ',', '.') }} ₺ @if($iDiscVal > 0) @if($iDiscType === 'percent')%{{ number_format($iDiscVal, 2, ',', '.') }}@else{{ number_format($iDiscVal, 2, ',', '.') }} ₺@endif @else — @endif {{ number_format((float)$item->total_price, 2, ',', '.') }} ₺
Ara toplam (KDV hariç) {{ number_format($araToplamHaric, 2, ',', '.') }} ₺
Teklif İskontosu @if($hasGlobalDisc) {{-- Her zaman yüzde göster (2 ondalık) --}} -%{{ number_format($proposal->global_discount_percentage, 2, ',', '.') }} oran @endif @if($hasGlobalDisc) −{{ number_format($globalDiscAmt, 2, ',', '.') }} ₺ @else — @endif
Net Toplam (KDV hariç) {{ number_format($netToplamHaric, 2, ',', '.') }} ₺
KDV tutarı @if($kdvOranlari){{ $kdvOranlari }}@endif {{ number_format($kdvTutari, 2, ',', '.') }} ₺
Genel toplam
KDV dahil
{{ number_format($genelToplam, 2, ',', '.') }} ₺
@endif {{-- ═══════ NOTLAR — her zaman göster ═══════ --}}
💬
Notlar
@if(!empty($proposal->description))
{{ $proposal->description }}
@else
Henüz not eklenmedi.
@endif
{{-- ═══════ ÖDEME PLANI — sadece toggle açıksa ═══════ --}} @if($proposal->include_payment_plan)
📅
Ödeme Planı
Toplam: %{{ number_format($ppGrandTotal, 0) }}
{{-- Saha Çalışması --}}
Anlaşma / Mobilizasyon / Saha Çalışması Aşaması
Talep: %{{ number_format($sahaTotal, 0) }}
@if($sahaItems->count() > 0) @foreach($sahaItems as $i => $pi) @endforeach
{{ $i+1 }} {{ $pi->description }} %{{ number_format((float)$pi->percentage, 0) }}
@else
Saha çalışması ödeme kalemi eklenmemiş.
@endif
{{-- Laboratuvar & Rapor --}}
Laboratuvar İşleri ve Rapor Yazım Aşaması
Talep: %{{ number_format($labTotal, 0) }}
@if($labItems->count() > 0) @foreach($labItems as $i => $pi) @endforeach
{{ $i+1 }} {{ $pi->description }} %{{ number_format((float)$pi->percentage, 0) }}
@else
Laboratuvar ödeme kalemi eklenmemiş.
@endif
{{-- Not & Banka --}}
Ödeme Planı Notu & Banka Bilgisi
{{ $proposal->payment_plan_note ?: '—' }}
@if($proposal->bank_account_info)
{{ $proposal->bank_account_info }}
@endif
@endif {{-- /include_payment_plan --}} {{-- ═══════ SORUMLULUKLAR — sadece toggle açıksa ═══════ --}} @if($proposal->include_responsibilities)
🛡️
Sorumluluk Açıklamaları
{{ $proposal->responsibilities->count() }} madde
@if($proposal->responsibilities->count() > 0) @php $respAll = $proposal->responsibilities; $respCols = [[], [], []]; // Sıralama: yukarıdan aşağıya, soldan sağa (column-fill) $totalResp = $respAll->count(); $rowsPerCol = (int) ceil($totalResp / 3); foreach ($respAll as $i => $r) { $colIndex = min(2, intdiv($i, $rowsPerCol)); $respCols[$colIndex][] = ['idx' => $i, 'resp' => $r]; } @endphp
@foreach($respCols as $colIdx => $colItems)
@foreach($colItems as $item) @php $idx = $item['idx']; $resp = $item['resp']; $party = $resp->responsible_party; @endphp @endforeach
No Açıklama Yok Yük. İşv.
{{ $idx + 1 }} {{ $resp->description }}
@endforeach
@else
Henüz sorumluluk açıklaması eklenmemiş.
@endif
@endif {{-- /include_responsibilities --}} {{-- ═══════ FOOTER ═══════ --}}