1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Customers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
6
|
|
|
|
7
|
|
|
use JeroenDesloovere\VCard\VCard; |
8
|
|
|
|
9
|
|
|
use App\Domains\Customers\GetCustomerContacts; |
10
|
|
|
use App\Domains\Customers\GetCustomerDetails; |
11
|
|
|
use App\Domains\Customers\SetCustomerContacts; |
12
|
|
|
|
13
|
|
|
use App\Http\Requests\CustomerEditContactRequest; |
14
|
|
|
use App\Http\Requests\CustomerNewContactRequest; |
15
|
|
|
|
16
|
|
|
class CustomerContactsController extends Controller |
17
|
|
|
{ |
18
|
26 |
|
public function __construct() |
19
|
|
|
{ |
20
|
26 |
|
$this->middleware('auth'); |
21
|
26 |
|
} |
22
|
|
|
|
23
|
|
|
// Index funtion will only return the type of phone numbers that can be assigned to a customer |
24
|
|
|
public function index() |
25
|
|
|
{ |
26
|
|
|
return (new GetCustomerContacts)->getPhoneNumberTypes(true); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
// Store a new customer contact |
30
|
4 |
|
public function store(CustomerNewContactRequest $request) |
31
|
|
|
{ |
32
|
4 |
|
(new SetCustomerContacts($request->cust_id))->createContact($request); |
33
|
4 |
|
return response()->json(['success' => true]); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// Get the contacts for a customer |
37
|
4 |
|
public function show($id) |
38
|
|
|
{ |
39
|
4 |
|
return (new GetCustomerContacts($id))->execute(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// Edit function will actually download the contact information in V-Card format |
43
|
|
|
public function edit($id) |
44
|
|
|
{ |
45
|
|
|
$contData = (new GetCustomerContacts)->getOneContact($id); |
46
|
|
|
$custData = (new GetCustomerDetails)->getDetails($contData['cust_id']); |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
$vcard = new VCard(); |
50
|
|
|
$vcard->addName($contData['lastName'], $contData['firstName'], $contData['additional'], $contData['prefix'], $contData['suffix']); |
51
|
|
|
$vcard->addCompany(/** @scrutinizer ignore-type */ $custData['name']); |
52
|
|
|
$vcard->addEmail($contData['email']); |
53
|
|
|
$vcard->addAddress(null, null, $custData['address'], $custData['city'], $custData['state'], $custData['zip'], null); |
54
|
|
|
if(!empty($contData['numbers'])) |
55
|
|
|
{ |
56
|
|
|
foreach($contData['numbers'] as $phone) |
57
|
|
|
{ |
58
|
|
|
$vcard->addPhoneNumber($phone->phone_number, $phone->description); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
return $vcard->download(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Update an existing Customer Contact |
65
|
6 |
|
public function update(CustomerEditContactRequest $request, $id) |
66
|
|
|
{ |
67
|
6 |
|
(new SetCustomerContacts($id))->updateContact($request); |
68
|
6 |
|
return response()->json(['success' => true]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
// Delete an existing contact |
72
|
2 |
|
public function destroy($id) |
73
|
|
|
{ |
74
|
2 |
|
(new SetCustomerContacts($id))->deleteContact($id); |
75
|
2 |
|
return response()->json(['success' => true]); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|