Passed
Push — master ( a8b594...f799ef )
by
unknown
02:38 queued 11s
created

Bill::lines()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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