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
231 lines
6.7 KiB
PHP
231 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\ParkingLot;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\LotParking\SiteParking;
|
|
use App\Models\LotParking\LotParkingLog;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ParkingLotController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$getArea = SiteParking::all(); // Mengambil semua data dari model SiteParking
|
|
$parkingDataByArea = []; // Array untuk menyimpan hasil query berdasarkan area
|
|
|
|
foreach ($getArea as $lantai) {
|
|
$spaceParking = $lantai->space_parking;
|
|
|
|
// Array untuk menyimpan data parking per lantai
|
|
$parkingData = [];
|
|
|
|
for ($lotNumber = 1; $lotNumber <= $spaceParking; $lotNumber++) {
|
|
// Melakukan query pada LotParkingLog berdasarkan area dan lot_number
|
|
$log = LotParkingLog::where("area", $lantai->sitearea_id)
|
|
->where("lot_number", $lotNumber)
|
|
->select("lot_number", "status")
|
|
->first();
|
|
|
|
// Jika data tidak ditemukan, buat object baru dengan lot_number dari pengulangan for
|
|
if (!$log) {
|
|
$log = (object) [
|
|
"lot_number" => $lotNumber,
|
|
"status" => 0,
|
|
];
|
|
}
|
|
|
|
// Menyimpan hasil query dalam array
|
|
$parkingData[] = $log;
|
|
}
|
|
|
|
// Menyimpan data parking per lantai dalam array berdasarkan area
|
|
$parkingDataByArea[] = [
|
|
"lantai" => $lantai->sitearea_id,
|
|
"data" => $parkingData,
|
|
];
|
|
}
|
|
|
|
// Melakukan dump and die untuk melihat hasil query sementara
|
|
// dd(json_encode($parkingDataByArea));
|
|
// dd($getArea->toJson());
|
|
return view("headoffice.space", [
|
|
"areas" => $getArea,
|
|
"parkingDataByArea" => $parkingDataByArea,
|
|
]);
|
|
|
|
return view("headoffice.space");
|
|
}
|
|
|
|
public function getParkingData()
|
|
{
|
|
Log::info("getParkingData method called");
|
|
|
|
$getArea = SiteParking::all(); // Mengambil semua data dari model SiteParking
|
|
$parkingDataByArea = []; // Array untuk menyimpan hasil query berdasarkan area
|
|
|
|
foreach ($getArea as $lantai) {
|
|
$spaceParking = $lantai->space_parking;
|
|
|
|
// Array untuk menyimpan data parking per lantai
|
|
$parkingData = [];
|
|
|
|
for ($lotNumber = 1; $lotNumber <= $spaceParking; $lotNumber++) {
|
|
// Melakukan query pada LotParkingLog berdasarkan area dan lot_number
|
|
$log = LotParkingLog::where("area", $lantai->sitearea_id)
|
|
->where("lot_number", $lotNumber)
|
|
->select("lot_number", "status")
|
|
->first();
|
|
|
|
// Jika data tidak ditemukan, buat object baru dengan lot_number dari pengulangan for
|
|
if (!$log) {
|
|
$log = (object) [
|
|
"lot_number" => $lotNumber,
|
|
"status" => 0,
|
|
];
|
|
}
|
|
|
|
// Menyimpan hasil query dalam array
|
|
$parkingData[] = $log;
|
|
}
|
|
|
|
// Menyimpan data parking per lantai dalam array berdasarkan area
|
|
$parkingDataByArea[] = [
|
|
"lantai" => $lantai->sitearea_id,
|
|
"data" => $parkingData,
|
|
];
|
|
|
|
Log::info($parkingDataByArea);
|
|
}
|
|
|
|
return response()->json($parkingDataByArea);
|
|
}
|
|
|
|
/**
|
|
* 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)
|
|
{
|
|
$area = $request->site_area;
|
|
$lotNumber = $request->lot_number;
|
|
Log::info($area);
|
|
Log::info($lotNumber);
|
|
$exisLot = LotParkingLog::where("area", $area)->where("lot_number", $lotNumber)->where("status", 1)->first();
|
|
|
|
if (!$exisLot) {
|
|
$LotParking = LotParkingLog::create([
|
|
"area" => $area,
|
|
"lot_number" => $lotNumber,
|
|
"status" => 1,
|
|
"update_at" => null,
|
|
]);
|
|
|
|
Log::info("Lot " . $lotNumber . " di " . $area . " terisi.");
|
|
|
|
return response()->json([
|
|
"status" => "success",
|
|
"message" => "Lot No " . $lotNumber . " terisi",
|
|
"data" => $LotParking,
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
"status" => "error",
|
|
"message" => "Kendaraan belum keluar",
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request)
|
|
{
|
|
Log::info(json_encode($request->all()));
|
|
$area = $request->site_area;
|
|
$lotNumber = $request->lot_number;
|
|
Log::info($area);
|
|
Log::info($lotNumber);
|
|
$exisLot = LotParkingLog::where("area", $area)
|
|
->where("lot_number", $lotNumber)
|
|
->where("status", 1)
|
|
->orderBy("updated_at", "desc")
|
|
->first();
|
|
|
|
if (!$exisLot) {
|
|
return response()->json([
|
|
"status" => "error",
|
|
"message" => "Lot masih kosong",
|
|
]);
|
|
} else {
|
|
$exisLot->update([
|
|
"status" => 0,
|
|
]);
|
|
|
|
Log::info("Lot " . $lotNumber . " di " . $area . " keluar area.");
|
|
|
|
return response()->json([
|
|
"status" => "success",
|
|
"message" => "Kendaraan telah keluar",
|
|
"data" => $exisLot,
|
|
]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
}
|