@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') { if ($process->crsCuts->isNotEmpty()) { // If any 'recreatewidth' is present (non-null), use the first one $firstRecreateWidth = $process->crsCuts->first()->recreatewidth; if ($firstRecreateWidth !== null) { $displayWidth = $firstRecreateWidth; } else { // Sum all cut_widths when recreatewidth is null $displayWidth = $process->crsCuts->sum(function ($cut) { return (float) $cut->cut_width; }); } // dd($displayWidth, $process, $process->crsCuts); break; } } elseif ($process->process_type === 'crs' && $process->crsCuts->isEmpty()) { $displayWidth = $process->crsCuts->first()->cut_width ?? $displayWidth; //dd($displayWidth,$process,$process->crsCuts); break; } elseif ($process->process_type === 'ctl' && $process->ctlCuts->isNotEmpty()) { $displayWidth = $process->ctlCuts->first()->cut_width ?? $displayWidth; //dd($displayWidth,$process,$process->ctlCuts); break; } } @endphp {{ $status }} - Plan

{{ ucwords(str_replace('_', ' ', $plan->status ?? 'N/A')) }} Plan

@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 @elseif ($status === '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->isNotEmpty() && $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!
@if ($isCompleted || $isScrap || $status != 'Under Production') @else @endif {{ number_format($balanceWeight, 3) }}
@if ($isCompleted || $isScrap || $status != 'Under Production') @else @endif
@if ($isCompleted || $isScrap || $status != 'Under Production') @else @endif
@if ($packets > 0 && $qtyPerPacket > 0 && ($underProductionCut && $underProductionCut->prod_qty > 0)) @php $currentQty = $underProductionCut ? $underProductionCut->prod_qty : 0; $packedQty = $packets * $qtyPerPacket; $remainingQty = $currentQty - $packedQty; $idealNumPackets = $qtyPerPacket > 0 ? ceil($currentQty / $qtyPerPacket) : 0; $fullPacketsPossible = floor( $currentQty / $qtyPerPacket, ); $fullPackets = min($fullPacketsPossible, $packets); $remainingQtyWithinPackets = $currentQty - $fullPackets * $qtyPerPacket; $packetsUsed = $fullPackets + ($remainingQtyWithinPackets > 0 && $fullPackets < $packets ? 1 : 0); @endphp
    @if ($fullPackets > 0)
  • {{ $fullPackets }} packet{{ $fullPackets > 1 ? 's' : '' }} of {{ $qtyPerPacket }}
  • @endif @if ($remainingQtyWithinPackets > 0 && $fullPackets < $packets)
  • 1 packet of {{ $remainingQtyWithinPackets }}
  • @endif @if ($packets < $idealNumPackets)
  • Error: Number of packets ({{ $packets }}) is less than required ({{ $idealNumPackets }}) for {{ $currentQty }} qty
  • @elseif ($remainingQty > 0)
  • Remaining qty: {{ $remainingQty }}
  • Set packets to {{ $idealNumPackets }} for full qty
  • @elseif ($remainingQty <= 0 && $packetsUsed < $packets)
  • {{ $packets - $packetsUsed }} packet{{ $packets - $packetsUsed > 1 ? 's' : '' }} not used
  • Set packets to {{ $packetsUsed }} for full qty
  • @endif
@else - @endif
Total {{ number_format($process->ctlCuts->sum('weight'), 3) }}
@endif @endforeach @if ($status === 'Under Production')
@endif
@endsection