Rapihin setup/member/lot-parking + fitur intercom, exclude WIP controller & file sampah dari git
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
This commit is contained in:
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Parking\Setup\Gate;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Parking\NetworkService;
|
||||
use App\Models\ConfigPosNetwork;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class MasterConfigNetworkController extends Controller
|
||||
{
|
||||
public function index(NetworkService $dhcp)
|
||||
{
|
||||
$reservations = ConfigPosNetwork::orderBy("hostname")->get();
|
||||
|
||||
$dhcpStatus = $dhcp->status();
|
||||
|
||||
return view("setup.index", compact("reservations", "dhcpStatus"));
|
||||
}
|
||||
|
||||
public function status(NetworkService $dhcp)
|
||||
{
|
||||
return response()->json($dhcp->status());
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
"hostname" => ["required", "string", "max:100", 'regex:/^[a-zA-Z0-9_-]+$/'],
|
||||
|
||||
"mac_address" => ["required", "string", 'regex:/^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$/'],
|
||||
|
||||
"ip_address" => ["required", "ip"],
|
||||
|
||||
"enabled" => ["nullable", "boolean"],
|
||||
]);
|
||||
|
||||
$data["mac_address"] = strtoupper($data["mac_address"]);
|
||||
|
||||
$data["enabled"] = $request->boolean("enabled");
|
||||
|
||||
// Cek duplicate MAC
|
||||
if (ConfigPosNetwork::where("mac_address", $data["mac_address"])->exists()) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "MAC address already registered.",
|
||||
],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
// Cek duplicate IP
|
||||
if (ConfigPosNetwork::where("ip_address", $data["ip_address"])->exists()) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "IP address already registered.",
|
||||
],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
$reservation = ConfigPosNetwork::create($data);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
"success" => true,
|
||||
"message" => "DHCP reservation created successfully.",
|
||||
"data" => $reservation,
|
||||
],
|
||||
201,
|
||||
);
|
||||
}
|
||||
|
||||
public function update(Request $request, ConfigPosNetwork $reservation)
|
||||
{
|
||||
$data = $request->validate([
|
||||
"hostname" => ["required", "string", "max:100", 'regex:/^[a-zA-Z0-9_-]+$/'],
|
||||
|
||||
"mac_address" => ["required", "string", 'regex:/^([0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}$/'],
|
||||
|
||||
"ip_address" => ["required", "ip"],
|
||||
|
||||
"enabled" => ["nullable", "boolean"],
|
||||
]);
|
||||
|
||||
$data["mac_address"] = strtoupper($data["mac_address"]);
|
||||
|
||||
$data["enabled"] = $request->boolean("enabled");
|
||||
|
||||
// Cek duplicate MAC,
|
||||
// kecuali reservation yang sedang diedit
|
||||
if (
|
||||
ConfigPosNetwork::where("mac_address", $data["mac_address"])->where("id", "!=", $reservation->id)->exists()
|
||||
) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "MAC address already registered.",
|
||||
],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
// Cek duplicate IP
|
||||
if (ConfigPosNetwork::where("ip_address", $data["ip_address"])->where("id", "!=", $reservation->id)->exists()) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "IP address already registered.",
|
||||
],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
$reservation->update($data);
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"message" => "DHCP reservation updated successfully.",
|
||||
"data" => $reservation->fresh(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(ConfigPosNetwork $reservation)
|
||||
{
|
||||
$reservation->delete();
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"message" => "Reservation deleted successfully.",
|
||||
]);
|
||||
}
|
||||
|
||||
public function test(NetworkService $dhcp)
|
||||
{
|
||||
try {
|
||||
$result = $dhcp->test();
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"message" => "DHCP configuration is valid.",
|
||||
"data" => $result,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => $e->getMessage(),
|
||||
],
|
||||
422,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function apply(NetworkService $dhcp)
|
||||
{
|
||||
try {
|
||||
$dhcp->apply();
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"message" => "DHCP configuration applied successfully.",
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => $e->getMessage(),
|
||||
],
|
||||
500,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function logs(NetworkService $dhcp)
|
||||
{
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"logs" => $dhcp->logs(30),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ConfigHardware;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class MasterGateHardwareController extends Controller
|
||||
{
|
||||
@@ -48,9 +47,11 @@ public function store(Request $request)
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
Log::info($id);
|
||||
// # ambil konfigurasi hardware berdasarkan id_pos (id pintu)
|
||||
$gateDetails = ConfigHardware::where('id_pos', $id)->first();
|
||||
return $gateDetails;
|
||||
|
||||
// # kalau belum ada datanya, kembalikan objek kosong biar form tetap kebuka
|
||||
return response()->json($gateDetails ?? (object) []);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,8 +74,26 @@ public function edit($id)
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
Log::info($id);
|
||||
Log::info($request->all());
|
||||
// # hanya kolom yang terdaftar di fillable yang boleh disimpan
|
||||
$allowed = (new ConfigHardware())->getFillable();
|
||||
$data = $request->input('data', []);
|
||||
|
||||
$filtered = [];
|
||||
foreach ((array) $data as $key => $value) {
|
||||
if (in_array($key, $allowed, true)) {
|
||||
// # ubah string kosong jadi null biar cocok dengan kolom integer
|
||||
$filtered[$key] = $value === '' ? null : $value;
|
||||
}
|
||||
}
|
||||
|
||||
// # simpan (buat baru kalau id_pos belum punya baris hardware)
|
||||
$hardware = ConfigHardware::updateOrCreate(['id_pos' => $id], $filtered);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Konfigurasi hardware berhasil disimpan.',
|
||||
'data' => $hardware,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Parking\Setup\Member;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use App\Models\Origin\MasterTarifStiker;
|
||||
use App\Models\Origin\MasterStasiunKerja;
|
||||
use App\Models\Origin\MasterJenisLangganan;
|
||||
|
||||
class MasterTarifStikerController extends Controller
|
||||
{
|
||||
/**
|
||||
* Halaman utama. Data dropdown (stasiun kerja & jenis langganan)
|
||||
* di-load langsung di sini biar gak perlu request tambahan pas modal dibuka.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$stasiunKerjaList = MasterStasiunKerja::orderBy("kode")->get(["kode", "nama"]);
|
||||
$jenisLanggananList = MasterJenisLangganan::orderBy("id")->get(["id", "nama"]);
|
||||
|
||||
return view("Parking.setup.member.tarifstiker", compact("stasiunKerjaList", "jenisLanggananList"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ambil seluruh data tarif stiker, sekalian join nama stasiun kerja
|
||||
* biar gak perlu N+1 query pas render tabel.
|
||||
*/
|
||||
public function data(): JsonResponse
|
||||
{
|
||||
$data = MasterTarifStiker::with(["stasiunKerja:kode,nama"])
|
||||
->orderByDesc("tarif_id")
|
||||
->get();
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"data" => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ambil satu data berdasarkan tarif_id.
|
||||
*/
|
||||
public function show(string $tarif_id): JsonResponse
|
||||
{
|
||||
$item = MasterTarifStiker::with(["stasiunKerja:kode,nama"])->find($tarif_id);
|
||||
|
||||
if (!$item) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Data tarif stiker tidak ditemukan.",
|
||||
],
|
||||
404,
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"data" => $item,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simpan data tarif stiker baru.
|
||||
* tarif_id tidak wajib diisi dari form — kalau kosong, di-generate
|
||||
* otomatis (max(tarif_id) + 1) karena tabel ini tidak punya
|
||||
* auto-increment/serial asli di database.
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
"tarif_id" => ["nullable", "integer", "unique:tarif_stiker,tarif_id"],
|
||||
"id_mobil" => ["required", "string", "max:10"],
|
||||
"jenis_langganan" => ["required", "string", "max:50"],
|
||||
"tarif" => ["required", "numeric"],
|
||||
"last_member" => ["nullable", "string", "max:5"],
|
||||
"tgl_akhir" => ["nullable", "string", "max:2"],
|
||||
"jenis" => ["nullable", "string", "max:30"],
|
||||
"jenis_member" => ["nullable", "string", "max:50"],
|
||||
"hitung_awal_bulan" => ["nullable", "integer"],
|
||||
"available_online" => ["nullable", "boolean"],
|
||||
"langganan" => ["nullable", "string", "max:32", "exists:stasiunkerja,kode"],
|
||||
"kode_akses" => ["nullable", "string", "max:5"],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Validasi gagal.",
|
||||
"errors" => $validator->errors(),
|
||||
],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
$payload = $validator->validated();
|
||||
$payload["available_online"] = $request->boolean("available_online");
|
||||
|
||||
// Transaksi + lock untuk menghindari race condition kalau
|
||||
// ada 2 request bersamaan sama-sama generate tarif_id baru.
|
||||
$item = DB::transaction(function () use ($payload) {
|
||||
if (empty($payload["tarif_id"])) {
|
||||
$maxId = MasterTarifStiker::lockForUpdate()->max("tarif_id");
|
||||
$payload["tarif_id"] = ($maxId ?? 0) + 1;
|
||||
}
|
||||
|
||||
return MasterTarifStiker::create($payload);
|
||||
});
|
||||
|
||||
$item->load("stasiunKerja:kode,nama");
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
"success" => true,
|
||||
"message" => "Data tarif stiker berhasil ditambahkan.",
|
||||
"data" => $item,
|
||||
],
|
||||
201,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perbarui data tarif stiker berdasarkan tarif_id.
|
||||
*/
|
||||
public function update(Request $request, string $tarif_id): JsonResponse
|
||||
{
|
||||
$item = MasterTarifStiker::find($tarif_id);
|
||||
|
||||
if (!$item) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Data tarif stiker tidak ditemukan.",
|
||||
],
|
||||
404,
|
||||
);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
"id_mobil" => ["required", "string", "max:10"],
|
||||
"jenis_langganan" => ["required", "string", "max:50"],
|
||||
"tarif" => ["required", "numeric"],
|
||||
"last_member" => ["nullable", "string", "max:5"],
|
||||
"tgl_akhir" => ["nullable", "string", "max:2"],
|
||||
"jenis" => ["nullable", "string", "max:30"],
|
||||
"jenis_member" => ["nullable", "string", "max:50"],
|
||||
"hitung_awal_bulan" => ["nullable", "integer"],
|
||||
"available_online" => ["nullable", "boolean"],
|
||||
"langganan" => ["nullable", "string", "max:32", "exists:stasiunkerja,kode"],
|
||||
"kode_akses" => ["nullable", "string", "max:5"],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Validasi gagal.",
|
||||
"errors" => $validator->errors(),
|
||||
],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
$payload = $validator->validated();
|
||||
$payload["available_online"] = $request->boolean("available_online");
|
||||
|
||||
$item->update($payload);
|
||||
$item->load("stasiunKerja:kode,nama");
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"message" => "Data tarif stiker berhasil diperbarui.",
|
||||
"data" => $item,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus data tarif stiker berdasarkan tarif_id.
|
||||
*/
|
||||
public function destroy(string $tarif_id): JsonResponse
|
||||
{
|
||||
$item = MasterTarifStiker::find($tarif_id);
|
||||
|
||||
if (!$item) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Data tarif stiker tidak ditemukan.",
|
||||
],
|
||||
404,
|
||||
);
|
||||
}
|
||||
|
||||
$item->delete();
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"message" => "Data tarif stiker berhasil dihapus.",
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Parking\Setup\Member;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Origin\MasterStasiunKerja;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class StasiunKerjaController extends Controller
|
||||
{
|
||||
/**
|
||||
* Tampilkan halaman utama (view + tabel kosong, data di-load via JS).
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view("Parking.setup.member.stasiunkerja");
|
||||
}
|
||||
|
||||
/**
|
||||
* Ambil seluruh data stasiun kerja dalam format JSON.
|
||||
* Dipanggil via fetch() dari JS untuk mengisi tabel.
|
||||
*/
|
||||
public function data(): JsonResponse
|
||||
{
|
||||
$data = MasterStasiunKerja::orderBy("kode")->get();
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"data" => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ambil satu data berdasarkan kode (dipakai saat buka form edit).
|
||||
*/
|
||||
public function show(string $kode): JsonResponse
|
||||
{
|
||||
$item = MasterStasiunKerja::find($kode);
|
||||
|
||||
if (!$item) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Data stasiun kerja tidak ditemukan.",
|
||||
],
|
||||
404,
|
||||
);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"data" => $item,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simpan data stasiun kerja baru.
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validator = Validator::make($request->all(), [
|
||||
"kode" => ["required", "string", "max:50", Rule::unique("stasiunkerja", "kode")],
|
||||
"nama" => ["required", "string", "max:255"],
|
||||
"margin" => ["nullable", "integer"],
|
||||
"spv" => ["nullable", "string", "max:20"],
|
||||
"target" => ["nullable", "integer"],
|
||||
"id_lokasi" => ["nullable", "string", "max:10"],
|
||||
"lantai" => ["nullable", "string", "max:4"],
|
||||
"status" => ["nullable", "integer"],
|
||||
"alamat" => ["nullable", "string", "max:255"],
|
||||
"bank" => ["nullable", "string", "max:64"],
|
||||
"telp" => ["nullable", "string", "max:32"],
|
||||
"kode_akses" => ["nullable", "string", "max:5"],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Validasi gagal.",
|
||||
"errors" => $validator->errors(),
|
||||
],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
$item = MasterStasiunKerja::create($validator->validated());
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
"success" => true,
|
||||
"message" => "Data stasiun kerja berhasil ditambahkan.",
|
||||
"data" => $item,
|
||||
],
|
||||
201,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perbarui data stasiun kerja berdasarkan kode.
|
||||
*/
|
||||
public function update(Request $request, string $kode): JsonResponse
|
||||
{
|
||||
$item = MasterStasiunKerja::find($kode);
|
||||
|
||||
if (!$item) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Data stasiun kerja tidak ditemukan.",
|
||||
],
|
||||
404,
|
||||
);
|
||||
}
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
"nama" => ["required", "string", "max:255"],
|
||||
"margin" => ["nullable", "integer"],
|
||||
"spv" => ["nullable", "string", "max:20"],
|
||||
"target" => ["nullable", "integer"],
|
||||
"id_lokasi" => ["nullable", "string", "max:10"],
|
||||
"lantai" => ["nullable", "string", "max:4"],
|
||||
"status" => ["nullable", "integer"],
|
||||
"alamat" => ["nullable", "string", "max:255"],
|
||||
"bank" => ["nullable", "string", "max:64"],
|
||||
"telp" => ["nullable", "string", "max:32"],
|
||||
"kode_akses" => ["nullable", "string", "max:5"],
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Validasi gagal.",
|
||||
"errors" => $validator->errors(),
|
||||
],
|
||||
422,
|
||||
);
|
||||
}
|
||||
|
||||
$item->update($validator->validated());
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"message" => "Data stasiun kerja berhasil diperbarui.",
|
||||
"data" => $item,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hapus data stasiun kerja berdasarkan kode.
|
||||
*/
|
||||
public function destroy(string $kode): JsonResponse
|
||||
{
|
||||
$item = MasterStasiunKerja::find($kode);
|
||||
|
||||
if (!$item) {
|
||||
return response()->json(
|
||||
[
|
||||
"success" => false,
|
||||
"message" => "Data stasiun kerja tidak ditemukan.",
|
||||
],
|
||||
404,
|
||||
);
|
||||
}
|
||||
|
||||
$item->delete();
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"message" => "Data stasiun kerja berhasil dihapus.",
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
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
|
||||
{
|
||||
@@ -40,7 +42,38 @@ public function create()
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +84,10 @@ public function store(Request $request)
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
$vehicle = VehicleItem::findOrFail($id);
|
||||
$tarif = MasterTarif::find($id);
|
||||
|
||||
return response()->json(['success' => true, 'data' => $vehicle, 'tarif' => $tarif]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,7 +98,7 @@ public function show($id)
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
return response()->json(['success' => true, 'data' => VehicleItem::findOrFail($id)]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,7 +110,18 @@ public function edit($id)
|
||||
*/
|
||||
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]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,6 +132,11 @@ public function update(Request $request, $id)
|
||||
*/
|
||||
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.']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,13 @@ public function store(Request $request)
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
// Log::info($id);
|
||||
$id = str($id);
|
||||
$vehicleRates = DB::table("tarif")->where("id_mobil", $id)->first();
|
||||
$vehicleRates = DB::table("tarif")->where("id_mobil", (string) $id)->first();
|
||||
|
||||
Log::info(json_encode($vehicleRates));
|
||||
return $vehicleRates;
|
||||
if (!$vehicleRates) {
|
||||
return response()->json(['status' => false, 'message' => 'Tarif kendaraan tidak ditemukan.'], 404);
|
||||
}
|
||||
|
||||
return response()->json($vehicleRates);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,14 +78,43 @@ public function edit($id)
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
Log::info($request->all());
|
||||
// $id = $request->id_mobil;
|
||||
|
||||
$dataQuery = MasterTarif::find($id);
|
||||
try {
|
||||
Log::info($request->all());
|
||||
if (!$dataQuery) {
|
||||
return response()->json(['status' => false, 'message' => 'Tarif kendaraan tidak ditemukan.'], 404);
|
||||
}
|
||||
|
||||
$dataQuery->fill($request->all());
|
||||
$validated = $request->validate([
|
||||
'waktu_gratis' => 'nullable|integer|min:0',
|
||||
'tarif_period' => 'nullable|numeric|min:0',
|
||||
'frek_interval' => 'nullable|integer|min:1',
|
||||
'interval' => 'nullable|integer|min:1',
|
||||
'tarif_interval' => 'nullable|numeric|min:0',
|
||||
'bayar_dimuka' => 'nullable|boolean',
|
||||
'asuransi_incl' => 'nullable|numeric|min:0',
|
||||
'frek_waktu2' => 'nullable|integer|min:1',
|
||||
'waktu2' => 'nullable|integer|min:1',
|
||||
'tarif2' => 'nullable|numeric|min:0',
|
||||
'tarif' => 'required|numeric|min:0',
|
||||
'waktu_tarif' => 'nullable|integer|min:1',
|
||||
'maksimum' => 'nullable|numeric|min:0',
|
||||
'maksimum_mode' => 'required|in:hour,day',
|
||||
'maksimum_hour' => 'nullable|integer|min:1',
|
||||
'maksimum_day_minute' => 'nullable|integer|min:0',
|
||||
'denda' => 'nullable|numeric|min:0',
|
||||
'denda_member' => 'nullable|integer|min:0',
|
||||
'denda_only_casual' => 'nullable|boolean',
|
||||
'denda_only' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
try {
|
||||
$data = collect($validated)->except(['maksimum_mode', 'maksimum_hour', 'maksimum_day_minute'])->all();
|
||||
$data['time_base'] = $validated['maksimum_mode'] === 'hour' ? 1 : 0;
|
||||
$data['time_base_maks'] = $validated['maksimum_mode'] === 'hour' ? $validated['maksimum_hour'] : null;
|
||||
$data['min_per_hari'] = $validated['maksimum_mode'] === 'day' ? $validated['maksimum_day_minute'] : null;
|
||||
$data['denda_only_casual'] = $request->boolean('denda_only_casual') ? 1 : 0;
|
||||
$data['denda_only'] = $request->boolean('denda_only') ? 1 : 0;
|
||||
|
||||
$dataQuery->fill($data);
|
||||
|
||||
if (!$dataQuery->isDirty()) {
|
||||
return response()->json([
|
||||
@@ -92,7 +122,6 @@ public function update(Request $request, $id)
|
||||
"message" => "Tidak ada perubahan data",
|
||||
]);
|
||||
}
|
||||
Log::info("Data yang di simpan" . json_encode($dataQuery->getDirty()));
|
||||
$dataQuery->save();
|
||||
|
||||
return response()->json([
|
||||
@@ -100,10 +129,7 @@ public function update(Request $request, $id)
|
||||
"message" => "Data berhasil di ubah",
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
Log::info("Data yang di simpan" . json_encode($dataQuery->getDirty()));
|
||||
|
||||
// Log::info($request->all());
|
||||
|
||||
Log::error('Gagal memperbarui tarif kendaraan', ['id_mobil' => $id, 'error' => $th->getMessage()]);
|
||||
return response()->json([
|
||||
"status" => false,
|
||||
"message" => "Gagal menyimpan data " . $th->getMessage(),
|
||||
|
||||
Reference in New Issue
Block a user