Merge remote-tracking branch 'composer/feature/senior-officer' into staging
This commit is contained in:
@@ -305,15 +305,19 @@ class SurveyorController extends Controller
|
|||||||
|
|
||||||
$formatFotojson = $existingData;
|
$formatFotojson = $existingData;
|
||||||
|
|
||||||
// Process each photo category
|
|
||||||
foreach ($photoCategories as $category => $fields) {
|
foreach ($photoCategories as $category => $fields) {
|
||||||
// Only update if new files are provided
|
$photoField = $fields[0];
|
||||||
if ($this->categoryHasNewFiles($request, $fields)) {
|
$nameField = $fields[1];
|
||||||
// Delete old files for this category only
|
$descriptionField = $fields[2] ?? null;
|
||||||
if (isset($existingData[$category])) {
|
|
||||||
$this->deleteFilesForCategory($existingData[$category]);
|
if ($request->hasFile($photoField)) {
|
||||||
}
|
$newPhotos = $this->processPhotoCategory(
|
||||||
$formatFotojson[$category] = $this->processPhotoCategory($request, $fields);
|
$request,
|
||||||
|
$fields,
|
||||||
|
$existingData[$category] ?? []
|
||||||
|
);
|
||||||
|
|
||||||
|
$formatFotojson[$category] = $newPhotos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,29 +346,40 @@ class SurveyorController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Process a photo category and its subcategories
|
* Process a photo category and its subcategories
|
||||||
*/
|
*/
|
||||||
|
private function processPhotoCategory(Request $request, array $fields, array $existingPhotos = [])
|
||||||
private function processPhotoCategory(Request $request, array $fields)
|
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = $existingPhotos; // Start with existing photos
|
||||||
$photoField = $fields[0];
|
$photoField = $fields[0];
|
||||||
|
$nameField = $fields[1];
|
||||||
|
$descriptionField = $fields[2] ?? null;
|
||||||
|
|
||||||
if ($request->hasFile($photoField)) {
|
if ($request->hasFile($photoField)) {
|
||||||
foreach ($request->file($photoField, []) as $key => $value) {
|
$newFiles = $request->file($photoField, []);
|
||||||
$item = [];
|
$newNames = $request->input($nameField, []);
|
||||||
$item[$fields[1]] = $request->input($fields[1] . '.' . $key);
|
$newDescriptions = $descriptionField ? $request->input($descriptionField, []) : [];
|
||||||
$item[$photoField] = $this->uploadFile($value, $photoField . '.' . $key);
|
|
||||||
|
|
||||||
if (isset($fields[2])) {
|
// Process each new file
|
||||||
$item[$fields[2]] = $request->input($fields[2] . '.' . $key);
|
foreach ($newFiles as $key => $file) {
|
||||||
|
// Create new photo entry
|
||||||
|
$newPhotoEntry = [
|
||||||
|
$nameField => $newNames[$key] ?? '', // Use new name if provided
|
||||||
|
$photoField => $this->uploadFile($file, $photoField . '.' . $key)
|
||||||
|
];
|
||||||
|
|
||||||
|
// Add description if field exists
|
||||||
|
if ($descriptionField) {
|
||||||
|
$newPhotoEntry[$descriptionField] = $newDescriptions[$key] ?? '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$result[] = $item;
|
// Add to result
|
||||||
|
$result[] = $newPhotoEntry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function categoryHasNewFiles(Request $request, array $fields): bool
|
private function categoryHasNewFiles(Request $request, array $fields): bool
|
||||||
{
|
{
|
||||||
$photoField = $fields[0]; // First element is usually the photo field
|
$photoField = $fields[0]; // First element is usually the photo field
|
||||||
@@ -465,7 +480,9 @@ class SurveyorController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Get all inspeksi records for this permohonan
|
// Get all inspeksi records for this permohonan
|
||||||
$inspeksiRecords = Inspeksi::where('permohonan_id', $id)->get();
|
$inspeksiRecords = Inspeksi::with(['dokument.jenisJaminan'])
|
||||||
|
->where('permohonan_id', $id)
|
||||||
|
->get();
|
||||||
|
|
||||||
if ($inspeksiRecords->isEmpty()) {
|
if ($inspeksiRecords->isEmpty()) {
|
||||||
return response()->json(['buttonDisable' => true]);
|
return response()->json(['buttonDisable' => true]);
|
||||||
@@ -477,23 +494,20 @@ class SurveyorController extends Controller
|
|||||||
$denahForm = json_decode($inspeksi->denah_form, true);
|
$denahForm = json_decode($inspeksi->denah_form, true);
|
||||||
$dataPembanding = json_decode($inspeksi->data_pembanding, true);
|
$dataPembanding = json_decode($inspeksi->data_pembanding, true);
|
||||||
|
|
||||||
// Get jenis jaminan to check if it needs denah
|
$jenisJaminan = $inspeksi->dokument->jenisJaminan->name ?? '';
|
||||||
$jenisJaminan = JenisJaminan::find($inspeksi->dokument_id);
|
|
||||||
$isTanahBangunan = !in_array(
|
$isTanahBangunan = !in_array(
|
||||||
strtoupper($jenisJaminan->name ?? ''),
|
strtoupper($jenisJaminan->name ?? ''),
|
||||||
['KAPAL', 'PESAWAT', 'KENDARAAN', 'ALAT BERAT']
|
['KAPAL', 'PESAWAT', 'KENDARAAN', 'ALAT BERAT']
|
||||||
);
|
);
|
||||||
|
|
||||||
// Check if required forms are empty or incomplete
|
$isInvalid =
|
||||||
if (empty($dataForm) || empty($fotoForm)) {
|
empty($dataForm) ||
|
||||||
return response()->json(['buttonDisable' => true]);
|
empty($fotoForm) ||
|
||||||
}
|
(($isTanahBangunan && empty($denahForm)) ||
|
||||||
|
empty($dataPembanding));
|
||||||
|
|
||||||
if ($isTanahBangunan && empty($denahForm)) {
|
if ($isInvalid) {
|
||||||
return response()->json(['buttonDisable' => true]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($dataPembanding)) {
|
|
||||||
return response()->json(['buttonDisable' => true]);
|
return response()->json(['buttonDisable' => true]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,8 @@ class Inspeksi extends Model
|
|||||||
return $this->belongsTo(Permohonan::class, 'permohonan_id');
|
return $this->belongsTo(Permohonan::class, 'permohonan_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jenis_jaminan()
|
public function dokument()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(JenisJaminan::class, 'jenis_jaminan_id');
|
return $this->belongsTo(DokumenJaminan::class, 'dokument_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected static function newFactory(): InspeksiFactory
|
|
||||||
// {
|
|
||||||
// // return InspeksiFactory::new();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user