Test Failed
Push — dev6 ( 25baf5...e081dc )
by Ron
19:34
created

Customer::CustomerContact()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
use Illuminate\Database\Eloquent\Factories\HasFactory;
8
9
class Customer extends Model
10
{
11
    use HasFactory;
12
    use SoftDeletes;
13
14
    protected $primaryKey = 'cust_id';
15
    protected $guarded    = ['updated_at', 'created_at', 'deleted_at'];
16
    protected $hidden     = ['updated_at', 'created_at', 'deleted_at'];
17
    protected $appends    = ['child_count'];
18
19
    /*
20
    *   If a customer is part of a multi-site customer, each site can be listed separately yet still be linked to the main site
21
    */
22
    public function Parent()
23
    {
24
        return $this->belongsTo(Customer::class, 'parent_id', 'cust_id');
25
    }
26
27
    /*
28
    *   If a customer is the parent and has children below it, they will be counted
29
    */
30
    public function getChildCountAttribute()
31
    {
32
        return Customer::where('parent_id', $this->cust_id)->count();
33
    }
34
35
    /*
36
    *   Several equipment types can be assigned to a customer
37
    */
38
    public function EquipmentType()
39
    {
40
        return $this->hasManyThrough('App\Models\EquipmentType', 'App\Models\CustomerEquipment', 'cust_id', 'equip_id', 'cust_id', 'equip_id');
41
    }
42
43
    /*
44
    *   Equipment that is assigned to a customer will be listed
45
    */
46
    public function CustomerEquipment()
47
    {
48
        return $this->hasMany(CustomerEquipment::class, 'cust_id', 'cust_id');
49
    }
50
51
    //  TODO - ParentEquipmentType()
52
53
    /*
54
    *   Equipment that is shared and belong to the parent site will show up for this customer
55
    */
56
    public function ParentEquipment()
57
    {
58
        //  TODO - verify only shared equipment make it through
59
        return $this->hasMany(CustomerEquipment::class, 'cust_id', 'parent_id')->whereShared(true); // ->where('shared', true);
60
    }
61
62
        /*
63
    *   Site and other contacts for the customer
64
    */
65
    public function CustomerContact()
66
    {
67
        return $this->hasMany(CustomerContact::class, 'cust_id', 'cust_id');
68
    }
69
70
    /*
71
    *   Shared contacts throughout all linked sites
72
    */
73
    public function ParentContact()
74
    {
75
        return $this->hasMany(CustomerContact::class, 'cust_id', 'parent_id')->where('shared', true);
76
    }
77
78
    /*
79
    *   Site Specific notes for this customer
80
    */
81
    public function CustomerNote()
82
    {
83
        return $this->hasMany(CustomerNote::class, 'cust_id', 'cust_id');
84
    }
85
86
    /*
87
    *   Shared notes throughout all sites
88
    */
89
    //  TODO - Parent Notes
90
91
    /*
92
    *   Files attached to this customer
93
    */
94
    public function CustomerFile()
95
    {
96
        return $this->hasMany(CustomerFile::class, 'cust_id', 'cust_id');
97
    }
98
99
    /*
100
    *   Files that are shared throughout all linked sites
101
    */
102
    public function ParentFile()
103
    {
104
        return $this->hasMany(CustomerFile::class, 'cust_id', 'parent_id')->where('shared', true);
105
    }
106
}
107