From 251298a230b61d5d7b831492b3babdf6c1456d01 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 29 May 2020 14:40:49 +1000 Subject: [PATCH] Added list option to invoice:generate. Fix account PushNew() --- app/Console/Commands/InvoiceGenerate.php | 20 +++++++++++++++++++- app/Models/Account.php | 5 +++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/InvoiceGenerate.php b/app/Console/Commands/InvoiceGenerate.php index 12b0f7b..d2a64e0 100644 --- a/app/Console/Commands/InvoiceGenerate.php +++ b/app/Console/Commands/InvoiceGenerate.php @@ -14,7 +14,7 @@ class InvoiceGenerate extends Command * * @var string */ - protected $signature = 'invoice:generate {account?} {--p|preview : Preview}'; + protected $signature = 'invoice:generate {account?} {--p|preview : Preview} {--l|list : List Items}'; /** * The console command description. @@ -60,6 +60,24 @@ class InvoiceGenerate extends Command $io->account_id = $o->id; + if ($this->option('list')) { + $this->warn(sprintf('|%4s|%4s|%-50s|%8s|', + 'SID', + 'PID', + 'Name', + 'Amount', + )); + + foreach ($io->items as $oo) { + $this->info(sprintf('|%4s|%4s|%-50s|%8.2f|', + $oo->service_id, + $oo->product_id, + $oo->item_type_name, + $oo->total, + )); + } + } + if ($this->option('preview')) { $this->info(sprintf('Invoice for Account [%d] - [%d] items totalling [%3.2f]',$o->id,$io->items->count(),$io->total)); continue; diff --git a/app/Models/Account.php b/app/Models/Account.php index b6006fe..ce67475 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -6,10 +6,11 @@ use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use App\Traits\NextKey; +use App\Traits\PushNew; class Account extends Model { - use NextKey; + use NextKey,PushNew; const RECORD_ID = 'account'; public $incrementing = FALSE; @@ -92,7 +93,7 @@ class Account extends Model // Build our where clause // First Name, Last name if (preg_match('/\ /',$term)) { - list($fn,$ln) = explode(' ',$term,2); + [$fn,$ln] = explode(' ',$term,2); $query->where(function($query1) use ($fn,$ln,$term) { $query1->where(function($query2) use ($fn,$ln) {