{{-- TEKLİF BELGESİ — ortak kabuğunu kullanır; sadece teklif İÇERİĞİNİ verir. Kabuk (kafa/CSS/araç çubuğu/sayfalama/print) components/belge.blade.php'de. Değişkenler: $proposal, $firmaSettings, $logoSrc, $yon, $margin, $show[logo|detay|odeme|sorumluluk|teklifnot], $autoPrint --}} @php use App\Enums\JobType; // ── Toplamlar (teklif iskontosu kalemlere dağıtıldı; brüt-net farkı = ek iskonto) ── $brutToplam = $proposal->grossSubtotal(); $siparisIskonto = $proposal->globalDiscountAmount(); $hasGlobalDisc = $siparisIskonto > 0.005; $araToplamHaric = $brutToplam - $siparisIskonto; // = Σ kalem net (KDV hariç) $discPctLabel = ($hasGlobalDisc && (float) $proposal->global_discount_percentage > 0) ? ' (%' . rtrim(rtrim(number_format($proposal->global_discount_percentage, 2, ',', '.'), '0'), ',') . ')' : ''; /* KDV ORANI ARTIK KALEMDEN (proposal_items.kdv_rate). Eskiden her basımda service_items'ten CANLI okunuyordu; katalogda oran değişince MÜŞTERİYE GÖNDERİLMİŞ belgenin genel toplamı da değişiyordu. Eski kalemler için katalog yedeği bırakıldı (migration hepsini doldurdu). */ $kdvKirilim = []; foreach ($proposal->items as $item) { $oran = (float) ($item->kdv_rate ?? $item->serviceItem->kdv_rate ?? 0); $anahtar = (string) $oran; if (!isset($kdvKirilim[$anahtar])) { $kdvKirilim[$anahtar] = ['oran' => $oran, 'matrah' => 0.0, 'kdv' => 0.0]; } $kdvKirilim[$anahtar]['matrah'] += (float) $item->total_price; $kdvKirilim[$anahtar]['kdv'] += (float) $item->total_price * $oran / 100; } $kdvKirilim = array_values(array_filter($kdvKirilim, fn ($k) => $k['kdv'] > 0.004)); usort($kdvKirilim, fn ($a, $b) => $b['oran'] <=> $a['oran']); $kdvTutari = array_sum(array_column($kdvKirilim, 'kdv')); $genelToplam = $araToplamHaric + $kdvTutari; // ── Kategori gruplama (ekranla aynı palet) ── $groupedItems = \App\Models\ServiceItem::sortGroupedByCategory( $proposal->items->groupBy(function($item){ return $item->serviceItem ? ($item->serviceItem->category ?? '__other__') : '__other__'; }) ); // ── Müşteri satırları ── $c = $proposal->contact; $custLines = array_values(array_filter([ $c && $c->tax_number ? 'VKN: ' . $c->tax_number . ($c->tax_office ? ' · ' . $c->tax_office : '') : ($c && $c->tax_office ? 'V.D.: ' . $c->tax_office : null), $c ? trim(implode(' / ', array_filter([$c->address, trim(implode(' ', array_filter([$c->district, $c->city])))]))) : null, $c && $c->phone ? 'Tel: ' . $c->phone : null, ])); // ── Proje / Konum satırları (teklif kendi konumunu taşır; proje varsa onu da) ── $pr = $proposal->project; $locStr = trim(implode(' / ', array_filter([ $proposal->district ?: null, $proposal->city ?: null, $proposal->neighborhood ?: null, ]))); $adaStr = collect([ $proposal->ada ? 'Ada ' . $proposal->ada : null, $proposal->parcel ? 'Parsel ' . $proposal->parcel : null, ])->filter()->implode(' / '); if ($adaStr && $proposal->pafta) $adaStr .= ' · Pafta: ' . $proposal->pafta; $projLines = array_values(array_filter([ $locStr ?: null, $adaStr ?: null, ])); $projName = $pr ? ($pr->project_number . ($pr->title ? ' — ' . $pr->title : '')) : ($proposal->title ?: '—'); // ── Durum ── $stColor = $proposal->status?->color() ?? '#64748b'; $stLabel = $proposal->status?->label() ?? '—'; $propDate = $proposal->requested_at ?? $proposal->created_at; // ── Teklif Detayları (müşteriye dönük alanlar; boşlar filtrelenir) ── $jt = $proposal->job_type ? JobType::tryFrom($proposal->job_type) : null; // Meta şeritte olanlar (Teklif Kodu/Tarih/Geçerlilik/Durum) burada TEKRARLANMAZ. $teklifDetay = array_filter([ 'İş Türü' => $jt ? $jt->label() : ($proposal->job_type ?: null), 'Teklif Dosya No' => $proposal->offer_file_no ?: null, 'Alan' => $proposal->area_m2 ? number_format($proposal->area_m2, 2, ',', '.') . ' m²' : null, 'Teklifin Amacı' => $proposal->purpose ?: null, 'Mal Sahibi / İş Adı' => $proposal->property_owner ?: null, 'Referans' => $proposal->reference ?: null, 'Hazırlayan' => $proposal->prepared_by_name ?: ($proposal->preparedBy?->name ?? null), ]); @endphp @php // Belge adı = "Kod - Proje Adı - Tip" (PDF dosya adı + araç çubuğu). Proje adı yoksa "Kod - Tip". $__belgeProj = $proposal->project?->title ?: ($proposal->title ?: null); $belgeBaslik = $proposal->proposal_number . ($__belgeProj ? '-' . $__belgeProj : '') . '-Teklif'; @endphp {{-- ══ Antet ══ --}} @if($show['logo'] ?? true)
{{ $firmaSettings['firma_kisa_adi'] ?: $firmaSettings['firma_adi'] }}
@if($firmaSettings['firma_kisa_adi'] && $firmaSettings['firma_adi'] && $firmaSettings['firma_kisa_adi'] !== $firmaSettings['firma_adi'])
{{ $firmaSettings['firma_adi'] }}
@endif @php $iletisim = trim(implode(' · ', array_filter([$firmaSettings['firma_telefon'] ?? '', $firmaSettings['firma_email'] ?? '']))); @endphp @if($iletisim)
{{ $iletisim }}
@endif
TEKLİF
Hizmet Teklif Formu
{{ $proposal->proposal_number }}
@endif {{-- ══ Müşteri + Proje/Konum ══ --}}
Müşteri
{{ optional($c)->display_name ?? optional($c)->name ?? '—' }}
@foreach($custLines as $ln)
{{ $ln }}
@endforeach
{{ $pr ? 'Proje' : 'Konum' }}
{{ $projName }}
@foreach($projLines as $ln)
{{ $ln }}
@endforeach
{{-- ══ Meta şerit ══ --}}
Teklif Kodu
{{ $proposal->proposal_number }}
Teklif Tarihi
{{ $propDate?->format('d.m.Y') ?? '—' }}
Geçerlilik
{{ $proposal->validity_days ? $proposal->validity_days.' gün' : '—' }}
Durum
{{ $stLabel }}
{{-- ══ Teklif Detayları (opsiyonel) ══ --}} @if(($show['detay'] ?? true) && count($teklifDetay))
Teklif Detayları
@php $detayChunks = array_chunk($teklifDetay, 2, true); @endphp @foreach($detayChunks as $row) @foreach($row as $lbl => $val) @endforeach @if(count($row) < 2)@endif @endforeach
{{ $lbl }}
{{ $val }}
@endif {{-- ══ Kalemler ══ --}}
Hizmet Kalemleri · {{ $proposal->items->count() }} kalem
@if($proposal->items->isEmpty())
Kalem bulunamadı.
@else
@foreach($groupedItems as $catSlug => $catItems) @php $si0 = $catItems->first()?->serviceItem; $catName = $si0?->category_label ?? (\App\Models\ServiceItem::$categoryLabels[$catSlug] ?? ($catSlug === '__other__' ? 'Katalog Dışı' : ucfirst((string)$catSlug))); $catTotal= (float) $catItems->sum('total_price'); $catSinif = ($catSlug === '__other__' || !$catSlug) ? 'diger' : $catSlug; @endphp {{-- Kategori satırı EKRANDAKİ dille aynı: tonlu satır + renkli çubuk yerine nötr şerit + rengi taşıyan kategori çipi. --}} @foreach($catItems as $item) @php $si = $item->serviceItem; $lineGross = (float) $item->quantity * (float) $item->unit_price; $lineNet = (float) $item->total_price; $lineDisc = max(0, $lineGross - $lineNet); $iDiscType = $item->discount_type ?? 'percent'; $iDiscVal = $item->discount_value ? (float) $item->discount_value : 0; $iKdvOran = (float) ($item->kdv_rate ?? $si?->kdv_rate ?? 0); @endphp @endforeach @endforeach
Kod Hizmet Adı / Açıklama Birim Miktar Birim Fiyat İskonto KDV Toplam
{{ $catName }} {{ $catItems->count() }} kalem {{ number_format($catTotal, 2, ',', '.') }} ₺
{{-- Kod SAYFA FONTUYLA ve kategori renginde (liste kuralı). --}} @if($si){{ $si->code }} @else — @endif {{ $si?->name ?: 'Katalog dışı' }} @if($item->description)
{{ $item->description }}
@endif
{{ $item->unit ?: '—' }} {{ number_format((float)$item->quantity, 2, ',', '.') }} {{ number_format((float)$item->unit_price, 2, ',', '.') }} ₺ @if($lineDisc > 0.005) −{{ number_format($lineDisc, 2, ',', '.') }} ₺ @if($iDiscVal > 0)
@if($iDiscType === 'percent')%{{ rtrim(rtrim(number_format($iDiscVal, 2, ',', '.'), '0'), ',') }}@else{{ number_format($iDiscVal, 2, ',', '.') }} ₺@endif
@endif @else — @endif
%{{ rtrim(rtrim(number_format($iKdvOran, 2, ',', '.'), '0'), ',') }} {{ number_format($lineNet, 2, ',', '.') }} ₺
@endif
{{-- ══ Toplamlar (renkli) ══ --}}
@if($hasGlobalDisc) @endif {{-- KDV HER ORAN KENDİ SATIRINDA + matrahı. Tek satırda toplam KDV yazmak, farklı oranlı bir teklifte hangi tutarın hangi orandan geldiğini gizliyordu; resmî belgede bu bilgi gerekli. --}} @forelse($kdvKirilim as $kk) @empty @endforelse
Brüt Ara Toplam:{{ number_format($brutToplam, 2, ',', '.') }} ₺
Teklif İskontosu{{ $discPctLabel }}:−{{ number_format($siparisIskonto, 2, ',', '.') }} ₺
{{ $hasGlobalDisc ? 'Net Ara Toplam' : 'Ara Toplam' }} (KDV Hariç):{{ number_format($araToplamHaric, 2, ',', '.') }} ₺
KDV %{{ rtrim(rtrim(number_format($kk['oran'], 2, ',', '.'), '0'), ',') }} (matrah {{ number_format($kk['matrah'], 2, ',', '.') }} ₺): {{ number_format($kk['kdv'], 2, ',', '.') }} ₺
KDV:0,00 ₺
GENEL TOPLAM (KDV Dahil):{{ number_format($genelToplam, 2, ',', '.') }} ₺
{{-- ══ Ödeme Planı (+ not & banka AYNI KART) — bölünmesin ══ --}} @if(($show['odeme'] ?? true))
@include('muhasebe.partials.odeme-plani', ['items' => $proposal->paymentPlanItems, 'note' => $proposal->payment_plan_note, 'bank' => $proposal->bank_account_info, 'pdf' => false])
@endif {{-- ══ Sorumluluklar — bölünmesin ══ --}} @if(($show['sorumluluk'] ?? true) && $proposal->responsibilities->isNotEmpty())
@include('muhasebe.partials.sorumluluklar', ['items' => $proposal->responsibilities, 'pdf' => false])
@endif {{-- ══ Notlar (Teklif Notu) — bölünmesin ══ --}} @if($show['teklifnot'] ?? true)
@include('muhasebe.partials.teklif-notu', ['note' => $proposal->description, 'pdf' => false])
@endif @php $hazirlayan = $proposal->preparedBy?->kisa_ad ?? $proposal->preparedBy?->name ?? ($proposal->prepared_by_name ?: null); $footerText = $firmaSettings['firma_adi'] . ' · Bu teklif ' . ($proposal->validity_days ?? 15) . ' gün geçerlidir'; if ($hazirlayan) $footerText .= ' · Hazırlayan: ' . $hazirlayan; @endphp
{{ $footerText }}