feat(qma): streamline transfer form with origin-location filtering and transporter logistics
This commit is contained in:
@@ -129,6 +129,20 @@ class UnitTransferController extends Controller
|
||||
->orderBy('code')
|
||||
->get();
|
||||
|
||||
// Cari lokasi awal jika vehicle_id disertakan
|
||||
$selectedOriginLocation = null;
|
||||
if ($selectedVehicleId) {
|
||||
$selectedVeh = $heavyUnits->firstWhere('id', $selectedVehicleId);
|
||||
if ($selectedVeh) {
|
||||
$selectedOriginLocation = $selectedVeh->location ?: 'Site Kerinci';
|
||||
}
|
||||
}
|
||||
|
||||
// Daftar lokasi awal unik yang saat ini memiliki unit alat berat beserta jumlah unitnya
|
||||
$originLocations = $heavyUnits->groupBy(fn($u) => $u->location ?: 'Site Kerinci')
|
||||
->map(fn($group) => $group->count())
|
||||
->sortKeys();
|
||||
|
||||
// 2. Daftar unit kendaraan kita untuk armada pengangkut (Truk, Flatbed, Lowbed, Towing, LV, dsb.)
|
||||
$transporterUnits = Vehicle::trackableUnits()
|
||||
->orderBy('category')
|
||||
@@ -149,6 +163,8 @@ class UnitTransferController extends Controller
|
||||
|
||||
return view('qma.unit_transfers_create', compact(
|
||||
'heavyUnits',
|
||||
'originLocations',
|
||||
'selectedOriginLocation',
|
||||
'transporterUnits',
|
||||
'drivers',
|
||||
'locationSuggestions',
|
||||
@@ -164,6 +180,7 @@ class UnitTransferController extends Controller
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'vehicle_id' => ['required', 'integer', 'exists:vehicles,id'],
|
||||
'from_location' => ['nullable', 'string', 'max:255'],
|
||||
'transfer_date' => ['required', 'date'],
|
||||
'to_location' => ['required', 'string', 'max:255'],
|
||||
'to_site_status' => ['required', 'in:inside_site,outside_site'],
|
||||
@@ -174,6 +191,7 @@ class UnitTransferController extends Controller
|
||||
'transporter_driver_id' => ['nullable', 'integer', 'exists:employees,id'],
|
||||
'transporter_driver_name' => ['nullable', 'string', 'max:255'],
|
||||
'transporter_description' => ['nullable', 'string', 'max:2000'],
|
||||
'update_transporter_location' => ['nullable', 'boolean'],
|
||||
'document_number' => ['required', 'string', 'max:255'],
|
||||
'document_title' => ['required', 'string', 'max:255'],
|
||||
'document_file' => ['nullable', 'file', 'mimes:pdf,jpg,jpeg,png', 'max:5120'],
|
||||
@@ -194,11 +212,13 @@ class UnitTransferController extends Controller
|
||||
$filePath = $request->file('document_file')->store('transfers/documents', 'public');
|
||||
}
|
||||
|
||||
$transfer = DB::transaction(function () use ($validated, $filePath) {
|
||||
$updateTransporter = $request->boolean('update_transporter_location', true);
|
||||
|
||||
$transfer = DB::transaction(function () use ($validated, $filePath, $updateTransporter) {
|
||||
$vehicle = Vehicle::trackableUnits()->findOrFail($validated['vehicle_id']);
|
||||
|
||||
// Lokasi dan status site awal sebelum dipindahkan
|
||||
$fromLocation = $vehicle->location ?: 'Site Kerinci';
|
||||
$fromLocation = $vehicle->location ?: ($validated['from_location'] ?? 'Site Kerinci');
|
||||
$fromSiteStatus = $vehicle->site_status ?: 'inside_site';
|
||||
|
||||
// Nama armada pengangkut
|
||||
@@ -278,6 +298,31 @@ class UnitTransferController extends Controller
|
||||
'recorded_at' => Carbon::now(),
|
||||
]);
|
||||
|
||||
// 4. Jika opsi perbarui posisi truk pengangkut aktif
|
||||
if ($updateTransporter && !empty($validated['transporter_vehicle_id'])) {
|
||||
$transporterVeh = Vehicle::find($validated['transporter_vehicle_id']);
|
||||
if ($transporterVeh && $transporterVeh->id !== $vehicle->id) {
|
||||
$transporterVeh->update([
|
||||
'location' => $toLocation,
|
||||
'site_status' => $validated['to_site_status'],
|
||||
'location_updated_at' => Carbon::now(),
|
||||
'location_updated_by' => $reportedBy,
|
||||
'location_note' => "Armada Pengangkut BAST {$validated['document_number']} untuk {$vehicle->code} ke {$toLocation}",
|
||||
]);
|
||||
|
||||
VehicleLocationHistory::create([
|
||||
'vehicle_id' => $transporterVeh->id,
|
||||
'site_status' => $validated['to_site_status'],
|
||||
'location' => $toLocation,
|
||||
'note' => "Armada Pengangkut: Mengantar {$vehicle->code} ({$vehicle->brand_type}) via BAST {$validated['document_number']} ke {$toLocation}",
|
||||
'source' => 'transfer',
|
||||
'user_id' => auth()->id(),
|
||||
'user_name' => $reportedBy,
|
||||
'recorded_at' => Carbon::now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return $transfer;
|
||||
});
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Form Pemindahan Unit Alat Berat
|
||||
</h2>
|
||||
<p class="text-xs sm:text-sm text-slate-500 mt-0.5">
|
||||
Lengkapi rincian pemindahan alat berat, armada pengangkut, dan data Berita Acara Serah Terima (BAST).
|
||||
Pilih lokasi asal untuk memfilter unit yang tersedia, tentukan tujuan baru, armada truk pengangkut, dan terbitkan BAST.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
@csrf
|
||||
|
||||
<!-- ============================================================= -->
|
||||
<!-- BAGIAN 1: DATA PEMINDAHAN ALAT BERAT -->
|
||||
<!-- BAGIAN 1: LOKASI AWAL & DATA ALAT BERAT -->
|
||||
<!-- ============================================================= -->
|
||||
<div class="bg-white rounded-2xl border border-slate-200/80 shadow-xs p-5 sm:p-6 space-y-5">
|
||||
<div class="flex items-center space-x-3 pb-3 border-b border-slate-100">
|
||||
@@ -57,38 +57,73 @@
|
||||
<i class="fa-solid fa-truck-monster"></i>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="text-base font-extrabold text-slate-900">1. Data Alat Berat yang Dipindahkan</h3>
|
||||
<p class="text-xs text-slate-500">Pilih unit alat berat dan tentukan lokasi penempatan barunya.</p>
|
||||
<h3 class="text-base font-extrabold text-slate-900">1. Lokasi Awal & Unit Alat Berat yang Dipindahkan</h3>
|
||||
<p class="text-xs text-slate-500">Pilih titik lokasi awal untuk melihat alat berat yang siap dipindahkan dari lokasi tersebut.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Pilih Alat Berat -->
|
||||
<div>
|
||||
<label for="vehicle_id" class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
Pilih Unit Alat Berat <span class="text-rose-500">*</span>
|
||||
</label>
|
||||
<select name="vehicle_id"
|
||||
id="vehicle_id"
|
||||
required
|
||||
onchange="onHeavyUnitSelected(this)"
|
||||
class="w-full px-3.5 py-2.5 text-xs rounded-xl border border-slate-200 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition bg-white text-slate-800 font-semibold">
|
||||
<option value="" disabled {{ old('vehicle_id', $selectedVehicleId) ? '' : 'selected' }}>-- Pilih Unit Alat Berat / Support Unit --</option>
|
||||
@foreach($heavyUnits as $unit)
|
||||
<option value="{{ $unit->id }}"
|
||||
data-code="{{ $unit->code }}"
|
||||
data-brand="{{ $unit->brand_type }}"
|
||||
data-category="{{ $unit->unit_category ?? ($unit->parent?->brand_type ?? 'Unit Support') }}"
|
||||
data-location="{{ $unit->location ?: 'Site Kerinci' }}"
|
||||
data-site-status="{{ $unit->site_status ?? 'inside_site' }}"
|
||||
data-photo="{{ $unit->photo_url }}"
|
||||
{{ old('vehicle_id', $selectedVehicleId) == $unit->id ? 'selected' : '' }}>
|
||||
{{ $unit->code }} - {{ $unit->brand_type }} (Lokasi Saat Ini: {{ $unit->location ?: 'Site Kerinci' }})
|
||||
<!-- Grid 2 Kolom: Langkah 1 (Lokasi Awal) & Langkah 2 (Pilih Alat Berat) -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<!-- LANGKAH 1: PILIH LOKASI AWAL (ORIGIN LOCATION) -->
|
||||
<div>
|
||||
<label for="origin_location" class="block text-xs font-bold text-slate-700 mb-1.5 flex items-center justify-between">
|
||||
<span>Langkah 1: Pilih Lokasi Awal (Asal) <span class="text-rose-500">*</span></span>
|
||||
<span class="text-[10px] text-emerald-700 font-semibold">Filter Berdasarkan Posisi</span>
|
||||
</label>
|
||||
<div class="relative">
|
||||
<i class="fa-solid fa-map-pin absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-400 text-xs"></i>
|
||||
<select name="from_location"
|
||||
id="origin_location"
|
||||
required
|
||||
onchange="onOriginLocationChanged(this.value)"
|
||||
class="w-full pl-9 pr-3.5 py-2.5 text-xs rounded-xl border border-slate-200 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition bg-white text-slate-800 font-bold">
|
||||
<option value="" disabled {{ empty($selectedOriginLocation) && !old('from_location') ? 'selected' : '' }}>
|
||||
-- Pilih Lokasi Awal Alat Berat --
|
||||
</option>
|
||||
<option value="ALL" {{ old('from_location', $selectedOriginLocation) === 'ALL' ? 'selected' : '' }}>
|
||||
[Tampilkan Semua Lokasi / Semua Alat Berat]
|
||||
</option>
|
||||
@foreach($originLocations as $locName => $count)
|
||||
<option value="{{ $locName }}" {{ old('from_location', $selectedOriginLocation) === $locName ? 'selected' : '' }}>
|
||||
{{ $locName }} ({{ $count }} Unit Tersedia)
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<p class="text-[10px] text-slate-400 mt-1">Memilih lokasi awal akan memfilter unit alat berat yang berada di titik tersebut.</p>
|
||||
</div>
|
||||
|
||||
<!-- LANGKAH 2: PILIH ALAT BERAT YANG AKAN DIPINDAHKAN -->
|
||||
<div>
|
||||
<label for="vehicle_id" class="block text-xs font-bold text-slate-700 mb-1.5 flex items-center justify-between">
|
||||
<span>Langkah 2: Pilih Unit Alat Berat <span class="text-rose-500">*</span></span>
|
||||
<span id="unitCounterBadge" class="text-[10px] font-semibold text-emerald-700 bg-emerald-50 px-2 py-0.5 rounded border border-emerald-200 hidden"></span>
|
||||
</label>
|
||||
<select name="vehicle_id"
|
||||
id="vehicle_id"
|
||||
required
|
||||
onchange="onHeavyUnitSelected(this)"
|
||||
class="w-full px-3.5 py-2.5 text-xs rounded-xl border border-slate-200 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition bg-white text-slate-800 font-semibold">
|
||||
<option value="" disabled {{ empty($selectedVehicleId) && !old('vehicle_id') ? 'selected' : '' }}>
|
||||
-- Pilih Lokasi Awal Terlebih Dahulu --
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('vehicle_id')
|
||||
<p class="text-rose-500 text-[11px] font-semibold mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
@foreach($heavyUnits as $unit)
|
||||
<option value="{{ $unit->id }}"
|
||||
data-code="{{ $unit->code }}"
|
||||
data-brand="{{ $unit->brand_type }}"
|
||||
data-category="{{ $unit->unit_category ?? ($unit->parent?->brand_type ?? 'Unit Support') }}"
|
||||
data-location="{{ $unit->location ?: 'Site Kerinci' }}"
|
||||
data-site-status="{{ $unit->site_status ?? 'inside_site' }}"
|
||||
data-photo="{{ $unit->photo_url }}"
|
||||
{{ old('vehicle_id', $selectedVehicleId) == $unit->id ? 'selected' : '' }}>
|
||||
{{ $unit->code }} - {{ $unit->brand_type }} [Posisi: {{ $unit->location ?: 'Site Kerinci' }}]
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('vehicle_id')
|
||||
<p class="text-rose-500 text-[11px] font-semibold mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Info Preview Card Unit Terpilih (Muncul Otomatis via JS) -->
|
||||
@@ -105,14 +140,14 @@
|
||||
</div>
|
||||
<p id="unitPreviewBrand" class="text-xs text-slate-600 font-medium mt-0.5 truncate"></p>
|
||||
<div class="mt-1 flex items-center space-x-2 text-[11px]">
|
||||
<span class="text-slate-400">Lokasi saat ini:</span>
|
||||
<span class="text-slate-400">Titik Keberangkatan (Asal):</span>
|
||||
<span id="unitPreviewCurrentLocation" class="font-bold text-emerald-800 bg-emerald-50 px-2 py-0.5 rounded border border-emerald-200"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Grid 2 Kolom: Tanggal Transfer & Lokasi Awal -->
|
||||
<!-- Grid 2 Kolom: Tanggal Transfer & Lokasi Tujuan -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<!-- Tanggal Pemindahan -->
|
||||
<div>
|
||||
@@ -130,29 +165,11 @@
|
||||
@enderror
|
||||
</div>
|
||||
|
||||
<!-- Lokasi Awal (Read-only / Terisi Otomatis) -->
|
||||
<div>
|
||||
<label for="from_location_display" class="block text-xs font-bold text-slate-700 mb-1.5 flex items-center justify-between">
|
||||
<span>Lokasi Awal (Terkini)</span>
|
||||
<span class="text-[10px] text-emerald-700 font-semibold">Otomatis dari Sistem</span>
|
||||
</label>
|
||||
<div class="relative">
|
||||
<i class="fa-solid fa-map-pin absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-400 text-xs"></i>
|
||||
<input type="text"
|
||||
id="from_location_display"
|
||||
readonly
|
||||
placeholder="Pilih unit alat berat terlebih dahulu"
|
||||
class="w-full pl-9 pr-3.5 py-2.5 text-xs rounded-xl border border-slate-200 bg-slate-100 text-slate-700 font-bold cursor-not-allowed">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Grid 2 Kolom: Lokasi Tujuan & Area Tujuan (Inside/Outside Site) -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<!-- Lokasi Tujuan -->
|
||||
<div>
|
||||
<label for="to_location" class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
Lokasi Tujuan Baru <span class="text-rose-500">*</span>
|
||||
<label for="to_location" class="block text-xs font-bold text-slate-700 mb-1.5 flex items-center justify-between">
|
||||
<span>Langkah 3: Lokasi Tujuan Baru <span class="text-rose-500">*</span></span>
|
||||
<span class="text-[10px] text-slate-400 font-normal">Pilih / Ketik Lokasi</span>
|
||||
</label>
|
||||
<div class="relative">
|
||||
<i class="fa-solid fa-location-dot absolute left-3.5 top-1/2 -translate-y-1/2 text-emerald-700 text-xs"></i>
|
||||
@@ -162,6 +179,7 @@
|
||||
list="locationSuggestionList"
|
||||
value="{{ old('to_location') }}"
|
||||
required
|
||||
oninput="updateRouteBanner()"
|
||||
placeholder="Contoh: Main Dam, Adit 2, Workshop GA..."
|
||||
class="w-full pl-9 pr-3.5 py-2.5 text-xs rounded-xl border border-slate-200 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition bg-white text-slate-800 font-semibold">
|
||||
</div>
|
||||
@@ -177,8 +195,11 @@
|
||||
@endforeach
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Status Area Tujuan: Di Dalam / Di Luar Site -->
|
||||
<!-- Grid 2 Kolom: Status Area Tujuan & Reported By -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<!-- Area Tujuan (Inside/Outside Site) -->
|
||||
<div>
|
||||
<label class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
Area Tujuan Pemindahan <span class="text-rose-500">*</span>
|
||||
@@ -214,21 +235,6 @@
|
||||
<p class="text-rose-500 text-[11px] font-semibold mt-1">{{ $message }}</p>
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Deskripsi & Reported By -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
|
||||
<!-- Deskripsi / Keperluan Pemindahan -->
|
||||
<div class="sm:col-span-2">
|
||||
<label for="description" class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
Deskripsi / Keperluan Pemindahan (Opsional)
|
||||
</label>
|
||||
<textarea name="description"
|
||||
id="description"
|
||||
rows="2"
|
||||
placeholder="Contoh: Relokasi excavator untuk percepatan galian bendungan intake Adit 2."
|
||||
class="w-full px-3.5 py-2 text-xs rounded-xl border border-slate-200 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition bg-white text-slate-800">{{ old('description') }}</textarea>
|
||||
</div>
|
||||
|
||||
<!-- Dilaporkan Oleh (Reported By) -->
|
||||
<div>
|
||||
@@ -250,6 +256,18 @@
|
||||
@enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Deskripsi / Keperluan Pemindahan -->
|
||||
<div>
|
||||
<label for="description" class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
Deskripsi / Keperluan Pemindahan (Opsional)
|
||||
</label>
|
||||
<textarea name="description"
|
||||
id="description"
|
||||
rows="2"
|
||||
placeholder="Contoh: Relokasi excavator untuk percepatan galian bendungan intake Adit 2."
|
||||
class="w-full px-3.5 py-2 text-xs rounded-xl border border-slate-200 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition bg-white text-slate-800">{{ old('description') }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ============================================================= -->
|
||||
@@ -262,7 +280,16 @@
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="text-base font-extrabold text-slate-900">2. Armada & Supir Pengangkut (Transporter)</h3>
|
||||
<p class="text-xs text-slate-500">Alat berat diangkut menggunakan truk/mobil pengangkut dari unit internal atau unit rekanan.</p>
|
||||
<p class="text-xs text-slate-500">Truk pengangkut dapat dipilih dari lokasi yang sama atau dimobilisasi dari pool/workshop lain.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Banner Info Logistik Rute (Muncul saat Truk dipilih) -->
|
||||
<div id="routeLogisticsBanner" class="hidden p-3.5 rounded-xl bg-blue-50/80 border border-blue-200 text-xs text-blue-900 flex items-start space-x-3">
|
||||
<i class="fa-solid fa-route text-blue-700 text-sm mt-0.5"></i>
|
||||
<div class="flex-1">
|
||||
<span class="font-bold block mb-0.5">Rute Logistik Pengangkutan:</span>
|
||||
<p id="routeLogisticsText" class="text-[11px] text-blue-800 leading-relaxed"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -271,19 +298,21 @@
|
||||
<!-- Pilih Mobil dari Unit Kita -->
|
||||
<div>
|
||||
<label for="transporter_vehicle_id" class="block text-xs font-bold text-slate-700 mb-1.5 flex items-center justify-between">
|
||||
<span>Pilih Mobil Pengangkut (Dari Unit Kita)</span>
|
||||
<span class="text-[10px] text-slate-400 font-normal">Opsional</span>
|
||||
<span>Pilih Kendaraan Pengangkut (Armada Kita)</span>
|
||||
<span id="transporterLocationHint" class="text-[10px] text-slate-400 font-normal">Truk / Lowbed / Towing</span>
|
||||
</label>
|
||||
<select name="transporter_vehicle_id"
|
||||
id="transporter_vehicle_id"
|
||||
onchange="onTransporterSelected(this)"
|
||||
class="w-full px-3.5 py-2.5 text-xs rounded-xl border border-slate-200 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition bg-white text-slate-800">
|
||||
<option value="">-- Tanpa Mobil Pengangkut / Unit Mandiri / Rental Luar --</option>
|
||||
<option value="">-- Tanpa Truk Pengangkut / Rental Luar / Mobilisasi Mandiri --</option>
|
||||
@foreach($transporterUnits as $tu)
|
||||
<option value="{{ $tu->id }}"
|
||||
data-code="{{ $tu->code }}"
|
||||
data-name="{{ $tu->code }} - {{ $tu->brand_type }}{{ $tu->license_plate ? ' (' . $tu->license_plate . ')' : '' }}"
|
||||
data-location="{{ $tu->location ?: 'Pool Workshop GA' }}"
|
||||
{{ old('transporter_vehicle_id') == $tu->id ? 'selected' : '' }}>
|
||||
{{ $tu->code }} - {{ $tu->brand_type }} {{ $tu->license_plate ? '[' . $tu->license_plate . ']' : '' }}
|
||||
{{ $tu->code }} - {{ $tu->brand_type }} [Posisi: {{ $tu->location ?: 'Pool Workshop' }}]
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@@ -292,7 +321,7 @@
|
||||
<!-- Input / Snapshot Nama Armada Pengangkut -->
|
||||
<div>
|
||||
<label for="transporter_unit_name" class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
Nama / Identitas Kendaraan Pengangkut
|
||||
Identitas / Keterangan Kendaraan Pengangkut
|
||||
</label>
|
||||
<div class="relative">
|
||||
<i class="fa-solid fa-truck absolute left-3.5 top-1/2 -translate-y-1/2 text-slate-400 text-xs"></i>
|
||||
@@ -300,14 +329,27 @@
|
||||
name="transporter_unit_name"
|
||||
id="transporter_unit_name"
|
||||
value="{{ old('transporter_unit_name') }}"
|
||||
placeholder="Contoh: DT-05 Hino 500 / Truk Towing Rekanan"
|
||||
placeholder="Contoh: DT-05 Hino 500 / Truk Towing Rekanan Luar"
|
||||
class="w-full pl-9 pr-3.5 py-2.5 text-xs rounded-xl border border-slate-200 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition bg-white text-slate-800 font-semibold">
|
||||
</div>
|
||||
<p class="text-[10px] text-slate-400 mt-1">Otomatis terisi jika memilih mobil dari unit kita, atau isi manual jika memakai vendor luar.</p>
|
||||
<p class="text-[10px] text-slate-400 mt-1">Otomatis terisi jika memilih armada internal, atau ketik nama vendor/unit rekanan luar.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Grid 2 Kolom: Supir Pengangkut & Deskripsi Angkutan -->
|
||||
<!-- Opsi Sinkronisasi Lokasi Truk Pengangkut -->
|
||||
<div class="p-3 rounded-xl bg-slate-50 border border-slate-200 flex items-center space-x-3">
|
||||
<input type="checkbox"
|
||||
name="update_transporter_location"
|
||||
id="update_transporter_location"
|
||||
value="1"
|
||||
checked
|
||||
class="w-4 h-4 rounded text-[#1b5e20] focus:ring-[#1b5e20] border-slate-300 cursor-pointer">
|
||||
<label for="update_transporter_location" class="text-xs text-slate-700 font-semibold cursor-pointer select-none">
|
||||
Perbarui juga posisi terkini truk pengangkut ke lokasi tujuan setelah proses pemindahan selesai
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Grid 2 Kolom: Supir Pengangkut & Catatan Angkutan -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<!-- Supir Pengangkut -->
|
||||
<div>
|
||||
@@ -337,12 +379,12 @@
|
||||
<!-- Deskripsi / Catatan Angkutan -->
|
||||
<div>
|
||||
<label for="transporter_description" class="block text-xs font-bold text-slate-700 mb-1.5">
|
||||
Deskripsi / Catatan Angkutan (Opsional)
|
||||
Catatan Pengangkutan & Pengamanan Muatan (Opsional)
|
||||
</label>
|
||||
<textarea name="transporter_description"
|
||||
id="transporter_description"
|
||||
rows="2"
|
||||
placeholder="Contoh: Unit telah diikat dengan rantai lashing 4 titik, lampu rotary aktif, kondisi aman."
|
||||
placeholder="Contoh: Unit telah diikat rantai lashing 4 titik, bucket terkunci, dikawal mobil patroli."
|
||||
class="w-full px-3.5 py-2 text-xs rounded-xl border border-slate-200 focus:outline-none focus:ring-2 focus:ring-[#1b5e20]/20 focus:border-[#1b5e20] transition bg-white text-slate-800">{{ old('transporter_description') }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
@@ -438,6 +480,110 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Inisialisasi daftar semua unit alat berat dari options
|
||||
let allHeavyUnits = [];
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const unitSelect = document.getElementById('vehicle_id');
|
||||
if (unitSelect) {
|
||||
Array.from(unitSelect.options).forEach(opt => {
|
||||
if (opt.value) {
|
||||
allHeavyUnits.push({
|
||||
id: opt.value,
|
||||
code: opt.getAttribute('data-code'),
|
||||
brand: opt.getAttribute('data-brand'),
|
||||
category: opt.getAttribute('data-category'),
|
||||
location: opt.getAttribute('data-location'),
|
||||
siteStatus: opt.getAttribute('data-site-status'),
|
||||
photo: opt.getAttribute('data-photo'),
|
||||
text: opt.textContent.trim()
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Cek jika sudah ada lokasi awal (dari old value atau selectedOriginLocation)
|
||||
const originSelect = document.getElementById('origin_location');
|
||||
if (originSelect && originSelect.value) {
|
||||
onOriginLocationChanged(originSelect.value, "{{ old('vehicle_id', $selectedVehicleId ?? '') }}");
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Handler ketika Lokasi Awal (Asal) berubah
|
||||
* Memfilter unit alat berat yang posisinya berada di lokasi tersebut
|
||||
*/
|
||||
function onOriginLocationChanged(selectedLocation, preselectUnitId = null) {
|
||||
const unitSelect = document.getElementById('vehicle_id');
|
||||
const badge = document.getElementById('unitCounterBadge');
|
||||
if (!unitSelect) return;
|
||||
|
||||
// Kosongkan options
|
||||
unitSelect.innerHTML = '';
|
||||
|
||||
if (!selectedLocation) {
|
||||
const defaultOpt = document.createElement('option');
|
||||
defaultOpt.value = '';
|
||||
defaultOpt.disabled = true;
|
||||
defaultOpt.selected = true;
|
||||
defaultOpt.textContent = '-- Pilih Lokasi Awal Terlebih Dahulu --';
|
||||
unitSelect.appendChild(defaultOpt);
|
||||
badge.classList.add('hidden');
|
||||
document.getElementById('unitPreviewCard').classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter unit
|
||||
const filteredUnits = (selectedLocation === 'ALL')
|
||||
? allHeavyUnits
|
||||
: allHeavyUnits.filter(u => u.location === selectedLocation);
|
||||
|
||||
// Update badge jumlah unit
|
||||
badge.classList.remove('hidden');
|
||||
badge.textContent = `${filteredUnits.length} Unit Tersedia`;
|
||||
|
||||
// Tambah opsi default
|
||||
const promptOpt = document.createElement('option');
|
||||
promptOpt.value = '';
|
||||
promptOpt.disabled = true;
|
||||
promptOpt.textContent = filteredUnits.length > 0 ? '-- Pilih Unit Alat Berat --' : '-- Tidak ada unit di lokasi ini --';
|
||||
if (!preselectUnitId) {
|
||||
promptOpt.selected = true;
|
||||
}
|
||||
unitSelect.appendChild(promptOpt);
|
||||
|
||||
// Tambah options hasil filter
|
||||
let hasPreselected = false;
|
||||
filteredUnits.forEach(u => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = u.id;
|
||||
opt.setAttribute('data-code', u.code);
|
||||
opt.setAttribute('data-brand', u.brand);
|
||||
opt.setAttribute('data-category', u.category);
|
||||
opt.setAttribute('data-location', u.location);
|
||||
opt.setAttribute('data-site-status', u.siteStatus);
|
||||
opt.setAttribute('data-photo', u.photo || '');
|
||||
opt.textContent = `${u.code} - ${u.brand} [Posisi: ${u.location}]`;
|
||||
|
||||
if (preselectUnitId && String(u.id) === String(preselectUnitId)) {
|
||||
opt.selected = true;
|
||||
hasPreselected = true;
|
||||
}
|
||||
unitSelect.appendChild(opt);
|
||||
});
|
||||
|
||||
if (hasPreselected) {
|
||||
onHeavyUnitSelected(unitSelect);
|
||||
} else {
|
||||
document.getElementById('unitPreviewCard').classList.add('hidden');
|
||||
}
|
||||
|
||||
updateRouteBanner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler saat Alat Berat Terpilih
|
||||
*/
|
||||
function onHeavyUnitSelected(selectElement) {
|
||||
const option = selectElement.options[selectElement.selectedIndex];
|
||||
if (!option || !option.value) return;
|
||||
@@ -446,12 +592,8 @@
|
||||
const brand = option.getAttribute('data-brand');
|
||||
const category = option.getAttribute('data-category');
|
||||
const location = option.getAttribute('data-location');
|
||||
const siteStatus = option.getAttribute('data-site-status');
|
||||
const photo = option.getAttribute('data-photo');
|
||||
|
||||
// Isi display lokasi awal
|
||||
document.getElementById('from_location_display').value = location;
|
||||
|
||||
// Buka preview card
|
||||
const card = document.getElementById('unitPreviewCard');
|
||||
card.classList.remove('hidden');
|
||||
@@ -476,8 +618,13 @@
|
||||
if (docTitle && (!docTitle.value || docTitle.value.includes('Pemindahan') || docTitle.value.includes('Relokasi'))) {
|
||||
docTitle.value = `Berita Acara Pemindahan Unit ${code} (${brand})`;
|
||||
}
|
||||
|
||||
updateRouteBanner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler saat Armada Pengangkut Terpilih
|
||||
*/
|
||||
function onTransporterSelected(selectElement) {
|
||||
const option = selectElement.options[selectElement.selectedIndex];
|
||||
const nameInput = document.getElementById('transporter_unit_name');
|
||||
@@ -487,14 +634,36 @@
|
||||
nameInput.value = dataName;
|
||||
}
|
||||
}
|
||||
updateRouteBanner();
|
||||
}
|
||||
|
||||
// Trigger preview on initial load if vehicle_id is already selected (e.g. from validation error back)
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const select = document.getElementById('vehicle_id');
|
||||
if (select && select.value) {
|
||||
onHeavyUnitSelected(select);
|
||||
/**
|
||||
* Update Banner Logistik Rute Perjalanan
|
||||
*/
|
||||
function updateRouteBanner() {
|
||||
const banner = document.getElementById('routeLogisticsBanner');
|
||||
const text = document.getElementById('routeLogisticsText');
|
||||
const transporterSelect = document.getElementById('transporter_vehicle_id');
|
||||
const originSelect = document.getElementById('origin_location');
|
||||
const destinationInput = document.getElementById('to_location');
|
||||
|
||||
const optTransporter = transporterSelect.options[transporterSelect.selectedIndex];
|
||||
if (!optTransporter || !optTransporter.value) {
|
||||
banner.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
const transporterCode = optTransporter.getAttribute('data-code');
|
||||
const transporterLoc = optTransporter.getAttribute('data-location') || 'Pool Workshop';
|
||||
const originLoc = originSelect.value && originSelect.value !== 'ALL' ? originSelect.value : 'Lokasi Asal Alat Berat';
|
||||
const destLoc = destinationInput.value ? destinationInput.value : '[Lokasi Tujuan Baru]';
|
||||
|
||||
banner.classList.remove('hidden');
|
||||
if (transporterLoc === originLoc) {
|
||||
text.innerHTML = `Truk <strong>${transporterCode}</strong> saat ini standby di <strong>${transporterLoc}</strong> (sama dengan lokasi alat berat) → Langsung mengangkut unit menuju tujuan <strong>${destLoc}</strong>.`;
|
||||
} else {
|
||||
text.innerHTML = `Truk <strong>${transporterCode}</strong> diberangkatkan dari <strong>${transporterLoc}</strong> → Menjemput alat berat di <strong>${originLoc}</strong> → Mengantarkannya ke tujuan <strong>${destLoc}</strong>.`;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@endsection
|
||||
|
||||
@@ -304,4 +304,43 @@ class QmaUnitTransferTest extends TestCase
|
||||
$response->assertSee('value="' . $this->heavyEquipment->id . '"', false);
|
||||
$response->assertSee('selected', false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Jika opsi update_transporter_location dicentang, armada pengangkut juga diperbarui posisinya
|
||||
* dan dicatat di riwayat mutasi lokasi.
|
||||
*/
|
||||
public function test_store_transfer_updates_transporter_truck_location_when_checked(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
$payload = [
|
||||
'vehicle_id' => $this->heavyEquipment->id,
|
||||
'from_location' => 'Main Dam',
|
||||
'transfer_date' => Carbon::now()->format('Y-m-d'),
|
||||
'to_location' => 'Adit 2 Intake',
|
||||
'to_site_status' => 'inside_site',
|
||||
'reported_by' => 'Staff QMA Logistik',
|
||||
'transporter_vehicle_id' => $this->transporterTruck->id,
|
||||
'transporter_unit_name' => 'DT-05',
|
||||
'update_transporter_location' => '1',
|
||||
'document_number' => '020/BAST-AB/QMA-KMH/X/2026',
|
||||
'document_title' => 'BAST Pemindahan Unit & Mobilisasi Truk',
|
||||
];
|
||||
|
||||
$response = $this->actingAs($this->qmaAdmin)->post(route('qma.unit_transfers.store'), $payload);
|
||||
$response->assertSessionHas('success');
|
||||
|
||||
// Posisi truk pengangkut harus terupdate ke Adit 2 Intake
|
||||
$freshTransporter = $this->transporterTruck->fresh();
|
||||
$this->assertEquals('Adit 2 Intake', $freshTransporter->location);
|
||||
|
||||
// Riwayat lokasi truk pengangkut harus tercatat
|
||||
$transporterHistory = VehicleLocationHistory::where('vehicle_id', $this->transporterTruck->id)
|
||||
->where('source', 'transfer')
|
||||
->first();
|
||||
|
||||
$this->assertNotNull($transporterHistory);
|
||||
$this->assertEquals('Adit 2 Intake', $transporterHistory->location);
|
||||
$this->assertStringContainsString('Mengantar EXCA-01', $transporterHistory->note);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user