|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NeptuneSoftware\Invoice\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
use NeptuneSoftware\Invoice\Scopes\InvoiceScope; |
|
8
|
|
|
|
|
9
|
|
|
class InvoiceLine extends Model |
|
10
|
|
|
{ |
|
11
|
|
|
protected $guarded = []; |
|
12
|
|
|
|
|
13
|
|
|
public $incrementing = false; |
|
14
|
|
|
|
|
15
|
|
|
protected $fillable = [ |
|
16
|
|
|
'amount', 'tax', 'tax_details', 'invoice_id', 'description', 'invoiceable_id', |
|
17
|
|
|
'invoiceable_type', 'name', 'discount', 'quantity', 'is_free', 'is_complimentary' |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
protected $casts = [ |
|
21
|
|
|
'tax_details' => 'array' |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* InvoiceLine constructor. |
|
26
|
|
|
* @param array $attributes |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct(array $attributes = []) |
|
29
|
|
|
{ |
|
30
|
|
|
parent::__construct($attributes); |
|
31
|
|
|
|
|
32
|
|
|
$this->setTable(config('invoice.table_names.invoice_lines')); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
protected static function boot() |
|
36
|
|
|
{ |
|
37
|
|
|
parent::boot(); |
|
38
|
|
|
static::creating(function ($model) { |
|
39
|
|
|
/** |
|
40
|
|
|
* @var \Illuminate\Database\Eloquent\Model $model |
|
41
|
|
|
*/ |
|
42
|
|
|
if (!$model->getKey()) { |
|
43
|
|
|
$model->{$model->getKeyName()} = Str::uuid()->toString(); |
|
44
|
|
|
} |
|
45
|
|
|
}); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function invoice() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->belongsTo(Invoice::class); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function bill() |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->belongsTo(Bill::class, 'invoice_id')->withoutGlobalScope(InvoiceScope::class); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphTo |
|
60
|
|
|
*/ |
|
61
|
|
|
public function related() |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->morphTo(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|