warn(sprintf($header, 'ID', 'Type', 'Product', 'Name', 'active', 'status', 'invoice next', 'start date', 'stop date', 'connect date', 'first invoice' )); foreach (Service::withoutGlobalScope(\App\Models\Scopes\SiteScope::class)->with(['site'])->cursor() as $o) { if ((! $this->option('inactive')) AND ! $o->isActive()) continue; Config::set('site',$o->site); if ($this->option('type') AND ($o->product->getProductTypeAttribute() !== $this->option('type'))) continue; $c = $o->invoice_items->filter(function($item) {return $item->item_type === 0; })->sortby('date_start')->first(); if ($this->option('fix') AND ! $o->date_start AND $c AND $c->date_start AND $o->type AND $o->type->service_connect_date AND $c->date_start->format('Y-m-d') == $o->type->service_connect_date->format('Y-m-d')) { $o->date_start = $o->type->service_connect_date; $o->save(); } $this->info(sprintf($header, $o->sid, $o->product->getProductTypeAttribute(), $o->product->getNameAttribute(), $o->name_short, $o->active ? 'active' : 'inactive', $o->status, $o->invoice_next ? $o->invoice_next->format('Y-m-d') : NULL, $o->date_start ? $o->date_start->format('Y-m-d') : NULL, $o->date_end ? $o->date_end->format('Y-m-d') : NULL, ($o->type AND $o->type->service_connect_date) ? $o->type->service_connect_date->format('Y-m-d') : NULL, ($c && $c->date_start) ? $c->date_start->format('Y-m-d') : NULL, )); } } }