diff --git a/app/Http/Controllers/DisposalController.php b/app/Http/Controllers/DisposalController.php index 59c2174..26ef85b 100644 --- a/app/Http/Controllers/DisposalController.php +++ b/app/Http/Controllers/DisposalController.php @@ -27,8 +27,6 @@ class DisposalController extends Controller return view('dashboard.Disposal.index', $data); } - - /** * Show the form for creating a new resource. */ @@ -86,17 +84,6 @@ class DisposalController extends Controller } } - /** - * Display the specified resource. - */ - // public function show($id) - // { - // $data = [ - // 'active' => 'menu-disposal', - // ]; - // return view('dashboard.Disposal.show', $data); - // } - /** * Show the form for editing the specified resource. */ @@ -194,4 +181,76 @@ class DisposalController extends Controller return response()->json(['peti' => $petiData, 'customer' => $customerData]); } + + // proses search Customer + public function searchCustomers(Request $request): JsonResponse + { + $query = $request->get('q'); + + $customers = Customer::select('id', 'name') + ->where('name', 'like', "%$query%") + ->get() + ->toArray(); + + return response()->json(['customers' => $customers]); + } + + public function searchWarehouses(Request $request): JsonResponse + { + $query = $request->get('q'); + + $warehouses = m_warehouse::select('id', 'name') + ->where('name', 'like', "%$query%") + ->get() + ->toArray(); + + return response()->json(['warehouses' => $warehouses]); + } + + // proses auto select customer dan warehouse berdasarkan peti id + public function getCustomerAndWarehouseByPeti(Request $request): JsonResponse + { + $petiId = $request->get('peti_id'); + + // Fetch customer data and warehouse based on the selected peti + $peti = Peti::with(['customer', 'warehouse']) + ->where('id', $petiId) + ->first(); + + $customerData = []; + $selectedCustomer = null; + $warehouseData = []; + $selectedWarehouse = null; + + if ($peti && $peti->customer) { + // Extract customer data from the related relationship + $customerData[] = [ + 'id' => $peti->customer->id, + 'name' => $peti->customer->name, + // Add any other fields you want to include + ]; + + // Set the selectedCustomer to the customer id + $selectedCustomer = $peti->customer->id; + } + + if ($peti && $peti->warehouse) { + // Extract warehouse data from the related relationship + $warehouseData[] = [ + 'id' => $peti->warehouse->id, + 'name' => $peti->warehouse->name, + // Add any other fields you want to include + ]; + + // Set the selectedWarehouse to the warehouse id + $selectedWarehouse = $peti->warehouse->id; + } + + return response()->json([ + 'customers' => $customerData, + 'selectedCustomer' => $selectedCustomer, + 'warehouses' => $warehouseData, + 'selectedWarehouse' => $selectedWarehouse, + ]); + } } diff --git a/app/Http/Controllers/PeminjamanController.php b/app/Http/Controllers/PeminjamanController.php index f248fcf..b3abba2 100644 --- a/app/Http/Controllers/PeminjamanController.php +++ b/app/Http/Controllers/PeminjamanController.php @@ -18,7 +18,7 @@ use App\Http\Requests\ValidasiUpdatePeminjaman; class PeminjamanController extends Controller { /** - * Display a listing of the resource. + * Halaman index */ public function index(Request $request) { @@ -88,7 +88,7 @@ class PeminjamanController extends Controller /** - * Show the form for creating a new resource. + * Halaman tambah data */ public function create() { @@ -116,7 +116,7 @@ class PeminjamanController extends Controller } /** - * Store a newly created resource in storage. + * Halaman proses tambah data */ public function store(ValidasiCreatePeminjaman $request) { @@ -141,15 +141,7 @@ class PeminjamanController extends Controller } /** - * Display the specified resource. - */ - public function show($id) - { - // dd('oke'); - } - - /** - * Show the form for editing the specified resource. + * Halaman edit data */ public function edit($id) { @@ -164,7 +156,7 @@ class PeminjamanController extends Controller } /** - * Update the specified resource in storage. + * Halaman proses edit data */ public function update(ValidasiUpdatePeminjaman $request, $id) { @@ -181,7 +173,7 @@ class PeminjamanController extends Controller } /** - * Remove the specified resource from storage. + * proses deleted */ public function destroy($id) { @@ -195,7 +187,7 @@ class PeminjamanController extends Controller } /** - * Show the form for editing the specified resource. + * Halaman proses pengembalian */ public function pengembalian($id) { @@ -210,6 +202,7 @@ class PeminjamanController extends Controller return view('dashboard.Peminjaman.pengembalian', $data); } + // proses search peti public function autoCompleteSearch(Request $request): JsonResponse { $petiData = []; @@ -234,4 +227,76 @@ class PeminjamanController extends Controller return response()->json(['peti' => $petiData, 'customer' => $customerData]); } + + // proses search Customer + public function searchCustomers(Request $request): JsonResponse + { + $query = $request->get('q'); + + $customers = Customer::select('id', 'name') + ->where('name', 'like', "%$query%") + ->get() + ->toArray(); + + return response()->json(['customers' => $customers]); + } + + public function searchWarehouses(Request $request): JsonResponse + { + $query = $request->get('q'); + + $warehouses = m_warehouse::select('id', 'name') + ->where('name', 'like', "%$query%") + ->get() + ->toArray(); + + return response()->json(['warehouses' => $warehouses]); + } + + // proses auto select customer dan warehouse berdasarkan peti id + public function getCustomerAndWarehouseByPeti(Request $request): JsonResponse + { + $petiId = $request->get('peti_id'); + + // Fetch customer data and warehouse based on the selected peti + $peti = Peti::with(['customer', 'warehouse']) + ->where('id', $petiId) + ->first(); + + $customerData = []; + $selectedCustomer = null; + $warehouseData = []; + $selectedWarehouse = null; + + if ($peti && $peti->customer) { + // Extract customer data from the related relationship + $customerData[] = [ + 'id' => $peti->customer->id, + 'name' => $peti->customer->name, + // Add any other fields you want to include + ]; + + // Set the selectedCustomer to the customer id + $selectedCustomer = $peti->customer->id; + } + + if ($peti && $peti->warehouse) { + // Extract warehouse data from the related relationship + $warehouseData[] = [ + 'id' => $peti->warehouse->id, + 'name' => $peti->warehouse->name, + // Add any other fields you want to include + ]; + + // Set the selectedWarehouse to the warehouse id + $selectedWarehouse = $peti->warehouse->id; + } + + return response()->json([ + 'customers' => $customerData, + 'selectedCustomer' => $selectedCustomer, + 'warehouses' => $warehouseData, + 'selectedWarehouse' => $selectedWarehouse, + ]); + } } diff --git a/app/Http/Controllers/TransferController.php b/app/Http/Controllers/TransferController.php index 4a35337..e9ec7be 100644 --- a/app/Http/Controllers/TransferController.php +++ b/app/Http/Controllers/TransferController.php @@ -114,17 +114,6 @@ class TransferController extends Controller // } // } - /** - * Display the specified resource. - */ - // public function show($id) - // { - // $data = [ - // 'active' => 'menu-transfer', - // ]; - // return view('dashboard.Transfer.show', $data); - // } - /** * Show the form for editing the specified resource. */ @@ -247,4 +236,76 @@ class TransferController extends Controller return response()->json(['peti' => $petiData, 'customer' => $customerData]); } + + // proses search Customer + public function searchCustomers(Request $request): JsonResponse + { + $query = $request->get('q'); + + $customers = Customer::select('id', 'name') + ->where('name', 'like', "%$query%") + ->get() + ->toArray(); + + return response()->json(['customers' => $customers]); + } + + public function searchWarehouses(Request $request): JsonResponse + { + $query = $request->get('q'); + + $warehouses = m_warehouse::select('id', 'name') + ->where('name', 'like', "%$query%") + ->get() + ->toArray(); + + return response()->json(['warehouses' => $warehouses]); + } + + // proses auto select customer dan warehouse berdasarkan peti id + public function getCustomerAndWarehouseByPeti(Request $request): JsonResponse + { + $petiId = $request->get('peti_id'); + + // Fetch customer data and warehouse based on the selected peti + $peti = Peti::with(['customer', 'warehouse']) + ->where('id', $petiId) + ->first(); + + $customerData = []; + $selectedCustomer = null; + $warehouseData = []; + $selectedWarehouse = null; + + if ($peti && $peti->customer) { + // Extract customer data from the related relationship + $customerData[] = [ + 'id' => $peti->customer->id, + 'name' => $peti->customer->name, + // Add any other fields you want to include + ]; + + // Set the selectedCustomer to the customer id + $selectedCustomer = $peti->customer->id; + } + + if ($peti && $peti->warehouse) { + // Extract warehouse data from the related relationship + $warehouseData[] = [ + 'id' => $peti->warehouse->id, + 'name' => $peti->warehouse->name, + // Add any other fields you want to include + ]; + + // Set the selectedWarehouse to the warehouse id + $selectedWarehouse = $peti->warehouse->id; + } + + return response()->json([ + 'customers' => $customerData, + 'selectedCustomer' => $selectedCustomer, + 'warehouses' => $warehouseData, + 'selectedWarehouse' => $selectedWarehouse, + ]); + } } diff --git a/resources/views/dashboard/Disposal/create.blade.php b/resources/views/dashboard/Disposal/create.blade.php index c3f0563..f53be1b 100644 --- a/resources/views/dashboard/Disposal/create.blade.php +++ b/resources/views/dashboard/Disposal/create.blade.php @@ -17,23 +17,9 @@ - {{-- --}} - + @@ -41,20 +27,7 @@ value="{{ old('date_disposal') }}" required> - - - {{-- - --}} + @@ -74,7 +47,10 @@ {{-- --}} - - - - - - + + + @endsection diff --git a/resources/views/dashboard/Peminjaman/create.blade.php b/resources/views/dashboard/Peminjaman/create.blade.php index 2265140..d5539bb 100644 --- a/resources/views/dashboard/Peminjaman/create.blade.php +++ b/resources/views/dashboard/Peminjaman/create.blade.php @@ -2,76 +2,6 @@ @section('title', 'Tambah Peminjaman') @section('content') @include('layouts.components.alert-prompt') - - {{--
-
-
-
-
Tambah Peminjaman
-
-
-
-
-
- @csrf -
- - - - - - - - - - - - - - - - - - -
- -
-
-
--}} -
@@ -91,13 +21,7 @@ - - {{-- --}} + @@ -109,12 +33,7 @@ - + @@ -139,7 +58,10 @@ {{-- --}} @@ -210,61 +192,4 @@ estimatedReturnDateInput.valueAsDate = estimatedReturnDate; }); - - - {{-- --}} - - - {{-- --}} @endsection diff --git a/resources/views/dashboard/Transfer/create.blade.php b/resources/views/dashboard/Transfer/create.blade.php index abadd7e..efb5321 100644 --- a/resources/views/dashboard/Transfer/create.blade.php +++ b/resources/views/dashboard/Transfer/create.blade.php @@ -17,15 +17,6 @@ - {{-- --}} @@ -33,21 +24,11 @@ required> - + - + @@ -72,7 +53,10 @@ {{-- --}} - - - - - - // Memilih customer berdasarkan data-customer-name - // for (let i = 0; i < name_customerSelect.options.length; i++) { - // if (name_customerSelect.options[i].text === customerName) { - // name_customerSelect.selectedIndex = i; - // break; - // } - // } + + @endsection diff --git a/routes/web.php b/routes/web.php index c6ca23f..f471409 100644 --- a/routes/web.php +++ b/routes/web.php @@ -65,6 +65,9 @@ Route::prefix('dashboard')->name('dashboard.')->middleware(['auth'])->group(func Route::delete('peminjaman/delete/{id}', 'destroy')->name('peminjaman.destroy'); Route::get('peminjaman/{id}/pengembalian', 'pengembalian')->name('peminjaman.pengembalian'); Route::get('peminjaman/Search', 'autoCompleteSearch')->name('peminjaman.autoCompleteSearch'); + Route::get('peminjaman/get-customer-and-warehouse-by-peti', 'getCustomerAndWarehouseByPeti')->name('peminjaman.getCustomerAndWarehouseByPeti'); + Route::get('peminjaman/search-customers', 'searchCustomers')->name('peminjaman.searchCustomers'); + Route::get('peminjaman/search-warehouses', 'searchWarehouses')->name('peminjaman.searchWarehouses'); }); //Halaman Pengembalian @@ -78,17 +81,6 @@ Route::prefix('dashboard')->name('dashboard.')->middleware(['auth'])->group(func Route::delete('pengembalian/delete/{id}', 'destroy')->name('pengembalian.destroy'); }); - // tidak di pakai - // Route::controller(TransaksiKeluarMasukController::class)->group(function () { - // Route::get('transaksikeluamasuk', 'index')->name('transaksikeluamasuk.index'); - // Route::get('transaksikeluamasuk/create', 'create')->name('transaksikeluamasuk.create'); - // Route::post('transaksikeluamasuk/store', 'store')->name('transaksikeluamasuk.store'); - // Route::get('transaksikeluamasuk/{id}', 'show')->name('transaksikeluamasuk.show'); - // Route::get('transaksikeluamasuk/{id}/edit', 'edit')->name('transaksikeluamasuk.edit'); - // Route::put('transaksikeluamasuk/{id}', 'update')->name('transaksikeluamasuk.update'); - // Route::delete('transaksikeluamasuk/delete/{id}', 'destroy')->name('transaksikeluamasuk.destroy'); - // }); - //Halaman Transfer Route::controller(TransferController::class)->group(function () { Route::get('transfer', 'index')->name('transfer.index'); @@ -98,6 +90,9 @@ Route::prefix('dashboard')->name('dashboard.')->middleware(['auth'])->group(func Route::put('transfer/{id}', 'update')->name('transfer.update'); Route::delete('transfer/delete/{id}', 'destroy')->name('transfer.destroy'); Route::get('transfer/Search', 'autoCompleteSearch')->name('transfer.autoCompleteSearch'); + Route::get('transfer/get-customer-and-warehouse-by-peti', 'getCustomerAndWarehouseByPeti')->name('transfer.getCustomerAndWarehouseByPeti'); + Route::get('transfer/search-customers', 'searchCustomers')->name('transfer.searchCustomers'); + Route::get('transfer/search-warehouses', 'searchWarehouses')->name('transfer.searchWarehouses'); }); //Halaman Disposal @@ -109,6 +104,9 @@ Route::prefix('dashboard')->name('dashboard.')->middleware(['auth'])->group(func Route::put('disposal/{id}', 'update')->name('disposal.update'); Route::delete('disposal/delete/{id}', 'destroy')->name('disposal.destroy'); Route::get('disposal/Search', 'autoCompleteSearch')->name('disposal.autoCompleteSearch'); + Route::get('disposal/get-customer-and-warehouse-by-peti', 'getCustomerAndWarehouseByPeti')->name('disposal.getCustomerAndWarehouseByPeti'); + Route::get('disposal/search-customers', 'searchCustomers')->name('disposal.searchCustomers'); + Route::get('disposal/search-warehouses', 'searchWarehouses')->name('disposal.searchWarehouses'); }); //Halaman History