2021-03-03 22:30:11 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-03-03 22:30:11 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-03-03 22:30:11 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
2023-02-09 02:30:35 +01:00
|
|
|
use App\DataMapper\ClientRegistrationFields;
|
2021-03-03 22:30:11 +01:00
|
|
|
use App\DataMapper\CompanySettings;
|
|
|
|
use App\Jobs\Company\CreateCompanyPaymentTerms;
|
|
|
|
use App\Jobs\Company\CreateCompanyTaskStatuses;
|
|
|
|
use App\Jobs\Util\VersionCheck;
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\CompanyToken;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
class CreateAccount extends Command
|
|
|
|
{
|
2024-01-14 05:05:00 +01:00
|
|
|
use MakesHash;
|
|
|
|
use GeneratesCounter;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-03-03 22:30:11 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Create Single Account';
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-03-03 22:30:11 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'ninja:create-account {--email=} {--password=}';
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$this->info(date('r').' Create Single Account...');
|
|
|
|
|
|
|
|
$this->createAccount();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createAccount()
|
|
|
|
{
|
2023-10-10 12:00:38 +02:00
|
|
|
$settings = CompanySettings::defaults();
|
|
|
|
|
|
|
|
$settings->name = "Untitled Company";
|
|
|
|
$settings->currency_id = '1';
|
|
|
|
$settings->language_id = '1';
|
|
|
|
|
2021-03-03 22:30:11 +01:00
|
|
|
$account = Account::factory()->create();
|
|
|
|
$company = Company::factory()->create([
|
|
|
|
'account_id' => $account->id,
|
2021-07-21 01:21:46 +02:00
|
|
|
'portal_domain' => config('ninja.app_url'),
|
|
|
|
'portal_mode' => 'domain',
|
2023-10-10 12:00:38 +02:00
|
|
|
'settings' => $settings,
|
2021-03-03 22:30:11 +01:00
|
|
|
]);
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-02-09 02:30:35 +01:00
|
|
|
$company->client_registration_fields = ClientRegistrationFields::generate();
|
|
|
|
$company->save();
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2021-03-03 22:30:11 +01:00
|
|
|
$account->default_company_id = $company->id;
|
2023-10-10 05:37:53 +02:00
|
|
|
$account->set_react_as_default_ap = true;
|
2021-03-03 22:30:11 +01:00
|
|
|
$account->save();
|
|
|
|
|
|
|
|
$email = $this->option('email') ?? 'admin@example.com';
|
|
|
|
$password = $this->option('password') ?? 'changeme!';
|
|
|
|
|
|
|
|
$user = User::factory()->create([
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'email' => $email,
|
|
|
|
'password' => Hash::make($password),
|
|
|
|
'confirmation_code' => $this->createDbHash(config('database.default')),
|
|
|
|
'email_verified_at' => now(),
|
2021-05-13 12:18:30 +02:00
|
|
|
'first_name' => 'New',
|
|
|
|
'last_name' => 'User',
|
|
|
|
'phone' => '',
|
2021-03-03 22:30:11 +01:00
|
|
|
]);
|
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
$company_token = new CompanyToken();
|
2021-03-03 22:30:11 +01:00
|
|
|
$company_token->user_id = $user->id;
|
|
|
|
$company_token->company_id = $company->id;
|
|
|
|
$company_token->account_id = $account->id;
|
|
|
|
$company_token->name = 'User Token';
|
|
|
|
$company_token->token = Str::random(64);
|
|
|
|
$company_token->is_system = true;
|
|
|
|
|
|
|
|
$company_token->save();
|
|
|
|
|
|
|
|
$user->companies()->attach($company->id, [
|
|
|
|
'account_id' => $account->id,
|
|
|
|
'is_owner' => 1,
|
|
|
|
'is_admin' => 1,
|
|
|
|
'is_locked' => 0,
|
|
|
|
'notifications' => CompanySettings::notificationDefaults(),
|
|
|
|
'settings' => null,
|
|
|
|
]);
|
|
|
|
|
2022-08-01 09:43:26 +02:00
|
|
|
(new CreateCompanyPaymentTerms($company, $user))->handle();
|
|
|
|
(new CreateCompanyTaskStatuses($company, $user))->handle();
|
|
|
|
(new VersionCheck())->handle();
|
2023-01-17 05:39:20 +01:00
|
|
|
|
2021-03-03 22:30:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|