1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Customers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
|
7
|
|
|
use App\Domains\Equipment\GetEquipmentData; |
8
|
|
|
use App\Domains\Customers\SetCustomerEquipment; |
9
|
|
|
use App\Domains\Customers\GetCustomerEquipment; |
10
|
|
|
|
11
|
|
|
use App\Http\Requests\CustomerNewEquipmentRequest; |
12
|
|
|
use App\Http\Requests\CustomerEditEquipmentRequest; |
13
|
|
|
|
14
|
|
|
class CustomerSystemsController extends Controller |
15
|
|
|
{ |
16
|
20 |
|
public function __construct() |
17
|
|
|
{ |
18
|
20 |
|
$this->middleware('auth'); |
19
|
20 |
|
} |
20
|
|
|
|
21
|
|
|
// Get the possible system types that can be assigned to the customer |
22
|
2 |
|
public function index() |
23
|
|
|
{ |
24
|
2 |
|
return (new GetEquipmentData)->getAllEquipmentWithDataList(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
// Store a new system for the customer |
28
|
4 |
|
public function store(CustomerNewEquipmentRequest $request) |
29
|
|
|
{ |
30
|
4 |
|
$equipObj = new SetCustomerEquipment($request->cust_id); |
31
|
4 |
|
if(!$equipObj->creatNewEquipment($request)) |
32
|
|
|
{ |
33
|
|
|
abort(404); |
34
|
|
|
} |
35
|
|
|
|
36
|
4 |
|
return response()->json(['success' => true]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// Get the list of systems attached to the customer |
40
|
6 |
|
public function show($id) |
41
|
|
|
{ |
42
|
6 |
|
return (new GetCustomerEquipment($id))->execute(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// Update the customers system data |
46
|
|
|
public function update(CustomerEditEquipmentRequest $request, $id) |
47
|
|
|
{ |
48
|
|
|
$updateObj = new SetCustomerEquipment($id); |
49
|
|
|
if(!$updateObj->updateEquipment($request)) |
50
|
|
|
{ |
51
|
|
|
abort(404); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return response()->json(['success' => true]); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Delete a system attached to a customer |
58
|
|
|
public function deleteEquip($equipID, $custID) |
59
|
|
|
{ |
60
|
|
|
$delObj = new SetCustomerEquipment($custID); |
61
|
|
|
if(!$delObj->deleteEquipment($equipID)) |
62
|
|
|
{ |
63
|
|
|
return response()->json(['success' => false]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return response()->json(['success' => true]); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|