@php // Internal cost sheet: deliverables → sections → subtotals → build-up → final. // Modelled on the delivery-note PDF (branded header, rainbow rule, ribbon // footer) but this document is for the shop's eyes, so it shows every cost. $preview = $preview ?? false; $accent = $setting?->primary_color ?: '#2e86ab'; $accentSoft = '#eef3f8'; $zebra = '#f7fafc'; $ink = '#1f2937'; $muted = '#6b7280'; $line = '#d5dde5'; $brand = ['#2e86ab', '#a8192e', '#ffd23f', '#1b1b1b']; // Interpolated brand rainbow (dompdf renders solid fills more reliably than // CSS gradients), same treatment as the other documents. $rainbowStops = [[46, 134, 171], [168, 25, 46], [255, 210, 63], [27, 27, 27], [255, 210, 63], [168, 25, 46], [46, 134, 171]]; $rainbow = []; $segs = count($rainbowStops) - 1; $steps = 72; for ($i = 0; $i < $steps; $i++) { $p = $i / ($steps - 1) * $segs; $idx = (int) min($segs - 1, floor($p)); $t = $p - $idx; [$a, $b] = [$rainbowStops[$idx], $rainbowStops[$idx + 1]]; $rainbow[] = sprintf('#%02x%02x%02x', (int) round($a[0] + ($b[0] - $a[0]) * $t), (int) round($a[1] + ($b[1] - $a[1]) * $t), (int) round($a[2] + ($b[2] - $a[2]) * $t)); } $logoData = null; if ($setting?->logo_path) { try { if ($preview) { $logoData = \Illuminate\Support\Facades\Storage::disk('public')->url($setting->logo_path); } else { $logoFull = \Illuminate\Support\Facades\Storage::disk('public')->path($setting->logo_path); if (is_file($logoFull)) { $logoData = 'data:' . (mime_content_type($logoFull) ?: 'image/png') . ';base64,' . base64_encode(file_get_contents($logoFull)); } } } catch (\Throwable $e) { $logoData = null; } } $companyName = $setting?->company_name ?: $worksheet->team?->name; $money = fn ($value) => $symbol . number_format((float) $value, 2); $num = fn ($value) => rtrim(rtrim(number_format((float) $value, 2), '0'), '.'); $pct = fn ($value) => rtrim(rtrim(number_format((float) $value, 2), '0'), '.') . '%'; $job = $studio['job']; $deliverables = $studio['deliverables']; // Line description helper: turn measure/qty/unit into a compact sub-label. $measureLabel = function (array $l) use ($num): string { $qty = (float) ($l['qty'] ?? 1); return match ($l['measure'] ?? 'unit') { 'area' => $num($l['area'] ?? ((float) ($l['w'] ?? 0) * (float) ($l['h'] ?? 0))) . ' m²' . ($qty > 1 ? ' × ' . $num($qty) : ''), 'linear' => $num($l['length_m'] ?? 0) . ' m' . ($qty > 1 ? ' × ' . $num($qty) : ''), default => $num($qty) . ' ' . __('unit') . ($qty != 1 ? 's' : ''), }; }; $meta = [__('Cost Sheet #') => $worksheet->id ?: __('Draft')]; if ($worksheet->customer) { $meta[__('Customer')] = $worksheet->customer->name; } if ($worksheet->job) { $meta[__('Job #')] = $worksheet->job->job_number; } $meta[__('Date')] = ($worksheet->updated_at ?? $worksheet->created_at)?->format('d M Y'); @endphp {{ __('Cost Sheet') }}, {{ $worksheet->title }}
@if ($logoData) @endif
@if ($companyName)
{{ $companyName }}
@endif @if ($setting?->phone)
{{ __('Mobile') }}: {{ $setting->phone }}
@endif @if ($setting?->email)
{{ __('Email') }}: {{ $setting->email }}
@endif
{{ __('Cost Sheet') }}
{{ __('Internal, Cost Build-Up') }}
@foreach ($meta as $label => $value) @endforeach
{{ $label }} {{ $value }}
@foreach ($rainbow as $c)@endforeach
{{ $worksheet->title }}
@if ($worksheet->notes)
{{ $worksheet->notes }}
@endif
{{ __('Confidential, Internal Costing') }}
@foreach ($deliverables as $d)
{{ $d['title'] ?: __('Deliverable') }}
{{ __('Qty') }}: {{ $num($d['qty']) }} @if ($d['margin'] !== null)  •  {{ __('Margin') }}: {{ $pct($d['margin']) }} @endif
{{ $money($d['price']) }} {{ __('Deliverable Price') }}
@foreach ($d['sections'] as $section)
{{ $section['title'] }}
@forelse ($section['lines'] as $l) @empty @endforelse
{{ $l['description'] ?: ($l['material_name'] ?? __('Line')) }}
{{ $measureLabel($l) }} @ {{ $money($l['unit_cost'] ?? 0) }}
{{ \App\Models\JobCost::CATEGORIES[$l['category'] ?? 'other'] ?? ($l['category'] ?? '') }} {{ $money($l['amount']) }}
{{ __('No lines.') }}
{{ __('Section subtotal') }} {{ $money($section['subtotal']) }}
@endforeach
@if ($d['misc'] > 0 || $d['misc_pct'] > 0) @endif
{{ __('Production cost') }} {{ $money($d['cost']) }}
{{ __('Profit') }} ({{ $pct($d['profit_pct']) }}) + {{ $money($d['profit']) }}
{{ __('Misc / contingency') }} ({{ $pct($d['misc_pct']) }}) + {{ $money($d['misc']) }}
{{ __('Deliverable price') }} {{ $money($d['price']) }}
@endforeach
{{ __('Job Total') }}
@if ($job['misc'] > 0) @endif @if ($job['additions'] != 0) @endif @if ($job['margin'] !== null) @endif
{{ __('Total production cost') }} {{ $money($job['cost']) }}
{{ __('Total profit') }} {{ $money($job['profit']) }}
{{ __('Total misc') }} {{ $money($job['misc']) }}
{{ __('Additions') }} {{ $money($job['additions']) }}
{{ __('Overall margin') }} {{ $pct($job['margin']) }}
{{ __('Final Price') }} {{ $money($job['price']) }}
{{ __('This cost sheet is an internal build-up and is not a customer quotation. Figures in :cur.', ['cur' => $symbol]) }}
@foreach ($brand as $c)@endforeach