712 lines
24 KiB
PHP
712 lines
24 KiB
PHP
<?php
|
|
|
|
namespace Modules\Lpj\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Barryvdh\DomPDF\Facade\Pdf; // https://github.com/barryvdh/laravel-dompdf
|
|
use Modules\Lpj\Models\Permohonan;
|
|
use Modules\Lpj\Models\Inspeksi;
|
|
use Modules\Lpj\Models\Penilai;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Facades\Auth;
|
|
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
|
|
{
|
|
public $user;
|
|
|
|
protected $surveyorController;
|
|
|
|
public function __construct(SurveyorController $surveyorController)
|
|
{
|
|
$this->surveyorController = $surveyorController;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('lpj::penilai.index');
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function lampiran(Request $request, $id)
|
|
{
|
|
|
|
$permohonanId = $request->query('permohonanId');
|
|
$documentId = $request->query('documentId');
|
|
$jaminanId = $request->query('jaminanId');
|
|
|
|
$permohonan = $this->surveyorController->getPermohonanJaminanId($id, $documentId, $jaminanId);
|
|
$inpeksi = Inspeksi::where('permohonan_id', $id)->where('dokument_id', $documentId)->first();
|
|
|
|
$formFoto = null;
|
|
if ($inpeksi) {
|
|
$formFoto = json_decode($inpeksi->foto_form, true);
|
|
}
|
|
|
|
return view('lpj::penilai.lampiran', compact('permohonan', 'formFoto'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('lpj::create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function sederhana(Request $request, $id)
|
|
{
|
|
|
|
$documentId = $request->query('documentId');
|
|
$jaminanId = $request->query('jaminanId');
|
|
|
|
$permohonan = $this->surveyorController->getPermohonanJaminanId($id, $documentId, $jaminanId);
|
|
$basicData = $this->surveyorController->getCommonData();
|
|
|
|
$inspeksi = Inspeksi::where('permohonan_id', $id)->where('dokument_id', $documentId)->first();
|
|
$lpj = Penilai::where('permohonan_id', $id)->where('dokument_id', $documentId)->first();
|
|
|
|
$forminspeksi = null;
|
|
$lpjData = null;
|
|
if ($inspeksi) {
|
|
$forminspeksi = json_decode($inspeksi->data_form, true);
|
|
}
|
|
|
|
if ($lpj) {
|
|
$lpjData = json_decode($lpj->lpj, true);
|
|
}
|
|
|
|
return view('lpj::penilai.components.lpj-sederhana-standard', compact('permohonan', 'forminspeksi', 'basicData', 'inspeksi', 'lpjData'));
|
|
}
|
|
|
|
public function standard(Request $request, $id)
|
|
{
|
|
|
|
$documentId = $request->query('documentId');
|
|
$jaminanId = $request->query('jaminanId');
|
|
|
|
$permohonan = $this->surveyorController->getPermohonanJaminanId($id, $documentId, $jaminanId);
|
|
$basicData = $this->surveyorController->getCommonData();
|
|
|
|
$inspeksi = Inspeksi::where('permohonan_id', $id)->where('dokument_id', $documentId)->first();
|
|
$lpj = Penilai::where('permohonan_id', $id)->where('dokument_id', $documentId)->first();
|
|
|
|
$forminspeksi = null;
|
|
$lpjData = null;
|
|
if ($inspeksi) {
|
|
$forminspeksi = json_decode($inspeksi->data_form, true);
|
|
}
|
|
|
|
if ($lpj) {
|
|
$lpjData = json_decode($lpj->lpj, true);
|
|
}
|
|
|
|
return view('lpj::penilai.components.lpj-sederhana-standard', compact('permohonan', 'forminspeksi', 'basicData', 'inspeksi', 'lpjData'));
|
|
}
|
|
|
|
public function resume(Request $request)
|
|
{
|
|
$permohonanId = $request->query('permohonanId');
|
|
$documentId = $request->query('documentId');
|
|
$inspeksiId = $request->query('inspeksiId');
|
|
$jaminanId = $request->query('jaminanId');
|
|
|
|
$permohonan = $this->surveyorController->getPermohonanJaminanId($permohonanId, $documentId, $jaminanId);
|
|
$inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
|
|
|
|
|
$resume = Penilai::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
|
$lpjData = null;
|
|
if ($resume) {
|
|
$resumeData = json_decode($resume->resume, true);
|
|
}
|
|
|
|
return view('lpj::penilai.components.resume', compact('permohonan', 'resumeData'));
|
|
}
|
|
|
|
public function memo(Request $request)
|
|
{
|
|
$permohonanId = $request->query('permohonanId');
|
|
$documentId = $request->query('documentId');
|
|
$inspeksiId = $request->query('inspeksiId');
|
|
$jaminanId = $request->query('jaminanId');
|
|
|
|
$permohonan = $this->surveyorController->getPermohonanJaminanId($permohonanId, $documentId, $jaminanId);
|
|
$inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
|
|
|
$provinces = Province::all();
|
|
$basicData = $this->surveyorController->getCommonData();
|
|
|
|
$formFoto = null;
|
|
$formPeta = null;
|
|
if ($inspeksi) {
|
|
$formFoto = json_decode($inspeksi->foto_form, true);
|
|
$formPeta = json_decode($inspeksi->data_form, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('lpj::penilai.components.memo', compact('permohonan', 'formFoto', 'formPeta', 'provinces', 'basicData'));
|
|
}
|
|
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$permohonan = Permohonan::with(['debiture.documents.jenisjaminan', 'region.teams.teamsUsers.user', 'penilaian', 'documents.inspeksi'])->find($id);
|
|
|
|
// return response()->json(['permohonan' => $permohonan]);
|
|
return view('lpj::penilai.show', compact('permohonan'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
return view('lpj::edit');
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function paparan(Request $request)
|
|
{
|
|
|
|
$permohonanId = $request->query('permohonanId');
|
|
$documentId = $request->query('documentId');
|
|
$inspeksiId = $request->query('inspeksiId');
|
|
$jaminanId = $request->query('jaminanId');
|
|
|
|
$permohonan = $this->surveyorController->getPermohonanJaminanId($permohonanId, $documentId, $jaminanId);
|
|
$penilai = Penilai::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
|
$inspeksi = Inspeksi::where('permohonan_id', $permohonanId)->where('dokument_id', $documentId)->first();
|
|
$formFoto = null;
|
|
if ($inspeksi) {
|
|
$formFoto = json_decode($inspeksi->foto_form, true);
|
|
}
|
|
|
|
return view('lpj::penilai.components.paparan', compact('permohonan', 'formFoto', 'penilai'));
|
|
}
|
|
|
|
|
|
public function rap(Request $request)
|
|
{
|
|
$permohonanId = $request->query('permohonanId');
|
|
return view('lpj::penilai.components.paparan');
|
|
}
|
|
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function dataForDatatables(Request $request)
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('penilai.view')) {
|
|
//abort(403, 'Sorry! You are not allowed to view users.');
|
|
}
|
|
|
|
// Retrieve data from the database
|
|
$query = Permohonan::query();
|
|
|
|
// Apply search filter if provided
|
|
if ($request->has('search') && !empty($request->get('search'))) {
|
|
$search = $request->get('search');
|
|
$columns = ['nomor_registrasi', 'debiture.name', 'branch.name', 'user.name', 'tujuanPenilaian.name', 'jenisfasilitasKredit.name'];
|
|
|
|
$query->where(function ($q) use ($search, $columns) {
|
|
foreach ($columns as $column) {
|
|
$q->orWhereRelation(explode('.', $column)[0], explode('.', $column)[1], 'LIKE', '%' . $search . '%');
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
if (!Auth::user()->hasRole('administrator')) {
|
|
$query->whereHas('penilaian.userPenilai', function ($q) {
|
|
$q
|
|
->where('role', 'penilai')
|
|
->where('user_id', Auth::user()->id);
|
|
});
|
|
}
|
|
|
|
// Apply sorting if provided
|
|
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
|
$order = $request->get('sortOrder');
|
|
$column = $request->get('sortField');
|
|
$query->orderBy($column, $order);
|
|
}
|
|
|
|
// Get the total count of records
|
|
$totalRecords = $query->count();
|
|
|
|
// Apply pagination if provided
|
|
if ($request->has('page') && $request->has('size')) {
|
|
$page = $request->get('page');
|
|
$size = $request->get('size');
|
|
$offset = ($page - 1) * $size;
|
|
|
|
$query->skip($offset)->take($size);
|
|
}
|
|
|
|
// Get the filtered count of records
|
|
$filteredRecords = $query->count();
|
|
|
|
// Get the data for the current page
|
|
$data = $query->with([
|
|
'user',
|
|
'debiture',
|
|
'branch',
|
|
'tujuanPenilaian',
|
|
'jenisfasilitasKredit',
|
|
'penilaian.userPenilai' // Ensure this relation is included
|
|
])->get();
|
|
|
|
// Calculate the page count
|
|
$pageCount = ceil($totalRecords / $request->get('size'));
|
|
|
|
// Calculate the current page number
|
|
$currentPage = $request->get('page', 1);
|
|
|
|
// Return the response data as a JSON object
|
|
return response()->json([
|
|
'draw' => $request->get('draw'),
|
|
'recordsTotal' => $totalRecords,
|
|
'recordsFiltered' => $filteredRecords,
|
|
'pageCount' => $pageCount,
|
|
'page' => $currentPage,
|
|
'totalCount' => $totalRecords,
|
|
'data' => $data,
|
|
]);
|
|
}
|
|
|
|
public function export_kertas_kerja(Request $request)
|
|
{
|
|
$permohonanId = $request->query('permohonanId');
|
|
$documentId = $request->query('documentId');
|
|
|
|
// Fetch the data from the database
|
|
$data = Inspeksi::where('permohonan_id', $permohonanId)
|
|
->where('dokument_id', $documentId)
|
|
->first();
|
|
|
|
// Check if data exists
|
|
if (!$data) {
|
|
return response()->json(['message' => 'Data not found'], 404);
|
|
}
|
|
|
|
// Decode the JSON fields
|
|
$dataForm = json_decode($data->data_form, true);
|
|
$fotoForm = json_decode($data->foto_form, true);
|
|
$denahForm = json_decode($data->denah_form, true);
|
|
$dataPembanding = json_decode($data->data_pembanding, true);
|
|
|
|
// Prepare the data for export
|
|
$exportData = [
|
|
'objek' => [
|
|
'jenis_aset' => $dataForm['asset']['jenis_asset']['sesuai'] ?? '',
|
|
'luas_tanah' => $dataForm['tanah']['luas_tanah']['tidak sesuai'] ?? '',
|
|
'harga' => $dataForm['asset']['harga'] ?? '',
|
|
'tanggal_penawaran' => $dataForm['tanggal_penawaran'] ?? '',
|
|
'diskon' => $dataForm['diskon'] ?? '',
|
|
'no_telepon' => $dataForm['no_telepon'] ?? '',
|
|
'nama_nara_sumber' => $dataForm['nama_nara_sumber'] ?? '',
|
|
'status_nara_sumber' => $dataForm['status_nara_sumber'] ?? '',
|
|
'alamat' => $dataForm['alamat'] ?? '',
|
|
// Add other fields as necessary
|
|
],
|
|
'pembanding1' => [],
|
|
'pembanding2' => [],
|
|
'pembanding3' => [],
|
|
'foto_peta' => [
|
|
'foto_tempat' => $dataForm['foto_tempat'] ?? [],
|
|
'foto_gistaru' => $dataForm['foto_gistaru'] ?? [],
|
|
'foto_bhumi' => $dataForm['foto_bhumi'] ?? [],
|
|
'foto_argis_region' => $dataForm['foto_argis_region'] ?? [],
|
|
],
|
|
'foto_objek' => $fotoForm['object_jaminan'] ?? [],
|
|
'foto_objek1' => [], // Populate with relevant data
|
|
'foto_objek2' => [], // Populate with relevant data
|
|
'tanggal_penilaian' => $data->tanggal_penilaian ?? '',
|
|
'nama_pemilik' => $data->nama_pemilik ?? '',
|
|
'lokasi_lengkap' => $data->lokasi_lengkap ?? '',
|
|
];
|
|
|
|
// Extract data pembanding
|
|
if (isset($dataPembanding['data_pembanding'])) {
|
|
foreach ($dataPembanding['data_pembanding'] as $index => $pembanding) {
|
|
if ($index == 0) {
|
|
$exportData['pembanding1'] = $pembanding;
|
|
} elseif ($index == 1) {
|
|
$exportData['pembanding2'] = $pembanding;
|
|
} elseif ($index == 2) {
|
|
$exportData['pembanding3'] = $pembanding;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Now create the export
|
|
// return response()->json([ 'data' => $fotoForm]);
|
|
return Excel::download(new KertasKerjaExport($exportData), 'kertas-kerja.xlsx');
|
|
}
|
|
|
|
|
|
|
|
public function import_kertas_kerja(Request $request)
|
|
{
|
|
|
|
$validatedData = $request->validate([
|
|
'permohonan_id' => 'required|integer',
|
|
'document_id' => 'required|integer',
|
|
'inspeksi_id' => 'required|integer',
|
|
'kertas_kerja' => 'required|file|mimes:pdf,doc,docx,xls,xlsx,xlsx',
|
|
]);
|
|
|
|
try {
|
|
// Simpan file kertas kerja
|
|
if ($request->hasFile('kertas_kerja')) {
|
|
$file = $request->file('kertas_kerja');
|
|
$filePath = $this->surveyorController->uploadFile($file, 'kertas_kerja');
|
|
Penilai::updateOrCreate(
|
|
[
|
|
'permohonan_id' => $validatedData['permohonan_id'],
|
|
'dokument_id' => $validatedData['document_id'],
|
|
'inspeksi_id' => $validatedData['inspeksi_id'],
|
|
],
|
|
[
|
|
'kertas_kerja' => $filePath,
|
|
]
|
|
);
|
|
|
|
return response()->json(['success' => true, 'message' => 'Kertas kerja berhasil diunggah.']);
|
|
}
|
|
|
|
return response()->json(['success' => false, 'message' => 'File kertas kerja tidak ditemukan.'], 400);
|
|
} catch (\Exception $e) {
|
|
return response()->json(['success' => false, 'message' => 'Terjadi kesalahan: ' . $e->getMessage()], 500);
|
|
}
|
|
}
|
|
|
|
|
|
public function status($id)
|
|
{
|
|
$penilai = Penilai::find($id);
|
|
return response()->json(['data' => $penilai]);
|
|
}
|
|
|
|
public function checkStatusLpj(Request $request)
|
|
{
|
|
$permohonanId = $request->query('permohonanId');
|
|
$documentId = $request->query('documentId');
|
|
$inspeksiId = $request->query('inspeksiId');
|
|
|
|
$statusLpj = Penilai::where('permohonan_id', $permohonanId)
|
|
->where('dokument_id', $documentId)
|
|
->where('inspeksi_id', $inspeksiId)
|
|
->first();
|
|
|
|
return response()->json(['status' => $statusLpj ? $statusLpj->type : null]);
|
|
}
|
|
|
|
public function saveStatusLpj(Request $request)
|
|
{
|
|
|
|
Penilai::updateOrCreate(
|
|
[
|
|
'permohonan_id' => $request->permohonan_id,
|
|
'dokument_id' => $request->document_id,
|
|
'inspeksi_id' => $request->inspeksi_id,
|
|
],
|
|
[
|
|
'type' => $request->type,
|
|
]
|
|
);
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
|
|
|
|
public function storePenilaian($id)
|
|
{
|
|
try {
|
|
$permohonan = Permohonan::findOrFail($id);
|
|
$permohonan->update([
|
|
'status' => 'proses-laporan',
|
|
]);
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'Berhasil menyimpan penilaian'
|
|
], 200);
|
|
|
|
} catch (\Exception $e) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Terjadi kesalahan',
|
|
'error' => $e->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
public function storeResume(Request $request)
|
|
{
|
|
try {
|
|
|
|
// dd($request->all());
|
|
$validatedData = $request->validate([
|
|
'permohonan_id' => 'required',
|
|
'document_id' => 'required',
|
|
'inspeksi_id' => 'required',
|
|
'resume' => 'required|array',
|
|
]);
|
|
|
|
// Simpan atau update data
|
|
Penilai::updateOrCreate(
|
|
[
|
|
'permohonan_id' => $validatedData['permohonan_id'],
|
|
'dokument_id' => $validatedData['document_id'],
|
|
'inspeksi_id' => $validatedData['inspeksi_id'],
|
|
],
|
|
[
|
|
'resume' => json_encode($validatedData['resume']),
|
|
]
|
|
);
|
|
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'Berhasil saved resume'
|
|
], 200);
|
|
} catch (\Exception $e) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Terjadi kesalahan',
|
|
'error' => $e->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
|
|
public function storeMemo(Request $request)
|
|
{
|
|
try {
|
|
|
|
$validatedData = $request->validate([
|
|
'permohonan_id' => 'required|integer',
|
|
'document_id' => 'required|integer',
|
|
'inspeksi_id' => 'required|integer',
|
|
'memo' => 'required',
|
|
]);
|
|
Penilai::updateOrCreate(
|
|
[
|
|
'permohonan_id' => $validatedData['permohonan_id'],
|
|
'dokument_id' => $validatedData['document_id'],
|
|
'inspeksi_id' => $validatedData['inspeksi_id'],
|
|
],
|
|
[
|
|
'memo' => json_encode($validatedData['memo']),
|
|
]
|
|
);
|
|
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'Berhasil saved memo'
|
|
], 200);
|
|
} catch (\Exception $e) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Terjadi kesalahan',
|
|
'error' => $e->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
public function storeLpjSederhanadanStandard(Request $request)
|
|
{
|
|
|
|
try {
|
|
|
|
$validatedData = $request->validate([
|
|
'permohonan_id' => 'required|integer',
|
|
'document_id' => 'required|integer',
|
|
'inspeksi_id' => 'required|integer',
|
|
'lpj' => 'required',
|
|
]);
|
|
Penilai::updateOrCreate(
|
|
[
|
|
'permohonan_id' => $validatedData['permohonan_id'],
|
|
'dokument_id' => $validatedData['document_id'],
|
|
'inspeksi_id' => $validatedData['inspeksi_id'],
|
|
],
|
|
[
|
|
'lpj' => json_encode($validatedData['lpj']),
|
|
]
|
|
);
|
|
|
|
|
|
return response()->json([
|
|
'success' => true,
|
|
'message' => 'Berhasil saved lpj'
|
|
], 200);
|
|
} catch (\Exception $e) {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Terjadi kesalahan',
|
|
'error' => $e->getMessage()
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
|
|
public function print_out(Request $request)
|
|
{
|
|
$documentId = $request->query('documentId');
|
|
$jaminanId = $request->query('jaminanId');
|
|
$permohonanId = $request->query('permohonanId');
|
|
$statusLpj = $request->query('statusLpj');
|
|
|
|
$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();
|
|
|
|
$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);
|
|
}
|
|
|
|
$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::' . $viewLaporan, compact(
|
|
'permohonan',
|
|
'forminspeksi',
|
|
'lpjData',
|
|
'formFoto',
|
|
'basicData',
|
|
'inspeksi',
|
|
'lpj',
|
|
'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.'. $e->getMessage()], 500);
|
|
}
|
|
|
|
}
|
|
|
|
public 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;
|
|
}
|
|
}
|
|
|
|
|
|
}
|