@extends('layouts.supervisor') @section('title', 'Detail Produksi - Supervisor') @section('content') @php $orderQty = $production->quantity ?? $production->order->quantity ?? 1; $materialTotal = $production->total_material_cost ?? 0; $sparepartTotal = $production->total_sparepart_cost ?? 0; $directTotal = $materialTotal + $sparepartTotal; $laborTotal = $production->labor_cost ?? 0; $actualTotal = $directTotal + $laborTotal; $totalCost = $actualTotal; @endphp
@php $backRoute = $production->planning_status === 'pending_approval' ? route('supervisor.productions.planning') : ($production->completion_status === 'pending_approval' ? route('supervisor.productions.completion') : route('supervisor.productions.planning')); @endphp

Detail Produksi #{{ $production->id }}

Order #{{ $production->order->id ?? 'N/A' }} · {{ $production->order->customer_name ?? 'N/A' }}

@if(session('success'))
{{ session('success') }}
@endif @if(session('info'))
{{ session('info') }}
@endif @if($errors->any())
@endif

Info Produksi

Qty: {{ $orderQty }} unit
Teknisi: {{ $production->teknisi->name ?? 'Belum ditugaskan' }}
Status: @php $statusConfig = [ 'menunggu' => ['bg' => 'bg-gray-100 dark:bg-gray-700/50', 'text' => 'text-gray-700 dark:text-gray-300', 'label' => 'Menunggu'], 'dalam_proses' => ['bg' => 'bg-yellow-100 dark:bg-yellow-900/40', 'text' => 'text-yellow-700 dark:text-yellow-300', 'label' => 'Dalam Proses'], 'selesai' => ['bg' => 'bg-green-100 dark:bg-green-900/40', 'text' => 'text-green-700 dark:text-green-300', 'label' => 'Selesai'], 'dibatalkan' => ['bg' => 'bg-red-100 dark:bg-red-900/40', 'text' => 'text-red-700 dark:text-red-300', 'label' => 'Dibatalkan'], ]; $status = $statusConfig[$production->status] ?? $statusConfig['menunggu']; @endphp {{ $status['label'] }}

Info Pesanan

Order ID: #{{ $production->order->id ?? 'N/A' }}
Produk: {{ Str::limit($production->product->product_title ?? 'N/A', 15) }}
Harga: Rp {{ number_format($production->order->price ?? 0, 0, ',', '.') }}

Ringkasan

Bahan: {{ $production->productionMaterials->count() }} item
Sparepart: {{ $production->productionSpareparts->count() }} item
Total: Rp {{ number_format($totalCost, 0, ',', '.') }}

Pembayaran

Metode: {{ strtoupper($production->order->payment_method ?? 'N/A') }}
@if($production->submitted_at)
Diajukan: {{ $production->submitted_at->format('d/m/Y') }}
@endif
@include('supervisor.productions.partials.timeline', ['production' => $production]) {{-- ============================================== --}} {{-- REQUEST ITEM DARI TEKNISI - URGENT NOTIFICATION --}} {{-- ============================================== --}} @php $itemRequests = $production->itemRequests ?? collect(); $pendingRequests = $itemRequests->where('status', 'pending'); @endphp @if($pendingRequests->count() > 0)

Request Item Menunggu Persetujuan

{{ $pendingRequests->count() }} request baru dari teknisi perlu ditinjau

