1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Models/Company.php

234 lines
4.8 KiB
PHP
Raw Normal View History

2019-04-18 07:01:40 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Models;
use App\DataMapper\CompanySettings;
use App\Models\Account;
use App\Models\Client;
use App\Models\CompanyGateway;
2019-06-24 13:05:47 +02:00
use App\Models\CompanyUser;
use App\Models\Country;
use App\Models\Currency;
use App\Models\Expense;
2019-09-10 04:30:43 +02:00
use App\Models\GroupSetting;
use App\Models\Industry;
use App\Models\Invoice;
use App\Models\Language;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\Product;
use App\Models\TaxRate;
use App\Models\Timezone;
use App\Models\Traits\AccountTrait;
use App\Models\User;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
2019-04-18 13:57:22 +02:00
use Illuminate\Support\Facades\Log;
use Laracasts\Presenter\PresentableTrait;
class Company extends BaseModel
{
use PresentableTrait;
use MakesHash;
protected $presenter = 'App\Models\Presenters\CompanyPresenter';
2019-06-17 02:15:42 +02:00
protected $fillable = [
'name',
2019-06-26 05:25:14 +02:00
'logo',
'industry_id',
'address1',
'address2',
'city',
'state',
'postal_code',
'work_phone',
'work_email',
'country_id',
'domain',
'vat_number',
'id_number',
'size_id',
'settings',
];
2019-07-30 00:28:38 +02:00
protected $hidden = [
'id',
'settings',
'account_id',
'company_key',
'db',
'domain',
'ip',
2019-08-21 06:29:07 +02:00
'industry_id',
'size_id',
];
protected $casts = [
'settings' => 'object'
];
2019-04-25 09:16:41 +02:00
protected $with = [
// 'tokens'
];
public function getCompanyIdAttribute()
{
return $this->encodePrimaryKey($this->id);
}
public function account()
{
return $this->belongsTo(Account::class);
}
public function users()
{
2019-06-24 13:05:47 +02:00
return $this->hasMany(CompanyUser::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function clients()
{
return $this->hasMany(Client::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function contacts()
{
2019-07-08 02:08:57 +02:00
return $this->hasMany(ClientContact::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function invoices()
{
return $this->hasMany(Invoice::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function company_gateways()
{
2019-09-09 04:19:19 +02:00
return $this->hasMany(CompanyGateway::class)->orderBy('sort_id','ASC');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function tax_rates()
{
return $this->hasMany(TaxRate::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function products()
{
return $this->hasMany(Product::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function country()
{
return $this->belongsTo(Country::class);
}
2019-09-10 04:30:43 +02:00
public function group_settings()
{
return $this->hasMany(GroupSetting::class);
}
/**
2019-04-30 08:02:39 +02:00
*
*/
public function timezone()
{
2019-04-30 08:02:39 +02:00
return Timezone::find($this->settings->timezone_id);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function language()
{
2019-04-30 08:02:39 +02:00
return Language::find($this->settings->language_id);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function currency()
{
return $this->belongsTo(Currency::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function industry()
{
return $this->belongsTo(Industry::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function payment_type()
{
return $this->belongsTo(PaymentType::class);
}
/**
* @return mixed
*/
public function expenses()
{
return $this->hasMany(Expense::class, 'account_id', 'id')->withTrashed();
}
/**
* @return mixed
*/
public function payments()
{
return $this->hasMany(Payment::class, 'account_id', 'id')->withTrashed();
}
2019-03-26 05:46:08 +01:00
public function tokens()
{
return $this->hasMany(CompanyToken::class);
}
2019-03-27 07:22:27 +01:00
public function company_users()
{
return $this->hasMany(CompanyUser::class);
}
2019-04-18 13:57:22 +02:00
public function owner()
{
$c = $this->company_users->where('is_owner',true)->first();
return User::find($c->user_id);
}
}