fix: tampilan detail laporan, dan ganti route print out, penambahan service
This commit is contained in:
@@ -10,7 +10,7 @@ use Modules\Lpj\Models\StatusPermohonan;
|
||||
use Modules\Lpj\Exports\LaporanPenilaiJaminanExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Models\Branch;
|
||||
use Modules\Lpj\Http\Controllers\SurveyorController;
|
||||
use Modules\Lpj\Services\PreviewLaporanService;
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use Modules\Lpj\Models\Penilai;
|
||||
|
||||
@@ -21,11 +21,11 @@ class LaporanPenilaiJaminanController extends Controller
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
|
||||
protected $surveyorController;
|
||||
protected $previewLaporanService;
|
||||
|
||||
public function __construct(SurveyorController $surveyorController)
|
||||
public function __construct(PreviewLaporanService $previewLaporanService)
|
||||
{
|
||||
$this->surveyorController = $surveyorController;
|
||||
$this->previewLaporanService = $previewLaporanService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
@@ -40,54 +40,8 @@ class LaporanPenilaiJaminanController extends Controller
|
||||
*/
|
||||
public function show($permohonan_id, $dokumen_id, $jaminan_id)
|
||||
{
|
||||
$permohonan = $this->surveyorController->getPermohonanJaminanId(
|
||||
$permohonan_id,
|
||||
$dokumen_id,
|
||||
$jaminan_id
|
||||
);
|
||||
|
||||
|
||||
|
||||
$basicData = $this->surveyorController->getCommonData();
|
||||
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonan_id)->where('dokument_id', $dokumen_id)->first();
|
||||
$lpj = Penilai::where('permohonan_id', $permohonan_id)->where('dokument_id', $dokumen_id)->first();
|
||||
|
||||
$nomorLaporan = getNomorLaporan($permohonan_id, $dokumen_id);
|
||||
$tanggalLaporan = $lpj->created_at ?? null;
|
||||
$forminspeksi = null;
|
||||
$lpjData = null;
|
||||
$formFoto = null;
|
||||
|
||||
if ($inspeksi) {
|
||||
$forminspeksi = json_decode($inspeksi->data_form, true);
|
||||
$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);
|
||||
$memo = json_decode($lpj->memo, true);
|
||||
$resumeData = json_decode($lpj->resume, true);
|
||||
$rap = json_decode($lpj->rap, true);
|
||||
$report = json_decode($lpj->call_report, true);
|
||||
}
|
||||
|
||||
$inputAddress = $forminspeksi['asset']['alamat']['sesuai'] ?? $forminspeksi['asset']['alamat']['tidak sesuai'] ?? [];
|
||||
|
||||
$alamat = [
|
||||
'address' => $inputAddress['address'] ?? null,
|
||||
'village_code' => getWilayahName($inputAddress['village_code'] ?? null, 'village'),
|
||||
'district_code' => getWilayahName($inputAddress['district_code'] ?? null, 'district'),
|
||||
'city_code' => getWilayahName($inputAddress['city_code'] ?? null, 'city'),
|
||||
'province_code' => getWilayahName($inputAddress['province_code'] ?? null, 'province')
|
||||
];
|
||||
|
||||
$statusLpj = 0;
|
||||
|
||||
// $viewLaporan = $this->getViewLaporan($tipeLaporan);
|
||||
return view('lpj::laporan-penilai-jaminan.show', compact('permohonan', 'basicData', 'forminspeksi', 'alamat', 'lpjData', 'memo', 'resumeData', 'rap', 'report', 'lpj', 'formFoto', 'nomorLaporan', 'tanggalLaporan', 'dataPembanding', 'inspeksi', 'statusLpj'));
|
||||
$back = route('laporan-penilai-jaminan.index');
|
||||
return $this->previewLaporanService->previewLaporan($permohonan_id, $dokumen_id, $jaminan_id, $back);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,18 +26,21 @@ use Modules\Lpj\Http\Requests\FormSurveyorRequest;
|
||||
use Modules\Lpj\Models\Authorization;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Services\SaveFormInspesksiService;
|
||||
use Modules\Lpj\Services\PreviewLaporanService;
|
||||
|
||||
class PenilaiController extends Controller
|
||||
{
|
||||
public $user;
|
||||
protected $surveyorController;
|
||||
protected $inspeksiService;
|
||||
protected $previewLaporanService;
|
||||
|
||||
|
||||
public function __construct(SurveyorController $surveyorController, SaveFormInspesksiService $inspeksiService)
|
||||
public function __construct(SurveyorController $surveyorController, SaveFormInspesksiService $inspeksiService, PreviewLaporanService $previewLaporanService)
|
||||
{
|
||||
$this->surveyorController = $surveyorController;
|
||||
$this->inspeksiService = $inspeksiService;
|
||||
$this->previewLaporanService = $previewLaporanService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -548,13 +551,7 @@ class PenilaiController extends Controller
|
||||
return view('lpj::penilai.components.call-report', compact('permohonan', 'basicData', 'nomorLaporan', 'forminspeksi', 'cities', 'districts', 'villages', 'cekAlamat', 'callReport'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
@@ -1277,132 +1274,13 @@ class PenilaiController extends Controller
|
||||
|
||||
|
||||
|
||||
public function print_out(Request $request)
|
||||
public function print_out_laporan($permohonan_id, $document_id, $jaminan_id)
|
||||
{
|
||||
$documentId = $request->query('documentId');
|
||||
$jaminanId = $request->query('jaminanId');
|
||||
$permohonanId = $request->query('permohonanId');
|
||||
$statusLpj = $request->query('statusLpj');
|
||||
$tipeLaporan = $request->query('type');
|
||||
|
||||
$permohonan = $this->surveyorController->getPermohonanJaminanId(
|
||||
$permohonanId,
|
||||
$documentId,
|
||||
$jaminanId
|
||||
);
|
||||
|
||||
$basicData = $this->surveyorController->getCommonData();
|
||||
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
||||
$lpj = Penilai::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
||||
|
||||
$nomorLaporan = getNomorLaporan($permohonanId, $documentId);
|
||||
$tanggalLaporan = $lpj->created_at ?? null;
|
||||
$forminspeksi = null;
|
||||
$lpjData = null;
|
||||
$formFoto = null;
|
||||
|
||||
if ($inspeksi) {
|
||||
$forminspeksi = json_decode($inspeksi->data_form, true);
|
||||
$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);
|
||||
$memo = json_decode($lpj->memo, true);
|
||||
$resumeData = json_decode($lpj->resume, true);
|
||||
$rap = json_decode($lpj->rap, true);
|
||||
$report = json_decode($lpj->call_report, true);
|
||||
}
|
||||
|
||||
$inputAddress = $forminspeksi['asset']['alamat']['sesuai'] ?? $forminspeksi['asset']['alamat']['tidak sesuai'] ?? [];
|
||||
|
||||
$alamat = [
|
||||
'address' => $inputAddress['address'] ?? null,
|
||||
'village_code' => getWilayahName($inputAddress['village_code'] ?? null, 'village'),
|
||||
'district_code' => getWilayahName($inputAddress['district_code'] ?? null, 'district'),
|
||||
'city_code' => getWilayahName($inputAddress['city_code'] ?? null, 'city'),
|
||||
'province_code' => getWilayahName($inputAddress['province_code'] ?? null, 'province')
|
||||
];
|
||||
|
||||
$viewLaporan = $this->getViewLaporan($tipeLaporan);
|
||||
try {
|
||||
|
||||
if ($statusLpj) {
|
||||
// $pdf = view('lpj::' . $viewLaporan, compact(
|
||||
$pdf = PDF::loadView('lpj::' . $viewLaporan, compact(
|
||||
'permohonan',
|
||||
'forminspeksi',
|
||||
'lpjData',
|
||||
'formFoto',
|
||||
'basicData',
|
||||
'inspeksi',
|
||||
'lpj',
|
||||
'statusLpj',
|
||||
'alamat',
|
||||
'dataPembanding',
|
||||
'nomorLaporan',
|
||||
'memo',
|
||||
'resumeData',
|
||||
'tanggalLaporan',
|
||||
'rap',
|
||||
'report'
|
||||
));
|
||||
// return $pdf;
|
||||
$cleanNomorLaporan = str_replace(['/', '\\'], '-', $nomorLaporan);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
$pdf->set_option('isHtml5ParserEnabled', true);
|
||||
$pdf->set_option('isPhpEnabled', true);
|
||||
return response($pdf->output(), 200)
|
||||
->header('Content-Type', 'application/pdf')
|
||||
->header('Content-Disposition', 'inline; filename="Laporan_' . $tipeLaporan . '_' . $permohonan->debiture->name . '_' . $cleanNomorLaporan . '.pdf"');
|
||||
// return $pdf->stream();
|
||||
} else {
|
||||
// $pdf = view('lpj::' . $viewLaporan, compact(
|
||||
$pdf = PDF::loadView('lpj::' . $viewLaporan, compact(
|
||||
'permohonan',
|
||||
'forminspeksi',
|
||||
'lpjData',
|
||||
'formFoto',
|
||||
'basicData',
|
||||
'inspeksi',
|
||||
'lpj',
|
||||
'statusLpj',
|
||||
'alamat',
|
||||
'dataPembanding',
|
||||
'nomorLaporan',
|
||||
'memo',
|
||||
'resumeData',
|
||||
'tanggalLaporan',
|
||||
'rap',
|
||||
'report'
|
||||
));
|
||||
// return $pdf;
|
||||
$cleanNomorLaporan = str_replace(['/', '\\'], '-', $nomorLaporan);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
$pdf->set_option('isHtml5ParserEnabled', true);
|
||||
$pdf->set_option('isPhpEnabled', true);
|
||||
return $pdf->download('Laporan_' . $tipeLaporan . '_' . $permohonan->debiture->name . '_' . $cleanNomorLaporan . '_data.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.' . $e->getMessage()], 500);
|
||||
}
|
||||
// jika tidak ada id kembalikan ke halaman sebelumnya
|
||||
if (!$permohonan_id || !$document_id || !$jaminan_id) {
|
||||
return redirect()->back()->with('error', 'Laporan tidak valid');
|
||||
}
|
||||
|
||||
private function getViewLaporan($tipe)
|
||||
{
|
||||
$viewMap = [
|
||||
'sederhana' => 'penilai.components.print-out-sederhana',
|
||||
'standar' => 'penilai.components.print-out-standar',
|
||||
'resume' => 'penilai.components.print-resume',
|
||||
'memo' => 'penilai.components.print-memo',
|
||||
'rap' => 'penilai.components.print-out-rap',
|
||||
'call-report' => 'penilai.components.print-out-call-report'
|
||||
];
|
||||
return $viewMap[$tipe] ?? 'penilai.components.print-resume';
|
||||
return $this->previewLaporanService->printOutLaporan($permohonan_id, $document_id, $jaminan_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -1429,48 +1307,7 @@ class PenilaiController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
public function checkPrintOutLaporan($permohonan_id, $dokumen_id)
|
||||
{
|
||||
// $permohonanId = $request->query('permohonanId');
|
||||
// $documentId = $request->query('documentId');
|
||||
$permohonanId = $permohonan_id;
|
||||
$documentId = $request->query('documentId');
|
||||
|
||||
// Ambil data berdasarkan ID
|
||||
$statusLpj = Penilai::where('permohonan_id', $permohonanId)
|
||||
->where('dokument_id', $documentId)
|
||||
->first();
|
||||
|
||||
// Jika data tidak ditemukan, kembalikan status null
|
||||
if (!$statusLpj) {
|
||||
return response()->json(['status' => null]);
|
||||
}
|
||||
|
||||
// Tentukan tipe berdasarkan kondisi
|
||||
$type = $statusLpj->type_penilai ?? null;
|
||||
|
||||
if ($type === 'memo') {
|
||||
return $this->checkDataMemo($type, $statusLpj);
|
||||
}
|
||||
|
||||
if ($type === 'resume') {
|
||||
return $this->checkDataResume($type, $statusLpj);
|
||||
}
|
||||
|
||||
|
||||
if ($type === 'standar' || $type === 'sederhana') {
|
||||
return $this->checkDataLpj($type, $statusLpj);
|
||||
}
|
||||
|
||||
if ($type === 'rap') {
|
||||
return $this->checkDataRap($type, $statusLpj);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Kembalikan respons dengan tipe yang sesuai
|
||||
return response()->json(['status' => $type]);
|
||||
}
|
||||
|
||||
|
||||
public function generateNoLaporan($permohonan, $documentId, $type)
|
||||
@@ -1510,239 +1347,6 @@ class PenilaiController extends Controller
|
||||
}
|
||||
|
||||
|
||||
public function checkDataMemo($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->memo, true) ?? [];
|
||||
|
||||
$validationRules = [
|
||||
'memo' => [
|
||||
'kepada',
|
||||
'dari',
|
||||
'nomor_memo',
|
||||
'tanggal',
|
||||
'perihal',
|
||||
'jenis_asset_tidak_sesuai',
|
||||
'lokasi.lokasi',
|
||||
'lokasi.province_code',
|
||||
'lokasi.city_code',
|
||||
'lokasi.district_code',
|
||||
'lokasi.village_code',
|
||||
'lokasi.penilai',
|
||||
'terlampir',
|
||||
'hasil_survey',
|
||||
'kesimpulan_saran',
|
||||
],
|
||||
];
|
||||
|
||||
// Validasi data JSON
|
||||
if (isset($validationRules[$type])) {
|
||||
$missingFields = [];
|
||||
|
||||
foreach ($validationRules[$type] as $field) {
|
||||
$keys = explode('.', $field);
|
||||
$value = $data;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($value[$key])) {
|
||||
$missingFields[] = $field;
|
||||
break;
|
||||
}
|
||||
$value = $value[$key];
|
||||
}
|
||||
}
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data memo terlebih dahulu.",
|
||||
'missing_fields' => $missingFields,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Jika data valid
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data memo valid.",
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function checkDataResume($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->resume, true) ?? [];
|
||||
|
||||
$validationRules = [
|
||||
'resume' => [
|
||||
'fisik'
|
||||
],
|
||||
];
|
||||
|
||||
// Validasi data JSON
|
||||
if (isset($validationRules[$type])) {
|
||||
$missingFields = [];
|
||||
|
||||
foreach ($validationRules[$type] as $field) {
|
||||
$keys = explode('.', $field);
|
||||
$value = $data;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($value[$key])) {
|
||||
$missingFields[] = $field;
|
||||
break;
|
||||
}
|
||||
$value = $value[$key];
|
||||
}
|
||||
|
||||
// Validasi khusus untuk array fisik dan sesuai_imb
|
||||
if ($field === 'fisik' || $field === 'sesuai_imb') {
|
||||
if (empty($value) || !is_array($value)) {
|
||||
$missingFields[] = $field;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validasi struktur data di dalam array
|
||||
foreach ($value as $item) {
|
||||
$requiredKeys = ['sertifikat', 'luas_tanah', 'nilai'];
|
||||
foreach ($requiredKeys as $requiredKey) {
|
||||
if (!isset($item[$requiredKey])) {
|
||||
$missingFields[] = $field . '.' . $requiredKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data resume terlebih dahulu.",
|
||||
'missing_fields' => $missingFields,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Jika data valid
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data resume valid.",
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkDataLpj($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->lpj, true) ?? [];
|
||||
|
||||
$validationRules = [
|
||||
'lpj' => [
|
||||
'luas_tanah',
|
||||
'nilai_tanah_1',
|
||||
'nilai_tanah_2',
|
||||
'luas_bangunan',
|
||||
'nilai_bangunan_1',
|
||||
'nilai_bangunan_2',
|
||||
'total_nilai_pasar_wajar',
|
||||
'likuidasi',
|
||||
'likuidasi_nilai_1',
|
||||
'likuidasi_nilai_2',
|
||||
'asuransi_luas_bangunan',
|
||||
'asuransi_nilai_1',
|
||||
'asuransi_nilai_2',
|
||||
'npw_tambahan'
|
||||
],
|
||||
];
|
||||
|
||||
// Validasi data JSON
|
||||
if (isset($validationRules[$type])) {
|
||||
$missingFields = [];
|
||||
|
||||
foreach ($validationRules[$type] as $field) {
|
||||
// Penanganan khusus untuk field yang boleh null
|
||||
if (in_array($field, ['sarana_pelengkap_penilai', 'nilai_sarana_pelengkap_1', 'nilai_sarana_pelengkap_2'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($data[$field])) {
|
||||
$missingFields[] = $field;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Validasi khusus untuk npw_tambahan
|
||||
if ($field === 'npw_tambahan' && is_array($data[$field])) {
|
||||
foreach ($data[$field] as $index => $item) {
|
||||
$requiredKeys = ['name', 'luas', 'nilai_1', 'nilai_2'];
|
||||
foreach ($requiredKeys as $key) {
|
||||
if (!isset($item[$key])) {
|
||||
$missingFields[] = "npw_tambahan[$index].$key";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data LPJ terlebih dahulu.",
|
||||
'missing_fields' => $missingFields,
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
// Jika data valid
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data LPJ valid.",
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkDataRap($type, $statusLpj)
|
||||
{
|
||||
// Ambil data JSON dari statusLpj
|
||||
$data = json_decode($statusLpj->rap, true) ?? [];
|
||||
|
||||
$requiredFields = [
|
||||
'dari',
|
||||
'kepada',
|
||||
'perihal',
|
||||
'tanggal',
|
||||
'nomor_rap'
|
||||
];
|
||||
|
||||
// Cek apakah ada field yang kosong
|
||||
$missingFields = [];
|
||||
foreach ($requiredFields as $field) {
|
||||
if (!isset($data[$field]) || empty($data[$field])) {
|
||||
$missingFields[] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
// Jika ada field yang kosong, kembalikan error
|
||||
if (!empty($missingFields)) {
|
||||
return response()->json([
|
||||
'status' => null,
|
||||
'message' => "Silahkan lengkapi data RAP terlebih dahulu.",
|
||||
'missing_fields' => $missingFields
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Jika semua data terisi
|
||||
return response()->json([
|
||||
'status' => $type,
|
||||
'message' => "Data RAP valid."
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function revisiSurveyor(Request $request, $id)
|
||||
{
|
||||
$permohonan = Permohonan::findOrFail($id);
|
||||
@@ -1773,4 +1377,24 @@ class PenilaiController extends Controller
|
||||
'message' => 'Berhasil Revisi Ke surveyor',
|
||||
], 200);
|
||||
}
|
||||
|
||||
public function showLaporanInspeksi(
|
||||
$permohonan_id,
|
||||
$dokumen_id,
|
||||
$jaminan_id,
|
||||
Request $request)
|
||||
{
|
||||
if ($request->type == 'penilai') {
|
||||
$back = route('penilai.show', $permohonan_id);
|
||||
}else{
|
||||
$back = route('surveyor.show', $permohonan_id);
|
||||
}
|
||||
|
||||
return $this->previewLaporanService->previewLaporan($permohonan_id, $dokumen_id, $jaminan_id, $back);
|
||||
}
|
||||
|
||||
public function showInspectionReportReview($permohonan_id, $dokumen_id, $jaminan_id)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2718,7 +2718,7 @@ class SurveyorController extends Controller
|
||||
$fileName = 'inspeksi-' . $namaDebiture . '-data.pdf';
|
||||
$pdf->set_option('isHtml5ParserEnabled', true);
|
||||
$pdf->set_option('isPhpEnabled', true);
|
||||
return $pdf->stream($fileName);
|
||||
return $pdf->download($fileName);
|
||||
}
|
||||
|
||||
public function approveReschedule(Request $request, $id)
|
||||
|
||||
Reference in New Issue
Block a user