Bill   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 37
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\BillScope;
8
9
class Bill extends BaseModel
10
{
11
    /**
12
     * Invoice constructor.
13
     * @param array $attributes
14
     */
15
    public function __construct(array $attributes = [])
16
    {
17
        parent::__construct($attributes);
18
19
        $this->setTable(config('soap.invoices.table_names.invoices'));
20
    }
21
22
    /**
23
     * The "booting" method of the model.
24
     *
25
     * @return void
26
     */
27
    protected static function boot()
28
    {
29
        parent::boot();
30
        static::addGlobalScope(new BillScope());
31
        static::creating(function ($model) {
32
            /**
33
             * @var \Illuminate\Database\Eloquent\Model $model
34
             */
35
            if (!$model->getKey()) {
36
                $model->{$model->getKeyName()} = Str::uuid()->toString();
37
            }
38
39
            $model->total     = 0;
40
            $model->tax       = 0;
41
            $model->discount  = 0;
42
            $model->is_bill   = true;
43
            $model->currency  = config('soap.invoices.default_currency', 'THB');
44
            $model->status    = config('soap.invoices.default_status', 'concept');
45
            $model->reference = InvoiceReferenceGenerator::generate();
46
        });
47
    }
48
}
49