'decimal:2', 'total_transactions' => 'integer', 'lifetime_returns' => 'decimal:2', 'last_purchase_at' => 'datetime', ]; public function sales(): HasMany { return $this->hasMany(Sale::class); } /** * Nivel o rango del cliente */ public function tier(): BelongsTo { return $this->belongsTo(ClientTier::class, 'tier_id'); } /** * Historial de cambios de nivel del cliente */ public function tierHistory(): HasMany { return $this->hasMany(ClientTierHistory::class)->orderBy('changed_at', 'desc'); } /** * Descuento aplicable segĂșn el nivel del cliente */ public function getDiscountPercentageAttribute(): float { return $this->tier?->discount_percentage ?? 0; } /** * Compras netas del cliente (total compras - devoluciones) */ public function getNetPurchasesAttribute(): float { return $this->total_purchases - $this->lifetime_returns; } }