2019-05-05 02:49:01 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-05-05 02:49:01 +02:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use App\Models\Filterable;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2020-03-29 14:22:14 +02:00
|
|
|
use Illuminate\Support\Carbon;
|
2019-05-05 02:49:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for Recurring Invoices.
|
|
|
|
*/
|
|
|
|
class RecurringQuote extends BaseModel
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use SoftDeletes;
|
|
|
|
use Filterable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Statuses
|
|
|
|
*/
|
|
|
|
const STATUS_DRAFT = 2;
|
|
|
|
const STATUS_ACTIVE = 3;
|
|
|
|
const STATUS_PENDING = -1;
|
|
|
|
const STATUS_COMPLETED = -2;
|
|
|
|
const STATUS_CANCELLED = -3;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Recurring intervals
|
|
|
|
*/
|
|
|
|
const FREQUENCY_WEEKLY = 1;
|
|
|
|
const FREQUENCY_TWO_WEEKS = 2;
|
|
|
|
const FREQUENCY_FOUR_WEEKS = 3;
|
|
|
|
const FREQUENCY_MONTHLY = 4;
|
|
|
|
const FREQUENCY_TWO_MONTHS = 5;
|
|
|
|
const FREQUENCY_THREE_MONTHS = 6;
|
|
|
|
const FREQUENCY_FOUR_MONTHS = 7;
|
|
|
|
const FREQUENCY_SIX_MONTHS = 8;
|
|
|
|
const FREQUENCY_ANNUALLY = 9;
|
|
|
|
const FREQUENCY_TWO_YEARS = 10;
|
|
|
|
|
|
|
|
const RECURS_INDEFINITELY = -1;
|
|
|
|
|
2019-06-26 06:04:10 +02:00
|
|
|
protected $fillable = [
|
|
|
|
'client_id',
|
|
|
|
'quote_number',
|
|
|
|
'discount',
|
|
|
|
'is_amount_discount',
|
|
|
|
'po_number',
|
|
|
|
'quote_date',
|
|
|
|
'valid_until',
|
|
|
|
'line_items',
|
|
|
|
'settings',
|
|
|
|
'footer',
|
|
|
|
'public_note',
|
|
|
|
'private_notes',
|
|
|
|
'terms',
|
|
|
|
'tax_name1',
|
|
|
|
'tax_name2',
|
2019-10-05 04:28:23 +02:00
|
|
|
'tax_name3',
|
2019-06-26 06:04:10 +02:00
|
|
|
'tax_rate1',
|
|
|
|
'tax_rate2',
|
2019-10-05 04:28:23 +02:00
|
|
|
'tax_rate3',
|
2019-06-26 06:04:10 +02:00
|
|
|
'custom_value1',
|
|
|
|
'custom_value2',
|
|
|
|
'custom_value3',
|
|
|
|
'custom_value4',
|
|
|
|
'amount',
|
|
|
|
'frequency_id',
|
|
|
|
'start_date',
|
|
|
|
];
|
2019-05-05 02:49:01 +02:00
|
|
|
|
2020-07-23 05:55:11 +02:00
|
|
|
protected $touches = [];
|
2020-07-16 13:01:39 +02:00
|
|
|
|
2019-05-05 02:49:01 +02:00
|
|
|
protected $casts = [
|
2020-03-29 14:22:14 +02:00
|
|
|
'line_items' => 'object',
|
2020-06-15 01:34:18 +02:00
|
|
|
'backup' => 'object',
|
2019-09-26 00:27:26 +02:00
|
|
|
'settings' => 'object',
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
2019-05-05 02:49:01 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
protected $with = [
|
|
|
|
// 'client',
|
|
|
|
// 'company',
|
|
|
|
];
|
|
|
|
|
2020-05-06 13:49:42 +02:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
|
|
|
return RecurringQuote::class;
|
|
|
|
}
|
|
|
|
|
2020-04-04 12:32:42 +02:00
|
|
|
public function getDateAttribute($value)
|
|
|
|
{
|
2020-03-29 23:29:00 +02:00
|
|
|
if (!empty($value)) {
|
2020-04-04 12:32:42 +02:00
|
|
|
return (new Carbon($value))->format('Y-m-d');
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2020-04-04 12:32:42 +02:00
|
|
|
public function getDueDateAttribute($value)
|
|
|
|
{
|
2020-03-29 23:29:00 +02:00
|
|
|
if (!empty($value)) {
|
2020-04-04 12:32:42 +02:00
|
|
|
return (new Carbon($value))->format('Y-m-d');
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2020-04-04 12:32:42 +02:00
|
|
|
public function getPartialDueDateAttribute($value)
|
|
|
|
{
|
2020-03-29 23:29:00 +02:00
|
|
|
if (!empty($value)) {
|
2020-04-04 12:32:42 +02:00
|
|
|
return (new Carbon($value))->format('Y-m-d');
|
2020-03-29 14:22:14 +02:00
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2019-05-05 02:49:01 +02:00
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function client()
|
|
|
|
{
|
2019-11-25 10:38:55 +01:00
|
|
|
return $this->belongsTo(Client::class)->withTrashed();
|
2019-05-05 02:49:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
2019-11-25 10:38:55 +01:00
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
2019-05-05 02:49:01 +02:00
|
|
|
}
|
|
|
|
|
2019-11-05 11:16:38 +01:00
|
|
|
public function assigned_user()
|
|
|
|
{
|
2019-12-30 22:59:12 +01:00
|
|
|
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
|
2019-11-05 11:16:38 +01:00
|
|
|
}
|
|
|
|
|
2019-05-05 02:49:01 +02:00
|
|
|
public function invitations()
|
|
|
|
{
|
|
|
|
$this->morphMany(RecurringQuoteInvitation::class);
|
|
|
|
}
|
|
|
|
}
|