Merge remote-tracking branch 'origin/feature/senior-officer' into surveyor
This commit is contained in:
@@ -14,6 +14,8 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
@@ -77,16 +79,15 @@ 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\Emails\SendEmail;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Modules\Lpj\Emails\SendJadwalKunjunganEmail;
|
||||
|
||||
class SurveyorController extends Controller
|
||||
{
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('lpj::surveyor.index');
|
||||
@@ -831,8 +832,6 @@ private function isValidFormat($data)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function checkButtonStatus($id)
|
||||
{
|
||||
try {
|
||||
@@ -901,24 +900,24 @@ private function isValidFormat($data)
|
||||
'deskripsi_penilaian' => 'required'
|
||||
]);
|
||||
|
||||
// $user = ['user' => 'rustammajid76@gmail.com'];
|
||||
$penilaian = Penilaian::findOrFail($validate['id']);
|
||||
|
||||
// $emailData = [
|
||||
// 'email' => 'rustammajid76@gmail.com',
|
||||
// 'subject' => 'Test',
|
||||
// 'emailData' => '<h2>Hello, World!</h2><h2>This is the email content. Waktu Penilaian:</h2>'
|
||||
// ];
|
||||
$emailData = [
|
||||
'email' => $penilaian->permohonan->user->email,
|
||||
'subject' => 'Jadwal Kunjungan',
|
||||
'emailData' => $validate,
|
||||
|
||||
// $this->sendMessage($emailData, $user);
|
||||
];
|
||||
|
||||
$id = $request->input('id');
|
||||
$penilaian = Penilaian::findOrFail($id);
|
||||
Mail::to($emailData['email'])->send(new SendJadwalKunjunganEmail($emailData, $penilaian->permohonan->nomor_resitrasi, $penilaian->permohonan->debiture));
|
||||
|
||||
if ($validate['waktu_penilaian'] <= $penilaian->tanggal_kunjungan) {
|
||||
|
||||
if (Carbon::parse($validate['waktu_penilaian']) <= Carbon::parse($penilaian->tanggal_kunjungan)) {
|
||||
return redirect()
|
||||
->route('surveyor.index')
|
||||
->with('error', 'Waktu penilaian harus lebih besar dari tanggal assign.');
|
||||
}
|
||||
|
||||
$penilaian->update([
|
||||
'waktu_penilaian' => $validate['waktu_penilaian'],
|
||||
'deskripsi_penilaian' => $validate['deskripsi_penilaian'],
|
||||
@@ -1940,7 +1939,7 @@ private function isValidFormat($data)
|
||||
|
||||
private function updateJenisAsset($permohonan, $request)
|
||||
{
|
||||
$jenis_jaminan_id = $permohonan->debiture->documents->first()->jenis_jaminan_id;
|
||||
$jenis_jaminan_id = $permohonan->documents->first()->jenis_jaminan_id;
|
||||
DokumenJaminan::where('permohonan_id', $permohonan->id)
|
||||
->where('jenis_jaminan_id', $jenis_jaminan_id)
|
||||
->update([
|
||||
@@ -1950,7 +1949,7 @@ private function isValidFormat($data)
|
||||
|
||||
private function updateDetails($permohonan, $key, $newValue)
|
||||
{
|
||||
$document = $permohonan->debiture->documents->first();
|
||||
$document = $permohonan->documents->first();
|
||||
|
||||
if (!$document) {
|
||||
throw new \Exception("Document not found");
|
||||
@@ -1964,18 +1963,18 @@ private function isValidFormat($data)
|
||||
|
||||
$datas = json_decode($detailsUpdate->details, true) ?? [];
|
||||
|
||||
if (is_numeric($newValue)) {
|
||||
$newValue = [$key => $newValue];
|
||||
if (!is_scalar($newValue)) {
|
||||
throw new \InvalidArgumentException("New value must be a scalar (string/number)");
|
||||
}
|
||||
|
||||
if (!is_array($newValue)) {
|
||||
throw new \InvalidArgumentException("'{$key}' must be an array or valid JSON string");
|
||||
}
|
||||
|
||||
foreach ($newValue as $subKey => $value) {
|
||||
$datas[$subKey] = $value; // Update atau tambahkan key baru
|
||||
// Update nilai berdasarkan kunci
|
||||
if (array_key_exists($key, $datas)) {
|
||||
$datas[$key] = $newValue;
|
||||
} else {
|
||||
throw new \Exception("Key '{$key}' not found in details");
|
||||
}
|
||||
|
||||
// Simpan kembali ke database
|
||||
$detailsUpdate->update([
|
||||
'details' => json_encode($datas),
|
||||
]);
|
||||
@@ -2341,26 +2340,48 @@ private function isValidFormat($data)
|
||||
$data['hub_cadeb_penghuni'] => ($data['hub_cadeb_penghuni'] == 'sesuai') ? $data['hub_cadeb_penghuni_sesuai'] : $data['hub_penghuni_tidak_sesuai']
|
||||
],
|
||||
'pihak_bank' => $data['pihak_bank'] ?? null,
|
||||
'nomor_nib' => $data['nomor_nib'] ?? null,
|
||||
|
||||
'kordinat_lng' => $data['kordinat_lng'] ?? null,
|
||||
'kordinat_lat' => $data['kordinat_lat'] ?? null,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function updateFormData(array &$dataForm, array $data, $inspeksi, string $section, string $key, string $sesuaiKey, string $tidakSesuaiKey): void
|
||||
{
|
||||
if (isset($dataForm[$section][$key])) {
|
||||
$dataForm[$section][$key] = []; // Reset data
|
||||
|
||||
if ($data[$key] == 'sesuai') {
|
||||
$dataForm[$section][$key]['sesuai'] = $data[$sesuaiKey] ?? null;
|
||||
} elseif ($data[$key] == 'tidak sesuai') {
|
||||
$dataForm[$section][$key]['tidak sesuai'] = $data[$tidakSesuaiKey] ?? null;
|
||||
}
|
||||
|
||||
if ($inspeksi) {
|
||||
$inspeksi->data_form = json_encode($dataForm);
|
||||
$inspeksi->save();
|
||||
}
|
||||
} else {
|
||||
$data[$key] = $this->getFieldData($data, $key, true);
|
||||
}
|
||||
}
|
||||
|
||||
private function getTanahData(array $data): array
|
||||
{
|
||||
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $data['permohonan_id'])->where('dokument_id', $data['dokument_id'])->first();
|
||||
|
||||
// Decode data_form dari inspeksi
|
||||
$dataForm = $inspeksi ? json_decode($inspeksi->data_form, true) : [];
|
||||
$this->updateFormData($dataForm, $data, $inspeksi, 'tanah', 'luas_tanah', 'luas_tanah_sesuai', 'luas_tanah_tidak_sesuai');
|
||||
$this->updateFormData($dataForm, $data, $inspeksi, 'tanah', 'hadap_mata_angin', 'hadap_mata_angin_sesuai', 'hadap_mata_angin_tidak_sesuai');
|
||||
// dd($dataForm);
|
||||
|
||||
return [
|
||||
'tanah' => [
|
||||
'luas_tanah' => $this->getFieldData(
|
||||
$data,
|
||||
'luas_tanah',
|
||||
true
|
||||
),
|
||||
'hadap_mata_angin' => [
|
||||
$data['hadap_mata_angin'] => $data['hadap_mata_angin'] == 'sesuai' ? $data['hadap_mata_angin_sesuai'] : $data['hadap_mata_angin_tidak_sesuai'] ?? null
|
||||
],
|
||||
'luas_tanah' => $dataForm['tanah']['luas_tanah'] ?? $data['luas_tanah'],
|
||||
'hadap_mata_angin' => $dataForm['tanah']['hadap_mata_angin'] ?? $data['hadap_mata_angin'],
|
||||
'bentuk_tanah' => $this->getFieldData(
|
||||
$data,
|
||||
'bentuk_tanah',
|
||||
@@ -2433,14 +2454,16 @@ private function isValidFormat($data)
|
||||
}
|
||||
}
|
||||
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $data['permohonan_id'])->where('dokument_id', $data['dokument_id'])->first();
|
||||
|
||||
// Decode data_form dari inspeksi
|
||||
$dataForm = $inspeksi ? json_decode($inspeksi->data_form, true) : [];
|
||||
$this->updateFormData($dataForm, $data, $inspeksi, 'bangunan', 'luas_tanah_bagunan', 'luas_tanah_bagunan_sesuai', 'luas_tanah_bagunan_tidak_sesuai');
|
||||
|
||||
|
||||
return [
|
||||
'bangunan' => [
|
||||
'luas_tanah_bagunan' => $this->getFieldData(
|
||||
$data,
|
||||
'luas_tanah_bagunan',
|
||||
true
|
||||
),
|
||||
'luas_tanah_bagunan' => $dataForm['bangunan']['luas_tanah_bagunan'] ?? $data['luas_tanah_bagunan'],
|
||||
'jenis_bangunan' => $data['jenis_bangunan'] ?? null,
|
||||
'kondisi_bangunan' => $data['kondisi_bangunan'] ?? null,
|
||||
'sifat_bangunan' => $data['sifat_bangunan'] ?? null,
|
||||
@@ -3115,6 +3138,7 @@ private function isValidFormat($data)
|
||||
|
||||
private function getUnitData($data, $request): array
|
||||
{
|
||||
|
||||
return [
|
||||
'action' => $data['action'] ?? null,
|
||||
'luas_unit' => $this->getFieldData(
|
||||
@@ -3196,26 +3220,32 @@ private function isValidFormat($data)
|
||||
bool $checkKesesuaian = false,
|
||||
?string $extraField = null
|
||||
): array {
|
||||
$result = [];
|
||||
|
||||
if ($checkKesesuaian) {
|
||||
return [
|
||||
$data[$fieldName] ?? '' => ($data[$fieldName] ?? '') === 'sesuai'
|
||||
? ($data["{$fieldName}_sesuai"] ?? '')
|
||||
: ($data["{$fieldName}_tidak_sesuai"] ?? '')
|
||||
];
|
||||
$isSesuai = ($data[$fieldName] ?? '') === 'sesuai';
|
||||
$fieldKey = $isSesuai ? "{$fieldName}_sesuai" : "{$fieldName}_tidak_sesuai";
|
||||
|
||||
// Hanya simpan key yang dipilih
|
||||
if ($isSesuai) {
|
||||
$result['sesuai'] = $data[$fieldKey] ?? null;
|
||||
} else {
|
||||
$result['tidak sesuai'] = $data[$fieldKey] ?? null;
|
||||
}
|
||||
} else {
|
||||
$result[$fieldName] = $data[$fieldName] ?? null;
|
||||
|
||||
if ($extraField) {
|
||||
$result[$extraField] = $data["{$fieldName}_{$extraField}"] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
$result = [
|
||||
$fieldName => $data[$fieldName] ?? null
|
||||
];
|
||||
|
||||
if ($extraField) {
|
||||
$result[$extraField] = $data["{$fieldName}_{$extraField}"] ?? null;
|
||||
}
|
||||
|
||||
return $result;
|
||||
// Hapus key dengan nilai null untuk memastikan hanya key yang valid yang disimpan
|
||||
return array_filter($result, fn ($value) => $value !== null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function export(string $type)
|
||||
{
|
||||
$modelClass = $this->getModelClass($type);
|
||||
@@ -3256,10 +3286,11 @@ private function isValidFormat($data)
|
||||
->first();
|
||||
|
||||
if (!$inspeksi) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Data inspeksi tidak ditemukan'
|
||||
], 404);
|
||||
$inspeksi = new Inspeksi();
|
||||
$inspeksi->permohonan_id = $request->input('permohonan_id');
|
||||
$inspeksi->dokument_id = $request->input('document_id');
|
||||
$inspeksi->data_form = json_encode([]); // Inisialisasi data_form kosong
|
||||
$inspeksi->save();
|
||||
}
|
||||
|
||||
// Decode data form yang ada
|
||||
@@ -3416,36 +3447,43 @@ private function isValidFormat($data)
|
||||
|
||||
public function print_out_inspeksi($permohonan_id, $dokument_id, $jenis_jaminan_id)
|
||||
{
|
||||
$permohonan = $this->getPermohonanJaminanId(
|
||||
$permohonan_id,
|
||||
$dokument_id,
|
||||
$jenis_jaminan_id
|
||||
);
|
||||
// Ambil data permohonan dan data umum
|
||||
$permohonan = $this->getPermohonanJaminanId($permohonan_id, $dokument_id, $jenis_jaminan_id);
|
||||
$basicData = $this->getCommonData();
|
||||
|
||||
// Ambil data inspeksi
|
||||
$inspeksi = Inspeksi::where('permohonan_id', $permohonan_id)
|
||||
->where('dokument_id', $dokument_id)
|
||||
->first();
|
||||
|
||||
$forminspeksi = null;
|
||||
|
||||
if ($inspeksi) {
|
||||
$forminspeksi = json_decode($inspeksi->data_form, true);
|
||||
if (!$inspeksi) {
|
||||
// Redirect jika inspeksi tidak ditemukan
|
||||
return redirect()->back()->with('error', 'Data inspeksi tidak ditemukan.');
|
||||
}
|
||||
|
||||
// Cek jika forminspeksi kosong
|
||||
// Decode data form inspeksi
|
||||
$forminspeksi = json_decode($inspeksi->data_form, true);
|
||||
|
||||
if (!$forminspeksi) {
|
||||
// Redirect kembali dengan pesan error
|
||||
return redirect()->back()->with('error', 'Silahkan isi terlebih dahulu form inspeksi');
|
||||
// Redirect jika data form inspeksi kosong
|
||||
return redirect()->back()->with('error', 'Silahkan isi terlebih dahulu form inspeksi.');
|
||||
}
|
||||
|
||||
// Pilih template PDF berdasarkan nama inspeksi
|
||||
$templateView = strtolower($inspeksi->name) === 'rap'
|
||||
? 'lpj::surveyor.components.print-out.main'
|
||||
: 'lpj::surveyor.components.print-out.main';
|
||||
|
||||
$pdf = PDF::loadView('lpj::surveyor.components.print-out.main', compact(
|
||||
'permohonan',
|
||||
'basicData',
|
||||
'forminspeksi',
|
||||
));
|
||||
// Generate PDF
|
||||
$pdf = PDF::loadView($templateView, compact('permohonan', 'basicData', 'forminspeksi'));
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
return $pdf->download('Laporan_data.pdf');
|
||||
|
||||
// Tentukan nama file PDF
|
||||
$namaDebiture = $permohonan->debiture->name . '-' . $permohonan->nomor_registrasi;
|
||||
$fileName = 'inspeksi-' . $namaDebiture . '-data.pdf';
|
||||
|
||||
return $pdf->download($fileName);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user