@extends('print.layout') @section('title', 'PTC_' . ($ptc->stock_no ?? 'N/A') . '_' . ($ptc->stock_date ?? date('d-m-Y'))) @section('content')
Process Travel Card (PTC)
{{-- PTC Header Information --}}
PTC No: PTC-{{ $ptc->stock_no ?? 'N/A' }}
Date: {{ $ptc->stock_date ?? 'N/A' }}
Order: {{ $ptc->job_no ?? 'N/A' }}
Status: @if($ptc->stock_status == 6) In Progress @elseif($ptc->stock_status == 7) Completed @else Unknown @endif
Product: {{ $product->name ?? 'N/A' }} - {{ $product->size_name ?? 'N/A' }}
Quantity: {{ $ptc->description ?? 'N/A' }}
Current Stage: {{ $ptc->current_stage_name ?? 'Completed' }}
{{-- Issuances and Receivings Table --}} @if($movements && $movements->count() > 0)

Production Activities

@php $issuanceSeqMap = []; foreach($issuances as $idx => $iss) { $issuanceSeqMap[$iss->stock_id] = str_pad($idx + 1, 3, '0', STR_PAD_LEFT); } @endphp @foreach($movements as $index => $movement) @php if ($movement->is_ptc_master == 1) { $displayRef = 'PTC-' . $ptc->stock_no . ' / I001'; } elseif ($movement->stock_type == 2) { $issSeq = $issuanceSeqMap[$movement->stock_id] ?? $movement->stock_no; $displayRef = 'PTC-' . $ptc->stock_no . ' / I' . $issSeq; } else { $displayRef = 'PTC-' . $ptc->stock_no . ' / ' . $movement->stock_no; } // Calculate average quantity for issuances and receivings $avgQty = '-'; if (isset($movementItems[$movement->stock_id])) { $items = $movementItems[$movement->stock_id]; if ($items->isNotEmpty()) { if ($movement->stock_type == 1) { // Receiving transaction - show the quantity of products received $receivedQty = $items->where('material_id', 0)->min('quantity'); if ($receivedQty !== null) { $avgQty = $receivedQty; } } elseif ($movement->stock_type == 2 || $movement->is_ptc_master == 1) { // Issuance transaction - calculate theoretical product quantity // Check if materials or products were issued $hasMaterials = $items->where('material_id', '>', 0)->count() > 0; $hasProducts = $items->where('product_type_id', '>', 0)->where('material_id', 0)->count() > 0; if ($hasMaterials && !$hasProducts) { // Only materials issued - calculate theoretical product quantity $theoreticalQties = []; foreach ($items as $item) { if ($item->material_id > 0 && isset($productMaterials[$item->material_id])) { $materialReq = $productMaterials[$item->material_id]->quantity; if ($materialReq > 0) { $theoreticalQties[] = $item->quantity / $materialReq; } } } if (!empty($theoreticalQties)) { $avgQty = number_format(min($theoreticalQties), 2); } } elseif ($hasProducts) { // Products issued - show minimum quantity $minQty = $items->where('material_id', 0)->min('quantity'); if ($minQty !== null) { $avgQty = $minQty; } } } } } @endphp @endforeach
{{-- Summary Section --}}

Activity Summary

Total Activities: {{ $movements->count() }}
Issuances: {{ $movements->where('stock_type', 2)->count() + ($movements->where('is_ptc_master', 1)->count() > 0 ? 1 : 0) }}
Receivings: {{ $movements->where('stock_type', 1)->count() }}
@else
No Activities Recorded

No issuances or receivings have been recorded for this PTC yet.

@endif @endsection