created_at)->translatedFormat('d F Y'); }); } public function formatCreatedAt(): Attribute { return Attribute::make(get: function () { return Carbon::parse($this->created_at)->translatedFormat('d F Y H:i:s'); }); } public function amount(): Attribute { return Attribute::make(get: function () { if ($this->credit == 0) { return number_format($this->debit, is_float($this->debit) ? 2 : 0, ',', '.'); } return number_format($this->credit, is_float($this->credit) ? 2 : 0, ',', '.'); }); } public function customer() { return $this->belongsTo(Customer::class); } public function update_customer_balance($updateExpired = false) { $customer = Customer::find($this->customer_id); $maxExpired = Setting::getByKey('MAX_POINT_EXPIRED'); if ($customer->poin_expired_at == null || $updateExpired) { $customer->poin_expired_at = now()->addDays($maxExpired); } $customer->update([ 'poin_balance' => $customer->poin_balance + $this->debit - $this->credit, 'poin_expired_at' => $customer->poin_expired_at, ]); } }