| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Http\Controllers\Controller;
- use App\Http\Requests\TestTransaction\StoreTestTransactionRequest;
- use App\Models\EntryTransaction;
- use App\Models\OutTransaction;
- use App\Models\ParkingFee;
- use App\Models\TypeVehicle;
- use App\Models\Vehicle;
- use Carbon\Carbon;
- use Illuminate\Http\Request;
- use Illuminate\Support\Str;
-
- class TestTransactionController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- //
- }
-
- /**
- * Show the form for creating a new resource.
- *
- * @return \Inertia\Response
- */
- public function create()
- {
- $entryTransactions = EntryTransaction::whereNotIn('transaction_number', OutTransaction::pluck('entry_transaction_id'))
- ->latest()
- ->paginate(5)
- ->withQueryString()
- ->through(fn($transactionIn) => [
- 'id' => $transactionIn->id,
- 'createdAt' => $transactionIn->created_at,
- 'transactionNumber' => $transactionIn->transaction_number,
- ]);
-
- $entryTransactionCount = EntryTransaction::get()->count();
-
- $outTransactions = OutTransaction::latest()
- ->paginate(5)
- ->withQueryString()
- ->through(fn($transactionOut) => [
- 'id' => $transactionOut->id,
- 'createdAt' => $transactionOut->created_at,
- 'platNumber' => $transactionOut->plat_number,
- 'entryTransactionId' => $transactionOut->entry_transaction_id,
- ]);
-
- $outTransactionCount = OutTransaction::get()->count();
-
- $typeVehicles = TypeVehicle::get()->transform(fn($typeVehicle) => [
- 'value' => $typeVehicle->id,
- 'label' => $typeVehicle->type,
- ]);
-
- return inertia('test-transaction/Create.vue', compact([
- 'entryTransactions',
- 'entryTransactionCount',
- 'outTransactions',
- 'outTransactionCount',
- 'typeVehicles',
- ]));
- }
-
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(StoreTestTransactionRequest $request)
- {
- if ($request->id === 2) {
- $vehicle = Vehicle::where('plat_number', $request->plat_number)->first();
-
- // Check member or not
- if ($vehicle && $vehicle->member_id) {
- $expDate = $vehicle->member->getRawOriginal('exp_date');
-
- // Check expired member or not
- $exp = !Carbon::parse($expDate)->greaterThanOrEqualTo(now());
-
- if ($exp) {
- return back()->with('warning', __('words.member_expired'));
- }
-
- OutTransaction::create([
- 'plat_number' => $request->plat_number,
- 'entry_transaction_id' => $request->entry_transaction_id,
- 'type_vehicle_id' => $vehicle->type_vehicle_id,
- 'user_id' => auth()->user()->id,
- ]);
-
- return back()->with('success', __('messages.success.store.out_transaction'));
- } else {
- $entryTransactions = EntryTransaction::where('transaction_number', $request->entry_transaction_id)->first();
-
- $vehicleEntryTime = $entryTransactions->getRawOriginal('created_at');
-
- $longParkingPerHours = Carbon::parse($vehicleEntryTime)->floatDiffInRealHours(now());
-
- $parkingFee = ParkingFee::get();
-
- return back()->with('success', __('messages.success.store.out_transaction'));
- }
- } else {
- EntryTransaction::create([
- 'transaction_number' => Str::uuid(),
- ]);
-
- return back()->with('success', __('messages.success.store.transaction'));
- }
- }
-
- /**
- * 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)
- {
- //
- }
- }
|