From 90fc1c8ff11b9fa9b4e4e5b16defe895e21c4953 Mon Sep 17 00:00:00 2001 From: KhatamNugraha Date: Tue, 30 Apr 2024 16:51:45 +0700 Subject: [PATCH] update validasi signer --- Http/Controllers/KonfirmasiBankController.php | 157 ++++++++----- Resources/views/pages/index_signer.blade.php | 208 +++++++----------- 2 files changed, 179 insertions(+), 186 deletions(-) diff --git a/Http/Controllers/KonfirmasiBankController.php b/Http/Controllers/KonfirmasiBankController.php index 1fb58a9..95e8828 100644 --- a/Http/Controllers/KonfirmasiBankController.php +++ b/Http/Controllers/KonfirmasiBankController.php @@ -34,6 +34,7 @@ use Modules\Konfirmasibank\Http\Requests\Fasilitas\StoreFasilitasRequest; use Akaunting\Money\Currency; use Akaunting\Money\Money; + use Illuminate\Validation\Rule; class KonfirmasiBankController extends Controller { @@ -227,44 +228,64 @@ return $formattedAmount; } - public function postSigner(Request $request){ - + public function postSigner(Request $request) + { if (is_null($this->user) || !$this->user->can('konfirmasibank.create')) { - abort(403, 'Sorry !! You are Unauthorized to create any konfirmasibank.create !'); + abort(403, 'Maaf!! Anda tidak memiliki otorisasi untuk membuat konfirmasi bank.'); } + $messages = [ + 'deputy_director.required' => 'Nama Deputy Director wajib diisi.', + 'deputy_director.string' => 'Nama Deputy Director harus berupa teks.', + 'deputy_director.unique' => 'Nama Deputy Director sudah terdaftar.', + 'deputy_director.regex' => 'Nama Deputy Director tidak boleh mengandung angka.', + 'executive_officer.required' => 'Nama Executive Officer wajib diisi.', + 'executive_officer.string' => 'Nama Executive Officer harus berupa teks.', + 'executive_officer.unique' => 'Nama Executive Officer sudah terdaftar.', + 'executive_officer.regex' => 'Nama Executive Officer tidak boleh mengandung angka.', + 'signer_type.required' => 'Tipe penandatangan wajib diisi.', + 'signer_type.string' => 'Tipe penandatangan harus berupa teks.', + ]; - $currentDate = Carbon::now(); - $validated = $request->validate([ - 'deputy_director' => 'required|string', - 'executive_officer' => 'required|string', + $request->validate([ + 'deputy_director' => [ + 'required', + 'string', + 'unique:signers,deputy_director_name', + 'regex:/^[a-zA-Z\s]*$/', + function($attribute, $value, $fail) use ($request) { + if ($value === $request->executive_officer) { + $fail('Nama Deputy Director tidak boleh sama dengan nama Executive Officer.'); + } + }, + ], + 'executive_officer' => [ + 'required', + 'string', + 'unique:signers,executive_officer_name', + 'regex:/^[a-zA-Z\s]*$/' + ], 'signer_type' => 'required|string' - ]); + ], $messages); - if ($validated) { - try { - // Create New User + try { + // Membuat instance baru dari Signer $signer = new Signer(); $signer->deputy_director_name = $request->deputy_director; $signer->executive_officer_name = $request->executive_officer; $signer->signer_type = $request->signer_type; - $signer->created_at = $currentDate; + $signer->created_at = Carbon::now(); $signer->status = 1; $signer->save(); - // return redirect()->route('konfirmasibank.addFasilitas')->with('success', 'Data berhasil ditambahkan'); - echo json_encode(['status' => 'success', 'message' => ' Add signer successfully .']); + return response()->json(['status' => 'success', 'message' => 'Penandatangan berhasil ditambahkan.']); } catch (Exception $e) { - return json_encode([ + return response()->json([ 'status' => 'error', 'message' => $e->getMessage() - ]); - } + ]); } - - return false; - - } + } /** * Show the form for editing the specified resource. @@ -286,45 +307,63 @@ } - public function updateSigner(Request $request) - { + public function updateSigner(Request $request) + { if (is_null($this->user) || !$this->user->can('konfirmasibank.update')) { - abort(403, 'Sorry !! You are Unauthorized to edit any role !'); + abort(403, 'Maaf!! Anda tidak memiliki otorisasi untuk mengupdate konfirmasi bank.'); } - $today = Carbon::now(); + $signer = Signer::findOrFail($request->id); - $validator = Validator::make($request->all(), [ - 'deputy_director' => 'required|string', - 'executive_officer' => 'required|string', - 'signer_type' => 'required|string' - ]); + $messages = [ + 'deputy_director.required' => 'Nama Deputy Director wajib diisi.', + 'deputy_director.string' => 'Nama Deputy Director harus berupa teks.', + 'deputy_director.unique' => 'Nama Deputy Director sudah terdaftar.', + 'deputy_director.regex' => 'Nama Deputy Director tidak boleh mengandung angka.', + 'executive_officer.required' => 'Nama Executive Officer wajib diisi.', + 'executive_officer.string' => 'Nama Executive Officer harus berupa teks.', + 'executive_officer.unique' => 'Nama Executive Officer sudah terdaftar.', + 'executive_officer.regex' => 'Nama Executive Officer tidak boleh mengandung angka.', + 'signer_type.required' => 'Tipe penandatangan wajib diisi.', + 'signer_type.string' => 'Tipe penandatangan harus berupa teks.', + ]; - if ($validator->fails()) { - return response()->json(['errors' => $validator->errors()], 422); // Return validation errors as JSON + $request->validate([ + 'deputy_director' => [ + 'required', + 'string', + // Rule::unique('signers', 'deputy_director_name')->ignore($signer->id), + 'regex:/^[a-zA-Z\s]*$/', + function($attribute, $value, $fail) use ($request) { + if ($value === $request->executive_officer) { + $fail('Nama Deputy Director tidak boleh sama dengan nama Executive Officer.'); + } + }, + ], + 'executive_officer' => [ + 'required', + 'string', + // Rule::unique('signers', 'executive_officer_name')->ignore($signer->id), + 'regex:/^[a-zA-Z\s]*$/' + ], + 'signer_type' => 'required|string' + ], $messages); + + try { + $signer->deputy_director_name = $request->deputy_director; + $signer->executive_officer_name = $request->executive_officer; + $signer->signer_type = $request->signer_type; + $signer->updated_at = Carbon::now(); + $signer->save(); + + return response()->json(['status' => 'success', 'message' => 'Penandatangan berhasil diperbarui.']); + } catch (Exception $e) { + return response()->json([ + 'status' => 'error', + 'message' => $e->getMessage() + ]); } - - - if ($validator) { - try { - $signer = Signer::findOrFail($request->id); - $signer->deputy_director_name = $request->deputy_director; - $signer->executive_officer_name = $request->executive_officer; - $signer->signer_type = $request->signer_type; - $signer->updated_at = $today; - $signer->save(); - - echo json_encode(['status' => 'success', 'message' => ' signer updated successfully.']); - - } catch (Exception $e) { - echo json_encode(['status' => 'error', 'message' => ' signer updated failed.']); - } - - return; - - } - echo json_encode(['status' => 'error', 'message' => ' signer updated failed.']); } public function export(Request $request){ @@ -337,12 +376,17 @@ $DataPinjaman = []; $DataFasilitas = []; $DataRK = []; + $Accounts = []; // dd($listAccount); $GetCustomer = $Account->getCustomer($request['cusNo'])->first(); $listAccount = $Account->getAccount($request['cusNo'], $arrAccount, $dateCore )->get(); + //dd( $listAccount); foreach ($listAccount as $key1 => $account) { $dataAADepo = $Account->getAA($request['cusNo'],$account->ACCOUNT_NUMBER, $dateCore)->first(); + array_push($Accounts, $account->ACCOUNT_NUMBER); + + // $AccountAnjak = $Account->getAccountAnjak($request['cusNo'], $dateCore )->first(); if ($account->CATEGORY == '6603' || $account->CATEGORY == '6602') { if ($dataAADepo != null) { @@ -383,6 +427,11 @@ } + // $string = implode(", ", $Accounts); + + // dd($string ); + // $DataAnjak = $Account->getAccountAnjak($Accounts, $dateCore)->get(); + // dd($DataAnjak ); $Arrangement = $Account->getPinjaman($request['cusNo'], $dateCore)->get(); foreach ($Arrangement as $key2 => $pinjaman) { @@ -402,6 +451,8 @@ $listAccountRK = $Account->getAccountRK($request['cusNo'], $dateCore )->get(); + + foreach ($listAccountRK as $rk => $valRk) { if ( $valRk->CATEGORY == '1003') { $rateRK = ""; diff --git a/Resources/views/pages/index_signer.blade.php b/Resources/views/pages/index_signer.blade.php index f9af66f..bbdc932 100644 --- a/Resources/views/pages/index_signer.blade.php +++ b/Resources/views/pages/index_signer.blade.php @@ -62,7 +62,7 @@
- +
@@ -77,7 +77,7 @@
@@ -152,128 +152,70 @@ $("#myModalEditSigner").modal("hide"); }); - // $('#executive_officer').on('keyup', function() { - // let deputy_eirector = $('input[name="deputy_director"]').val(); - // let executive_officer = $(this).val(); - // var value = $(this).val(); - // // var valid = /^[A-Za-z ]+$/.test(value); - // // if (!valid) { - // // $(this).css('border-color', 'red'); // Ubah warna border menjadi merah jika input tidak valid - // // $('#submitSigner, #submitFormUpdateSigner').prop('disabled', true); // Non-aktifkan tombol submit - // // alert('Input hanya boleh berisi huruf.'); - // // } else { - // // $(this).css('border-color', ''); // Kembalikan warna border - // // $('#submitSigner, #submitFormUpdateSigner').prop('disabled', false); // Aktifkan tombol submit - // // } - // if (executive_officer == deputy_eirector ) { - // // alert('Penandatangan Tidak Boleh Sama'); - // $('#executive_officer').css('border-color', 'red'); - // $('#submitSigner').attr('disabled', 'disabled'); - // $('#note').show(); - // }else{ - // $('#executive_officer').css('border-color', ''); - // $('#submitSigner').attr('disabled', false); - // $('#note').hide(); - // } - // }); + // $('input[name="deputy_director"]').on('input', function() { + // let executive_officer = $('input[name="executive_officer"]').val(); + // var deputy_eirector = $(this).val(); + // var valid = /^[A-Za-z ]+$/.test(deputy_eirector); - // $('#executive_officer2').on('keyup', function() { - // let deputy_eirector = $('input[name="deputy_director"]').val().toUpperCase(); - // let executive_officer = $(this).val(); - // if (executive_officer == deputy_eirector ) { - // $('#executive_officer2').css('border-color', 'red'); - // $('#submitFormUpdateSigner').attr('disabled', 'disabled'); - // $('#note2').show(); - // }else{ - // $('#executive_officer2').css('border-color', ''); - // $('#submitFormUpdateSigner').attr('disabled', false); - // $('#note2').hide(); - // } - // }); + // if (!valid) { + // $(this).css('border-color', 'red'); // Ubah warna border menjadi merah jika input tidak valid + // $('#submitSigner, #submitFormUpdateSigner').prop('disabled', true); // Non-aktifkan tombol submit + // $('#deputy_director').css('border-color', 'red'); + // $('.noteDir').show(); + // // alert('Input hanya boleh berisi huruf.'); + // } else { + // $(this).css('border-color', ''); // Kembalikan warna border + // $('#submitSigner, #submitFormUpdateSigner').prop('disabled', false); // Aktifkan tombol submit + // $('.noteDir').hide(); + // } + + // }); + + // $('input[name="executive_officer"]').on('input', function() { + // let deputy_eirector = $('input[name="deputy_director"]').val(); + // var executive_officer = $(this).val(); + // var valid = /^[A-Za-z ]+$/.test(executive_officer); + + // if (!valid) { + // $(this).css('border-color', 'red'); // Ubah warna border menjadi merah jika input tidak valid + // $('#submitSigner, #submitFormUpdateSigner').prop('disabled', true); // Non-aktifkan tombol submit + // $('#executive_officer').css('border-color', 'red'); + // $('.noteEx').show(); + // // alert('Input hanya boleh berisi huruf.'); + // } else { + // $(this).css('border-color', ''); // Kembalikan warna border + // $('#submitSigner, #submitFormUpdateSigner').prop('disabled', false); // Aktifkan tombol submit + // $('.noteEx').hide(); + // } - $('input[name="deputy_director"]').on('input', function() { - let executive_officer = $('input[name="executive_officer"]').val(); - var deputy_eirector = $(this).val(); - var valid = /^[A-Za-z ]+$/.test(deputy_eirector); - if (!valid) { - $(this).css('border-color', 'red'); // Ubah warna border menjadi merah jika input tidak valid - $('#submitSigner, #submitFormUpdateSigner').prop('disabled', true); // Non-aktifkan tombol submit - $('#deputy_director').css('border-color', 'red'); - $('.noteDir').show(); - // alert('Input hanya boleh berisi huruf.'); - } else { - $(this).css('border-color', ''); // Kembalikan warna border - $('#submitSigner, #submitFormUpdateSigner').prop('disabled', false); // Aktifkan tombol submit - $('.noteDir').hide(); - } - - }); - - $('input[name="executive_officer"]').on('input', function() { - let deputy_eirector = $('input[name="deputy_director"]').val(); - var executive_officer = $(this).val(); - var valid = /^[A-Za-z ]+$/.test(executive_officer); - - if (!valid) { - $(this).css('border-color', 'red'); // Ubah warna border menjadi merah jika input tidak valid - $('#submitSigner, #submitFormUpdateSigner').prop('disabled', true); // Non-aktifkan tombol submit - $('#executive_officer').css('border-color', 'red'); - $('.noteEx').show(); - // alert('Input hanya boleh berisi huruf.'); - } else { - $(this).css('border-color', ''); // Kembalikan warna border - $('#submitSigner, #submitFormUpdateSigner').prop('disabled', false); // Aktifkan tombol submit - $('.noteEx').hide(); - } - - if (executive_officer == deputy_eirector ) { - // alert('Penandatangan Tidak Boleh Sama'); - $('#executive_officer').css('border-color', 'red'); - $('#submitSigner').attr('disabled', 'disabled'); - $('.note').show(); - }else{ - $('#executive_officer').css('border-color', ''); - $('#submitSigner').attr('disabled', false); - $('.note').hide(); - } - - }); + // }); // Handle form submission when the "Submit" button inside the modal is clicked $("#submitSigner").click(function(e) { - // Serialize the form data - e.preventDefault(); - var formData = $("#formSigner").serialize(); - // var executive_officer = $('input[name="executive_officer"]').val(); - // var deputy_director = $('input[name="executive_officer"]').val(); - // if(executive_officer == deputy_director){ - // alert(); - // } - // Send an AJAX request to the form submission route + e.preventDefault(); // Mencegah submit form secara default + var formData = $("#formSigner").serialize(); // Mengambil data dari form dan mengubahnya menjadi string query + $.ajax({ - type: 'POST', - url: "{{ route('konfirmasibank.postSigner') }}", - data: formData, - dataType: 'json', - success: function(data) { - $("#signerModal").modal('hide'); - // var _data = JSON.parse(data); - toastr.success(data.message); - location.reload(); - - }, - error: function(xhr, status, error) { - // Handle error response (if applicable) - var errors = data.responseJSON.errors; - $.each(errors, function(key, value) { - toastr.error(value); - }); - } + type: 'POST', // Metode HTTP yang digunakan untuk request + url: "{{ route('konfirmasibank.postSigner') }}", // URL tujuan request + data: formData, // Data yang dikirimkan + dataType: 'json', // Tipe data yang diharapkan dari server + success: function(data) { + $("#signerModal").modal('hide'); // Menutup modal setelah data berhasil dikirim + toastr.success(data.message); // Menampilkan pesan sukses + location.reload(); // Memuat ulang halaman + }, + error: function(xhr, status, error) { + // Menangani respons error + var errors = xhr.responseJSON.errors; + $.each(errors, function(key, value) { + toastr.error(value); // Menampilkan pesan error + }); + } }); - }); $(".btnEditSigner").click(function(e) { @@ -310,26 +252,26 @@ $("#submitFormUpdateSigner").click(function(e) { - // Serialize the form data - e.preventDefault(); - var formData = $("#formUpdateSigner").serialize(); - $.ajax({ - type: "POST", - url: "{{ route('konfirmasibank.updateSigner') }}", - data: formData, // serializes the form's elements. - success: function(data) { - $("#myModalEditSigner").modal('hide'); - var _data = JSON.parse(data); - toastr.success(_data.message); - location.reload(); + e.preventDefault(); // Mencegah pengiriman formulir secara default - }, - error: function(data, textStatus, errorThrown) { - var errors = data.responseJSON.errors; - $.each(errors, function(key, value) { - toastr.error(value); - }); - } + var formData = $("#formUpdateSigner").serialize(); // Mengambil data dari formulir dan mengubahnya menjadi string query + + $.ajax({ + type: "POST", + url: "{{ route('konfirmasibank.updateSigner') }}", // URL tujuan request, sesuaikan dengan route yang benar + data: formData, // Data yang dikirimkan + success: function(response) { + $("#myModalEditSigner").modal('hide'); // Menutup modal setelah data berhasil dikirim + toastr.success(response.message); // Menampilkan pesan sukses + location.reload(); // Memuat ulang halaman + }, + error: function(xhr, status, error) { + // Menangani respons error + var errors = xhr.responseJSON.errors; + $.each(errors, function(key, value) { + toastr.error(value); // Menampilkan pesan error + }); + } }); });