@section('page-title', 'Edit Final Planning') @php $asianPorts = $asianPorts ?? \App\Models\FinalPlanning::getAsianPorts(); $allPorts = collect($asianPorts)->flatten()->toArray(); $oldOrigin = old('port_origin', $planning->port_origin ?? ''); $oldDestination = old('port_destination', $planning->port_destination ?? ''); $selectedOrigin = in_array($oldOrigin, $allPorts) ? $oldOrigin : ($oldOrigin ? 'OTHER' : ''); $customOrigin = !in_array($oldOrigin, $allPorts) && $oldOrigin ? $oldOrigin : old('port_origin_custom', ''); $selectedDestination = in_array($oldDestination, $allPorts) ? $oldDestination : ($oldDestination ? 'OTHER' : ''); $customDestination = !in_array($oldDestination, $allPorts) && $oldDestination ? $oldDestination : old('port_destination_custom', ''); $existingCargoList = []; $rawCargoInput = old('cargo_data'); if (is_array($rawCargoInput)) { foreach ($rawCargoInput as $r) { $existingCargoList[] = [ 'cargo' => $r['cargo'] ?? ($r['cargo_name'] ?? ($r['name'] ?? '')), 'cargo_type' => $r['cargo_type'] ?? ($r['type'] ?? ''), 'discharging' => $r['discharging'] ?? 0, 'unit' => $r['unit'] ?? 'UNITS', 'stevedoring' => $r['stevedoring'] ?? '', 'cargodoring' => $r['cargodoring'] ?? '', 'consignee' => $r['consignee'] ?? ($r['nominative_owner'] ?? ''), ]; } } elseif ($planning->consignees && $planning->consignees->isNotEmpty()) { foreach ($planning->consignees as $c) { if ($c->items && $c->items->isNotEmpty()) { foreach ($c->items as $cItem) { $dVal = (int)($cItem->discharging ?? 0); $lVal = (int)($cItem->loading ?? 0); $cName = trim((string)($cItem->cargo ?? '')); if ($dVal > 0 || ($lVal === 0 && $dVal === 0 && $cName !== '' && $cName !== 'General Cargo' && $c->consignee !== '-')) { $existingCargoList[] = [ 'cargo' => $cItem->cargo ?: '', 'cargo_type' => $cItem->cargo_type ?: '', 'discharging' => $dVal, 'unit' => $cItem->unit ?: 'UNITS', 'stevedoring' => ($cItem->stevedoring !== '-' && $cItem->stevedoring !== '0') ? $cItem->stevedoring : '', 'cargodoring' => ($cItem->cargodoring !== '-' && $cItem->cargodoring !== '0') ? $cItem->cargodoring : '', 'consignee' => ($c->consignee !== '-') ? $c->consignee : '', ]; } } } else { $existingCargoList[] = [ 'cargo' => '', 'cargo_type' => '', 'discharging' => 0, 'unit' => 'UNITS', 'stevedoring' => '', 'cargodoring' => '', 'consignee' => ($c->consignee !== '-') ? $c->consignee : '', ]; } } } elseif (!empty($planning->cargo_estimasi) || !empty($planning->estimasi_unit)) { $existingCargoList[] = [ 'cargo' => $planning->cargo_estimasi ?: 'General Cargo', 'cargo_type' => '', 'discharging' => (int) ($planning->estimasi_unit ?: 0), 'unit' => 'UNITS', 'stevedoring' => 'APS', 'cargodoring' => 'APS', 'consignee' => '', ]; } $existingLoadingCargoList = []; $rawLoadingCargoInput = old('cargo_loading_data'); if (is_array($rawLoadingCargoInput)) { foreach ($rawLoadingCargoInput as $r) { $existingLoadingCargoList[] = [ 'cargo' => $r['cargo'] ?? ($r['cargo_name'] ?? ($r['name'] ?? '')), 'cargo_type' => $r['cargo_type'] ?? ($r['type'] ?? ''), 'loading' => $r['loading'] ?? ($r['discharging'] ?? 0), 'unit' => $r['unit'] ?? 'UNITS', 'stevedoring' => $r['stevedoring'] ?? '', 'cargodoring' => $r['cargodoring'] ?? '', 'consignee' => $r['consignee'] ?? ($r['nominative_owner'] ?? ''), ]; } } elseif ($planning->consignees && $planning->consignees->isNotEmpty()) { foreach ($planning->consignees as $c) { if ($c->items && $c->items->isNotEmpty()) { foreach ($c->items as $cItem) { if ((int)($cItem->loading ?? 0) > 0) { $existingLoadingCargoList[] = [ 'cargo' => $cItem->cargo ?: '', 'cargo_type' => $cItem->cargo_type ?: '', 'loading' => (int) $cItem->loading, 'unit' => $cItem->unit ?: 'UNITS', 'stevedoring' => ($cItem->stevedoring !== '-' && $cItem->stevedoring !== '0') ? $cItem->stevedoring : '', 'cargodoring' => ($cItem->cargodoring !== '-' && $cItem->cargodoring !== '0') ? $cItem->cargodoring : '', 'consignee' => ($c->consignee !== '-') ? $c->consignee : '', ]; } } } } } $existingSpecialCargos = old('special_cargos'); if ($existingSpecialCargos === null && $planning->specialHandlings && $planning->specialHandlings->isNotEmpty()) { $existingSpecialCargos = $planning->specialHandlings->map(function($sh) { return [ 'cargo_type' => $sh->cargo_type, 'nominative_owner' => $sh->nominative_owner, 'issue' => $sh->issue, 'handling_plan' => $sh->handling_plan, 'note' => $sh->note, ]; })->toArray(); } @endphp
{{-- Top Page Header --}}

