mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-13 22:54:25 +01:00
60 lines
1.3 KiB
PHP
60 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* Class Scheduled Report
|
|
*/
|
|
class ScheduledReport extends EntityModel
|
|
{
|
|
use SoftDeletes;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'frequency',
|
|
'config',
|
|
'send_date',
|
|
];
|
|
|
|
/**
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function account()
|
|
{
|
|
return $this->belongsTo('App\Models\Account');
|
|
}
|
|
|
|
/**
|
|
* @return mixed
|
|
*/
|
|
public function user()
|
|
{
|
|
return $this->belongsTo('App\Models\User')->withTrashed();
|
|
}
|
|
|
|
public function updateSendDate()
|
|
{
|
|
switch ($this->frequency) {
|
|
case REPORT_FREQUENCY_DAILY;
|
|
$this->send_date = Carbon::now()->addDay()->toDateString();
|
|
break;
|
|
case REPORT_FREQUENCY_WEEKLY:
|
|
$this->send_date = Carbon::now()->addWeek()->toDateString();
|
|
break;
|
|
case REPORT_FREQUENCY_BIWEEKLY:
|
|
$this->send_date = Carbon::now()->addWeeks(2)->toDateString();
|
|
break;
|
|
case REPORT_FREQUENCY_MONTHLY:
|
|
$this->send_date = Carbon::now()->addMonth()->toDateString();
|
|
break;
|
|
}
|
|
|
|
$this->save();
|
|
}
|
|
}
|