Kumpulan perubahan yang udah numpuk di working tree: refactor Setup (Gate/Vehicle/Member), rapihin memberin & stiker, service parking baru (ParkingUtilsServices, NetworkService), model/migration lot-parking & DHCP reservation, dan fitur baru Intercom (controller/model/migration/ view). ReportTransaksiController versi lokal ini WIP (~90%, masih didebug) - versi yang bener ada di server, jadi dikeluarin dari git (ditambahin ke .gitignore) biar gak numpuk nindihin punya server pas git pull di sana. Sekalian keluarin dump mentah tabel softseting (1.8MB, nyasar ke-commit), file .bak, dan arsip ad-hoc (api.tgz, c.zip) yang emang bukan source code. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01EAJc2mrpj2cSTe4oowLPzQ
143 lines
3.9 KiB
PHP
143 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Parking\Setup\Vehicle;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\VehicleItem;
|
|
use App\Models\MasterTarif;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class MasterVehicleController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$vehicle = VehicleItem::orderBy('id')->get();
|
|
|
|
// dd($vehicle);
|
|
|
|
return view ('setup.vehicle.vehicle', compact('vehicle'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$request->merge([
|
|
'id' => strtoupper((string) $request->input('id')),
|
|
'short_cut' => strtoupper((string) $request->input('short_cut')),
|
|
]);
|
|
|
|
$data = $request->validate([
|
|
'id' => 'required|string|max:16|alpha_num|unique:jenis_mobil,id',
|
|
'nama' => 'required|string|max:100',
|
|
'short_cut' => 'required|string|max:16',
|
|
'tarif' => 'required|numeric|min:0',
|
|
]);
|
|
|
|
$vehicle = DB::transaction(function () use ($data) {
|
|
$vehicle = VehicleItem::create([
|
|
'id' => strtoupper($data['id']),
|
|
'nama' => $data['nama'],
|
|
'short_cut' => strtoupper($data['short_cut']),
|
|
'tanggal' => now(),
|
|
'orang' => 0,
|
|
'validasi' => 0,
|
|
]);
|
|
|
|
MasterTarif::create([
|
|
'id_mobil' => $vehicle->id,
|
|
'tarif' => $data['tarif'],
|
|
'tanggal' => now(),
|
|
]);
|
|
|
|
return $vehicle;
|
|
});
|
|
|
|
return response()->json(['success' => true, 'message' => 'Jenis kendaraan dan tarif awal berhasil ditambahkan.', 'data' => $vehicle], 201);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$vehicle = VehicleItem::findOrFail($id);
|
|
$tarif = MasterTarif::find($id);
|
|
|
|
return response()->json(['success' => true, 'data' => $vehicle, 'tarif' => $tarif]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
return response()->json(['success' => true, 'data' => VehicleItem::findOrFail($id)]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$data = $request->validate([
|
|
'nama' => 'required|string|max:100',
|
|
'short_cut' => 'required|string|max:16',
|
|
]);
|
|
|
|
$vehicle = VehicleItem::findOrFail($id);
|
|
$vehicle->update([
|
|
'nama' => $data['nama'],
|
|
'short_cut' => strtoupper($data['short_cut']),
|
|
]);
|
|
|
|
return response()->json(['success' => true, 'message' => 'Jenis kendaraan berhasil diperbarui.', 'data' => $vehicle]);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
DB::transaction(function () use ($id) {
|
|
MasterTarif::where('id_mobil', $id)->delete();
|
|
VehicleItem::findOrFail($id)->delete();
|
|
});
|
|
|
|
return response()->json(['success' => true, 'message' => 'Jenis kendaraan dan tarif terkait berhasil dihapus.']);
|
|
}
|
|
}
|