Browse Source

update autometik select customer and warehouse in peti

master
Gunawan19621 1 year ago
parent
commit
9794342584
  1. 85
      app/Http/Controllers/DisposalController.php
  2. 95
      app/Http/Controllers/PeminjamanController.php
  3. 83
      app/Http/Controllers/TransferController.php
  4. 167
      resources/views/dashboard/Disposal/create.blade.php
  5. 245
      resources/views/dashboard/Peminjaman/create.blade.php
  6. 155
      resources/views/dashboard/Transfer/create.blade.php
  7. 20
      routes/web.php

85
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,
]);
}
}

95
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,
]);
}
}

83
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,
]);
}
}

167
resources/views/dashboard/Disposal/create.blade.php

@ -17,23 +17,9 @@
<label for="peti_id" class="col-form-label">Pilih Detail Peti: <span
class="text-danger">*</span></label>
<select class="form-control" id="searchPeti" name="peti_id"></select>
{{-- <select class="form-control" name="peti_id" type="text" id="peti_id" required>
<option disabled selected>Pilih Detail Peti</option>
@foreach ($peti as $data_peti)
<option value="{{ $data_peti->id }}" data-warehouse-id="{{ $data_peti->warehouse_id }}"
data-customer-name="{{ $data_peti->customer->name }}">
{{ $data_peti->fix_lot }}
</option>
@endforeach
</select> --}}
<label for="customer_id" class="col-form-label">Customer: <span class="text-danger">*</span></label>
<select class="form-control" name="customer_id" type="text" id="customer_id" required>
<option disabled selected>Masukan Nama Customer</option>
@foreach ($customer as $data_customer)
<option value="{{ $data_customer->id }}">{{ $data_customer->name }}</option>
@endforeach
</select>
<select class="form-control" id="searchCustomer" name="customer_id"></select>
<label for="date_disposal" class="col-form-label">Tanggal Disposal: <span
class="text-danger">*</span></label>
@ -41,20 +27,7 @@
value="{{ old('date_disposal') }}" required>
<label for="warehouse_id" class="col-form-label">Asal Gudang: <span class="text-danger">*</span></label>
<select class="form-control" name="warehouse_id" type="text" id="warehouse_id" required>
<option disabled selected>Pilih Asal gudang</option>
@foreach ($warehouse as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach
</select>
{{-- <label for="status_disposal" class="col-form-label">Status Peti: <span
class="text-danger">*</span></label>
<select class="form-control" name="status_disposal" id="status_disposal" required>
<option disabled selected>Pilih Jenis Status Peti</option>
<option value="AKTIF">AKTIF</option>
<option value="INAKTIF">INAKTIF</option>
</select> --}}
<select class="form-control" id="searchWarehouse" name="warehouse_id"></select>
<label for="description" class="col-form-label">Alasan Disposal: <span
class="text-danger">*</span></label>
@ -74,7 +47,10 @@
{{-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> --}}
<script type="text/javascript">
var path = "{{ route('dashboard.disposal.autoCompleteSearch') }}";
var searchCustomersPath = "{{ route('dashboard.disposal.searchCustomers') }}";
var searchWarehousesPath = "{{ route('dashboard.disposal.searchWarehouses') }}";
// Inisialisasi dropdown peti
$('#searchPeti').select2({
placeholder: 'Pilih Detail Peti',
ajax: {
@ -95,65 +71,92 @@
}
});
// Inisialisasi select2 untuk customer
// $('#searchCustomer').select2({
// placeholder: 'Pilih Detail Customer',
// ajax: {
// url: path,
// dataType: 'json',
// delay: 250,
// processResults: function(data) {
// return {
// results: $.map(data.customer, function(item) {
// return {
// text: item.name,
// id: item.id
// }
// })
// };
// },
// cache: true
// }
// });
</script>
<!-- auto disable form pada saat sudah di simpan-->
<script>
document.getElementById('disposalForm').addEventListener('submit', function() {
document.getElementById('submitButton').setAttribute('disabled', 'true');
// Inisialisasi dropdown pelanggan dengan Select2
$('#searchCustomer').select2({
placeholder: 'Cari atau Pilih Pelanggan',
ajax: {
url: searchCustomersPath,
dataType: 'json',
delay: 250,
processResults: function(data) {
return {
results: $.map(data.customers, function(customer) {
return {
text: customer.name,
id: customer.id
}
})
};
},
cache: true
}
});
</script>
<!-- otomatis asal gudang dan Customer berdasarkan detail peti -->
<script>
// Mendapatkan elemen select detail peti
const petiSelect = document.getElementById('peti_id');
// Mendapatkan elemen select asal gudang
const warehouseSelect = document.getElementById('warehouse_id');
// Mendapatkan elemen select Customer
const customerSelect = document.getElementById('customer_id');
// Menambahkan event listener ke select detail peti
petiSelect.addEventListener('change', function() {
// Mendapatkan data-warehouse-id dari option yang dipilih
const selectedOption = this.options[this.selectedIndex];
const warehouseId = selectedOption.getAttribute('data-warehouse-id');
// Inisialisasi dropdown gudang
$('#searchWarehouse').select2({
placeholder: 'Pilih data gudang',
ajax: {
url: searchWarehousesPath,
dataType: 'json',
delay: 250,
processResults: function(data) {
return {
results: $.map(data.warehouses, function(warehouse) {
return {
text: warehouse.name,
id: warehouse.id
}
})
};
},
cache: true
}
});
// Mendapatkan data-customer-name dari option yang dipilih
const customerName = selectedOption.getAttribute('data-customer-name');
// Tambahkan listener perubahan pada dropdown peti
$('#searchPeti').on('change', function() {
var selectedPetiId = $(this).val();
// Memilih asal gudang berdasarkan data-warehouse-id
warehouseSelect.value = warehouseId;
// Bersihkan dan reset dropdown pelanggan dan gudang
$('#searchCustomer').empty().val(null).trigger('change');
$('#searchWarehouse').empty().val(null).trigger('change');
// Memilih customer berdasarkan data-customer-name
for (let i = 0; i < customerSelect.options.length; i++) {
if (customerSelect.options[i].text === customerName) {
customerSelect.selectedIndex = i;
break;
// Ambil dan perbarui data pelanggan dan gudang berdasarkan peti yang dipilih
$.ajax({
url: "{{ route('dashboard.disposal.getCustomerAndWarehouseByPeti') }}",
type: 'GET',
data: {
peti_id: selectedPetiId
},
dataType: 'json',
success: function(data) {
$.each(data.customers, function(index, customer) {
// Tambahkan opsi ke dropdown pelanggan
$('#searchCustomer').append('<option value="' + customer.id + '">' +
customer.name + '</option>');
});
$.each(data.warehouses, function(index, warehouse) {
// Tambahkan opsi ke dropdown gudang
$('#searchWarehouse').append('<option value="' + warehouse.id + '">' +
warehouse.name + '</option>');
});
// Pilih pelanggan dan gudang berdasarkan data yang diterima
$('#searchCustomer').val(data.selectedCustomer).trigger('change');
$('#searchWarehouse').val(data.selectedWarehouse).trigger('change');
},
error: function(error) {
console.error('Error fetching customer and warehouse data:', error);
}
}
});
});
</script>
<!-- auto disable form pada saat sudah di simpan-->
<script>
document.getElementById('disposalForm').addEventListener('submit', function() {
document.getElementById('submitButton').setAttribute('disabled', 'true');
});
</script>
@endsection

245
resources/views/dashboard/Peminjaman/create.blade.php

@ -2,76 +2,6 @@
@section('title', 'Tambah Peminjaman')
@section('content')
@include('layouts.components.alert-prompt')
<!-- Cara Lama -->
{{-- <div class="card shadow mb-4">
<div class="card-header py-3">
<div class="row">
<div class="col-6">
<h5 class="m-0 font-weight-bold text-primary mt-2">Tambah Peminjaman</h5>
</div>
</div>
</div>
<div class="card-body">
<form action="{{ route('dashboard.peminjaman.store') }}" method="POST" enctype="multipart/form-data"
id="peminjamanForm">
@csrf
<div class="form-group">
<label for="peti_id" class="col-form-label">Pilih Detail Peti: <span
class="text-danger">*</span></label>
<select class="form-control" name="peti_id" id="peti_id" required>
<option disabled selected>Pilih Detail Peti</option>
@foreach ($peti_block as $data_peti)
<option value="{{ $data_peti->id }}" data-warehouse-id="{{ $data_peti->warehouse_id }}"
data-customer-id="{{ $data_peti->customer->id }}"
data-warehouse-name="{{ $data_peti->warehouse->name }}">
{{ $data_peti->fix_lot }}
</option>
@endforeach
</select>
<label for="customer_id" class="col-form-label">Customer:<span class="text-danger">*</span></label>
<select class="form-control" name="customer_id" type="text" id="customer_id" required>
<option disabled selected>Pilih Nama Customer</option>
@foreach ($customer as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach
</select>
<label for="exit_at" class="col-form-label">Tanggal Peminjaman: <span
class="text-danger">*</span></label>
<input class="form-control" name="exit_at" type="date" id="exit_at" value="{{ old('exit_at') }}"
required>
<label for="est_pengembalian" class="col-form-label">Estimasi Tanggal Pengembalian: <span
class="text-danger">*</span></label>
<input class="form-control" name="est_pengembalian" type="date" id="est_pengembalian" required>
<label for="warehouse_id" class="col-form-label">Asal Gudang:</label>
<select class="form-control" name="warehouse_id" type="text" id="warehouse_id" required>
<option disabled selected>Pilih Asal Gudang</option>
@foreach ($warehouse as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach
</select>
<label for="exit_warehouse" class="col-form-label">Tujuan Gudang: <span
class="text-danger">*</span></label>
<select class="form-control" name="exit_warehouse" type="text" id="exit_warehouse" required>
<option disabled selected>Pilih Tujuan Gudang</option>
@foreach ($warehouse as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach
</select>
</div>
<div class="modal-footer d-flex justify-content-center">
<a href="{{ route('dashboard.peminjaman.index') }}" class="btn btn-secondary">Kembali</a>
<button type="submit" class="btn btn-primary" id="submitButton">Simpan</button>
</div>
</form>
</div>
</div> --}}
<!-- Cara Baru -->
<div class="card shadow mb-4">
<div class="card-header py-3">
@ -91,13 +21,7 @@
<select class="form-control" id="searchPeti" name="peti_id"></select>
<label for="customer_id" class="col-form-label">Customer:<span class="text-danger">*</span></label>
<select class="form-control" name="customer_id" type="text" id="customer_id" required>
<option disabled selected>Pilih Nama Customer</option>
@foreach ($customer as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach
</select>
{{-- <select class="form-control" id="searchCustomer" name="customer_id"></select> --}}
<select class="form-control" id="searchCustomer" name="customer_id"></select>
<label for="exit_at" class="col-form-label">Tanggal Peminjaman: <span
class="text-danger">*</span></label>
@ -109,12 +33,7 @@
<input class="form-control" name="est_pengembalian" type="date" id="est_pengembalian" required>
<label for="warehouse_id" class="col-form-label">Asal Gudang:</label>
<select class="form-control" name="warehouse_id" type="text" id="warehouse_id" required>
<option disabled selected>Pilih Asal Gudang</option>
@foreach ($warehouse as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach
</select>
<select class="form-control" id="searchWarehouse" name="warehouse_id"></select>
<label for="exit_warehouse" class="col-form-label">Tujuan Gudang: <span
class="text-danger">*</span></label>
@ -139,7 +58,10 @@
{{-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> --}}
<script type="text/javascript">
var path = "{{ route('dashboard.peminjaman.autoCompleteSearch') }}";
var searchCustomersPath = "{{ route('dashboard.peminjaman.searchCustomers') }}";
var searchWarehousesPath = "{{ route('dashboard.peminjaman.searchWarehouses') }}";
// Inisialisasi dropdown peti
$('#searchPeti').select2({
placeholder: 'Pilih Detail Peti',
ajax: {
@ -160,26 +82,86 @@
}
});
// Inisialisasi select2 untuk customer
// $('#searchCustomer').select2({
// placeholder: 'Pilih Detail Customer',
// ajax: {
// url: path,
// dataType: 'json',
// delay: 250,
// processResults: function(data) {
// return {
// results: $.map(data.customer, function(item) {
// return {
// text: item.name,
// id: item.id
// }
// })
// };
// },
// cache: true
// }
// });
// Inisialisasi dropdown pelanggan dengan Select2
$('#searchCustomer').select2({
placeholder: 'Cari atau Pilih Pelanggan',
ajax: {
url: searchCustomersPath,
dataType: 'json',
delay: 250,
processResults: function(data) {
return {
results: $.map(data.customers, function(customer) {
return {
text: customer.name,
id: customer.id
}
})
};
},
cache: true
}
});
// Inisialisasi dropdown gudang
$('#searchWarehouse').select2({
placeholder: 'Pilih data gudang',
ajax: {
url: searchWarehousesPath,
dataType: 'json',
delay: 250,
processResults: function(data) {
return {
results: $.map(data.warehouses, function(warehouse) {
return {
text: warehouse.name,
id: warehouse.id
}
})
};
},
cache: true
}
});
// Tambahkan listener perubahan pada dropdown peti
$('#searchPeti').on('change', function() {
var selectedPetiId = $(this).val();
// Bersihkan dan reset dropdown pelanggan dan gudang
$('#searchCustomer').empty().val(null).trigger('change');
$('#searchWarehouse').empty().val(null).trigger('change');
// Ambil dan perbarui data pelanggan dan gudang berdasarkan peti yang dipilih
$.ajax({
url: "{{ route('dashboard.peminjaman.getCustomerAndWarehouseByPeti') }}",
type: 'GET',
data: {
peti_id: selectedPetiId
},
dataType: 'json',
success: function(data) {
$.each(data.customers, function(index, customer) {
// Tambahkan opsi ke dropdown pelanggan
$('#searchCustomer').append('<option value="' + customer.id + '">' +
customer.name + '</option>');
});
$.each(data.warehouses, function(index, warehouse) {
// Tambahkan opsi ke dropdown gudang
$('#searchWarehouse').append('<option value="' + warehouse.id + '">' +
warehouse.name + '</option>');
});
// Pilih pelanggan dan gudang berdasarkan data yang diterima
$('#searchCustomer').val(data.selectedCustomer).trigger('change');
$('#searchWarehouse').val(data.selectedWarehouse).trigger('change');
},
error: function(error) {
console.error('Error fetching customer and warehouse data:', error);
}
});
});
</script>
<!-- auto disable form pada saat sudah di simpan-->
@ -210,61 +192,4 @@
estimatedReturnDateInput.valueAsDate = estimatedReturnDate;
});
</script>
<!-- otomatis asal gudang dan Customer berdasarkan detail peti -->
{{-- <script>
// Mendapatkan elemen select detail peti
const petiSelect = document.getElementById('peti_id');
// Mendapatkan elemen select customer
const customerSelect = document.getElementById('customer_id');
// Mendapatkan elemen select asal gudang
const warehouseSelect = document.getElementById('warehouse_id');
// Menambahkan event listener ke select detail peti
petiSelect.addEventListener('change', function() {
// Mendapatkan data-warehouse-id dari option yang dipilih
const selectedOption = this.options[this.selectedIndex];
const warehouseId = selectedOption.getAttribute('data-warehouse-id');
const customerId = selectedOption.getAttribute('data-customer-id');
const warehouseName = selectedOption.getAttribute('data-warehouse-name');
// Memilih asal gudang berdasarkan data-warehouse-id
warehouseSelect.value = warehouseId;
// Memilih customer berdasarkan data-customer-id
customerSelect.value = customerId;
});
</script> --}}
<!-- Penambahan cara baru -->
{{-- <script>
// Mendapatkan elemen select detail peti
const petiSelect = $('#searchPeti');
// Mendapatkan elemen select warehouse
const warehouseSelect = $('#warehouse_id');
// Menambahkan event listener ke select detail peti
petiSelect.on('change', function() {
// Mendapatkan nilai peti_id yang terpilih
const selectedPetiId = $(this).val();
// Memilih warehouse berdasarkan peti_id yang terpilih
$.ajax({
url: `/api/peti/${selectedPetiId}/warehouse`, // Gantilah dengan URL endpoint yang sesuai
method: 'GET',
success: function(warehouseData) {
// Mengisi opsi warehouse
const warehouseOption = new Option(warehouseData.name, warehouseData.id, true,
true);
warehouseSelect.html('').append(warehouseOption).trigger('change');
},
error: function(error) {
console.error(error);
}
});
});
</script> --}}
@endsection

155
resources/views/dashboard/Transfer/create.blade.php

@ -17,15 +17,6 @@
<label for="peti_id" class="col-form-label">Pilih Detail Peti: <span
class="text-danger">*</span></label>
<select class="form-control" id="searchPeti" name="peti_id"></select>
{{-- <select class="form-control" name="peti_id" type="text" id="peti_id" required>
<option disabled selected>Pilih Detail Peti</option>
@foreach ($peti as $data_peti)
<option value="{{ $data_peti->id }}" data-warehouse-id="{{ $data_peti->warehouse_id }}"
data-customer-name="{{ $data_peti->customer->name }}">
{{ $data_peti->fix_lot }}
</option>
@endforeach
</select> --}}
<label for="date" class="col-form-label">Tanggal Transfer: <span
class="text-danger">*</span></label>
@ -33,21 +24,11 @@
required>
<label for="name_customer" class="col-form-label">Customer: <span class="text-danger">*</span></label>
<select class="form-control" name="name_customer" type="text" id="name_customer" required>
<option disabled selected>Pilih Nama Customer</option>
@foreach ($customer as $data_customer)
<option value="{{ $data_customer->id }}">{{ $data_customer->name }}</option>
@endforeach
</select>
<select class="form-control" id="searchCustomer" name="name_customer"></select>
<label for="source_warehouse" class="col-form-label">Asal Gudang: <span
class="text-danger">*</span></label>
<select class="form-control" name="source_warehouse" type="text" id="source_warehouse" required>
<option disabled selected>Pilih Asal gudang</option>
@foreach ($warehouse as $data)
<option value="{{ $data->id }}">{{ $data->name }}</option>
@endforeach
</select>
<select class="form-control" id="searchWarehouse" name="source_warehouse"></select>
<label for="destination_warehouse" class="col-form-label">Tujuan Gudang: <span
class="text-danger">*</span></label>
@ -72,7 +53,10 @@
{{-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> --}}
<script type="text/javascript">
var path = "{{ route('dashboard.transfer.autoCompleteSearch') }}";
var searchCustomersPath = "{{ route('dashboard.transfer.searchCustomers') }}";
var searchWarehousesPath = "{{ route('dashboard.transfer.searchWarehouses') }}";
// Inisialisasi dropdown peti
$('#searchPeti').select2({
placeholder: 'Pilih Detail Peti',
ajax: {
@ -93,65 +77,92 @@
}
});
// Inisialisasi select2 untuk customer
// $('#searchCustomer').select2({
// placeholder: 'Pilih Detail Customer',
// ajax: {
// url: path,
// dataType: 'json',
// delay: 250,
// processResults: function(data) {
// return {
// results: $.map(data.customer, function(item) {
// return {
// text: item.name,
// id: item.id
// }
// })
// };
// },
// cache: true
// }
// });
</script>
<!-- auto disable form pada saat sudah di simpan-->
<script>
document.getElementById('transferForm').addEventListener('submit', function() {
document.getElementById('submitButton').setAttribute('disabled', 'true');
// Inisialisasi dropdown pelanggan dengan Select2
$('#searchCustomer').select2({
placeholder: 'Cari atau Pilih Pelanggan',
ajax: {
url: searchCustomersPath,
dataType: 'json',
delay: 250,
processResults: function(data) {
return {
results: $.map(data.customers, function(customer) {
return {
text: customer.name,
id: customer.id
}
})
};
},
cache: true
}
});
</script>
<!-- otomatis asal gudang dan Customer berdasarkan detail peti -->
<script>
// Mendapatkan elemen select detail peti
const petiSelect = document.getElementById('peti_id');
// Inisialisasi dropdown gudang
$('#searchWarehouse').select2({
placeholder: 'Pilih data gudang',
ajax: {
url: searchWarehousesPath,
dataType: 'json',
delay: 250,
processResults: function(data) {
return {
results: $.map(data.warehouses, function(warehouse) {
return {
text: warehouse.name,
id: warehouse.id
}
})
};
},
cache: true
}
});
// Mendapatkan elemen select asal gudang
const source_warehouseSelect = document.getElementById('source_warehouse');
// Tambahkan listener perubahan pada dropdown peti
$('#searchPeti').on('change', function() {
var selectedPetiId = $(this).val();
// Mendapatkan elemen select Customer
// const name_customerSelect = document.getElementById('name_customer');
// Bersihkan dan reset dropdown pelanggan dan gudang
$('#searchCustomer').empty().val(null).trigger('change');
$('#searchWarehouse').empty().val(null).trigger('change');
// Menambahkan event listener ke select detail peti
petiSelect.addEventListener('change', function() {
// Mendapatkan data-warehouse-id dari option yang dipilih
const selectedOption = this.options[this.selectedIndex];
const warehouseId = selectedOption.getAttribute('data-warehouse-id');
// Ambil dan perbarui data pelanggan dan gudang berdasarkan peti yang dipilih
$.ajax({
url: "{{ route('dashboard.transfer.getCustomerAndWarehouseByPeti') }}",
type: 'GET',
data: {
peti_id: selectedPetiId
},
dataType: 'json',
success: function(data) {
$.each(data.customers, function(index, customer) {
// Tambahkan opsi ke dropdown pelanggan
$('#searchCustomer').append('<option value="' + customer.id + '">' +
customer.name + '</option>');
});
// Mendapatkan data-customer-name dari option yang dipilih
// const customerName = selectedOption.getAttribute('data-customer-name');
$.each(data.warehouses, function(index, warehouse) {
// Tambahkan opsi ke dropdown gudang
$('#searchWarehouse').append('<option value="' + warehouse.id + '">' +
warehouse.name + '</option>');
});
// Memilih asal gudang berdasarkan data-warehouse-id
source_warehouseSelect.value = warehouseId;
// Pilih pelanggan dan gudang berdasarkan data yang diterima
$('#searchCustomer').val(data.selectedCustomer).trigger('change');
$('#searchWarehouse').val(data.selectedWarehouse).trigger('change');
},
error: function(error) {
console.error('Error fetching customer and warehouse data:', error);
}
});
});
</script>
// 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;
// }
// }
<!-- auto disable form pada saat sudah di simpan-->
<script>
document.getElementById('transferForm').addEventListener('submit', function() {
document.getElementById('submitButton').setAttribute('disabled', 'true');
});
</script>
@endsection

20
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

Loading…
Cancel
Save