diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index f3b7d63ef01e..b4d35e71e656 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -103,9 +103,8 @@ class ActivityController extends BaseController $system = ctrans('texts.system'); - $data = $activities->cursor()->map(function ($activity) use ($system) { + $data = $activities->cursor()->map(function ($activity) { - return $activity->activity_string(); $arr = [ 'client' => $activity->client ? $activity->client : '', @@ -126,21 +125,31 @@ class ActivityController extends BaseController ]; $activity_array = $activity->toArray(); - $activity_meta = []; - $activity_meta['hashed_id'] = $activity->hashed_id; - $activity_meta['notes'] = $activity->notes; - $activity_meta['ip'] = $activity->ip; - $activity_meta['activity_type_id'] = $activity->activity_type_id; - $activity_meta['created_at'] = $activity->created_at; - $activity_meta['updated_at'] = $activity->updated_at; - $activity_meta['is_system'] = $activity->is_system; - // $activity_meta['currency_id'] = $activity->currency_id; return array_merge($arr, $activity_array); }); return response()->json(['data' => $data->toArray()], 200); } + elseif($request->has('reactv2')) { + + /** @var \App\Models\User auth()->user() */ + $user = auth()->user(); + + if (!$user->isAdmin()) { + $activities->where('user_id', auth()->user()->id); + } + + $system = ctrans('texts.system'); + + $data = $activities->cursor()->map(function ($activity) use ($system) { + + return $activity->activity_string(); + + }); + + return response()->json(['data' => $data->toArray()], 200); + } return $this->listResponse($activities); } diff --git a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php index 9c0285d6db92..9d05e1c2d70c 100644 --- a/app/Listeners/Invoice/InvoiceEmailFailedActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailFailedActivity.php @@ -58,7 +58,6 @@ class InvoiceEmailFailedActivity implements ShouldQueue $fields->client_contact_id = $event->invitation->client_contact_id; $fields->company_id = $event->invitation->invoice->company_id; $fields->activity_type_id = Activity::EMAIL_INVOICE_FAILED; - $fields->notes = $event->message; $this->activity_repo->save($fields, $event->invitation->invoice, $event->event_vars); } diff --git a/app/Listeners/User/ArchivedUserActivity.php b/app/Listeners/User/ArchivedUserActivity.php index 0a9509e5d32f..3e4a7bf37213 100644 --- a/app/Listeners/User/ArchivedUserActivity.php +++ b/app/Listeners/User/ArchivedUserActivity.php @@ -46,7 +46,6 @@ class ArchivedUserActivity implements ShouldQueue $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->creating_user->id; $fields->user_id = $user_id; - $fields->notes = $event->creating_user->present()->name.' Archived User '.$event->user->present()->name(); $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::ARCHIVE_USER; diff --git a/app/Listeners/User/CreatedUserActivity.php b/app/Listeners/User/CreatedUserActivity.php index d88c8c69a745..892ded9761a6 100644 --- a/app/Listeners/User/CreatedUserActivity.php +++ b/app/Listeners/User/CreatedUserActivity.php @@ -46,7 +46,6 @@ class CreatedUserActivity implements ShouldQueue $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->creating_user->id; $fields->user_id = $user_id; - $fields->notes = $event->creating_user->present()->name().' Created the user '.$event->user->present()->name(); $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::CREATE_USER; diff --git a/app/Listeners/User/DeletedUserActivity.php b/app/Listeners/User/DeletedUserActivity.php index 9ebab1b2180d..85a19f48ac54 100644 --- a/app/Listeners/User/DeletedUserActivity.php +++ b/app/Listeners/User/DeletedUserActivity.php @@ -51,8 +51,6 @@ class DeletedUserActivity implements ShouldQueue $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->creating_user->id; $fields->user_id = $user_id; - - $fields->notes = $event->creating_user->present()->name().' Deleted the user '.$event->user->present()->name(); $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::DELETE_USER; diff --git a/app/Listeners/User/RestoredUserActivity.php b/app/Listeners/User/RestoredUserActivity.php index 85b9867e62ac..272cdaf59648 100644 --- a/app/Listeners/User/RestoredUserActivity.php +++ b/app/Listeners/User/RestoredUserActivity.php @@ -45,7 +45,6 @@ class RestoredUserActivity implements ShouldQueue $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->creating_user->id; $fields->user_id = $user_id; - $fields->notes = $event->creating_user->present()->name().' Restored user '.$event->user->present()->name(); $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::RESTORE_USER; diff --git a/app/Listeners/User/UpdatedUserActivity.php b/app/Listeners/User/UpdatedUserActivity.php index f03df374467d..07770f4ac760 100644 --- a/app/Listeners/User/UpdatedUserActivity.php +++ b/app/Listeners/User/UpdatedUserActivity.php @@ -45,7 +45,6 @@ class UpdatedUserActivity implements ShouldQueue $user_id = array_key_exists('user_id', $event->event_vars) ? $event->event_vars['user_id'] : $event->creating_user->id; $fields->user_id = $user_id; - $fields->notes = $event->creating_user->present()->name().' Updated user '.$event->user->present()->name(); $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::UPDATE_USER; diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 14c4a3365682..679373fa0363 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -484,40 +484,41 @@ class Activity extends StaticModel ':number', ':payment_amount', ':gateway', - ':adjustment', - ':ip', + ':adjustment' ]; $found_variables = array_intersect(explode(" ",trans("texts.activity_{$this->activity_type_id}")), $intersect); $replacements = []; - foreach($found_variables as $var){ - $replacements[] = $this->matchVar($var); - } + foreach($found_variables as $var) + $replacements = array_merge($replacements, $this->matchVar($var)); - foreach(['id', 'hashed_id','notes','created_at','activity_type_id'] as $var) - $replacements[] = $this->matchVar($var); - - // return ctrans("texts.activity_{$this->activity_type_id}",$replacements); + if($this->client) + $replacements['client'] = ['label' => $this?->client?->present()->name() ?? '', 'hashed_id' => $this->client->hashed_id ?? '']; + if($this->vendor) + $replacements['vendor'] = ['label' => $this?->vendor?->present()->name() ?? '', 'hashed_id' => $this->vendor->hashed_id ?? '']; + + $replacements['activity_type_id'] = $this->activity_type_id; + $replacements['id'] = $this->id; + $replacements['hashed_id'] = $this->hashed_id; + $replacements['notes'] = $this->notes ?? ''; + $replacements['created_at'] = $this->created_at ?? ''; + $replacements['ip'] = $this->ip ?? ''; + return $replacements; } private function matchVar(string $variable) { + $system = ctrans('texts.system'); + return match($variable) { - 'activity_type_id' => $translation = ['activity_type_id' => $this->activity_type_id], - 'id' => $translation = ['id' => $this->id], - 'hashed_id' => $translation = ['hashed_id' => $this->hashed_id], - 'notes' => $translation = ['notes' => $this->notes ?? ''], - 'created_at' => $translation = ['created_at' => $this->created_at ?? ''], ':invoice' => $translation = [substr($variable, 1) => [ 'label' => $this?->invoice?->number ?? '', 'hashed_id' => $this->invoice?->hashed_id ?? '']], - ':client' => $translation = [substr($variable, 1) => [ 'label' => $this?->client?->present()->name() ?? '', 'hashed_id' => $this->client->hashed_id ?? '']], - ':contact' => $translation = [substr($variable, 1) => [ 'label' => $this?->contact?->present()->name() ?? '', 'hashed_id' => $this->contact->client->hashed_id ?? '']], - ':user' => $translation = [substr($variable, 1) => [ 'label' => $this?->user?->present()->name() ??'', 'hashed_id' => $this->user->hashed_id ?? '']], - ':vendor' => $translation = [substr($variable, 1) => [ 'label' => $this?->vendor?->present()->name() ?? '', 'hashed_id' => $this->vendor->hashed_id ?? '']], + ':contact' => $translation = $this->resolveContact(), + ':user' => $translation = [substr($variable, 1) => [ 'label' => $this?->user?->present()->name() ?? $system, 'hashed_id' => $this->user->hashed_id ?? '']], ':quote' => $translation = [substr($variable, 1) => [ 'label' => $this?->quote?->number ?? '', 'hashed_id' => $this->quote->hashed_id ?? '']], ':credit' => $translation = [substr($variable, 1) => [ 'label' => $this?->credit?->number ?? '', 'hashed_id' => $this->credit->hashed_id ?? '']], ':payment' => $translation = [substr($variable, 1) => [ 'label' => $this?->payment?->number ?? '', 'hashed_id' => $this->payment->hashed_id ?? '']], @@ -527,17 +528,23 @@ class Activity extends StaticModel ':subscription' => $translation = [substr($variable, 1) => [ 'label' => $this?->subscription?->number ?? '', 'hashed_id' => $this->subscription->hashed_id ?? '' ]], ':recurring_invoice' => $translation = [substr($variable, 1) =>[ 'label' => $this?->recurring_invoice?->number ??'', 'hashed_id' => $this->recurring_invoice->hashed_id ?? '']], ':recurring_expense' => $translation = [substr($variable, 1) => [ 'label' => $this?->recurring_expense?->number ??'', 'hashed_id' => $this->recurring_expense->hashed_id ?? '']], - ':payment_amount' => $translation = [substr($variable, 1) =>[ 'label' => Number::formatMoney($this?->payment?->amount, $this?->payment?->client) ?? '']], - ':adjustment' => $translation = [substr($variable, 1) =>[ 'label' => Number::formatMoney($this?->payment?->refunded, $this?->payment?->client) ?? '']], + ':payment_amount' => $translation = [substr($variable, 1) =>[ 'label' => Number::formatMoney($this?->payment?->amount, $this?->payment?->client) ?? '', 'hashed_id' => '']], + ':adjustment' => $translation = [substr($variable, 1) =>[ 'label' => Number::formatMoney($this?->payment?->refunded, $this?->payment?->client) ?? '', 'hashed_id' => '']], ':ip' => $translation = [ 'ip' => $this->ip ?? ''], - default => $translation = [substr($variable, 1) => ''], + default => $translation = [], }; return $translation; } - private function returnEntityValue(string $variable) + private function resolveContact() : array { + $contact = $this->contact ? $this->contact : $this->vendor_contact; + $entity = $this->contact ? $this->client : $this->vendor; + + $contact_entity = $this->contact ? 'clients' : 'vendors'; + + return ['contact' => [ 'label' => $contact?->present()->name() ?? '', 'hashed_id' => $entity->hashed_id ?? '', 'contact_entity' => $contact_entity]]; } }