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 @@