Rework service, removed redundant code, service invoicing improvements
This commit is contained in:
@@ -48,11 +48,13 @@ class Broadband extends Type implements ServiceUsage
|
||||
* The usage information for broadband
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
* @todo rename to usage()
|
||||
*/
|
||||
public function traffic()
|
||||
{
|
||||
return $this->hasMany(UsageBroadband::class,'service_item_id')
|
||||
->where('site_id',$this->site_id);
|
||||
->where('date','>=',Carbon::now()->startOfMonth());
|
||||
//->where('site_id',$this->site_id);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
@@ -154,8 +156,6 @@ class Broadband extends Type implements ServiceUsage
|
||||
if (! $maxdate)
|
||||
return collect();
|
||||
|
||||
Log::debug(sprintf('%s:Getting Usage data for [%d] months from [%s]',self::LOGKEY,$months,$maxdate),['m'=>__METHOD__]);
|
||||
|
||||
// Go back an extra month;
|
||||
$start = $maxdate->date->subMonths($months);
|
||||
|
||||
@@ -166,8 +166,6 @@ class Broadband extends Type implements ServiceUsage
|
||||
$start = $start->subDays($start->day-15);
|
||||
}
|
||||
|
||||
Log::debug(sprintf('%s:Getting Usage data from [%s]',self::LOGKEY,$start->format('Y-m-d')),['m'=>__METHOD__]);
|
||||
|
||||
$result = collect();
|
||||
|
||||
foreach ($this->traffic()
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace App\Models\Service;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
use Leenooks\Carbon as LeenooksCarbon;
|
||||
|
||||
use App\Interfaces\ServiceItem;
|
||||
@@ -41,6 +42,14 @@ abstract class Type extends Model implements ServiceItem
|
||||
return $this->morphOne(Service::class,'type','model','id','service_id');
|
||||
}
|
||||
|
||||
public function traffic()
|
||||
{
|
||||
// Return a null relationship by default, if the child class doesnt track usage (and thus no usage table)
|
||||
return $this->hasMany(Generic::class,'id')
|
||||
->where('id',NULL)
|
||||
->where('site_id',$this->site_id);
|
||||
}
|
||||
|
||||
/* INTERFACE */
|
||||
|
||||
public function getContractTermAttribute(): int
|
||||
@@ -97,4 +106,15 @@ abstract class Type extends Model implements ServiceItem
|
||||
{
|
||||
return $this->service->offering->supplied ?: new \App\Models\Supplier\Generic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default usage summary is empty if the underlying model doesnt capture usage
|
||||
*
|
||||
* @param int $months
|
||||
* @return Collection
|
||||
*/
|
||||
public function usage_summary(int $months=2): Collection
|
||||
{
|
||||
return collect();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user