{{ $pendingRequests->count() }} Pending
@foreach($pendingRequests as $request) @php $quantity = (int)$request->quantity; // Ambil harga: prioritas dari relasi material/sparepart, jika tidak ada cari di master berdasarkan nama, terakhir pakai estimated_price $estimatedPrice = 0; if ($request->item_type === 'material' && $request->material) { $estimatedPrice = $request->material->price ?? $request->estimated_price ?? 0; } elseif ($request->item_type === 'sparepart' && $request->sparepart) { $estimatedPrice = $request->sparepart->price ?? $request->estimated_price ?? 0; } else { // Item baru: coba cari di master barang berdasarkan nama if ($request->item_name) { if ($request->item_type === 'material') { // Coba exact match dulu $foundMaterial = \App\Models\Material::where('name', $request->item_name)->first(); // Jika tidak ada, coba partial match if (!$foundMaterial) { $foundMaterial = \App\Models\Material::where('name', 'LIKE', '%' . trim($request->item_name) . '%')->first(); } if ($foundMaterial) { $estimatedPrice = $foundMaterial->price ?? $request->estimated_price ?? 0; } else { $estimatedPrice = $request->estimated_price ?? 0; } } else { // Coba exact match dulu $foundSparepart = \App\Models\Sparepart::where('name', $request->item_name)->first(); // Jika tidak ada, coba partial match if (!$foundSparepart) { $foundSparepart = \App\Models\Sparepart::where('name', 'LIKE', '%' . trim($request->item_name) . '%')->first(); } if ($foundSparepart) { $estimatedPrice = $foundSparepart->price ?? $request->estimated_price ?? 0; } else { $estimatedPrice = $request->estimated_price ?? 0; } } } else { $estimatedPrice = $request->estimated_price ?? 0; } } $totalPrice = $quantity * $estimatedPrice; // Ambil stok terbaru dari database (fresh) $currentStock = 0; if ($request->item_type === 'material' && $request->material_id) { $material = \App\Models\Material::find($request->material_id); $currentStock = $material ? $material->stock : 0; } elseif ($request->item_type === 'sparepart' && $request->sparepart_id) { $sparepart = \App\Models\Sparepart::find($request->sparepart_id); $currentStock = $sparepart ? $sparepart->stock : 0; } $totalNeeded = $quantity * $orderQty; $stockStatus = 'available'; $stockStatusLabel = 'Tersedia'; $stockStatusClass = 'bg-green-100 dark:bg-green-900/40 text-green-700 dark:text-green-300'; $stockStatusIcon = 'check-circle'; if ($currentStock < $totalNeeded) { if ($currentStock == 0) { $stockStatus = 'pending_purchase'; $stockStatusLabel = 'Perlu Pembelian'; $stockStatusClass = 'bg-red-100 dark:bg-red-900/40 text-red-700 dark:text-red-300'; $stockStatusIcon = 'times-circle'; } else { $stockStatus = 'insufficient'; $stockStatusLabel = 'Perlu Pembelian (Kurang)'; $stockStatusClass = 'bg-amber-100 dark:bg-amber-900/40 text-amber-700 dark:text-amber-300'; $stockStatusIcon = 'exclamation-triangle'; } } @endphp @endforeach
Item Tipe Jumlah Satuan Harga/Unit Total Stok Status Ketersediaan Alasan Diminta Oleh
{{ $request->item_name_display }}
@if($request->is_new_item) Item Baru @endif
@if($request->item_type === 'material') Bahan @else Sparepart @endif {{ $quantity }} {{ $request->unit }} @if($estimatedPrice > 0) Rp {{ number_format($estimatedPrice, 0, ',', '.') }} @else - @endif @if($totalPrice > 0) Rp {{ number_format($totalPrice, 0, ',', '.') }} @else - @endif
{{ $currentStock }} Butuh: {{ $totalNeeded }}
{{ $stockStatusLabel }} @if($stockStatus !== 'available')
@if($stockStatus === 'insufficient') Kurang: {{ $totalNeeded - $currentStock }} {{ $request->unit }} @else Stok: 0 @endif
@endif
{{ Str::limit($request->reason, 50) }}
{{ $request->requester->name ?? 'N/A' }}
{{ $request->created_at->format('d/m/Y H:i') }}
@endif {{-- ============================================== --}} {{-- TABEL USULAN PERTAMA, KEDUA, KETIGA (SUPERVISOR) --}} {{-- ============================================== --}} @php $itemRequests = $production->itemRequests ?? collect(); $proposalGroups = $itemRequests->groupBy('proposal_number')->sortKeys(); @endphp @if($proposalGroups->count() > 0)

Usulan Bahan & Sparepart

Dikelompokkan berdasarkan usulan pertama, kedua, ketiga @if($pendingRequests->count() > 0) · Item pending juga ada di notifikasi di atas @endif

@if($itemRequests->count() > 0)
Total: {{ $itemRequests->count() }} item
@endif
@foreach($proposalGroups as $proposalNumber => $requests)

{{ $proposalNumber ?? '1' }} Usulan {{ $proposalNumber == 1 ? 'Pertama' : ($proposalNumber == 2 ? 'Kedua' : ($proposalNumber == 3 ? 'Ketiga' : 'Ke-' . $proposalNumber)) }} {{ $requests->count() }} item

