update data pemanding dan otorisator, pembuatan seeder kjpp mengunakan exel
This commit is contained in:
@@ -112,11 +112,16 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="px-4 py-2">Luas Tanah (m²)</td>
|
||||
@php
|
||||
$cekLuas = $inspectionData['tanah']['luas_tanah'] == 'sesuai' ? 'sesuai' :'tidak sesuai';
|
||||
|
||||
@endphp
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="luas_tanah" class="input number-format"
|
||||
value="{{ $inspectionData['tanah']['luas_tanah']['tidak sesuai'] ?? ($inspectionData['tanah']['luas_tanah']['sesuai'] ?? '') }}">
|
||||
value="{{ $inspectionData['tanah']['luas_tanah']['sesuai'] ?? $inspectionData['tanah']['luas_tanah']['tidak sesuai'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
|
||||
<input type="text" name="luas_tanah_pembanding[]"
|
||||
class="input number-format">
|
||||
</td>
|
||||
@@ -124,8 +129,9 @@
|
||||
<tr>
|
||||
<td class="px-4 py-2">Luas Bangunan (m²)</td>
|
||||
<td class="px-4 py-2">
|
||||
|
||||
<input type="text" name="luas_tanah_bagunan" class="input number-format"
|
||||
value="{{ $inspectionData['bangunan']['luas_tanah_bagunan']['tidak sesuai'] ?? ($inspectionData['bangunan']['luas_tanah_bagunan']['sesuai'] ?? '') }}">
|
||||
value="{{ $inspectionData['bangunan']['luas_tanah_bagunan']['sesuai'] ?? $inspectionData['bangunan']['luas_tanah_bagunan']['tidak sesuai'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="luas_bangunan_pembanding[]"
|
||||
@@ -141,8 +147,8 @@
|
||||
<tr>
|
||||
<td class="px-4 py-2">Status Narasumber</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="nama_nara_sumber" class="input"
|
||||
value="{{ $inspectionData['nama_nara_sumber'] ?? '' }}">
|
||||
<input type="text" name="status_nara_sumber" class="input"
|
||||
value="{{ $inspectionData['asset']['status_nara_sumber'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="status_nara_sumber_pembanding[]"
|
||||
@@ -153,7 +159,7 @@
|
||||
<td class="px-4 py-2">Nama Narasumber</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="nama_nara_sumber" class="input"
|
||||
value="{{ $inspectionData['nama_nara_sumber'] ?? '' }}">
|
||||
value="{{ $inspectionData['asset']['nama_nara_sumber'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="nama_nara_sumber_pembanding[]"
|
||||
@@ -358,7 +364,7 @@
|
||||
<td class="px-4 py-2">Harga</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="harga" class="input currency-format"
|
||||
value="{{ $inspectionData['harga'] ?? '' }}">
|
||||
value="{{ $inspectionData['asset']['harga'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="harga_pembanding[]"
|
||||
@@ -368,8 +374,8 @@
|
||||
<tr>
|
||||
<td class="px-4 py-2">Diskon</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="harga" class="input currency-format"
|
||||
value="{{ $inspectionData['diskon'] ?? '' }}">
|
||||
<input type="text" name="diskon" class="input currency-format"
|
||||
value="{{ $inspectionData['asset']['diskon'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="diskon_pembanding[]"
|
||||
@@ -380,7 +386,7 @@
|
||||
<td class="px-4 py-2">Total</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="total" class="input currency-format"
|
||||
value="{{ $inspectionData['total'] ?? '' }}">
|
||||
value="{{ $inspectionData['asset']['total'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="total_pembanding[]"
|
||||
@@ -391,7 +397,7 @@
|
||||
<td class="px-4 py-2">Harga Setelah Diskon</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="harga_diskon" class="input currency-format"
|
||||
value="{{ $inspectionData['harga_diskon'] ?? '' }}">
|
||||
value="{{ $inspectionData['asset']['harga_diskon'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="harga_diskon_pembanding[]"
|
||||
@@ -417,43 +423,64 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading Overlay -->
|
||||
<div id="loadingOverlay" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
|
||||
<div class="bg-white p-4 rounded-lg">
|
||||
<div class="loader"></div>
|
||||
<p class="mt-2 text-center">Sedang memproses...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
@include('lpj::surveyor.js.utils')
|
||||
<script>
|
||||
let columnCount = 1;
|
||||
|
||||
|
||||
|
||||
// Fungsi calculate prices yang diperbaiki
|
||||
function calculatePrices(index) {
|
||||
const hargaInput = document.getElementsByName('harga_pembanding[]')[index];
|
||||
const diskonInput = document.getElementsByName('diskon_pembanding[]')[index];
|
||||
const totalInput = document.getElementsByName('total_pembanding[]')[index];
|
||||
const hargaDiskonInput = document.getElementsByName('harga_diskon_pembanding[]')[index];
|
||||
|
||||
if (hargaInput && diskonInput && totalInput && hargaDiskonInput) {
|
||||
// Ambil nilai numerik dari input
|
||||
const harga = parseFloat(hargaInput.value.replace(/[^\d]/g, '') || '0');
|
||||
const diskon = parseFloat(diskonInput.value.replace(/[^\d]/g, '') || '0');
|
||||
|
||||
// Hitung total dan harga setelah diskon
|
||||
const total = harga;
|
||||
const hargaSetelahDiskon = harga - (harga * (diskon / 100));
|
||||
|
||||
// Update nilai dengan format currency
|
||||
if (totalInput) totalInput.value = formatCurrency(total.toString());
|
||||
if (hargaDiskonInput) hargaDiskonInput.value = formatCurrency(hargaSetelahDiskon.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Update fungsi fillPembandingData
|
||||
function fillPembandingData(data, index) {
|
||||
if (!data) return;
|
||||
|
||||
// Helper function untuk mengisi nilai input array dengan aman
|
||||
function setArrayInputValue(name, value, index) {
|
||||
const element = document.getElementsByName(name)[index];
|
||||
if (element) {
|
||||
if (element.tagName === "SELECT") {
|
||||
// Jika elemen adalah select, set selected value
|
||||
const options = Array.from(element.options);
|
||||
const optionToSelect = options.find(option => option.value === value);
|
||||
if (optionToSelect) {
|
||||
optionToSelect.selected = true;
|
||||
} else {
|
||||
element.selectedIndex = 0; // Pilih default jika tidak ditemukan
|
||||
element.selectedIndex = 0;
|
||||
}
|
||||
} else {
|
||||
// Jika elemen bukan select, langsung set value
|
||||
element.value = value || '';
|
||||
// Format currency untuk input harga
|
||||
if (name.includes('harga') || name.includes('total') || name.includes('diskon')) {
|
||||
element.value = formatCurrency(value ? value.toString() : '0');
|
||||
} else {
|
||||
element.value = value || '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Isi data pembanding
|
||||
const inputs = {
|
||||
'jenis_aset_pembanding[]': data.jenis_aset,
|
||||
'luas_tanah_pembanding[]': data.luas_tanah,
|
||||
@@ -471,15 +498,13 @@
|
||||
'harga_diskon_pembanding[]': data.harga_diskon,
|
||||
'total_pembanding[]': data.total,
|
||||
'diskon_pembanding[]': data.diskon,
|
||||
|
||||
};
|
||||
|
||||
// Isi semua input fields
|
||||
Object.entries(inputs).forEach(([name, value]) => {
|
||||
setArrayInputValue(name, value, index);
|
||||
});
|
||||
|
||||
// Handle foto pembanding jika ada
|
||||
// Handle foto objek
|
||||
if (data.foto_objek) {
|
||||
const imageId = `uploadedImage${index + 2}`;
|
||||
const preview = document.getElementById(imageId);
|
||||
@@ -488,15 +513,59 @@
|
||||
preview.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// Handle lokasi secara berurutan
|
||||
if (data.province_code) {
|
||||
setTimeout(() => {
|
||||
getCity(data.province_code, index + 1).then(() => {
|
||||
if (data.city_code) {
|
||||
setArrayInputValue('city_code_pembanding[]', data.city_code, index);
|
||||
getDistrict(data.city_code, index + 1).then(() => {
|
||||
if (data.district_code) {
|
||||
setArrayInputValue('district_code_pembanding[]', data
|
||||
.district_code, index);
|
||||
getVillage(data.district_code, index + 1).then(() => {
|
||||
if (data.village_code) {
|
||||
setArrayInputValue('village_code_pembanding[]',
|
||||
data.village_code, index);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// Hitung harga setelah data terisi
|
||||
setTimeout(() => calculatePrices(index), 200);
|
||||
}
|
||||
|
||||
// Update event listener untuk input harga dan diskon
|
||||
function initializePriceCalculation() {
|
||||
document.querySelectorAll('[name="harga_pembanding[]"], [name="diskon_pembanding[]"]').forEach((input) => {
|
||||
input.addEventListener('input', function() {
|
||||
const inputs = document.getElementsByName(this.name);
|
||||
const index = Array.from(inputs).indexOf(this);
|
||||
calculatePrices(index);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Event listener dengan pengecekan data
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
try {
|
||||
const inspectionData = {!! isset($inspectionData) ? json_encode($inspectionData) : 'null' !!};
|
||||
const comparisons = {!! isset($comparisons) ? json_encode($comparisons) : 'null' !!};
|
||||
|
||||
console.log('inspectionData:', inspectionData);
|
||||
console.log('comparisons:', comparisons);
|
||||
|
||||
initializeFirstPembandingListeners();
|
||||
ensureLocationEventListeners();
|
||||
initializePriceCalculation();
|
||||
|
||||
if (comparisons) {
|
||||
comparisons.data_pembanding.forEach((comparison, index) => {
|
||||
if (index > 0) {
|
||||
@@ -513,30 +582,26 @@
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function addColumn() {
|
||||
columnCount++;
|
||||
const table = document.getElementById('dataTable');
|
||||
const headerRow = table.querySelector('thead tr');
|
||||
const bodyRows = table.querySelectorAll('tbody tr');
|
||||
|
||||
// Add header
|
||||
const newHeader = document.createElement('th');
|
||||
newHeader.className = 'px-4 py-3 min-w-[250px]';
|
||||
newHeader.textContent = `Data Pembanding ${columnCount}`;
|
||||
headerRow.appendChild(newHeader);
|
||||
|
||||
// Add cells to each row
|
||||
bodyRows.forEach(row => {
|
||||
const newCell = document.createElement('td');
|
||||
newCell.className = 'px-4 py-2';
|
||||
|
||||
const lastInputCell = row.querySelector('td:last-child');
|
||||
if (lastInputCell) {
|
||||
const clonedContent = lastInputCell.innerHTML;
|
||||
const firstInputCell = row.querySelector('td:last-child');
|
||||
if (firstInputCell) {
|
||||
const clonedContent = firstInputCell.innerHTML;
|
||||
newCell.innerHTML = clonedContent;
|
||||
|
||||
// Update IDs and names for the new cell
|
||||
const inputs = newCell.querySelectorAll('input, select, textarea');
|
||||
inputs.forEach((input) => {
|
||||
if (input.type === 'file') {
|
||||
@@ -552,41 +617,63 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Menangani select alamat
|
||||
if (input.tagName === 'SELECT') {
|
||||
const oldId = input.id;
|
||||
const newId = `${oldId}_${columnCount}`;
|
||||
const baseId = input.id.replace(/_\d+$/, '').replace('_pembanding', '');
|
||||
const newId = `${baseId}_pembanding_${columnCount}`;
|
||||
input.id = newId;
|
||||
|
||||
// Menambahkan event listener untuk select alamat
|
||||
if (oldId.includes('city')) {
|
||||
if (input.name.includes('jenis_aset')) {
|
||||
const originalOptions = document.querySelector(
|
||||
'select[name="jenis_aset_pembanding[]"]').innerHTML;
|
||||
input.innerHTML = originalOptions;
|
||||
} else if (!input.id.includes('province')) {
|
||||
// Reset opsi untuk select lokasi
|
||||
input.innerHTML = `<option value="">Pilih ${
|
||||
input.id.includes('city') ? 'Kota/Kabupaten' :
|
||||
input.id.includes('district') ? 'Kecamatan' :
|
||||
'Desa/Kelurahan'
|
||||
}</option>`;
|
||||
}
|
||||
|
||||
if (input.id.includes('province')) {
|
||||
input.onchange = function() {
|
||||
handleProvinceChange(this);
|
||||
};
|
||||
} else if (input.id.includes('city')) {
|
||||
input.onchange = function() {
|
||||
handleCityChange(this);
|
||||
};
|
||||
} else if (oldId.includes('district')) {
|
||||
} else if (input.id.includes('district')) {
|
||||
input.onchange = function() {
|
||||
handleDistrictChange(this);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Clear values
|
||||
if (input.type !== 'file') {
|
||||
if (input.type !== 'file' && input.tagName !== 'SELECT') {
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
if (input.classList.contains('currency-format')) {
|
||||
input.addEventListener('input', function() {
|
||||
formatCurrency(this);
|
||||
});
|
||||
}
|
||||
if (input.classList.contains('number-format')) {
|
||||
input.addEventListener('input', function() {
|
||||
formatNumber(this);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
row.appendChild(newCell);
|
||||
});
|
||||
|
||||
updateRemoveButtonVisibility();
|
||||
reinitializeEventListeners();
|
||||
}
|
||||
|
||||
|
||||
function updateDynamicId(currentId, columnCount) {
|
||||
return `${currentId.split('_')[0]}_${'code_pembanding'}_${columnCount}`;
|
||||
}
|
||||
|
||||
|
||||
function removeColumn() {
|
||||
if (columnCount > 1) {
|
||||
@@ -609,166 +696,36 @@
|
||||
}
|
||||
}
|
||||
|
||||
function fillComparisonData(comparison, index) {
|
||||
Object.entries(comparison).forEach(([key, value]) => {
|
||||
if (key === 'foto_objek') {
|
||||
const imageId = `uploadedImage${index + 1}`;
|
||||
const preview = document.getElementById(imageId);
|
||||
if (preview && value) {
|
||||
preview.src = `{{ asset('storage/pembanding/') }}/${value}`;
|
||||
preview.classList.remove('hidden');
|
||||
}
|
||||
} else {
|
||||
const input = document.querySelector(`[name="${key}_pembanding[]"]:nth-of-type(${index})`);
|
||||
if (input) {
|
||||
input.value = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function previewImage(input, imageId) {
|
||||
const preview = document.getElementById(imageId);
|
||||
if (input.files && input.files[0]) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
preview.src = e.target.result;
|
||||
preview.classList.remove('hidden');
|
||||
}
|
||||
reader.readAsDataURL(input.files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function formatCurrency(input) {
|
||||
let value = input.value.replace(/[^\d]/g, '');
|
||||
value = new Intl.NumberFormat('id-ID').format(value);
|
||||
input.value = value;
|
||||
}
|
||||
|
||||
function formatNumber(input) {
|
||||
let value = input.value.replace(/[^\d.]/g, '');
|
||||
input.value = value;
|
||||
}
|
||||
|
||||
function initializeEventListeners() {
|
||||
// Button event listeners
|
||||
document.getElementById('addColumnBtn').addEventListener('click', addColumn);
|
||||
document.getElementById('removeColumnBtn').addEventListener('click', removeColumn);
|
||||
|
||||
// Form submission
|
||||
|
||||
reinitializeEventListeners();
|
||||
}
|
||||
|
||||
|
||||
function reinitializeEventListeners() {
|
||||
// Currency format
|
||||
// Event listener yang sudah ada
|
||||
document.querySelectorAll('.currency-format').forEach(input => {
|
||||
input.addEventListener('input', function() {
|
||||
formatCurrency(this);
|
||||
});
|
||||
});
|
||||
|
||||
// Number format
|
||||
document.querySelectorAll('.number-format').forEach(input => {
|
||||
input.addEventListener('input', function() {
|
||||
formatNumber(this);
|
||||
});
|
||||
});
|
||||
|
||||
// Tambahkan kalkulasi harga
|
||||
initializePriceCalculation();
|
||||
|
||||
// Location event listeners
|
||||
ensureLocationEventListeners();
|
||||
}
|
||||
|
||||
function submitData() {
|
||||
const loadingOverlay = document.getElementById('loadingOverlay');
|
||||
loadingOverlay.classList.remove('hidden');
|
||||
loadingOverlay.classList.add('flex');
|
||||
const form = document.querySelector('form');
|
||||
const formData = new FormData(form);
|
||||
|
||||
console.log('Form data entries:', Array.from(formData.entries()));
|
||||
|
||||
$.ajax({
|
||||
url: '{{ route('surveyor.storeDataPembanding') }}',
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
},
|
||||
success: function(result) {
|
||||
if (result.success) {
|
||||
Swal.fire({
|
||||
title: 'Berhasil!',
|
||||
text: result.message,
|
||||
icon: 'success',
|
||||
confirmButtonText: 'OK'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
window.location.href =
|
||||
'{{ route('surveyor.show', ['id' => $permohonan->id]) }}';
|
||||
}
|
||||
console.log(result);
|
||||
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: 'Error!',
|
||||
text: result.message || 'Terjadi kesalahan',
|
||||
icon: 'error',
|
||||
confirmButtonText: 'OK'
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('Error:', error);
|
||||
Swal.fire({
|
||||
title: 'Error!',
|
||||
text: 'Terjadi kesalahan pada server',
|
||||
icon: 'error',
|
||||
confirmButtonText: 'OK'
|
||||
});
|
||||
},
|
||||
complete: function() {
|
||||
loadingOverlay.classList.add('hidden');
|
||||
loadingOverlay.classList.remove('flex');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function loadIdSelectAddres(inputs) {
|
||||
const data = [
|
||||
'province_code_pembanding',
|
||||
'city_code_pembanding',
|
||||
'district_code_pembanding',
|
||||
'village_code_pembanding'
|
||||
]
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Inisialisasi event listener untuk data pembanding pertama
|
||||
initializeFirstPembandingListeners();
|
||||
|
||||
try {
|
||||
const inspectionData = {!! isset($inspectionData) ? json_encode($inspectionData) : 'null' !!};
|
||||
const comparisons = {!! isset($comparisons) ? json_encode($comparisons) : 'null' !!};
|
||||
|
||||
if (comparisons) {
|
||||
comparisons.data_pembanding.forEach((comparison, index) => {
|
||||
if (index > 0) {
|
||||
addColumn();
|
||||
}
|
||||
fillPembandingData(comparison, index);
|
||||
});
|
||||
}
|
||||
|
||||
updateRemoveButtonVisibility();
|
||||
initializeEventListeners();
|
||||
} catch (error) {
|
||||
console.error('Error initializing form:', error);
|
||||
}
|
||||
});
|
||||
|
||||
function initializeFirstPembandingListeners() {
|
||||
// Event listener untuk province pembanding pertama
|
||||
const firstProvinceSelect = document.getElementById('province_code_pembanding');
|
||||
if (firstProvinceSelect) {
|
||||
firstProvinceSelect.addEventListener('change', function() {
|
||||
@@ -779,7 +736,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Event listener untuk city pembanding pertama
|
||||
const firstCitySelect = document.getElementById('city_code_pembanding');
|
||||
if (firstCitySelect) {
|
||||
firstCitySelect.addEventListener('change', function() {
|
||||
@@ -790,7 +746,6 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Event listener untuk district pembanding pertama
|
||||
const firstDistrictSelect = document.getElementById('district_code_pembanding');
|
||||
if (firstDistrictSelect) {
|
||||
firstDistrictSelect.addEventListener('change', function() {
|
||||
@@ -802,11 +757,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
function ensureLocationEventListeners() {
|
||||
document.querySelectorAll('[id^="province_code_pembanding"]').forEach(select => {
|
||||
select.onchange = function() {
|
||||
handleProvinceChange(this);
|
||||
};
|
||||
});
|
||||
|
||||
document.querySelectorAll('[id^="city_code_pembanding"]').forEach(select => {
|
||||
select.onchange = function() {
|
||||
handleCityChange(this);
|
||||
};
|
||||
});
|
||||
|
||||
document.querySelectorAll('[id^="district_code_pembanding"]').forEach(select => {
|
||||
select.onchange = function() {
|
||||
handleDistrictChange(this);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function handleProvinceChange(provinceSelect) {
|
||||
const provinceId = provinceSelect.value;
|
||||
let columnIndex;
|
||||
|
||||
// Cek apakah ini pembanding pertama atau tambahan
|
||||
if (provinceSelect.id === 'province_code_pembanding') {
|
||||
columnIndex = 1;
|
||||
} else {
|
||||
@@ -853,7 +827,6 @@
|
||||
const response = await fetch(`/locations/cities/province/${provinceId}`);
|
||||
const data = await response.json();
|
||||
|
||||
// Pilih dropdown berdasarkan index
|
||||
const cityDropdown = columnIndex === 1 ?
|
||||
document.getElementById('city_code_pembanding') :
|
||||
document.getElementById(`city_code_pembanding_${columnIndex}`);
|
||||
@@ -910,41 +883,60 @@
|
||||
}
|
||||
}
|
||||
|
||||
function submitData() {
|
||||
showLoadingSwal('Mengirim data ke server...');
|
||||
const form = document.querySelector('form');
|
||||
const formData = new FormData(form);
|
||||
|
||||
function resetDropdown(elementId, placeholder) {
|
||||
const dropdown = document.getElementById(elementId);
|
||||
dropdown.innerHTML = `<option value="">${placeholder}</option>`;
|
||||
console.log('Form data entries:', Array.from(formData.entries()));
|
||||
|
||||
$.ajax({
|
||||
url: '{{ route('surveyor.storeDataPembanding') }}',
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
},
|
||||
success: function(result) {
|
||||
hideLoadingSwal();
|
||||
console.log(result);
|
||||
if (result.success) {
|
||||
Swal.fire({
|
||||
title: 'Berhasil!',
|
||||
text: result.message,
|
||||
icon: 'success',
|
||||
confirmButtonText: 'OK'
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
window.location.href =
|
||||
'{{ route('surveyor.show', ['id' => $permohonan->id]) }}';
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
} else {
|
||||
Swal.fire({
|
||||
title: 'Error!',
|
||||
text: result.message || 'Terjadi kesalahan',
|
||||
icon: 'error',
|
||||
confirmButtonText: 'OK'
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
hideLoadingSwal();
|
||||
console.error('Error:', error);
|
||||
Swal.fire({
|
||||
title: 'Error!',
|
||||
text: 'Terjadi kesalahan pada server',
|
||||
icon: 'error',
|
||||
confirmButtonText: 'OK'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.loader {
|
||||
border: 4px solid #f3f3f3;
|
||||
border-radius: 50%;
|
||||
border-top: 4px solid #3498db;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
animation: spin 1s linear infinite;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.scrollable-x-auto {
|
||||
overflow-x: auto;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.table {
|
||||
min-width: 100%;
|
||||
}
|
||||
</style>
|
||||
@endpush
|
||||
|
||||
Reference in New Issue
Block a user