fix(surveyor dan penilai): perbaikan upload foto dan print out
This commit is contained in:
@@ -1043,7 +1043,7 @@ class PenilaiController extends Controller
|
||||
|
||||
if ($statusLpj) {
|
||||
// $pdf = view('lpj::' . $viewLaporan, compact(
|
||||
$pdf = PDF::loadView('lpj::' . $viewLaporan, compact(
|
||||
$pdf = PDF::loadView('lpj::' . $viewLaporan, compact(
|
||||
'permohonan',
|
||||
'forminspeksi',
|
||||
'lpjData',
|
||||
|
||||
@@ -384,14 +384,14 @@ class SurveyorController extends Controller
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
private function isValidFormat($data)
|
||||
{
|
||||
if (!isset($data['upload_foto']) || !is_array($data['upload_foto'])) {
|
||||
return false;
|
||||
}
|
||||
private function isValidFormat($data)
|
||||
{
|
||||
if (!isset($data['upload_foto']) || !is_array($data['upload_foto'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function updateFoto(Request $request)
|
||||
@@ -1419,6 +1419,8 @@ private function isValidFormat($data)
|
||||
'permohonan_id' => 'required|exists:permohonan,id',
|
||||
'type' => 'required|string',
|
||||
'dokument_id' => 'required',
|
||||
'name_foto_objek' => 'nullable|string',
|
||||
'nomor_registrasi' => 'required|string',
|
||||
'foto_objek' => 'nullable|image|max:'.$maxSize,
|
||||
'foto_objek_pembanding.*' => 'nullable|image|max:'.$maxSize,
|
||||
]);
|
||||
@@ -1434,43 +1436,7 @@ private function isValidFormat($data)
|
||||
$objekPenilaian = $this->formatObjekPenilaian($request);
|
||||
}
|
||||
if ($request->hasFile('foto_objek')) {
|
||||
$newFoto = $this->handleupdateOrDeleteFile(
|
||||
$request->file('foto_objek'),
|
||||
$request['type'] = 'pembanding',
|
||||
'objek_penilaian'
|
||||
);
|
||||
|
||||
// Update foto_form
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))
|
||||
->where('dokument_id', $request->input('dokument_id'))
|
||||
->first();
|
||||
|
||||
if ($inspeksi) {
|
||||
$fotoForm = json_decode($inspeksi->foto_form, true) ?: [];
|
||||
if (!isset($fotoForm['object_jaminan'])) {
|
||||
$fotoForm['object_jaminan'] = [];
|
||||
}
|
||||
if (empty($fotoForm['object_jaminan'])) {
|
||||
$fotoForm['object_jaminan'][] = [
|
||||
'name_objek' => 'Tampak Depan Objek',
|
||||
'foto_objek' => $newFoto,
|
||||
'deskripsi_objek' => ''
|
||||
];
|
||||
} else {
|
||||
// Update objek pertama dalam array object_jaminan
|
||||
$fotoForm['object_jaminan'][0]['foto_objek'] = $newFoto;
|
||||
|
||||
// Tambahkan nama dan deskripsi jika belum ada
|
||||
if (!isset($fotoForm['object_jaminan'][0]['name_objek'])) {
|
||||
$fotoForm['object_jaminan'][0]['name_objek'] = 'Tampak Depan Objek';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$inspeksi->foto_form = json_encode($fotoForm);
|
||||
$inspeksi->save();
|
||||
}
|
||||
|
||||
$newFoto = $this->handleEditTampakDepan($request);
|
||||
$objekPenilaian['foto_objek'] = $newFoto;
|
||||
}
|
||||
|
||||
@@ -1503,7 +1469,75 @@ private function isValidFormat($data)
|
||||
}
|
||||
}
|
||||
|
||||
public function handleEditTampakDepan(Request $request)
|
||||
{
|
||||
|
||||
$nomor_registrasi = $request->nomor_registrasi;
|
||||
|
||||
// Ambil data inspeksi
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))
|
||||
->where('dokument_id', $request->input('dokument_id'))
|
||||
->firstOrFail();
|
||||
|
||||
// Bersihkan path dari request
|
||||
$cleanRequestPath = str_replace('/storage/', '', $request['path']);
|
||||
|
||||
// Ambil foto_form dari inspeksi
|
||||
$fotoForm = json_decode($inspeksi->foto_form, true) ?? [];
|
||||
$fotoForm['upload_foto'] = $fotoForm['upload_foto'] ?? [];
|
||||
|
||||
$existingIndex = null;
|
||||
if (!empty($request['path'])) {
|
||||
foreach ($fotoForm['upload_foto'] as $index => $foto) {
|
||||
if ($foto['path'] === $cleanRequestPath) {
|
||||
$existingIndex = $index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->hasFile('foto_objek')) {
|
||||
$file = $request->file('foto_objek');
|
||||
$timestamp = time();
|
||||
$originalName = $file->getClientOriginalName();
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
|
||||
// Validasi nama file
|
||||
if (empty($originalName)) {
|
||||
$originalName = "file_{$timestamp}";
|
||||
}
|
||||
$uniqueFileName = "{$timestamp}.{$extension}";
|
||||
|
||||
// Simpan file ke penyimpanan publik
|
||||
$path = $file->storeAs("surveyor/upload_foto/{$nomor_registrasi}", $uniqueFileName, 'public');
|
||||
|
||||
// Data baru untuk foto
|
||||
$newFotoData = [
|
||||
'name' => $originalName,
|
||||
'description' => null,
|
||||
'category' => 'Tampak Depan',
|
||||
'sub' => null,
|
||||
'path' => $path,
|
||||
'created_by' => Auth::user()->name,
|
||||
'created_at' => now()->toDateTimeString(),
|
||||
'updated_by' => Auth::user()->name,
|
||||
'updated_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
// Update atau tambahkan data baru
|
||||
if ($existingIndex !== null) {
|
||||
$fotoForm['upload_foto'][$existingIndex] = $newFotoData;
|
||||
} else {
|
||||
$fotoForm['upload_foto'][] = $newFotoData;
|
||||
}
|
||||
|
||||
// Simpan kembali data ke database
|
||||
$inspeksi->foto_form = json_encode($fotoForm);
|
||||
$inspeksi->save();
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Form inspeksi.
|
||||
|
||||
Reference in New Issue
Block a user