@foreach($requests as $request) @php $quantity = (int)$request->quantity; // Ambil harga: prioritas dari relasi material/sparepart, jika tidak ada cari di master berdasarkan nama, terakhir pakai estimated_price $estimatedPrice = 0; if ($request->item_type === 'material' && $request->material) { $estimatedPrice = $request->material->price ?? $request->estimated_price ?? 0; } elseif ($request->item_type === 'sparepart' && $request->sparepart) { $estimatedPrice = $request->sparepart->price ?? $request->estimated_price ?? 0; } else { // Item baru: coba cari di master barang berdasarkan nama if ($request->item_name) { if ($request->item_type === 'material') { $foundMaterial = \App\Models\Material::where('name', 'LIKE', '%' . $request->item_name . '%')->first(); if ($foundMaterial) { $estimatedPrice = $foundMaterial->price ?? $request->estimated_price ?? 0; } else { $estimatedPrice = $request->estimated_price ?? 0; } } else { $foundSparepart = \App\Models\Sparepart::where('name', 'LIKE', '%' . $request->item_name . '%')->first(); if ($foundSparepart) { $estimatedPrice = $foundSparepart->price ?? $request->estimated_price ?? 0; } else { $estimatedPrice = $request->estimated_price ?? 0; } } } else { $estimatedPrice = $request->estimated_price ?? 0; } } $totalPrice = $quantity * $estimatedPrice; // Ambil stok terbaru dari database (fresh) $currentStock = 0; if ($request->item_type === 'material' && $request->material_id) { $material = \App\Models\Material::find($request->material_id); $currentStock = $material ? $material->stock : 0; } elseif ($request->item_type === 'sparepart' && $request->sparepart_id) { $sparepart = \App\Models\Sparepart::find($request->sparepart_id); $currentStock = $sparepart ? $sparepart->stock : 0; } $totalNeeded = $quantity * $orderQty; $stockStatus = 'available'; $stockStatusLabel = 'Tersedia'; $stockStatusClass = 'bg-green-100 dark:bg-green-900/40 text-green-700 dark:text-green-300'; $stockStatusIcon = 'check-circle'; if ($currentStock < $totalNeeded) { if ($currentStock == 0) { $stockStatus = 'pending_purchase'; $stockStatusLabel = 'Perlu Pembelian'; $stockStatusClass = 'bg-red-100 dark:bg-red-900/40 text-red-700 dark:text-red-300'; $stockStatusIcon = 'times-circle'; } else { $stockStatus = 'insufficient'; $stockStatusLabel = 'Perlu Pembelian (Kurang)'; $stockStatusClass = 'bg-amber-100 dark:bg-amber-900/40 text-amber-700 dark:text-amber-300'; $stockStatusIcon = 'exclamation-triangle'; } } @endphp @endforeach
Item Tipe Jumlah Satuan Harga/Unit Total Stok Status Ketersediaan Alasan Status Tanggal Aksi
{{ $request->item_name_display }} @if($request->status === 'pending') Pending @endif
@if($request->is_new_item) Item Baru @endif
@if($request->item_type === 'material') Bahan @else Sparepart @endif {{ $quantity }} {{ $request->unit }} @if($estimatedPrice > 0) Rp {{ number_format($estimatedPrice, 0, ',', '.') }} @else - @endif @if($totalPrice > 0) Rp {{ number_format($totalPrice, 0, ',', '.') }} @else - @endif
{{ $currentStock }} Butuh: {{ $totalNeeded }}
{{ $stockStatusLabel }} @if($stockStatus !== 'available')
@if($stockStatus === 'insufficient') Kurang: {{ $totalNeeded - $currentStock }} {{ $request->unit }} @else Stok: 0 @endif
@endif
{{ Str::limit($request->reason, 50) }} @if($request->status === 'pending') @elseif($request->status === 'approved') @elseif($request->status === 'rejected') @elseif($request->status === 'purchased') @elseif($request->status === 'sent') @elseif($request->status === 'received') @endif {{ $request->status_label }} {{ $request->requested_at->format('d/m/Y H:i') }} @if($request->status === 'pending') Menunggu Admin @elseif($request->status === 'approved' && !$request->purchase_id) Menunggu Pembelian @elseif($request->status === 'purchased' && $request->purchase_id) Menunggu Pengiriman @elseif($request->status === 'sent') Dikirim ke Teknisi @elseif($request->status === 'received') Sudah Diterima @elseif($request->status === 'rejected') Ditolak @else - @endif
@endforeach
@endif

