Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
66.67% covered (warning)
66.67%
2 / 3
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
BomItem
66.67% covered (warning)
66.67%
2 / 3
66.67% covered (warning)
66.67%
2 / 3
3.33
0.00% covered (danger)
0.00%
0 / 1
 bom
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 material
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 qtyPerUnit
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Models;
4
5use App\Models\admin\Product;
6use Illuminate\Database\Eloquent\Model;
7
8class BomItem extends Model
9{
10    protected $fillable = ['bom_id', 'material_id', 'qty', 'unit', 'wastage_pct'];
11
12    protected $casts = [
13        'qty' => 'decimal:4',
14        'wastage_pct' => 'decimal:2',
15    ];
16
17    public function bom()
18    {
19        return $this->belongsTo(Bom::class);
20    }
21
22    public function material()
23    {
24        return $this->belongsTo(Product::class, 'material_id');
25    }
26
27    /** Quantity actually required per finished unit, wastage included. */
28    public function qtyPerUnit(): float
29    {
30        return (float) $this->qty * (1 + ((float) $this->wastage_pct / 100));
31    }
32}