1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Customers; |
4
|
|
|
|
5
|
|
|
use App\Domains\Users\GetUserStats; |
6
|
|
|
use App\Domains\Customers\DestroyCustomer; |
7
|
|
|
use App\Domains\Customers\GetCustomerDetails; |
8
|
|
|
use App\Domains\Customers\SetCustomerDetails; |
9
|
|
|
|
10
|
|
|
use App\Http\Controllers\Controller; |
11
|
|
|
use App\Http\Requests\CustomerCreateRequest; |
12
|
|
|
use App\Http\Requests\CustomerParentSetRequest; |
13
|
|
|
use App\Http\Requests\CustomerDetailsUpdateRequest; |
14
|
|
|
|
15
|
|
|
class CustomerDetailsController extends Controller |
16
|
|
|
{ |
17
|
44 |
|
public function __construct() |
18
|
|
|
{ |
19
|
44 |
|
$this->middleware('auth'); |
20
|
44 |
|
} |
21
|
|
|
|
22
|
|
|
// New Customer Form |
23
|
4 |
|
public function create() |
24
|
|
|
{ |
25
|
4 |
|
$this->authorize('hasAccess', 'Add Customer'); |
26
|
2 |
|
return view('customer.newCustomer'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
// Submit the new customer form |
30
|
8 |
|
public function store(CustomerCreateRequest $request) |
31
|
|
|
{ |
32
|
8 |
|
$this->authorize('hasAccess', 'Add Customer'); |
33
|
6 |
|
$newID = (new SetCustomerDetails)->createNewCustomer($request); |
34
|
6 |
|
return response()->json(['success' => true, 'cust_id' => $newID]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// Show the customer details |
38
|
4 |
|
public function details($id, $name) |
39
|
|
|
{ |
40
|
4 |
|
$details = (new GetCustomerDetails)->getDetailsWithParent($id); |
41
|
|
|
|
42
|
4 |
|
if(!$details) |
43
|
|
|
{ |
44
|
2 |
|
return view('customer.customerNotFound'); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
return view('customer.details', [ |
48
|
2 |
|
'isFav' => (new GetUserStats)->checkForCustomerFav($id) ? "true" : "false", |
49
|
2 |
|
'details' => $details->toJson(), |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// Update the customer details |
54
|
2 |
|
public function update(CustomerDetailsUpdateRequest $request, $id) |
55
|
|
|
{ |
56
|
2 |
|
(new SetCustomerDetails)->updateCustomerDetails($request, $id); |
57
|
|
|
|
58
|
2 |
|
return response()->json(['success' => true]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// Link a site to a parent site |
62
|
4 |
|
public function linkParent(CustomerParentSetRequest $request) |
63
|
|
|
{ |
64
|
4 |
|
(new SetCustomerDetails)->setParentCustomerID($request); |
65
|
|
|
|
66
|
4 |
|
return response()->json(['success' => true]); |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
public function removeParent($id) |
70
|
|
|
{ |
71
|
2 |
|
(new SetCustomerDetails)->removeParentCustomerID($id); |
72
|
|
|
|
73
|
2 |
|
return response()->json(['success' => true]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
// Deactivate a customer - note this will not remove it from the database, but make it inaccessable |
77
|
4 |
|
public function destroy($id) |
78
|
|
|
{ |
79
|
4 |
|
$this->authorize('hasAccess', 'Delete Customer'); |
80
|
2 |
|
(new DestroyCustomer)->softDelete($id); |
81
|
|
|
|
82
|
2 |
|
return response()->json(['success' => true]); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|