From 786f5476e68362aa0f1309015cde799d14658986 Mon Sep 17 00:00:00 2001 From: Gunawan19621 Date: Mon, 4 Dec 2023 22:03:39 +0700 Subject: [PATCH] update select menggunakan select2 --- app/Http/Controllers/DisposalController.php | 30 ++++++++ app/Http/Controllers/PeminjamanController.php | 35 ++++----- app/Http/Controllers/TransferController.php | 29 +++++++- .../views/dashboard/Disposal/create.blade.php | 58 ++++++++++++++- .../dashboard/Peminjaman/create.blade.php | 74 ++++++++++++------- .../views/dashboard/Transfer/create.blade.php | 56 +++++++++++++- routes/web.php | 2 + 7 files changed, 229 insertions(+), 55 deletions(-) diff --git a/app/Http/Controllers/DisposalController.php b/app/Http/Controllers/DisposalController.php index 0d7e07b..59c2174 100644 --- a/app/Http/Controllers/DisposalController.php +++ b/app/Http/Controllers/DisposalController.php @@ -6,7 +6,9 @@ use App\Models\Peti; use App\Models\Customer; use App\Models\Disposal; use App\Models\m_warehouse; +use Illuminate\Http\Request; use Symfony\Component\Uid\Uuid; +use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Auth; use App\Http\Requests\Disposal\ValidasiCreateDisposal; use App\Http\Requests\Disposal\ValidasiUpdateDisposal; @@ -164,4 +166,32 @@ class DisposalController extends Controller return redirect()->back()->with('error', 'Data disposal peti gagal dihapus'); } } + + /** + * Search peti by fix_lot + */ + public function autoCompleteSearch(Request $request): JsonResponse + { + $petiData = []; + $customerData = []; + + if ($request->filled('q')) { + $petiData = Peti::select("fix_lot", "id") + ->where('fix_lot', 'LIKE', '%' . $request->get('q') . '%') + ->where(function ($query) { + $query->whereHas('assetStatuses', function ($subquery) { + $subquery->where('status', '!=', 0) + ->where('created_at', '=', function ($maxQuery) { + $maxQuery->selectRaw('MAX(created_at)') + ->from('asset_statuses') + ->whereColumn('peti_id', 'petis.id'); + }); + })->orWhereDoesntHave('assetStatuses'); + }) + ->where('status', 'AKTIF') + ->get(); + } + + return response()->json(['peti' => $petiData, 'customer' => $customerData]); + } } diff --git a/app/Http/Controllers/PeminjamanController.php b/app/Http/Controllers/PeminjamanController.php index 5888e50..c3a784c 100644 --- a/app/Http/Controllers/PeminjamanController.php +++ b/app/Http/Controllers/PeminjamanController.php @@ -20,18 +20,6 @@ class PeminjamanController extends Controller /** * Display a listing of the resource. */ - // public function index() - // { - - // $data = [ - // // 'peminjaman' => asset_status::get(), - // 'peminjaman' => asset_status::orderBy('created_at', 'desc')->get(), - // 'warehouse' => m_warehouse::get(), - // 'active' => 'menu-peminjaman', - // ]; - - // return view('dashboard.Peminjaman.index', $data); - // } public function index(Request $request) { $perPage = $request->input('perPage', 5); @@ -223,19 +211,26 @@ class PeminjamanController extends Controller public function autoCompleteSearch(Request $request): JsonResponse { - $data = []; + $petiData = []; + $customerData = []; if ($request->filled('q')) { - $data = Peti::select("fix_lot", "id") + $petiData = Peti::select("fix_lot", "id") ->where('fix_lot', 'LIKE', '%' . $request->get('q') . '%') + ->where(function ($query) { + $query->whereHas('assetStatuses', function ($subquery) { + $subquery->where('status', '!=', 0) + ->where('created_at', '=', function ($maxQuery) { + $maxQuery->selectRaw('MAX(created_at)') + ->from('asset_statuses') + ->whereColumn('peti_id', 'petis.id'); + }); + })->orWhereDoesntHave('assetStatuses'); + }) + ->where('status', 'AKTIF') ->get(); } - // if ($request->filled('q')) { - // $data = Peti::select("fix_lot", "id", "warehouse_id as warehouseId", "customer_id as customerId") - // ->where('fix_lot', 'LIKE', '%' . $request->get('q') . '%') - // ->get(); - // } - return response()->json($data); + return response()->json(['peti' => $petiData, 'customer' => $customerData]); } } diff --git a/app/Http/Controllers/TransferController.php b/app/Http/Controllers/TransferController.php index 462f4ff..4a35337 100644 --- a/app/Http/Controllers/TransferController.php +++ b/app/Http/Controllers/TransferController.php @@ -3,11 +3,12 @@ namespace App\Http\Controllers; use App\Models\Peti; -use Symfony\Component\Uid\Uuid; use App\Models\Customer; use App\Models\Transfer; use App\Models\m_warehouse; use Illuminate\Http\Request; +use Symfony\Component\Uid\Uuid; +use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Auth; use App\Http\Requests\Transfer\ValidasiCreateTransfer; use App\Http\Requests\Transfer\ValidasiUpdateTransfer; @@ -220,4 +221,30 @@ class TransferController extends Controller return redirect()->back()->with('error', 'Data transfer peti gagal dihapus'); } } + + // Proses select2 autocomplete + public function autoCompleteSearch(Request $request): JsonResponse + { + $petiData = []; + $customerData = []; + + if ($request->filled('q')) { + $petiData = Peti::select("fix_lot", "id") + ->where('fix_lot', 'LIKE', '%' . $request->get('q') . '%') + ->where(function ($query) { + $query->whereHas('assetStatuses', function ($subquery) { + $subquery->where('status', '!=', 0) + ->where('created_at', '=', function ($maxQuery) { + $maxQuery->selectRaw('MAX(created_at)') + ->from('asset_statuses') + ->whereColumn('peti_id', 'petis.id'); + }); + })->orWhereDoesntHave('assetStatuses'); + }) + ->where('status', 'AKTIF') + ->get(); + } + + return response()->json(['peti' => $petiData, 'customer' => $customerData]); + } } diff --git a/resources/views/dashboard/Disposal/create.blade.php b/resources/views/dashboard/Disposal/create.blade.php index 8c7254a..c3f0563 100644 --- a/resources/views/dashboard/Disposal/create.blade.php +++ b/resources/views/dashboard/Disposal/create.blade.php @@ -16,7 +16,8 @@
- + {{-- + --}} - + @foreach ($warehouse as $data) @endforeach @@ -67,6 +68,55 @@
+ + + + {{-- --}} + + @@ -222,29 +237,34 @@ customerSelect.value = customerId; }); --}} + + {{-- --}} - - @endsection diff --git a/resources/views/dashboard/Transfer/create.blade.php b/resources/views/dashboard/Transfer/create.blade.php index 1a2cd0b..abadd7e 100644 --- a/resources/views/dashboard/Transfer/create.blade.php +++ b/resources/views/dashboard/Transfer/create.blade.php @@ -16,7 +16,8 @@
- + {{-- + --}} @@ -42,7 +43,7 @@