added remarks for payments, expanded currency list

This commit is contained in:
Kwesi Banson Jnr
2026-09-14 11:57:34 +00:00
parent c96e49ccdf
commit 71bc103fee
9 changed files with 165 additions and 160 deletions

View File

@@ -6,6 +6,21 @@ $(document).ready(function() {
allowClear: true,
dropdownParent: $('#createClientModal')
});
// Initialize Currency for Create Modal
$('#clientCurrency').select2({
theme: 'bootstrap-5',
placeholder: "-- Select Currency --",
allowClear: true,
// Attach to the immediate column wrapper so it moves with the input
dropdownParent: $('#clientCurrency').parent()
});
$('#edit_currency').select2({
theme: 'bootstrap-5',
placeholder: "-- Select Currency --",
allowClear: true,
// Attach to the immediate column wrapper so it moves with the input
dropdownParent: $('#edit_currency').parent()
});
let searchTimer;
// Initialize the table on page load
@@ -80,6 +95,8 @@ $(document).ready(function() {
$('#edit_industry').val(client.industry);
$('#edit_status').val(client.status);
$('#edit_currency').val(client.currency);
$('#edit_currency').val(client.currency).trigger('change');
$('#edit_account_manager').val(client.auth_user_id).trigger('change');
// $('#edit_country').val(client.country);
loadCountries(client.country);
// Helper for multi-select Select2 fields
@@ -212,6 +229,79 @@ $(document).ready(function() {
});
});
// ---------------------------------------------------------
// AJAX FORM SUBMISSION (Edit Client)
// ---------------------------------------------------------
$('#editClientForm').on('submit', function(e) {
e.preventDefault();
let $form = $(this);
let $submitBtn = $form.find('button[type="submit"]');
let originalText = $submitBtn.html();
$submitBtn.html('<span class="spinner-border spinner-border-sm me-2"></span>Updating...').prop('disabled', true);
// Clear previous validation errors
$form.find('.is-invalid').removeClass('is-invalid');
$form.find('.invalid-feedback').remove();
$.ajax({
url: $form.attr('action'),
method: 'POST', // @method('PUT') is already included in the serialized data
data: $form.serialize(),
success: function(response) {
$('#editClientModal').modal('hide');
Swal.fire({
icon: 'success',
title: 'Updated!',
text: response.message || 'Client updated successfully!',
showConfirmButton: false,
timer: 1500
});
// Refresh the table data
fetchClients(1);
},
error: function(xhr) {
if (xhr.status === 401) {
window.location.href = base_url + '/login';
} else if (xhr.status === 422) {
let errors = xhr.responseJSON.errors;
$.each(errors, function(key, value) {
// Map validation keys to actual input names if they are arrays
let fieldName = key;
let arrayFields = ['services', 'message_types', 'connections', 'support_phones', 'support_emails', 'rate_emails', 'support_skype'];
if (arrayFields.includes(key)) {
fieldName = key + '[]';
}
let $input = $form.find('[name="' + fieldName + '"]');
if ($input.length) {
// If Select2, target the container for the red border
if ($input.hasClass('select2-hidden-accessible')) {
$input.next('.select2-container').addClass('is-invalid');
} else {
$input.addClass('is-invalid');
}
$input.parent().append('<div class="invalid-feedback d-block fw-medium">' + value[0] + '</div>');
}
});
} else {
Swal.fire({
icon: 'error',
title: 'Server Error',
text: 'An unexpected error occurred. Please try again.',
confirmButtonColor: '#5c4df0'
});
}
},
complete: function() {
$submitBtn.html(originalText).prop('disabled', false);
}
});
});
$('#createClientModal').on('hidden.bs.modal', function () {
$('#createClientForm')[0].reset();
$('#clientService').val(null).trigger('change');