added class option to company seed

This commit is contained in:
denisdulici 2020-02-07 12:44:26 +03:00
parent ee33a211d8
commit 0f5bcfc5b2
6 changed files with 61 additions and 145 deletions

View File

@ -3,6 +3,7 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
class CompanySeed extends Command
{
@ -11,36 +12,39 @@ class CompanySeed extends Command
*
* @var string
*/
protected $signature = 'company:seed {company}';
protected $signature = 'company:seed {company} {--class= : with Fully Qualified Name}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Seed for specific company';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
protected $description = 'Run one or all seeds for a specific company';
/**
* Execute the console command.
*
* @return mixed
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function handle()
{
$class = $this->laravel->make('CompanySeeder');
$class_name = $this->input->getOption('class') ?? 'Database\Seeds\Company';
$seeder = $class->setContainer($this->laravel)->setCommand($this);
$class = $this->laravel->make($class_name);
$seeder->__invoke();
$class->setContainer($this->laravel)->setCommand($this)->__invoke();
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder', 'Database\Seeds\Company'],
];
}
}

View File

@ -37,10 +37,8 @@ class UserSeed extends Command
*/
public function handle()
{
$class = $this->laravel->make('UserSeeder');
$class = $this->laravel->make('Database\Seeds\User');
$seeder = $class->setContainer($this->laravel)->setCommand($this);
$seeder->__invoke();
$class->setContainer($this->laravel)->setCommand($this)->__invoke();
}
}

View File

@ -214,109 +214,18 @@ class Version200 extends Listener
public function createEmailTemplates($company)
{
$templates = [
[
'alias' => 'invoice_new_customer',
'class' => 'App\Notifications\Sale\Invoice',
'name' => 'settings.email.templates.invoice_new_customer',
],
[
'alias' => 'invoice_remind_customer',
'class' => 'App\Notifications\Sale\Invoice',
'name' => 'settings.email.templates.invoice_remind_customer',
],
[
'alias' => 'invoice_remind_admin',
'class' => 'App\Notifications\Sale\Invoice',
'name' => 'settings.email.templates.invoice_remind_admin',
],
[
'alias' => 'invoice_recur_customer',
'class' => 'App\Notifications\Sale\Invoice',
'name' => 'settings.email.templates.invoice_recur_customer',
],
[
'alias' => 'invoice_recur_admin',
'class' => 'App\Notifications\Sale\Invoice',
'name' => 'settings.email.templates.invoice_recur_admin',
],
[
'alias' => 'invoice_payment_customer',
'class' => 'App\Notifications\Portal\PaymentReceived',
'name' => 'settings.email.templates.invoice_payment_customer',
],
[
'alias' => 'invoice_payment_admin',
'class' => 'App\Notifications\Portal\PaymentReceived',
'name' => 'settings.email.templates.invoice_payment_admin',
],
[
'alias' => 'bill_remind_admin',
'class' => 'App\Notifications\Purchase\Bill',
'name' => 'settings.email.templates.bill_remind_admin',
],
[
'alias' => 'bill_recur_admin',
'class' => 'App\Notifications\Purchase\Bill',
'name' => 'settings.email.templates.bill_recur_admin',
],
];
foreach ($templates as $template) {
EmailTemplate::create([
'company_id' => $company->id,
'alias' => $template['alias'],
'class' => $template['class'],
'name' => $template['name'],
'subject' => trans('email_templates.' . $template['alias'] . '.subject'),
'body' => trans('email_templates.' . $template['alias'] . '.body'),
Artisan::call('company:seed', [
'company' => $company->id,
'--class' => 'Database\Seeders\EmailTemplates',
]);
}
}
public function createReports($company)
{
$rows = [
[
'company_id' => $company->id,
'class' => 'App\Reports\IncomeSummary',
'name' => trans('reports.summary.income'),
'description' => trans('demo.reports.income'),
'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
],
[
'company_id' => $company->id,
'class' => 'App\Reports\ExpenseSummary',
'name' => trans('reports.summary.expense'),
'description' => trans('demo.reports.expense'),
'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
],
[
'company_id' => $company->id,
'class' => 'App\Reports\IncomeExpenseSummary',
'name' => trans('reports.summary.income_expense'),
'description' => trans('demo.reports.income_expense'),
'settings' => ['group' => 'category', 'period' => 'monthly', 'basis' => 'accrual', 'chart' => 'line'],
],
[
'company_id' => $company->id,
'class' => 'App\Reports\ProfitLoss',
'name' => trans('reports.profit_loss'),
'description' => trans('demo.reports.profit_loss'),
'settings' => ['group' => 'category', 'period' => 'quarterly', 'basis' => 'accrual'],
],
[
'company_id' => $company->id,
'class' => 'App\Reports\TaxSummary',
'name' => trans('reports.summary.tax'),
'description' => trans('demo.reports.tax'),
'settings' => ['period' => 'quarterly', 'basis' => 'accrual'],
],
];
foreach ($rows as $row) {
Report::create($row);
}
Artisan::call('company:seed', [
'company' => $company->id,
'--class' => 'Database\Seeders\Reports',
]);
}
public function createDashboards()
@ -971,6 +880,7 @@ class Version200 extends Listener
'config/modules.php',
'docker-compose.yml',
'database/seeds/Roles.php',
'database/seeds/CompanySeeder.php',
'Dockerfile',
'modules/PaypalStandard/Http/Controllers/PaypalStandard.php',
'modules/PaypalStandard/Http/routes.php',

View File

@ -0,0 +1,24 @@
<?php
namespace Database\Seeds;
use Illuminate\Database\Seeder;
class Company extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(Accounts::class);
$this->call(Categories::class);
$this->call(Currencies::class);
$this->call(EmailTemplates::class);
$this->call(Modules::class);
$this->call(Reports::class);
$this->call(Settings::class);
}
}

View File

@ -1,22 +0,0 @@
<?php
use Illuminate\Database\Seeder;
class CompanySeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->call(Database\Seeds\Accounts::class);
$this->call(Database\Seeds\Categories::class);
$this->call(Database\Seeds\Currencies::class);
$this->call(Database\Seeds\EmailTemplates::class);
$this->call(Database\Seeds\Modules::class);
$this->call(Database\Seeds\Reports::class);
$this->call(Database\Seeds\Settings::class);
}
}

View File

@ -1,8 +1,10 @@
<?php
namespace Database\Seeds;
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
class User extends Seeder
{
/**
* Run the database seeds.
@ -11,6 +13,6 @@ class UserSeeder extends Seeder
*/
public function run()
{
$this->call(Database\Seeds\Dashboards::class);
$this->call(Dashboards::class);
}
}