From 6558d8348bdd37f4a9005102ff682a8fd553840d Mon Sep 17 00:00:00 2001 From: rahmatrafli1 Date: Mon, 30 Sep 2024 13:04:50 +0700 Subject: [PATCH] Mengubah tampilan show KJPP dan Create/Edit KJPP --- app/Http/Controllers/KJPPController.php | 3 + app/Http/Requests/KJPPRequest.php | 18 +++-- .../2024_09_30_021444_update_kjpp_table.php | 30 +++++++++ resources/views/kjpp/create.blade.php | 14 ++-- resources/views/kjpp/show.blade.php | 66 ++++++++++--------- 5 files changed, 85 insertions(+), 46 deletions(-) create mode 100644 database/migrations/2024_09_30_021444_update_kjpp_table.php diff --git a/app/Http/Controllers/KJPPController.php b/app/Http/Controllers/KJPPController.php index 2552a58..966c35c 100644 --- a/app/Http/Controllers/KJPPController.php +++ b/app/Http/Controllers/KJPPController.php @@ -62,6 +62,9 @@ class KJPPController extends Controller Storage::copy('public/test/default.pdf', 'public/uploads_pdf/' . $filename); } + $validated['ijin_usaha_id'] = json_encode($request->input('ijin_usaha_id')); + $validated['jenis_aset_id'] = json_encode($request->input('jenis_aset_id')); + // Tambahkan nama file ke data yang divalidasi $validated['attachment'] = $filename; diff --git a/app/Http/Requests/KJPPRequest.php b/app/Http/Requests/KJPPRequest.php index 3b5c637..e3e6fe4 100644 --- a/app/Http/Requests/KJPPRequest.php +++ b/app/Http/Requests/KJPPRequest.php @@ -32,8 +32,10 @@ class KJPPRequest extends FormRequest 'nomor_hp_pic_admin' => 'required|numeric|digits_between:10,15', 'nama_pic_marketing' => 'required|string|not_regex:/^\d+$/|max:255', 'nomor_hp_pic_marketing' => 'required|numeric|digits_between:10,15', - 'ijin_usaha_id' => 'nullable', - 'jenis_aset_id' => 'nullable', + 'ijin_usaha_id' => 'required|array', + 'ijin_usaha_id.*' => 'exists:ijin_usaha,code', + 'jenis_aset_id' => 'required|array', + 'jenis_aset_id.*' => 'exists:jenis_jaminan,code', 'attachment' => 'nullable|mimes:pdf|max:1024' ]; @@ -54,14 +56,6 @@ class KJPPRequest extends FormRequest return true; } - public function prepareForValidation(): void - { - $this->merge([ - 'ijin_usaha_id' => json_encode($this->ijin_usaha_id), - 'jenis_aset_id' => json_encode($this->jenis_aset_id) - ]); - } - public function messages(): array { return [ @@ -106,6 +100,10 @@ class KJPPRequest extends FormRequest 'nomor_hp_pic_marketing.required' => 'Nomor HP PIC Marketing Wajib diisi!', 'nomor_hp_pic_marketing.numeric' => 'Nomor HP PIC Marketing harus berupa angka!', 'nomor_hp_pic_marketing.digits_between' => 'Nomor HP PIC Marketing minimum 10 digit dan maksimum 15 digit!', + 'ijin_usaha_id.required' => 'Ijin Usaha Wajib diisi!', + 'ijin_usaha_id.min' => 'Ijin Usaha Wajib diisi minimal satu atau lebih!', + 'jenis_aset_id.required' => 'Jenis Aset Wajib diisi!', + 'jenis_aset_id.min' => 'Jenis Aset Wajib diisi minimal satu atau lebih!', 'attachment.mimes' => 'Attachment harus berformat pdf!', 'attachment.max' => 'Attachment berukuran maksimum 1 MB!', ]; diff --git a/database/migrations/2024_09_30_021444_update_kjpp_table.php b/database/migrations/2024_09_30_021444_update_kjpp_table.php new file mode 100644 index 0000000..1ffb5a1 --- /dev/null +++ b/database/migrations/2024_09_30_021444_update_kjpp_table.php @@ -0,0 +1,30 @@ +string('ijin_usaha_id')->change(); + $table->string('jenis_aset_id')->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('kjpp', function (Blueprint $table) { + $table->string('ijin_usaha_id')->nullable()->change(); + $table->string('jenis_aset_id')->nullable()->change(); + }); + } +}; diff --git a/resources/views/kjpp/create.blade.php b/resources/views/kjpp/create.blade.php index 4a43191..e0c854d 100644 --- a/resources/views/kjpp/create.blade.php +++ b/resources/views/kjpp/create.blade.php @@ -51,7 +51,7 @@
- @if (isset($ijin_usaha)) @@ -357,10 +358,10 @@ @endforeach + @error('ijin_usaha_id') + {{ $message }} + @enderror
- @error('ijin_usaha_id') - {{ $message }} - @enderror
diff --git a/resources/views/kjpp/show.blade.php b/resources/views/kjpp/show.blade.php index 9680756..35762c9 100644 --- a/resources/views/kjpp/show.blade.php +++ b/resources/views/kjpp/show.blade.php @@ -149,45 +149,49 @@ Ijin Usaha
- + @if (isset($kjpp->ijin_usaha_id)) +
+ @foreach (json_decode($kjpp->ijin_usaha_id, true) as $ijin_code) + @php + $ijin_usaha = $ijin_usahas->firstWhere('code', $ijin_code); + @endphp + @if ($ijin_usaha) +
+ {{ $ijin_usaha->name }} +
+ @endif + @endforeach +
+ @else +
No + business license + selected.
+ @endif
-
- + @else + + No asset type selected. + + @endif