<?php
 namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class CouponUsage extends Model { use HasFactory; protected $table = 'coupon_usages'; protected $fillable = [ 'coupon_id', 'client_id', 'order_id', 'discount_amount', 'original_amount', 'final_amount', 'currency_id', 'used_at', 'metadata', ]; protected $casts = [ 'discount_amount' => 'decimal:2', 'original_amount' => 'decimal:2', 'final_amount' => 'decimal:2', 'used_at' => 'datetime', 'metadata' => 'array', ]; public function coupon(): BelongsTo { return $this->belongsTo(Coupon::class); } public function client(): BelongsTo { return $this->belongsTo(Client::class); } public function order(): BelongsTo { return $this->belongsTo(Order::class); } public function currency(): BelongsTo { return $this->belongsTo(Currency::class); } public function getDiscountPercentageAttribute(): float { if ($this->original_amount > 0) { return round(($this->discount_amount / $this->original_amount) * 100, 2); } return 0; } public function getDiscountTextAttribute(): string { return $this->currency->code.' '.$this->discount_amount.' (%'.$this->discount_percentage.')'; } public function getSavingsTextAttribute(): string { return $this->currency->code.' '.$this->discount_amount.' tasarruf'; } } 