@extends('layouts.structure') @section('title', 'Classic Roof Pvt Ltd') @section('content') @php // Map plan status to display-friendly text $status = match (strtolower($plan->status ?? 'N/A')) { 'pending' => 'Pending', 'approved' => 'Approved', 'under production' => 'Under Production', 'completed' => 'Completed', 'ready to dispatch' => 'Ready to Dispatch', 'partially dispatched' => 'Partially Dispatched', 'dispatched' => 'Dispatched', default => 'N/A', }; // Convert session error to string $sessionError = session('error') ? (is_array(session('error')) ? implode(', ', array_map('strval', session('error'))) : session('error')) : ''; // Convert session success to string $sessionSuccess = session('success') ? (is_array(session('success')) ? implode(', ', array_map('strval', session('success'))) : session('success')) : ''; // Calculate sheets per packet for CTL $thickness = $plan->coil->thickness ?? 0.5; $maxHeightPerPacket = 400; $sheetsPerPacket = $thickness > 0 ? floor($maxHeightPerPacket / $thickness) : 1; // Log plan details for debugging \Log::info('Plan variables for rendering', [ 'plan_id' => $plan->id ?? 'N/A', 'status' => $status, 'client_name' => $plan->client->client_name ?? 'N/A', 'crr_no' => $plan->coil->crr_no ?? 'N/A', 'grade_name' => $plan->grade->grade_name ?? 'N/A', 'inward_code' => $plan->inward->inward_code ?? 'N/A', 'thickness' => $plan->coil->thickness ?? 'N/A', 'coil_width' => $plan->coil->width ?? 'N/A', 'coil_net_weight' => $plan->coil->net_weight ?? 0, 'crs_bal_weight' => $plan->crs_bal_weight ?? 0, 'ctl_bal_weight' => $plan->ctl_bal_weight ?? 0, 'under_production_cuts_count' => $plan->underProductionCuts->count(), ]); // width for recreated plans $displayWidth = $plan->coil->width ?? 0; foreach ($plan->processes as $process) { if ($process->process_type === 'crs' && $process->crsCuts->isNotEmpty()) { $displayWidth = $process->crsCuts->first()->cut_width ?? $displayWidth; break; } elseif ($process->process_type === 'ctl' && $process->ctlCuts->isNotEmpty()) { $displayWidth = $process->ctlCuts->first()->cut_width ?? $displayWidth; break; } } @endphp Metal Coil Processing - Under Production

Metal Coil Processing - Under Production

@if ($sessionError) @endif @if ($sessionSuccess) @endif
@if ($status === 'Pending') Approve Plan @elseif ($status === 'Approved') Start Production @elseif ($status === 'Under Production') Mark as Completed @elseif ($status === 'Completed') Ready to Dispatch @elseif ($status === 'Ready to Dispatch') Mark as Partially Dispatched @elseif ($status === 'Partially Dispatched') Mark as Dispatched @endif @if($status==="Approved") Download Excel @endif Back to Plans
@csrf @method('POST')

Plan Details

@foreach ($plan->processes as $process) @if ($process->process_type === 'crs')

CRS – Cut to Width

CRS Process Details:
- Process Type: CRS
Bal. Weight: {{ number_format($process->crsCuts->sum('crs_bal_weight') ?? 0, 3) }} TON
@foreach ($process->crsCuts as $index => $cut) @php // Find matching under_production_cuts record $underProductionCut = null; foreach ($plan->underProductionCuts ?? [] as $item) { if ( $item->cut_id == $cut->crs_cut_id && $item->cut_type == 'crs' ) { $underProductionCut = $item; break; } } $isScrap = \App\Models\Scrap::where('plan_id', $plan->id) ->where('process_id', $process->process_id) ->where('process_type', 'crs') ->where('cut_id', $cut->crs_cut_id) ->exists(); $isCompleted = ($underProductionCut ? $underProductionCut->prod_qty : 0) >= $cut->quantity; // Use UnderProductionCut.bal_weight if available, else PlanCrsCut.crs_bal_weight $balanceWeight = $isScrap ? 0 : ($underProductionCut ? $underProductionCut->bal_weight : $cut->crs_bal_weight); $grossWeight = $underProductionCut ? $underProductionCut->gross_weight ?? 0 : 0; @endphp @endforeach
Cut Width (mm) Qty Prod. Weight (TON) Current Qty Current Weight (TON) Bal. Weight (TON) Gross Weight (TON) Declare Balance Weight As
{{ number_format($cut->cut_width, 2) }} {{ $cut->quantity }} {{ number_format($cut->weight, 3) }} @if ($isCompleted || $isScrap || $status != 'Under Production') @else @endif
Completed!
{{ number_format($underProductionCut ? $underProductionCut->prod_weight : 0, 3) }} {{ number_format($balanceWeight, 3) }} @if ($isCompleted || $isScrap || $status != 'Under Production') @else @endif
Total {{ number_format($process->crsCuts->sum('weight'), 3) }}
@elseif ($process->process_type === 'ctl')

CTL – Cut to Length @if ($process->ctlCuts->first()->dependent_index > 0) (Dependent) @endif

CTL Process Details:
- Process Type: CTL @if ($process->ctlCuts->first()->dependent_index > 0) (Dependent on Process {{ $process->ctlCuts->first()->dependent_index ?? 'N/A' }}) @endif
Bal. Weight: {{ number_format($process->ctlCuts->sum('ctl_bal_weight') ?? 0, 3) }} TON
@foreach ($process->ctlCuts as $index => $cut) @php // Find matching under_production_cuts record $underProductionCut = null; foreach ($plan->underProductionCuts ?? [] as $item) { if ( $item->cut_id == $cut->ctl_cut_id && $item->cut_type == 'ctl' ) { $underProductionCut = $item; break; } } $isScrap = \App\Models\Scrap::where('plan_id', $plan->id) ->where('process_id', $process->process_id) ->where('process_type', 'ctl') ->where('cut_id', $cut->ctl_cut_id) ->exists(); $isCompleted = ($underProductionCut ? $underProductionCut->prod_qty : 0) >= $cut->quantity; // Use UnderProductionCut.bal_weight if available, else PlanCtlCut.ctl_bal_weight $balanceWeight = $isScrap ? 0 : ($underProductionCut ? $underProductionCut->bal_weight : $cut->ctl_bal_weight); $packets = $underProductionCut ? $underProductionCut->packets ?? 0 : 0; $qtyPerPacket = $underProductionCut ? $underProductionCut->qty_per_packet ?? 0 : 0; @endphp @endforeach
Dep. Cut (mm) Length (mm) Qty Prod. Weight (TON) Current Qty Current Weight (TON) Bal. Weight (TON) Declare Balance Weight As Packets Quantity per Packet Packet Details
{{ number_format($cut->cut_width, 2) }} {{ number_format($cut->cut_length, 2) }} {{ $cut->quantity }} {{ number_format($cut->weight, 3) }} @if ($isCompleted || $isScrap || $status != 'Under Production') @else @endif
Completed!
{{ number_format($underProductionCut ? $underProductionCut->prod_weight : 0, 3) }} {{ number_format($balanceWeight, 3) }}
@if ($isCompleted || $isScrap || $status != 'Under Production') @else @endif
@if ($isCompleted || $isScrap || $status != 'Under Production') @else @endif
{{ $packets }} Packets of {{ $qtyPerPacket }}
Total {{ number_format($process->ctlCuts->sum('weight'), 3) }}
@endif @endforeach @if ($status === 'Under Production')
@endif
@endsection