TestTransactionController.php 3.6KB

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