argument('account')) $accounts = collect()->push(Account::find($this->argument('account'))); else $accounts = Account::active()->get(); foreach ($accounts as $o) { $io = new Invoice; foreach ($o->services(TRUE)->get() as $so) { foreach ($so->next_invoice_items(FALSE) as $ooo) $io->items->push($ooo); } // If there are no items, no reason to do anything if (! $io->items->count()) continue; $io->account_id = $o->id; if ($this->option('preview')) { $this->info(sprintf('Invoice for Account [%d] - [%d] items totalling [%3.2f]',$o->id,$io->items->count(),$io->total)); continue; } // Save the invoice $io->site_id = 1; // @todo $io->active = 1; $io->pushNew(); } } }