diff --git a/app/Console/Commands/CompanySeed.php b/app/Console/Commands/CompanySeed.php index f4e140a7f..98eae12ea 100644 --- a/app/Console/Commands/CompanySeed.php +++ b/app/Console/Commands/CompanySeed.php @@ -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'], + ]; } } diff --git a/app/Console/Commands/UserSeed.php b/app/Console/Commands/UserSeed.php index 172e1930b..f3af20276 100644 --- a/app/Console/Commands/UserSeed.php +++ b/app/Console/Commands/UserSeed.php @@ -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(); } } diff --git a/app/Listeners/Update/V20/Version200.php b/app/Listeners/Update/V20/Version200.php index ec4c428a0..3d79ebd98 100644 --- a/app/Listeners/Update/V20/Version200.php +++ b/app/Listeners/Update/V20/Version200.php @@ -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', @@ -1083,9 +993,9 @@ class Version200 extends Listener public function updateEnv() { Installer::updateEnv([ - 'QUEUE_CONNECTION' => 'sync', - 'LOG_CHANNEL' => 'stack', - 'FIREWALL_ENABLED' => 'true', + 'QUEUE_CONNECTION' => 'sync', + 'LOG_CHANNEL' => 'stack', + 'FIREWALL_ENABLED' => 'true', ]); } } diff --git a/database/seeds/Company.php b/database/seeds/Company.php new file mode 100644 index 000000000..97fd0c024 --- /dev/null +++ b/database/seeds/Company.php @@ -0,0 +1,24 @@ +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); + } +} diff --git a/database/seeds/CompanySeeder.php b/database/seeds/CompanySeeder.php deleted file mode 100644 index 4df8350ac..000000000 --- a/database/seeds/CompanySeeder.php +++ /dev/null @@ -1,22 +0,0 @@ -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); - } -} diff --git a/database/seeds/UserSeeder.php b/database/seeds/User.php similarity index 62% rename from database/seeds/UserSeeder.php rename to database/seeds/User.php index 8b5d4e45e..022ac7930 100644 --- a/database/seeds/UserSeeder.php +++ b/database/seeds/User.php @@ -1,8 +1,10 @@ call(Database\Seeds\Dashboards::class); + $this->call(Dashboards::class); } }