1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00
invoiceninja/app/Models/LookupAccount.php

53 lines
1.2 KiB
PHP
Raw Normal View History

2017-04-30 19:08:49 +02:00
<?php
namespace App\Models;
use Eloquent;
/**
* Class ExpenseCategory.
*/
2017-04-30 21:18:17 +02:00
class LookupAccount extends LookupModel
2017-04-30 19:08:49 +02:00
{
/**
* @var array
*/
protected $fillable = [
'lookup_company_id',
'account_key',
];
2017-04-30 21:52:05 +02:00
public function lookupCompany()
{
return $this->belongsTo('App\Models\LookupCompany');
}
2017-05-01 10:13:15 +02:00
public static function createAccount($accountKey, $companyId)
{
if (! env('MULTI_DB_ENABLED')) {
return;
}
$current = config('database.default');
config(['database.default' => DB_NINJA_LOOKUP]);
2017-05-01 14:46:57 +02:00
2017-05-01 10:13:15 +02:00
$server = DbServer::whereName($current)->firstOrFail();
$lookupCompany = LookupCompany::whereDbServerId($server->id)
->whereCompanyId($companyId)->first();
if (! $lookupCompany) {
$lookupCompany = LookupCompany::create([
'db_server_id' => $server->id,
'company_id' => $companyId,
]);
}
LookupAccount::create([
'lookup_company_id' => $lookupCompany->id,
'account_key' => $accountKey,
]);
static::setDbServer($current);
}
2017-04-30 19:08:49 +02:00
}