Merge branch 'fix/save-penilai' into feature/senior-officer

This commit is contained in:
majid
2025-03-09 12:26:24 +07:00
38 changed files with 1292 additions and 2145 deletions

View File

@@ -2309,6 +2309,41 @@ class SurveyorController extends Controller
];
private function updateOrDeleteFile($data, $request, $fileKey)
{
if ($request->hasFile($fileKey)) {
$file = $request->file($fileKey);
if ($file->isValid()) {
$fileName = time() . '_' . $file->getClientOriginalName();
$path = $file->storeAs("public/surveyor/{$request->type}", $fileName);
if ($path === false) {
throw new Exception("Failed to store file for {$fileKey}");
}
if (isset($data[$fileKey]) && $data[$fileKey]) {
$this->deleteFile($data[$fileKey]);
}
return str_replace('public/', '', $path);
} else {
throw new Exception("Invalid file upload for {$fileKey}");
}
} elseif (isset($data[$fileKey]) && $data[$fileKey]) {
return $data[$fileKey];
} else {
return null;
}
}
private function deleteFile($filePath)
{
$fullPath = storage_path('app/public/' . $filePath);
if (file_exists($fullPath)) {
unlink($fullPath);
}
}
/**
* Helper untuk upload file
*
@@ -2334,7 +2369,6 @@ class SurveyorController extends Controller
return str_replace('public/', '', $path);
}
/**
* Helper untuk memetakan array dengan inputannya
*
@@ -2598,7 +2632,8 @@ class SurveyorController extends Controller
// Tentukan nama file PDF
$namaDebiture = $permohonan->debiture->name . '-' . $permohonan->nomor_registrasi;
$fileName = 'inspeksi-' . $namaDebiture . '-data.pdf';
$pdf->set_option('isHtml5ParserEnabled', true);
$pdf->set_option('isPhpEnabled', true);
return $pdf->stream($fileName);
}