bug fix 4 in clients show view

This commit is contained in:
Kwesi Banson Jnr
2026-08-27 16:40:58 +00:00
parent fd02359a34
commit bc2b952341
3 changed files with 407 additions and 2 deletions

View File

@@ -35,7 +35,7 @@ class ClientsController extends Controller
}
public function show(int $id)
public function showOld(int $id)
{
$showclient = Models\Client::with([
'service_info',
@@ -170,6 +170,144 @@ class ClientsController extends Controller
]);
}
public function show(int $id)
{
$showclient = Models\Client::with([
'service_info',
'country_flag_info',
'auth_user_info',
'short_code_info',
])->findOrFail($id);
// Sanitize communication fields to prevent count() type errors on production
$showclient->finance_email = is_array($showclient->finance_email) ? $showclient->finance_email : (json_decode($showclient->finance_email, true) ?? []);
$showclient->support_emails = is_array($showclient->support_emails) ? $showclient->support_emails : (json_decode($showclient->support_emails, true) ?? []);
$showclient->rate_emails = is_array($showclient->rate_emails) ? $showclient->rate_emails : (json_decode($showclient->rate_emails, true) ?? []);
$showclient->support_phones = is_array($showclient->support_phones) ? $showclient->support_phones : (json_decode($showclient->support_phones, true) ?? []);
$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');
$change_account_mgr_permission = $this->hasAnyAccess([$change_account_mgr_permission]) ? 'YES' : 'NO';
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 --'],
]);
}
private function getRenewalDue(?string $contractValidity): array
{
if (blank($contractValidity)) {