'int', 'source_id' => 'int', 'month' => 'int', 'year' => 'int', 'points_onetime' => 'int', 'points_accumulated' => 'int', 'is_storno' => 'bool', 'storno_of_id' => 'int', 'user_sales_volume_id' => 'int', 'incentive_new_partner_id' => 'int', 'incentive_new_abo_id' => 'int', ]; protected $fillable = [ 'participant_id', 'type', 'source_type', 'source_id', 'source_label', 'month', 'year', 'points_onetime', 'points_accumulated', 'is_storno', 'storno_of_id', 'user_sales_volume_id', 'incentive_new_partner_id', 'incentive_new_abo_id', ]; public static $types = [ 'partner' => 'partner', 'abo' => 'abo', ]; // Relationships public function participant() { return $this->belongsTo(IncentiveParticipant::class, 'participant_id'); } public function salesVolume() { return $this->belongsTo(UserSalesVolume::class, 'user_sales_volume_id'); } public function incentiveNewPartner() { return $this->belongsTo(IncentiveNewPartner::class, 'incentive_new_partner_id'); } public function incentiveNewAbo() { return $this->belongsTo(IncentiveNewAbo::class, 'incentive_new_abo_id'); } public function stornoOf() { return $this->belongsTo(self::class, 'storno_of_id'); } public function stornoEntries() { return $this->hasMany(self::class, 'storno_of_id'); } // Scopes public function scopePartner($query) { return $query->where('type', 'partner'); } public function scopeAbo($query) { return $query->where('type', 'abo'); } public function scopeActive($query) { return $query->where('is_storno', false); } public function scopeForMonth($query, int $month, int $year) { return $query->where('month', $month)->where('year', $year); } // Helpers public function getTotalPoints(): int { return $this->points_onetime + $this->points_accumulated; } public function getFormattedMonthYear(): string { return str_pad($this->month, 2, '0', STR_PAD_LEFT).'/'.$this->year; } }