1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/app/Models/Scheduler.php

91 lines
2.0 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Models;
2023-01-13 02:43:38 +01:00
use App\Services\Scheduler\SchedulerService;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @property bool paused
* @property bool is_deleted
* @property \Carbon\Carbon|mixed start_from
2023-01-13 02:43:38 +01:00
* @property int frequency_id
* @property \Carbon\Carbon|mixed next_run
* @property int company_id
* @property int updated_at
* @property int created_at
* @property int deleted_at
2022-05-30 20:45:38 +02:00
* @property string action_name
* @property mixed company
* @property array parameters
* @property string action_class
*/
class Scheduler extends BaseModel
{
2023-01-13 02:43:38 +01:00
use SoftDeletes;
protected $fillable = [
2023-01-13 10:16:17 +01:00
'name',
'frequency_id',
'next_run',
2023-01-17 09:42:34 +01:00
'next_run_client',
2023-01-13 10:16:17 +01:00
'template',
'is_paused',
2022-05-30 20:45:38 +02:00
'parameters',
2023-02-16 23:34:50 +01:00
'remaining_cycles',
];
2022-05-27 05:10:32 +02:00
protected $casts = [
2023-01-13 02:43:38 +01:00
'next_run' => 'datetime',
2023-01-17 09:42:34 +01:00
'next_run_client' => 'datetime',
2022-05-27 02:50:03 +02:00
'created_at' => 'timestamp',
'updated_at' => 'timestamp',
'deleted_at' => 'timestamp',
2023-01-13 10:16:17 +01:00
'is_paused' => 'boolean',
'is_deleted' => 'boolean',
2022-05-30 20:45:38 +02:00
'parameters' => 'array',
];
2022-05-30 20:45:38 +02:00
2023-01-13 02:43:38 +01:00
protected $appends = [
'hashed_id',
];
/**
* Service entry points.
*/
2023-01-13 02:43:38 +01:00
public function service(): SchedulerService
{
2023-01-13 02:43:38 +01:00
return new SchedulerService($this);
}
public function company()
{
return $this->belongsTo(Company::class);
}
2023-02-16 23:34:50 +01:00
/**
* remainingCycles
*
* @return int
*/
public function remainingCycles() : int
{
if ($this->remaining_cycles == 0) {
return 0;
} elseif ($this->remaining_cycles == -1) {
return -1;
} else {
return $this->remaining_cycles - 1;
}
}
}