2019-11-16 07:21:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
|
|
trait Contacts
|
|
|
|
|
{
|
2020-06-08 20:09:43 +00:00
|
|
|
public function isCustomer()
|
2019-11-16 07:21:14 +00:00
|
|
|
{
|
2021-10-05 10:26:27 +00:00
|
|
|
$type = $this->type ?? $this->contact->type ?? $this->model->type ?? 'customer';
|
2020-06-08 20:40:04 +00:00
|
|
|
|
|
|
|
|
return in_array($type, $this->getCustomerTypes());
|
2020-06-08 20:09:43 +00:00
|
|
|
}
|
2019-11-16 07:21:14 +00:00
|
|
|
|
2020-06-08 20:09:43 +00:00
|
|
|
public function isVendor()
|
|
|
|
|
{
|
2021-10-05 10:26:27 +00:00
|
|
|
$type = $this->type ?? $this->contact->type ?? $this->model->type ?? 'vendor';
|
2020-06-08 20:40:04 +00:00
|
|
|
|
|
|
|
|
return in_array($type, $this->getVendorTypes());
|
2020-06-08 20:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-24 08:02:45 +00:00
|
|
|
public function isEmployee()
|
|
|
|
|
{
|
|
|
|
|
$type = $this->type ?? $this->contact->type ?? $this->model->type ?? 'employee';
|
|
|
|
|
|
|
|
|
|
return in_array($type, $this->getEmployeeTypes());
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 20:09:43 +00:00
|
|
|
public function getCustomerTypes($return = 'array')
|
|
|
|
|
{
|
|
|
|
|
return $this->getContactTypes('customer', $return);
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVendorTypes($return = 'array')
|
|
|
|
|
{
|
2020-06-08 20:09:43 +00:00
|
|
|
return $this->getContactTypes('vendor', $return);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 08:02:45 +00:00
|
|
|
public function getEmployeeTypes($return = 'array')
|
|
|
|
|
{
|
|
|
|
|
return $this->getContactTypes('employee', $return);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 20:09:43 +00:00
|
|
|
public function getContactTypes($index, $return = 'array')
|
|
|
|
|
{
|
2020-08-26 12:14:16 +00:00
|
|
|
$types = (string) setting('contact.type.' . $index);
|
2019-11-16 07:21:14 +00:00
|
|
|
|
|
|
|
|
return ($return == 'array') ? explode(',', $types) : $types;
|
|
|
|
|
}
|
2020-01-22 18:24:00 +00:00
|
|
|
|
2020-01-22 18:37:01 +00:00
|
|
|
public function addCustomerType($new_type)
|
2020-01-22 18:24:00 +00:00
|
|
|
{
|
2020-06-08 20:09:43 +00:00
|
|
|
$this->addContactType($new_type, 'customer');
|
2020-01-22 18:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-22 18:37:01 +00:00
|
|
|
public function addVendorType($new_type)
|
2020-01-22 18:24:00 +00:00
|
|
|
{
|
2020-06-08 20:09:43 +00:00
|
|
|
$this->addContactType($new_type, 'vendor');
|
2020-01-22 18:24:00 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-24 08:02:45 +00:00
|
|
|
public function addEmployeeType($new_type)
|
|
|
|
|
{
|
|
|
|
|
$this->addContactType($new_type, 'employee');
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 20:09:43 +00:00
|
|
|
public function addContactType($new_type, $index)
|
2020-01-22 18:24:00 +00:00
|
|
|
{
|
2020-08-26 12:14:16 +00:00
|
|
|
$types = explode(',', setting('contact.type.' . $index));
|
2020-01-22 18:24:00 +00:00
|
|
|
|
|
|
|
|
if (in_array($new_type, $types)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$types[] = $new_type;
|
|
|
|
|
|
|
|
|
|
setting([
|
|
|
|
|
'contact.type.' . $index => implode(',', $types),
|
|
|
|
|
])->save();
|
|
|
|
|
}
|
2024-07-23 08:00:39 +00:00
|
|
|
|
|
|
|
|
public function getFormattedAddress($city = null, $country = null, $state = null, $zip_code = null)
|
|
|
|
|
{
|
2024-07-31 11:13:17 +00:00
|
|
|
if (is_null($city)
|
|
|
|
|
&& is_null($country)
|
|
|
|
|
&& is_null($state)
|
|
|
|
|
&& is_null($zip_code)
|
|
|
|
|
) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 08:00:39 +00:00
|
|
|
$address_format = setting('default.address_format');
|
|
|
|
|
|
|
|
|
|
$formatted_address = str_replace(
|
|
|
|
|
["{city}", "{country}", "{state}", "{zip_code}", "\n"],
|
|
|
|
|
[$city, $country, $state, $zip_code, '<br>'],
|
|
|
|
|
$address_format
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $formatted_address;
|
|
|
|
|
}
|
2019-11-16 07:21:14 +00:00
|
|
|
}
|