update validasi signer
This commit is contained in:
@ -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,45 +228,65 @@
|
||||
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
|
||||
// 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.
|
||||
*
|
||||
@ -290,41 +311,59 @@
|
||||
{
|
||||
|
||||
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();
|
||||
|
||||
$validator = Validator::make($request->all(), [
|
||||
'deputy_director' => 'required|string',
|
||||
'executive_officer' => 'required|string',
|
||||
'signer_type' => 'required|string'
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json(['errors' => $validator->errors()], 422); // Return validation errors as JSON
|
||||
}
|
||||
|
||||
|
||||
if ($validator) {
|
||||
try {
|
||||
$signer = Signer::findOrFail($request->id);
|
||||
|
||||
$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.',
|
||||
];
|
||||
|
||||
$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 = $today;
|
||||
$signer->updated_at = Carbon::now();
|
||||
$signer->save();
|
||||
|
||||
echo json_encode(['status' => 'success', 'message' => ' signer updated successfully.']);
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => 'Penandatangan berhasil diperbarui.']);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['status' => 'error', 'message' => ' signer updated failed.']);
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
|
||||
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 = "";
|
||||
|
@ -62,7 +62,7 @@
|
||||
<div class="form-group row">
|
||||
<label for="inputName" class="col-sm-4 col-form-label">Executive Officer</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control form-control-sm " id="executive_officer" name="executive_officer" placeholder="Nama Executive Officer" id="executive_officer" >
|
||||
<input type="text" class="form-control form-control-sm " name="executive_officer" placeholder="Nama Executive Officer" id="executive_officer" >
|
||||
<span class="note" style="color:darkred;display:none" ><small>Nama Tidak Boleh Sama .. !</small></span>
|
||||
<span class="noteEx" style="color:darkred;display:none" ><small>Nama Hanya Boleh Huruf.. !</small></span>
|
||||
</div>
|
||||
@ -77,7 +77,7 @@
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary btn-sm closeButtonSigner"
|
||||
data-dismiss="modal">Close</button>
|
||||
<button type="button" class="btn btn-primary btn-sm" id="submitSigner">Submit</button>
|
||||
<button type="button" class="btn btn-primary btn-sm submitSigner" id="submitSigner">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@ -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
|
||||
// $('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
|
||||
// // }
|
||||
// if (executive_officer == deputy_eirector ) {
|
||||
// // alert('Penandatangan Tidak Boleh Sama');
|
||||
// } 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');
|
||||
// $('#submitSigner').attr('disabled', 'disabled');
|
||||
// $('#note').show();
|
||||
// $('.noteEx').show();
|
||||
// // alert('Input hanya boleh berisi huruf.');
|
||||
// } else {
|
||||
// $('#executive_officer').css('border-color', '');
|
||||
// $('#submitSigner').attr('disabled', false);
|
||||
// $('#note').hide();
|
||||
// $(this).css('border-color', ''); // Kembalikan warna border
|
||||
// $('#submitSigner, #submitFormUpdateSigner').prop('disabled', false); // Aktifkan tombol submit
|
||||
// $('.noteEx').hide();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// });
|
||||
|
||||
// $('#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();
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
$('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
|
||||
$.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();
|
||||
e.preventDefault(); // Mencegah submit form secara default
|
||||
var formData = $("#formSigner").serialize(); // Mengambil data dari form dan mengubahnya menjadi string query
|
||||
|
||||
$.ajax({
|
||||
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) {
|
||||
// Handle error response (if applicable)
|
||||
var errors = data.responseJSON.errors;
|
||||
// Menangani respons error
|
||||
var errors = xhr.responseJSON.errors;
|
||||
$.each(errors, function(key, value) {
|
||||
toastr.error(value);
|
||||
toastr.error(value); // Menampilkan pesan error
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$(".btnEditSigner").click(function(e) {
|
||||
@ -310,24 +252,24 @@
|
||||
|
||||
|
||||
$("#submitFormUpdateSigner").click(function(e) {
|
||||
// Serialize the form data
|
||||
e.preventDefault();
|
||||
var formData = $("#formUpdateSigner").serialize();
|
||||
e.preventDefault(); // Mencegah pengiriman formulir secara default
|
||||
|
||||
var formData = $("#formUpdateSigner").serialize(); // Mengambil data dari formulir dan mengubahnya menjadi string query
|
||||
|
||||
$.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();
|
||||
|
||||
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(data, textStatus, errorThrown) {
|
||||
var errors = data.responseJSON.errors;
|
||||
error: function(xhr, status, error) {
|
||||
// Menangani respons error
|
||||
var errors = xhr.responseJSON.errors;
|
||||
$.each(errors, function(key, value) {
|
||||
toastr.error(value);
|
||||
toastr.error(value); // Menampilkan pesan error
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user