Edit {{ $planning->stage_label ?: 'Final Planning' }}: {{ $planning->vessel ?: ($planning->nama_kapal ?: 'MV. -') }}

Perbarui lembar dokumen rencana operasional kapal ({{ $planning->no_planning }})

Lihat Detail @if(auth()->user()?->canModule('planning', 'delete'))
@csrf @method('DELETE')
@endif
@php $preSibling = $planning->planning_stage === 'pre_planning' ? $planning : (isset($siblings) ? $siblings->where('planning_stage', 'pre_planning')->first() : null); $intSibling = $planning->planning_stage === 'intermediate' ? $planning : (isset($siblings) ? $siblings->where('planning_stage', 'intermediate')->first() : null); $fnlSibling = in_array($planning->planning_stage, ['final_planning', null]) ? $planning : (isset($siblings) ? $siblings->whereIn('planning_stage', ['final_planning', null])->first() : null); @endphp {{-- Stage Switcher Card / Tabs --}}
Tahapan Dokumen Pilih / Ubah Tahapan Formulir:

Anda dapat meningkatkan tahapan dokumen ini (misal: Pre Planning → Intermediate → Final Planning).

{{-- 3 Switcher Buttons --}}
@if ($errors->any())

Periksa kembali isian formulir:

    @foreach ($errors->all() as $err)
  • {{ $err }}
  • @endforeach
@endif
@csrf @method('PUT') {{-- Top Card: No. Planning & Status Dokumen --}}
@error('no_planning')

{{ $message }}

@enderror
@php $currentStatus = old('status', $planning->status ?: 'scheduled'); @endphp
{{-- ========================================================================= --}} {{-- MAIN DOCUMENT CARD (Formatted like the Paper Sheet in Time Sheet / SOF) --}} {{-- ========================================================================= --}}
{{-- Document Header --}}

{{ $planning->stage_title ?: 'FINAL PLANNING' }}

{{ old('no_planning', $planning->no_planning) }}
{{-- Section 1: Vessel & Voyage Header Info (Unified 2-Column Grid) --}}
{{-- Left Column --}}
NAME OF VESSEL :
VOY. NO :
PRINCIPAL :
SHIPPING AGENT :
{{-- Right Column --}}
BERTH :
OPERATION : @php $defaultKegiatan = old('kegiatan', $planning->kegiatan ?: 'Stevedoring'); @endphp
PORT OF ORIGIN :
NEXT PORT :
{{-- ========================================================================= --}} {{-- SECTION 2: DATA CARGO (DISCHARGING / LOADING) --}} {{-- ========================================================================= --}}

DATA CARGO - DISCHARGING

(0 Item)
{{-- Diisi oleh JavaScript --}} {{-- Diisi oleh JavaScript --}}
NO CARGO NAME TYPE DISCHARGING STEVEDORING CARGODORING NOMINATIVE OWNER
TOTAL DISCHARGING 0
{{-- ========================================================================= --}} {{-- SECTION 3: TOTAL KATEGORI CARGO & SPECIAL HANDLING CARGO --}} {{-- ========================================================================= --}} @php $rawTotalCargoSummary = old('total_cargo_summary', $planning->getCalculatedTotalCargoSummary()); @endphp

TOTAL KATEGORI CARGO

@foreach([ 'mobil_cbu' => 'CBU', 'truck' => 'TRUCK', 'bus' => 'BUS', 'hh' => 'HEAVY HIGH (HH)', 'part' => 'PART / STATIC', 'mafi' => 'MAFI', ] as $catKey => $catLabel) @endforeach
TYPE CARGO DISCHARGING LOADING TOTAL
{{ $catLabel }}
TOTAL 0 0 0
{{-- ========================================================================= --}} {{-- SECTION 3B: SPECIAL HANDLING CARGO --}} {{-- ========================================================================= --}}

