{{-- HAKEDİŞ BELGESİ — ortak kabuğunu kullanır; sadece hakediş İÇERİĞİNİ verir. Kabuk (kafa/CSS/araç çubuğu/sayfalama/print) components/belge.blade.php'de. Ödeme planı / sorumluluk / teklif notu → siparişten gelir. Değişkenler: $hakedis, $firmaSettings, $logoSrc, $yon, $margin, $show[logo|odeme|sorumluluk|teklifnot], $autoPrint --}} @php // ── Toplamlar (kalem bazlı; brüt−iskonto=net) ── $brutToplam = (float) $hakedis->kalemler->sum(fn($k) => $k->grossLineTotal()); $araToplamHaric = (float) $hakedis->kalemler->sum('subtotal'); // = net KDV hariç $siparisIskonto = max(0, round($brutToplam - $araToplamHaric, 2)); $hasGlobalDisc = $siparisIskonto > 0.005; $kdvTutari = (float) $hakedis->kdv_amount; /* KDV HER ORAN AYRI — oran kalemden (hakedis_kalemleri.kdv_rate). */ $kdvKirilim = []; foreach ($hakedis->kalemler as $kk) { $oran = (float) ($kk->kdv_rate ?? 0); $ah = (string) $oran; if (!isset($kdvKirilim[$ah])) { $kdvKirilim[$ah] = ['oran' => $oran, 'matrah' => 0.0, 'kdv' => 0.0]; } $kdvKirilim[$ah]['matrah'] += (float) $kk->subtotal; $kdvKirilim[$ah]['kdv'] += (float) ($kk->kdv_amount ?? ((float) $kk->subtotal * $oran / 100)); } $kdvKirilim = array_values(array_filter($kdvKirilim, fn ($x) => $x['kdv'] > 0.004)); usort($kdvKirilim, fn ($x, $z) => $z['oran'] <=> $x['oran']); $genelToplam = (float) $hakedis->total_amount; $groupedKalemler = \App\Models\ServiceItem::sortGroupedByCategory( $hakedis->kalemler->groupBy(function($k){ return $k->category ?? $k->serviceItem?->category ?? '__other__'; }) ); $c = $hakedis->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, ])); $p = $hakedis->project ?? $hakedis->siparis?->project; $projLines = array_values(array_filter([ $p ? trim(implode(' / ', array_filter([$p->district, $p->city]))) : null, $p && ($p->ada || $p->parcel || $p->pafta) ? trim('Ada/Parsel: ' . implode(' / ', array_filter([$p->ada, $p->parcel]))) . ($p->pafta ? ' · Pafta: ' . $p->pafta : '') : null, ])); $partyLabel = $hakedis->isTedarikci() ? 'Tedarikçi' : 'Müşteri'; $partyColor = $hakedis->isTedarikci() ? 'var(--ks-on-green)' : 'var(--belge-ana)'; @endphp @php // Belge adı = "Kod - Proje Adı - Tip" (PDF dosya adı + araç çubuğu). Proje adı yoksa "Kod - Tip". $__belgeProj = $hakedis->title; $belgeBaslik = $hakedis->hakedis_no . ($__belgeProj ? '-' . $__belgeProj : '') . '-Hakediş'; @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
HAKEDİŞ
{{ $hakedis->tipLabel() }}
{{ $hakedis->hakedis_no }}
@endif {{-- ══ Müşteri + Proje ══ --}}
{{ $partyLabel }}
{{ optional($c)->display_name ?? optional($c)->name ?? '—' }}
@foreach($custLines as $ln)
{{ $ln }}
@endforeach
Proje
{{ optional($p)->project_number ?? '—' }}@if($p && $hakedis->title) — {{ $hakedis->title }}@endif
@foreach($projLines as $ln)
{{ $ln }}
@endforeach
{{-- ══ Meta şerit ══ --}}
Hakediş No
{{ $hakedis->hakedis_no }}
Hakediş Tarihi
{{ $hakedis->hakedis_date?->format('d.m.Y') ?? '—' }}
Sipariş No
{{ optional($hakedis->siparis)->siparis_no ?: '—' }}
Durum
{{ $hakedis->statusLabel() }}
{{-- ══ Kalemler ══ --}}
Hakediş Kalemleri · {{ $hakedis->kalemler->count() }} kalem
@if($hakedis->kalemler->isEmpty())
Kalem bulunamadı.
@else
@foreach($groupedKalemler as $catSlug => $catItems) @php $k0 = $catItems->first(); $catName = $k0?->category_label ?? $k0?->serviceItem?->category_label ?? (\App\Models\ServiceItem::$categoryLabels[$catSlug] ?? 'Katalog Dışı'); $catTotal= (float) $catItems->sum('subtotal'); $catSinif = ($catSlug === '__other__' || !$catSlug) ? 'diger' : $catSlug; @endphp {{-- Kategori satırı EKRANDAKİ dille aynı: nötr şerit + kategori çipi. --}} @foreach($catItems as $k) @php $itemName = $k->item_name ?? $k->serviceItem?->name; $itemCode = $k->item_code ?? $k->serviceItem?->code; /* Açıklama sipariş kaleminde tutulur (hakediş kaleminde kolon yok). AYIRT EDİCİDİR: aynı kodun birden çok kalemi olabiliyor, ikisini yalnız açıklama ayırır. */ $itemDesc = $k->siparisKalem?->description; $lineNet = (float) $k->subtotal; $lineDisc = $k->lineDiscountAmount(); $discPct = ($k->grossLineTotal() > 0) ? ($lineDisc / $k->grossLineTotal() * 100) : 0; $kKdvOran = (float) ($k->kdv_rate ?? 0); @endphp @endforeach @endforeach
Kod Hizmet Adı Birim Miktar Birim Fiyat İskonto KDV Toplam
{{ $catName }} {{ $catItems->count() }} kalem {{ number_format($catTotal, 2, ',', '.') }} ₺
{{-- Kod SAYFA FONTUYLA ve kategori renginde (liste kuralı). --}} @if($itemCode){{ $itemCode }} @else — @endif {{ $itemName ?: 'Katalog dışı' }} @if($itemDesc)
{{ $itemDesc }}
@endif
{{ $k->unit ?: '—' }} {{ number_format((float)$k->quantity_done, 2, ',', '.') }} {{ number_format((float)$k->unit_price, 2, ',', '.') }} ₺ @if($lineDisc > 0.005) −{{ number_format($lineDisc, 2, ',', '.') }} ₺
%{{ rtrim(rtrim(number_format($discPct, 2, ',', '.'), '0'), ',') }}
@else — @endif
%{{ rtrim(rtrim(number_format($kKdvOran, 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 belgede 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, ',', '.') }} ₺
İskonto:−{{ 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:{{ number_format($kdvTutari, 2, ',', '.') }} ₺
GENEL TOPLAM (KDV Dahil):{{ number_format($genelToplam, 2, ',', '.') }} ₺
{{-- ══ Ödeme Planı (siparişten) — bölünmesin ══ --}} @if(($show['odeme'] ?? true) && optional($hakedis->siparis)->paymentPlanItems)
@include('muhasebe.partials.odeme-plani', ['items' => $hakedis->siparis->paymentPlanItems, 'note' => $hakedis->siparis->payment_plan_note, 'bank' => $hakedis->siparis->bank_account_info, 'pdf' => false])
@endif {{-- ══ Sorumluluklar (siparişten) — bölünmesin ══ --}} @if(($show['sorumluluk'] ?? true) && optional(optional($hakedis->siparis)->responsibilityItems)->isNotEmpty())
@include('muhasebe.partials.sorumluluklar', ['items' => $hakedis->siparis->responsibilityItems, 'pdf' => false])
@endif {{-- ══ Notlar (siparişin teklif notu) — bölünmesin ══ --}} @if($show['teklifnot'] ?? true)
@include('muhasebe.partials.teklif-notu', ['note' => optional($hakedis->siparis)->notes, 'pdf' => false])
@endif
Not: Bu hakediş, ilgili siparişin bu döneme ait tamamlanan iş kalemlerini kapsar. KDV dahil tutar üzerinden faturalandırılır.
{{ $firmaSettings['firma_adi'] }} · Düzenleyen: {{ optional($hakedis->creator)->kisa_ad ?? optional($hakedis->creator)->name ?? '—' }}@if($hakedis->approver) · Onaylayan: {{ $hakedis->approver->kisa_ad ?? $hakedis->approver->name }}@endif