update menu penilai lpj dan perbaikan data pembanding
This commit is contained in:
@@ -74,8 +74,11 @@
|
||||
<div class="flex flex-col gap-2">
|
||||
<img id="uploadedImage2" class="max-w-[200px] hidden"
|
||||
alt="Pembanding Image">
|
||||
<input type="file" name="foto_objek_pembanding[]" class="file-input"
|
||||
accept="image/*" onchange="previewImage(this, 'uploadedImage2')">
|
||||
<input type="file"
|
||||
name="foto_objek_pembanding[]"
|
||||
class="file-input"
|
||||
accept="image/*"
|
||||
onchange="previewImage(this, 'uploadedImage2')">
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -190,54 +193,199 @@
|
||||
<tr>
|
||||
<td class="px-4 py-2">Alamat</td>
|
||||
<td class="px-4 py-2">
|
||||
<textarea name="alamat" class="input" rows="2">{{ $inspectionData['alamat'] ?? '' }}</textarea>
|
||||
@php
|
||||
$statusAlamat = isset($inspectionData['asset']['alamat']['sesuai'])
|
||||
? 'sesuai'
|
||||
: 'tidak sesuai';
|
||||
$address =
|
||||
$inspectionData['asset']['alamat'][$statusAlamat]['address'] ??
|
||||
null;
|
||||
@endphp
|
||||
<textarea name="address" class="input py-2" rows="2">{{ $address }}</textarea>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<textarea name="alamat_pembanding[]" class="input" rows="2"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="px-4 py-2">Desa/Kelurahan</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="desa" class="input"
|
||||
value="{{ $inspectionData['desa'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="desa_pembanding[]" class="input">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="px-4 py-2">Kecamatan</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="kecamatan" class="input"
|
||||
value="{{ $inspectionData['kecamatan'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="kecamatan_pembanding[]" class="input">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="px-4 py-2">Kabupaten/Kota</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="kabupaten" class="input"
|
||||
value="{{ $inspectionData['kabupaten'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="kabupaten_pembanding[]" class="input">
|
||||
<textarea name="address_pembanding[]" class="input py-2" rows="2"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="px-4 py-2">Provinsi</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="provinsi" class="input"
|
||||
value="{{ $inspectionData['provinsi'] ?? '' }}">
|
||||
<select id="province_code" name="province_code" class="input w-full">
|
||||
@php
|
||||
$statusKey = isset($inspectionData['asset']['alamat']['sesuai'])
|
||||
? 'sesuai'
|
||||
: 'tidak sesuai';
|
||||
$address =
|
||||
$inspectionData['asset']['alamat'][$statusKey][
|
||||
'province_code'
|
||||
] ?? null;
|
||||
@endphp
|
||||
<option value="">Select Province</option>
|
||||
@foreach ($provinces as $province)
|
||||
@php
|
||||
$statusKey = isset(
|
||||
$inspectionData['asset']['alamat']['sesuai'],
|
||||
)
|
||||
? 'sesuai'
|
||||
: 'tidak sesuai';
|
||||
$selectedProvince =
|
||||
$inspectionData['asset']['alamat'][$statusKey][
|
||||
'province_code'
|
||||
] ?? null;
|
||||
@endphp
|
||||
|
||||
<option value="{{ $province->code }}"
|
||||
{{ $selectedProvince == $province->code ? 'selected' : '' }}>
|
||||
{{ $province->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="provinsi_pembanding[]" class="input">
|
||||
<select id="province_code" name="province_code_pembanding[]"
|
||||
class="input w-full">
|
||||
<option value="">Select Province</option>
|
||||
@foreach ($provinces as $province)
|
||||
|
||||
<option value="{{ $province->code }}">
|
||||
{{ $province->name }}
|
||||
</option>
|
||||
|
||||
@endforeach
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="px-4 py-2">Harga (Rp)</td>
|
||||
<td class="px-4 py-2">Kabupaten/Kota</td>
|
||||
<td class="px-4 py-2">
|
||||
<select id="city_code" name="city_code" class="select w-full">
|
||||
@php
|
||||
|
||||
$statusKey = isset($inspectionData['asset']['alamat']['sesuai'])
|
||||
? 'sesuai'
|
||||
: 'tidak sesuai';
|
||||
$selectedCity =
|
||||
$inspectionData['asset']['alamat'][$statusKey][
|
||||
'city_code'
|
||||
] ?? null;
|
||||
@endphp
|
||||
<option value="">Pilih Kota/Kabupaten</option>
|
||||
@if (isset($selectedCity))
|
||||
@foreach ($cities as $city)
|
||||
<option value="{{ $city->code }}"
|
||||
{{ $selectedCity == $city->code ? 'selected' : '' }}>
|
||||
{{ $city->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<select id="city_code" name="city_code_pembanding[]"
|
||||
class="input w-full">
|
||||
|
||||
<option value="">Pilih Kota/Kabupaten</option>
|
||||
@if (isset($cities))
|
||||
@foreach ($cities as $city)
|
||||
<option value="{{ $city->code }}">
|
||||
{{ $city->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="px-4 py-2">Kecamatan</td>
|
||||
<td class="px-4 py-2">
|
||||
<select id="district_code" name="district_code" class="select w-full">
|
||||
@php
|
||||
|
||||
$statusKey = isset($inspectionData['asset']['alamat']['sesuai'])
|
||||
? 'sesuai'
|
||||
: 'tidak sesuai';
|
||||
$selectedDisrict =
|
||||
$inspectionData['asset']['alamat'][$statusKey][
|
||||
'district_code'
|
||||
] ?? null;
|
||||
@endphp
|
||||
<option value="">Pilih Kecamatan</option>
|
||||
@if (isset($selectedDisrict))
|
||||
@foreach ($districts as $district)
|
||||
<option value="{{ $district->code }}"
|
||||
{{ $selectedDisrict == $district->code ? 'selected' : '' }}>
|
||||
{{ $district->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
|
||||
<select id="district_code" name="district_code_pembanding[]"
|
||||
class="input w-full">
|
||||
|
||||
<option value="">Pilih Kecamatan</option>
|
||||
@if (isset($districts))
|
||||
@foreach ($districts as $district)
|
||||
<option value="{{ $district->code }}">
|
||||
{{ $district->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class="px-4 py-2">Desa/Kelurahan</td>
|
||||
<td class="px-4 py-2">
|
||||
<select id="village_code" name="village_code" class="select w-full">
|
||||
@php
|
||||
$statusKey = isset($inspectionData['asset']['alamat']['sesuai'])
|
||||
? 'sesuai'
|
||||
: 'tidak sesuai';
|
||||
$selectedDesa =
|
||||
$inspectionData['asset']['alamat'][$statusKey][
|
||||
'village_code'
|
||||
] ?? null;
|
||||
@endphp
|
||||
<option value="">Pilih Kecamatan</option>
|
||||
@if (isset($selectedDesa))
|
||||
@foreach ($villages as $village)
|
||||
<option value="{{ $village->code }}"
|
||||
{{ $selectedDesa == $village->code ? 'selected' : '' }}>
|
||||
{{ $village->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<select id="village_code" name="village_code_pembanding[]"
|
||||
class="input w-full">
|
||||
|
||||
<option value="">Pilih Kecamatan</option>
|
||||
@if (isset($villages))
|
||||
@foreach ($villages as $village)
|
||||
<option value="{{ $village->code }}">
|
||||
{{ $village->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
@endif
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="bg-gray-100">
|
||||
<td colspan="3" class="px-4 py-2 font-semibold">Harga Per Meter</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<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'] ?? '' }}">
|
||||
@@ -247,6 +395,39 @@
|
||||
class="input currency-format">
|
||||
</td>
|
||||
</tr>
|
||||
<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'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="diskon_pembanding[]"
|
||||
class="input currency-format">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<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'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="total_pembanding[]"
|
||||
class="input currency-format">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<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'] ?? '' }}">
|
||||
</td>
|
||||
<td class="px-4 py-2">
|
||||
<input type="text" name="harga_diskon_pembanding[]"
|
||||
class="input currency-format">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -254,7 +435,7 @@
|
||||
|
||||
<div class="card-footer">
|
||||
<div class="flex justify-end gap-2">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<button type="button" onclick="submitData()" class="btn btn-primary">
|
||||
<i class="ki-duotone ki-save-2 fs-2"></i>
|
||||
Simpan
|
||||
</button>
|
||||
@@ -263,7 +444,7 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div </div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading Overlay -->
|
||||
@@ -279,55 +460,6 @@
|
||||
<script>
|
||||
let columnCount = 1;
|
||||
|
||||
function fillObjekPenilaian(data) {
|
||||
if (!data) return;
|
||||
|
||||
// Helper function untuk mengisi nilai input dengan aman
|
||||
function setInputValue(selector, value) {
|
||||
const element = document.querySelector(selector);
|
||||
if (element) {
|
||||
element.value = value || '';
|
||||
}
|
||||
}
|
||||
|
||||
// Isi data koordinat
|
||||
if (data.asset) {
|
||||
setInputValue('input[name="kordinat_lat"]', data.asset.kordinat_lat);
|
||||
setInputValue('input[name="kordinat_lng"]', data.asset.kordinat_lng);
|
||||
}
|
||||
|
||||
// Isi data tanah
|
||||
if (data.tanah) {
|
||||
const luasTanah = data.tanah.luas_tanah?.sesuai ||
|
||||
data.tanah.luas_tanah?.['tidak sesuai'] || '';
|
||||
setInputValue('input[name="luas_tanah"]', luasTanah);
|
||||
}
|
||||
|
||||
// Isi data bangunan
|
||||
if (data.bangunan) {
|
||||
const luasBangunan = data.bangunan.luas_tanah_bagunan?.sesuai ||
|
||||
data.bangunan.luas_tanah_bagunan?.['tidak sesuai'] || '';
|
||||
setInputValue('input[name="luas_tanah_bagunan"]', luasBangunan);
|
||||
}
|
||||
|
||||
console.log("tee", data.asset.alamat.sesuai.nama_jalan);
|
||||
|
||||
// Isi data umum
|
||||
setInputValue('input[name="alamat"]', data.asset.alamat.sesuai.nama_jalan);
|
||||
setInputValue('input[name="desa"]', data.desa);
|
||||
setInputValue('input[name="kecamatan"]', data.kecamatan);
|
||||
setInputValue('input[name="kabupaten"]', data.kabupaten);
|
||||
setInputValue('input[name="provinsi"]', data.provinsi);
|
||||
setInputValue('input[name="nama_nara_sumber"]', data.nama_nara_sumber);
|
||||
setInputValue('input[name="harga"]', data.harga);
|
||||
|
||||
// Set jenis aset dengan pengecekan
|
||||
const jenisAsetSelect = document.querySelector('select[name="jenis_aset"]');
|
||||
if (jenisAsetSelect && data.jenis_aset) {
|
||||
jenisAsetSelect.value = data.jenis_aset;
|
||||
}
|
||||
}
|
||||
|
||||
function fillPembandingData(data, index) {
|
||||
if (!data) return;
|
||||
|
||||
@@ -335,7 +467,19 @@
|
||||
function setArrayInputValue(name, value, index) {
|
||||
const element = document.getElementsByName(name)[index];
|
||||
if (element) {
|
||||
element.value = value || '';
|
||||
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
|
||||
}
|
||||
} else {
|
||||
// Jika elemen bukan select, langsung set value
|
||||
element.value = value || '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,12 +492,16 @@
|
||||
'nama_nara_sumber_pembanding[]': data.nama_nara_sumber,
|
||||
'kordinat_lat_pembanding[]': data.kordinat_lat,
|
||||
'kordinat_lng_pembanding[]': data.kordinat_lng,
|
||||
'alamat_pembanding[]': data.alamat,
|
||||
'desa_pembanding[]': data.desa,
|
||||
'kecamatan_pembanding[]': data.kecamatan,
|
||||
'kabupaten_pembanding[]': data.kabupaten,
|
||||
'provinsi_pembanding[]': data.provinsi,
|
||||
'harga_pembanding[]': data.harga
|
||||
'address_pembanding[]': data.address,
|
||||
'village_code_pembanding[]': data.village_code,
|
||||
'district_code_pembanding[]': data.district_code,
|
||||
'city_code_pembanding[]': data.city_code,
|
||||
'province_code_pembanding[]': data.province_code,
|
||||
'harga_pembanding[]': data.harga,
|
||||
'harga_diskon_pembanding[]': data.harga_diskon,
|
||||
'total_pembanding[]': data.total,
|
||||
'diskon_pembanding[]': data.diskon,
|
||||
|
||||
};
|
||||
|
||||
// Isi semua input fields
|
||||
@@ -366,31 +514,22 @@
|
||||
const imageId = `uploadedImage${index + 2}`;
|
||||
const preview = document.getElementById(imageId);
|
||||
if (preview) {
|
||||
preview.src = `/storage/pembanding/${data.foto_objek}`;
|
||||
preview.src = `/storage/${data.foto_objek}`;
|
||||
preview.classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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('Inspection Data:', inspectionData); // Debug
|
||||
console.log('Comparisons:', comparisons); // Debug
|
||||
|
||||
if (inspectionData) {
|
||||
fillObjekPenilaian(inspectionData);
|
||||
}
|
||||
|
||||
if (comparisons) {
|
||||
console.log("comparisons", comparisons);
|
||||
|
||||
comparisons.data_pembanding.forEach((comparison, index) => {
|
||||
if (index > 0) { // Skip kolom pertama karena sudah ada di template
|
||||
if (index > 0) {
|
||||
addColumn();
|
||||
}
|
||||
fillPembandingData(comparison, index);
|
||||
@@ -524,7 +663,6 @@
|
||||
document.getElementById('removeColumnBtn').addEventListener('click', removeColumn);
|
||||
|
||||
// Form submission
|
||||
document.getElementById('dataPembandingForm').addEventListener('submit', handleSubmit);
|
||||
|
||||
reinitializeEventListeners();
|
||||
}
|
||||
@@ -545,14 +683,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
|
||||
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);
|
||||
|
||||
const formData = new FormData(e.target);
|
||||
console.log('Form data entries:', Array.from(formData.entries()));
|
||||
|
||||
$.ajax({
|
||||
url: '{{ route('surveyor.storeDataPembanding') }}',
|
||||
@@ -575,6 +713,8 @@
|
||||
window.location.href =
|
||||
'{{ route('surveyor.show', ['id' => $permohonan->id]) }}';
|
||||
}
|
||||
console.log(result);
|
||||
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
|
||||
Reference in New Issue
Block a user