Invoice   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A boot() 0 19 2
1
<?php
2
3
namespace Soap\Invoices\Models;
4
5
use Illuminate\Support\Str;
6
use Soap\Invoices\InvoiceReferenceGenerator;
7
use Soap\Invoices\Scopes\InvoiceScope;
8
9
class Invoice extends BaseModel
10
{
11
12
    /**
13
     * Invoice constructor.
14
     * @param array $attributes
15
     */
16
    public function __construct(array $attributes = [])
17
    {
18
        parent::__construct($attributes);
19
20
        $this->setTable(config('soap.invoices.table_names.invoices'));
21
    }
22
23
    /**
24
     * The "booting" method of the model.
25
     *
26
     * @return void
27
     */
28
    protected static function boot()
29
    {
30
        parent::boot();
31
        static::addGlobalScope(new InvoiceScope());
32
        static::creating(function ($model) {
33
            /**
34
             * @var \Illuminate\Database\Eloquent\Model $model
35
             */
36
            if (!$model->getKey()) {
37
                $model->{$model->getKeyName()} = Str::uuid()->toString();
38
            }
39
40
            $model->total     = 0;
41
            $model->tax       = 0;
42
            $model->discount  = 0;
43
            $model->is_bill   = false;
44
            $model->currency  = config('soap.invoices.default_currency', 'THB');
45
            $model->status    = config('soap.invoices.default_status', 'concept');
46
            $model->reference = InvoiceReferenceGenerator::generate();
47
        });
48
    }
49
}
50