TestTransactionController.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\TestTransaction\StoreTestTransactionRequest;
  5. use App\Models\EntryTransaction;
  6. use App\Models\OutTransaction;
  7. use App\Models\ParkingFee;
  8. use App\Models\TypeVehicle;
  9. use Carbon\Carbon;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Str;
  12. class TestTransactionController extends Controller
  13. {
  14. /**
  15. * Display a listing of the resource.
  16. *
  17. * @return \Illuminate\Http\Response
  18. */
  19. public function index()
  20. {
  21. //
  22. }
  23. /**
  24. * Show the form for creating a new resource.
  25. *
  26. * @return \Inertia\Response
  27. */
  28. public function create()
  29. {
  30. $entryTransactions = EntryTransaction::whereNotIn('transaction_number', OutTransaction::pluck('entry_transaction_id'))
  31. ->latest()
  32. ->paginate(5)
  33. ->withQueryString()
  34. ->through(fn($transactionIn) => [
  35. 'id' => $transactionIn->id,
  36. 'createdAt' => $transactionIn->created_at,
  37. 'transactionNumber' => $transactionIn->transaction_number,
  38. ]);
  39. $entryTransactionCount = EntryTransaction::get()->count();
  40. $outTransactions = OutTransaction::latest()
  41. ->paginate(5)
  42. ->withQueryString()
  43. ->through(fn($transactionOut) => [
  44. 'id' => $transactionOut->id,
  45. 'createdAt' => $transactionOut->created_at,
  46. 'entryTransactionId' => $transactionOut->entry_transaction_id,
  47. ]);
  48. $outTransactionCount = OutTransaction::get()->count();
  49. $typeVehicles = TypeVehicle::get()->transform(fn($typeVehicle) => [
  50. 'value' => $typeVehicle->id,
  51. 'label' => $typeVehicle->type,
  52. ]);
  53. return inertia('test-transaction/Create.vue', compact([
  54. 'entryTransactions',
  55. 'entryTransactionCount',
  56. 'outTransactions',
  57. 'outTransactionCount',
  58. 'typeVehicles',
  59. ]));
  60. }
  61. /**
  62. * Store a newly created resource in storage.
  63. *
  64. * @param \Illuminate\Http\Request $request
  65. * @return \Illuminate\Http\Response
  66. */
  67. public function store(StoreTestTransactionRequest $request)
  68. {
  69. if ($request->id === 2) {
  70. $entryTransactions = EntryTransaction::where('transaction_number', $request->entry_transaction_id)->first();
  71. $vehicleEntryTime = $entryTransactions->getRawOriginal('created_at');
  72. $longParkingPerHours = Carbon::parse($vehicleEntryTime)->floatDiffInRealHours(now());
  73. $parkingFee = ParkingFee::get();
  74. return;
  75. } else {
  76. EntryTransaction::create([
  77. 'transaction_number' => Str::uuid(),
  78. ]);
  79. return back()->with('success', __('messages.success.store.transaction'));
  80. }
  81. }
  82. /**
  83. * Display the specified resource.
  84. *
  85. * @param int $id
  86. * @return \Illuminate\Http\Response
  87. */
  88. public function show($id)
  89. {
  90. //
  91. }
  92. /**
  93. * Show the form for editing the specified resource.
  94. *
  95. * @param int $id
  96. * @return \Illuminate\Http\Response
  97. */
  98. public function edit($id)
  99. {
  100. //
  101. }
  102. /**
  103. * Update the specified resource in storage.
  104. *
  105. * @param \Illuminate\Http\Request $request
  106. * @param int $id
  107. * @return \Illuminate\Http\Response
  108. */
  109. public function update(Request $request, $id)
  110. {
  111. //
  112. }
  113. /**
  114. * Remove the specified resource from storage.
  115. *
  116. * @param int $id
  117. * @return \Illuminate\Http\Response
  118. */
  119. public function destroy($id)
  120. {
  121. //
  122. }
  123. }