2020-02-24 22:17:16 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Migration;
|
|
|
|
|
2020-11-10 16:20:02 +01:00
|
|
|
use App\Models\Account;
|
2020-02-24 22:17:16 +01:00
|
|
|
|
|
|
|
class CompanyService
|
|
|
|
{
|
|
|
|
protected $isSuccessful;
|
|
|
|
protected $companies = [];
|
|
|
|
|
|
|
|
public function start()
|
|
|
|
{
|
2020-11-10 16:20:02 +01:00
|
|
|
try {
|
2020-11-19 12:29:49 +01:00
|
|
|
if (session(SESSION_USER_ACCOUNTS)) {
|
|
|
|
foreach (session(SESSION_USER_ACCOUNTS) as $company) {
|
|
|
|
$account = Account::find($company->account_id);
|
|
|
|
|
|
|
|
if ($account) {
|
|
|
|
$this->companies[] = [
|
|
|
|
'id' => $account->id,
|
|
|
|
'name' => $account->present()->name(),
|
|
|
|
'company_key' => $account->account_key,
|
|
|
|
];
|
|
|
|
}
|
2020-11-10 16:20:02 +01:00
|
|
|
}
|
2020-11-19 12:29:49 +01:00
|
|
|
} else {
|
|
|
|
$this->companies[] = [
|
|
|
|
'id' => auth()->user()->account->id,
|
|
|
|
'name' => auth()->user()->account->present()->name(),
|
|
|
|
'company_key' => auth()->user()->account->account_key,
|
|
|
|
];
|
2020-02-24 22:17:16 +01:00
|
|
|
}
|
|
|
|
|
2020-11-10 16:20:02 +01:00
|
|
|
$this->isSuccessful = true;
|
|
|
|
} catch (\Exception $th) {
|
2020-02-24 22:17:16 +01:00
|
|
|
$this->isSuccessful = false;
|
2020-11-10 16:20:02 +01:00
|
|
|
$this->errors = [];
|
2020-02-24 22:17:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function isSuccessful()
|
|
|
|
{
|
|
|
|
return $this->isSuccessful;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCompanies()
|
|
|
|
{
|
|
|
|
if ($this->isSuccessful) {
|
|
|
|
return $this->companies;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getErrors()
|
|
|
|
{
|
|
|
|
return $this->errors;
|
|
|
|
}
|
|
|
|
}
|