| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 3 | CRAP | 0.00% covered (danger) | 0.00% | 0 / 19
RejectedBillItem | 0.00% covered (danger) | 0.00% | 0 / 1 | 0.00% covered (danger) | 0.00% | 0 / 3 | 56.00 | 0.00% covered (danger) | 0.00% | 0 / 19
rejectedBill | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 1
injectCommodityName | 0.00% covered (danger) | 0.00% | 0 / 1 | 30.00 | 0.00% covered (danger) | 0.00% | 0 / 16
getQualityLabelAttribute | 0.00% covered (danger) | 0.00% | 0 / 1 | 2.00 | 0.00% covered (danger) | 0.00% | 0 / 2

1 | <?php
2 |
3 | namespace App;
4 |
5 | use Illuminate\Database\Eloquent\Collection;
6 | use Illuminate\Database\Eloquent\Model;
7 | use Illuminate\Database\Eloquent\SoftDeletes;
8 |
9 | /**
10 | * @property mixed rejectedBill
11 | */
12 | class RejectedBillItem extends Model
13 | {
14 | use SoftDeletes;
15 | protected $fillable=['id_rejected_bill','barcode_goods','name_goods','amount','id_quality_label',
16 | 'batch_number','validity_at','made_at','is_checked','remark','is_loaded'];
17 |
18 | protected $appends = ['quality_label'];
19 |
20 | public function rejectedBill(){
21 | return $this->belongsTo('App\RejectedBill', 'id_rejected_bill', 'id');
22 | }
23 | public function injectCommodityName(){
24 | if(!$this['name_goods'])return;
25 | $barcode=$this['barcode_goods'];
26 | $name=$this['name_goods'];
27 | $commodity=Commodity::where('barcode', $barcode)->first();
28 | if($commodity){
29 | if($commodity['name']!=$name){
30 | $commodity['name']=$name;
31 | }
32 | if(!$commodity['owner_name']){
33 | $commodity['owner_name']=$this->rejectedBill->owner->name;
34 | }
35 | $commodity->update();
36 | }
37 | else{
38 | $commodity = new Commodity();
39 | $commodity['barcode']=$barcode;
40 | $commodity['name']=$name;
41 | $commodity['owner_name']=$this->rejectedBill->owner->name;
42 | $commodity->save();
43 | }
44 | }
45 | public function getQualityLabelAttribute(){
46 | $label=QualityLabel::find($this['id_quality_label']);
47 | return $label['name'];
48 | }
49 | }