From dc1356f2345dfcdbc75fe80267bc4e8fc11dd562 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:07:59 +0700 Subject: [PATCH 01/13] Tambah informasi detail permohonan dan debitur Menambahkan tampilan informasi detail permohonan termasuk nomor registrasi, pemohon, tujuan permohonan, nilai plafond, status bayar, dan nilai NJOP. Juga menambahkan tampilan detail debitur yang mencakup nama, email, telepon, alamat lengkap, cabang, CIF, nomor rekening, dan NPWP pada halaman 'detail-jaminan.blade.php'. --- .../views/component/detail-jaminan.blade.php | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/resources/views/component/detail-jaminan.blade.php b/resources/views/component/detail-jaminan.blade.php index 3435775..63b2817 100644 --- a/resources/views/component/detail-jaminan.blade.php +++ b/resources/views/component/detail-jaminan.blade.php @@ -1,3 +1,164 @@ +
+
+

+ Data Permohonan +

+ +
+ Back +
+
+
+
+

+ Nomor Register Permohonan: +

+ + {{ $permohonan->nomor_registrasi }} + +
+ +
+

+ Pemohon: +

+ + {{ $permohonan->user->nik }} | {{ $permohonan->user->name }} | {{ $permohonan->user->branch->name }} + +
+ +
+

+ Tujan Permohonan: +

+ + {{ $permohonan->tujuanPenilaian->name }} + +
+ +
+

+ Nilai Plafond: +

+ + {{ $permohonan->nilaiPlafond->name }} + +
+ +
+

+ Status Bayar: +

+ + {{ str_replace('_',' ',$permohonan->status_bayar) }} + +
+ +
+

+ Nilai NJOP: +

+ + {{ formatRupiah($permohonan->niilai_njop) }} + +
+ +
+
+ +
+
+

+ Detail Debitur +

+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ Name + + {{ $permohonan->debiture->name ?? "" }} +
+ Email + + {{ $permohonan->debiture->email ?? "" }} +
+ Phone + + {{ $permohonan->debiture->phone ?? "" }} +
+ Address + + {{ $permohonan->debiture->address ?? "" }} +
+   + + {{ $permohonan->debiture->village->name ?? "" }}, {{ $permohonan->debiture->district->name ?? "" }}, {{ $permohonan->debiture->city->name ?? "" }}, {{ $permohonan->debiture->province->name ?? "" }} - {{ $permohonan->debiture->village->postal_code ?? "" }} +
+
+
+ + + + + + + + + + + + + + + + + +
+ Cabang + + {{ $permohonan->debiture->branch->name ?? "" }} +
+ CIF + + {{ $permohonan->debiture->cif ?? "" }} +
+ Nomor Rekening + + {{ $permohonan->debiture->nomor_rekening ?? "" }} +
+ NPWP + + {{ $permohonan->debiture->npwp ?? "" }} +
+
+
+
+
+

From 9641ee6bb9c10aab8db768476523810dc431b8b9 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:08:37 +0700 Subject: [PATCH 02/13] Tambahkan relasi permohonan di model Debiture Menambahkan fungsi `permohonan` untuk relasi one-to-one antara model Debiture dan Permohonan guna mempermudah akses data permohonan terkait. --- app/Models/Debiture.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Models/Debiture.php b/app/Models/Debiture.php index 8980513..3080ecb 100644 --- a/app/Models/Debiture.php +++ b/app/Models/Debiture.php @@ -60,4 +60,8 @@ return $this->hasMany(DokumenJaminan::class); } + public function permohonan(){ + return $this->hasOne(Permohonan::class, 'debiture_id', 'id' ); + } + } From c0de927d15251401c43300bb5bd763c01da18366 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:09:07 +0700 Subject: [PATCH 03/13] Hapus detail permohonan dan debitur Menghapus semua informasi detail terkait permohonan dan debitur dari tampilan halaman. Penyesuaian juga dilakukan pada komponen detail jaminan dengan menambahkan link kembali ke 'authorization.index'. --- .../permohonan/authorization/show.blade.php | 150 +----------------- 1 file changed, 1 insertion(+), 149 deletions(-) diff --git a/resources/views/permohonan/authorization/show.blade.php b/resources/views/permohonan/authorization/show.blade.php index 2036ba1..c5d1d56 100644 --- a/resources/views/permohonan/authorization/show.blade.php +++ b/resources/views/permohonan/authorization/show.blade.php @@ -6,155 +6,7 @@ @section('content')
-
-
-

- Data Permohonan -

-
-
-
-

- Nomor Register Permohonan: -

- - {{ $permohonan->nomor_registrasi }} - -
- -
-

- Pemohon: -

- - {{ $permohonan->user->nik }} | {{ $permohonan->user->name }} | {{ $permohonan->user->branch->name }} - -
- -
-

- Tujan Permohonan: -

- - {{ $permohonan->tujuanPenilaian->name }} - -
- -
-

- Nilai Plafond: -

- - {{ $permohonan->nilaiPlafond->name }} - -
- -
-

- Status Bayar: -

- - {{ str_replace('_',' ',$permohonan->status_bayar) }} - -
- -
-
- -
-
-

- Detail Debutur -

-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - -
- Name - - {{ $permohonan->debiture->name ?? "" }} -
- Email - - {{ $permohonan->debiture->email ?? "" }} -
- Phone - - {{ $permohonan->debiture->phone ?? "" }} -
- Address - - {{ $permohonan->debiture->address ?? "" }} -
-   - - {{ $permohonan->debiture->village->name ?? "" }}, {{ $permohonan->debiture->district->name ?? "" }}, {{ $permohonan->debiture->city->name ?? "" }}, {{ $permohonan->debiture->province->name ?? "" }} - {{ $permohonan->debiture->village->postal_code ?? "" }} -
-
-
- - - - - - - - - - - - - - - - - -
- Cabang - - {{ $permohonan->debiture->branch->name ?? "" }} -
- CIF - - {{ $permohonan->debiture->cif ?? "" }} -
- Nomor Rekening - - {{ $permohonan->debiture->nomor_rekening ?? "" }} -
- NPWP - - {{ $permohonan->debiture->npwp ?? "" }} -
-
-
-
-
- - @include('lpj::component.detail-jaminan') + @include('lpj::component.detail-jaminan',['backLink' => 'authorization.index'])
From abf17c9b8ac815cc246c2853499d8ebe78a64785 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:09:17 +0700 Subject: [PATCH 04/13] Hapus detail permohonan dan debitur Menghapus semua informasi detail terkait permohonan dan debitur dari tampilan halaman. Penyesuaian juga dilakukan pada komponen detail jaminan dengan menambahkan link kembali ke 'permohonan.index'. --- resources/views/permohonan/show.blade.php | 168 +--------------------- 1 file changed, 1 insertion(+), 167 deletions(-) diff --git a/resources/views/permohonan/show.blade.php b/resources/views/permohonan/show.blade.php index d1de6f8..3ccb967 100644 --- a/resources/views/permohonan/show.blade.php +++ b/resources/views/permohonan/show.blade.php @@ -6,173 +6,7 @@ @section('content')
-
-
-
-

- Data Permohonan -

-
-
-
-

- Nomor Register Permohonan: -

- - {{ $permohonan->nomor_registrasi }} - -
- -
-

- Pemohon: -

- - {{ $permohonan->user->nik }} | {{ $permohonan->user->name }} | {{ $permohonan->user->branch->name }} - -
- -
-

- Tujan Permohonan: -

- - {{ $permohonan->tujuanPenilaian->name }} - -
- -
-
- -
-
-

- Fasilitas Kredit -

-
-
-
-

- Jenis Fasilitas -

- - {{ $permohonan->jenisFasilitasKredit->name }} - -
- -
-

- Nilai Plafond: -

- - {{ $permohonan->nilaiPlafond->name }} - -
- -
-

- Nilai NJOP: -

- - {{ $permohonan->nilai_njop }} - -
-
-
-
-
-
-

- Detail Debutur -

-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - -
- Name - - {{ $permohonan->debiture->name ?? "" }} -
- Email - - {{ $permohonan->debiture->email ?? "" }} -
- Phone - - {{ $permohonan->debiture->phone ?? "" }} -
- Address - - {{ $permohonan->debiture->address ?? "" }} -
-   - - {{ $permohonan->debiture->village->name ?? "" }}, {{ $permohonan->debiture->district->name ?? "" }}, {{ $permohonan->debiture->city->name ?? "" }}, {{ $permohonan->debiture->province->name ?? "" }} - {{ $permohonan->debiture->village->postal_code ?? "" }} -
-
-
- - - - - - - - - - - - - - - - - -
- Cabang - - {{ $permohonan->debiture->branch->name ?? "" }} -
- CIF - - {{ $permohonan->debiture->cif ?? "" }} -
- Nomor Rekening - - {{ $permohonan->debiture->nomor_rekening ?? "" }} -
- NPWP - - {{ $permohonan->debiture->npwp ?? "" }} -
-
-
-
-
- @include('lpj::component.detail-jaminan') + @include('lpj::component.detail-jaminan',['backLink' => 'prmohonan.index'])
From ba2bb1220a50c2b0d0aba7bd2735570ded561cd7 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:12:18 +0700 Subject: [PATCH 05/13] Hapus detail data permohonan dan debitur Telah dihapus tampilan detail data permohonan, debitur, dan biaya dari halaman registrasi. Detail jaminan masih disertakan dengan penambahan tautan kembali ke indeks registrasi. Perubahan ini bertujuan menyederhanakan tampilan halaman dan mengurangi informasi yang tidak diperlukan. --- resources/views/registrasi/show.blade.php | 175 +--------------------- 1 file changed, 2 insertions(+), 173 deletions(-) diff --git a/resources/views/registrasi/show.blade.php b/resources/views/registrasi/show.blade.php index af13005..9e18a05 100644 --- a/resources/views/registrasi/show.blade.php +++ b/resources/views/registrasi/show.blade.php @@ -10,185 +10,14 @@ @endphp @section('content')
-
-
-

- Data Permohonan -

- -
-
-
-

- Nomor Register Permohonan: -

- - {{ $permohonan->nomor_registrasi }} - -
- -
-

- Pemohon: -

- - {{ $permohonan->user->nik }} | {{ $permohonan->user->name }} | {{ $permohonan->user->branch->name }} - -
- -
-

- Tujan Permohonan: -

- - {{ $permohonan->tujuanPenilaian->name }} - -
- -
-
- -
-
-

- Detail Debutur -

-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - -
- Name - - {{ $permohonan->debiture->name ?? "" }} -
- Email - - {{ $permohonan->debiture->email ?? "" }} -
- Phone - - {{ $permohonan->debiture->phone ?? "" }} -
- Address - - {{ $permohonan->debiture->address ?? "" }} -
-   - - {{ $permohonan->debiture->village->name ?? "" }}, {{ $permohonan->debiture->district->name ?? "" }}, {{ $permohonan->debiture->city->name ?? "" }}, {{ $permohonan->debiture->province->name ?? "" }} - {{ $permohonan->debiture->village->postal_code ?? "" }} -
-
-
- - - - - - - - - - - - - - - - - -
- Cabang - - {{ $permohonan->debiture->branch->name ?? "" }} -
- CIF - - {{ $permohonan->debiture->cif ?? "" }} -
- Nomor Rekening - - {{ $permohonan->debiture->nomor_rekening ?? "" }} -
- NPWP - - {{ $permohonan->debiture->npwp ?? "" }} -
-
-
-
-
- - @include('lpj::component.detail-jaminan') - -
-
-

- Data Biaya -

-
-
-
-
- - - - - - - - - - -
- Status Bayar - - {{ strtoupper(str_replace('_',' ',$permohonan->status_bayar)) }} -
- Nilai NJOP - - {{ $permohonan->nilai_njop }} -
-
-
-
-
+ @include('lpj::component.detail-jaminan',['backLink' => 'registrasi.index'])

Registrasi

-
@@ -240,7 +69,7 @@ -
+

+ +
+

+ Nilai Plafond: +

+ + {{ $permohonan->nilaiPlafond->name }} + +
+ +
+

+ Status Bayar: +

+ + {{ str_replace('_',' ',$permohonan->status_bayar) }} + +
+ +
+

+ Nilai NJOP: +

+ + {{ formatRupiah($permohonan->niilai_njop) }} + +
-
-
-

- Detail Debutur -

-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - -
- Name - - {{ $permohonan->debiture->name ?? "" }} -
- Email - - {{ $permohonan->debiture->email ?? "" }} -
- Phone - - {{ $permohonan->debiture->phone ?? "" }} -
- Address - - {{ $permohonan->debiture->address ?? "" }} -
-   - - {{ $permohonan->debiture->village->name ?? "" }}, {{ $permohonan->debiture->district->name ?? "" }}, {{ $permohonan->debiture->city->name ?? "" }}, {{ $permohonan->debiture->province->name ?? "" }} - {{ $permohonan->debiture->village->postal_code ?? "" }} -
-
-
- - - - - - - - - - - - - - - - - -
- Cabang - - {{ $permohonan->debiture->branch->name ?? "" }} -
- CIF - - {{ $permohonan->debiture->cif ?? "" }} -
- Nomor Rekening - - {{ $permohonan->debiture->nomor_rekening ?? "" }} -
- NPWP - - {{ $permohonan->debiture->npwp ?? "" }} -
-
-
-
-
- - @include('lpj::component.detail-jaminan') + @include('lpj::component.detail-jaminan',['backLink' => 'registrasifinal.index','hidePermohonan'=>true])
@endsection From 5785bf63249acd4b860f36a6bdea8163c11f3d6e Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:13:07 +0700 Subject: [PATCH 07/13] Hapus Detail Data Permohonan dan Debitur Menghapus tampilan detail data permohonan dan debitur dari form penilaian untuk menyederhanakan antarmuka pengguna. Mengubah @include komponen detail-jaminan dengan menambahkan parameter backLink. --- resources/views/penilaian/form.blade.php | 142 +---------------------- 1 file changed, 2 insertions(+), 140 deletions(-) diff --git a/resources/views/penilaian/form.blade.php b/resources/views/penilaian/form.blade.php index 0433bfc..4c6ebc6 100644 --- a/resources/views/penilaian/form.blade.php +++ b/resources/views/penilaian/form.blade.php @@ -22,145 +22,7 @@ @section('content')
-
-
-

