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
|
|
|
|
*/
|
2018-10-22 14:04:37 +02:00
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
use App\DataMapper\CompanySettings;
|
2019-01-25 11:47:23 +01:00
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Client;
|
2019-08-22 03:58:42 +02:00
|
|
|
use App\Models\CompanyGateway;
|
2019-06-24 13:05:47 +02:00
|
|
|
use App\Models\CompanyUser;
|
2019-01-25 11:47:23 +01:00
|
|
|
use App\Models\Country;
|
|
|
|
use App\Models\Currency;
|
|
|
|
use App\Models\Expense;
|
2019-09-10 04:30:43 +02:00
|
|
|
use App\Models\GroupSetting;
|
2019-01-25 11:47:23 +01:00
|
|
|
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;
|
2018-10-22 14:04:37 +02:00
|
|
|
use App\Models\Traits\AccountTrait;
|
2019-01-25 11:47:23 +01:00
|
|
|
use App\Models\User;
|
2019-10-10 04:24:19 +02:00
|
|
|
use App\Utils\Traits\SettingsSaver;
|
2018-11-20 05:36:56 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-04-18 13:57:22 +02:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2018-11-02 11:54:46 +01: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-10-10 04:24:19 +02:00
|
|
|
use SettingsSaver;
|
2019-10-09 14:21:21 +02:00
|
|
|
|
2018-11-02 11:54:46 +01:00
|
|
|
protected $presenter = 'App\Models\Presenters\CompanyPresenter';
|
|
|
|
|
2019-06-17 02:15:42 +02:00
|
|
|
protected $fillable = [
|
2019-10-04 14:37:40 +02:00
|
|
|
// 'name',
|
|
|
|
// 'logo',
|
2019-06-26 06:04:10 +02:00
|
|
|
'industry_id',
|
2019-10-04 14:37:40 +02:00
|
|
|
// 'address1',
|
|
|
|
// 'address2',
|
|
|
|
// 'city',
|
|
|
|
// 'state',
|
|
|
|
// 'postal_code',
|
|
|
|
// 'phone',
|
|
|
|
// 'email',
|
|
|
|
// 'country_id',
|
2019-07-12 07:03:30 +02:00
|
|
|
'domain',
|
2019-10-04 14:37:40 +02:00
|
|
|
// 'vat_number',
|
|
|
|
// 'id_number',
|
2019-06-26 06:04:10 +02:00
|
|
|
'size_id',
|
2019-10-09 23:36:50 +02:00
|
|
|
//'settings',
|
2019-10-10 04:52:57 +02:00
|
|
|
'custom_fields',
|
2018-10-22 14:04:37 +02:00
|
|
|
];
|
|
|
|
|
2019-07-30 00:28:38 +02:00
|
|
|
protected $hidden = [
|
|
|
|
'id',
|
2019-10-09 14:21:21 +02:00
|
|
|
// 'settings',
|
|
|
|
// 'account_id',
|
|
|
|
// 'company_key',
|
2019-07-30 00:28:38 +02:00
|
|
|
'db',
|
2019-10-09 14:21:21 +02:00
|
|
|
// 'domain',
|
2019-07-30 00:28:38 +02:00
|
|
|
'ip',
|
2019-10-09 14:21:21 +02:00
|
|
|
// 'industry_id',
|
|
|
|
// 'size_id',
|
2019-03-02 22:44:08 +01:00
|
|
|
];
|
2019-02-17 11:34:46 +01:00
|
|
|
|
|
|
|
protected $casts = [
|
2019-09-26 00:27:26 +02:00
|
|
|
'settings' => 'object',
|
2019-10-10 04:52:57 +02:00
|
|
|
'custom_fields' => 'object',
|
2019-09-26 00:27:26 +02:00
|
|
|
'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'
|
|
|
|
];
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
public function users()
|
|
|
|
{
|
2019-06-24 13:05:47 +02:00
|
|
|
return $this->hasMany(CompanyUser::class);
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
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
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
|
|
|
public function invoices()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Invoice::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
*/
|
2019-08-22 03:58:42 +02:00
|
|
|
public function company_gateways()
|
2018-10-22 14:04:37 +02:00
|
|
|
{
|
2019-09-10 11:35:18 +02:00
|
|
|
return $this->hasMany(CompanyGateway::class)->orderBy('priority_id','ASC');
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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()
|
|
|
|
{
|
2019-10-04 14:37:40 +02:00
|
|
|
//return $this->belongsTo(Country::class);
|
|
|
|
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
|
|
|
/**
|
2019-04-30 08:02:39 +02:00
|
|
|
*
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2019-10-03 07:17:57 +02:00
|
|
|
public function getLogo()
|
|
|
|
{
|
2019-10-11 06:30:26 +02:00
|
|
|
return $this->settings->company_logo ?: null;
|
2019-10-03 07:17:57 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:04:37 +02:00
|
|
|
}
|