Move email/ resources to mail/, added invoice generated email to admin, updated email template

This commit is contained in:
2024-08-03 10:06:25 +10:00
parent f8453ae391
commit 0469d64577
40 changed files with 439 additions and 213 deletions

View File

@@ -3,7 +3,6 @@
namespace App\Console\Commands;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Mail;
use Illuminate\Console\Command;
use App\Models\{Invoice,Site};
@@ -15,7 +14,9 @@ class InvoiceEmail extends Command
*
* @var string
*/
protected $signature = 'invoice:email {site} {id}';
protected $signature = 'invoice:email'
.' {--s|site : Site ID}'
.' {id?}';
/**
* The console command description.
@@ -31,21 +32,23 @@ class InvoiceEmail extends Command
*/
public function handle()
{
Config::set('site',Site::findOrFail($this->argument('site')));
Config::set(
'site',
$this->option('site')
? Site::findOrFail($this->option('site'))
: Site::where('url',config('app.url'))->sole()
);
$o = Invoice::findOrFail($this->argument('id'));
$result = Mail::to($o->account->user->email)->send(new \App\Mail\InvoiceEmail($o));
try {
$o->print_status = TRUE;
//$o->reminders = $o->reminders('send');
$o->send();
$o->save();
} catch (\Exception $e) {
dd($e);
}
dump($result->getDebug());
return self::SUCCESS;
}
}

View File

@@ -2,6 +2,7 @@
namespace App\Console\Commands;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
@@ -14,7 +15,11 @@ class InvoiceGenerate extends Command
*
* @var string
*/
protected $signature = 'invoice:generate {site} {account?} {--p|preview : Preview} {--l|list : List Items}';
protected $signature = 'invoice:generate'
.' {--l|list : List Items}'
.' {--p|preview : Preview}'
.' {--s|site : Site ID}'
.' {id?}';
/**
* The console command description.
@@ -30,37 +35,50 @@ class InvoiceGenerate extends Command
*/
public function handle()
{
Config::set('site',Site::findOrFail($this->argument('site')));
Config::set(
'site',
$this->option('site')
? Site::findOrFail($this->option('site'))
: Site::where('url',config('app.url'))->sole()
);
if ($this->argument('account'))
$accounts = collect()->push(Account::find($this->argument('account')));
if ($this->argument('id'))
$accounts = collect()->push(Account::find($this->argument('id')));
else
$accounts = Account::active()->get();
foreach ($accounts as $o) {
$items = $o->invoice_next(Carbon::now());
if (! $items->count()) {
$this->warn(sprintf('No items for account (%s) [%d]',$o->name,$o->id));
continue;
}
$this->info(sprintf('Account: %s [%d]',$o->name,$o->lid));
$io = new Invoice;
$io->account_id = $o->id;
foreach ($o->services(TRUE)->get() as $so) {
foreach ($so->next_invoice_items(FALSE) as $ooo)
$io->items->push($ooo);
}
foreach ($items as $oo)
$io->items_active->push($oo);
// If there are no items, no reason to do anything
if (! $io->items->count() OR $io->total < 0)
if ($io->total < 0) {
$this->warn(sprintf(' - Invoice totals [%3.2f] - skipping',$io->total));
continue;
}
$io->account_id = $o->id;
if ($this->option('list')) {
$this->warn(sprintf('|%4s|%4s|%-50s|%8s|',
$this->line(sprintf('|%4s|%4s|%-50s|%8s|',
'SID',
'PID',
'Name',
'Amount',
));
foreach ($io->items as $oo) {
foreach ($io->items_active as $oo) {
$this->info(sprintf('|%4s|%4s|%-50s|%8.2f|',
$oo->service_id,
$oo->product_id,
@@ -70,8 +88,9 @@ class InvoiceGenerate extends Command
}
}
//dump($io);
if ($this->option('preview')) {
$this->info(sprintf('Invoice for Account [%d] - [%d] items totalling [%3.2f]',$o->id,$io->items->count(),$io->total));
$this->info(sprintf('=> Invoice for Account [%d] - [%d] items totalling [%3.2f]',$o->id,$io->items_active->count(),$io->total));
continue;
}
@@ -81,5 +100,7 @@ class InvoiceGenerate extends Command
$io->pushNew();
}
return self::SUCCESS;
}
}