InvoiceDetail   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 57
rs 10
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A invoice() 0 3 1
A getPriceWithCurrencyAttribute() 0 7 2
A getFinalPriceAttribute() 0 3 2
A getPriceAttribute() 0 3 1
A getTotalPriceAttribute() 0 3 1
A setPriceAttribute() 0 3 1
A product() 0 3 1
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
use Spatie\Activitylog\Traits\LogsActivity;
8
9
/**
10
 * @mixin IdeHelperInvoiceDetail
11
 */
12
class InvoiceDetail extends Model
13
{
14
    use SoftDeletes;
15
    use LogsActivity;
16
17
    protected $guarded = ['id'];
18
19
    protected static bool $logUnguarded = true;
20
21
    protected $appends = ['price_with_currency'];
22
23
    public function invoice()
24
    {
25
        return $this->belongsTo(Invoice::class);
26
    }
27
28
    /**
29
     * Get the parent invoiceable model
30
     */
31
    public function product()
32
    {
33
        return $this->morphTo();
34
    }
35
36
    public function getPriceAttribute($value)
37
    {
38
        return $value / 100;
39
    }
40
41
    public function getFinalPriceAttribute($value)
42
    {
43
        return $value ? $value / 100 : $this->price;
44
    }
45
46
    public function getTotalPriceAttribute($value)
47
    {
48
        return ($value * $this->quantity) / 100;
49
    }
50
51
    public function getPriceWithCurrencyAttribute()
52
    {
53
        if (config('app.currency_position') === 'before') {
54
            return config('app.currency_symbol').' '.$this->price;
55
        }
56
57
        return $this->price.' '.config('app.currency_symbol');
58
    }
59
60
    /*
61
|--------------------------------------------------------------------------
62
| MUTATORS
63
|--------------------------------------------------------------------------
64
*/
65
66
    public function setPriceAttribute($value)
67
    {
68
        $this->attributes['price'] = $value * 100;
69
    }
70
}
71