akaunting/app/Traits/Contacts.php

63 lines
1.4 KiB
PHP
Raw Normal View History

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
{
2020-06-08 23:40:04 +03:00
$type = $this->type ?? $this->contact->type ?? 'customer';
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()
{
2020-06-08 23:40:04 +03:00
$type = $this->type ?? $this->contact->type ?? 'vendor';
return in_array($type, $this->getVendorTypes());
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);
}
public function getContactTypes($index, $return = 'array')
{
$types = (string) setting('contact.type.' . $index, $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
}
2020-06-08 23:09:43 +03:00
public function addContactType($new_type, $index)
2020-01-22 21:24:00 +03:00
{
$types = explode(',', setting('contact.type.' . $index, $index));
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
}