akaunting/app/Models/Common/Recurring.php

72 lines
1.5 KiB
PHP
Raw Normal View History

2018-04-26 02:17:55 +03:00
<?php
namespace App\Models\Common;
2019-11-16 10:21:14 +03:00
use App\Abstracts\Model;
2018-05-02 00:59:55 +03:00
use App\Traits\Recurring as RecurringTrait;
2022-06-01 10:15:55 +03:00
use Illuminate\Database\Eloquent\Builder;
2018-04-26 02:17:55 +03:00
class Recurring extends Model
{
2018-05-02 00:59:55 +03:00
use RecurringTrait;
2018-04-26 02:17:55 +03:00
2022-06-01 10:15:55 +03:00
public const ACTIVE_STATUS = 'active';
public const END_STATUS = 'ended';
public const COMPLETE_STATUS = 'completed';
2018-04-27 17:42:45 +03:00
protected $table = 'recurring';
2018-04-26 18:40:04 +03:00
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
2022-06-01 10:15:55 +03:00
protected $fillable = [
'company_id',
'recurable_id',
'recurable_type',
'frequency',
'interval',
'started_at',
'status',
'limit_by',
'limit_count',
'limit_date',
'auto_send',
'created_from',
'created_by',
];
/**
* The attributes that should be cast.
*
* @var array
*/
protected $casts = [
'auto_send' => 'boolean',
];
2018-04-26 18:40:04 +03:00
2018-04-26 02:17:55 +03:00
/**
2018-05-01 19:00:33 +03:00
* Get all of the owning recurable models.
2018-04-26 02:17:55 +03:00
*/
2018-04-27 17:42:45 +03:00
public function recurable()
2018-04-26 02:17:55 +03:00
{
return $this->morphTo();
}
2022-06-01 10:15:55 +03:00
public function scopeActive(Builder $query): Builder
{
return $query->where($this->qualifyColumn('status'), '=', static::ACTIVE_STATUS);
}
public function scopeEnded(Builder $query): Builder
{
return $query->where($this->qualifyColumn('status'), '=', static::END_STATUS);
}
public function scopeCompleted(Builder $query): Builder
{
return $query->where($this->qualifyColumn('status'), '=', static::COMPLETE_STATUS);
}
2018-04-26 02:17:55 +03:00
}