2019-04-18 07:01:40 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2018-10-22 14:04:37 +02:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
use App\Models\Presenters\CompanyPresenter;
|
2021-05-13 14:41:32 +02:00
|
|
|
use App\Models\User;
|
2020-02-24 11:15:30 +01:00
|
|
|
use App\Services\Notification\NotificationService;
|
2019-11-20 21:55:16 +01:00
|
|
|
use App\Utils\Ninja;
|
2019-11-12 22:26:40 +01:00
|
|
|
use App\Utils\Traits\CompanySettingsSaver;
|
2018-11-20 05:36:56 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-11-25 10:38:55 +01:00
|
|
|
use App\Utils\Traits\ThrottlesEmail;
|
2020-10-28 11:10:49 +01:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2020-02-24 11:15:30 +01:00
|
|
|
use Illuminate\Notifications\Notification;
|
2021-03-17 16:12:25 +01:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2021-05-13 14:41:32 +02:00
|
|
|
use Laracasts\Presenter\PresentableTrait;
|
2018-10-22 14:04:37 +02:00
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
class Company extends BaseModel
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
2018-11-02 11:54:46 +01:00
|
|
|
use PresentableTrait;
|
2018-11-20 05:36:56 +01:00
|
|
|
use MakesHash;
|
2019-11-12 22:26:40 +01:00
|
|
|
use CompanySettingsSaver;
|
2019-11-25 10:38:55 +01:00
|
|
|
use ThrottlesEmail;
|
2020-02-15 10:06:30 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
const ENTITY_RECURRING_INVOICE = 'recurring_invoice';
|
|
|
|
const ENTITY_CREDIT = 'credit';
|
|
|
|
const ENTITY_QUOTE = 'quote';
|
|
|
|
const ENTITY_TASK = 'task';
|
|
|
|
const ENTITY_EXPENSE = 'expense';
|
|
|
|
const ENTITY_PROJECT = 'project';
|
|
|
|
const ENTITY_VENDOR = 'vendor';
|
|
|
|
const ENTITY_TICKET = 'ticket';
|
|
|
|
const ENTITY_PROPOSAL = 'proposal';
|
|
|
|
const ENTITY_RECURRING_EXPENSE = 'recurring_expense';
|
|
|
|
const ENTITY_RECURRING_TASK = 'task';
|
|
|
|
const ENTITY_RECURRING_QUOTE = 'recurring_quote';
|
2020-03-03 10:44:26 +01:00
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
protected $presenter = CompanyPresenter::class;
|
2018-11-02 11:54:46 +01:00
|
|
|
|
2019-06-17 02:15:42 +02:00
|
|
|
protected $fillable = [
|
2021-01-05 03:24:32 +01:00
|
|
|
'calculate_expense_tax_by_amount',
|
2020-10-29 00:11:52 +01:00
|
|
|
'invoice_expense_documents',
|
|
|
|
'invoice_task_documents',
|
2020-10-28 06:50:06 +01:00
|
|
|
'show_tasks_table',
|
2020-10-14 23:25:40 +02:00
|
|
|
'mark_expenses_invoiceable',
|
|
|
|
'mark_expenses_paid',
|
2020-06-24 01:18:38 +02:00
|
|
|
'enabled_item_tax_rates',
|
2019-11-22 22:10:53 +01:00
|
|
|
'fill_products',
|
2019-06-26 06:04:10 +02:00
|
|
|
'industry_id',
|
2019-12-10 21:53:41 +01:00
|
|
|
'subdomain',
|
2019-06-26 06:04:10 +02:00
|
|
|
'size_id',
|
2019-10-10 04:52:57 +02:00
|
|
|
'custom_fields',
|
2019-11-12 12:36:24 +01:00
|
|
|
'enable_product_cost',
|
|
|
|
'enable_product_quantity',
|
2020-02-26 04:26:07 +01:00
|
|
|
'enabled_modules',
|
2019-11-12 12:36:24 +01:00
|
|
|
'default_quantity',
|
2019-11-21 09:38:57 +01:00
|
|
|
'enabled_tax_rates',
|
|
|
|
'portal_mode',
|
|
|
|
'portal_domain',
|
|
|
|
'convert_products',
|
|
|
|
'update_products',
|
|
|
|
'custom_surcharge_taxes1',
|
|
|
|
'custom_surcharge_taxes2',
|
|
|
|
'custom_surcharge_taxes3',
|
|
|
|
'custom_surcharge_taxes4',
|
2019-12-26 23:33:07 +01:00
|
|
|
'show_product_details',
|
2020-02-25 09:33:53 +01:00
|
|
|
'first_day_of_week',
|
|
|
|
'first_month_of_year',
|
2020-02-28 22:57:47 +01:00
|
|
|
'slack_webhook_url',
|
2020-04-09 14:04:26 +02:00
|
|
|
'google_analytics_key',
|
2020-06-28 12:38:41 +02:00
|
|
|
'client_can_register',
|
2020-07-29 11:25:59 +02:00
|
|
|
'enable_shop_api',
|
2020-10-26 21:46:06 +01:00
|
|
|
'invoice_task_timelog',
|
|
|
|
'auto_start_tasks',
|
2020-11-01 06:18:40 +01:00
|
|
|
'is_disabled',
|
2020-12-14 22:52:14 +01:00
|
|
|
'default_task_is_date_based',
|
2020-12-17 11:53:20 +01:00
|
|
|
'enable_product_discount',
|
2021-01-08 11:27:49 +01:00
|
|
|
'expense_inclusive_taxes',
|
2021-02-15 22:52:38 +01:00
|
|
|
'session_timeout',
|
|
|
|
'oauth_password_required',
|
2021-02-27 11:08:39 +01:00
|
|
|
'invoice_task_datelog',
|
2021-03-09 11:34:39 +01:00
|
|
|
'default_password_timeout',
|
2021-05-06 23:12:07 +02:00
|
|
|
'show_task_end_date',
|
2018-10-22 14:04:37 +02:00
|
|
|
];
|
|
|
|
|
2019-07-30 00:28:38 +02:00
|
|
|
protected $hidden = [
|
|
|
|
'id',
|
|
|
|
'db',
|
|
|
|
'ip',
|
2019-03-02 22:44:08 +01:00
|
|
|
];
|
2019-02-17 11:34:46 +01:00
|
|
|
|
|
|
|
protected $casts = [
|
2019-11-10 13:06:30 +01:00
|
|
|
'country_id' => 'string',
|
|
|
|
'custom_fields' => 'object',
|
2019-09-26 00:27:26 +02:00
|
|
|
'settings' => 'object',
|
|
|
|
'updated_at' => 'timestamp',
|
|
|
|
'created_at' => 'timestamp',
|
|
|
|
'deleted_at' => 'timestamp',
|
2019-02-17 11:34:46 +01:00
|
|
|
];
|
|
|
|
|
2019-04-25 09:16:41 +02:00
|
|
|
protected $with = [
|
|
|
|
// 'tokens'
|
|
|
|
];
|
|
|
|
|
2020-03-03 10:44:26 +01:00
|
|
|
public static $modules = [
|
|
|
|
self::ENTITY_RECURRING_INVOICE => 1,
|
|
|
|
self::ENTITY_CREDIT => 2,
|
|
|
|
self::ENTITY_QUOTE => 4,
|
|
|
|
self::ENTITY_TASK => 8,
|
|
|
|
self::ENTITY_EXPENSE => 16,
|
|
|
|
self::ENTITY_PROJECT => 32,
|
|
|
|
self::ENTITY_VENDOR => 64,
|
|
|
|
self::ENTITY_TICKET => 128,
|
|
|
|
self::ENTITY_PROPOSAL => 256,
|
|
|
|
self::ENTITY_RECURRING_EXPENSE => 512,
|
|
|
|
self::ENTITY_RECURRING_TASK => 1024,
|
2020-03-08 10:06:21 +01:00
|
|
|
self::ENTITY_RECURRING_QUOTE => 2048,
|
2020-03-03 10:44:26 +01:00
|
|
|
];
|
|
|
|
|
2020-06-24 10:59:56 +02:00
|
|
|
public function documents()
|
|
|
|
{
|
|
|
|
return $this->morphMany(Document::class, 'documentable');
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-05-06 13:49:42 +02:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
return self::class;
|
2020-05-06 13:49:42 +02:00
|
|
|
}
|
|
|
|
|
2020-04-11 13:19:05 +02:00
|
|
|
public function ledger()
|
|
|
|
{
|
|
|
|
return $this->hasMany(CompanyLedger::class);
|
|
|
|
}
|
|
|
|
|
2018-11-20 05:36:56 +01:00
|
|
|
public function getCompanyIdAttribute()
|
|
|
|
{
|
|
|
|
return $this->encodePrimaryKey($this->id);
|
|
|
|
}
|
2018-10-22 14:04:37 +02:00
|
|
|
|
|
|
|
public function account()
|
|
|
|
{
|
2018-11-02 11:54:46 +01:00
|
|
|
return $this->belongsTo(Account::class);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
2021-05-13 05:32:36 +02:00
|
|
|
public function client_contacts()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ClientContact::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
public function users()
|
|
|
|
{
|
2020-01-07 10:35:55 +01:00
|
|
|
return $this->hasManyThrough(User::class, CompanyUser::class, 'company_id', 'id', 'id', 'user_id');
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
2020-10-25 21:56:02 +01:00
|
|
|
public function expense_categories()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ExpenseCategory::class)->withTrashed();
|
|
|
|
}
|
2021-03-25 11:55:59 +01:00
|
|
|
|
|
|
|
public function subscriptions()
|
2021-03-10 01:08:58 +01:00
|
|
|
{
|
2021-03-25 11:55:59 +01:00
|
|
|
return $this->hasMany(Subscription::class)->withTrashed();
|
2021-03-10 01:08:58 +01:00
|
|
|
}
|
|
|
|
|
2020-10-25 21:56:02 +01:00
|
|
|
public function task_statuses()
|
|
|
|
{
|
|
|
|
return $this->hasMany(TaskStatus::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
public function clients()
|
|
|
|
{
|
2019-11-25 10:38:55 +01:00
|
|
|
return $this->hasMany(Client::class)->withTrashed();
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
2020-01-21 01:32:34 +01:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2020-01-21 01:32:34 +01:00
|
|
|
*/
|
|
|
|
public function tasks()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Task::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2020-07-07 00:35:28 +02:00
|
|
|
public function webhooks()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Webhook::class);
|
|
|
|
}
|
|
|
|
|
2020-01-21 01:32:34 +01:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2020-01-21 01:32:34 +01:00
|
|
|
*/
|
|
|
|
public function projects()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Project::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2020-01-20 02:31:58 +01:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2020-01-20 02:31:58 +01:00
|
|
|
*/
|
|
|
|
public function vendors()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Vendor::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2021-05-13 05:32:36 +02:00
|
|
|
public function all_activities()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Activity::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-27 10:47:59 +01:00
|
|
|
public function activities()
|
|
|
|
{
|
2020-06-24 01:18:38 +02:00
|
|
|
return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(300);
|
2019-11-27 10:47:59 +01:00
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
|
|
|
public function contacts()
|
|
|
|
{
|
2019-07-08 02:08:57 +02:00
|
|
|
return $this->hasMany(ClientContact::class);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-22 12:41:43 +02:00
|
|
|
public function groups()
|
|
|
|
{
|
|
|
|
return $this->hasMany(GroupSetting::class);
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
|
|
|
public function invoices()
|
|
|
|
{
|
2019-11-25 10:38:55 +01:00
|
|
|
return $this->hasMany(Invoice::class)->withTrashed();
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
2020-09-10 03:05:42 +02:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2020-09-10 03:05:42 +02:00
|
|
|
*/
|
|
|
|
public function recurring_invoices()
|
|
|
|
{
|
|
|
|
return $this->hasMany(RecurringInvoice::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2019-12-25 13:22:10 +01:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2019-12-25 13:22:10 +01:00
|
|
|
*/
|
|
|
|
public function quotes()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Quote::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2019-12-25 13:22:10 +01:00
|
|
|
*/
|
|
|
|
public function credits()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Credit::class)->withTrashed();
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
2019-08-22 03:58:42 +02:00
|
|
|
public function company_gateways()
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
2019-11-11 13:21:19 +01:00
|
|
|
return $this->hasMany(CompanyGateway::class);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
|
|
|
public function tax_rates()
|
|
|
|
{
|
|
|
|
return $this->hasMany(TaxRate::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return HasMany
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
|
|
|
public function products()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Product::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return BelongsTo
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
|
|
|
public function country()
|
|
|
|
{
|
2021-03-17 16:12:25 +01:00
|
|
|
// return $this->belongsTo(Country::class);
|
2019-10-04 14:37:40 +02:00
|
|
|
return Country::find($this->settings->country_id);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-10 04:30:43 +02:00
|
|
|
public function group_settings()
|
|
|
|
{
|
|
|
|
return $this->hasMany(GroupSetting::class);
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
public function timezone()
|
|
|
|
{
|
2019-04-30 08:02:39 +02:00
|
|
|
return Timezone::find($this->settings->timezone_id);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
2020-02-15 10:06:30 +01:00
|
|
|
public function designs()
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
return $this->hasMany(Design::class)->whereCompanyId($this->id)->orWhere('company_id', null);
|
2020-02-15 10:06:30 +01:00
|
|
|
}
|
|
|
|
|
2021-05-13 03:25:26 +02:00
|
|
|
public function user_designs()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Design::class);
|
|
|
|
}
|
|
|
|
|
2020-05-23 05:33:44 +02:00
|
|
|
public function payment_terms()
|
|
|
|
{
|
|
|
|
return $this->hasMany(PaymentTerm::class)->whereCompanyId($this->id)->orWhere('company_id', null);
|
|
|
|
}
|
|
|
|
|
2021-05-13 03:25:26 +02:00
|
|
|
public function user_payment_terms()
|
|
|
|
{
|
|
|
|
return $this->hasMany(PaymentTerm::class);
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return BelongsTo
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
|
|
|
public function language()
|
|
|
|
{
|
2019-04-30 08:02:39 +02:00
|
|
|
return Language::find($this->settings->language_id);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
2019-09-11 01:31:55 +02:00
|
|
|
public function getLocale()
|
|
|
|
{
|
|
|
|
return isset($this->settings->language_id) && $this->language() ? $this->language()->locale : config('ninja.i18n.locale');
|
|
|
|
}
|
|
|
|
|
2020-10-15 11:41:59 +02:00
|
|
|
public function getLogo() :?string
|
2019-10-03 07:17:57 +02:00
|
|
|
{
|
2019-10-11 06:30:26 +02:00
|
|
|
return $this->settings->company_logo ?: null;
|
2019-10-03 07:17:57 +02:00
|
|
|
}
|
|
|
|
|
2020-03-25 03:50:08 +01:00
|
|
|
public function locale()
|
|
|
|
{
|
|
|
|
return $this->getLocale();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSetting($setting)
|
|
|
|
{
|
|
|
|
if (property_exists($this->settings, $setting) != false) {
|
|
|
|
return $this->settings->{$setting};
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
public function currency()
|
|
|
|
{
|
2021-03-17 16:12:25 +01:00
|
|
|
$currencies = Cache::get('currencies');
|
|
|
|
|
|
|
|
return $currencies->filter(function ($item) {
|
|
|
|
return $item->id == $this->settings->currency_id;
|
|
|
|
})->first();
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return BelongsTo
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
|
|
|
public function industry()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Industry::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return BelongsTo
|
2018-10-22 14:04:37 +02:00
|
|
|
*/
|
|
|
|
public function payment_type()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(PaymentType::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function expenses()
|
|
|
|
{
|
2019-12-25 13:22:10 +01:00
|
|
|
return $this->hasMany(Expense::class)->withTrashed();
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function payments()
|
|
|
|
{
|
2019-12-25 13:22:10 +01:00
|
|
|
return $this->hasMany(Payment::class)->withTrashed();
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
2019-03-26 05:46:08 +01:00
|
|
|
public function tokens()
|
|
|
|
{
|
|
|
|
return $this->hasMany(CompanyToken::class);
|
|
|
|
}
|
|
|
|
|
2021-01-31 06:07:45 +01:00
|
|
|
public function client_gateway_tokens()
|
|
|
|
{
|
|
|
|
return $this->hasMany(ClientGatewayToken::class);
|
|
|
|
}
|
|
|
|
|
2020-08-24 04:45:53 +02:00
|
|
|
public function system_logs()
|
|
|
|
{
|
2021-03-30 00:32:33 +02:00
|
|
|
return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC')->take(100);
|
2020-08-24 04:45:53 +02:00
|
|
|
}
|
|
|
|
|
2021-01-06 22:27:59 +01:00
|
|
|
public function system_log_relation()
|
|
|
|
{
|
|
|
|
return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC');
|
|
|
|
}
|
|
|
|
|
2020-07-13 04:54:56 +02:00
|
|
|
public function tokens_hashed()
|
|
|
|
{
|
|
|
|
return $this->hasMany(CompanyToken::class);
|
|
|
|
}
|
|
|
|
|
2019-03-27 07:22:27 +01:00
|
|
|
public function company_users()
|
|
|
|
{
|
2020-02-24 11:15:30 +01:00
|
|
|
return $this->hasMany(CompanyUser::class);
|
2019-03-27 07:22:27 +01:00
|
|
|
}
|
|
|
|
|
2019-04-18 13:57:22 +02:00
|
|
|
public function owner()
|
2021-05-13 15:37:25 +02:00
|
|
|
{
|
|
|
|
return $this->company_users->where('is_owner', true)->first()->user;
|
2019-04-18 13:57:22 +02:00
|
|
|
}
|
|
|
|
|
2020-11-25 15:19:52 +01:00
|
|
|
public function resolveRouteBinding($value, $field = null)
|
2019-11-12 05:41:02 +01:00
|
|
|
{
|
2020-08-14 02:40:59 +02:00
|
|
|
return $this->where('id', $this->decodePrimaryKey($value))->firstOrFail();
|
2019-11-12 05:41:02 +01:00
|
|
|
}
|
2019-11-20 21:55:16 +01:00
|
|
|
|
2019-12-10 21:53:41 +01:00
|
|
|
public function domain()
|
|
|
|
{
|
2021-05-15 06:29:19 +02:00
|
|
|
if (Ninja::isHosted()) {
|
2021-04-28 05:40:11 +02:00
|
|
|
|
|
|
|
if($this->portal_mode == 'domain')
|
|
|
|
return $this->portal_domain;
|
|
|
|
|
2021-05-16 08:44:12 +02:00
|
|
|
return "https://{$this->subdomain}." . config('ninja.app_domain');
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-18 10:40:15 +01:00
|
|
|
|
|
|
|
return config('ninja.app_url');
|
2019-12-10 21:53:41 +01:00
|
|
|
}
|
2020-02-24 11:15:30 +01:00
|
|
|
|
|
|
|
public function notification(Notification $notification)
|
|
|
|
{
|
|
|
|
return new NotificationService($this, $notification);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function routeNotificationForSlack($notification)
|
|
|
|
{
|
2020-03-03 10:44:26 +01:00
|
|
|
return $this->slack_webhook_url;
|
2020-02-24 11:15:30 +01:00
|
|
|
}
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|