2019-04-04 01:30:49 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-04-04 01:30:49 +02:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-12-17 23:40:15 +01:00
|
|
|
use App\Helpers\Invoice\InvoiceSum;
|
|
|
|
use App\Helpers\Invoice\InvoiceSumInclusive;
|
2019-05-02 13:24:00 +02:00
|
|
|
use App\Models\Filterable;
|
2019-04-04 01:30:49 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-11-12 05:41:02 +01:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2019-04-04 01:30:49 +02:00
|
|
|
|
|
|
|
class Quote extends BaseModel
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2019-05-02 13:24:00 +02:00
|
|
|
use Filterable;
|
2019-11-12 05:41:02 +01:00
|
|
|
use SoftDeletes;
|
|
|
|
|
2019-12-17 23:40:15 +01:00
|
|
|
protected $fillable = [
|
|
|
|
'number',
|
2019-06-26 06:04:10 +02:00
|
|
|
'discount',
|
|
|
|
'po_number',
|
2019-12-17 23:40:15 +01:00
|
|
|
'date',
|
|
|
|
'due_date',
|
2019-06-26 06:04:10 +02:00
|
|
|
'terms',
|
2019-12-17 23:40:15 +01:00
|
|
|
'public_notes',
|
|
|
|
'private_notes',
|
|
|
|
'invoice_type_id',
|
2019-06-26 06:04:10 +02:00
|
|
|
'tax_name1',
|
|
|
|
'tax_rate1',
|
2019-12-17 23:40:15 +01:00
|
|
|
'tax_name2',
|
2019-06-26 06:04:10 +02:00
|
|
|
'tax_rate2',
|
2019-12-17 23:40:15 +01:00
|
|
|
'tax_name3',
|
2019-10-05 04:28:23 +02:00
|
|
|
'tax_rate3',
|
2019-12-17 23:40:15 +01:00
|
|
|
'is_amount_discount',
|
|
|
|
'footer',
|
|
|
|
'partial',
|
|
|
|
'partial_due_date',
|
2019-06-26 06:04:10 +02:00
|
|
|
'custom_value1',
|
|
|
|
'custom_value2',
|
|
|
|
'custom_value3',
|
|
|
|
'custom_value4',
|
2019-12-17 23:40:15 +01:00
|
|
|
'line_items',
|
|
|
|
'client_id',
|
|
|
|
'footer',
|
|
|
|
];
|
2019-04-04 01:30:49 +02:00
|
|
|
|
2019-05-02 13:24:00 +02:00
|
|
|
protected $casts = [
|
2019-12-17 23:40:15 +01:00
|
|
|
'line_items' => 'object',
|
2019-09-26 00:27:26 +02:00
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
2019-05-02 13:24:00 +02:00
|
|
|
];
|
|
|
|
|
2019-04-04 01:30:49 +02:00
|
|
|
const STATUS_DRAFT = 1;
|
|
|
|
const STATUS_SENT = 2;
|
2019-05-02 13:24:00 +02:00
|
|
|
const STATUS_APPROVED = 3;
|
|
|
|
const STATUS_EXPIRED = -1;
|
2019-04-04 01:30:49 +02:00
|
|
|
|
|
|
|
public function company()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function user()
|
|
|
|
{
|
2019-11-25 10:38:55 +01:00
|
|
|
return $this->belongsTo(User::class)->withTrashed();
|
2019-04-04 01:30:49 +02:00
|
|
|
}
|
|
|
|
|
2019-11-16 04:12:29 +01:00
|
|
|
public function client()
|
|
|
|
{
|
2019-11-25 10:38:55 +01:00
|
|
|
return $this->belongsTo(Client::class)->withTrashed();
|
2019-11-16 04:12:29 +01: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-04-04 01:30:49 +02:00
|
|
|
public function invitations()
|
|
|
|
{
|
2019-04-24 02:22:02 +02:00
|
|
|
return $this->hasMany(QuoteInvitation::class);
|
2019-04-04 01:30:49 +02:00
|
|
|
}
|
2019-04-24 02:22:02 +02:00
|
|
|
|
2019-04-28 07:31:32 +02:00
|
|
|
public function documents()
|
|
|
|
{
|
|
|
|
return $this->morphMany(Document::class, 'documentable');
|
|
|
|
}
|
|
|
|
|
2019-12-17 23:40:15 +01:00
|
|
|
/**
|
|
|
|
* Access the quote calculator object
|
|
|
|
*
|
|
|
|
* @return object The quote calculator object getters
|
|
|
|
*/
|
|
|
|
public function calc()
|
|
|
|
{
|
|
|
|
$quote_calc = null;
|
|
|
|
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($this->uses_inclusive_taxes) {
|
2019-12-17 23:40:15 +01:00
|
|
|
$quote_calc = new InvoiceSumInclusive($this);
|
2019-12-30 22:59:12 +01:00
|
|
|
} else {
|
2019-12-17 23:40:15 +01:00
|
|
|
$quote_calc = new InvoiceSum($this);
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-12-17 23:40:15 +01:00
|
|
|
|
|
|
|
return $quote_calc->build();
|
|
|
|
}
|
2019-04-04 01:30:49 +02:00
|
|
|
}
|