From 0279cebbaf48af158eb53a0a0ad823031e0ca7cd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 24 Jun 2023 11:30:44 +1000 Subject: [PATCH] Working on activity logs --- app/Http/Controllers/ActivityController.php | 6 +- app/Models/Activity.php | 65 +++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 865c43376532..ccd990e57235 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -93,7 +93,11 @@ class ActivityController extends BaseController ->take($default_activities); if ($request->has('react')) { - if (!auth()->user()->isAdmin()) { + + /** @var \App\Models\User auth()->user() */ + $user = auth()->user(); + + if (!$user->isAdmin()) { $activities->where('user_id', auth()->user()->id); } diff --git a/app/Models/Activity.php b/app/Models/Activity.php index a5091f79bd8d..8c044f708b20 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -460,4 +460,69 @@ class Activity extends StaticModel { return $this->belongsTo(Company::class); } + + public function activity_string() + { + $intersect = [ + ':invoice', + ':client', + ':contact', + ':user', + ':vendor', + ':quote', + ':credit', + ':payment', + ':task', + ':expense', + ':purchase_order', + ':subscription', + ':recurring_invoice', + ':recurring_expense', + ':amount', + ':balance', + ':number', + ':payment_amount', + ':gateway', + ':adjustment', + ]; + + $found_variables = array_intersect(explode(" ",trans("texts.activity_{$this->activity_type_id}"))); + + $replacements = []; + + foreach($found_variables as $var){ + $replacements[] = $this->matchVar($var); + } + + return ctrans("texts.activity_{$this->activity_type_id}",$replacements); + } + + private function matchVar(string $variable) + { + return match($variable) { + ':invoice' => $translation = [substr($variable, -1) => $this?->invoice?->number ?? ''], + ':client' => $translation = [substr($variable, -1) => $this?->client?->present()->name() ?? ''], + ':contact' => $translation = [substr($variable, -1) => $this?->contact?->present()->name() ?? ''], + ':user' => $translation = [substr($variable, -1) => $this?->user?->present()->name() ??''], + ':vendor' => $translation = [substr($variable, -1) => $this?->vendor?->present()->name() ?? ''], + ':quote' => $translation = [substr($variable, -1) => $this?->quote?->number ?? ''], + ':credit' => $translation = [substr($variable, -1) => $this?->credit?->number ?? ''], + ':payment' => $translation = [substr($variable, -1) => $this?->payment?->number ?? ''], + ':task' => $translation = [substr($variable, -1) => $this?->task?->number ?? ''], + ':expense' => $translation = [substr($variable, -1) => $this?->expense?->number ?? ''], + ':purchase_order' => $translation = [substr($variable, -1) => $this?->purchase_order?->number ?? ''], + ':subscription' => $translation = [substr($variable, -1) => $this?->subscription?->number ?? ''], + ':recurring_invoice' => $translation = [substr($variable, -1) => $this?->purchase_order?->number ??''], + ':recurring_expense' => $translation = [substr($variable, -1) => $this?->recurring_expense?->number ??''], + ':amount' => $translation = [substr($variable, -1) => ''], + ':balance' => $translation = [substr($variable, -1) => ''], + ':number' => $translation = [substr($variable, -1) => ''], + ':payment_amount' => $translation = [substr($variable, -1) => ''], + ':adjustment' => $translation = [substr($variable, -1) => $this->payment->refunded ?? ''], + default => $translation = [substr($variable, -1) => ''], + }; + + return $translation; + } + }