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') - - {{--