osb/app/Console/Commands/InvoiceEmail.php

54 lines
879 B
PHP

<?php
namespace App\Console\Commands;
use Illuminate\Support\Facades\Config;
use Illuminate\Console\Command;
use App\Models\{Invoice,Site};
class InvoiceEmail extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'invoice:email'
.' {--s|site : Site ID}'
.' {id?}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Email Invoices to be client';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
Config::set(
'site',
$this->option('site')
? Site::findOrFail($this->option('site'))
: Site::where('url',config('app.url'))->sole()
);
$o = Invoice::findOrFail($this->argument('id'));
try {
$o->send();
$o->save();
} catch (\Exception $e) {
dd($e);
}
return self::SUCCESS;
}
}