Fix email generation and sending via CLI

This commit is contained in:
Deon George 2022-08-25 11:08:10 +10:00
parent 8955df84cd
commit 39db6303c2
3 changed files with 9 additions and 8 deletions

View File

@ -25,7 +25,7 @@ class AccountingAccountSync extends Command
* *
* @var string * @var string
*/ */
protected $description = 'Synchronise accounts with account system'; protected $description = 'Synchronise accounts with accounting system';
/** /**
* Execute the console command. * Execute the console command.

View File

@ -6,7 +6,7 @@ use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Mail;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use App\Models\Invoice; use App\Models\{Invoice,Site};
class InvoiceEmail extends Command class InvoiceEmail extends Command
{ {
@ -15,7 +15,7 @@ class InvoiceEmail extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'invoice:email {id}'; protected $signature = 'invoice:email {site} {id}';
/** /**
* The console command description. * The console command description.
@ -31,8 +31,9 @@ class InvoiceEmail extends Command
*/ */
public function handle() public function handle()
{ {
Config::set('site',Site::findOrFail($this->argument('site')));
$o = Invoice::findOrFail($this->argument('id')); $o = Invoice::findOrFail($this->argument('id'));
Config::set('site',$o->account->site);
Mail::to($o->account->user->email)->send(new \App\Mail\InvoiceEmail($o)); Mail::to($o->account->user->email)->send(new \App\Mail\InvoiceEmail($o));

View File

@ -5,7 +5,7 @@ namespace App\Console\Commands;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use App\Models\{Account,Invoice}; use App\Models\{Account,Invoice,Site};
class InvoiceGenerate extends Command class InvoiceGenerate extends Command
{ {
@ -14,7 +14,7 @@ class InvoiceGenerate extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'invoice:generate {account?} {--p|preview : Preview} {--l|list : List Items}'; protected $signature = 'invoice:generate {site} {account?} {--p|preview : Preview} {--l|list : List Items}';
/** /**
* The console command description. * The console command description.
@ -30,14 +30,14 @@ class InvoiceGenerate extends Command
*/ */
public function handle() public function handle()
{ {
Config::set('site',Site::findOrFail($this->argument('site')));
if ($this->argument('account')) if ($this->argument('account'))
$accounts = collect()->push(Account::find($this->argument('account'))); $accounts = collect()->push(Account::find($this->argument('account')));
else else
$accounts = Account::active()->get(); $accounts = Account::active()->get();
foreach ($accounts as $o) { foreach ($accounts as $o) {
Config::set('site',$o->site);
$io = new Invoice; $io = new Invoice;
$io->account_id = $o->id; $io->account_id = $o->id;