fix(surveyor): perbaikan luas tanah, bangunan, unit not found

This commit is contained in:
majid
2025-03-04 09:36:15 +07:00
parent 5c4eb4eebb
commit e12114c3e4
6 changed files with 105 additions and 50 deletions

View File

@@ -2007,7 +2007,21 @@ class SurveyorController extends Controller
'analisa_unit' => 'luas_unit',
};
$this->updateDetails($permohonan, $key, $request->input($key));
$jenis_jaminan_mapping = [
'luas_unit' => $request->input('jenis_legalistas_jaminan_unit_id'),
'luas_bangunan' => $request->input('jenis_legalistas_jaminan_bangunan_id'),
'luas_tanah' => $request->input('jenis_legalistas_jaminan_tanah_id'),
];
$jenis_jaminan_id = $jenis_jaminan_mapping[$key] ?? 0;
// dd($jenis_jaminan_id);
$inputValue = $request->input($key);
$cleanedValue = preg_replace('/\D/', '', $inputValue);
$this->updateDetails($permohonan, $key, $cleanedValue, $jenis_jaminan_id);
}
return response()->json([
@@ -2031,7 +2045,7 @@ class SurveyorController extends Controller
]);
}
private function updateDetails($permohonan, $key, $newValue)
private function updateDetails($permohonan, $key, $newValue, $jenis_jaminan_id)
{
$document = $permohonan->documents->first();
@@ -2039,7 +2053,12 @@ class SurveyorController extends Controller
throw new \Exception("Document not found");
}
$detailsUpdate = DetailDokumenJaminan::where('dokumen_jaminan_id', $document->id)->first();
// dd($jenis_jaminan_id);
$detailsUpdate = DetailDokumenJaminan::where('dokumen_jaminan_id', $document->id)
->where('jenis_legalitas_jaminan_id', $jenis_jaminan_id)
->first();
// dd($detailsUpdate);
if (!$detailsUpdate) {
throw new \Exception("DetailDokumenJaminan not found");
@@ -2055,7 +2074,7 @@ class SurveyorController extends Controller
if (array_key_exists($key, $datas)) {
$datas[$key] = $newValue;
} else {
throw new \Exception("Key '{$key}' not found in details");
$datas[$key] = $newValue;
}
// Simpan kembali ke database