akaunting/app/Traits/Contacts.php

63 lines
1.4 KiB
PHP
Raw Normal View History

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
{
$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()
{
$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
}
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);
}
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
}
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();
}
2019-11-16 07:21:14 +00:00
}