osb/app/Console/Commands/ServiceList.php

84 lines
2.1 KiB
PHP
Raw Normal View History

2020-02-10 11:07:46 +00:00
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
2020-02-10 11:07:46 +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
*/
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
$this->warn(sprintf($header,
'ID',
'Type',
'Product',
'Name',
'Active',
'Status',
'Next Invoice',
'Start Date',
'Stop Date',
'Connect Date',
'First Invoice'
));
foreach (Service::withoutGlobalScope(\App\Models\Scopes\SiteScope::class)->with(['site'])->cursor() as $o) {
//dd($o,$o->site);
if ((! $this->option('inactive')) AND ! $o->isActive())
continue;
Config::set('site',$o->site);
if ($this->option('type') AND ($o->product->getCategoryAttribute() !== $this->option('type')))
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();
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;
$o->save();
}
$this->info(sprintf($header,
2020-02-10 11:07:46 +00:00
$o->sid,
$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->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,
($c && $c->date_start) ? $c->date_start->format('Y-m-d') : NULL,
2020-02-10 11:07:46 +00:00
));
}
}
}