update print out laporan

This commit is contained in:
majid76
2024-12-27 04:16:01 +07:00
parent 7c55d7624e
commit decca9be29
12 changed files with 2840 additions and 1870 deletions

View File

@@ -13,6 +13,9 @@ use Maatwebsite\Excel\Facades\Excel;
use Modules\Lpj\Exports\KertasKerjaExport;
use Modules\Lpj\Http\Controllers\SurveyorController;
use Modules\Location\Models\Province;
use Modules\Location\Models\City;
use Modules\Location\Models\District;
use Modules\Location\Models\Village;
use Illuminate\Support\Facades\Log;
class PenilaiController extends Controller
@@ -603,27 +606,37 @@ class PenilaiController extends Controller
$formFoto = json_decode($inspeksi->foto_form, true);
// $denahForm = json_decode($data->denah_form, true);
$dataPembanding = json_decode($inspeksi->data_pembanding, true);
}
if ($lpj) {
$lpjData = json_decode($lpj->lpj, true);
}
$inputAddress = $forminspeksi['asset']['alamat']['sesuai'] ?? $forminspeksi['asset']['alamat']['tidak sesuai'];
$alamat = [
'address' => $inputAddress['address'] ?? null,
'village_code' => $this->getWilayahName($inputAddress['village_code'] ?? null, 'village'),
'district_code' => $this->getWilayahName($inputAddress['district_code'] ?? null, 'district'),
'city_code' => $this->getWilayahName($inputAddress['city_code'] ?? null, 'city'),
'province_code' => $this->getWilayahName($inputAddress['province_code'] ?? null, 'province')
];
$laporan = $lpj->type == 'sederhana' ? true : false;
$viewLaporan = null;
if($laporan){
$viewLaporan = 'penilai.components.print-out-sederhana';
}else{
$viewLaporan = 'penilai.components.print-out-standard';
}
try {
// if ($statusLpj) {
// return view('lpj::penilai.components.print-out-laporan', compact(
// 'permohonan',
// 'forminspeksi',
// 'lpjData',
// 'formFoto',
// 'basicData',
// 'inspeksi',
// 'lpj',
// 'statusLpj'
// ));
// }else{
$pdf = PDF::loadView('lpj::penilai.components.print-out-laporan', compact(
if ($statusLpj) {
return view('lpj::' . $viewLaporan, compact(
'permohonan',
'forminspeksi',
'lpjData',
@@ -631,19 +644,67 @@ class PenilaiController extends Controller
'basicData',
'inspeksi',
'lpj',
'statusLpj'
'statusLpj',
'alamat',
'dataPembanding'
));
}else{
$pdf = PDF::loadView('lpj::' . $viewLaporan, compact(
'permohonan',
'forminspeksi',
'lpjData',
'formFoto',
'basicData',
'inspeksi',
'lpj',
'statusLpj',
'alamat',
'dataPembanding'
));
$pdf->setPaper('A4', 'portrait');
return $pdf->download('laporan.pdf');
// }
}
} catch (\Exception $e) {
Log::error('PDF generation failed: ' . $e->getMessage());
return response()->json(['error' => 'Failed to generate PDF. Please check the log for details.'], 500);
return response()->json(['error' => 'Failed to generate PDF. Please check the log for details.'. $e->getMessage()], 500);
}
}
function getWilayahName($code, $type) {
try {
$wilayah = null;
if (!$code) {
return null;
}
switch($type) {
case 'province':
$wilayah = Province::where('code', $code)->first();
return $wilayah ? $wilayah->name : null;
case 'city':
$wilayah = City::where('code', $code)->first();
return $wilayah ? $wilayah->name : null;
case 'district':
$wilayah = District::where('code', $code)->first();
return $wilayah ? $wilayah->name : null;
case 'village':
$wilayah = Village::where('code', $code)->first();
return $wilayah ? $wilayah->name : null;
default:
return null;
}
} catch (\Exception $e) {
return null;
}
}
}

View File

@@ -306,6 +306,10 @@ class SurveyorController extends Controller
$formatFotojson = $existingData;
if ($request->has('foto_lantai_unit')) {
$formatFotojson['foto_lantai_unit'] = $this->processFotoLantaiUnit($request);
}
foreach ($photoCategories as $category => $fields) {
$photoField = $fields[0];
$nameField = $fields[1];
@@ -380,6 +384,44 @@ class SurveyorController extends Controller
return $result;
}
private function processFotoLantaiUnit(Request $request)
{
$processedFotoLantaiUnit = [];
// Ambil semua file foto lantai unit
$fotoLantaiUnit = $request->file('foto_lantai_unit', []);
foreach ($fotoLantaiUnit as $lantaiKey => $files) {
$processedFiles = [];
foreach ($files as $index => $file) {
// Pastikan file valid
if ($file && $file->isValid()) {
// Generate unique filename
$filename = $this->generateUniqueFileName($file, "lantai_unit_{$lantaiKey}_{$index}");
$processedFiles[] = [
'path' => $this->uploadFile($file, $filename . '.' . $index),
'name' => "Foto Lantai {$lantaiKey} - " . ($index + 1),
];
}
}
// Simpan file yang diproses dengan kunci lantai
if (!empty($processedFiles)) {
$processedFotoLantaiUnit[$lantaiKey] = $processedFiles;
}
}
return $processedFotoLantaiUnit;
}
// Fungsi helper untuk generate nama file unik
private function generateUniqueFileName($file, $prefix = '')
{
$extension = $file->getClientOriginalExtension();
return $prefix . '_' . uniqid() . '.' . $extension;
}
private function categoryHasNewFiles(Request $request, array $fields): bool
{
@@ -425,8 +467,7 @@ class SurveyorController extends Controller
'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_lantai_unit.*' => 'nullable|string|max:255',
'foto_lantai_unit.*' => 'required|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,
@@ -435,6 +476,11 @@ class SurveyorController extends Controller
'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',
'foto_lantai_unit' => 'array',
'foto_lantai_unit.*' => 'array',
]);
}