{{-- SİPARİŞ BELGESİ — ortak kabuğunu kullanır; sadece sipariş İÇERİĞİNİ verir. Kabuk (kafa/CSS/araç çubuğu/sayfalama/print) components/belge.blade.php'de. Değişkenler: $siparis, $firmaSettings, $logoSrc, $yon, $margin, $show[logo|odeme|sorumluluk|teklifnot], $autoPrint --}} @php $araToplamHaric = (float) $siparis->kalemler->sum('total_price'); $kdvTutari = 0.0; foreach ($siparis->kalemler as $kk) { $siK = $kk->serviceItem ?? $kk->proposalItem?->serviceItem; $rate = (float) ($kk->kdv_rate ?? $siK?->kdv_rate ?? 0); $kdvTutari += (float) $kk->total_price * $rate / 100; } $genelToplam = $araToplamHaric + $kdvTutari; /* KDV HER ORAN AYRI — oran kalemden (siparis_kalemleri.kdv_rate). */ $kdvKirilim = []; foreach ($siparis->kalemler as $kk) { $siK = $kk->serviceItem ?? $kk->proposalItem?->serviceItem; $oran = (float) ($kk->kdv_rate ?? $siK?->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->total_price; $kdvKirilim[$ah]['kdv'] += (float) $kk->total_price * $oran / 100; } $kdvKirilim = array_values(array_filter($kdvKirilim, fn ($x) => $x['kdv'] > 0.004)); usort($kdvKirilim, fn ($x, $z) => $z['oran'] <=> $x['oran']); $brutToplam = (float) $siparis->kalemler->sum(fn($kk) => (float) $kk->quantity * (float) $kk->unit_price); $siparisIskonto = max(0, round($brutToplam - $araToplamHaric, 2)); $hasGlobalDisc = $siparisIskonto > 0.005; $groupedKalemler = \App\Models\ServiceItem::sortGroupedByCategory( $siparis->kalemler->groupBy(function($kk){ $siK = $kk->serviceItem ?? $kk->proposalItem?->serviceItem; return $kk->category ?? $siK?->category ?? '__other__'; }) ); $c = $siparis->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 = $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, ])); @endphp @php // Belge adı = "Kod - Proje Adı - Tip" (PDF dosya adı + araç çubuğu). Proje adı yoksa "Kod - Tip". $__belgeProj = $siparis->title; $belgeBaslik = $siparis->siparis_no . ($__belgeProj ? '-' . $__belgeProj : '') . '-Sipariş'; @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
SİPARİŞ
Hizmet Sipariş Formu
{{ $siparis->siparis_no }}
@endif {{-- ══ Müşteri + Proje ══ --}}
{{ $siparis->isTedarikci() ? 'Tedarikçi' : 'Müşteri' }}
{{ optional($c)->display_name ?? '—' }}
@foreach($custLines as $ln)
{{ $ln }}
@endforeach
Proje
{{ optional($p)->project_number ?? '—' }}@if($p && $p->title) — {{ $p->title }}@endif
@foreach($projLines as $ln)
{{ $ln }}
@endforeach
{{-- ══ Meta şerit ══ --}}
Sipariş No
{{ $siparis->siparis_no }}
Sipariş Tarihi
{{ $siparis->order_date?->format('d.m.Y') ?? '—' }}
Teklif Dosya No
{{ $p?->offer_file_no ?: '—' }}
Durum
{{ $siparis->statusLabel() }}
{{-- ══ Kalemler ══ --}}
Sipariş Kalemleri · {{ $siparis->kalemler->count() }} kalem
@if($siparis->kalemler->isEmpty())
Kalem bulunamadı.
@else
@foreach($groupedKalemler as $catSlug => $catItems) @php $si0 = $catItems->first(); $catName = $si0?->category_label ?? (\App\Models\ServiceItem::$categoryLabels[$catSlug] ?? 'Katalog Dışı'); $catTotal= (float) $catItems->sum('total_price'); $catSinif = ($catSlug === '__other__' || !$catSlug) ? 'diger' : $catSlug; @endphp {{-- Kategori satırı EKRANDAKİ dille aynı: tonlu satır zemini ve renkli çubuk yerine NÖTR şerit + rengi taşıyan kategori çipi. Belge kabuğu ks-tema.css ve yüklüyor, yani `.ks-kat-cip` burada da çalışıyor. --}} @foreach($catItems as $k) @php $si = $k->serviceItem ?? $k->proposalItem?->serviceItem; $itemName = $k->item_name ?? $si?->name; $itemCode = $k->item_code ?? $si?->code; $kIsIptal = $k->isIptal(); $lineGross= (float) $k->quantity * (float) $k->unit_price; $lineNet = (float) $k->total_price; $lineDisc = max(0, $lineGross - $lineNet); $kKdvOran = (float) ($k->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 — ekrandaki `.ks-svc-code` ile aynı (liste kuralı: monospace DEĞİL). --}} @if($itemCode){{ $itemCode }} @else — @endif {{ $itemName ?: 'Katalog dışı' }} @if($kIsIptal)İptal@endif @if($k->description)
{{ $k->description }}
@endif
{{ $k->unit ?: '—' }} {{ number_format((float)$k->quantity, 2, ',', '.') }} {{ number_format((float)$k->unit_price, 2, ',', '.') }} ₺ @if($lineDisc > 0.005) −{{ number_format($lineDisc, 2, ',', '.') }} ₺
%{{ rtrim(rtrim(number_format($k->discountPercent(), 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ı (+ not & banka AYNI KART) — bölünmesin ══ --}} @if($show['odeme'] ?? true)
@include('muhasebe.partials.odeme-plani', ['items' => $siparis->paymentPlanItems, 'note' => $siparis->payment_plan_note, 'bank' => $siparis->bank_account_info, 'pdf' => false])
@endif {{-- ══ Sorumluluklar — bölünmesin ══ --}} @if(($show['sorumluluk'] ?? true) && $siparis->responsibilityItems->isNotEmpty())
@include('muhasebe.partials.sorumluluklar', ['items' => $siparis->responsibilityItems, 'pdf' => false])
@endif {{-- ══ Notlar (Teklif Notu) — bölünmesin ══ --}} @if($show['teklifnot'] ?? true)
@include('muhasebe.partials.teklif-notu', ['note' => $siparis->notes, 'pdf' => false])
@endif
Not: Sipariş tutarı KDV hariçtir. Hakediş kesildikçe bu tutardan düşülür; KDV faturalaşma aşamasında işlenir.
{{ $firmaSettings['firma_adi'] }} · Düzenleyen: {{ optional($siparis->creator)->kisa_ad ?? optional($siparis->creator)->name ?? '—' }}