1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Domains\Customers; |
4
|
|
|
|
5
|
|
|
use App\CustomerContacts; |
6
|
|
|
use Illuminate\Support\Facades\Auth; |
7
|
|
|
use Illuminate\Support\Facades\Log; |
8
|
|
|
use JeroenDesloovere\VCard\VCard; |
9
|
|
|
|
10
|
|
|
class GetCustomerContacts extends GetCustomerDetails |
11
|
|
|
{ |
12
|
4 |
|
public function execute($custID) |
13
|
|
|
{ |
14
|
4 |
|
$contacts = $this->getAllContacts($custID); |
15
|
|
|
|
16
|
|
|
// Get any contacts that are shared between sites |
17
|
4 |
|
if($parent = $this->getParentID($custID)) |
18
|
|
|
{ |
19
|
2 |
|
$contacts = $contacts->merge($this->getAllContacts($parent, true)); |
20
|
|
|
} |
21
|
|
|
|
22
|
4 |
|
return $contacts; |
23
|
|
|
} |
24
|
|
|
|
25
|
2 |
|
public function getOneContact($contID) |
26
|
|
|
{ |
27
|
2 |
|
$cont = CustomerContacts::where('cont_id', $contID)->with('CustomerContactPhones')->first(); |
28
|
2 |
|
$cust = $this->getDetails($cont->cust_id); |
29
|
2 |
|
$name = explode(' ', $cont->name); |
30
|
|
|
|
31
|
|
|
// Build the VCard |
32
|
2 |
|
$vcard = new VCard(); |
33
|
2 |
|
$vcard->addName(isset($name[1]) ? $name[1] : null, $name[0]); |
34
|
2 |
|
$vcard->addCompany($cust->name); |
35
|
2 |
|
$vcard->addAddress(null, null, $cust->address, $cust->city, $cust->state, $cust->zip, null); |
36
|
|
|
|
37
|
|
|
// Add phone numbers to the VCard |
38
|
2 |
|
foreach($cont->CustomerContactPhones as $phone) |
39
|
|
|
{ |
40
|
2 |
|
$number = $phone->readable; |
41
|
2 |
|
if($phone->extension) |
42
|
|
|
{ |
43
|
2 |
|
$number .= ', '.$phone->extension; |
44
|
|
|
} |
45
|
2 |
|
$vcard->addPhoneNumber($number, $phone->type_name); |
46
|
|
|
} |
47
|
|
|
|
48
|
2 |
|
return $vcard; |
49
|
|
|
} |
50
|
|
|
|
51
|
4 |
|
protected function getAllContacts($custID, $shared = false) |
52
|
|
|
{ |
53
|
4 |
|
return CustomerContacts::where('cust_id', $custID) |
54
|
|
|
->when($shared, function($q) |
55
|
|
|
{ |
56
|
2 |
|
$q->where('shared', 1); |
57
|
4 |
|
}) |
58
|
4 |
|
->with('CustomerContactPhones') |
59
|
4 |
|
->get(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|