Daftar Bahan & Sparepart

{{ $production->productionMaterials->count() + $production->productionSpareparts->count() }} item · {{ $orderQty }} unit produk

@php $allItems = collect(); foreach($production->productionMaterials as $pm) { // Untuk item request yang sudah diterima (is_additional = true dan is_received = true) // Stok di master barang sudah dikurangi saat admin kirim, jadi stok yang ditampilkan // adalah stok yang "tersedia untuk produksi" (quantity yang sudah diterima) $currentStock = $pm->material->stock ?? 0; if ($pm->is_additional && $pm->is_received) { $currentStock = $pm->quantity * $orderQty; } $allItems->push([ 'type' => 'material', 'name' => $pm->material->name ?? 'N/A', 'quantity' => $pm->quantity, 'unit' => $pm->unit, 'unit_cost' => $pm->unit_cost, 'total_cost' => $pm->total_cost, 'stock' => $currentStock, 'is_additional' => $pm->is_additional ?? false, 'is_received' => $pm->is_received ?? false, ]); } foreach($production->productionSpareparts as $ps) { // Untuk item request yang sudah diterima (is_additional = true dan is_received = true) // Stok di master barang sudah dikurangi saat admin kirim, jadi stok yang ditampilkan // adalah stok yang "tersedia untuk produksi" (quantity yang sudah diterima) $currentStock = $ps->sparepart->stock ?? 0; if ($ps->is_additional && $ps->is_received) { $currentStock = $ps->quantity * $orderQty; } $allItems->push([ 'type' => 'sparepart', 'name' => $ps->sparepart->name ?? 'N/A', 'quantity' => $ps->quantity, 'unit' => $ps->unit, 'unit_cost' => $ps->unit_cost, 'total_cost' => $ps->total_cost, 'stock' => $currentStock, 'is_additional' => $ps->is_additional ?? false, 'is_received' => $ps->is_received ?? false, ]); } @endphp @if($allItems->count() > 0)
@foreach($allItems as $item) @endforeach
Nama Item Tipe Jumlah Satuan Harga/Unit Total Stok
{{ $item['name'] }} @if($item['type'] === 'material') Bahan @else Sparepart @endif {{ $item['quantity'] }} {{ $item['unit'] }} Rp {{ number_format($item['unit_cost'], 0, ',', '.') }} Rp {{ number_format($item['total_cost'], 0, ',', '.') }} @if(isset($item['is_additional']) && $item['is_additional'] && isset($item['is_received']) && $item['is_received']) {{ $item['stock'] }} @elseif($item['stock'] >= $item['quantity'] * $orderQty) {{ $item['stock'] }} @else {{ $item['stock'] }} @endif
Bahan: Rp {{ number_format($materialTotal, 0, ',', '.') }} Sparepart: Rp {{ number_format($sparepartTotal, 0, ',', '.') }}
Total: Rp {{ number_format($directTotal, 0, ',', '.') }}
@else

Belum ada bahan atau sparepart ditambahkan

@endif
@if($laborTotal > 0)

Biaya Tenaga Kerja (Labor)

Upah untuk {{ $orderQty }} unit produk

Rp {{ number_format($laborTotal, 0, ',', '.') }}

Per unit: Rp {{ number_format($laborTotal / max($orderQty, 1), 0, ',', '.') }}

@endif

Total Biaya Produksi

Rp {{ number_format($actualTotal, 0, ',', '.') }}

Langsung: Rp {{ number_format($directTotal, 0, ',', '.') }} Labor: Rp {{ number_format($laborTotal, 0, ',', '.') }}

Per Unit

Rp {{ number_format($actualTotal / max($orderQty, 1), 0, ',', '.') }}

@if($production->notes)

Catatan dari Teknisi

{{ $production->notes }}

@endif
@if($production->planning_status === 'pending_approval')
@elseif($production->completion_status === 'pending_approval')
@else @if($production->planning_status === 'approved') Planning sudah disetujui @elseif($production->status === 'selesai') Produksi sudah selesai @else Tidak ada aksi yang diperlukan @endif @endif
@endsection