Rework service, removed redundant code, service invoicing improvements
This commit is contained in:
@@ -333,7 +333,7 @@ class ServiceController extends Controller
|
||||
$start_at = Carbon::create(Arr::get($request->broadband,'start_at'));
|
||||
|
||||
// Get the invoiced items covering the start_at date
|
||||
foreach ($o->invoice_items->filter(function($item) use ($start_at) {
|
||||
foreach ($o->invoiced_items->filter(function($item) use ($start_at) {
|
||||
return ($item->start_at < $start_at) && ($item->stop_at > $start_at) && ($item->item_type === 0);
|
||||
}) as $iio)
|
||||
{
|
||||
@@ -351,7 +351,7 @@ class ServiceController extends Controller
|
||||
$co->stop_at = $iio->stop_at;
|
||||
$co->amount = $iio->price_base;
|
||||
$co->taxable = TRUE; // @todo this should be determined
|
||||
$co->quantity = -1*$start_at->diff($iio->stop_at)->days/$iio->start_at->diff($iio->stop_at)->days;
|
||||
$co->quantity = -1*$start_at->diffInDays($iio->stop_at)/$iio->start_at->diffInDays($iio->stop_at);
|
||||
$charges->push($co);
|
||||
|
||||
// Add the new charge
|
||||
@@ -368,7 +368,7 @@ class ServiceController extends Controller
|
||||
$co->stop_at = $iio->stop_at;
|
||||
$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;
|
||||
$co->quantity = $start_at->diffInDays($iio->stop_at)/$iio->start_at->diffInDays($iio->stop_at);
|
||||
$charges->push($co);
|
||||
}
|
||||
|
||||
@@ -424,10 +424,10 @@ class ServiceController extends Controller
|
||||
$request->post(),
|
||||
$x=collect($o->type->validation())
|
||||
->keys()
|
||||
->transform(fn($item)=>sprintf('%s.%s',$o->category,$item))
|
||||
->transform(fn($item)=>sprintf('%s.%s',$o->product->category,$item))
|
||||
->combine(array_values($o->type->validation()))
|
||||
->transform(fn($item)=>is_string($item)
|
||||
? preg_replace('/^exclude_without:/',sprintf('exclude_without:%s.',$o->category),$item)
|
||||
? preg_replace('/^exclude_without:/',sprintf('exclude_without:%s.',$o->product->category),$item)
|
||||
: $item)
|
||||
->merge(
|
||||
[
|
||||
@@ -436,7 +436,7 @@ class ServiceController extends Controller
|
||||
'recur_schedule' => ['required',Rule::in(collect(Invoice::billing_periods)->keys())],
|
||||
'invoice_next_at' => 'nullable|date',
|
||||
'price' => 'nullable|numeric',
|
||||
$o->category => 'array|min:1',
|
||||
$o->product->category => 'array|min:1',
|
||||
]
|
||||
)
|
||||
->toArray()
|
||||
@@ -452,13 +452,13 @@ class ServiceController extends Controller
|
||||
$validated = collect($validator->validated());
|
||||
|
||||
// Store our service type values
|
||||
$o->type->forceFill($validated->get($o->category));
|
||||
$o->type->forceFill($validated->get($o->product->category));
|
||||
|
||||
// Some special handling
|
||||
switch ($o->category) {
|
||||
switch ($o->product->category) {
|
||||
case 'broadband':
|
||||
// If pppoe is not set, then we dont need username/password
|
||||
$o->type->pppoe = ($x=data_get($validated,$o->category.'.pppoe',FALSE));
|
||||
$o->type->pppoe = ($x=data_get($validated,$o->product->category.'.pppoe',FALSE));
|
||||
|
||||
if (! $x) {
|
||||
$o->type->service_username = NULL;
|
||||
@@ -487,7 +487,7 @@ class ServiceController extends Controller
|
||||
|
||||
else {
|
||||
// For broadband, start_at is connect_at in the type record
|
||||
switch ($o->category) {
|
||||
switch ($o->product->category) {
|
||||
case 'broadband':
|
||||
$o->start_at = $o->type->connect_at;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user