SPECIAL HANDLING CARGO

{{-- Dynamic Special Cargo cards rendered here --}}

TIDAK ADA SPECIAL HANDLING CARGO

Klik "+ Tambah Special Cargo" di kanan atas apabila ada muatan dengan penanganan khusus.

{{-- ========================================================================= --}} {{-- SECTION 4: DATA OPERATING VESSEL --}} {{-- ========================================================================= --}} @php $defaultOpRows = \App\Models\FinalPlanning::getDefaultOperatingVesselRows(); $rawOpData = old('operating_vessel_data', $planning->operating_vessel_data ?? []); $opRows = []; foreach ($defaultOpRows as $idx => $defRow) { $existing = null; if (!empty($rawOpData) && is_array($rawOpData)) { foreach ($rawOpData as $rItem) { $rName = strtolower(trim($rItem['name'] ?? '')); $dName = strtolower(trim($defRow['name'])); if ($rName === $dName || ($dName === 'open ramp' && str_contains($rName, 'open') && str_contains($rName, 'ramp')) || ($dName === 'close ramp' && str_contains($rName, 'close') && str_contains($rName, 'ramp')) || ($dName === 'commenced of discharging' && str_contains($rName, 'commence') && (str_contains($rName, 'discharg') || !str_contains($rName, 'load'))) || ($dName === 'completed of discharging' && str_contains($rName, 'complete') && (str_contains($rName, 'discharg') || !str_contains($rName, 'load'))) || ($dName === 'commenced of loading' && str_contains($rName, 'commence') && str_contains($rName, 'load')) || ($dName === 'completed of loading' && str_contains($rName, 'complete') && str_contains($rName, 'load')) || ($dName === 'vessel arrived' && $rName === 'eta') || ($dName === 'berthed at ikt car terminal 2 port' && $rName === 'etb') || ($dName === 'vessel sailed from wharf' && $rName === 'etd') ) { $existing = $rItem; break; } } if ($existing === null && isset($rawOpData[$idx])) { $candName = strtolower(trim($rawOpData[$idx]['name'] ?? '')); if ($candName === '' || $candName === $dName) { $existing = $rawOpData[$idx]; } } } $opRows[] = [ 'name' => $defRow['name'], 'is_red' => $defRow['is_red'], 'has_date' => $defRow['has_date'], 'plan_date' => $existing['plan_date'] ?? '', 'plan_time' => \App\Models\FinalPlanning::formatTimeColon($existing['plan_time'] ?? '', ''), 'actual_date' => $existing['actual_date'] ?? '', 'actual_time' => \App\Models\FinalPlanning::formatTimeColon($existing['actual_time'] ?? '', ''), 'time_diff' => \App\Models\FinalPlanning::formatTimeColon($existing['time_diff'] ?? '', ''), ]; } @endphp

DATA OPERATING VESSEL

PLAN SCHEDULE
@foreach($opRows as $idx => $r) {{-- Plan Date --}} @if($r['has_date']) @else @endif {{-- Plan Time (Format Form Checker) --}} @endforeach
DATA OPERATING VESSEL PLAN DATE PLAN TIME
{{ $r['name'] }} -
{{-- ========================================================================= --}} {{-- SECTION 5: SEQUENCING CARGO OPERATION --}} {{-- ========================================================================= --}} @php $rawSeq = old('sequencing_cargo_data', $planning->sequencing_cargo_data ?? []); $dischargingData = $rawSeq['discharging'] ?? (isset($rawSeq['rows']) ? $rawSeq : []); $loadingData = $rawSeq['loading'] ?? []; $shiftingData = $rawSeq['shifting'] ?? []; $defaultDischargingRows = \App\Models\FinalPlanning::getDefaultSequencingCargoRows('discharging'); $defaultLoadingRows = \App\Models\FinalPlanning::getDefaultSequencingCargoRows('loading'); $defaultShiftingRows = \App\Models\FinalPlanning::getDefaultSequencingCargoRows('shifting'); $seqDischargingRows = $dischargingData['rows'] ?? $defaultDischargingRows; $seqDischargingTotals = $dischargingData['totals'] ?? []; $seqLoadingRows = $loadingData['rows'] ?? $defaultLoadingRows; $seqLoadingTotals = $loadingData['totals'] ?? []; $seqShiftingRows = $shiftingData['rows'] ?? $defaultShiftingRows; $seqShiftingTotals = $shiftingData['totals'] ?? []; $shiftActPerfMinutes = 0; foreach ($seqShiftingRows as $r) { $val = trim((string)($r['actual_performance'] ?? '')); if ($val !== '' && $val !== '-' && $val !== '00:00' && $val !== '0:00') { if (str_contains($val, ':')) { $PART = explode(':', $val); $shiftActPerfMinutes += (intval($PART[0]) * 60) + intval($PART[1] ?? 0); } elseif (str_contains($val, '.')) { $PART = explode('.', $val); $shiftActPerfMinutes += (intval($PART[0]) * 60) + intval($PART[1] ?? 0); } else { $shiftActPerfMinutes += intval(floatval($val) * 60); } } } $shiftActPerfH = floor($shiftActPerfMinutes / 60); $shiftActPerfM = $shiftActPerfMinutes % 60; $defaultShiftActPerfTime = sprintf('%d:%02d', $shiftActPerfH, $shiftActPerfM); $defaultShiftActPerfFormatted = sprintf('%dhr%02dmin', $shiftActPerfH, $shiftActPerfM); $shiftActPerfTotal = !empty($seqShiftingTotals['actual_performance_time']) && $seqShiftingTotals['actual_performance_time'] !== '0:00' ? $seqShiftingTotals['actual_performance_time'] : ($shiftActPerfMinutes > 0 ? $defaultShiftActPerfTime : ($seqShiftingTotals['actual_performance'] ?? '0:00')); $shiftActPerfFormatted = !empty($seqShiftingTotals['actual_performance_formatted']) && $seqShiftingTotals['actual_performance_formatted'] !== '0hr00min' ? $seqShiftingTotals['actual_performance_formatted'] : ($shiftActPerfMinutes > 0 ? $defaultShiftActPerfFormatted : '0hr00min'); @endphp

