1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Domains\Customers; |
4
|
|
|
|
5
|
|
|
use App\CustomerSystemData; |
6
|
|
|
use App\CustomerSystems; |
7
|
|
|
use Illuminate\Support\Facades\Auth; |
8
|
|
|
use Illuminate\Support\Facades\Log; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class SetCustomerEquipment extends GetCustomerDetails |
12
|
|
|
{ |
13
|
6 |
|
public function createNewEquipment($request, $custID) |
14
|
|
|
{ |
15
|
6 |
|
if($request->shared) |
16
|
|
|
{ |
17
|
6 |
|
$parent = $this->getParentID($custID); |
18
|
6 |
|
if($parent) |
19
|
|
|
{ |
20
|
2 |
|
$custID = $parent; |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
6 |
|
$equipID = $this->createEquipment($request->sys_id, $custID, $request->shared); |
25
|
6 |
|
$this->processFields($request->fields, $equipID); |
26
|
|
|
|
27
|
6 |
|
return true; |
28
|
|
|
} |
29
|
|
|
|
30
|
6 |
|
public function updateExistingEquipment($request, $custID, $equipID) |
31
|
|
|
{ |
32
|
6 |
|
if($request->shared) |
33
|
|
|
{ |
34
|
6 |
|
$parent = $this->getParentID($custID); |
35
|
6 |
|
if($parent) |
36
|
|
|
{ |
37
|
2 |
|
$custID = $parent; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
6 |
|
$this->updateEquipment($equipID, $custID, $request->shared); |
42
|
6 |
|
$this->processFields($request->fields, $equipID); |
43
|
|
|
|
44
|
6 |
|
return true; |
45
|
|
|
} |
46
|
|
|
|
47
|
4 |
|
public function deleteEquip($equipID) |
48
|
|
|
{ |
49
|
4 |
|
CustomerSystems::find($equipID)->delete(); |
50
|
4 |
|
return true; |
51
|
|
|
} |
52
|
|
|
|
53
|
6 |
|
protected function createEquipment($sysID, $custID, $shared) |
54
|
|
|
{ |
55
|
6 |
|
$newSys = CustomerSystems::create([ |
56
|
6 |
|
'cust_id' => $custID, |
57
|
6 |
|
'sys_id' => $sysID, |
58
|
6 |
|
'shared' => $shared, |
59
|
|
|
]); |
60
|
|
|
|
61
|
6 |
|
return $newSys->cust_sys_id; |
62
|
|
|
} |
63
|
|
|
|
64
|
6 |
|
protected function updateEquipment($equipID, $custID, $shared) |
65
|
|
|
{ |
66
|
6 |
|
CustomerSystems::find($equipID)->update([ |
67
|
6 |
|
'cust_id' => $custID, |
68
|
6 |
|
'shared' => $shared, |
69
|
|
|
]); |
70
|
6 |
|
} |
71
|
|
|
|
72
|
12 |
|
protected function processFields($fieldData, $equipID) |
73
|
|
|
{ |
74
|
12 |
|
foreach($fieldData as $field) |
75
|
|
|
{ |
76
|
12 |
|
Log::emergency($field); |
77
|
12 |
|
CustomerSystemData::firstOrCreate([ |
78
|
12 |
|
'cust_sys_id' => $equipID, |
79
|
12 |
|
'field_id' => $field['field_id'], |
80
|
|
|
], |
81
|
12 |
|
[ 'cust_sys_id' => $equipID, |
82
|
12 |
|
'field_id' => $field['field_id'], |
83
|
12 |
|
'value' => isset($field['value']) ? $field['value'] : null,])->update([ |
84
|
12 |
|
'value' => isset($field['value']) ? $field['value'] : null, |
85
|
|
|
]); |
86
|
|
|
} |
87
|
|
|
|
88
|
12 |
|
return true; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|