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

@@ -22,154 +22,21 @@ class ClientsController extends Controller
public function index(){ public function index(){
$countries = Models\Country::pluck('en_short_name', 'en_short_name'); $countries = Models\Country::pluck('en_short_name', 'en_short_name');
$service_type = Models\Service::pluck('name', 'name'); $service_type = Models\Service::pluck('name', 'name');
$staff_members = Models\StaffMember::pluck('name', 'id'); $staff_members = Models\StaffMember::pluck('name', 'id'); //where('department_id', '1')->
$currencies = Models\Currency::get();
// dd($staff_members); // dd($staff_members);
$data = [ $data = [
'page_title' => 'Dashboard', 'page_title' => 'Dashboard',
'service_types' => $service_type, 'service_types' => $service_type,
'countries' => $countries, 'countries' => $countries,
'staff_members' => $staff_members 'staff_members' => $staff_members,
'currencies' => $currencies
]; ];
return view('clients.index', $data); return view('clients.index', $data);
} }
public function showOld(int $id)
{
$showclient = Models\Client::with([
'service_info',
'country_flag_info',
'auth_user_info',
'short_code_info',
])->findOrFail($id);
$progress_indicators = Models\ClientIndicator::pluck('name', 'name');
$service_type = Models\Service::pluck('name', 'id');
$service_type_names = Models\Service::pluck('name', 'name');
$show_services = Models\ClientCategory::where('client_id', $id)->get();
$country_networks = DB::table('network_operators')
->selectRaw('id, CONCAT(name, " (", country, ")") AS network')
->orderBy('network')
->pluck('network', 'network');
$auth_users = Models\SystemUser::orderBy('name')->pluck('name', 'id');
$networks_raw = [
'AirtelTigo GH',
'MTN GH',
'Airtel MW',
'Airtel Zambia',
'TNM MW',
'Safaricom Kenya',
'Airtel Kenya',
'Telkom Kenya',
'Orange Kenya',
];
$show_notes_query = Models\ClientNote::with(['created_by_info', 'client_info'])
->where('client_id', $id)
->latest();
$show_notes = $show_notes_query->take(20)->get();
$show_notes_highlight = (clone $show_notes_query)
->where('highlight', 'YES')
->take(1)
->get();
$voice_codes = Models\ClientShortCode::where('client_id', $id)
->where('code_type', 'voice')
->get();
$sms_codes = Models\ClientShortCode::where('client_id', $id)
->where('code_type', 'sms')
->get();
$ussd_codes = Models\ClientShortCode::where('client_id', $id)
->where('code_type', 'ussd')
->get();
$recent_payments = Models\ClientPayment::where('client_id', $id)
->latest('id')
->get();
$countries = Models\Country::pluck('en_short_name', 'en_short_name');
$networks = Models\NetworkOperator::pluck('name', 'id');
$support_fees = Models\ClientSupportFees::where('client_id', $id)
->latest('id')
->get();
$showdocuments = Models\ClientFile::where('client_id', $id)->get();
$status_bg = match ($showclient->status) {
'Live' => 'info',
'Prospective' => 'warning',
default => 'danger',
};
$progress_status_bg = match (true) {
$showclient->progress_indicator_score >= 70 => 'success',
$showclient->progress_indicator_score >= 50 => 'warning',
default => 'danger',
};
[$renewal_due, $highlight_colour] = $this->getRenewalDue(
$showclient->contract_validity
);
$recurring_arr = [
'NO' => 'NO',
'Monthly' => 'Monthly',
'Quarterly' => 'Quarterly',
'Semiannual' => 'Semiannual',
'Yearly' => 'Yearly',
];
$sender_id_statuses = [
'Pending' => 'Pending',
'Inactive' => 'Inactive',
'Approved' => 'Approved',
];
$change_account_mgr_permission = Config::get('permissions.CHANGE_ACCOUNT_MANAGERS');
// dump($change_account_mgr_permission);
$change_account_mgr_permission = $this->hasAnyAccess([$change_account_mgr_permission]) ? 'YES' : 'NO';
// dd($change_account_mgr_permission);
// dd($showclient);
return view('clients.show', [
'page_title' => 'Client Profile',
'showclient' => $showclient,
'show_services' => $show_services,
'service_type' => $service_type,
'service_type_names' => $service_type_names,
'show_notes' => $show_notes,
'show_notes_highlight' => $show_notes_highlight,
'status_bg' => $status_bg,
'progress_status_bg' => $progress_status_bg,
'voice_codes' => $voice_codes,
'sms_codes' => $sms_codes,
'ussd_codes' => $ussd_codes,
'countries' => $countries,
'networks' => $networks,
'progress_indicators' => $progress_indicators,
'networks_raw' => array_combine($networks_raw, $networks_raw),
'renewal_due' => $renewal_due,
'recent_payments' => $recent_payments,
'highlight_colour' => $highlight_colour,
'showdocuments' => $showdocuments,
'support_fees' => $support_fees,
'recurring_arr' => $recurring_arr,
'sender_id_statuses' => $sender_id_statuses,
'change_account_mgr_permisson' => $change_account_mgr_permission,
'am_list_arr' => $auth_users,
'country_network_arr' => $country_networks,
'mnos_arr' => ['' => '-- Select Country first --'],
]);
}
public function show(int $id) public function show(int $id)
{ {
$showclient = Models\Client::with([ $showclient = Models\Client::with([
@@ -189,6 +56,10 @@ class ClientsController extends Controller
$service_type = Models\Service::pluck('name', 'id'); $service_type = Models\Service::pluck('name', 'id');
$service_type_names = Models\Service::pluck('name', 'name'); $service_type_names = Models\Service::pluck('name', 'name');
$show_services = Models\ClientCategory::where('client_id', $id)->get(); $show_services = Models\ClientCategory::where('client_id', $id)->get();
$currencies = Models\Currency::get();
$staff_members = Models\StaffMember::pluck('name', 'id'); //where('department_id', '1')->
$country_networks = DB::table('network_operators') $country_networks = DB::table('network_operators')
->selectRaw('id, CONCAT(name, " (", country, ")") AS network') ->selectRaw('id, CONCAT(name, " (", country, ")") AS network')
@@ -279,7 +150,7 @@ class ClientsController extends Controller
$change_account_mgr_permission = Config::get('permissions.CHANGE_ACCOUNT_MANAGERS'); $change_account_mgr_permission = Config::get('permissions.CHANGE_ACCOUNT_MANAGERS');
$change_account_mgr_permission = $this->hasAnyAccess([$change_account_mgr_permission]) ? 'YES' : 'NO'; $change_account_mgr_permission = $this->hasAnyAccess([$change_account_mgr_permission]) ? 'YES' : 'NO';
// dd($showclient);
return view('clients.show', [ return view('clients.show', [
'page_title' => 'Client Profile', 'page_title' => 'Client Profile',
'showclient' => $showclient, 'showclient' => $showclient,
@@ -295,6 +166,8 @@ class ClientsController extends Controller
'ussd_codes' => $ussd_codes, 'ussd_codes' => $ussd_codes,
'countries' => $countries, 'countries' => $countries,
'networks' => $networks, 'networks' => $networks,
'currencies' => $currencies,
'staff_members' => $staff_members,
'progress_indicators' => $progress_indicators, 'progress_indicators' => $progress_indicators,
'networks_raw' => array_combine($networks_raw, $networks_raw), 'networks_raw' => array_combine($networks_raw, $networks_raw),
'renewal_due' => $renewal_due, 'renewal_due' => $renewal_due,
@@ -551,7 +424,7 @@ class ClientsController extends Controller
'status' => $request->status, 'status' => $request->status,
'pay_mode' => $request->payment_mode, 'pay_mode' => $request->payment_mode,
'currency' => $request->currency, 'currency' => $request->currency,
'auth_user_id' => $request->auth_user_id, 'auth_user_id' => $request->account_manager,
'created_by' => Auth::user()->id, 'created_by' => Auth::user()->id,
'last_modified_by' => Auth::user()->id, 'last_modified_by' => Auth::user()->id,
'progress_indicator_score' => 10, 'progress_indicator_score' => 10,
@@ -617,7 +490,6 @@ class ClientsController extends Controller
public function update(Request $request, $id) public function update(Request $request, $id)
{ {
$client = \App\Models\Client::findOrFail($id); $client = \App\Models\Client::findOrFail($id);
$client->update([ $client->update([
'name' => $request->name, 'name' => $request->name,
'email' => $request->email, 'email' => $request->email,
@@ -629,7 +501,7 @@ class ClientsController extends Controller
'status' => $request->status, 'status' => $request->status,
'currency' => $request->currency, 'currency' => $request->currency,
'country' => $request->country, 'country' => $request->country,
// Arrays handled by model casts 'auth_user_id' => $request->account_manager,
'services' => $request->services, 'services' => $request->services,
'message_types' => $request->message_types, 'message_types' => $request->message_types,
'connections' => $request->connections, 'connections' => $request->connections,
@@ -773,8 +645,6 @@ class ClientsController extends Controller
dispatch(new SendShortCodeListToFinance($short_code_list, $message_body, $finance_arr)); dispatch(new SendShortCodeListToFinance($short_code_list, $message_body, $finance_arr));
} }
#$payments = Models\ClientPayment::with('client_info', 'created_by_info')->find($result->id);
if ($result) { if ($result) {
$data = ['code' => 1, 'msg' => 'Payment Details successfully added']; $data = ['code' => 1, 'msg' => 'Payment Details successfully added'];
} }
@@ -809,6 +679,9 @@ class ClientsController extends Controller
$payment->short_code = ($request->short_code) ? $request->short_code : ""; $payment->short_code = ($request->short_code) ? $request->short_code : "";
$payment->services = implode(',', $request->services); $payment->services = implode(',', $request->services);
if ($request->has('remarks')) {
$payment->remarks = $request->remarks;
}
$result = $payment->save(); $result = $payment->save();
$client = Models\Client::find($request->client_id); $client = Models\Client::find($request->client_id);
if ($request->has('short_code')) { if ($request->has('short_code')) {
@@ -1017,13 +890,17 @@ class ClientsController extends Controller
'invoice_amount' => 'required|numeric', 'invoice_amount' => 'required|numeric',
'invoice_date' => 'required|date', 'invoice_date' => 'required|date',
'invoice_status' => 'required|string', 'invoice_status' => 'required|string',
'remarks' => 'sometimes|string'
]); ]);
// Find the record and update it // Find the record and update it
$payment = Models\ClientPayment::findOrFail($id); // Adjust 'ClientPayment' to your actual model name // if ($request->has('remarks')) {
// $payment->remarks = $request->remarks;
// }
$payment = Models\ClientPayment::findOrFail($id);
$payment->update($validated); $payment->update($validated);
// Return the JSON response for SweetAlert
return response()->json([ return response()->json([
'success' => true, 'success' => true,
'message' => 'Payment record updated successfully!' 'message' => 'Payment record updated successfully!'

View File

@@ -6,6 +6,21 @@ $(document).ready(function() {
allowClear: true, allowClear: true,
dropdownParent: $('#createClientModal') 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; let searchTimer;
// Initialize the table on page load // Initialize the table on page load
@@ -80,6 +95,8 @@ $(document).ready(function() {
$('#edit_industry').val(client.industry); $('#edit_industry').val(client.industry);
$('#edit_status').val(client.status); $('#edit_status').val(client.status);
$('#edit_currency').val(client.currency); $('#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); // $('#edit_country').val(client.country);
loadCountries(client.country); loadCountries(client.country);
// Helper for multi-select Select2 fields // 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 () { $('#createClientModal').on('hidden.bs.modal', function () {
$('#createClientForm')[0].reset(); $('#createClientForm')[0].reset();
$('#clientService').val(null).trigger('change'); $('#clientService').val(null).trigger('change');

View File

@@ -175,6 +175,5 @@
@push('scripts') @push('scripts')
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script src="{{ asset('public/assets/js/client-index.js') }}"></script> <script src="{{ asset('public/assets/js/client-index.js') }}"></script>
@endpush @endpush

View File

@@ -21,10 +21,6 @@
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
<label class="form-label text-secondary fw-semibold" style="font-size: 0.85rem;">Location / Country *</label> <label class="form-label text-secondary fw-semibold" style="font-size: 0.85rem;">Location / Country *</label>
<!-- Changed name from 'location' to 'country' -->
<!-- <input type="text" class="form-control" id="country" name="country" required placeholder="e.g. Ghana"> -->
<!-- <div class="col-md-4"> -->
<label class="form-label text-muted small fw-bold">Country</label>
<select name="country" id="create_country" class="form-select w-100"> <select name="country" id="create_country" class="form-select w-100">
<option value="">Select Country</option> <option value="">Select Country</option>
</select> </select>
@@ -108,10 +104,12 @@
<!-- Added Missing Required Fields for the Controller --> <!-- Added Missing Required Fields for the Controller -->
<div class="col-md-6 mt-3"> <div class="col-md-6 mt-3">
<label class="form-label text-secondary fw-semibold" style="font-size: 0.85rem;">Currency *</label> <label class="form-label text-secondary fw-semibold" style="font-size: 0.85rem;">Currency *</label>
<select class="form-select" id="clientCurrency" name="currency" required> <select class="form-select select2-currency" id="clientCurrency" name="currency" required style="width: 100%;">
<option value="" selected disabled>--Select--</option> <option value="" selected disabled>--Select--</option>
<option value="USD">USD</option> <!-- Assuming you pass $currencies from your controller -->
<option value="EUR">EUR</option> @foreach($currencies as $currency)
<option value="{{ $currency->currency_code }}">{{ $currency->currency_code }} ({{ $currency->name }})</option>
@endforeach
</select> </select>
</div> </div>
<div class="col-md-6 mt-3"> <div class="col-md-6 mt-3">

View File

@@ -75,15 +75,26 @@
<label class="form-label text-muted small fw-bold">Support MS Teams</label> <label class="form-label text-muted small fw-bold">Support MS Teams</label>
<select name="support_skype[]" id="edit_support_skype" class="form-select select2-tags" multiple="multiple"></select> <select name="support_skype[]" id="edit_support_skype" class="form-select select2-tags" multiple="multiple"></select>
</div> </div>
<!-- Status & Meta --> <!-- Status & Meta -->
<div class="col-md-4"> <div class="col-md-4">
<label class="form-label text-muted small fw-bold">Status</label> <!-- <label class="form-label text-muted small fw-bold">Status</label> -->
<input type="text" name="status" id="edit_status" class="form-control"> <!-- <input type="text" name="status" id="edit_status" class="form-control"> -->
<label class="form-label text-secondary fw-semibold" style="font-size: 0.85rem;">Account Status *</label>
<select class="form-select" id="edit_status" name="status" required>
<option value="" selected disabled>--Select--</option>
<option value="Live">Active / Live</option>
<option value="Prospective">Prospective</option>
<option value="Cancelled">Cancelled</option>
</select>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<label class="form-label text-muted small fw-bold">Currency</label> <label class="form-label text-muted small fw-bold">Currency</label>
<input type="text" name="currency" id="edit_currency" class="form-control"> <select name="currency" id="edit_currency" class="form-select select2-currency" style="width: 100%;">
<option value="">Select Currency</option>
@foreach($currencies as $currency)
<option value="{{ $currency->currency_code }}">{{ $currency->currency_code }} ({{ $currency->name }})</option>
@endforeach
</select>
</div> </div>
<div class="col-md-4"> <div class="col-md-4">
<label class="form-label text-muted small fw-bold">Country</label> <label class="form-label text-muted small fw-bold">Country</label>
@@ -91,6 +102,17 @@
<option value="">Select Country</option> <option value="">Select Country</option>
</select> </select>
</div> </div>
<!-- Add Account Manager Field here -->
<div class="col-md-6 mt-3">
<label class="form-label text-muted small fw-bold">Account Manager</label>
<select name="account_manager" id="edit_account_manager" class="form-select w-100">
<option value="">Select Manager</option>
@foreach($staff_members as $id => $name)
<option value="{{ $id }}">{{ $name }}</option>
@endforeach
</select>
</div>
</div> </div>
</div> </div>
<div class="modal-footer bg-light"> <div class="modal-footer bg-light">

View File

@@ -117,6 +117,10 @@
<option value="Cancelled">Cancelled</option> <option value="Cancelled">Cancelled</option>
</select> </select>
</div> </div>
<div class="mb-3">
<label for="editRemarks" class="form-label text-muted small fw-bold">Remarks</label>
<textarea name="remarks" class="form-control" value="" id="editRemarks"></textarea>
</div>
</div> </div>
</div> </div>
<div class="modal-footer bg-light"> <div class="modal-footer bg-light">

View File

@@ -114,6 +114,10 @@
<option value="partial">Partial</option> <option value="partial">Partial</option>
</select> </select>
</div> </div>
<div class="mb-3">
<label for="remarks" class="form-label text-muted small fw-bold">Remarks</label>
<textarea name="remarks" class="form-control" value="" id="remarks"></textarea>
</div>
</div> </div>
<div class="modal-footer bg-light"> <div class="modal-footer bg-light">
<button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Cancel</button> <button type="button" class="btn btn-secondary btn-sm" data-bs-dismiss="modal">Cancel</button>

View File

@@ -52,6 +52,7 @@
<!-- COLUMN 1 --> <!-- COLUMN 1 -->
<div class="col-lg-4 d-flex flex-column"> <div class="col-lg-4 d-flex flex-column">
<!-- Company Profile -->
<!-- Company Profile --> <!-- Company Profile -->
<div class="card border-light-subtle shadow-sm mb-4"> <div class="card border-light-subtle shadow-sm mb-4">
<div class="card-header bg-white py-3 border-bottom border-light"> <div class="card-header bg-white py-3 border-bottom border-light">
@@ -77,6 +78,14 @@
<span class="text-muted small">Date Added</span> <span class="text-muted small">Date Added</span>
<span class="fw-medium text-dark">{{ $showclient->created_at ? \Carbon\Carbon::parse($showclient->created_at)->format('d M Y') : 'N/A' }}</span> <span class="fw-medium text-dark">{{ $showclient->created_at ? \Carbon\Carbon::parse($showclient->created_at)->format('d M Y') : 'N/A' }}</span>
</li> </li>
<!-- Standardized Account Manager Row -->
<li class="list-group-item px-0 py-2 d-flex justify-content-between align-items-center border-0">
<span class="text-muted small">Account Manager</span>
<span class="fw-bold text-primary">
<i class="bi bi-person-badge me-1"></i>
{{ $showclient->account_manager->name ?? $showclient->accountManager->name ?? 'Unassigned' }}
</span>
</li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -505,6 +514,7 @@
<th>Invoice #</th> <th>Invoice #</th>
<th>Services</th> <th>Services</th>
<th>Amount</th> <th>Amount</th>
<th>Remarks</th>
<th>Date</th> <th>Date</th>
<th>Status</th> <th>Status</th>
<th class="text-end">Actions</th> <th class="text-end">Actions</th>
@@ -530,6 +540,7 @@
@endif @endif
</td> </td>
<td>{{ $payment->invoice_amount }}</td> <td>{{ $payment->invoice_amount }}</td>
<td>{{ $payment->remarks ?? 'N/A' }}</td>
<td class="text-muted small">{{ $payment->invoice_date ? \Carbon\Carbon::parse($payment->invoice_date)->format('d M Y') : 'N/A' }}</td> <td class="text-muted small">{{ $payment->invoice_date ? \Carbon\Carbon::parse($payment->invoice_date)->format('d M Y') : 'N/A' }}</td>
<td> <td>
<span class="badge bg-info bg-opacity-10 text-info text-uppercase">{{ $payment->invoice_status ?? 'Pending' }}</span> <span class="badge bg-info bg-opacity-10 text-info text-uppercase">{{ $payment->invoice_status ?? 'Pending' }}</span>

View File

@@ -63,7 +63,7 @@
<!-- <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> --> <!-- <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> -->
<script src="{{ asset('public/assets/libs/jquery-3.7.1.min.js') }}"></script> <script src="{{ asset('public/assets/libs/jquery-3.7.1.min.js') }}"></script>
<script src="{{ asset('public/assets/libs/bootstrap/js/bootstrap5.3.2.js') }}"></script> <script src="{{ asset('public/assets/libs/bootstrap/js/bootstrap5.3.2.js') }}"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> --> <!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> -->
<!-- SweetAlert2 CDN --> <!-- SweetAlert2 CDN -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>