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