akaunting/database/seeds/TestCompany.php

121 lines
3.0 KiB
PHP
Raw Permalink Normal View History

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