akaunting/app/Traits/Contacts.php
2020-06-08 23:09:43 +03:00

59 lines
1.3 KiB
PHP

<?php
namespace App\Traits;
trait Contacts
{
public function isCustomer()
{
return in_array($this->type, $this->getCustomerTypes());
}
public function isVendor()
{
return in_array($this->type, $this->getVendorTypes());
}
public function getCustomerTypes($return = 'array')
{
return $this->getContactTypes('customer', $return);
}
public function getVendorTypes($return = 'array')
{
return $this->getContactTypes('vendor', $return);
}
public function getContactTypes($index, $return = 'array')
{
$types = (string) setting('contact.type.' . $index, $index);
return ($return == 'array') ? explode(',', $types) : $types;
}
public function addCustomerType($new_type)
{
$this->addContactType($new_type, 'customer');
}
public function addVendorType($new_type)
{
$this->addContactType($new_type, 'vendor');
}
public function addContactType($new_type, $index)
{
$types = explode(',', setting('contact.type.' . $index, $index));
if (in_array($new_type, $types)) {
return;
}
$types[] = $new_type;
setting([
'contact.type.' . $index => implode(',', $types),
])->save();
}
}