2020-02-10 11:07:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
2024-07-29 13:12:53 +00:00
|
|
|
use App\Models\Service;
|
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()
|
|
|
|
{
|
2024-07-29 13:12:53 +00:00
|
|
|
$header = '|%5s|%-9s|%-30s|%-30s|%7s|%7s|%10s|%10s|%10s|%10s|%10s|';
|
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',
|
2024-07-29 13:12:53 +00:00
|
|
|
'Start',
|
|
|
|
'Stop',
|
|
|
|
'Connect',
|
|
|
|
'First',
|
|
|
|
'Next',
|
2021-12-24 01:14:01 +00:00
|
|
|
));
|
2020-05-27 06:09:03 +00:00
|
|
|
|
2024-07-29 13:12:53 +00:00
|
|
|
foreach (Service::cursor() as $o) {
|
|
|
|
if ((! $this->option('inactive')) && (! $o->isActive()))
|
2020-05-27 06:09:03 +00:00
|
|
|
continue;
|
|
|
|
|
2024-07-29 13:12:53 +00:00
|
|
|
if ($this->option('type') && ($o->product->getCategoryAttribute() !== $this->option('type')))
|
2020-05-27 06:09:03 +00:00
|
|
|
continue;
|
|
|
|
|
2024-07-29 13:12:53 +00:00
|
|
|
$c = $o->invoiced_items
|
|
|
|
->filter(fn($item)=>$item->item_type === 0)
|
|
|
|
->sortby('start_at')
|
|
|
|
->first();
|
2020-05-27 06:09:03 +00:00
|
|
|
|
2024-07-29 13:12:53 +00:00
|
|
|
if ($this->option('fix') && (! $o->start_at) && $c && $c->start_at && $o->type && $o->type->connect_at && $c->start_at->format('Y-m-d') == $o->type->connect_at->format('Y-m-d')) {
|
2022-04-19 07:07:39 +00:00
|
|
|
$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,
|
2024-07-29 13:12:53 +00:00
|
|
|
$o->lid,
|
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->start_at?->format('Y-m-d'),
|
|
|
|
$o->stop_at?->format('Y-m-d'),
|
2024-07-29 13:12:53 +00:00
|
|
|
($o->type && $o->type->connect_at) ? $o->type->connect_at->format('Y-m-d') : NULL,
|
|
|
|
($c && $c->start_at) ? $c->start_at->format('Y-m-d') : NULL,
|
|
|
|
$o->invoice_next?->format('Y-m-d'),
|
2020-02-10 11:07:46 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|