Fix broadband plan change update

This commit is contained in:
2023-05-03 18:09:29 +10:00
parent fd110f5c6f
commit 4f19da5987
7 changed files with 67 additions and 26 deletions

View File

@@ -96,6 +96,7 @@ class ServiceController extends Controller
$co->save();
$o->product_id = Arr::get($request->broadband,'product_id');
$o->price = Arr::get($request->broadband,'price');
$o->order_status = 'ACTIVE';
$o->save();
@@ -345,7 +346,7 @@ class ServiceController extends Controller
$co->type = $iio->item_type;
$co->start_at = $start_at;
$co->stop_at = $iio->stop_at;
$co->amount = $po->base_charge;
$co->amount = Arr::get($request->broadband,'price') ?: $po->base_charge;
$co->taxable = TRUE; // @todo this should be determined
$co->quantity = $start_at->diff($iio->stop_at)->days/$iio->start_at->diff($iio->stop_at)->days;
$charges->push($co);

View File

@@ -32,6 +32,7 @@ class ServiceChangeRequest extends FormRequest
return [
'broadband.product_id' => 'required|exists:products,id',
'broadband.change_fee' => 'nullable|numeric',
'broadband.price' => 'nullable|numeric',
'broadband.start_at' => 'required|date', // @todo Check that it is not more than 1 billing cycle ago, and not future.
];
}

View File

@@ -184,11 +184,11 @@ class Product extends Model implements IDs
/**
* Return the type of service is provided. eg: Broadband, Phone.
*
* @return string
* @return string|null
*/
public function getCategoryAttribute(): string
public function getCategoryAttribute(): ?string
{
return $this->supplied->getCategoryAttribute();
return $this->supplied ? $this->supplied->getCategoryAttribute() : NULL;
}
/**

View File

@@ -35,6 +35,7 @@ use App\Traits\SiteID;
* + billed_to : When this service has been billed to // @todo rename all references to invoice_to
* + category : The type of service this is, eg: broadband, phone
* + category_name : The type of service this is, eg: Broadband, Telephone (in human friendly)
* + isChargedOverride : Has the price been overridden?
* + contract_term : The term that this service must be active
* + contract_end : The date that the contract ends for this service
* + name : Service short name with service address
@@ -1216,6 +1217,11 @@ class Service extends Model implements IDs
AND ! in_array($this->order_status,array_merge(self::INACTIVE_STATUS,['INACTIVE']));
}
public function isChargeOverriden(): bool
{
return (! is_null($this->price)) || (! is_null($this->price_override));
}
/**
* Generate a collection of invoice_item objects that will be billed for the next invoice
*