Rework service, removed redundant code, service invoicing improvements

This commit is contained in:
2024-07-29 23:12:53 +10:00
parent 5f10175b35
commit 0b5bc9e012
29 changed files with 474 additions and 523 deletions

View File

@@ -3,9 +3,8 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use App\Models\{Service,Site};
use App\Models\Service;
class ServiceList extends Command
{
@@ -33,7 +32,7 @@ class ServiceList extends Command
*/
public function handle()
{
$header = '|%13s|%-14s|%-35s|%-40s|%8s|%17s|%12s|%12s|%12s|%12s|%14s|';
$header = '|%5s|%-9s|%-30s|%-30s|%7s|%7s|%10s|%10s|%10s|%10s|%10s|';
$this->warn(sprintf($header,
'ID',
@@ -42,41 +41,42 @@ class ServiceList extends Command
'Name',
'Active',
'Status',
'Next Invoice',
'Start Date',
'Stop Date',
'Connect Date',
'First Invoice'
'Start',
'Stop',
'Connect',
'First',
'Next',
));
foreach (Service::withoutGlobalScope(\App\Models\Scopes\SiteScope::class)->with(['site'])->cursor() as $o) {
if ((! $this->option('inactive')) AND ! $o->isActive())
foreach (Service::cursor() as $o) {
if ((! $this->option('inactive')) && (! $o->isActive()))
continue;
Config::set('site',$o->site);
if ($this->option('type') AND ($o->product->getCategoryAttribute() !== $this->option('type')))
if ($this->option('type') && ($o->product->getCategoryAttribute() !== $this->option('type')))
continue;
$c = $o->invoice_items->filter(function($item) {return $item->item_type === 0; })->sortby('start_at')->first();
$c = $o->invoiced_items
->filter(fn($item)=>$item->item_type === 0)
->sortby('start_at')
->first();
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')) {
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')) {
$o->start_at = $o->type->connect_at;
$o->save();
}
$this->info(sprintf($header,
$o->sid,
$o->lid,
$o->product->getCategoryNameAttribute(),
substr($o->product->getNameAttribute(),0,35),
substr($o->name_short,0,40),
$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'),
($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,
($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'),
));
}
}