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

154 lines
3.2 KiB
PHP
Raw Normal View History

2019-05-05 02:49:01 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-11 05:32:07 +02:00
*/
2019-05-05 02:49:01 +02:00
namespace App\Models;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\SoftDeletes;
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.
2019-05-05 02:49:01 +02:00
*/
const STATUS_DRAFT = 2;
const STATUS_ACTIVE = 3;
const STATUS_PENDING = -1;
const STATUS_COMPLETED = -2;
const STATUS_CANCELLED = -3;
/**
* Recurring intervals.
2019-05-05 02:49:01 +02:00
*/
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;
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',
'tax_name3',
'tax_rate1',
'tax_rate2',
'tax_rate3',
'custom_value1',
'custom_value2',
'custom_value3',
'custom_value4',
'amount',
'frequency_id',
2020-09-13 12:20:11 +02:00
'due_date_days',
];
2019-05-05 02:49:01 +02:00
2020-07-23 05:55:11 +02:00
protected $touches = [];
2019-05-05 02:49:01 +02:00
protected $casts = [
'line_items' => 'object',
'backup' => 'object',
'settings' => 'object',
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'deleted_at' => 'timestamp',
2019-05-05 02:49:01 +02:00
];
protected $with = [
// 'client',
// 'company',
];
public function getEntityType()
{
return self::class;
}
public function getDateAttribute($value)
{
if (! empty($value)) {
return (new Carbon($value))->format('Y-m-d');
}
return $value;
}
public function getDueDateAttribute($value)
{
if (! empty($value)) {
return (new Carbon($value))->format('Y-m-d');
}
return $value;
}
public function getPartialDueDateAttribute($value)
{
if (! empty($value)) {
return (new Carbon($value))->format('Y-m-d');
}
return $value;
}
2019-05-05 02:49:01 +02:00
public function company()
{
return $this->belongsTo(Company::class);
}
public function client()
{
return $this->belongsTo(Client::class)->withTrashed();
2019-05-05 02:49:01 +02:00
}
public function user()
{
return $this->belongsTo(User::class)->withTrashed();
2019-05-05 02:49:01 +02:00
}
public function assigned_user()
{
return $this->belongsTo(User::class, 'assigned_user_id', 'id')->withTrashed();
}
2019-05-05 02:49:01 +02:00
public function invitations()
{
$this->morphMany(RecurringQuoteInvitation::class);
}
}