SEQUENCING CARGO OPERATION

{{-- 1. DISCHARGING --}} @foreach($seqDischargingRows as $idx => $row) @php $dischargingRateDefaults = ['CBU' => '150', 'Truck' => '20', 'Bus' => '10', 'HH' => '10']; $cat = $row['category'] ?? ''; if (isset($dischargingRateDefaults[$cat]) && (empty($row['std_performance']) || in_array($row['std_performance'], ['100', '12', '7', '5']))) { $row['std_performance'] = $dischargingRateDefaults[$cat]; } $stdRateDisplay = !empty($row['std_performance']) ? ($row['std_performance'] . ' ' . ($row['std_unit'] ?? 'Unit/hrs')) : ''; @endphp @endforeach {{-- 2. LOADING --}} @foreach($seqLoadingRows as $idx => $row) @php $loadingRateDefaults = ['CBU' => '100', 'Truck' => '12', 'Bus' => '7', 'HH' => '5']; $cat = $row['category'] ?? ''; if (isset($loadingRateDefaults[$cat]) && (empty($row['std_performance']) || in_array($row['std_performance'], ['150', '20', '10']))) { $row['std_performance'] = $loadingRateDefaults[$cat]; } $stdRateDisplay = !empty($row['std_performance']) ? ($row['std_performance'] . ' ' . ($row['std_unit'] ?? 'Unit/hrs')) : ''; @endphp @endforeach {{-- 3. SHIFTING --}} @foreach($seqShiftingRows as $idx => $row) @endforeach
Discharging STD Proformance Discharging qty (Unit/pkgs)
Approximately STD Duration Time
(hrs:min)
{{ $row['category'] }} @if($stdRateDisplay) ({{ $stdRateDisplay }}) @endif
{{ $row['std_duration_time'] ?? '00:00' }} Hrs
TOTAL {{ $seqDischargingTotals['std_duration_time'] ?? '0:00' }} {{ $seqDischargingTotals['std_duration_formatted'] ?? '0hr00min' }}
{{-- ========================================================================= --}} {{-- SECTION 6: OPERATION STRATEGIC --}} {{-- ========================================================================= --}} @php $rawOpStrat = old('ops_strategic_data', $planning->ops_strategic_data ?? []); $opStrat = \App\Models\FinalPlanning::normalizeOperationStrategicTimesToColon(is_array($rawOpStrat) ? $rawOpStrat : []); @endphp

OPERATION STRATEGIC

PLAN DURATION
{{-- Row 1 --}} {{-- Row 2 --}} {{-- Row 3 --}} {{-- Row 4 --}} {{-- Row 5 --}} {{-- Row 6: Available Time --}}
OPERATION STRATEGIC (PLAN) PLAN DURATION TIME
Total Approximately Duration Time Hrs
Waiting Cargo / Document Hrs
Idle Time / Stop Operation Hrs
Shifting Hrs
MEAL BREAK Hrs
AVAILABLE TIME Hrs
{{-- ========================================================================= --}} {{-- SECTION 7, 8 & 9: DEPLOYMENT, ESTIMATE BUDGET & MECHANICAL EQUIPMENT --}} {{-- ========================================================================= --}} @include('final-planning._deployment-sheet-tables') {{-- Submit Action Bar inside Sheet Footer --}}
Batal