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;
}
}
}