From cab4591777863e69b081717958b2c679ac84cea0 Mon Sep 17 00:00:00 2001 From: Kwesi Banson Jnr Date: Sat, 8 Aug 2026 21:20:40 +0000 Subject: [PATCH] updated notes with services and updated sample texts on views --- app/Http/Controllers/ClientsController.php | 15 +++++++- app/Models/ClientNote.php | 15 ++++++++ public/assets/js/client-show-modal.js | 38 ++++++++++++++++++- .../shortcode-payment-docs-modal.blade.php | 34 ++++++++++------- resources/views/clients/show.blade.php | 10 +++++ .../views/network_operators/index.blade.php | 8 ++-- resources/views/senderids/index.blade.php | 6 +-- 7 files changed, 102 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/ClientsController.php b/app/Http/Controllers/ClientsController.php index b3fcc79..8ba6489 100644 --- a/app/Http/Controllers/ClientsController.php +++ b/app/Http/Controllers/ClientsController.php @@ -704,9 +704,20 @@ class ClientsController extends Controller } public function storeNote(Request $request) { - $request->validate(['note' => 'required|string', 'client_id' => 'required|exists:clients,id']); + $request->validate([ + 'note' => 'required|string', + 'client_id' => 'required|exists:clients,id', + 'services' => 'nullable|array', + ]); - \App\Models\ClientNote::create($request->all()); + \App\Models\ClientNote::create([ + 'client_id' => $request->client_id, + 'user_id' => auth()->id(), + 'notes_body' => $request->note, + 'services' => $request->services, + ]); + + return response()->json(['message' => 'Note added successfully!']); } diff --git a/app/Models/ClientNote.php b/app/Models/ClientNote.php index f232ea1..258a744 100644 --- a/app/Models/ClientNote.php +++ b/app/Models/ClientNote.php @@ -21,5 +21,20 @@ class ClientNote extends Model public function created_by_info(){ return $this->hasOne('App\Models\SystemUser', 'id', 'auth_user_id'); } + protected $casts = [ + 'services' => 'array', + ]; + public function getServiceNamesAttribute() + { + if (empty($this->services) || !is_array($this->services)) { + return collect(); + } + return \App\Models\Service::whereIn('id', $this->services)->pluck('name'); + } + + public function user() + { + return $this->belongsTo(App\Models\User::class); + } } diff --git a/public/assets/js/client-show-modal.js b/public/assets/js/client-show-modal.js index 03f8aae..c81c614 100644 --- a/public/assets/js/client-show-modal.js +++ b/public/assets/js/client-show-modal.js @@ -5,7 +5,7 @@ document.addEventListener("DOMContentLoaded", function() { } $(document).ready(function() { - console.log('Client modals AJAX script loaded with SweetAlert.'); + // Generic AJAX handler for standard forms (Shortcodes & Payments) $(document).on('submit', '#shortcodeForm, #paymentForm, #noteForm', function(e) { @@ -122,7 +122,7 @@ document.addEventListener("DOMContentLoaded", function() { // Only fetch if options haven't been loaded yet if ($select.children('option').length === 0) { $.ajax({ - url: base_url + '/api/services', // Update route if needed + url: base_url + '/api/services', type: 'GET', success: function(data) { $select.empty(); @@ -151,6 +151,40 @@ document.addEventListener("DOMContentLoaded", function() { } }); + // Initialize Select2 for Note Services when modal opens + $('#addNoteModal').on('shown.bs.modal', function () { + let $select = $('#noteServicesSelect'); + + if ($select.children('option').length === 0) { + $.ajax({ + url: base_url + '/api/services', + type: 'GET', + success: function(data) { + $select.empty(); + data.forEach(function(service) { + $select.append(new Option(service.name, service.id, false, false)); + }); + + $select.select2({ + theme: 'bootstrap-5', + dropdownParent: $('#addNoteModal'), + placeholder: 'Search and select services...' + }); + } + }); + } else { + $select.select2({ + theme: 'bootstrap-5', + dropdownParent: $('#addNoteModal'), + placeholder: 'Search and select services...' + }); + } + }); + + // Clear Select2 values when modal is closed + $('#addNoteModal').on('hidden.bs.modal', function () { + $('#noteServicesSelect').val(null).trigger('change'); + }); // Clear Select2 values when modal is closed $('#addPaymentModal').on('hidden.bs.modal', function () { $('#paymentServicesSelect').val(null).trigger('change'); diff --git a/resources/views/clients/partials/shortcode-payment-docs-modal.blade.php b/resources/views/clients/partials/shortcode-payment-docs-modal.blade.php index 6c89ac0..f74c44c 100644 --- a/resources/views/clients/partials/shortcode-payment-docs-modal.blade.php +++ b/resources/views/clients/partials/shortcode-payment-docs-modal.blade.php @@ -1,6 +1,6 @@ - - - + + +