'integer', 'qty' => 'integer', 'total' => 'integer', 'price_type' => PriceType::class, ]; } protected function priceFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->price, 0, ',', '.'), ); } protected function totalFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->total, 0, ',', '.'), ); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function order(): BelongsTo { return $this->belongsTo(Order::class); } public function product(): BelongsTo { return $this->belongsTo(Product::class); } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logOnly(['price', 'qty', 'total', 'price_type']) ->logOnlyDirty() ->useLogName('Item Pesanan'); } public function tapActivity(Activity $activity, string $eventName) { $activity->description = match ($eventName) { 'created' => 'TAMBAH', 'updated' => 'UBAH', 'deleted' => 'HAPUS', default => $activity->description, }; if (isset($activity->properties['attributes'])) { $attributeMap = [ 'price' => 'Harga', 'qty' => 'Jumlah', 'total' => 'Total', 'price_type' => 'Jenis Harga', ]; $properties = $activity->properties->toArray(); $localizeValues = function ($attrs) use ($attributeMap) { $newAttrs = []; foreach ($attrs as $key => $value) { $label = $attributeMap[$key] ?? $key; $newAttrs[$label] = $value; } return $newAttrs; }; $properties['attributes'] = $localizeValues($properties['attributes']); if (isset($properties['old'])) { $properties['old'] = $localizeValues($properties['old']); } $activity->properties = collect($properties); } } }