Move email/ resources to mail/, added invoice generated email to admin, updated email template
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user