Cleanup usage of Leenooks\Carbon, change ServiceType to be consistent with Products/ Suppliers/
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Casts\AsCollection;
|
||||
use Illuminate\Database\Eloquent\Collection as DatabaseCollection;
|
||||
@@ -14,8 +15,8 @@ use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Leenooks\Carbon;
|
||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||
use Leenooks\Carbon as LeenooksCarbon;
|
||||
|
||||
use App\Interfaces\IDs;
|
||||
use App\Traits\ScopeServiceUserAuthorised;
|
||||
@@ -539,7 +540,7 @@ class Service extends Model implements IDs
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getContractEndAttribute(): ?\Carbon\Carbon
|
||||
public function getContractEndAttribute(): ?Carbon
|
||||
{
|
||||
// If we have no start date or expire date, then NULL;
|
||||
if (! $this->start_at && ! $this->type->expire_at)
|
||||
@@ -585,15 +586,14 @@ class Service extends Model implements IDs
|
||||
/**
|
||||
* Return the date for the next invoice
|
||||
*
|
||||
* @return Carbon|string
|
||||
* @return LeenooksCarbon
|
||||
*/
|
||||
public function getInvoiceNextAttribute(): \Carbon\Carbon
|
||||
public function getInvoiceNextAttribute(): LeenooksCarbon
|
||||
{
|
||||
$last = $this->getInvoiceToAttribute();
|
||||
return $last
|
||||
? $last->addDay()
|
||||
: ($this->date_next_invoice ? $this->date_next_invoice->clone()
|
||||
: ($this->start_at ?: Carbon::now()));
|
||||
: ($this->date_next_invoice ? $this->date_next_invoice->clone() : ($this->start_at ?: LeenooksCarbon::now()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -733,8 +733,10 @@ class Service extends Model implements IDs
|
||||
|
||||
/**
|
||||
* Get the date that the service has been invoiced to
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function getInvoiceToAttribute(): ?\Carbon\Carbon
|
||||
public function getInvoiceToAttribute(): ?Carbon
|
||||
{
|
||||
$result = ($x=$this->invoice_items->filter(function($item) { return $item->item_type === 0;}))->count()
|
||||
? $x->last()->date_stop
|
||||
@@ -807,6 +809,8 @@ class Service extends Model implements IDs
|
||||
|
||||
/**
|
||||
* Work out when this service has been paid to.
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getPaidToAttribute(): Carbon
|
||||
{
|
||||
@@ -834,6 +838,17 @@ class Service extends Model implements IDs
|
||||
return $value ?? Invoice::BILL_QUARTERLY;
|
||||
}
|
||||
|
||||
/**
|
||||
* We need to cast some dates to LeenooksCarbon to get access to startOfHalf()/endOfHalf() methods
|
||||
*
|
||||
* @param $value
|
||||
* @return LeenooksCarbon
|
||||
*/
|
||||
public function getStartAtAttribute($value): LeenooksCarbon
|
||||
{
|
||||
return LeenooksCarbon::create($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Service Status
|
||||
*
|
||||
|
Reference in New Issue
Block a user