fix(survyor/penilai): perbaikan view print-resume, lampiran, foto-lampiran, foto, header, main dan controller penilai dan surveyor
This commit is contained in:
@@ -96,6 +96,7 @@ class PenilaianController extends Controller
|
||||
}
|
||||
|
||||
} else {
|
||||
$teams_ids[] = $validatedData['teams_id'];
|
||||
$user_ids[] = $validatedData['surveyor_id'];
|
||||
|
||||
}
|
||||
@@ -136,13 +137,14 @@ class PenilaianController extends Controller
|
||||
$user_ids[] = $validatedData['penilai_surveyor_id'];
|
||||
}
|
||||
} else {
|
||||
$teams_ids[] = $validatedData['teams_id'];
|
||||
$user_ids[] = $validatedData['penilai_id'];
|
||||
}
|
||||
|
||||
$roles[] = 'penilai';
|
||||
}
|
||||
|
||||
// dd($teams_ids, $user_ids);
|
||||
// dd($validatedData['penilai_region_id'],$validatedData['teams_id']);
|
||||
foreach ($teams_ids as $key => $teams_id) {
|
||||
PenilaianTeam::create([
|
||||
'penilaian_id' => $validatedData['penilaian_id'],
|
||||
@@ -153,13 +155,11 @@ class PenilaianController extends Controller
|
||||
}
|
||||
|
||||
if ($validatedData['surveyor_id'] === 'pilih_dari_region' || $validatedData['penilai_id'] === 'pilih_dari_region' || $validatedData['penilai_surveyor_id'] === 'pilih_dari_region') {
|
||||
$status = $permohonan->status;
|
||||
}else {
|
||||
$status = 'reassign';
|
||||
} else {
|
||||
$status = 'assign';
|
||||
}
|
||||
|
||||
|
||||
|
||||
$permohonan->update([
|
||||
'status' => $status,
|
||||
]);
|
||||
@@ -344,7 +344,7 @@ class PenilaianController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
$query->whereIn('status', ['registered', 'registrasi-final']);
|
||||
$query->whereIn('status', ['registered', 'registrasi-final', 'reassign']);
|
||||
|
||||
// Filter berdasarkan role
|
||||
if (Auth::user()->roles[0]->name !== 'administrator') {
|
||||
|
||||
@@ -491,56 +491,78 @@ class SurveyorController extends Controller
|
||||
{
|
||||
if ($request->hasFile($paramName)) {
|
||||
$files = $request->file($paramName);
|
||||
|
||||
|
||||
// Pastikan $files adalah array
|
||||
if (!is_array($files)) {
|
||||
$files = [$files];
|
||||
}
|
||||
|
||||
|
||||
$formatFotoData = [];
|
||||
$nomor_registrasi = $request->nomor_registrasi;
|
||||
|
||||
|
||||
// Generate a unique timestamp for this batch
|
||||
$batchTimestamp = time();
|
||||
|
||||
foreach ($files as $index => $file) {
|
||||
$timestamp = time();
|
||||
$originalName = $file->getClientOriginalName();
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
|
||||
// Validasi nama file
|
||||
if (empty($originalName)) {
|
||||
$originalName = "file_{$timestamp}";
|
||||
$originalName = "file_{$batchTimestamp}";
|
||||
}
|
||||
$uniqueFileName = "{$timestamp}.{$extension}";
|
||||
|
||||
|
||||
// Use batchTimestamp and index to ensure uniqueness
|
||||
$uniqueFileName = "{$batchTimestamp}_{$index}.{$extension}";
|
||||
|
||||
// Simpan file
|
||||
$nomor_registrasi = $request->nomor_registrasi;
|
||||
$path = $file->storeAs("surveyor/{$paramName}/{$nomor_registrasi}", $uniqueFileName, 'public');
|
||||
|
||||
$fotoData = [
|
||||
'name' => pathinfo($originalName, PATHINFO_FILENAME),
|
||||
'path' => $path,
|
||||
'category' => 'lainnya',
|
||||
'sub' => null,
|
||||
'description' => null,
|
||||
'created_by' => Auth::user()->name,
|
||||
'created_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
$formatFotoData[] = $fotoData;
|
||||
|
||||
// Check if this file already exists in formatFotojson
|
||||
$fileExists = false;
|
||||
if (isset($formatFotojson[$paramName]) && is_array($formatFotojson[$paramName])) {
|
||||
foreach ($formatFotojson[$paramName] as $existingFile) {
|
||||
// Check if the original file name matches
|
||||
if (isset($existingFile['name']) &&
|
||||
$existingFile['name'] === pathinfo($originalName, PATHINFO_FILENAME)) {
|
||||
$fileExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only add if this file doesn't already exist
|
||||
if (!$fileExists) {
|
||||
$fotoData = [
|
||||
'name' => pathinfo($originalName, PATHINFO_FILENAME),
|
||||
'path' => $path,
|
||||
'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])) {
|
||||
$formatFotojson[$paramName] = $formatFotoData;
|
||||
} else {
|
||||
$formatFotojson[$paramName] = array_merge(
|
||||
$formatFotojson[$paramName] ?? [],
|
||||
$formatFotoData
|
||||
);
|
||||
|
||||
// Only update if we have new photos to add
|
||||
if (!empty($formatFotoData)) {
|
||||
// Struktur JSON yang konsisten
|
||||
if (!isset($formatFotojson[$paramName])) {
|
||||
$formatFotojson[$paramName] = $formatFotoData;
|
||||
} else {
|
||||
$formatFotojson[$paramName] = array_merge(
|
||||
$formatFotojson[$paramName] ?? [],
|
||||
$formatFotoData
|
||||
);
|
||||
}
|
||||
|
||||
return $formatFotoData;
|
||||
}
|
||||
|
||||
|
||||
return $formatFotoData;
|
||||
}
|
||||
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -699,80 +721,6 @@ class SurveyorController extends Controller
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hapusLantai(Request $request)
|
||||
{
|
||||
$permohonanId = $request->permohonan_id;
|
||||
$dokumentId = $request->dokument_id;
|
||||
|
||||
// Normalisasi path foto
|
||||
$cleanRequestPath = str_replace(['storage/', 'surveyor/'], '', $request->foto_path);
|
||||
|
||||
$inspeksi = Inspeksi::firstOrNew(
|
||||
['permohonan_id' => $permohonanId, 'dokument_id' => $dokumentId]
|
||||
);
|
||||
$fotoLantaiUnit = json_decode($inspeksi->foto_form, true);
|
||||
|
||||
// Konversi lantai ke string untuk konsistensi
|
||||
$lantai = (string)$request->lantai;
|
||||
|
||||
// Cek apakah lantai ada di array
|
||||
$pat = null;
|
||||
if (isset($fotoLantaiUnit['foto_lantai_unit'][$lantai])) {
|
||||
// Filter foto, hapus foto yang sesuai
|
||||
$fotoLantaiUnit['foto_lantai_unit'][$lantai] = array_filter(
|
||||
$fotoLantaiUnit['foto_lantai_unit'][$lantai],
|
||||
function ($foto) use ($cleanRequestPath) {
|
||||
// Normalisasi path foto yang tersimpan
|
||||
$storedPath = str_replace(['storage/', 'surveyor/'], '', $foto['path']);
|
||||
|
||||
// Jika path cocok, hapus file dari storage
|
||||
if ($storedPath === $cleanRequestPath) {
|
||||
// Hapus file dari storage dengan berbagai kemungkinan path
|
||||
$possiblePaths = [
|
||||
'storage/surveyor/lantai_unit/' . $cleanRequestPath,
|
||||
'storage/surveyor/' . $cleanRequestPath,
|
||||
'storage/' . $cleanRequestPath,
|
||||
$cleanRequestPath
|
||||
];
|
||||
|
||||
foreach ($possiblePaths as $path) {
|
||||
if (Storage::disk('public')->exists($path)) {
|
||||
Storage::disk('public')->delete($path);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false; // Hapus dari array
|
||||
}
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
// Reset index array
|
||||
$fotoLantaiUnit['foto_lantai_unit'][$lantai] = array_values($fotoLantaiUnit['foto_lantai_unit'][$lantai]);
|
||||
|
||||
// Hapus lantai jika tidak ada foto
|
||||
if (empty($fotoLantaiUnit['foto_lantai_unit'][$lantai])) {
|
||||
unset($fotoLantaiUnit['foto_lantai_unit'][$lantai]);
|
||||
}
|
||||
|
||||
// Update inspeksi
|
||||
$inspeksi->foto_form = json_encode($fotoLantaiUnit);
|
||||
$inspeksi->save();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'foto_lantai_unit' => $pat
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'gagal menghapus'
|
||||
], 404);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function generateUniqueFileName($file, $prefix = '')
|
||||
{
|
||||
@@ -797,7 +745,7 @@ class SurveyorController extends Controller
|
||||
'permohonan_id' => 'required',
|
||||
'dokument_id' => 'required',
|
||||
'nomor_registrasi' => 'required',
|
||||
'foto_rute.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
|
||||
'upload_foto.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg,webp,bmp,tiff,heic,heif|max:'. $maxSize,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user