2020-02-10 11:07:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2021-12-24 01:14:01 +00:00
|
|
|
use Illuminate\Support\Facades\Config;
|
2020-02-10 11:07:46 +00:00
|
|
|
|
2021-12-24 01:14:01 +00:00
|
|
|
use App\Models\{Service,Site};
|
2020-02-10 11:07:46 +00:00
|
|
|
|
|
|
|
class ServiceList extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2021-12-24 01:14:01 +00:00
|
|
|
protected $signature = 'service:list'.
|
|
|
|
' {--i|inactive : Include Inactive}'.
|
|
|
|
' {--t|type= : Type}'.
|
|
|
|
' {--f|fix : Fix start_date}';
|
2020-02-10 11:07:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'List all services';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2022-04-19 07:07:39 +00:00
|
|
|
$header = '|%13s|%-14s|%-35s|%-40s|%8s|%17s|%12s|%12s|%12s|%12s|%14s|';
|
2020-02-10 11:07:46 +00:00
|
|
|
|
2021-12-24 01:14:01 +00:00
|
|
|
$this->warn(sprintf($header,
|
2020-05-27 06:09:03 +00:00
|
|
|
'ID',
|
2021-12-24 01:14:01 +00:00
|
|
|
'Type',
|
2020-05-27 06:09:03 +00:00
|
|
|
'Product',
|
|
|
|
'Name',
|
2022-06-12 01:21:20 +00:00
|
|
|
'Active',
|
|
|
|
'Status',
|
|
|
|
'Next Invoice',
|
|
|
|
'Start Date',
|
|
|
|
'Stop Date',
|
|
|
|
'Connect Date',
|
|
|
|
'First Invoice'
|
2021-12-24 01:14:01 +00:00
|
|
|
));
|
2020-05-27 06:09:03 +00:00
|
|
|
|
2021-12-24 01:14:01 +00:00
|
|
|
foreach (Service::withoutGlobalScope(\App\Models\Scopes\SiteScope::class)->with(['site'])->cursor() as $o) {
|
2022-06-12 01:21:20 +00:00
|
|
|
//dd($o,$o->site);
|
2021-12-24 01:14:01 +00:00
|
|
|
if ((! $this->option('inactive')) AND ! $o->isActive())
|
2020-05-27 06:09:03 +00:00
|
|
|
continue;
|
|
|
|
|
2021-12-24 01:14:01 +00:00
|
|
|
Config::set('site',$o->site);
|
|
|
|
|
2022-06-12 01:21:20 +00:00
|
|
|
if ($this->option('type') AND ($o->product->getCategoryAttribute() !== $this->option('type')))
|
2020-05-27 06:09:03 +00:00
|
|
|
continue;
|
|
|
|
|
2022-04-19 07:07:39 +00:00
|
|
|
$c = $o->invoice_items->filter(function($item) {return $item->item_type === 0; })->sortby('start_at')->first();
|
2020-05-27 06:09:03 +00:00
|
|
|
|
2022-04-19 07:07:39 +00:00
|
|
|
if ($this->option('fix') AND ! $o->start_at AND $c AND $c->start_at AND $o->type AND $o->type->connect_at AND $c->start_at->format('Y-m-d') == $o->type->connect_at->format('Y-m-d')) {
|
|
|
|
$o->start_at = $o->type->connect_at;
|
2020-05-27 06:09:03 +00:00
|
|
|
$o->save();
|
|
|
|
}
|
|
|
|
|
2021-12-24 01:14:01 +00:00
|
|
|
$this->info(sprintf($header,
|
2020-02-10 11:07:46 +00:00
|
|
|
$o->sid,
|
2022-06-12 01:21:20 +00:00
|
|
|
$o->product->getCategoryNameAttribute(),
|
2022-04-19 07:07:39 +00:00
|
|
|
substr($o->product->getNameAttribute(),0,35),
|
|
|
|
substr($o->name_short,0,40),
|
2020-02-10 11:07:46 +00:00
|
|
|
$o->active ? 'active' : 'inactive',
|
|
|
|
$o->status,
|
2022-06-12 01:21:20 +00:00
|
|
|
$o->invoice_next?->format('Y-m-d'),
|
|
|
|
$o->start_at?->format('Y-m-d'),
|
|
|
|
$o->stop_at?->format('Y-m-d'),
|
2022-04-19 07:07:39 +00:00
|
|
|
($o->type AND $o->type->connect_at) ? $o->type->connect_at->format('Y-m-d') : NULL,
|
2021-12-24 01:14:01 +00:00
|
|
|
($c && $c->date_start) ? $c->date_start->format('Y-m-d') : NULL,
|
2020-02-10 11:07:46 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|