1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Models/ScheduledReport.php

60 lines
1.3 KiB
PHP
Raw Normal View History

2017-11-21 22:51:59 +01:00
<?php
namespace App\Models;
2017-11-23 11:23:19 +01:00
use Carbon;
2017-11-21 22:51:59 +01:00
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Scheduled Report
*/
class ScheduledReport extends EntityModel
{
use SoftDeletes;
/**
* @var array
*/
protected $fillable = [
'frequency',
'config',
2017-11-23 09:10:14 +01:00
'send_date',
2017-11-21 22:51:59 +01:00
];
2017-11-23 09:10:14 +01:00
/**
* @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();
}
2017-11-23 11:23:19 +01:00
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();
}
2017-11-21 22:51:59 +01:00
}