Penambahan login cashier via API, perhitungan tarif
This commit is contained in:
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Cashier;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\JenisMobil;
|
||||
use App\Models\NamaPos;
|
||||
use App\Models\Pegawai;
|
||||
use App\Models\Softseting;
|
||||
use App\Services\Parking\geTransaksi;
|
||||
use App\Services\Parking\RateParkingService;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use function GuzzleHttp\json_encode;
|
||||
|
||||
class CashierOperationController extends Controller
|
||||
{
|
||||
public function login(Request $request)
|
||||
{
|
||||
$username = $request->username;
|
||||
$password = $request->password;
|
||||
$gateStatus = $request->idpintu;
|
||||
|
||||
$user = Pegawai::where("username", $username)->where("password", $password)->first();
|
||||
|
||||
$gateId = NamaPos::with("posHardware", "posParams")->where("id", $gateStatus)->first();
|
||||
|
||||
if (!$gateId) {
|
||||
return response()->json([
|
||||
"status" => false,
|
||||
"message" => "ID Pintu tidak ditemukan",
|
||||
]);
|
||||
}
|
||||
|
||||
$globalSetting = Softseting::first();
|
||||
|
||||
$shortcutVeh = explode(",", $gateId->posParams->kend_valid);
|
||||
|
||||
$kendValid = JenisMobil::whereIn("id", $shortcutVeh)->orderBy("id")->get();
|
||||
|
||||
if (!$user) {
|
||||
return response()->json([
|
||||
"status" => false,
|
||||
"message" => "Username dan Password salah atau user tidak aktif",
|
||||
]);
|
||||
}
|
||||
|
||||
Log::info("Login user " . $user->nama . " berhasil.");
|
||||
|
||||
$fotoPegawai = $user->foto;
|
||||
|
||||
Log::info([
|
||||
"type" => gettype($fotoPegawai),
|
||||
"resource" => is_resource($fotoPegawai),
|
||||
"length" => is_string($fotoPegawai) ? strlen($fotoPegawai) : null,
|
||||
]);
|
||||
|
||||
if (is_resource($fotoPegawai)) {
|
||||
// $pegawaiFilename = $user->username;
|
||||
rewind($fotoPegawai);
|
||||
$fotoPegawai = stream_get_contents($fotoPegawai);
|
||||
} else {
|
||||
$user->foto = url(Storage::url("images/pegawai/no-image.jpg"));
|
||||
}
|
||||
|
||||
// $fotoPegawai = pg_unescape_bytea($fotoPegawai);
|
||||
// $foto = stream_get_contents($fotoPegawai);
|
||||
|
||||
// file_put_contents(storage_path("app/debug_before.bin"), $foto);
|
||||
|
||||
// file_put_contents(
|
||||
// storage_path("app/debug_after.bin"),
|
||||
// pg_unescape_bytea($foto),
|
||||
// );
|
||||
|
||||
// $raw = stream_get_contents($fotoPegawai);
|
||||
|
||||
// Log::info([
|
||||
// "raw_size" => strlen($raw),
|
||||
// ]);
|
||||
|
||||
// $binary = pg_unescape_bytea($raw);
|
||||
|
||||
// Log::info([
|
||||
// "binary_size" => strlen($binary),
|
||||
// ]);
|
||||
|
||||
// Log::info([
|
||||
// "resource" => is_resource($fotoPegawai),
|
||||
// "type" => gettype($fotoPegawai),
|
||||
// "size" => is_string($fotoPegawai) ? strlen($fotoPegawai) : null,
|
||||
// "hex" => bin2hex(substr($fotoPegawai, 0, 100)),
|
||||
// "before" => bin2hex(substr($fotoPegawai, 0, 16)),
|
||||
// // "after" => bin2hex(substr($decoded, 0, 16)),
|
||||
// ]);
|
||||
|
||||
if (!empty($fotoPegawai)) {
|
||||
$filename = "pegawai_" . $user->nomer . ".jpg";
|
||||
|
||||
$result = Storage::disk("public")->put("images/pegawai/" . $filename, $fotoPegawai);
|
||||
|
||||
Log::info(["save" => $result]);
|
||||
|
||||
$user->foto = url(Storage::url("images/pegawai/" . $filename));
|
||||
}
|
||||
// Log::info($user->toArray());
|
||||
|
||||
return response()->json([
|
||||
"status" => true,
|
||||
"message" => "Login berhasil",
|
||||
"data" => [
|
||||
"user" => $user,
|
||||
"gate" => $gateId,
|
||||
"settings" => $globalSetting,
|
||||
"vehicleValid" => $kendValid,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
function checkMember(Request $request)
|
||||
{
|
||||
Log::info($request->input("transaksi"));
|
||||
$getMember = new geTransaksi();
|
||||
$data = $getMember->TransaksiMember($request->input("transaksi"));
|
||||
|
||||
if (!$data) {
|
||||
return response()->json([
|
||||
"success" => false,
|
||||
"message" => "Transaksi member tidak ditemukan",
|
||||
]);
|
||||
}
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"data" => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
function transaksiInside(Request $request)
|
||||
{
|
||||
Log::info("Transaksi di input : " . $request->input("transaksi"));
|
||||
$gateOut = $request->input("idpintu");
|
||||
$vehicle = $request->input("kendaraan");
|
||||
$licensePlate = $request->input("platNomer");
|
||||
$gettransaksi = new geTransaksi();
|
||||
$dateNow = Carbon::now()->format("Y-m-d HH:mm:ss");
|
||||
Log::info("Kendaraan di pilih : " . $vehicle);
|
||||
|
||||
$Transaksi = $gettransaksi->TransaksiParkir($request->input("transaksi"));
|
||||
|
||||
if (!$Transaksi) {
|
||||
Log::info("Transaksi tidak ditemukan : " . json_encode($Transaksi));
|
||||
return response()->json([
|
||||
"success" => false,
|
||||
"message" => "Transaksi tidak ditemukan",
|
||||
]);
|
||||
}
|
||||
|
||||
Log::info("Transaksi ditemukan : " . json_encode($Transaksi));
|
||||
$waktu_masuk = Str::of($Transaksi->waktu_masuk)->trim();
|
||||
|
||||
$timeInSecond = Carbon::parse($waktu_masuk);
|
||||
$timeOutSecond = Carbon::now();
|
||||
$duration = $timeInSecond->diffInSeconds($timeOutSecond);
|
||||
|
||||
$hitungTarif = new RateParkingService();
|
||||
|
||||
[$duration, $tarifParkir] = $hitungTarif->parkingTimeCalc($vehicle, $duration);
|
||||
|
||||
$Transaksi["waktu_keluar"] = $timeOutSecond->format("Y-m-d H:i:s");
|
||||
$Transaksi["bayar_keluar"] = (int) $tarifParkir;
|
||||
$Transaksi["id_pintu_keluar"] = $gateOut;
|
||||
Log::info("jam masuk : " . $timeInSecond);
|
||||
Log::info("jam keluar : " . $timeOutSecond);
|
||||
Log::info("Lama parkir dalam detik : " . $duration);
|
||||
Log::info("Tarif transaksi : " . $tarifParkir);
|
||||
|
||||
return response()->json([
|
||||
"success" => true,
|
||||
"data" => $Transaksi,
|
||||
]);
|
||||
}
|
||||
|
||||
// function transaksiProcess(Request $request)
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ParkingOperationConteroller extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\TransaksiParkir;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Parking\geTransaksiParkir;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -14,9 +15,60 @@ class ParkingOperationController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function inTransaksi($data)
|
||||
{
|
||||
Log::info('Memulai proses pintu masuk : ' . $data);
|
||||
$service = new geTransaksiParkir();
|
||||
$data = $service->TransaksiParkir($data);
|
||||
|
||||
Log::info('Hasil : ' . $data);
|
||||
|
||||
if ($data) {
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Kendaraan masih didalam',
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
$data = $service->TransaksiMember($data);
|
||||
|
||||
// if (!$data) {
|
||||
// // store ke function/ insert ke database
|
||||
// $memberActive = $service->TransaksiMember($data);
|
||||
// // if (!$memberActive)
|
||||
// }
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
public function outTransaksi($data, geTransaksiParkir $TransaksiParkir)
|
||||
{
|
||||
$data = $TransaksiParkir->TransaksiParkir($data);
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
|
||||
return TransaksiParkir::selectRaw(
|
||||
'transaksi_parkir.id::VARCHAR as id,
|
||||
no_pol,
|
||||
id_kendaraan,
|
||||
id_pintu_masuk,
|
||||
id_pintu_keluar,
|
||||
waktu_masuk,
|
||||
waktu_keluar,
|
||||
bayar_keluar,
|
||||
jm.nama',
|
||||
)->leftJoin('jenis_mobil as jm','transaksi_parkir.id_kendaraan','=','jm.id')
|
||||
// ->where('status', 1)
|
||||
->orderByDesc('waktu_masuk')
|
||||
->limit(50)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,15 +89,25 @@ public function create()
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$transaksi = $this->show($request->input('transaksi'))->getData();
|
||||
|
||||
// dd($transaksi)->status;
|
||||
// dd($transaksi->getData());
|
||||
Log::info(get_class($transaksi));
|
||||
dd(get_class($transaksi));
|
||||
// if ($transaksi->status === true && $transaksi->member === false) {
|
||||
// }
|
||||
return;
|
||||
$gateStatus = $request->input('gate');
|
||||
$no_pol = $request->input('transaksi');
|
||||
Log::info($no_pol);
|
||||
|
||||
if ($gateStatus == 0) {
|
||||
|
||||
$transaksiIn = $this->inTransaksi($no_pol);
|
||||
|
||||
if ($transaksiIn) {
|
||||
return $transaksiIn;
|
||||
}
|
||||
|
||||
$transaksi = $this->store($no_pol);
|
||||
}
|
||||
// Log::info($data);
|
||||
|
||||
return response()->json([
|
||||
// 'data' => $data
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user