'boolean', 'updated_at' => 'timestamp', 'created_at' => 'timestamp', 'deleted_at' => 'timestamp', ]; protected $appends = [ 'hashed_id', ]; protected $with = [ 'backup', ]; /** * @return mixed */ public function getHashedIdAttribute() { return $this->encodePrimaryKey($this->id); } /** * @return mixed */ public function getEntityType() { return self::class; } /** * @return mixed */ public function backup() { return $this->hasOne(Backup::class); } /** * @return mixed */ public function history() { return $this->hasOne(Backup::class); } /** * @return mixed */ public function user() { return $this->belongsTo(User::class)->withTrashed(); } /** * @return mixed */ public function contact() { return $this->belongsTo(ClientContact::class, 'client_contact_id', 'id')->withTrashed(); } /** * @return mixed */ public function client() { return $this->belongsTo(Client::class)->withTrashed(); } /** * @return mixed */ public function invoice() { return $this->belongsTo(Invoice::class)->withTrashed(); } /** * @return mixed */ public function vendor() { return $this->belongsTo(Vendor::class)->withTrashed(); } /** * @return mixed */ public function recurring_invoice() { return $this->belongsTo(RecurringInvoice::class)->withTrashed(); } /** * @return mixed */ public function credit() { return $this->belongsTo(Credit::class)->withTrashed(); } /** * @return mixed */ public function quote() { return $this->belongsTo(Quote::class)->withTrashed(); } /** * @return mixed */ public function subscription() { return $this->belongsTo(Subscription::class)->withTrashed(); } /** * @return mixed */ public function payment() { return $this->belongsTo(Payment::class)->withTrashed(); } /** * @return mixed */ public function expense() { return $this->belongsTo(Expense::class)->withTrashed(); } /** * @return mixed */ public function recurring_expense() { return $this->belongsTo(RecurringExpense::class)->withTrashed(); } /** * @return mixed */ public function purchase_order() { return $this->belongsTo(PurchaseOrder::class)->withTrashed(); } /** * @return mixed */ public function vendor_contact() { return $this->belongsTo(VendorContact::class)->withTrashed(); } /** * @return mixed */ public function task() { return $this->belongsTo(Task::class)->withTrashed(); } /** * @return mixed */ public function company() { 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; } }