2017-09-14 22:21:00 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Seeds;
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
use App\Abstracts\Model;
|
2019-11-18 10:54:26 +03:00
|
|
|
use App\Jobs\Auth\CreateUser;
|
2019-12-22 18:57:04 +03:00
|
|
|
use App\Jobs\Common\CreateCompany;
|
2020-01-07 15:41:47 +03:00
|
|
|
use App\Jobs\Common\CreateContact;
|
2019-11-18 10:54:26 +03:00
|
|
|
use App\Traits\Jobs;
|
2020-03-27 17:18:50 +03:00
|
|
|
use Artisan;
|
2017-09-14 22:21:00 +03:00
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class TestCompany extends Seeder
|
|
|
|
{
|
2019-11-18 10:54:26 +03:00
|
|
|
use Jobs;
|
|
|
|
|
2017-09-14 22:21:00 +03:00
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
Model::unguard();
|
|
|
|
|
2020-02-06 17:24:23 +03:00
|
|
|
$this->call(Permissions::class);
|
2017-09-14 22:21:00 +03:00
|
|
|
|
|
|
|
$this->createCompany();
|
|
|
|
|
|
|
|
$this->createUser();
|
|
|
|
|
2020-03-27 17:18:50 +03:00
|
|
|
$this->createCustomer();
|
|
|
|
|
|
|
|
$this->installModules();
|
2020-01-07 15:41:47 +03:00
|
|
|
|
2017-09-14 22:21:00 +03:00
|
|
|
Model::reguard();
|
|
|
|
}
|
|
|
|
|
|
|
|
private function createCompany()
|
|
|
|
{
|
2020-01-07 18:14:28 +03:00
|
|
|
$company = $this->dispatch(new CreateCompany([
|
2019-12-22 18:57:04 +03:00
|
|
|
'name' => 'My Company',
|
2020-06-09 04:27:15 +03:00
|
|
|
'email' => 'test@company.com',
|
2019-12-22 18:57:04 +03:00
|
|
|
'domain' => 'company.com',
|
|
|
|
'address' => 'New Street 1254',
|
|
|
|
'currency' => 'USD',
|
|
|
|
'locale' => 'en-GB',
|
|
|
|
'enabled' => '1',
|
|
|
|
'settings' => [
|
2019-12-22 19:15:58 +03:00
|
|
|
'schedule.send_invoice_reminder' => '1',
|
|
|
|
'schedule.send_bill_reminder' => '1',
|
2019-12-22 19:27:10 +03:00
|
|
|
'wizard.completed' => '1',
|
2021-04-18 01:39:36 +03:00
|
|
|
'email.protocol' => 'array',
|
2019-12-22 18:57:04 +03:00
|
|
|
],
|
2021-09-10 00:31:39 +03:00
|
|
|
'created_from' => 'core::seed',
|
2019-12-22 18:57:04 +03:00
|
|
|
]));
|
2017-09-14 22:21:00 +03:00
|
|
|
|
2021-04-18 01:39:36 +03:00
|
|
|
$company->makeCurrent(true);
|
2021-02-13 11:10:42 +03:00
|
|
|
|
2022-06-01 10:15:55 +03:00
|
|
|
setting()->set('email.protocol', 'log');
|
|
|
|
config(['mail.default' => setting('email.protocol')]);
|
|
|
|
|
2017-09-14 22:21:00 +03:00
|
|
|
$this->command->info('Test company created.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createUser()
|
|
|
|
{
|
2020-01-07 18:14:28 +03:00
|
|
|
$this->dispatch(new CreateUser([
|
2019-12-22 18:57:04 +03:00
|
|
|
'name' => 'Test User',
|
2019-11-18 10:54:26 +03:00
|
|
|
'email' => 'test@company.com',
|
2017-09-14 22:21:00 +03:00
|
|
|
'password' => '123456',
|
2019-11-18 10:54:26 +03:00
|
|
|
'locale' => 'en-GB',
|
2021-04-16 00:59:43 +03:00
|
|
|
'companies' => [company_id()],
|
2019-11-18 10:54:26 +03:00
|
|
|
'roles' => ['1'],
|
|
|
|
'enabled' => '1',
|
|
|
|
]));
|
2019-11-17 15:06:00 +03:00
|
|
|
|
2019-11-18 10:54:26 +03:00
|
|
|
$this->command->info('Test user created.');
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|
2020-01-07 15:41:47 +03:00
|
|
|
|
2020-03-27 17:18:50 +03:00
|
|
|
private function createCustomer()
|
2020-01-07 15:41:47 +03:00
|
|
|
{
|
|
|
|
$this->dispatch(new CreateContact([
|
|
|
|
'type' => 'customer',
|
2020-03-27 17:18:50 +03:00
|
|
|
'name' => 'Test Customer',
|
|
|
|
'email' => 'customer@company.com',
|
2022-10-05 10:35:19 +03:00
|
|
|
'currency_code' => default_currency(),
|
2020-01-07 15:41:47 +03:00
|
|
|
'password' => '123456',
|
|
|
|
'password_confirmation' => '123456',
|
2021-04-16 00:59:43 +03:00
|
|
|
'company_id' => company_id(),
|
2020-01-07 15:41:47 +03:00
|
|
|
'enabled' => '1',
|
2020-06-09 04:31:53 +03:00
|
|
|
'create_user' => 'true',
|
2020-01-07 15:41:47 +03:00
|
|
|
]));
|
|
|
|
|
2020-03-27 17:18:50 +03:00
|
|
|
$this->command->info('Test customer created.');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function installModules()
|
|
|
|
{
|
|
|
|
$core_modules = ['offline-payments', 'paypal-standard'];
|
|
|
|
|
|
|
|
$modules = module()->all();
|
|
|
|
|
|
|
|
foreach ($modules as $module) {
|
|
|
|
$alias = $module->getAlias();
|
|
|
|
|
|
|
|
if (in_array($alias, $core_modules)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Artisan::call('module:install', [
|
|
|
|
'alias' => $alias,
|
2021-04-16 00:59:43 +03:00
|
|
|
'company' => company_id(),
|
2021-06-15 14:46:18 +03:00
|
|
|
'locale' => session('locale', company(company_id())->locale),
|
2020-03-27 17:18:50 +03:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->command->info('Modules installed.');
|
2020-01-07 15:41:47 +03:00
|
|
|
}
|
2017-09-14 22:21:00 +03:00
|
|
|
}
|