'abo_history.action_initial', 'added' => 'abo_history.action_added', 'removed' => 'abo_history.action_removed', 'qty_changed' => 'abo_history.action_qty_changed', 'comp_product_changed' => 'abo_history.action_comp_changed', 'comp_added' => 'abo_history.action_comp_added', 'comp_removed' => 'abo_history.action_comp_removed', 'rollback' => 'abo_history.action_rollback', ]; public static $actionColors = [ 'initial' => 'info', 'added' => 'success', 'removed' => 'danger', 'qty_changed' => 'warning', 'comp_product_changed' => 'primary', 'comp_added' => 'success', 'comp_removed' => 'danger', 'rollback' => 'dark', ]; public static $channelLabels = [ 'admin' => 'abo_history.channel_admin', 'user_me' => 'abo_history.channel_user_me', 'user_ot' => 'abo_history.channel_user_ot', 'portal' => 'abo_history.channel_portal', 'system' => 'abo_history.channel_system', ]; public static $channelColors = [ 'admin' => 'danger', 'user_me' => 'warning', 'user_ot' => 'info', 'portal' => 'secondary', 'system' => 'default', ]; protected $casts = [ 'user_abo_id' => 'int', 'user_abo_item_id' => 'int', 'product_id' => 'int', 'unit_price' => 'float', 'total_price' => 'float', 'qty_before' => 'int', 'qty_after' => 'int', 'old_product_id' => 'int', 'comp' => 'int', 'changed_by_user_id' => 'int', 'is_initial' => 'bool', ]; protected $fillable = [ 'user_abo_id', 'user_abo_item_id', 'product_id', 'action', 'product_name', 'product_number', 'unit_price', 'total_price', 'qty_before', 'qty_after', 'old_product_id', 'old_product_name', 'comp', 'changed_by_user_id', 'changed_by_name', 'channel', 'batch_id', 'is_initial', ]; public function user_abo() { return $this->belongsTo(UserAbo::class); } public function product() { return $this->belongsTo(Product::class); } public function old_product() { return $this->belongsTo(Product::class, 'old_product_id'); } public function changed_by() { return $this->belongsTo(User::class, 'changed_by_user_id'); } public function getActionBadge() { $label = isset(self::$actionLabels[$this->action]) ? __(self::$actionLabels[$this->action]) : $this->action; $color = self::$actionColors[$this->action] ?? 'secondary'; return ''.$label.''; } public function getChannelBadge() { $label = isset(self::$channelLabels[$this->channel]) ? __(self::$channelLabels[$this->channel]) : $this->channel; $color = self::$channelColors[$this->channel] ?? 'secondary'; return ''.$label.''; } public function getChangeDescription() { switch ($this->action) { case self::ACTION_INITIAL: return __('abo_history.desc_initial', ['qty' => $this->qty_after]); case self::ACTION_ADDED: return __('abo_history.desc_added', ['qty' => $this->qty_after]); case self::ACTION_REMOVED: return __('abo_history.desc_removed'); case self::ACTION_QTY_CHANGED: return __('abo_history.desc_qty_changed', ['from' => $this->qty_before, 'to' => $this->qty_after]); case self::ACTION_COMP_CHANGED: return __('abo_history.desc_comp_changed', ['old' => $this->old_product_name]); case self::ACTION_COMP_ADDED: return __('abo_history.desc_comp_added'); case self::ACTION_COMP_REMOVED: return __('abo_history.desc_comp_removed'); case self::ACTION_ROLLBACK: return __('abo_history.desc_rollback'); default: return ''; } } public function getFormattedUnitPrice() { return Util::formatNumber($this->unit_price); } public function getFormattedTotalPrice() { return Util::formatNumber($this->total_price); } public function getFormattedDate() { return Carbon::parse($this->created_at)->format('d.m.Y H:i'); } }