Merge branch 'staging' of https://git.putrakuningan.com/daengdeni/lpj into tender

This commit is contained in:
2025-02-07 09:31:11 +07:00
23 changed files with 3576 additions and 5161 deletions

View File

@@ -52,7 +52,7 @@ class PenilaiController extends Controller
$permohonanId = $request->query('permohonanId');
$documentId = $request->query('documentId');
$jaminanId = $request->query('jaminanId');
$basicData = $this->surveyorController->getCommonData();
$permohonan = $this->surveyorController->getPermohonanJaminanId($permohonanId, $documentId, $jaminanId);
$inpeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
@@ -62,7 +62,7 @@ class PenilaiController extends Controller
$forminspeksi = json_decode($inpeksi->data_form, true);
}
return view('lpj::penilai.lampiran', compact('permohonan', 'formFoto', 'forminspeksi'));
return view('lpj::penilai.lampiran', compact('permohonan', 'formFoto', 'forminspeksi','basicData'));
}
public function create()
@@ -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',

View File

@@ -340,18 +340,6 @@ class SurveyorController extends Controller
{
$validatedData = $this->validateFotoRequest($request);
try {
$log = [];
$photoCategories = [
'rute_menuju_lokasi',
'foto_lingkungan',
];
$lainnya = [
'foto_rute_lainnya' => ['foto_rute_lainnya', 'name_rute_lainnya'],
'foto_lantai_lainnya' => ['foto_lantai_lainnya', 'name_lantai_lainnya']
];
$inspeksi = Inspeksi::firstOrNew([
'permohonan_id' => $request->input('permohonan_id'),
'dokument_id' => $request->input('dokument_id')
@@ -361,62 +349,23 @@ class SurveyorController extends Controller
? json_decode($inspeksi->foto_form, true)
: [];
$formatFotojson = $existingData;
if (!$this->isValidFormat($existingData)) {
$existingData = [];
}
// Upload berbagai jenis foto
$this->handleFileUpload($request, 'rute_menuju_lokasi', $formatFotojson);
$this->handleFileUpload($request, 'foto_lingkungan', $formatFotojson);
$newFoto = $this->handleFileUpload($request, 'upload_foto', $existingData);
$this->processFotoLantaiUnit($request, $formatFotojson);
if ($request->hasFile('foto_objek')) {
$existingObjekJaminan = $formatFotojson['object_jaminan'] ?? [];
$formatFotojson['object_jaminan'] = $this->processObjekJaminanPhotos(
$request,
$existingObjekJaminan
);
}
foreach ($lainnya as $category => $fields) {
$photoField = $fields[0];
$nameField = $fields[1];
$descriptionField = $fields[2] ?? null;
if ($request->hasFile($photoField)) {
$newPhotos = $this->processPhotoLainnya(
$request,
$fields,
$existingData[$category] ?? []
);
$formatFotojson[$category] = $newPhotos;
}
}
// // Process single files
$singleFiles = ['foto_basement', 'foto_gerbang', 'pendamping'];
foreach ($singleFiles as $file) {
if ($request->hasFile($file)) {
// Hapus file lama jika ada
if (isset($formatFotojson[$file])) {
$this->deleteOfFile($formatFotojson[$file]);
}
// Upload dan simpan file baru
$formatFotojson[$file] = $this->uploadFile($request->file($file), $file);
}
}
// Update record
if (!empty($formatFotojson)) {
$inspeksi->foto_form = json_encode($formatFotojson);
if (!empty($newFoto)) {
$inspeksi->foto_form = json_encode($existingData);
$inspeksi->save();
return response()->json([
'success' => true,
'message' => 'Data berhasil disimpan',
'data' => $formatFotojson,
'log' => $log
'file' => $newFoto
], 200);
}
@@ -430,74 +379,107 @@ class SurveyorController extends Controller
}
/**
* Process a photo
*/
protected function processFotoLantaiUnit(Request $request, &$formatFotojson)
* Validasi apakah format JSON sesuai dengan yang diinginkan.
*
* @param array $data
* @return bool
*/
private function isValidFormat($data)
{
// Pastikan foto_lantai_unit sudah ada di formatFotojson
if (!isset($formatFotojson['foto_lantai_unit'])) {
$formatFotojson['foto_lantai_unit'] = [];
if (!isset($data['upload_foto']) || !is_array($data['upload_foto'])) {
return false;
}
// Ambil nama-nama lantai dari request
$lantaiNama = $request->input('lantai_nama', []);
// Tambahan: gunakan lantai_index jika tersedia
$lantaiIndex = $request->input('lantai_index', null);
// Cek apakah ada file foto lantai yang diunggah
$lantaiFiles = $request->file('foto_lantai_unit', []);
// Proses setiap file foto lantai
foreach ($lantaiFiles as $index => $files) {
// Pastikan $files adalah array
if (!is_array($files)) {
$files = [$files];
}
// Gunakan lantai_index jika tersedia, jika tidak gunakan cara sebelumnya
$lantaiNomor = $lantaiIndex ?? ($index + 1);
// Inisialisasi array untuk lantai ini jika belum ada
if (!isset($formatFotojson['foto_lantai_unit'][$lantaiNomor])) {
$formatFotojson['foto_lantai_unit'][$lantaiNomor] = [];
}
foreach ($files as $fileIndex => $file) {
// Validasi file
if (!$file->isValid()) {
continue; // Lewati file yang tidak valid
}
// Generate nama file unik
$uniqueFileName = 'lantai_unit_' . $lantaiNomor . '_' . $fileIndex . '_' . Str::random(10) . '.' . $file->getClientOriginalExtension();
// Simpan file dengan nama asli
$path = $file->storeAs(
'surveyor/lantai_unit',
$uniqueFileName . '/' . time() . '_' . $file->getClientOriginalName(),
'public'
);
// Buat nama foto
$fotoName = "Foto Lantai {$lantaiNomor} - " . ($fileIndex + 1);
// Tambahkan detail foto ke array
$fotoDetail = [
'path' => $path,
'name' => $fotoName
];
// Tambahkan ke array foto lantai unit sesuai struktur
$formatFotojson['foto_lantai_unit'][$lantaiNomor][] = $fotoDetail;
}
}
return $formatFotojson;
return true;
}
public function updateFoto(Request $request)
{
try {
// Validasi input
$validated = $request->validate([
'permohonan_id' => 'required',
'dokument_id' => 'required|string',
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'category' => 'required|string|max:255',
'sub' => 'nullable|string|max:255',
'path' => 'nullable|string',
]);
$inspeksi = Inspeksi::firstOrNew([
'permohonan_id' => $validated['permohonan_id'],
'dokument_id' => $validated['dokument_id'],
]);
$cleanRequestPath = str_replace('/storage/', '', $validated['path']);
$fotoForm = json_decode($inspeksi->foto_form, true) ?? [];
if (!isset($fotoForm['upload_foto'])) {
$fotoForm['upload_foto'] = [];
}
$existingIndex = null;
if (!empty($validated['path'])) {
foreach ($fotoForm['upload_foto'] as $index => $foto) {
if ($foto['path'] === $cleanRequestPath) {
$existingIndex = $index;
break;
}
}
}
// Siapkan data baru
$newFotoData = [
'name' => $validated['name'],
'description' => $validated['description'],
'category' => $validated['category'],
'sub' => $validated['sub'],
'path' => $cleanRequestPath,
'created_by' => Auth::user()->name,
'created_at' => now()->toDateTimeString(),
'updated_by' => Auth::user()->name,
'updated_at' => now()->toDateTimeString(),
];
if ($existingIndex !== null) {
$existingFoto = $fotoForm['upload_foto'][$existingIndex];
$fotoForm['upload_foto'][$existingIndex] = [
'name' => $validated['name'],
'description' => $validated['description'],
'category' => $validated['category'],
'sub' => $validated['sub'],
'path' => $cleanRequestPath,
'created_by' => $existingFoto['created_by'] ?? Auth::user()->name,
'created_at' => $existingFoto['created_at'] ?? now()->toDateTimeString(),
'updated_by' => Auth::user()->name,
'updated_at' => now()->toDateTimeString(),
];
} else {
$fotoForm['upload_foto'][] = $newFotoData;
}
// Simpan kembali data ke database
$inspeksi->foto_form = json_encode($fotoForm);
$inspeksi->save();
return response()->json([
'success' => true,
'message' => 'Data berhasil diperbarui.',
], 200);
} catch (\Exception $e) {
return response()->json([
'success' => false,
'message' => 'Gagal memperbarui data: ' . $e->getMessage(),
], 500);
}
}
private function handleFileUpload(Request $request, $paramName, &$formatFotojson)
{
@@ -510,45 +492,54 @@ class SurveyorController extends Controller
}
$formatFotoData = [];
$nomor_registrasi = $request->nomor_registrasi;
foreach ($files as $index => $file) {
$timestamp = time();
$originalName = $file->getClientOriginalName();
$uniqueFileName = "{$timestamp}_{$originalName}";
$extension = $file->getClientOriginalExtension();
// Validasi nama file
if (empty($originalName)) {
$originalName = "file_{$timestamp}";
}
$uniqueFileName = "{$timestamp}.{$extension}";
// Simpan file
$path = $file->storeAs("surveyor/{$paramName}", $uniqueFileName, 'public');
$nomor_registrasi = $request->nomor_registrasi;
$path = $file->storeAs("surveyor/{$paramName}/{$nomor_registrasi}", $uniqueFileName, 'public');
$fotoData = [
'name' => pathinfo($originalName, PATHINFO_FILENAME),
'path' => $path,
'name' => ucwords(str_replace('_', ' ', $paramName)) . ' - ' . ($index + 1)
'category' => 'lainnya',
'sub' => null,
'description' => null,
'created_by' => Auth::user()->name,
'created_at' => now()->toDateTimeString(),
];
$formatFotoData[] = $fotoData;
}
// Struktur JSON yang konsisten
if (!isset($formatFotojson[$paramName][$paramName][0])) {
$formatFotojson[$paramName] = [
$paramName => [
$formatFotoData
]
];
if (!isset($formatFotojson[$paramName])) {
$formatFotojson[$paramName] = $formatFotoData;
} else {
$formatFotojson[$paramName][$paramName][0] = array_merge(
$formatFotojson[$paramName][$paramName][0] ?? [],
$formatFotojson[$paramName] = array_merge(
$formatFotojson[$paramName] ?? [],
$formatFotoData
);
}
return $formatFotoData;
}
return [];
}
public function hapusFoto(Request $request)
{
try {
@@ -563,39 +554,35 @@ class SurveyorController extends Controller
);
$fotoForm = json_decode($inspeksi->foto_form, true);
if (isset($fotoForm[$paramName][$paramName][0])) {
// Filter foto yang akan dihapus
$tes = null;
$fotoForm[$paramName][$paramName][0] = array_values(
array_filter(
$fotoForm[$paramName][$paramName][0],
function ($foto) use ($cleanRequestPath) {
if ($foto['path'] === $cleanRequestPath) {
// Hapus file dari storage
\Storage::disk('public')->delete($cleanRequestPath);
return false; // Hapus elemen ini dari array
}
$tes = $foto['path'];
return true;
if (isset($fotoForm[$paramName]) && is_array($fotoForm[$paramName])) {
// Filter foto yang tidak sesuai dengan path yang akan dihapus
$fotoForm[$paramName] = array_values(array_filter(
$fotoForm[$paramName],
function ($foto) use ($cleanRequestPath) {
if ($foto['path'] === $cleanRequestPath) {
// Hapus file dari storage
\Storage::disk('public')->delete($cleanRequestPath);
return false;
}
)
);
return true;
}
));
// Reset array index
$fotoForm[$paramName][$paramName][0] = array_values($fotoForm[$paramName][$paramName][0]);
$inspeksi->foto_form = $fotoForm;
// Simpan kembali data ke database
$inspeksi->foto_form = json_encode($fotoForm);
$inspeksi->save();
return response()->json([
'success' => true,
'message' => 'Foto berhasil dihapus',
'message' => 'Foto berhasil dihapus',
], 200);
}
return response()->json(['success' => false], 400);
// Jika parameter tidak ditemukan
return response()->json([
'success' => false,
'message' => 'Foto atau parameter tidak ditemukan',
], 400);
} catch (\Exception $e) {
return response()->json([
'success' => false,
@@ -622,37 +609,32 @@ class SurveyorController extends Controller
$fotos = $this->findFotoByParamName($fotoForm, $paramName);
$param = $paramName == 'rute_menuju_lokasi' ? $fotos['rute_menuju_lokasi'][0] : $fotos['foto_lingkungan'][0];
$data = array_map(function ($foto) {
return [
'name' => $foto['name'] ?? 'Foto',
'path' => \Storage::url($foto['path']),
'path' => \Storage::url($foto['path'] ?? ''),
'category' => $foto['category'] ?? 'lainnya',
'sub' => $foto['sub'] ?? null,
'description' => $foto['description'] ?? null,
'upload_by' => $foto['upload_by'] ?? null,
];
}, $param);
}, $fotos);
return response()->json([
'fotos' => $data,
'success' => !empty($data)
'success' => !empty($data),
]);
}
private function findFotoByParamName($fotoForm, $paramName)
{
// Mapping parameter name ke struktur JSON
$paramMapping = [
'rute_menuju_lokasi' => ['rute_menuju_lokasi'],
'foto_lingkungan' => ['foto_lingkungan'],
];
// // Traverse array menggunakan mapping
$fotos = $fotoForm;
if (isset($paramMapping[$paramName])) {
foreach ($paramMapping[$paramName] as $key) {
$fotos = $fotos[$key] ?? [];
}
if (isset($fotoForm[$paramName]) && is_array($fotoForm[$paramName])) {
return $fotoForm[$paramName]; // Kembalikan array foto jika ditemukan
}
return is_array($fotos) ? $fotos : [];
// Jika parameter tidak ditemukan atau bukan array, kembalikan array kosong
return [];
}
@@ -784,38 +766,7 @@ class SurveyorController extends Controller
], 404);
}
private function processPhotoLainnya(Request $request, array $fields, array $existingPhotos = [])
{
$result = $existingPhotos; // Start with existing photos
$photoField = $fields[0];
$nameField = $fields[1];
$descriptionField = $fields[2] ?? null;
if ($request->hasFile($photoField)) {
$newFiles = $request->file($photoField, []);
$newNames = $request->input($nameField, []);
$newDescriptions = $descriptionField ? $request->input($descriptionField, []) : [];
// Process each new file
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] ?? '';
}
// Add to result
$result[] = $newPhotoEntry;
}
}
return $result;
}
private function generateUniqueFileName($file, $prefix = '')
{
@@ -839,27 +790,8 @@ class SurveyorController extends Controller
return $request->validate([
'permohonan_id' => 'required',
'dokument_id' => 'required',
'pendamping' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
'foto_objek.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
'name_objek.*' => 'required|string|max:255',
'name_lingkungan.*' => 'required|string|max:255',
'nomor_registrasi' => 'required',
'foto_rute.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
'name_rute.*' => 'required|string|max:255',
'lantai.*' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
'name_rute_lainnya.*' => 'nullable|string',
'foto_rute_lainnya.*' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
'foto_lantai_lainnya.*' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
'name_lantai_lainnya.*' => 'nullable|string|max:255',
'foto_basement.*' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
'name_basement.*' => 'nullable|string|max:255',
'foto_gerbang' => 'nullable|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
'name_gerbang' => 'nullable|string|max:255',
'name_lantai_unit' => 'array',
]);
}
@@ -1487,6 +1419,8 @@ class SurveyorController extends Controller
'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,
]);
@@ -1502,43 +1436,7 @@ class SurveyorController extends Controller
$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;
}
@@ -1571,7 +1469,75 @@ class SurveyorController extends Controller
}
}
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.
@@ -1707,6 +1673,7 @@ class SurveyorController extends Controller
$permohonan = $this->getPermohonanJaminanId($id, $dokumentId, $jaminanId);
$surveyor = $id;
$branches = Branch::all();
$provinces = Province::all();
@@ -2342,7 +2309,8 @@ class SurveyorController extends Controller
'perkerasanJalan' => PerkerasanJalan::all(),
'terletakDiArea' => TerletakArea::all(),
'tujuanPenilaian' => TujuanPenilaian::all(),
'perizinan' => Perizinan::all()
'perizinan' => Perizinan::all(),
'foto' => FotoObjekJaminan::all()
];
}