- Data Permohonan -

-
- - Back -
-
-
-
-

- Nomor Register Permohonan: -

- - {{ $permohonan->nomor_registrasi }} - -
- -
-

- Pemohon: -

- - {{ $permohonan->user->nik }} | {{ $permohonan->user->name }} | {{ $permohonan->user->branch->name }} - -
- -
-

- Tujan Permohonan: -

- - {{ $permohonan->tujuanPenilaian->name }} - -
- -
-
- -
-
-

- Detail Debutur -

-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - -
- Name - - {{ $permohonan->debiture->name ?? '' }} -
- Email - - {{ $permohonan->debiture->email ?? '' }} -
- Phone - - {{ $permohonan->debiture->phone ?? '' }} -
- Address - - {{ $permohonan->debiture->address ?? '' }} -
-   - - {{ $permohonan->debiture->village->name ?? '' }}, - {{ $permohonan->debiture->district->name ?? '' }}, - {{ $permohonan->debiture->city->name ?? '' }}, - {{ $permohonan->debiture->province->name ?? '' }} - - {{ $permohonan->debiture->village->postal_code ?? '' }} -
-
-
- - - - - - - - - - - - - - - - - -
- Cabang - - {{ $permohonan->debiture->branch->name ?? '' }} -
- CIF - - {{ $permohonan->debiture->cif ?? '' }} -
- Nomor Rekening - - {{ $permohonan->debiture->nomor_rekening ?? '' }} -
- NPWP - - {{ $permohonan->debiture->npwp ?? '' }} -
-
-
-
-
- - @include('lpj::component.detail-jaminan') + @include('lpj::component.detail-jaminan',['backLink' => 'penilaian.index'])
@@ -451,7 +313,7 @@ - +
From 0601936ca587db76f492a72bc404503a85e1e169 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:13:41 +0700 Subject: [PATCH 08/13] Tingkatkan include pada detail view Menambahkan parameter `backLink` pada include `detail-jaminan` di file `surveyor/detail.blade.php` untuk mengarahkan kembali ke index surveyor. Perubahan ini bertujuan untuk memperbaiki navigasi kembali bagi pengguna. --- resources/views/surveyor/detail.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/surveyor/detail.blade.php b/resources/views/surveyor/detail.blade.php index 24f60b1..9be9cbe 100644 --- a/resources/views/surveyor/detail.blade.php +++ b/resources/views/surveyor/detail.blade.php @@ -58,7 +58,7 @@
- @include('lpj::component.detail-jaminan') + @include('lpj::component.detail-jaminan',['backLink'=>'surveyor.index'])
From 187282fe9f7820f1c70e62c871930e739e6d2ebb Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:14:07 +0700 Subject: [PATCH 09/13] Perbarui metode bulkDownload untuk penanganan file lebih baik Tambahkan pengelompokan dokumen berdasarkan jenis jaminan dalam folder terstruktur, log peringatan untuk file yang hilang, dan bersihkan nama folder untuk kompatibilitas. --- .../Controllers/DokumenJaminanController.php | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/DokumenJaminanController.php b/app/Http/Controllers/DokumenJaminanController.php index 6c2411f..51364d9 100644 --- a/app/Http/Controllers/DokumenJaminanController.php +++ b/app/Http/Controllers/DokumenJaminanController.php @@ -383,7 +383,8 @@ public function bulkDownload() { $dokumenIds = request()->get('jaminan'); // Expecting an array of dokumen_jaminan_id - $documents = DetailDokumenJaminan::where('dokumen_jaminan_id', $dokumenIds)->get(); + $documents = DokumenJaminan::where('id', $dokumenIds)->with(['jenisJaminan', 'detail','debiture'])->get(); + if ($documents->isEmpty()) { return redirect()->back()->with('error', 'No documents found for the provided IDs.'); } @@ -394,18 +395,24 @@ if ($zip->open($zipFilePath, ZipArchive::CREATE) === true) { foreach ($documents as $document) { - if($document->dokumen_jaminan) { - $files = is_array(json_decode($document->dokumen_jaminan)) ? json_decode( - $document->dokumen_jaminan, - ) : [$document->dokumen_jaminan]; + $jenisJaminan = $document->debiture->permohonan->nomor_registrasi ?? 'Uncategorized'; + $folderName = $this->sanitizeFolderName($jenisJaminan); - foreach ($files as $file) { - $filePath = storage_path('app/public/' . $file); - if (file_exists($filePath)) { - $zip->addFile($filePath, basename($filePath)); - } else { - // Log or display an error message for missing files - return redirect()->back()->with('error', 'File not found: ' . $filePath); + foreach ($document->detail as $detail) { + if($detail->dokumen_jaminan) { + $folderJaminanName = $this->sanitizeFolderName($detail->jenisLegalitasJaminan->name?? 'Uncategorized'); + $files = is_array(json_decode($detail->dokumen_jaminan)) + ? json_decode($detail->dokumen_jaminan) + : [$detail->dokumen_jaminan]; + + foreach ($files as $file) { + $filePath = storage_path('app/public/' . $file); + if (file_exists($filePath)) { + $zip->addFile($filePath, $folderName . '/' .$folderJaminanName.'/'.basename($filePath)); + } else { + // Log or display an error message for missing files + \Log::warning('File not found: ' . $filePath); + } } } } @@ -423,7 +430,13 @@ 'Content-Type' => 'application/zip', 'Content-Disposition' => 'attachment; filename="' . $zipFileName . '"', 'Content-Length' => filesize($zipFilePath), - ])->deleteFileAfterSend(false); + ])->deleteFileAfterSend(true); + } + + private function sanitizeFolderName($name) + { + // Remove any characters that are not allowed in folder names + return preg_replace('/[^a-zA-Z0-9_\-]/', '_', $name); } From 02c04a43460f76b4b77b9aba2709979019b24af1 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:14:26 +0700 Subject: [PATCH 10/13] Tambah fungsi unggah lampiran dan riwayat permohonan Menambahkan fungsi untuk mengunggah lampiran saat membuat dan memperbarui permohonan, serta mencatat riwayat perubahan permohonan dengan menggunakan PermohonanHistoryService. Fitur ini memastikan file lampiran tersimpan dengan benar dan perubahan terhadap permohonan terdokumentasi. --- app/Models/Permohonan.php | 59 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/app/Models/Permohonan.php b/app/Models/Permohonan.php index 1dd7bdd..60c9303 100644 --- a/app/Models/Permohonan.php +++ b/app/Models/Permohonan.php @@ -3,6 +3,7 @@ namespace Modules\Lpj\Models; use Modules\Lpj\Database\Factories\PermohonanFactory; +use Modules\Lpj\Services\PermohonanHistoryService; use Modules\Usermanagement\Models\User; class Permohonan extends Base @@ -38,8 +39,66 @@ class Permohonan extends Base 'registrasi_at', 'jenis_penilaian_id', 'region_id', + 'attachment' ]; + protected static function boot() + { + parent::boot(); + + static::creating(function ($permohonan) { + static::handleFileUpload($permohonan); + }); + + static::updating(function ($permohonan) { + static::handleFileUpload($permohonan); + }); + + static::created(function ($permohonan) { + static::createHistory($permohonan, 'created'); + }); + + static::updated(function ($permohonan) { + static::createHistory($permohonan, 'updated'); + }); + } + + protected static function handleFileUpload($permohonan) + { + if (request()->hasFile('attachment')) { + $file = request()->file('attachment'); + $fileName = time() . '_' . $file->getClientOriginalName(); + $filePath = $file->storeAs('permohonan_attachments', $fileName, 'public'); + + // Delete old file if it exists + if ($permohonan->attachment) { + Storage::disk('public')->delete($permohonan->attachment); + } + + $permohonan->attachment = $filePath; + } + } + + protected static function createHistory($permohonan, $action) + { + $historyService = app(PermohonanHistoryService::class); + + $status = $permohonan->status; + $keterangan = request()->input('keterangan'); // Get keterangan from request + $beforeRequest = $action === 'updated' ? $permohonan->getOriginal() : []; + $afterRequest = $permohonan->toArray(); + $file = $permohonan->attachment ? Storage::disk('public')->path($permohonan->attachment) : null; + + $historyService->createHistory( + $permohonan, + $status, + $keterangan, + $beforeRequest, + $afterRequest, + $file + ); + } + public function user() { return $this->belongsTo(User::class); From 4eba7f893a40c8d2efc08d37d31bcdae3931c869 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 14 Nov 2024 03:15:45 +0700 Subject: [PATCH 11/13] Refactor and optimize RegistrasiController Menghapus komentar yang tidak diperlukan, merapikan kode, dan menambahkan dependensi yang hilang. Perubahan ini juga mencakup optimalisasi pengambilan data serta perbaikan penanganan permintaan AJAX pada metode setData dan update. --- app/Http/Controllers/RegistrasiController.php | 187 ++++++++---------- 1 file changed, 81 insertions(+), 106 deletions(-) diff --git a/app/Http/Controllers/RegistrasiController.php b/app/Http/Controllers/RegistrasiController.php index 99e5f4f..6b69cd0 100644 --- a/app/Http/Controllers/RegistrasiController.php +++ b/app/Http/Controllers/RegistrasiController.php @@ -4,28 +4,14 @@ use App\Http\Controllers\Controller; use Exception; - use Illuminate\Http\Request; - use Maatwebsite\Excel\Facades\Excel; - // use Modules\Location\Models\City; - // use Modules\Location\Models\District; - // use Modules\Location\Models\Province; - // use Modules\Location\Models\Village; - // use Modules\Lpj\Exports\DebitureExport; - // use Modules\Lpj\Http\Requests\DebitureRequest; - // use Modules\Lpj\Http\Requests\DokumenJaminanRequest; - // use Modules\Lpj\Models\Branch; - // use Modules\Lpj\Models\Debiture; - // use Modules\Lpj\Models\DokumenJaminan; - // use Modules\Lpj\Models\JenisJaminan; - // use Modules\Lpj\Models\JenisLegalitasJaminan; - // use Modules\Lpj\Models\PemilikJaminan; - use Modules\Lpj\Models\Permohonan; - use Modules\Lpj\Models\JenisPenilaian; - use Modules\Lpj\Models\Regions; use Illuminate\Http\JsonResponse; - use Illuminate\Support\Facades\Validator; + use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; - + use Illuminate\Support\Facades\Validator; + use Maatwebsite\Excel\Facades\Excel; + use Modules\Lpj\Models\JenisPenilaian; + use Modules\Lpj\Models\Permohonan; + use Modules\Lpj\Models\Regions; class RegistrasiController extends Controller { @@ -43,7 +29,7 @@ } // Retrieve data from the database - $query = Permohonan::query()->where('status','=','preregister'); + $query = Permohonan::query()->where('status', '=', 'preregister'); // Apply search filter if provided if ($request->has('search') && !empty($request->get('search'))) { @@ -101,143 +87,132 @@ 'data' => $data, ]); } - + public function edit($id) { return view('lpj::registrasi.edit', compact('id')); } - public function setData(Request $request): JsonResponse - { - $data = array(); - $datas = array(); + public function setData(Request $request) + : JsonResponse { + $data = []; + $datas = []; if (request()->ajax()) { - $id = $request->id; + $id = $request->id; $datas = Permohonan::find($id); - + if ($datas) { - $jenisPenilaians=null; - $regions=null; - $regions=Regions::pluck('name', 'id'); - $jenisPenilaians=JenisPenilaian::pluck('name', 'id'); - - $data['status'] = 'success'; - $data['regions'] = $regions; - $data['jenisPenilaians'] = $jenisPenilaians; - $data['datas'] = $datas; - $data['message'] ['message_success'] = array("data successfully found"); + $jenisPenilaians = null; + $regions = null; + $regions = Regions::pluck('name', 'id'); + $jenisPenilaians = JenisPenilaian::pluck('name', 'id'); + + $data['status'] = 'success'; + $data['regions'] = $regions; + $data['jenisPenilaians'] = $jenisPenilaians; + $data['datas'] = $datas; + $data['message'] ['message_success'] = ["data successfully found"]; } else { - $data['status'] = 'error'; - $data['datas'] = null; - $data['message'] ['message_data'] = array("data not found"); + $data['status'] = 'error'; + $data['datas'] = null; + $data['message'] ['message_data'] = ["data not found"]; } } else { - $data['status'] = 'error'; - $data['message'] ['message_ajax'] = array("no ajax request"); + $data['status'] = 'error'; + $data['message'] ['message_ajax'] = ["no ajax request"]; } return response()->json($data); } - public function update(Request $request, $id): JsonResponse - { + public function update(Request $request, $id) + : JsonResponse { // init - $data = array(); - $dataku = array(); + $data = []; + $dataku = []; $tindakan = null; if (request()->ajax()) { $validator = RegistrasiController::rulesEditnya($request, $id); - + if ($validator['fails']) { $data['message'] = $validator['errors']; - $data['status'] = 'error'; - } - else - { + $data['status'] = 'error'; + } else { try { + $tindakan = $request->tindakan; + $dataku = [ + 'registrasi_by' => Auth::id(), + 'registrasi_at' => now(), + ]; - $tindakan=$request->tindakan; - $dataku = ['registrasi_by' => Auth::id(), - 'registrasi_at' => now() - ]; - - if($tindakan==0) - { - $dataku['jenis_penilaian_id'] =$request->jenis_penilaian; - $dataku['region_id'] =$request->region; - $dataku['status'] = 'registered'; - if($request->catatan2) - $dataku['registrasi_catatan'] =$request->catatan2; - } - else - { - $dataku['registrasi_catatan'] =$request->catatan; - $dataku['status'] = 'revisi'; + if ($tindakan == 0) { + $dataku['jenis_penilaian_id'] = $request->jenis_penilaian; + $dataku['region_id'] = $request->region; + $dataku['status'] = 'registered'; + if ($request->catatan2) { + $dataku['registrasi_catatan'] = $request->catatan2; + } + } else { + $dataku['registrasi_catatan'] = $request->catatan; + $dataku['status'] = 'revisi'; } - $data['dataku'] =$dataku; - + $data['dataku'] = $dataku; + $modal = Permohonan::find($id); - + $modal->update($dataku); - // - $data['status'] = 'success'; - $data['message'] ['message_success'] = array('Regitrasi '.$modal->nomor_registrasi.' successfully'); + // + $data['status'] = 'success'; + $data['message'] ['message_success'] = ['Regitrasi ' . $modal->nomor_registrasi . ' successfully']; } catch (Exception $e) { - - $data['status'] = 'error'; - $data['message'] ['message_try_catch'] = array('Regitrasi updated failed.'); + $data['status'] = 'error'; + $data['message'] ['message_try_catch'] = ['Regitrasi updated failed.']; } } - } else { - $data['status'] = 'error'; - $data['message'] ['message_ajax'] = array("no ajax request"); + $data['status'] = 'error'; + $data['message'] ['message_ajax'] = ["no ajax request"]; } return response()->json($data); - } public function rulesEditnya($request, $id) { - $tindakan=null; - $jenis_penilaian=null; - $validate_catatan=''; - $tindakan=$request->tindakan; - $jenis_penilaian=$request->jenis_penilaian; - + $tindakan = null; + $jenis_penilaian = null; + $validate_catatan = ''; + $tindakan = $request->tindakan; + $jenis_penilaian = $request->jenis_penilaian; + $validateIt = [ // 'name' diambil dari definisi parameter yang di kirim pada POST Data 'tindakan' => 'required', ]; $messageIt = [ - 'tindakan.required' => 'Silahkan pilih Tindakan' + 'tindakan.required' => 'Silahkan pilih Tindakan', ]; - if($tindakan==0) - { - $validateIt['jenis_penilaian'] = ['required']; - $messageIt ['jenis_penilaian.required']= 'Silahkan pilih Jenis Penilaian'; + if ($tindakan == 0) { + $validateIt['jenis_penilaian'] = ['required']; + $messageIt ['jenis_penilaian.required'] = 'Silahkan pilih Jenis Penilaian'; - // INTERNAL - if(1==$jenis_penilaian) - { - $validateIt['region'] = ['required']; - $messageIt ['region.required']= 'Silahkan pilih Region'; + // INTERNAL + if (1 == $jenis_penilaian) { + $validateIt['region'] = ['required']; + $messageIt ['region.required'] = 'Silahkan pilih Region'; } - } - elseif($tindakan==1) - { - $validateIt['catatan'] = ['required']; - $messageIt ['catatan.required']= 'Silahkan isi Catatan'; + } elseif ($tindakan == 1) { + $validateIt['catatan'] = ['required']; + $messageIt ['catatan.required'] = 'Silahkan isi Catatan'; } $validator = Validator::make($request->all(), $validateIt, $messageIt); - $data['fails'] = $validator->fails(); + $data['fails'] = $validator->fails(); $data['errors'] = $validator->errors(); return $data; @@ -245,8 +220,8 @@ public function show($id) { - $permohonan = Permohonan::find($id); - return view('lpj::registrasi.show', compact('id','permohonan')); + $permohonan = Permohonan::find($id); + return view('lpj::registrasi.show', compact('id', 'permohonan')); } } From d3d918b838690caaa37a1d40ade8318be5c86e05 Mon Sep 17 00:00:00 2001 From: majid Date: Wed, 13 Nov 2024 22:12:51 +0700 Subject: [PATCH 12/13] update form data surveyor --- app/Http/Controllers/PermohonanController.php | 10 +- app/Http/Controllers/SurveyorController.php | 943 +++++++++--------- app/Http/Requests/FormSurveyorRequest.php | 162 +-- app/Http/Requests/JenisJaminanRequest.php | 1 + app/Models/JenisJaminan.php | 2 +- app/Models/Penilaian.php | 2 +- ...1_13_071043_update_jenis_jaminan_table.php | 28 + ...24_11_13_101409_update_penilaian_table.php | 30 + .../views/jenis_jaminan/create.blade.php | 22 + resources/views/permohonan/index.blade.php | 41 +- .../surveyor/components/bangunan.blade.php | 67 +- .../surveyor/components/card-tambah.blade.php | 215 ++-- .../views/surveyor/components/denah.blade.php | 98 +- .../views/surveyor/components/fakta.blade.php | 13 +- .../views/surveyor/components/foto.blade.php | 697 ++++++------- .../surveyor/components/inspeksi.blade.php | 276 ++--- .../surveyor/components/lingkungan.blade.php | 29 +- .../views/surveyor/components/tanah.blade.php | 4 +- resources/views/surveyor/detail.blade.php | 70 +- resources/views/surveyor/index.blade.php | 310 +++--- routes/web.php | 8 +- 21 files changed, 1518 insertions(+), 1510 deletions(-) create mode 100644 database/migrations/2024_11_13_071043_update_jenis_jaminan_table.php create mode 100644 database/migrations/2024_11_13_101409_update_penilaian_table.php diff --git a/app/Http/Controllers/PermohonanController.php b/app/Http/Controllers/PermohonanController.php index 2f9f357..3a0956d 100644 --- a/app/Http/Controllers/PermohonanController.php +++ b/app/Http/Controllers/PermohonanController.php @@ -225,6 +225,10 @@ // Get the total count of records $totalRecords = $query->count(); + $size = $request->get('size', 10); + if ($size == 0) { + $size = 10; + } // Apply pagination if provided if ($request->has('page') && $request->has('size')) { @@ -239,13 +243,13 @@ $filteredRecords = $query->count(); // Get the data for the current page - $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian'])->get(); + $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian','penilaian'])->get(); // Calculate the page count - $pageCount = ceil($totalRecords / $request->get('size')); + $pageCount = ceil($totalRecords / $size); // Calculate the current page number - $currentPage = 0 + 1; + $currentPage = max(1, $request->get('page', 1)); // Return the response data as a JSON object return response()->json([ diff --git a/app/Http/Controllers/SurveyorController.php b/app/Http/Controllers/SurveyorController.php index 3d68811..3d56f22 100644 --- a/app/Http/Controllers/SurveyorController.php +++ b/app/Http/Controllers/SurveyorController.php @@ -25,6 +25,7 @@ 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; @@ -95,27 +96,7 @@ class SurveyorController extends Controller $jenisJaminanIds = $permohonan->debiture->documents; - $buttonDisable = false; - foreach ($jenisJaminanIds as $jenisJaminanId) { - $denah = Denah::where('permohonan_id', $id) - ->where('jenis_jaminan_id', $jenisJaminanId->jenis_jaminan_id) - ->first(); - - $fotojaminan = FotoJaminan::where('permohonan_id', $id) - ->where('jenis_jaminan_id', $jenisJaminanId->jenis_jaminan_id) - ->first(); - - $analisa = Analisa::where('permohonan_id', $id) - ->where('jenis_jaminan_id', $jenisJaminanId->jenis_jaminan_id) - ->first(); - - // cek jika tidak ada - if (!$denah || !$fotojaminan || !$analisa) { - $buttonDisable = true; - break; - } - } $denah = Denah::where('permohonan_id', $id)->get(); $fotojaminan = FotoJaminan::where('permohonan_id', $id)->get(); @@ -123,13 +104,20 @@ class SurveyorController extends Controller ->where('permohonan_id', $id) ->get(); - $inpeksi = Inspeksi::where('permohonan_id', $id)->get(); - $forminspeksi = json_decode($inpeksi[0]->data_form, true); + $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); + if ($inpeksi) { + $forminspeksi = json_decode($inpeksi->data_form, true); + $formFoto = json_decode($inpeksi->foto_form, true); + $formDenah = json_decode($inpeksi->denah_form, true); + } else { + $forminspeksi = null; + $formFoto = null; + $formDenah = null; + } + return view('lpj::surveyor.detail', compact( - 'buttonDisable', - 'fotojaminan', 'denah', 'analisa', 'permohonan', @@ -147,7 +135,10 @@ class SurveyorController extends Controller 'spekKategoriBagunan', 'spekBangunan', 'saranaPelengkap', - 'arahMataAngin' + 'arahMataAngin', + 'forminspeksi', + 'formDenah', + 'formFoto', )); } /** @@ -155,158 +146,75 @@ class SurveyorController extends Controller */ public function store(FormSurveyorRequest $request) { - $data = $request->validated(); - if ($data) { - try { + if (!$data) { + return response()->json(['success' => false, 'message' => 'Invalid data'], 400); + } + try { + DB::beginTransaction(); - $formatTanahJson = [ - 'debitur_perwakilan' => $data['debitur_perwakilan'] ?? [], - 'jenis_asset' => $data['jenis_asset'] ?? null, - 'jenis_asset_tidak_sesuai' => $data['jenis_asset_tidak_sesuai'] ?? null, - 'alamat_sesuai' => $data['alamat_sesuai'] ?? null, - 'alamat_tidak_sesuai' => $data['alamat_tidak_sesuai'] ?? null, - 'nama_jalan' => $data['nama_jalan'] ?? null, - 'desa_kelurahan' => $data['desa_kelurahan'] ?? null, - 'kecamatan' => $data['kecamatan'] ?? null, - 'kota_kabupaten' => $data['kota_kabupaten'] ?? null, - 'provinsi' => $data['provinsi'] ?? null, - 'kordinat_lng' => $data['kordinat_lng'] ?? null, - 'kordinat_lat' => $data['kordinat_lat'] ?? null, - 'luas_tanah' => $data['luas_tanah'] ?? null, - 'luas_tanah_tidak_sesuai' => $data['luas_tanah_tidak_sesuai'] ?? null, - 'hadap_mata_angin' => $data['hadap_mata_angin'] ?? null, - 'hadap_mata_angin_tidak_sesuai' => $data['hadap_mata_angin_tidak_sesuai'] ?? null, - 'bentuk_tanah' => $data['bentuk_tanah'] ?? null, - 'bentuk_tanah_lainnya' => $data['bentuk_tanah_lainnya'] ?? null, - 'kontur_tanah' => $data['kontur_tanah'] ?? [], - 'ketinggian_tanah' => $data['ketinggian_tanah'] ?? [], - 'ketinggian_tanah_tidak_sesuai' => $data['ketinggian_tanah_tidak_sesuai'] ?? [], - 'posisi_kavling' => $data['posisi_kavling'] ?? [], - 'posisi_kavling_lainnya' => $data['posisi_kavling_lainnya'] ?? null, - 'tusuk_sate' => $data['tusuk_sate'] ?? null, - 'lockland' => $data['lockland'] ?? null, - 'kondisi_fisik_tanah' => $data['kondisi_fisik_tanah'] ?? [], - 'kondisi_fisik_tanah_lainnya' => $data['kondisi_fisik_tanah_lainnya'] ?? null, - ]; + $action = $request->input('type'); + $rules = $this->getActionSpecificRules($data, $action, $request); + $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->first(); - $formatBangunanJson = [ - 'luas_tanah_bangunan' => $data['luas_tanah_bangunan'] ?? null, - 'jenis_bangunan' => $data['jenis_bangunan'] ?? null, - 'kondisi_bangunan' => $data['kondisi_bangunan'] ?? null, - 'sifat_bangunan' => $data['sifat_bangunan'] ?? null, - 'sifat_bangunan_input' => $data['sifat_bagunan_input'] ?? null, - 'spek_kategori_bagunan' => $data['spek_kategori_bagunan'] ?? null, - 'spek_bangunan' => $data['spek_bangunan'] ?? null, - 'sarana_pelengkap' => $data['sarana_pelengkap'] ?? [], - 'sarana_pelengkap_input' => $data['sarana_pelengkap_input'] ?? null, - ]; - - - $formatLingkunganJson = [ - 'jarak_jalan_utama' => $data['jarak_jalan_utama'] ?? null, - 'jalan_linkungan' => $data['jalan_linkungan'] ?? null, - 'jarak_cbd_point' => $data['jarak_cbd_point'] ?? null, - 'nama_cbd_point' => $data['nama_cbd_point'] ?? null, - 'lebar_perkerasan_jalan' => $data['lebar_perkerasan_jalan'] ?? null, - 'perkerasan_jalan' => $data['perkerasan_jalan'] ?? null, - 'lalu_lintas' => $data['lalu_lintas'] ?? null, - 'gol_mas_sekitar' => $data['gol_mas_sekitar'] ?? null, - 'tingkat_keramaian' => $data['tingkat_keramaian'] ?? null, - 'terletak_diarea' => $data['terletak_diarea'] ?? null, - 'disekitar_lokasi' => $data['disekitar_lokasi'] ?? null, - 'kondisi_bangunan_sekitar' => $data['kondisi_bangunan_sekitar'] ?? null, - 'sifat_bangunan_sekitar' => $data['sifat_bangunan_sekitar'] ?? null, - 'dekat_makam' => $data['dekat_makam'] ?? null, - 'jarak_makam' => $data['jarak_makam'] ?? null, - 'nama_makam' => $data['nama_makam'] ?? null, - 'dekat_tps' => $data['dekat_tps'] ?? null, - 'jarak_tps' => $data['jarak_tps'] ?? null, - 'nama_tps' => $data['nama_tps'] ?? null, - 'merupakan_daerah' => $data['merupakan_daerah'] ?? null, - 'fasilitas_dekat_object' => $data['fasilitas_dekat_object'] ?? null, - - ]; - - - $formatFaktaJson = [ - 'fakta_positif' => $data['fakta_positif'] ?? null, - 'fakta_negatif' => $data['fakta_negatif'] ?? null, - 'rute_menuju' => $data['rute_menuju'] ?? null, - 'batas_batas' => $data['batas_batas'] ?? null, - 'kondisi_lingkungan' => $data['kondisi_lingkungan'] ?? null, - 'kondisi_lain_bangunan' => $data['kondisi_lain_bangunan'] ?? null, - 'informasi_dokument' => $data['informasi_dokument'] ?? null, - 'peruntukan' => $data['peruntukan'] ?? null, - 'kdb' => $data['kdb'] ?? null, - 'kdh' => $data['kdh'] ?? null, - 'gsb' => $data['gsb'] ?? null, - 'max_lantai' => $data['max_lantai'] ?? null, - 'klb' => $data['klb'] ?? null, - 'gss' => $data['gss'] ?? null, - 'pelebaran_jalan' => $data['pelebaran_jalan'] ?? null, - 'nama_petugas' => $data['nama_petugas'] ?? null, - 'lat' => $data['lat'] ?? null, - 'lng' => $data['lng'] ?? null, - 'foto_gistaru' => $data['foto_gistaru'] = $this->uploadFile($request->file('foto_gistaru'), $request->type) ?? null, - 'foto_bhumi' => $data['foto_bhumi'] = $this->uploadFile($request->file('foto_bhumi'), $request->type) ?? null, - 'foto_argis_region' => $data['foto_argis_region'] = $this->uploadFile($request->file('foto_argis_region'), $request->type) ?? null, - 'foto_tempat' => $data['foto_tempat'] = $this->uploadFile($request->file('foto_tempat'), $request->type) ?? null, - 'keterangan' => $data['keterangan'] ?? null, - ]; - - $mergeData = array_merge($formatTanahJson, $formatBangunanJson, $formatLingkunganJson, $formatFaktaJson); - + if ($inspeksi) { + $inspeksi->update(['data_form' => json_encode($rules)]); + } else { Inspeksi::create([ 'permohonan_id' => $request->permohonan_id, - 'data_form' => json_encode($mergeData), + 'data_form' => json_encode($rules), 'name' => $request->type, - ]); - return response()->json(['success' => true, 'message' => 'Data berhasil disimpan', - 'data' => $mergeData], 200); - } catch (Exception $e) { + } - return response()->json(['success' => false, 'message' => 'Data gagal disimpan: ' . $e->getMessage()], 500); + DB::commit(); + + return response()->json(['success' => true, 'message' => 'Data saved successfully', 'data' => $rules], 200); + } catch (Exception $e) { + DB::rollBack(); + return response()->json(['success' => false, 'message' => 'Failed to save data: ' . $e->getMessage()], 500); + } + } + + private function getActionSpecificRules($data, $action, $request): array + { + $pisah = explode(',', $action); + + $allRules = [ + 'tanah' => $this->getTanahData($data, $request), + 'bangunan' => $this->getBangunanData($data, $request), + 'kapal' => $this->getKapalData($data, $request), + 'kendaraan' => $this->getKendaraanData($data, $request), + 'mesin' => $this->getMesinData($data, $request), + 'pesawat' => $this->getPesawatData($data, $request), + 'alat-berat' => $this->getAlatBeratData($data, $request), + 'apartemen-kantor' => $this->getUnitData($data, $request), + 'lingkungan' => $this->getLingkunganData($data, $request), + 'fakta' => $this->getFactData($data, $request), + ]; + + $rules = []; + $hasAssetDescriptionRules = false; + + foreach ($pisah as $act) { + if (isset($allRules[$act])) { + $rules = array_merge($rules, $allRules[$act]); + if ($act == 'tanah' || $act == 'bangunan') { + $hasAssetDescriptionRules = true; + } } } - } - private function handleTanahBangunan(array $validatedData, FormSurveyorRequest $request) - { - $analisaTanahBangunan = AnalisaTanahBagunan::create($validatedData); - if ($analisaTanahBangunan) { - $this->createSpekBangunanAnalisa($request, $analisaTanahBangunan); + if ($hasAssetDescriptionRules) { + $rules = array_merge($rules, $this->getAssetData($data)); } + + return $rules; } - private function handleUnit(array $validatedData) - { - AnalisaUnit::create($validatedData); - } - - private function createSpekBangunanAnalisa($request, $analisaTanahBangunan) - { - foreach ($request->input('kategori', []) as $spek) { - $spek['analisa_tanah_bangunan_id'] = $analisaTanahBangunan->id; - $spekBangunan = SpekBangunanAnalisa::create($spek); - - if ($spekBangunan) { - $this->createSpekBangunanAnalisaDetails($request, $spekBangunan); - } - } - } - - private function createSpekBangunanAnalisaDetails($request, $spekBangunan) - { - foreach ($request->input('name', []) as $detail) { - $detail['spek_bangunan_analisa_id'] = $spekBangunan->id; - SpekBagunanAnalisaDetail::create($detail); - } - } public function storeDenah(Request $request) { @@ -319,26 +227,31 @@ class SurveyorController extends Controller 'jenis_jaminan_id' => 'required' ]); - $validatedData['foto_denah'] = $this->uploadFile($request->file('foto_denah'), 'foto_denah'); - Denah::create($validatedData); - return redirect()->route('surveyor.show', [ - 'id' => $validatedData['permohonan_id'], - 'form' => 'denah' - ])->with('success', 'Data foto berhasil disimpan'); + $formatJsonDenah = [ + 'foto_denah' => $validatedData['foto_denah'], + 'luas' => $validatedData['luas'], + ]; + + + $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->first(); + if ($request->input('permohonan_id') == $inspeksi->permohonan_id) { + $inspeksi->update([ + 'denah_form' => json_encode($formatJsonDenah) + ]); + } else { + Inspeksi::create([ + 'permohonan_id' => $request->input('permohonan_id'), + 'denah_form' => json_encode($formatFotojson) + ]); + } + + return response()->json(['success' => true, 'message' => 'Data berhasil disimpan', + 'data' => $formatJsonDenah], 200); } catch (Exception $e) { - $failureRedirectUrl = route('surveyor.denah', [ - 'id' => $validatedData['permohonan_id'], - 'jenis_jaminan_id' => $validatedData['jenis_jaminan_id'] - ]); - - $failureRedirectUrl .= '?form=create-denah&denah=' . $validatedData['permohonan_id'] . '&jenis_jaminan=' . $validatedData['jenis_jaminan_id']; - - return redirect($failureRedirectUrl) - ->withInput() - ->with(['error' => 'Gagal menyimpan data: ' . $e->getMessage()]); + return response()->json(['success' => false, 'message' => 'Data gagal disimpan: ' . $e->getMessage()], 500); } } @@ -370,8 +283,6 @@ class SurveyorController extends Controller 'name_gerbang' => 'nullable|string|max:255', ]); - // DB::beginTransaction(); - try { $rute_menuju_lokasi = []; @@ -440,6 +351,7 @@ class SurveyorController extends Controller $basement = $this->uploadFile($request->file('foto_basement'), 'foto_basement'); $gerbang = $this->uploadFile($request->file('foto_gerbang'), 'foto_gerbang'); + $pendamping = $this->uploadFile($request->file('pendamping'), 'pendamping'); $formatFotojson = [ @@ -450,291 +362,130 @@ class SurveyorController extends Controller 'foto_lantai_lainnya' => $foto_lantai_lainnya, 'foto_rute_lainnya' => $foto_rute_lainnya, 'basement' => $basement, - 'gerbang' => $gerbang + 'gerbang' => $gerbang, + 'pendamping' => $pendamping ]; + $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->first(); - if($request->input('permohonan_id') == $inspeksi->permohonan_id){ + if ($request->input('permohonan_id') == $inspeksi->permohonan_id) { $inspeksi->update([ 'foto_form' => json_encode($formatFotojson) ]); - }else { - + } else { Inspeksi::create([ 'permohonan_id' => $request->input('permohonan_id'), 'foto_form' => json_encode($formatFotojson) ]); } - - // DB::commit(); - return response()->json(['success' => true, 'message' => 'Data berhasil disimpan', 'data' => $formatFotojson], 200); } catch (Exception $e) { - return response()->json(['success' => false, 'message' => 'Failed to upload: ' . $e->getMessage()], 500); } } - - - public function update(FormSurveyorRequest $request, $id) + public function submitSurveyor($id) { - $validatedData = $request->validated(); - - DB::beginTransaction(); - try { - // Update Analisa entity - $analisa = Analisa::findOrFail($id); - $analisa->update($validatedData); - - if ($analisa) { - $validatedData['analisa_id'] = $analisa->id; - $analisaTanahBangunan = AnalisaTanahBagunan::where('analisa_id', $analisa->id)->firstOrFail(); - $analisaTanahBangunan->update($validatedData); - - if ($analisaTanahBangunan) { - $this->updateSpekBangunanAnalisa($request, $analisaTanahBangunan); - } - - $analisaLingkungan = AnalisaLingkungan::where('analisa_id', $analisa->id)->firstOrFail(); - $analisaLingkungan->update($validatedData); - - if ($request->hasFile('foto_tempat')) { - $validatedData['foto_tempat'] = $this->uploadFile($request->file('foto_tempat'), 'foto_tempat'); - } - - $analisaFakta = AnalisaFakta::where('analisa_id', $analisa->id)->firstOrFail(); - $analisaFakta->update($validatedData); + $cekButton = $this->checkButtonStatus($id)->getData(); + if (!$cekButton->buttonDisable) { + $permohonan = Permohonan::find($id); + $permohonan->update([ + 'status' => 'done', + ]); + return response()->json(['success' => true, 'message' => 'Form surveyor submitted successfully'], 200); + } else { + return response()->json(['error' => 'Something went wrong'], 400); } - - DB::commit(); - return redirect()->route('surveyor.show', [ - 'id' => $validatedData['permohonan_id'], - 'form' => 'inspeksi' - ])->with('success', 'Data form surveyor berhasil diperbarui'); } catch (Exception $e) { - DB::rollback(); - return response()->json(['error' => 'Failed to update data', 'details' => $e->getMessage()], 500); + return response()->json(['error' => 'Something went wrong', 'message' => $e->getMessage()], 500); } } - private function updateSpekBangunanAnalisa($request, $analisaTanahBangunan) + + + public function checkButtonStatus($id) { + try { + $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); - SpekBangunanAnalisa::where('analisa_tanah_bangunan_id', $analisaTanahBangunan->id)->delete(); + if ($inpeksi) { + $forminspeksi = json_decode($inpeksi->data_form, true); + $formFoto = json_decode($inpeksi->foto_form, true); - foreach ($request->input('kategori', []) as $spek) { - $spek['analisa_tanah_bangunan_id'] = $analisaTanahBangunan->id; - $spekBangunan = SpekBangunanAnalisa::create($spek); + $buttonDisable = false; + if ( + $formFoto && count($formFoto) > 0 && + $forminspeksi + ) { + $buttonDisable = false; + } else { + $buttonDisable = true; + } - if ($spekBangunan) { - $this->updateSpekBangunanAnalisaDetails($request, $spekBangunan); + return response()->json(['buttonDisable' => $buttonDisable]); + } else { + return response()->json(['buttonDisable' => true]); } - } - } - - private function updateSpekBangunanAnalisaDetails($request, $spekBangunan) - { - // Delete existing SpekBagunanAnalisaDetail records - SpekBagunanAnalisaDetail::where('spek_bangunan_analisa_id', $spekBangunan->id)->delete(); - - // Create new SpekBagunanAnalisaDetail records - foreach ($request->input('name', []) as $detail) { - $detail['spek_bangunan_analisa_id'] = $spekBangunan->id; - SpekBagunanAnalisaDetail::create($detail); + } catch (\Exception $e) { + return response()->json(['error' => 'Something went wrong', 'message' => $e->getMessage()], 500); } } - public function updateDenah(Request $request, $id): RedirectResponse - { - } - private function processObjekUploads(Request $request, FotoJaminan $fotojaminan) - { - $fotoObjek = $request->file('foto_objek'); - $nameObjek = $request->input('name_objek'); - $analisaType = $request->input('analisa_type'); // Tambahkan input untuk tipe analisa + public function storeJadwal(Request $request) +{ + try { - if (!is_array($fotoObjek) || !is_array($nameObjek) || count($fotoObjek) !== count($nameObjek)) { - throw new Exception("Mismatched foto_objek and name_objek inputs"); - } - - // Definisikan labels berdasarkan tipe analisa - $objekLabels = []; - if ($analisaType === 'tanah_bangunan') { - $objekLabels = [ - 'Tampak Samping Kiri', - 'Tampak Samping Kanan', - 'Nomor Rumah/Unit' - ]; - } elseif ($analisaType === 'unit') { - $objekLabels = [ - 'Tampak Loby', - 'Tampak Lift', - 'Tampak Samping Kiri Unit', - 'Tampak Samping Kanan Unit', - 'Tampak Depan Unit', - 'Nomor Unit' - ]; - } - - foreach ($fotoObjek as $index => $foto) { - if (!isset($nameObjek[$index])) { - throw new Exception("Missing description for foto_objek at index {$index}"); - } - - // Pastikan index ada dalam objekLabels - $label = isset($objekLabels[$index]) ? $objekLabels[$index] : "Foto {$index}"; - - $path = $this->uploadFile($foto, 'objek'); - ObjekJaminan::create([ - 'foto_jaminan_id' => $fotojaminan->id, - 'name_objek' => $label . ': ' . $nameObjek[$index], - 'foto_objek' => $path, - ]); - } - } - - private function processUploads($type, Request $request, FotoJaminan $fotojaminan) - { - $files = $request->file("foto_{$type}"); - $names = $request->input("name_{$type}"); - - if (!is_array($files) || !is_array($names) || count($files) !== count($names)) { - throw new Exception("Mismatched foto_{$type} and name_{$type} inputs"); - } - - foreach ($files as $index => $file) { - if (!isset($names[$index])) { - throw new Exception("Missing description for {$type} at index {$index}"); - } - - $path = $this->uploadFile($file, $type); - - $data = [ - 'foto_jaminan_id' => $fotojaminan->id, - "name_{$type}" => $names[$index], - "foto_{$type}" => $path, - ]; - - switch ($type) { - case 'rute': - RuteJaminan::create($data); - break; - case 'lingkungan': - Lingkungan::create($data); - break; - } - } - } - - private function processLantaiUnitUploads(Request $request, FotoJaminan $fotojaminan) - { - $lantaiFiles = $request->file('foto_lantai_unit'); - $lantaiNames = $request->input('name_lantai_unit'); - - if (!$lantaiFiles) { - return; - } - - if (!is_array($lantaiFiles) || !is_array($lantaiNames) || count($lantaiFiles) !== count($lantaiNames)) { - throw new Exception("Mismatched foto_lantai_unit and name_lantai_unit inputs"); - } - - foreach ($lantaiFiles as $index => $file) { - $path = $this->uploadFile($file, 'lantai'); - LantaiUnit::create([ - 'objek_jaminan_id' => $fotojaminan->id, - 'name_lantai_unit' => "Lantai " . ($index + 1), - 'foto_lantai_unit' => $path, - ]); - } - } - - private function uploadFile($file, $type) - { - if (!$file->isValid()) { - throw new Exception("Invalid file upload for {$type}"); - } - - $fileName = time() . '_' . $file->getClientOriginalName(); - $path = $file->storeAs("public/surveyor/{$type}", $fileName); - - if ($path === false) { - throw new Exception("Failed to store file for {$type}"); - } - - return str_replace('public/', '', $path); - } - - - public function dataForDatatables(Request $request) - { - if (is_null($this->user) || !$this->user->can('debitur.view')) { - // abort(403, 'Sorry! You are not allowed to view users.'); - } - - $query = Permohonan::query(); - - if ($request->has('search') && !empty($request->get('search'))) { - $search = $request->get('search'); - $query->where(function ($q) use ($search) { - $q->where('nomor_registrasi', 'LIKE', '%' . $search . '%'); - $q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%'); - $q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%'); - $q->orWhereRelation('debiture', 'name', 'LIKE', '%' . $search . '%'); - $q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%'); - $q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%'); - $q->orWhere('status', 'LIKE', '%' . $search . '%'); - }); - } - - $query->whereRaw('LOWER(status) = ?', ['assign']); - - $query->whereHas('penilaian.userPenilai', function ($q) { - $q->where('user_id', Auth::user()->id); - $q->where('role', 'surveyor'); - }); - - - if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) { - $order = $request->get('sortOrder'); - $column = $request->get('sortField'); - $query->orderBy($column, $order); - } - - $totalRecords = $query->count(); - - $size = $request->get('size', 10); - if ($size == 0) { - $size = 10; - } - - if ($request->has('page') && $request->has('size')) { - $page = $request->get('page', 1); - $offset = ($page - 1) * $size; - - $query->skip($offset)->take($size); - } - - $filteredRecords = $query->count(); - $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'jenisFasilitasKredit'])->get(); - - $pageCount = ceil($totalRecords / $size); - - $currentPage = max(1, $request->get('page', 1)); - return response()->json([ - 'draw' => $request->get('draw'), - 'recordsTotal' => $totalRecords, - 'recordsFiltered' => $filteredRecords, - 'pageCount' => $pageCount, - 'page' => $currentPage, - 'totalCount' => $totalRecords, - 'data' => $data, + $validate = $request->validate([ + 'id' => 'required', + 'waktu_penilaian' => 'required', + 'deskripsi_penilaian' => 'required' ]); + + // return response()->json([ + // 'daa'=>$validate + // ]); + $id = $request->input('id'); + $penilaian = Penilaian::findOrFail($id); + + $penilaian->update([ + 'waktu_penilaian' => $validate['waktu_penilaian'], + 'deskripsi_penilaian' => $validate['deskripsi_penilaian'], + + ]); + + return redirect() + ->route('surveyor.index') + ->with('success', 'Jadwal berhasil dibuat.'); + } catch (\Exception $e) { + return redirect() + ->route('surveyor.index') + ->with('error', 'Gagal membuat jadwal: ' . $e->getMessage()); } +} + +public function storeAproved($id) +{ + try { + + + $penilaian = Penilaian::findOrFail($id); + + $penilaian->update([ + 'authorized_status' => 1, + ]); + + return redirect() + ->route('permohonan.index') + ->with('success', 'Jadwal berhasil di aprove.'); + } catch (\Exception $e) { + return redirect() + ->route('permohonan.index') + ->with('error', 'Gagal membuat jadwal: ' . $e->getMessage()); + } +} /** * Form inspeksi. */ @@ -777,18 +528,18 @@ class SurveyorController extends Controller $perkerasanJalan = PerkerasanJalan::all(); - $analisa = Analisa::with('analisaTanahBangunan', 'analisaLingkungan', 'analisaFakta', 'jenisJaminan') - ->where('permohonan_id', $id) - ->where('jenis_jaminan_id', $jaminanId) - ->first(); + // return response()->json([ + // 'per'=> + // $permohonan]); - $inpeksi = Inspeksi::where('permohonan_id', $id)->get(); - $forminspeksi = json_decode($inpeksi[0]->data_form, true); - + $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); + $forminspeksi = null; + if ($inpeksi) { + $forminspeksi = json_decode($inpeksi->data_form, true); + } return view('lpj::surveyor.components.inspeksi', compact( - 'analisa', 'permohonan', 'surveyor', 'branches', @@ -824,9 +575,17 @@ class SurveyorController extends Controller { $permohonan = $this->getPermohonanJaminanId($id, $jaminanId); - $denah = Denah::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first(); + $denah = null; - return view('lpj::surveyor.components.denah', compact('permohonan', 'denah')); + + $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); + $formDenah = null; + if ($inpeksi) { + $formDenah = json_decode($inpeksi->denah_form, true); + } + + // return response()->json($formDenah); + return view('lpj::surveyor.components.denah', compact('permohonan', 'denah', 'formDenah')); } /** @@ -840,11 +599,21 @@ class SurveyorController extends Controller $branches = Branch::all(); $provinces = Province::all(); - // $fotoJaminan = FotoJaminan::with(['objekJaminan', 'lantaiUnit' ,'ruteJaminan', 'lingkungan'])->where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first(); + + $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); + $formFoto = null; + if ($inpeksi) { + $formFoto = json_decode($inpeksi->foto_form, true); + } $fotoJaminan = null; - return view('lpj::surveyor.components.foto', compact('permohonan', 'surveyor', 'branches', 'provinces', 'fotoJaminan')); + // return response()->json([ + // 'inspeksi' => $formFoto, + + // ]); + + return view('lpj::surveyor.components.foto', compact('permohonan', 'surveyor', 'branches', 'provinces', 'fotoJaminan', 'formFoto')); } /** @@ -1010,6 +779,73 @@ class SurveyorController extends Controller } + public function dataForDatatables(Request $request) + { + if (is_null($this->user) || !$this->user->can('debitur.view')) { + // abort(403, 'Sorry! You are not allowed to view users.'); + } + + $query = Permohonan::query(); + + if ($request->has('search') && !empty($request->get('search'))) { + $search = $request->get('search'); + $query->where(function ($q) use ($search) { + $q->where('nomor_registrasi', 'LIKE', '%' . $search . '%'); + $q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%'); + $q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%'); + $q->orWhereRelation('debiture', 'name', 'LIKE', '%' . $search . '%'); + $q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%'); + $q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%'); + $q->orWhere('status', 'LIKE', '%' . $search . '%'); + }); + } + + $query->whereRaw('LOWER(status) = ?', ['assign']); + + $query->whereHas('penilaian.userPenilai', function ($q) { + $q->where('user_id', Auth::user()->id); + $q->where('role', 'surveyor'); + }); + + + if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) { + $order = $request->get('sortOrder'); + $column = $request->get('sortField'); + $query->orderBy($column, $order); + } + + $totalRecords = $query->count(); + + $size = $request->get('size', 10); + if ($size == 0) { + $size = 10; + } + + if ($request->has('page') && $request->has('size')) { + $page = $request->get('page', 1); + $offset = ($page - 1) * $size; + + $query->skip($offset)->take($size); + } + + $filteredRecords = $query->count(); + $data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'jenisFasilitasKredit','penilaian'])->get(); + + $pageCount = ceil($totalRecords / $size); + + $currentPage = max(1, $request->get('page', 1)); + return response()->json([ + 'draw' => $request->get('draw'), + 'recordsTotal' => $totalRecords, + 'recordsFiltered' => $filteredRecords, + 'pageCount' => $pageCount, + 'page' => $currentPage, + 'totalCount' => $totalRecords, + 'data' => $data, + ]); + } + + public function dataForDatatablesData(Request $request, $type) { @@ -1129,6 +965,7 @@ class SurveyorController extends Controller 'branch', 'tujuanPenilaian', 'penilaian', + 'debiture.documents.jenisJaminan', 'debiture.documents' => function ($query) use ($jaminanId) { $query->where('jenis_jaminan_id', $jaminanId); } @@ -1139,26 +976,8 @@ class SurveyorController extends Controller ->findOrFail($id); } - public function submitSurveyor(Request $request, $id) - { - $permohonan = Permohonan::find($id); - $permohonan->update([ - 'status' => 'done', - ]); - return redirect() - ->route('surveyor.index') - ->with('success', 'form surveyor submitted successfully'); - - } - - - public function validateSubmit() - { - - } - private function getModelClass(string $type): ?string { @@ -1236,4 +1055,216 @@ class SurveyorController extends Controller 'perkerasan-jalan' => ['Perkerasan jalan', 'perkerasan-jalan'] ]; + private function getAssetData($data) + { + return [ + 'debitur_perwakilan' => $data['debitur_perwakilan'] ?? [], + 'jenis_asset' => $data['jenis_asset'] ?? null, + 'jenis_asset_tidak_sesuai' => $data['jenis_asset_tidak_sesuai'] ?? null, + 'alamat_sesuai' => $data['alamat_sesuai'] ?? null, + 'alamat_tidak_sesuai' => $data['alamat_tidak_sesuai'] ?? null, + 'nama_jalan' => $data['nama_jalan'] ?? null, + 'desa_kelurahan' => $data['desa_kelurahan'] ?? null, + 'kecamatan' => $data['kecamatan'] ?? null, + 'kota_kabupaten' => $data['kota_kabupaten'] ?? null, + 'provinsi' => $data['provinsi'] ?? null, + 'kordinat_lng' => $data['kordinat_lng'] ?? null, + 'kordinat_lat' => $data['kordinat_lat'] ?? null, + ]; + } + + + private function getTanahData($data,$request): array + { + return [ + 'luas_tanah' => $data['luas_tanah'] ?? null, + 'luas_tanah_tidak_sesuai' => $data['luas_tanah_tidak_sesuai'] ?? null, + 'hadap_mata_angin' => $data['hadap_mata_angin'] ?? null, + 'hadap_mata_angin_tidak_sesuai' => $data['hadap_mata_angin_tidak_sesuai'] ?? null, + 'bentuk_tanah' => $data['bentuk_tanah'] ?? null, + 'bentuk_tanah_lainnya' => $data['bentuk_tanah_lainnya'] ?? null, + 'kontur_tanah' => $data['kontur_tanah'] ?? [], + 'ketinggian_tanah' => $data['ketinggian_tanah'] ?? [], + 'ketinggian_tanah_tidak_sesuai' => $data['ketinggian_tanah_tidak_sesuai'] ?? [], + 'kontur_jalan' => $data['kontur_jalan'] ?? null, + 'ketinggian_jalan' => $data['ketinggian_jalan'] ?? [], + 'posisi_kavling' => $data['posisi_kavling'] ?? [], + 'posisi_kavling_lainnya' => $data['posisi_kavling_lainnya'] ?? null, + 'tusuk_sate' => $data['tusuk_sate'] ?? null, + 'lockland' => $data['lockland'] ?? null, + 'kondisi_fisik_tanah' => $data['kondisi_fisik_tanah'] ?? [], + 'kondisi_fisik_tanah_lainnya' => $data['kondisi_fisik_tanah_lainnya'] ?? null, + ]; + } + + private function getBangunanData($data, $request): array + { + return [ + 'luas_tanah_bagunan' => $data['luas_tanah_bagunan'] ?? null, + 'jenis_bangunan' => $data['jenis_bangunan'] ?? null, + 'kondisi_bangunan' => $data['kondisi_bangunan'] ?? null, + 'sifat_bangunan' => $data['sifat_bangunan'] ?? null, + 'sifat_bangunan_input' => $data['sifat_bagunan_input'] ?? null, + 'spek_kategori_bagunan' => $data['spek_kategori_bagunan'] ?? null, + 'spek_bangunan' => $data['spek_bangunan'] ?? null, + 'sarana_pelengkap' => $data['sarana_pelengkap'] ?? [], + 'sarana_pelengkap_input' => $data['sarana_pelengkap_input'] ?? null, + ]; + } + + private function getLingkunganData($data, $request): array + { + return [ + 'jarak_jalan_utama' => $data['jarak_jalan_utama'] ?? null, + 'jalan_linkungan' => $data['jalan_linkungan'] ?? null, + 'jarak_cbd_point' => $data['jarak_cbd_point'] ?? null, + 'nama_cbd_point' => $data['nama_cbd_point'] ?? null, + 'lebar_perkerasan_jalan' => $data['lebar_perkerasan_jalan'] ?? null, + 'perkerasan_jalan' => $data['perkerasan_jalan'] ?? null, + 'lalu_lintas' => $data['lalu_lintas'] ?? null, + 'gol_mas_sekitar' => $data['gol_mas_sekitar'] ?? null, + 'tingkat_keramaian' => $data['tingkat_keramaian'] ?? null, + 'terletak_diarea' => $data['terletak_diarea'] ?? null, + 'disekitar_lokasi' => $data['disekitar_lokasi'] ?? null, + 'kondisi_bangunan_sekitar' => $data['kondisi_bangunan_sekitar'] ?? null, + 'sifat_bangunan_sekitar' => $data['sifat_bangunan_sekitar'] ?? null, + 'dekat_makam' => $data['dekat_makam'] ?? null, + 'jarak_makam' => $data['jarak_makam'] ?? null, + 'nama_makam' => $data['nama_makam'] ?? null, + 'dekat_tps' => $data['dekat_tps'] ?? null, + 'jarak_tps' => $data['jarak_tps'] ?? null, + 'nama_tps' => $data['nama_tps'] ?? null, + 'merupakan_daerah' => $data['merupakan_daerah'] ?? null, + 'fasilitas_dekat_object' => $data['fasilitas_dekat_object'] ?? null, + ]; + } + + private function getFactData($data, $request): array + { + $factData = [ + 'fakta_positif' => $data['fakta_positif'] ?? null, + 'fakta_negatif' => $data['fakta_negatif'] ?? null, + 'rute_menuju' => $data['rute_menuju'] ?? null, + 'batas_batas' => $data['batas_batas'] ?? null, + 'kondisi_lingkungan' => $data['kondisi_lingkungan'] ?? null, + 'kondisi_lain_bangunan' => $data['kondisi_lain_bangunan'] ?? null, + 'informasi_dokument' => $data['informasi_dokument'] ?? null, + 'peruntukan' => $data['peruntukan'] ?? null, + 'kdb' => $data['kdb'] ?? null, + 'kdh' => $data['kdh'] ?? null, + 'gsb' => $data['gsb'] ?? null, + 'max_lantai' => $data['max_lantai'] ?? null, + 'klb' => $data['klb'] ?? null, + 'gss' => $data['gss'] ?? null, + 'pelebaran_jalan' => $data['pelebaran_jalan'] ?? null, + 'nama_petugas' => $data['nama_petugas'] ?? null, + 'lat' => $data['lat'] ?? null, + 'lng' => $data['lng'] ?? null, + 'keterangan' => $data['keterangan'] ?? null, + ]; + + $factData['foto_gistaru'] = $this->updateOrDeleteFile($data, $request, 'foto_gistaru'); + $factData['foto_bhumi'] = $this->updateOrDeleteFile($data, $request, 'foto_bhumi'); + $factData['foto_argis_region'] = $this->updateOrDeleteFile($data, $request, 'foto_argis_region'); + $factData['foto_tempat'] = $this->updateOrDeleteFile($data, $request, 'foto_tempat'); + + return $factData; + } + + private function updateOrDeleteFile($data, $request, $fileKey) + { + if ($request->hasFile($fileKey)) { + $file = $request->file($fileKey); + if ($file->isValid()) { + $fileName = time() . '_' . $file->getClientOriginalName(); + $path = $file->storeAs("public/surveyor/{$request->type}", $fileName); + if ($path === false) { + throw new Exception("Failed to store file for {$fileKey}"); + } + if (isset($data[$fileKey]) && $data[$fileKey]) { + $this->deleteFile($data[$fileKey]); + } + return str_replace('public/', '', $path); + } else { + throw new Exception("Invalid file upload for {$fileKey}"); + } + } elseif (isset($data[$fileKey]) && $data[$fileKey]) { + return $data[$fileKey]; + } else { + return null; + } + } + + private function deleteFile($filePath) + { + $fullPath = storage_path('app/public/' . $filePath); + if (file_exists($fullPath)) { + unlink($fullPath); + } + } + private function getKapalData($data): array + { + return [ + 'keterangan' => $data['keterangan'] + ]; + } + + private function getKendaraanData($data): array + { + return [ + 'keterangan' => $data['keterangan'] + ]; + } + + private function getMesinData($data): array + { + return [ + 'keterangan' => $data['keterangan'] + ]; + } + + private function getPesawatData($data): array + { + return [ + 'keterangan' => $data['keterangan'] + ]; + } + + + private function getAlatBeratData($data): array + { + return [ + 'keterangan' => $data['keterangan'] + ]; + } + + + private function getUnitData($data): array + { + return [ + 'keterangan' => $data['keterangan'] + ]; + } + + + + + + // function upload file to storage + private function uploadFile($file, $type) + { + if (!$file->isValid()) { + throw new Exception("Invalid file upload for {$type}"); + } + + $fileName = time() . '_' . $file->getClientOriginalName(); + $path = $file->storeAs("public/surveyor/{$type}", $fileName); + + if ($path === false) { + throw new Exception("Failed to store file for {$type}"); + } + + return str_replace('public/', '', $path); + } + } diff --git a/app/Http/Requests/FormSurveyorRequest.php b/app/Http/Requests/FormSurveyorRequest.php index e003a36..d724c72 100644 --- a/app/Http/Requests/FormSurveyorRequest.php +++ b/app/Http/Requests/FormSurveyorRequest.php @@ -19,75 +19,50 @@ class FormSurveyorRequest extends FormRequest */ public function rules(): array { - $commonRules = $this->getBangunanRules(); + $actionSpecificRules = $this->getActionSpecificRules(); - - return array_merge($commonRules, $actionSpecificRules); return $actionSpecificRules; } - /** - * Get common rules that apply to all actions. - */ - private function getCommonRules(): array - { - return [ - 'fakta_positif' => 'nullable|array', - 'fakta_negatif' => 'nullable|array', - 'rute_menuju' => 'nullable', - 'batas_batas' => 'nullable|array', - 'kondisi_linkungan' => 'nullable|array', - 'kondisi_lain_bangunan' => 'nullable|array', - 'informasi_dokument' => 'nullable', - 'peruntukan' => 'nullable', - 'kdb' => 'nullable', - 'kdh' => 'nullable', - 'gsb' => 'nullable', - 'max_lantai' => 'nullable', - 'klb' => 'nullable', - 'gss' => 'nullable', - 'pelebaran_jalan' => 'nullable', - 'nama_petugas' => 'nullable', - 'lat' => 'nullable|numeric', - 'lng' => 'nullable|numeric', - 'foto_gistaru' => 'nullable', - 'foto_bhumi' => 'nullable', - 'foto_argis_region' => 'nullable', - 'foto_tempat' => 'nullable', - 'keterangan' => 'nullable', - ]; - } - /** * Get rules specific to the action. */ private function getActionSpecificRules(): array { $action = $this->input('action'); + $pisah = explode(',', $action); - switch ($action) { - case 'tanah': - return $this->getTanahRules(); - case 'unit': - return $this->getUnitRules(); - case 'kapal': - return $this->getUnitRules(); - case 'kendaraan': - return $this->getUnitRules(); - case 'mesin': - return $this->getUnitRules(); - case 'bangunan': - return $this->getTanahBangunanRules(); - case 'tanah_bangunan': - return array_merge($this->getAssetDescriptionRules(),$this->getTanahRules(), $this->getBangunanRules(), $this->getLinkunganRules(), $this->getCommonRules()); + $allRules = [ + 'tanah' => $this->getTanahRules(), + 'bangunan' => $this->getBangunanRules(), + 'kapal' => $this->getKapalRules(), + 'kendaraan' => $this->getKendaraanRules(), + 'mesin' => $this->getMesinRules(), + 'pesawat' => $this->getLinkunganRules(), + 'alat-berat' => $this->getLinkunganRules(), + 'apartemen-kantor' => $this->getUnitRules(), + 'lingkungan' => $this->getLinkunganRules(), + 'fakta' => $this->getCommonRules(), + ]; - case 'alat-berat': - return $this->getUnitRules(); - default: - return []; + $rules = []; + $hasAssetDescriptionRules = false; + + foreach ($pisah as $act) { + if (isset($allRules[$act])) { + $rules = array_merge($rules, $allRules[$act]); + if ($act == 'tanah' || $act == 'bangunan') { + $hasAssetDescriptionRules = true; + } + } } - } + if ($hasAssetDescriptionRules) { + $rules = array_merge($rules, $this->getAssetDescriptionRules()); + } + + return $rules; + } /** * Get rules specific to tanah action. */ @@ -133,9 +108,9 @@ class FormSurveyorRequest extends FormRequest ]; } - /** - * Get rules specific to unit action. - */ + /** + * Get rules specific to unit action. + */ private function getUnitRules(): array { return [ @@ -164,7 +139,7 @@ class FormSurveyorRequest extends FormRequest 'jarak_cbd_point' => 'nullable', 'nama_cbd_point' => 'nullable', 'lebar_perkerasan_jalan' => 'nullable', - 'perkerasan_jalan' => 'nullable', + 'perkerasan_jalan.*' => 'nullable', 'lalu_lintas' => 'nullable', 'gol_mas_sekitar' => 'nullable', 'tingkat_keramaian' => 'nullable', @@ -223,24 +198,57 @@ class FormSurveyorRequest extends FormRequest private function getAssetDescriptionRules(): array -{ - return [ - 'permohonan_id' => 'required', - 'type' => 'required', - 'debitur_perwakilan' => 'required|array', - 'jenis_asset' => 'required', - 'jenis_asset_tidak_sesuai' => 'nullable', - 'alamat_sesuai' => 'required', - 'alamat_tidak_sesuai' => 'nullable', - 'nama_jalan' => 'nullable', - 'desa_kelurahan' => 'nullable', - 'kecamatan' => 'nullable', - 'kota_kabupaten' => 'nullable', - 'provinsi' => 'nullable', - 'kordinat_lng' => 'nullable', - 'kordinat_lat' => 'nullable', - ]; -} + { + return [ + 'permohonan_id' => 'required', + 'type' => 'required', + 'debitur_perwakilan' => 'required|array', + 'jenis_asset' => 'required', + 'jenis_asset_tidak_sesuai' => 'nullable', + 'alamat_sesuai' => 'required', + 'alamat_tidak_sesuai' => 'nullable', + 'nama_jalan' => 'nullable', + 'desa_kelurahan' => 'nullable', + 'kecamatan' => 'nullable', + 'kota_kabupaten' => 'nullable', + 'provinsi' => 'nullable', + 'kordinat_lng' => 'nullable', + 'kordinat_lat' => 'nullable', + ]; + } + + /** + * Get common rules that apply to all actions. + */ + private function getCommonRules(): array + { + return [ + 'fakta_positif' => 'nullable|array', + 'fakta_negatif' => 'nullable|array', + 'rute_menuju' => 'nullable', + 'batas_batas' => 'nullable|array', + 'kondisi_lingkungan' => 'nullable|array', + 'kondisi_lain_bangunan' => 'nullable|array', + 'informasi_dokument' => 'nullable', + 'peruntukan' => 'nullable', + 'kdb' => 'nullable', + 'kdh' => 'nullable', + 'gsb' => 'nullable', + 'max_lantai' => 'nullable', + 'klb' => 'nullable', + 'gss' => 'nullable', + 'pelebaran_jalan' => 'nullable', + 'nama_petugas' => 'nullable', + 'lat' => 'nullable|numeric', + 'lng' => 'nullable|numeric', + 'foto_gistaru' => 'nullable', + 'foto_bhumi' => 'nullable', + 'foto_argis_region' => 'nullable', + 'foto_tempat' => 'nullable', + 'keterangan' => 'nullable', + ]; + } + } diff --git a/app/Http/Requests/JenisJaminanRequest.php b/app/Http/Requests/JenisJaminanRequest.php index 6f0325c..96d9653 100644 --- a/app/Http/Requests/JenisJaminanRequest.php +++ b/app/Http/Requests/JenisJaminanRequest.php @@ -19,6 +19,7 @@ 'name' => 'required|max:255', 'slug' => 'required|max:255', 'jenis_legalitas_jaminan_id' => 'nullable', + 'form_kategori.*' => 'required', ]; } diff --git a/app/Models/JenisJaminan.php b/app/Models/JenisJaminan.php index e8f4e17..0adc1b4 100644 --- a/app/Models/JenisJaminan.php +++ b/app/Models/JenisJaminan.php @@ -5,5 +5,5 @@ namespace Modules\Lpj\Models; class JenisJaminan extends Base { protected $table = 'jenis_jaminan'; - protected $fillable = ['code', 'name', 'slug', 'jenis_legalitas_jaminan_id']; + protected $fillable = ['code', 'name', 'slug', 'jenis_legalitas_jaminan_id', 'form_kategori']; } diff --git a/app/Models/Penilaian.php b/app/Models/Penilaian.php index 1de2dc5..7648592 100644 --- a/app/Models/Penilaian.php +++ b/app/Models/Penilaian.php @@ -19,7 +19,7 @@ class Penilaian extends Model protected $fillable = [ 'jenis_penilaian_id', 'penilaian_id', 'tanggal_kunjungan', 'keterangan','nomor_registrasi', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_at', - 'created_by', 'updated_at', 'updated_by', 'deleted_at', 'deleted_by' + 'created_by', 'updated_at', 'updated_by', 'deleted_at', 'deleted_by','waktu_penilaian', 'deskripsi_penilaian' ]; public function jenis_penilaian() diff --git a/database/migrations/2024_11_13_071043_update_jenis_jaminan_table.php b/database/migrations/2024_11_13_071043_update_jenis_jaminan_table.php new file mode 100644 index 0000000..2e2ee64 --- /dev/null +++ b/database/migrations/2024_11_13_071043_update_jenis_jaminan_table.php @@ -0,0 +1,28 @@ +json('form_kategori')->after('slug')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('jenis_jaminan', function (Blueprint $table) { + $table->dropColumn('form_kategori'); + }); + } +}; diff --git a/database/migrations/2024_11_13_101409_update_penilaian_table.php b/database/migrations/2024_11_13_101409_update_penilaian_table.php new file mode 100644 index 0000000..d71ff4a --- /dev/null +++ b/database/migrations/2024_11_13_101409_update_penilaian_table.php @@ -0,0 +1,30 @@ +datetime('waktu_penilaian')->nullable(); + $table->text('deskripsi_penilaian')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('penilaian', function (Blueprint $table) { + $table->dropColumn('waktu_penilaian'); + $table->dropColumn('deskripsi_penilaian'); + }); + } +}; diff --git a/resources/views/jenis_jaminan/create.blade.php b/resources/views/jenis_jaminan/create.blade.php index 0f9d930..a12b7ee 100644 --- a/resources/views/jenis_jaminan/create.blade.php +++ b/resources/views/jenis_jaminan/create.blade.php @@ -66,6 +66,28 @@
+ +
+ +
+ + @error('form_kategori') + {{ $message }} + @enderror +
+
+
- +

@@ -69,18 +66,20 @@ @foreach ($kondisiBangunan as $item) @if (strcasecmp($item->name, 'lainnya') == 0)
-
@endif @@ -101,11 +100,12 @@
-
@endforeach @@ -128,7 +128,8 @@ @if (@isset($spekKategoriBagunan)) @foreach ($spekKategoriBagunan as $item)
- +
@@ -136,7 +137,8 @@ @foreach ($spekBangunan as $spek) @if ($spek->spek_kategori_bangunan_id == $item->id) @@ -144,7 +146,8 @@ @endforeach
- +
@endforeach @@ -175,11 +178,12 @@
-
@endforeach @@ -188,8 +192,9 @@ - - + + + @push('scripts') +@endpush diff --git a/resources/views/surveyor/components/fakta.blade.php b/resources/views/surveyor/components/fakta.blade.php index a27f17b..0609899 100644 --- a/resources/views/surveyor/components/fakta.blade.php +++ b/resources/views/surveyor/components/fakta.blade.php @@ -28,7 +28,7 @@ - @if ($analisaType != 'mesin' && $analisaType != 'kapal' && $analisaType != 'kendaraan' && $analisaType != 'pesawat') +
@@ -84,9 +84,9 @@
- + - +
- @endif +
- @if ($analisaType != 'mesin' && $analisaType != 'kapal' && $analisaType != 'kendaraan' && $analisaType != 'pesawat') +
@@ -315,6 +315,7 @@
- @endif + @endpush diff --git a/resources/views/surveyor/components/lingkungan.blade.php b/resources/views/surveyor/components/lingkungan.blade.php index c66fcf3..54e98d1 100644 --- a/resources/views/surveyor/components/lingkungan.blade.php +++ b/resources/views/surveyor/components/lingkungan.blade.php @@ -48,7 +48,9 @@ @if (isset($perkerasanJalan)) @foreach ($perkerasanJalan as $item) @endforeach @@ -68,7 +70,9 @@ @endforeach @@ -87,7 +91,8 @@ @endforeach @@ -107,7 +112,8 @@ @endforeach @@ -127,7 +133,8 @@ @endforeach @@ -220,7 +227,7 @@ @endforeach @@ -255,7 +262,15 @@ @endforeach diff --git a/resources/views/surveyor/components/tanah.blade.php b/resources/views/surveyor/components/tanah.blade.php index c47792e..717ba96 100644 --- a/resources/views/surveyor/components/tanah.blade.php +++ b/resources/views/surveyor/components/tanah.blade.php @@ -134,8 +134,8 @@ @foreach ($konturTanah as $item) @endforeach diff --git a/resources/views/surveyor/detail.blade.php b/resources/views/surveyor/detail.blade.php index 9be9cbe..0333a6b 100644 --- a/resources/views/surveyor/detail.blade.php +++ b/resources/views/surveyor/detail.blade.php @@ -83,7 +83,7 @@
@if (request()->has('form') && request('form') == 'denah') @include('lpj::surveyor.components.card-tambah') - {{-- @elseif(request()->has('form') && request('form') == 'data-pembanding') + {{-- @elseif(request()->has('form') && request('form') == 'data-pembanding') @include('lpj::surveyor.components.data-pembanding') --}} @elseif(request()->has('form') && request('form') == 'foto') @include('lpj::surveyor.components.card-tambah') @@ -92,23 +92,75 @@ @endIf
- @if (request()->has('form') && request('form') !== 'data-pembanding') - - @endif +
+
@endsection @push('scripts') + + }; + + let dataTable = new KTDataTable(element, dataTableOptions); + + searchInput.addEventListener('input', function() { + const searchValue = this.value.trim(); + dataTable.search(searchValue, true); + }); + + // statusFilter.addEventListener('change', function() { + // const selectedStatus = this.value; + // dataTable.search(selectedStatus); + // }); + + function convertDate(date) { + const createdAt = new Date(date); + const day = String(createdAt.getDate()).padStart(2, '0'); + const month = String(createdAt.getMonth() + 1).padStart(2, '0'); + const year = createdAt.getFullYear(); + return `${day}-${month}-${year}`; + } + + + + + @endpush + + diff --git a/routes/web.php b/routes/web.php index 47f49ad..016eb75 100644 --- a/routes/web.php +++ b/routes/web.php @@ -460,14 +460,18 @@ Route::middleware(['auth'])->group(function () { Route::get('/', [SurveyorController::class, 'index'])->name('index'); Route::get('{id}/show', [SurveyorController::class, 'show'])->name('show'); Route::post('store', [SurveyorController::class, 'store'])->name('store'); - Route::post('storeDenah', [SurveyorController::class, 'storeDenah'])->name('storeDenah'); + Route::post('storeDenah/{id}', [SurveyorController::class, 'storeDenah'])->name('storeDenah'); + Route::put('storeJadwal', [SurveyorController::class, 'storeJadwal'])->name('storeJadwal'); + Route::get('storeAproved/{id}', [SurveyorController::class, 'storeAproved'])->name('storeAproved'); Route::post('storeFoto', [SurveyorController::class, 'storeFoto'])->name('storeFoto'); + Route::get('checkButtonStatus/{id}', [SurveyorController::class, 'checkButtonStatus'])->name('checkButtonStatus'); + Route::get('datatables', [SurveyorController::class, 'dataForDatatables'])->name('datatables'); Route::get('inspeksi/{id}/{jaminanId}', [SurveyorController::class, 'formInspeksi'])->name('inspeksi'); Route::get('denah/{id}/{jaminanId}', [SurveyorController::class, 'denah'])->name('denah'); Route::get('foto/{id}/{jaminanId}', [SurveyorController::class, 'foto'])->name('foto'); Route::get('data-pembanding/{id}', [SurveyorController::class, 'dataPembanding'])->name('data-pembanding'); - Route::put('submitSurveyor/{id}', [SurveyorController::class, 'submitSurveyor'])->name('submitSurveyor'); + Route::get('submitSurveyor/{id}', [SurveyorController::class, 'submitSurveyor'])->name('submitSurveyor'); }); Route::name('penilai.')->prefix('penilai')->group(function () { From 3f8475f418f12782e2bcfa23604a68901573ad16 Mon Sep 17 00:00:00 2001 From: majid Date: Thu, 14 Nov 2024 00:08:45 +0700 Subject: [PATCH 13/13] update form apartemen dan foto --- app/Http/Controllers/SurveyorController.php | 122 ++++++------ app/Models/Inspeksi.php | 12 +- ...024_11_13_153901_update_inspeksi_table.php | 29 +++ .../components/apartemen-kantor.blade.php | 4 +- .../views/surveyor/components/foto.blade.php | 175 +++++++++++------- .../surveyor/components/inspeksi.blade.php | 17 +- routes/web.php | 2 +- 7 files changed, 221 insertions(+), 140 deletions(-) create mode 100644 database/migrations/2024_11_13_153901_update_inspeksi_table.php diff --git a/app/Http/Controllers/SurveyorController.php b/app/Http/Controllers/SurveyorController.php index 3d56f22..3c86379 100644 --- a/app/Http/Controllers/SurveyorController.php +++ b/app/Http/Controllers/SurveyorController.php @@ -94,7 +94,6 @@ class SurveyorController extends Controller $saranaPelengkap = SaranaPelengkap::all(); $arahMataAngin = ArahMataAngin::all(); - $jenisJaminanIds = $permohonan->debiture->documents; @@ -104,7 +103,15 @@ class SurveyorController extends Controller ->where('permohonan_id', $id) ->get(); - $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); + + + $jenisJaminanIds = $permohonan->debiture->documents->pluck('jenisJaminan.id')->toArray(); // Convert to array + + $jaminanId = $jenisJaminanIds[0]; + $inpeksi = Inspeksi::where('permohonan_id', $id) + ->whereIn('jenis_jaminan_id', $jenisJaminanIds) + ->first(); + if ($inpeksi) { $forminspeksi = json_decode($inpeksi->data_form, true); $formFoto = json_decode($inpeksi->foto_form, true); @@ -139,6 +146,7 @@ class SurveyorController extends Controller 'forminspeksi', 'formDenah', 'formFoto', + 'jaminanId' )); } /** @@ -158,15 +166,15 @@ class SurveyorController extends Controller $action = $request->input('type'); $rules = $this->getActionSpecificRules($data, $action, $request); - $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->first(); - - if ($inspeksi) { + $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->where('jenis_jaminan_id', $request->input('jenis_jaminan_id'))->first(); + if ($request->input('permohonan_id') == $inspeksi->permohonan_id && $request->input('jenis_jaminan_id') == $inspeksi->jenis_jaminan_id) { $inspeksi->update(['data_form' => json_encode($rules)]); } else { Inspeksi::create([ 'permohonan_id' => $request->permohonan_id, 'data_form' => json_encode($rules), 'name' => $request->type, + 'jenis_jaminan_id' => $request->input('jenis_jaminan_id'), ]); } @@ -236,8 +244,8 @@ class SurveyorController extends Controller ]; - $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->first(); - if ($request->input('permohonan_id') == $inspeksi->permohonan_id) { + $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->where('jenis_jaminan_id', $request->input('jenis_jaminan_id'))->first(); + if ($request->input('permohonan_id') == $inspeksi->permohonan_id && $request->input('jenis_jaminan_id') == $inspeksi->jenis_jaminan_id) { $inspeksi->update([ 'denah_form' => json_encode($formatJsonDenah) ]); @@ -262,7 +270,6 @@ class SurveyorController extends Controller $validatedData = $request->validate([ 'permohonan_id' => 'required', 'jenis_jaminan_id' => 'required', - 'analisa_type' => 'required|in:tanah_bangunan,unit', 'pendamping' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'foto_objek.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', 'name_objek.*' => 'required|string|max:255', @@ -366,8 +373,8 @@ class SurveyorController extends Controller 'pendamping' => $pendamping ]; - $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->first(); - if ($request->input('permohonan_id') == $inspeksi->permohonan_id) { + $inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->where('jenis_jaminan_id', $request->input('jenis_jaminan_id'))->first(); + if ($request->input('permohonan_id') == $inspeksi->permohonan_id && $request->input('jenis_jaminan_id') == $inspeksi->jenis_jaminan_id) { $inspeksi->update([ 'foto_form' => json_encode($formatFotojson) ]); @@ -384,7 +391,7 @@ class SurveyorController extends Controller } } - public function submitSurveyor($id) + public function submitSurveyor($id,$jaminanId) { try { $cekButton = $this->checkButtonStatus($id)->getData(); @@ -407,6 +414,7 @@ class SurveyorController extends Controller public function checkButtonStatus($id) { try { + $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); if ($inpeksi) { @@ -428,64 +436,64 @@ class SurveyorController extends Controller return response()->json(['buttonDisable' => true]); } } catch (\Exception $e) { - return response()->json(['error' => 'Something went wrong', 'message' => $e->getMessage()], 500); + return response()->json(['buttonDisable' => true]); } } public function storeJadwal(Request $request) -{ - try { + { + try { - $validate = $request->validate([ - 'id' => 'required', - 'waktu_penilaian' => 'required', - 'deskripsi_penilaian' => 'required' - ]); + $validate = $request->validate([ + 'id' => 'required', + 'waktu_penilaian' => 'required', + 'deskripsi_penilaian' => 'required' + ]); - // return response()->json([ - // 'daa'=>$validate - // ]); - $id = $request->input('id'); - $penilaian = Penilaian::findOrFail($id); + // return response()->json([ + // 'daa'=>$validate + // ]); + $id = $request->input('id'); + $penilaian = Penilaian::findOrFail($id); - $penilaian->update([ - 'waktu_penilaian' => $validate['waktu_penilaian'], - 'deskripsi_penilaian' => $validate['deskripsi_penilaian'], - - ]); + $penilaian->update([ + 'waktu_penilaian' => $validate['waktu_penilaian'], + 'deskripsi_penilaian' => $validate['deskripsi_penilaian'], - return redirect() - ->route('surveyor.index') - ->with('success', 'Jadwal berhasil dibuat.'); - } catch (\Exception $e) { - return redirect() - ->route('surveyor.index') - ->with('error', 'Gagal membuat jadwal: ' . $e->getMessage()); + ]); + + return redirect() + ->route('surveyor.index') + ->with('success', 'Jadwal berhasil dibuat.'); + } catch (\Exception $e) { + return redirect() + ->route('surveyor.index') + ->with('error', 'Gagal membuat jadwal: ' . $e->getMessage()); + } } -} -public function storeAproved($id) -{ - try { + public function storeAproved($id) + { + try { - $penilaian = Penilaian::findOrFail($id); + $penilaian = Penilaian::findOrFail($id); - $penilaian->update([ - 'authorized_status' => 1, - ]); + $penilaian->update([ + 'authorized_status' => 1, + ]); - return redirect() - ->route('permohonan.index') - ->with('success', 'Jadwal berhasil di aprove.'); - } catch (\Exception $e) { - return redirect() - ->route('permohonan.index') - ->with('error', 'Gagal membuat jadwal: ' . $e->getMessage()); + return redirect() + ->route('permohonan.index') + ->with('success', 'Jadwal berhasil di aprove.'); + } catch (\Exception $e) { + return redirect() + ->route('permohonan.index') + ->with('error', 'Gagal membuat jadwal: ' . $e->getMessage()); + } } -} /** * Form inspeksi. */ @@ -534,7 +542,7 @@ public function storeAproved($id) - $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); + $inpeksi = Inspeksi::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first(); $forminspeksi = null; if ($inpeksi) { $forminspeksi = json_decode($inpeksi->data_form, true); @@ -577,8 +585,7 @@ public function storeAproved($id) $denah = null; - - $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); + $inpeksi = Inspeksi::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first(); $formDenah = null; if ($inpeksi) { $formDenah = json_decode($inpeksi->denah_form, true); @@ -601,7 +608,8 @@ public function storeAproved($id) - $inpeksi = Inspeksi::where('permohonan_id', $id)->first(); + $inpeksi = Inspeksi::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first(); + $formFoto = null; if ($inpeksi) { $formFoto = json_decode($inpeksi->foto_form, true); @@ -1074,7 +1082,7 @@ public function storeAproved($id) } - private function getTanahData($data,$request): array + private function getTanahData($data, $request): array { return [ 'luas_tanah' => $data['luas_tanah'] ?? null, diff --git a/app/Models/Inspeksi.php b/app/Models/Inspeksi.php index 16c3629..ebbe399 100644 --- a/app/Models/Inspeksi.php +++ b/app/Models/Inspeksi.php @@ -14,7 +14,17 @@ class Inspeksi extends Model /** * The attributes that are mass assignable. */ - protected $fillable = ['data_form', 'foto_form', 'denah_form','permohonan_id', 'name', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_by', 'updated_by', 'deleted_by']; + protected $fillable = ['data_form', 'foto_form', 'denah_form','permohonan_id', 'name', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_by', 'updated_by', 'deleted_by','jenis_jaminan_id']; + + public function permohonan() + { + return $this->belongsTo(Permohonan::class, 'permohonan_id'); + } + + public function jenis_jaminan() + { + return $this->belongsTo(JenisJaminan::class, 'jenis_jaminan_id'); + } // protected static function newFactory(): InspeksiFactory // { diff --git a/database/migrations/2024_11_13_153901_update_inspeksi_table.php b/database/migrations/2024_11_13_153901_update_inspeksi_table.php new file mode 100644 index 0000000..552ed5c --- /dev/null +++ b/database/migrations/2024_11_13_153901_update_inspeksi_table.php @@ -0,0 +1,29 @@ +unsignedBigInteger('jenis_jaminan_id')->nullable()->after('permohonan_id'); + $table->foreign('jenis_jaminan_id')->references('id')->on('jenis_jaminan')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('inspeksi', function (Blueprint $table) { + $table->dropColumn('jenis_jaminan_id'); + }); + } +}; diff --git a/resources/views/surveyor/components/apartemen-kantor.blade.php b/resources/views/surveyor/components/apartemen-kantor.blade.php index 40d53a9..00ec1e8 100644 --- a/resources/views/surveyor/components/apartemen-kantor.blade.php +++ b/resources/views/surveyor/components/apartemen-kantor.blade.php @@ -17,12 +17,12 @@
diff --git a/resources/views/surveyor/components/foto.blade.php b/resources/views/surveyor/components/foto.blade.php index 4617dc7..4228f8b 100644 --- a/resources/views/surveyor/components/foto.blade.php +++ b/resources/views/surveyor/components/foto.blade.php @@ -89,24 +89,6 @@ - @foreach ($permohonan->debiture->documents as $dokumen) - @if ($dokumen->jenisJaminan) - @php - $formKategori = json_decode($dokumen->jenisJaminan->form_kategori, true); - @endphp - - - @if (is_array($formKategori)) - @foreach ($formKategori as $kategori) - @include('lpj::surveyor.components.' . str_replace('-', '_', $kategori), [ - 'dokumen' => $dokumen, - ]) - @endforeach - @endif - @endif - @endforeach
@@ -226,61 +208,110 @@

Objek Jaminan

- @php - $objekViews = []; - if ($analisaType === 'tanah_bangunan') { - $objekViews = [ - ['label' => 'Tampak Samping Kiri', 'index' => 0], - ['label' => 'Tampak Samping Kanan', 'index' => 1], - ['label' => 'Nomor Rumah/Unit', 'index' => 2], - ]; - } elseif ($analisaType === 'unit') { - $objekViews = [ - ['label' => 'Tampak Loby', 'index' => 0], - ['label' => 'Tampak Lift', 'index' => 1], - ['label' => 'Tampak Samping Kiri Unit', 'index' => 2], - ['label' => 'Tampak Samping Kanan Unit', 'index' => 3], - ['label' => 'Tampak Depan Unit', 'index' => 4], - ['label' => 'Nomor Unit', 'index' => 5], - ]; - } - @endphp - @if (count($objekViews) > 0) - @foreach ($objekViews as $view) -
-
- - -
- {{ $view['label'] }} + @foreach ($permohonan->debiture->documents as $dokumen) + @if ($dokumen->jenisJaminan) + @php + $formKategori = json_decode($dokumen->jenisJaminan->form_kategori, true); + @endphp + @if (isset($formKategori) && $formKategori) + + + @if (is_array($formKategori)) + @foreach ($formKategori as $kategori) + @if ($kategori === 'tanah' || $kategori === 'bangunan') + @php + $objekViews = [ + ['label' => 'Tampak Samping Kiri', 'index' => 0], + ['label' => 'Tampak Samping Kanan', 'index' => 1], + ['label' => 'Nomor Rumah/Unit', 'index' => 2], + ]; + @endphp + @elseif ($kategori === 'apartemen-kantor') + @php + $objekViews = [ + ['label' => 'Tampak Loby', 'index' => 0], + ['label' => 'Tampak Lift', 'index' => 1], + ['label' => 'Tampak Samping Kiri Unit', 'index' => 2], + ['label' => 'Tampak Samping Kanan Unit', 'index' => 3], + ['label' => 'Tampak Depan Unit', 'index' => 4], + ['label' => 'Nomor Unit', 'index' => 5], + ]; + @endphp + @elseif ($kategori === 'kendaraan') + @php + $objekViews = [ + ['label' => 'Tampak Depan Objek', 'index' => 0], + ['label' => 'Tampak Kanan Objek', 'index' => 1], + ['label' => 'Tampak Samping Kiri Objek', 'index' => 2], + ['label' => 'Tampak Belakang Objek', 'index' => 3], + ['label' => 'Tampak Bagian Dalam', 'index' => 4], + ['label' => 'Nomor Panel Instrument', 'index' => 5], + ['label' => 'Tampak Odometer', 'index' => 6], + ['label' => 'Tampak Aksesoris Tambahan', 'index' => 7], + ['label' => 'Tampak Nomor Rangka', 'index' => 8], + ['label' => 'Tampak Nomor Mesin', 'index' => 9], + ['label' => 'Tampak Penilai dan Pendamping di lapangan', 'index' => 10], + ]; + @endphp + @elseif ($kategori === 'kapal') + @php + $objekViews = [ + ['label' => 'Tampak Depan', 'index' => 0], + ['label' => 'Tampak Kanan', 'index' => 1], + ['label' => 'Tampak Samping Kiri', 'index' => 2], + ['label' => 'Tampak Belakang', 'index' => 3], + ['label' => 'Tampak Bagian Dalam', 'index' => 4], + ['label' => 'Nomor Panel Instrument', 'index' => 5], + ['label' => 'Tampak Hours Meters', 'index' => 6], + ['label' => 'Tampak Aksesoris Tambahan', 'index' => 7], + ['label' => 'Tampak Nomor Rangka', 'index' => 8], + ['label' => 'Tampak Nomor Mesin', 'index' => 9], + ['label' => 'Tampak Penilai dan Pendamping di lapangan', 'index' => 10], + ]; + @endphp + @endif -
- - -
- -
-
- -
- @endforeach - @else -
-

Tipe analisa tidak valid atau belum dipilih.

-
+ @if (count($objekViews) > 0) + @foreach ($objekViews as $view) +
+
+ + +
+ {{ $view['label'] }} + +
+ + +
+ + +
+
+ +
+ @endforeach + @endif + @endforeach + @endif + @endif @endif + @endforeach
@@ -656,10 +687,10 @@ 'X-CSRF-TOKEN': '{{ csrf_token() }}' }, success: function(response) { - // if (response.success) { - // window.location.href = - // '{{ route('surveyor.show', ['id' => $permohonan->id]) }}?form=foto'; - // } + if (response.success) { + window.location.href = + '{{ route('surveyor.show', ['id' => $permohonan->id]) }}?form=foto'; + } console.log(response); }, error: function(xhr, status, error) { diff --git a/resources/views/surveyor/components/inspeksi.blade.php b/resources/views/surveyor/components/inspeksi.blade.php index 10e72f2..8182440 100644 --- a/resources/views/surveyor/components/inspeksi.blade.php +++ b/resources/views/surveyor/components/inspeksi.blade.php @@ -30,27 +30,30 @@ @csrf - + @foreach ($permohonan->debiture->documents as $dokumen) - @if ($dokumen->jenisJaminan) - @php - $formKategori = json_decode($dokumen->jenisJaminan->form_kategori, true); - @endphp + @if ($dokumen->jenisJaminan) + @php + $formKategori = json_decode($dokumen->jenisJaminan->form_kategori, true); + @endphp + @if (isset($formKategori) && $formKategori) @if (is_array($formKategori)) @foreach ($formKategori as $kategori) - @include('lpj::surveyor.components.' . str_replace('-', '_', $kategori), [ + @include('lpj::surveyor.components.' . str_replace('-', '-', $kategori), [ 'dokumen' => $dokumen, ]) @endforeach @endif @endif - @endforeach + @endif + @endforeach