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)
|
||||
|
||||
597
app/Services/PreviewLaporanService.php
Normal file
597
app/Services/PreviewLaporanService.php
Normal file
@@ -0,0 +1,597 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Models\LaporanExternal;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\Branch;
|
||||
use Modules\Lpj\Models\Surveyor;
|
||||
use Modules\Lpj\Models\BentukTanah;
|
||||
use Modules\Lpj\Models\KonturTanah;
|
||||
use Modules\Location\Models\Province;
|
||||
use Modules\Location\Models\City;
|
||||
use Modules\Location\Models\District;
|
||||
use Modules\Location\Models\Village;
|
||||
use Modules\Lpj\Models\PosisiKavling;
|
||||
use Modules\Lpj\Models\KondisiFisikTanah;
|
||||
use Modules\Lpj\Models\FotoObjekJaminan;
|
||||
use Modules\Lpj\Models\Perizinan;
|
||||
use Modules\Lpj\Models\KetinggianTanah;
|
||||
use Modules\Lpj\Models\SifatBangunan;
|
||||
use Modules\Lpj\Models\JenisJaminan;
|
||||
use Modules\Lpj\Models\JenisBangunan;
|
||||
use Modules\Lpj\Models\KondisiBangunan;
|
||||
use Modules\Lpj\Models\SpekBangunan;
|
||||
use Modules\Lpj\Models\SpekKategoritBangunan;
|
||||
use Modules\Lpj\Models\SaranaPelengkap;
|
||||
use Modules\Lpj\Models\ArahMataAngin;
|
||||
use Modules\Lpj\Models\Analisa;
|
||||
use Modules\Lpj\Models\Penilaian;
|
||||
use Modules\Lpj\Models\PerkerasanJalan;
|
||||
use Modules\Lpj\Models\AnalisaFakta;
|
||||
use Modules\Lpj\Models\AnalisaLingkungan;
|
||||
use Modules\Lpj\Models\AnalisaTanahBagunan;
|
||||
use Modules\Lpj\Models\SpekBangunanAnalisa;
|
||||
use Modules\Lpj\Models\Denah;
|
||||
use Modules\Lpj\Models\FotoJaminan;
|
||||
use Modules\Lpj\Models\Lingkungan;
|
||||
use Modules\Lpj\Models\LantaiUnit;
|
||||
use Modules\Lpj\Models\Teams;
|
||||
use Modules\Lpj\Models\Lantai;
|
||||
use Modules\Lpj\Models\Inspeksi;
|
||||
use Modules\Lpj\Models\ViewUnit;
|
||||
use Modules\Lpj\Models\JenisUnit;
|
||||
use Modules\Lpj\Models\BentukUnit;
|
||||
use Modules\Lpj\Models\PosisiUnit;
|
||||
use Modules\Lpj\Models\TerletakArea;
|
||||
use Modules\Lpj\Models\FasilitasObjek;
|
||||
use Modules\Lpj\Models\MerupakanDaerah;
|
||||
use Modules\Lpj\Models\ObjekJaminan;
|
||||
use Modules\Lpj\Models\ModelAlatBerat;
|
||||
use Modules\Lpj\Models\JenisPesawat;
|
||||
use Modules\Lpj\Models\DokumenJaminan;
|
||||
use Modules\Lpj\Models\DetailDokumenJaminan;
|
||||
use Modules\Lpj\Models\JenisKapal;
|
||||
use Modules\Lpj\Models\JenisKendaraan;
|
||||
use Modules\Lpj\Models\RuteJaminan;
|
||||
use Modules\Lpj\Models\HubunganPemilikJaminan;
|
||||
use Modules\Lpj\Models\HubunganPenghuniJaminan;
|
||||
use Modules\Lpj\Models\AnalisaUnit;
|
||||
use Modules\Lpj\Models\GolonganMasySekitar;
|
||||
use Modules\Lpj\Models\TingkatKeramaian;
|
||||
use Modules\Lpj\Models\TujuanPenilaian;
|
||||
use Modules\Lpj\Models\LaluLintasLokasi;
|
||||
use Modules\Lpj\Models\SpekBagunanAnalisaDetail;
|
||||
use Modules\Lpj\Http\Requests\SurveyorRequest;
|
||||
use Modules\Lpj\Http\Requests\FormSurveyorRequest;
|
||||
use Modules\Lpj\Jobs\SendJadwalKunjunganEmailJob;
|
||||
use App\Helpers\Lpj;
|
||||
use Modules\Lpj\Models\Penilai;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
class PreviewLaporanService
|
||||
{
|
||||
public function previewLaporan($permohonan_id, $dokumen_id, $jaminan_id, $back)
|
||||
{
|
||||
$permohonan = $this->getPermohonanJaminanId(
|
||||
$permohonan_id,
|
||||
$dokumen_id,
|
||||
$jaminan_id
|
||||
);
|
||||
|
||||
$basicData = $this->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::component.show-laporan-inspeksi', compact('permohonan', 'basicData', 'forminspeksi', 'alamat', 'lpjData', 'memo', 'resumeData', 'rap', 'report', 'lpj', 'formFoto', 'nomorLaporan', 'tanggalLaporan', 'dataPembanding', 'inspeksi', 'statusLpj', 'permohonan_id', 'back'));
|
||||
}
|
||||
|
||||
public function printOutLaporan($permohonan_id, $document_id, $jaminan_id)
|
||||
{
|
||||
|
||||
$tipeLaporanResponse = $this->checkPrintOutLaporan($permohonan_id, $document_id);
|
||||
$tipeLaporan = $tipeLaporanResponse->getData();
|
||||
|
||||
if (!$tipeLaporan->status) {
|
||||
return redirect()->back()->with('error', 'Laporan tidak valid');
|
||||
}
|
||||
$permohonan = $this->getPermohonanJaminanId(
|
||||
$permohonan_id,
|
||||
$document_id,
|
||||
$jaminan_id
|
||||
);
|
||||
|
||||
$basicData = $this->getCommonData();
|
||||
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonan_id)->where('dokument_id', $document_id)->first();
|
||||
$lpj = Penilai::where('permohonan_id', $permohonan_id)->where('dokument_id', $document_id)->first();
|
||||
|
||||
$nomorLaporan = getNomorLaporan($permohonan_id, $document_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'] ?? [];
|
||||
|
||||
$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->status);
|
||||
$statusLpj = 1;
|
||||
try {
|
||||
$pdf = $this->generatePDF($viewLaporan, compact(
|
||||
'permohonan',
|
||||
'forminspeksi',
|
||||
'lpjData',
|
||||
'formFoto',
|
||||
'basicData',
|
||||
'inspeksi',
|
||||
'lpj',
|
||||
'statusLpj',
|
||||
'alamat',
|
||||
'dataPembanding',
|
||||
'nomorLaporan',
|
||||
'memo',
|
||||
'resumeData',
|
||||
'tanggalLaporan',
|
||||
'rap',
|
||||
'report'
|
||||
));
|
||||
|
||||
$cleanNomorLaporan = str_replace(['/', '\\'], '-', $nomorLaporan);
|
||||
$filename = 'Laporan_' . $tipeLaporan->status . '_' . $permohonan->debiture->name . '_' . $cleanNomorLaporan;
|
||||
|
||||
return $pdf->download($filename . '_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.'], 500);
|
||||
}
|
||||
}
|
||||
|
||||
private function generatePDF(string $viewLaporan, array $data)
|
||||
{
|
||||
$pdf = PDF::loadView('lpj::' . $viewLaporan, $data);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
$pdf->set_option('isHtml5ParserEnabled', true);
|
||||
$pdf->set_option('isPhpEnabled', true);
|
||||
|
||||
return $pdf;
|
||||
}
|
||||
|
||||
|
||||
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';
|
||||
}
|
||||
|
||||
public function checkPrintOutLaporan($permohonan_id, $dokumen_id)
|
||||
{
|
||||
|
||||
|
||||
// Ambil data berdasarkan ID
|
||||
$statusLpj = Penilai::where('permohonan_id', $permohonan_id)
|
||||
->where('dokument_id', $dokumen_id)
|
||||
->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 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."
|
||||
]);
|
||||
}
|
||||
private function getPermohonanJaminanId($id, $dokumentId, $jaminanId)
|
||||
{
|
||||
return Permohonan::with([
|
||||
'user',
|
||||
'debiture.province',
|
||||
'debiture.city',
|
||||
'debiture.district',
|
||||
'debiture.village',
|
||||
'branch',
|
||||
'tujuanPenilaian',
|
||||
'penilaian',
|
||||
'penawaran',
|
||||
'debiture.documents' => function ($query) use ($dokumentId, $jaminanId) {
|
||||
$query->where('id', $dokumentId)
|
||||
->where('jenis_jaminan_id', $jaminanId);
|
||||
}
|
||||
])->findOrFail($id);
|
||||
}
|
||||
|
||||
public function getCommonData()
|
||||
{
|
||||
return [
|
||||
'branches' => Branch::all(),
|
||||
'bentukTanah' => BentukTanah::all(),
|
||||
'konturTanah' => KonturTanah::all(),
|
||||
'posisiKavling' => PosisiKavling::all(),
|
||||
'ketinggianTanah' => KetinggianTanah::all(),
|
||||
'kondisiFisikTanah' => KondisiFisikTanah::all(),
|
||||
'jenisBangunan' => JenisBangunan::all(),
|
||||
'kondisiBangunan' => KondisiBangunan::all(),
|
||||
'sifatBangunan' => SifatBangunan::all(),
|
||||
'spekKategoriBangunan' => SpekKategoritBangunan::all(),
|
||||
'spekBangunan' => SpekBangunan::all(),
|
||||
'saranaPelengkap' => SaranaPelengkap::all(),
|
||||
'arahMataAngin' => ArahMataAngin::all(),
|
||||
'lantai' => Lantai::all(),
|
||||
'viewUnit' => ViewUnit::all(),
|
||||
'golMasySekitar' => GolonganMasySekitar::all(),
|
||||
'tingkatKeramaian' => TingkatKeramaian::all(),
|
||||
'laluLintasLokasi' => LaluLintasLokasi::all(),
|
||||
'jenisPesawat' => JenisPesawat::all(),
|
||||
'modelAlatBerat' => ModelAlatBerat::all(),
|
||||
'jenisKapal' => JenisKapal::all(),
|
||||
'jenisKendaraan' => JenisKendaraan::all(),
|
||||
'terletakArea' => TerletakArea::all(),
|
||||
'posisiUnit' => PosisiUnit::all(),
|
||||
'bentukUnit' => BentukUnit::all(),
|
||||
'fasilitasObjek' => FasilitasObjek::all(),
|
||||
'merupakanDaerah' => MerupakanDaerah::all(),
|
||||
'jenisUnit' => JenisUnit::all(),
|
||||
'jenisJaminan' => JenisJaminan::all(),
|
||||
'hubCadeb' => HubunganPemilikJaminan::all(),
|
||||
'hubPenghuni' => HubunganPenghuniJaminan::all(),
|
||||
'perkerasanJalan' => PerkerasanJalan::all(),
|
||||
'terletakDiArea' => TerletakArea::all(),
|
||||
'tujuanPenilaian' => TujuanPenilaian::all(),
|
||||
'perizinan' => Perizinan::all(),
|
||||
'foto' => FotoObjekJaminan::all()
|
||||
];
|
||||
}
|
||||
|
||||
private const HEADERS = [
|
||||
'bentuk-tanah' => ['Bentuk Tanah', 'bentuk-tanah'],
|
||||
'kontur-tanah' => ['Kontur Tanah', 'kontur-tanah'],
|
||||
'posisi-kavling' => ['Posisi Kavling', 'posisi-kavling'],
|
||||
'ketinggian-tanah' => ['Ketinggian Tanah', 'ketinggian-tanah'],
|
||||
'kondisi-fisik-tanah' => ['Kondisi Fisik Tanah', 'kondisi-fisik-tanah'],
|
||||
'jenis-bangunan' => ['Jenis Bangunan', 'jenis-bangunan'],
|
||||
'kondisi-bangunan' => ['Kondisi Bangunan', 'kondisi-bangunan'],
|
||||
'sifat-bangunan' => ['Sifat Bangunan', 'sifat-bangunan'],
|
||||
'sarana-pelengkap' => ['Sarana Pelengkap', 'sarana-pelengkap'],
|
||||
'lalu-lintas-lokasi' => ['Lalu Lintas Depan Lokasi', 'lalu-lintas-lokasi'],
|
||||
'tingkat-keramaian' => ['Tingkat Keramaian', 'tingkat-keramaian'],
|
||||
'gol-mas-sekitar' => ['Golongan Masyarakat Sekitar', 'gol-mas-sekitar'],
|
||||
'spek-kategori-bangunan' => ['Spek Kategori Bangunan', 'spek-kategori-bangunan'],
|
||||
'spek-bangunan' => ['Spek Bangunan', 'spek-bangunan'],
|
||||
'lantai-unit' => ['Lantai Unit', 'lantai-unit'],
|
||||
'view-unit' => ['View Unit', 'view-unit'],
|
||||
'perkerasan-jalan' => ['Perkerasan jalan', 'perkerasan-jalan'],
|
||||
'jenis-pesawat' => ['Jenis pesawat', 'jenis-pesawat'],
|
||||
'model-alat-berat' => ['Model alat berat', 'model-alat-berat'],
|
||||
'jenis-kapal' => ['Jenis kapal', 'jenis-kapal'],
|
||||
'jenis-kendaraan' => ['Jenis kendaraan', 'jenis-kendaraan'],
|
||||
'jenis-unit' => ['Jenis unit', 'jenis-unit'],
|
||||
'terletak-area' => ['Terletak di Area', 'terletak-area'],
|
||||
'merupakan-daerah' => ['Merupakan Daerah', 'merupakan-daerah'],
|
||||
'posisi-unit' => ['Posisi unit', 'posisi-unit'],
|
||||
'bentuk-unit' => ['Bentuk unit', 'bentuk-unit'],
|
||||
'fasilitas-objek' => ['Fasilitas Umum Dekat Objek', 'fasilitas-objek'],
|
||||
'foto-objek-jaminan' => ['Foto Objek Jaminan', 'foto-objek-jaminan'],
|
||||
'perizinan' => ['Perizinan', 'perizinan'],
|
||||
];
|
||||
|
||||
}
|
||||
107
app/Services/TypeLaporanService.php
Normal file
107
app/Services/TypeLaporanService.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Services;
|
||||
|
||||
class TypeLaporanService
|
||||
{
|
||||
public function handleRequest($type, $permohonanId, $documentId, $jaminanId, $surveyorController)
|
||||
{
|
||||
$permohonan = $this->getPermohonanData($surveyorController, $permohonanId, $documentId, $jaminanId);
|
||||
|
||||
if ($permohonan->status == 'proses-laporan') {
|
||||
throw new \Exception('Masih dalam proses laporan');
|
||||
}
|
||||
|
||||
$nomorLaporan = $this->generateNomorLaporan($surveyorController, $permohonan, $documentId, $type);
|
||||
$inspeksi = $this->getInspeksi($permohonanId, $documentId);
|
||||
$this->updatePenilai($permohonanId, $documentId, $type);
|
||||
|
||||
$debitur = Debiture::find($permohonan->debiture_id);
|
||||
$forminspeksi = $inspeksi ? json_decode($inspeksi->data_form, true) : null;
|
||||
|
||||
$locationCodes = $this->getAlamatData($debitur, $forminspeksi);
|
||||
$locationData = $this->getLocationData(
|
||||
$locationCodes['provinceCode'],
|
||||
$locationCodes['cityCode'],
|
||||
$locationCodes['districtCode'],
|
||||
$forminspeksi
|
||||
);
|
||||
|
||||
return [
|
||||
'permohonan' => $permohonan,
|
||||
'nomorLaporan' => $nomorLaporan,
|
||||
'basicData' => $surveyorController->getCommonData(),
|
||||
'cities' => $locationData['cities'],
|
||||
'districts' => $locationData['districts'],
|
||||
'villages' => $locationData['villages'],
|
||||
'forminspeksi' => $forminspeksi,
|
||||
];
|
||||
}
|
||||
|
||||
private function getPermohonanData($surveyorController, $permohonanId, $documentId, $jaminanId)
|
||||
{
|
||||
return $surveyorController->getPermohonanData($permohonanId, $documentId, $jaminanId);
|
||||
}
|
||||
|
||||
private function generateNomorLaporan($surveyorController, $permohonan, $documentId, $type)
|
||||
{
|
||||
return $surveyorController->generateNomorLaporan($permohonan, $documentId, $type);
|
||||
}
|
||||
|
||||
private function getInspeksi($permohonanId, $documentId)
|
||||
{
|
||||
return Inspeksi::where('permohonan_id', $permohonanId)
|
||||
->where('document_id', $documentId)
|
||||
->first();
|
||||
}
|
||||
|
||||
private function updatePenilai($permohonanId, $documentId, $type)
|
||||
{
|
||||
// Logika untuk memperbarui data berdasarkan tipe laporan
|
||||
}
|
||||
|
||||
private function getAlamatData($debitur, $forminspeksi)
|
||||
{
|
||||
return [
|
||||
'provinceCode' => $debitur->province_id ?? $forminspeksi['province'],
|
||||
'cityCode' => $debitur->city_id ?? $forminspeksi['city'],
|
||||
'districtCode' => $debitur->district_id ?? $forminspeksi['district'],
|
||||
];
|
||||
}
|
||||
|
||||
private function getLocationData($provinceCode, $cityCode, $districtCode, $forminspeksi)
|
||||
{
|
||||
return [
|
||||
'cities' => $this->fetchCityData($provinceCode),
|
||||
'districts' => $this->fetchDistrictData($cityCode),
|
||||
'villages' => $this->fetchVillageData($districtCode),
|
||||
];
|
||||
}
|
||||
|
||||
private function fetchCityData($provinceCode)
|
||||
{
|
||||
return City::where('province_code', $provinceCode)->get();
|
||||
}
|
||||
private function fetchDistrictData($cityCode)
|
||||
{
|
||||
return District::where('city_code', $cityCode)->get();
|
||||
}
|
||||
private function fetchVillageData($districtCode)
|
||||
{
|
||||
return Village::where('district_code', $districtCode)->get();
|
||||
}
|
||||
|
||||
private function updateOrCreatePenilai($permohonan_id, $document_id, $type, $data)
|
||||
{
|
||||
return Penilai::updateOrCreate(
|
||||
[
|
||||
'permohonan_id' => $permohonan_id,
|
||||
'dokument_id' => $document_id,
|
||||
|
||||
],
|
||||
[
|
||||
$type => json_encode($data),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user