'integer', 'subtotal' => 'integer', 'discount' => 'integer', 'payment' => 'integer', 'total' => 'integer', 'payment_method' => PaymentMethod::class, 'order_status' => OrderStatus::class, 'order_channel' => OrderChannel::class, ]; } protected function hppFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->cogs, 0, ',', '.'), ); } protected function subtotalFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->subtotal, 0, ',', '.'), ); } protected function discountFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->discount, 0, ',', '.'), ); } protected function paymentFormatted(): Attribute { return Attribute::make( get: fn () => 'Rp '.number_format($this->payment, 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 items(): HasMany { return $this->hasMany(OrderItem::class); } public function getActivitylogOptions(): LogOptions { return LogOptions::defaults() ->logOnly(['order_number', 'customer_name', 'cogs', 'subtotal', 'discount', 'payment', 'total', 'payment_method', 'order_status', 'order_channel']) ->logOnlyDirty() ->useLogName('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 = [ 'order_number' => 'Nomor Order', 'customer_name' => 'Nama Pelanggan', 'cogs' => 'Modal', 'subtotal' => 'Subtotal', 'discount' => 'Diskon', 'payment' => 'Bayar', 'total' => 'Total', 'payment_method' => 'Metode Pembayaran', 'order_status' => 'Status Pesanan', 'order_channel' => 'Saluran Pesanan', ]; $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); } } }