2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
trait Contacts
|
|
|
|
{
|
2020-06-08 23:09:43 +03:00
|
|
|
public function isCustomer()
|
2019-11-16 10:21:14 +03:00
|
|
|
{
|
2021-10-05 13:26:27 +03:00
|
|
|
$type = $this->type ?? $this->contact->type ?? $this->model->type ?? 'customer';
|
2020-06-08 23:40:04 +03:00
|
|
|
|
|
|
|
return in_array($type, $this->getCustomerTypes());
|
2020-06-08 23:09:43 +03:00
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-08 23:09:43 +03:00
|
|
|
public function isVendor()
|
|
|
|
{
|
2021-10-05 13:26:27 +03:00
|
|
|
$type = $this->type ?? $this->contact->type ?? $this->model->type ?? 'vendor';
|
2020-06-08 23:40:04 +03:00
|
|
|
|
|
|
|
return in_array($type, $this->getVendorTypes());
|
2020-06-08 23:09:43 +03:00
|
|
|
}
|
|
|
|
|
2023-04-24 11:02:45 +03:00
|
|
|
public function isEmployee()
|
|
|
|
{
|
|
|
|
$type = $this->type ?? $this->contact->type ?? $this->model->type ?? 'employee';
|
|
|
|
|
|
|
|
return in_array($type, $this->getEmployeeTypes());
|
|
|
|
}
|
|
|
|
|
2020-06-08 23:09:43 +03:00
|
|
|
public function getCustomerTypes($return = 'array')
|
|
|
|
{
|
|
|
|
return $this->getContactTypes('customer', $return);
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getVendorTypes($return = 'array')
|
|
|
|
{
|
2020-06-08 23:09:43 +03:00
|
|
|
return $this->getContactTypes('vendor', $return);
|
|
|
|
}
|
|
|
|
|
2023-04-24 11:02:45 +03:00
|
|
|
public function getEmployeeTypes($return = 'array')
|
|
|
|
{
|
|
|
|
return $this->getContactTypes('employee', $return);
|
|
|
|
}
|
|
|
|
|
2020-06-08 23:09:43 +03:00
|
|
|
public function getContactTypes($index, $return = 'array')
|
|
|
|
{
|
2020-08-26 15:14:16 +03:00
|
|
|
$types = (string) setting('contact.type.' . $index);
|
2019-11-16 10:21:14 +03:00
|
|
|
|
|
|
|
return ($return == 'array') ? explode(',', $types) : $types;
|
|
|
|
}
|
2020-01-22 21:24:00 +03:00
|
|
|
|
2020-01-22 21:37:01 +03:00
|
|
|
public function addCustomerType($new_type)
|
2020-01-22 21:24:00 +03:00
|
|
|
{
|
2020-06-08 23:09:43 +03:00
|
|
|
$this->addContactType($new_type, 'customer');
|
2020-01-22 21:24:00 +03:00
|
|
|
}
|
|
|
|
|
2020-01-22 21:37:01 +03:00
|
|
|
public function addVendorType($new_type)
|
2020-01-22 21:24:00 +03:00
|
|
|
{
|
2020-06-08 23:09:43 +03:00
|
|
|
$this->addContactType($new_type, 'vendor');
|
2020-01-22 21:24:00 +03:00
|
|
|
}
|
|
|
|
|
2023-04-24 11:02:45 +03:00
|
|
|
public function addEmployeeType($new_type)
|
|
|
|
{
|
|
|
|
$this->addContactType($new_type, 'employee');
|
|
|
|
}
|
|
|
|
|
2020-06-08 23:09:43 +03:00
|
|
|
public function addContactType($new_type, $index)
|
2020-01-22 21:24:00 +03:00
|
|
|
{
|
2020-08-26 15:14:16 +03:00
|
|
|
$types = explode(',', setting('contact.type.' . $index));
|
2020-01-22 21:24:00 +03:00
|
|
|
|
|
|
|
if (in_array($new_type, $types)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$types[] = $new_type;
|
|
|
|
|
|
|
|
setting([
|
|
|
|
'contact.type.' . $index => implode(',', $types),
|
|
|
|
])->save();
|
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|