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-11 09:52:13 +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-05-11 09:52:13 +02:00
|
|
|
|
|
|
|
public function getDbServer()
|
|
|
|
{
|
|
|
|
return $this->lookupCompany->dbServer->name;
|
|
|
|
}
|
|
|
|
|
2017-04-30 19:08:49 +02:00
|
|
|
}
|