osb/app/Console/Commands/ServiceList.php

83 lines
1.9 KiB
PHP
Raw Normal View History

2020-02-10 11:07:46 +00:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
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
*/
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()
{
$header = '|%5s|%-9s|%-30s|%-30s|%7s|%7s|%10s|%10s|%10s|%10s|%10s|';
2020-02-10 11:07:46 +00:00
$this->warn(sprintf($header,
'ID',
'Type',
'Product',
'Name',
'Active',
'Status',
'Start',
'Stop',
'Connect',
'First',
'Next',
));
foreach (Service::cursor() as $o) {
if ((! $this->option('inactive')) && (! $o->isActive()))
continue;
if ($this->option('type') && ($o->product->getCategoryAttribute() !== $this->option('type')))
continue;
$c = $o->invoiced_items
->filter(fn($item)=>$item->item_type === 0)
->sortby('start_at')
->first();
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;
$o->save();
}
$this->info(sprintf($header,
$o->lid,
$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,
$o->start_at?->format('Y-m-d'),
$o->stop_at?->format('Y-m-d'),
($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
));
}
}
}